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 BRUSHPREVIEW_H
20 #define BRUSHPREVIEW_H
21 
22 #include "../../libclient/brushes/brush.h"
23 #include "../../libclient/core/blendmodes.h"
24 
25 #include <QFrame>
26 
27 #ifdef DESIGNER_PLUGIN
28 #include <QtUiPlugin/QDesignerExportWidget>
29 #else
30 #define QDESIGNER_WIDGET_EXPORT
31 #endif
32 
33 class QMenu;
34 
35 namespace paintcore {
36 	class LayerStack;
37 	class LayerStackPixmapCacheObserver;
38 }
39 
40 namespace widgets {
41 
42 /**
43  * @brief Brush previewing widget
44  */
45 class QDESIGNER_WIDGET_EXPORT BrushPreview : public QFrame {
46 	Q_OBJECT
47 	Q_PROPERTY(PreviewShape previewShape READ previewShape WRITE setPreviewShape)
48 	Q_ENUMS(PreviewShape)
49 public:
50 	enum PreviewShape {Stroke, Line, Rectangle, Ellipse, FloodFill, FloodErase};
51 
52 	explicit BrushPreview(QWidget *parent=nullptr, Qt::WindowFlags f=Qt::WindowFlags());
53 	~BrushPreview();
54 
55 	//! Set preview shape
56 	void setPreviewShape(PreviewShape shape);
57 
previewShape()58 	PreviewShape previewShape() const { return m_shape; }
59 
brushColor()60 	QColor brushColor() const { return m_brush.color(); }
brush()61 	const brushes::ClassicBrush &brush() const { return m_brush; }
62 
63 public slots:
64 	//! Set the brush to preview
65 	void setBrush(const brushes::ClassicBrush& brush);
66 
67 	//! This is used for flood fill preview only
68 	void setFloodFillTolerance(int tolerance);
69 
70 	//! This is used for flood fill preview only
71 	void setFloodFillExpansion(int expansion);
72 
73 	//! This is used for flood fill preview only
74 	void setUnderFill(bool underfill);
75 
76 signals:
77 	void requestColorChange();
78 
79 protected:
80 	void paintEvent(QPaintEvent *event);
81 	void resizeEvent(QResizeEvent *);
82 	void changeEvent(QEvent *);
83 	void mouseDoubleClickEvent(QMouseEvent*);
84 
85 private:
86 	void updatePreview();
87 	void updateBackground();
88 
89 	brushes::ClassicBrush m_brush;
90 
91 	paintcore::LayerStack *m_preview = nullptr;
92 	paintcore::LayerStackPixmapCacheObserver *m_previewCache = nullptr;
93 
94 	QColor m_bg = Qt::white;
95 	PreviewShape m_shape = Stroke;
96 	int m_fillTolerance = 0;
97 	int m_fillExpansion = 0;
98 	bool m_underFill = false;
99 	bool m_needupdate = false;
100 };
101 
102 }
103 
104 #endif
105 
106