Version: 9.15.0
QtxColorButton Class Reference

The QtxColorButton class implements a widget for color preference items editing. More...

#include <QtxColorButton.h>

Inheritance diagram for QtxColorButton:
Inheritance graph

Signals

void clicked (QColor)
 This signal is emitted when the widget button is clicked by the user. More...
 
void changed (QColor)
 This signal is emitted when the current color is changed. More...
 

Public Member Functions

 QtxColorButton (QWidget *=0)
 Constructor. More...
 
virtual ~QtxColorButton ()
 Destructor. More...
 
QColor color () const
 Get currently selected color. More...
 
void setColor (const QColor &)
 Set color. More...
 
bool eventFilter (QObject *, QEvent *)
 Filter events for the child widgets. More...
 
bool isAutoEnabled () const
 Returns the status of "auto" color button in popup widget. More...
 
void setAutoEnabled (bool)
 Enable/disable the "auto" color button in popup widget. More...
 
QString autoText () const
 Returns text of the "auto" color button in popup widget. More...
 
void setAutoText (const QString &)
 Sets text of the "auto" color button in popup widget. More...
 
QSize sizeHint () const
 Get size hint for this widget. More...
 

Protected Member Functions

virtual void paintEvent (QPaintEvent *)
 Customize paint event for the widget. More...
 

Private Types

typedef QMap< const QToolButton *, QColor > ColorMap
 

Private Slots

void onClicked (bool)
 Called when the button is clicked by the user. More...
 
void onToggled (bool)
 Called when any color selection button from popup menu is clicked. More...
 
void onAboutToShow ()
 Called when the popup menu is about to show. More...
 
void onAutoClicked (bool)
 Called the "Auto" child button from popup menu is clicked. More...
 
void onDialogClicked (bool)
 Called the "Other colors" child button from popup menu is clicked. More...
 

Private Member Functions

QList< QColor > colorsList () const
 Get predefined list of colors to be used in the popup menu. More...
 
void updateState ()
 Update widget state. More...
 
void updateButton (QToolButton *)
 Update child button state. More...
 
QPixmap buttonIcon (const QColor &) const
 Generate (if necessary) or get the icon for the button. More...
 
void drawColor (QPaintDevice *, const QColor &, const QColor &=Qt::black, const int=1) const
 Draw pixmap. More...
 

Private Attributes

ColorMap myColors
 
QToolButtonmyAutoButton
 

Detailed Description

The QtxColorButton class implements a widget for color preference items editing.

The color preference item is represented as the colored button with assocoiated popup menu whihc is called when the user presses the small arrow button near it. The popup menu allows selecting of the color from the predefined set. In addition it contains the button which invokes standard "Select color" dialog box.

Initial color value can be set with setColor() method. Chosen color can be retrieved with the color() method.

Member Typedef Documentation

◆ ColorMap

typedef QMap<const QToolButton*, QColor> QtxColorButton::ColorMap
private

Constructor & Destructor Documentation

◆ QtxColorButton()

QtxColorButton::QtxColorButton ( QWidget parent = 0)

◆ ~QtxColorButton()

QtxColorButton::~QtxColorButton ( )
virtual

Destructor.

Member Function Documentation

◆ autoText()

QString QtxColorButton::autoText ( ) const

Returns text of the "auto" color button in popup widget.

References myAutoButton.

◆ buttonIcon()

QPixmap QtxColorButton::buttonIcon ( const QColor &  c) const
private

Generate (if necessary) or get the icon for the button.

Parameters
ccolor to be used for the icon
Returns
icon pixmap for the button

References drawColor().

◆ changed

void QtxColorButton::changed ( QColor  color)
signal

This signal is emitted when the current color is changed.

Parameters
colornew current color

◆ clicked

void QtxColorButton::clicked ( QColor  color)
signal

This signal is emitted when the widget button is clicked by the user.

Parameters
colorcurrent color

◆ color()

QColor QtxColorButton::color ( ) const

Get currently selected color.

Returns null QColor if no color is selected.

Returns
selected color
See also
setColor()

References myColors.

◆ colorsList()

QList< QColor > QtxColorButton::colorsList ( ) const
private

Get predefined list of colors to be used in the popup menu.

Returns
list of colors

◆ drawColor()

void QtxColorButton::drawColor ( QPaintDevice *  pd,
const QColor &  c,
const QColor &  bc = Qt::black,
const int  m = 1 
) const
private

Draw pixmap.

Parameters
pdpaint device
ccolor
mmargin

◆ eventFilter()

bool QtxColorButton::eventFilter ( QObject o,
QEvent e 
)

Filter events for the child widgets.

Parameters
oevent receiver object
eevent
Returns
true if the event should be filtered

References updateButton().

◆ isAutoEnabled()

bool QtxColorButton::isAutoEnabled ( ) const

Returns the status of "auto" color button in popup widget.

Returns
true if the "auto" button is enabled

References myAutoButton.

◆ onAboutToShow

void QtxColorButton::onAboutToShow ( )
privateslot

Called when the popup menu is about to show.

Updates the menu and child widgets state.

References updateState().

◆ onAutoClicked

void QtxColorButton::onAutoClicked ( bool  )
privateslot

Called the "Auto" child button from popup menu is clicked.

Sets the undefined (auto) color as current.

Parameters
on(not used)

References setColor().

◆ onClicked

void QtxColorButton::onClicked ( bool  )
privateslot

Called when the button is clicked by the user.

Emits the signal clicked( QColor ).

Parameters
onbutton state (not used)

References clicked(), and color().

◆ onDialogClicked

void QtxColorButton::onDialogClicked ( bool  )
privateslot

Called the "Other colors" child button from popup menu is clicked.

Invokes standard "Select color" dialog box allowing user to select custom color. If the current color is changed by the user, emits the signal changed( QColor ).

Parameters
on(not used)

References changed(), color(), and setColor().

◆ onToggled

void QtxColorButton::onToggled ( bool  on)
privateslot

Called when any color selection button from popup menu is clicked.

Changes the currently selected color and emits the signal changed( QColor ).

Parameters
onbutton state

References changed(), color(), myColors, updateButton(), and updateState().

◆ paintEvent()

void QtxColorButton::paintEvent ( QPaintEvent *  e)
protectedvirtual

Customize paint event for the widget.

Parameters
epaint event

References color(), drawColor(), and isValid().

◆ setAutoEnabled()

void QtxColorButton::setAutoEnabled ( bool  on)

Enable/disable the "auto" color button in popup widget.

Parameters
onenable/disable state

References myAutoButton.

◆ setAutoText()

void QtxColorButton::setAutoText ( const QString &  txt)

Sets text of the "auto" color button in popup widget.

Parameters
txtnew button text

References myAutoButton.

◆ setColor()

void QtxColorButton::setColor ( const QColor &  c)

Set color.

Parameters
ccolor to be set as current
See also
color()

References myColors, updateButton(), and updateState().

◆ sizeHint()

QSize QtxColorButton::sizeHint ( ) const

Get size hint for this widget.

◆ updateButton()

void QtxColorButton::updateButton ( QToolButton btn)
private

Update child button state.

Parameters
btnchild button

References buttonIcon(), color(), and myColors.

◆ updateState()

void QtxColorButton::updateState ( )
private

Update widget state.

References updateButton().

Member Data Documentation

◆ myAutoButton

QToolButton* QtxColorButton::myAutoButton
private

◆ myColors

ColorMap QtxColorButton::myColors
private

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