+// inlines of ChatItem
+QTextLayout *ChatItem::layout() const { return privateData()->layout; }
+ChatItemPrivate *ChatItem::privateData() const { return _data; }
+
+// ************************************************************
+// TimestampChatItem
+// ************************************************************
+
+//! A ChatItem for the timestamp column
+class TimestampChatItem : public ChatItem {
+public:
+ TimestampChatItem(const qreal &width, const qreal &height, QGraphicsItem *parent) : ChatItem(width, height, QPointF(0, 0), parent) {}
+ virtual inline ChatLineModel::ColumnType column() const { return ChatLineModel::TimestampColumn; }
+};
+
+// ************************************************************
+// 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; }
+ virtual inline QTextLayout *createLayout() { return ChatItem::createLayout(QTextOption::WrapAnywhere, Qt::AlignRight); }
+};
+
+// ************************************************************
+// ContentsChatItem
+// ************************************************************
+struct ContentsChatItemPrivate;
+
+//! A ChatItem for the contents column
+class ContentsChatItem : public ChatItem {
+public:
+ ContentsChatItem(const qreal &width, const QPointF &pos, QGraphicsItem *parent);
+
+ inline ChatLineModel::ColumnType column() const { return ChatLineModel::ContentsColumn; }
+
+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 QVector<QTextLayout::FormatRange> additionalFormats() const;
+
+ virtual void updateLayout();
+
+private:
+ struct Clickable;
+ class WrapColumnFinder;
+
+ inline ContentsChatItemPrivate *privateData() const;
+
+ QList<Clickable> findClickables();
+ void endHoverMode();
+
+ // 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;
+
+ inline QFontMetricsF *fontMetrics() const { return _fontMetrics; }
+ QFontMetricsF *_fontMetrics;
+};
+
+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 : ChatItemPrivate {
+ ContentsChatItem *contentsItem;
+ QList<ContentsChatItem::Clickable> clickables;
+ ContentsChatItem::Clickable currentClickable;
+ bool hasDragged;
+
+ ContentsChatItemPrivate(QTextLayout *l, const QList<ContentsChatItem::Clickable> &c, ContentsChatItem *parent) : ChatItemPrivate(l), contentsItem(parent), clickables(c), hasDragged(false), controller(0) {}
+ ~ContentsChatItemPrivate();
+
+ void loadWebPreview(const QString &url, const QRectF &urlRect);
+ void clearPreview();
+
+private:
+ class PreviewController;
+ class PreviewItem;
+ PreviewController *controller;
+};
+
+class ContentsChatItemPrivate::PreviewController : public QObject {
+ Q_OBJECT
+public:
+ PreviewController(ContentsChatItem *contentsItem) : contentsItem(contentsItem), previewItem(0) {}
+ ~PreviewController();
+
+ void loadPage(const QString &url, const QRectF &urlRect);
+
+private slots:
+ void pageLoaded(bool success);
+
+private:
+ ContentsChatItem *contentsItem;
+ ContentsChatItemPrivate::PreviewItem *previewItem;
+
+ QString url;
+};
+
+class QWebView;
+class ContentsChatItemPrivate::PreviewItem : public QGraphicsItem {
+public:
+ PreviewItem(QWebView *webView);
+ virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
+ virtual inline QRectF boundingRect() const { return _boundingRect; }
+
+private:
+ QRectF _boundingRect;
+};
+
+//inlines regarding ContentsChatItemPrivate
+ContentsChatItemPrivate *ContentsChatItem::privateData() const { return (ContentsChatItemPrivate *)ChatItem::privateData(); }
+
+class ContentsChatItem::WrapColumnFinder {
+public:
+ WrapColumnFinder(ChatItem *parent);
+ ~WrapColumnFinder();