File indexing completed on 2024-04-21 14:55:57
0001 /* This file is part of the KDE libraries 0002 * Copyright (c) 1997 Patrick Dowler <dowler@morgul.fsh.uvic.ca> 0003 * Copyright (c) 2000 Dirk Mueller <mueller@kde.org> 0004 * Copyright (c) 2002 Marc Mutz <mutz@kde.org> 0005 * 0006 * This library is free software; you can redistribute it and/or 0007 * modify it under the terms of the GNU Library General Public 0008 * License as published by the Free Software Foundation; either 0009 * version 2 of the License, or (at your option) any later version. 0010 * 0011 * This library is distributed in the hope that it will be useful, 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0014 * Library General Public License for more details. 0015 * 0016 * You should have received a copy of the GNU Library General Public License 0017 * along with this library; see the file COPYING.LIB. If not, write to 0018 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0019 * Boston, MA 02110-1301, USA. 0020 */ 0021 0022 #ifndef K_NUMINPUT_H 0023 #define K_NUMINPUT_H 0024 0025 #include <kdelibs4support_export.h> 0026 0027 #include <QWidget> 0028 #include <QSpinBox> 0029 0030 class QSlider; 0031 class QSpinBox; 0032 class QValidator; 0033 0034 class KIntSpinBox; 0035 class KNumInputPrivate; 0036 class KLocalizedString; 0037 0038 /** 0039 * @deprecated since 5.0, use QSpinBox instead 0040 * 0041 * You need to inherit from this class if you want to implement K*NumInput 0042 * for a different variable type 0043 * 0044 */ 0045 class KDELIBS4SUPPORT_DEPRECATED_EXPORT KNumInput : public QWidget 0046 { 0047 Q_OBJECT 0048 Q_PROPERTY(QString label READ label WRITE setLabel) 0049 public: 0050 /** 0051 * Default constructor 0052 * @param parent If parent is 0, the new widget becomes a top-level 0053 * window. If parent is another widget, this widget becomes a child 0054 * window inside parent. The new widget is deleted when its parent is deleted. 0055 */ 0056 KDELIBS4SUPPORT_DEPRECATED explicit KNumInput(QWidget *parent = nullptr); 0057 0058 /** 0059 * @param below A pointer to another KNumInput. 0060 * @param parent parent widget 0061 * \deprecated - use the version without the below parameter instead 0062 */ 0063 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED 0064 KDELIBS4SUPPORT_DEPRECATED KNumInput(QWidget *parent, KNumInput *below); 0065 #endif 0066 0067 /** 0068 * Destructor 0069 */ 0070 ~KNumInput() override; 0071 0072 /** 0073 * Sets the text and alignment of the main description label. 0074 * 0075 * @param label The text of the label. 0076 * Use QString() to remove an existing one. 0077 * 0078 * @param a The alignment of the label (Qt::Alignment). 0079 * Default is @p Qt:AlignLeft | @p Qt:AlignTop. 0080 * 0081 * The vertical alignment flags have special meaning with this 0082 * widget: 0083 * 0084 * @li @p Qt:AlignTop The label is placed above the edit/slider 0085 * @li @p Qt:AlignVCenter The label is placed left beside the edit 0086 * @li @p Qt:AlignBottom The label is placed below the edit/slider 0087 * 0088 */ 0089 virtual void setLabel(const QString &label, Qt::Alignment a = Qt::AlignLeft | Qt::AlignTop); 0090 0091 /** 0092 * @return the text of the label. 0093 */ 0094 QString label() const; 0095 0096 /** 0097 * @return if the num input has a slider. 0098 */ 0099 bool showSlider() const; 0100 0101 /** 0102 * Sets the spacing of tickmarks for the slider. 0103 * 0104 * @param minor Minor tickmark separation. 0105 * @param major Major tickmark separation. 0106 */ 0107 void setSteps(int minor, int major); 0108 0109 /** 0110 * Returns a size which fits the contents of the control. 0111 * 0112 * @return the preferred size necessary to show the control 0113 */ 0114 QSize sizeHint() const override; 0115 0116 protected: 0117 /** 0118 * @return the slider widget. 0119 * @internal 0120 */ 0121 QSlider *slider() const; 0122 0123 /** 0124 * Call this function whenever you change something in the geometry 0125 * of your KNumInput child. 0126 * 0127 */ 0128 void layout(bool deep); 0129 0130 /** 0131 * You need to overwrite this method and implement your layout 0132 * calculations there. 0133 * 0134 * See KIntNumInput::doLayout and KDoubleNumInput::doLayout implementation 0135 * for details. 0136 * 0137 */ 0138 virtual void doLayout() = 0; 0139 0140 private: 0141 friend class KNumInputPrivate; 0142 KNumInputPrivate *const d; 0143 0144 Q_DISABLE_COPY(KNumInput) 0145 }; 0146 0147 /* ------------------------------------------------------------------------ */ 0148 0149 /** 0150 * @deprecated since 5.0, use QSpinBox instead 0151 * 0152 * @short An input widget for integer numbers, consisting of a spinbox and a slider. 0153 * 0154 * KIntNumInput combines a QSpinBox and optionally a QSlider 0155 * with a label to make an easy to use control for setting some integer 0156 * parameter. This is especially nice for configuration dialogs, 0157 * which can have many such combinated controls. 0158 * 0159 * The slider is created only when the user specifies a range 0160 * for the control using the setRange function or when the user 0161 * calls setSliderEnabled. 0162 * 0163 * A special feature of KIntNumInput, designed specifically for 0164 * the situation when there are several KIntNumInputs in a column, 0165 * is that you can specify what portion of the control is taken by the 0166 * QSpinBox (the remaining portion is used by the slider). This makes 0167 * it very simple to have all the sliders in a column be the same size. 0168 * 0169 * It uses KIntValidator validator class. KIntNumInput enforces the 0170 * value to be in the given range, and can display it in any base 0171 * between 2 and 36. 0172 * 0173 * \image html kintnuminput.png "KDE Int Number Input Spinbox" 0174 */ 0175 0176 class KDELIBS4SUPPORT_DEPRECATED_EXPORT KIntNumInput : public KNumInput 0177 { 0178 Q_OBJECT 0179 Q_PROPERTY(int value READ value WRITE setValue NOTIFY valueChanged USER true) 0180 Q_PROPERTY(int minimum READ minimum WRITE setMinimum) 0181 Q_PROPERTY(int maximum READ maximum WRITE setMaximum) 0182 Q_PROPERTY(int singleStep READ singleStep WRITE setSingleStep) 0183 Q_PROPERTY(int referencePoint READ referencePoint WRITE setReferencePoint) 0184 Q_PROPERTY(double relativeValue READ relativeValue WRITE setRelativeValue) 0185 Q_PROPERTY(QString suffix READ suffix WRITE setSuffix) 0186 Q_PROPERTY(QString prefix READ prefix WRITE setPrefix) 0187 Q_PROPERTY(QString specialValueText READ specialValueText WRITE setSpecialValueText) 0188 Q_PROPERTY(bool sliderEnabled READ showSlider WRITE setSliderEnabled) 0189 0190 public: 0191 /** 0192 * Constructs an input control for integer values 0193 * with base 10 and initial value 0. 0194 */ 0195 KDELIBS4SUPPORT_DEPRECATED explicit KIntNumInput(QWidget *parent = nullptr); 0196 /** 0197 * Constructor 0198 * It constructs a QSpinBox that allows the input of integer numbers 0199 * in the range of -INT_MAX to +INT_MAX. To set a descriptive label, 0200 * use setLabel(). To enforce the value being in a range and optionally to 0201 * attach a slider to it, use setRange(). 0202 * 0203 * @param value initial value for the control 0204 * @param base numeric base used for display 0205 * @param parent parent QWidget 0206 */ 0207 KDELIBS4SUPPORT_DEPRECATED explicit KIntNumInput(int value, QWidget *parent = nullptr, int base = 10); 0208 0209 /** 0210 * Constructor 0211 * 0212 * the difference to the one above is the "below" parameter. It tells 0213 * this instance that it is visually put below some other KNumInput widget. 0214 * Note that these two KNumInput's need not to have the same parent widget 0215 * or be in the same layout group. 0216 * The effect is that it'll adjust its layout in correspondence 0217 * with the layout of the other KNumInput's (you can build an arbitrary long 0218 * chain). 0219 * 0220 * @param below append KIntNumInput to the KNumInput chain 0221 * @param value initial value for the control 0222 * @param base numeric base used for display 0223 * @param parent parent QWidget 0224 * 0225 * \deprecated use the version without the below parameter instead. 0226 */ 0227 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED 0228 KDELIBS4SUPPORT_DEPRECATED KIntNumInput(KNumInput *below, int value, QWidget *parent, int base = 10); 0229 #endif 0230 0231 /** 0232 * Destructor 0233 * 0234 * 0235 */ 0236 ~KIntNumInput() override; 0237 0238 /** 0239 * @return the current value. 0240 */ 0241 int value() const; 0242 0243 /** 0244 * @return the curent value in units of the referencePoint. 0245 */ 0246 double relativeValue() const; 0247 0248 /** 0249 * @return the current reference point 0250 */ 0251 int referencePoint() const; 0252 0253 /** 0254 * @return the suffix displayed behind the value. 0255 * @see setSuffix() 0256 */ 0257 QString suffix() const; 0258 /** 0259 * @return the prefix displayed in front of the value. 0260 * @see setPrefix() 0261 */ 0262 QString prefix() const; 0263 /** 0264 * @return the string displayed for a special value. 0265 * @see setSpecialValueText() 0266 */ 0267 QString specialValueText() const; 0268 0269 /** 0270 * Sets the allowed input range and the step size for the slider and the 0271 * spin box. 0272 * 0273 * @param min minimum value 0274 * @param max maximum value 0275 * @param step step size 0276 */ 0277 void setRange(int min, int max, int singleStep = 1); 0278 0279 /** 0280 * @deprecated Use the other setRange function and setSliderEnabled instead 0281 */ 0282 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED 0283 KDELIBS4SUPPORT_DEPRECATED void setRange(int min, int max, int singleStep, bool slider); 0284 #endif 0285 0286 /** 0287 * @param enabled Show the slider 0288 * @default enabled 0289 */ 0290 void setSliderEnabled(bool enabled = true); 0291 0292 /** 0293 * Sets the minimum value. 0294 */ 0295 void setMinimum(int min); 0296 /** 0297 * @return the minimum value. 0298 */ 0299 int minimum() const; 0300 /** 0301 * Sets the maximum value. 0302 */ 0303 void setMaximum(int max); 0304 /** 0305 * @return the maximum value. 0306 */ 0307 int maximum() const; 0308 0309 /** 0310 * @return the step of the spin box 0311 */ 0312 int singleStep() const; 0313 0314 /** 0315 * @return the step of the spin box 0316 */ 0317 void setSingleStep(int step); 0318 0319 /** 0320 * Sets the special value text. If set, the SpinBox will display 0321 * this text instead of the numeric value whenever the current 0322 * value is equal to minVal(). Typically this is used for indicating 0323 * that the choice has a special (default) meaning. 0324 */ 0325 void setSpecialValueText(const QString &text); 0326 0327 void setLabel(const QString &label, Qt::Alignment a = Qt::AlignLeft | Qt::AlignTop) override; 0328 0329 /** 0330 * This method returns the minimum size necessary to display the 0331 * control. The minimum size is enough to show all the labels 0332 * in the current font (font change may invalidate the return value). 0333 * 0334 * @return the minimum size necessary to show the control 0335 */ 0336 QSize minimumSizeHint() const override; 0337 0338 public Q_SLOTS: 0339 /** 0340 * Sets the value of the control. 0341 */ 0342 void setValue(int); 0343 0344 /** 0345 * Sets the value in units of the referencePoint 0346 */ 0347 void setRelativeValue(double); 0348 0349 /** 0350 * Sets the reference point for relativeValue. 0351 */ 0352 void setReferencePoint(int); 0353 0354 /** 0355 * Sets the suffix to @p suffix. 0356 * Use QString() to disable this feature. 0357 * Formatting has to be provided (e.g. a space separator between the 0358 * prepended @p value and the suffix's text has to be provided 0359 * as the first character in the suffix). 0360 * 0361 * @see QSpinBox::setSuffix(), #setPrefix() 0362 */ 0363 void setSuffix(const QString &suffix); 0364 0365 /** 0366 * Sets the suffix to @p suffix. 0367 * Use this to add a plural-aware suffix, e.g. by using ki18np("singular", "plural"). 0368 * 0369 * @since 4.3 0370 */ 0371 void setSuffix(const KLocalizedString &suffix); 0372 0373 /** 0374 * Sets the prefix to @p prefix. 0375 * Use QString() to disable this feature. 0376 * Formatting has to be provided (see above). 0377 * 0378 * @see QSpinBox::setPrefix(), #setSuffix() 0379 */ 0380 void setPrefix(const QString &prefix); 0381 0382 /** 0383 * sets focus to the edit widget and marks all text in if mark == true 0384 * 0385 */ 0386 void setEditFocus(bool mark = true); 0387 0388 Q_SIGNALS: 0389 /** 0390 * Emitted every time the value changes (by calling setValue() or 0391 * by user interaction). 0392 */ 0393 void valueChanged(int); 0394 0395 /** 0396 * Emitted whenever valueChanged is. Contains the change 0397 * relative to the referencePoint. 0398 */ 0399 void relativeValueChanged(double); 0400 0401 private Q_SLOTS: 0402 void spinValueChanged(int); 0403 void slotEmitRelativeValueChanged(int); 0404 0405 protected: 0406 /** 0407 * @return the spin box widget. 0408 * @internal 0409 */ 0410 QSpinBox *spinBox() const; 0411 0412 void doLayout() override; 0413 void resizeEvent(QResizeEvent *) override; 0414 0415 private: 0416 void initWidget(int value, int _base); 0417 0418 private: 0419 class KIntNumInputPrivate; 0420 friend class KIntNumInputPrivate; 0421 KIntNumInputPrivate *const d; 0422 0423 Q_DISABLE_COPY(KIntNumInput) 0424 }; 0425 0426 /* ------------------------------------------------------------------------ */ 0427 0428 class KDoubleLine; 0429 0430 /** 0431 * @deprecated since 5.0, use QSpinBox instead 0432 * 0433 * @short An input control for real numbers, consisting of a spinbox and a slider. 0434 * 0435 * KDoubleNumInput combines a QSpinBox and optionally a QSlider 0436 * with a label to make an easy to use control for setting some float 0437 * parameter. This is especially nice for configuration dialogs, 0438 * which can have many such combinated controls. 0439 * 0440 * The slider is created only when the user specifies a range 0441 * for the control using the setRange function with the slider 0442 * parameter set to "true". 0443 * 0444 * A special feature of KDoubleNumInput, designed specifically for 0445 * the situation when there are several instances in a column, 0446 * is that you can specify what portion of the control is taken by the 0447 * QSpinBox (the remaining portion is used by the slider). This makes 0448 * it very simple to have all the sliders in a column be the same size. 0449 * 0450 * \image html kdoublenuminput.png "KDE Double Number Input Spinbox" 0451 * 0452 * @see KIntNumInput 0453 */ 0454 0455 class KDELIBS4SUPPORT_DEPRECATED_EXPORT KDoubleNumInput : public KNumInput 0456 { 0457 Q_OBJECT 0458 Q_PROPERTY(double value READ value WRITE setValue NOTIFY valueChanged USER true) 0459 Q_PROPERTY(double minimum READ minimum WRITE setMinimum) 0460 Q_PROPERTY(double maximum READ maximum WRITE setMaximum) 0461 Q_PROPERTY(double singleStep READ singleStep WRITE setSingleStep) 0462 Q_PROPERTY(QString suffix READ suffix WRITE setSuffix) 0463 Q_PROPERTY(QString prefix READ prefix WRITE setPrefix) 0464 Q_PROPERTY(QString specialValueText READ specialValueText WRITE setSpecialValueText) 0465 Q_PROPERTY(int decimals READ decimals WRITE setDecimals) 0466 Q_PROPERTY(double referencePoint READ referencePoint WRITE setReferencePoint) 0467 Q_PROPERTY(double relativeValue READ relativeValue WRITE setRelativeValue) 0468 Q_PROPERTY(bool sliderEnabled READ showSlider WRITE setSliderEnabled) 0469 Q_PROPERTY(double exponentRatio READ exponentRatio WRITE setExponentRatio) 0470 0471 public: 0472 /** 0473 * Constructs an input control for double values 0474 * with initial value 0.00. 0475 */ 0476 KDELIBS4SUPPORT_DEPRECATED explicit KDoubleNumInput(QWidget *parent = nullptr); 0477 0478 /** 0479 * Constructor 0480 * 0481 * @param lower lower boundary value 0482 * @param upper upper boundary value 0483 * @param value initial value for the control 0484 * @param singleStep step size to use for up/down arrow clicks 0485 * @param precision number of digits after the decimal point 0486 * @param parent parent QWidget 0487 */ 0488 KDoubleNumInput(double lower, double upper, double value, QWidget *parent = nullptr, double singleStep = 0.01, 0489 int precision = 2); 0490 0491 /** 0492 * destructor 0493 */ 0494 ~KDoubleNumInput() override; 0495 0496 /** 0497 * Constructor 0498 * 0499 * the difference here is the "below" parameter. It tells this 0500 * instance that it is visually put below some other KNumInput 0501 * widget. Note that these two KNumInput's need not to have the 0502 * same parent widget or be in the same layout group. The effect 0503 * is that it'll adjust its layout in correspondence with the 0504 * layout of the other KNumInput's (you can build an arbitrary long 0505 * chain). 0506 * 0507 * @param below append KDoubleNumInput to the KDoubleNumInput chain 0508 * @param lower lower boundary value 0509 * @param upper upper boundary value 0510 * @param value initial value for the control 0511 * @param singleStep step size to use for up/down arrow clicks 0512 * @param precision number of digits after the decimal point 0513 * @param parent parent QWidget 0514 * 0515 * \deprecated use the version without below instead 0516 */ 0517 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED 0518 KDELIBS4SUPPORT_DEPRECATED KDoubleNumInput(KNumInput *below, 0519 double lower, double upper, double value, QWidget *parent = nullptr, double singleStep = 0.02, 0520 int precision = 2); 0521 #endif 0522 0523 /** 0524 * @return the current value. 0525 */ 0526 double value() const; 0527 0528 /** 0529 * @return the suffix. 0530 * @see setSuffix() 0531 */ 0532 QString suffix() const; 0533 0534 /** 0535 * @return the prefix. 0536 * @see setPrefix() 0537 */ 0538 QString prefix() const; 0539 0540 /** 0541 * @return number of decimals. 0542 * @see setDecimals() 0543 */ 0544 int decimals() const; 0545 0546 /** 0547 * @return the string displayed for a special value. 0548 * @see setSpecialValueText() 0549 */ 0550 QString specialValueText() const; 0551 0552 /** 0553 * @param min minimum value 0554 * @param max maximum value 0555 * @param singleStep step size for the QSlider 0556 * @param slider whether the slider is created or not 0557 */ 0558 void setRange(double min, double max, double singleStep = 1, bool slider = true); 0559 0560 /** 0561 * @param enabled Show the slider 0562 * @default enabled 0563 */ 0564 void setSliderEnabled(bool enabled); 0565 0566 /** 0567 * Sets the minimum value. 0568 */ 0569 void setMinimum(double min); 0570 /** 0571 * @return the minimum value. 0572 */ 0573 double minimum() const; 0574 /** 0575 * Sets the maximum value. 0576 */ 0577 void setMaximum(double max); 0578 /** 0579 * @return the maximum value. 0580 */ 0581 double maximum() const; 0582 0583 /** 0584 * @return the step of the spin box 0585 */ 0586 double singleStep() const; 0587 0588 /** 0589 * @return the step of the spin box 0590 */ 0591 void setSingleStep(double singleStep); 0592 0593 /** 0594 * Specifies the number of digits to use. 0595 */ 0596 void setDecimals(int decimals); 0597 0598 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED 0599 KDELIBS4SUPPORT_DEPRECATED void setPrecision(int precision) 0600 { 0601 setDecimals(precision); 0602 } 0603 #endif 0604 0605 /** 0606 * @return the reference point for relativeValue calculation 0607 */ 0608 double referencePoint() const; 0609 0610 /** 0611 * @return the current value in units of referencePoint. 0612 */ 0613 double relativeValue() const; 0614 0615 /** 0616 * Sets the special value text. If set, the spin box will display 0617 * this text instead of the numeric value whenever the current 0618 * value is equal to minVal(). Typically this is used for indicating 0619 * that the choice has a special (default) meaning. 0620 */ 0621 void setSpecialValueText(const QString &text); 0622 0623 void setLabel(const QString &label, Qt::Alignment a = Qt::AlignLeft | Qt::AlignTop) override; 0624 QSize minimumSizeHint() const override; 0625 0626 /** 0627 * @return the value of the exponent use to map the slider to the 0628 * spin box. 0629 */ 0630 double exponentRatio() const; 0631 0632 /** 0633 * @param dbl the value of the exponent use to map the slider to the 0634 * spin box (dbl need to be strictly positive). 0635 */ 0636 void setExponentRatio(double dbl); 0637 public Q_SLOTS: 0638 /** 0639 * Sets the value of the control. 0640 */ 0641 void setValue(double); 0642 0643 /** 0644 * Sets the value in units of referencePoint. 0645 */ 0646 void setRelativeValue(double); 0647 0648 /** 0649 * Sets the reference Point to @p ref. It @p ref == 0, emitting of 0650 * relativeValueChanged is blocked and relativeValue 0651 * just returns 0. 0652 */ 0653 void setReferencePoint(double ref); 0654 0655 /** 0656 * Sets the suffix to be displayed to @p suffix. Use QString() to disable 0657 * this feature. Note that the suffix is attached to the value without any 0658 * spacing. So if you prefer to display a space separator, set suffix 0659 * to something like " cm". 0660 * @see setSuffix() 0661 */ 0662 void setSuffix(const QString &suffix); 0663 0664 /** 0665 * Sets the prefix to be displayed to @p prefix. Use QString() to disable 0666 * this feature. Note that the prefix is attached to the value without any 0667 * spacing. 0668 * @see setPrefix() 0669 */ 0670 void setPrefix(const QString &prefix); 0671 0672 Q_SIGNALS: 0673 /** 0674 * Emitted every time the value changes (by calling setValue() or 0675 * by user interaction). 0676 */ 0677 void valueChanged(double); 0678 /** 0679 * This is an overloaded member function, provided for 0680 * convenience. It essentially behaves like the above function. 0681 * 0682 * Contains the value in units of referencePoint. 0683 */ 0684 void relativeValueChanged(double); 0685 0686 private Q_SLOTS: 0687 void sliderMoved(int); 0688 void spinBoxChanged(double); 0689 void slotEmitRelativeValueChanged(double); 0690 0691 protected: 0692 void doLayout() override; 0693 void resizeEvent(QResizeEvent *) override; 0694 0695 friend class KDoubleLine; 0696 private: 0697 void initWidget(double value, double lower, double upper, 0698 double singleStep, int precision); 0699 double mapSliderToSpin(int) const; 0700 void updateLegacyMembers(); 0701 0702 private: 0703 class KDoubleNumInputPrivate; 0704 friend class KDoubleNumInputPrivate; 0705 KDoubleNumInputPrivate *const d; 0706 0707 Q_DISABLE_COPY(KDoubleNumInput) 0708 }; 0709 0710 /* ------------------------------------------------------------------------ */ 0711 0712 /** 0713 * @deprecated since 5.0, use QSpinBox instead 0714 * 0715 * @short A QSpinBox with support for arbitrary base numbers. 0716 * 0717 * A QSpinBox with support for arbitrary base numbers 0718 * (e.g. hexadecimal). 0719 * 0720 * The class provides an easy interface to use other 0721 * numeric systems than the decimal. 0722 * 0723 * \image html kintspinbox.png "KDE Integer Input Spinboxes with hexadecimal and binary input" 0724 */ 0725 class KDELIBS4SUPPORT_DEPRECATED_EXPORT KIntSpinBox : public QSpinBox 0726 { 0727 Q_OBJECT 0728 Q_PROPERTY(int base READ base WRITE setBase) 0729 0730 public: 0731 0732 /** 0733 * Constructor. 0734 * 0735 * Constructs a widget with an integer inputline with a little scrollbar 0736 * and a slider, with minimal value 0, maximal value 99, step 1, base 10 0737 * and initial value 0. 0738 */ 0739 KDELIBS4SUPPORT_DEPRECATED explicit KIntSpinBox(QWidget *parent = nullptr); 0740 0741 /** 0742 * Constructor. 0743 * 0744 * Constructs a widget with an integer inputline with a little scrollbar 0745 * and a slider. 0746 * 0747 * @param lower The lowest valid value. 0748 * @param upper The greatest valid value. 0749 * @param singleStep The step size of the scrollbar. 0750 * @param value The actual value. 0751 * @param base The base of the used number system. 0752 * @param parent The parent of the widget. 0753 */ 0754 KIntSpinBox(int lower, int upper, int singleStep, int value, QWidget *parent, int base = 10); 0755 0756 /** 0757 * Destructor. 0758 */ 0759 ~KIntSpinBox() override; 0760 0761 /** 0762 * Sets the base in which the numbers in the spin box are represented. 0763 * 0764 * @deprecated since 5.0, use QSpinBox::setDisplayIntegerBase(base) instead. 0765 */ 0766 void setBase(int base); 0767 /** 0768 * @return the base in which numbers in the spin box are represented. 0769 * 0770 * @deprecated since 5.0, use int displayIntegerBase() 0771 */ 0772 int base() const; 0773 /** 0774 * sets focus and optionally marks all text 0775 * 0776 */ 0777 void setEditFocus(bool mark); 0778 0779 /** 0780 * Sets the suffix to @p suffix. 0781 * Use this to add a plural-aware suffix, e.g. by using ki18np("singular", "plural"). 0782 * 0783 * @since 4.3 0784 */ 0785 void setSuffix(const KLocalizedString &suffix); 0786 0787 using QSpinBox::setSuffix; 0788 0789 protected: 0790 0791 /** 0792 * Overloaded the method in QSpinBox 0793 * to make use of the base given in the constructor. 0794 */ 0795 QString textFromValue(int) const override; 0796 0797 /** 0798 * Overloaded the method in QSpinBox 0799 * to make use of the base given in the constructor. 0800 */ 0801 int valueFromText(const QString &text) const override; 0802 0803 private: 0804 class KIntSpinBoxPrivate; 0805 friend class KIntSpinBoxPrivate; 0806 KIntSpinBoxPrivate *const d; 0807 0808 Q_DISABLE_COPY(KIntSpinBox) 0809 Q_PRIVATE_SLOT(d, void updateSuffix(int)) 0810 }; 0811 0812 #endif // K_NUMINPUT_H