qtInputs.h 4.97 KB
Newer Older
Sylvain Thery's avatar
Sylvain Thery committed
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
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* version 0.1                                                                  *
* Copyright (C) 2009, IGG Team, LSIIT, University of Strasbourg                *
*                                                                              *
* This library is free software; you can redistribute it and/or modify it      *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your     *
* option) any later version.                                                   *
*                                                                              *
* This library 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 Lesser General Public License  *
* for more details.                                                            *
*                                                                              *
* You should have received a copy of the GNU Lesser General Public License     *
* along with this library; if not, write to the Free Software Foundation,      *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.           *
*                                                                              *
* Web site: https://iggservis.u-strasbg.fr/CGoGN/                              *
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

#ifndef QTINPUTS_H_
#define QTINPUTS_H_

//#include <QApplication>
#include <QDesktopWidget>
//#include <QMainWindow>
#include <QWidget>
#include <QtGui>
#include <QDialog>
#include <QLabel>


namespace CGoGN
{

namespace Utils
{

namespace QT
{

/**
 * Abstract class for Variable input in dialog window
 */
class Var
{
protected:
	const Var* m_next;
	std::string m_label;
public:
	Var(const Var& v);
	Var();

	const Var* next() const;
	QLabel* label() const;

	virtual QWidget* createInput() const =0;
	virtual void updateFrom( QWidget* widg) const =0;

};

/**
 * Class for boolean input in dialog window
 * Use: VarBool(ref_to_val, "label" [,nextVar])
 */
class VarBool: public Var
{
public:
	bool& m_val;
public:
	VarBool(bool& val, const std::string& label);
	VarBool(bool& val, const std::string& label, const Var& var);
	QWidget* createInput() const;
	void updateFrom( QWidget* widg) const;
};

/**
 * Class for integer input in dialog window (with spinbox)
 * Use: VarBool(min,max,ref_to_val, "label" [,nextVar])
 */
thery's avatar
thery committed
85
class VarInteger: public Var
Sylvain Thery's avatar
Sylvain Thery committed
86
87
88
89
90
91
{
public:
	int m_min;
	int m_max;
	int& m_val;
public:
thery's avatar
thery committed
92
93
	VarInteger(int min, int max, int& val, const std::string& label);
	VarInteger(int min, int max, int& val, const std::string& label, const Var& var);
Sylvain Thery's avatar
Sylvain Thery committed
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
	QWidget* createInput() const;
	void updateFrom( QWidget* widg) const;
};

/**
 * Class for double input in dialog window (with spinbox)
 * Use: VarBool(min,max,ref_to_val, "label" [,nextVar])
 */
class VarDbl: public Var
{
public:
	double m_min;
	double m_max;
	double& m_val;
public:
	VarDbl(double min, double max, double& val, const std::string& label);
	VarDbl(double min, double max, double& val, const std::string& label, const Var& var);
	QWidget* createInput() const;
	void updateFrom( QWidget* widg) const;
};

/**
 * Class for integer input in dialog window (with slider)
 * Use: VarBool(min,max,ref_to_val, "label" [,nextVar])
 */
class VarSlider: public Var
{
public:
	int m_min;
	int m_max;
	int& m_val;
public:
	VarSlider(int min, int max, int& val, const std::string& label);
	VarSlider(int min, int max, int& val, const std::string& label, const Var& var);
	QWidget* createInput() const;
	void updateFrom( QWidget* widg) const;
};

/**
 * Class for combo input (interger in dialog window (with spinbox)
 * Use: VarBool("list_of_item, ref_to_val, "label" [,nextVar])
 *     item are separated by ; in list_of_item
 */
class VarCombo: public Var
{
public:
	const std::string& m_choices;
	int& m_val;
public:
	VarCombo(const std::string& choices, int& v, const std::string& label);
	VarCombo(const std::string& choices, int& v, const std::string& label, const Var& var);
	QWidget* createInput() const;
	void updateFrom( QWidget* widg) const;
};



/**
 * Open a QtDialog for inputs of all chain Var defined
 * &param v1 a Var object (that chain other Var objects
 * Example:
 * {using namespace Utils::QT
 *  inputValues(VarInt(0,20,x, "Entier",
 *				VarBool(b, "Bool",
 * 				VarDbl(0.314,3.14,d,"Double",
 *				VarSlider(10,100,s,"Slider",
 *				VarCombo("Riri;Fifi;Loulou;Donald",c,"Combo"))))) );
 * } // limit scope of using namespace
 */
bool inputValues(const Var& v1, const std::string& title ="input data");


}
} // end namespaces
}

#endif