cmake: avoid de-duplication of user's CXXFLAGS
[quassel.git] / src / qtui / chatline.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2019 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 "chatitem.h"
27 #include "chatlinemodel.h"
28 #include "chatscene.h"
29
30 class ChatLine : public QGraphicsItem
31 {
32 public:
33     ChatLine(int row,
34              QAbstractItemModel* model,
35              const qreal& width,
36              const qreal& timestampWidth,
37              const qreal& senderWidth,
38              const qreal& contentsWidth,
39              const QPointF& senderPos,
40              const QPointF& contentsPos,
41              QGraphicsItem* parent = nullptr);
42
43     ~ChatLine() override;
44
45     inline QRectF boundingRect() const override { return {0, 0, _width, _height}; }
46
47     inline QModelIndex index() const { return model()->index(row(), 0); }
48     inline MsgId msgId() const { return index().data(MessageModel::MsgIdRole).value<MsgId>(); }
49     inline Message::Type msgType() const { return (Message::Type)index().data(MessageModel::TypeRole).toInt(); }
50
51     inline int row() const { return _row; }
52     inline void setRow(int row) { _row = row; }
53
54     inline const QAbstractItemModel* model() const { return _model; }
55     inline ChatScene* chatScene() const { return qobject_cast<ChatScene*>(scene()); }
56     inline ChatView* chatView() const { return chatScene() ? chatScene()->chatView() : nullptr; }
57
58     inline qreal width() const { return _width; }
59     inline qreal height() const { return _height; }
60
61     ChatItem* item(ChatLineModel::ColumnType);
62     ChatItem* itemAt(const QPointF& pos);
63     inline ChatItem* timestampItem() { return &_timestampItem; }
64     inline ChatItem* senderItem() { return &_senderItem; }
65     inline ContentsChatItem* contentsItem() { return &_contentsItem; }
66
67     void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = nullptr) override;
68     enum
69     {
70         Type = ChatScene::ChatLineType
71     };
72     inline int type() const override { return Type; }
73
74     // pos is relative to the parent ChatLine
75     void setFirstColumn(const qreal& timestampWidth, const qreal& senderWidth, const QPointF& senderPos);
76     // setSecondColumn and setGeometryByWidth both also relocate the chatline.
77     // the _bottom_ position is passed via linePos. linePos is updated to the top of the chatLine.
78     void setSecondColumn(const qreal& senderWidth, const qreal& contentsWidth, const QPointF& contentsPos, qreal& linePos);
79     void setGeometryByWidth(const qreal& width, const qreal& contentsWidth, qreal& linePos);
80
81     void setSelected(bool selected, ChatLineModel::ColumnType minColumn = ChatLineModel::ContentsColumn);
82     void setHighlighted(bool highlighted);
83
84     void clearCache();
85
86 protected:
87     bool sceneEvent(QEvent* event) override;
88
89     // These need to be relayed to the appropriate ChatItem
90     void mouseMoveEvent(QGraphicsSceneMouseEvent* event) override;
91     void mousePressEvent(QGraphicsSceneMouseEvent* event) override;
92     void mouseReleaseEvent(QGraphicsSceneMouseEvent* event) override;
93     void hoverEnterEvent(QGraphicsSceneHoverEvent* event) override;
94     void hoverLeaveEvent(QGraphicsSceneHoverEvent* event) override;
95     void hoverMoveEvent(QGraphicsSceneHoverEvent* event) override;
96
97     ChatItem* mouseEventTargetItem(const QPointF& pos);
98
99     inline ChatItem* mouseGrabberItem() const { return _mouseGrabberItem; }
100     void setMouseGrabberItem(ChatItem* item);
101
102 private:
103     int _row;
104     QAbstractItemModel* _model;
105     ContentsChatItem _contentsItem;
106     SenderChatItem _senderItem;
107     TimestampChatItem _timestampItem;
108     qreal _width, _height;
109
110     enum
111     {
112         ItemMask = 0x3f,
113         Selected = 0x40,
114         Highlighted = 0x80
115     };
116     // _selection[1..0] ... Min Selected Column (See MessageModel::ColumnType)
117     // _selection[5..2] ... reserved for new column types
118     // _selection[6] ...... Selected
119     // _selection[7] ...... Highlighted
120     quint8 _selection;  // save space, so we put both the col and the flags into one byte
121
122     ChatItem* _mouseGrabberItem;
123     ChatItem* _hoverItem;
124 };
125
126 #endif