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 <QGraphicsItem>
26 #include <QGraphicsScene>
30 #include "chatlinemodel.h"
31 #include "messagefilter.h"
37 class ColumnHandleItem;
40 class QGraphicsSceneMouseEvent;
42 class ChatScene : public QGraphicsScene {
52 ChatLineType = QGraphicsItem::UserType + 1,
54 TimestampChatItemType,
70 ChatScene(QAbstractItemModel *model, const QString &idString, qreal width, ChatView *parent);
73 inline QAbstractItemModel *model() const { return _model; }
74 inline QString idString() const { return _idString; }
76 int rowByScenePos(qreal y);
77 inline int rowByScenePos(const QPointF &pos) { return rowByScenePos(pos.y()); }
78 ChatLineModel::ColumnType columnByScenePos(qreal x);
79 inline ChatLineModel::ColumnType columnByScenePos(const QPointF &pos) { return columnByScenePos(pos.x()); }
81 ChatView *chatView() const;
82 ChatItem *chatItemAt(const QPointF &pos) const;
84 inline bool isSingleBufferScene() const { return _singleBufferScene; }
85 bool containsBuffer(const BufferId &id) const;
86 inline ChatLine *chatLine(int row) { return (row < _lines.count()) ? _lines[row] : 0; }
88 ColumnHandleItem *firstColumnHandle() const;
89 ColumnHandleItem *secondColumnHandle() const;
91 inline CutoffMode senderCutoffMode() const { return _cutoffMode; }
92 inline void setSenderCutoffMode(CutoffMode mode) { _cutoffMode = mode; }
94 QString selection() const;
95 inline bool hasGlobalSelection() const { return _selectionStart >= 0; }
96 inline bool isGloballySelecting() const { return _isSelecting; }
97 bool isPosOverSelection(const QPointF &) const;
98 void initiateDrag(QWidget *source);
100 bool isScrollingAllowed() const;
102 virtual bool event(QEvent *e);
105 void updateForViewport(qreal width, qreal height);
106 void setWidth(qreal width);
108 // these are used by the chatitems to notify the scene and manage selections
109 void setSelectingItem(ChatItem *item);
110 ChatItem *selectingItem() const { return _selectingItem; }
111 void startGlobalSelection(ChatItem *item, const QPointF &itemPos);
112 void clearGlobalSelection();
113 void clearSelection();
115 void putToClipboard(const QString &);
117 void requestBacklog();
119 void loadWebPreview(ChatItem *parentItem, const QString &url, const QRectF &urlRect);
120 void clearWebPreview(ChatItem *parentItem = 0);
123 void lastLineChanged(QGraphicsItem *item, qreal offset);
124 void layoutChanged(); // indicates changes to the scenerect due to resizing of the contentsitems
125 void mouseMoveWhileSelecting(const QPointF &scenePos);
128 virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent);
129 virtual void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent);
130 virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent);
131 virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *mouseEvent);
132 virtual void handleClick(Qt::MouseButton button, const QPointF &scenePos);
135 void rowsInserted(const QModelIndex &, int, int);
136 void rowsAboutToBeRemoved(const QModelIndex &, int, int);
139 void firstHandlePositionChanged(qreal xpos);
140 void secondHandlePositionChanged(qreal xpos);
141 void showWebPreviewEvent();
142 void deleteWebPreviewEvent();
143 void showWebPreviewChanged();
148 void setHandleXLimits();
149 void updateSelection(const QPointF &pos);
153 QAbstractItemModel *_model;
154 QList<ChatLine *> _lines;
155 bool _singleBufferScene;
157 // calls to QChatScene::sceneRect() are very expensive. As we manage the scenerect ourselves
158 // we store the size in a member variable.
160 int _firstLineRow; // the first row to display (aka: not a daychange msg)
161 void updateSceneRect(qreal width);
162 inline void updateSceneRect() { updateSceneRect(_sceneRect.width()); }
163 void updateSceneRect(const QRectF &rect);
164 qreal _viewportHeight;
166 ColumnHandleItem *_firstColHandle, *_secondColHandle;
167 qreal _firstColHandlePos, _secondColHandlePos;
168 CutoffMode _cutoffMode;
170 ChatItem *_selectingItem;
171 int _selectionStartCol, _selectionMinCol;
174 int _firstSelectionRow;
178 ClickMode _clickMode;
181 bool _leftButtonPressed;
183 bool _showWebPreview;
186 ChatItem *parentItem;
187 QGraphicsItem *previewItem;
192 WebPreview() : parentItem(0), previewItem(0) {}
194 WebPreview webPreview;