itom  4.1.0
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 
38 class ITOMWIDGETS_EXPORT ColorPickerButton : public QPushButton
39 {
40  Q_OBJECT
41  Q_FLAGS(ColorDialogOption ColorDialogOptions)
42 
43 
44  Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged USER true)
46 
47 
48  Q_PROPERTY(QString colorName READ colorName WRITE setColorName NOTIFY colorNameChanged)
51 
52 
53  Q_PROPERTY(bool displayColorName READ displayColorName WRITE setDisplayColorName DESIGNABLE true)
56 
57 
58  Q_PROPERTY(ColorDialogOptions dialogOptions READ dialogOptions WRITE setDialogOptions)
59 public:
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 
112 public Q_SLOTS:
115  void setColor(const QColor& color);
116 
121  void changeColor();
122 
126  void setDisplayColorName(bool displayColorName);
127 
128 Q_SIGNALS:
131  void colorChanged(QColor);
132 
134  void colorNameChanged(QString);
135 
136 protected Q_SLOTS:
137  void onToggled(bool change = true);
138 
139 protected:
140  virtual void paintEvent(QPaintEvent* event);
141 
142  QScopedPointer<ColorPickerButtonPrivate> d_ptr;
143 private :
144  Q_DECLARE_PRIVATE(ColorPickerButton);
145  Q_DISABLE_COPY(ColorPickerButton);
146 };
147 
148 Q_DECLARE_OPERATORS_FOR_FLAGS(ColorPickerButton::ColorDialogOptions)
149 
150 #endif
Definition: colorPickerButton.cpp:36
Definition: colorPickerButton.h:38