[KLF Backend][KLF Tools][KLF Home]
KLatexFormula Project
Protected Member Functions | Static Protected Member Functions | Protected Attributes
KLFColorComponentsEditorBase Class Reference

Base utility class that stores and calculates specific components of a color that is being edited. More...

#include <klfcolorchooser.h>

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

List of all members.

Protected Member Functions

int valueAFromNewColor (const QColor &color) const
int valueBFromNewColor (const QColor &color) const
int valueA () const
int valueB () const
int valueAMax () const
int valueBMax () const
QColor colorFromValues (QColor color_base, int value_a, int value_b=-1)
bool refreshColorFromInternalValues (int value_a, int value_b=-1)

Static Protected Member Functions

static int valueFromNewColor (const QColor &color, const QString &component)
static int valueMax (const QString &component)

Protected Attributes

QColor _color
QString _colorcomponent
QString _colorcomponent_b

Detailed Description

Base utility class that stores and calculates specific components of a color that is being edited.

Example: a Red: [...] spin-box would have to calculate the red component of a newly set color, while a Saturation: (.............) slider would have to calculate the same, but for the saturation value.

This class is a base class that stores a color one (respectively two) components are being edited in a widget subclass. This class also provides some utilities to calculate the component values from a color and vice versa.

An editor is assumed to handle at most two components of a color (labels A and B indicate respectively the first edited component and the second edited component). If the editor can edit only one component (eg. spin-box), then the second component is set to the special component "fix" and ignored by this class.

The subclasses have to set _colorcomponent (component A) and _colorcomponent_b (component B) directly, for example in their constructor.

Valid components are: "hue", "sat", "val", "red", "green", "blue", "alpha", and "fix". "fix" should be used when the component is not used (eg. 2nd component of a 1-D slider). Components are case sensitive (all lower case).

This class assumes that the editor subclass will be displayed in conjunction with other similar editors, also KLFColorComponentsEditorBase subclasses (eg. a list of spin boxes to edit each component of a color). It is therefore important to synchronize the various editors, because the information that is displayed is redundant: for example red, green, blue editors may be displayed simultaniously next to hue, saturation, and value editors. When for example the red component is changed, then the saturation, value and hue will have to update.

In the setup above, when one of the editors has its value changed, that editor that changed should calculate the new color using refreshColorFromInternalValues() with the new component value(s), and notify the other editors (eg. with signal-slot connections) of the change (note that the return value of refreshColorFromInternalValues() indicates whether the color changed). All the other editors should then calculate their new component values (with valueAFromNewColor() and valueBFromNewColor() to get the values for component A and B respectively) and display those values.

Note that all editors (in the setup described above) store independently the current color in their _color member. Eventually the color may be obtained by querying any of the editors.

Note that both components may be set to "fix", for example for a widget that just displays the current color (this is no longer an editor!).

Definition at line 143 of file klfcolorchooser.h.


Member Function Documentation

QColor KLFColorComponentsEditorBase::colorFromValues ( QColor  color_base,
int  value_a,
int  value_b = -1 
) [protected]

Calculate the color that we get when in color_base, we set the component A value to value_a and component B to value_b.

Example, with component A being red and component B being blue:

 colorFromValues(QColor(120, 60, 44), 10, 33)   ==   QColor(10, 60, 33)

This example is somewhat trivial in that the displayed components are independant. However this function can also handle the case when the components are not independant, eg. component A being saturation and B being red.

Example with A being Hue ("hue") and with B unused ("fix"):

 colorFromValues(QColor(20, 90, 120), 110)   ==   QColor(37, 120, 20)

Definition at line 450 of file klfcolorchooser.cpp.

References _colorcomponent, _colorcomponent_b, QColor::alpha(), QColor::blue(), QByteArray::constData(), QColor::green(), QColor::hue(), QString::isEmpty(), QColor::red(), QColor::saturation(), QColor::setAlpha(), QColor::setHsv(), QColor::setRgb(), QString::toLocal8Bit(), and QColor::value().

Referenced by KLFColorChooseWidgetPane::keyPressEvent(), KLFColorChooseWidgetPane::mouseMoveEvent(), KLFColorChooseWidgetPane::mousePressEvent(), KLFColorChooseWidgetPane::paintEvent(), refreshColorFromInternalValues(), and KLFColorChooseWidgetPane::wheelEvent().

bool KLFColorComponentsEditorBase::refreshColorFromInternalValues ( int  value_a,
int  value_b = -1 
) [protected]

Calls colorFromValues() with the given values and with the current _color, and sets _color to the returned value.

Returns:
TRUE if the color changed, FALSE otherwise.

Definition at line 511 of file klfcolorchooser.cpp.

References _color, and colorFromValues().

int KLFColorComponentsEditorBase::valueA ( ) const [inline, protected]

Returns the current value of component A in the color being edited (_color)

Definition at line 151 of file klfcolorchooser.h.

Referenced by KLFColorChooseWidgetPane::keyPressEvent(), KLFColorChooseWidgetPane::paintEvent(), and KLFColorChooseWidgetPane::wheelEvent().

int KLFColorComponentsEditorBase::valueAFromNewColor ( const QColor color) const [protected]

Returns the value of component A in the color color

Definition at line 402 of file klfcolorchooser.cpp.

References _colorcomponent, and valueFromNewColor().

Referenced by KLFColorComponentSpinBox::KLFColorComponentSpinBox(), and KLFColorComponentSpinBox::setColor().

int KLFColorComponentsEditorBase::valueAMax ( ) const [inline, protected]
int KLFColorComponentsEditorBase::valueB ( ) const [inline, protected]

Returns the current value of component B in the color being edited (_color)

Definition at line 153 of file klfcolorchooser.h.

Referenced by KLFColorChooseWidgetPane::keyPressEvent(), KLFColorChooseWidgetPane::paintEvent(), and KLFColorChooseWidgetPane::wheelEvent().

int KLFColorComponentsEditorBase::valueBFromNewColor ( const QColor color) const [protected]

Returns the value of component B in the color color

Definition at line 406 of file klfcolorchooser.cpp.

References _colorcomponent_b, and valueFromNewColor().

int KLFColorComponentsEditorBase::valueBMax ( ) const [inline, protected]
int KLFColorComponentsEditorBase::valueFromNewColor ( const QColor color,
const QString component 
) [static, protected]
int KLFColorComponentsEditorBase::valueMax ( const QString component) [static, protected]

Returns the Maximum value the given component may be assigned. This is 359 for hue, 255 for others except 'fix', for which it is -1.

Note that for all (valid) componenets minimum value is zero.

Definition at line 435 of file klfcolorchooser.cpp.

References QByteArray::constData(), QString::isEmpty(), and QString::toLocal8Bit().


Member Data Documentation


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

Generated by doxygen 1.7.6.1. The KLatexFormula website is hosted on sourceforge.net