286 .drawAxes = setting<Setting::DrawAxes>(), |
286 .drawAxes = setting<Setting::DrawAxes>(), |
287 .wireframe = setting<Setting::Wireframe>(), |
287 .wireframe = setting<Setting::Wireframe>(), |
288 }; |
288 }; |
289 } |
289 } |
290 |
290 |
291 void initializeTools(Ui_MainWindow* ui, DocumentManager* documents, QWidget* parent) |
291 struct ToolWidgets |
292 { |
292 { |
293 CircleToolOptionsWidget* circleToolOptions = new CircleToolOptionsWidget{parent}; |
293 CircleToolOptionsWidget* circleToolOptions; |
294 ObjectEditor* objectEditor = new ObjectEditor{parent}; |
294 ObjectEditor* objectEditor; |
|
295 }; |
|
296 |
|
297 void initializeTools(Ui_MainWindow* ui, ToolWidgets* toolWidgets, QWidget* parent) |
|
298 { |
295 const struct |
299 const struct |
296 { |
300 { |
297 QString name, tooltip; |
301 QString name, tooltip; |
298 QPixmap icon; |
302 QPixmap icon; |
299 QWidget* widget; |
303 QWidget* widget; |
300 } editingModesInfo[] = { |
304 } editingModesInfo[] = { |
301 { |
305 { |
302 .name = QObject::tr("Select"), |
306 .name = QObject::tr("Select"), |
303 .tooltip = QObject::tr("Select elements from the model."), |
307 .tooltip = QObject::tr("Select elements from the model."), |
304 .icon = {":/icons/navigate-outline.png"}, |
308 .icon = {":/icons/navigate-outline.png"}, |
305 .widget = objectEditor, |
309 .widget = toolWidgets->objectEditor, |
306 }, |
310 }, |
307 { |
311 { |
308 .name = QObject::tr("Draw"), |
312 .name = QObject::tr("Draw"), |
309 .tooltip = QObject::tr("Draw new elements into the model."), |
313 .tooltip = QObject::tr("Draw new elements into the model."), |
310 .icon = {":/icons/pencil-outline.png"}, |
314 .icon = {":/icons/pencil-outline.png"}, |
312 }, |
316 }, |
313 { |
317 { |
314 .name = QObject::tr("Circle"), |
318 .name = QObject::tr("Circle"), |
315 .tooltip = QObject::tr("Draw circular primitives."), |
319 .tooltip = QObject::tr("Draw circular primitives."), |
316 .icon = {":/icons/linetype-circularprimitive.png"}, |
320 .icon = {":/icons/linetype-circularprimitive.png"}, |
317 .widget = circleToolOptions, |
321 .widget = toolWidgets->circleToolOptions, |
318 }, |
322 }, |
319 }; |
323 }; |
320 for (int i = 0; i < countof(editingModesInfo); ++i) { |
324 for (int i = 0; i < countof(editingModesInfo); ++i) { |
321 const auto& editingModeInfo = editingModesInfo[i]; |
325 const auto& editingModeInfo = editingModesInfo[i]; |
322 QAction* action = new QAction{editingModeInfo.name, parent}; |
326 QAction* action = new QAction{editingModeInfo.name, parent}; |
333 ui->toolWidgetStack->addWidget(widget); |
337 ui->toolWidgetStack->addWidget(widget); |
334 QObject::connect(action, &QAction::triggered, [ui, i]{ |
338 QObject::connect(action, &QAction::triggered, [ui, i]{ |
335 ui->toolWidgetStack->setCurrentIndex(i); |
339 ui->toolWidgetStack->setCurrentIndex(i); |
336 }); |
340 }); |
337 } |
341 } |
338 QObject::connect( |
|
339 circleToolOptions, |
|
340 &CircleToolOptionsWidget::optionsChanged, |
|
341 [ui, documents](const CircleToolOptions& options) { |
|
342 if (ModelData* data = currentModelData(ui, documents)) { |
|
343 data->tools->setCircleToolOptions(options); |
|
344 } |
|
345 }); |
|
346 } |
342 } |
347 |
343 |
348 constexpr bool sortModelIndexesByRow(const QModelIndex& a, const QModelIndex& b) |
344 constexpr bool sortModelIndexesByRow(const QModelIndex& a, const QModelIndex& b) |
349 { |
345 { |
350 return a.row() < b.row(); |
346 return a.row() < b.row(); |
375 ColorTable colorTable; |
371 ColorTable colorTable; |
376 gl::RenderPreferences renderPreferences; |
372 gl::RenderPreferences renderPreferences; |
377 MessageLog messageLog; |
373 MessageLog messageLog; |
378 Signal settingsChanged; |
374 Signal settingsChanged; |
379 ui.setupUi(&mainWindow); |
375 ui.setupUi(&mainWindow); |
|
376 ToolWidgets toolWidgets{ |
|
377 .circleToolOptions = new CircleToolOptionsWidget{&mainWindow}, |
|
378 .objectEditor = new ObjectEditor{&mainWindow}, |
|
379 }; |
380 const uiutilities::KeySequenceMap defaultKeyboardShortcuts = |
380 const uiutilities::KeySequenceMap defaultKeyboardShortcuts = |
381 uiutilities::makeKeySequenceMap(uiutilities::collectActions(&mainWindow)); |
381 uiutilities::makeKeySequenceMap(uiutilities::collectActions(&mainWindow)); |
382 const auto saveSettings = [&]{ |
382 const auto saveSettings = [&]{ |
383 setSetting<Setting::MainWindowGeometry>(mainWindow.saveGeometry()); |
383 setSetting<Setting::MainWindowGeometry>(mainWindow.saveGeometry()); |
384 setSetting<Setting::MainWindowState>(mainWindow.saveState()); |
384 setSetting<Setting::MainWindowState>(mainWindow.saveState()); |
461 &EditTools::modelAction, |
461 &EditTools::modelAction, |
462 std::bind(executeAction, model, std::placeholders::_1)); |
462 std::bind(executeAction, model, std::placeholders::_1)); |
463 QObject::connect( |
463 QObject::connect( |
464 data->itemSelectionModel.get(), |
464 data->itemSelectionModel.get(), |
465 &QItemSelectionModel::selectionChanged, |
465 &QItemSelectionModel::selectionChanged, |
466 [modelId, &documents]{ |
466 [modelId, &documents, &toolWidgets]{ |
467 ModelData* data = findModelData(&documents, modelId); |
467 ModelData* data = findModelData(&documents, modelId); |
468 if (data != nullptr) { |
468 if (data != nullptr) { |
469 auto resolveIndex = [&data](const QModelIndex& index){ |
469 auto resolveIndex = [&data](const QModelIndex& index){ |
470 return data->model->idAt(unsigned_cast(index.row())); |
470 return data->model->idAt(unsigned_cast(index.row())); |
471 }; |
471 }; |
472 const auto selection = data->itemSelectionModel->selection(); |
472 const auto selection = data->itemSelectionModel->selection(); |
473 const auto indices = fn::map<QSet<ModelId>>(selection.indexes(), resolveIndex); |
473 const auto indices = fn::map<QSet<ModelId>>(selection.indexes(), resolveIndex); |
474 data->canvas->setSelection(indices); |
474 data->canvas->setSelection(indices); |
|
475 /* |
|
476 if (indices.size() == 1) { |
|
477 opt<std::size_t> index = data->model->find(*indices.begin()); |
|
478 if (index.has_value()) { |
|
479 toolWidgets.objectEditor->setObject((*data->model)[*index]); |
|
480 } |
|
481 } |
|
482 else { |
|
483 toolWidgets.objectEditor->reset(); |
|
484 } |
|
485 */ |
475 } |
486 } |
476 }); |
487 }); |
477 data->canvas->setRenderPreferences(renderPreferences); |
488 data->canvas->setRenderPreferences(renderPreferences); |
478 QObject::connect( |
489 QObject::connect( |
479 data->tools.get(), |
490 data->tools.get(), |
631 const auto checkEditingModeAction = [&ui](EditingMode mode) { |
642 const auto checkEditingModeAction = [&ui](EditingMode mode) { |
632 for (QAction* action : ui.editingModesToolBar->actions()) { |
643 for (QAction* action : ui.editingModesToolBar->actions()) { |
633 action->setChecked(action->data().value<EditingMode>() == mode); |
644 action->setChecked(action->data().value<EditingMode>() == mode); |
634 } |
645 } |
635 }; |
646 }; |
636 initializeTools(&ui, &documents, &mainWindow); |
647 initializeTools(&ui, &toolWidgets, &mainWindow); |
637 for (QAction* action : ui.editingModesToolBar->actions()) { |
648 for (QAction* action : ui.editingModesToolBar->actions()) { |
638 QObject::connect(action, &QAction::triggered, [&, action]{ |
649 QObject::connect(action, &QAction::triggered, [&, action]{ |
639 if (ModelData* data = currentModelData(&ui, &documents)) { |
650 if (ModelData* data = currentModelData(&ui, &documents)) { |
640 const EditingMode mode = action->data().value<EditingMode>(); |
651 const EditingMode mode = action->data().value<EditingMode>(); |
641 data->tools->setEditMode(mode); |
652 data->tools->setEditMode(mode); |
667 ui.messageLog->resizeRowsToContents(); |
678 ui.messageLog->resizeRowsToContents(); |
668 if (ui.messageLog->property("shouldAutoScroll").toBool()) { |
679 if (ui.messageLog->property("shouldAutoScroll").toBool()) { |
669 ui.messageLog->scrollToBottom(); |
680 ui.messageLog->scrollToBottom(); |
670 } |
681 } |
671 }); |
682 }); |
|
683 QObject::connect( |
|
684 toolWidgets.circleToolOptions, |
|
685 &CircleToolOptionsWidget::optionsChanged, |
|
686 [&ui, &documents](const CircleToolOptions& options) { |
|
687 if (ModelData* data = currentModelData(&ui, &documents)) { |
|
688 data->tools->setCircleToolOptions(options); |
|
689 } |
|
690 }); |
672 mainWindow.setWindowTitle(title()); |
691 mainWindow.setWindowTitle(title()); |
673 mainWindow.tabifyDockWidget(ui.messageLogDock, ui.toolOptionsDock); |
692 mainWindow.tabifyDockWidget(ui.messageLogDock, ui.toolOptionsDock); |
674 mainWindow.restoreGeometry(setting<Setting::MainWindowGeometry>()); |
693 mainWindow.restoreGeometry(setting<Setting::MainWindowGeometry>()); |
675 mainWindow.restoreState(setting<Setting::MainWindowState>()); |
694 mainWindow.restoreState(setting<Setting::MainWindowState>()); |
676 // If a dock is made floating and the app is closed, the dock becomes invisible |
695 // If a dock is made floating and the app is closed, the dock becomes invisible |