45 #include <QGridLayout> 49 #include "matrix4x4Widget.hh" 66 QGridLayout *gL =
new QGridLayout;
68 for (
int i = 0; i < 16; i++)
76 if (_hints.contains (
"default"))
78 QStringList sl = _hints[
"default"].split (
',');
80 if (sl.length () == 16)
82 for (
int i = 0; i < 16 && ok; i++)
83 default_[i] = sl[i].toFloat (&ok);
86 for (
int i = 0; i < 16; i++)
91 for (
int i = 0; i < 16; i++)
92 fields_[i] =
new QLineEdit;
94 for (
int i = 0; i < 4; i++)
96 gL->addWidget (
new QLabel (
"("),i, 0);
97 gL->addWidget (fields_[i], i, 1);
98 gL->addWidget (
new QLabel (
","), i, 2);
99 gL->addWidget (fields_[i + 4], i, 3);
100 gL->addWidget (
new QLabel (
","), i, 4);
101 gL->addWidget (fields_[i + 8], i, 5);
102 gL->addWidget (
new QLabel (
","), i, 6);
103 gL->addWidget (fields_[i + 12], i, 7);
104 gL->addWidget (
new QLabel (
")"), i, 8);
107 for (
int i = 0; i < 16; i++)
109 fields_[i]->setText (QString::number (default_[i]));
110 connect (fields_[i], SIGNAL (editingFinished ()),
this, SLOT (editingFinished ()));
115 for (
int i = 0; i < 16; i++)
116 current_[i] = default_[i];
120 Matrix4x4Widget::~ Matrix4x4Widget()
129 QString rv =
"Matrix4x4 (";
130 for (
int i = 0; i < 16; i++)
131 rv += QString::number (current_[i]) +
",";
133 rv.remove (rv.length () - 1, 1);
143 if (_from.startsWith (
"Matrix4x4 ("))
144 _from.remove (0, 11);
145 if (_from.endsWith (
")"))
146 _from.remove (_from.length () - 1, 1);
148 QStringList sl = _from.split (
',');
153 if (sl.length () == 16)
155 for (
int i = 0; i < 16 && ok; i++)
156 v[i] = sl[i].toFloat (&ok);
159 for (
int i = 0; i < 16; i++)
162 fields_[i]->setText (QString::number (current_[i]));
170 void Matrix4x4Widget::editingFinished ()
174 for (
int i = 0; i < 16; i++)
176 const float v = fields_[i]->text ().toFloat (&ok);
181 fields_[i]->setText (QString::number (current_[i]));
192 for (
int i = 0; i < 16; i++)
194 current_[i] = default_[i];
195 fields_[i]->setText (QString::number (current_[i]));
void fromValue(QString _from)
Read value from string.
Matrix4x4Widget(QMap< QString, QString > &_hints, QString _typeName, QWidget *_parent=NULL)
Constructor.
void toDefault()
Reset to default.
QString toValue()
Convert current value to string.