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

A cross platform button subclass for selecting colors. Will open a color chooser dialog when clicked. Offers live updates to button from color chooser dialog. More...

#include <qgscolorbutton.h>

Inheritance diagram for QgsColorButton:
Inheritance graph
[legend]
Collaboration diagram for QgsColorButton:
Collaboration graph
[legend]

Public Slots

void setButtonBackground (QColor color=QColor())
 Sets the background pixmap for the button based upon color and transparency. More...
 

Signals

void colorChanged (const QColor &color)
 Is emitted, whenever a new color is accepted. More...
 

Public Member Functions

 QgsColorButton (QWidget *parent=0, QString cdt="", QColorDialog::ColorDialogOptions cdo=0)
 Construct a new color button. More...
 
 ~QgsColorButton ()
 
void setColor (const QColor &color)
 Specify the current color. More...
 
QColor color () const
 Return the currently selected color. More...
 
void setColorDialogOptions (QColorDialog::ColorDialogOptions cdo)
 Specify the options for the color chooser dialog (e.g. More...
 
QColorDialog::ColorDialogOptions colorDialogOptions ()
 Returns the options for the color chooser dialog. More...
 
void setColorDialogTitle (QString cdt)
 Set the title, which the color chooser dialog will show. More...
 
QString colorDialogTitle ()
 Returns the title, which the color chooser dialog shows. More...
 
bool acceptLiveUpdates ()
 Whether the button accepts live updates from QColorDialog. More...
 
void setAcceptLiveUpdates (bool accept)
 Sets whether the button accepts live updates from QColorDialog. More...
 

Protected Member Functions

void changeEvent (QEvent *e)
 
void showEvent (QShowEvent *e)
 
void mousePressEvent (QMouseEvent *e)
 Reimplemented to detect right mouse button clicks on the color button and allow dragging colors. More...
 
void mouseMoveEvent (QMouseEvent *e)
 Reimplemented to allow dragging colors from button. More...
 
void mouseReleaseEvent (QMouseEvent *e)
 Reimplemented to allow color picking. More...
 
void keyPressEvent (QKeyEvent *e)
 Reimplemented to allow cancelling color pick via keypress, and sample via space bar press. More...
 
void dragEnterEvent (QDragEnterEvent *e)
 Reimplemented to accept dragged colors. More...
 
void dropEvent (QDropEvent *e)
 Reimplemented to accept dropped colors. More...
 

Static Protected Member Functions

static const QPixmap & transpBkgrd ()
 

Properties

QString colorDialogTitle
 
bool acceptLiveUpdates
 
QColor color
 
QColorDialog::ColorDialogOptions colorDialogOptions
 

Private Slots

void onButtonClicked ()
 
void setValidColor (const QColor &newColor)
 Sets color for button, if valid. More...
 

Private Member Functions

void showContextMenu (QMouseEvent *event)
 Shows the color button context menu and handles copying and pasting color values. More...
 
QMimeData * createColorMimeData () const
 Creates mime data from the current color. More...
 
bool colorFromMimeData (const QMimeData *mimeData, QColor &resultColor)
 Attempts to parse mimeData as a color, either via the mime data's color data or by parsing a textual representation of a color. More...
 
void stopPicking (QPointF eventPos, bool sampleColor=true)
 Ends a color picking operation. More...
 

Private Attributes

QString mColorDialogTitle
 
QColor mColor
 
QColorDialog::ColorDialogOptions mColorDialogOptions
 
bool mAcceptLiveUpdates
 
QTemporaryFile mTempPNG
 
bool mColorSet
 
QPoint mDragStartPosition
 
bool mPickingColor
 

Detailed Description

A cross platform button subclass for selecting colors. Will open a color chooser dialog when clicked. Offers live updates to button from color chooser dialog.

A cross platform button subclass for selecting colors.

A subclass of QPushButton is needed to draw the button content because some platforms such as Mac OS X and Windows XP enforce a consistent GUI look by always using the button color of the current style and not allowing button backgrounds to be changed on a button by button basis. Therefore, a wholely stylesheet-based button is used for the no-text variant.

This class is a simplified version of QtColorButton, an internal class used by Qt Designer to do the same thing.

Will open a color chooser dialog when clicked. Offers live updates to button from color chooser dialog

Note
inherited base class moved from QToolButton to QPushButton in QGIS 1.9

Definition at line 31 of file qgscolorbutton.h.

Constructor & Destructor Documentation

QgsColorButton::QgsColorButton ( QWidget *  parent = 0,
QString  cdt = "",
QColorDialog::ColorDialogOptions  cdo = 0 
)

Construct a new color button.

Parameters
parentThe parent QWidget for the dialog
cdtThe title to show in the color chooser dialog
cdoOptions for the color chooser dialog
Note
changed in 1.9

Definition at line 67 of file qgscolorbutton.cpp.

References onButtonClicked().

QgsColorButton::~QgsColorButton ( )

Definition at line 81 of file qgscolorbutton.cpp.

References mTempPNG.

Member Function Documentation

bool QgsColorButton::acceptLiveUpdates ( )
inline

Whether the button accepts live updates from QColorDialog.

Note
added in 1.9

Definition at line 104 of file qgscolorbutton.h.

void QgsColorButton::changeEvent ( QEvent *  e)
protected

Definition at line 365 of file qgscolorbutton.cpp.

References setButtonBackground().

QColor QgsColorButton::color ( ) const

Return the currently selected color.

Returns
the currently selected color
Note
added in 1.9

Referenced by onButtonClicked(), and setColor().

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

Is emitted, whenever a new color is accepted.

The color is always valid. In case the new color is the same, no signal is emitted, to avoid infinite loops.

Parameters
colorNew color
Note
added in 1.9

Referenced by setColor().

QColorDialog::ColorDialogOptions QgsColorButton::colorDialogOptions ( )

Returns the options for the color chooser dialog.

Returns
Options for the color chooser dialog
Note
added in 1.9
QString QgsColorButton::colorDialogTitle ( )

Returns the title, which the color chooser dialog shows.

Returns
Title for the color chooser dialog
Note
added in 1.9
bool QgsColorButton::colorFromMimeData ( const QMimeData *  mimeData,
QColor &  resultColor 
)
private

Attempts to parse mimeData as a color, either via the mime data's color data or by parsing a textual representation of a color.

Returns
true if mime data could be intrepreted as a color
Parameters
mimeDatamime data
resultColorQColor to store evaluated color
Note
added in 2.3
See also
createColorMimeData

Definition at line 147 of file qgscolorbutton.cpp.

References mColor, mColorDialogOptions, and QgsSymbolLayerV2Utils::parseColorWithAlpha().

Referenced by dragEnterEvent(), dropEvent(), and showContextMenu().

QMimeData * QgsColorButton::createColorMimeData ( ) const
private

Creates mime data from the current color.

Sets both the mime data's color data, and the mime data's text with the color's hex code.

Note
added in 2.3
See also
colorFromMimeData

Definition at line 139 of file qgscolorbutton.cpp.

References mColor.

Referenced by mouseMoveEvent(), and showContextMenu().

void QgsColorButton::dragEnterEvent ( QDragEnterEvent *  e)
protected

Reimplemented to accept dragged colors.

Definition at line 285 of file qgscolorbutton.cpp.

References colorFromMimeData().

void QgsColorButton::dropEvent ( QDropEvent *  e)
protected

Reimplemented to accept dropped colors.

Definition at line 295 of file qgscolorbutton.cpp.

References colorFromMimeData(), and setColor().

void QgsColorButton::keyPressEvent ( QKeyEvent *  e)
protected

Reimplemented to allow cancelling color pick via keypress, and sample via space bar press.

Definition at line 272 of file qgscolorbutton.cpp.

References mPickingColor, and stopPicking().

void QgsColorButton::mouseMoveEvent ( QMouseEvent *  e)
protected

Reimplemented to allow dragging colors from button.

Definition at line 185 of file qgscolorbutton.cpp.

References createColorMimeData(), mColor, mDragStartPosition, mPickingColor, and setButtonBackground().

void QgsColorButton::mousePressEvent ( QMouseEvent *  e)
protected

Reimplemented to detect right mouse button clicks on the color button and allow dragging colors.

Definition at line 118 of file qgscolorbutton.cpp.

References mDragStartPosition, mPickingColor, and showContextMenu().

void QgsColorButton::mouseReleaseEvent ( QMouseEvent *  e)
protected

Reimplemented to allow color picking.

Definition at line 239 of file qgscolorbutton.cpp.

References mPickingColor, and stopPicking().

void QgsColorButton::onButtonClicked ( )
privateslot
void QgsColorButton::setAcceptLiveUpdates ( bool  accept)
inline

Sets whether the button accepts live updates from QColorDialog.

Live updates may cause changes that are not undoable on QColorDialog cancel.

Note
added in 1.9

Definition at line 112 of file qgscolorbutton.h.

void QgsColorButton::setButtonBackground ( QColor  color = QColor())
slot

Sets the background pixmap for the button based upon color and transparency.

Call directly to update background after adding/removing QColorDialog::ShowAlphaChannel option but the color has not changed, i.e. setColor() wouldn't update button and you want the button to retain the set color's alpha component regardless

Parameters
colorColor for button background
Note
added in 1.9

Definition at line 415 of file qgscolorbutton.cpp.

References mColor, mColorDialogOptions, mTempPNG, and transpBkgrd().

Referenced by changeEvent(), mouseMoveEvent(), setColor(), and showEvent().

void QgsColorButton::setColor ( const QColor &  color)

Specify the current color.

Will emit a colorChanged signal if the color is different to the previous.

Parameters
colorthe new color
Note
added in 1.9

Definition at line 392 of file qgscolorbutton.cpp.

References color(), colorChanged(), mColor, mColorSet, and setButtonBackground().

Referenced by dropEvent(), setValidColor(), QgsColorWidgetWrapper::setValue(), showContextMenu(), and stopPicking().

void QgsColorButton::setColorDialogOptions ( QColorDialog::ColorDialogOptions  cdo)

Specify the options for the color chooser dialog (e.g.

alpha).

Parameters
cdoOptions for the color chooser dialog
Note
added in 1.9

Definition at line 550 of file qgscolorbutton.cpp.

References mColorDialogOptions.

void QgsColorButton::setColorDialogTitle ( QString  cdt)

Set the title, which the color chooser dialog will show.

Parameters
cdtTitle for the color chooser dialog
Note
added in 1.9

Definition at line 560 of file qgscolorbutton.cpp.

References mColorDialogTitle.

void QgsColorButton::setValidColor ( const QColor &  newColor)
privateslot

Sets color for button, if valid.

Note
added in 1.9

Definition at line 357 of file qgscolorbutton.cpp.

References setColor().

Referenced by onButtonClicked().

void QgsColorButton::showContextMenu ( QMouseEvent *  event)
private

Shows the color button context menu and handles copying and pasting color values.

Definition at line 306 of file qgscolorbutton.cpp.

References colorFromMimeData(), createColorMimeData(), mPickingColor, sampler_cursor, setColor(), and tr.

Referenced by mousePressEvent().

void QgsColorButton::showEvent ( QShowEvent *  e)
protected

Definition at line 386 of file qgscolorbutton.cpp.

References setButtonBackground().

void QgsColorButton::stopPicking ( QPointF  eventPos,
bool  sampleColor = true 
)
private

Ends a color picking operation.

Parameters
eventPosglobal position of pixel to sample color from
sampleColorset to true to actually sample the color, false to just cancel the color picking operation
Note
added in 2.5

Definition at line 252 of file qgscolorbutton.cpp.

References mPickingColor, and setColor().

Referenced by keyPressEvent(), and mouseReleaseEvent().

const QPixmap & QgsColorButton::transpBkgrd ( )
staticprotected

Definition at line 87 of file qgscolorbutton.cpp.

References QgsApplication::getThemePixmap().

Referenced by setButtonBackground().

Member Data Documentation

bool QgsColorButton::mAcceptLiveUpdates
private

Definition at line 174 of file qgscolorbutton.h.

Referenced by onButtonClicked().

QColor QgsColorButton::mColor
private
QColorDialog::ColorDialogOptions QgsColorButton::mColorDialogOptions
private
QString QgsColorButton::mColorDialogTitle
private

Definition at line 171 of file qgscolorbutton.h.

Referenced by onButtonClicked(), and setColorDialogTitle().

bool QgsColorButton::mColorSet
private

Definition at line 176 of file qgscolorbutton.h.

Referenced by setColor().

QPoint QgsColorButton::mDragStartPosition
private

Definition at line 178 of file qgscolorbutton.h.

Referenced by mouseMoveEvent(), and mousePressEvent().

bool QgsColorButton::mPickingColor
private
QTemporaryFile QgsColorButton::mTempPNG
private

Definition at line 175 of file qgscolorbutton.h.

Referenced by setButtonBackground(), and ~QgsColorButton().

Property Documentation

bool QgsColorButton::acceptLiveUpdates
readwriteprivate

Definition at line 35 of file qgscolorbutton.h.

QColor QgsColorButton::color
readwriteprivate

Definition at line 36 of file qgscolorbutton.h.

Referenced by QgsColorWidgetWrapper::value().

QColorDialog::ColorDialogOptions QgsColorButton::colorDialogOptions
readwriteprivate

Definition at line 38 of file qgscolorbutton.h.

QString QgsColorButton::colorDialogTitle
readwriteprivate

Definition at line 34 of file qgscolorbutton.h.


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