itom
Loading...
Searching...
No Matches
colorPickerButton.h
1/*=========================================================================
2
3 Library: CTK
4
5 Copyright (c) Kitware Inc.
6
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
10
11 http://www.apache.org/licenses/LICENSE-2.0.txt
12
13 Unless required by applicable law or agreed to in writing, software
14 distributed under the License is distributed on an "AS IS" BASIS,
15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 See the License for the specific language governing permissions and
17 limitations under the License.
18
19=========================================================================*/
20
21#ifndef COLORPICKERBUTTON_H
22#define COLORPICKERBUTTON_H
23
24// Qt includes
25#include <QPushButton>
26#include <QColor>
27
28// CTK includes
29#include "commonWidgets.h"
31
38class ITOMWIDGETS_EXPORT ColorPickerButton : public QPushButton
39{
40 Q_OBJECT
41 Q_FLAGS(ColorDialogOption ColorDialogOptions)
42
43
45 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged USER true)
46
50 Q_PROPERTY(QString colorName READ colorName WRITE setColorName NOTIFY colorNameChanged)
51
55 Q_PROPERTY(bool displayColorName READ displayColorName WRITE setDisplayColorName DESIGNABLE true)
56
58 Q_PROPERTY(ColorDialogOptions dialogOptions READ dialogOptions WRITE setDialogOptions)
59public:
60 enum ColorDialogOption {
61 ShowAlphaChannel = 0x00000001,
62 NoButtons = 0x00000002,
63 DontUseNativeDialog = 0x00000004,
64 UseColorDialog = 0x0000000C
65 };
66 Q_DECLARE_FLAGS(ColorDialogOptions, ColorDialogOption)
67
68
69 explicit ColorPickerButton(QWidget* parent = 0);
70
74 explicit ColorPickerButton(const QString& text, QWidget* parent = 0 );
75
79 explicit ColorPickerButton(const QColor& color, const QString & text, QWidget* parent = 0 );
80
81 virtual ~ColorPickerButton();
82
84 QColor color()const;
85
90 QString colorName()const;
91
95 void setColorName(const QString& name);
96
99 bool displayColorName()const;
100
104 void setDialogOptions(const ColorDialogOptions& options);
105 const ColorDialogOptions& dialogOptions() const;
106
110 virtual QSize sizeHint()const;
111
112public Q_SLOTS:
115 void setColor(const QColor& color);
116
121 void changeColor();
122
126 void setDisplayColorName(bool displayColorName);
127
128Q_SIGNALS:
131 void colorChanged(QColor);
132
134 void colorNameChanged(QString);
135
136protected Q_SLOTS:
137 void onToggled(bool change = true);
138
139protected:
140 virtual void paintEvent(QPaintEvent* event);
141
142 QScopedPointer<ColorPickerButtonPrivate> d_ptr;
143private :
144 Q_DECLARE_PRIVATE(ColorPickerButton);
145 Q_DISABLE_COPY(ColorPickerButton);
146};
147
148Q_DECLARE_OPERATORS_FOR_FLAGS(ColorPickerButton::ColorDialogOptions)
149
150#endif
Definition colorPickerButton.h:39
void colorNameChanged(QString)
This signaled is fired anytime a new color name is set.
void colorChanged(QColor)
Definition colorPickerButton.cpp:37