# HG changeset patch # User Teemu Piippo # Date 1521902003 -7200 # Node ID 1f342d5abc858726839a29e91a5b2d75791a3114 # Parent 1152c9fefa3e69c01d87e28175ddc3fac68d9cad Added support for 8-primitives diff -r 1152c9fefa3e -r 1f342d5abc85 src/dialogs/generateprimitivedialog.cpp --- a/src/dialogs/generateprimitivedialog.cpp Sat Mar 24 16:12:08 2018 +0200 +++ b/src/dialogs/generateprimitivedialog.cpp Sat Mar 24 16:33:23 2018 +0200 @@ -25,7 +25,24 @@ ui(*new Ui_GeneratePrimitiveDialog) { ui.setupUi (this); - connect (ui.highResolution, &QCheckBox::toggled, this, &GeneratePrimitiveDialog::highResolutionToggled); + this->previousDivisions = ui.divisions->currentText().toInt(); + connect( + ui.divisions, + &QComboBox::currentTextChanged, + [&]() + { + int divisions = ui.divisions->currentText().toInt(); + + // Scale the segments value to fit. + int newSegments = static_cast(round( + ui.segments->value() * double(divisions) / this->previousDivisions + )); + + ui.segments->setMaximum(divisions); + ui.segments->setValue(newSegments); + this->previousDivisions = divisions; + } + ); } @@ -35,17 +52,6 @@ } -void GeneratePrimitiveDialog::highResolutionToggled (bool on) -{ - ui.segments->setMaximum (on ? HighResolution : LowResolution); - - // If the current value is 16 and we switch to hi-res, default the - // spinbox to 48. (should we scale this?) - if (on and ui.segments->value() == LowResolution) - ui.segments->setValue(HighResolution); -} - - PrimitiveModel GeneratePrimitiveDialog::primitiveModel() const { PrimitiveModel result; @@ -56,7 +62,7 @@ ui.typeDiscNegative->isChecked() ? PrimitiveModel::DiscNegative : ui.typeRing->isChecked() ? PrimitiveModel::Ring : PrimitiveModel::Cone; - result.divisions = ui.highResolution->isChecked() ? HighResolution : LowResolution; + result.divisions = ui.divisions->currentText().toInt(); result.segments = ui.segments->value(); result.ringNumber = ui.ringNumber->value(); return result; diff -r 1152c9fefa3e -r 1f342d5abc85 src/dialogs/generateprimitivedialog.h --- a/src/dialogs/generateprimitivedialog.h Sat Mar 24 16:12:08 2018 +0200 +++ b/src/dialogs/generateprimitivedialog.h Sat Mar 24 16:33:23 2018 +0200 @@ -31,9 +31,7 @@ virtual ~GeneratePrimitiveDialog(); PrimitiveModel primitiveModel() const; -public slots: - void highResolutionToggled (bool on); - private: Ui_GeneratePrimitiveDialog& ui; + int previousDivisions = 0; }; diff -r 1152c9fefa3e -r 1f342d5abc85 src/dialogs/generateprimitivedialog.ui --- a/src/dialogs/generateprimitivedialog.ui Sat Mar 24 16:12:08 2018 +0200 +++ b/src/dialogs/generateprimitivedialog.ui Sat Mar 24 16:33:23 2018 +0200 @@ -6,8 +6,8 @@ 0 0 - 413 - 169 + 446 + 193 @@ -46,7 +46,7 @@ - Cylinder + C&ylinder @@ -60,7 +60,7 @@ - Disc Negative + Disc &Negative @@ -99,29 +99,25 @@ - - - High resolution (48) - - - - - - - - Segments: + + + + false - + Ring number: + + ringNumber + - + 1 @@ -134,10 +130,45 @@ - - - - false + + + + Segments: + + + segments + + + + + + + 1 + + + + 8 + + + + + 16 + + + + + 48 + + + + + + + + Di&visions: + + + divisions @@ -181,8 +212,8 @@ accept() - 254 - 140 + 263 + 183 157 @@ -197,8 +228,8 @@ reject() - 322 - 140 + 331 + 183 286 @@ -217,8 +248,8 @@ 41 - 305 - 86 + 433 + 131 @@ -233,8 +264,8 @@ 42 - 287 - 86 + 433 + 131 @@ -245,12 +276,12 @@ setDisabled(bool) - 49 - 66 + 77 + 97 - 287 - 87 + 433 + 131 @@ -261,12 +292,12 @@ setDisabled(bool) - 121 - 58 + 221 + 97 - 288 - 83 + 433 + 131 @@ -277,12 +308,12 @@ setEnabled(bool) - 45 - 90 + 73 + 131 - 301 - 86 + 433 + 131 @@ -293,12 +324,12 @@ setEnabled(bool) - 111 - 89 + 217 + 131 - 302 - 85 + 433 + 131 diff -r 1152c9fefa3e -r 1f342d5abc85 src/editmodes/circleMode.cpp --- a/src/editmodes/circleMode.cpp Sat Mar 24 16:12:08 2018 +0200 +++ b/src/editmodes/circleMode.cpp Sat Mar 24 16:33:23 2018 +0200 @@ -66,7 +66,7 @@ Model model {m_documents}; PrimitiveModel primitiveModel; primitiveModel.segments = m_window->ringToolSegments(); - primitiveModel.divisions = m_window->ringToolHiRes() ? HighResolution : LowResolution; + primitiveModel.divisions = m_window->ringToolDivisions(); primitiveModel.ringNumber = 0; double dist0 (getCircleDrawDist (0)); double dist1 (getCircleDrawDist (1)); @@ -160,7 +160,7 @@ { if (not m_drawedVerts.isEmpty()) { - int divisions = m_window->ringToolHiRes() ? HighResolution : LowResolution; + int divisions = m_window->ringToolDivisions(); QPointF originSpot = renderer()->currentCamera().convert3dTo2d(m_drawedVerts.first()); // Line from the origin of the circle to current mouse position QLineF hand1 = {originSpot, renderer()->mousePositionF()}; @@ -196,7 +196,7 @@ QVector innerverts2d, outerverts2d; double innerdistance = getCircleDrawDist(0); double outerdistance = countof(m_drawedVerts) >= 2 ? getCircleDrawDist (1) : -1; - int divisions = m_window->ringToolHiRes() ? HighResolution : LowResolution; + int divisions = m_window->ringToolDivisions(); int segments = m_window->ringToolSegments(); double angleUnit = 2 * pi / divisions; Axis relX, relY; diff -r 1152c9fefa3e -r 1f342d5abc85 src/grid.cpp --- a/src/grid.cpp Sat Mar 24 16:12:08 2018 +0200 +++ b/src/grid.cpp Sat Mar 24 16:33:23 2018 +0200 @@ -108,8 +108,10 @@ { default: case Coarse: + return LowResolution; + case Medium: - return LowResolution; + return MediumResolution; case Fine: return HighResolution; diff -r 1152c9fefa3e -r 1f342d5abc85 src/linetypes/modelobject.h --- a/src/linetypes/modelobject.h Sat Mar 24 16:12:08 2018 +0200 +++ b/src/linetypes/modelobject.h Sat Mar 24 16:33:23 2018 +0200 @@ -219,7 +219,8 @@ enum { - LowResolution = 16, + LowResolution = 8, + MediumResolution = 16, HighResolution = 48 }; diff -r 1152c9fefa3e -r 1f342d5abc85 src/mainwindow.cpp --- a/src/mainwindow.cpp Sat Mar 24 16:12:08 2018 +0200 +++ b/src/mainwindow.cpp Sat Mar 24 16:33:23 2018 +0200 @@ -98,8 +98,8 @@ updateTitle(); loadShortcuts(); setMinimumSize (300, 200); - connect (ui.ringToolHiRes, SIGNAL (clicked (bool)), this, SLOT (ringToolHiResClicked (bool))); - connect (ui.ringToolSegments, SIGNAL (valueChanged (int)), this, SLOT (circleToolSegmentsChanged())); + connect(ui.ringToolDivisions, SIGNAL(currentTextChanged(QString)), this, SLOT(ringToolDivisionsChanged())); + connect(ui.ringToolSegments, SIGNAL(valueChanged(int)), this, SLOT(circleToolSegmentsChanged())); circleToolSegmentsChanged(); // invoke it manually for initial label text // Examine the toolsets and make a dictionary of tools @@ -798,11 +798,9 @@ return m_defaultShortcuts[act]; } -// --------------------------------------------------------------------------------------------------------------------- -// -bool MainWindow::ringToolHiRes() const +int MainWindow::ringToolDivisions() const { - return ui.ringToolHiRes->isChecked(); + return ui.ringToolDivisions->currentText().toInt(); } // --------------------------------------------------------------------------------------------------------------------- @@ -814,26 +812,25 @@ // --------------------------------------------------------------------------------------------------------------------- // -void MainWindow::ringToolHiResClicked (bool checked) +void MainWindow::ringToolDivisionsChanged() { - if (checked) - { - ui.ringToolSegments->setMaximum (HighResolution); - ui.ringToolSegments->setValue (ui.ringToolSegments->value() * 3); - } - else - { - ui.ringToolSegments->setValue (ui.ringToolSegments->value() / 3); - ui.ringToolSegments->setMaximum (LowResolution); - } + // Scale the segments value to fit. + int divisions = this->ringToolDivisions(); + int newSegments = static_cast(round( + this->ringToolSegments() * double(divisions) / this->previousDivisions + )); + this->ui.ringToolSegments->setMaximum(divisions); + this->ui.ringToolSegments->setValue(newSegments); + this->previousDivisions = divisions; + this->renderer()->update(); } // --------------------------------------------------------------------------------------------------------------------- // void MainWindow::circleToolSegmentsChanged() { - int numerator (ui.ringToolSegments->value()); - int denominator (ui.ringToolHiRes->isChecked() ? HighResolution : LowResolution); + int numerator = this->ringToolSegments(); + int denominator = this->ringToolDivisions(); simplify (numerator, denominator); ui.ringToolSegmentsLabel->setText (format ("%1 / %2", numerator, denominator)); } diff -r 1152c9fefa3e -r 1f342d5abc85 src/mainwindow.h --- a/src/mainwindow.h Sat Mar 24 16:12:08 2018 +0200 +++ b/src/mainwindow.h Sat Mar 24 16:33:23 2018 +0200 @@ -90,7 +90,7 @@ Canvas* renderer(); void refresh(); void replaceSelection(const QItemSelection& selection); - bool ringToolHiRes() const; + int ringToolDivisions() const; int ringToolSegments() const; bool save (LDDocument* doc, bool saveAs); void saveShortcuts(); @@ -125,7 +125,7 @@ void circleToolSegmentsChanged(); void closeTab (int tabindex); void historyTraversed(); - void ringToolHiResClicked (bool clicked); + void ringToolDivisionsChanged(); void tabSelected(); void documentClosed(LDDocument* document); void updateTitle(); @@ -154,6 +154,7 @@ DocumentManager* m_documents; LDDocument* m_currentDocument; QMap m_defaultShortcuts; + int previousDivisions = MediumResolution; private slots: void finishInitialization(); diff -r 1152c9fefa3e -r 1f342d5abc85 src/mainwindow.ui --- a/src/mainwindow.ui Sat Mar 24 16:12:08 2018 +0200 +++ b/src/mainwindow.ui Sat Mar 24 16:33:23 2018 +0200 @@ -40,7 +40,7 @@ - 0 + 2 @@ -48,7 +48,7 @@ 0 0 465 - 387 + 362 @@ -65,8 +65,8 @@ 0 0 - 98 - 93 + 465 + 362 @@ -93,8 +93,8 @@ 0 0 - 277 - 121 + 465 + 362 @@ -109,10 +109,10 @@ - - + + - High resolution + Divisions: @@ -150,6 +150,28 @@ + + + + 1 + + + + 8 + + + + + 16 + + + + + 48 + + + + @@ -175,8 +197,8 @@ 0 0 - 98 - 93 + 465 + 362 @@ -210,7 +232,7 @@ 0 0 1010 - 26 + 31 @@ -1726,7 +1748,7 @@ - Fix rounding errors + Fi&x rounding errors @@ -1740,6 +1762,7 @@ + diff -r 1152c9fefa3e -r 1f342d5abc85 src/primitives.cpp --- a/src/primitives.cpp Sat Mar 24 16:12:08 2018 +0200 +++ b/src/primitives.cpp Sat Mar 24 16:33:23 2018 +0200 @@ -434,7 +434,7 @@ } // Compose some general information: prefix, fraction, root, ring number - QString prefix = (divisions == LowResolution) ? "" : format ("%1/", divisions); + QString prefix = (divisions == MediumResolution) ? "" : format ("%1\\", divisions); QString frac = format ("%1-%2", numerator, denominator); static const char* roots[] = {"edge", "cyli", "disc", "ndis", "ring", "con"}; QString root = roots[type];