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(ChatLineModel::TimestampColumn, model, this),
39 _senderItem(ChatLineModel::SenderColumn, model, this),
40 _contentsItem(ChatLineModel::ContentsColumn, 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, qreal firstHandlePos, qreal secondHandlePos) {
70 prepareGeometryChange();
71 qreal firstsep = QtUi::style()->firstColumnSeparator()/2;
72 qreal secondsep = QtUi::style()->secondColumnSeparator()/2;
74 _height = _contentsItem.setGeometry(width - secondHandlePos - secondsep);
75 _timestampItem.setGeometry(firstHandlePos - firstsep, _height);
76 _senderItem.setGeometry(secondHandlePos - firstHandlePos - (firstsep+secondsep), _height);
78 _senderItem.setPos(firstHandlePos + firstsep, 0);
79 _contentsItem.setPos(secondHandlePos + secondsep, 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) {
114 if(_selection & Highlighted) {
115 painter->fillRect(boundingRect(), QBrush(QtUi::style()->highlightColor()));
117 if(_selection & Selected) {
118 qreal left = item((ChatLineModel::ColumnType)(_selection & 0x3f)).x();
119 QRectF selectRect(left, 0, width() - left, height());
120 painter->fillRect(selectRect, QApplication::palette().brush(QPalette::Highlight));
124 const QAbstractItemModel *model_ = model();
125 if(model_ && row() > 0) {
126 QModelIndex prevRowIdx = model_->index(row() - 1, 0);
127 MsgId msgId = model_->data(prevRowIdx, MessageModel::MsgIdRole).value<MsgId>();
128 Message::Flags flags = (Message::Flags)model_->data(model_->index(row(), 0), MessageModel::FlagsRole).toInt();
129 // don't show the marker if we wrote that new line
130 if(!(flags & Message::Self)) {
131 BufferId bufferId = model_->data(prevRowIdx, MessageModel::BufferIdRole).value<BufferId>();
132 if(msgId == Client::networkModel()->lastSeenMsgId(bufferId) && chatScene()->isSingleBufferScene()) {
133 QtUiSettings s("QtUiStyle/Colors");
134 QLinearGradient gradient(0, 0, 0, height());
135 gradient.setColorAt(0, s.value("newMsgMarkerFG", QColor(Qt::red)).value<QColor>());
136 gradient.setColorAt(0.1, Qt::transparent);
137 painter->fillRect(boundingRect(), gradient);