From f002d44370b473b940d4771a8fa8b280341f9324 Mon Sep 17 00:00:00 2001 From: rexim Date: Fri, 17 May 2019 20:26:07 +0700 Subject: [PATCH] If hover over ImageLayoutElement show the preview of image --- src/widgets/helper/ChannelView.cpp | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/widgets/helper/ChannelView.cpp b/src/widgets/helper/ChannelView.cpp index 90c0e9b93..30d34beef 100644 --- a/src/widgets/helper/ChannelView.cpp +++ b/src/widgets/helper/ChannelView.cpp @@ -1217,9 +1217,32 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event) } else { + auto imageLayoutElement = + dynamic_cast(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("
%2x%3
%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->setWordWrap(isLinkValid); - tooltipWidget->setText(tooltip); tooltipWidget->adjustSize(); tooltipWidget->show(); tooltipWidget->raise();