1 /***************************************************************************
2 * Copyright (C) 2005-09 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 ***************************************************************************/
21 #include "chatlinemodelitem.h"
22 #include "chatlinemodel.h"
24 #include "qtuistyle.h"
26 // ****************************************
27 // the actual ChatLineModelItem
28 // ****************************************
29 ChatLineModelItem::ChatLineModelItem(const Message &msg)
33 if(!msg.sender().contains('!'))
34 _styledMsg.setFlags(msg.flags() |= Message::ServerMsg);
37 QVariant ChatLineModelItem::data(int column, int role) const {
38 if(role == ChatLineModel::MsgLabelRole)
39 return messageLabel();
42 MessageModel::ColumnType col = (MessageModel::ColumnType)column;
44 case ChatLineModel::TimestampColumn:
45 variant = timestampData(role);
47 case ChatLineModel::SenderColumn:
48 variant = senderData(role);
50 case ChatLineModel::ContentsColumn:
51 variant = contentsData(role);
56 if(!variant.isValid())
57 return MessageModelItem::data(column, role);
61 QVariant ChatLineModelItem::timestampData(int role) const {
63 case ChatLineModel::DisplayRole:
64 return _styledMsg.decoratedTimestamp();
65 case ChatLineModel::EditRole:
66 return _styledMsg.timestamp();
67 case ChatLineModel::BackgroundRole:
68 return backgroundBrush(UiStyle::Timestamp);
69 case ChatLineModel::SelectedBackgroundRole:
70 return backgroundBrush(UiStyle::Timestamp, true);
71 case ChatLineModel::FormatRole:
72 return QVariant::fromValue<UiStyle::FormatList>(UiStyle::FormatList()
73 << qMakePair((quint16)0, (quint32)UiStyle::formatType(_styledMsg.type()) | UiStyle::Timestamp));
78 QVariant ChatLineModelItem::senderData(int role) const {
80 case ChatLineModel::DisplayRole:
81 return _styledMsg.decoratedSender();
82 case ChatLineModel::EditRole:
83 return _styledMsg.plainSender();
84 case ChatLineModel::BackgroundRole:
85 return backgroundBrush(UiStyle::Sender);
86 case ChatLineModel::SelectedBackgroundRole:
87 return backgroundBrush(UiStyle::Sender, true);
88 case ChatLineModel::FormatRole:
89 return QVariant::fromValue<UiStyle::FormatList>(UiStyle::FormatList()
90 << qMakePair((quint16)0, (quint32)UiStyle::formatType(_styledMsg.type()) | UiStyle::Sender));
95 QVariant ChatLineModelItem::contentsData(int role) const {
97 case ChatLineModel::DisplayRole:
98 case ChatLineModel::EditRole:
99 return _styledMsg.plainContents();
100 case ChatLineModel::BackgroundRole:
101 return backgroundBrush(UiStyle::Contents);
102 case ChatLineModel::SelectedBackgroundRole:
103 return backgroundBrush(UiStyle::Contents, true);
104 case ChatLineModel::FormatRole:
105 return QVariant::fromValue<UiStyle::FormatList>(_styledMsg.contentsFormatList());
110 quint32 ChatLineModelItem::messageLabel() const {
111 quint32 label = _styledMsg.senderHash() << 16;
112 if(_styledMsg.flags() & Message::Self)
113 label |= UiStyle::OwnMsg;
114 if(_styledMsg.flags() & Message::Highlight)
115 label |= UiStyle::Highlight;
119 QVariant ChatLineModelItem::backgroundBrush(UiStyle::FormatType subelement, bool selected) const {
120 QTextCharFormat fmt = QtUi::style()->format(UiStyle::formatType(_styledMsg.type()) | subelement, messageLabel() | (selected ? UiStyle::Selected : 0));
121 if(fmt.hasProperty(QTextFormat::BackgroundBrush))
122 return QVariant::fromValue<QBrush>(fmt.background());