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/messages/layouts/MessageLayoutElement.hpp b/src/messages/layouts/MessageLayoutElement.hpp index d5e11a0a3..a7214937a 100644 --- a/src/messages/layouts/MessageLayoutElement.hpp +++ b/src/messages/layouts/MessageLayoutElement.hpp @@ -41,6 +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; + const Link &getLink() const; const QString &getText() const; FlagsEnum getFlags() const; diff --git a/src/singletons/Settings.hpp b/src/singletons/Settings.hpp index 0d103cc36..e4b30de67 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}; + IntSetting emotesTooltipPreview = {"/misc/emotesTooltipPreview", 0}; QStringSetting cachePath = {"/cache/path", ""}; diff --git a/src/singletons/TooltipPreviewImage.cpp b/src/singletons/TooltipPreviewImage.cpp new file mode 100644 index 000000000..99cd9548b --- /dev/null +++ b/src/singletons/TooltipPreviewImage.cpp @@ -0,0 +1,37 @@ +#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..67ba9cd95 --- /dev/null +++ b/src/singletons/TooltipPreviewImage.hpp @@ -0,0 +1,21 @@ +#pragma once + +#include "messages/Image.hpp" + +namespace chatterino { +class TooltipPreviewImage +{ +public: + static TooltipPreviewImage &getInstance(); + void setImage(ImagePtr image); + + TooltipPreviewImage(const TooltipPreviewImage &) = delete; + +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 90c0e9b93..36f8dd8ec 100644 --- a/src/widgets/helper/ChannelView.cpp +++ b/src/widgets/helper/ChannelView.cpp @@ -15,6 +15,7 @@ #include "providers/twitch/TwitchServer.hpp" #include "singletons/Settings.hpp" #include "singletons/Theme.hpp" +#include "singletons/TooltipPreviewImage.hpp" #include "singletons/WindowManager.hpp" #include "util/DistanceBetweenPoints.hpp" #include "util/IncognitoBrowser.hpp" @@ -311,6 +312,7 @@ void ChannelView::queueUpdate() // } // this->repaint(); + this->update(); // this->updateTimer.start(); @@ -1217,6 +1219,28 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event) } else { + auto &tooltipPreviewImage = TooltipPreviewImage::getInstance(); + 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); + } + tooltipWidget->moveTo(this, event->globalPos()); tooltipWidget->setWordWrap(isLinkValid); tooltipWidget->setText(tooltip); diff --git a/src/widgets/helper/ChannelView.hpp b/src/widgets/helper/ChannelView.hpp index 70b5fd0b4..b4f33bf71 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/Image.hpp" #include "widgets/BaseWidget.hpp" #include diff --git a/src/widgets/settingspages/GeneralPage.cpp b/src/widgets/settingspages/GeneralPage.cpp index 2df805554..32414a7f9 100644 --- a/src/widgets/settingspages/GeneralPage.cpp +++ b/src/widgets/settingspages/GeneralPage.cpp @@ -270,6 +270,11 @@ 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.addDropdown( + "Show emote preview in tooltip on hover", + {"Don't show", "Always show", "Hold shift"}, s.emotesTooltipPreview, + [](int index) { return index; }, [](auto args) { return args.index; }, + false); layout.addSpacing(16); layout.addSeperator();