qtInputs.h 5.44 KB
Newer Older
Sylvain Thery's avatar
Sylvain Thery committed
1 2 3
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* version 0.1                                                                  *
4
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg           *
Sylvain Thery's avatar
Sylvain Thery committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
*                                                                              *
* 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.           *
*                                                                              *
20
* Web site: http://cgogn.unistra.fr/                                           *
Sylvain Thery's avatar
Sylvain Thery committed
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
* 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;
Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
53

Sylvain Thery's avatar
Sylvain Thery committed
54 55 56 57 58 59 60
public:
	Var(const Var& v);
	Var();

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

Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
61 62
	virtual QWidget* createInput() const = 0;
	virtual void updateFrom( QWidget* widg) const = 0;
Sylvain Thery's avatar
Sylvain Thery committed
63 64 65 66 67 68 69 70 71 72
};

/**
 * Class for boolean input in dialog window
 * Use: VarBool(ref_to_val, "label" [,nextVar])
 */
class VarBool: public Var
{
public:
	bool& m_val;
Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
73

Sylvain Thery's avatar
Sylvain Thery committed
74 75 76 77
public:
	VarBool(bool& val, const std::string& label);
	VarBool(bool& val, const std::string& label, const Var& var);
	QWidget* createInput() const;
Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
78
	void updateFrom(QWidget* widg) const;
Sylvain Thery's avatar
Sylvain Thery committed
79 80 81 82 83 84
};

/**
 * 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
{
public:
	int m_min;
	int m_max;
	int& m_val;
Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
91

Sylvain Thery's avatar
Sylvain Thery committed
92
public:
thery's avatar
thery committed
93 94
	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
95
	QWidget* createInput() const;
Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
96
	void updateFrom(QWidget* widg) const;
Sylvain Thery's avatar
Sylvain Thery committed
97 98 99 100 101 102 103 104 105 106 107 108
};

/**
 * 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;
Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
109

Sylvain Thery's avatar
Sylvain Thery committed
110 111 112 113
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;
Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
114
	void updateFrom(QWidget* widg) const;
Sylvain Thery's avatar
Sylvain Thery committed
115 116
};

117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136

/**
 * Class for double input in dialog window (with spinbox)
 * Use: VarBool(min,max,ref_to_val, "label" [,nextVar])
 */
class VarFloat: public Var
{
public:
	float m_min;
	float m_max;
	float& m_val;

public:
	VarFloat(float min, float max, float& val, const std::string& label);
	VarFloat(float min, float max, float& val, const std::string& label, const Var& var);
	QWidget* createInput() const;
	void updateFrom(QWidget* widg) const;
};


Sylvain Thery's avatar
Sylvain Thery committed
137 138 139 140 141 142 143 144 145 146
/**
 * 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;
Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
147

Sylvain Thery's avatar
Sylvain Thery committed
148 149 150 151
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;
Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
152
	void updateFrom(QWidget* widg) const;
Sylvain Thery's avatar
Sylvain Thery committed
153 154 155 156 157 158 159 160 161 162 163 164
};

/**
 * 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;
Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
165

Sylvain Thery's avatar
Sylvain Thery committed
166 167 168 169
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;
Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
170
	void updateFrom(QWidget* widg) const;
Sylvain Thery's avatar
Sylvain Thery committed
171 172 173 174 175 176 177 178 179 180 181 182 183 184
};

/**
 * 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
 */
Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
185 186 187 188
bool inputValues(const Var& v1, const std::string& title = "input data");


} // namespace QT
Sylvain Thery's avatar
Sylvain Thery committed
189

Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
190
} // namespace Utils
Sylvain Thery's avatar
Sylvain Thery committed
191

Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
192
} // namespace CGoGN
Sylvain Thery's avatar
Sylvain Thery committed
193 194

#endif