QGIS API Documentation  2.6.0-Brighton
 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 
57  void setColor( const QColor &color );
63  QColor color() const;
64 
70  void setColorDialogOptions( QColorDialog::ColorDialogOptions cdo );
71 
77  QColorDialog::ColorDialogOptions colorDialogOptions();
78 
84  void setColorDialogTitle( QString cdt );
85 
91  QString colorDialogTitle();
92 
96  bool acceptLiveUpdates() { return mAcceptLiveUpdates; }
97 
102  void setAcceptLiveUpdates( bool accept ) { mAcceptLiveUpdates = accept; }
103 
104  public slots:
112  void setButtonBackground( QColor color = QColor() );
113 
114  signals:
121  void colorChanged( const QColor &color );
122 
123  protected:
124  void changeEvent( QEvent* e );
125  void showEvent( QShowEvent* e );
126  static const QPixmap& transpBkgrd();
127 
131  void mousePressEvent( QMouseEvent* e );
132 
136  void mouseMoveEvent( QMouseEvent *e );
137 
141  void mouseReleaseEvent( QMouseEvent *e );
142 
146  void keyPressEvent( QKeyEvent *e );
147 
151  void dragEnterEvent( QDragEnterEvent * e );
152 
156  void dropEvent( QDropEvent *e );
157 
158  private:
159  QString mColorDialogTitle;
160  QColor mColor;
161  QColorDialog::ColorDialogOptions mColorDialogOptions;
162  bool mAcceptLiveUpdates;
163  QTemporaryFile mTempPNG;
164  bool mColorSet; // added in QGIS 2.1
165 
166  QPoint mDragStartPosition;
167  bool mPickingColor;
168 
172  void showContextMenu( QMouseEvent* event );
173 
180  QMimeData* createColorMimeData() const;
181 
191  bool colorFromMimeData( const QMimeData *mimeData, QColor &resultColor );
192 
193 #ifdef Q_OS_WIN
194 
200  QString fullPath( const QString &path );
201 #endif
202 
210  void stopPicking( QPointF eventPos, bool sampleColor = true );
211 
212  private slots:
213  void onButtonClicked();
214 
218  void setValidColor( const QColor& newColor );
219 };
220 
221 #endif