QGIS API Documentation
3.16.0-Hannover (43b64b13f3)
|
A base class for interactive color widgets. More...
#include <qgscolorwidgets.h>
Public Types | |
enum | ColorComponent { Multiple = 0, Red, Green, Blue, Hue, Saturation, Value, Alpha } |
Specifies the color component which the widget alters. More... | |
Public Slots | |
virtual void | setColor (const QColor &color, bool emitSignals=false) |
Sets the color for the widget. More... | |
virtual void | setComponent (QgsColorWidget::ColorComponent component) |
Sets the color component which the widget controls. More... | |
virtual void | setComponentValue (int value) |
Alters the widget's color by setting the value for the widget's color component. More... | |
Signals | |
void | colorChanged (const QColor &color) |
Emitted when the widget's color changes. More... | |
void | hovered () |
Emitted when mouse hovers over widget. More... | |
Public Member Functions | |
QgsColorWidget (QWidget *parent=nullptr, ColorComponent component=Multiple) | |
Construct a new color widget. More... | |
QColor | color () const |
Returns the current color for the widget. More... | |
ColorComponent | component () const |
Returns the color component which the widget controls. More... | |
int | componentValue () const |
Returns the current value of the widget's color component. More... | |
Static Public Member Functions | |
static QPixmap | createDragIcon (const QColor &color) |
Create an icon for dragging colors. More... | |
Protected Member Functions | |
void | alterColor (QColor &color, QgsColorWidget::ColorComponent component, int newValue) const |
Alters a color by modifying the value of a specific color component. More... | |
int | componentRange () const |
Returns the range of valid values for the color widget's component. More... | |
int | componentRange (ColorComponent component) const |
Returns the range of valid values a color component. More... | |
int | componentValue (ColorComponent component) const |
Returns the value of a component of the widget's current color. More... | |
void | dragEnterEvent (QDragEnterEvent *e) override |
void | dropEvent (QDropEvent *e) override |
int | hue () const |
Returns the hue for the widget. More... | |
void | mouseMoveEvent (QMouseEvent *e) override |
void | mousePressEvent (QMouseEvent *e) override |
void | mouseReleaseEvent (QMouseEvent *e) override |
Static Protected Member Functions | |
static const QPixmap & | transparentBackground () |
Generates a checkboard pattern pixmap for use as a background to transparent colors. More... | |
Protected Attributes | |
ColorComponent | mComponent |
QColor | mCurrentColor |
int | mExplicitHue = 0 |
QColor wipes the hue information when it is ambiguous (e.g., for saturation = 0). More... | |
A base class for interactive color widgets.
Widgets can either allow setting a single component of a color (e.g., the red or green components), or an entire color. The QgsColorWidget also keeps track of any explicitly set hue for the color, so that this information is not lost when the widget is set to a color with an ambiguous hue (e.g., black or white shades).
Definition at line 39 of file qgscolorwidgets.h.
Specifies the color component which the widget alters.
Definition at line 48 of file qgscolorwidgets.h.
QgsColorWidget::QgsColorWidget | ( | QWidget * | parent = nullptr , |
ColorComponent | component = Multiple |
||
) |
Construct a new color widget.
parent | parent QWidget for the widget |
component | color component the widget alters |
Definition at line 43 of file qgscolorwidgets.cpp.
|
protected |
Alters a color by modifying the value of a specific color component.
color | color to alter |
component | color component to alter |
newValue | new value of color component. Values are automatically clipped to a valid range for the color component. |
Definition at line 142 of file qgscolorwidgets.cpp.
QColor QgsColorWidget::color | ( | ) | const |
Returns the current color for the widget.
Definition at line 244 of file qgscolorwidgets.cpp.
|
signal |
Emitted when the widget's color changes.
color | new widget color |
|
inline |
Returns the color component which the widget controls.
Definition at line 79 of file qgscolorwidgets.h.
|
protected |
Returns the range of valid values for the color widget's component.
Definition at line 105 of file qgscolorwidgets.cpp.
|
protected |
Returns the range of valid values a color component.
Definition at line 110 of file qgscolorwidgets.cpp.
int QgsColorWidget::componentValue | ( | ) | const |
Returns the current value of the widget's color component.
Definition at line 51 of file qgscolorwidgets.cpp.
|
protected |
Returns the value of a component of the widget's current color.
This method correctly handles hue values when the color has an ambiguous hue (e.g., black or white shades)
component | color component to return |
Definition at line 76 of file qgscolorwidgets.cpp.
|
static |
Create an icon for dragging colors.
color | for icon |
Definition at line 56 of file qgscolorwidgets.cpp.
|
overrideprotected |
Definition at line 188 of file qgscolorwidgets.cpp.
|
overrideprotected |
Definition at line 201 of file qgscolorwidgets.cpp.
|
signal |
Emitted when mouse hovers over widget.
|
protected |
Returns the hue for the widget.
This may differ from the hue for the QColor returned by color(), as QColor returns a hue of -1 if the color's hue is ambiguous (e.g., if the saturation is zero).
Definition at line 130 of file qgscolorwidgets.cpp.
|
overrideprotected |
Definition at line 225 of file qgscolorwidgets.cpp.
|
overrideprotected |
Definition at line 232 of file qgscolorwidgets.cpp.
|
overrideprotected |
Definition at line 238 of file qgscolorwidgets.cpp.
|
virtualslot |
Sets the color for the widget.
color | widget color |
emitSignals | set to true to emit the colorChanged signal after setting color |
Reimplemented in QgsColorTextWidget, and QgsColorSliderWidget.
Definition at line 342 of file qgscolorwidgets.cpp.
|
virtualslot |
Sets the color component which the widget controls.
component | color component for widget |
Reimplemented in QgsColorSliderWidget, and QgsColorBox.
Definition at line 249 of file qgscolorwidgets.cpp.
|
virtualslot |
Alters the widget's color by setting the value for the widget's color component.
value | value for widget's color component. This value is automatically clipped to the range of valid values for the color component. |
Reimplemented in QgsColorSliderWidget.
Definition at line 260 of file qgscolorwidgets.cpp.
|
staticprotected |
Generates a checkboard pattern pixmap for use as a background to transparent colors.
Definition at line 178 of file qgscolorwidgets.cpp.
|
protected |
Definition at line 142 of file qgscolorwidgets.h.
|
protected |
Definition at line 140 of file qgscolorwidgets.h.
|
protected |
QColor wipes the hue information when it is ambiguous (e.g., for saturation = 0).
So the hue is stored in mExplicit hue to keep it around, as it is useful when modifying colors
Definition at line 148 of file qgscolorwidgets.h.