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.h948
1 files changed, 948 insertions, 0 deletions
diff --git a/microkde/kdeui/knuminput.h b/microkde/kdeui/knuminput.h
new file mode 100644
index 0000000..123fefa
--- a/dev/null
+++ b/microkde/kdeui/knuminput.h
@@ -0,0 +1,948 @@
1/*
2 * knuminput.h
3 *
4 * Copyright (c) 1997 Patrick Dowler <dowler@morgul.fsh.uvic.ca>
5 * Copyright (c) 2000 Dirk A. Mueller <mueller@kde.org>
6 * Copyright (c) 2002 Marc Mutz <mutz@kde.org>
7 *
8 * Requires the Qt widget libraries, available at no cost at
9 * http://www.troll.no/
10 *
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Library General Public
13 * License as published by the Free Software Foundation; either
14 * version 2 of the License, or (at your option) any later version.
15 *
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Library General Public License for more details.
20 *
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
23 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 * Boston, MA 02111-1307, USA.
25 */
26
27#ifndef K_NUMINPUT_H
28#define K_NUMINPUT_H
29
30#include <qwidget.h>
31#include <qspinbox.h>
32
33class QLabel;
34class QSlider;
35class QLineEdit;
36class QLayout;
37class QValidator;
38
39class KIntSpinBox;
40
41/* ------------------------------------------------------------------------ */
42
43/**
44 * You need to inherit from this class if you want to implement K*NumInput
45 * for a different variable type
46 *
47 */
48class KNumInput : public QWidget
49{
50 Q_OBJECT
51 Q_PROPERTY( QString label READ label WRITE setLabel )
52public:
53 /**
54 * Default constructor
55 *
56 */
57 KNumInput(QWidget* parent=0, const char* name=0);
58
59 /**
60 * @param below A pointer to another KNumInput.
61 *
62 */
63 KNumInput(KNumInput* below, QWidget* parent=0, const char* name=0);
64 ~KNumInput();
65
66 /**
67 * Sets the text and alignment of the main description label.
68 *
69 * @param label The text of the label.
70 * Use QString::null to remove an existing one.
71 *
72 * @param a one of @p AlignLeft, @p AlignHCenter, YAlignRight and
73 * @p AlignTop, @p AlignVCenter, @p AlignBottom.
74 * default is @p AlignLeft | @p AlignTop.
75 *
76 * The vertical alignment flags have special meaning with this
77 * widget:
78 *
79 * @li @p AlignTop The label is placed above the edit/slider
80 * @li @p AlignVCenter The label is placed left beside the edit
81 * @li @p AlignBottom The label is placed below the edit/slider
82 *
83 */
84 virtual void setLabel(const QString & label, int a = AlignLeft | AlignTop);
85
86 /**
87 * @return the text of the label.
88 */
89 QString label() const;
90
91 /**
92 * @return if the num input has a slider.
93 * @since 3.1
94 */
95 bool showSlider() const { return m_slider; }
96
97 /**
98 * Sets the spacing of tickmarks for the slider.
99 *
100 * @param minor Minor tickmark separation.
101 * @param major Major tickmark separation.
102 */
103 void setSteps(int minor, int major);
104
105 /**
106 * Specifies that this widget may stretch horizontally, but is
107 * fixed vertically (like @ref QSpinBox itself).
108 */
109 QSizePolicy sizePolicy() const;
110
111 /**
112 * Returns a size which fits the contents of the control.
113 *
114 * @return the preferred size necessary to show the control
115 */
116 virtual QSize sizeHint() const;
117
118protected:
119 /**
120 * Call this function whenever you change something in the geometry
121 * of your KNumInput child.
122 *
123 */
124 void layout(bool deep);
125
126 /**
127 * You need to overwrite this method and implement your layout
128 * calculations there.
129 *
130 * See KIntNumInput::doLayout and KDoubleNumInput::doLayout implementation
131 * for details.
132 *
133 */
134 virtual void doLayout() = 0;
135
136 KNumInput* m_prev, *m_next;
137 int m_colw1, m_colw2;
138
139 QLabel* m_label;
140 QSlider* m_slider;
141 QSize m_sizeSlider, m_sizeLabel;
142
143 int m_alignment;
144
145private:
146 void init();
147
148protected:
149 virtual void virtual_hook( int id, void* data );
150private:
151 class KNumInputPrivate;
152 KNumInputPrivate *d;
153};
154
155/* ------------------------------------------------------------------------ */
156
157/**
158 * 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
160 * parameter. This is especially nice for configuration dialogs,
161 * which can have many such combinated controls.
162 *
163 * The slider is created only when the user specifies a range
164 * for the control using the setRange function with the slider
165 * parameter set to "true".
166 *
167 * A special feature of KIntNumInput, designed specifically for
168 * 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
170 * 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.
172 *
173 * It uses @ref KIntValidator validator class. KIntNumInput enforces the
174 * value to be in the given range, and can display it in any base
175 * between 2 and 36.
176 *
177 * @short An input widget for integer numbers, consisting of a spinbox and a slider.
178 * @version $Id$
179 */
180
181class KIntNumInput : public KNumInput
182{
183 Q_OBJECT
184 Q_PROPERTY( int value READ value WRITE setValue )
185 Q_PROPERTY( int minValue READ minValue WRITE setMinValue )
186 Q_PROPERTY( int maxValue READ maxValue WRITE setMaxValue )
187 Q_PROPERTY( int referencePoint READ referencePoint WRITE setReferencePoint )
188 Q_PROPERTY( QString suffix READ suffix WRITE setSuffix )
189 Q_PROPERTY( QString prefix READ prefix WRITE setPrefix )
190 Q_PROPERTY( QString specialValueText READ specialValueText WRITE setSpecialValueText )
191
192public:
193 /**
194 * Constructs an input control for integer values
195 * with base 10 and initial value 0.
196 */
197 KIntNumInput(QWidget *parent=0, const char *name=0);
198 /**
199 * Constructor
200 * It constructs a QSpinBox that allows the input of integer numbers
201 * in the range of -INT_MAX to +INT_MAX. To set a descriptive label,
202 * use setLabel(). To enforce the value being in a range and optionally to
203 * attach a slider to it, use setRange().
204 *
205 * @param value initial value for the control
206 * @param base numeric base used for display
207 * @param parent parent QWidget
208 * @param name internal name for this widget
209 */
210 KIntNumInput(int value, QWidget* parent=0, int base = 10, const char *name=0);
211
212 /**
213 * Constructor
214 *
215 * 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.
217 * Note that these two KNumInput's need not to have the same parent widget
218 * or be in the same layout group.
219 * 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
221 * chain).
222 *
223 * @param below append KIntNumInput to the KNumInput chain
224 * @param value initial value for the control
225 * @param base numeric base used for display
226 * @param parent parent QWidget
227 * @param name internal name for this widget
228 */
229 KIntNumInput(KNumInput* below, int value, QWidget* parent=0, int base = 10, const char *name=0);
230
231 /**
232 * Destructor
233 *
234 *
235 */
236 virtual ~KIntNumInput();
237
238 /**
239 * @return the current value.
240 */
241 int value() const;
242
243 /**
244 * @return the curent value in units of the @ref referencePoint.
245 * @since 3.1
246 */
247 double relativeValue() const;
248
249 /**
250 * @return the current reference point
251 * @since 3.1
252 */
253 int referencePoint() const;
254
255 /**
256 * @return the suffix displayed behind the value.
257 * @see #setSuffix()
258 */
259 QString suffix() const;
260 /**
261 * @return the prefix displayed in front of the value.
262 * @see #setPrefix()
263 */
264 QString prefix() const;
265 /**
266 * @return the string displayed for a special value.
267 * @see #setSpecialValueText()
268 */
269 QString specialValueText() const;
270
271 /**
272 * @param min minimum value
273 * @param max maximum value
274 * @param step step size for the QSlider
275 */
276 void setRange(int min, int max, int step=1, bool slider=true);
277 /**
278 * Sets the minimum value.
279 */
280 void setMinValue(int min);
281 /**
282 * @return the minimum value.
283 */
284 int minValue() const;
285 /**
286 * Sets the maximum value.
287 */
288 void setMaxValue(int max);
289 /**
290 * @return the maximum value.
291 */
292 int maxValue() const;
293
294 /**
295 * Sets the special value text. If set, the SpinBox will display
296 * this text instead of the numeric value whenever the current
297 * value is equal to minVal(). Typically this is used for indicating
298 * that the choice has a special (default) meaning.
299 */
300 void setSpecialValueText(const QString& text);
301
302 /**
303 * @reimplemented
304 */
305 virtual void setLabel(const QString & label, int a = AlignLeft | AlignTop);
306
307 /**
308 * This method returns the minimum size necessary to display the
309 * control. The minimum size is enough to show all the labels
310 * in the current font (font change may invalidate the return value).
311 *
312 * @return the minimum size necessary to show the control
313 */
314 virtual QSize minimumSizeHint() const;
315
316public slots:
317 /**
318 * Sets the value of the control.
319 */
320 void setValue(int);
321
322 /**
323 * Sets the value in units of the @ref referencePoint
324 * @since 3.1
325 */
326 void setRelativeValue(double);
327
328 /**
329 * Sets the reference point for @ref relativeValue.
330 * @since 3.1
331 */
332 void setReferencePoint(int);
333
334 /**
335 * Sets the suffix to @p suffix.
336 * Use QString::null to disable this feature.
337 * 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
339 * as the first character in the suffix).
340 *
341 * @see QSpinBox::setSuffix(), #setPrefix()
342 */
343 void setSuffix(const QString &suffix);
344
345 /**
346 * Sets the prefix to @p prefix.
347 * Use QString::null to disable this feature.
348 * Formatting has to be provided (see above).
349 *
350 * @see QSpinBox::setPrefix(), #setSuffix()
351 */
352 void setPrefix(const QString &prefix);
353
354 /**
355 * sets focus to the edit widget and marks all text in if mark == true
356 *
357 */
358 void setEditFocus( bool mark = true );
359
360signals:
361 /**
362 * Emitted every time the value changes (by calling @ref setValue() or
363 * by user interaction).
364 */
365 void valueChanged(int);
366
367 /**
368 * Emitted whenever @ref #valueChanged is. Contains the change
369 * relative to the @ref referencePoint.
370 * @since 3.1
371 */
372 void relativeValueChanged(double);
373
374private slots:
375 void spinValueChanged(int);
376 void slotEmitRelativeValueChanged(int);
377
378protected:
379 /**
380 * @reimplemented
381 */
382 virtual void doLayout();
383 /**
384 * @reimplemented
385 */
386 void resizeEvent ( QResizeEvent * );
387
388 KIntSpinBox* m_spin;
389 QSize m_sizeSpin;
390
391private:
392 void init(int value, int _base);
393
394protected:
395 virtual void virtual_hook( int id, void* data );
396private:
397 class KIntNumInputPrivate;
398 KIntNumInputPrivate *d;
399};
400
401
402/* ------------------------------------------------------------------------ */
403
404class KDoubleLine;
405
406/**
407 * KDoubleNumInput combines a @ref QSpinBox and optionally a @ref QSlider
408 * with a label to make an easy to use control for setting some float
409 * parameter. This is especially nice for configuration dialogs,
410 * which can have many such combinated controls.
411 *
412 * The slider is created only when the user specifies a range
413 * for the control using the setRange function with the slider
414 * parameter set to "true".
415 *
416 * A special feature of KDoubleNumInput, designed specifically for
417 * the situation when there are several instances in a column,
418 * is that you can specify what portion of the control is taken by the
419 * QSpinBox (the remaining portion is used by the slider). This makes
420 * it very simple to have all the sliders in a column be the same size.
421 *
422 * It uses the @ref KDoubleValidator validator class. KDoubleNumInput
423 * enforces the value to be in the given range, but see the class
424 * documentation of @ref KDoubleSpinBox for the tricky
425 * interrelationship of precision and values. All of what is said
426 * there applies here, too.
427 *
428 * @see KIntNumInput, KDoubleSpinBox
429 * @short An input control for real numbers, consisting of a spinbox and a slider.
430 */
431
432class KDoubleNumInput : public KNumInput
433{
434 Q_OBJECT
435 Q_PROPERTY( double value READ value WRITE setValue )
436 Q_PROPERTY( double minValue READ minValue WRITE setMinValue )
437 Q_PROPERTY( double maxValue READ maxValue WRITE setMaxValue )
438 Q_PROPERTY( QString suffix READ suffix WRITE setSuffix )
439 Q_PROPERTY( QString prefix READ prefix WRITE setPrefix )
440 Q_PROPERTY( QString specialValueText READ specialValueText WRITE setSpecialValueText )
441 Q_PROPERTY( int precision READ precision WRITE setPrecision )
442
443public:
444 /**
445 * Constructs an input control for double values
446 * with initial value 0.00.
447 */
448 KDoubleNumInput(QWidget *parent=0, const char *name=0);
449
450 /**
451 * @deprecated (value is rounded to a multiple of 1/100)
452 * Constructor
453 *
454 * @param value initial value for the control
455 * @param parent parent QWidget
456 * @param name internal name for this widget
457 */
458 KDoubleNumInput(double value, QWidget *parent=0, const char *name=0);
459
460 /**
461 * Constructor
462 *
463 * @param lower lower boundary value
464 * @param upper upper boundary value
465 * @param value initial value for the control
466 * @param step step size to use for up/down arrow clicks
467 * @param precision number of digits after the decimal point
468 * @param parent parent QWidget
469 * @param name internal name for this widget
470 * @since 3.1
471 */
472 KDoubleNumInput(double lower, double upper, double value, double step=0.01,
473 int precision=2, QWidget *parent=0, const char *name=0);
474
475 /**
476 * destructor
477 */
478 virtual ~KDoubleNumInput();
479
480 /**
481 * @deprecated (rounds @p value to a mulitple of 1/100)
482 * Constructor
483 *
484 * puts it below other KNumInput
485 *
486 * @param below
487 * @param value initial value for the control
488 * @param parent parent QWidget
489 * @param name internal name for this widget
490 **/
491 KDoubleNumInput(KNumInput* below, double value, QWidget* parent=0, const char* name=0);
492
493 /**
494 * Constructor
495 *
496 * puts it below other KNumInput
497 *
498 * @param lower lower boundary value
499 * @param upper upper boundary value
500 * @param value initial value for the control
501 * @param step step size to use for up/down arrow clicks
502 * @param precision number of digits after the decimal point
503 * @param parent parent QWidget
504 * @param name internal name for this widget
505 * @since 3.1
506 */
507 KDoubleNumInput(KNumInput* below,
508 double lower, double upper, double value, double step=0.02,
509 int precision=2, QWidget *parent=0, const char *name=0);
510
511 /**
512 * @return the current value.
513 */
514 double value() const;
515
516 /**
517 * @return the suffix.
518 * @see #setSuffix()
519 */
520 QString suffix() const;
521
522 /**
523 * @return the prefix.
524 * @see #setPrefix()
525 */
526 QString prefix() const;
527
528 /**
529 * @return the precision.
530 * @see #setPrecision()
531 */
532 int precision() const;
533
534 /**
535 * @return the string displayed for a special value.
536 * @see #setSpecialValueText()
537 */
538 QString specialValueText() const { return m_specialvalue; }
539
540 /**
541 * @param min minimum value
542 * @param max maximum value
543 * @param step step size for the QSlider
544 */
545 void setRange(double min, double max, double step=1, bool slider=true);
546 /**
547 * Sets the minimum value.
548 */
549 void setMinValue(double min);
550 /**
551 * @return the minimum value.
552 */
553 double minValue() const;
554 /**
555 * Sets the maximum value.
556 */
557 void setMaxValue(double max);
558 /**
559 * @return the maximum value.
560 */
561 double maxValue() const;
562
563 /**
564 * Specifies the number of digits to use.
565 */
566 void setPrecision(int precision);
567
568 /**
569 * @return the reference point for @ref #relativeValue calculation
570 * @since 3.1
571 */
572 double referencePoint() const;
573
574 /**
575 * @return the current value in units of @ref #referencePoint.
576 * @since 3.1
577 */
578 double relativeValue() const;
579
580 /**
581 * Sets the special value text. If set, the spin box will display
582 * this text instead of the numeric value whenever the current
583 * value is equal to @ref #minVal(). Typically this is used for indicating
584 * that the choice has a special (default) meaning.
585 */
586 void setSpecialValueText(const QString& text);
587
588 /**
589 * @reimplemented
590 */
591 virtual void setLabel(const QString & label, int a = AlignLeft | AlignTop);
592 /**
593 * @reimplemented
594 */
595 virtual QSize minimumSizeHint() const;
596 /**
597 * @reimplemented
598 */
599 virtual bool eventFilter(QObject*, QEvent*);
600
601public slots:
602 /**
603 * Sets the value of the control.
604 */
605 void setValue(double);
606
607 /**
608 * Sets the value in units of @ref #referencePoint.
609 * @since 3.1
610 */
611 void setRelativeValue(double);
612
613 /**
614 * Sets the reference Point to @p ref. It @p ref == 0, emitting of
615 * @ref #relativeValueChanged is blocked and @ref #relativeValue
616 * just returns 0.
617 * @since 3.1
618 */
619 void setReferencePoint(double ref);
620
621 /**
622 * 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
624 * spacing. So if you prefer to display a space separator, set suffix
625 * to something like " cm".
626 * @see #setSuffix()
627 */
628 void setSuffix(const QString &suffix);
629
630 /**
631 * 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
633 * spacing.
634 * @see #setPrefix()
635 */
636 void setPrefix(const QString &prefix);
637
638signals:
639 /**
640 * Emitted every time the value changes (by calling @ref setValue() or
641 * by user interaction).
642 */
643 void valueChanged(double);
644 /**
645 * This is an overloaded member function, provided for
646 * convenience. It essentially behaves like the above function.
647 *
648 * Contains the value in units of @ref #referencePoint.
649 * @since 3.1
650 */
651 void relativeValueChanged(double);
652
653private slots:
654 void sliderMoved(int);
655 void slotEmitRelativeValueChanged(double);
656
657protected:
658
659 /**
660 * @reimplemented
661 */
662 virtual void doLayout();
663 /**
664 * @reimplemented
665 */
666 void resizeEvent ( QResizeEvent * );
667 virtual void resetEditBox();
668
669 // ### no longer used, remove when BIC allowed
670 KDoubleLine* edit;
671
672 bool m_range;
673 double m_lower, m_upper, m_step;
674 // ### end no longer used
675
676 QSize m_sizeEdit;
677
678 friend class KDoubleLine;
679private:
680 void init(double value, double lower, double upper,
681 double step, int precision);
682 double mapSliderToSpin(int) const;
683 void updateLegacyMembers();
684 // ### no longer used, remove when BIC allowed:
685 QString m_specialvalue, m_prefix, m_suffix;
686 double m_value;
687 short m_precision;
688 // ### end remove when BIC allowed
689
690protected:
691 virtual void virtual_hook( int id, void* data );
692private:
693 class KDoubleNumInputPrivate;
694 KDoubleNumInputPrivate *d;
695};
696
697
698/* ------------------------------------------------------------------------ */
699
700/**
701 * A @ref QSpinBox with support for arbitrary base numbers
702 * (e.g. hexadecimal).
703 *
704 * The class provides an easy interface to use other
705 * numeric systems than the decimal.
706 *
707 * @short A @ref QSpinBox with support for arbitrary base numbers.
708 */
709class KIntSpinBox : public QSpinBox
710{
711 Q_OBJECT
712 Q_PROPERTY( int base READ base WRITE setBase )
713
714public:
715
716 /**
717 * Constructor.
718 *
719 * 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
721 * and initial value 0.
722 */
723 KIntSpinBox( QWidget *parent=0, const char *name=0);
724
725 /**
726 * Constructor.
727 *
728 * Constructs a widget with an integer inputline with a little scrollbar
729 * and a slider.
730 *
731 * @param lower The lowest valid value.
732 * @param upper The greatest valid value.
733 * @param step The step size of the scrollbar.
734 * @param value The actual value.
735 * @param base The base of the used number system.
736 * @param parent The parent of the widget.
737 * @param name The Name of the widget.
738 */
739 KIntSpinBox(int lower, int upper, int step, int value, int base = 10,
740 QWidget* parent = 0, const char* name = 0);
741
742 /**
743 * Destructor.
744 */
745 virtual ~KIntSpinBox();
746
747 /**
748 * Sets the base in which the numbers in the spin box are represented.
749 */
750 void setBase(int base);
751 /**
752 * @return the base in which numbers in the spin box are represented.
753 */
754 int base() const;
755 /**
756 * sets focus and optionally marks all text
757 *
758 */
759 void setEditFocus(bool mark);
760
761protected:
762
763 /**
764 * Overloaded the method in QSpinBox
765 * to make use of the base given in the constructor.
766 */
767 virtual QString mapValueToText(int);
768
769 /**
770 * Overloaded the method in QSpinBox
771 * to make use of the base given in the constructor.
772 */
773 virtual int mapTextToValue(bool*);
774
775private:
776 int val_base;
777protected:
778 virtual void virtual_hook( int id, void* data );
779private:
780 class KIntSpinBoxPrivate;
781 KIntSpinBoxPrivate *d;
782};
783
784
785/* --------------------------------------------------------------------------- */
786
787/**
788 This class provides a spin box for fractional numbers.
789
790 @sect Parameters
791
792 There are a number of interdependent parameters whose relation to
793 each other you need to understand in order to make successful use
794 of the spin box.
795
796 @li precision: The number of decimals after the decimal point.
797 @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
799 the up or down buttons
800
801 Since we work with fixed-point numbers internally, the maximum
802 precision is a function of the valid range and vice versa. More
803 precisely, the following relations hold:
804 <pre>
805 max( abs(minValue()), abs(maxValue() ) <= INT_MAX/10^precision
806 maxPrecision = floor( log10( INT_MAX/max(abs(minValue()),abs(maxValue())) ) )
807 </pre>
808
809 Since the value, bounds and step are rounded to the current
810 precision, you may experience that the order of setting above
811 parameters matters. E.g. the following are @em not equivalent (try
812 it!):
813
814 <pre>
815 // sets precision,
816 // then min/max value (rounded to precison and clipped to obtainable range if needed)
817 // then value and lineStep
818 KDoubleSpinBox * spin = new KDoubleSpinBox( 0, 9.999, 0.001, 4.321, 3, this );
819
820 // 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...
822 KDpubleSpinBox * spin = new KDoubleSpinBox( this );
823 spin->setMinValue( 0 );
824 spin->setMaxValue( 9.999 );
825 spin->setValue( 4.321 );
826 spin->setPrecision( 3 );
827 </pre>
828
829 @short A spin box for fractional numbers.
830 @author Marc Mutz <mutz@kde.org>
831 @version $Id$
832 @since 3.1
833**/
834
835class KDoubleSpinBox : public QSpinBox {
836 Q_OBJECT
837 Q_PROPERTY( bool acceptLocalizedNumbers READ acceptLocalizedNumbers WRITE setAcceptLocalizedNumbers )
838 Q_OVERRIDE( double maxValue READ maxValue WRITE setMaxValue )
839 Q_OVERRIDE( double minValue READ minValue WRITE setMinValue )
840 Q_OVERRIDE( double lineStep READ lineStep WRITE setLineStep )
841 Q_OVERRIDE( double value READ value WRITE setValue )
842 Q_PROPERTY( int precision READ precision WRITE setPrecision )
843
844public:
845 /** Constructs a @ref KDoubleSpinBox with parent @p parent and
846 default values for range and value (whatever @ref QRangeControl
847 uses) and precision (2). */
848 KDoubleSpinBox( QWidget * parent=0, const char * name=0 );
849 /** Constructs a @ref KDoubleSpinBox with parent @p parent, range
850 [@p lower,@p upper], @ref lineStep @p step, @ref precision @p
851 precision and initial value @p value. */
852 KDoubleSpinBox( double lower, double upper, double step, double value,
853 int precision=2, QWidget * parent=0, const char * name=0 );
854
855 virtual ~KDoubleSpinBox();
856
857 /** @return whether the spinbox uses localized numbers */
858 bool acceptLocalizedNumbers() const;
859 /** Sets whether to use and accept localized numbers as returned by
860 @ref KLocale::formatNumber() */
861 virtual void setAcceptLocalizedNumbers( bool accept );
862
863 /** Sets a new range for the spin box values. Note that @p lower, @p
864 upper and @p step are rounded to @p precision decimal points
865 first. */
866 void setRange( double lower, double upper, double step=0.01, int precision=2 );
867
868 /** @return the current number of decimal points displayed. */
869 int precision() const;
870 /** Equivalent to @ref setPrecsion( @p precison, @p false ); Needed
871 since Qt's moc doesn't ignore trailing parameters with default
872 args when searching for a property setter method. */
873 void setPrecision( int precision );
874 /** Sets the number of decimal points to use. Note that there is a
875 tradeoff between the precision used and the available range of
876 values. See the class docs for more.
877 @param precision the new number of decimal points to use
878
879 @param force disables checking of bound violations that can
880 arise if you increase the precision so much that the
881 minimum and maximum values can't be represented
882 anymore. Disabling is useful if you don't want to keep
883 the current min and max values anyway. This is what
884 e.g. @ref setRange() does.
885 **/
886 virtual void setPrecision( int precision, bool force );
887
888 /** @return the current value */
889 double value() const;
890 /** @return the current lower bound */
891 double minValue() const;
892 /** Sets the lower bound of the range to @p value, subject to the
893 contraints that @p value is first rounded to the current
894 precision and then clipped to the maximum representable
895 interval.
896 @see maxValue, minValue, setMaxValue, setRange
897 */
898 void setMinValue( double value );
899 /** @return the current upper bound */
900 double maxValue() const;
901 /** Sets the upper bound of the range to @p value, subject to the
902 contraints that @p value is first rounded to the current
903 precision and then clipped to the maximum representable
904 interval.
905 @see minValue, maxValue, setMinValue, setRange
906 */
907 void setMaxValue( double value );
908
909 /** @return the current step size */
910 double lineStep() const;
911 /** Sets the step size for clicking the up/down buttons to @p step,
912 subject to the constraints that @p step is first rounded to the
913 current precision and then clipped to the meaningful interval
914 [1, @p maxValue - @p minValue]. */
915 void setLineStep( double step );
916
917 /** Overridden to ignore any setValidator() calls. */
918 void setValidator( const QValidator * );
919
920signals:
921 /** Emitted whenever @ref QSpinBox::valueChanged( int ) is emitted. */
922 void valueChanged( double value );
923
924public slots:
925 /** Sets the current value to @p value, cubject to the constraints
926 that @p value is frist rounded to the current precision and then
927 clipped to the interval [@p minvalue(),@p maxValue()]. */
928 virtual void setValue( double value );
929
930protected:
931 virtual QString mapValueToText(int);
932 virtual int mapTextToValue(bool*);
933
934protected slots:
935 void slotValueChanged( int value );
936
937protected:
938 virtual void virtual_hook( int id, void* data );
939private:
940 typedef QSpinBox base;
941 void updateValidator();
942 int maxPrecision() const;
943
944 class Private;
945 Private * d;
946};
947
948#endif // K_NUMINPUT_H