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 ***************************************************************************/
25 #include "bufferinfo.h"
30 ChatLine::ChatLine(int row, QAbstractItemModel *model, QGraphicsItem *parent)
31 : QGraphicsItem(parent),
32 _row(row), // needs to be set before the items
33 _timestampItem(ChatLineModel::TimestampColumn, model, this),
34 _senderItem(ChatLineModel::SenderColumn, model, this),
35 _contentsItem(ChatLineModel::ContentsColumn, model, this),
41 QModelIndex index = model->index(row, ChatLineModel::ContentsColumn);
42 setHighlighted(model->data(index, MessageModel::FlagsRole).toInt() & Message::Highlight);
45 QRectF ChatLine::boundingRect () const {
46 //return childrenBoundingRect();
47 return QRectF(0, 0, _width, _height);
50 ChatItem &ChatLine::item(ChatLineModel::ColumnType column) {
52 case ChatLineModel::TimestampColumn:
53 return _timestampItem;
54 case ChatLineModel::SenderColumn:
56 case ChatLineModel::ContentsColumn:
59 return *(ChatItem *)0; // provoke an error
63 qreal ChatLine::setGeometry(qreal width, qreal firstHandlePos, qreal secondHandlePos) {
65 prepareGeometryChange();
66 qreal firstsep = QtUi::style()->firstColumnSeparator()/2;
67 qreal secondsep = QtUi::style()->secondColumnSeparator()/2;
69 _timestampItem.setWidth(firstHandlePos - firstsep);
70 _senderItem.setWidth(secondHandlePos - firstHandlePos - (firstsep+secondsep));
71 _height = _contentsItem.setWidth(width - secondHandlePos - secondsep);
73 _senderItem.setPos(firstHandlePos + firstsep, 0);
74 _contentsItem.setPos(secondHandlePos + secondsep, 0);
80 void ChatLine::setSelected(bool selected, ChatLineModel::ColumnType minColumn) {
82 quint8 sel = (_selection & 0x80) | 0x40 | minColumn;
83 if(sel != _selection) {
85 for(int i = 0; i < minColumn; i++)
86 item((ChatLineModel::ColumnType)i).clearSelection();
87 for(int i = minColumn; i <= ChatLineModel::ContentsColumn; i++)
88 item((ChatLineModel::ColumnType)i).setFullSelection();
92 quint8 sel = _selection & 0x80;
93 if(sel != _selection) {
95 for(int i = 0; i <= ChatLineModel::ContentsColumn; i++)
96 item((ChatLineModel::ColumnType)i).clearSelection();
102 void ChatLine::setHighlighted(bool highlighted) {
103 if(highlighted) _selection |= 0x80;
104 else _selection &= 0x7f;
108 void ChatLine::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
109 if(_selection & Highlighted) {
110 painter->fillRect(boundingRect(), QBrush(QtUi::style()->highlightColor()));
112 if(_selection & Selected) {
113 qreal left = item((ChatLineModel::ColumnType)(_selection & 0x3f)).x();
114 QRectF selectRect(left, 0, width() - left, height());
115 painter->fillRect(selectRect, QApplication::palette().brush(QPalette::Highlight));