-Added timeline
[dashstudio.git] / src / components / colorpalette / private / gradientselector.h
bloba04dcd6c9bcb803a99088d0d36132a23e44426ed
1 /***************************************************************************
2 * Copyright (C) 2005 by Jorge Cuadrado *
3 * kuadrosx@toonka.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #ifndef GRADIENTSELECTOR_H
22 #define GRADIENTSELECTOR_H
24 #include <QAbstractSlider>
25 #include <QColor>
26 #include <QImage>
27 #include <QPixmap>
28 #include <QPainter>
29 #include <QMouseEvent>
30 #include <QWheelEvent>
31 #include <QPaintEvent>
32 #include <QPoint>
33 #include <QLinearGradient>
34 #include <QPainterPath>
36 #include <QList>
38 /**
39 * @if english
40 * @short translate me
41 * @elseif spanish
42 * @short Esta clase provee de una simple interfaz grafica para generar "GradientStops".
43 * @endif
44 * @author Jorge Cuadrado <kuadrosx@toonka.com>
46 class GradientSelector : public QAbstractSlider
48 Q_OBJECT;
50 private:
51 class DGradientArrow : public QObject
53 public:
54 DGradientArrow(QPoint pos, const QColor& color, QObject *parent = 0) : QObject(parent), m_color(color)
56 QPolygon array(6);
57 // if ( orientation() == Qt::Vertical )
58 // {
59 // array.setPoint( 0, pos.x()+0, pos.y()+0 );
60 // array.setPoint( 1, pos.x()+5, pos.y()+5 );
61 // array.setPoint( 2, pos.x()+5, pos.y()-5 );
62 //
64 // }
65 // else
66 // {
67 array.setPoint( 0, pos.x()+0, pos.y()+0 );
68 array.setPoint( 1, pos.x()+5, pos.y()+5 );
69 array.setPoint( 2, pos.x()+5, pos.y()+9 );
70 array.setPoint( 3, pos.x()-5, pos.y()+9 );
71 array.setPoint( 4, pos.x()-5, pos.y()+5 );
72 array.setPoint( 5, pos.x()+0, pos.y()+0 );
73 // }
74 m_form.addPolygon(array);
76 ~DGradientArrow(){}
77 double position()
79 return m_form.currentPosition().x();
81 bool contains ( const QPoint & pt )
83 return m_form.contains (pt);
85 void moveArrow( const QPoint &pos )
87 QMatrix matrix;
89 matrix.translate(pos.x() - m_form.currentPosition().x(), 0);
91 m_form = matrix.map(m_form);
93 QPainterPath form()
95 return m_form;
97 QColor color() const
99 return m_color;
101 void setColor(const QColor &color)
103 m_color = color;
105 void moveVertical(const QPoint &pos)
107 QMatrix matrix;
109 matrix.translate(0, pos.y() - m_form.currentPosition().y());
111 m_form = matrix.map(m_form);
113 QPainterPath m_form;
114 QColor m_color;
118 public:
121 * @if english
122 * Translate
123 * @elseif spanish
124 * Constructor por defecto.
125 * @endif
127 GradientSelector( QWidget *parent=0 );
130 * @if english
131 * Translate
132 * @elseif spanish
133 * Crea un GradientSelector, con una orientacion definida.
134 * @endif
135 * @see Qt::Orientation
137 GradientSelector( Qt::Orientation o, QWidget *parent = 0 );
139 * Destructor
141 ~GradientSelector();
143 * @if english
144 * Translate
145 * @elseif spanish
146 * Pone un GradienStops, para ser editado.
147 * @endif
149 void setStops(const QGradientStops &);
151 // void setColors( const QColor &col1, const QColor &col2 )
152 // { color1 = col1; color2 = col2; update(); }
153 // void setText( const QString &t1, const QString &t2 )
154 // { text1 = t1; text2 = t2; update(); }
156 // void setFirstColor( const QColor &col )
157 // { color1 = col; update(); }
158 // void setSecondColor( const QColor &col )
159 // { color2 = col; update(); }
161 // void setFirstText( const QString &t )
162 // { text1 = t; update(); }
163 // void setSecondText( const QString &t )
164 // { text2 = t; update(); }
166 // const QColor firstColor() const
167 // { return color1; }
168 // const QColor secondColor() const
169 // { return color2; }
171 // const QString firstText() const
172 // { return text1; }
173 // const QString secondText() const
174 // { return text2; }
177 Qt::Orientation orientation() const
178 { return _orientation; }
181 QRect contentsRect() const;
183 void setValue(int value)
185 QAbstractSlider::setValue(value);
188 int value() const
190 return QAbstractSlider
191 ::value();
195 * @if english
196 * Translate
197 * @elseif spanish
198 * Pone el numero maximo de flechas, que definen el "GradienStops".
199 * @endif
201 void setMaxArrows(int value);
203 * @if english
204 * Translate
205 * @elseif spanish
206 * Devuelve el "GradienStops" actual.
207 * @endif
209 QGradientStops gradientStops() const
211 return m_gradient.stops();
214 * @if english
215 * Translate
216 * @elseif spanish
217 * Crea el "GradienStops" actual apartir de las flechas acutales.
218 * @endif
220 void createGradient();
221 // void setMinValue(int value)
222 // { QAbstractSlider::setMaximum(value); }
224 // int minValue() const
225 // {
226 // return QAbstractSlider::minValue();
227 // }
230 // void setMaxValue(int value)
231 // {
232 // QAbstractSlider::setMaximum(value);
233 // }
235 // int maxValue() const
236 // {
237 // return QAbstractSlider::maxValue();
238 // }
241 * @if english
242 * Translate
243 * @elseif spanish
244 * Cambia el color de la flecha actualmente seleccionada.
245 * @endif
247 void setCurrentColor(const QColor& color);
248 signals:
249 void newValue( int value );
250 void gradientChanged( const QGradientStops& );
251 void arrowAdded();
253 public slots:
254 void addArrow(QPoint position, QColor color);
255 virtual void valueChange( int value);
256 protected:
257 virtual void drawContents( QPainter * );
259 virtual void paintEvent( QPaintEvent * );
260 virtual void mousePressEvent( QMouseEvent *e );
261 virtual void mouseMoveEvent( QMouseEvent *e );
262 virtual void wheelEvent( QWheelEvent * );
264 virtual QSize minimumSize() const
265 { return sizeHint(); }
266 virtual void resizeEvent ( QResizeEvent * event );
267 virtual QSize sizeHint() const
269 return QSize(width(), 35);
272 private:
273 QPoint calcArrowPos( int val );
274 void moveArrow( const QPoint &pos );
276 double valueToGradient(int _value) const;
277 Qt::Orientation _orientation;
279 private:
280 void init();
281 int m_currentArrowIndex;
282 QLinearGradient m_gradient;
283 QList<DGradientArrow*> m_arrows;
284 bool m_update;
285 int m_maxArrows;
286 QColor m_currentColor;
289 #endif