1 /***************************************************************************
2 * Copyright (C) 2005-07 by the Quassel IRC Team *
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"
30 ChatLine::ChatLine(Message msg) : QGraphicsItem(), AbstractUiMsg() {
31 _styledTimestamp = QtUi::style()->styleString(msg.formattedTimestamp());
32 _styledSender = QtUi::style()->styleString(msg.formattedSender());
33 _styledText = QtUi::style()->styleString(msg.formattedText());
35 _timestamp = msg.timestamp();
37 _tsColWidth = _senderColWidth = _textColWidth = 0;
39 option.setWrapMode(QTextOption::NoWrap);
40 _tsItem = new ChatItem(this);
41 _tsItem->setTextOption(option);
42 _tsItem->setText(_styledTimestamp);
44 option.setAlignment(Qt::AlignRight);
45 _senderItem = new ChatItem(this);
46 _senderItem->setTextOption(option);
47 _senderItem->setText(_styledSender);
49 option.setAlignment(Qt::AlignLeft);
50 option.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
51 _textItem = new ChatItem(this);
52 _textItem->setTextOption(option);
53 _textItem->setText(_styledText);
57 ChatLine::~ChatLine() {
61 QString ChatLine::sender() const {
65 QString ChatLine::text() const {
69 MsgId ChatLine::msgId() const {
73 BufferInfo ChatLine::bufferInfo() const {
74 Q_ASSERT(false); // do we actually need this function???
78 QDateTime ChatLine::timestamp() const {
82 QRectF ChatLine::boundingRect () const {
83 return childrenBoundingRect();
86 void ChatLine::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
90 void ChatLine::setColumnWidths(int tsColWidth, int senderColWidth, int textColWidth) {
92 _tsColWidth = tsColWidth;
93 _tsItem->setWidth(tsColWidth);
95 if(senderColWidth >= 0) {
96 _senderColWidth = senderColWidth;
97 _senderItem->setWidth(senderColWidth);
99 if(textColWidth >= 0) {
100 _textColWidth = textColWidth;
101 _textItem->setWidth(textColWidth);
106 void ChatLine::layout() {
107 prepareGeometryChange();
108 _tsItem->setPos(QPointF(0, 0));
109 _senderItem->setPos(QPointF(_tsColWidth + QtUi::style()->sepTsSender(), 0));
110 _textItem->setPos(QPointF(_tsColWidth + QtUi::style()->sepTsSender() + _senderColWidth + QtUi::style()->sepSenderText(), 0));
114 bool ChatLine::sceneEvent ( QEvent * event ) {
115 qDebug() <<(void*)this<< "receiving event";