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 
00033 class QLabel;
00034 class QSlider;
00035 class QLineEdit;
00036 class QLayout;
00037 class QValidator;
00038 
00039 class KIntSpinBox;
00040 
00041 /* ------------------------------------------------------------------------ */
00042 
00048 class KNumInput : public QWidget
00049 {
00050     Q_OBJECT
00051     Q_PROPERTY( QString label READ label WRITE setLabel )
00052 public:
00057     KNumInput(QWidget* parent=0, const char* name=0);
00058 
00063     KNumInput(KNumInput* below, QWidget* parent=0, const char* name=0);
00064     ~KNumInput();
00065 
00084     virtual void setLabel(const QString & label, int a = AlignLeft | AlignTop);
00085 
00089     QString label() const;
00090 
00095     bool showSlider() const { return m_slider; }
00096 
00103     void setSteps(int minor, int major);
00104 
00109     QSizePolicy sizePolicy() const;
00110 
00116     virtual QSize sizeHint() const;
00117 
00118 protected:
00124     void layout(bool deep);
00125 
00134     virtual void doLayout() = 0;
00135 
00136     KNumInput* m_prev, *m_next;
00137     int m_colw1, m_colw2;
00138 
00139     QLabel*  m_label;
00140     QSlider* m_slider;
00141     QSize    m_sizeSlider, m_sizeLabel;
00142 
00143     int      m_alignment;
00144 
00145 private:
00146     void init();
00147 
00148 protected:
00149     virtual void virtual_hook( int id, void* data );
00150 private:
00151     class KNumInputPrivate;
00152     KNumInputPrivate *d;
00153 };
00154 
00155 /* ------------------------------------------------------------------------ */
00156 
00181 class KIntNumInput : public KNumInput
00182 {
00183     Q_OBJECT
00184     Q_PROPERTY( int value READ value WRITE setValue )
00185     Q_PROPERTY( int minValue READ minValue WRITE setMinValue )
00186     Q_PROPERTY( int maxValue READ maxValue WRITE setMaxValue )
00187     Q_PROPERTY( int referencePoint READ referencePoint WRITE setReferencePoint )
00188     Q_PROPERTY( QString suffix READ suffix WRITE setSuffix )
00189     Q_PROPERTY( QString prefix READ prefix WRITE setPrefix )
00190     Q_PROPERTY( QString specialValueText READ specialValueText WRITE setSpecialValueText )
00191 
00192 public:
00197     KIntNumInput(QWidget *parent=0, const char *name=0);
00210     KIntNumInput(int value, QWidget* parent=0, int base = 10, const char *name=0);
00211 
00229     KIntNumInput(KNumInput* below, int value, QWidget* parent=0, int base = 10, const char *name=0);
00230 
00236     virtual ~KIntNumInput();
00237 
00241     int value() const;
00242 
00247     double relativeValue() const;
00248 
00253     int referencePoint() const;
00254 
00259     QString suffix() const;
00264     QString prefix() const;
00269     QString specialValueText() const;
00270 
00276     void setRange(int min, int max, int step=1, bool slider=true);
00280     void setMinValue(int min);
00284     int minValue() const;
00288     void setMaxValue(int max);
00292     int maxValue() const;
00293 
00300     void setSpecialValueText(const QString& text);
00301 
00305     virtual void setLabel(const QString & label, int a = AlignLeft | AlignTop);
00306 
00314     virtual QSize minimumSizeHint() const;
00315 
00316 public slots:
00320     void setValue(int);
00321 
00326     void setRelativeValue(double);
00327 
00332     void setReferencePoint(int);
00333 
00343     void setSuffix(const QString &suffix);
00344 
00352     void setPrefix(const QString &prefix);
00353 
00358     void setEditFocus( bool mark = true );
00359 
00360 signals:
00365     void valueChanged(int);
00366 
00372     void relativeValueChanged(double);
00373 
00374 private slots:
00375     void spinValueChanged(int);
00376     void slotEmitRelativeValueChanged(int); 
00377 
00378 protected:
00382     virtual void doLayout();
00386     void resizeEvent ( QResizeEvent * );
00387 
00388     KIntSpinBox* m_spin;
00389     QSize        m_sizeSpin;
00390 
00391 private:
00392     void init(int value, int _base);
00393 
00394 protected:
00395     virtual void virtual_hook( int id, void* data );
00396 private:
00397     class KIntNumInputPrivate;
00398     KIntNumInputPrivate *d;
00399 };
00400 
00401 
00402 /* ------------------------------------------------------------------------ */
00403 
00404 class KDoubleLine;
00405 
00432 class KDoubleNumInput : public KNumInput
00433 {
00434     Q_OBJECT
00435     Q_PROPERTY( double value READ value WRITE setValue )
00436     Q_PROPERTY( double minValue READ minValue WRITE setMinValue )
00437     Q_PROPERTY( double maxValue READ maxValue WRITE setMaxValue )
00438     Q_PROPERTY( QString suffix READ suffix WRITE setSuffix )
00439     Q_PROPERTY( QString prefix READ prefix WRITE setPrefix )
00440     Q_PROPERTY( QString specialValueText READ specialValueText WRITE setSpecialValueText )
00441 
00442 public:
00447     KDoubleNumInput(QWidget *parent=0, const char *name=0);
00448 
00457     KDoubleNumInput(double value, QWidget *parent=0, const char *name=0);
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);
00491 
00506     KDoubleNumInput(KNumInput* below,
00507             double lower, double upper, double value, double step=0.02,
00508             int precision=2, QWidget *parent=0, const char *name=0);
00509 
00513     double value() const;
00514 
00519     QString suffix() const;
00520 
00525     QString prefix() const;
00526 
00531     int precision() const;
00532 
00537     QString specialValueText() const { return m_specialvalue; }
00538 
00544     void setRange(double min, double max, double step=1, bool slider=true);
00548     void setMinValue(double min);
00552     double minValue() const;
00556     void setMaxValue(double max);
00560     double maxValue() const;
00561 
00565     void setPrecision(int precision);
00566 
00571     double referencePoint() const;
00572 
00577     double relativeValue() const;
00578 
00585     void setSpecialValueText(const QString& text);
00586 
00590     virtual void setLabel(const QString & label, int a = AlignLeft | AlignTop);
00594     virtual QSize minimumSizeHint() const;
00598     virtual bool eventFilter(QObject*, QEvent*);
00599 
00600 public slots:
00604     void setValue(double);
00605 
00610     void setRelativeValue(double);
00611 
00618     void setReferencePoint(double ref);
00619 
00627     void setSuffix(const QString &suffix);
00628 
00635     void setPrefix(const QString &prefix);
00636 
00637 signals:
00642     void valueChanged(double);
00650     void relativeValueChanged(double);
00651 
00652 private slots:
00653     void sliderMoved(int);
00654     void slotEmitRelativeValueChanged(double);
00655 
00656 protected:
00657 
00661     virtual void doLayout();
00665     void resizeEvent ( QResizeEvent * );
00666     virtual void resetEditBox();
00667 
00668     // ### no longer used, remove when BIC allowed
00669     KDoubleLine*   edit;
00670 
00671     bool     m_range;
00672     double   m_lower, m_upper, m_step;
00673     // ### end no longer used
00674 
00675     QSize    m_sizeEdit;
00676 
00677     friend class KDoubleLine;
00678 private:
00679     void init(double value, double lower, double upper,
00680           double step, int precision);
00681     double mapSliderToSpin(int) const;
00682     void updateLegacyMembers();
00683     // ### no longer used, remove when BIC allowed:
00684     QString  m_specialvalue, m_prefix, m_suffix;
00685     double   m_value;
00686     short    m_precision;
00687     // ### end remove when BIC allowed
00688 
00689 protected:
00690     virtual void virtual_hook( int id, void* data );
00691 private:
00692     class KDoubleNumInputPrivate;
00693     KDoubleNumInputPrivate *d;
00694 };
00695 
00696 
00697 /* ------------------------------------------------------------------------ */
00698 
00708 class KIntSpinBox : public QSpinBox
00709 {
00710     Q_OBJECT
00711     Q_PROPERTY( int base READ base WRITE setBase )
00712 
00713 public:
00714 
00722     KIntSpinBox( QWidget *parent=0, const char *name=0);
00723 
00738     KIntSpinBox(int lower, int upper, int step, int value, int base = 10,
00739                 QWidget* parent = 0, const char* name = 0);
00740 
00744     virtual ~KIntSpinBox();
00745 
00749     void setBase(int base);
00753     int base() const;
00758     void setEditFocus(bool mark);
00759 
00760 protected:
00761 
00766     virtual QString mapValueToText(int);
00767 
00772     virtual int mapTextToValue(bool*);
00773 
00774 private:
00775     int val_base;
00776 protected:
00777     virtual void virtual_hook( int id, void* data );
00778 private:
00779     class KIntSpinBoxPrivate;
00780     KIntSpinBoxPrivate *d;
00781 };
00782 
00783 
00784 /* --------------------------------------------------------------------------- */
00785 
00834 class KDoubleSpinBox : public QSpinBox {
00835   Q_OBJECT
00836   Q_PROPERTY( bool acceptLocalizedNumbers READ acceptLocalizedNumbers WRITE setAcceptLocalizedNumbers )
00837   Q_OVERRIDE( double maxValue READ maxValue WRITE setMaxValue )
00838   Q_OVERRIDE( double minValue READ minValue WRITE setMinValue )
00839   Q_OVERRIDE( double lineStep READ lineStep WRITE setLineStep )
00840   Q_OVERRIDE( double value READ value WRITE setValue )
00841   Q_PROPERTY( int precision READ precision WRITE setPrecision )
00842 
00843 public:
00847   KDoubleSpinBox( QWidget * parent=0, const char * name=0 );
00851   KDoubleSpinBox( double lower, double upper, double step, double value,
00852           int precision=2, QWidget * parent=0, const char * name=0 );
00853 
00854   virtual ~KDoubleSpinBox();
00855 
00857   bool acceptLocalizedNumbers() const;
00860   virtual void setAcceptLocalizedNumbers( bool accept );
00861 
00865   void setRange( double lower, double upper, double step=0.01, int precision=2 );
00866 
00868   int precision() const;
00872   void setPrecision( int precision );
00885   virtual void setPrecision( int precision, bool force );
00886 
00888   double value() const;
00890   double minValue() const;
00897   void setMinValue( double value );
00899   double maxValue() const;
00906   void setMaxValue( double value );
00907 
00909   double lineStep() const;
00914   void setLineStep( double step );
00915 
00917   void setValidator( const QValidator * );
00918 
00919 signals:
00921   void valueChanged( double value );
00922 
00923 public slots:
00927   virtual void setValue( double value );
00928 
00929 protected:
00930   virtual QString mapValueToText(int);
00931   virtual int mapTextToValue(bool*);
00932 
00933 protected slots:
00934   void slotValueChanged( int value );
00935 
00936 protected:
00937  virtual void virtual_hook( int id, void* data );
00938 private:
00939   typedef QSpinBox base; 
00940   void updateValidator();
00941   int maxPrecision() const;
00942 
00943   class Private;
00944   Private * d;
00945 };
00946 
00947 #endif // K_NUMINPUT_H
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.4.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sun Feb 27 22:15:04 2005 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001