Sat, 05 Mar 2022 13:18:40 +0200
Icons update
85
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
1 | #include "main.h" |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
2 | #include "matrixeditor.h" |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
3 | #include "ui_matrixeditor.h" |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
4 | #include "../ui/multiplyfactordialog.h" |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
5 | |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
6 | constexpr char BUTTON_COLUMN_PROPERTY[] = "_ldforge_column"; |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
7 | |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
8 | MatrixEditor::MatrixEditor(const glm::mat4 value, QWidget* parent) : |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
9 | QWidget(parent), |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
10 | ui(new Ui::MatrixEditor) |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
11 | { |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
12 | ui->setupUi(this); |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
13 | for (int column = 0; column < countof(this->spinboxes); column += 1) |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
14 | { |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
15 | for (int row = 0; row < countof(this->spinboxes[0]); row += 1) |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
16 | { |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
17 | const QString name = "cell"_q + QString::number(column) + QString::number(row); |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
18 | QDoubleSpinBox** spinbox = &this->spinboxes[column][row]; |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
19 | *spinbox = this->findChild<QDoubleSpinBox*>(name); |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
20 | connect(*spinbox, qOverload<double>(&QDoubleSpinBox::valueChanged), [&]() |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
21 | { |
112 | 22 | Q_EMIT this->valueChanged(this->value()); |
85
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
23 | }); |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
24 | Q_ASSERT(*spinbox != nullptr); |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
25 | } |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
26 | QAbstractButton* button = this->findChild<QAbstractButton*>("multiply"_q + QString::number(column)); |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
27 | button->setProperty(BUTTON_COLUMN_PROPERTY, column); |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
28 | connect(button, &QAbstractButton::clicked, this, &MatrixEditor::multiplyButtonPressed); |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
29 | } |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
30 | this->setValue(value); |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
31 | } |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
32 | |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
33 | MatrixEditor::MatrixEditor(QWidget *parent) : |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
34 | MatrixEditor{glm::mat4{1}, parent} |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
35 | { |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
36 | } |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
37 | |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
38 | MatrixEditor::~MatrixEditor() |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
39 | { |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
40 | delete ui; |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
41 | } |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
42 | |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
43 | glm::mat4 MatrixEditor::value() const |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
44 | { |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
45 | glm::mat4 result{1}; |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
46 | for (int column = 0; column < countof(this->spinboxes); column += 1) |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
47 | { |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
48 | for (int row = 0; row < countof(this->spinboxes[0]); row += 1) |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
49 | { |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
50 | result[column][row] = this->spinboxes[column][row]->value(); |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
51 | } |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
52 | } |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
53 | return result; |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
54 | } |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
55 | |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
56 | void MatrixEditor::setValue(const glm::mat4& value) |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
57 | { |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
58 | for (int column = 0; column < countof(this->spinboxes); column += 1) |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
59 | { |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
60 | for (int row = 0; row < countof(this->spinboxes[0]); row += 1) |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
61 | { |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
62 | QDoubleSpinBox* spinbox = this->spinboxes[column][row]; |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
63 | QSignalBlocker blocker{spinbox}; |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
64 | spinbox->setValue(value[column][row]); |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
65 | } |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
66 | } |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
67 | } |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
68 | |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
69 | void MatrixEditor::multiplyButtonPressed() |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
70 | { |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
71 | QAbstractButton* button = qobject_cast<QAbstractButton*>(this->sender()); |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
72 | if (button != nullptr) |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
73 | { |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
74 | bool ok; |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
75 | const int column = button->property(BUTTON_COLUMN_PROPERTY).toInt(&ok); |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
76 | if (ok and column >= 0 and column < this->matrixSize()) |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
77 | { |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
78 | glm::mat4 newValue = this->value(); |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
79 | MultiplyFactorDialog dialog{newValue[column], this}; |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
80 | const int result = dialog.exec(); |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
81 | if (result == QDialog::Accepted) |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
82 | { |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
83 | newValue[column] = glm::vec4{dialog.value(), (column == 3) ? 1 : 0}; |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
84 | this->setValue(newValue); |
112 | 85 | Q_EMIT valueChanged(newValue); |
85
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
86 | } |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
87 | } |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
88 | } |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
89 | } |