1 /*
2    Drawpile - a collaborative drawing program.
3 
4    Copyright (C) 2006-2019 Calle Laakkonen
5 
6    Drawpile is free software: you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation, either version 3 of the License, or
9    (at your option) any later version.
10 
11    Drawpile is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15 
16    You should have received a copy of the GNU General Public License
17    along with Drawpile.  If not, see <http://www.gnu.org/licenses/>.
18 */
19 #ifndef CANVAS_SCENE_H
20 #define CANVAS_SCENE_H
21 
22 #include <QGraphicsScene>
23 
24 namespace paintcore {
25 	class LayerStackPixmapCacheObserver;
26 	class LayerStack;
27 	class Brush;
28 }
29 
30 namespace net {
31 	class Client;
32 }
33 
34 class QGraphicsItem;
35 
36 namespace canvas {
37 	class CanvasModel;
38 	class Selection;
39 }
40 
41 //! Drawing board related classes
42 namespace drawingboard {
43 
44 class CanvasItem;
45 class AnnotationState;
46 class AnnotationItem;
47 class SelectionItem;
48 class UserMarkerItem;
49 class LaserTrailItem;
50 
51 /**
52  * @brief The drawing board
53  * The drawing board contains the picture and provides methods
54  * to modify it.
55  */
56 class CanvasScene : public QGraphicsScene
57 {
58 	Q_OBJECT
59 
60 public:
61 	//! Margin around the image to make working near corners easier
62 	static const int MARGIN = 900;
63 
64 	CanvasScene(QObject *parent);
65 	~CanvasScene();
66 
67 	//! Clear and initialize the canvas
68 	void initCanvas(canvas::CanvasModel *model);
69 
70 	//! Is there an image on the drawing board
hasImage()71 	bool hasImage() const { return m_model != nullptr; }
72 
73 	//! Are annotation borders shown?
showAnnotationBorders()74 	bool showAnnotationBorders() const { return _showAnnotationBorders; }
75 
76 	//! Show/hide annotations
77 	void showAnnotations(bool show);
78 
model()79 	canvas::CanvasModel *model() const { return m_model; }
80 
layerStackObserver()81 	paintcore::LayerStackPixmapCacheObserver *layerStackObserver() { return m_layerstackObserver; }
82 
83 public slots:
84 	//! Show annotation borders
85 	void showAnnotationBorders(bool hl);
86 
87 	//! Show/hide remote cursor markers
88 	void showUserMarkers(bool show);
89 
90 	//! Show user names in cursor markers
91 	void showUserNames(bool show);
92 
93 	//! Show layer selection in cursor marker
94 	void showUserLayers(bool show);
95 
96 	//! Show avatars in cursor marker
97 	void showUserAvatars(bool show);
98 
99 	//! Show hide laser pointer trails
100 	void showLaserTrails(bool show);
101 
102 	void activeAnnotationChanged(int id);
103 
104 	//! Reveal the canvas item
105 	void showCanvas();
106 
107 	//! Hide canvas item
108 	void hideCanvas();
109 
110 signals:
111 	//! Canvas size has just changed
112 	void canvasResized(int xoffset, int yoffset, const QSize &oldSize);
113 
114 private slots:
115 	void onSelectionChanged(canvas::Selection *sel);
116 	void handleCanvasResize(int xoffset, int yoffset, const QSize &oldsize);
117 	void advanceUsermarkerAnimation();
118 
119 	void userCursorAdded(const QModelIndex&, int first, int last);
120 	void userCursorRemoved(const QModelIndex&, int first, int last);
121 	void userCursorChanged(const QModelIndex &first, const QModelIndex &last, const QVector<int> &changed);
122 
123 	void annotationsAdded(const QModelIndex&, int first, int last);
124 	void annotationsRemoved(const QModelIndex&, int first, int last);
125 	void annotationsChanged(const QModelIndex &first, const QModelIndex &last, const QVector<int> &changed);
126 	void annotationsReset();
127 
128 	void laserAdded(const QModelIndex&, int first, int last);
129 	void laserRemoved(const QModelIndex&, int first, int last);
130 	void laserChanged(const QModelIndex &first, const QModelIndex &last, const QVector<int> &changed);
131 
132 private:
133 	AnnotationItem *getAnnotationItem(int id);
134 
135 	//! The board contents
136 	paintcore::LayerStackPixmapCacheObserver *m_layerstackObserver;
137 	CanvasItem *m_canvasItem;
138 
139 	canvas::CanvasModel *m_model;
140 
141 	//! Laser pointer trails
142 	QHash<int, LaserTrailItem*> m_lasertrails;
143 
144 	//! Current selection
145 	SelectionItem *m_selection;
146 
147 	//! User markers display remote user cursor positions
148 	QHash<int, UserMarkerItem*> m_usermarkers;
149 
150 	QTimer *_animTickTimer;
151 
152 	bool _showAnnotationBorders;
153 	bool _showAnnotations;
154 	bool m_showUserMarkers;
155 	bool m_showUserNames;
156 	bool m_showUserLayers;
157 	bool m_showUserAvatars;
158 	bool m_showLaserTrails;
159 };
160 
161 }
162 
163 #endif
164 
165