src/ui/multiplyfactordialog.cpp

Wed, 25 May 2022 20:36:34 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Wed, 25 May 2022 20:36:34 +0300
changeset 199
6988973515d2
parent 115
ed884a2fb009
permissions
-rw-r--r--

Fix pick() picking from weird places on the screen with high DPI scaling

glReadPixels reads data from the frame buffer, which contains data after
high DPI scaling, so any reads to that need to take this scaling into account

81
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
1 #include "multiplyfactordialog.h"
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
2 #include "ui_multiplyfactordialog.h"
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
3
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
4 MultiplyFactorDialog::MultiplyFactorDialog(const glm::vec3& baseVector, QWidget* parent) :
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
5 QDialog{parent},
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
6 baseVector{baseVector},
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
7 preview{baseVector, parent, Vec3Editor::NoMultiplyButton}
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
8 {
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
9 ui = std::make_unique<Ui::MultiplyFactorDialog>();
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
10 ui->setupUi(this);
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
11 this->preview.setEnabled(false);
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
12 this->ui->previewGroupBox->setLayout(new QVBoxLayout{parent});
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
13 this->ui->previewGroupBox->layout()->addWidget(&this->preview);
115
ed884a2fb009 fix too long lines
Teemu Piippo <teemu@hecknology.net>
parents: 88
diff changeset
14 connect(
ed884a2fb009 fix too long lines
Teemu Piippo <teemu@hecknology.net>
parents: 88
diff changeset
15 this->ui->invert,
ed884a2fb009 fix too long lines
Teemu Piippo <teemu@hecknology.net>
parents: 88
diff changeset
16 &QCheckBox::clicked,
ed884a2fb009 fix too long lines
Teemu Piippo <teemu@hecknology.net>
parents: 88
diff changeset
17 this,
ed884a2fb009 fix too long lines
Teemu Piippo <teemu@hecknology.net>
parents: 88
diff changeset
18 &MultiplyFactorDialog::updatePreview);
ed884a2fb009 fix too long lines
Teemu Piippo <teemu@hecknology.net>
parents: 88
diff changeset
19 connect(
ed884a2fb009 fix too long lines
Teemu Piippo <teemu@hecknology.net>
parents: 88
diff changeset
20 this->ui->factor,
ed884a2fb009 fix too long lines
Teemu Piippo <teemu@hecknology.net>
parents: 88
diff changeset
21 qOverload<double>(&DoubleSpinBox::valueChanged),
ed884a2fb009 fix too long lines
Teemu Piippo <teemu@hecknology.net>
parents: 88
diff changeset
22 this,
ed884a2fb009 fix too long lines
Teemu Piippo <teemu@hecknology.net>
parents: 88
diff changeset
23 &MultiplyFactorDialog::updatePreview);
81
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
24 }
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
25
88
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
26 /**
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
27 * @brief empty destructor, necessary because std::unique_ptr is used with a forward declaration
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
28 */
81
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
29 MultiplyFactorDialog::~MultiplyFactorDialog()
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
30 {
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
31 }
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
32
88
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
33 /**
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
34 * @brief Computes the resulting vector
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
35 * @return the input vector multiplied by the specified vector
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
36 */
81
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
37 glm::vec3 MultiplyFactorDialog::value() const
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
38 {
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
39 glm::vec3 result = baseVector;
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
40 if (this->ui->invert->isChecked())
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
41 {
88
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
42 if (qFuzzyIsNull(this->ui->factor->value()))
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
43 {
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
44 constexpr double infinity = std::numeric_limits<double>::quiet_NaN();
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
45 result = {infinity, infinity, infinity};
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
46 }
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
47 else
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
48 {
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
49 result /= this->ui->factor->value();
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
50 }
81
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
51 }
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
52 else
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
53 {
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
54 result *= this->ui->factor->value();
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
55 }
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
56 return result;
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
57 }
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
58
88
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
59 /**
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
60 * @brief Makes a string that is prefixed to the factor input.
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
61 * @param ui
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
62 * @return prefix string
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
63 */
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
64 QString prefixForFactorInput(const Ui::MultiplyFactorDialog& ui)
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
65 {
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
66 if (ui.invert->isChecked())
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
67 {
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
68 return "1 : ";
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
69 }
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
70 else
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
71 {
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
72 return "";
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
73 }
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
74 }
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
75
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
76 /**
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
77 * @brief Makes a string that is suffixed to the factor input.
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
78 * @param ui
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
79 * @return prefix string
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
80 */
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
81 QString suffixForFactorInput(const Ui::MultiplyFactorDialog& ui)
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
82 {
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
83 if (ui.invert->isChecked())
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
84 {
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
85 // render the actual factor that stuff gets effectively multiplied by
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
86 return " = " + QString::number(1.0 / (ui.factor->value()));
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
87 }
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
88 else
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
89 {
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
90 return "";
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
91 }
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
92 }
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
93
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
94 /**
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
95 * @brief Responds to changes in the value and updates previews accordingly
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
96 */
81
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
97 void MultiplyFactorDialog::updatePreview()
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
98 {
88
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
99 this->ui->factor->setPrefix(::prefixForFactorInput(*this->ui));
14e51640c189 finetuning in multiplyfactordialog
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
100 this->ui->factor->setSuffix(::suffixForFactorInput(*this->ui));
81
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
101 this->preview.setValue(this->value());
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
102 }

mercurial