51 std::unique_ptr<PartRenderer> canvas; |
51 std::unique_ptr<PartRenderer> canvas; |
52 std::unique_ptr<EditTools> tools; |
52 std::unique_ptr<EditTools> tools; |
53 std::unique_ptr<AxesLayer> axesLayer; |
53 std::unique_ptr<AxesLayer> axesLayer; |
54 std::unique_ptr<GridLayer> gridLayer; |
54 std::unique_ptr<GridLayer> gridLayer; |
55 std::unique_ptr<QTextCursor> textcursor; |
55 std::unique_ptr<QTextCursor> textcursor; |
56 Model* model; |
56 QTextDocument* model; |
57 }; |
57 }; |
58 |
58 |
59 class Signal final : public QObject |
59 class Signal final : public QObject |
60 { |
60 { |
61 Q_OBJECT |
61 Q_OBJECT |
84 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) |
84 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) |
85 qRegisterMetaTypeStreamOperators<Library>("Library"); |
85 qRegisterMetaTypeStreamOperators<Library>("Library"); |
86 qRegisterMetaTypeStreamOperators<Libraries>("Libraries"); |
86 qRegisterMetaTypeStreamOperators<Libraries>("Libraries"); |
87 qRegisterMetaTypeStreamOperators<gl::RenderStyle>(); |
87 qRegisterMetaTypeStreamOperators<gl::RenderStyle>(); |
88 qRegisterMetaTypeStreamOperators<QMdiArea::ViewMode>(); |
88 qRegisterMetaTypeStreamOperators<QMdiArea::ViewMode>(); |
|
89 qRegisterMetaTypeStreamOperators<Qt::ToolButtonStyle>(); |
89 #endif |
90 #endif |
90 } |
91 } |
91 |
92 |
92 template<typename BaseType, typename MemberType, typename DataType> |
93 template<typename BaseType, typename MemberType, typename DataType> |
93 struct MemberData |
94 struct MemberData |
160 |
161 |
161 static ModelData* currentModelData(Ui_MainWindow* ui, const DocumentManager* documents) |
162 static ModelData* currentModelData(Ui_MainWindow* ui, const DocumentManager* documents) |
162 { |
163 { |
163 if (auto* const activeSubWindow = currentModelSubWindow(ui)) { |
164 if (auto* const activeSubWindow = currentModelSubWindow(ui)) { |
164 return findModelData(documents, activeSubWindow->modelId); |
165 return findModelData(documents, activeSubWindow->modelId); |
165 } |
|
166 else { |
|
167 return nullptr; |
|
168 } |
|
169 } |
|
170 |
|
171 static Model* currentModelBody(Ui_MainWindow* ui, DocumentManager* documents) |
|
172 { |
|
173 if (auto* const activeSubWindow = currentModelSubWindow(ui)) { |
|
174 return documents->getModelById(activeSubWindow->modelId); |
|
175 } |
166 } |
176 else { |
167 else { |
177 return nullptr; |
168 return nullptr; |
178 } |
169 } |
179 } |
170 } |
329 ui->toolWidgetStack->setCurrentIndex(i); |
320 ui->toolWidgetStack->setCurrentIndex(i); |
330 }); |
321 }); |
331 } |
322 } |
332 } |
323 } |
333 |
324 |
334 static QFont monospace() |
|
335 { |
|
336 QFont font{"Monospace"}; |
|
337 font.setStyleHint(QFont::TypeWriter); |
|
338 font.setPointSize(10); |
|
339 font.setFixedPitch(true); |
|
340 return font; |
|
341 } |
|
342 |
|
343 constexpr bool sortModelIndexesByRow(const QModelIndex& a, const QModelIndex& b) |
325 constexpr bool sortModelIndexesByRow(const QModelIndex& a, const QModelIndex& b) |
344 { |
326 { |
345 return a.row() < b.row(); |
327 return a.row() < b.row(); |
346 } |
328 } |
347 |
329 |
406 SubWindow* subWindow = new SubWindow{args..., nullptr}; |
388 SubWindow* subWindow = new SubWindow{args..., nullptr}; |
407 mdiArea->addSubWindow(subWindow); |
389 mdiArea->addSubWindow(subWindow); |
408 return subWindow; |
390 return subWindow; |
409 } |
391 } |
410 |
392 |
411 static QSet<ElementId> resolveIdsFromSelection(const ModelData* data) |
|
412 { |
|
413 // const auto selection = data->itemSelectionModel->selection(); |
|
414 QSet<ElementId> selectedIndexes; |
|
415 /* for (const QModelIndex& qindex : selection.indexes()) { |
|
416 const std::size_t row = unsigned_cast(qindex.row()); |
|
417 selectedIndexes.insert(data->model->idAt(row)); |
|
418 } |
|
419 */ return selectedIndexes; |
|
420 } |
|
421 |
|
422 int main(int argc, char *argv[]) |
393 int main(int argc, char *argv[]) |
423 { |
394 { |
424 doQtRegistrations(); |
395 doQtRegistrations(); |
425 QApplication app{argc, argv}; |
396 QApplication app{argc, argv}; |
426 QApplication::setWindowIcon(QIcon{":/icons/appicon.png"}); |
397 QApplication::setWindowIcon(QIcon{":/icons/appicon.png"}); |
466 } |
437 } |
467 ); |
438 ); |
468 } |
439 } |
469 }; |
440 }; |
470 const auto executeAction = [&]( |
441 const auto executeAction = [&]( |
471 Model* model, const ModelAction& action |
442 QTextDocument* model, const ModelAction& action |
472 ) { |
443 ) { |
473 /* |
|
474 std::visit(overloaded{ |
444 std::visit(overloaded{ |
475 [model](const AppendToModel& action){ |
445 [model](const AppendToModel& action){ |
476 model->append(action.newElement); |
446 QTextCursor cursor{model}; |
|
447 cursor.movePosition(QTextCursor::End); |
|
448 const QString newText = modelElementToString(action.newElement); |
|
449 // Make sure we have an empty line |
|
450 if (not model->lastBlock().text().isEmpty()) { |
|
451 cursor.insertBlock(); |
|
452 } |
|
453 cursor.insertText(newText); |
477 }, |
454 }, |
478 [model](const DeleteFromModel& action){ |
455 [](const DeleteFromModel&){}, |
479 model->remove(action.position); |
|
480 }, |
|
481 [model](const ModifyModel& action){ |
456 [model](const ModifyModel& action){ |
482 model->assignAt(action.position, action.newElement); |
457 QTextBlock block = model->findBlockByLineNumber((int) action.position); |
|
458 if (block.isValid()) { |
|
459 QTextCursor cursor{block}; |
|
460 cursor.select(QTextCursor::LineUnderCursor); |
|
461 cursor.insertText(modelElementToString(action.newElement)); |
|
462 } |
|
463 //model->assignAt(action.position, action.newElement); |
483 }, |
464 }, |
484 }, action); |
465 }, action); |
485 */ |
|
486 |
466 |
487 }; |
467 }; |
488 const auto restoreSettings = [&]{ |
468 const auto restoreSettings = [&]{ |
489 recentlyOpenedFiles = setting<Setting::RecentFiles>(); |
469 recentlyOpenedFiles = setting<Setting::RecentFiles>(); |
490 renderPreferences = loadRenderPreferences(); |
470 renderPreferences = loadRenderPreferences(); |
492 updateRecentlyOpenedDocumentsMenu(); |
472 updateRecentlyOpenedDocumentsMenu(); |
493 colorTable = loadColors(&libraries); |
473 colorTable = loadColors(&libraries); |
494 updateRenderPreferences(&ui, &renderPreferences, &documents); |
474 updateRenderPreferences(&ui, &renderPreferences, &documents); |
495 ui.mdiArea->setViewMode(setting<Setting::ViewMode>()); |
475 ui.mdiArea->setViewMode(setting<Setting::ViewMode>()); |
496 ui.retranslateUi(&mainWindow); |
476 ui.retranslateUi(&mainWindow); |
|
477 mainWindow.setToolButtonStyle(setting<Setting::ToolButtonStyle>()); |
497 settingsChanged.emit(); |
478 settingsChanged.emit(); |
498 }; |
479 }; |
499 const auto addRecentlyOpenedFile = [&](const QString& path){ |
480 const auto addRecentlyOpenedFile = [&](const QString& path){ |
500 constexpr int maxRecentlyOpenedFiles = 10; |
481 constexpr int maxRecentlyOpenedFiles = 10; |
501 recentlyOpenedFiles.removeAll(path); |
482 recentlyOpenedFiles.removeAll(path); |
506 } |
487 } |
507 saveSettings(); |
488 saveSettings(); |
508 updateRecentlyOpenedDocumentsMenu(); |
489 updateRecentlyOpenedDocumentsMenu(); |
509 }; |
490 }; |
510 const auto openModelForEditing = [&](const ModelId modelId){ |
491 const auto openModelForEditing = [&](const ModelId modelId){ |
511 Model* model = documents.getModelById(modelId); |
492 QTextDocument* model = documents.getModelById(modelId); |
512 if (model != nullptr) { |
493 if (model != nullptr) { |
513 ModelData* data = new ModelData(&documents); |
494 ModelData* data = new ModelData(&documents); |
514 data->tools = std::make_unique<EditTools>(); |
495 data->tools = std::make_unique<EditTools>(); |
515 data->canvas = std::make_unique<PartRenderer>(model, &documents, colorTable); |
496 data->canvas = std::make_unique<PartRenderer>(model, &documents, colorTable); |
516 data->axesLayer = std::make_unique<AxesLayer>(); |
497 data->axesLayer = std::make_unique<AxesLayer>(); |
743 QObject::connect( |
724 QObject::connect( |
744 ui.actionMakeUnofficial, |
725 ui.actionMakeUnofficial, |
745 &QAction::triggered, |
726 &QAction::triggered, |
746 [&]{ |
727 [&]{ |
747 if (ModelData* data = currentModelData(&ui, &documents)) { |
728 if (ModelData* data = currentModelData(&ui, &documents)) { |
748 Model* const model = data->model; |
729 QTextDocument* const model = data->model; |
749 for (const ModelAction& action : ldraw::makeUnofficial(model)) { |
730 for (const ModelAction& action : ldraw::makeUnofficial(model)) { |
750 executeAction(model, action); |
731 executeAction(model, action); |
751 } |
732 } |
752 } |
733 } |
753 }); |
734 }); |