Sat, 24 Mar 2018 16:33:23 +0200
Added support for 8-primitives
--- 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<int>(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;
--- 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; };
--- 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 @@ <rect> <x>0</x> <y>0</y> - <width>413</width> - <height>169</height> + <width>446</width> + <height>193</height> </rect> </property> <property name="windowTitle"> @@ -46,7 +46,7 @@ <item row="1" column="1"> <widget class="QRadioButton" name="typeCylinder"> <property name="text"> - <string>Cylinder</string> + <string>C&ylinder</string> </property> </widget> </item> @@ -60,7 +60,7 @@ <item row="2" column="1"> <widget class="QRadioButton" name="typeDiscNegative"> <property name="text"> - <string>Disc Negative</string> + <string>Disc &Negative</string> </property> </widget> </item> @@ -99,29 +99,25 @@ </spacer> </item> <item> - <widget class="QCheckBox" name="highResolution"> - <property name="text"> - <string>High resolution (48)</string> - </property> - </widget> - </item> - <item> <layout class="QGridLayout" name="gridLayout_2"> - <item row="0" column="0"> - <widget class="QLabel" name="label"> - <property name="text"> - <string>Segments:</string> + <item row="2" column="1"> + <widget class="QSpinBox" name="ringNumber"> + <property name="enabled"> + <bool>false</bool> </property> </widget> </item> - <item row="1" column="0"> + <item row="2" column="0"> <widget class="QLabel" name="label_2"> <property name="text"> <string>Ring number:</string> </property> + <property name="buddy"> + <cstring>ringNumber</cstring> + </property> </widget> </item> - <item row="0" column="1"> + <item row="1" column="1"> <widget class="QSpinBox" name="segments"> <property name="minimum"> <number>1</number> @@ -134,10 +130,45 @@ </property> </widget> </item> - <item row="1" column="1"> - <widget class="QSpinBox" name="ringNumber"> - <property name="enabled"> - <bool>false</bool> + <item row="1" column="0"> + <widget class="QLabel" name="label"> + <property name="text"> + <string>Segments:</string> + </property> + <property name="buddy"> + <cstring>segments</cstring> + </property> + </widget> + </item> + <item row="0" column="1"> + <widget class="QComboBox" name="divisions"> + <property name="currentIndex"> + <number>1</number> + </property> + <item> + <property name="text"> + <string>8</string> + </property> + </item> + <item> + <property name="text"> + <string>16</string> + </property> + </item> + <item> + <property name="text"> + <string>48</string> + </property> + </item> + </widget> + </item> + <item row="0" column="0"> + <widget class="QLabel" name="label_3"> + <property name="text"> + <string>Di&visions:</string> + </property> + <property name="buddy"> + <cstring>divisions</cstring> </property> </widget> </item> @@ -181,8 +212,8 @@ <slot>accept()</slot> <hints> <hint type="sourcelabel"> - <x>254</x> - <y>140</y> + <x>263</x> + <y>183</y> </hint> <hint type="destinationlabel"> <x>157</x> @@ -197,8 +228,8 @@ <slot>reject()</slot> <hints> <hint type="sourcelabel"> - <x>322</x> - <y>140</y> + <x>331</x> + <y>183</y> </hint> <hint type="destinationlabel"> <x>286</x> @@ -217,8 +248,8 @@ <y>41</y> </hint> <hint type="destinationlabel"> - <x>305</x> - <y>86</y> + <x>433</x> + <y>131</y> </hint> </hints> </connection> @@ -233,8 +264,8 @@ <y>42</y> </hint> <hint type="destinationlabel"> - <x>287</x> - <y>86</y> + <x>433</x> + <y>131</y> </hint> </hints> </connection> @@ -245,12 +276,12 @@ <slot>setDisabled(bool)</slot> <hints> <hint type="sourcelabel"> - <x>49</x> - <y>66</y> + <x>77</x> + <y>97</y> </hint> <hint type="destinationlabel"> - <x>287</x> - <y>87</y> + <x>433</x> + <y>131</y> </hint> </hints> </connection> @@ -261,12 +292,12 @@ <slot>setDisabled(bool)</slot> <hints> <hint type="sourcelabel"> - <x>121</x> - <y>58</y> + <x>221</x> + <y>97</y> </hint> <hint type="destinationlabel"> - <x>288</x> - <y>83</y> + <x>433</x> + <y>131</y> </hint> </hints> </connection> @@ -277,12 +308,12 @@ <slot>setEnabled(bool)</slot> <hints> <hint type="sourcelabel"> - <x>45</x> - <y>90</y> + <x>73</x> + <y>131</y> </hint> <hint type="destinationlabel"> - <x>301</x> - <y>86</y> + <x>433</x> + <y>131</y> </hint> </hints> </connection> @@ -293,12 +324,12 @@ <slot>setEnabled(bool)</slot> <hints> <hint type="sourcelabel"> - <x>111</x> - <y>89</y> + <x>217</x> + <y>131</y> </hint> <hint type="destinationlabel"> - <x>302</x> - <y>85</y> + <x>433</x> + <y>131</y> </hint> </hints> </connection>
--- 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<QPointF> 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;
--- 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;
--- 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 };
--- 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<int>(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)); }
--- 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<QAction*, QKeySequence> m_defaultShortcuts; + int previousDivisions = MediumResolution; private slots: void finishInitialization();
--- 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 @@ <item> <widget class="QToolBox" name="toolBox"> <property name="currentIndex"> - <number>0</number> + <number>2</number> </property> <widget class="QWidget" name="page"> <property name="geometry"> @@ -48,7 +48,7 @@ <x>0</x> <y>0</y> <width>465</width> - <height>387</height> + <height>362</height> </rect> </property> <attribute name="label"> @@ -65,8 +65,8 @@ <rect> <x>0</x> <y>0</y> - <width>98</width> - <height>93</height> + <width>465</width> + <height>362</height> </rect> </property> <attribute name="label"> @@ -93,8 +93,8 @@ <rect> <x>0</x> <y>0</y> - <width>277</width> - <height>121</height> + <width>465</width> + <height>362</height> </rect> </property> <attribute name="label"> @@ -109,10 +109,10 @@ <layout class="QVBoxLayout" name="verticalLayout_5"> <item> <layout class="QFormLayout" name="formLayout"> - <item row="0" column="1"> - <widget class="QCheckBox" name="ringToolHiRes"> + <item row="0" column="0"> + <widget class="QLabel" name="label_2"> <property name="text"> - <string>High resolution</string> + <string>Divisions:</string> </property> </widget> </item> @@ -150,6 +150,28 @@ </item> </layout> </item> + <item row="0" column="1"> + <widget class="QComboBox" name="ringToolDivisions"> + <property name="currentIndex"> + <number>1</number> + </property> + <item> + <property name="text"> + <string>8</string> + </property> + </item> + <item> + <property name="text"> + <string>16</string> + </property> + </item> + <item> + <property name="text"> + <string>48</string> + </property> + </item> + </widget> + </item> </layout> </item> </layout> @@ -175,8 +197,8 @@ <rect> <x>0</x> <y>0</y> - <width>98</width> - <height>93</height> + <width>465</width> + <height>362</height> </rect> </property> <attribute name="label"> @@ -210,7 +232,7 @@ <x>0</x> <y>0</y> <width>1010</width> - <height>26</height> + <height>31</height> </rect> </property> <widget class="QMenu" name="menuFile"> @@ -1726,7 +1748,7 @@ </action> <action name="actionFixRoundingErrors"> <property name="text"> - <string>Fix rounding errors</string> + <string>Fi&x rounding errors</string> </property> </action> </widget> @@ -1740,6 +1762,7 @@ </customwidgets> <resources> <include location="../ldforge.qrc"/> + <include location="../ldforge.qrc"/> </resources> <connections/> </ui>
--- 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];