Diffstat (limited to 'noncore/settings/networksettings/ppp/knuminput.h') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/networksettings/ppp/knuminput.h | 947 |
1 files changed, 947 insertions, 0 deletions
diff --git a/noncore/settings/networksettings/ppp/knuminput.h b/noncore/settings/networksettings/ppp/knuminput.h new file mode 100644 index 0000000..67f3b44 --- a/dev/null +++ b/noncore/settings/networksettings/ppp/knuminput.h | |||
@@ -0,0 +1,947 @@ | |||
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 | |||
33 | class QLabel; | ||
34 | class QSlider; | ||
35 | class QLineEdit; | ||
36 | class QLayout; | ||
37 | class QValidator; | ||
38 | |||
39 | class 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 | */ | ||
48 | class KNumInput : public QWidget | ||
49 | { | ||
50 | Q_OBJECT | ||
51 | Q_PROPERTY( QString label READ label WRITE setLabel ) | ||
52 | public: | ||
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 | |||
118 | protected: | ||
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 | |||
145 | private: | ||
146 | void init(); | ||
147 | |||
148 | protected: | ||
149 | virtual void virtual_hook( int id, void* data ); | ||
150 | private: | ||
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 | |||
181 | class 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 | |||
192 | public: | ||
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 | |||
316 | public 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 | |||
360 | signals: | ||
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 | |||
374 | private slots: | ||
375 | void spinValueChanged(int); | ||
376 | void slotEmitRelativeValueChanged(int); | ||
377 | |||
378 | protected: | ||
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 | |||
391 | private: | ||
392 | void init(int value, int _base); | ||
393 | |||
394 | protected: | ||
395 | virtual void virtual_hook( int id, void* data ); | ||
396 | private: | ||
397 | class KIntNumInputPrivate; | ||
398 | KIntNumInputPrivate *d; | ||
399 | }; | ||
400 | |||
401 | |||
402 | /* ------------------------------------------------------------------------ */ | ||
403 | |||
404 | class 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 | |||
432 | class 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 | |||
442 | public: | ||
443 | /** | ||
444 | * Constructs an input control for double values | ||
445 | * with initial value 0.00. | ||
446 | */ | ||
447 | KDoubleNumInput(QWidget *parent=0, const char *name=0); | ||
448 | |||
449 | /** | ||
450 | * @deprecated (value is rounded to a multiple of 1/100) | ||
451 | * Constructor | ||
452 | * | ||
453 | * @param value initial value for the control | ||
454 | * @param parent parent QWidget | ||
455 | * @param name internal name for this widget | ||
456 | */ | ||
457 | KDoubleNumInput(double value, QWidget *parent=0, const char *name=0); | ||
458 | |||
459 | /** | ||
460 | * Constructor | ||
461 | * | ||
462 | * @param lower lower boundary value | ||
463 | * @param upper upper boundary value | ||
464 | * @param value initial value for the control | ||
465 | * @param step step size to use for up/down arrow clicks | ||
466 | * @param precision number of digits after the decimal point | ||
467 | * @param parent parent QWidget | ||
468 | * @param name internal name for this widget | ||
469 | * @since 3.1 | ||
470 | */ | ||
471 | KDoubleNumInput(double lower, double upper, double value, double step=0.01, | ||
472 | int precision=2, QWidget *parent=0, const char *name=0); | ||
473 | |||
474 | /** | ||
475 | * destructor | ||
476 | */ | ||
477 | virtual ~KDoubleNumInput(); | ||
478 | |||
479 | /** | ||
480 | * @deprecated (rounds @p value to a mulitple of 1/100) | ||
481 | * Constructor | ||
482 | * | ||
483 | * puts it below other KNumInput | ||
484 | * | ||
485 | * @param below | ||
486 | * @param value initial value for the control | ||
487 | * @param parent parent QWidget | ||
488 | * @param name internal name for this widget | ||
489 | **/ | ||
490 | KDoubleNumInput(KNumInput* below, double value, QWidget* parent=0, const char* name=0); | ||
491 | |||
492 | /** | ||
493 | * Constructor | ||
494 | * | ||
495 | * puts it below other KNumInput | ||
496 | * | ||
497 | * @param lower lower boundary value | ||
498 | * @param upper upper boundary value | ||
499 | * @param value initial value for the control | ||
500 | * @param step step size to use for up/down arrow clicks | ||
501 | * @param precision number of digits after the decimal point | ||
502 | * @param parent parent QWidget | ||
503 | * @param name internal name for this widget | ||
504 | * @since 3.1 | ||
505 | */ | ||
506 | KDoubleNumInput(KNumInput* below, | ||
507 | double lower, double upper, double value, double step=0.02, | ||
508 | int precision=2, QWidget *parent=0, const char *name=0); | ||
509 | |||
510 | /** | ||
511 | * @return the current value. | ||
512 | */ | ||
513 | double value() const; | ||
514 | |||
515 | /** | ||
516 | * @return the suffix. | ||
517 | * @see #setSuffix() | ||
518 | */ | ||
519 | QString suffix() const; | ||
520 | |||
521 | /** | ||
522 | * @return the prefix. | ||
523 | * @see #setPrefix() | ||
524 | */ | ||
525 | QString prefix() const; | ||
526 | |||
527 | /** | ||
528 | * @return the precision. | ||
529 | * @see #setPrecision() | ||
530 | */ | ||
531 | int precision() const; | ||
532 | |||
533 | /** | ||
534 | * @return the string displayed for a special value. | ||
535 | * @see #setSpecialValueText() | ||
536 | */ | ||
537 | QString specialValueText() const { return m_specialvalue; } | ||
538 | |||
539 | /** | ||
540 | * @param min minimum value | ||
541 | * @param max maximum value | ||
542 | * @param step step size for the QSlider | ||
543 | */ | ||
544 | void setRange(double min, double max, double step=1, bool slider=true); | ||
545 | /** | ||
546 | * Sets the minimum value. | ||
547 | */ | ||
548 | void setMinValue(double min); | ||
549 | /** | ||
550 | * @return the minimum value. | ||
551 | */ | ||
552 | double minValue() const; | ||
553 | /** | ||
554 | * Sets the maximum value. | ||
555 | */ | ||
556 | void setMaxValue(double max); | ||
557 | /** | ||
558 | * @return the maximum value. | ||
559 | */ | ||
560 | double maxValue() const; | ||
561 | |||
562 | /** | ||
563 | * Specifies the number of digits to use. | ||
564 | */ | ||
565 | void setPrecision(int precision); | ||
566 | |||
567 | /** | ||
568 | * @return the reference point for @ref #relativeValue calculation | ||
569 | * @since 3.1 | ||
570 | */ | ||
571 | double referencePoint() const; | ||
572 | |||
573 | /** | ||
574 | * @return the current value in units of @ref #referencePoint. | ||
575 | * @since 3.1 | ||
576 | */ | ||
577 | double relativeValue() const; | ||
578 | |||
579 | /** | ||
580 | * Sets the special value text. If set, the spin box will display | ||
581 | * this text instead of the numeric value whenever the current | ||
582 | * value is equal to @ref #minVal(). Typically this is used for indicating | ||
583 | * that the choice has a special (default) meaning. | ||
584 | */ | ||
585 | void setSpecialValueText(const QString& text); | ||
586 | |||
587 | /** | ||
588 | * @reimplemented | ||
589 | */ | ||
590 | virtual void setLabel(const QString & label, int a = AlignLeft | AlignTop); | ||
591 | /** | ||
592 | * @reimplemented | ||
593 | */ | ||
594 | virtual QSize minimumSizeHint() const; | ||
595 | /** | ||
596 | * @reimplemented | ||
597 | */ | ||
598 | virtual bool eventFilter(QObject*, QEvent*); | ||
599 | |||
600 | public slots: | ||
601 | /** | ||
602 | * Sets the value of the control. | ||
603 | */ | ||
604 | void setValue(double); | ||
605 | |||
606 | /** | ||
607 | * Sets the value in units of @ref #referencePoint. | ||
608 | * @since 3.1 | ||
609 | */ | ||
610 | void setRelativeValue(double); | ||
611 | |||
612 | /** | ||
613 | * Sets the reference Point to @p ref. It @p ref == 0, emitting of | ||
614 | * @ref #relativeValueChanged is blocked and @ref #relativeValue | ||
615 | * just returns 0. | ||
616 | * @since 3.1 | ||
617 | */ | ||
618 | void setReferencePoint(double ref); | ||
619 | |||
620 | /** | ||
621 | * Sets the suffix to be displayed to @p suffix. Use QString::null to disable | ||
622 | * this feature. Note that the suffix is attached to the value without any | ||
623 | * spacing. So if you prefer to display a space separator, set suffix | ||
624 | * to something like " cm". | ||
625 | * @see #setSuffix() | ||
626 | */ | ||
627 | void setSuffix(const QString &suffix); | ||
628 | |||
629 | /** | ||
630 | * Sets the prefix to be displayed to @p prefix. Use QString::null to disable | ||
631 | * this feature. Note that the prefix is attached to the value without any | ||
632 | * spacing. | ||
633 | * @see #setPrefix() | ||
634 | */ | ||
635 | void setPrefix(const QString &prefix); | ||
636 | |||
637 | signals: | ||
638 | /** | ||
639 | * Emitted every time the value changes (by calling @ref setValue() or | ||
640 | * by user interaction). | ||
641 | */ | ||
642 | void valueChanged(double); | ||
643 | /** | ||
644 | * This is an overloaded member function, provided for | ||
645 | * convenience. It essentially behaves like the above function. | ||
646 | * | ||
647 | * Contains the value in units of @ref #referencePoint. | ||
648 | * @since 3.1 | ||
649 | */ | ||
650 | void relativeValueChanged(double); | ||
651 | |||
652 | private slots: | ||
653 | void sliderMoved(int); | ||
654 | void slotEmitRelativeValueChanged(double); | ||
655 | |||
656 | protected: | ||
657 | |||
658 | /** | ||
659 | * @reimplemented | ||
660 | */ | ||
661 | virtual void doLayout(); | ||
662 | /** | ||
663 | * @reimplemented | ||
664 | */ | ||
665 | void resizeEvent ( QResizeEvent * ); | ||
666 | virtual void resetEditBox(); | ||
667 | |||
668 | // ### no longer used, remove when BIC allowed | ||
669 | KDoubleLine* edit; | ||
670 | |||
671 | bool m_range; | ||
672 | double m_lower, m_upper, m_step; | ||
673 | // ### end no longer used | ||
674 | |||
675 | QSize m_sizeEdit; | ||
676 | |||
677 | friend class KDoubleLine; | ||
678 | private: | ||
679 | void init(double value, double lower, double upper, | ||
680 | double step, int precision); | ||
681 | double mapSliderToSpin(int) const; | ||
682 | void updateLegacyMembers(); | ||
683 | // ### no longer used, remove when BIC allowed: | ||
684 | QString m_specialvalue, m_prefix, m_suffix; | ||
685 | double m_value; | ||
686 | short m_precision; | ||
687 | // ### end remove when BIC allowed | ||
688 | |||
689 | protected: | ||
690 | virtual void virtual_hook( int id, void* data ); | ||
691 | private: | ||
692 | class KDoubleNumInputPrivate; | ||
693 | KDoubleNumInputPrivate *d; | ||
694 | }; | ||
695 | |||
696 | |||
697 | /* ------------------------------------------------------------------------ */ | ||
698 | |||
699 | /** | ||
700 | * A @ref QSpinBox with support for arbitrary base numbers | ||
701 | * (e.g. hexadecimal). | ||
702 | * | ||
703 | * The class provides an easy interface to use other | ||
704 | * numeric systems then the decimal. | ||
705 | * | ||
706 | * @short A @ref QSpinBox with support for arbitrary base numbers. | ||
707 | */ | ||
708 | class KIntSpinBox : public QSpinBox | ||
709 | { | ||
710 | Q_OBJECT | ||
711 | Q_PROPERTY( int base READ base WRITE setBase ) | ||
712 | |||
713 | public: | ||
714 | |||
715 | /** | ||
716 | * Constructor. | ||
717 | * | ||
718 | * Constructs a widget with an integer inputline with a little scrollbar | ||
719 | * and a slider, with minimal value 0, maximal value 99, step 1, base 10 | ||
720 | * and initial value 0. | ||
721 | */ | ||
722 | KIntSpinBox( QWidget *parent=0, const char *name=0); | ||
723 | |||
724 | /** | ||
725 | * Constructor. | ||
726 | * | ||
727 | * Constructs a widget with an integer inputline with a little scrollbar | ||
728 | * and a slider. | ||
729 | * | ||
730 | * @param lower The lowest valid value. | ||
731 | * @param upper The greatest valid value. | ||
732 | * @param step The step size of the scrollbar. | ||
733 | * @param value The actual value. | ||
734 | * @param base The base of the used number system. | ||
735 | * @param parent The parent of the widget. | ||
736 | * @param name The Name of the widget. | ||
737 | */ | ||
738 | KIntSpinBox(int lower, int upper, int step, int value, int base = 10, | ||
739 | QWidget* parent = 0, const char* name = 0); | ||
740 | |||
741 | /** | ||
742 | * Destructor. | ||
743 | */ | ||
744 | virtual ~KIntSpinBox(); | ||
745 | |||
746 | /** | ||
747 | * Sets the base in which the numbers in the spin box are represented. | ||
748 | */ | ||
749 | void setBase(int base); | ||
750 | /** | ||
751 | * @return the base in which numbers in the spin box are represented. | ||
752 | */ | ||
753 | int base() const; | ||
754 | /** | ||
755 | * sets focus and optionally marks all text | ||
756 | * | ||
757 | */ | ||
758 | void setEditFocus(bool mark); | ||
759 | |||
760 | protected: | ||
761 | |||
762 | /** | ||
763 | * Overloaded the method in QSpinBox | ||
764 | * to make use of the base given in the constructor. | ||
765 | */ | ||
766 | virtual QString mapValueToText(int); | ||
767 | |||
768 | /** | ||
769 | * Overloaded the method in QSpinBox | ||
770 | * to make use of the base given in the constructor. | ||
771 | */ | ||
772 | virtual int mapTextToValue(bool*); | ||
773 | |||
774 | private: | ||
775 | int val_base; | ||
776 | protected: | ||
777 | virtual void virtual_hook( int id, void* data ); | ||
778 | private: | ||
779 | class KIntSpinBoxPrivate; | ||
780 | KIntSpinBoxPrivate *d; | ||
781 | }; | ||
782 | |||
783 | |||
784 | /* --------------------------------------------------------------------------- */ | ||
785 | |||
786 | /** | ||
787 | This class provides a spin box for fractional numbers. | ||
788 | |||
789 | @sect Parameters | ||
790 | |||
791 | There are a number of interdependent parameters whose relation to | ||
792 | each other you need to understand in order to make successful use | ||
793 | of the spin box. | ||
794 | |||
795 | @li precision: The number of decimals after the decimal point. | ||
796 | @li maxValue/minValue: upper and lower bound of the valid range | ||
797 | @li lineStep: the size of the step that is taken when the user hits | ||
798 | the up or down buttons | ||
799 | |||
800 | Since we work with fixed-point numbers internally, the maximum | ||
801 | precision is a function of the valid range and vice versa. More | ||
802 | precisely, the following relations hold: | ||
803 | <pre> | ||
804 | max( abs(minValue()), abs(maxValue() ) <= INT_MAX/10^precision | ||
805 | maxPrecision = floor( log10( INT_MAX/max(abs(minValue()),abs(maxValue())) ) ) | ||
806 | </pre> | ||
807 | |||
808 | Since the value, bounds and step are rounded to the current | ||
809 | precision, you may experience that the order of setting above | ||
810 | parameters matters. E.g. the following are @em not equivalent (try | ||
811 | it!): | ||
812 | |||
813 | <pre> | ||
814 | // sets precision, | ||
815 | // then min/max value (rounded to precison and clipped to obtainable range if needed) | ||
816 | // then value and lineStep | ||
817 | KDoubleSpinBox * spin = new KDoubleSpinBox( 0, 9.999, 0.001, 4.321, 3, this ); | ||
818 | |||
819 | // sets minValue to 0; maxValue to 10.00(!); value to 4.32(!) and only then | ||
820 | // increases the precision - too late, since e.g. value has already been rounded... | ||
821 | KDpubleSpinBox * spin = new KDoubleSpinBox( this ); | ||
822 | spin->setMinValue( 0 ); | ||
823 | spin->setMaxValue( 9.999 ); | ||
824 | spin->setValue( 4.321 ); | ||
825 | spin->setPrecision( 3 ); | ||
826 | </pre> | ||
827 | |||
828 | @short A spin box for fractional numbers. | ||
829 | @author Marc Mutz <mutz@kde.org> | ||
830 | @version $Id$ | ||
831 | @since 3.1 | ||
832 | **/ | ||
833 | |||
834 | class KDoubleSpinBox : public QSpinBox { | ||
835 | Q_OBJECT | ||
836 | Q_PROPERTY( bool acceptLocalizedNumbers READ acceptLocalizedNumbers WRITE setAcceptLocalizedNumbers ) | ||
837 | Q_OVERRIDE( double maxValue READ maxValue WRITE setMaxValue ) | ||
838 | Q_OVERRIDE( double minValue READ minValue WRITE setMinValue ) | ||
839 | Q_OVERRIDE( double lineStep READ lineStep WRITE setLineStep ) | ||
840 | Q_OVERRIDE( double value READ value WRITE setValue ) | ||
841 | Q_PROPERTY( int precision READ precision WRITE setPrecision ) | ||
842 | |||
843 | public: | ||
844 | /** Constructs a @ref KDoubleSpinBox with parent @p parent and | ||
845 | default values for range and value (whatever @ref QRangeControl | ||
846 | uses) and precision (2). */ | ||
847 | KDoubleSpinBox( QWidget * parent=0, const char * name=0 ); | ||
848 | /** Constructs a @ref KDoubleSpinBox with parent @p parent, range | ||
849 | [@p lower,@p upper], @ref lineStep @p step, @ref precision @p | ||
850 | precision and initial value @p value. */ | ||
851 | KDoubleSpinBox( double lower, double upper, double step, double value, | ||
852 | int precision=2, QWidget * parent=0, const char * name=0 ); | ||
853 | |||
854 | virtual ~KDoubleSpinBox(); | ||
855 | |||
856 | /** @return whether the spinbox uses localized numbers */ | ||
857 | bool acceptLocalizedNumbers() const; | ||
858 | /** Sets whether to use and accept localized numbers as returned by | ||
859 | @ref KLocale::formatNumber() */ | ||
860 | virtual void setAcceptLocalizedNumbers( bool accept ); | ||
861 | |||
862 | /** Sets a new range for the spin box values. Note that @p lower, @p | ||
863 | upper and @p step are rounded to @p precision decimal points | ||
864 | first. */ | ||
865 | void setRange( double lower, double upper, double step=0.01, int precision=2 ); | ||
866 | |||
867 | /** @return the current number of decimal points displayed. */ | ||
868 | int precision() const; | ||
869 | /** Equivalent to @ref setPrecsion( @p precison, @p false ); Needed | ||
870 | since Qt's moc doesn't ignore trailing parameters with default | ||
871 | args when searching for a property setter method. */ | ||
872 | void setPrecision( int precision ); | ||
873 | /** Sets the number of decimal points to use. Note that there is a | ||
874 | tradeoff between the precision used and the available range of | ||
875 | values. See the class docs for more. | ||
876 | @param precision the new number of decimal points to use | ||
877 | |||
878 | @param force disables checking of bound violations that can | ||
879 | arise if you increase the precision so much that the | ||
880 | minimum and maximum values can't be represented | ||
881 | anymore. Disabling is useful if you don't want to keep | ||
882 | the current min and max values anyway. This is what | ||
883 | e.g. @ref setRange() does. | ||
884 | **/ | ||
885 | virtual void setPrecision( int precision, bool force ); | ||
886 | |||
887 | /** @return the current value */ | ||
888 | double value() const; | ||
889 | /** @return the current lower bound */ | ||
890 | double minValue() const; | ||
891 | /** Sets the lower bound of the range to @p value, subject to the | ||
892 | contraints that @p value is first rounded to the current | ||
893 | precision and then clipped to the maximum representable | ||
894 | interval. | ||
895 | @see maxValue, minValue, setMaxValue, setRange | ||
896 | */ | ||
897 | void setMinValue( double value ); | ||
898 | /** @return the current upper bound */ | ||
899 | double maxValue() const; | ||
900 | /** Sets the upper bound of the range to @p value, subject to the | ||
901 | contraints that @p value is first rounded to the current | ||
902 | precision and then clipped to the maximum representable | ||
903 | interval. | ||
904 | @see minValue, maxValue, setMinValue, setRange | ||
905 | */ | ||
906 | void setMaxValue( double value ); | ||
907 | |||
908 | /** @return the current step size */ | ||
909 | double lineStep() const; | ||
910 | /** Sets the step size for clicking the up/down buttons to @p step, | ||
911 | subject to the constraints that @p step is first rounded to the | ||
912 | current precision and then clipped to the meaningful interval | ||
913 | [1, @p maxValue - @p minValue]. */ | ||
914 | void setLineStep( double step ); | ||
915 | |||
916 | /** Overridden to ignore any setValidator() calls. */ | ||
917 | void setValidator( const QValidator * ); | ||
918 | |||
919 | signals: | ||
920 | /** Emitted whenever @ref QSpinBox::valueChanged( int ) is emitted. */ | ||
921 | void valueChanged( double value ); | ||
922 | |||
923 | public slots: | ||
924 | /** Sets the current value to @p value, cubject to the constraints | ||
925 | that @p value is frist rounded to the current precision and then | ||
926 | clipped to the interval [@p minvalue(),@p maxValue()]. */ | ||
927 | virtual void setValue( double value ); | ||
928 | |||
929 | protected: | ||
930 | virtual QString mapValueToText(int); | ||
931 | virtual int mapTextToValue(bool*); | ||
932 | |||
933 | protected slots: | ||
934 | void slotValueChanged( int value ); | ||
935 | |||
936 | protected: | ||
937 | virtual void virtual_hook( int id, void* data ); | ||
938 | private: | ||
939 | typedef QSpinBox base; | ||
940 | void updateValidator(); | ||
941 | int maxPrecision() const; | ||
942 | |||
943 | class Private; | ||
944 | Private * d; | ||
945 | }; | ||
946 | |||
947 | #endif // K_NUMINPUT_H | ||