mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
Get rid of dynamic_cast
This commit is contained in:
parent
cbb1ec2d7a
commit
aa4e7f13e7
3 changed files with 20 additions and 9 deletions
|
@ -296,6 +296,11 @@ int TextLayoutElement::getXFromIndex(int index)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boost::optional<QPixmap> TextLayoutElement::pixmap() const
|
||||||
|
{
|
||||||
|
return boost::none;
|
||||||
|
}
|
||||||
|
|
||||||
// TEXT ICON
|
// TEXT ICON
|
||||||
TextIconLayoutElement::TextIconLayoutElement(MessageElement &creator,
|
TextIconLayoutElement::TextIconLayoutElement(MessageElement &creator,
|
||||||
const QString &_line1,
|
const QString &_line1,
|
||||||
|
@ -373,4 +378,10 @@ int TextIconLayoutElement::getXFromIndex(int index)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boost::optional<QPixmap> TextIconLayoutElement::pixmap() const
|
||||||
|
{
|
||||||
|
return boost::none;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace chatterino
|
} // namespace chatterino
|
||||||
|
|
|
@ -41,6 +41,8 @@ public:
|
||||||
virtual void paintAnimated(QPainter &painter, int yOffset) = 0;
|
virtual void paintAnimated(QPainter &painter, int yOffset) = 0;
|
||||||
virtual int getMouseOverIndex(const QPoint &abs) const = 0;
|
virtual int getMouseOverIndex(const QPoint &abs) const = 0;
|
||||||
virtual int getXFromIndex(int index) = 0;
|
virtual int getXFromIndex(int index) = 0;
|
||||||
|
virtual boost::optional<QPixmap> pixmap() const = 0;
|
||||||
|
|
||||||
const Link &getLink() const;
|
const Link &getLink() const;
|
||||||
const QString &getText() const;
|
const QString &getText() const;
|
||||||
FlagsEnum<MessageElementFlag> getFlags() const;
|
FlagsEnum<MessageElementFlag> getFlags() const;
|
||||||
|
@ -62,8 +64,6 @@ public:
|
||||||
ImageLayoutElement(MessageElement &creator, ImagePtr image,
|
ImageLayoutElement(MessageElement &creator, ImagePtr image,
|
||||||
const QSize &size);
|
const QSize &size);
|
||||||
|
|
||||||
boost::optional<QPixmap> pixmap() const;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void addCopyTextToString(QString &str, int from = 0,
|
void addCopyTextToString(QString &str, int from = 0,
|
||||||
int to = INT_MAX) const override;
|
int to = INT_MAX) const override;
|
||||||
|
@ -72,6 +72,7 @@ protected:
|
||||||
void paintAnimated(QPainter &painter, int yOffset) override;
|
void paintAnimated(QPainter &painter, int yOffset) override;
|
||||||
int getMouseOverIndex(const QPoint &abs) const override;
|
int getMouseOverIndex(const QPoint &abs) const override;
|
||||||
int getXFromIndex(int index) override;
|
int getXFromIndex(int index) override;
|
||||||
|
boost::optional<QPixmap> pixmap() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ImagePtr image_;
|
ImagePtr image_;
|
||||||
|
@ -95,6 +96,7 @@ protected:
|
||||||
void paintAnimated(QPainter &painter, int yOffset) override;
|
void paintAnimated(QPainter &painter, int yOffset) override;
|
||||||
int getMouseOverIndex(const QPoint &abs) const override;
|
int getMouseOverIndex(const QPoint &abs) const override;
|
||||||
int getXFromIndex(int index) override;
|
int getXFromIndex(int index) override;
|
||||||
|
boost::optional<QPixmap> pixmap() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QColor color_;
|
QColor color_;
|
||||||
|
@ -120,6 +122,7 @@ protected:
|
||||||
void paintAnimated(QPainter &painter, int yOffset) override;
|
void paintAnimated(QPainter &painter, int yOffset) override;
|
||||||
int getMouseOverIndex(const QPoint &abs) const override;
|
int getMouseOverIndex(const QPoint &abs) const override;
|
||||||
int getXFromIndex(int index) override;
|
int getXFromIndex(int index) override;
|
||||||
|
boost::optional<QPixmap> pixmap() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
float scale;
|
float scale;
|
||||||
|
|
|
@ -1217,12 +1217,9 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto imageLayoutElement =
|
if (auto pixmap = hoverLayoutElement->pixmap()) {
|
||||||
dynamic_cast<const ImageLayoutElement *>(hoverLayoutElement);
|
|
||||||
|
|
||||||
if (imageLayoutElement && imageLayoutElement->pixmap()) {
|
|
||||||
QBuffer buffer;
|
QBuffer buffer;
|
||||||
imageLayoutElement->pixmap()->save(&buffer, "PNG");
|
pixmap->save(&buffer, "PNG");
|
||||||
|
|
||||||
// FIXME: Image inside of imageLayoutElement is not always the biggest
|
// FIXME: Image inside of imageLayoutElement is not always the biggest
|
||||||
// FIXME: Inject image directly into tooltipWidget without base64 bs
|
// FIXME: Inject image directly into tooltipWidget without base64 bs
|
||||||
|
@ -1232,8 +1229,8 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event)
|
||||||
tooltipWidget->setText(
|
tooltipWidget->setText(
|
||||||
QString("<img src='data:image/png;base64,%1' /><br/>%2x%3<br/>%4")
|
QString("<img src='data:image/png;base64,%1' /><br/>%2x%3<br/>%4")
|
||||||
.arg(QString(buffer.data().toBase64()))
|
.arg(QString(buffer.data().toBase64()))
|
||||||
.arg(imageLayoutElement->pixmap()->width())
|
.arg(pixmap->width())
|
||||||
.arg(imageLayoutElement->pixmap()->height())
|
.arg(pixmap->height())
|
||||||
.arg(tooltip));
|
.arg(tooltip));
|
||||||
} else {
|
} else {
|
||||||
tooltipWidget->setText(tooltip);
|
tooltipWidget->setText(tooltip);
|
||||||
|
|
Loading…
Reference in a new issue