00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 #ifndef QTCOLORTRIANGLE_H
00048 #define QTCOLORTRIANGLE_H
00049 #include <QtGui/QImage>
00050 #include <QtGui/QWidget>
00051
00052 class QPointF;
00053 struct Vertex;
00054
00055 #if defined(Q_WS_WIN)
00056 # if !defined(QT_QTCOLORTRIANGLE_EXPORT) && !defined(QT_QTCOLORTRIANGLE_IMPORT)
00057 # define QT_QTCOLORTRIANGLE_EXPORT
00058 # elif defined(QT_QTCOLORTRIANGLE_IMPORT)
00059 # if defined(QT_QTCOLORTRIANGLE_EXPORT)
00060 # undef QT_QTCOLORTRIANGLE_EXPORT
00061 # endif
00062 # define QT_QTCOLORTRIANGLE_EXPORT __declspec(dllimport)
00063 # elif defined(QT_QTCOLORTRIANGLE_EXPORT)
00064 # undef QT_QTCOLORTRIANGLE_EXPORT
00065 # define QT_QTCOLORTRIANGLE_EXPORT __declspec(dllexport)
00066 # endif
00067 #else
00068 # define QT_QTCOLORTRIANGLE_EXPORT
00069 #endif
00070
00071 class QT_QTCOLORTRIANGLE_EXPORT QtColorTriangle : public QWidget
00072 {
00073 Q_OBJECT
00074
00075 public:
00076 QtColorTriangle(QWidget *parent = 0);
00077 ~QtColorTriangle();
00078
00079 QSize sizeHint() const;
00080 int heightForWidth(int w) const;
00081
00082 void polish();
00083 QColor color() const;
00084
00085 Q_SIGNALS:
00086 void colorChanged(const QColor &col);
00087
00088 public Q_SLOTS:
00089 void setColor(const QColor &col);
00090
00091 protected:
00092 void paintEvent(QPaintEvent *);
00093 void mouseMoveEvent(QMouseEvent *);
00094 void mousePressEvent(QMouseEvent *);
00095 void mouseReleaseEvent(QMouseEvent *);
00096 void keyPressEvent(QKeyEvent *e);
00097 void resizeEvent(QResizeEvent *);
00098 void drawTrigon(QImage *p, const QPointF &a, const QPointF &b,
00099 const QPointF &c, const QColor &color);
00100
00101 private:
00102 double radiusAt(const QPointF &pos, const QRect &rect) const;
00103 double angleAt(const QPointF &pos, const QRect &rect) const;
00104 QPointF movePointToTriangle(double x, double y, const Vertex &a,
00105 const Vertex &b, const Vertex &c) const;
00106
00107 QPointF pointFromColor(const QColor &col) const;
00108 QColor colorFromPoint(const QPointF &p) const;
00109
00110 void genBackground();
00111
00112 QImage bg;
00113 double a, b, c;
00114 QPointF pa, pb, pc, pd;
00115
00116 QColor curColor;
00117 int curHue;
00118
00119 bool mustGenerateBackground;
00120 int penWidth;
00121 int ellipseSize;
00122
00123 int outerRadius;
00124 QPointF selectorPos;
00125
00126 enum SelectionMode {
00127 Idle,
00128 SelectingHue,
00129 SelectingSatValue
00130 } selMode;
00131 };
00132
00133 #endif