QGIS API Documentation  3.0.2-Girona (307d082)
qgscolorrampbutton.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgscolorrampbutton.h - Color ramp button
3  --------------------------------------
4  Date : November 27, 2016
5  Copyright : (C) 2016 by Mathieu Pellerin
6  Email : nirvn dot asia at gmail dot com
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 QGSCOLORRAMPBUTTON_H
16 #define QGSCOLORRAMPBUTTON_H
17 
18 #include "qgscolorrampbutton.h"
19 
20 #include "qgscolorramp.h"
21 #include "qgsstyle.h"
22 
23 #include <QToolButton>
24 #include "qgis_gui.h"
25 #include "qgis.h"
26 
27 class QgsPanelWidget;
28 
37 class GUI_EXPORT QgsColorRampButton : public QToolButton
38 {
39  Q_OBJECT
40  Q_PROPERTY( QString colorRampDialogTitle READ colorRampDialogTitle WRITE setColorRampDialogTitle )
41  Q_PROPERTY( bool acceptLiveUpdates READ acceptLiveUpdates WRITE setAcceptLiveUpdates )
42  Q_PROPERTY( bool showMenu READ showMenu WRITE setShowMenu )
43  Q_PROPERTY( QgsColorRamp *defaultColorRamp READ defaultColorRamp WRITE setDefaultColorRamp )
44  Q_PROPERTY( QString context READ context WRITE setContext )
45 
46  public:
47 
53  QgsColorRampButton( QWidget *parent SIP_TRANSFERTHIS = nullptr, const QString &dialogTitle = QString() );
54 
55  ~QgsColorRampButton() override;
56 
57  QSize sizeHint() const override;
58 
63  QgsColorRamp *colorRamp() const SIP_FACTORY;
64 
70  void setColorRampDialogTitle( const QString &title );
71 
77  QString colorRampDialogTitle() const;
78 
84  bool acceptLiveUpdates() const { return mAcceptLiveUpdates; }
85 
92  void setAcceptLiveUpdates( const bool accept ) { mAcceptLiveUpdates = accept; }
93 
100  void setShowMenu( const bool showMenu );
101 
107  bool showMenu() const { return menu() ? true : false; }
108 
116  void setDefaultColorRamp( QgsColorRamp *colorramp );
117 
125  QgsColorRamp *defaultColorRamp() const SIP_FACTORY { return mDefaultColorRamp ? mDefaultColorRamp->clone() : nullptr ; }
126 
132  void setShowRandomColorRamp( bool showRandom ) { mShowRandomColorRamp = showRandom; }
133 
138  bool showRandomColorRamp() const { return mShowRandomColorRamp; }
139 
145  bool isRandomColorRamp() const;
146 
153  void setShowNull( bool showNull );
154 
160  bool showNull() const;
161 
167  bool isNull() const;
168 
176  void setContext( const QString &context ) { mContext = context; }
177 
185  QString context() const { return mContext; }
186 
192  void setShowGradientOnly( bool gradientonly ) { mShowGradientOnly = gradientonly; }
193 
198  bool showGradientOnly() const { return mShowGradientOnly; }
199 
205  void setColorRampName( const QString &name ) { mColorRampName = name; }
206 
211  QString colorRampName() const { return mColorRampName; }
212 
213  public slots:
214 
221  void setColorRamp( QgsColorRamp *colorramp );
222 
228  void setRandomColorRamp();
229 
236  void setColorRampFromName( const QString &name = QString() );
237 
243  void setButtonBackground( QgsColorRamp *colorramp = nullptr );
244 
251  void setToDefaultColorRamp();
252 
257  void setToNull();
258 
259  signals:
260 
265  void colorRampChanged();
266 
267  private slots:
268 
269  void rampWidgetUpdated();
270 
271  protected:
272 
273  bool event( QEvent *e ) override;
274  void changeEvent( QEvent *e ) override;
275  void showEvent( QShowEvent *e ) override;
276  void resizeEvent( QResizeEvent *event ) override;
277 
281  void mousePressEvent( QMouseEvent *e ) override;
282 
283  private:
284 
285  QString mColorRampDialogTitle;
286  bool mShowGradientOnly = false;
287  QgsColorRamp *mColorRamp = nullptr;
288  QString mColorRampName;
289  QgsStyle *mStyle = nullptr;
290 
291  QgsColorRamp *mDefaultColorRamp = nullptr;
292  QString mContext;
293  bool mAcceptLiveUpdates = true;
294  bool mColorRampSet = false;
295  bool mShowRandomColorRamp = false;
296  bool mShowNull = false;
297 
298  QMenu *mMenu = nullptr;
299  QMenu *mAllRampsMenu = nullptr;
300 
301  QSize mIconSize;
302 
307  QPixmap createMenuIcon( QgsColorRamp *colorramp );
308 
309  private slots:
310 
311  void buttonClicked();
312 
316  void showColorRampDialog();
317 
321  void createColorRamp();
322 
326  void saveColorRamp();
327 
331  void invertColorRamp();
332 
336  void loadColorRamp();
337 
341  void prepareMenu();
342 };
343 
344 #endif
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:46
QString colorRampName() const
Returns the name of the current color ramp when it&#39;s available in the style manager.
Abstract base class for color ramps.
Definition: qgscolorramp.h:31
Base class for any widget that can be shown as a inline panel.
QgsColorRamp * defaultColorRamp() const
Returns a copy of the default color ramp for the button, which is shown in the button&#39;s drop-down men...
void setAcceptLiveUpdates(const bool accept)
Sets whether the button accepts live updates from QgsColorRampDialog.
void setContext(const QString &context)
Sets the context string for the color ramp button.
bool showMenu() const
Returns whether the drop-down menu is shown for the button.
#define SIP_FACTORY
Definition: qgis_sip.h:69
bool showRandomColorRamp() const
Returns whether random colors option is shown in the button&#39;s drop-down menu.
A cross platform button subclass for selecting color ramps.
void setColorRampName(const QString &name)
Sets the name of the current color ramp when it&#39;s available in the style manager. ...
void setShowGradientOnly(bool gradientonly)
Sets whether the color ramp button only shows gradient type ramps.
QString context() const
Returns the context string for the color ramp button.
void setShowRandomColorRamp(bool showRandom)
Sets whether a random colors option is shown in the button&#39;s drop-down menu.
bool showGradientOnly() const
Returns true if the color ramp button only shows gradient type ramps.