| 1 | /**************************************************************************** | 
|---|
| 2 | ** | 
|---|
| 3 | ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). | 
|---|
| 4 | ** All rights reserved. | 
|---|
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) | 
|---|
| 6 | ** | 
|---|
| 7 | ** This file is part of the demonstration applications of the Qt Toolkit. | 
|---|
| 8 | ** | 
|---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | 
|---|
| 10 | ** Commercial Usage | 
|---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in | 
|---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the | 
|---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in | 
|---|
| 14 | ** a written agreement between you and Nokia. | 
|---|
| 15 | ** | 
|---|
| 16 | ** GNU Lesser General Public License Usage | 
|---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser | 
|---|
| 18 | ** General Public License version 2.1 as published by the Free Software | 
|---|
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the | 
|---|
| 20 | ** packaging of this file.  Please review the following information to | 
|---|
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements | 
|---|
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | 
|---|
| 23 | ** | 
|---|
| 24 | ** In addition, as a special exception, Nokia gives you certain additional | 
|---|
| 25 | ** rights.  These rights are described in the Nokia Qt LGPL Exception | 
|---|
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | 
|---|
| 27 | ** | 
|---|
| 28 | ** GNU General Public License Usage | 
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU | 
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software | 
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the | 
|---|
| 32 | ** packaging of this file.  Please review the following information to | 
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be | 
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html. | 
|---|
| 35 | ** | 
|---|
| 36 | ** If you have questions regarding the use of this file, please contact | 
|---|
| 37 | ** Nokia at qt-info@nokia.com. | 
|---|
| 38 | ** $QT_END_LICENSE$ | 
|---|
| 39 | ** | 
|---|
| 40 | ****************************************************************************/ | 
|---|
| 41 |  | 
|---|
| 42 | #ifndef GRADIENTS_H | 
|---|
| 43 | #define GRADIENTS_H | 
|---|
| 44 |  | 
|---|
| 45 | #include "arthurwidgets.h" | 
|---|
| 46 |  | 
|---|
| 47 | #include <QtGui> | 
|---|
| 48 |  | 
|---|
| 49 | class HoverPoints; | 
|---|
| 50 |  | 
|---|
| 51 |  | 
|---|
| 52 | class ShadeWidget : public QWidget | 
|---|
| 53 | { | 
|---|
| 54 | Q_OBJECT | 
|---|
| 55 | public: | 
|---|
| 56 | enum ShadeType { | 
|---|
| 57 | RedShade, | 
|---|
| 58 | GreenShade, | 
|---|
| 59 | BlueShade, | 
|---|
| 60 | ARGBShade | 
|---|
| 61 | }; | 
|---|
| 62 |  | 
|---|
| 63 | ShadeWidget(ShadeType type, QWidget *parent); | 
|---|
| 64 |  | 
|---|
| 65 | void setGradientStops(const QGradientStops &stops); | 
|---|
| 66 |  | 
|---|
| 67 | void paintEvent(QPaintEvent *e); | 
|---|
| 68 |  | 
|---|
| 69 | QSize sizeHint() const { return QSize(150, 40); } | 
|---|
| 70 | QPolygonF points() const; | 
|---|
| 71 |  | 
|---|
| 72 | HoverPoints *hoverPoints() const { return m_hoverPoints; } | 
|---|
| 73 |  | 
|---|
| 74 | uint colorAt(int x); | 
|---|
| 75 |  | 
|---|
| 76 | signals: | 
|---|
| 77 | void colorsChanged(); | 
|---|
| 78 |  | 
|---|
| 79 | private: | 
|---|
| 80 | void generateShade(); | 
|---|
| 81 |  | 
|---|
| 82 | ShadeType m_shade_type; | 
|---|
| 83 | QImage m_shade; | 
|---|
| 84 | HoverPoints *m_hoverPoints; | 
|---|
| 85 | QLinearGradient m_alpha_gradient; | 
|---|
| 86 | }; | 
|---|
| 87 |  | 
|---|
| 88 | class GradientEditor : public QWidget | 
|---|
| 89 | { | 
|---|
| 90 | Q_OBJECT | 
|---|
| 91 | public: | 
|---|
| 92 | GradientEditor(QWidget *parent); | 
|---|
| 93 |  | 
|---|
| 94 | void setGradientStops(const QGradientStops &stops); | 
|---|
| 95 |  | 
|---|
| 96 | public slots: | 
|---|
| 97 | void pointsUpdated(); | 
|---|
| 98 |  | 
|---|
| 99 | signals: | 
|---|
| 100 | void gradientStopsChanged(const QGradientStops &stops); | 
|---|
| 101 |  | 
|---|
| 102 | private: | 
|---|
| 103 | ShadeWidget *m_red_shade; | 
|---|
| 104 | ShadeWidget *m_green_shade; | 
|---|
| 105 | ShadeWidget *m_blue_shade; | 
|---|
| 106 | ShadeWidget *m_alpha_shade; | 
|---|
| 107 | }; | 
|---|
| 108 |  | 
|---|
| 109 |  | 
|---|
| 110 | class GradientRenderer : public ArthurFrame | 
|---|
| 111 | { | 
|---|
| 112 | Q_OBJECT | 
|---|
| 113 | public: | 
|---|
| 114 | GradientRenderer(QWidget *parent); | 
|---|
| 115 | void paint(QPainter *p); | 
|---|
| 116 |  | 
|---|
| 117 | QSize sizeHint() const { return QSize(400, 400); } | 
|---|
| 118 |  | 
|---|
| 119 | HoverPoints *hoverPoints() const { return m_hoverPoints; } | 
|---|
| 120 | void mousePressEvent(QMouseEvent *e); | 
|---|
| 121 |  | 
|---|
| 122 | public slots: | 
|---|
| 123 | void setGradientStops(const QGradientStops &stops); | 
|---|
| 124 |  | 
|---|
| 125 | void setPadSpread() { m_spread = QGradient::PadSpread; update(); } | 
|---|
| 126 | void setRepeatSpread() { m_spread = QGradient::RepeatSpread; update(); } | 
|---|
| 127 | void setReflectSpread() { m_spread = QGradient::ReflectSpread; update(); } | 
|---|
| 128 |  | 
|---|
| 129 | void setLinearGradient() { m_gradientType = Qt::LinearGradientPattern; update(); } | 
|---|
| 130 | void setRadialGradient() { m_gradientType = Qt::RadialGradientPattern; update(); } | 
|---|
| 131 | void setConicalGradient() { m_gradientType = Qt::ConicalGradientPattern; update(); } | 
|---|
| 132 |  | 
|---|
| 133 |  | 
|---|
| 134 | private: | 
|---|
| 135 | QGradientStops m_stops; | 
|---|
| 136 | HoverPoints *m_hoverPoints; | 
|---|
| 137 |  | 
|---|
| 138 | QGradient::Spread m_spread; | 
|---|
| 139 | Qt::BrushStyle m_gradientType; | 
|---|
| 140 | }; | 
|---|
| 141 |  | 
|---|
| 142 |  | 
|---|
| 143 | class GradientWidget : public QWidget | 
|---|
| 144 | { | 
|---|
| 145 | Q_OBJECT | 
|---|
| 146 | public: | 
|---|
| 147 | GradientWidget(QWidget *parent); | 
|---|
| 148 |  | 
|---|
| 149 | public slots: | 
|---|
| 150 | void setDefault1() { setDefault(1); } | 
|---|
| 151 | void setDefault2() { setDefault(2); } | 
|---|
| 152 | void setDefault3() { setDefault(3); } | 
|---|
| 153 | void setDefault4() { setDefault(4); } | 
|---|
| 154 |  | 
|---|
| 155 | private: | 
|---|
| 156 | void setDefault(int i); | 
|---|
| 157 |  | 
|---|
| 158 | GradientRenderer *m_renderer; | 
|---|
| 159 | GradientEditor *m_editor; | 
|---|
| 160 |  | 
|---|
| 161 | QRadioButton *m_linearButton; | 
|---|
| 162 | QRadioButton *m_radialButton; | 
|---|
| 163 | QRadioButton *m_conicalButton; | 
|---|
| 164 | QRadioButton *m_padSpreadButton; | 
|---|
| 165 | QRadioButton *m_reflectSpreadButton; | 
|---|
| 166 | QRadioButton *m_repeatSpreadButton; | 
|---|
| 167 |  | 
|---|
| 168 | }; | 
|---|
| 169 |  | 
|---|
| 170 | #endif // GRADIENTS_H | 
|---|