kdeui Library API Documentation

knuminput.h

00001 /* 00002 * knuminput.h 00003 * 00004 * Copyright (c) 1997 Patrick Dowler <dowler@morgul.fsh.uvic.ca> 00005 * Copyright (c) 2000 Dirk A. Mueller <mueller@kde.org> 00006 * Copyright (c) 2002 Marc Mutz <mutz@kde.org> 00007 * 00008 * Requires the Qt widget libraries, available at no cost at 00009 * http://www.troll.no/ 00010 * 00011 * This library is free software; you can redistribute it and/or 00012 * modify it under the terms of the GNU Library General Public 00013 * License as published by the Free Software Foundation; either 00014 * version 2 of the License, or (at your option) any later version. 00015 * 00016 * This library is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00019 * Library General Public License for more details. 00020 * 00021 * You should have received a copy of the GNU Library General Public License 00022 * along with this library; see the file COPYING.LIB. If not, write to 00023 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00024 * Boston, MA 02111-1307, USA. 00025 */ 00026 00027 #ifndef K_NUMINPUT_H 00028 #define K_NUMINPUT_H 00029 00030 #include <qwidget.h> 00031 #include <qspinbox.h> 00032 #include <kdemacros.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 KNumInput : public QWidget 00050 { 00051 Q_OBJECT 00052 Q_PROPERTY( QString label READ label WRITE setLabel ) 00053 public: 00058 KNumInput(QWidget* parent=0, const char* name=0); 00059 00064 KNumInput(KNumInput* below, QWidget* parent=0, const char* name=0); 00065 ~KNumInput(); 00066 00085 virtual void setLabel(const QString & label, int a = AlignLeft | AlignTop); 00086 00090 QString label() const; 00091 00096 bool showSlider() const { return m_slider; } 00097 00104 void setSteps(int minor, int major); 00105 00110 QSizePolicy sizePolicy() const; 00111 00117 virtual QSize sizeHint() const; 00118 00119 protected: 00125 void layout(bool deep); 00126 00135 virtual void doLayout() = 0; 00136 00137 KNumInput* m_prev, *m_next; 00138 int m_colw1, m_colw2; 00139 00140 QLabel* m_label; 00141 QSlider* m_slider; 00142 QSize m_sizeSlider, m_sizeLabel; 00143 00144 int m_alignment; 00145 00146 private: 00147 void init(); 00148 00149 protected: 00150 virtual void virtual_hook( int id, void* data ); 00151 private: 00152 class KNumInputPrivate; 00153 KNumInputPrivate *d; 00154 }; 00155 00156 /* ------------------------------------------------------------------------ */ 00157 00184 class KIntNumInput : public KNumInput 00185 { 00186 Q_OBJECT 00187 Q_PROPERTY( int value READ value WRITE setValue ) 00188 Q_PROPERTY( int minValue READ minValue WRITE setMinValue ) 00189 Q_PROPERTY( int maxValue READ maxValue WRITE setMaxValue ) 00190 Q_PROPERTY( int referencePoint READ referencePoint WRITE setReferencePoint ) 00191 Q_PROPERTY( QString suffix READ suffix WRITE setSuffix ) 00192 Q_PROPERTY( QString prefix READ prefix WRITE setPrefix ) 00193 Q_PROPERTY( QString specialValueText READ specialValueText WRITE setSpecialValueText ) 00194 00195 public: 00200 KIntNumInput(QWidget *parent=0, const char *name=0); 00213 KIntNumInput(int value, QWidget* parent=0, int base = 10, const char *name=0); 00214 00232 KIntNumInput(KNumInput* below, int value, QWidget* parent=0, int base = 10, const char *name=0); 00233 00239 virtual ~KIntNumInput(); 00240 00244 int value() const; 00245 00250 double relativeValue() const; 00251 00256 int referencePoint() const; 00257 00262 QString suffix() const; 00267 QString prefix() const; 00272 QString specialValueText() const; 00273 00280 void setRange(int min, int max, int step=1, bool slider=true); 00284 void setMinValue(int min); 00288 int minValue() const; 00292 void setMaxValue(int max); 00296 int maxValue() const; 00297 00304 void setSpecialValueText(const QString& text); 00305 00306 virtual void setLabel(const QString & label, int a = AlignLeft | AlignTop); 00307 00315 virtual QSize minimumSizeHint() const; 00316 00317 public slots: 00321 void setValue(int); 00322 00327 void setRelativeValue(double); 00328 00333 void setReferencePoint(int); 00334 00344 void setSuffix(const QString &suffix); 00345 00353 void setPrefix(const QString &prefix); 00354 00359 void setEditFocus( bool mark = true ); 00360 00361 signals: 00366 void valueChanged(int); 00367 00373 void relativeValueChanged(double); 00374 00375 private slots: 00376 void spinValueChanged(int); 00377 void slotEmitRelativeValueChanged(int); 00378 00379 protected: 00380 virtual void doLayout(); 00381 void resizeEvent ( QResizeEvent * ); 00382 00383 KIntSpinBox* m_spin; 00384 QSize m_sizeSpin; 00385 00386 private: 00387 void init(int value, int _base); 00388 00389 protected: 00390 virtual void virtual_hook( int id, void* data ); 00391 private: 00392 class KIntNumInputPrivate; 00393 KIntNumInputPrivate *d; 00394 }; 00395 00396 00397 /* ------------------------------------------------------------------------ */ 00398 00399 class KDoubleLine; 00400 00427 class KDoubleNumInput : public KNumInput 00428 { 00429 Q_OBJECT 00430 Q_PROPERTY( double value READ value WRITE setValue ) 00431 Q_PROPERTY( double minValue READ minValue WRITE setMinValue ) 00432 Q_PROPERTY( double maxValue READ maxValue WRITE setMaxValue ) 00433 Q_PROPERTY( QString suffix READ suffix WRITE setSuffix ) 00434 Q_PROPERTY( QString prefix READ prefix WRITE setPrefix ) 00435 Q_PROPERTY( QString specialValueText READ specialValueText WRITE setSpecialValueText ) 00436 Q_PROPERTY( int precision READ precision WRITE setPrecision ) 00437 00438 public: 00443 KDoubleNumInput(QWidget *parent=0, const char *name=0); 00444 00453 KDoubleNumInput(double value, QWidget *parent=0, const char *name=0) KDE_DEPRECATED; 00454 00467 KDoubleNumInput(double lower, double upper, double value, double step=0.01, 00468 int precision=2, QWidget *parent=0, const char *name=0); 00469 00473 virtual ~KDoubleNumInput(); 00474 00486 KDoubleNumInput(KNumInput* below, double value, QWidget* parent=0, const char* name=0) KDE_DEPRECATED; 00487 00509 KDoubleNumInput(KNumInput* below, 00510 double lower, double upper, double value, double step=0.02, 00511 int precision=2, QWidget *parent=0, const char *name=0); 00512 00516 double value() const; 00517 00522 QString suffix() const; 00523 00528 QString prefix() const; 00529 00534 int precision() const; 00535 00540 QString specialValueText() const { return m_specialvalue; } 00541 00548 void setRange(double min, double max, double step=1, bool slider=true); 00552 void setMinValue(double min); 00556 double minValue() const; 00560 void setMaxValue(double max); 00564 double maxValue() const; 00565 00569 void setPrecision(int precision); 00570 00575 double referencePoint() const; 00576 00581 double relativeValue() const; 00582 00589 void setSpecialValueText(const QString& text); 00590 00591 virtual void setLabel(const QString & label, int a = AlignLeft | AlignTop); 00592 virtual QSize minimumSizeHint() const; 00593 virtual bool eventFilter(QObject*, QEvent*); 00594 00595 public slots: 00599 void setValue(double); 00600 00605 void setRelativeValue(double); 00606 00613 void setReferencePoint(double ref); 00614 00622 void setSuffix(const QString &suffix); 00623 00630 void setPrefix(const QString &prefix); 00631 00632 signals: 00637 void valueChanged(double); 00645 void relativeValueChanged(double); 00646 00647 private slots: 00648 void sliderMoved(int); 00649 void slotEmitRelativeValueChanged(double); 00650 00651 protected: 00652 virtual void doLayout(); 00653 void resizeEvent ( QResizeEvent * ); 00654 00655 virtual void resetEditBox(); 00656 00657 // ### no longer used, remove when BIC allowed 00658 KDoubleLine* edit; 00659 00660 bool m_range; 00661 double m_lower, m_upper, m_step; 00662 // ### end no longer used 00663 00664 QSize m_sizeEdit; 00665 00666 friend class KDoubleLine; 00667 private: 00668 void init(double value, double lower, double upper, 00669 double step, int precision); 00670 double mapSliderToSpin(int) const; 00671 void updateLegacyMembers(); 00672 // ### no longer used, remove when BIC allowed: 00673 QString m_specialvalue, m_prefix, m_suffix; 00674 double m_value; 00675 short m_precision; 00676 // ### end remove when BIC allowed 00677 00678 protected: 00679 virtual void virtual_hook( int id, void* data ); 00680 private: 00681 class KDoubleNumInputPrivate; 00682 KDoubleNumInputPrivate *d; 00683 }; 00684 00685 00686 /* ------------------------------------------------------------------------ */ 00687 00697 class KIntSpinBox : public QSpinBox 00698 { 00699 Q_OBJECT 00700 Q_PROPERTY( int base READ base WRITE setBase ) 00701 00702 public: 00703 00711 KIntSpinBox( QWidget *parent=0, const char *name=0); 00712 00727 KIntSpinBox(int lower, int upper, int step, int value, int base = 10, 00728 QWidget* parent = 0, const char* name = 0); 00729 00733 virtual ~KIntSpinBox(); 00734 00738 void setBase(int base); 00742 int base() const; 00747 void setEditFocus(bool mark); 00748 00749 protected: 00750 00755 virtual QString mapValueToText(int); 00756 00761 virtual int mapTextToValue(bool*); 00762 00763 private: 00764 int val_base; 00765 protected: 00766 virtual void virtual_hook( int id, void* data ); 00767 private: 00768 class KIntSpinBoxPrivate; 00769 KIntSpinBoxPrivate *d; 00770 }; 00771 00772 00773 /* --------------------------------------------------------------------------- */ 00774 00823 class KDoubleSpinBox : public QSpinBox { 00824 Q_OBJECT 00825 Q_PROPERTY( bool acceptLocalizedNumbers READ acceptLocalizedNumbers WRITE setAcceptLocalizedNumbers ) 00826 Q_OVERRIDE( double maxValue READ maxValue WRITE setMaxValue ) 00827 Q_OVERRIDE( double minValue READ minValue WRITE setMinValue ) 00828 Q_OVERRIDE( double lineStep READ lineStep WRITE setLineStep ) 00829 Q_OVERRIDE( double value READ value WRITE setValue ) 00830 Q_PROPERTY( int precision READ precision WRITE setPrecision ) 00831 00832 public: 00836 KDoubleSpinBox( QWidget * parent=0, const char * name=0 ); 00840 KDoubleSpinBox( double lower, double upper, double step, double value, 00841 int precision=2, QWidget * parent=0, const char * name=0 ); 00842 00843 virtual ~KDoubleSpinBox(); 00844 00846 bool acceptLocalizedNumbers() const; 00849 virtual void setAcceptLocalizedNumbers( bool accept ); 00850 00854 void setRange( double lower, double upper, double step=0.01, int precision=2 ); 00855 00857 int precision() const; 00861 void setPrecision( int precision ); 00874 virtual void setPrecision( int precision, bool force ); 00875 00877 double value() const; 00879 double minValue() const; 00886 void setMinValue( double value ); 00888 double maxValue() const; 00895 void setMaxValue( double value ); 00896 00898 double lineStep() const; 00903 void setLineStep( double step ); 00904 00906 void setValidator( const QValidator * ); 00907 00908 signals: 00910 void valueChanged( double value ); 00911 00912 public slots: 00916 virtual void setValue( double value ); 00917 00918 protected: 00919 virtual QString mapValueToText(int); 00920 virtual int mapTextToValue(bool*); 00921 00922 protected slots: 00923 void slotValueChanged( int value ); 00924 00925 protected: 00926 virtual void virtual_hook( int id, void* data ); 00927 private: 00928 typedef QSpinBox base; 00929 void updateValidator(); 00930 int maxPrecision() const; 00931 00932 class Private; 00933 Private * d; 00934 }; 00935 00936 #endif // K_NUMINPUT_H
KDE Logo
This file is part of the documentation for kdeui Library Version 3.2.3.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 12 15:08:17 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003