QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 "qgsvectorcolorrampv2.h"
20 #include <QWidget>
21 
22 
30 class GUI_EXPORT QgsGradientStopEditor : public QWidget
31 {
32  Q_OBJECT
33 
34  public:
35 
40  QgsGradientStopEditor( QWidget* parent = nullptr, QgsVectorGradientColorRampV2* ramp = nullptr );
41 
46  void setGradientRamp( const QgsVectorGradientColorRampV2& ramp );
47 
51  QgsVectorGradientColorRampV2 gradientRamp() const { return mGradient; }
52 
57  void selectStop( int index );
58 
62  QgsGradientStop selectedStop() const;
63 
64  virtual QSize sizeHint() const override;
65  void paintEvent( QPaintEvent* event ) override;
66 
67  public slots:
68 
76  void setSelectedStopColor( const QColor& color );
77 
84  void setSelectedStopOffset( double offset );
85 
92  void setSelectedStopDetails( const QColor& color, double offset );
93 
97  void deleteSelectedStop();
98 
104  void setColor1( const QColor& color );
105 
111  void setColor2( const QColor& color );
112 
113  signals:
114 
116  void changed();
117 
121  void selectedStopChanged( const QgsGradientStop& stop );
122 
123  protected:
124 
125  virtual void mouseMoveEvent( QMouseEvent *event ) override;
126  virtual void mousePressEvent( QMouseEvent *event ) override;
127  virtual void mouseDoubleClickEvent( QMouseEvent * event ) override;
128  virtual void keyPressEvent( QKeyEvent * event ) override;
129 
130  //Reimplemented to accept dragged colors
131  void dragEnterEvent( QDragEnterEvent * e ) override;
132 
133  //Reimplemented to accept dropped colors
134  void dropEvent( QDropEvent *e ) override;
135 
136  private:
137 
141  const QPixmap& transparentBackground();
142 
149  void drawStopMarker( QPainter& painter, QPoint topMiddle, const QColor& color, bool selected = false );
150 
152  double pointToRelativePosition( int x ) const;
153 
155  int relativePositionToPoint( double position ) const;
156 
158  bool selectedStopIsMovable() const;
159 
161  int findClosestStop( int x, int threshold = -1 ) const;
162 
164 
166  QgsGradientStopsList mStops;
167 
169  int mSelectedStop;
170 
172  QPolygonF sOuterTriangle;
173 
175  QPolygonF sInnerTriangle;
176 
177 };
178 
179 #endif // QGSGRADIENTSTOPEDITOR_H
static unsigned index
virtual void dropEvent(QDropEvent *event)
Represents a color stop within a gradient color ramp.
An interactive editor for previewing a gradient color ramp and modifying the position of color stops ...
virtual void dragEnterEvent(QDragEnterEvent *event)
QgsVectorGradientColorRampV2 gradientRamp() const
Returns the current ramp created by the editor.
virtual void paintEvent(QPaintEvent *event)
virtual void mousePressEvent(QMouseEvent *event)
virtual void mouseMoveEvent(QMouseEvent *event)
virtual QSize sizeHint() const
virtual void mouseDoubleClickEvent(QMouseEvent *event)
virtual void keyPressEvent(QKeyEvent *event)
Gradient color ramp, which smoothly interpolates between two colors and also supports optional extra ...