QGIS API Documentation  2.4.0-Chugiak
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgscolorbutton.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgscolorbutton.h - Color button
3  --------------------------------------
4  Date : 12-Dec-2006
5  Copyright : (C) 2006 by Tom Elwertowski
6  Email : telwertowski at users dot sourceforge dot net
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 #ifndef QGSCOLORBUTTON_H
16 #define QGSCOLORBUTTON_H
17 
18 #include <QColorDialog>
19 #include <QPushButton>
20 #include <QTemporaryFile>
21 
22 class QMimeData;
23 
31 class GUI_EXPORT QgsColorButton: public QPushButton
32 {
33  Q_OBJECT
34  Q_PROPERTY( QString colorDialogTitle READ colorDialogTitle WRITE setColorDialogTitle )
35  Q_PROPERTY( bool acceptLiveUpdates READ acceptLiveUpdates WRITE setAcceptLiveUpdates )
36  Q_PROPERTY( QColor color READ color WRITE setColor )
37  Q_FLAGS( QColorDialog::ColorDialogOptions )
38  Q_PROPERTY( QColorDialog::ColorDialogOptions colorDialogOptions READ colorDialogOptions WRITE setColorDialogOptions )
39 
40  public:
49  QgsColorButton( QWidget *parent = 0, QString cdt = "", QColorDialog::ColorDialogOptions cdo = 0 );
50  ~QgsColorButton();
51 
58  void setColor( const QColor &color );
65  QColor color() const;
66 
73  void setColorDialogOptions( QColorDialog::ColorDialogOptions cdo );
74 
81  QColorDialog::ColorDialogOptions colorDialogOptions();
82 
89  void setColorDialogTitle( QString cdt );
90 
97  QString colorDialogTitle();
98 
104  bool acceptLiveUpdates() { return mAcceptLiveUpdates; }
105 
112  void setAcceptLiveUpdates( bool accept ) { mAcceptLiveUpdates = accept; }
113 
114  public slots:
123  void setButtonBackground();
124 
125  signals:
133  void colorChanged( const QColor &color );
134 
135  protected:
136  void changeEvent( QEvent* e );
137  void showEvent( QShowEvent* e );
138  static const QPixmap& transpBkgrd();
139 
143  void mousePressEvent( QMouseEvent* e );
144 
148  void mouseMoveEvent( QMouseEvent *e );
149 
153  void dragEnterEvent( QDragEnterEvent * e ) ;
154 
158  void dropEvent( QDropEvent *e );
159 
160  private:
162  QColor mColor;
163  QColorDialog::ColorDialogOptions mColorDialogOptions;
165  QTemporaryFile mTempPNG;
166  bool mColorSet; // added in QGIS 2.1
167 
169 
173  void showContextMenu( QMouseEvent* event );
174 
181  QMimeData* createColorMimeData() const;
182 
192  bool colorFromMimeData( const QMimeData *mimeData, QColor &resultColor );
193 
194 #ifdef Q_OS_WIN
195 
201  QString fullPath( const QString &path );
202 #endif
203 
204  private slots:
205  void onButtonClicked();
206 
212  void setValidColor( const QColor& newColor );
213 };
214 
215 #endif
void setAcceptLiveUpdates(bool accept)
Sets whether the button accepts live updates from QColorDialog.
A cross platform button subclass for selecting colors. Will open a color chooser dialog when clicked...
QColorDialog::ColorDialogOptions mColorDialogOptions
QString mColorDialogTitle
QPoint mDragStartPosition
QTemporaryFile mTempPNG