1 /***************************************************************************
2 * Copyright (C) 2005-09 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 MessageFilter *filter() const { return qobject_cast<MessageFilter*>(_model); }
76 inline QString idString() const { return _idString; }
78 int rowByScenePos(qreal y) const;
79 inline int rowByScenePos(const QPointF &pos) const { return rowByScenePos(pos.y()); }
80 ChatLineModel::ColumnType columnByScenePos(qreal x) const ;
81 inline ChatLineModel::ColumnType columnByScenePos(const QPointF &pos) const { return columnByScenePos(pos.x()); }
83 ChatView *chatView() const;
84 ChatItem *chatItemAt(const QPointF &pos) const;
85 inline ChatLine *chatLine(int row) { return (row < _lines.count()) ? _lines[row] : 0; }
87 inline bool isSingleBufferScene() const { return _singleBufferId.isValid(); }
88 inline BufferId singleBufferId() const { return _singleBufferId; }
89 bool containsBuffer(const BufferId &id) const;
91 ColumnHandleItem *firstColumnHandle() const;
92 ColumnHandleItem *secondColumnHandle() const;
94 inline CutoffMode senderCutoffMode() const { return _cutoffMode; }
95 inline void setSenderCutoffMode(CutoffMode mode) { _cutoffMode = mode; }
97 QString selection() const;
98 bool hasSelection() const;
99 bool hasGlobalSelection() const;
100 bool isPosOverSelection(const QPointF &) const;
101 bool isGloballySelecting() const;
102 void initiateDrag(QWidget *source);
104 bool isScrollingAllowed() const;
106 virtual bool event(QEvent *e);
109 void updateForViewport(qreal width, qreal height);
110 void setWidth(qreal width);
111 void layout(int start, int end, qreal width);
113 // these are used by the chatitems to notify the scene and manage selections
114 void setSelectingItem(ChatItem *item);
115 ChatItem *selectingItem() const { return _selectingItem; }
116 void startGlobalSelection(ChatItem *item, const QPointF &itemPos);
117 void clearGlobalSelection();
118 void clearSelection();
119 void selectionToClipboard(QClipboard::Mode = QClipboard::Clipboard);
120 void stringToClipboard(const QString &str, QClipboard::Mode = QClipboard::Clipboard);
122 void requestBacklog();
125 void loadWebPreview(ChatItem *parentItem, const QString &url, const QRectF &urlRect);
126 void clearWebPreview(ChatItem *parentItem = 0);
130 void lastLineChanged(QGraphicsItem *item, qreal offset);
131 void layoutChanged(); // indicates changes to the scenerect due to resizing of the contentsitems
132 void mouseMoveWhileSelecting(const QPointF &scenePos);
135 virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent *contextMenuEvent);
136 virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent);
137 virtual void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent);
138 virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent);
139 virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *mouseEvent);
140 virtual void handleClick(Qt::MouseButton button, const QPointF &scenePos);
143 void rowsInserted(const QModelIndex &, int, int);
144 void rowsAboutToBeRemoved(const QModelIndex &, int, int);
145 void dataChanged(const QModelIndex &, const QModelIndex &);
148 void firstHandlePositionChanged(qreal xpos);
149 void secondHandlePositionChanged(qreal xpos);
151 void webPreviewNextStep();
153 void showWebPreviewChanged();
158 void setHandleXLimits();
159 void updateSelection(const QPointF &pos);
163 QAbstractItemModel *_model;
164 QList<ChatLine *> _lines;
165 BufferId _singleBufferId;
167 // calls to QChatScene::sceneRect() are very expensive. As we manage the scenerect ourselves
168 // we store the size in a member variable.
170 int _firstLineRow; // the first row to display (aka: not a daychange msg)
171 void updateSceneRect(qreal width);
172 inline void updateSceneRect() { updateSceneRect(_sceneRect.width()); }
173 void updateSceneRect(const QRectF &rect);
174 qreal _viewportHeight;
176 ColumnHandleItem *_firstColHandle, *_secondColHandle;
177 qreal _firstColHandlePos, _secondColHandlePos;
178 CutoffMode _cutoffMode;
180 ChatItem *_selectingItem;
181 int _selectionStartCol, _selectionMinCol;
184 int _firstSelectionRow;
188 ClickMode _clickMode;
191 bool _leftButtonPressed;
193 bool _showWebPreview;
204 ChatItem *parentItem;
205 QGraphicsItem *previewItem;
208 PreviewState previewState;
210 WebPreview() : parentItem(0), previewItem(0), previewState(NoPreview) {}
212 WebPreview webPreview;
213 #endif // HAVE_WEBKIT