summaryrefslogtreecommitdiffabout
path: root/microkde/kdeui/knuminput.h
Unidiff
Diffstat (limited to 'microkde/kdeui/knuminput.h') (more/less context) (ignore whitespace changes)
-rw-r--r--microkde/kdeui/knuminput.h15
1 files changed, 12 insertions, 3 deletions
diff --git a/microkde/kdeui/knuminput.h b/microkde/kdeui/knuminput.h
index 123fefa..9f9e200 100644
--- a/microkde/kdeui/knuminput.h
+++ b/microkde/kdeui/knuminput.h
@@ -1,180 +1,185 @@
1/* 1/*
2 * knuminput.h 2 * knuminput.h
3 * 3 *
4 * Copyright (c) 1997 Patrick Dowler <dowler@morgul.fsh.uvic.ca> 4 * Copyright (c) 1997 Patrick Dowler <dowler@morgul.fsh.uvic.ca>
5 * Copyright (c) 2000 Dirk A. Mueller <mueller@kde.org> 5 * Copyright (c) 2000 Dirk A. Mueller <mueller@kde.org>
6 * Copyright (c) 2002 Marc Mutz <mutz@kde.org> 6 * Copyright (c) 2002 Marc Mutz <mutz@kde.org>
7 * 7 *
8 * Requires the Qt widget libraries, available at no cost at 8 * Requires the Qt widget libraries, available at no cost at
9 * http://www.troll.no/ 9 * http://www.troll.no/
10 * 10 *
11 * This library is free software; you can redistribute it and/or 11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Library General Public 12 * modify it under the terms of the GNU Library General Public
13 * License as published by the Free Software Foundation; either 13 * License as published by the Free Software Foundation; either
14 * version 2 of the License, or (at your option) any later version. 14 * version 2 of the License, or (at your option) any later version.
15 * 15 *
16 * This library is distributed in the hope that it will be useful, 16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Library General Public License for more details. 19 * Library General Public License for more details.
20 * 20 *
21 * You should have received a copy of the GNU Library General Public License 21 * You should have received a copy of the GNU Library General Public License
22 * along with this library; see the file COPYING.LIB. If not, write to 22 * along with this library; see the file COPYING.LIB. If not, write to
23 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 23 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 * Boston, MA 02111-1307, USA. 24 * Boston, MA 02111-1307, USA.
25 */ 25 */
26 26
27#ifndef K_NUMINPUT_H 27#ifndef K_NUMINPUT_H
28#define K_NUMINPUT_H 28#define K_NUMINPUT_H
29 29
30#include <qwidget.h> 30#include <qwidget.h>
31#include <qspinbox.h> 31#include <qspinbox.h>
32#include <QLineEdit>
33//Added by qt3to4:
34#include <QResizeEvent>
35#include <QLabel>
36#include <QEvent>
32 37
33class QLabel; 38class QLabel;
34class QSlider; 39class QSlider;
35class QLineEdit; 40class QLineEdit;
36class QLayout; 41class QLayout;
37class QValidator; 42class QValidator;
38 43
39class KIntSpinBox; 44class KIntSpinBox;
40 45
41/* ------------------------------------------------------------------------ */ 46/* ------------------------------------------------------------------------ */
42 47
43/** 48/**
44 * You need to inherit from this class if you want to implement K*NumInput 49 * You need to inherit from this class if you want to implement K*NumInput
45 * for a different variable type 50 * for a different variable type
46 * 51 *
47 */ 52 */
48class KNumInput : public QWidget 53class KNumInput : public QWidget
49{ 54{
50 Q_OBJECT 55 Q_OBJECT
51 Q_PROPERTY( QString label READ label WRITE setLabel ) 56 Q_PROPERTY( QString label READ label WRITE setLabel )
52public: 57public:
53 /** 58 /**
54 * Default constructor 59 * Default constructor
55 * 60 *
56 */ 61 */
57 KNumInput(QWidget* parent=0, const char* name=0); 62 KNumInput(QWidget* parent=0, const char* name=0);
58 63
59 /** 64 /**
60 * @param below A pointer to another KNumInput. 65 * @param below A pointer to another KNumInput.
61 * 66 *
62 */ 67 */
63 KNumInput(KNumInput* below, QWidget* parent=0, const char* name=0); 68 KNumInput(KNumInput* below, QWidget* parent=0, const char* name=0);
64 ~KNumInput(); 69 ~KNumInput();
65 70
66 /** 71 /**
67 * Sets the text and alignment of the main description label. 72 * Sets the text and alignment of the main description label.
68 * 73 *
69 * @param label The text of the label. 74 * @param label The text of the label.
70 * Use QString::null to remove an existing one. 75 * Use QString::null to remove an existing one.
71 * 76 *
72 * @param a one of @p AlignLeft, @p AlignHCenter, YAlignRight and 77 * @param a one of @p AlignLeft, @p AlignHCenter, YAlignRight and
73 * @p AlignTop, @p AlignVCenter, @p AlignBottom. 78 * @p AlignTop, @p AlignVCenter, @p AlignBottom.
74 * default is @p AlignLeft | @p AlignTop. 79 * default is @p AlignLeft | @p AlignTop.
75 * 80 *
76 * The vertical alignment flags have special meaning with this 81 * The vertical alignment flags have special meaning with this
77 * widget: 82 * widget:
78 * 83 *
79 * @li @p AlignTop The label is placed above the edit/slider 84 * @li @p AlignTop The label is placed above the edit/slider
80 * @li @p AlignVCenter The label is placed left beside the edit 85 * @li @p AlignVCenter The label is placed left beside the edit
81 * @li @p AlignBottom The label is placed below the edit/slider 86 * @li @p AlignBottom The label is placed below the edit/slider
82 * 87 *
83 */ 88 */
84 virtual void setLabel(const QString & label, int a = AlignLeft | AlignTop); 89 virtual void setLabel(const QString & label, int a = Qt::AlignLeft | Qt::AlignTop);
85 90
86 /** 91 /**
87 * @return the text of the label. 92 * @return the text of the label.
88 */ 93 */
89 QString label() const; 94 QString label() const;
90 95
91 /** 96 /**
92 * @return if the num input has a slider. 97 * @return if the num input has a slider.
93 * @since 3.1 98 * @since 3.1
94 */ 99 */
95 bool showSlider() const { return m_slider; } 100 bool showSlider() const { return m_slider; }
96 101
97 /** 102 /**
98 * Sets the spacing of tickmarks for the slider. 103 * Sets the spacing of tickmarks for the slider.
99 * 104 *
100 * @param minor Minor tickmark separation. 105 * @param minor Minor tickmark separation.
101 * @param major Major tickmark separation. 106 * @param major Major tickmark separation.
102 */ 107 */
103 void setSteps(int minor, int major); 108 void setSteps(int minor, int major);
104 109
105 /** 110 /**
106 * Specifies that this widget may stretch horizontally, but is 111 * Specifies that this widget may stretch horizontally, but is
107 * fixed vertically (like @ref QSpinBox itself). 112 * fixed vertically (like @ref QSpinBox itself).
108 */ 113 */
109 QSizePolicy sizePolicy() const; 114 QSizePolicy sizePolicy() const;
110 115
111 /** 116 /**
112 * Returns a size which fits the contents of the control. 117 * Returns a size which fits the contents of the control.
113 * 118 *
114 * @return the preferred size necessary to show the control 119 * @return the preferred size necessary to show the control
115 */ 120 */
116 virtual QSize sizeHint() const; 121 virtual QSize sizeHint() const;
117 122
118protected: 123protected:
119 /** 124 /**
120 * Call this function whenever you change something in the geometry 125 * Call this function whenever you change something in the geometry
121 * of your KNumInput child. 126 * of your KNumInput child.
122 * 127 *
123 */ 128 */
124 void layout(bool deep); 129 void layout(bool deep);
125 130
126 /** 131 /**
127 * You need to overwrite this method and implement your layout 132 * You need to overwrite this method and implement your layout
128 * calculations there. 133 * calculations there.
129 * 134 *
130 * See KIntNumInput::doLayout and KDoubleNumInput::doLayout implementation 135 * See KIntNumInput::doLayout and KDoubleNumInput::doLayout implementation
131 * for details. 136 * for details.
132 * 137 *
133 */ 138 */
134 virtual void doLayout() = 0; 139 virtual void doLayout() = 0;
135 140
136 KNumInput* m_prev, *m_next; 141 KNumInput* m_prev, *m_next;
137 int m_colw1, m_colw2; 142 int m_colw1, m_colw2;
138 143
139 QLabel* m_label; 144 QLabel* m_label;
140 QSlider* m_slider; 145 QSlider* m_slider;
141 QSize m_sizeSlider, m_sizeLabel; 146 QSize m_sizeSlider, m_sizeLabel;
142 147
143 int m_alignment; 148 int m_alignment;
144 149
145private: 150private:
146 void init(); 151 void init();
147 152
148protected: 153protected:
149 virtual void virtual_hook( int id, void* data ); 154 virtual void virtual_hook( int id, void* data );
150private: 155private:
151 class KNumInputPrivate; 156 class KNumInputPrivate;
152 KNumInputPrivate *d; 157 KNumInputPrivate *d;
153}; 158};
154 159
155/* ------------------------------------------------------------------------ */ 160/* ------------------------------------------------------------------------ */
156 161
157/** 162/**
158 * KIntNumInput combines a @ref QSpinBox and optionally a @ref QSlider 163 * KIntNumInput combines a @ref QSpinBox and optionally a @ref QSlider
159 * with a label to make an easy to use control for setting some integer 164 * with a label to make an easy to use control for setting some integer
160 * parameter. This is especially nice for configuration dialogs, 165 * parameter. This is especially nice for configuration dialogs,
161 * which can have many such combinated controls. 166 * which can have many such combinated controls.
162 * 167 *
163 * The slider is created only when the user specifies a range 168 * The slider is created only when the user specifies a range
164 * for the control using the setRange function with the slider 169 * for the control using the setRange function with the slider
165 * parameter set to "true". 170 * parameter set to "true".
166 * 171 *
167 * A special feature of KIntNumInput, designed specifically for 172 * A special feature of KIntNumInput, designed specifically for
168 * the situation when there are several KIntNumInputs in a column, 173 * the situation when there are several KIntNumInputs in a column,
169 * is that you can specify what portion of the control is taken by the 174 * is that you can specify what portion of the control is taken by the
170 * QSpinBox (the remaining portion is used by the slider). This makes 175 * QSpinBox (the remaining portion is used by the slider). This makes
171 * it very simple to have all the sliders in a column be the same size. 176 * it very simple to have all the sliders in a column be the same size.
172 * 177 *
173 * It uses @ref KIntValidator validator class. KIntNumInput enforces the 178 * It uses @ref KIntValidator validator class. KIntNumInput enforces the
174 * value to be in the given range, and can display it in any base 179 * value to be in the given range, and can display it in any base
175 * between 2 and 36. 180 * between 2 and 36.
176 * 181 *
177 * @short An input widget for integer numbers, consisting of a spinbox and a slider. 182 * @short An input widget for integer numbers, consisting of a spinbox and a slider.
178 * @version $Id$ 183 * @version $Id$
179 */ 184 */
180 185
@@ -209,193 +214,193 @@ public:
209 */ 214 */
210 KIntNumInput(int value, QWidget* parent=0, int base = 10, const char *name=0); 215 KIntNumInput(int value, QWidget* parent=0, int base = 10, const char *name=0);
211 216
212 /** 217 /**
213 * Constructor 218 * Constructor
214 * 219 *
215 * the difference to the one above is the "below" parameter. It tells 220 * the difference to the one above is the "below" parameter. It tells
216 * this instance that it is visually put below some other KNumInput widget. 221 * this instance that it is visually put below some other KNumInput widget.
217 * Note that these two KNumInput's need not to have the same parent widget 222 * Note that these two KNumInput's need not to have the same parent widget
218 * or be in the same layout group. 223 * or be in the same layout group.
219 * The effect is that it'll adjust it's layout in correspondence 224 * The effect is that it'll adjust it's layout in correspondence
220 * with the layout of the other KNumInput's (you can build an arbitary long 225 * with the layout of the other KNumInput's (you can build an arbitary long
221 * chain). 226 * chain).
222 * 227 *
223 * @param below append KIntNumInput to the KNumInput chain 228 * @param below append KIntNumInput to the KNumInput chain
224 * @param value initial value for the control 229 * @param value initial value for the control
225 * @param base numeric base used for display 230 * @param base numeric base used for display
226 * @param parent parent QWidget 231 * @param parent parent QWidget
227 * @param name internal name for this widget 232 * @param name internal name for this widget
228 */ 233 */
229 KIntNumInput(KNumInput* below, int value, QWidget* parent=0, int base = 10, const char *name=0); 234 KIntNumInput(KNumInput* below, int value, QWidget* parent=0, int base = 10, const char *name=0);
230 235
231 /** 236 /**
232 * Destructor 237 * Destructor
233 * 238 *
234 * 239 *
235 */ 240 */
236 virtual ~KIntNumInput(); 241 virtual ~KIntNumInput();
237 242
238 /** 243 /**
239 * @return the current value. 244 * @return the current value.
240 */ 245 */
241 int value() const; 246 int value() const;
242 247
243 /** 248 /**
244 * @return the curent value in units of the @ref referencePoint. 249 * @return the curent value in units of the @ref referencePoint.
245 * @since 3.1 250 * @since 3.1
246 */ 251 */
247 double relativeValue() const; 252 double relativeValue() const;
248 253
249 /** 254 /**
250 * @return the current reference point 255 * @return the current reference point
251 * @since 3.1 256 * @since 3.1
252 */ 257 */
253 int referencePoint() const; 258 int referencePoint() const;
254 259
255 /** 260 /**
256 * @return the suffix displayed behind the value. 261 * @return the suffix displayed behind the value.
257 * @see #setSuffix() 262 * @see #setSuffix()
258 */ 263 */
259 QString suffix() const; 264 QString suffix() const;
260 /** 265 /**
261 * @return the prefix displayed in front of the value. 266 * @return the prefix displayed in front of the value.
262 * @see #setPrefix() 267 * @see #setPrefix()
263 */ 268 */
264 QString prefix() const; 269 QString prefix() const;
265 /** 270 /**
266 * @return the string displayed for a special value. 271 * @return the string displayed for a special value.
267 * @see #setSpecialValueText() 272 * @see #setSpecialValueText()
268 */ 273 */
269 QString specialValueText() const; 274 QString specialValueText() const;
270 275
271 /** 276 /**
272 * @param min minimum value 277 * @param min minimum value
273 * @param max maximum value 278 * @param max maximum value
274 * @param step step size for the QSlider 279 * @param step step size for the QSlider
275 */ 280 */
276 void setRange(int min, int max, int step=1, bool slider=true); 281 void setRange(int min, int max, int step=1, bool slider=true);
277 /** 282 /**
278 * Sets the minimum value. 283 * Sets the minimum value.
279 */ 284 */
280 void setMinValue(int min); 285 void setMinValue(int min);
281 /** 286 /**
282 * @return the minimum value. 287 * @return the minimum value.
283 */ 288 */
284 int minValue() const; 289 int minValue() const;
285 /** 290 /**
286 * Sets the maximum value. 291 * Sets the maximum value.
287 */ 292 */
288 void setMaxValue(int max); 293 void setMaxValue(int max);
289 /** 294 /**
290 * @return the maximum value. 295 * @return the maximum value.
291 */ 296 */
292 int maxValue() const; 297 int maxValue() const;
293 298
294 /** 299 /**
295 * Sets the special value text. If set, the SpinBox will display 300 * Sets the special value text. If set, the SpinBox will display
296 * this text instead of the numeric value whenever the current 301 * this text instead of the numeric value whenever the current
297 * value is equal to minVal(). Typically this is used for indicating 302 * value is equal to minVal(). Typically this is used for indicating
298 * that the choice has a special (default) meaning. 303 * that the choice has a special (default) meaning.
299 */ 304 */
300 void setSpecialValueText(const QString& text); 305 void setSpecialValueText(const QString& text);
301 306
302 /** 307 /**
303 * @reimplemented 308 * @reimplemented
304 */ 309 */
305 virtual void setLabel(const QString & label, int a = AlignLeft | AlignTop); 310 virtual void setLabel(const QString & label, int a = Qt::AlignLeft | Qt::AlignTop);
306 311
307 /** 312 /**
308 * This method returns the minimum size necessary to display the 313 * This method returns the minimum size necessary to display the
309 * control. The minimum size is enough to show all the labels 314 * control. The minimum size is enough to show all the labels
310 * in the current font (font change may invalidate the return value). 315 * in the current font (font change may invalidate the return value).
311 * 316 *
312 * @return the minimum size necessary to show the control 317 * @return the minimum size necessary to show the control
313 */ 318 */
314 virtual QSize minimumSizeHint() const; 319 virtual QSize minimumSizeHint() const;
315 320
316public slots: 321public slots:
317 /** 322 /**
318 * Sets the value of the control. 323 * Sets the value of the control.
319 */ 324 */
320 void setValue(int); 325 void setValue(int);
321 326
322 /** 327 /**
323 * Sets the value in units of the @ref referencePoint 328 * Sets the value in units of the @ref referencePoint
324 * @since 3.1 329 * @since 3.1
325 */ 330 */
326 void setRelativeValue(double); 331 void setRelativeValue(double);
327 332
328 /** 333 /**
329 * Sets the reference point for @ref relativeValue. 334 * Sets the reference point for @ref relativeValue.
330 * @since 3.1 335 * @since 3.1
331 */ 336 */
332 void setReferencePoint(int); 337 void setReferencePoint(int);
333 338
334 /** 339 /**
335 * Sets the suffix to @p suffix. 340 * Sets the suffix to @p suffix.
336 * Use QString::null to disable this feature. 341 * Use QString::null to disable this feature.
337 * Formatting has to be provided (e.g. a space separator between the 342 * Formatting has to be provided (e.g. a space separator between the
338 * prepended @p value and the suffix's text has to be provided 343 * prepended @p value and the suffix's text has to be provided
339 * as the first character in the suffix). 344 * as the first character in the suffix).
340 * 345 *
341 * @see QSpinBox::setSuffix(), #setPrefix() 346 * @see QSpinBox::setSuffix(), #setPrefix()
342 */ 347 */
343 void setSuffix(const QString &suffix); 348 void setSuffix(const QString &suffix);
344 349
345 /** 350 /**
346 * Sets the prefix to @p prefix. 351 * Sets the prefix to @p prefix.
347 * Use QString::null to disable this feature. 352 * Use QString::null to disable this feature.
348 * Formatting has to be provided (see above). 353 * Formatting has to be provided (see above).
349 * 354 *
350 * @see QSpinBox::setPrefix(), #setSuffix() 355 * @see QSpinBox::setPrefix(), #setSuffix()
351 */ 356 */
352 void setPrefix(const QString &prefix); 357 void setPrefix(const QString &prefix);
353 358
354 /** 359 /**
355 * sets focus to the edit widget and marks all text in if mark == true 360 * sets focus to the edit widget and marks all text in if mark == true
356 * 361 *
357 */ 362 */
358 void setEditFocus( bool mark = true ); 363 void setEditFocus( bool mark = true );
359 364
360signals: 365signals:
361 /** 366 /**
362 * Emitted every time the value changes (by calling @ref setValue() or 367 * Emitted every time the value changes (by calling @ref setValue() or
363 * by user interaction). 368 * by user interaction).
364 */ 369 */
365 void valueChanged(int); 370 void valueChanged(int);
366 371
367 /** 372 /**
368 * Emitted whenever @ref #valueChanged is. Contains the change 373 * Emitted whenever @ref #valueChanged is. Contains the change
369 * relative to the @ref referencePoint. 374 * relative to the @ref referencePoint.
370 * @since 3.1 375 * @since 3.1
371 */ 376 */
372 void relativeValueChanged(double); 377 void relativeValueChanged(double);
373 378
374private slots: 379private slots:
375 void spinValueChanged(int); 380 void spinValueChanged(int);
376 void slotEmitRelativeValueChanged(int); 381 void slotEmitRelativeValueChanged(int);
377 382
378protected: 383protected:
379 /** 384 /**
380 * @reimplemented 385 * @reimplemented
381 */ 386 */
382 virtual void doLayout(); 387 virtual void doLayout();
383 /** 388 /**
384 * @reimplemented 389 * @reimplemented
385 */ 390 */
386 void resizeEvent ( QResizeEvent * ); 391 void resizeEvent ( QResizeEvent * );
387 392
388 KIntSpinBox* m_spin; 393 KIntSpinBox* m_spin;
389 QSize m_sizeSpin; 394 QSize m_sizeSpin;
390 395
391private: 396private:
392 void init(int value, int _base); 397 void init(int value, int _base);
393 398
394protected: 399protected:
395 virtual void virtual_hook( int id, void* data ); 400 virtual void virtual_hook( int id, void* data );
396private: 401private:
397 class KIntNumInputPrivate; 402 class KIntNumInputPrivate;
398 KIntNumInputPrivate *d; 403 KIntNumInputPrivate *d;
399}; 404};
400 405
401 406
@@ -495,362 +500,366 @@ public:
495 * 500 *
496 * puts it below other KNumInput 501 * puts it below other KNumInput
497 * 502 *
498 * @param lower lower boundary value 503 * @param lower lower boundary value
499 * @param upper upper boundary value 504 * @param upper upper boundary value
500 * @param value initial value for the control 505 * @param value initial value for the control
501 * @param step step size to use for up/down arrow clicks 506 * @param step step size to use for up/down arrow clicks
502 * @param precision number of digits after the decimal point 507 * @param precision number of digits after the decimal point
503 * @param parent parent QWidget 508 * @param parent parent QWidget
504 * @param name internal name for this widget 509 * @param name internal name for this widget
505 * @since 3.1 510 * @since 3.1
506 */ 511 */
507 KDoubleNumInput(KNumInput* below, 512 KDoubleNumInput(KNumInput* below,
508 double lower, double upper, double value, double step=0.02, 513 double lower, double upper, double value, double step=0.02,
509 int precision=2, QWidget *parent=0, const char *name=0); 514 int precision=2, QWidget *parent=0, const char *name=0);
510 515
511 /** 516 /**
512 * @return the current value. 517 * @return the current value.
513 */ 518 */
514 double value() const; 519 double value() const;
515 520
516 /** 521 /**
517 * @return the suffix. 522 * @return the suffix.
518 * @see #setSuffix() 523 * @see #setSuffix()
519 */ 524 */
520 QString suffix() const; 525 QString suffix() const;
521 526
522 /** 527 /**
523 * @return the prefix. 528 * @return the prefix.
524 * @see #setPrefix() 529 * @see #setPrefix()
525 */ 530 */
526 QString prefix() const; 531 QString prefix() const;
527 532
528 /** 533 /**
529 * @return the precision. 534 * @return the precision.
530 * @see #setPrecision() 535 * @see #setPrecision()
531 */ 536 */
532 int precision() const; 537 int precision() const;
533 538
534 /** 539 /**
535 * @return the string displayed for a special value. 540 * @return the string displayed for a special value.
536 * @see #setSpecialValueText() 541 * @see #setSpecialValueText()
537 */ 542 */
538 QString specialValueText() const { return m_specialvalue; } 543 QString specialValueText() const { return m_specialvalue; }
539 544
540 /** 545 /**
541 * @param min minimum value 546 * @param min minimum value
542 * @param max maximum value 547 * @param max maximum value
543 * @param step step size for the QSlider 548 * @param step step size for the QSlider
544 */ 549 */
545 void setRange(double min, double max, double step=1, bool slider=true); 550 void setRange(double min, double max, double step=1, bool slider=true);
546 /** 551 /**
547 * Sets the minimum value. 552 * Sets the minimum value.
548 */ 553 */
549 void setMinValue(double min); 554 void setMinValue(double min);
550 /** 555 /**
551 * @return the minimum value. 556 * @return the minimum value.
552 */ 557 */
553 double minValue() const; 558 double minValue() const;
554 /** 559 /**
555 * Sets the maximum value. 560 * Sets the maximum value.
556 */ 561 */
557 void setMaxValue(double max); 562 void setMaxValue(double max);
558 /** 563 /**
559 * @return the maximum value. 564 * @return the maximum value.
560 */ 565 */
561 double maxValue() const; 566 double maxValue() const;
562 567
563 /** 568 /**
564 * Specifies the number of digits to use. 569 * Specifies the number of digits to use.
565 */ 570 */
566 void setPrecision(int precision); 571 void setPrecision(int precision);
567 572
568 /** 573 /**
569 * @return the reference point for @ref #relativeValue calculation 574 * @return the reference point for @ref #relativeValue calculation
570 * @since 3.1 575 * @since 3.1
571 */ 576 */
572 double referencePoint() const; 577 double referencePoint() const;
573 578
574 /** 579 /**
575 * @return the current value in units of @ref #referencePoint. 580 * @return the current value in units of @ref #referencePoint.
576 * @since 3.1 581 * @since 3.1
577 */ 582 */
578 double relativeValue() const; 583 double relativeValue() const;
579 584
580 /** 585 /**
581 * Sets the special value text. If set, the spin box will display 586 * Sets the special value text. If set, the spin box will display
582 * this text instead of the numeric value whenever the current 587 * this text instead of the numeric value whenever the current
583 * value is equal to @ref #minVal(). Typically this is used for indicating 588 * value is equal to @ref #minVal(). Typically this is used for indicating
584 * that the choice has a special (default) meaning. 589 * that the choice has a special (default) meaning.
585 */ 590 */
586 void setSpecialValueText(const QString& text); 591 void setSpecialValueText(const QString& text);
587 592
588 /** 593 /**
589 * @reimplemented 594 * @reimplemented
590 */ 595 */
591 virtual void setLabel(const QString & label, int a = AlignLeft | AlignTop); 596 virtual void setLabel(const QString & label, int a = Qt::AlignLeft | Qt::AlignTop);
592 /** 597 /**
593 * @reimplemented 598 * @reimplemented
594 */ 599 */
595 virtual QSize minimumSizeHint() const; 600 virtual QSize minimumSizeHint() const;
596 /** 601 /**
597 * @reimplemented 602 * @reimplemented
598 */ 603 */
599 virtual bool eventFilter(QObject*, QEvent*); 604 virtual bool eventFilter(QObject*, QEvent*);
600 605
601public slots: 606public slots:
602 /** 607 /**
603 * Sets the value of the control. 608 * Sets the value of the control.
604 */ 609 */
605 void setValue(double); 610 void setValue(double);
606 611
607 /** 612 /**
608 * Sets the value in units of @ref #referencePoint. 613 * Sets the value in units of @ref #referencePoint.
609 * @since 3.1 614 * @since 3.1
610 */ 615 */
611 void setRelativeValue(double); 616 void setRelativeValue(double);
612 617
613 /** 618 /**
614 * Sets the reference Point to @p ref. It @p ref == 0, emitting of 619 * Sets the reference Point to @p ref. It @p ref == 0, emitting of
615 * @ref #relativeValueChanged is blocked and @ref #relativeValue 620 * @ref #relativeValueChanged is blocked and @ref #relativeValue
616 * just returns 0. 621 * just returns 0.
617 * @since 3.1 622 * @since 3.1
618 */ 623 */
619 void setReferencePoint(double ref); 624 void setReferencePoint(double ref);
620 625
621 /** 626 /**
622 * Sets the suffix to be displayed to @p suffix. Use QString::null to disable 627 * Sets the suffix to be displayed to @p suffix. Use QString::null to disable
623 * this feature. Note that the suffix is attached to the value without any 628 * this feature. Note that the suffix is attached to the value without any
624 * spacing. So if you prefer to display a space separator, set suffix 629 * spacing. So if you prefer to display a space separator, set suffix
625 * to something like " cm". 630 * to something like " cm".
626 * @see #setSuffix() 631 * @see #setSuffix()
627 */ 632 */
628 void setSuffix(const QString &suffix); 633 void setSuffix(const QString &suffix);
629 634
630 /** 635 /**
631 * Sets the prefix to be displayed to @p prefix. Use QString::null to disable 636 * Sets the prefix to be displayed to @p prefix. Use QString::null to disable
632 * this feature. Note that the prefix is attached to the value without any 637 * this feature. Note that the prefix is attached to the value without any
633 * spacing. 638 * spacing.
634 * @see #setPrefix() 639 * @see #setPrefix()
635 */ 640 */
636 void setPrefix(const QString &prefix); 641 void setPrefix(const QString &prefix);
637 642
638signals: 643signals:
639 /** 644 /**
640 * Emitted every time the value changes (by calling @ref setValue() or 645 * Emitted every time the value changes (by calling @ref setValue() or
641 * by user interaction). 646 * by user interaction).
642 */ 647 */
643 void valueChanged(double); 648 void valueChanged(double);
644 /** 649 /**
645 * This is an overloaded member function, provided for 650 * This is an overloaded member function, provided for
646 * convenience. It essentially behaves like the above function. 651 * convenience. It essentially behaves like the above function.
647 * 652 *
648 * Contains the value in units of @ref #referencePoint. 653 * Contains the value in units of @ref #referencePoint.
649 * @since 3.1 654 * @since 3.1
650 */ 655 */
651 void relativeValueChanged(double); 656 void relativeValueChanged(double);
652 657
653private slots: 658private slots:
654 void sliderMoved(int); 659 void sliderMoved(int);
655 void slotEmitRelativeValueChanged(double); 660 void slotEmitRelativeValueChanged(double);
656 661
657protected: 662protected:
658 663
659 /** 664 /**
660 * @reimplemented 665 * @reimplemented
661 */ 666 */
662 virtual void doLayout(); 667 virtual void doLayout();
663 /** 668 /**
664 * @reimplemented 669 * @reimplemented
665 */ 670 */
666 void resizeEvent ( QResizeEvent * ); 671 void resizeEvent ( QResizeEvent * );
667 virtual void resetEditBox(); 672 virtual void resetEditBox();
668 673
669 // ### no longer used, remove when BIC allowed 674 // ### no longer used, remove when BIC allowed
670 KDoubleLine* edit; 675 KDoubleLine* edit;
671 676
672 bool m_range; 677 bool m_range;
673 double m_lower, m_upper, m_step; 678 double m_lower, m_upper, m_step;
674 // ### end no longer used 679 // ### end no longer used
675 680
676 QSize m_sizeEdit; 681 QSize m_sizeEdit;
677 682
678 friend class KDoubleLine; 683 friend class KDoubleLine;
679private: 684private:
680 void init(double value, double lower, double upper, 685 void init(double value, double lower, double upper,
681 double step, int precision); 686 double step, int precision);
682 double mapSliderToSpin(int) const; 687 double mapSliderToSpin(int) const;
683 void updateLegacyMembers(); 688 void updateLegacyMembers();
684 // ### no longer used, remove when BIC allowed: 689 // ### no longer used, remove when BIC allowed:
685 QString m_specialvalue, m_prefix, m_suffix; 690 QString m_specialvalue, m_prefix, m_suffix;
686 double m_value; 691 double m_value;
687 short m_precision; 692 short m_precision;
688 // ### end remove when BIC allowed 693 // ### end remove when BIC allowed
689 694
690protected: 695protected:
691 virtual void virtual_hook( int id, void* data ); 696 virtual void virtual_hook( int id, void* data );
692private: 697private:
693 class KDoubleNumInputPrivate; 698 class KDoubleNumInputPrivate;
694 KDoubleNumInputPrivate *d; 699 KDoubleNumInputPrivate *d;
695}; 700};
696 701
697 702
698/* ------------------------------------------------------------------------ */ 703/* ------------------------------------------------------------------------ */
699 704
700/** 705/**
701 * A @ref QSpinBox with support for arbitrary base numbers 706 * A @ref QSpinBox with support for arbitrary base numbers
702 * (e.g. hexadecimal). 707 * (e.g. hexadecimal).
703 * 708 *
704 * The class provides an easy interface to use other 709 * The class provides an easy interface to use other
705 * numeric systems than the decimal. 710 * numeric systems than the decimal.
706 * 711 *
707 * @short A @ref QSpinBox with support for arbitrary base numbers. 712 * @short A @ref QSpinBox with support for arbitrary base numbers.
708 */ 713 */
709class KIntSpinBox : public QSpinBox 714class KIntSpinBox : public QSpinBox
710{ 715{
711 Q_OBJECT 716 Q_OBJECT
712 Q_PROPERTY( int base READ base WRITE setBase ) 717 Q_PROPERTY( int base READ base WRITE setBase )
713 718
714public: 719public:
715 720
716 /** 721 /**
717 * Constructor. 722 * Constructor.
718 * 723 *
719 * Constructs a widget with an integer inputline with a little scrollbar 724 * Constructs a widget with an integer inputline with a little scrollbar
720 * and a slider, with minimal value 0, maximal value 99, step 1, base 10 725 * and a slider, with minimal value 0, maximal value 99, step 1, base 10
721 * and initial value 0. 726 * and initial value 0.
722 */ 727 */
723 KIntSpinBox( QWidget *parent=0, const char *name=0); 728 KIntSpinBox( QWidget *parent=0, const char *name=0);
724 729
725 /** 730 /**
726 * Constructor. 731 * Constructor.
727 * 732 *
728 * Constructs a widget with an integer inputline with a little scrollbar 733 * Constructs a widget with an integer inputline with a little scrollbar
729 * and a slider. 734 * and a slider.
730 * 735 *
731 * @param lower The lowest valid value. 736 * @param lower The lowest valid value.
732 * @param upper The greatest valid value. 737 * @param upper The greatest valid value.
733 * @param step The step size of the scrollbar. 738 * @param step The step size of the scrollbar.
734 * @param value The actual value. 739 * @param value The actual value.
735 * @param base The base of the used number system. 740 * @param base The base of the used number system.
736 * @param parent The parent of the widget. 741 * @param parent The parent of the widget.
737 * @param name The Name of the widget. 742 * @param name The Name of the widget.
738 */ 743 */
739 KIntSpinBox(int lower, int upper, int step, int value, int base = 10, 744 KIntSpinBox(int lower, int upper, int step, int value, int base = 10,
740 QWidget* parent = 0, const char* name = 0); 745 QWidget* parent = 0, const char* name = 0);
741 746
742 /** 747 /**
743 * Destructor. 748 * Destructor.
744 */ 749 */
745 virtual ~KIntSpinBox(); 750 virtual ~KIntSpinBox();
746 751
747 /** 752 /**
748 * Sets the base in which the numbers in the spin box are represented. 753 * Sets the base in which the numbers in the spin box are represented.
749 */ 754 */
750 void setBase(int base); 755 void setBase(int base);
751 /** 756 /**
752 * @return the base in which numbers in the spin box are represented. 757 * @return the base in which numbers in the spin box are represented.
753 */ 758 */
754 int base() const; 759 int base() const;
755 /** 760 /**
756 * sets focus and optionally marks all text 761 * sets focus and optionally marks all text
757 * 762 *
758 */ 763 */
759 void setEditFocus(bool mark); 764 void setEditFocus(bool mark);
760 765
766 void setValidator(const QValidator *v) {
767 lineEdit()->setValidator(v);
768 }
769
761protected: 770protected:
762 771
763 /** 772 /**
764 * Overloaded the method in QSpinBox 773 * Overloaded the method in QSpinBox
765 * to make use of the base given in the constructor. 774 * to make use of the base given in the constructor.
766 */ 775 */
767 virtual QString mapValueToText(int); 776 virtual QString mapValueToText(int);
768 777
769 /** 778 /**
770 * Overloaded the method in QSpinBox 779 * Overloaded the method in QSpinBox
771 * to make use of the base given in the constructor. 780 * to make use of the base given in the constructor.
772 */ 781 */
773 virtual int mapTextToValue(bool*); 782 virtual int mapTextToValue(bool*);
774 783
775private: 784private:
776 int val_base; 785 int val_base;
777protected: 786protected:
778 virtual void virtual_hook( int id, void* data ); 787 virtual void virtual_hook( int id, void* data );
779private: 788private:
780 class KIntSpinBoxPrivate; 789 class KIntSpinBoxPrivate;
781 KIntSpinBoxPrivate *d; 790 KIntSpinBoxPrivate *d;
782}; 791};
783 792
784 793
785/* --------------------------------------------------------------------------- */ 794/* --------------------------------------------------------------------------- */
786 795
787/** 796/**
788 This class provides a spin box for fractional numbers. 797 This class provides a spin box for fractional numbers.
789 798
790 @sect Parameters 799 @sect Parameters
791 800
792 There are a number of interdependent parameters whose relation to 801 There are a number of interdependent parameters whose relation to
793 each other you need to understand in order to make successful use 802 each other you need to understand in order to make successful use
794 of the spin box. 803 of the spin box.
795 804
796 @li precision: The number of decimals after the decimal point. 805 @li precision: The number of decimals after the decimal point.
797 @li maxValue/minValue: upper and lower bound of the valid range 806 @li maxValue/minValue: upper and lower bound of the valid range
798 @li lineStep: the size of the step that is taken when the user hits 807 @li lineStep: the size of the step that is taken when the user hits
799 the up or down buttons 808 the up or down buttons
800 809
801 Since we work with fixed-point numbers internally, the maximum 810 Since we work with fixed-point numbers internally, the maximum
802 precision is a function of the valid range and vice versa. More 811 precision is a function of the valid range and vice versa. More
803 precisely, the following relations hold: 812 precisely, the following relations hold:
804 <pre> 813 <pre>
805 max( abs(minValue()), abs(maxValue() ) <= INT_MAX/10^precision 814 max( abs(minValue()), abs(maxValue() ) <= INT_MAX/10^precision
806 maxPrecision = floor( log10( INT_MAX/max(abs(minValue()),abs(maxValue())) ) ) 815 maxPrecision = floor( log10( INT_MAX/max(abs(minValue()),abs(maxValue())) ) )
807 </pre> 816 </pre>
808 817
809 Since the value, bounds and step are rounded to the current 818 Since the value, bounds and step are rounded to the current
810 precision, you may experience that the order of setting above 819 precision, you may experience that the order of setting above
811 parameters matters. E.g. the following are @em not equivalent (try 820 parameters matters. E.g. the following are @em not equivalent (try
812 it!): 821 it!):
813 822
814 <pre> 823 <pre>
815 // sets precision, 824 // sets precision,
816 // then min/max value (rounded to precison and clipped to obtainable range if needed) 825 // then min/max value (rounded to precison and clipped to obtainable range if needed)
817 // then value and lineStep 826 // then value and lineStep
818 KDoubleSpinBox * spin = new KDoubleSpinBox( 0, 9.999, 0.001, 4.321, 3, this ); 827 KDoubleSpinBox * spin = new KDoubleSpinBox( 0, 9.999, 0.001, 4.321, 3, this );
819 828
820 // sets minValue to 0; maxValue to 10.00(!); value to 4.32(!) and only then 829 // sets minValue to 0; maxValue to 10.00(!); value to 4.32(!) and only then
821 // increases the precision - too late, since e.g. value has already been rounded... 830 // increases the precision - too late, since e.g. value has already been rounded...
822 KDpubleSpinBox * spin = new KDoubleSpinBox( this ); 831 KDpubleSpinBox * spin = new KDoubleSpinBox( this );
823 spin->setMinValue( 0 ); 832 spin->setMinValue( 0 );
824 spin->setMaxValue( 9.999 ); 833 spin->setMaxValue( 9.999 );
825 spin->setValue( 4.321 ); 834 spin->setValue( 4.321 );
826 spin->setPrecision( 3 ); 835 spin->setPrecision( 3 );
827 </pre> 836 </pre>
828 837
829 @short A spin box for fractional numbers. 838 @short A spin box for fractional numbers.
830 @author Marc Mutz <mutz@kde.org> 839 @author Marc Mutz <mutz@kde.org>
831 @version $Id$ 840 @version $Id$
832 @since 3.1 841 @since 3.1
833**/ 842**/
834 843
835class KDoubleSpinBox : public QSpinBox { 844class KDoubleSpinBox : public QSpinBox {
836 Q_OBJECT 845 Q_OBJECT
837 Q_PROPERTY( bool acceptLocalizedNumbers READ acceptLocalizedNumbers WRITE setAcceptLocalizedNumbers ) 846 Q_PROPERTY( bool acceptLocalizedNumbers READ acceptLocalizedNumbers WRITE setAcceptLocalizedNumbers )
838 Q_OVERRIDE( double maxValue READ maxValue WRITE setMaxValue ) 847 Q_OVERRIDE( double maxValue READ maxValue WRITE setMaxValue )
839 Q_OVERRIDE( double minValue READ minValue WRITE setMinValue ) 848 Q_OVERRIDE( double minValue READ minValue WRITE setMinValue )
840 Q_OVERRIDE( double lineStep READ lineStep WRITE setLineStep ) 849 Q_OVERRIDE( double lineStep READ lineStep WRITE setLineStep )
841 Q_OVERRIDE( double value READ value WRITE setValue ) 850 Q_OVERRIDE( double value READ value WRITE setValue )
842 Q_PROPERTY( int precision READ precision WRITE setPrecision ) 851 Q_PROPERTY( int precision READ precision WRITE setPrecision )
843 852
844public: 853public:
845 /** Constructs a @ref KDoubleSpinBox with parent @p parent and 854 /** Constructs a @ref KDoubleSpinBox with parent @p parent and
846 default values for range and value (whatever @ref QRangeControl 855 default values for range and value (whatever @ref QRangeControl
847 uses) and precision (2). */ 856 uses) and precision (2). */
848 KDoubleSpinBox( QWidget * parent=0, const char * name=0 ); 857 KDoubleSpinBox( QWidget * parent=0, const char * name=0 );
849 /** Constructs a @ref KDoubleSpinBox with parent @p parent, range 858 /** Constructs a @ref KDoubleSpinBox with parent @p parent, range
850 [@p lower,@p upper], @ref lineStep @p step, @ref precision @p 859 [@p lower,@p upper], @ref lineStep @p step, @ref precision @p
851 precision and initial value @p value. */ 860 precision and initial value @p value. */
852 KDoubleSpinBox( double lower, double upper, double step, double value, 861 KDoubleSpinBox( double lower, double upper, double step, double value,
853 int precision=2, QWidget * parent=0, const char * name=0 ); 862 int precision=2, QWidget * parent=0, const char * name=0 );
854 863
855 virtual ~KDoubleSpinBox(); 864 virtual ~KDoubleSpinBox();
856 865