Revamping ChatView/ChatScene's mouse handling
[quassel.git] / src / qtui / chatitem.h
index 3ed2cee..6c08003 100644 (file)
@@ -52,16 +52,23 @@ 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<QRectF> findWords(const QString &searchWord, Qt::CaseSensitivity caseSensitive);
 
+  virtual void handleClick(const QPointF &pos, ChatScene::ClickMode);
+
 protected:
   virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
   virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
@@ -69,8 +76,10 @@ 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);
+
+  qint16 posToCursor(const QPointF &pos) const;
 
   inline bool hasPrivateData() const { return (bool)_data; }
   ChatItemPrivate *privateData() const;
@@ -124,6 +133,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; }
 };
 
@@ -137,7 +148,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)); }
 };
 
 // ************************************************************
@@ -150,6 +164,9 @@ 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; }
 
@@ -159,6 +176,9 @@ 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;
 
@@ -207,7 +227,8 @@ struct ContentsChatItemPrivate : ChatItemPrivate {
   ContentsChatItem::Clickable currentClickable;
   bool hasDragged;
 
-  ContentsChatItemPrivate(QTextLayout *l, const QList<ContentsChatItem::Clickable> &c, ContentsChatItem *parent) : ChatItemPrivate(l), contentsItem(parent), clickables(c), hasDragged(false) {}
+  ContentsChatItemPrivate(QTextLayout *l, const QList<ContentsChatItem::Clickable> &c, ContentsChatItem *parent)
+  : ChatItemPrivate(l), contentsItem(parent), clickables(c), hasDragged(false) {}
 };
 
 //inlines regarding ContentsChatItemPrivate