If hover over ImageLayoutElement show the preview of image

This commit is contained in:
rexim 2019-05-17 20:26:07 +07:00
parent d4a6defed6
commit f002d44370

View file

@ -1217,9 +1217,32 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event)
} }
else else
{ {
auto imageLayoutElement =
dynamic_cast<const ImageLayoutElement *>(hoverLayoutElement);
if (imageLayoutElement && imageLayoutElement->pixmap()) {
QBuffer buffer;
const int width = imageLayoutElement->pixmap()->width();
const int height = imageLayoutElement->pixmap()->height();
imageLayoutElement->pixmap()->save(&buffer, "PNG");
// FIXME: Image inside of imageLayoutElement is not always the biggest
// FIXME: Inject image directly into tooltipWidget without base64 bs
// FIXME: Gifs are not animated
// FIXME: No way to opt-out
tooltipWidget->setText(
QString("<img src='data:image/png;base64,%1' /><br/>%2x%3<br/>%4")
.arg(QString(buffer.data().toBase64()))
.arg(imageLayoutElement->pixmap()->width())
.arg(imageLayoutElement->pixmap()->height())
.arg(tooltip));
} else {
tooltipWidget->setText(tooltip);
}
tooltipWidget->moveTo(this, event->globalPos()); tooltipWidget->moveTo(this, event->globalPos());
tooltipWidget->setWordWrap(isLinkValid); tooltipWidget->setWordWrap(isLinkValid);
tooltipWidget->setText(tooltip);
tooltipWidget->adjustSize(); tooltipWidget->adjustSize();
tooltipWidget->show(); tooltipWidget->show();
tooltipWidget->raise(); tooltipWidget->raise();