src/main.cpp

changeset 375
21a5ecbe34e4
parent 374
75efc3ba5a56
child 376
3cef3b016330
equal deleted inserted replaced
374:75efc3ba5a56 375:21a5ecbe34e4
174 fn(&info, modelSpecificData); 174 fn(&info, modelSpecificData);
175 } 175 }
176 }); 176 });
177 } 177 }
178 178
179 static void updateRenderPreferences( 179 static void updateRenderPreferences(MainState* state)
180 MainWindow* ui, 180 {
181 const gl::RenderPreferences* renderPreferences, 181 forEachModel(&state->documents, [state](const void*, const ModelData* data){
182 const DocumentManager* documents)
183 {
184 forEachModel(documents, [&renderPreferences](const void*, const ModelData* data){
185 if (data->canvas != nullptr) { 182 if (data->canvas != nullptr) {
186 data->canvas->setRenderPreferences(*renderPreferences); 183 data->canvas->setRenderPreferences(state->renderPreferences);
187 data->canvas->setLayerEnabled(data->axesLayer.get(), renderPreferences->drawAxes); 184 data->canvas->setLayerEnabled(data->axesLayer.get(), state->renderPreferences.drawAxes);
188 } 185 }
189 }); 186 });
190 ui->setRenderStyle(renderPreferences->style); 187 state->mainWindow.setRenderStyle(state->renderPreferences.style);
191 ui->actionDrawAxes->setChecked(renderPreferences->drawAxes); 188 state->mainWindow.actionDrawAxes->setChecked(state->renderPreferences.drawAxes);
192 ui->actionWireframe->setChecked(renderPreferences->wireframe); 189 state->mainWindow.actionWireframe->setChecked(state->renderPreferences.wireframe);
193 } 190 }
194 191
195 static gl::RenderPreferences loadRenderPreferences() 192 static gl::RenderPreferences loadRenderPreferences()
196 { 193 {
197 return gl::RenderPreferences{ 194 return gl::RenderPreferences{
392 state->recentlyOpenedFiles = setting<Setting::RecentFiles>(); 389 state->recentlyOpenedFiles = setting<Setting::RecentFiles>();
393 state->renderPreferences = loadRenderPreferences(); 390 state->renderPreferences = loadRenderPreferences();
394 state->libraries.restoreFromSettings(); 391 state->libraries.restoreFromSettings();
395 updateRecentlyOpenedDocumentsMenu(state); 392 updateRecentlyOpenedDocumentsMenu(state);
396 state->colorTable = loadColors(&state->libraries); 393 state->colorTable = loadColors(&state->libraries);
397 updateRenderPreferences(&state->mainWindow, &state->renderPreferences, &state->documents); 394 updateRenderPreferences(state);
398 state->mainWindow.mdiArea->setViewMode(setting<Setting::ViewMode>()); 395 state->mainWindow.mdiArea->setViewMode(setting<Setting::ViewMode>());
399 state->mainWindow.retranslateUi(&state->mainWindow); 396 state->mainWindow.retranslateUi(&state->mainWindow);
400 state->mainWindow.setToolButtonStyle(setting<Setting::ToolButtonStyle>()); 397 state->mainWindow.setToolButtonStyle(setting<Setting::ToolButtonStyle>());
401 } 398 }
402 399
597 QObject::connect(state.mainWindow.actionDrawAxes, &QAction::triggered, [&state] 594 QObject::connect(state.mainWindow.actionDrawAxes, &QAction::triggered, [&state]
598 (bool drawAxes) 595 (bool drawAxes)
599 { 596 {
600 state.renderPreferences.drawAxes = drawAxes; 597 state.renderPreferences.drawAxes = drawAxes;
601 saveSettings(&state); 598 saveSettings(&state);
602 updateRenderPreferences(&state.mainWindow, &state.renderPreferences, &state.documents); 599 updateRenderPreferences(&state);
603 }); 600 });
604 QObject::connect(state.mainWindow.actionWireframe, &QAction::triggered, [&state] 601 QObject::connect(state.mainWindow.actionWireframe, &QAction::triggered, [&state]
605 (bool enabled) 602 (bool enabled)
606 { 603 {
607 state.renderPreferences.wireframe = enabled; 604 state.renderPreferences.wireframe = enabled;
608 saveSettings(&state); 605 saveSettings(&state);
609 updateRenderPreferences(&state.mainWindow, &state.renderPreferences, &state.documents); 606 updateRenderPreferences(&state);
610 }); 607 });
611 QObject::connect(&state.mainWindow, &MainWindow::renderStyleSelected, [&state] 608 QObject::connect(&state.mainWindow, &MainWindow::renderStyleSelected, [&state]
612 (gl::RenderStyle newStyle) 609 (gl::RenderStyle newStyle)
613 { 610 {
614 state.renderPreferences.style = newStyle; 611 state.renderPreferences.style = newStyle;
615 saveSettings(&state); 612 saveSettings(&state);
616 updateRenderPreferences(&state.mainWindow, &state.renderPreferences, &state.documents); 613 updateRenderPreferences(&state);
617 }); 614 });
618 initializeTools(&state.mainWindow, &state.toolWidgets, &state.mainWindow); 615 initializeTools(&state.mainWindow, &state.toolWidgets, &state.mainWindow);
619 for (QAction* action : state.mainWindow.editingModesToolBar->actions()) { 616 for (QAction* action : state.mainWindow.editingModesToolBar->actions()) {
620 QObject::connect(action, &QAction::triggered, [action, &state] 617 QObject::connect(action, &QAction::triggered, [action, &state]
621 { 618 {
732 QTextCursor cursor = state.mainWindow.modelEdit->textCursor(); 729 QTextCursor cursor = state.mainWindow.modelEdit->textCursor();
733 replace_color_in_selected_code(&cursor, ColorIndex{4}); 730 replace_color_in_selected_code(&cursor, ColorIndex{4});
734 } 731 }
735 ); 732 );
736 restoreSettings(&state); 733 restoreSettings(&state);
737 updateRenderPreferences(&state.mainWindow, &state.renderPreferences, &state.documents); 734 updateRenderPreferences(&state);
738 const int result = app.exec(); 735 const int result = app.exec();
739 saveSettings(&state); 736 saveSettings(&state);
740 return result; 737 return result;
741 } 738 }

mercurial