1 /***************************************************************************
2     qgspresetcolorrampdialog.h
3     ---------------------
4     begin                : September 2016
5     copyright            : (C) 2016 by Nyall Dawson
6     email                : nyall dot dawson 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 
16 #ifndef QGSPRESETCOLORRAMPDIALOG_H
17 #define QGSPRESETCOLORRAMPDIALOG_H
18 
19 #include <QDialog>
20 #include "qgis_sip.h"
21 #include "qgspanelwidget.h"
22 #include "qgscolorramp.h"
23 #include "ui_qgspresetcolorrampwidgetbase.h"
24 #include "qgis_gui.h"
25 
26 class QDialogButtonBox;
27 
28 /**
29  * \ingroup gui
30  * \class QgsPresetColorRampWidget
31  * \brief A widget which allows users to modify the properties of a QgsPresetSchemeColorRamp.
32  * \since QGIS 3.0
33  */
34 class GUI_EXPORT QgsPresetColorRampWidget : public QgsPanelWidget, private Ui::QgsPresetColorRampWidgetBase
35 {
36     Q_OBJECT
37     Q_PROPERTY( QgsPresetSchemeColorRamp ramp READ ramp WRITE setRamp )
38 
39   public:
40 
41     /**
42      * Constructor for QgsPresetColorRampWidget.
43      * \param ramp initial ramp to show in dialog
44      * \param parent parent widget
45      */
46     QgsPresetColorRampWidget( const QgsPresetSchemeColorRamp &ramp, QWidget *parent SIP_TRANSFERTHIS = nullptr );
47 
48     /**
49      * Returns a color ramp representing the current settings from the dialog.
50      * \see setRamp()
51      */
52     QgsPresetSchemeColorRamp ramp() const;
53 
54     /**
55      * Sets the color ramp to show in the dialog.
56      * \param ramp color ramp
57      * \see ramp()
58      */
59     void setRamp( const QgsPresetSchemeColorRamp &ramp );
60 
61   signals:
62 
63     //! Emitted when the dialog settings change
64     void changed();
65 
66   private slots:
67     void setColors();
68 
69     void mButtonAddColor_clicked();
70 
71     void newColorChanged( const QColor &color );
72     void schemeChanged();
73 
74   private:
75 
76     void updatePreview();
77     QgsPresetSchemeColorRamp mRamp;
78 };
79 
80 /**
81  * \ingroup gui
82  * \class QgsPresetColorRampDialog
83  * \brief A dialog which allows users to modify the properties of a QgsPresetSchemeColorRamp.
84  * \since QGIS 3.0
85  */
86 class GUI_EXPORT QgsPresetColorRampDialog : public QDialog
87 {
88     Q_OBJECT
89     Q_PROPERTY( QgsPresetSchemeColorRamp ramp READ ramp WRITE setRamp )
90 
91   public:
92 
93     /**
94      * Constructor for QgsPresetColorRampDialog.
95      * \param ramp initial ramp to show in dialog
96      * \param parent parent widget
97      */
98     QgsPresetColorRampDialog( const QgsPresetSchemeColorRamp &ramp, QWidget *parent SIP_TRANSFERTHIS = nullptr );
99 
100     /**
101      * Returns a color ramp representing the current settings from the dialog.
102      * \see setRamp()
103      */
ramp()104     QgsPresetSchemeColorRamp ramp() const { return mWidget->ramp(); }
105 
106     /**
107      * Sets the color ramp to show in the dialog.
108      * \param ramp color ramp
109      * \see ramp()
110      */
setRamp(const QgsPresetSchemeColorRamp & ramp)111     void setRamp( const QgsPresetSchemeColorRamp &ramp ) { mWidget->setRamp( ramp ); }
112 
113     /**
114      * Returns a reference to the dialog's button box.
115      * \since QGIS 3.10
116      */
117     QDialogButtonBox *buttonBox() const;
118 
119   signals:
120 
121     //! Emitted when the dialog settings change
122     void changed();
123 
124   private:
125 
126     QgsPresetColorRampWidget *mWidget = nullptr;
127     QDialogButtonBox *mButtonBox = nullptr;
128 
129   private slots:
130 
131     void showHelp();
132 
133 };
134 
135 #endif //QGSPRESETCOLORRAMPDIALOG_H
136