Mon, 10 Apr 2023 12:40:49 +0300
isConvex renamed to quadrilateral_convexity, refactor, now returns an enum instead of bool
264
76a025db4948
Convert all includes to be relative to project root directory. Files that cannot be found in this manner use angle brackets.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
252
diff
changeset
|
1 | #include <ui_matrixeditor.h> |
76a025db4948
Convert all includes to be relative to project root directory. Files that cannot be found in this manner use angle brackets.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
252
diff
changeset
|
2 | #include "widgets/matrixeditor.h" |
76a025db4948
Convert all includes to be relative to project root directory. Files that cannot be found in this manner use angle brackets.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
252
diff
changeset
|
3 | #include "widgets/multiplyfactordialog.h" |
85
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
4 | |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
5 | constexpr char BUTTON_COLUMN_PROPERTY[] = "_ldforge_column"; |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
6 | |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
7 | MatrixEditor::MatrixEditor(const glm::mat4 value, QWidget* parent) : |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
8 | QWidget(parent), |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
9 | ui(new Ui::MatrixEditor) |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
10 | { |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
11 | ui->setupUi(this); |
252
da4876bfd822
Move some widgets into a static library
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
250
diff
changeset
|
12 | for (int column = 0; column < (int)glm::countof(this->spinboxes); column += 1) |
85
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
13 | { |
252
da4876bfd822
Move some widgets into a static library
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
250
diff
changeset
|
14 | for (int row = 0; row < (int)glm::countof(this->spinboxes[0]); row += 1) |
85
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
15 | { |
206
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
112
diff
changeset
|
16 | const QString name = QStringLiteral("cell%1%2").arg(column).arg(row); |
85
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
17 | QDoubleSpinBox** spinbox = &this->spinboxes[column][row]; |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
18 | *spinbox = this->findChild<QDoubleSpinBox*>(name); |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
19 | connect(*spinbox, qOverload<double>(&QDoubleSpinBox::valueChanged), [&]() |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
20 | { |
112 | 21 | Q_EMIT this->valueChanged(this->value()); |
85
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
22 | }); |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
23 | Q_ASSERT(*spinbox != nullptr); |
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
24 | } |
206
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
112
diff
changeset
|
25 | const QString multiplyButtonName = QStringLiteral("multiply%1").arg(column); |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
112
diff
changeset
|
26 | QAbstractButton* button = this->findChild<QAbstractButton*>(multiplyButtonName); |
85
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}; |
252
da4876bfd822
Move some widgets into a static library
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
250
diff
changeset
|
46 | for (int column = 0; column < (int)glm::countof(this->spinboxes); column += 1) |
85
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
47 | { |
252
da4876bfd822
Move some widgets into a static library
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
250
diff
changeset
|
48 | for (int row = 0; row < (int)glm::countof(this->spinboxes[0]); row += 1) |
85
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
49 | { |
252
da4876bfd822
Move some widgets into a static library
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
250
diff
changeset
|
50 | result[column][row] = static_cast<float>(this->spinboxes[column][row]->value()); |
85
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 | { |
252
da4876bfd822
Move some widgets into a static library
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
250
diff
changeset
|
58 | for (int column = 0; column < (int)glm::countof(this->spinboxes); column += 1) |
85
40e2940605a3
added a matrix editing widget
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
59 | { |
252
da4876bfd822
Move some widgets into a static library
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
250
diff
changeset
|
60 | for (int row = 0; row < (int)glm::countof(this->spinboxes[0]); row += 1) |
85
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 | } |