Salome HOME
447d080028796619706228d95951de618cd9b697
[modules/gui.git] / src / Qtx / QtxColorButton.h
1 // Copyright (C) 2007-2024  CEA, EDF, 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, or (at your option) any later version.
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   QSize         sizeHint() const;
55
56 signals:
57   void          clicked( QColor );
58   void          changed( QColor );
59
60 private slots:
61   void          onClicked( bool );
62   void          onToggled( bool );
63
64   void          onAboutToShow();
65   void          onAutoClicked( bool );
66   void          onDialogClicked( bool );
67
68 protected:
69   virtual void  paintEvent( QPaintEvent* );
70
71 private:
72   QList<QColor> colorsList() const;
73
74   void          updateState();
75   void          updateButton( QToolButton* );
76   QPixmap       buttonIcon( const QColor& ) const;
77   void          drawColor( QPaintDevice*, const QColor&, const QColor& = Qt::black, const int = 1 ) const;
78
79 private:
80   typedef QMap<const QToolButton*, QColor> ColorMap;
81
82 private:
83   ColorMap      myColors;
84   QToolButton*  myAutoButton;
85 };
86
87 #endif