From d4a6defed6e8e9e731dbb00d54b96286ccf22ad9 Mon Sep 17 00:00:00 2001 From: rexim Date: Fri, 17 May 2019 20:25:15 +0700 Subject: [PATCH 01/19] Introduce a way to extract QPixmap from ImageLayoutElement Probably should be a part of MessageLayoutElement interface, but good for now --- src/messages/layouts/MessageLayoutElement.cpp | 5 +++++ src/messages/layouts/MessageLayoutElement.hpp | 2 ++ 2 files changed, 7 insertions(+) diff --git a/src/messages/layouts/MessageLayoutElement.cpp b/src/messages/layouts/MessageLayoutElement.cpp index a8bcc30c9..bd90d4ca9 100644 --- a/src/messages/layouts/MessageLayoutElement.cpp +++ b/src/messages/layouts/MessageLayoutElement.cpp @@ -168,6 +168,11 @@ int ImageLayoutElement::getXFromIndex(int index) } } +boost::optional ImageLayoutElement::pixmap() const +{ + return this->image_->pixmap(); +} + // // TEXT // diff --git a/src/messages/layouts/MessageLayoutElement.hpp b/src/messages/layouts/MessageLayoutElement.hpp index d5e11a0a3..5c92665b9 100644 --- a/src/messages/layouts/MessageLayoutElement.hpp +++ b/src/messages/layouts/MessageLayoutElement.hpp @@ -62,6 +62,8 @@ public: ImageLayoutElement(MessageElement &creator, ImagePtr image, const QSize &size); + boost::optional pixmap() const; + protected: void addCopyTextToString(QString &str, int from = 0, int to = INT_MAX) const override; From f002d44370b473b940d4771a8fa8b280341f9324 Mon Sep 17 00:00:00 2001 From: rexim Date: Fri, 17 May 2019 20:26:07 +0700 Subject: [PATCH 02/19] 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(); From cbb1ec2d7ae9ec35aad3903db3dab36f1ff86440 Mon Sep 17 00:00:00 2001 From: rexim Date: Wed, 22 May 2019 00:20:47 +0700 Subject: [PATCH 03/19] Remove dead code --- src/widgets/helper/ChannelView.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/widgets/helper/ChannelView.cpp b/src/widgets/helper/ChannelView.cpp index 30d34beef..d5f1d72c9 100644 --- a/src/widgets/helper/ChannelView.cpp +++ b/src/widgets/helper/ChannelView.cpp @@ -1222,8 +1222,6 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event) 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 From aa4e7f13e71ba052b5d443883d4fa820f07b31e7 Mon Sep 17 00:00:00 2001 From: rexim Date: Wed, 22 May 2019 00:33:12 +0700 Subject: [PATCH 04/19] Get rid of dynamic_cast --- src/messages/layouts/MessageLayoutElement.cpp | 11 +++++++++++ src/messages/layouts/MessageLayoutElement.hpp | 7 +++++-- src/widgets/helper/ChannelView.cpp | 11 ++++------- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/messages/layouts/MessageLayoutElement.cpp b/src/messages/layouts/MessageLayoutElement.cpp index bd90d4ca9..1b52201bb 100644 --- a/src/messages/layouts/MessageLayoutElement.cpp +++ b/src/messages/layouts/MessageLayoutElement.cpp @@ -296,6 +296,11 @@ int TextLayoutElement::getXFromIndex(int index) } } +boost::optional TextLayoutElement::pixmap() const +{ + return boost::none; +} + // TEXT ICON TextIconLayoutElement::TextIconLayoutElement(MessageElement &creator, const QString &_line1, @@ -373,4 +378,10 @@ int TextIconLayoutElement::getXFromIndex(int index) } } +boost::optional TextIconLayoutElement::pixmap() const +{ + return boost::none; +} + + } // namespace chatterino diff --git a/src/messages/layouts/MessageLayoutElement.hpp b/src/messages/layouts/MessageLayoutElement.hpp index 5c92665b9..3c2c1b24c 100644 --- a/src/messages/layouts/MessageLayoutElement.hpp +++ b/src/messages/layouts/MessageLayoutElement.hpp @@ -41,6 +41,8 @@ public: virtual void paintAnimated(QPainter &painter, int yOffset) = 0; virtual int getMouseOverIndex(const QPoint &abs) const = 0; virtual int getXFromIndex(int index) = 0; + virtual boost::optional pixmap() const = 0; + const Link &getLink() const; const QString &getText() const; FlagsEnum getFlags() const; @@ -62,8 +64,6 @@ public: ImageLayoutElement(MessageElement &creator, ImagePtr image, const QSize &size); - boost::optional pixmap() const; - protected: void addCopyTextToString(QString &str, int from = 0, int to = INT_MAX) const override; @@ -72,6 +72,7 @@ protected: void paintAnimated(QPainter &painter, int yOffset) override; int getMouseOverIndex(const QPoint &abs) const override; int getXFromIndex(int index) override; + boost::optional pixmap() const override; private: ImagePtr image_; @@ -95,6 +96,7 @@ protected: void paintAnimated(QPainter &painter, int yOffset) override; int getMouseOverIndex(const QPoint &abs) const override; int getXFromIndex(int index) override; + boost::optional pixmap() const override; private: QColor color_; @@ -120,6 +122,7 @@ protected: void paintAnimated(QPainter &painter, int yOffset) override; int getMouseOverIndex(const QPoint &abs) const override; int getXFromIndex(int index) override; + boost::optional pixmap() const override; private: float scale; diff --git a/src/widgets/helper/ChannelView.cpp b/src/widgets/helper/ChannelView.cpp index d5f1d72c9..8087d8b1a 100644 --- a/src/widgets/helper/ChannelView.cpp +++ b/src/widgets/helper/ChannelView.cpp @@ -1217,12 +1217,9 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event) } else { - auto imageLayoutElement = - dynamic_cast(hoverLayoutElement); - - if (imageLayoutElement && imageLayoutElement->pixmap()) { + if (auto pixmap = hoverLayoutElement->pixmap()) { QBuffer buffer; - imageLayoutElement->pixmap()->save(&buffer, "PNG"); + pixmap->save(&buffer, "PNG"); // FIXME: Image inside of imageLayoutElement is not always the biggest // FIXME: Inject image directly into tooltipWidget without base64 bs @@ -1232,8 +1229,8 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event) tooltipWidget->setText( QString("
%2x%3
%4") .arg(QString(buffer.data().toBase64())) - .arg(imageLayoutElement->pixmap()->width()) - .arg(imageLayoutElement->pixmap()->height()) + .arg(pixmap->width()) + .arg(pixmap->height()) .arg(tooltip)); } else { tooltipWidget->setText(tooltip); From 959aa4616f6d779c618963f32f4e196e2b50f03a Mon Sep 17 00:00:00 2001 From: rexim Date: Wed, 22 May 2019 00:52:09 +0700 Subject: [PATCH 05/19] pixmap() -> imagePreview() --- src/messages/layouts/MessageLayoutElement.cpp | 6 +++--- src/messages/layouts/MessageLayoutElement.hpp | 8 ++++---- src/widgets/helper/ChannelView.cpp | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/messages/layouts/MessageLayoutElement.cpp b/src/messages/layouts/MessageLayoutElement.cpp index 1b52201bb..9f5db03d9 100644 --- a/src/messages/layouts/MessageLayoutElement.cpp +++ b/src/messages/layouts/MessageLayoutElement.cpp @@ -168,7 +168,7 @@ int ImageLayoutElement::getXFromIndex(int index) } } -boost::optional ImageLayoutElement::pixmap() const +boost::optional ImageLayoutElement::imagePreview() const { return this->image_->pixmap(); } @@ -296,7 +296,7 @@ int TextLayoutElement::getXFromIndex(int index) } } -boost::optional TextLayoutElement::pixmap() const +boost::optional TextLayoutElement::imagePreview() const { return boost::none; } @@ -378,7 +378,7 @@ int TextIconLayoutElement::getXFromIndex(int index) } } -boost::optional TextIconLayoutElement::pixmap() const +boost::optional TextIconLayoutElement::imagePreview() const { return boost::none; } diff --git a/src/messages/layouts/MessageLayoutElement.hpp b/src/messages/layouts/MessageLayoutElement.hpp index 3c2c1b24c..9837146a6 100644 --- a/src/messages/layouts/MessageLayoutElement.hpp +++ b/src/messages/layouts/MessageLayoutElement.hpp @@ -41,7 +41,7 @@ public: virtual void paintAnimated(QPainter &painter, int yOffset) = 0; virtual int getMouseOverIndex(const QPoint &abs) const = 0; virtual int getXFromIndex(int index) = 0; - virtual boost::optional pixmap() const = 0; + virtual boost::optional imagePreview() const = 0; const Link &getLink() const; const QString &getText() const; @@ -72,7 +72,7 @@ protected: void paintAnimated(QPainter &painter, int yOffset) override; int getMouseOverIndex(const QPoint &abs) const override; int getXFromIndex(int index) override; - boost::optional pixmap() const override; + boost::optional imagePreview() const override; private: ImagePtr image_; @@ -96,7 +96,7 @@ protected: void paintAnimated(QPainter &painter, int yOffset) override; int getMouseOverIndex(const QPoint &abs) const override; int getXFromIndex(int index) override; - boost::optional pixmap() const override; + boost::optional imagePreview() const override; private: QColor color_; @@ -122,7 +122,7 @@ protected: void paintAnimated(QPainter &painter, int yOffset) override; int getMouseOverIndex(const QPoint &abs) const override; int getXFromIndex(int index) override; - boost::optional pixmap() const override; + boost::optional imagePreview() const override; private: float scale; diff --git a/src/widgets/helper/ChannelView.cpp b/src/widgets/helper/ChannelView.cpp index 8087d8b1a..0d53a9b7c 100644 --- a/src/widgets/helper/ChannelView.cpp +++ b/src/widgets/helper/ChannelView.cpp @@ -1217,7 +1217,7 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event) } else { - if (auto pixmap = hoverLayoutElement->pixmap()) { + if (auto pixmap = hoverLayoutElement->imagePreview()) { QBuffer buffer; pixmap->save(&buffer, "PNG"); From 7251a20dfbaa07d6c8aac2d8cbcbb5ca35f12f56 Mon Sep 17 00:00:00 2001 From: rexim Date: Wed, 22 May 2019 02:14:41 +0700 Subject: [PATCH 06/19] Get the biggest version of emote from EmoteElement --- src/widgets/helper/ChannelView.cpp | 32 ++++++++++++++++++------------ 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/widgets/helper/ChannelView.cpp b/src/widgets/helper/ChannelView.cpp index 0d53a9b7c..b89f0a46b 100644 --- a/src/widgets/helper/ChannelView.cpp +++ b/src/widgets/helper/ChannelView.cpp @@ -1217,21 +1217,27 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event) } else { - if (auto pixmap = hoverLayoutElement->imagePreview()) { - QBuffer buffer; - pixmap->save(&buffer, "PNG"); + auto emoteElement = dynamic_cast(&hoverLayoutElement->getCreator()); - // 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 + if (emoteElement) { + auto pixmap = emoteElement->getEmote()->images.getImage(3.0)->pixmap(); + if (pixmap) { + QBuffer buffer; + pixmap->save(&buffer, "PNG"); - tooltipWidget->setText( - QString("
%2x%3
%4") - .arg(QString(buffer.data().toBase64())) - .arg(pixmap->width()) - .arg(pixmap->height()) - .arg(tooltip)); + // 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(pixmap->width()) + .arg(pixmap->height()) + .arg(tooltip)); + } else { + tooltipWidget->setText(tooltip); + } } else { tooltipWidget->setText(tooltip); } From a569985315dd5356aec82bc2c21c35f67c7ec9ac Mon Sep 17 00:00:00 2001 From: rexim Date: Wed, 22 May 2019 02:25:09 +0700 Subject: [PATCH 07/19] Remove dead code --- src/messages/layouts/MessageLayoutElement.cpp | 16 ---------------- src/messages/layouts/MessageLayoutElement.hpp | 4 ---- 2 files changed, 20 deletions(-) diff --git a/src/messages/layouts/MessageLayoutElement.cpp b/src/messages/layouts/MessageLayoutElement.cpp index 9f5db03d9..a8bcc30c9 100644 --- a/src/messages/layouts/MessageLayoutElement.cpp +++ b/src/messages/layouts/MessageLayoutElement.cpp @@ -168,11 +168,6 @@ int ImageLayoutElement::getXFromIndex(int index) } } -boost::optional ImageLayoutElement::imagePreview() const -{ - return this->image_->pixmap(); -} - // // TEXT // @@ -296,11 +291,6 @@ int TextLayoutElement::getXFromIndex(int index) } } -boost::optional TextLayoutElement::imagePreview() const -{ - return boost::none; -} - // TEXT ICON TextIconLayoutElement::TextIconLayoutElement(MessageElement &creator, const QString &_line1, @@ -378,10 +368,4 @@ int TextIconLayoutElement::getXFromIndex(int index) } } -boost::optional TextIconLayoutElement::imagePreview() const -{ - return boost::none; -} - - } // namespace chatterino diff --git a/src/messages/layouts/MessageLayoutElement.hpp b/src/messages/layouts/MessageLayoutElement.hpp index 9837146a6..a7214937a 100644 --- a/src/messages/layouts/MessageLayoutElement.hpp +++ b/src/messages/layouts/MessageLayoutElement.hpp @@ -41,7 +41,6 @@ public: virtual void paintAnimated(QPainter &painter, int yOffset) = 0; virtual int getMouseOverIndex(const QPoint &abs) const = 0; virtual int getXFromIndex(int index) = 0; - virtual boost::optional imagePreview() const = 0; const Link &getLink() const; const QString &getText() const; @@ -72,7 +71,6 @@ protected: void paintAnimated(QPainter &painter, int yOffset) override; int getMouseOverIndex(const QPoint &abs) const override; int getXFromIndex(int index) override; - boost::optional imagePreview() const override; private: ImagePtr image_; @@ -96,7 +94,6 @@ protected: void paintAnimated(QPainter &painter, int yOffset) override; int getMouseOverIndex(const QPoint &abs) const override; int getXFromIndex(int index) override; - boost::optional imagePreview() const override; private: QColor color_; @@ -122,7 +119,6 @@ protected: void paintAnimated(QPainter &painter, int yOffset) override; int getMouseOverIndex(const QPoint &abs) const override; int getXFromIndex(int index) override; - boost::optional imagePreview() const override; private: float scale; From 8b79faf958a59d21d74b755d9af0a7815131d145 Mon Sep 17 00:00:00 2001 From: rexim Date: Tue, 28 May 2019 23:43:36 +0700 Subject: [PATCH 08/19] Make Emotes Tooltip Preview disablable in the Settings --- src/singletons/Settings.hpp | 1 + src/widgets/helper/ChannelView.cpp | 3 +-- src/widgets/settingspages/GeneralPage.cpp | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/singletons/Settings.hpp b/src/singletons/Settings.hpp index 0d103cc36..63f5f4f4c 100644 --- a/src/singletons/Settings.hpp +++ b/src/singletons/Settings.hpp @@ -192,6 +192,7 @@ public: QStringSetting currentVersion = {"/misc/currentVersion", ""}; BoolSetting loadTwitchMessageHistoryOnConnect = { "/misc/twitch/loadMessageHistoryOnConnect", true}; + BoolSetting emotesTooltipPreview = {"/misc/emotesTooltipPreview", false}; QStringSetting cachePath = {"/cache/path", ""}; diff --git a/src/widgets/helper/ChannelView.cpp b/src/widgets/helper/ChannelView.cpp index b89f0a46b..61b047380 100644 --- a/src/widgets/helper/ChannelView.cpp +++ b/src/widgets/helper/ChannelView.cpp @@ -1219,7 +1219,7 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event) { auto emoteElement = dynamic_cast(&hoverLayoutElement->getCreator()); - if (emoteElement) { + if (emoteElement && getSettings()->emotesTooltipPreview.getValue()) { auto pixmap = emoteElement->getEmote()->images.getImage(3.0)->pixmap(); if (pixmap) { QBuffer buffer; @@ -1227,7 +1227,6 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event) // 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") diff --git a/src/widgets/settingspages/GeneralPage.cpp b/src/widgets/settingspages/GeneralPage.cpp index 2df805554..9cf81a154 100644 --- a/src/widgets/settingspages/GeneralPage.cpp +++ b/src/widgets/settingspages/GeneralPage.cpp @@ -270,6 +270,7 @@ void GeneralPage::initLayout(SettingsLayout &layout) layout.addCheckbox("Double click links to open", s.linksDoubleClickOnly); layout.addCheckbox("Unshorten links", s.unshortLinks); layout.addCheckbox("Show live indicator in tabs", s.showTabLive); + layout.addCheckbox("Show emote preview in tooltip on hover", s.emotesTooltipPreview); layout.addSpacing(16); layout.addSeperator(); From 94e705ec1bcf86f75defc77f4de094d135cb82a7 Mon Sep 17 00:00:00 2001 From: rexim Date: Wed, 29 May 2019 00:58:14 +0700 Subject: [PATCH 09/19] Inject Emotes into TooltipWidget directly --- src/widgets/helper/ChannelView.cpp | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/src/widgets/helper/ChannelView.cpp b/src/widgets/helper/ChannelView.cpp index 61b047380..1f0147f35 100644 --- a/src/widgets/helper/ChannelView.cpp +++ b/src/widgets/helper/ChannelView.cpp @@ -1217,33 +1217,21 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event) } else { - auto emoteElement = dynamic_cast(&hoverLayoutElement->getCreator()); + tooltipWidget->clearImage(); + auto emoteElement = dynamic_cast(&hoverLayoutElement->getCreator()); if (emoteElement && getSettings()->emotesTooltipPreview.getValue()) { auto pixmap = emoteElement->getEmote()->images.getImage(3.0)->pixmap(); if (pixmap) { - QBuffer buffer; - pixmap->save(&buffer, "PNG"); - - // FIXME: Inject image directly into tooltipWidget without base64 bs // FIXME: Gifs are not animated - - tooltipWidget->setText( - QString("
%2x%3
%4") - .arg(QString(buffer.data().toBase64())) - .arg(pixmap->width()) - .arg(pixmap->height()) - .arg(tooltip)); - } else { - tooltipWidget->setText(tooltip); + tooltipWidget->setImage(*pixmap); } - } else { - tooltipWidget->setText(tooltip); } tooltipWidget->moveTo(this, event->globalPos()); tooltipWidget->setWordWrap(isLinkValid); tooltipWidget->adjustSize(); + tooltipWidget->setText(tooltip); tooltipWidget->show(); tooltipWidget->raise(); } From a84716547b5c63e33708d709a3c28ea227a4e75e Mon Sep 17 00:00:00 2001 From: rexim Date: Wed, 5 Jun 2019 00:59:08 +0700 Subject: [PATCH 10/19] Animate gifs in the tooltip preview --- src/widgets/helper/ChannelView.cpp | 20 +++++++++++++------- src/widgets/helper/ChannelView.hpp | 3 +++ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/widgets/helper/ChannelView.cpp b/src/widgets/helper/ChannelView.cpp index 1f0147f35..ef3c290fc 100644 --- a/src/widgets/helper/ChannelView.cpp +++ b/src/widgets/helper/ChannelView.cpp @@ -311,6 +311,15 @@ void ChannelView::queueUpdate() // } // this->repaint(); + + auto tooltipWidget = TooltipWidget::getInstance(); + if (this->currentPreviewEmote) { + auto pixmap = this->currentPreviewEmote->images.getImage(3.0)->pixmap(); + if (pixmap) { + tooltipWidget->setImage(*pixmap); + } + } + this->update(); // this->updateTimer.start(); @@ -1217,15 +1226,12 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event) } else { - tooltipWidget->clearImage(); - auto emoteElement = dynamic_cast(&hoverLayoutElement->getCreator()); if (emoteElement && getSettings()->emotesTooltipPreview.getValue()) { - auto pixmap = emoteElement->getEmote()->images.getImage(3.0)->pixmap(); - if (pixmap) { - // FIXME: Gifs are not animated - tooltipWidget->setImage(*pixmap); - } + this->currentPreviewEmote = emoteElement->getEmote(); + } else { + this->currentPreviewEmote = nullptr; + tooltipWidget->clearImage(); } tooltipWidget->moveTo(this, event->globalPos()); diff --git a/src/widgets/helper/ChannelView.hpp b/src/widgets/helper/ChannelView.hpp index 70b5fd0b4..7abf29380 100644 --- a/src/widgets/helper/ChannelView.hpp +++ b/src/widgets/helper/ChannelView.hpp @@ -4,6 +4,7 @@ #include "messages/LimitedQueue.hpp" #include "messages/LimitedQueueSnapshot.hpp" #include "messages/Selection.hpp" +#include "messages/Emote.hpp" #include "widgets/BaseWidget.hpp" #include @@ -209,6 +210,8 @@ private: static constexpr int leftPadding = 8; static constexpr int scrollbarPadding = 8; + EmotePtr currentPreviewEmote = nullptr; + private slots: void wordFlagsChanged() { From 0fb16d150bf86b2e32c4b3ca80b4976c3bf62c65 Mon Sep 17 00:00:00 2001 From: rexim Date: Wed, 5 Jun 2019 01:18:32 +0700 Subject: [PATCH 11/19] Preview images instead of emotes --- src/widgets/helper/ChannelView.cpp | 8 ++++---- src/widgets/helper/ChannelView.hpp | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/widgets/helper/ChannelView.cpp b/src/widgets/helper/ChannelView.cpp index ef3c290fc..e4fad5ce0 100644 --- a/src/widgets/helper/ChannelView.cpp +++ b/src/widgets/helper/ChannelView.cpp @@ -313,8 +313,8 @@ void ChannelView::queueUpdate() // this->repaint(); auto tooltipWidget = TooltipWidget::getInstance(); - if (this->currentPreviewEmote) { - auto pixmap = this->currentPreviewEmote->images.getImage(3.0)->pixmap(); + if (this->currentPreviewImage) { + auto pixmap = this->currentPreviewImage->pixmap(); if (pixmap) { tooltipWidget->setImage(*pixmap); } @@ -1228,9 +1228,9 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event) { auto emoteElement = dynamic_cast(&hoverLayoutElement->getCreator()); if (emoteElement && getSettings()->emotesTooltipPreview.getValue()) { - this->currentPreviewEmote = emoteElement->getEmote(); + this->currentPreviewImage = emoteElement->getEmote()->images.getImage(3.0); } else { - this->currentPreviewEmote = nullptr; + this->currentPreviewImage = nullptr; tooltipWidget->clearImage(); } diff --git a/src/widgets/helper/ChannelView.hpp b/src/widgets/helper/ChannelView.hpp index 7abf29380..58b296718 100644 --- a/src/widgets/helper/ChannelView.hpp +++ b/src/widgets/helper/ChannelView.hpp @@ -4,7 +4,7 @@ #include "messages/LimitedQueue.hpp" #include "messages/LimitedQueueSnapshot.hpp" #include "messages/Selection.hpp" -#include "messages/Emote.hpp" +#include "messages/Image.hpp" #include "widgets/BaseWidget.hpp" #include @@ -210,7 +210,7 @@ private: static constexpr int leftPadding = 8; static constexpr int scrollbarPadding = 8; - EmotePtr currentPreviewEmote = nullptr; + ImagePtr currentPreviewImage = nullptr; private slots: void wordFlagsChanged() From e1a901aa98677ebc776a6aaae7af8fa575cb40b0 Mon Sep 17 00:00:00 2001 From: rexim Date: Wed, 5 Jun 2019 01:22:21 +0700 Subject: [PATCH 12/19] Adjust tooltip size after setting the text --- src/widgets/helper/ChannelView.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/widgets/helper/ChannelView.cpp b/src/widgets/helper/ChannelView.cpp index e4fad5ce0..6a49d2f5b 100644 --- a/src/widgets/helper/ChannelView.cpp +++ b/src/widgets/helper/ChannelView.cpp @@ -1236,8 +1236,8 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event) tooltipWidget->moveTo(this, event->globalPos()); tooltipWidget->setWordWrap(isLinkValid); - tooltipWidget->adjustSize(); tooltipWidget->setText(tooltip); + tooltipWidget->adjustSize(); tooltipWidget->show(); tooltipWidget->raise(); } From 3f4d3ce14a8cb38631fbf54ddd9067a793fd3d48 Mon Sep 17 00:00:00 2001 From: rexim Date: Wed, 12 Jun 2019 00:22:26 +0700 Subject: [PATCH 13/19] (#976) Make currentPreviewImage shareable between ChannelView-s --- src/widgets/helper/ChannelView.cpp | 13 ++++++++----- src/widgets/helper/ChannelView.hpp | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/widgets/helper/ChannelView.cpp b/src/widgets/helper/ChannelView.cpp index 6a49d2f5b..657c2de0b 100644 --- a/src/widgets/helper/ChannelView.cpp +++ b/src/widgets/helper/ChannelView.cpp @@ -105,6 +105,8 @@ namespace { } } // namespace +ImagePtr ChannelView::currentPreviewImage = nullptr; + ChannelView::ChannelView(BaseWidget *parent) : BaseWidget(parent) , scrollBar_(new Scrollbar(this)) @@ -313,11 +315,13 @@ void ChannelView::queueUpdate() // this->repaint(); auto tooltipWidget = TooltipWidget::getInstance(); - if (this->currentPreviewImage) { - auto pixmap = this->currentPreviewImage->pixmap(); + if (ChannelView::currentPreviewImage) { + auto pixmap = ChannelView::currentPreviewImage->pixmap(); if (pixmap) { tooltipWidget->setImage(*pixmap); } + } else { + tooltipWidget->clearImage(); } this->update(); @@ -1228,10 +1232,9 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event) { auto emoteElement = dynamic_cast(&hoverLayoutElement->getCreator()); if (emoteElement && getSettings()->emotesTooltipPreview.getValue()) { - this->currentPreviewImage = emoteElement->getEmote()->images.getImage(3.0); + ChannelView::currentPreviewImage = emoteElement->getEmote()->images.getImage(3.0); } else { - this->currentPreviewImage = nullptr; - tooltipWidget->clearImage(); + ChannelView::currentPreviewImage = nullptr; } tooltipWidget->moveTo(this, event->globalPos()); diff --git a/src/widgets/helper/ChannelView.hpp b/src/widgets/helper/ChannelView.hpp index 58b296718..7a9a6e31d 100644 --- a/src/widgets/helper/ChannelView.hpp +++ b/src/widgets/helper/ChannelView.hpp @@ -210,7 +210,7 @@ private: static constexpr int leftPadding = 8; static constexpr int scrollbarPadding = 8; - ImagePtr currentPreviewImage = nullptr; + static ImagePtr currentPreviewImage; private slots: void wordFlagsChanged() From 3838157d8221151e38df3fa85b5fc0ea6d3a50f1 Mon Sep 17 00:00:00 2001 From: rexim Date: Wed, 12 Jun 2019 01:03:04 +0700 Subject: [PATCH 14/19] Extract TooltipWidget updating into a separate class --- chatterino.pro | 2 ++ src/singletons/TooltipPreviewImage.cpp | 32 ++++++++++++++++++++++++++ src/singletons/TooltipPreviewImage.hpp | 18 +++++++++++++++ src/widgets/helper/ChannelView.cpp | 18 ++++----------- src/widgets/helper/ChannelView.hpp | 2 -- 5 files changed, 56 insertions(+), 16 deletions(-) create mode 100644 src/singletons/TooltipPreviewImage.cpp create mode 100644 src/singletons/TooltipPreviewImage.hpp diff --git a/chatterino.pro b/chatterino.pro index 41c875862..56517ef3c 100644 --- a/chatterino.pro +++ b/chatterino.pro @@ -139,6 +139,7 @@ SOURCES += \ src/singletons/Toasts.cpp \ src/singletons/Updates.cpp \ src/singletons/WindowManager.cpp \ + src/singletons/TooltipPreviewImage.cpp \ src/util/DebugCount.cpp \ src/util/FormatTime.cpp \ src/util/IncognitoBrowser.cpp \ @@ -301,6 +302,7 @@ HEADERS += \ src/providers/twitch/TwitchServer.hpp \ src/providers/twitch/TwitchUser.hpp \ src/RunGui.hpp \ + src/singletons/TooltipPreviewImage.hpp \ src/singletons/Badges.hpp \ src/singletons/Emotes.hpp \ src/singletons/helper/GifTimer.hpp \ diff --git a/src/singletons/TooltipPreviewImage.cpp b/src/singletons/TooltipPreviewImage.cpp new file mode 100644 index 000000000..b2d0445a4 --- /dev/null +++ b/src/singletons/TooltipPreviewImage.cpp @@ -0,0 +1,32 @@ +#include "TooltipPreviewImage.hpp" + +#include "Application.hpp" +#include "singletons/WindowManager.hpp" +#include "widgets/TooltipWidget.hpp" + +namespace chatterino { + TooltipPreviewImage &TooltipPreviewImage::getInstance() { + static TooltipPreviewImage *instance = new TooltipPreviewImage(); + return *instance; + } + + TooltipPreviewImage::TooltipPreviewImage() { + connections_.push_back(getApp()->windows->gifRepaintRequested.connect( + [&] { + auto tooltipWidget = TooltipWidget::getInstance(); + if (this->image_ && !tooltipWidget->isHidden()) { + auto pixmap = this->image_->pixmap(); + if (pixmap) { + tooltipWidget->setImage(*pixmap); + } + } else { + tooltipWidget->clearImage(); + } + })); + + } + + void TooltipPreviewImage::setImage(ImagePtr image) { + this->image_ = image; + } +} // namespace chatterino diff --git a/src/singletons/TooltipPreviewImage.hpp b/src/singletons/TooltipPreviewImage.hpp new file mode 100644 index 000000000..1d2474e04 --- /dev/null +++ b/src/singletons/TooltipPreviewImage.hpp @@ -0,0 +1,18 @@ +#pragma once + +#include "messages/Image.hpp" + +namespace chatterino { + class TooltipPreviewImage { + public: + static TooltipPreviewImage &getInstance(); + void setImage(ImagePtr image); + + private: + TooltipPreviewImage(); + + private: + ImagePtr image_ = nullptr; + std::vector connections_; + }; +} // namespace chatterino diff --git a/src/widgets/helper/ChannelView.cpp b/src/widgets/helper/ChannelView.cpp index 657c2de0b..61dfbbfbd 100644 --- a/src/widgets/helper/ChannelView.cpp +++ b/src/widgets/helper/ChannelView.cpp @@ -23,6 +23,7 @@ #include "widgets/dialogs/UserInfoPopup.hpp" #include "widgets/helper/EffectLabel.hpp" #include "widgets/splits/Split.hpp" +#include "TooltipPreviewImage.hpp" #include #include @@ -105,8 +106,6 @@ namespace { } } // namespace -ImagePtr ChannelView::currentPreviewImage = nullptr; - ChannelView::ChannelView(BaseWidget *parent) : BaseWidget(parent) , scrollBar_(new Scrollbar(this)) @@ -314,16 +313,6 @@ void ChannelView::queueUpdate() // this->repaint(); - auto tooltipWidget = TooltipWidget::getInstance(); - if (ChannelView::currentPreviewImage) { - auto pixmap = ChannelView::currentPreviewImage->pixmap(); - if (pixmap) { - tooltipWidget->setImage(*pixmap); - } - } else { - tooltipWidget->clearImage(); - } - this->update(); // this->updateTimer.start(); @@ -1230,11 +1219,12 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event) } else { + auto tooltipPreviewImage = TooltipPreviewImage::getInstance(); auto emoteElement = dynamic_cast(&hoverLayoutElement->getCreator()); if (emoteElement && getSettings()->emotesTooltipPreview.getValue()) { - ChannelView::currentPreviewImage = emoteElement->getEmote()->images.getImage(3.0); + tooltipPreviewImage->setImage(emoteElement->getEmote()->images.getImage(3.0)); } else { - ChannelView::currentPreviewImage = nullptr; + tooltipPreviewImage->setImage(nullptr); } tooltipWidget->moveTo(this, event->globalPos()); diff --git a/src/widgets/helper/ChannelView.hpp b/src/widgets/helper/ChannelView.hpp index 7a9a6e31d..b4f33bf71 100644 --- a/src/widgets/helper/ChannelView.hpp +++ b/src/widgets/helper/ChannelView.hpp @@ -210,8 +210,6 @@ private: static constexpr int leftPadding = 8; static constexpr int scrollbarPadding = 8; - static ImagePtr currentPreviewImage; - private slots: void wordFlagsChanged() { From 483e177a39ed1ae24be5c553fa389ec6ca37a0e1 Mon Sep 17 00:00:00 2001 From: rexim Date: Wed, 12 Jun 2019 01:16:56 +0700 Subject: [PATCH 15/19] (#976) Fix compilation errors Which were not visible because of incremental build or something --- src/widgets/helper/ChannelView.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/widgets/helper/ChannelView.cpp b/src/widgets/helper/ChannelView.cpp index 61dfbbfbd..0304ec5bb 100644 --- a/src/widgets/helper/ChannelView.cpp +++ b/src/widgets/helper/ChannelView.cpp @@ -16,6 +16,7 @@ #include "singletons/Settings.hpp" #include "singletons/Theme.hpp" #include "singletons/WindowManager.hpp" +#include "singletons/TooltipPreviewImage.hpp" #include "util/DistanceBetweenPoints.hpp" #include "util/IncognitoBrowser.hpp" #include "widgets/Scrollbar.hpp" @@ -23,7 +24,6 @@ #include "widgets/dialogs/UserInfoPopup.hpp" #include "widgets/helper/EffectLabel.hpp" #include "widgets/splits/Split.hpp" -#include "TooltipPreviewImage.hpp" #include #include @@ -1222,9 +1222,9 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event) auto tooltipPreviewImage = TooltipPreviewImage::getInstance(); auto emoteElement = dynamic_cast(&hoverLayoutElement->getCreator()); if (emoteElement && getSettings()->emotesTooltipPreview.getValue()) { - tooltipPreviewImage->setImage(emoteElement->getEmote()->images.getImage(3.0)); + tooltipPreviewImage.setImage(emoteElement->getEmote()->images.getImage(3.0)); } else { - tooltipPreviewImage->setImage(nullptr); + tooltipPreviewImage.setImage(nullptr); } tooltipWidget->moveTo(this, event->globalPos()); From 244252f61052f3555a90fa01f6b1e87d1e667689 Mon Sep 17 00:00:00 2001 From: rexim Date: Wed, 12 Jun 2019 02:04:57 +0700 Subject: [PATCH 16/19] (#976) Make TooltipPreviewImage non-copyable --- src/singletons/TooltipPreviewImage.hpp | 2 ++ src/widgets/helper/ChannelView.cpp | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/singletons/TooltipPreviewImage.hpp b/src/singletons/TooltipPreviewImage.hpp index 1d2474e04..a56a37888 100644 --- a/src/singletons/TooltipPreviewImage.hpp +++ b/src/singletons/TooltipPreviewImage.hpp @@ -8,6 +8,8 @@ namespace chatterino { static TooltipPreviewImage &getInstance(); void setImage(ImagePtr image); + TooltipPreviewImage(const TooltipPreviewImage&) = delete; + private: TooltipPreviewImage(); diff --git a/src/widgets/helper/ChannelView.cpp b/src/widgets/helper/ChannelView.cpp index 0304ec5bb..9af6a8ca5 100644 --- a/src/widgets/helper/ChannelView.cpp +++ b/src/widgets/helper/ChannelView.cpp @@ -1219,7 +1219,7 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event) } else { - auto tooltipPreviewImage = TooltipPreviewImage::getInstance(); + auto &tooltipPreviewImage = TooltipPreviewImage::getInstance(); auto emoteElement = dynamic_cast(&hoverLayoutElement->getCreator()); if (emoteElement && getSettings()->emotesTooltipPreview.getValue()) { tooltipPreviewImage.setImage(emoteElement->getEmote()->images.getImage(3.0)); From f362548e285504253cabef5486c5f679784e38d7 Mon Sep 17 00:00:00 2001 From: rexim Date: Wed, 12 Jun 2019 02:05:18 +0700 Subject: [PATCH 17/19] (#976) Use int for emotesTooltipPreview --- src/singletons/Settings.hpp | 2 +- src/widgets/settingspages/GeneralPage.cpp | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/singletons/Settings.hpp b/src/singletons/Settings.hpp index 63f5f4f4c..e4b30de67 100644 --- a/src/singletons/Settings.hpp +++ b/src/singletons/Settings.hpp @@ -192,7 +192,7 @@ public: QStringSetting currentVersion = {"/misc/currentVersion", ""}; BoolSetting loadTwitchMessageHistoryOnConnect = { "/misc/twitch/loadMessageHistoryOnConnect", true}; - BoolSetting emotesTooltipPreview = {"/misc/emotesTooltipPreview", false}; + IntSetting emotesTooltipPreview = {"/misc/emotesTooltipPreview", 0}; QStringSetting cachePath = {"/cache/path", ""}; diff --git a/src/widgets/settingspages/GeneralPage.cpp b/src/widgets/settingspages/GeneralPage.cpp index 9cf81a154..914f9eb70 100644 --- a/src/widgets/settingspages/GeneralPage.cpp +++ b/src/widgets/settingspages/GeneralPage.cpp @@ -270,7 +270,12 @@ void GeneralPage::initLayout(SettingsLayout &layout) layout.addCheckbox("Double click links to open", s.linksDoubleClickOnly); layout.addCheckbox("Unshorten links", s.unshortLinks); layout.addCheckbox("Show live indicator in tabs", s.showTabLive); - layout.addCheckbox("Show emote preview in tooltip on hover", s.emotesTooltipPreview); + layout.addDropdown( + "Show emote preview in tooltip on hover", + {"Don't show", "Always show"}, + s.emotesTooltipPreview, + [](int index) { return index; }, + [](auto args) { return args.index; }); layout.addSpacing(16); layout.addSeperator(); From 70bb63d20fc65266c8e5de894f5fff6acd1b5d3d Mon Sep 17 00:00:00 2001 From: apa420 Date: Tue, 11 Jun 2019 22:54:20 +0200 Subject: [PATCH 18/19] Added option for shift, used clang and made setting uneditable --- src/widgets/helper/ChannelView.cpp | 24 ++++++++++++++++++----- src/widgets/settingspages/GeneralPage.cpp | 7 +++---- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/widgets/helper/ChannelView.cpp b/src/widgets/helper/ChannelView.cpp index 9af6a8ca5..36f8dd8ec 100644 --- a/src/widgets/helper/ChannelView.cpp +++ b/src/widgets/helper/ChannelView.cpp @@ -15,8 +15,8 @@ #include "providers/twitch/TwitchServer.hpp" #include "singletons/Settings.hpp" #include "singletons/Theme.hpp" -#include "singletons/WindowManager.hpp" #include "singletons/TooltipPreviewImage.hpp" +#include "singletons/WindowManager.hpp" #include "util/DistanceBetweenPoints.hpp" #include "util/IncognitoBrowser.hpp" #include "widgets/Scrollbar.hpp" @@ -1220,10 +1220,24 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event) else { auto &tooltipPreviewImage = TooltipPreviewImage::getInstance(); - auto emoteElement = dynamic_cast(&hoverLayoutElement->getCreator()); - if (emoteElement && getSettings()->emotesTooltipPreview.getValue()) { - tooltipPreviewImage.setImage(emoteElement->getEmote()->images.getImage(3.0)); - } else { + auto emoteElement = dynamic_cast( + &hoverLayoutElement->getCreator()); + + if (emoteElement && getSettings()->emotesTooltipPreview.getValue()) + { + if (event->modifiers() == Qt::ShiftModifier || + getSettings()->emotesTooltipPreview.getValue() == 1) + { + tooltipPreviewImage.setImage( + emoteElement->getEmote()->images.getImage(3.0)); + } + else + { + tooltipPreviewImage.setImage(nullptr); + } + } + else + { tooltipPreviewImage.setImage(nullptr); } diff --git a/src/widgets/settingspages/GeneralPage.cpp b/src/widgets/settingspages/GeneralPage.cpp index 914f9eb70..32414a7f9 100644 --- a/src/widgets/settingspages/GeneralPage.cpp +++ b/src/widgets/settingspages/GeneralPage.cpp @@ -272,10 +272,9 @@ void GeneralPage::initLayout(SettingsLayout &layout) layout.addCheckbox("Show live indicator in tabs", s.showTabLive); layout.addDropdown( "Show emote preview in tooltip on hover", - {"Don't show", "Always show"}, - s.emotesTooltipPreview, - [](int index) { return index; }, - [](auto args) { return args.index; }); + {"Don't show", "Always show", "Hold shift"}, s.emotesTooltipPreview, + [](int index) { return index; }, [](auto args) { return args.index; }, + false); layout.addSpacing(16); layout.addSeperator(); From 3226ab6c68c271f396b6a0baf6ff80cab4cc90a6 Mon Sep 17 00:00:00 2001 From: apa420 Date: Wed, 12 Jun 2019 00:31:02 +0200 Subject: [PATCH 19/19] ran clang --- src/singletons/TooltipPreviewImage.cpp | 47 ++++++++++++++------------ src/singletons/TooltipPreviewImage.hpp | 23 +++++++------ 2 files changed, 38 insertions(+), 32 deletions(-) diff --git a/src/singletons/TooltipPreviewImage.cpp b/src/singletons/TooltipPreviewImage.cpp index b2d0445a4..99cd9548b 100644 --- a/src/singletons/TooltipPreviewImage.cpp +++ b/src/singletons/TooltipPreviewImage.cpp @@ -5,28 +5,33 @@ #include "widgets/TooltipWidget.hpp" namespace chatterino { - TooltipPreviewImage &TooltipPreviewImage::getInstance() { - static TooltipPreviewImage *instance = new TooltipPreviewImage(); - return *instance; - } +TooltipPreviewImage &TooltipPreviewImage::getInstance() +{ + static TooltipPreviewImage *instance = new TooltipPreviewImage(); + return *instance; +} - TooltipPreviewImage::TooltipPreviewImage() { - connections_.push_back(getApp()->windows->gifRepaintRequested.connect( - [&] { - auto tooltipWidget = TooltipWidget::getInstance(); - if (this->image_ && !tooltipWidget->isHidden()) { - auto pixmap = this->image_->pixmap(); - if (pixmap) { - tooltipWidget->setImage(*pixmap); - } - } else { - tooltipWidget->clearImage(); +TooltipPreviewImage::TooltipPreviewImage() +{ + connections_.push_back(getApp()->windows->gifRepaintRequested.connect([&] { + auto tooltipWidget = TooltipWidget::getInstance(); + if (this->image_ && !tooltipWidget->isHidden()) + { + auto pixmap = this->image_->pixmap(); + if (pixmap) + { + tooltipWidget->setImage(*pixmap); } - })); + } + else + { + tooltipWidget->clearImage(); + } + })); +} - } - - void TooltipPreviewImage::setImage(ImagePtr image) { - this->image_ = image; - } +void TooltipPreviewImage::setImage(ImagePtr image) +{ + this->image_ = image; +} } // namespace chatterino diff --git a/src/singletons/TooltipPreviewImage.hpp b/src/singletons/TooltipPreviewImage.hpp index a56a37888..67ba9cd95 100644 --- a/src/singletons/TooltipPreviewImage.hpp +++ b/src/singletons/TooltipPreviewImage.hpp @@ -3,18 +3,19 @@ #include "messages/Image.hpp" namespace chatterino { - class TooltipPreviewImage { - public: - static TooltipPreviewImage &getInstance(); - void setImage(ImagePtr image); +class TooltipPreviewImage +{ +public: + static TooltipPreviewImage &getInstance(); + void setImage(ImagePtr image); - TooltipPreviewImage(const TooltipPreviewImage&) = delete; + TooltipPreviewImage(const TooltipPreviewImage &) = delete; - private: - TooltipPreviewImage(); +private: + TooltipPreviewImage(); - private: - ImagePtr image_ = nullptr; - std::vector connections_; - }; +private: + ImagePtr image_ = nullptr; + std::vector connections_; +}; } // namespace chatterino