1/* This file is part of the KDE libraries
2 Copyright (C) 1997 Martin Jones (mjones@kde.org)
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
18*/
19//-----------------------------------------------------------------------------
20// Selector widgets for KDE Color Selector, but probably useful for other
21// stuff also.
22
23#ifndef KSELECTOR_H
24#define KSELECTOR_H
25
26#include <kdeui_export.h>
27
28#include <QtGui/QAbstractSlider>
29#include <QtGui/QGradient>
30#include <QtGui/QWidget>
31
32/**
33 * KSelector is the base class for other widgets which
34 * provides the ability to choose from a one-dimensional
35 * range of values. An example is the KGradientSelector
36 * which allows to choose from a range of colors.
37 *
38 * A custom drawing routine for the widget surface has
39 * to be provided by the subclass.
40 */
41class KDEUI_EXPORT KSelector : public QAbstractSlider
42{
43 Q_OBJECT
44 Q_PROPERTY( int value READ value WRITE setValue )
45 Q_PROPERTY( int minValue READ minimum WRITE setMinimum )
46 Q_PROPERTY( int maxValue READ maximum WRITE setMaximum )
47 Q_PROPERTY( bool indent READ indent WRITE setIndent )
48 Q_PROPERTY( Qt::ArrowType arrowDirection READ arrowDirection WRITE setArrowDirection )
49public:
50
51 /**
52 * Constructs a horizontal one-dimensional selection widget.
53 */
54 explicit KSelector( QWidget *parent=0 );
55 /**
56 * Constructs a one-dimensional selection widget with
57 * a given orientation.
58 */
59 explicit KSelector( Qt::Orientation o, QWidget *parent = 0 );
60 /*
61 * Destructs the widget.
62 */
63 ~KSelector();
64
65 /**
66 * @return the rectangle on which subclasses should draw.
67 */
68 QRect contentsRect() const;
69
70 /**
71 * Sets the indent option of the widget to i.
72 * This determines whether a shaded frame is drawn.
73 */
74 void setIndent( bool i );
75
76 /**
77 * @return whether the indent option is set.
78 */
79 bool indent() const;
80
81 /**
82 * Sets the arrow direction.
83 */
84 void setArrowDirection( Qt::ArrowType direction );
85
86 /**
87 * @return the current arrow direction
88 */
89 Qt::ArrowType arrowDirection() const;
90
91protected:
92 /**
93 * Override this function to draw the contents of the control.
94 * The default implementation does nothing.
95 *
96 * Draw only within contentsRect().
97 */
98 virtual void drawContents( QPainter * );
99 /**
100 * Override this function to draw the cursor which
101 * indicates the current value.
102 */
103 virtual void drawArrow( QPainter *painter, const QPoint &pos );
104
105 virtual void paintEvent( QPaintEvent * );
106 virtual void mousePressEvent( QMouseEvent *e );
107 virtual void mouseMoveEvent( QMouseEvent *e );
108 virtual void mouseReleaseEvent( QMouseEvent *e );
109 virtual void wheelEvent( QWheelEvent * );
110
111private:
112 QPoint calcArrowPos( int val );
113 void moveArrow( const QPoint &pos );
114
115private:
116 class Private;
117 friend class Private;
118 Private * const d;
119
120 Q_DISABLE_COPY(KSelector)
121};
122
123
124/**
125 * The KGradientSelector widget allows the user to choose
126 * from a one-dimensional range of colors which is given as a
127 * gradient between two colors provided by the programmer.
128 *
129 * \image html kgradientselector.png "KDE Gradient Selector Widget"
130 *
131 **/
132class KDEUI_EXPORT KGradientSelector : public KSelector
133{
134 Q_OBJECT
135
136 Q_PROPERTY( QColor firstColor READ firstColor WRITE setFirstColor )
137 Q_PROPERTY( QColor secondColor READ secondColor WRITE setSecondColor )
138 Q_PROPERTY( QString firstText READ firstText WRITE setFirstText )
139 Q_PROPERTY( QString secondText READ secondText WRITE setSecondText )
140
141public:
142 /**
143 * Constructs a horizontal color selector which
144 * contains a gradient between white and black.
145 */
146 explicit KGradientSelector( QWidget *parent=0 );
147 /**
148 * Constructs a colors selector with orientation o which
149 * contains a gradient between white and black.
150 */
151 explicit KGradientSelector( Qt::Orientation o, QWidget *parent=0 );
152 /**
153 * Destructs the widget.
154 */
155 ~KGradientSelector();
156
157 /**
158 * Sets the colors that make up the gradient. Any previously set colors
159 * are removed.
160 * @since 4.5
161 */
162 void setStops(const QGradientStops &stops);
163
164 /**
165 * Get the colors that make up the gradient.
166 * @since 4.5
167 */
168 QGradientStops stops() const;
169
170 /**
171 * Sets the two colors which span the gradient.
172 */
173 void setColors( const QColor &col1, const QColor &col2 );
174 void setText( const QString &t1, const QString &t2 );
175
176 /**
177 * Set each color on its own.
178 */
179 void setFirstColor( const QColor &col );
180 void setSecondColor( const QColor &col );
181
182 /**
183 * Set each description on its own
184 */
185 void setFirstText( const QString &t );
186 void setSecondText( const QString &t );
187
188 QColor firstColor() const;
189 QColor secondColor() const;
190
191 QString firstText() const;
192 QString secondText() const;
193
194protected:
195
196 virtual void drawContents( QPainter * );
197 virtual QSize minimumSize() const;
198
199private:
200 class KGradientSelectorPrivate;
201 friend class KGradientSelectorPrivate;
202 KGradientSelectorPrivate * const d;
203
204 Q_DISABLE_COPY(KGradientSelector)
205};
206
207#endif // KSELECTOR_H
208