src/ui/circletooloptionswidget.cpp

Tue, 28 Jun 2022 19:21:37 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Tue, 28 Jun 2022 19:21:37 +0300
changeset 293
9f85a54ead29
parent 264
76a025db4948
child 379
8d88adffb779
permissions
-rw-r--r--

Add OpenGL information to about page

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: 250
diff changeset
1 #include "src/ui/circletooloptionswidget.h"
233
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
2
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
3 static QString circularPrimitiveTypeName(CircularPrimitive::Type type)
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
4 {
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
5 switch (type) {
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
6 case CircularPrimitive::Circle:
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
7 return CircleToolOptionsWidget::tr("Circle");
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
8 case CircularPrimitive::Disc:
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
9 return CircleToolOptionsWidget::tr("Disc");
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
10 case CircularPrimitive::Cylinder:
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
11 return CircleToolOptionsWidget::tr("Cylinder");
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
12 case CircularPrimitive::CylinderOpen:
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
13 return CircleToolOptionsWidget::tr("Cylinder open");
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
14 case CircularPrimitive::CylinderClosed:
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
15 return CircleToolOptionsWidget::tr("Cylinder closed");
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
16 case CircularPrimitive::DiscNegative:
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
17 return CircleToolOptionsWidget::tr("Disc negative");
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
18 case CircularPrimitive::Chord:
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
19 return CircleToolOptionsWidget::tr("Chord");
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
20 }
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
21 return "";
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
22 }
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
23
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
24 CircleToolOptionsWidget::CircleToolOptionsWidget(QWidget *parent) :
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
25 QWidget{parent}
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
26 {
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
27 this->ui.setupUi(this);
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
28 for (int i = 0; i < CircularPrimitive::NUM_TYPES; ++i) {
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
29 const auto type = static_cast<CircularPrimitive::Type>(i);
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
30 this->ui.type->addItem(circularPrimitiveTypeName(type), type);
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
31 }
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
32 connect(ui.segments, qOverload<int>(&QSpinBox::valueChanged), this, &CircleToolOptionsWidget::handleInputChange);
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
33 connect(ui.divisions, &QComboBox::currentTextChanged, this, &CircleToolOptionsWidget::handleInputChange);
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
34 connect(ui.type, &QComboBox::currentTextChanged, this, &CircleToolOptionsWidget::handleInputChange);
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
35 }
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
36
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
37 CircleToolOptionsWidget::~CircleToolOptionsWidget()
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
38 {
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
39 }
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
40
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
41 unsigned int CircleToolOptionsWidget::segments() const
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
42 {
250
2837b549e616 I felt that the compiler was too kind to me, so I enabled a big pile of warnings
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 233
diff changeset
43 return unsigned_cast(this->ui.segments->value());
233
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
44 }
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
45
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
46 unsigned int CircleToolOptionsWidget::divisions() const
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
47 {
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
48 bool ok;
250
2837b549e616 I felt that the compiler was too kind to me, so I enabled a big pile of warnings
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 233
diff changeset
49 const unsigned int divs = this->ui.divisions->currentText().toUInt(&ok);
233
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
50 if (ok) {
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
51 return divs;
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
52 }
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
53 else {
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
54 return 16;
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
55 }
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
56 }
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
57
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
58 CircularPrimitive::Type CircleToolOptionsWidget::type() const
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
59 {
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
60 return this->ui.type->currentData().value<CircularPrimitive::Type>();
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
61 }
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
62
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
63 void CircleToolOptionsWidget::handleInputChange()
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
64 {
250
2837b549e616 I felt that the compiler was too kind to me, so I enabled a big pile of warnings
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 233
diff changeset
65 const unsigned int olddivs = unsigned_cast(this->ui.segments->maximum());
2837b549e616 I felt that the compiler was too kind to me, so I enabled a big pile of warnings
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 233
diff changeset
66 const unsigned int newdivs = this->divisions();
233
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
67 if (olddivs != newdivs) {
250
2837b549e616 I felt that the compiler was too kind to me, so I enabled a big pile of warnings
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 233
diff changeset
68 this->ui.segments->setMaximum(signed_cast(newdivs));
2837b549e616 I felt that the compiler was too kind to me, so I enabled a big pile of warnings
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 233
diff changeset
69 this->ui.segments->setValue(signed_cast(this->segments() * newdivs / olddivs));
233
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
70 }
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
71 const qreal ratio = static_cast<qreal>(this->segments()) / newdivs;
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
72 this->ui.ratio->setText(QString::number(ratio, 'g', 4));
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
73 Q_EMIT this->optionsChanged(CircleToolOptions{
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
74 .fraction = CircularFraction{this->segments(), this->divisions()},
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
75 .type = this->type(),
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
76 });
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
77 }

mercurial