1 /*
2  * Copyright (C) 2009 Matthew Gates
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA  02110-1335, USA.
17  */
18 
19 #ifndef TUINODEDOUBLE_HPP
20 #define TUINODEDOUBLE_HPP
21 
22 #include "TuiNodeEditable.hpp"
23 #include <QObject>
24 #include <QString>
25 
26 
27 //! @class TuiNodeDouble
28 //! Allows navigation but also editing of a double value
29 class TuiNodeDouble : public TuiNodeEditable
30 {
31 	Q_OBJECT
32 
33 public:
34 	//! Create a TuiNodeDouble node.
35 	//! @param text the text to be displayed for this node
36 	//! @param receiver a QObject which will receive a signal when the value
37 	//! is changed
38 	//! @param method the method in the receiver which will be called when
39 	//! the value is changed.  Note that this should be passed using the
40 	//! SLOT() macro.
41 	//! @param defValue the default value for the node
42 	//! @param min the minimum acceptable value for the node
43 	//! @param max the maximum acceptable value for the node
44 	//! @param inc the increment which will be added and subtracted
45 	//! from the current value when the up and down cursors are used
46 	//! @param parent the node for the parent menu item
47 	//! @param prev the previous node in the current menu (typically
48 	//! shares the same parent)
49 	TuiNodeDouble(const QString& text, QObject* receiver, const char* method, double defValue,
50 		      double min, double max, double inc, TuiNode* parent=Q_NULLPTR, TuiNode* prev=Q_NULLPTR);
51 	virtual TuiNodeResponse handleEditingKey(int key) Q_DECL_OVERRIDE;
52 	virtual QString getDisplayText() const Q_DECL_OVERRIDE;
53 
54 signals:
55 	void setValue(double b);
56 
57 private:
58 	double value;
59 	//! persistent copy of the value in string format.
60 	//! This is necessary, because if the string is re-created from double
61 	//! on every digit entered, it is impossible to enter numbers with 0
62 	//! in any position after the decimal sign.
63 	QString stringValue;
64 	double minimum;
65 	double maximum;
66 	double increment;
67 	bool typing;
68 	bool typedDecimal;
69 };
70 
71 #endif /*TUINODEDOUBLE_HPP*/
72 
73