Checking in WiP on the MessageModel. More cleanly separated code and compiling of...
[quassel.git] / src / qtui / chatline.h
1 /***************************************************************************
2  *   Copyright (C) 2005-08 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  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20
21 #ifndef _CHATLINE_H_
22 #define _CHATLINE_H_
23
24 #include <QGraphicsItem>
25
26 #include "message.h"
27 #include "quasselui.h"
28 #include "uistyle.h"
29
30 class ChatItem;
31 class ChatLineData;
32
33 /* Concept Ideas
34 * Probably makes sense to have ChatLineData be the AbstractUiMsg instead, if it turns out that creating ChatLineData
35 is the expensive part... In that case, we could have a QHash<MsgId, ChatLineData*> in the Client, and ChatLine just
36 gets a data pointer. This would allow us to share most data between AbstractUiMsgs, and ChatLines themselves could
37 be pretty cheap - that'd be a clean solution for having a monitor buffer, highlight buffer etcpp.
38
39 * ItemLayoutData
40
41 */
42
43 class ChatLine : public QGraphicsItem, public AbstractUiMsg {
44
45   public:
46     ChatLine(Message);
47     virtual ~ChatLine();
48     virtual QString sender() const;
49     virtual QString text() const;
50     virtual MsgId msgId() const;
51     virtual BufferInfo bufferInfo() const;
52     virtual QDateTime timestamp() const;
53
54     virtual QRectF boundingRect () const;
55     virtual void paint (QPainter * painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
56     void layout();
57
58     void setColumnWidths(int tsColWidth, int senderColWidth, int textColWidth);
59
60     void myMousePressEvent ( QGraphicsSceneMouseEvent * event ) { qDebug() << "press"; mousePressEvent(event); }
61
62   protected:
63     bool sceneEvent ( QEvent * event );
64
65   private:
66     UiStyle::StyledText _styledTimestamp, _styledText, _styledSender;
67
68     QDateTime _timestamp;
69     MsgId _msgId;
70
71     ChatItem *_tsItem, *_senderItem, *_textItem;
72     int _tsColWidth, _senderColWidth, _textColWidth;
73 };
74
75 //! This contains the data of a ChatLine, i.e. mainly the styled message contents.
76 /** By separating ChatLine and ChatLineData, ChatLine itself is very small and we can reuse the
77  *  same contents in several ChatLine objects without duplicating data.
78  */
79 class ChatLineData {
80
81   public:
82     ChatLineData(const Message &msg);
83
84     inline UiStyle::StyledText styledSender() const { return _styledSender; }
85     inline UiStyle::StyledText styledTimestamp() const { return _styledTimestamp; }
86     inline UiStyle::StyledText styledText() const { return _styledText; }
87
88     inline QString sender() const { return _styledSender.text; }
89     inline QString text() const { return _styledText.text; }
90     inline QDateTime timestamp() const { return _timestamp; }
91     inline MsgId msgId() const { return _msgId; }
92
93   private:
94     UiStyle::StyledText _styledSender, _styledText, _styledTimestamp;
95     QDateTime _timestamp;
96     MsgId _msgId;
97
98 };
99
100
101 #endif