Back to index

scribus-ng  1.3.4.dfsg+svn20071115
Public Types | Signals | Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes
ColorWheel Class Reference

Widget ColorWheel graphically shows a color wheel for color theory. More...

#include <colorwheelwidget.h>

List of all members.

Public Types

enum  MethodType {
  Monochromatic, Analogous, Complementary, Split,
  Triadic, Tetradic
}
 It can handle these color theory methods. More...

Signals

void clicked (int button, const QPoint &point)
 Signal raised by mouse click on widget by user.

Public Member Functions

 ColorWheel (QWidget *parent, const char *name=0)
 ~ColorWheel ()
QString getTypeDescription (MethodType aType)
 Returns localized name of the type.
ScColor colorByAngle (int angle)
 Get sample color from specifid angle.
void makeColors ()
 Call one of makeFoo() methods depending on the currentType value.
bool recomputeColor (ScColor col)
 Setup the values by given QColor.

Public Attributes

ScribusDoc * currentDoc
QString trBaseColor
 name of the "base color" to handle in extern color lists
colorModel currentColorSpace
 Which color model is in use.
MethodType currentType
 Actual type of color computing. See MethodType.
int angle
 Difference between selected value and counted ones.
int baseAngle
 Angle of the base color.
ScColor actualColor
 RGB interpretation of the leading point in the wheel.
ColorList colorList
 List of the colors created in this widget.

Protected Member Functions

void mouseReleaseEvent (QMouseEvent *e)
 An event for mouse actions handling.
void mousePressEvent (QMouseEvent *e)
 Mouse handling.
void mouseMoveEvent (QMouseEvent *e)
 Mouse handling.
void paintEvent (QPaintEvent *)
 Repaint the widget.
void makeMonochromatic ()
 Counts the monochromatic colors.
void makeAnalogous ()
 Counts the analogous colors.
void makeComplementary ()
 Counts the complementary colors.
void makeSplit ()
 Counts the split-complementary colors.
void makeTriadic ()
 Counts the triadic colors.
void makeTetradic ()
 Counts the tetradic colors.
void paintCenterSample ()
 Draw center circle filled with base color.
void paintWheel ()
 Draw a color wheel.
ScColor sampleByAngle (int angle)
 Appends a color into.
void baseColor ()
 Appends the base color into color list.
ScColor colorSpaceColor (ScColor col)
 Creates a Scribus ScColor from rgb value.
void drawBorderPoint (int angle, bool base=false, bool clear=false)
 Display user selection - selected colors.
void clearBorder ()
 Clear border marks before redrawing.
int valueFromPoint (const QPoint &p) const
 Counts an angle of the point in color wheel.

Protected Attributes

ColorMap colorMap
 Internal color mapping.
int angleShift
 Angle diff between colorMap and painted wheel itself.
int widthH
 Half of the widget sizes.
int heightH

Detailed Description

Widget ColorWheel graphically shows a color wheel for color theory.

Class ColorWheel is new widget inherited from the QLabel. See e.g. http://en.wikipedia.org/wiki/Color_wheel for more info.

Author:
Petr Vanek petr@.nosp@m.scri.nosp@m.bus.i.nosp@m.nfo
Date:
April 2005

Definition at line 29 of file colorwheelwidget.h.


Member Enumeration Documentation

It can handle these color theory methods.

Enumerator:
Monochromatic 
Analogous 
Complementary 
Split 
Triadic 
Tetradic 

Definition at line 38 of file colorwheelwidget.h.


Constructor & Destructor Documentation

ColorWheel::ColorWheel ( QWidget *  parent,
const char *  name = 0 
)

Definition at line 18 of file colorwheelwidget.cpp.

                                                          : QLabel(parent, name, WNoAutoErase)
{
       currentDoc = NULL;
       currentColorSpace = colorModelRGB;
       baseAngle = 0;
       angleShift = 270;
       widthH = heightH = 150;
       // create color map
       colorMap.clear();
       // fit the colorMap 1st value with matrix beginning
       int mapIndex = angleShift;
       for (int i = 0; i < 360; ++i)
       {
              QColor c;
              c.setHsv(i, 255, 255);
              ScColor col;
              col.fromQColor(c);
              colorMap[mapIndex++] = col;
              if (mapIndex > 359)
                     mapIndex = 0;
       }
       actualColor = colorMap[0];
       trBaseColor = tr("Base Color");
}

Here is the call graph for this function:

Definition at line 35 of file colorwheelwidget.h.

{};

Member Function Documentation

void ColorWheel::baseColor ( ) [protected]

Appends the base color into color list.

Definition at line 170 of file colorwheelwidget.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void ColorWheel::clearBorder ( ) [protected]

Clear border marks before redrawing.

It redraws only small piece of the bitmap

Definition at line 235 of file colorwheelwidget.cpp.

{
       for (int i = 0; i < 360; ++i)
              drawBorderPoint(i, false, true);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void ColorWheel::clicked ( int  button,
const QPoint &  point 
) [signal]

Signal raised by mouse click on widget by user.

Parameters:
buttonMouse button number. See Qt docs.
pointCoordinates of the mouse pointer.

Here is the caller graph for this function:

ScColor ColorWheel::colorByAngle ( int  angle)

Get sample color from specifid angle.

Parameters:
angleAngle of the color in the wheel. An angle for transformation counting. E.g. base angle is 30, param is 90 - transformation is 120. There is easy "convert 665485 into 0-359 interval" algorithm too.
Return values:
ScColorScribus color of the angle.

Definition at line 138 of file colorwheelwidget.cpp.

{
       while (angle > 359)
              angle -= 359;
       while (angle < 0)
              angle += 359;
       return colorSpaceColor(colorMap[angle]);
}

Here is the call graph for this function:

ScColor ColorWheel::colorSpaceColor ( ScColor  col) [protected]

Creates a Scribus ScColor from rgb value.

Its result depends on the currentColorSpace value.

Parameters:
cola ScColor to convert.
Return values:
ScColorScribus color structure

Definition at line 157 of file colorwheelwidget.cpp.

{
       QColor newcol;
       ScColor ret;
       int h, s, v;

       ScColorEngine::getRGBColor(col, currentDoc).getHsv(&h, &s, &v);
       newcol.setHsv(h, s, v);
       ret.fromQColor(newcol);
       ret = ScColorEngine::convertToModel(ret, currentDoc, currentColorSpace);
       return ret;
}

Here is the caller graph for this function:

void ColorWheel::drawBorderPoint ( int  angle,
bool  base = false,
bool  clear = false 
) [protected]

Display user selection - selected colors.

Chosen colors are marked via bullets on the border of the wheel.

Parameters:
angleangle of the drawed mark
baseDraw it highlighted if it is base color
clearDraw point with white = clear it from painter

Definition at line 241 of file colorwheelwidget.cpp.

{
       double r = 137.0;
       angle -= angleShift;
       double radang = M_PI * (double)angle/180.0;
       int x = (int)(r * cos(radang)) + widthH;
       int y = (int)(r * sin(radang)) + heightH;
       // draw border mark
       QPainter p;
       p.begin(this);
       if (clear)
       {
              p.setPen(QPen(Qt::white, 1));
              p.setBrush(Qt::white);
       }
       else
       {
              p.setPen(QPen(Qt::black, 1));
              if (base)
                     p.setBrush(Qt::red);
              else
                     p.setBrush(Qt::SolidPattern);
       }
       p.drawEllipse(x-4, y-4, 8, 8);
       p.end();
}

Here is the call graph for this function:

Here is the caller graph for this function:

Returns localized name of the type.

Parameters:
aTypeType of the color algorithm. See MethodType.
Return values:
QStringTranslated method name.

Definition at line 124 of file colorwheelwidget.cpp.

{
       switch (aType)
       {
              case Monochromatic: return tr("Monochromatic");
              case Analogous: return tr("Analogous");
              case Complementary: return tr("Complementary");
              case Split: return tr("Split Complementary");
              case Triadic: return tr("Triadic");
              case Tetradic: return tr("Tetradic (Double Complementary)");
       }
       return "n/a";
}

Here is the call graph for this function:

void ColorWheel::makeAnalogous ( ) [protected]

Counts the analogous colors.

The analogous color scheme uses colors that are changed by an angle in the color wheel. It looks richer than mono scheme.

Definition at line 193 of file colorwheelwidget.cpp.

{
       baseColor();
       colorList[tr("1st. Analogous")] = sampleByAngle(baseAngle + angle);
       colorList[tr("2nd. Analogous")] = sampleByAngle(baseAngle - angle);
       currentType = Analogous;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Call one of makeFoo() methods depending on the currentType value.

Definition at line 68 of file colorwheelwidget.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void ColorWheel::makeComplementary ( ) [protected]

Counts the complementary colors.

It takes two opposite colors (180 deg). It looks great when you choose a warm color against a cool one. E.g. dark green vs. wine red. Hmmm wine...

Definition at line 201 of file colorwheelwidget.cpp.

{
       baseColor();
       colorList[tr("Complementary")] = sampleByAngle(baseAngle + 180);
       currentType = Complementary;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void ColorWheel::makeMonochromatic ( ) [protected]

Counts the monochromatic colors.

The monochromatic color scheme uses variations in lightness and saturation of a single color. It's clean and elegant color schema. I like it's minimalism ;)

Definition at line 179 of file colorwheelwidget.cpp.

{
       baseColor();
       QColor col(ScColorEngine::getRGBColor(actualColor, currentDoc));
       ScColor l;
       l.fromQColor(col.light());
       l = ScColorEngine::convertToModel(l, currentDoc, currentColorSpace);
       colorList[tr("Monochromatic Light")] = l;
       l.fromQColor(col.dark());
       l = ScColorEngine::convertToModel(l, currentDoc, currentColorSpace);
       colorList[tr("Monochromatic Dark")] = l;
       currentType = Monochromatic;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void ColorWheel::makeSplit ( ) [protected]

Counts the split-complementary colors.

It's enthanced complementary method. It takes base and opposite colors with applied angle differences.

Definition at line 208 of file colorwheelwidget.cpp.

{
       baseColor();
       colorList[tr("1st. Split")] = sampleByAngle(baseAngle + angle);
       colorList[tr("2nd. Split")] = sampleByAngle(baseAngle - angle);
       colorList[tr("3rd. Split")] = sampleByAngle(baseAngle + 180 + angle);
       colorList[tr("4th. Split")] = sampleByAngle(baseAngle + 180 - angle);
       currentType = Split;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void ColorWheel::makeTetradic ( ) [protected]

Counts the tetradic colors.

It's two times complementary.

Definition at line 226 of file colorwheelwidget.cpp.

{
       baseColor();
       colorList[tr("1st. Tetradic (base opposite)")] = sampleByAngle(baseAngle + 180);
       colorList[tr("2nd. Tetradic (angle)")] = sampleByAngle(baseAngle + angle);
       colorList[tr("3rd. Tetradic (angle opposite)")] = sampleByAngle(baseAngle + angle + 180);
       currentType = Tetradic;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void ColorWheel::makeTriadic ( ) [protected]

Counts the triadic colors.

It takes three colors balanced on the wheel (by 120 grades).

Definition at line 218 of file colorwheelwidget.cpp.

{
       baseColor();
       colorList[tr("1st. Triadic")] = sampleByAngle(baseAngle + 120);
       colorList[tr("2nd. Triadic")] = sampleByAngle(baseAngle - 120);
       currentType = Triadic;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void ColorWheel::mouseMoveEvent ( QMouseEvent *  e) [protected]

Mouse handling.

It calls mouseReleaseEvent

Parameters:
eMouse properties.

Definition at line 48 of file colorwheelwidget.cpp.

Here is the call graph for this function:

void ColorWheel::mousePressEvent ( QMouseEvent *  e) [protected]

Mouse handling.

It calls mouseReleaseEvent

Parameters:
eMouse properties.

Definition at line 43 of file colorwheelwidget.cpp.

Here is the call graph for this function:

void ColorWheel::mouseReleaseEvent ( QMouseEvent *  e) [protected]

An event for mouse actions handling.

See

See also:
clicked() for more info.
Parameters:
eMouse properties.

Definition at line 53 of file colorwheelwidget.cpp.

{
       baseAngle = valueFromPoint(e->pos());
       actualColor = colorMap[baseAngle];
       actualColor = ScColorEngine::convertToModel(actualColor, currentDoc, currentColorSpace);
       emit clicked(e->button(), e->pos());
}

Here is the call graph for this function:

Here is the caller graph for this function:

void ColorWheel::paintCenterSample ( ) [protected]

Draw center circle filled with base color.

Definition at line 84 of file colorwheelwidget.cpp.

{
       QPainter p;
       p.begin(this);
       p.setPen(QPen(Qt::black, 2));
       p.setBrush(ScColorEngine::getDisplayColor(actualColor, currentDoc ));
       p.drawEllipse(widthH - 20, heightH - 20, 40, 40);
       p.end();
}

Here is the caller graph for this function:

void ColorWheel::paintEvent ( QPaintEvent *  ) [protected]

Repaint the widget.

It prevents the bugs with another window moving over it

Definition at line 61 of file colorwheelwidget.cpp.

Here is the call graph for this function:

void ColorWheel::paintWheel ( ) [protected]

Draw a color wheel.

Definition at line 94 of file colorwheelwidget.cpp.

{
       int h, s, v;
       QColor col(ScColorEngine::getDisplayColor(actualColor, currentDoc ));
       col.hsv(&h, &s, &v);
       int width = this->width();
       int height = this->height();
       QPainter p;
       p.begin(this);
       p.setWindow( 0, 0, width, height);
       p.fillRect(0, 0, width, height, Qt::white);
       p.setPen(Qt::black);
       p.drawRect(0, 0, width, height);
       // Half sizes
       heightH = height / 2;
       widthH = width / 2;
       for (int i = 0; i < 360; ++i)
       {
              QWMatrix matrix;
              matrix.translate(widthH, heightH);
              matrix.rotate((float)i);
              p.setWorldMatrix(matrix);
              QColor c;
              c.setHsv(i, 255, 255);
              p.setPen(QPen(c, 7));
              p.setBrush(c);
              p.drawLine(0, 0, 130, 0);
       }
}

Here is the caller graph for this function:

bool ColorWheel::recomputeColor ( ScColor  col)

Setup the values by given QColor.

It sets all options by given color (from input color dialogs).

Parameters:
colexamined color
Return values:
trueon color found, false when color not found - black or white etc.

Definition at line 290 of file colorwheelwidget.cpp.

{
       int origh, origs, origv;
       ColorMap::iterator it;
       QColor c(ScColorEngine::getRGBColor(col, currentDoc));
       QColor act(ScColorEngine::getRGBColor(actualColor, currentDoc));

       c.hsv(&origh, &origs, &origv);
       for (it = colorMap.begin(); it != colorMap.end(); ++it)
       {
              int tmph, tmps, tmpv;
              QColor col(ScColorEngine::getRGBColor(it.data(), currentDoc));
              col.hsv(&tmph, &tmps, &tmpv);
              if (origh == tmph)
              {
                     act.setHsv(tmph, origs, origv);
                     actualColor.fromQColor(act);
                     actualColor = ScColorEngine::convertToModel(actualColor, currentDoc, currentColorSpace);
                     baseAngle = it.key();
                     return true;
              }
       }
       return false;
}
ScColor ColorWheel::sampleByAngle ( int  angle) [protected]

Appends a color into.

See also:
colorList.
Parameters:
angleAngle of the color in the wheel. An angle for transformation counting. E.g. base angle is 30, param is 90 - transformation is 120. There is easy "convert 665485 into 0-359 interval" algorithm too.
Return values:
ScColorScribus color of the angle.

Definition at line 147 of file colorwheelwidget.cpp.

{
       while (angle > 359)
              angle -= 359;
       while (angle < 0)
              angle += 359;
       drawBorderPoint(angle);
       return colorSpaceColor(colorMap[angle]);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int ColorWheel::valueFromPoint ( const QPoint &  p) const [protected]

Counts an angle of the point in color wheel.

Modified method from Qt QDial widget.

Parameters:
pcoordinates of the point.
Return values:
intindex in the colorMap

Definition at line 268 of file colorwheelwidget.cpp.

{
       double yy = (double)heightH - (double)p.y();
       double xx = (double)p.x() - (double)widthH;
       double a = (xx || yy) ? atan2(yy, xx) : 0.0;

       if ( a < M_PI/-2 )
              a = a + M_PI * 2;

       int dist = 0;
       int minv = 0, maxv = 359;
       int r = maxv - minv;
       int val;

       val = (int)(0.5 + minv + r * (M_PI * 3/2 -a) / (2 * M_PI));

       if ( dist > 0 )
              val -= dist;

       return val;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

RGB interpretation of the leading point in the wheel.

Definition at line 69 of file colorwheelwidget.h.

Difference between selected value and counted ones.

Let's set angle = 15 and base point e.g. 60 (everything in grades). Now you will have Analogous angles 60 (base) and 75 (+15) and 45 (-15). Exact interpretation of the angle value depends on the MethodType value.

Definition at line 63 of file colorwheelwidget.h.

Angle diff between colorMap and painted wheel itself.

QWMatrix wheel and colorMap have different start points. It's taken from Qt.

Definition at line 111 of file colorwheelwidget.h.

Angle of the base color.

Definition at line 66 of file colorwheelwidget.h.

List of the colors created in this widget.

Colors can be added into Scribus color list later.

Definition at line 73 of file colorwheelwidget.h.

Internal color mapping.

It provides angle-color dictionary.

Definition at line 106 of file colorwheelwidget.h.

Which color model is in use.

Definition at line 53 of file colorwheelwidget.h.

Definition at line 47 of file colorwheelwidget.h.

Actual type of color computing. See MethodType.

Definition at line 56 of file colorwheelwidget.h.

int ColorWheel::heightH [protected]

Definition at line 116 of file colorwheelwidget.h.

name of the "base color" to handle in extern color lists

Definition at line 50 of file colorwheelwidget.h.

int ColorWheel::widthH [protected]

Half of the widget sizes.

To prevent all width()/2 divisions.

Definition at line 115 of file colorwheelwidget.h.


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