QGIS API Documentation  2.10.1-Pisa
 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_ENUMS( Behaviour )
38  Q_PROPERTY( QString colorDialogTitle READ colorDialogTitle WRITE setColorDialogTitle )
39  Q_PROPERTY( bool acceptLiveUpdates READ acceptLiveUpdates WRITE setAcceptLiveUpdates )
40  Q_PROPERTY( QColor color READ color WRITE setColor )
41  Q_PROPERTY( bool allowAlpha READ allowAlpha WRITE setAllowAlpha )
42  Q_PROPERTY( bool showMenu READ showMenu WRITE setShowMenu )
43  Q_PROPERTY( Behaviour behaviour READ behaviour WRITE setBehaviour )
44  Q_PROPERTY( QColor defaultColor READ defaultColor WRITE setDefaultColor )
45  Q_PROPERTY( bool showNoColor READ showNoColor WRITE setShowNoColor )
46  Q_PROPERTY( QString noColorString READ noColorString WRITE setNoColorString )
47  Q_PROPERTY( QString context READ context WRITE setContext )
48 
49  public:
50 
53  enum Behaviour
54  {
55  ShowDialog = 0,
56  SignalOnly
57  };
58 
65  QgsColorButtonV2( QWidget *parent = 0, QString cdt = "", QgsColorSchemeRegistry* registry = 0 );
66 
67  virtual ~QgsColorButtonV2();
68 
69  virtual QSize sizeHint() const override;
70 
75  QColor color() const;
76 
82  void setAllowAlpha( const bool allowAlpha );
83 
89  bool allowAlpha() const { return mAllowAlpha; }
90 
95  void setColorDialogTitle( const QString title );
96 
101  QString colorDialogTitle() const;
102 
107  bool acceptLiveUpdates() const { return mAcceptLiveUpdates; }
108 
114  void setAcceptLiveUpdates( const bool accept ) { mAcceptLiveUpdates = accept; }
115 
121  void setShowMenu( const bool showMenu );
122 
127  bool showMenu() const { return menu() ? true : false; }
128 
134  void setBehaviour( const Behaviour behaviour );
135 
140  Behaviour behaviour() const { return mBehaviour; }
141 
148  void setDefaultColor( const QColor color );
149 
156  QColor defaultColor() const { return mDefaultColor; }
157 
166  void setShowNoColor( const bool showNoColorOption ) { mShowNoColorOption = showNoColorOption; }
167 
176  bool showNoColor() const { return mShowNoColorOption; }
177 
185  void setNoColorString( const QString noColorString ) { mNoColorString = noColorString; }
186 
194  QString noColorString() const { return mNoColorString; }
195 
202  void setContext( const QString context ) { mContext = context; }
203 
210  QString context() const { return mContext; }
211 
218  void setColorSchemeRegistry( QgsColorSchemeRegistry* registry ) { mColorSchemeRegistry = registry; }
219 
226  QgsColorSchemeRegistry* colorSchemeRegistry() { return mColorSchemeRegistry; }
227 
228  public slots:
229 
235  void setColor( const QColor &color );
236 
244  void setButtonBackground( const QColor &color = QColor() );
245 
249  void copyColor();
250 
255  void pasteColor();
256 
259  void activatePicker();
260 
265  void setToNoColor();
266 
271  void setToDefaultColor();
272 
273  signals:
274 
279  void colorChanged( const QColor &color );
280 
286  void colorClicked( const QColor &color );
287 
288  protected:
289 
290  void changeEvent( QEvent* e ) override;
291  void showEvent( QShowEvent* e ) override;
292  void resizeEvent( QResizeEvent *event ) override;
293 
296  static const QPixmap& transparentBackground();
297 
301  void mousePressEvent( QMouseEvent* e ) override;
302 
306  void mouseMoveEvent( QMouseEvent *e ) override;
307 
311  void mouseReleaseEvent( QMouseEvent *e ) override;
312 
316  void keyPressEvent( QKeyEvent *e ) override;
317 
321  void dragEnterEvent( QDragEnterEvent * e ) override;
322 
326  void dragLeaveEvent( QDragLeaveEvent *e ) override;
327 
331  void dropEvent( QDropEvent *e ) override;
332 
333  private:
334 
335  Behaviour mBehaviour;
336  QString mColorDialogTitle;
337  QColor mColor;
338 
339  QgsColorSchemeRegistry* mColorSchemeRegistry;
340 
341  QColor mDefaultColor;
342  QString mContext;
343  bool mAllowAlpha;
344  bool mAcceptLiveUpdates;
345  bool mColorSet;
346 
347  bool mShowNoColorOption;
348  QString mNoColorString;
349 
350  QPoint mDragStartPosition;
351  bool mPickingColor;
352 
353  QMenu* mMenu;
354 
355  QSize mIconSize;
356 
364  bool colorFromMimeData( const QMimeData *mimeData, QColor &resultColor );
365 
371  void stopPicking( QPointF eventPos, bool sampleColor = true );
372 
378  QPixmap createMenuIcon( const QColor &color, const bool showChecks = true );
379 
380  private slots:
381 
382  void buttonClicked();
383 
384  void showColorDialog();
385 
388  void setValidColor( const QColor& newColor );
389 
393  void addRecentColor( const QColor& color );
394 
397  void prepareMenu();
398 };
399 
400 #endif
QString noColorString() const
Returns the string used for the "no color" option in the button's drop down menu.
virtual void dropEvent(QDropEvent *event)
A cross platform button subclass for selecting colors.
Registry of color schemes.
virtual QSize sizeHint() const
virtual void dragLeaveEvent(QDragLeaveEvent *event)
bool allowAlpha() const
Returns whether alpha modification (transparency) is permitted for the color.
virtual void dragEnterEvent(QDragEnterEvent *event)
virtual void mouseMoveEvent(QMouseEvent *e)
bool showMenu() const
Returns whether the drop down menu is shown for the button.
void setShowNoColor(const bool showNoColorOption)
Sets whether the "no color" option should be shown in the button's drop down menu.
QgsColorSchemeRegistry * colorSchemeRegistry()
Returns the color scheme registry for the button, which controls the color swatch grids that are show...
void setContext(const QString context)
Sets the context string for the color button.
virtual void showEvent(QShowEvent *event)
virtual void mousePressEvent(QMouseEvent *e)
virtual void mouseReleaseEvent(QMouseEvent *e)
void setColorSchemeRegistry(QgsColorSchemeRegistry *registry)
Sets the color scheme registry for the button, which controls the color swatch grids that are shown i...
bool showNoColor() const
Returns whether the "no color" option is shown in the button's drop down menu.
QString context() const
Returns the context string for the color button.
virtual void changeEvent(QEvent *e)
QMenu * menu() const
void setAcceptLiveUpdates(const bool accept)
Sets whether the button accepts live updates from QColorDialog.
bool acceptLiveUpdates() const
Returns whether the button accepts live updates from QColorDialog.
virtual void keyPressEvent(QKeyEvent *e)
QColor defaultColor() const
Returns the default color for the button, which is shown in the button's drop down menu for the "defa...
Behaviour behaviour() const
Returns the behaviour for when the button is clicked.
void setNoColorString(const QString noColorString)
Sets the string to use for the "no color" option in the button's drop down menu.
virtual void resizeEvent(QResizeEvent *event)