-
Notifications
You must be signed in to change notification settings - Fork 122
/
DoubleSpinBox.h
105 lines (88 loc) · 3.78 KB
/
DoubleSpinBox.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/***************************************************************************
File : DoubleSpinBox.h
Project : QtiPlot
--------------------------------------------------------------------
Copyright : (C) 2007-2008 by Ion Vasilief
Email (use @ for *) : ion_vasilief*yahoo.fr
Description : A Double Spin Box
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the Free Software *
* Foundation, Inc., 51 Franklin Street, Fifth Floor, *
* Boston, MA 02110-1301 USA *
* *
***************************************************************************/
#ifndef DoubleSpinBox_H
#define DoubleSpinBox_H
#include <QAbstractSpinBox>
#include <QCheckBox>
//! A QDoubleSpinBox allowing to customize numbers display with respect to locale settings.
/**
* It allows the user to specify a custom display format.
*/
class DoubleSpinBox : public QAbstractSpinBox
{
Q_OBJECT
public:
//! Constructor.
/**
* \param format format used to display numbers: has the same meaning as in QLocale::toString ( double i, char f = 'g', int prec = 6 )
* \param parent parent widget (only affects placement of the dialog)
*/
DoubleSpinBox(const char format = 'g', QWidget * parent = 0);
void setSingleStep(double val);
void setMaximum(double max);
void setMinimum(double min);
void setRange(double min, double max);
int decimals(){return d_prec;};
void setDecimals(int prec){if (prec >= 0) d_prec = prec;};
double value();
bool setValue(double val);
void setFormat(const char format, int prec = 1){d_format = format; setDecimals(prec);};
QString textFromValue ( double value ) const;
virtual QValidator::State validate ( QString & input, int & pos ) const;
signals:
void valueChanged ( double d );
//! Signal emitted when the spin box gains focus
void activated(DoubleSpinBox *);
private slots:
void interpretText(bool notify=true);
protected:
void stepBy ( int steps );
StepEnabled stepEnabled () const;
void focusInEvent(QFocusEvent *);
private:
char d_format;
double d_min_val;
double d_max_val;
double d_value;
double d_step;
int d_prec;
};
//! A checkable DoubleSpinBox that can be used to select the limits of a double interval.
class RangeLimitBox : public QWidget
{
public:
enum LimitType{LeftLimit, RightLimit};
RangeLimitBox(LimitType type, QWidget * parent = 0);
void setDecimals(int prec){d_spin_box->setDecimals(prec);};
double value();
bool isChecked(){return d_checkbox->isChecked();};
private:
DoubleSpinBox *d_spin_box;
QCheckBox *d_checkbox;
LimitType d_type;
};
#endif // FITDIALOG_H