51 #include <QHBoxLayout>
55 #include "vec4dWidget.hh"
72 QHBoxLayout *hL =
new QHBoxLayout;
74 for (
int i = 0; i < 4; i++)
78 if (_hints.contains (
"default"))
80 QStringList sl = _hints[
"default"].split (
',');
82 if (sl.length () == 4)
84 for (
int i = 0; i < 4 && ok; i++)
85 default_[i] = sl[i].toFloat (&ok);
88 for (
int i = 0; i < 4; i++)
93 for (
int i = 0; i < 4; 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 (
","));
103 hL->addWidget (fields_[3]);
104 hL->addWidget (
new QLabel (
")"));
106 for (
int i = 0; i < 4; i++)
108 fields_[i]->setText (QString::number (default_[i]));
109 connect (fields_[i], SIGNAL (editingFinished ()),
this, SLOT (editingFinished ()));
114 for (
int i = 0; i < 4; i++)
115 current_[i] = default_[i];
128 QString rv =
"Vector4 (";
129 rv += QString::number (current_[0]) +
",";
130 rv += QString::number (current_[1]) +
",";
131 rv += QString::number (current_[2]) +
",";
132 rv += QString::number (current_[3]) +
")";
141 if (_from.startsWith (
"Vector4 ("))
143 if (_from.endsWith (
")"))
144 _from.remove (_from.length () - 1, 1);
146 QStringList sl = _from.split (
',');
151 if (sl.length () == 4)
153 for (
int i = 0; i < 4 && ok; i++)
154 v[i] = sl[i].toFloat (&ok);
157 for (
int i = 0; i < 4; i++)
160 fields_[i]->setText (QString::number (current_[i]));
168 void Vec4DWidget::editingFinished ()
172 for (
int i = 0; i < 4; i++)
174 const float v = fields_[i]->text ().toFloat (&ok);
179 fields_[i]->setText (QString::number (current_[i]));
190 for (
int i = 0; i < 4; i++)
192 current_[i] = default_[i];
193 fields_[i]->setText (QString::number (current_[i]));
QString toValue()
Convert current value to string.
Vec4DWidget(QMap< QString, QString > &_hints, QString _typeName, QWidget *_parent=NULL)
Constructor.
void fromValue(QString _from)
Read value from string.
void toDefault()
Reset to default.
~Vec4DWidget()
Destructor.