QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 "qgscolorrampimpl.h"
20 #include "qgis_sip.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 
101  void setSelectedStopColorSpec( QColor::Spec spec );
102 
108  void setSelectedStopDirection( Qgis::AngularDirection direction );
109 
117  void setSelectedStopDetails( const QColor &color, double offset );
118 
123  void deleteSelectedStop();
124 
131  void setColor1( const QColor &color );
132 
139  void setColor2( const QColor &color );
140 
141  signals:
142 
144  void changed();
145 
150  void selectedStopChanged( const QgsGradientStop &stop );
151 
152  protected:
153 
154  void mouseMoveEvent( QMouseEvent *event ) override;
155  void mousePressEvent( QMouseEvent *event ) override;
156  void mouseDoubleClickEvent( QMouseEvent *event ) override;
157  void keyPressEvent( QKeyEvent *event ) override;
158 
159  //Reimplemented to accept dragged colors
160  void dragEnterEvent( QDragEnterEvent *e ) override;
161 
162  //Reimplemented to accept dropped colors
163  void dropEvent( QDropEvent *e ) override;
164 
165  private:
166 
171  QPixmap transparentBackground();
172 
180  void drawStopMarker( QPainter &painter, QPoint topMiddle, const QColor &color, bool selected = false );
181 
183  double pointToRelativePosition( int x ) const;
184 
186  int relativePositionToPoint( double position ) const;
187 
189  bool selectedStopIsMovable() const;
190 
192  int findClosestStop( int x, int threshold = -1 ) const;
193 
194  QgsGradientColorRamp mGradient;
195 
197  QgsGradientStopsList mStops;
198 
200  int mSelectedStop = 0;
201 
203  QPolygonF sOuterTriangle;
204 
206  QPolygonF sInnerTriangle;
207 
208 };
209 
210 #endif // QGSGRADIENTSTOPEDITOR_H
qgscolorrampimpl.h
QgsGradientStopEditor::gradientRamp
QgsGradientColorRamp gradientRamp() const
Returns the current ramp created by the editor.
Definition: qgsgradientstopeditor.h:57
QgsGradientColorRamp
Gradient color ramp, which smoothly interpolates between two colors and also supports optional extra ...
Definition: qgscolorrampimpl.h:136
qgis_sip.h
QgsGradientStopsList
QList< QgsGradientStop > QgsGradientStopsList
List of gradient stops.
Definition: qgscolorrampimpl.h:122
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
QgsGradientStop
Represents a color stop within a QgsGradientColorRamp color ramp.
Definition: qgscolorrampimpl.h:38
QgsGradientStopEditor
An interactive editor for previewing a gradient color ramp and modifying the position of color stops ...
Definition: qgsgradientstopeditor.h:33
Qgis::AngularDirection
AngularDirection
Angular directions.
Definition: qgis.h:1635