44 #include <QHBoxLayout> 48 #include "vec4dWidget.hh" 65 QHBoxLayout *hL =
new QHBoxLayout;
67 for (
int i = 0; i < 4; i++)
71 if (_hints.contains (
"default"))
73 QStringList sl = _hints[
"default"].split (
',');
75 if (sl.length () == 4)
77 for (
int i = 0; i < 4 && ok; i++)
78 default_[i] = sl[i].toFloat (&ok);
81 for (
int i = 0; i < 4; i++)
86 for (
int i = 0; i < 4; i++)
87 fields_[i] =
new QLineEdit;
89 hL->addWidget (
new QLabel (
"("));
90 hL->addWidget (fields_[0]);
91 hL->addWidget (
new QLabel (
","));
92 hL->addWidget (fields_[1]);
93 hL->addWidget (
new QLabel (
","));
94 hL->addWidget (fields_[2]);
95 hL->addWidget (
new QLabel (
","));
96 hL->addWidget (fields_[3]);
97 hL->addWidget (
new QLabel (
")"));
99 for (
int i = 0; i < 4; i++)
101 fields_[i]->setText (QString::number (default_[i]));
102 connect (fields_[i], SIGNAL (editingFinished ()),
this, SLOT (editingFinished ()));
107 for (
int i = 0; i < 4; i++)
108 current_[i] = default_[i];
112 Vec4DWidget::~ Vec4DWidget()
121 QString rv =
"Vector4 (";
122 rv += QString::number (current_[0]) +
",";
123 rv += QString::number (current_[1]) +
",";
124 rv += QString::number (current_[2]) +
",";
125 rv += QString::number (current_[3]) +
")";
134 if (_from.startsWith (
"Vector4 ("))
136 if (_from.endsWith (
")"))
137 _from.remove (_from.length () - 1, 1);
139 QStringList sl = _from.split (
',');
144 if (sl.length () == 4)
146 for (
int i = 0; i < 4 && ok; i++)
147 v[i] = sl[i].toFloat (&ok);
150 for (
int i = 0; i < 4; i++)
153 fields_[i]->setText (QString::number (current_[i]));
161 void Vec4DWidget::editingFinished ()
165 for (
int i = 0; i < 4; i++)
167 const float v = fields_[i]->text ().toFloat (&ok);
172 fields_[i]->setText (QString::number (current_[i]));
183 for (
int i = 0; i < 4; i++)
185 current_[i] = default_[i];
186 fields_[i]->setText (QString::number (current_[i]));
QString toValue()
Convert current value to string.
void toDefault()
Reset to default.
void fromValue(QString _from)
Read value from string.
Vec4DWidget(QMap< QString, QString > &_hints, QString _typeName, QWidget *_parent=NULL)
Constructor.