QGIS API Documentation  3.0.2-Girona (307d082)
qgsgradientstopeditor.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsgradientstopeditor.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 QGSGRADIENTSTOPEDITOR_H
17 #define QGSGRADIENTSTOPEDITOR_H
18 
19 #include "qgscolorramp.h"
20 #include "qgis.h"
21 #include <QWidget>
22 #include "qgis_gui.h"
23 
24 
33 class GUI_EXPORT QgsGradientStopEditor : public QWidget
34 {
35  Q_OBJECT
36 
37  public:
38 
44  QgsGradientStopEditor( QWidget *parent SIP_TRANSFERTHIS = nullptr, QgsGradientColorRamp *ramp = nullptr );
45 
51  void setGradientRamp( const QgsGradientColorRamp &ramp );
52 
57  QgsGradientColorRamp gradientRamp() const { return mGradient; }
58 
64  void selectStop( int index );
65 
70  QgsGradientStop selectedStop() const;
71 
72  QSize sizeHint() const override;
73  void paintEvent( QPaintEvent *event ) override;
74 
75  public slots:
76 
85  void setSelectedStopColor( const QColor &color );
86 
94  void setSelectedStopOffset( double offset );
95 
103  void setSelectedStopDetails( const QColor &color, double offset );
104 
109  void deleteSelectedStop();
110 
117  void setColor1( const QColor &color );
118 
125  void setColor2( const QColor &color );
126 
127  signals:
128 
130  void changed();
131 
136  void selectedStopChanged( const QgsGradientStop &stop );
137 
138  protected:
139 
140  void mouseMoveEvent( QMouseEvent *event ) override;
141  void mousePressEvent( QMouseEvent *event ) override;
142  void mouseDoubleClickEvent( QMouseEvent *event ) override;
143  void keyPressEvent( QKeyEvent *event ) override;
144 
145  //Reimplemented to accept dragged colors
146  void dragEnterEvent( QDragEnterEvent *e ) override;
147 
148  //Reimplemented to accept dropped colors
149  void dropEvent( QDropEvent *e ) override;
150 
151  private:
152 
157  QPixmap transparentBackground();
158 
166  void drawStopMarker( QPainter &painter, QPoint topMiddle, const QColor &color, bool selected = false );
167 
169  double pointToRelativePosition( int x ) const;
170 
172  int relativePositionToPoint( double position ) const;
173 
175  bool selectedStopIsMovable() const;
176 
178  int findClosestStop( int x, int threshold = -1 ) const;
179 
180  QgsGradientColorRamp mGradient;
181 
183  QgsGradientStopsList mStops;
184 
186  int mSelectedStop = 0;
187 
189  QPolygonF sOuterTriangle;
190 
192  QPolygonF sInnerTriangle;
193 
194 };
195 
196 #endif // QGSGRADIENTSTOPEDITOR_H
QgsGradientColorRamp gradientRamp() const
Returns the current ramp created by the editor.
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:46
Represents a color stop within a QgsGradientColorRamp color ramp.
Definition: qgscolorramp.h:101
An interactive editor for previewing a gradient color ramp and modifying the position of color stops ...
QList< QgsGradientStop > QgsGradientStopsList
List of gradient stops.
Definition: qgscolorramp.h:127
Gradient color ramp, which smoothly interpolates between two colors and also supports optional extra ...
Definition: qgscolorramp.h:139