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>
26 #include <QGraphicsItem>
27 #include <QGraphicsScene>
31 #include "chatlinemodel.h"
32 #include "messagefilter.h"
38 class ColumnHandleItem;
41 class QGraphicsSceneMouseEvent;
43 class ChatScene : public QGraphicsScene {
53 ChatLineType = QGraphicsItem::UserType + 1,
55 TimestampChatItemType,
71 ChatScene(QAbstractItemModel *model, const QString &idString, qreal width, ChatView *parent);
74 inline QAbstractItemModel *model() const { return _model; }
75 inline QString idString() const { return _idString; }
77 int rowByScenePos(qreal y);
78 inline int rowByScenePos(const QPointF &pos) { return rowByScenePos(pos.y()); }
79 ChatLineModel::ColumnType columnByScenePos(qreal x);
80 inline ChatLineModel::ColumnType columnByScenePos(const QPointF &pos) { return columnByScenePos(pos.x()); }
82 ChatView *chatView() const;
83 ChatItem *chatItemAt(const QPointF &pos) const;
85 inline bool isSingleBufferScene() const { return _singleBufferScene; }
86 bool containsBuffer(const BufferId &id) const;
87 inline ChatLine *chatLine(int row) { return (row < _lines.count()) ? _lines[row] : 0; }
89 ColumnHandleItem *firstColumnHandle() const;
90 ColumnHandleItem *secondColumnHandle() const;
92 inline CutoffMode senderCutoffMode() const { return _cutoffMode; }
93 inline void setSenderCutoffMode(CutoffMode mode) { _cutoffMode = mode; }
95 QString selection() const;
96 bool hasSelection() const;
97 bool hasGlobalSelection() const;
98 bool isPosOverSelection(const QPointF &) const;
99 bool isGloballySelecting() const;
100 void initiateDrag(QWidget *source);
102 bool isScrollingAllowed() const;
104 virtual bool event(QEvent *e);
107 void updateForViewport(qreal width, qreal height);
108 void setWidth(qreal width);
110 // these are used by the chatitems to notify the scene and manage selections
111 void setSelectingItem(ChatItem *item);
112 ChatItem *selectingItem() const { return _selectingItem; }
113 void startGlobalSelection(ChatItem *item, const QPointF &itemPos);
114 void clearGlobalSelection();
115 void clearSelection();
116 void selectionToClipboard(QClipboard::Mode = QClipboard::Clipboard);
118 void requestBacklog();
120 void loadWebPreview(ChatItem *parentItem, const QString &url, const QRectF &urlRect);
121 void clearWebPreview(ChatItem *parentItem = 0);
124 void lastLineChanged(QGraphicsItem *item, qreal offset);
125 void layoutChanged(); // indicates changes to the scenerect due to resizing of the contentsitems
126 void mouseMoveWhileSelecting(const QPointF &scenePos);
129 virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent *contextMenuEvent);
130 virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent);
131 virtual void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent);
132 virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent);
133 virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *mouseEvent);
134 virtual void handleClick(Qt::MouseButton button, const QPointF &scenePos);
137 void rowsInserted(const QModelIndex &, int, int);
138 void rowsAboutToBeRemoved(const QModelIndex &, int, int);
141 void firstHandlePositionChanged(qreal xpos);
142 void secondHandlePositionChanged(qreal xpos);
143 void showWebPreviewEvent();
144 void deleteWebPreviewEvent();
145 void showWebPreviewChanged();
150 void setHandleXLimits();
151 void updateSelection(const QPointF &pos);
155 QAbstractItemModel *_model;
156 QList<ChatLine *> _lines;
157 bool _singleBufferScene;
159 // calls to QChatScene::sceneRect() are very expensive. As we manage the scenerect ourselves
160 // we store the size in a member variable.
162 int _firstLineRow; // the first row to display (aka: not a daychange msg)
163 void updateSceneRect(qreal width);
164 inline void updateSceneRect() { updateSceneRect(_sceneRect.width()); }
165 void updateSceneRect(const QRectF &rect);
166 qreal _viewportHeight;
168 ColumnHandleItem *_firstColHandle, *_secondColHandle;
169 qreal _firstColHandlePos, _secondColHandlePos;
170 CutoffMode _cutoffMode;
172 ChatItem *_selectingItem;
173 int _selectionStartCol, _selectionMinCol;
176 int _firstSelectionRow;
180 ClickMode _clickMode;
183 bool _leftButtonPressed;
185 bool _showWebPreview;
188 ChatItem *parentItem;
189 QGraphicsItem *previewItem;
194 WebPreview() : parentItem(0), previewItem(0) {}
196 WebPreview webPreview;