45 #include <QHBoxLayout> 49 #include "vec3dWidget.hh" 66 QHBoxLayout *hL =
new QHBoxLayout;
68 for (
int i = 0; i < 3; i++)
72 if (_hints.contains (
"default"))
74 QStringList sl = _hints[
"default"].split (
',');
76 if (sl.length () == 3)
78 for (
int i = 0; i < 3 && ok; i++)
79 default_[i] = sl[i].toFloat (&ok);
82 for (
int i = 0; i < 3; i++)
87 for (
int i = 0; i < 3; i++)
88 fields_[i] =
new QLineEdit;
90 hL->addWidget (
new QLabel (
"("));
91 hL->addWidget (fields_[0]);
92 hL->addWidget (
new QLabel (
","));
93 hL->addWidget (fields_[1]);
94 hL->addWidget (
new QLabel (
","));
95 hL->addWidget (fields_[2]);
96 hL->addWidget (
new QLabel (
")"));
98 for (
int i = 0; i < 3; i++)
100 fields_[i]->setText (QString::number (default_[i]));
101 connect (fields_[i], SIGNAL (editingFinished ()),
this, SLOT (editingFinished ()));
106 for (
int i = 0; i < 3; i++)
107 current_[i] = default_[i];
111 Vec3DWidget::~ Vec3DWidget()
120 QString rv =
"Vector (";
121 rv += QString::number (current_[0]) +
",";
122 rv += QString::number (current_[1]) +
",";
123 rv += QString::number (current_[2]) +
")";
132 if (_from.startsWith (
"Vector ("))
134 if (_from.endsWith (
")"))
135 _from.remove (_from.length () - 1, 1);
137 QStringList sl = _from.split (
',');
142 if (sl.length () == 3)
144 for (
int i = 0; i < 3 && ok; i++)
145 v[i] = sl[i].toFloat (&ok);
148 for (
int i = 0; i < 3; i++)
151 fields_[i]->setText (QString::number (current_[i]));
159 void Vec3DWidget::editingFinished ()
163 for (
int i = 0; i < 3; i++)
165 const float v = fields_[i]->text ().toFloat (&ok);
170 fields_[i]->setText (QString::number (current_[i]));
181 for (
int i = 0; i < 3; i++)
183 current_[i] = default_[i];
184 fields_[i]->setText (QString::number (current_[i]));
void toDefault()
Reset to default.
QString toValue()
Convert current value to string.
void fromValue(QString _from)
Read value from string.
Vec3DWidget(QMap< QString, QString > &_hints, QString _typeName, QWidget *_parent=NULL)
Constructor.