Back to index

salome-gui  6.5.0
QtxColorButton.h
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 // File:      QtxColorButton.h
00021 // Author:    Sergey TELKOV
00022 //
00023 #ifndef QTXCOLORBUTTON_H
00024 #define QTXCOLORBUTTON_H
00025 
00026 #include "Qtx.h"
00027 
00028 #include <QMap>
00029 #include <QColor>
00030 #include <QPixmap>
00031 #include <QToolButton>
00032 
00033 class QPaintDevice;
00034 
00035 class QTX_EXPORT QtxColorButton : public QToolButton
00036 {
00037   Q_OBJECT
00038 
00039 public:
00040   QtxColorButton( QWidget* = 0 );
00041   virtual ~QtxColorButton();
00042 
00043   QColor        color() const;
00044   void          setColor( const QColor& );
00045 
00046   bool          eventFilter( QObject*, QEvent* );
00047 
00048   bool          isAutoEnabled() const;
00049   void          setAutoEnabled( bool );
00050 
00051   QString       autoText() const;
00052   void          setAutoText( const QString& );
00053 
00054 signals:
00055   void          clicked( QColor );
00056   void          changed( QColor );
00057 
00058 private slots:
00059   void          onClicked( bool );
00060   void          onToggled( bool );
00061 
00062   void          onAboutToShow();
00063   void          onAutoClicked( bool );
00064   void          onDialogClicked( bool );
00065 
00066 protected:
00067   virtual void  paintEvent( QPaintEvent* );
00068 
00069 private:
00070   QList<QColor> colorsList() const;
00071 
00072   void          updateState();
00073   void          updateButton( QToolButton* );
00074   QPixmap       buttonIcon( const QColor& ) const;
00075   void          drawColor( QPaintDevice*, const QColor&, const QColor& = Qt::black, const int = 1 ) const;
00076 
00077 private:
00078   typedef QMap<const QToolButton*, QColor> ColorMap;
00079 
00080 private:
00081   ColorMap      myColors;
00082   QToolButton*  myAutoButton;
00083 };
00084 
00085 #endif