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 <QAbstractItemModel>
25 #include <QGraphicsScene>
29 #include "chatlinemodel.h"
30 #include "columnhandleitem.h"
31 #include "messagefilter.h"
38 class QGraphicsSceneMouseEvent;
40 class ChatScene : public QGraphicsScene {
50 ChatLineType = QGraphicsItem::UserType + 1,
52 TimestampChatItemType,
66 ChatScene(QAbstractItemModel *model, const QString &idString, qreal width, QObject *parent);
69 inline QAbstractItemModel *model() const { return _model; }
70 inline QString idString() const { return _idString; }
72 int rowByScenePos(qreal y);
73 inline int rowByScenePos(const QPointF &pos) { return rowByScenePos(pos.y()); }
74 ChatLineModel::ColumnType columnByScenePos(qreal x);
75 inline ChatLineModel::ColumnType columnByScenePos(const QPointF &pos) { return columnByScenePos(pos.x()); }
76 inline bool isSingleBufferScene() const { return _singleBufferScene; }
77 bool containsBuffer(const BufferId &id) const;
78 inline ChatLine *chatLine(int row) { return (row < _lines.count()) ? _lines[row] : 0; }
80 inline ColumnHandleItem *firstColumnHandle() const { return _firstColHandle; }
81 inline ColumnHandleItem *secondColumnHandle() const { return _secondColHandle; }
83 inline CutoffMode senderCutoffMode() const { return _cutoffMode; }
84 inline void setSenderCutoffMode(CutoffMode mode) { _cutoffMode = mode; }
86 bool isScrollingAllowed() const;
88 virtual bool event(QEvent *e);
91 void updateForViewport(qreal width, qreal height);
92 void setWidth(qreal width);
94 // these are used by the chatitems to notify the scene and manage selections
95 void setSelectingItem(ChatItem *item);
96 ChatItem *selectingItem() const { return _selectingItem; }
97 void startGlobalSelection(ChatItem *item, const QPointF &itemPos);
98 void putToClipboard(const QString &);
100 void requestBacklog();
102 void loadWebPreview(ChatItem *parentItem, const QString &url, const QRectF &urlRect);
103 void clearWebPreview(ChatItem *parentItem = 0);
106 void lastLineChanged(QGraphicsItem *item, qreal offset);
107 void layoutChanged(); // indicates changes to the scenerect due to resizing of the contentsitems
108 void mouseMoveWhileSelecting(const QPointF &scenePos);
111 virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent);
112 virtual void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent);
113 virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent);
114 //virtual bool handleLeftClick(ClickMode mode);
117 void rowsInserted(const QModelIndex &, int, int);
118 void rowsAboutToBeRemoved(const QModelIndex &, int, int);
121 void firstHandlePositionChanged(qreal xpos);
122 void secondHandlePositionChanged(qreal xpos);
123 void showWebPreviewEvent();
124 void deleteWebPreviewEvent();
125 void showWebPreviewChanged();
128 void setHandleXLimits();
129 void updateSelection(const QPointF &pos);
130 QString selectionToString() const;
133 QAbstractItemModel *_model;
134 QList<ChatLine *> _lines;
135 bool _singleBufferScene;
137 // calls to QChatScene::sceneRect() are very expensive. As we manage the scenerect ourselves
138 // we store the size in a member variable.
140 int _firstLineRow; // the first row to display (aka: not a daychange msg)
141 void updateSceneRect(qreal width);
142 inline void updateSceneRect() { updateSceneRect(_sceneRect.width()); }
143 void updateSceneRect(const QRectF &rect);
144 qreal _viewportHeight;
146 ColumnHandleItem *_firstColHandle, *_secondColHandle;
147 qreal _firstColHandlePos, _secondColHandlePos;
148 CutoffMode _cutoffMode;
150 ChatItem *_selectingItem;
151 int _selectionStartCol, _selectionMinCol;
154 int _firstSelectionRow;
157 bool _showWebPreview;
162 ChatItem *parentItem;
163 QGraphicsItem *previewItem;
168 WebPreview() : parentItem(0), previewItem(0) {}
170 WebPreview webPreview;