Home

qtcolortriangle.h

This is the verbatim text of the qtcolortriangle.h include file. It is provided only for illustration; the copyright remains with Trolltech.


#ifndef QTCOLORTRIANGLE_H
#define QTCOLORTRIANGLE_H
#include <qframe.h>
#include <qimage.h>

#if defined(Q_WS_WIN)
#  if !defined(QT_QTCOLORTRIANGLE_EXPORT) && !defined(QT_QTCOLORTRIANGLE_IMPORT)
#    define QT_QTCOLORTRIANGLE_EXPORT
#  elif defined(QT_QTCOLORTRIANGLE_IMPORT)
#    if defined(QT_QTCOLORTRIANGLE_EXPORT)
#      undef QT_QTCOLORTRIANGLE_EXPORT
#    endif
#    define QT_QTCOLORTRIANGLE_EXPORT __declspec(dllimport)
#  elif defined(QT_QTCOLORTRIANGLE_EXPORT)
#    undef QT_QTCOLORTRIANGLE_EXPORT
#    define QT_QTCOLORTRIANGLE_EXPORT __declspec(dllexport)
#  endif
#else
#  define QT_QTCOLORTRIANGLE_EXPORT
#endif

class QT_QTCOLORTRIANGLE_EXPORT QtColorTriangle : public QFrame
{
    Q_OBJECT

public:
    QtColorTriangle(QWidget *parent = 0, const char *name = 0);
    ~QtColorTriangle();

    QSize sizeHint() const;

    void polish();

    QColor color() const;

signals:
    void colorChanged(const QColor &col);

public slots:
    void setColor(const QColor &col);

protected:
    void drawContents(QPainter *);
    void mouseMoveEvent(QMouseEvent *);
    void mousePressEvent(QMouseEvent *);
    void mouseReleaseEvent(QMouseEvent *);
    void keyPressEvent(QKeyEvent *e);
    void resizeEvent(QResizeEvent *);

private:
    /*
    Used to store color values in the range 0..255 as doubles.
    */
    struct DoubleColor
    {
        double r, g, b;

        DoubleColor() : r(0.0), g(0.0), b(0.0) {}
        DoubleColor(double red, double green, double blue) : r(red), g(green), b(blue) {}
        DoubleColor(const DoubleColor &c) : r(c.r), g(c.g), b(c.b) {}
    };

    /*
        Used to store x-y coordinate values as doubles.
    */
    struct DoublePoint
    {
        double x;
        double y;

        DoublePoint() : x(0), y(0) {}
        DoublePoint(double xx, double yy) : x(xx), y(yy) {}
        DoublePoint(const DoublePoint &c) : x(c.x), y(c.y) {}
    };

    /*
        Used to store pairs of DoubleColor and DoublePoint in one structure.
    */
    struct Vertex {
        DoubleColor color;
        DoublePoint point;

        Vertex(const DoubleColor &c, const DoublePoint &p) : color(c), point(p) {}
        Vertex(const QColor &c, const DoublePoint &p)
            : color(DoubleColor((double) c.red(), (double) c.green(),
                        (double) c.blue())), point(p) {}
    };
    void drawTrigon(QImage *p, const DoublePoint &a, const DoublePoint &b,
		    const DoublePoint &c, const QColor &color);
    void swap(QtColorTriangle::Vertex **a, QtColorTriangle::Vertex **b) const;
    double radiusAt(const DoublePoint &pos, const QRect &rect) const;
    double angleAt(const DoublePoint &pos, const QRect &rect) const;
    DoublePoint movePointToTriangle(double x, double y, const Vertex &a,
				    const Vertex &b, const Vertex &c) const;

    DoublePoint pointFromColor(const QColor &col) const;
    QColor colorFromPoint(const DoublePoint &p) const;

    void genBackground();

    QImage bg;
    double a, b, c;
    DoublePoint pa, pb, pc, pd;

    QColor curColor;
    int curHue;

    bool mustGenerateBackground;
    int penWidth;
    int ellipseSize;

    int outerRadius;
    DoublePoint selectorPos;

    enum SelectionMode {
	Idle,
	SelectingHue,
	SelectingSatValue
    } selMode;
};
#endif

Copyright © 2003-2006 TrolltechTrademarks
Qt Solutions