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"
26 #include "buffersyncer.h"
30 #include "messagemodel.h"
33 ChatLine::ChatLine(int row, QAbstractItemModel *model, QGraphicsItem *parent)
34 : QGraphicsItem(parent),
35 _row(row), // needs to be set before the items
36 _timestampItem(ChatLineModel::TimestampColumn, model, this),
37 _senderItem(ChatLineModel::SenderColumn, model, this),
38 _contentsItem(ChatLineModel::ContentsColumn, model, this),
44 QModelIndex index = model->index(row, ChatLineModel::ContentsColumn);
45 setHighlighted(model->data(index, MessageModel::FlagsRole).toInt() & Message::Highlight);
48 QRectF ChatLine::boundingRect () const {
49 //return childrenBoundingRect();
50 return QRectF(0, 0, _width, _height);
53 ChatItem &ChatLine::item(ChatLineModel::ColumnType column) {
55 case ChatLineModel::TimestampColumn:
56 return _timestampItem;
57 case ChatLineModel::SenderColumn:
59 case ChatLineModel::ContentsColumn:
62 return *(ChatItem *)0; // provoke an error
66 qreal ChatLine::setGeometry(qreal width, qreal firstHandlePos, qreal secondHandlePos) {
68 prepareGeometryChange();
69 qreal firstsep = QtUi::style()->firstColumnSeparator()/2;
70 qreal secondsep = QtUi::style()->secondColumnSeparator()/2;
72 _timestampItem.setWidth(firstHandlePos - firstsep);
73 _senderItem.setWidth(secondHandlePos - firstHandlePos - (firstsep+secondsep));
74 _height = _contentsItem.setWidth(width - secondHandlePos - secondsep);
76 _senderItem.setPos(firstHandlePos + firstsep, 0);
77 _contentsItem.setPos(secondHandlePos + secondsep, 0);
83 void ChatLine::setSelected(bool selected, ChatLineModel::ColumnType minColumn) {
85 quint8 sel = (_selection & 0x80) | 0x40 | minColumn;
86 if(sel != _selection) {
88 for(int i = 0; i < minColumn; i++)
89 item((ChatLineModel::ColumnType)i).clearSelection();
90 for(int i = minColumn; i <= ChatLineModel::ContentsColumn; i++)
91 item((ChatLineModel::ColumnType)i).setFullSelection();
95 quint8 sel = _selection & 0x80;
96 if(sel != _selection) {
98 for(int i = 0; i <= ChatLineModel::ContentsColumn; i++)
99 item((ChatLineModel::ColumnType)i).clearSelection();
105 void ChatLine::setHighlighted(bool highlighted) {
106 if(highlighted) _selection |= 0x80;
107 else _selection &= 0x7f;
111 void ChatLine::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
112 // const QAbstractItemModel *model_ = model();
113 // if(model_ && row() > 0) {
114 // MsgId msgId = model_->data(model_->index(row() - 1, 0), MessageModel::MsgIdRole).value<MsgId>();
115 // BufferId bufferId = model_->data(model_->index(row() - 1, 0), MessageModel::BufferIdRole).value<BufferId>();
116 // qDebug() << msgId;
118 if(_selection & Highlighted) {
119 painter->fillRect(boundingRect(), QBrush(QtUi::style()->highlightColor()));
121 if(_selection & Selected) {
122 qreal left = item((ChatLineModel::ColumnType)(_selection & 0x3f)).x();
123 QRectF selectRect(left, 0, width() - left, height());
124 painter->fillRect(selectRect, QApplication::palette().brush(QPalette::Highlight));