VisLU Flow 0.1

src/ColorPicker/qtcolortriangle.h

00001 /****************************************************************************
00002 **
00003 ** This file is part of a Qt Solutions component.
00004 ** 
00005 ** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
00006 ** 
00007 ** Contact:  Qt Software Information (qt-info@nokia.com)
00008 ** 
00009 ** Commercial Usage  
00010 ** Licensees holding valid Qt Commercial licenses may use this file in
00011 ** accordance with the Qt Solutions Commercial License Agreement provided
00012 ** with the Software or, alternatively, in accordance with the terms
00013 ** contained in a written agreement between you and Nokia.
00014 ** 
00015 ** GNU Lesser General Public License Usage
00016 ** Alternatively, this file may be used under the terms of the GNU Lesser
00017 ** General Public License version 2.1 as published by the Free Software
00018 ** Foundation and appearing in the file LICENSE.LGPL included in the
00019 ** packaging of this file.  Please review the following information to
00020 ** ensure the GNU Lesser General Public License version 2.1 requirements
00021 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
00022 ** 
00023 ** In addition, as a special exception, Nokia gives you certain
00024 ** additional rights. These rights are described in the Nokia Qt LGPL
00025 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
00026 ** package.
00027 ** 
00028 ** GNU General Public License Usage 
00029 ** Alternatively, this file may be used under the terms of the GNU
00030 ** General Public License version 3.0 as published by the Free Software
00031 ** Foundation and appearing in the file LICENSE.GPL included in the
00032 ** packaging of this file.  Please review the following information to
00033 ** ensure the GNU General Public License version 3.0 requirements will be
00034 ** met: http://www.gnu.org/copyleft/gpl.html.
00035 ** 
00036 ** Please note Third Party Software included with Qt Solutions may impose
00037 ** additional restrictions and it is the user's responsibility to ensure
00038 ** that they have met the licensing requirements of the GPL, LGPL, or Qt
00039 ** Solutions Commercial license and the relevant license of the Third
00040 ** Party Software they are using.
00041 ** 
00042 ** If you are unsure which license is appropriate for your use, please
00043 ** contact the sales department at qt-sales@nokia.com.
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 
00093     void paintEvent(QPaintEvent *);
00094     void mouseMoveEvent(QMouseEvent *);
00095     void mousePressEvent(QMouseEvent *);
00096     void mouseReleaseEvent(QMouseEvent *);
00097     void keyPressEvent(QKeyEvent *e);
00098     void resizeEvent(QResizeEvent *);
00099     void drawTrigon(QImage *p, const QPointF &a, const QPointF &b,
00100                     const QPointF &c, const QColor &color);
00101 
00102 private:
00103     double radiusAt(const QPointF &pos, const QRect &rect) const;
00104     double angleAt(const QPointF &pos, const QRect &rect) const;
00105     QPointF movePointToTriangle(double x, double y, const Vertex &a,
00106                                     const Vertex &b, const Vertex &c) const;
00107 
00108     QPointF pointFromColor(const QColor &col) const;
00109     QColor colorFromPoint(const QPointF &p) const;
00110 
00111     void genBackground();
00112 
00113     QImage bg;
00114     double a, b, c;
00115     QPointF pa, pb, pc, pd;
00116 
00117     QColor curColor;
00118     int curHue;
00119 
00120     bool mustGenerateBackground;
00121     int penWidth;
00122     int ellipseSize;
00123 
00124     int outerRadius;
00125     QPointF selectorPos;
00126 
00127     enum SelectionMode {
00128         Idle,
00129         SelectingHue,
00130         SelectingSatValue
00131     } selMode;
00132 };
00133 
00134 #endif
 All Classes Functions Variables