1 /***************************************************************************
2 * Copyright (C) 2005-2011 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 #ifndef QMLCHATLINE_H_
22 #define QMLCHATLINE_H_
24 #include <QDeclarativeItem>
28 class QAbstractItemModel;
30 #include <QAbstractItemModel>
32 class QmlChatLine : public QDeclarativeItem {
35 Q_PROPERTY(QObject *model READ modelPointer WRITE setModelPointer)
36 Q_PROPERTY(QmlChatLine::RenderData renderData READ renderData WRITE setRenderData)
37 Q_PROPERTY(qreal timestampWidth READ timestampWidth WRITE setTimestampWidth NOTIFY timestampWidthChanged)
38 Q_PROPERTY(qreal senderWidth READ senderWidth WRITE setSenderWidth NOTIFY senderWidthChanged)
39 Q_PROPERTY(qreal contentsWidth READ contentsWidth WRITE setContentsWidth NOTIFY contentsWidthChanged)
40 Q_PROPERTY(qreal columnSpacing READ columnSpacing WRITE setColumnSpacing NOTIFY columnSpacingChanged)
41 Q_PROPERTY(QVariant test READ test WRITE setTest)
51 //! Contains all model data needed to render a QmlChatLine
55 UiStyle::FormatList formats;
57 QBrush selectedBackground;
63 Column &operator[](ColumnType col) {
67 Column const &operator[](ColumnType col) const {
71 RenderData() { messageLabel = 0; isValid = false; }
74 Column _data[NumColumns];
79 QmlChatLine(QDeclarativeItem *parent = 0);
80 virtual ~QmlChatLine();
82 inline QAbstractItemModel *model() const { return _model; }
83 inline QObject *modelPointer() const { return _model; }
84 void setModelPointer(QObject *model) { _model = qobject_cast<QAbstractItemModel *>(model); }
86 inline RenderData renderData() const { return _data; }
87 void setRenderData(const RenderData &data);
89 ColumnLayout *layout() const;
91 inline qreal timestampWidth() const { return _timestampWidth; }
92 void setTimestampWidth(qreal w);
93 inline qreal senderWidth() const { return _senderWidth; }
94 void setSenderWidth(qreal w);
95 inline qreal contentsWidth() const { return _contentsWidth; }
96 void setContentsWidth(qreal w);
97 inline qreal columnSpacing() const { return _columnSpacing; }
98 void setColumnSpacing(qreal s);
100 inline QString text() const { return renderData()[ContentsColumn].text; }
102 void setTest(const QVariant &test) { _test = test; qDebug() << "set test" << test; }
103 QVariant test() const { return _test; }
105 QPointF columnPos(ColumnType colType) const;
106 qreal columnWidth(ColumnType colType) const;
107 QRectF columnBoundingRect(ColumnType colType) const;
109 virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
111 static void registerTypes();
114 void timestampWidthChanged(qreal);
115 void senderWidthChanged(qreal);
116 void contentsWidthChanged(qreal);
117 void columnWidthChanged(ColumnType column);
118 void columnSpacingChanged(qreal);
121 void onClicked(qreal mouseX, qreal mouseY) { qDebug() << "clicked" << mouseX << mouseY; }
122 void onPressed(qreal mouseX, qreal mouseY) { qDebug() << "pressed" << mouseX << mouseY; }
123 void onMousePositionChanged(qreal mouseX, qreal mouseY) { qDebug() << "moved" << mouseX << mouseY; }
128 void onColumnWidthChanged(ColumnType column);
131 QAbstractItemModel *_model;
134 qreal _timestampWidth, _senderWidth, _contentsWidth;
135 qreal _columnSpacing;
139 mutable ColumnLayout *_layout;
142 QDataStream &operator<<(QDataStream &out, const QmlChatLine::RenderData &data);
143 QDataStream &operator>>(QDataStream &in, QmlChatLine::RenderData &data);
145 Q_DECLARE_METATYPE(QmlChatLine::RenderData)
147 class QmlChatLine::ColumnLayout {
149 explicit ColumnLayout(const QmlChatLine *parent);
150 virtual ~ColumnLayout() {}
152 inline const QmlChatLine *chatLine() const { return _parent; }
154 qreal height() const;
155 virtual void prepare();
156 virtual void draw(QPainter *p);
159 const QmlChatLine *_parent;