1 /* |
|
2 * LDForge: LDraw parts authoring CAD |
|
3 * Copyright (C) 2013 - 2018 Teemu Piippo |
|
4 * |
|
5 * This program is free software: you can redistribute it and/or modify |
|
6 * it under the terms of the GNU General Public License as published by |
|
7 * the Free Software Foundation, either version 3 of the License, or |
|
8 * (at your option) any later version. |
|
9 * |
|
10 * This program is distributed in the hope that it will be useful, |
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 * GNU General Public License for more details. |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License |
|
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
17 */ |
|
18 |
|
19 #include <QGridLayout> |
|
20 #include "matrixinput.h" |
|
21 |
|
22 MatrixInput::MatrixInput(QWidget *parent) : QWidget(parent) |
|
23 { |
|
24 QGridLayout* layout = new QGridLayout {this}; |
|
25 setLayout(layout); |
|
26 |
|
27 for (int i = 0; i < 3; ++i) |
|
28 for (int j = 0; j < 3; ++j) |
|
29 { |
|
30 _spinboxes[i * 3 + j] = new QDoubleSpinBox {this}; |
|
31 layout->addWidget(_spinboxes[i * 3 + j], i, j); |
|
32 } |
|
33 } |
|
34 |
|
35 int MatrixInput::decimals() const |
|
36 { |
|
37 return _spinboxes[0]->decimals(); |
|
38 } |
|
39 |
|
40 double MatrixInput::maximum() const |
|
41 { |
|
42 return _spinboxes[0]->maximum(); |
|
43 } |
|
44 |
|
45 double MatrixInput::minimum() const |
|
46 { |
|
47 return _spinboxes[0]->minimum(); |
|
48 } |
|
49 |
|
50 QString MatrixInput::prefix() const |
|
51 { |
|
52 return _spinboxes[0]->prefix(); |
|
53 } |
|
54 |
|
55 void MatrixInput::setDecimals(int precision) |
|
56 { |
|
57 for (QDoubleSpinBox* spinbox : _spinboxes) |
|
58 spinbox->setDecimals(precision); |
|
59 } |
|
60 |
|
61 void MatrixInput::setMaximum(double maximum) |
|
62 { |
|
63 for (QDoubleSpinBox* spinbox : _spinboxes) |
|
64 spinbox->setMaximum(maximum); |
|
65 } |
|
66 |
|
67 void MatrixInput::setMinimum(double minimum) |
|
68 { |
|
69 for (QDoubleSpinBox* spinbox : _spinboxes) |
|
70 spinbox->setMinimum(minimum); |
|
71 } |
|
72 |
|
73 void MatrixInput::setPrefix(const QString& prefix) |
|
74 { |
|
75 for (QDoubleSpinBox* spinbox : _spinboxes) |
|
76 spinbox->setPrefix(prefix); |
|
77 } |
|
78 |
|
79 void MatrixInput::setRange(double minimum, double maximum) |
|
80 { |
|
81 for (QDoubleSpinBox* spinbox : _spinboxes) |
|
82 spinbox->setRange(minimum, maximum); |
|
83 } |
|
84 |
|
85 void MatrixInput::setSingleStep(double singleStep) |
|
86 { |
|
87 for (QDoubleSpinBox* spinbox : _spinboxes) |
|
88 spinbox->setSingleStep(singleStep); |
|
89 } |
|
90 |
|
91 void MatrixInput::setSuffix(const QString& suffix) |
|
92 { |
|
93 for (QDoubleSpinBox* spinbox : _spinboxes) |
|
94 spinbox->setSuffix(suffix); |
|
95 } |
|
96 |
|
97 QString MatrixInput::suffix() |
|
98 { |
|
99 return _spinboxes[0]->suffix(); |
|
100 } |
|
101 |
|
102 void MatrixInput::setValue(const Matrix& value) |
|
103 { |
|
104 for (int i = 0; i < 3; ++i) |
|
105 for (int j = 0; j < 3; ++j) |
|
106 _spinboxes[i * 3 + j]->setValue(value(i, j)); |
|
107 } |
|
108 |
|
109 Matrix MatrixInput::value() |
|
110 { |
|
111 Matrix result; |
|
112 |
|
113 for (int i = 0; i < 3; ++i) |
|
114 for (int j = 0; j < 3; ++j) |
|
115 result(i, j) = _spinboxes[i * 3 + j]->value(); |
|
116 |
|
117 return result; |
|
118 } |
|