src/matrixinput.cpp

Tue, 14 Feb 2017 08:15:58 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Tue, 14 Feb 2017 08:15:58 +0200
changeset 1132
825dd975588d
parent 1072
9ce9496427f2
child 1326
69a90bd2dba2
permissions
-rw-r--r--

Fixed the free camera icon not showing up anymore.

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

mercurial