[KLF Backend][KLF Tools][KLF Home]
KLatexFormula Project
QtColorTriangle Class Reference

The QtColorTriangle class provides a triangular color selection widget. More...

#include <qtcolortriangle.h>

Inheritance diagram for QtColorTriangle:
Collaboration diagram for QtColorTriangle:

Public Slots

void setColor (const QColor &col)

Signals

void colorChanged (const QColor &col)

Public Member Functions

 QtColorTriangle (QWidget *parent=0)
 ~QtColorTriangle ()
QSize sizeHint () const
int heightForWidth (int w) const
void polish ()
QColor color () const

Protected Member Functions

void paintEvent (QPaintEvent *)
void mouseMoveEvent (QMouseEvent *)
void mousePressEvent (QMouseEvent *)
void mouseReleaseEvent (QMouseEvent *)
void keyPressEvent (QKeyEvent *e)
void resizeEvent (QResizeEvent *)
void drawTrigon (QImage *p, const QPointF &a, const QPointF &b, const QPointF &c, const QColor &color)
void internalSetNewColor (const QColor &color)

Properties

QColor color

Detailed Description

The QtColorTriangle class provides a triangular color selection widget.

This widget uses the HSV color model, and is therefore useful for selecting colors by eye.

The triangle in the center of the widget is used for selecting saturation and value, and the surrounding circle is used for selecting hue.

Use setColor() and color() to set and get the current color.

Definition at line 79 of file qtcolortriangle.h.

Constructor & Destructor Documentation

◆ QtColorTriangle()

QtColorTriangle::QtColorTriangle ( QWidget * parent = 0)

Constructs a color triangle widget with the given parent.

Definition at line 140 of file qtcolortriangle.cpp.

References setColor(), QColor::setHsv(), and sizeHint().

◆ ~QtColorTriangle()

QtColorTriangle::~QtColorTriangle ( )

Destructs the color triangle.

Definition at line 156 of file qtcolortriangle.cpp.

Member Function Documentation

◆ color()

QColor QtColorTriangle::color ( ) const

Returns the current color of the triangle.

Definition at line 864 of file qtcolortriangle.cpp.

◆ colorChanged

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

Whenever the color triangles color changes this signal is emitted with the new color.

References color, drawTrigon(), internalSetNewColor(), keyPressEvent(), mouseMoveEvent(), mousePressEvent(), mouseReleaseEvent(), paintEvent(), resizeEvent(), and setColor().

Referenced by internalSetNewColor().

◆ drawTrigon()

void QtColorTriangle::drawTrigon ( QImage * buf,
const QPointF & pa,
const QPointF & pb,
const QPointF & pc,
const QColor & color )
protected

Draws a trigon (polygon with three corners pa, pb and pc and three edges), using painter.

Fills the trigon with a gradient, where the pa point has the color color, pb is black and bc is white. Bilinear gradient.

Definition at line 620 of file qtcolortriangle.cpp.

References color, QVarLengthArray::resize(), QImage::scanLine(), QPointF::x(), and QPointF::y().

Referenced by colorChanged(), and paintEvent().

◆ heightForWidth()

int QtColorTriangle::heightForWidth ( int w) const

Forces the triangle widget to always be square. Returns the value w.

Definition at line 203 of file qtcolortriangle.cpp.

◆ internalSetNewColor()

void QtColorTriangle::internalSetNewColor ( const QColor & color)
protected

Definition at line 604 of file qtcolortriangle.cpp.

References color, and colorChanged().

Referenced by colorChanged(), mouseMoveEvent(), mousePressEvent(), and setColor().

◆ keyPressEvent()

void QtColorTriangle::keyPressEvent ( QKeyEvent * e)
protected

Definition at line 443 of file qtcolortriangle.cpp.

References QKeyEvent::key(), QKeyEvent::modifiers(), setColor(), and QColor::setHsv().

Referenced by colorChanged().

◆ mouseMoveEvent()

void QtColorTriangle::mouseMoveEvent ( QMouseEvent * e)
protected

Selects new hue or saturation/value values, depending on where the mouse button was pressed initially.

Definition at line 271 of file qtcolortriangle.cpp.

References QMouseEvent::buttons(), QColor::getHsv(), internalSetNewColor(), PI, QMouseEvent::pos(), TWOPI, QPoint::x(), QPointF::x(), QPoint::y(), and QPointF::y().

Referenced by colorChanged().

◆ mousePressEvent()

void QtColorTriangle::mousePressEvent ( QMouseEvent * e)
protected

When the left mouse button is pressed, this function determines what part of the color triangle the cursor is, and from that it initiates either selecting the hue (outside the triangle's area) or the saturation/value (inside the triangle's area).

Definition at line 352 of file qtcolortriangle.cpp.

References QMouseEvent::button(), internalSetNewColor(), PI, QMouseEvent::pos(), QColor::setAlpha(), TWOPI, QPoint::x(), QPointF::x(), QPoint::y(), and QPointF::y().

Referenced by colorChanged().

◆ mouseReleaseEvent()

void QtColorTriangle::mouseReleaseEvent ( QMouseEvent * e)
protected

Stops selecting of colors with the mouse.

Definition at line 434 of file qtcolortriangle.cpp.

References QMouseEvent::button().

Referenced by colorChanged().

◆ paintEvent()

void QtColorTriangle::paintEvent ( QPaintEvent * e)
protected

(reimplemented)

First copies a background image of the hue donut and its background color onto the frame, then draws the color triangle, and finally the selectors.

Definition at line 538 of file qtcolortriangle.cpp.

References QImage::copy(), QPainter::drawEllipse(), QPainter::drawLine(), QPainter::drawPixmap(), drawTrigon(), QPixmap::fromImage(), QColor::getRgb(), QRegion::intersected(), QRect::intersects(), QPaintEvent::rect(), QPaintEvent::region(), QPainter::setClipRegion(), QColor::setHsv(), QPainter::setPen(), and QPainter::setRenderHint().

Referenced by colorChanged().

◆ polish()

void QtColorTriangle::polish ( )

Generates the first background image.

Definition at line 165 of file qtcolortriangle.cpp.

◆ resizeEvent()

void QtColorTriangle::resizeEvent ( QResizeEvent * )
protected

Regenerates the background image and sends an update.

Definition at line 504 of file qtcolortriangle.cpp.

Referenced by colorChanged().

◆ setColor

void QtColorTriangle::setColor ( const QColor & col)
slot

Sets the color of the triangle to col.

Definition at line 820 of file qtcolortriangle.cpp.

References QColor::getHsv(), internalSetNewColor(), PI, and TWOPI.

Referenced by colorChanged(), keyPressEvent(), and QtColorTriangle().

◆ sizeHint()

QSize QtColorTriangle::sizeHint ( ) const

(reimplemented)

Definition at line 194 of file qtcolortriangle.cpp.

Referenced by QtColorTriangle().

Property Documentation

◆ color

QColor QtColorTriangle::color
readwrite

Definition at line 83 of file qtcolortriangle.h.

Referenced by colorChanged(), drawTrigon(), and internalSetNewColor().


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

Generated by doxygen 1.14.0