Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
[FEATURE] New reusable interactive widget for editing gradient ramps
Supports: - drag to move color stops - double clicking to add a new stop - pressing delete will remove the selected stop - pressing arrow keys will move the selected stop, shift+arrow= larger move - drag and drop a color onto the widget to add a new stop Sponsored by North Road
- Loading branch information
1 parent
79f3d42
commit 881be0f
Showing
5 changed files
with
774 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/** \ingroup gui | ||
* \class QgsGradientStopEditor | ||
* An interactive editor for previewing a gradient color ramp and modifying the position of color | ||
* stops along the gradient. | ||
* \note Added in version 2.16 | ||
*/ | ||
|
||
class QgsGradientStopEditor : QWidget | ||
{ | ||
%TypeHeaderCode | ||
#include <qgsgradientstopeditor.h> | ||
%End | ||
|
||
public: | ||
|
||
/** Constructor for QgsGradientStopEditor. | ||
* @param parent parent widget | ||
* @param ramp optional initial gradient ramp | ||
*/ | ||
QgsGradientStopEditor( QWidget* parent /TransferThis/ = nullptr, QgsVectorGradientColorRampV2* ramp = nullptr ); | ||
|
||
/** Sets the current ramp shown in the editor. | ||
* @param ramp color ramp | ||
* @see gradientRamp() | ||
*/ | ||
void setGradientRamp( const QgsVectorGradientColorRampV2& ramp ); | ||
|
||
/** Returns the current ramp created by the editor. | ||
* @see setGradientRamp() | ||
*/ | ||
QgsVectorGradientColorRampV2 gradientRamp() const; | ||
|
||
/** Sets the currently selected stop. | ||
* @param index index of stop, where 0 corresponds to the first stop | ||
* @see selectedStop() | ||
*/ | ||
void selectStop( int index ); | ||
|
||
/** Returns details about the currently selected stop. | ||
* @see selectStop() | ||
*/ | ||
QgsGradientStop selectedStop() const; | ||
|
||
virtual QSize sizeHint() const; | ||
void paintEvent( QPaintEvent* event ); | ||
|
||
public slots: | ||
|
||
/** Sets the color for the current selected stop. | ||
* @param color new stop color | ||
* @see setSelectedStopOffset() | ||
* @see setSelectedStopDetails() | ||
* @see setColor1() | ||
* @see setColor2() | ||
*/ | ||
void setSelectedStopColor( const QColor& color ); | ||
|
||
/** Sets the offset for the current selected stop. This slot has no effect if either the | ||
* first or last stop is selected, as they cannot be repositioned. | ||
* @param offset new stop offset | ||
* @see setSelectedStopColor() | ||
* @see setSelectedStopDetails() | ||
*/ | ||
void setSelectedStopOffset( double offset ); | ||
|
||
/** Sets the color and offset for the current selected stop. | ||
* @param color new stop color | ||
* @param offset new stop offset | ||
* @see setSelectedStopColor() | ||
* @see setSelectedStopOffset() | ||
*/ | ||
void setSelectedStopDetails( const QColor& color, double offset ); | ||
|
||
/** Deletes the current selected stop. This slot has no effect if either the | ||
* first or last stop is selected, as they cannot be deleted. | ||
*/ | ||
void deleteSelectedStop(); | ||
|
||
/** Sets the color for the first stop. | ||
* @param color new stop color | ||
* @see setColor2() | ||
* @see setSelectedStopColor() | ||
*/ | ||
void setColor1( const QColor& color ); | ||
|
||
/** Sets the color for the last stop. | ||
* @param color new stop color | ||
* @see setColor1() | ||
* @see setSelectedStopColor() | ||
*/ | ||
void setColor2( const QColor& color ); | ||
|
||
signals: | ||
|
||
//! Emmitted when the gradient ramp is changed by a user | ||
void changed(); | ||
|
||
/** Emmitted when the current selected stop changes. | ||
* @param stop details about newly selected stop | ||
*/ | ||
void selectedStopChanged( const QgsGradientStop& stop ); | ||
|
||
protected: | ||
|
||
virtual void mouseMoveEvent( QMouseEvent *event ); | ||
virtual void mousePressEvent( QMouseEvent *event ); | ||
virtual void mouseDoubleClickEvent( QMouseEvent * event ); | ||
virtual void keyPressEvent( QKeyEvent * event ); | ||
|
||
//Reimplemented to accept dragged colors | ||
void dragEnterEvent( QDragEnterEvent * e ); | ||
|
||
//Reimplemented to accept dropped colors | ||
void dropEvent( QDropEvent *e ); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.