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"
33 #include "qtuisettings.h"
35 ChatLine::ChatLine(int row, QAbstractItemModel *model, QGraphicsItem *parent)
36 : QGraphicsItem(parent),
37 _row(row), // needs to be set before the items
38 _timestampItem(model, this),
39 _senderItem(model, this),
40 _contentsItem(model, this),
46 QModelIndex index = model->index(row, ChatLineModel::ContentsColumn);
47 setHighlighted(model->data(index, MessageModel::FlagsRole).toInt() & Message::Highlight);
50 QRectF ChatLine::boundingRect () const {
51 //return childrenBoundingRect();
52 return QRectF(0, 0, _width, _height);
55 ChatItem &ChatLine::item(ChatLineModel::ColumnType column) {
57 case ChatLineModel::TimestampColumn:
58 return _timestampItem;
59 case ChatLineModel::SenderColumn:
61 case ChatLineModel::ContentsColumn:
64 return *(ChatItem *)0; // provoke an error
68 qreal ChatLine::setGeometry(qreal width) {
70 prepareGeometryChange();
71 QRectF firstColHandleRect = chatScene()->firstColumnHandleRect();
72 QRectF secondColHandleRect = chatScene()->secondColumnHandleRect();
74 _height = _contentsItem.setGeometry(width - secondColHandleRect.right());
75 _timestampItem.setGeometry(firstColHandleRect.left(), _height);
76 _senderItem.setGeometry(secondColHandleRect.left() - firstColHandleRect.right(), _height);
78 _senderItem.setPos(firstColHandleRect.right(), 0);
79 _contentsItem.setPos(secondColHandleRect.right(), 0);
85 void ChatLine::setSelected(bool selected, ChatLineModel::ColumnType minColumn) {
87 quint8 sel = (_selection & 0x80) | 0x40 | minColumn;
88 if(sel != _selection) {
90 for(int i = 0; i < minColumn; i++)
91 item((ChatLineModel::ColumnType)i).clearSelection();
92 for(int i = minColumn; i <= ChatLineModel::ContentsColumn; i++)
93 item((ChatLineModel::ColumnType)i).setFullSelection();
97 quint8 sel = _selection & 0x80;
98 if(sel != _selection) {
100 for(int i = 0; i <= ChatLineModel::ContentsColumn; i++)
101 item((ChatLineModel::ColumnType)i).clearSelection();
107 void ChatLine::setHighlighted(bool highlighted) {
108 if(highlighted) _selection |= 0x80;
109 else _selection &= 0x7f;
113 void ChatLine::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
116 if(_selection & Highlighted) {
117 painter->fillRect(boundingRect(), QBrush(QtUi::style()->highlightColor()));
119 if(_selection & Selected) {
120 qreal left = item((ChatLineModel::ColumnType)(_selection & 0x3f)).x();
121 QRectF selectRect(left, 0, width() - left, height());
122 painter->fillRect(selectRect, QApplication::palette().brush(QPalette::Highlight));
126 const QAbstractItemModel *model_ = model();
127 if(model_ && row() > 0) {
128 QModelIndex prevRowIdx = model_->index(row() - 1, 0);
129 MsgId msgId = model_->data(prevRowIdx, MessageModel::MsgIdRole).value<MsgId>();
130 Message::Flags flags = (Message::Flags)model_->data(model_->index(row(), 0), MessageModel::FlagsRole).toInt();
131 // don't show the marker if we wrote that new line
132 if(!(flags & Message::Self)) {
133 BufferId bufferId = model_->data(prevRowIdx, MessageModel::BufferIdRole).value<BufferId>();
134 if(msgId == Client::networkModel()->lastSeenMsgId(bufferId) && chatScene()->isSingleBufferScene()) {
135 QtUiSettings s("QtUiStyle/Colors");
136 QLinearGradient gradient(0, 0, 0, height());
137 gradient.setColorAt(0, s.value("newMsgMarkerFG", QColor(Qt::red)).value<QColor>());
138 gradient.setColorAt(0.1, Qt::transparent);
139 painter->fillRect(boundingRect(), gradient);