QGIS API Documentation 3.41.0-Master (3440c17df1d)
Loading...
Searching...
No Matches
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
32class GUI_EXPORT QgsGradientStopEditor : public QWidget
33{
34 Q_OBJECT
35
36 public:
37
43 QgsGradientStopEditor( QWidget *parent SIP_TRANSFERTHIS = nullptr, QgsGradientColorRamp *ramp = nullptr );
44
50 void setGradientRamp( const QgsGradientColorRamp &ramp );
51
56 QgsGradientColorRamp gradientRamp() const { return mGradient; }
57
63 void selectStop( int index );
64
69 QgsGradientStop selectedStop() const;
70
71 QSize sizeHint() const override;
72 void paintEvent( QPaintEvent *event ) override;
73
74 public slots:
75
84 void setSelectedStopColor( const QColor &color );
85
93 void setSelectedStopOffset( double offset );
94
100 void setSelectedStopColorSpec( QColor::Spec spec );
101
107 void setSelectedStopDirection( Qgis::AngularDirection direction );
108
116 void setSelectedStopDetails( const QColor &color, double offset );
117
122 void deleteSelectedStop();
123
130 void setColor1( const QColor &color );
131
138 void setColor2( const QColor &color );
139
140 signals:
141
143 void changed();
144
150
151 protected:
152
153 void mouseMoveEvent( QMouseEvent *event ) override;
154 void mousePressEvent( QMouseEvent *event ) override;
155 void mouseDoubleClickEvent( QMouseEvent *event ) override;
156 void keyPressEvent( QKeyEvent *event ) override;
157
158 //Reimplemented to accept dragged colors
159 void dragEnterEvent( QDragEnterEvent *e ) override;
160
161 //Reimplemented to accept dropped colors
162 void dropEvent( QDropEvent *e ) override;
163
164 private:
165
170 QPixmap transparentBackground();
171
179 void drawStopMarker( QPainter &painter, QPoint topMiddle, const QColor &color, bool selected = false );
180
182 double pointToRelativePosition( int x ) const;
183
185 int relativePositionToPoint( double position ) const;
186
188 bool selectedStopIsMovable() const;
189
191 int findClosestStop( int x, int threshold = -1 ) const;
192
193 QgsGradientColorRamp mGradient;
194
197
199 int mSelectedStop = 0;
200
202 QPolygonF sOuterTriangle;
203
205 QPolygonF sInnerTriangle;
206
207};
208
209#endif // QGSGRADIENTSTOPEDITOR_H
AngularDirection
Angular directions.
Definition qgis.h:3183
Gradient color ramp, which smoothly interpolates between two colors and also supports optional extra ...
An interactive editor for previewing a gradient color ramp and modifying the position of color stops ...
QgsGradientColorRamp gradientRamp() const
Returns the current ramp created by the editor.
void changed()
Emitted when the gradient ramp is changed by a user.
void selectedStopChanged(const QgsGradientStop &stop)
Emitted when the current selected stop changes.
Represents a color stop within a QgsGradientColorRamp color ramp.
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
QList< QgsGradientStop > QgsGradientStopsList
List of gradient stops.