QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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( QColor color = QColor() );
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 mouseReleaseEvent( QMouseEvent *e );
154 
158  void keyPressEvent( QKeyEvent *e );
159 
163  void dragEnterEvent( QDragEnterEvent * e ) ;
164 
168  void dropEvent( QDropEvent *e );
169 
170  private:
171  QString mColorDialogTitle;
172  QColor mColor;
173  QColorDialog::ColorDialogOptions mColorDialogOptions;
174  bool mAcceptLiveUpdates;
175  QTemporaryFile mTempPNG;
176  bool mColorSet; // added in QGIS 2.1
177 
178  QPoint mDragStartPosition;
179  bool mPickingColor;
180 
184  void showContextMenu( QMouseEvent* event );
185 
192  QMimeData* createColorMimeData() const;
193 
203  bool colorFromMimeData( const QMimeData *mimeData, QColor &resultColor );
204 
205 #ifdef Q_OS_WIN
206 
212  QString fullPath( const QString &path );
213 #endif
214 
222  void stopPicking( QPointF eventPos, bool sampleColor = true );
223 
224  private slots:
225  void onButtonClicked();
226 
232  void setValidColor( const QColor& newColor );
233 };
234 
235 #endif
void setAcceptLiveUpdates(bool accept)
Sets whether the button accepts live updates from QColorDialog.
Definition: qgscolorbutton.h:112
A cross platform button subclass for selecting colors. Will open a color chooser dialog when clicked...
Definition: qgscolorbutton.h:31
bool acceptLiveUpdates()
Whether the button accepts live updates from QColorDialog.
Definition: qgscolorbutton.h:104