summaryrefslogtreecommitdiffstats
path: root/tdeui/kselect.h
blob: 58efab2931d16c1ca4fde462214974d13634bdb1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
/* This file is part of the KDE libraries
    Copyright (C) 1997 Martin Jones ([email protected])

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
    Boston, MA 02110-1301, USA.
*/
//-----------------------------------------------------------------------------
// Selector widgets for KDE Color Selector, but probably useful for other
// stuff also.

#ifndef __KSELECT_H__
#define __KSELECT_H__

#include <tqwidget.h>
#include <tqrangecontrol.h>
#include <tqpixmap.h>

#include <tdelibs_export.h>

/**
 * KXYSelector is the base class for other widgets which
 * provides the ability to choose from a two-dimensional
 * range of values. The currently chosen value is indicated
 * by a cross. An example is the KHSSelector which
 * allows to choose from a range of colors, and which is
 * used in KColorDialog.
 *
 * A custom drawing routine for the widget surface has
 * to be provided by the subclass.
 */
class TDEUI_EXPORT KXYSelector : public TQWidget
{
  Q_OBJECT
  Q_PROPERTY( int xValue READ xValue WRITE setXValue )
  Q_PROPERTY( int yValue READ yValue WRITE setYValue )
  
public:
  /**
   * Constructs a two-dimensional selector widget which
   * has a value range of [0..100] in both directions.
   */
  KXYSelector( TQWidget *parent=0, const char *name=0 );
  /**
   * Destructs the widget.
   */
  ~KXYSelector();

  /**
   * Sets the current values in horizontal and
   * vertical direction.
   * @param xPos the horizontal value
   * @param yPos the veritcal value
   */
  void setValues( int xPos, int yPos );
  
  /**
   * Sets the current horizontal value
   * @param xPos the horizontal value
   */
  void setXValue( int xPos );
  
  /**
   * Sets the current vertical value
   * @param yPos the veritcal value
   */
  void setYValue( int yPos );
  
  /**
   * Sets the range of possible values.
   */
  void setRange( int minX, int minY, int maxX, int maxY );

  /**
   * @return the current value in horizontal direction.
   */
  int xValue() const {	return xPos; }
  /**
   * @return the current value in vertical direction.
   */
  int yValue() const {	return yPos; }

  /**
   * @return the rectangle on which subclasses should draw.
   */
  TQRect contentsRect() const;

signals:
  /**
   * This signal is emitted whenever the user chooses a value,
   * e.g. by clicking with the mouse on the widget.
   */
  void valueChanged( int x, int y );

protected:
  /**
   * Override this function to draw the contents of the widget.
   * The default implementation does nothing.
   *
   * Draw within contentsRect() only.
   */
  virtual void drawContents( TQPainter * );
  /**
   * Override this function to draw the cursor which
   * indicates the currently selected value pair.
   */
  virtual void drawCursor( TQPainter *p, int xp, int yp );

  virtual void paintEvent( TQPaintEvent *e );
  virtual void mousePressEvent( TQMouseEvent *e );
  virtual void mouseMoveEvent( TQMouseEvent *e );
  virtual void wheelEvent( TQWheelEvent * );

  /**
   * Converts a pixel position to its corresponding values.
   */
  void valuesFromPosition( int x, int y, int& xVal, int& yVal ) const;

private:
  void setPosition( int xp, int yp );
  int px;
  int py;
  int xPos;
  int yPos;
  int minX;
  int maxX;
  int minY;
  int maxY;
  TQPixmap store;

protected:
  virtual void virtual_hook( int id, void* data );
private:
  class KXYSelectorPrivate;
  KXYSelectorPrivate *d;
};


/**
 * KSelector is the base class for other widgets which
 * provides the ability to choose from a one-dimensional
 * range of values. An example is the KGradientSelector
 * which allows to choose from a range of colors.
 *
 * A custom drawing routine for the widget surface has
 * to be provided by the subclass.
 */
class TDEUI_EXPORT KSelector : public TQWidget, public TQRangeControl
{
  Q_OBJECT
  Q_PROPERTY( int value READ value WRITE setValue )
  Q_PROPERTY( int minValue READ minValue WRITE setMinValue )
  Q_PROPERTY( int maxValue READ maxValue WRITE setMaxValue )
public:

  /**
   * Constructs a horizontal one-dimensional selection widget.
   */
  KSelector( TQWidget *parent=0, const char *name=0 );
  /**
   * Constructs a one-dimensional selection widget with
   * a given orientation.
   */
  KSelector( Orientation o, TQWidget *parent = 0L, const char *name = 0L );
  /*
   * Destructs the widget.
   */
  ~KSelector();

  /**
   * @return the orientation of the widget.
   */
  Orientation orientation() const
  {	return _orientation; }

  /**
   * @return the rectangle on which subclasses should draw.
   */
  TQRect contentsRect() const;

  /**
   * Sets the indent option of the widget to i.
   * This determines whether a shaded frame is drawn.
   */
  void setIndent( bool i )
  {	_indent = i; }
  /**
   * @return whether the indent option is set.
   */
  bool indent() const
  {	return _indent; }

  /**
   * Sets the value.
   */
  void setValue(int value)
  { TQRangeControl::setValue(value); }

  /**
   * @returns the value.
   */
  int value() const
  { return TQRangeControl::value(); }

  /**
   * Sets the min value.
   */
  void setMinValue(int value)
  { TQRangeControl::setMinValue(value); }

  /**
   * @return the min value.
   */
  int minValue() const
  { return TQRangeControl::minValue(); }

  /**
   * Sets the max value.
   */
  void setMaxValue(int value)
  { TQRangeControl::setMaxValue(value); }

  /**
   * @return the max value.
   */
  int maxValue() const
  { return TQRangeControl::maxValue(); }

signals:
  /**
   * This signal is emitted whenever the user chooses a value,
   * e.g. by clicking with the mouse on the widget.
   */
  void valueChanged( int value );

protected:
  /**
   * Override this function to draw the contents of the control.
   * The default implementation does nothing.
   *
   * Draw only within contentsRect().
   */
  virtual void drawContents( TQPainter * );
  /**
   * Override this function to draw the cursor which
   * indicates the current value. This function is
   * always called twice, once with argument show=false
   * to clear the old cursor, once with argument show=true
   * to draw the new one.
   */
  virtual void drawArrow( TQPainter *painter, bool show, const TQPoint &pos );

  virtual void valueChange();
  virtual void paintEvent( TQPaintEvent * );
  virtual void mousePressEvent( TQMouseEvent *e );
  virtual void mouseMoveEvent( TQMouseEvent *e );
  virtual void wheelEvent( TQWheelEvent * );

private:
  TQPoint calcArrowPos( int val );
  void moveArrow( const TQPoint &pos );

  Orientation _orientation;
  bool _indent;

protected:
  virtual void virtual_hook( int id, void* data );
private:
  class KSelectorPrivate;
  KSelectorPrivate *d;
};


/**
 * The KGradientSelector widget allows the user to choose
 * from a one-dimensional range of colors which is given as a
 * gradient between two colors provided by the programmer.
 *
 * \image html kgradientselector.png "KDE Gradient Selector Widget"
 *
 **/
class TDEUI_EXPORT KGradientSelector : public KSelector
{
  Q_OBJECT

  Q_PROPERTY( TQColor firstColor READ firstColor WRITE setFirstColor )
  Q_PROPERTY( TQColor secondColor READ secondColor WRITE setSecondColor )
  Q_PROPERTY( TQString firstText READ firstText WRITE setFirstText )
  Q_PROPERTY( TQString secondText READ secondText WRITE setSecondText )

public:
  /**
   * Constructs a horizontal color selector which
   * contains a gradient between white and black.
   */
  KGradientSelector( TQWidget *parent=0, const char *name=0 );
  /**
   * Constructs a colors selector with orientation o which
   * contains a gradient between white and black.
   */
  KGradientSelector( Orientation o, TQWidget *parent=0, const char *name=0 );
  /**
   * Destructs the widget.
   */
  ~KGradientSelector();
  /**
   * Sets the two colors which span the gradient.
   */
  void setColors( const TQColor &col1, const TQColor &col2 )
  {	color1 = col1; color2 = col2; update();}
  void setText( const TQString &t1, const TQString &t2 )
  {	text1 = t1; text2 = t2; update(); }

  /**
   * Set each color on its own.
   */
  void setFirstColor( const TQColor &col )
  { color1 = col; update(); }
  void setSecondColor( const TQColor &col )
  { color2 = col; update(); }

  /**
   * Set each description on its own
   */
  void setFirstText( const TQString &t )
  { text1 = t; update(); }
  void setSecondText( const TQString &t )
  { text2 = t; update(); }

  const TQColor firstColor() const
  { return color1; }
  const TQColor secondColor() const
  { return color2; }

  const TQString firstText() const
  { return text1; }
  const TQString secondText() const
  { return text2; }

protected:

  virtual void drawContents( TQPainter * );
  virtual TQSize minimumSize() const
  { return sizeHint(); }

private:
  void init();
  TQColor color1;
  TQColor color2;
  TQString text1;
  TQString text2;

protected:
  virtual void virtual_hook( int id, void* data );
private:
  class KGradientSelectorPrivate;
  KGradientSelectorPrivate *d;
};


#endif		// __KSELECT_H__