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: 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 00186 class KIntNumInput : public KNumInput 00187 { 00188 Q_OBJECT 00189 Q_PROPERTY( int value READ value WRITE setValue ) 00190 Q_PROPERTY( int minValue READ minValue WRITE setMinValue ) 00191 Q_PROPERTY( int maxValue READ maxValue WRITE setMaxValue ) 00192 Q_PROPERTY( int referencePoint READ referencePoint WRITE setReferencePoint ) 00193 Q_PROPERTY( QString suffix READ suffix WRITE setSuffix ) 00194 Q_PROPERTY( QString prefix READ prefix WRITE setPrefix ) 00195 Q_PROPERTY( QString specialValueText READ specialValueText WRITE setSpecialValueText ) 00196 00197 public: 00202 KIntNumInput(QWidget *parent=0, const char *name=0); 00215 KIntNumInput(int value, QWidget* parent=0, int base = 10, const char *name=0); 00216 00234 KIntNumInput(KNumInput* below, int value, QWidget* parent=0, int base = 10, const char *name=0); 00235 00241 virtual ~KIntNumInput(); 00242 00246 int value() const; 00247 00252 double relativeValue() const; 00253 00258 int referencePoint() const; 00259 00264 QString suffix() const; 00269 QString prefix() const; 00274 QString specialValueText() const; 00275 00282 void setRange(int min, int max, int step=1, bool slider=true); 00286 void setMinValue(int min); 00290 int minValue() const; 00294 void setMaxValue(int max); 00298 int maxValue() const; 00299 00306 void setSpecialValueText(const QString& text); 00307 00308 virtual void setLabel(const QString & label, int a = AlignLeft | AlignTop); 00309 00317 virtual QSize minimumSizeHint() const; 00318 00319 public slots: 00323 void setValue(int); 00324 00329 void setRelativeValue(double); 00330 00335 void setReferencePoint(int); 00336 00346 void setSuffix(const QString &suffix); 00347 00355 void setPrefix(const QString &prefix); 00356 00361 void setEditFocus( bool mark = true ); 00362 00363 signals: 00368 void valueChanged(int); 00369 00375 void relativeValueChanged(double); 00376 00377 private slots: 00378 void spinValueChanged(int); 00379 void slotEmitRelativeValueChanged(int); 00380 00381 protected: 00382 virtual void doLayout(); 00383 void resizeEvent ( QResizeEvent * ); 00384 00385 KIntSpinBox* m_spin; 00386 QSize m_sizeSpin; 00387 00388 private: 00389 void init(int value, int _base); 00390 00391 protected: 00392 virtual void virtual_hook( int id, void* data ); 00393 private: 00394 class KIntNumInputPrivate; 00395 KIntNumInputPrivate *d; 00396 }; 00397 00398 00399 /* ------------------------------------------------------------------------ */ 00400 00401 class KDoubleLine; 00402 00429 class KDoubleNumInput : public KNumInput 00430 { 00431 Q_OBJECT 00432 Q_PROPERTY( double value READ value WRITE setValue ) 00433 Q_PROPERTY( double minValue READ minValue WRITE setMinValue ) 00434 Q_PROPERTY( double maxValue READ maxValue WRITE setMaxValue ) 00435 Q_PROPERTY( QString suffix READ suffix WRITE setSuffix ) 00436 Q_PROPERTY( QString prefix READ prefix WRITE setPrefix ) 00437 Q_PROPERTY( QString specialValueText READ specialValueText WRITE setSpecialValueText ) 00438 Q_PROPERTY( int precision READ precision WRITE setPrecision ) 00439 00440 public: 00445 KDoubleNumInput(QWidget *parent=0, const char *name=0); 00446 00455 KDoubleNumInput(double value, QWidget *parent=0, const char *name=0) KDE_DEPRECATED; 00456 00469 KDoubleNumInput(double lower, double upper, double value, double step=0.01, 00470 int precision=2, QWidget *parent=0, const char *name=0); 00471 00475 virtual ~KDoubleNumInput(); 00476 00488 KDoubleNumInput(KNumInput* below, double value, QWidget* parent=0, const char* name=0) KDE_DEPRECATED; 00489 00511 KDoubleNumInput(KNumInput* below, 00512 double lower, double upper, double value, double step=0.02, 00513 int precision=2, QWidget *parent=0, const char *name=0); 00514 00518 double value() const; 00519 00524 QString suffix() const; 00525 00530 QString prefix() const; 00531 00536 int precision() const; 00537 00542 QString specialValueText() const { return m_specialvalue; } 00543 00550 void setRange(double min, double max, double step=1, bool slider=true); 00554 void setMinValue(double min); 00558 double minValue() const; 00562 void setMaxValue(double max); 00566 double maxValue() const; 00567 00571 void setPrecision(int precision); 00572 00577 double referencePoint() const; 00578 00583 double relativeValue() const; 00584 00591 void setSpecialValueText(const QString& text); 00592 00593 virtual void setLabel(const QString & label, int a = AlignLeft | AlignTop); 00594 virtual QSize minimumSizeHint() const; 00595 virtual bool eventFilter(QObject*, QEvent*); 00596 00597 public slots: 00601 void setValue(double); 00602 00607 void setRelativeValue(double); 00608 00615 void setReferencePoint(double ref); 00616 00624 void setSuffix(const QString &suffix); 00625 00632 void setPrefix(const QString &prefix); 00633 00634 signals: 00639 void valueChanged(double); 00647 void relativeValueChanged(double); 00648 00649 private slots: 00650 void sliderMoved(int); 00651 void slotEmitRelativeValueChanged(double); 00652 00653 protected: 00654 virtual void doLayout(); 00655 void resizeEvent ( QResizeEvent * ); 00656 00657 virtual void resetEditBox(); 00658 00659 // ### no longer used, remove when BIC allowed 00660 KDoubleLine* edit; 00661 00662 bool m_range; 00663 double m_lower, m_upper, m_step; 00664 // ### end no longer used 00665 00666 QSize m_sizeEdit; 00667 00668 friend class KDoubleLine; 00669 private: 00670 void init(double value, double lower, double upper, 00671 double step, int precision); 00672 double mapSliderToSpin(int) const; 00673 void updateLegacyMembers(); 00674 // ### no longer used, remove when BIC allowed: 00675 QString m_specialvalue, m_prefix, m_suffix; 00676 double m_value; 00677 short m_precision; 00678 // ### end remove when BIC allowed 00679 00680 protected: 00681 virtual void virtual_hook( int id, void* data ); 00682 private: 00683 class KDoubleNumInputPrivate; 00684 KDoubleNumInputPrivate *d; 00685 }; 00686 00687 00688 /* ------------------------------------------------------------------------ */ 00689 00699 class KIntSpinBox : public QSpinBox 00700 { 00701 Q_OBJECT 00702 Q_PROPERTY( int base READ base WRITE setBase ) 00703 00704 public: 00705 00713 KIntSpinBox( QWidget *parent=0, const char *name=0); 00714 00729 KIntSpinBox(int lower, int upper, int step, int value, int base = 10, 00730 QWidget* parent = 0, const char* name = 0); 00731 00735 virtual ~KIntSpinBox(); 00736 00740 void setBase(int base); 00744 int base() const; 00749 void setEditFocus(bool mark); 00750 00751 protected: 00752 00757 virtual QString mapValueToText(int); 00758 00763 virtual int mapTextToValue(bool*); 00764 00765 private: 00766 int val_base; 00767 protected: 00768 virtual void virtual_hook( int id, void* data ); 00769 private: 00770 class KIntSpinBoxPrivate; 00771 KIntSpinBoxPrivate *d; 00772 }; 00773 00774 00775 /* --------------------------------------------------------------------------- */ 00776 00825 class KDoubleSpinBox : public QSpinBox { 00826 Q_OBJECT 00827 Q_PROPERTY( bool acceptLocalizedNumbers READ acceptLocalizedNumbers WRITE setAcceptLocalizedNumbers ) 00828 Q_OVERRIDE( double maxValue READ maxValue WRITE setMaxValue ) 00829 Q_OVERRIDE( double minValue READ minValue WRITE setMinValue ) 00830 Q_OVERRIDE( double lineStep READ lineStep WRITE setLineStep ) 00831 Q_OVERRIDE( double value READ value WRITE setValue ) 00832 Q_PROPERTY( int precision READ precision WRITE setPrecision ) 00833 00834 public: 00838 KDoubleSpinBox( QWidget * parent=0, const char * name=0 ); 00842 KDoubleSpinBox( double lower, double upper, double step, double value, 00843 int precision=2, QWidget * parent=0, const char * name=0 ); 00844 00845 virtual ~KDoubleSpinBox(); 00846 00848 bool acceptLocalizedNumbers() const; 00851 virtual void setAcceptLocalizedNumbers( bool accept ); 00852 00856 void setRange( double lower, double upper, double step=0.01, int precision=2 ); 00857 00859 int precision() const; 00863 void setPrecision( int precision ); 00876 virtual void setPrecision( int precision, bool force ); 00877 00879 double value() const; 00881 double minValue() const; 00888 void setMinValue( double value ); 00890 double maxValue() const; 00897 void setMaxValue( double value ); 00898 00900 double lineStep() const; 00905 void setLineStep( double step ); 00906 00908 void setValidator( const QValidator * ); 00909 00910 signals: 00912 void valueChanged( double value ); 00913 00914 public slots: 00918 virtual void setValue( double value ); 00919 00920 protected: 00921 virtual QString mapValueToText(int); 00922 virtual int mapTextToValue(bool*); 00923 00924 protected slots: 00925 void slotValueChanged( int value ); 00926 00927 protected: 00928 virtual void virtual_hook( int id, void* data ); 00929 private: 00930 typedef QSpinBox base; 00931 void updateValidator(); 00932 int maxPrecision() const; 00933 00934 class Private; 00935 Private * d; 00936 }; 00937 00938 #endif // K_NUMINPUT_H
KDE Logo
This file is part of the documentation for kdeui Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Sep 29 09:43:29 2004 by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2003