QGIS API Documentation  2.7.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Public Types | Public Slots | Signals | Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
QgsColorWidget Class Reference

A base class for interactive color widgets. More...

#include <qgscolorwidgets.h>

Inheritance diagram for QgsColorWidget:
Inheritance graph
[legend]

Public Types

enum  ColorComponent {
  Multiple = 0, Red, Green, Blue,
  Hue, Saturation, Value, Alpha
}
 

Public Slots

virtual void setColor (const QColor &color, const bool emitSignals=false)
 Sets the color for the widget. More...
 
virtual void setComponent (const ColorComponent component)
 Sets the color component which the widget controls. More...
 
virtual void setComponentValue (const 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...
 

Public Member Functions

 QgsColorWidget (QWidget *parent=0, const ColorComponent component=Multiple)
 Construct a new color widget. More...
 
virtual ~QgsColorWidget ()
 
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, const QgsColorWidget::ColorComponent component, const int newValue) const
 Alters a color by modifiying 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 (const ColorComponent component) const
 Returns the range of valid values a color component. More...
 
int componentValue (const ColorComponent component) const
 Returns the value of a component of the widget's current color. More...
 
void dragEnterEvent (QDragEnterEvent *e)
 
void dropEvent (QDropEvent *e)
 
int hue () const
 Returns the hue for the widget. More...
 

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
 QColor wipes the hue information when it is ambiguous (eg, for saturation = 0). More...
 

Detailed Description

A base class for interactive color widgets.

Widgets can either allow setting a single component of a color (eg the red or green components), or an entire color. The QgsColorWidget also keeps track of any explicitely set hue for the color, so that this information is not lost when the widget is set to a color with an ambiguous hue (eg black or white shades).

Note
Added in version 2.5

Definition at line 35 of file qgscolorwidgets.h.

Member Enumeration Documentation

Specifies the color component which the widget alters

Enumerator
Multiple 

widget alters multiple color components

Red 

red component of color

Green 

green component of color

Blue 

blue component of color

Hue 

hue component of color (based on HSV model)

Saturation 

saturation component of color (based on HSV model)

Value 

value component of color (based on HSV model)

Alpha 

alpha component (opacity) of color

Definition at line 43 of file qgscolorwidgets.h.

Constructor & Destructor Documentation

QgsColorWidget::QgsColorWidget ( QWidget *  parent = 0,
const ColorComponent  component = Multiple 
)

Construct a new color widget.

Parameters
parentparent QWidget for the widget
componentcolor component the widget alters

Definition at line 36 of file qgscolorwidgets.cpp.

QgsColorWidget::~QgsColorWidget ( )
virtual

Definition at line 45 of file qgscolorwidgets.cpp.

Member Function Documentation

void QgsColorWidget::alterColor ( QColor &  color,
const QgsColorWidget::ColorComponent  component,
const int  newValue 
) const
protected

Alters a color by modifiying the value of a specific color component.

Parameters
colorcolor to alter
componentcolor component to alter
newValuenew value of color component. Values are automatically clipped to a valid range for the color component.

Definition at line 140 of file qgscolorwidgets.cpp.

QColor QgsColorWidget::color ( void  ) const

Returns the current color for the widget.

Returns
current widget color
See also
setColor

Definition at line 223 of file qgscolorwidgets.cpp.

void QgsColorWidget::colorChanged ( const QColor &  color)
signal

Emitted when the widget's color changes.

Parameters
colornew widget color
ColorComponent QgsColorWidget::component ( ) const
inline

Returns the color component which the widget controls.

Returns
color component for widget
See also
setComponent

Definition at line 73 of file qgscolorwidgets.h.

int QgsColorWidget::componentRange ( ) const
protected

Returns the range of valid values for the color widget's component.

Returns
maximum value allowed for color component, or -1 if widget has multiple components

Definition at line 103 of file qgscolorwidgets.cpp.

int QgsColorWidget::componentRange ( const ColorComponent  component) const
protected

Returns the range of valid values a color component.

Returns
maximum value allowed for color component

Definition at line 108 of file qgscolorwidgets.cpp.

int QgsColorWidget::componentValue ( ) const

Returns the current value of the widget's color component.

Returns
value of color component, or -1 if widget has multiple components or an invalid color set
See also
setComponentValue
component

Definition at line 50 of file qgscolorwidgets.cpp.

int QgsColorWidget::componentValue ( const ColorComponent  component) const
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 (eg black or white shades)

Parameters
componentcolor component to return
Returns
value of color component, or -1 if widget has an invalid color set
See also
hue

Definition at line 74 of file qgscolorwidgets.cpp.

QPixmap QgsColorWidget::createDragIcon ( const QColor &  color)
static

Create an icon for dragging colors.

Parameters
colorfor icon

Definition at line 55 of file qgscolorwidgets.cpp.

void QgsColorWidget::dragEnterEvent ( QDragEnterEvent *  e)
protected

Definition at line 186 of file qgscolorwidgets.cpp.

void QgsColorWidget::dropEvent ( QDropEvent *  e)
protected

Definition at line 199 of file qgscolorwidgets.cpp.

int QgsColorWidget::hue ( ) const
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 (eg, if the saturation is zero).

Returns
explicitly set hue for widget

Definition at line 128 of file qgscolorwidgets.cpp.

void QgsColorWidget::setColor ( const QColor &  color,
const bool  emitSignals = false 
)
virtualslot

Sets the color for the widget.

Parameters
colorwidget color
emitSignalsset to true to emit the colorChanged signal after setting color
See also
color

Reimplemented in QgsColorTextWidget, and QgsColorSliderWidget.

Definition at line 321 of file qgscolorwidgets.cpp.

void QgsColorWidget::setComponent ( const ColorComponent  component)
virtualslot

Sets the color component which the widget controls.

Parameters
componentcolor component for widget
See also
component

Reimplemented in QgsColorSliderWidget, and QgsColorBox.

Definition at line 228 of file qgscolorwidgets.cpp.

void QgsColorWidget::setComponentValue ( const int  value)
virtualslot

Alters the widget's color by setting the value for the widget's color component.

Parameters
valuevalue for widget's color component. This value is automatically clipped to the range of valid values for the color component.
See also
componentValue
setComponent
Note
this method has no effect if the widget is set to the QgsColorWidget::Multiple component

Reimplemented in QgsColorSliderWidget.

Definition at line 239 of file qgscolorwidgets.cpp.

const QPixmap & QgsColorWidget::transparentBackground ( )
staticprotected

Generates a checkboard pattern pixmap for use as a background to transparent colors.

Returns
checkerboard pixmap

Definition at line 176 of file qgscolorwidgets.cpp.

Member Data Documentation

ColorComponent QgsColorWidget::mComponent
protected

Definition at line 124 of file qgscolorwidgets.h.

QColor QgsColorWidget::mCurrentColor
protected

Definition at line 122 of file qgscolorwidgets.h.

int QgsColorWidget::mExplicitHue
protected

QColor wipes the hue information when it is ambiguous (eg, 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 129 of file qgscolorwidgets.h.


The documentation for this class was generated from the following files: