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"
31 #include "networkmodel.h"
34 ChatLine::ChatLine(int row, QAbstractItemModel *model, QGraphicsItem *parent)
35 : QGraphicsItem(parent),
36 _row(row), // needs to be set before the items
37 _timestampItem(ChatLineModel::TimestampColumn, model, this),
38 _senderItem(ChatLineModel::SenderColumn, model, this),
39 _contentsItem(ChatLineModel::ContentsColumn, model, this),
45 QModelIndex index = model->index(row, ChatLineModel::ContentsColumn);
46 setHighlighted(model->data(index, MessageModel::FlagsRole).toInt() & Message::Highlight);
49 QRectF ChatLine::boundingRect () const {
50 //return childrenBoundingRect();
51 return QRectF(0, 0, _width, _height);
54 ChatItem &ChatLine::item(ChatLineModel::ColumnType column) {
56 case ChatLineModel::TimestampColumn:
57 return _timestampItem;
58 case ChatLineModel::SenderColumn:
60 case ChatLineModel::ContentsColumn:
63 return *(ChatItem *)0; // provoke an error
67 qreal ChatLine::setGeometry(qreal width, qreal firstHandlePos, qreal secondHandlePos) {
69 prepareGeometryChange();
70 qreal firstsep = QtUi::style()->firstColumnSeparator()/2;
71 qreal secondsep = QtUi::style()->secondColumnSeparator()/2;
73 _timestampItem.setWidth(firstHandlePos - firstsep);
74 _senderItem.setWidth(secondHandlePos - firstHandlePos - (firstsep+secondsep));
75 _height = _contentsItem.setWidth(width - secondHandlePos - secondsep);
77 _senderItem.setPos(firstHandlePos + firstsep, 0);
78 _contentsItem.setPos(secondHandlePos + secondsep, 0);
84 void ChatLine::setSelected(bool selected, ChatLineModel::ColumnType minColumn) {
86 quint8 sel = (_selection & 0x80) | 0x40 | minColumn;
87 if(sel != _selection) {
89 for(int i = 0; i < minColumn; i++)
90 item((ChatLineModel::ColumnType)i).clearSelection();
91 for(int i = minColumn; i <= ChatLineModel::ContentsColumn; i++)
92 item((ChatLineModel::ColumnType)i).setFullSelection();
96 quint8 sel = _selection & 0x80;
97 if(sel != _selection) {
99 for(int i = 0; i <= ChatLineModel::ContentsColumn; i++)
100 item((ChatLineModel::ColumnType)i).clearSelection();
106 void ChatLine::setHighlighted(bool highlighted) {
107 if(highlighted) _selection |= 0x80;
108 else _selection &= 0x7f;
112 void ChatLine::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
113 if(_selection & Highlighted) {
114 painter->fillRect(boundingRect(), QBrush(QtUi::style()->highlightColor()));
116 if(_selection & Selected) {
117 qreal left = item((ChatLineModel::ColumnType)(_selection & 0x3f)).x();
118 QRectF selectRect(left, 0, width() - left, height());
119 painter->fillRect(selectRect, QApplication::palette().brush(QPalette::Highlight));
122 const QAbstractItemModel *model_ = model();
123 if(model_ && row() > 0) {
124 MsgId msgId = model_->data(model_->index(row() - 1, 0), MessageModel::MsgIdRole).value<MsgId>();
125 BufferId bufferId = model_->data(model_->index(row() - 1, 0), MessageModel::BufferIdRole).value<BufferId>();
126 if(msgId == Client::networkModel()->lastSeenMsgId(bufferId) && chatScene()->isSingleBufferScene()) {
127 QLinearGradient gradient(0, 0, 0, height());
128 gradient.setColorAt(0, Qt::transparent);
129 gradient.setColorAt(1, Qt::red);
130 painter->fillRect(boundingRect(), gradient);