+ // selection stuff, to be called by the scene
+ QString selection() const;
+ void clearSelection();
+ void setFullSelection();
+ void continueSelecting(const QPointF &pos);
+ bool hasSelection() const;
+ bool isPosOverSelection(const QPointF &pos) const;
+
+ QList<QRectF> findWords(const QString &searchWord, Qt::CaseSensitivity caseSensitive);
+
+ virtual void addActionsToMenu(QMenu *menu, const QPointF &itemPos);
+ virtual void handleClick(const QPointF &pos, ChatScene::ClickMode);
+
+ void initLayoutHelper(QTextLayout *layout, QTextOption::WrapMode, Qt::Alignment = Qt::AlignLeft) const;
+
+ //! Remove internally cached data
+ /** This removes e.g. the cached QTextLayout to avoid wasting space for nonvisible ChatLines
+ */
+ virtual void clearCache();
+
+protected:
+ enum SelectionMode {
+ NoSelection,
+ PartialSelection,
+ FullSelection
+ };
+
+ virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
+ virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
+ virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
+ virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *) {}
+ virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *) {}
+ virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *) {}
+
+ QTextLayout *layout() const;
+
+ virtual void initLayout(QTextLayout *layout) const;
+ virtual void doLayout(QTextLayout *) const;
+ virtual UiStyle::FormatList formatList() const;
+
+ void paintBackground(QPainter *);
+ QVector<QTextLayout::FormatRange> selectionFormats() const;
+ virtual QVector<QTextLayout::FormatRange> additionalFormats() const;
+ void overlayFormat(UiStyle::FormatList &fmtList, int start, int end, quint32 overlayFmt) const;
+
+ inline qint16 selectionStart() const { return _selectionStart; }
+ inline void setSelectionStart(qint16 start) { _selectionStart = start; }
+ inline qint16 selectionEnd() const { return _selectionEnd; }
+ inline void setSelectionEnd(qint16 end) { _selectionEnd = end; }
+ inline SelectionMode selectionMode() const { return _selectionMode; }
+ inline void setSelectionMode(SelectionMode mode) { _selectionMode = mode; }
+ void setSelection(SelectionMode mode, qint16 selectionStart, qint16 selectionEnd);
+
+ qint16 posToCursor(const QPointF &pos) const;
+
+ inline void setGeometry(qreal width, qreal height) { clearCache(); _boundingRect.setSize(QSizeF(width, height)); }
+ inline void setHeight(const qreal &height) { clearCache(); _boundingRect.setHeight(height); }
+ inline void setWidth(const qreal &width) { clearCache(); _boundingRect.setWidth(width); }
+ inline void setPos(const QPointF &pos) { _boundingRect.moveTopLeft(pos); }
+
+private:
+ ChatLine *_parent;
+ QRectF _boundingRect;
+
+ SelectionMode _selectionMode;
+ qint16 _selectionStart, _selectionEnd;
+
+ mutable QTextLayout *_cachedLayout;
+
+ // internal selection stuff
+ void setSelection(int start, int length);
+
+ friend class ChatLine;
+};
+
+
+// ************************************************************
+// TimestampChatItem
+// ************************************************************
+
+//! A ChatItem for the timestamp column
+class TimestampChatItem : public ChatItem
+{
+public:
+ TimestampChatItem(const QRectF &boundingRect, ChatLine *parent) : ChatItem(boundingRect, parent) {}
+ virtual inline int type() const { return ChatScene::TimestampChatItemType; }
+ virtual inline ChatLineModel::ColumnType column() const { return ChatLineModel::TimestampColumn; }
+};
+
+
+// ************************************************************
+// SenderChatItem
+// ************************************************************
+//! A ChatItem for the sender column
+class SenderChatItem : public ChatItem
+{
+public:
+ SenderChatItem(const QRectF &boundingRect, ChatLine *parent) : ChatItem(boundingRect, parent) {}
+ virtual inline ChatLineModel::ColumnType column() const { return ChatLineModel::SenderColumn; }
+ virtual void handleClick(const QPointF &pos, ChatScene::ClickMode clickMode);
+
+protected:
+ virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
+ virtual inline int type() const { return ChatScene::SenderChatItemType; }
+ virtual void initLayout(QTextLayout *layout) const;
+};
+
+
+// ************************************************************
+// 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();
+
+ virtual inline int type() const { return ChatScene::ContentsChatItemType; }
+
+ inline ChatLineModel::ColumnType column() const { return ChatLineModel::ContentsColumn; }
+ QFontMetricsF *fontMetrics() const;
+
+ virtual void clearCache();
+
+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();