QGIS API Documentation
2.4.0-Chugiak
|
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>
Public Slots | |
void | setButtonBackground () |
Sets the background pixmap for the button based upon set 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 | 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... | |
Private Attributes | |
QString | mColorDialogTitle |
QColor | mColor |
QColorDialog::ColorDialogOptions | mColorDialogOptions |
bool | mAcceptLiveUpdates |
QTemporaryFile | mTempPNG |
bool | mColorSet |
QPoint | mDragStartPosition |
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
Definition at line 31 of file qgscolorbutton.h.
QgsColorButton::QgsColorButton | ( | QWidget * | parent = 0 , |
QString | cdt = "" , |
||
QColorDialog::ColorDialogOptions | cdo = 0 |
||
) |
Construct a new color button.
parent | The parent QWidget for the dialog |
cdt | The title to show in the color chooser dialog |
cdo | Options for the color chooser dialog |
Definition at line 65 of file qgscolorbutton.cpp.
References onButtonClicked().
QgsColorButton::~QgsColorButton | ( | ) |
Definition at line 78 of file qgscolorbutton.cpp.
References mTempPNG.
|
inline |
Whether the button accepts live updates from QColorDialog.
Definition at line 104 of file qgscolorbutton.h.
|
protected |
Definition at line 274 of file qgscolorbutton.cpp.
References setButtonBackground().
QColor QgsColorButton::color | ( | ) | const |
Return the currently selected color.
Referenced by onButtonClicked(), and setColor().
|
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.
color | New color |
Referenced by setColor().
QColorDialog::ColorDialogOptions QgsColorButton::colorDialogOptions | ( | ) |
Returns the options for the color chooser dialog.
QString QgsColorButton::colorDialogTitle | ( | ) |
Returns the title, which the color chooser dialog shows.
|
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.
mimeData | mime data |
resultColor | QColor to store evaluated color |
Definition at line 137 of file qgscolorbutton.cpp.
References mColor, mColorDialogOptions, and QgsSymbolLayerV2Utils::parseColorWithAlpha().
Referenced by dragEnterEvent(), dropEvent(), and showContextMenu().
|
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.
Definition at line 129 of file qgscolorbutton.cpp.
References mColor.
Referenced by mouseMoveEvent(), and showContextMenu().
|
protected |
Reimplemented to accept dragged colors.
Definition at line 212 of file qgscolorbutton.cpp.
References colorFromMimeData().
|
protected |
Reimplemented to accept dropped colors.
Definition at line 222 of file qgscolorbutton.cpp.
References colorFromMimeData(), and setColor().
|
protected |
Reimplemented to allow dragging colors from button.
Definition at line 175 of file qgscolorbutton.cpp.
References createColorMimeData(), mColor, and mDragStartPosition.
|
protected |
Reimplemented to detect right mouse button clicks on the color button and allow dragging colors.
Definition at line 115 of file qgscolorbutton.cpp.
References mDragStartPosition, and showContextMenu().
|
privateslot |
Definition at line 94 of file qgscolorbutton.cpp.
References color(), QgsColorDialog::getLiveColor(), mAcceptLiveUpdates, mColorDialogOptions, mColorDialogTitle, and setValidColor().
Referenced by QgsColorButton().
|
inline |
Sets whether the button accepts live updates from QColorDialog.
Live updates may cause changes that are not undoable on QColorDialog cancel.
Definition at line 112 of file qgscolorbutton.h.
|
slot |
Sets the background pixmap for the button based upon set 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
Definition at line 324 of file qgscolorbutton.cpp.
References mColor, mColorDialogOptions, mTempPNG, and transpBkgrd().
Referenced by changeEvent(), 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.
color | the new color |
Definition at line 301 of file qgscolorbutton.cpp.
References color(), colorChanged(), mColor, mColorSet, and setButtonBackground().
Referenced by dropEvent(), setValidColor(), and showContextMenu().
void QgsColorButton::setColorDialogOptions | ( | QColorDialog::ColorDialogOptions | cdo | ) |
Specify the options for the color chooser dialog (e.g.
alpha).
cdo | Options for the color chooser dialog |
Definition at line 455 of file qgscolorbutton.cpp.
References mColorDialogOptions.
void QgsColorButton::setColorDialogTitle | ( | QString | cdt | ) |
Set the title, which the color chooser dialog will show.
cdt | Title for the color chooser dialog |
Definition at line 465 of file qgscolorbutton.cpp.
References mColorDialogTitle.
|
privateslot |
Sets color for button, if valid.
Definition at line 266 of file qgscolorbutton.cpp.
References setColor().
Referenced by onButtonClicked().
|
private |
Shows the color button context menu and handles copying and pasting color values.
Definition at line 233 of file qgscolorbutton.cpp.
References colorFromMimeData(), createColorMimeData(), setColor(), and tr.
Referenced by mousePressEvent().
|
protected |
Definition at line 295 of file qgscolorbutton.cpp.
References setButtonBackground().
|
staticprotected |
Definition at line 84 of file qgscolorbutton.cpp.
References QgsApplication::getThemePixmap().
Referenced by setButtonBackground().
|
private |
Definition at line 164 of file qgscolorbutton.h.
Referenced by onButtonClicked().
|
private |
Definition at line 162 of file qgscolorbutton.h.
Referenced by colorFromMimeData(), createColorMimeData(), mouseMoveEvent(), setButtonBackground(), and setColor().
|
private |
Definition at line 163 of file qgscolorbutton.h.
Referenced by colorFromMimeData(), onButtonClicked(), setButtonBackground(), and setColorDialogOptions().
|
private |
Definition at line 161 of file qgscolorbutton.h.
Referenced by onButtonClicked(), and setColorDialogTitle().
|
private |
Definition at line 166 of file qgscolorbutton.h.
Referenced by setColor().
|
private |
Definition at line 168 of file qgscolorbutton.h.
Referenced by mouseMoveEvent(), and mousePressEvent().
|
private |
Definition at line 165 of file qgscolorbutton.h.
Referenced by setButtonBackground(), and ~QgsColorButton().
|
readwrite |
Definition at line 35 of file qgscolorbutton.h.
|
readwrite |
Definition at line 36 of file qgscolorbutton.h.
|
readwrite |
Definition at line 38 of file qgscolorbutton.h.
|
readwrite |
Definition at line 34 of file qgscolorbutton.h.