+// ************************************************************
+// SenderChatItem
+// ************************************************************
+//! A ChatItem for the sender column
+class SenderChatItem : public ChatItem {
+public:
+ SenderChatItem(const qreal &width, const qreal &height, const QPointF &pos, QGraphicsItem *parent) : ChatItem(width, height, pos, parent) {}
+ virtual inline ChatLineModel::ColumnType column() const { return ChatLineModel::SenderColumn; }
+
+protected:
+ virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
+ enum { Type = ChatScene::SenderChatItemType };
+ virtual inline int type() const { return Type; }
+ virtual inline void initLayout(QTextLayout *layout) const {
+ initLayoutHelper(layout, QTextOption::ManualWrap, Qt::AlignRight);
+ doLayout(layout);
+ }
+};
+
+// ************************************************************
+// ContentsChatItem
+// ************************************************************
+struct ContentsChatItemPrivate;
+
+//! A ChatItem for the contents column
+class ContentsChatItem : public ChatItem {
+ Q_DECLARE_TR_FUNCTIONS(ContentsChatItem);
+
+public:
+ ContentsChatItem(const qreal &width, const QPointF &pos, QGraphicsItem *parent);
+ ~ContentsChatItem();
+
+ enum { Type = ChatScene::ContentsChatItemType };
+ virtual inline int type() const { return Type; }
+
+ inline ChatLineModel::ColumnType column() const { return ChatLineModel::ContentsColumn; }
+ QFontMetricsF *fontMetrics() const;
+
+protected:
+ virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
+ virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
+ virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
+ virtual void handleClick(const QPointF &pos, ChatScene::ClickMode clickMode);
+
+ virtual void addActionsToMenu(QMenu *menu, const QPointF &itemPos);
+ virtual void copyLinkToClipboard();
+
+ virtual QVector<QTextLayout::FormatRange> additionalFormats() const;
+
+ virtual inline void initLayout(QTextLayout *layout) const {
+ initLayoutHelper(layout, QTextOption::WrapAnywhere);
+ doLayout(layout);
+ }
+ virtual void doLayout(QTextLayout *layout) const;
+ virtual UiStyle::FormatList formatList() const;
+
+private:
+ struct Clickable;
+ class ActionProxy;
+ class WrapColumnFinder;
+
+ ContentsChatItemPrivate *_data;
+ ContentsChatItemPrivate *privateData() const;
+
+ QList<Clickable> findClickables() const;
+ Clickable clickableAt(const QPointF &pos) const;
+
+ void endHoverMode();
+ void showWebPreview(const Clickable &click);
+ void clearWebPreview();
+
+ qreal setGeometryByWidth(qreal w);
+ friend class ChatLine;
+ friend struct ContentsChatItemPrivate;
+
+ QFontMetricsF *_fontMetrics;
+
+ // we need a receiver for Action signals
+ static ActionProxy _actionProxy;
+};
+
+struct ContentsChatItem::Clickable {
+ // Don't change these enums without also changing the regexps in analyze()!
+ enum Type {
+ Invalid = -1,
+ Url = 0,
+ Channel = 1,
+ Nick = 2
+ };
+
+ Type type;
+ quint16 start;
+ quint16 length;
+
+ inline Clickable() : type(Invalid) {};
+ inline Clickable(Type type_, quint16 start_, quint16 length_) : type(type_), start(start_), length(length_) {};
+ inline bool isValid() const { return type != Invalid; }
+};
+
+struct ContentsChatItemPrivate {
+ ContentsChatItem *contentsItem;
+ QList<ContentsChatItem::Clickable> clickables;
+ ContentsChatItem::Clickable currentClickable;
+ ContentsChatItem::Clickable activeClickable;
+
+ ContentsChatItemPrivate(const QList<ContentsChatItem::Clickable> &c, ContentsChatItem *parent) : contentsItem(parent), clickables(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 *>());
+ }
+};
+
+/*************************************************************************************************/
+
+// Avoid circular include deps
+#include "chatline.h"
+const QAbstractItemModel *ChatItem::model() const { return static_cast<ChatLine *>(parentItem())->model(); }
+int ChatItem::row() const { return static_cast<ChatLine *>(parentItem())->row(); }
+