added context menu to links
[quassel.git] / src / qtui / chatitem.h
index dd926bb..996cb43 100644 (file)
@@ -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);
@@ -71,11 +69,14 @@ protected:
 
   inline QTextLayout *layout() const;
 
+  virtual QTextLayout::FormatRange selectionFormat() const;
   virtual inline QVector<QTextLayout::FormatRange> additionalFormats() const { return QVector<QTextLayout::FormatRange>(); }
+
   qint16 posToCursor(const QPointF &pos);
 
-  inline void setPrivateData(ChatItemPrivate *data) { Q_ASSERT(!_data); _data = data; }
-  inline ChatItemPrivate *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()
@@ -84,8 +85,12 @@ protected:
     _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) {
+    _boundingRect.setHeight(height);
+  }
+  inline void setWidth(const qreal &width) {
+    _boundingRect.setWidth(width);
+  }
 
 private:
   // internal selection stuff
@@ -111,7 +116,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 +137,10 @@ 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 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
+  virtual inline ChatItemPrivate *newPrivateData() { return new ChatItemPrivate(createLayout(QTextOption::ManualWrap, 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);
@@ -153,10 +162,14 @@ protected:
   virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
   virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
   virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
+  virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
+
+
 
   virtual QVector<QTextLayout::FormatRange> additionalFormats() const;
 
-  virtual void updateLayout();
+  virtual void doLayout();
+  virtual inline ChatItemPrivate *newPrivateData();
 
 private:
   struct Clickable;
@@ -164,20 +177,15 @@ private:
 
   inline ContentsChatItemPrivate *privateData() const;
 
-  QList<Clickable> findClickables();
+  QList<Clickable> 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()
-  //  b) calling Chatline::setPos() immediately afterwards
   qreal setGeometryByWidth(qreal w);
   friend class ChatLine;
   friend struct ContentsChatItemPrivate;
 
-  inline QFontMetricsF *fontMetrics() const { return _fontMetrics; }
   QFontMetricsF *_fontMetrics;
 };
 
@@ -205,37 +213,12 @@ struct ContentsChatItemPrivate : ChatItemPrivate {
   ContentsChatItem::Clickable currentClickable;
   bool hasDragged;
 
-#ifndef HAVE_WEBKIT
-  ContentsChatItemPrivate(QTextLayout *l, const QList<ContentsChatItem::Clickable> &c, ContentsChatItem *parent) : ChatItemPrivate(l), contentsItem(parent), clickables(c), hasDragged(false) {}
-#else
-  ContentsChatItemPrivate(QTextLayout *l, const QList<ContentsChatItem::Clickable> &c, ContentsChatItem *parent) : ChatItemPrivate(l), contentsItem(parent), clickables(c), hasDragged(false), previewItem(0) {}
-  ~ContentsChatItemPrivate();
-
-  void loadWebPreview(const QString &url, const QRectF &urlRect);
-  void clearWebPreview();
-
-private:
-  class PreviewItem;
-  PreviewItem *previewItem;
-  QString previewUrl;
-  QRectF previewUrlRect;
-#endif //#ifndef HAVE_WEBKIT
-};
-
-#ifdef HAVE_WEBKIT
-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;
+  ContentsChatItemPrivate(QTextLayout *l, const QList<ContentsChatItem::Clickable> &c, ContentsChatItem *parent)
+  : ChatItemPrivate(l), contentsItem(parent), clickables(c), hasDragged(false) {}
 };
-#endif //#ifdef HAVE_WEBKIT
 
 //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 {