QGIS API Documentation  2.6.0-Brighton
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgscolorbuttonv2.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 QGSCOLORBUTTONV2_H
16 #define QGSCOLORBUTTONV2_H
17 
18 #include <QColorDialog>
19 #include <QToolButton>
20 #include <QTemporaryFile>
21 #include "qgscolorscheme.h"
22 
23 class QMimeData;
25 
34 class GUI_EXPORT QgsColorButtonV2: public QToolButton
35 {
36  Q_OBJECT
37  Q_PROPERTY( QString colorDialogTitle READ colorDialogTitle WRITE setColorDialogTitle )
38  Q_PROPERTY( bool acceptLiveUpdates READ acceptLiveUpdates WRITE setAcceptLiveUpdates )
39  Q_PROPERTY( QColor color READ color WRITE setColor )
40  Q_PROPERTY( bool allowAlpha READ allowAlpha WRITE setAllowAlpha )
41  Q_PROPERTY( bool showMenu READ showMenu WRITE setShowMenu )
42  Q_PROPERTY( Behaviour behaviour READ behaviour WRITE setBehaviour )
43  Q_PROPERTY( QColor defaultColor READ defaultColor WRITE setDefaultColor )
44  Q_PROPERTY( bool showNoColor READ showNoColor WRITE setShowNoColor )
45  Q_PROPERTY( QString noColorString READ noColorString WRITE setNoColorString )
46  Q_PROPERTY( QString context READ context WRITE setContext )
47 
48  public:
49 
52  enum Behaviour
53  {
54  ShowDialog = 0,
55  SignalOnly
56  };
57 
64  QgsColorButtonV2( QWidget *parent = 0, QString cdt = "", QgsColorSchemeRegistry* registry = 0 );
65 
66  virtual ~QgsColorButtonV2();
67 
68  virtual QSize sizeHint() const;
69 
74  QColor color() const;
75 
81  void setAllowAlpha( const bool allowAlpha );
82 
88  bool allowAlpha() const { return mAllowAlpha; }
89 
94  void setColorDialogTitle( const QString title );
95 
100  QString colorDialogTitle() const;
101 
106  bool acceptLiveUpdates() const { return mAcceptLiveUpdates; }
107 
113  void setAcceptLiveUpdates( const bool accept ) { mAcceptLiveUpdates = accept; }
114 
120  void setShowMenu( const bool showMenu );
121 
126  bool showMenu() const { return menu() ? true : false; }
127 
133  void setBehaviour( const Behaviour behaviour );
134 
139  Behaviour behaviour() const { return mBehaviour; }
140 
147  void setDefaultColor( const QColor color );
148 
155  QColor defaultColor() const { return mDefaultColor; }
156 
165  void setShowNoColor( const bool showNoColorOption ) { mShowNoColorOption = showNoColorOption; }
166 
175  bool showNoColor() const { return mShowNoColorOption; }
176 
184  void setNoColorString( const QString noColorString ) { mNoColorString = noColorString; }
185 
193  QString noColorString() const { return mNoColorString; }
194 
201  void setContext( const QString context ) { mContext = context; }
202 
209  QString context() const { return mContext; }
210 
217  void setColorSchemeRegistry( QgsColorSchemeRegistry* registry ) { mColorSchemeRegistry = registry; }
218 
225  QgsColorSchemeRegistry* colorSchemeRegistry() { return mColorSchemeRegistry; }
226 
227  public slots:
228 
234  void setColor( const QColor &color );
235 
243  void setButtonBackground( const QColor color = QColor() );
244 
248  void copyColor();
249 
254  void pasteColor();
255 
258  void activatePicker();
259 
264  void setToNoColor();
265 
270  void setToDefaultColor();
271 
272  signals:
273 
278  void colorChanged( const QColor &color );
279 
285  void colorClicked( const QColor color );
286 
287  protected:
288 
289  void changeEvent( QEvent* e );
290  void showEvent( QShowEvent* e );
291  void resizeEvent( QResizeEvent *event );
292 
295  static const QPixmap& transparentBackground();
296 
300  void mousePressEvent( QMouseEvent* e );
301 
305  void mouseMoveEvent( QMouseEvent *e );
306 
310  void mouseReleaseEvent( QMouseEvent *e );
311 
315  void keyPressEvent( QKeyEvent *e );
316 
320  void dragEnterEvent( QDragEnterEvent * e );
321 
325  void dragLeaveEvent( QDragLeaveEvent *e );
326 
330  void dropEvent( QDropEvent *e );
331 
332  private:
333 
334  Behaviour mBehaviour;
335  QString mColorDialogTitle;
336  QColor mColor;
337 
338  QgsColorSchemeRegistry* mColorSchemeRegistry;
339 
340  QColor mDefaultColor;
341  QString mContext;
342  bool mAllowAlpha;
343  bool mAcceptLiveUpdates;
344  bool mColorSet;
345 
346  bool mShowNoColorOption;
347  QString mNoColorString;
348 
349  QPoint mDragStartPosition;
350  bool mPickingColor;
351 
352  QMenu* mMenu;
353 
354  QSize mIconSize;
355 
363  bool colorFromMimeData( const QMimeData *mimeData, QColor &resultColor );
364 
370  void stopPicking( QPointF eventPos, bool sampleColor = true );
371 
377  QPixmap createMenuIcon( const QColor color, const bool showChecks = true );
378 
379  private slots:
380 
381  void buttonClicked();
382 
383  void showColorDialog();
384 
387  void setValidColor( const QColor& newColor );
388 
392  void addRecentColor( const QColor& color );
393 
396  void prepareMenu();
397 };
398 
399 #endif