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,
69 ChatScene(QAbstractItemModel *model, const QString &idString, qreal width, ChatView *parent);
72 inline QAbstractItemModel *model() const { return _model; }
73 inline QString idString() const { return _idString; }
75 int rowByScenePos(qreal y);
76 inline int rowByScenePos(const QPointF &pos) { return rowByScenePos(pos.y()); }
77 ChatLineModel::ColumnType columnByScenePos(qreal x);
78 inline ChatLineModel::ColumnType columnByScenePos(const QPointF &pos) { return columnByScenePos(pos.x()); }
80 ChatView *chatView() const;
81 ChatItem *chatItemAt(const QPointF &pos) const;
83 inline bool isSingleBufferScene() const { return _singleBufferScene; }
84 bool containsBuffer(const BufferId &id) const;
85 inline ChatLine *chatLine(int row) { return (row < _lines.count()) ? _lines[row] : 0; }
87 ColumnHandleItem *firstColumnHandle() const;
88 ColumnHandleItem *secondColumnHandle() const;
90 inline CutoffMode senderCutoffMode() const { return _cutoffMode; }
91 inline void setSenderCutoffMode(CutoffMode mode) { _cutoffMode = mode; }
93 QString selection() const;
94 inline bool hasGlobalSelection() const { return _selectionStart >= 0; }
95 inline bool isGloballySelecting() const { return _isSelecting; }
96 bool isPosOverSelection(const QPointF &) const;
97 void initiateDrag(QWidget *source);
99 bool isScrollingAllowed() const;
101 virtual bool event(QEvent *e);
104 void updateForViewport(qreal width, qreal height);
105 void setWidth(qreal width);
107 // these are used by the chatitems to notify the scene and manage selections
108 void setSelectingItem(ChatItem *item);
109 ChatItem *selectingItem() const { return _selectingItem; }
110 void startGlobalSelection(ChatItem *item, const QPointF &itemPos);
111 void clearGlobalSelection();
112 void clearSelection();
114 void putToClipboard(const QString &);
116 void requestBacklog();
118 void loadWebPreview(ChatItem *parentItem, const QString &url, const QRectF &urlRect);
119 void clearWebPreview(ChatItem *parentItem = 0);
122 void lastLineChanged(QGraphicsItem *item, qreal offset);
123 void layoutChanged(); // indicates changes to the scenerect due to resizing of the contentsitems
124 void mouseMoveWhileSelecting(const QPointF &scenePos);
127 virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent);
128 virtual void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent);
129 virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent);
130 virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *mouseEvent);
131 virtual void handleClick(Qt::MouseButton button, const QPointF &scenePos);
134 void rowsInserted(const QModelIndex &, int, int);
135 void rowsAboutToBeRemoved(const QModelIndex &, int, int);
138 void firstHandlePositionChanged(qreal xpos);
139 void secondHandlePositionChanged(qreal xpos);
140 void showWebPreviewEvent();
141 void deleteWebPreviewEvent();
142 void showWebPreviewChanged();
147 void setHandleXLimits();
148 void updateSelection(const QPointF &pos);
152 QAbstractItemModel *_model;
153 QList<ChatLine *> _lines;
154 bool _singleBufferScene;
156 // calls to QChatScene::sceneRect() are very expensive. As we manage the scenerect ourselves
157 // we store the size in a member variable.
159 int _firstLineRow; // the first row to display (aka: not a daychange msg)
160 void updateSceneRect(qreal width);
161 inline void updateSceneRect() { updateSceneRect(_sceneRect.width()); }
162 void updateSceneRect(const QRectF &rect);
163 qreal _viewportHeight;
165 ColumnHandleItem *_firstColHandle, *_secondColHandle;
166 qreal _firstColHandlePos, _secondColHandlePos;
167 CutoffMode _cutoffMode;
169 ChatItem *_selectingItem;
170 int _selectionStartCol, _selectionMinCol;
173 int _firstSelectionRow;
176 bool _showWebPreview;
179 ClickMode _clickMode;
182 bool _leftButtonPressed;
185 ChatItem *parentItem;
186 QGraphicsItem *previewItem;
191 WebPreview() : parentItem(0), previewItem(0) {}
193 WebPreview webPreview;