50 |
50 |
51 // --------------------------------------------------------------------------------------------------------------------- |
51 // --------------------------------------------------------------------------------------------------------------------- |
52 // |
52 // |
53 MainWindow::MainWindow(QWidget* parent, Qt::WindowFlags flags) : |
53 MainWindow::MainWindow(QWidget* parent, Qt::WindowFlags flags) : |
54 QMainWindow (parent, flags), |
54 QMainWindow (parent, flags), |
55 m_config(*::config), |
|
56 m_guiUtilities (new GuiUtilities (this)), |
55 m_guiUtilities (new GuiUtilities (this)), |
57 m_primitives(new PrimitiveManager(this)), |
56 m_primitives(new PrimitiveManager(this)), |
58 m_grid(new Grid(this)), |
57 m_grid(new Grid(this)), |
59 m_mathFunctions(new MathFunctions(this)), |
58 m_mathFunctions(new MathFunctions(this)), |
60 ui (*new Ui_MainWindow), |
59 ui (*new Ui_MainWindow), |
61 m_externalPrograms (nullptr), |
60 m_externalPrograms (nullptr), |
62 m_settings (makeSettings (this)), |
|
63 m_documents (new DocumentManager (this)), |
61 m_documents (new DocumentManager (this)), |
64 m_currentDocument (nullptr) |
62 m_currentDocument (nullptr) |
65 { |
63 { |
66 m_messageLog = new MessageManager {this}; |
64 m_messageLog = new MessageManager {this}; |
67 ui.setupUi (this); |
65 ui.setupUi (this); |
139 else |
137 else |
140 m_toolmap[action] = info; |
138 m_toolmap[action] = info; |
141 } |
139 } |
142 } |
140 } |
143 |
141 |
144 for (QVariant const& toolbarname : m_config.hiddenToolbars()) |
142 for (QVariant const& toolbarname : config::hiddenToolbars()) |
145 { |
143 { |
146 QToolBar* toolbar = findChild<QToolBar*> (toolbarname.toString()); |
144 QToolBar* toolbar = findChild<QToolBar*> (toolbarname.toString()); |
147 |
145 |
148 if (toolbar) |
146 if (toolbar) |
149 toolbar->hide(); |
147 toolbar->hide(); |
150 } |
148 } |
151 |
149 |
152 // If this is the first start, get the user to configuration. Especially point |
150 // If this is the first start, get the user to configuration. Especially point |
153 // them to the profile tab, it's the most important form to fill in. |
151 // them to the profile tab, it's the most important form to fill in. |
154 if (m_config.firstStart()) |
152 if (config::firstStart()) |
155 { |
153 { |
156 ConfigDialog* dialog = new ConfigDialog (this, ConfigDialog::ProfileTab); |
154 ConfigDialog* dialog = new ConfigDialog (this, ConfigDialog::ProfileTab); |
157 dialog->show(); |
155 dialog->show(); |
158 m_config.setFirstStart (false); |
156 config::setFirstStart (false); |
159 } |
157 } |
160 |
158 |
161 QMetaObject::invokeMethod (this, "finishInitialization", Qt::QueuedConnection); |
159 QMetaObject::invokeMethod (this, "finishInitialization", Qt::QueuedConnection); |
162 } |
160 } |
163 |
161 |
220 |
217 |
221 m_recentFiles.clear(); |
218 m_recentFiles.clear(); |
222 |
219 |
223 QAction* first = nullptr; |
220 QAction* first = nullptr; |
224 |
221 |
225 for (const QVariant& it : m_config.recentFiles()) |
222 for (const QVariant& it : config::recentFiles()) |
226 { |
223 { |
227 QString file = it.toString(); |
224 QString file = it.toString(); |
228 QAction* recent = new QAction (getIcon ("open-recent"), file, this); |
225 QAction* recent = new QAction (getIcon ("open-recent"), file, this); |
229 connect (recent, SIGNAL (triggered()), this, SLOT (recentFileClicked())); |
226 connect (recent, SIGNAL (triggered()), this, SLOT (recentFileClicked())); |
230 ui.menuOpenRecent->insertAction (first, recent); |
227 ui.menuOpenRecent->insertAction (first, recent); |
269 // --------------------------------------------------------------------------------------------------------------------- |
266 // --------------------------------------------------------------------------------------------------------------------- |
270 // |
267 // |
271 void MainWindow::updateGridToolBar() |
268 void MainWindow::updateGridToolBar() |
272 { |
269 { |
273 // Ensure that the current grid - and only the current grid - is selected. |
270 // Ensure that the current grid - and only the current grid - is selected. |
274 int grid = m_config.grid(); |
271 int grid = config::grid(); |
275 ui.actionGridCoarse->setChecked (grid == Grid::Coarse); |
272 ui.actionGridCoarse->setChecked (grid == Grid::Coarse); |
276 ui.actionGridMedium->setChecked (grid == Grid::Medium); |
273 ui.actionGridMedium->setChecked (grid == Grid::Medium); |
277 ui.actionGridFine->setChecked (grid == Grid::Fine); |
274 ui.actionGridFine->setChecked (grid == Grid::Fine); |
278 ui.actionPolarGrid->setChecked(m_grid->type() == Grid::Polar); |
275 ui.actionPolarGrid->setChecked(m_grid->type() == Grid::Polar); |
279 emit gridChanged(); |
276 emit gridChanged(); |
441 if (toolbar->isHidden()) |
438 if (toolbar->isHidden()) |
442 hiddenToolbars << toolbar->objectName(); |
439 hiddenToolbars << toolbar->objectName(); |
443 } |
440 } |
444 |
441 |
445 // Save the configuration before leaving. |
442 // Save the configuration before leaving. |
446 m_config.setHiddenToolbars (hiddenToolbars); |
443 config::setHiddenToolbars (hiddenToolbars); |
447 syncSettings(); |
444 settingsObject().sync(); |
448 ev->accept(); |
445 ev->accept(); |
449 } |
446 } |
450 |
447 |
451 // --------------------------------------------------------------------------------------------------------------------- |
448 // --------------------------------------------------------------------------------------------------------------------- |
452 // |
449 // |
720 int pos = his->position(); |
717 int pos = his->position(); |
721 ui.actionUndo->setEnabled (pos != -1); |
718 ui.actionUndo->setEnabled (pos != -1); |
722 ui.actionRedo->setEnabled (pos < (long) his->size() - 1); |
719 ui.actionRedo->setEnabled (pos < (long) his->size() - 1); |
723 } |
720 } |
724 |
721 |
725 ui.actionWireframe->setChecked (m_config.drawWireframe()); |
722 ui.actionWireframe->setChecked (config::drawWireframe()); |
726 ui.actionAxes->setChecked (m_config.drawAxes()); |
723 ui.actionAxes->setChecked (config::drawAxes()); |
727 ui.actionBfcView->setChecked (m_config.bfcRedGreenView()); |
724 ui.actionBfcView->setChecked (config::bfcRedGreenView()); |
728 ui.actionRandomColors->setChecked (m_config.randomColors()); |
725 ui.actionRandomColors->setChecked (config::randomColors()); |
729 ui.actionDrawAngles->setChecked (m_config.drawAngles()); |
726 ui.actionDrawAngles->setChecked (config::drawAngles()); |
730 ui.actionDrawSurfaces->setChecked (m_config.drawSurfaces()); |
727 ui.actionDrawSurfaces->setChecked (config::drawSurfaces()); |
731 ui.actionDrawEdgeLines->setChecked (m_config.drawEdgeLines()); |
728 ui.actionDrawEdgeLines->setChecked (config::drawEdgeLines()); |
732 ui.actionDrawConditionalLines->setChecked (m_config.drawConditionalLines()); |
729 ui.actionDrawConditionalLines->setChecked (config::drawConditionalLines()); |
733 ui.actionLighting->setChecked(m_config.lighting()); |
730 ui.actionLighting->setChecked(config::lighting()); |
734 } |
731 } |
735 |
732 |
736 // --------------------------------------------------------------------------------------------------------------------- |
733 // --------------------------------------------------------------------------------------------------------------------- |
737 // |
734 // |
738 PrimitiveManager* MainWindow::primitives() |
735 PrimitiveManager* MainWindow::primitives() |
777 // |
774 // |
778 void MainWindow::loadShortcuts() |
775 void MainWindow::loadShortcuts() |
779 { |
776 { |
780 for (QAction* act : findChildren<QAction*>()) |
777 for (QAction* act : findChildren<QAction*>()) |
781 { |
778 { |
782 QKeySequence seq = m_settings->value ("shortcut_" + act->objectName(), act->shortcut()).value<QKeySequence>(); |
779 QKeySequence seq = settingsObject().value("shortcut_" + act->objectName(), act->shortcut()).value<QKeySequence>(); |
783 act->setShortcut (seq); |
780 act->setShortcut (seq); |
784 } |
781 } |
785 } |
782 } |
786 |
783 |
787 // --------------------------------------------------------------------------------------------------------------------- |
784 // --------------------------------------------------------------------------------------------------------------------- |
791 applyToActions ([&](QAction* act) |
788 applyToActions ([&](QAction* act) |
792 { |
789 { |
793 QString const key = "shortcut_" + act->objectName(); |
790 QString const key = "shortcut_" + act->objectName(); |
794 |
791 |
795 if (m_defaultShortcuts[act] != act->shortcut()) |
792 if (m_defaultShortcuts[act] != act->shortcut()) |
796 m_settings->setValue (key, act->shortcut()); |
793 settingsObject().setValue(key, act->shortcut()); |
797 else |
794 else |
798 m_settings->remove (key); |
795 settingsObject().remove(key); |
799 }); |
796 }); |
800 } |
797 } |
801 |
798 |
802 // --------------------------------------------------------------------------------------------------------------------- |
799 // --------------------------------------------------------------------------------------------------------------------- |
803 // |
800 // |
853 { |
850 { |
854 int numerator (ui.ringToolSegments->value()); |
851 int numerator (ui.ringToolSegments->value()); |
855 int denominator (ui.ringToolHiRes->isChecked() ? HighResolution : LowResolution); |
852 int denominator (ui.ringToolHiRes->isChecked() ? HighResolution : LowResolution); |
856 simplify (numerator, denominator); |
853 simplify (numerator, denominator); |
857 ui.ringToolSegmentsLabel->setText (format ("%1 / %2", numerator, denominator)); |
854 ui.ringToolSegmentsLabel->setText (format ("%1 / %2", numerator, denominator)); |
858 } |
|
859 |
|
860 /* |
|
861 * Returns a settings object that interfaces the ini file. |
|
862 */ |
|
863 QSettings* MainWindow::makeSettings(QObject* parent) |
|
864 { |
|
865 QString path = qApp->applicationDirPath() + "/" UNIXNAME ".ini"; |
|
866 return new QSettings {path, QSettings::IniFormat, parent}; |
|
867 } |
|
868 |
|
869 // --------------------------------------------------------------------------------------------------------------------- |
|
870 // |
|
871 void MainWindow::syncSettings() |
|
872 { |
|
873 m_settings->sync(); |
|
874 } |
|
875 |
|
876 // --------------------------------------------------------------------------------------------------------------------- |
|
877 // |
|
878 QVariant MainWindow::getConfigValue (QString name) |
|
879 { |
|
880 QVariant value = m_settings->value (name, m_config.defaultValueByName (name)); |
|
881 return value; |
|
882 } |
855 } |
883 |
856 |
884 // --------------------------------------------------------------------------------------------------------------------- |
857 // --------------------------------------------------------------------------------------------------------------------- |
885 // |
858 // |
886 void MainWindow::createBlankDocument() |
859 void MainWindow::createBlankDocument() |