51 #include <QHBoxLayout>
55 #include "vec3dWidget.hh"
72 QHBoxLayout *hL =
new QHBoxLayout;
74 for (
int i = 0; i < 3; i++)
78 if (_hints.contains (
"default"))
80 QStringList sl = _hints[
"default"].split (
',');
82 if (sl.length () == 3)
84 for (
int i = 0; i < 3 && ok; i++)
85 default_[i] = sl[i].toFloat (&ok);
88 for (
int i = 0; i < 3; i++)
93 for (
int i = 0; i < 3; i++)
94 fields_[i] =
new QLineEdit;
96 hL->addWidget (
new QLabel (
"("));
97 hL->addWidget (fields_[0]);
98 hL->addWidget (
new QLabel (
","));
99 hL->addWidget (fields_[1]);
100 hL->addWidget (
new QLabel (
","));
101 hL->addWidget (fields_[2]);
102 hL->addWidget (
new QLabel (
")"));
104 for (
int i = 0; i < 3; i++)
106 fields_[i]->setText (QString::number (default_[i]));
107 connect (fields_[i], SIGNAL (editingFinished ()),
this, SLOT (editingFinished ()));
112 for (
int i = 0; i < 3; i++)
113 current_[i] = default_[i];
126 QString rv =
"Vector (";
127 rv += QString::number (current_[0]) +
",";
128 rv += QString::number (current_[1]) +
",";
129 rv += QString::number (current_[2]) +
")";
138 if (_from.startsWith (
"Vector ("))
140 if (_from.endsWith (
")"))
141 _from.remove (_from.length () - 1, 1);
143 QStringList sl = _from.split (
',');
148 if (sl.length () == 3)
150 for (
int i = 0; i < 3 && ok; i++)
151 v[i] = sl[i].toFloat (&ok);
154 for (
int i = 0; i < 3; i++)
157 fields_[i]->setText (QString::number (current_[i]));
165 void Vec3DWidget::editingFinished ()
169 for (
int i = 0; i < 3; i++)
171 const float v = fields_[i]->text ().toFloat (&ok);
176 fields_[i]->setText (QString::number (current_[i]));
187 for (
int i = 0; i < 3; i++)
189 current_[i] = default_[i];
190 fields_[i]->setText (QString::number (current_[i]));
Vec3DWidget(QMap< QString, QString > &_hints, QString _typeName, QWidget *_parent=NULL)
Constructor.
~Vec3DWidget()
Destructor.
void fromValue(QString _from)
Read value from string.
QString toValue()
Convert current value to string.
void toDefault()
Reset to default.