00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef K_NUMINPUT_H
00028 #define K_NUMINPUT_H
00029
00030 #include <qwidget.h>
00031 #include <qspinbox.h>
00032 #include <kdelibs_export.h>
00033
00034 class QLabel;
00035 class QSlider;
00036 class QLineEdit;
00037 class QLayout;
00038 class QValidator;
00039
00040 class KIntSpinBox;
00041
00042
00043
00049 class KDEUI_EXPORT KNumInput : public QWidget
00050 {
00051 Q_OBJECT
00052 Q_PROPERTY( QString label READ label WRITE setLabel )
00053 public:
00059 KNumInput(QWidget* parent=0, const char* name=0);
00060
00066 KNumInput(KNumInput* below, QWidget* parent=0, const char* name=0);
00067 ~KNumInput();
00068
00087 virtual void setLabel(const QString & label, int a = AlignLeft | AlignTop);
00088
00092 QString label() const;
00093
00098 bool showSlider() const { return m_slider; }
00099
00106 void setSteps(int minor, int major);
00107
00112 QSizePolicy sizePolicy() const;
00113
00119 virtual QSize sizeHint() const;
00120
00121 protected:
00127 void layout(bool deep);
00128
00137 virtual void doLayout() = 0;
00138
00139 KNumInput* m_prev, *m_next;
00140 int m_colw1, m_colw2;
00141
00142 QLabel* m_label;
00143 QSlider* m_slider;
00144 QSize m_sizeSlider, m_sizeLabel;
00145
00146 int m_alignment;
00147
00148 private:
00149 void init();
00150
00151 protected:
00152 virtual void virtual_hook( int id, void* data );
00153 private:
00154 class KNumInputPrivate;
00155 KNumInputPrivate *d;
00156 };
00157
00158
00159
00187 class KDEUI_EXPORT KIntNumInput : public KNumInput
00188 {
00189 Q_OBJECT
00190 Q_PROPERTY( int value READ value WRITE setValue )
00191 Q_PROPERTY( int minValue READ minValue WRITE setMinValue )
00192 Q_PROPERTY( int maxValue READ maxValue WRITE setMaxValue )
00193 Q_PROPERTY( int referencePoint READ referencePoint WRITE setReferencePoint )
00194 Q_PROPERTY( QString suffix READ suffix WRITE setSuffix )
00195 Q_PROPERTY( QString prefix READ prefix WRITE setPrefix )
00196 Q_PROPERTY( QString specialValueText READ specialValueText WRITE setSpecialValueText )
00197
00198 public:
00203 KIntNumInput(QWidget *parent=0, const char *name=0);
00216 KIntNumInput(int value, QWidget* parent=0, int base = 10, const char *name=0);
00217
00235 KIntNumInput(KNumInput* below, int value, QWidget* parent=0, int base = 10, const char *name=0);
00236
00242 virtual ~KIntNumInput();
00243
00247 int value() const;
00248
00253 double relativeValue() const;
00254
00259 int referencePoint() const;
00260
00265 QString suffix() const;
00270 QString prefix() const;
00275 QString specialValueText() const;
00276
00283 void setRange(int min, int max, int step=1, bool slider=true);
00287 void setMinValue(int min);
00291 int minValue() const;
00295 void setMaxValue(int max);
00299 int maxValue() const;
00300
00307 void setSpecialValueText(const QString& text);
00308
00309 virtual void setLabel(const QString & label, int a = AlignLeft | AlignTop);
00310
00318 virtual QSize minimumSizeHint() const;
00319
00320 public slots:
00324 void setValue(int);
00325
00330 void setRelativeValue(double);
00331
00336 void setReferencePoint(int);
00337
00347 void setSuffix(const QString &suffix);
00348
00356 void setPrefix(const QString &prefix);
00357
00362 void setEditFocus( bool mark = true );
00363
00364 signals:
00369 void valueChanged(int);
00370
00376 void relativeValueChanged(double);
00377
00378 private slots:
00379 void spinValueChanged(int);
00380 void slotEmitRelativeValueChanged(int);
00381
00382 protected:
00383 virtual void doLayout();
00384 void resizeEvent ( QResizeEvent * );
00385
00386 KIntSpinBox* m_spin;
00387 QSize m_sizeSpin;
00388
00389 private:
00390 void init(int value, int _base);
00391
00392 protected:
00393 virtual void virtual_hook( int id, void* data );
00394 private:
00395 class KIntNumInputPrivate;
00396 KIntNumInputPrivate *d;
00397 };
00398
00399
00400
00401
00402 class KDoubleLine;
00403
00431 class KDEUI_EXPORT KDoubleNumInput : public KNumInput
00432 {
00433 Q_OBJECT
00434 Q_PROPERTY( double value READ value WRITE setValue )
00435 Q_PROPERTY( double minValue READ minValue WRITE setMinValue )
00436 Q_PROPERTY( double maxValue READ maxValue WRITE setMaxValue )
00437 Q_PROPERTY( QString suffix READ suffix WRITE setSuffix )
00438 Q_PROPERTY( QString prefix READ prefix WRITE setPrefix )
00439 Q_PROPERTY( QString specialValueText READ specialValueText WRITE setSpecialValueText )
00440 Q_PROPERTY( int precision READ precision WRITE setPrecision )
00441
00442 public:
00447 KDoubleNumInput(QWidget *parent=0, const char *name=0);
00448
00457 KDoubleNumInput(double value, QWidget *parent=0, const char *name=0) KDE_DEPRECATED;
00458
00471 KDoubleNumInput(double lower, double upper, double value, double step=0.01,
00472 int precision=2, QWidget *parent=0, const char *name=0);
00473
00477 virtual ~KDoubleNumInput();
00478
00490 KDoubleNumInput(KNumInput* below, double value, QWidget* parent=0, const char* name=0) KDE_DEPRECATED;
00491
00513 KDoubleNumInput(KNumInput* below,
00514 double lower, double upper, double value, double step=0.02,
00515 int precision=2, QWidget *parent=0, const char *name=0);
00516
00520 double value() const;
00521
00526 QString suffix() const;
00527
00532 QString prefix() const;
00533
00538 int precision() const;
00539
00544 QString specialValueText() const { return m_specialvalue; }
00545
00552 void setRange(double min, double max, double step=1, bool slider=true);
00556 void setMinValue(double min);
00560 double minValue() const;
00564 void setMaxValue(double max);
00568 double maxValue() const;
00569
00573 void setPrecision(int precision);
00574
00579 double referencePoint() const;
00580
00585 double relativeValue() const;
00586
00593 void setSpecialValueText(const QString& text);
00594
00595 virtual void setLabel(const QString & label, int a = AlignLeft | AlignTop);
00596 virtual QSize minimumSizeHint() const;
00597 virtual bool eventFilter(QObject*, QEvent*);
00598
00599 public slots:
00603 void setValue(double);
00604
00609 void setRelativeValue(double);
00610
00617 void setReferencePoint(double ref);
00618
00626 void setSuffix(const QString &suffix);
00627
00634 void setPrefix(const QString &prefix);
00635
00636 signals:
00641 void valueChanged(double);
00649 void relativeValueChanged(double);
00650
00651 private slots:
00652 void sliderMoved(int);
00653 void slotEmitRelativeValueChanged(double);
00654
00655 protected:
00656 virtual void doLayout();
00657 void resizeEvent ( QResizeEvent * );
00658
00659 virtual void resetEditBox();
00660
00661
00662 KDoubleLine* edit;
00663
00664 bool m_range;
00665 double m_lower, m_upper, m_step;
00666
00667
00668 QSize m_sizeEdit;
00669
00670 friend class KDoubleLine;
00671 private:
00672 void init(double value, double lower, double upper,
00673 double step, int precision);
00674 double mapSliderToSpin(int) const;
00675 void updateLegacyMembers();
00676
00677 QString m_specialvalue, m_prefix, m_suffix;
00678 double m_value;
00679 short m_precision;
00680
00681
00682 protected:
00683 virtual void virtual_hook( int id, void* data );
00684 private:
00685 class KDoubleNumInputPrivate;
00686 KDoubleNumInputPrivate *d;
00687 };
00688
00689
00690
00691
00701 class KDEUI_EXPORT KIntSpinBox : public QSpinBox
00702 {
00703 Q_OBJECT
00704 Q_PROPERTY( int base READ base WRITE setBase )
00705
00706 public:
00707
00715 KIntSpinBox( QWidget *parent=0, const char *name=0);
00716
00731 KIntSpinBox(int lower, int upper, int step, int value, int base = 10,
00732 QWidget* parent = 0, const char* name = 0);
00733
00737 virtual ~KIntSpinBox();
00738
00742 void setBase(int base);
00746 int base() const;
00751 void setEditFocus(bool mark);
00752
00753 protected:
00754
00759 virtual QString mapValueToText(int);
00760
00765 virtual int mapTextToValue(bool*);
00766
00767 private:
00768 int val_base;
00769 protected:
00770 virtual void virtual_hook( int id, void* data );
00771 private:
00772 class KIntSpinBoxPrivate;
00773 KIntSpinBoxPrivate *d;
00774 };
00775
00776
00777
00778
00831 class KDEUI_EXPORT KDoubleSpinBox : public QSpinBox {
00832 Q_OBJECT
00833 Q_PROPERTY( bool acceptLocalizedNumbers READ acceptLocalizedNumbers WRITE setAcceptLocalizedNumbers )
00834 Q_OVERRIDE( double maxValue READ maxValue WRITE setMaxValue )
00835 Q_OVERRIDE( double minValue READ minValue WRITE setMinValue )
00836 Q_OVERRIDE( double lineStep READ lineStep WRITE setLineStep )
00837 Q_OVERRIDE( double value READ value WRITE setValue )
00838 Q_PROPERTY( int precision READ precision WRITE setPrecision )
00839
00840 public:
00844 KDoubleSpinBox( QWidget * parent=0, const char * name=0 );
00845
00849 KDoubleSpinBox( double lower, double upper, double step, double value,
00850 int precision=2, QWidget * parent=0, const char * name=0 );
00851
00852 virtual ~KDoubleSpinBox();
00853
00855 bool acceptLocalizedNumbers() const;
00856
00859 virtual void setAcceptLocalizedNumbers( bool accept );
00860
00864 void setRange( double lower, double upper, double step=0.01, int precision=2 );
00865
00868 int precision() const;
00869
00873 void setPrecision( int precision );
00874
00887 virtual void setPrecision( int precision, bool force );
00888
00890 double value() const;
00891
00893 double minValue() const;
00894
00901 void setMinValue( double value );
00902
00904 double maxValue() const;
00905
00912 void setMaxValue( double value );
00913
00915 double lineStep() const;
00916
00921 void setLineStep( double step );
00922
00924 void setValidator( const QValidator * );
00925
00926 signals:
00928 void valueChanged( double value );
00929
00930 public slots:
00934 virtual void setValue( double value );
00935
00936 protected:
00937 virtual QString mapValueToText(int);
00938 virtual int mapTextToValue(bool*);
00939
00940 protected slots:
00941 void slotValueChanged( int value );
00942
00943 protected:
00944 virtual void virtual_hook( int id, void* data );
00945 private:
00946 typedef QSpinBox base;
00947 void updateValidator();
00948 int maxPrecision() const;
00949
00950 class Private;
00951 Private * d;
00952 };
00953
00954 #endif // K_NUMINPUT_H