26 #include "settingseditor/settingseditor.h" |
26 #include "settingseditor/settingseditor.h" |
27 #include "version.h" |
27 #include "version.h" |
28 #include "document.h" |
28 #include "document.h" |
29 #include "uiutilities.h" |
29 #include "uiutilities.h" |
30 #include "widgets/colorselectdialog.h" |
30 #include "widgets/colorselectdialog.h" |
31 #include "modeleditor.h" |
|
32 |
31 |
33 template<typename BaseType, typename MemberType, typename DataType> |
32 template<typename BaseType, typename MemberType, typename DataType> |
34 struct MemberData |
33 struct MemberData |
35 { |
34 { |
36 std::size_t member; |
35 std::size_t member; |
191 this->updateRecentlyOpenedDocumentsMenu(); |
190 this->updateRecentlyOpenedDocumentsMenu(); |
192 } |
191 } |
193 |
192 |
194 void MainWindow::openModelForEditing(const ModelId modelId) |
193 void MainWindow::openModelForEditing(const ModelId modelId) |
195 { |
194 { |
196 Document* document = new Document{this->documents.getModelById(modelId), &this->documents, this->colorTable}; |
195 EditorTabWidget* document = new EditorTabWidget{ |
|
196 this->documents.getModelById(modelId), |
|
197 &this->documents, |
|
198 this->colorTable, |
|
199 }; |
197 document->canvas->setRenderPreferences(this->renderPreferences); |
200 document->canvas->setRenderPreferences(this->renderPreferences); |
198 connect(document, &Document::newStatusText, [&](const QString& newStatusText) |
201 connect(document, &EditorTabWidget::newStatusText, [&](const QString& newStatusText) |
199 { |
202 { |
200 this->statusBar()->showMessage(newStatusText); |
203 this->statusBar()->showMessage(newStatusText); |
201 }); |
204 }); |
202 const QFileInfo fileInfo{*this->documents.modelPath(modelId)}; |
205 const QFileInfo fileInfo{*this->documents.modelPath(modelId)}; |
203 QString tabName = fileInfo.baseName(); |
206 QString tabName = fileInfo.baseName(); |
218 { |
221 { |
219 this->restoreSettings(); |
222 this->restoreSettings(); |
220 } |
223 } |
221 } |
224 } |
222 |
225 |
223 Document* MainWindow::currentDocument() |
226 EditorTabWidget* MainWindow::currentDocument() |
224 { |
227 { |
225 return qobject_cast<Document*>(this->ui->tabs->currentWidget()); |
228 return qobject_cast<EditorTabWidget*>(this->ui->tabs->currentWidget()); |
226 } |
229 } |
227 |
230 |
228 const Document* MainWindow::currentDocument() const |
231 const EditorTabWidget* MainWindow::currentDocument() const |
229 { |
232 { |
230 return qobject_cast<const Document*>(this->ui->tabs->currentWidget()); |
233 return qobject_cast<const EditorTabWidget*>(this->ui->tabs->currentWidget()); |
231 } |
234 } |
232 |
235 |
233 void MainWindow::handleDocumentSplitterChange() |
236 void MainWindow::handleDocumentSplitterChange() |
234 { |
237 { |
235 Document* currentDocument = this->currentDocument(); |
238 EditorTabWidget* currentDocument = this->currentDocument(); |
236 if (currentDocument != nullptr) |
239 if (currentDocument != nullptr) |
237 { |
240 { |
238 this->documentSplitterState = currentDocument->saveSplitterState(); |
241 this->documentSplitterState = currentDocument->saveSplitterState(); |
239 for (int i = 0; i < this->ui->tabs->count(); i += 1) |
242 for (int i = 0; i < this->ui->tabs->count(); i += 1) |
240 { |
243 { |
241 Document* document = qobject_cast<Document*>(this->ui->tabs->widget(i)); |
244 EditorTabWidget* document = qobject_cast<EditorTabWidget*>(this->ui->tabs->widget(i)); |
242 if (document != nullptr and document != currentDocument) |
245 if (document != nullptr and document != currentDocument) |
243 { |
246 { |
244 document->restoreSplitterState(this->documentSplitterState); |
247 document->restoreSplitterState(this->documentSplitterState); |
245 } |
248 } |
246 } |
249 } |
361 /** |
364 /** |
362 * @brief Handles the "Delete" (Del) action |
365 * @brief Handles the "Delete" (Del) action |
363 */ |
366 */ |
364 void MainWindow::actionDelete() |
367 void MainWindow::actionDelete() |
365 { |
368 { |
366 Document* document = this->currentDocument(); |
369 /* |
|
370 EditorTabWidget* document = this->currentDocument(); |
367 if (document != nullptr) |
371 if (document != nullptr) |
368 { |
372 { |
369 std::unique_ptr<ModelEditor> modelEditor = document->editModel(); |
373 std::unique_ptr<ModelEditor> modelEditor = document->editModel(); |
370 QSet<ldraw::id_t> ids = document->selectedObjects(); // copy |
374 QSet<ldraw::id_t> ids = document->selectedObjects(); // copy |
371 for (const ldraw::id_t id : ids) |
375 for (const ldraw::id_t id : ids) |
375 { |
379 { |
376 modelEditor->remove(index.row()); |
380 modelEditor->remove(index.row()); |
377 } |
381 } |
378 } |
382 } |
379 } |
383 } |
|
384 */ |
380 } |
385 } |
381 |
386 |
382 /** |
387 /** |
383 * @brief Handles the "Invert" action |
388 * @brief Handles the "Invert" action |
384 */ |
389 */ |
385 void MainWindow::actionInvert() |
390 void MainWindow::actionInvert() |
386 { |
391 { |
387 Document* document = this->currentDocument(); |
392 /* |
|
393 EditorTabWidget* document = this->currentDocument(); |
388 if (document != nullptr) |
394 if (document != nullptr) |
389 { |
395 { |
390 // TODO: simplify |
396 // TODO: simplify |
391 std::unique_ptr<ModelEditor> modelEditor = document->editModel(); |
397 std::unique_ptr<ModelEditor> modelEditor = document->editModel(); |
392 const std::optional<ModelId> modelId = this->documents.findIdForModel(&modelEditor->model()); |
398 const std::optional<ModelId> modelId = this->documents.findIdForModel(&modelEditor->model()); |
403 object->invert(&context); |
409 object->invert(&context); |
404 }); |
410 }); |
405 } |
411 } |
406 } |
412 } |
407 } |
413 } |
|
414 */ |
408 } |
415 } |
409 |
416 |
410 /** |
417 /** |
411 * @brief Removes the document at the specified tab index |
418 * @brief Removes the document at the specified tab index |
412 * @param index |
419 * @param index |
413 */ |
420 */ |
414 void MainWindow::handleTabCloseButton(int tabIndex) |
421 void MainWindow::handleTabCloseButton(int tabIndex) |
415 { |
422 { |
416 if (tabIndex >= 0 and tabIndex < this->ui->tabs->count()) |
423 if (tabIndex >= 0 and tabIndex < this->ui->tabs->count()) |
417 { |
424 { |
418 Document* document = qobject_cast<Document*>(this->ui->tabs->widget(tabIndex)); |
425 EditorTabWidget* document = qobject_cast<EditorTabWidget*>(this->ui->tabs->widget(tabIndex)); |
419 if (document != nullptr) |
426 if (document != nullptr) |
420 { |
427 { |
421 this->closeDocument(document); |
428 this->closeDocument(document); |
422 } |
429 } |
423 } |
430 } |
425 |
432 |
426 /** |
433 /** |
427 * @brief Closes the specified document |
434 * @brief Closes the specified document |
428 * @param document |
435 * @param document |
429 */ |
436 */ |
430 void MainWindow::closeDocument(Document *document) |
437 void MainWindow::closeDocument(EditorTabWidget *document) |
431 { |
438 { |
432 std::optional<ModelId> modelId = this->documents.findIdForModel(&document->getModel()); |
439 std::optional<ModelId> modelId = this->documents.findIdForModel(document->model); |
433 if (modelId.has_value()) |
440 if (modelId.has_value()) |
434 { |
441 { |
435 this->documents.closeDocument(modelId.value()); |
442 this->documents.closeDocument(modelId.value()); |
436 delete document; |
443 delete document; |
437 } |
444 } |
438 } |
445 } |
439 |
446 |
440 std::optional<ModelId> MainWindow::findCurrentModelId() const |
447 std::optional<ModelId> MainWindow::findCurrentModelId() const |
441 { |
448 { |
442 const Document* document = this->currentDocument(); |
449 const EditorTabWidget* document = this->currentDocument(); |
443 if (document != nullptr) |
450 if (document != nullptr) |
444 { |
451 { |
445 return this->documents.findIdForModel(&document->getModel()); |
452 return this->documents.findIdForModel(document->model); |
446 } |
453 } |
447 else |
454 else |
448 { |
455 { |
449 return {}; |
456 return {}; |
450 } |
457 } |
490 |
497 |
491 void MainWindow::updateRenderPreferences() |
498 void MainWindow::updateRenderPreferences() |
492 { |
499 { |
493 for (int i = 0; i < this->ui->tabs->count(); i += 1) |
500 for (int i = 0; i < this->ui->tabs->count(); i += 1) |
494 { |
501 { |
495 Document* document = qobject_cast<Document*>(this->ui->tabs->widget(i)); |
502 EditorTabWidget* document = qobject_cast<EditorTabWidget*>(this->ui->tabs->widget(i)); |
496 if (document != nullptr) |
503 if (document != nullptr) |
497 { |
504 { |
498 document->canvas->setRenderPreferences(this->renderPreferences); |
505 document->canvas->setRenderPreferences(this->renderPreferences); |
499 } |
506 } |
500 } |
507 } |