| 66 this->setRenderStyle(data.payload); |
66 this->setRenderStyle(data.payload); |
| 67 }); |
67 }); |
| 68 } |
68 } |
| 69 this->updateTitle(); |
69 this->updateTitle(); |
| 70 this->restoreSettings(); |
70 this->restoreSettings(); |
| 71 this->updateRenderStyles(); |
71 this->updateRenderPreferences(); |
| 72 this->newModel(); |
72 this->newModel(); |
| 73 } |
73 } |
| 74 |
74 |
| |
75 // MainWindow needs a destructor even if it is empty because otherwise the destructor of the |
| |
76 // std::unique_ptr is resolved in the header file, where it will complain about Ui_MainWindow |
| |
77 // being incomplete. |
| 75 MainWindow::~MainWindow() |
78 MainWindow::~MainWindow() |
| 76 { |
79 { |
| 77 } |
80 } |
| 78 |
81 |
| 79 void MainWindow::newModel() |
82 void MainWindow::newModel() |
| 160 } |
163 } |
| 161 |
164 |
| 162 void MainWindow::openModelForEditing(const QString& modelName) |
165 void MainWindow::openModelForEditing(const QString& modelName) |
| 163 { |
166 { |
| 164 Document* document = new Document{this->documents.findModelByName(modelName), &this->documents, this->colorTable}; |
167 Document* document = new Document{this->documents.findModelByName(modelName), &this->documents, this->colorTable}; |
| 165 document->setRenderStyle(this->renderStyle); |
168 document->setRenderPreferences(this->renderPreferences); |
| 166 this->ui->tabs->addTab(document, modelName); |
169 this->ui->tabs->addTab(document, modelName); |
| 167 this->ui->tabs->setCurrentWidget(document); |
170 this->ui->tabs->setCurrentWidget(document); |
| 168 document->restoreSplitterState(this->documentSplitterState); |
171 document->restoreSplitterState(this->documentSplitterState); |
| 169 connect(document, &Document::splitterChanged, this, &MainWindow::handleDocumentSplitterChange); |
172 connect(document, &Document::splitterChanged, this, &MainWindow::handleDocumentSplitterChange); |
| 170 } |
173 } |
| 219 } |
222 } |
| 220 } |
223 } |
| 221 |
224 |
| 222 void MainWindow::setRenderStyle(gl::RenderStyle renderStyle) |
225 void MainWindow::setRenderStyle(gl::RenderStyle renderStyle) |
| 223 { |
226 { |
| 224 this->renderStyle = renderStyle; |
227 this->renderPreferences.style = renderStyle; |
| 225 this->saveSettings(); |
228 this->saveSettings(); |
| 226 this->updateRenderStyles(); |
229 this->updateRenderPreferences(); |
| 227 } |
230 } |
| 228 |
231 |
| 229 void MainWindow::changeEvent(QEvent* event) |
232 void MainWindow::changeEvent(QEvent* event) |
| 230 { |
233 { |
| 231 if (event != nullptr) |
234 if (event != nullptr) |
| 262 title += " "; |
265 title += " "; |
| 263 title += fullVersionString(); |
266 title += fullVersionString(); |
| 264 setWindowTitle(title); |
267 setWindowTitle(title); |
| 265 } |
268 } |
| 266 |
269 |
| 267 void MainWindow::updateRenderStyles() |
270 void MainWindow::updateRenderPreferences() |
| 268 { |
271 { |
| 269 for (int i = 0; i < this->ui->tabs->count(); i += 1) |
272 for (int i = 0; i < this->ui->tabs->count(); i += 1) |
| 270 { |
273 { |
| 271 Document* document = qobject_cast<Document*>(this->ui->tabs->widget(i)); |
274 Document* document = qobject_cast<Document*>(this->ui->tabs->widget(i)); |
| 272 if (document != nullptr) |
275 if (document != nullptr) |
| 273 { |
276 { |
| 274 document->setRenderStyle(renderStyle); |
277 document->setRenderPreferences(this->renderPreferences); |
| 275 } |
278 } |
| 276 } |
279 } |
| 277 for (auto data : ::renderStyleButtons) |
280 for (auto data : ::renderStyleButtons) |
| 278 { |
281 { |
| 279 QAction* action = data.memberInstance(this->ui.get()); |
282 QAction* action = data.memberInstance(this->ui.get()); |
| 280 action->setChecked(this->renderStyle == data.payload); |
283 action->setChecked(this->renderPreferences.style == data.payload); |
| 281 } |
284 } |
| 282 } |
285 } |
| 283 |
286 |
| 284 /** |
287 /** |
| 285 * @brief Stores the settings of the main window, storing geometry, etc |
288 * @brief Stores the settings of the main window, storing geometry, etc |
| 287 void MainWindow::saveSettings() |
290 void MainWindow::saveSettings() |
| 288 { |
291 { |
| 289 this->settings.setValue("MainWindow/Geometry", this->saveGeometry()); |
292 this->settings.setValue("MainWindow/Geometry", this->saveGeometry()); |
| 290 this->settings.setValue("MainWindow/RecentlyOpened", this->recentlyOpenedFiles); |
293 this->settings.setValue("MainWindow/RecentlyOpened", this->recentlyOpenedFiles); |
| 291 this->settings.setValue("MainWindow/DocumentSplitterState", this->documentSplitterState); |
294 this->settings.setValue("MainWindow/DocumentSplitterState", this->documentSplitterState); |
| 292 this->settings.setValue("MainWindow/RenderStyle", static_cast<int>(this->renderStyle)); |
295 this->settings.setValue("MainWindow/RenderStyle", static_cast<int>(this->renderPreferences.style)); |
| 293 this->libraries.storeToSettings(&this->settings); |
296 this->libraries.storeToSettings(&this->settings); |
| 294 } |
297 } |
| 295 |
298 |
| 296 /** |
299 /** |
| 297 * @brief Restores saved settings relating to the main window |
300 * @brief Restores saved settings relating to the main window |
| 299 void MainWindow::restoreSettings() |
302 void MainWindow::restoreSettings() |
| 300 { |
303 { |
| 301 this->restoreGeometry(this->settings.value("MainWindow/Geometry").toByteArray()); |
304 this->restoreGeometry(this->settings.value("MainWindow/Geometry").toByteArray()); |
| 302 this->recentlyOpenedFiles = this->settings.value("MainWindow/RecentlyOpened").toStringList(); |
305 this->recentlyOpenedFiles = this->settings.value("MainWindow/RecentlyOpened").toStringList(); |
| 303 this->documentSplitterState = this->settings.value("MainWindow/DocumentSplitterState").toByteArray(); |
306 this->documentSplitterState = this->settings.value("MainWindow/DocumentSplitterState").toByteArray(); |
| 304 this->renderStyle = static_cast<gl::RenderStyle>(this->settings.value("MainWindow/RenderStyle").toInt()); |
307 this->renderPreferences.style = static_cast<gl::RenderStyle>(this->settings.value("Render/Style").toInt()); |
| |
308 this->renderPreferences.mainColor = this->settings.value("Render/MainColor").toString(); |
| 305 const QString systemLocale = QLocale::system().name(); |
309 const QString systemLocale = QLocale::system().name(); |
| 306 const QVariant defaultLocale = this->settings.value("locale", systemLocale); |
310 const QVariant defaultLocale = this->settings.value("locale", systemLocale); |
| 307 changeLanguage(defaultLocale.toString()); |
311 changeLanguage(defaultLocale.toString()); |
| 308 this->libraries.restoreFromSettings(&this->settings); |
312 this->libraries.restoreFromSettings(&this->settings); |
| 309 this->updateRecentlyOpenedDocumentsMenu(); |
313 this->updateRecentlyOpenedDocumentsMenu(); |
| 310 this->loadColors(); |
314 this->loadColors(); |
| |
315 this->updateRenderPreferences(); |
| 311 } |
316 } |
| 312 |
317 |
| 313 QString MainWindow::pathToTranslation(const QString& localeCode) |
318 QString MainWindow::pathToTranslation(const QString& localeCode) |
| 314 { |
319 { |
| 315 QDir dir {":/locale"}; |
320 QDir dir {":/locale"}; |