OK, disabled warnings for the moment :)
[quassel.git] / src / qtui / chatline.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-08 by the Quassel Project                          *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
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.                                           *
9  *                                                                         *
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.                          *
14  *                                                                         *
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  ***************************************************************************/
20
21 #include <QDateTime>
22 #include <QString>
23 #include <QtGui>
24
25 #include "bufferinfo.h"
26 #include "chatitem.h"
27 #include "chatline.h"
28 #include "qtui.h"
29
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());
34   _msgId = msg.msgId();
35   _timestamp = msg.timestamp();
36
37   _tsColWidth = _senderColWidth = _textColWidth = 0;
38   QTextOption option;
39   option.setWrapMode(QTextOption::NoWrap);
40   _tsItem = new ChatItem(this);
41   _tsItem->setTextOption(option);
42   _tsItem->setText(_styledTimestamp);
43
44   option.setAlignment(Qt::AlignRight);
45   _senderItem = new ChatItem(this);
46   _senderItem->setTextOption(option);
47   _senderItem->setText(_styledSender);
48
49   option.setAlignment(Qt::AlignLeft);
50   option.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
51   _textItem = new ChatItem(this);
52   _textItem->setTextOption(option);
53   _textItem->setText(_styledText);
54
55 }
56
57 ChatLine::~ChatLine() {
58   
59 }
60
61 QString ChatLine::sender() const {
62   return QString();
63 }
64
65 QString ChatLine::text() const {
66   return QString();
67 }
68
69 MsgId ChatLine::msgId() const {
70   return 0;
71 }
72
73 BufferInfo ChatLine::bufferInfo() const {
74   Q_ASSERT(false); // do we actually need this function???
75   return BufferInfo();
76 }
77
78 QDateTime ChatLine::timestamp() const {
79   return QDateTime();
80 }
81
82 QRectF ChatLine::boundingRect () const {
83   return childrenBoundingRect();
84 }
85
86 void ChatLine::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
87
88 }
89
90 void ChatLine::setColumnWidths(int tsColWidth, int senderColWidth, int textColWidth) {
91   if(tsColWidth >= 0) {
92     _tsColWidth = tsColWidth;
93     _tsItem->setWidth(tsColWidth);
94   }
95   if(senderColWidth >= 0) {
96     _senderColWidth = senderColWidth;
97     _senderItem->setWidth(senderColWidth);
98   }
99   if(textColWidth >= 0) {
100     _textColWidth = textColWidth;
101     _textItem->setWidth(textColWidth);
102   }
103   layout();
104 }
105
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));
111 }
112
113
114 bool ChatLine::sceneEvent ( QEvent * event ) {
115   qDebug() <<(void*)this<< "receiving event";
116   event->ignore();
117   return false;
118 }
119
120