1 /*
2    Drawpile - a collaborative drawing program.
3 
4    Copyright (C) 2006-2014 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 COLORBUTTON_H
20 #define COLORBUTTON_H
21 
22 #include <QToolButton>
23 
24 #ifdef DESIGNER_PLUGIN
25 #include <QtUiPlugin/QDesignerExportWidget>
26 #else
27 #define QDESIGNER_WIDGET_EXPORT
28 #endif
29 
30 namespace widgets {
31 
32 //! A button for selecting a color
33 class QDESIGNER_WIDGET_EXPORT ColorButton : public QToolButton {
34 Q_OBJECT
35 Q_PROPERTY(QColor color READ color WRITE setColor)
36 Q_PROPERTY(bool setAlpha READ alpha WRITE setAlpha)
37 Q_PROPERTY(bool locked READ locked WRITE setLocked)
38 public:
39 	ColorButton(QWidget *parent=nullptr, const QColor& color = Qt::black);
~ColorButton()40 	~ColorButton() {}
41 
42 	//! Get the selected color
color()43 	QColor color() const { return _color; }
44 
45 	//! Allow setting of alpha value
46 	void setAlpha(bool use);
47 
48 	//! Set alpha value?
alpha()49 	bool alpha() const { return _setAlpha; }
50 
51 	//! Lock color changing
setLocked(bool locked)52 	void setLocked(bool locked) { _locked = locked; }
53 
locked()54 	bool locked() const { return _locked; }
55 
56 public slots:
57 	//! Set color selection
58 	void setColor(const QColor& color);
59 
60 signals:
61 	void colorChanged(const QColor& color);
62 
63 private slots:
64 	void selectColor();
65 
66 protected:
67 	void paintEvent(QPaintEvent *);
68 	void dragEnterEvent(QDragEnterEvent *);
69 	void dropEvent(QDropEvent *);
70 
71 private:
72 	QColor _color;
73 	bool _setAlpha;
74 	bool _locked;
75 };
76 
77 }
78 
79 #endif
80