src/main.cpp

changeset 218
63125c36de73
parent 217
6d95c1a41e6e
child 221
e28f89b8ccdf
equal deleted inserted replaced
217:6d95c1a41e6e 218:63125c36de73
11 #include "gl/gridprogram.h" 11 #include "gl/gridprogram.h"
12 #include "gl/partrenderer.h" 12 #include "gl/partrenderer.h"
13 #include "document.h" 13 #include "document.h"
14 #include "settingseditor/settingseditor.h" 14 #include "settingseditor/settingseditor.h"
15 #include "widgets/colorselectdialog.h" 15 #include "widgets/colorselectdialog.h"
16 #include "settings.h"
16 17
17 static const QDir LOCALE_DIR {":/locale"}; 18 static const QDir LOCALE_DIR {":/locale"};
18 19
19 class ModelSubWindow : public QMdiSubWindow 20 class ModelSubWindow : public QMdiSubWindow
20 { 21 {
52 QCoreApplication::setApplicationName(::appName); 53 QCoreApplication::setApplicationName(::appName);
53 QCoreApplication::setOrganizationName("hecknology.net"); 54 QCoreApplication::setOrganizationName("hecknology.net");
54 QCoreApplication::setOrganizationDomain("hecknology.net"); 55 QCoreApplication::setOrganizationDomain("hecknology.net");
55 qRegisterMetaTypeStreamOperators<Library>("Library"); 56 qRegisterMetaTypeStreamOperators<Library>("Library");
56 qRegisterMetaTypeStreamOperators<Libraries>("Libraries"); 57 qRegisterMetaTypeStreamOperators<Libraries>("Libraries");
58 qRegisterMetaTypeStreamOperators<gl::RenderStyle>();
59 qRegisterMetaTypeStreamOperators<QMdiArea::ViewMode>();
57 } 60 }
58 61
59 template<typename BaseType, typename MemberType, typename DataType> 62 template<typename BaseType, typename MemberType, typename DataType>
60 struct MemberData 63 struct MemberData
61 { 64 {
249 action->setChecked(renderPreferences->style == data.payload); 252 action->setChecked(renderPreferences->style == data.payload);
250 } 253 }
251 ui->actionDrawAxes->setChecked(renderPreferences->drawAxes); 254 ui->actionDrawAxes->setChecked(renderPreferences->drawAxes);
252 }; 255 };
253 256
254 static gl::RenderPreferences loadRenderPreferences(Configuration* settings) 257 static gl::RenderPreferences loadRenderPreferences()
255 { 258 {
256 return gl::RenderPreferences{ 259 return gl::RenderPreferences{
257 .style = static_cast<gl::RenderStyle>(settings->renderStyle()), 260 .style = setting<Setting::RenderStyle>(),
258 .mainColor = settings->mainColor(), 261 .mainColor = setting<Setting::MainColor>(),
259 .backgroundColor = settings->backgroundColor(), 262 .backgroundColor = setting<Setting::BackgroundColor>(),
260 .selectedColor = settings->selectedColor(), 263 .selectedColor = setting<Setting::SelectedColor>(),
261 .lineThickness = settings->lineThickness(), 264 .lineThickness = setting<Setting::LineThickness>(),
262 .lineAntiAliasing = settings->lineAntiAliasing(), 265 .lineAntiAliasing = setting<Setting::LineAntiAliasing>(),
263 .drawAxes = settings->drawAxes(), 266 .drawAxes = setting<Setting::DrawAxes>(),
264 }; 267 };
265 } 268 }
266 269
267 void initializeTools(Ui_MainWindow* ui, QWidget* parent) 270 void initializeTools(Ui_MainWindow* ui, QWidget* parent)
268 { 271 {
325 QMainWindow mainWindow; 328 QMainWindow mainWindow;
326 Ui_MainWindow ui; 329 Ui_MainWindow ui;
327 DocumentManager documents; 330 DocumentManager documents;
328 QString currentLanguage = "en"; 331 QString currentLanguage = "en";
329 QTranslator translator{&mainWindow}; 332 QTranslator translator{&mainWindow};
330 Configuration settings;
331 LibraryManager libraries{&mainWindow}; 333 LibraryManager libraries{&mainWindow};
332 QByteArray documentSplitterState;
333 QStringList recentlyOpenedFiles; 334 QStringList recentlyOpenedFiles;
334 ColorTable colorTable; 335 ColorTable colorTable;
335 gl::RenderPreferences renderPreferences; 336 gl::RenderPreferences renderPreferences;
336 ui.setupUi(&mainWindow); 337 ui.setupUi(&mainWindow);
337 const uiutilities::KeySequenceMap defaultKeyboardShortcuts = 338 const uiutilities::KeySequenceMap defaultKeyboardShortcuts =
338 uiutilities::makeKeySequenceMap(uiutilities::collectActions(&mainWindow)); 339 uiutilities::makeKeySequenceMap(uiutilities::collectActions(&mainWindow));
339 const auto saveSettings = [&]{ 340 const auto saveSettings = [&]{
340 settings.setMainWindowGeometry(mainWindow.saveGeometry()); 341 setSetting<Setting::MainWindowGeometry>(mainWindow.saveGeometry());
341 settings.setRecentFiles(recentlyOpenedFiles); 342 setSetting<Setting::RecentFiles>(recentlyOpenedFiles);
342 settings.setMainSplitterState(documentSplitterState); 343 setSetting<Setting::RenderStyle>(renderPreferences.style);
343 settings.setRenderStyle(static_cast<int>(renderPreferences.style)); 344 setSetting<Setting::DrawAxes>(renderPreferences.drawAxes);
344 settings.setDrawAxes(renderPreferences.drawAxes); 345 setSetting<Setting::DrawAxes>("hello world");
345 libraries.storeToSettings(&settings); 346 libraries.storeToSettings();
346 }; 347 };
347 const auto updateRecentlyOpenedDocumentsMenu = [&]{ 348 const auto updateRecentlyOpenedDocumentsMenu = [&]{
348 rebuildRecentFilesMenu(ui.menuRecentFiles, recentlyOpenedFiles, &mainWindow); 349 rebuildRecentFilesMenu(ui.menuRecentFiles, recentlyOpenedFiles, &mainWindow);
349 for (QAction* action : ui.menuRecentFiles->findChildren<QAction*>()) { 350 for (QAction* action : ui.menuRecentFiles->findChildren<QAction*>()) {
350 QString path = action->data().toString(); 351 QString path = action->data().toString();
368 model->remove(action.position); 369 model->remove(action.position);
369 }, 370 },
370 }, action); 371 }, action);
371 }; 372 };
372 const auto restoreSettings = [&]{ 373 const auto restoreSettings = [&]{
373 recentlyOpenedFiles = settings.recentFiles(); 374 recentlyOpenedFiles = setting<Setting::RecentFiles>();
374 documentSplitterState = settings.mainSplitterState(); 375 renderPreferences = loadRenderPreferences();
375 renderPreferences = loadRenderPreferences(&settings); 376 changeLanguage(setting<Setting::Locale>(), &translator);
376 changeLanguage(settings.locale(), &translator); 377 libraries.restoreFromSettings();
377 libraries.restoreFromSettings(&settings);
378 updateRecentlyOpenedDocumentsMenu(); 378 updateRecentlyOpenedDocumentsMenu();
379 colorTable = loadColors(&libraries); 379 colorTable = loadColors(&libraries);
380 updateRenderPreferences(&ui, &renderPreferences, &documents); 380 updateRenderPreferences(&ui, &renderPreferences, &documents);
381 ui.mdiArea->setViewMode(static_cast<QMdiArea::ViewMode>(settings.viewMode())); 381 ui.mdiArea->setViewMode(setting<Setting::ViewMode>());
382 ui.retranslateUi(&mainWindow); 382 ui.retranslateUi(&mainWindow);
383 }; 383 };
384 const auto addRecentlyOpenedFile = [&](const QString& path){ 384 const auto addRecentlyOpenedFile = [&](const QString& path){
385 constexpr int maxRecentlyOpenedFiles = 10; 385 constexpr int maxRecentlyOpenedFiles = 10;
386 recentlyOpenedFiles.removeAll(path); 386 recentlyOpenedFiles.removeAll(path);
405 data->gridLayer = std::make_unique<GridLayer>(); 405 data->gridLayer = std::make_unique<GridLayer>();
406 data->gridLayer->setGridMatrix(XZ); 406 data->gridLayer->setGridMatrix(XZ);
407 data->tools->setGridMatrix(XZ); 407 data->tools->setGridMatrix(XZ);
408 data->model = model; 408 data->model = model;
409 data->canvas->addRenderLayer(data->axesLayer.get()); 409 data->canvas->addRenderLayer(data->axesLayer.get());
410 data->canvas->setLayerEnabled(data->axesLayer.get(), settings.drawAxes()); 410 data->canvas->setLayerEnabled(data->axesLayer.get(), setting<Setting::DrawAxes>());
411 data->canvas->addRenderLayer(data->gridLayer.get()); 411 data->canvas->addRenderLayer(data->gridLayer.get());
412 data->canvas->addRenderLayer(data->tools.get()); 412 data->canvas->addRenderLayer(data->tools.get());
413 documents.setModelPayload(modelId, data); 413 documents.setModelPayload(modelId, data);
414 QObject::connect( 414 QObject::connect(
415 data->tools.get(), 415 data->tools.get(),
474 addRecentlyOpenedFile(path); 474 addRecentlyOpenedFile(path);
475 } 475 }
476 } 476 }
477 }); 477 });
478 QObject::connect(ui.actionSettingsEditor, &QAction::triggered, [&]{ 478 QObject::connect(ui.actionSettingsEditor, &QAction::triggered, [&]{
479 SettingsEditor settingsEditor{&settings, defaultKeyboardShortcuts, &mainWindow}; 479 SettingsEditor settingsEditor{defaultKeyboardShortcuts, &mainWindow};
480 const int result = settingsEditor.exec(); 480 const int result = settingsEditor.exec();
481 if (result == QDialog::Accepted) 481 if (result == QDialog::Accepted)
482 { 482 {
483 restoreSettings(); 483 restoreSettings();
484 } 484 }
598 } 598 }
599 } 599 }
600 } 600 }
601 }); 601 });
602 mainWindow.setWindowTitle(title()); 602 mainWindow.setWindowTitle(title());
603 mainWindow.restoreGeometry(settings.mainWindowGeometry()); 603 mainWindow.restoreGeometry(setting<Setting::MainWindowGeometry>());
604 restoreSettings(); 604 restoreSettings();
605 updateRenderPreferences(&ui, &renderPreferences, &documents); 605 updateRenderPreferences(&ui, &renderPreferences, &documents);
606 mainWindow.show(); 606 mainWindow.show();
607 const int result = app.exec(); 607 const int result = app.exec();
608 saveSettings(); 608 saveSettings();

mercurial