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);