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) const;
78 inline int rowByScenePos(const QPointF &pos) const { return rowByScenePos(pos.y()); }
79 ChatLineModel::ColumnType columnByScenePos(qreal x) const ;
80 inline ChatLineModel::ColumnType columnByScenePos(const QPointF &pos) const { return columnByScenePos(pos.x()); }
82 ChatView *chatView() const;
83 ChatItem *chatItemAt(const QPointF &pos) const;
84 inline ChatLine *chatLine(int row) { return (row < _lines.count()) ? _lines[row] : 0; }
86 inline bool isSingleBufferScene() const { return _singleBufferId.isValid(); }
87 inline BufferId singleBufferId() const { return _singleBufferId; }
88 bool containsBuffer(const BufferId &id) const;
90 ColumnHandleItem *firstColumnHandle() const;
91 ColumnHandleItem *secondColumnHandle() const;
93 inline CutoffMode senderCutoffMode() const { return _cutoffMode; }
94 inline void setSenderCutoffMode(CutoffMode mode) { _cutoffMode = mode; }
96 QString selection() const;
97 bool hasSelection() const;
98 bool hasGlobalSelection() const;
99 bool isPosOverSelection(const QPointF &) const;
100 bool isGloballySelecting() const;
101 void initiateDrag(QWidget *source);
103 bool isScrollingAllowed() const;
105 virtual bool event(QEvent *e);
108 void updateForViewport(qreal width, qreal height);
109 void setWidth(qreal width);
111 // these are used by the chatitems to notify the scene and manage selections
112 void setSelectingItem(ChatItem *item);
113 ChatItem *selectingItem() const { return _selectingItem; }
114 void startGlobalSelection(ChatItem *item, const QPointF &itemPos);
115 void clearGlobalSelection();
116 void clearSelection();
117 void selectionToClipboard(QClipboard::Mode = QClipboard::Clipboard);
118 void stringToClipboard(const QString &str, QClipboard::Mode = QClipboard::Clipboard);
120 void requestBacklog();
122 void loadWebPreview(ChatItem *parentItem, const QString &url, const QRectF &urlRect);
123 void clearWebPreview(ChatItem *parentItem = 0);
126 void lastLineChanged(QGraphicsItem *item, qreal offset);
127 void layoutChanged(); // indicates changes to the scenerect due to resizing of the contentsitems
128 void mouseMoveWhileSelecting(const QPointF &scenePos);
131 virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent *contextMenuEvent);
132 virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent);
133 virtual void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent);
134 virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent);
135 virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *mouseEvent);
136 virtual void handleClick(Qt::MouseButton button, const QPointF &scenePos);
139 void rowsInserted(const QModelIndex &, int, int);
140 void rowsAboutToBeRemoved(const QModelIndex &, int, int);
143 void firstHandlePositionChanged(qreal xpos);
144 void secondHandlePositionChanged(qreal xpos);
145 void showWebPreviewEvent();
146 void deleteWebPreviewEvent();
147 void showWebPreviewChanged();
152 void setHandleXLimits();
153 void updateSelection(const QPointF &pos);
157 QAbstractItemModel *_model;
158 QList<ChatLine *> _lines;
159 BufferId _singleBufferId;
161 // calls to QChatScene::sceneRect() are very expensive. As we manage the scenerect ourselves
162 // we store the size in a member variable.
164 int _firstLineRow; // the first row to display (aka: not a daychange msg)
165 void updateSceneRect(qreal width);
166 inline void updateSceneRect() { updateSceneRect(_sceneRect.width()); }
167 void updateSceneRect(const QRectF &rect);
168 qreal _viewportHeight;
170 ColumnHandleItem *_firstColHandle, *_secondColHandle;
171 qreal _firstColHandlePos, _secondColHandlePos;
172 CutoffMode _cutoffMode;
174 ChatItem *_selectingItem;
175 int _selectionStartCol, _selectionMinCol;
178 int _firstSelectionRow;
182 ClickMode _clickMode;
185 bool _leftButtonPressed;
187 bool _showWebPreview;
190 ChatItem *parentItem;
191 QGraphicsItem *previewItem;
196 WebPreview() : parentItem(0), previewItem(0) {}
198 WebPreview webPreview;