QtiPlot  0.9.8.2
DoubleSpinBox.h
Go to the documentation of this file.
00001 /***************************************************************************
00002     File                 : DoubleSpinBox.h
00003     Project              : QtiPlot
00004     --------------------------------------------------------------------
00005     Copyright            : (C) 2007-2008 by Ion Vasilief
00006     Email (use @ for *)  : ion_vasilief*yahoo.fr
00007     Description          : A Double Spin Box
00008 
00009  ***************************************************************************/
00010 
00011 /***************************************************************************
00012  *                                                                         *
00013  *  This program is free software; you can redistribute it and/or modify   *
00014  *  it under the terms of the GNU General Public License as published by   *
00015  *  the Free Software Foundation; either version 2 of the License, or      *
00016  *  (at your option) any later version.                                    *
00017  *                                                                         *
00018  *  This program is distributed in the hope that it will be useful,        *
00019  *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
00020  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
00021  *  GNU General Public License for more details.                           *
00022  *                                                                         *
00023  *   You should have received a copy of the GNU General Public License     *
00024  *   along with this program; if not, write to the Free Software           *
00025  *   Foundation, Inc., 51 Franklin Street, Fifth Floor,                    *
00026  *   Boston, MA  02110-1301  USA                                           *
00027  *                                                                         *
00028  ***************************************************************************/
00029 #ifndef DoubleSpinBox_H
00030 #define DoubleSpinBox_H
00031 
00032 #include <QAbstractSpinBox>
00033 #include <QCheckBox>
00034 
00036 
00039 class DoubleSpinBox : public QAbstractSpinBox
00040 {
00041     Q_OBJECT
00042 
00043 public:
00045 
00049     DoubleSpinBox(const char format = 'g', QWidget * parent = 0);
00050 
00051     void setSingleStep(double val);
00052     void setMaximum(double max);
00053     void setMinimum(double min);
00054     void setRange(double min, double max);
00055 
00056     int decimals(){return d_prec;};
00057     void setDecimals(int prec){if (prec >= 0) d_prec = prec;};
00058 
00059     double value(){interpretText(); return d_value;};
00060     bool setValue(double val);
00061 
00062     QString prefix() const;
00063     void setPrefix(const QString & prefix){d_prefix = prefix;}
00064     
00065     void setFormat(const char format, int prec = 1){d_format = format; setDecimals(prec);};
00066 
00067     QString textFromValue ( double value ) const;
00068     virtual QValidator::State validate ( QString & input, int & pos ) const;
00069 
00070 signals:
00071     void valueChanged ( double d );
00073     void activated(DoubleSpinBox *);
00074 
00075 private slots:
00076     void interpretText();
00077 
00078 protected:
00079     void stepBy ( int steps );
00080     StepEnabled stepEnabled () const;
00081     void focusInEvent(QFocusEvent *);
00082 
00083 private:
00084     char d_format;
00085     double d_min_val;
00086     double d_max_val;
00087     double d_value;
00088     double d_step;
00089     int d_prec;
00090     QString d_prefix;
00091 };
00092 
00094 class RangeLimitBox : public QWidget
00095 {
00096 public:
00097     enum LimitType{LeftLimit, RightLimit};
00098 
00099     RangeLimitBox(LimitType type, QWidget * parent = 0);    
00100     void setDecimals(int prec){d_spin_box->setDecimals(prec);};
00101     double value();
00102     bool isChecked(){return d_checkbox->isChecked();};
00103 
00104 private:
00105     DoubleSpinBox *d_spin_box;
00106     QCheckBox *d_checkbox;
00107     LimitType d_type;
00108 };
00109 #endif // FITDIALOG_H