1 /***************************************************************************
2 * Copyright (C) 2005 by Jorge Cuadrado *
3 * kuadrosx@toonka.com *
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. *
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. *
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>
29 #include <QMouseEvent>
30 #include <QWheelEvent>
31 #include <QPaintEvent>
33 #include <QLinearGradient>
34 #include <QPainterPath>
42 * @short Esta clase provee de una simple interfaz grafica para generar "GradientStops".
44 * @author Jorge Cuadrado <kuadrosx@toonka.com>
46 class GradientSelector
: public QAbstractSlider
51 class DGradientArrow
: public QObject
54 DGradientArrow(QPoint pos
, const QColor
& color
, QObject
*parent
= 0) : QObject(parent
), m_color(color
)
57 // if ( orientation() == Qt::Vertical )
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 );
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 );
74 m_form
.addPolygon(array
);
79 return m_form
.currentPosition().x();
81 bool contains ( const QPoint
& pt
)
83 return m_form
.contains (pt
);
85 void moveArrow( const QPoint
&pos
)
89 matrix
.translate(pos
.x() - m_form
.currentPosition().x(), 0);
91 m_form
= matrix
.map(m_form
);
101 void setColor(const QColor
&color
)
105 void moveVertical(const QPoint
&pos
)
109 matrix
.translate(0, pos
.y() - m_form
.currentPosition().y());
111 m_form
= matrix
.map(m_form
);
124 * Constructor por defecto.
127 GradientSelector( QWidget
*parent
=0 );
133 * Crea un GradientSelector, con una orientacion definida.
135 * @see Qt::Orientation
137 GradientSelector( Qt::Orientation o
, QWidget
*parent
= 0 );
146 * Pone un GradienStops, para ser editado.
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
173 // const QString secondText() const
177 Qt::Orientation
orientation() const
178 { return _orientation
; }
181 QRect
contentsRect() const;
183 void setValue(int value
)
185 QAbstractSlider::setValue(value
);
190 return QAbstractSlider
198 * Pone el numero maximo de flechas, que definen el "GradienStops".
201 void setMaxArrows(int value
);
206 * Devuelve el "GradienStops" actual.
209 QGradientStops
gradientStops() const
211 return m_gradient
.stops();
217 * Crea el "GradienStops" actual apartir de las flechas acutales.
220 void createGradient();
221 // void setMinValue(int value)
222 // { QAbstractSlider::setMaximum(value); }
224 // int minValue() const
226 // return QAbstractSlider::minValue();
230 // void setMaxValue(int value)
232 // QAbstractSlider::setMaximum(value);
235 // int maxValue() const
237 // return QAbstractSlider::maxValue();
244 * Cambia el color de la flecha actualmente seleccionada.
247 void setCurrentColor(const QColor
& color
);
249 void newValue( int value
);
250 void gradientChanged( const QGradientStops
& );
254 void addArrow(QPoint position
, QColor color
);
255 virtual void valueChange( int value
);
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);
273 QPoint
calcArrowPos( int val
);
274 void moveArrow( const QPoint
&pos
);
276 double valueToGradient(int _value
) const;
277 Qt::Orientation _orientation
;
281 int m_currentArrowIndex
;
282 QLinearGradient m_gradient
;
283 QList
<DGradientArrow
*> m_arrows
;
286 QColor m_currentColor
;