+
+// ************************************************************
+// ContentsChatItem
+// ************************************************************
+struct ContentsChatItemPrivate;
+
+//! A ChatItem for the contents column
+class ContentsChatItem : public ChatItem
+{
+ Q_DECLARE_TR_FUNCTIONS(ContentsChatItem)
+
+public:
+ ContentsChatItem(const QPointF &pos, const qreal &width, ChatLine *parent);
+ ~ContentsChatItem() override;
+
+ inline int type() const override { return ChatScene::ContentsChatItemType; }
+
+ inline ChatLineModel::ColumnType column() const override { return ChatLineModel::ContentsColumn; }
+ QFontMetricsF *fontMetrics() const;
+
+ void clearCache() override;
+
+protected:
+ void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
+ void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override;
+ void hoverMoveEvent(QGraphicsSceneHoverEvent *event) override;
+ void handleClick(const QPointF &pos, ChatScene::ClickMode clickMode) override;
+
+ bool hasActiveClickable() const override;
+ std::pair<quint16, quint16> activeClickableRange() const override;
+
+ void addActionsToMenu(QMenu *menu, const QPointF &itemPos) override;
+ virtual void copyLinkToClipboard();
+
+ void initLayout(QTextLayout *layout) const override;
+ void doLayout(QTextLayout *layout) const override;
+ UiStyle::FormatList formatList() const override;
+
+private:
+ class ActionProxy;
+ class WrapColumnFinder;
+
+ mutable ContentsChatItemPrivate *_data;
+ ContentsChatItemPrivate *privateData() const;
+
+ Clickable clickableAt(const QPointF &pos) const;
+
+ void endHoverMode();
+ void showWebPreview(const Clickable &click);
+ void clearWebPreview();
+
+ qreal setGeometryByWidth(qreal w);
+
+ QFontMetricsF *_fontMetrics;
+
+ // we need a receiver for Action signals
+ static ActionProxy _actionProxy;
+
+ friend class ChatLine;
+ friend struct ContentsChatItemPrivate;
+};
+
+
+struct ContentsChatItemPrivate {
+ ContentsChatItem *contentsItem;
+ ClickableList clickables;
+ Clickable currentClickable;
+ Clickable activeClickable;
+
+ ContentsChatItemPrivate(ClickableList c, ContentsChatItem *parent) : contentsItem(parent), clickables(std::move(c)) {}
+};
+
+class ContentsChatItem::WrapColumnFinder
+{
+public:
+ WrapColumnFinder(const ChatItem *parent);
+ ~WrapColumnFinder();
+
+ qint16 nextWrapColumn(qreal width);
+
+private:
+ const ChatItem *item;
+ QTextLayout layout;
+ QTextLine line;
+ ChatLineModel::WrapList wrapList;
+ qint16 wordidx;
+ qint16 lineCount;
+ qreal choppedTrailing;
+};
+
+
+//! Acts as a proxy for Action signals targetted at a ContentsChatItem
+/** Since a ChatItem is not a QObject, hence cannot receive signals, we use a static ActionProxy
+ * as a receiver instead. This avoids having to handle ChatItem actions (e.g. context menu entries)
+ * outside the ChatItem.
+ */
+class ContentsChatItem::ActionProxy : public QObject
+{
+ Q_OBJECT
+
+public slots:
+ inline void copyLinkToClipboard() { item()->copyLinkToClipboard(); }
+
+private:
+ /// Returns the ContentsChatItem that should receive the action event.
+ /** For efficiency reasons, values are not checked for validity. You gotta make sure that you set the data() member
+ * in the Action correctly.
+ * @return The ChatItem from which the sending Action originated
+ */
+ inline ContentsChatItem *item() const
+ {
+ return static_cast<ContentsChatItem *>(qobject_cast<QAction *>(sender())->data().value<void *>());
+ }
+};
+
+
+/*************************************************************************************************/
+
+// Inlines
+
+QRectF ChatItem::boundingRect() const { return _boundingRect; }
+qreal ChatItem::width() const { return _boundingRect.width(); }
+qreal ChatItem::height() const { return _boundingRect.height(); }
+QPointF ChatItem::pos() const { return _boundingRect.topLeft(); }
+qreal ChatItem::x() const { return pos().x(); }
+qreal ChatItem::y() const { return pos().y(); }
+