QGIS API Documentation  3.13.0-Master (788156190c)
qgscompoundcolorwidget.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgscompoundcolorwidget.h
3  ------------------------
4  begin : April 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 QGSCOMPOUNDCOLORWIDGET_H
17 #define QGSCOMPOUNDCOLORWIDGET_H
18 
19 #include "qgsguiutils.h"
20 #include "qgis_sip.h"
21 #include "qgspanelwidget.h"
22 #include "ui_qgscompoundcolorwidget.h"
23 #include "qgis_gui.h"
24 
33 class GUI_EXPORT QgsCompoundColorWidget : public QgsPanelWidget, private Ui::QgsCompoundColorWidgetBase
34 {
35 
36  Q_OBJECT
37 
38  public:
39 
41  enum Layout
42  {
43  LayoutDefault = 0,
45  };
46 
53  QgsCompoundColorWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr, const QColor &color = QColor(), Layout layout = LayoutDefault );
54 
55  ~QgsCompoundColorWidget() override;
56 
61  QColor color() const;
62 
69  void setAllowOpacity( bool allowOpacity );
70 
77  void setDiscarded( bool discarded ) { mDiscarded = discarded; }
78 
89  static QgsUserColorScheme *importUserPaletteFromFile( QWidget *parent );
90 
101  static QgsUserColorScheme *createNewUserPalette( QWidget *parent );
102 
113  static bool removeUserPalette( QgsUserColorScheme *scheme, QWidget *parent );
114 
115  signals:
116 
121  void currentColorChanged( const QColor &color );
122 
123  public slots:
124 
129  void setColor( const QColor &color );
130 
135  void setPreviousColor( const QColor &color );
136 
137  protected:
138 
139  void mousePressEvent( QMouseEvent *e ) override;
140 
141  void mouseMoveEvent( QMouseEvent *e ) override;
142 
143  void mouseReleaseEvent( QMouseEvent *e ) override;
144 
145  void keyPressEvent( QKeyEvent *e ) override;
146 
147  private slots:
148 
149  void mHueRadio_toggled( bool checked );
150  void mSaturationRadio_toggled( bool checked );
151  void mValueRadio_toggled( bool checked );
152  void mRedRadio_toggled( bool checked );
153  void mGreenRadio_toggled( bool checked );
154  void mBlueRadio_toggled( bool checked );
155 
156  void mAddColorToSchemeButton_clicked();
157 
158  void importPalette();
159  void removePalette();
160  void newPalette();
161 
162  void schemeIndexChanged( int index );
163  void listSelectionChanged( const QItemSelection &selected, const QItemSelection &deselected );
164 
165  void mAddCustomColorButton_clicked();
166 
167  void mSampleButton_clicked();
168  void mTabWidget_currentChanged( int index );
169 
170  private slots:
171 
172  void mActionShowInButtons_toggled( bool state );
173 
174  private:
175 
176  static QScreen *findScreenAt( QPoint pos );
177 
178  bool mAllowAlpha = true;
179 
180  int mLastCustomColorIndex = 0;
181 
182  bool mPickingColor = false;
183 
184  bool mDiscarded = false;
185 
189  void saveSettings();
190 
197  void stopPicking( QPoint eventPos, bool takeSample = true );
198 
204  QColor averageColor( const QImage &image ) const;
205 
211  QColor sampleColor( QPoint point ) const;
212 
216  void refreshSchemeComboBox();
217 
221  static QString gplFilePath();
222 
224  void updateActionsForCurrentScheme();
225 };
226 
227 #endif // QGSCOMPOUNDCOLORWIDGET_H
QgsUserColorScheme
A color scheme which stores its colors in a gpl palette file within the "palettes" subfolder off the ...
Definition: qgscolorscheme.h:175
QgsCompoundColorWidget::Layout
Layout
Widget layout.
Definition: qgscompoundcolorwidget.h:41
QgsCompoundColorWidget
Definition: qgscompoundcolorwidget.h:33
QgsCompoundColorWidget::LayoutVertical
@ LayoutVertical
Use a narrower, vertically stacked layout.
Definition: qgscompoundcolorwidget.h:44
QgsPanelWidget
Base class for any widget that can be shown as a inline panel.
Definition: qgspanelwidget.h:29
qgis_sip.h
QgsPanelWidget::keyPressEvent
void keyPressEvent(QKeyEvent *event) override
Overridden key press event to handle the esc event on the widget.
Definition: qgspanelwidget.cpp:112
QgsCompoundColorWidget::setDiscarded
void setDiscarded(bool discarded)
Sets whether the widget's color has been "discarded" and the selected color should not be stored in t...
Definition: qgscompoundcolorwidget.h:77
qgsguiutils.h
qgspanelwidget.h
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53