X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fchatitem.h;h=98056effd754dbf299251aa52d6bffb0eb25e610;hp=5877040cf33b2b914ba1545d6645f65f58d066d5;hb=9ee36f12340682fb2420c3444efb23b5040c4823;hpb=e88a5b5f44c84f3892c120b98e6a376032a32644 diff --git a/src/qtui/chatitem.h b/src/qtui/chatitem.h index 5877040c..98056eff 100644 --- a/src/qtui/chatitem.h +++ b/src/qtui/chatitem.h @@ -52,25 +52,50 @@ public: void clearLayout(); virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); + enum { Type = ChatScene::ChatItemType }; + virtual inline int type() const { return Type; } QVariant data(int role) const; // 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 findWords(const QString &searchWord, Qt::CaseSensitivity caseSensitive); + virtual void handleClick(const QPointF &pos, ChatScene::ClickMode); + protected: + enum SelectionMode { + NoSelection, + PartialSelection, + FullSelection + }; + virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event); virtual void mousePressEvent(QGraphicsSceneMouseEvent *event); virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); + //virtual bool handleClick(ClickMode mode); + inline QTextLayout *layout() const; + virtual QTextLayout::FormatRange selectionFormat() const; virtual inline QVector additionalFormats() const { return QVector(); } - qint16 posToCursor(const QPointF &pos); + + 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 bool hasPrivateData() const { return (bool)_data; } ChatItemPrivate *privateData() const; @@ -80,16 +105,13 @@ protected: // a) calling prepareGeometryChange() immediately before setColumns() // b) calling Chatline::setPos() immediately afterwards inline void setGeometry(qreal width, qreal height) { - prepareGeometryChange(); _boundingRect.setWidth(width); _boundingRect.setHeight(height); } inline void setHeight(const qreal &height) { - prepareGeometryChange(); _boundingRect.setHeight(height); } inline void setWidth(const qreal &width) { - prepareGeometryChange(); _boundingRect.setWidth(width); } @@ -100,7 +122,6 @@ private: ChatItemPrivate *_data; QRectF _boundingRect; - enum SelectionMode { NoSelection, PartialSelection, FullSelection }; SelectionMode _selectionMode; qint16 _selectionStart, _selectionEnd; @@ -127,6 +148,8 @@ ChatItemPrivate *ChatItem::newPrivateData() { return new ChatItemPrivate(createL class TimestampChatItem : public ChatItem { public: TimestampChatItem(const qreal &width, const qreal &height, QGraphicsItem *parent) : ChatItem(width, height, QPointF(0, 0), parent) {} + enum { Type = ChatScene::TimestampChatItemType }; + virtual inline int type() const { return Type; } virtual inline ChatLineModel::ColumnType column() const { return ChatLineModel::TimestampColumn; } }; @@ -140,7 +163,10 @@ public: virtual inline ChatLineModel::ColumnType column() const { return ChatLineModel::SenderColumn; } protected: - virtual inline ChatItemPrivate *newPrivateData() { return new ChatItemPrivate(createLayout(QTextOption::WrapAnywhere, Qt::AlignRight)); } + virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); + enum { Type = ChatScene::SenderChatItemType }; + virtual inline int type() const { return Type; } + virtual inline ChatItemPrivate *newPrivateData() { return new ChatItemPrivate(createLayout(QTextOption::ManualWrap, Qt::AlignRight)); } }; // ************************************************************ @@ -153,15 +179,19 @@ class ContentsChatItem : public ChatItem { public: ContentsChatItem(const qreal &width, const QPointF &pos, QGraphicsItem *parent); + enum { Type = ChatScene::ContentsChatItemType }; + virtual inline int type() const { return Type; } + inline ChatLineModel::ColumnType column() const { return ChatLineModel::ContentsColumn; } inline QFontMetricsF *fontMetrics() const { return _fontMetrics; } protected: virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event); - virtual void mousePressEvent(QGraphicsSceneMouseEvent *event); - virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event); + virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent *event); + + virtual void handleClick(const QPointF &pos, ChatScene::ClickMode clickMode); virtual QVector additionalFormats() const; @@ -179,10 +209,6 @@ private: void showWebPreview(const Clickable &click); void clearWebPreview(); - - // WARNING: setGeometry and setHeight should not be used without either: - // a) calling prepareGeometryChange() immediately before setColumns() - // b) calling Chatline::setPos() immediately afterwards qreal setGeometryByWidth(qreal w); friend class ChatLine; friend struct ContentsChatItemPrivate; @@ -212,13 +238,15 @@ struct ContentsChatItemPrivate : ChatItemPrivate { ContentsChatItem *contentsItem; QList clickables; ContentsChatItem::Clickable currentClickable; - bool hasDragged; - ContentsChatItemPrivate(QTextLayout *l, const QList &c, ContentsChatItem *parent) : ChatItemPrivate(l), contentsItem(parent), clickables(c), hasDragged(false) {} + ContentsChatItemPrivate(QTextLayout *l, const QList &c, ContentsChatItem *parent) + : ChatItemPrivate(l), contentsItem(parent), clickables(c) {} }; //inlines regarding ContentsChatItemPrivate -ChatItemPrivate *ContentsChatItem::newPrivateData() { return new ContentsChatItemPrivate(createLayout(QTextOption::WrapAnywhere), findClickables(), this); } +ChatItemPrivate *ContentsChatItem::newPrivateData() { + return new ContentsChatItemPrivate(createLayout(QTextOption::WrapAnywhere), findClickables(), this); +} ContentsChatItemPrivate *ContentsChatItem::privateData() const { return (ContentsChatItemPrivate *)ChatItem::privateData(); } class ContentsChatItem::WrapColumnFinder {