X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fchatitem.h;h=5877040cf33b2b914ba1545d6645f65f58d066d5;hp=31fdd5eec7d8ec59bc1389cb268ecdbecf95ec85;hb=01cfbba296ffa89627284fbbe07cb76d7ff3cc29;hpb=429f2aad1e22ba8410f4ea63471fcfc9887c55aa diff --git a/src/qtui/chatitem.h b/src/qtui/chatitem.h index 31fdd5ee..5877040c 100644 --- a/src/qtui/chatitem.h +++ b/src/qtui/chatitem.h @@ -47,10 +47,8 @@ public: inline qreal width() const { return _boundingRect.width(); } inline qreal height() const { return _boundingRect.height(); } - inline bool hasLayout() const { return (bool)_data; } - QTextLayout *createLayout(QTextOption::WrapMode, Qt::Alignment = Qt::AlignLeft); - virtual inline QTextLayout *createLayout() { return createLayout(QTextOption::WrapAnywhere); } - virtual void updateLayout(); + QTextLayout *createLayout(QTextOption::WrapMode, Qt::Alignment = Qt::AlignLeft) const; + virtual void doLayout(); void clearLayout(); virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); @@ -74,18 +72,26 @@ protected: virtual inline QVector additionalFormats() const { return QVector(); } qint16 posToCursor(const QPointF &pos); - inline void ChatItem::setPrivateData(ChatItemPrivate *data) { Q_ASSERT(!_data); _data = data; } - inline ChatItemPrivate *ChatItem::privateData() const; + inline bool hasPrivateData() const { return (bool)_data; } + ChatItemPrivate *privateData() const; + virtual inline ChatItemPrivate *newPrivateData(); // WARNING: setGeometry and setHeight should not be used without either: // 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) { _boundingRect.setHeight(height); } - inline void setWidth(const qreal &width) { _boundingRect.setWidth(width); } + inline void setHeight(const qreal &height) { + prepareGeometryChange(); + _boundingRect.setHeight(height); + } + inline void setWidth(const qreal &width) { + prepareGeometryChange(); + _boundingRect.setWidth(width); + } private: // internal selection stuff @@ -111,7 +117,7 @@ struct ChatItemPrivate { // inlines of ChatItem QTextLayout *ChatItem::layout() const { return privateData()->layout; } -ChatItemPrivate *ChatItem::privateData() const { return _data; } +ChatItemPrivate *ChatItem::newPrivateData() { return new ChatItemPrivate(createLayout(QTextOption::WrapAnywhere)); } // ************************************************************ // TimestampChatItem @@ -132,7 +138,9 @@ 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; } - virtual inline QTextLayout *createLayout() { return ChatItem::createLayout(QTextOption::WrapAnywhere, Qt::AlignRight); } + +protected: + virtual inline ChatItemPrivate *newPrivateData() { return new ChatItemPrivate(createLayout(QTextOption::WrapAnywhere, Qt::AlignRight)); } }; // ************************************************************ @@ -146,6 +154,7 @@ public: ContentsChatItem(const qreal &width, const QPointF &pos, QGraphicsItem *parent); inline ChatLineModel::ColumnType column() const { return ChatLineModel::ContentsColumn; } + inline QFontMetricsF *fontMetrics() const { return _fontMetrics; } protected: virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event); @@ -156,7 +165,8 @@ protected: virtual QVector additionalFormats() const; - virtual void updateLayout(); + virtual void doLayout(); + virtual inline ChatItemPrivate *newPrivateData(); private: struct Clickable; @@ -164,8 +174,11 @@ private: inline ContentsChatItemPrivate *privateData() const; - QList findClickables(); + QList findClickables() const; void endHoverMode(); + void showWebPreview(const Clickable &click); + void clearWebPreview(); + // WARNING: setGeometry and setHeight should not be used without either: // a) calling prepareGeometryChange() immediately before setColumns() @@ -174,7 +187,6 @@ private: friend class ChatLine; friend struct ContentsChatItemPrivate; - inline QFontMetricsF *fontMetrics() const { return _fontMetrics; } QFontMetricsF *_fontMetrics; }; @@ -197,14 +209,16 @@ struct ContentsChatItem::Clickable { }; struct ContentsChatItemPrivate : ChatItemPrivate { + ContentsChatItem *contentsItem; QList clickables; ContentsChatItem::Clickable currentClickable; bool hasDragged; - ContentsChatItemPrivate(QTextLayout *l, const QList &c) : ChatItemPrivate(l), clickables(c), hasDragged(false) {} + ContentsChatItemPrivate(QTextLayout *l, const QList &c, ContentsChatItem *parent) : ChatItemPrivate(l), contentsItem(parent), clickables(c), hasDragged(false) {} }; //inlines regarding ContentsChatItemPrivate +ChatItemPrivate *ContentsChatItem::newPrivateData() { return new ContentsChatItemPrivate(createLayout(QTextOption::WrapAnywhere), findClickables(), this); } ContentsChatItemPrivate *ContentsChatItem::privateData() const { return (ContentsChatItemPrivate *)ChatItem::privateData(); } class ContentsChatItem::WrapColumnFinder { @@ -222,9 +236,6 @@ private: qint16 wordidx; qint16 lineCount; qreal choppedTrailing; - qint16 lastwrapcol; - qreal lastwrappos; - qreal width; }; /*************************************************************************************************/