Salome HOME
Merge from V6_main 01/04/2013
[modules/gui.git] / src / Qtx / QtxColorButton.h
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 // File:      QtxColorButton.h
21 // Author:    Sergey TELKOV
22 //
23 #ifndef QTXCOLORBUTTON_H
24 #define QTXCOLORBUTTON_H
25
26 #include "Qtx.h"
27
28 #include <QMap>
29 #include <QColor>
30 #include <QPixmap>
31 #include <QToolButton>
32
33 class QPaintDevice;
34
35 class QTX_EXPORT QtxColorButton : public QToolButton
36 {
37   Q_OBJECT
38
39 public:
40   QtxColorButton( QWidget* = 0 );
41   virtual ~QtxColorButton();
42
43   QColor        color() const;
44   void          setColor( const QColor& );
45
46   bool          eventFilter( QObject*, QEvent* );
47
48   bool          isAutoEnabled() const;
49   void          setAutoEnabled( bool );
50
51   QString       autoText() const;
52   void          setAutoText( const QString& );
53
54 signals:
55   void          clicked( QColor );
56   void          changed( QColor );
57
58 private slots:
59   void          onClicked( bool );
60   void          onToggled( bool );
61
62   void          onAboutToShow();
63   void          onAutoClicked( bool );
64   void          onDialogClicked( bool );
65
66 protected:
67   virtual void  paintEvent( QPaintEvent* );
68
69 private:
70   QList<QColor> colorsList() const;
71
72   void          updateState();
73   void          updateButton( QToolButton* );
74   QPixmap       buttonIcon( const QColor& ) const;
75   void          drawColor( QPaintDevice*, const QColor&, const QColor& = Qt::black, const int = 1 ) const;
76
77 private:
78   typedef QMap<const QToolButton*, QColor> ColorMap;
79
80 private:
81   ColorMap      myColors;
82   QToolButton*  myAutoButton;
83 };
84
85 #endif