itom 2.2.1
K:/git-itom/sources/itom/itomWidgets/colorPickerButton.h
00001 /*=========================================================================
00002 
00003   Library:   CTK
00004 
00005   Copyright (c) Kitware Inc.
00006 
00007   Licensed under the Apache License, Version 2.0 (the "License");
00008   you may not use this file except in compliance with the License.
00009   You may obtain a copy of the License at
00010 
00011       http://www.apache.org/licenses/LICENSE-2.0.txt
00012 
00013   Unless required by applicable law or agreed to in writing, software
00014   distributed under the License is distributed on an "AS IS" BASIS,
00015   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00016   See the License for the specific language governing permissions and
00017   limitations under the License.
00018 
00019 =========================================================================*/
00020 
00021 #ifndef COLORPICKERBUTTON_H
00022 #define COLORPICKERBUTTON_H
00023 
00024 // Qt includes
00025 #include <QPushButton>
00026 #include <QColor>
00027 
00028 // CTK includes
00029 #include "commonWidgets.h"
00030 class ColorPickerButtonPrivate;
00031 
00038 class ITOMWIDGETS_EXPORT ColorPickerButton : public QPushButton
00039 {
00040   Q_OBJECT
00041   Q_FLAGS(ColorDialogOption ColorDialogOptions)
00042 
00043   
00044 
00045   Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged USER true)
00046 
00050   Q_PROPERTY(QString colorName READ colorName WRITE setColorName NOTIFY colorNameChanged)
00051 
00055   Q_PROPERTY(bool displayColorName READ displayColorName WRITE setDisplayColorName DESIGNABLE true)
00056 
00058   Q_PROPERTY(ColorDialogOptions dialogOptions READ dialogOptions WRITE setDialogOptions)
00059 public:
00060   enum ColorDialogOption {
00061     ShowAlphaChannel    = 0x00000001,
00062     NoButtons           = 0x00000002,
00063     DontUseNativeDialog = 0x00000004,
00064     UseColorDialog   = 0x0000000C
00065   };
00066   Q_DECLARE_FLAGS(ColorDialogOptions, ColorDialogOption)
00067 
00068   
00069   explicit ColorPickerButton(QWidget* parent = 0);
00070 
00074   explicit ColorPickerButton(const QString& text, QWidget* parent = 0 );
00075 
00079   explicit ColorPickerButton(const QColor& color, const QString & text, QWidget* parent = 0 );
00080 
00081   virtual ~ColorPickerButton();
00082 
00084   QColor color()const;
00085 
00090   QString colorName()const;
00091 
00095   void setColorName(const QString& name);
00096 
00099   bool displayColorName()const;
00100 
00104   void setDialogOptions(const ColorDialogOptions& options);
00105   const ColorDialogOptions& dialogOptions() const;
00106 
00110   virtual QSize sizeHint()const;
00111 
00112 public Q_SLOTS:
00115   void setColor(const QColor& color);
00116 
00121   void changeColor();
00122 
00126   void setDisplayColorName(bool displayColorName);
00127 
00128 Q_SIGNALS:
00131   void colorChanged(QColor);
00132 
00134   void colorNameChanged(QString);
00135 
00136 protected Q_SLOTS:
00137   void onToggled(bool change = true);
00138 
00139 protected:
00140   virtual void paintEvent(QPaintEvent* event);
00141 
00142   QScopedPointer<ColorPickerButtonPrivate> d_ptr;
00143 private :
00144   Q_DECLARE_PRIVATE(ColorPickerButton);
00145   Q_DISABLE_COPY(ColorPickerButton);
00146 };
00147 
00148 Q_DECLARE_OPERATORS_FOR_FLAGS(ColorPickerButton::ColorDialogOptions)
00149 
00150 #endif
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Properties Friends