Fixed a bug in the new topic widget where no repaint event was triggered if only...
[quassel.git] / src / qtui / chatline-old.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_OLD_H_
22 #define _CHATLINE_OLD_H_
23
24 #include <QtGui>
25
26 #include "util.h"
27 #include "uistyle.h"
28 #include "quasselui.h"
29
30 //FIXME: chatline doku
31 //!\brief Containing the layout and providing the rendering of a single message.
32 /** A ChatLineOld takes a Message object,
33  * formats it (by turning the various message types into a human-readable form and afterwards pumping it through
34  * our Style engine), and stores it as a number of QTextLayouts representing the three fields of a chat line
35  * (timestamp, sender and text). These layouts already include any rendering information such as font,
36  * color, or selected characters. By calling layout(), they can be quickly layouted to fit a given set of field widths.
37  * Afterwards, they can quickly be painted whenever necessary.
38  *
39  * By separating the complex and slow task of interpreting and formatting Message objects (which happens exactly once
40  * per message) from the actual layouting and painting, we gain a lot of speed compared to the standard Qt rendering
41  * functions.
42  */
43 class ChatLineOld : public QObject, public AbstractUiMsg {
44   Q_OBJECT
45
46   public:
47     ChatLineOld(Message message);
48     virtual ~ChatLineOld();
49
50     qreal layout(qreal tsWidth, qreal nickWidth, qreal textWidth);
51     qreal height() const { return hght; }
52     int posToCursor(QPointF pos);
53     void draw(QPainter *p, const QPointF &pos);
54
55     enum SelectionMode { None, Partial, Full };
56     void setSelection(SelectionMode, int start = 0, int end = 0);
57
58     QDateTime timestamp() const;
59     QString sender() const;
60     QString text() const;
61     MsgId msgId() const;
62     BufferInfo bufferInfo() const;
63
64     bool isUrl(int pos) const;
65     QUrl getUrl(int pos) const;
66
67   public slots:
68
69   private:
70     qreal hght;
71     Message msg;
72     qreal tsWidth, senderWidth, textWidth;
73     UiStyle::StyledText styledTimeStamp, styledSender, styledText;
74
75     struct FormatRange {
76       int start;
77       int length;
78       int height;
79       QTextCharFormat format;
80     };
81     struct Word {
82       int start;
83       int length;
84       int trailing;
85       int height;
86     };
87     struct LineLayout {
88       int y;
89       int height;
90       int start;
91       int length;
92     };
93     QVector<int> charPos;
94     QVector<int> charWidths;
95     QVector<int> charHeights;
96     QVector<int> charUrlIdx;
97     QList<FormatRange> tsFormat, senderFormat, textFormat;
98     QList<Word> words;
99     QList<LineLayout> lineLayouts;
100     int minHeight;
101
102     bool isHighlight;
103     SelectionMode selectionMode;
104     int selectionStart, selectionEnd;
105     void formatMsg(Message);
106     void precomputeLine();
107     QList<FormatRange> calcFormatRanges(UiStyle::StyledText, QTextLayout::FormatRange additional = QTextLayout::FormatRange());
108 };
109
110 #endif