1 /***************************************************************************
2 * Copyright (C) 2005-08 by the Quassel Project *
3 * devel@quassel-irc.org *
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. *
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. *
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 ***************************************************************************/
28 #include "quasselui.h"
30 //FIXME: chatline doku
31 //!\brief Containing the layout and providing the rendering of a single message.
32 /** A ChatLine 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.
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
43 class ChatLine : public QObject, public AbstractUiMsg {
47 ChatLine(Message message);
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);
55 enum SelectionMode { None, Partial, Full };
56 void setSelection(SelectionMode, int start = 0, int end = 0);
58 QDateTime timestamp() const;
59 QString sender() const;
62 BufferInfo bufferInfo() const;
64 bool isUrl(int pos) const;
65 QUrl getUrl(int pos) const;
72 qreal tsWidth, senderWidth, textWidth;
73 UiStyle::StyledText styledTimeStamp, styledSender, styledText;
79 QTextCharFormat format;
94 QVector<int> charWidths;
95 QVector<int> charHeights;
96 QVector<int> charUrlIdx;
97 QList<FormatRange> tsFormat, senderFormat, textFormat;
99 QList<LineLayout> lineLayouts;
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());