476 action->setEnabled(hasDocument); |
476 action->setEnabled(hasDocument); |
477 action->setChecked(hasDocument and action->data().value<EditingMode>() == mode); |
477 action->setChecked(hasDocument and action->data().value<EditingMode>() == mode); |
478 } |
478 } |
479 } |
479 } |
480 |
480 |
|
481 static void update_model_grid_matrix(MainState* state) |
|
482 { |
|
483 const glm::mat4 new_grid_matrix = state->mainWindow.gridMatrix->value(); |
|
484 forEachModel(&state->documents, [&](const void*, const ModelData* data) |
|
485 { |
|
486 if (data->gridLayer != nullptr and data->tools != nullptr and data->canvas != nullptr) |
|
487 { |
|
488 data->gridLayer->setGridMatrix(new_grid_matrix); |
|
489 data->tools->setGridMatrix(new_grid_matrix); |
|
490 data->canvas->setModelViewOrigin(new_grid_matrix[3]); |
|
491 data->canvas->update(); |
|
492 } |
|
493 }); |
|
494 } |
|
495 |
|
496 static void set_grid_scale(MainState* state, const float factor) |
|
497 { |
|
498 const glm::mat4 original = state->mainWindow.gridMatrix->value(); |
|
499 const glm::mat4 unscaled = extractScaling(original).unscaled; |
|
500 const glm::mat4 rescaled = factor * unscaled; |
|
501 state->mainWindow.gridMatrix->setValue(rescaled); |
|
502 update_model_grid_matrix(state); |
|
503 } |
|
504 |
481 int main(int argc, char *argv[]) |
505 int main(int argc, char *argv[]) |
482 { |
506 { |
483 doQtRegistrations(); |
507 doQtRegistrations(); |
484 QApplication app{argc, argv}; |
508 QApplication app{argc, argv}; |
485 QApplication::setWindowIcon(QIcon{":/icons/appicon.png"}); |
509 QApplication::setWindowIcon(QIcon{":/icons/appicon.png"}); |
653 } |
677 } |
654 }); |
678 }); |
655 QObject::connect( |
679 QObject::connect( |
656 state.mainWindow.gridMatrix, |
680 state.mainWindow.gridMatrix, |
657 &MatrixEditor::valueChanged, |
681 &MatrixEditor::valueChanged, |
658 [&](const glm::mat4& newGridMatrix) |
682 [&state] |
659 { |
683 { |
660 forEachModel(&state.documents, [&](const void*, const ModelData* data) |
684 update_model_grid_matrix(&state); |
661 { |
|
662 if (data->gridLayer != nullptr and data->tools != nullptr and data->canvas != nullptr) |
|
663 { |
|
664 data->gridLayer->setGridMatrix(newGridMatrix); |
|
665 data->tools->setGridMatrix(newGridMatrix); |
|
666 data->canvas->setModelViewOrigin(newGridMatrix[3]); |
|
667 data->canvas->update(); |
|
668 } |
|
669 }); |
|
670 } |
685 } |
671 ); |
686 ); |
672 QObject::connect( |
687 QObject::connect( |
673 state.mainWindow.actionDelete, |
688 state.mainWindow.actionDelete, |
674 &QAction::triggered, |
689 &QAction::triggered, |
675 [&state]{ |
690 [&state]{ |
676 QTextCursor cursor = state.mainWindow.modelEdit->textCursor(); |
691 QTextCursor cursor = state.mainWindow.modelEdit->textCursor(); |
677 cursor.removeSelectedText(); |
692 cursor.removeSelectedText(); |
|
693 } |
|
694 ); |
|
695 QObject::connect( |
|
696 state.mainWindow.actionGridCoarse, |
|
697 &QAction::triggered, |
|
698 [&state]{ |
|
699 set_grid_scale(&state, 5.0f); |
|
700 } |
|
701 ); |
|
702 QObject::connect( |
|
703 state.mainWindow.actionGridMedium, |
|
704 &QAction::triggered, |
|
705 [&state]{ |
|
706 set_grid_scale(&state, 1.0f); |
|
707 } |
|
708 ); |
|
709 QObject::connect( |
|
710 state.mainWindow.actionGridFine, |
|
711 &QAction::triggered, |
|
712 [&state]{ |
|
713 set_grid_scale(&state, 0.1f); |
678 } |
714 } |
679 ); |
715 ); |
680 restoreSettings(&state); |
716 restoreSettings(&state); |
681 updateRenderPreferences(&state.mainWindow, &state.renderPreferences, &state.documents); |
717 updateRenderPreferences(&state.mainWindow, &state.renderPreferences, &state.documents); |
682 const int result = app.exec(); |
718 const int result = app.exec(); |