Quassel IRC  Pre-Release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
chatline.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2015 by the Quassel Project *
3  * devel@quassel-irc.org *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) version 3. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19  ***************************************************************************/
20 
21 #ifndef CHATLINE_H_
22 #define CHATLINE_H_
23 
24 #include <QGraphicsItem>
25 
26 #include "chatlinemodel.h"
27 #include "chatitem.h"
28 #include "chatscene.h"
29 
30 class ChatLine : public QGraphicsItem
31 {
32 public:
33  ChatLine(int row, QAbstractItemModel *model,
34  const qreal &width,
35  const qreal &timestampWidth, const qreal &senderWidth, const qreal &contentsWidth,
36  const QPointF &senderPos, const QPointF &contentsPos,
37  QGraphicsItem *parent = 0);
38 
39  virtual ~ChatLine();
40 
41  virtual inline QRectF boundingRect() const { return QRectF(0, 0, _width, _height); }
42 
43  inline QModelIndex index() const { return model()->index(row(), 0); }
44  inline MsgId msgId() const { return index().data(MessageModel::MsgIdRole).value<MsgId>(); }
45  inline Message::Type msgType() const { return (Message::Type)index().data(MessageModel::TypeRole).toInt(); }
46 
47  inline int row() const { return _row; }
48  inline void setRow(int row) { _row = row; }
49 
50  inline const QAbstractItemModel *model() const { return _model; }
51  inline ChatScene *chatScene() const { return qobject_cast<ChatScene *>(scene()); }
52  inline ChatView *chatView() const { return chatScene() ? chatScene()->chatView() : 0; }
53 
54  inline qreal width() const { return _width; }
55  inline qreal height() const { return _height; }
56 
58  ChatItem *itemAt(const QPointF &pos);
59  inline ChatItem *timestampItem() { return &_timestampItem; }
60  inline ChatItem *senderItem() { return &_senderItem; }
62 
63  virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
65  virtual inline int type() const { return Type; }
66 
67  // pos is relative to the parent ChatLine
68  void setFirstColumn(const qreal &timestampWidth, const qreal &senderWidth, const QPointF &senderPos);
69  // setSecondColumn and setGeometryByWidth both also relocate the chatline.
70  // the _bottom_ position is passed via linePos. linePos is updated to the top of the chatLine.
71  void setSecondColumn(const qreal &senderWidth, const qreal &contentsWidth, const QPointF &contentsPos, qreal &linePos);
72  void setGeometryByWidth(const qreal &width, const qreal &contentsWidth, qreal &linePos);
73 
75  void setHighlighted(bool highlighted);
76 
77  void clearCache();
78 
79 protected:
80  virtual bool sceneEvent(QEvent *event);
81 
82  // These need to be relayed to the appropriate ChatItem
83  virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
84  virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
85  virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
86  virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
87  virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
88  virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
89 
90  ChatItem *mouseEventTargetItem(const QPointF &pos);
91 
92  inline ChatItem *mouseGrabberItem() const { return _mouseGrabberItem; }
94 
95 private:
96  int _row;
97  QAbstractItemModel *_model;
101  qreal _width, _height;
102 
103  enum { ItemMask = 0x3f,
104  Selected = 0x40,
105  Highlighted = 0x80 };
106  // _selection[1..0] ... Min Selected Column (See MessageModel::ColumnType)
107  // _selection[5..2] ... reserved for new column types
108  // _selection[6] ...... Selected
109  // _selection[7] ...... Highlighted
110  quint8 _selection; // save space, so we put both the col and the flags into one byte
111 
114 };
115 
116 
117 #endif