1 /*
2    Drawpile - a collaborative drawing program.
3 
4    Copyright (C) 2015-2017 Calle Laakkonen, GroupedToolButton based on Gwenview's StatusBarToolbutton by Aurélien Gâteau
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 
20 #ifndef STATUSBARTOOLBUTTON_H
21 #define STATUSBARTOOLBUTTON_H
22 
23 #include <QToolButton>
24 
25 #ifdef DESIGNER_PLUGIN
26 #include <QtUiPlugin/QDesignerExportWidget>
27 #else
28 #define QDESIGNER_WIDGET_EXPORT
29 #endif
30 
31 namespace widgets {
32 
33 /**
34  * A thin tool button which can be grouped with another and look like one solid
35  * bar:
36  *
37  * ( button1 | button2 )
38  *
39  * New Drawpile specific features:
40  *  - Dropdown arrow if a menu (and text) is attached
41  *  - Color swatch mode
42  */
43 class QDESIGNER_WIDGET_EXPORT GroupedToolButton : public QToolButton
44 {
45 	Q_OBJECT
46 	Q_PROPERTY(GroupPosition groupPosition READ groupPosition WRITE setGroupPosition)
47 	Q_ENUMS(GroupPosition)
48 public:
49 	enum GroupPosition {
50 		NotGrouped = 0,
51 		GroupLeft = 1,
52 		GroupRight = 2,
53 		GroupCenter = 3
54 	};
55 
56 	explicit GroupedToolButton(GroupPosition position, QWidget* parent=0);
57 	explicit GroupedToolButton(QWidget* parent=0);
58 
groupPosition()59 	GroupPosition groupPosition() const { return mGroupPosition; }
60 	void setGroupPosition(GroupPosition groupPosition);
61 
62 	void setColorSwatch(const QColor &color);
colorSwatch()63 	QColor colorSwatch() const { return m_colorSwatch; }
64 
65 protected:
66 	virtual void paintEvent(QPaintEvent* event) Q_DECL_OVERRIDE;
67 
68 private:
69 	GroupPosition mGroupPosition;
70 	QColor m_colorSwatch;
71 };
72 
73 }
74 
75 #endif
76