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 ***************************************************************************/
24 #include <QGraphicsItem>
26 #include "chatlinemodel.h"
29 class ChatLine : public QGraphicsItem {
31 ChatLine(int row, QAbstractItemModel *model,
33 const qreal ×tampWidth, const qreal &senderWidth, const qreal &contentsWidth,
34 const QPointF &senderPos, const QPointF &contentsPos,
35 QGraphicsItem *parent = 0);
37 virtual inline QRectF boundingRect () const { return QRectF(0, 0, _width, _height); }
39 inline int row() { return _row; }
40 inline void setRow(int row) { _row = row; }
42 inline const QAbstractItemModel *model() const { return _model; }
43 inline ChatScene *chatScene() const { return qobject_cast<ChatScene *>(scene()); }
45 inline qreal width() const { return _width; }
46 inline qreal height() const { return _height; }
48 ChatItem &item(ChatLineModel::ColumnType);
49 inline ChatItem ×tampItem() { return _timestampItem; }
50 inline ChatItem &senderItem() { return _senderItem; }
51 inline ContentsChatItem &contentsItem() { return _contentsItem; }
53 virtual void paint (QPainter * painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
55 // setColumns and setGeometryByWidth both return height
56 qreal setColumns(const qreal ×tampWidth, const qreal &senderWidth, const qreal &contentsWidth,
57 const QPointF &senderPos, const QPointF &contentsPos);
58 qreal setGeometryByWidth(const qreal &width, const qreal &contentsWidth);
60 void setSelected(bool selected, ChatLineModel::ColumnType minColumn = ChatLineModel::ContentsColumn);
61 void setHighlighted(bool highlighted);
65 QAbstractItemModel *_model;
66 ContentsChatItem _contentsItem;
67 SenderChatItem _senderItem;
68 TimestampChatItem _timestampItem;
69 qreal _width, _height;
71 enum { ItemMask = 0x3f,
75 // _selection[1..0] ... Min Selected Column (See MessageModel::ColumnType)
76 // _selection[5..2] ... reserved for new column types
77 // _selection[6] ...... Selected
78 // _selection[7] ...... Highlighted
79 quint8 _selection; // save space, so we put both the col and the flags into one byte