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 ***************************************************************************/
24 #include <QGraphicsItem>
27 #include "chatlinemodel.h"
28 #include "chatscene.h"
34 class ChatItem : public QGraphicsItem {
37 ChatItem(ChatLineModel::ColumnType column, QAbstractItemModel *, QGraphicsItem *parent);
41 inline const QAbstractItemModel *model() const { return chatScene() ? chatScene()->model() : 0; }
42 inline int row() const;
43 virtual ChatLineModel::ColumnType column() const = 0;
44 inline ChatScene *chatScene() const { return qobject_cast<ChatScene *>(scene()); }
46 inline QFontMetricsF *fontMetrics() const { return _fontMetrics; }
47 inline QRectF boundingRect() const { return _boundingRect; }
48 inline qreal width() const { return _boundingRect.width(); }
49 inline qreal height() const { return _boundingRect.height(); }
51 inline bool haveLayout() const { return _layoutData != 0 && layout() != 0; }
52 void clearLayoutData();
53 virtual QTextLayout *createLayout(QTextOption::WrapMode, Qt::Alignment = Qt::AlignLeft);
54 virtual void updateLayout();
55 virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
57 virtual QVariant data(int role) const;
60 qreal setGeometry(qreal width, qreal height = -1);
62 // selection stuff, to be called by the scene
63 void clearSelection();
64 void setFullSelection();
65 void continueSelecting(const QPointF &pos);
67 QList<QRectF> findWords(const QString &searchWord, Qt::CaseSensitivity caseSensitive);
70 virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
71 virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
72 virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
73 virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
75 virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
76 virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
77 virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
80 inline QTextLayout *layout() const;
81 void setLayout(QTextLayout *);
82 qint16 posToCursor(const QPointF &pos);
84 virtual qreal computeHeight();
89 // internal selection stuff
90 void setSelection(int start, int length);
92 QFontMetricsF *_fontMetrics;
94 enum SelectionMode { NoSelection, PartialSelection, FullSelection };
95 SelectionMode _selectionMode;
96 qint16 _selectionStart, _selectionEnd;
98 LayoutData *_layoutData;
101 struct ChatItem::LayoutData {
104 LayoutData() { layout = 0; }
105 ~LayoutData() { delete layout; }
108 class TimestampChatItem : public ChatItem {
111 TimestampChatItem(QAbstractItemModel *model, QGraphicsItem *parent) : ChatItem(column(), model, parent) {}
112 inline ChatLineModel::ColumnType column() const { return ChatLineModel::TimestampColumn; }
116 class SenderChatItem : public ChatItem {
119 SenderChatItem(QAbstractItemModel *model, QGraphicsItem *parent) : ChatItem(column(), model, parent) {}
120 inline ChatLineModel::ColumnType column() const { return ChatLineModel::SenderColumn; }
125 class ContentsChatItem : public ChatItem {
128 ContentsChatItem(QAbstractItemModel *model, QGraphicsItem *parent) : ChatItem(column(), model, parent) {}
129 inline ChatLineModel::ColumnType column() const { return ChatLineModel::ContentsColumn; }
134 qreal computeHeight();
136 class WrapColumnFinder;
141 class ContentsChatItem::WrapColumnFinder {
143 WrapColumnFinder(ChatItem *parent);
146 qint16 nextWrapColumn();
152 ChatLineModel::WrapList wrapList;
159 #include "chatline.h"
160 inline int ChatItem::row() const { return static_cast<ChatLine *>(parentItem())->row(); }
161 inline QTextLayout *ChatItem::layout() const { return _layoutData->layout; }