KDELibs4Support

knuminput.h
1 /* This file is part of the KDE libraries
2  * Copyright (c) 1997 Patrick Dowler <[email protected]>
3  * Copyright (c) 2000 Dirk Mueller <[email protected]>
4  * Copyright (c) 2002 Marc Mutz <[email protected]>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public License
17  * along with this library; see the file COPYING.LIB. If not, write to
18  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  */
21 
22 #ifndef K_NUMINPUT_H
23 #define K_NUMINPUT_H
24 
25 #include <kdelibs4support_export.h>
26 
27 #include <QWidget>
28 #include <QSpinBox>
29 
30 class QSlider;
31 class QSpinBox;
32 class QValidator;
33 
34 class KIntSpinBox;
35 class KNumInputPrivate;
36 class KLocalizedString;
37 
45 class KDELIBS4SUPPORT_DEPRECATED_EXPORT KNumInput : public QWidget
46 {
47  Q_OBJECT
48  Q_PROPERTY(QString label READ label WRITE setLabel)
49 public:
56  KDELIBS4SUPPORT_DEPRECATED explicit KNumInput(QWidget *parent = nullptr);
57 
63 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED
64  KDELIBS4SUPPORT_DEPRECATED KNumInput(QWidget *parent, KNumInput *below);
65 #endif
66 
70  ~KNumInput();
71 
89  virtual void setLabel(const QString &label, Qt::Alignment a = Qt::AlignLeft | Qt::AlignTop);
90 
94  QString label() const;
95 
99  bool showSlider() const;
100 
107  void setSteps(int minor, int major);
108 
114  QSize sizeHint() const override;
115 
116 protected:
121  QSlider *slider() const;
122 
128  void layout(bool deep);
129 
138  virtual void doLayout() = 0;
139 
140 private:
141  friend class KNumInputPrivate;
142  KNumInputPrivate *const d;
143 
144  Q_DISABLE_COPY(KNumInput)
145 };
146 
147 /* ------------------------------------------------------------------------ */
148 
176 class KDELIBS4SUPPORT_DEPRECATED_EXPORT KIntNumInput : public KNumInput
177 {
178  Q_OBJECT
179  Q_PROPERTY(int value READ value WRITE setValue NOTIFY valueChanged USER true)
180  Q_PROPERTY(int minimum READ minimum WRITE setMinimum)
181  Q_PROPERTY(int maximum READ maximum WRITE setMaximum)
182  Q_PROPERTY(int singleStep READ singleStep WRITE setSingleStep)
183  Q_PROPERTY(int referencePoint READ referencePoint WRITE setReferencePoint)
184  Q_PROPERTY(double relativeValue READ relativeValue WRITE setRelativeValue)
185  Q_PROPERTY(QString suffix READ suffix WRITE setSuffix)
186  Q_PROPERTY(QString prefix READ prefix WRITE setPrefix)
187  Q_PROPERTY(QString specialValueText READ specialValueText WRITE setSpecialValueText)
188  Q_PROPERTY(bool sliderEnabled READ showSlider WRITE setSliderEnabled)
189 
190 public:
195  KDELIBS4SUPPORT_DEPRECATED explicit KIntNumInput(QWidget *parent = nullptr);
207  KDELIBS4SUPPORT_DEPRECATED explicit KIntNumInput(int value, QWidget *parent = nullptr, int base = 10);
208 
227 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED
228  KDELIBS4SUPPORT_DEPRECATED KIntNumInput(KNumInput *below, int value, QWidget *parent, int base = 10);
229 #endif
230 
236  virtual ~KIntNumInput();
237 
241  int value() const;
242 
246  double relativeValue() const;
247 
251  int referencePoint() const;
252 
257  QString suffix() const;
262  QString prefix() const;
267  QString specialValueText() const;
268 
277  void setRange(int min, int max, int singleStep = 1);
278 
282 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED
283  KDELIBS4SUPPORT_DEPRECATED void setRange(int min, int max, int singleStep, bool slider);
284 #endif
285 
290  void setSliderEnabled(bool enabled = true);
291 
295  void setMinimum(int min);
299  int minimum() const;
303  void setMaximum(int max);
307  int maximum() const;
308 
312  int singleStep() const;
313 
317  void setSingleStep(int step);
318 
325  void setSpecialValueText(const QString &text);
326 
327  void setLabel(const QString &label, Qt::Alignment a = Qt::AlignLeft | Qt::AlignTop) override;
328 
336  QSize minimumSizeHint() const override;
337 
338 public Q_SLOTS:
342  void setValue(int);
343 
347  void setRelativeValue(double);
348 
352  void setReferencePoint(int);
353 
363  void setSuffix(const QString &suffix);
364 
371  void setSuffix(const KLocalizedString &suffix);
372 
380  void setPrefix(const QString &prefix);
381 
386  void setEditFocus(bool mark = true);
387 
388 Q_SIGNALS:
393  void valueChanged(int);
394 
399  void relativeValueChanged(double);
400 
401 private Q_SLOTS:
402  void spinValueChanged(int);
403  void slotEmitRelativeValueChanged(int);
404 
405 protected:
410  QSpinBox *spinBox() const;
411 
412  void doLayout() override;
413  void resizeEvent(QResizeEvent *) override;
414 
415 private:
416  void initWidget(int value, int _base);
417 
418 private:
419  class KIntNumInputPrivate;
420  friend class KIntNumInputPrivate;
421  KIntNumInputPrivate *const d;
422 
423  Q_DISABLE_COPY(KIntNumInput)
424 };
425 
426 /* ------------------------------------------------------------------------ */
427 
428 class KDoubleLine;
429 
455 class KDELIBS4SUPPORT_DEPRECATED_EXPORT KDoubleNumInput : public KNumInput
456 {
457  Q_OBJECT
458  Q_PROPERTY(double value READ value WRITE setValue NOTIFY valueChanged USER true)
459  Q_PROPERTY(double minimum READ minimum WRITE setMinimum)
460  Q_PROPERTY(double maximum READ maximum WRITE setMaximum)
461  Q_PROPERTY(double singleStep READ singleStep WRITE setSingleStep)
462  Q_PROPERTY(QString suffix READ suffix WRITE setSuffix)
463  Q_PROPERTY(QString prefix READ prefix WRITE setPrefix)
464  Q_PROPERTY(QString specialValueText READ specialValueText WRITE setSpecialValueText)
465  Q_PROPERTY(int decimals READ decimals WRITE setDecimals)
466  Q_PROPERTY(double referencePoint READ referencePoint WRITE setReferencePoint)
467  Q_PROPERTY(double relativeValue READ relativeValue WRITE setRelativeValue)
468  Q_PROPERTY(bool sliderEnabled READ showSlider WRITE setSliderEnabled)
469  Q_PROPERTY(double exponentRatio READ exponentRatio WRITE setExponentRatio)
470 
471 public:
476  KDELIBS4SUPPORT_DEPRECATED explicit KDoubleNumInput(QWidget *parent = nullptr);
477 
488  KDoubleNumInput(double lower, double upper, double value, QWidget *parent = nullptr, double singleStep = 0.01,
489  int precision = 2);
490 
494  virtual ~KDoubleNumInput();
495 
517 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED
518  KDELIBS4SUPPORT_DEPRECATED KDoubleNumInput(KNumInput *below,
519  double lower, double upper, double value, QWidget *parent = nullptr, double singleStep = 0.02,
520  int precision = 2);
521 #endif
522 
526  double value() const;
527 
532  QString suffix() const;
533 
538  QString prefix() const;
539 
544  int decimals() const;
545 
550  QString specialValueText() const;
551 
558  void setRange(double min, double max, double singleStep = 1, bool slider = true);
559 
564  void setSliderEnabled(bool enabled);
565 
569  void setMinimum(double min);
573  double minimum() const;
577  void setMaximum(double max);
581  double maximum() const;
582 
586  double singleStep() const;
587 
591  void setSingleStep(double singleStep);
592 
596  void setDecimals(int decimals);
597 
598 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED
599  KDELIBS4SUPPORT_DEPRECATED void setPrecision(int precision)
600  {
601  setDecimals(precision);
602  }
603 #endif
604 
608  double referencePoint() const;
609 
613  double relativeValue() const;
614 
621  void setSpecialValueText(const QString &text);
622 
623  void setLabel(const QString &label, Qt::Alignment a = Qt::AlignLeft | Qt::AlignTop) override;
624  QSize minimumSizeHint() const override;
625 
630  double exponentRatio() const;
631 
636  void setExponentRatio(double dbl);
637 public Q_SLOTS:
641  void setValue(double);
642 
646  void setRelativeValue(double);
647 
653  void setReferencePoint(double ref);
654 
662  void setSuffix(const QString &suffix);
663 
670  void setPrefix(const QString &prefix);
671 
672 Q_SIGNALS:
677  void valueChanged(double);
684  void relativeValueChanged(double);
685 
686 private Q_SLOTS:
687  void sliderMoved(int);
688  void spinBoxChanged(double);
689  void slotEmitRelativeValueChanged(double);
690 
691 protected:
692  void doLayout() override;
693  void resizeEvent(QResizeEvent *) override;
694 
695  friend class KDoubleLine;
696 private:
697  void initWidget(double value, double lower, double upper,
698  double singleStep, int precision);
699  double mapSliderToSpin(int) const;
700  void updateLegacyMembers();
701 
702 private:
703  class KDoubleNumInputPrivate;
704  friend class KDoubleNumInputPrivate;
705  KDoubleNumInputPrivate *const d;
706 
707  Q_DISABLE_COPY(KDoubleNumInput)
708 };
709 
710 /* ------------------------------------------------------------------------ */
711 
725 class KDELIBS4SUPPORT_DEPRECATED_EXPORT KIntSpinBox : public QSpinBox
726 {
727  Q_OBJECT
728  Q_PROPERTY(int base READ base WRITE setBase)
729 
730 public:
731 
739  KDELIBS4SUPPORT_DEPRECATED explicit KIntSpinBox(QWidget *parent = nullptr);
740 
754  KIntSpinBox(int lower, int upper, int singleStep, int value, QWidget *parent, int base = 10);
755 
759  virtual ~KIntSpinBox();
760 
766  void setBase(int base);
772  int base() const;
777  void setEditFocus(bool mark);
778 
785  void setSuffix(const KLocalizedString &suffix);
786 
787  using QSpinBox::setSuffix;
788 
789 protected:
790 
795  QString textFromValue(int) const override;
796 
801  int valueFromText(const QString &text) const override;
802 
803 private:
804  class KIntSpinBoxPrivate;
805  friend class KIntSpinBoxPrivate;
806  KIntSpinBoxPrivate *const d;
807 
808  Q_DISABLE_COPY(KIntSpinBox)
809  Q_PRIVATE_SLOT(d, void updateSuffix(int))
810 };
811 
812 #endif // K_NUMINPUT_H
QLayout * layout() const const
virtual void setLabel(const QString &label, Qt::Alignment a=Qt::AlignLeft|Qt::AlignTop)
Sets the text and alignment of the main description label.
Definition: knuminput.cpp:134
void setEditFocus(bool enable)
void setSuffix(const QString &suffix)
virtual QSize minimumSizeHint() const const
typedef Alignment
Q_PROPERTY(...)
virtual QString textFromValue(int value) const const
virtual QSize sizeHint() const const
virtual int valueFromText(const QString &text) const const
Q_DISABLE_COPY(Class)
A QSpinBox with support for arbitrary base numbers.
Definition: knuminput.h:725
An input control for real numbers, consisting of a spinbox and a slider.
Definition: knuminput.h:455
virtual void resizeEvent(QResizeEvent *event)
virtual void doLayout()=0
You need to overwrite this method and implement your layout calculations there.
An input widget for integer numbers, consisting of a spinbox and a slider.
Definition: knuminput.h:176
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat Jun 6 2020 22:41:40 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.