Mon, 10 Apr 2023 14:18:11 +0300
Grid scaling buttons now work
src/main.cpp | file | annotate | diff | comparison | revisions | |
src/mainwindow.ui | file | annotate | diff | comparison | revisions |
--- a/src/main.cpp Mon Apr 10 12:40:49 2023 +0300 +++ b/src/main.cpp Mon Apr 10 14:18:11 2023 +0300 @@ -478,6 +478,30 @@ } } +static void update_model_grid_matrix(MainState* state) +{ + const glm::mat4 new_grid_matrix = state->mainWindow.gridMatrix->value(); + forEachModel(&state->documents, [&](const void*, const ModelData* data) + { + if (data->gridLayer != nullptr and data->tools != nullptr and data->canvas != nullptr) + { + data->gridLayer->setGridMatrix(new_grid_matrix); + data->tools->setGridMatrix(new_grid_matrix); + data->canvas->setModelViewOrigin(new_grid_matrix[3]); + data->canvas->update(); + } + }); +} + +static void set_grid_scale(MainState* state, const float factor) +{ + const glm::mat4 original = state->mainWindow.gridMatrix->value(); + const glm::mat4 unscaled = extractScaling(original).unscaled; + const glm::mat4 rescaled = factor * unscaled; + state->mainWindow.gridMatrix->setValue(rescaled); + update_model_grid_matrix(state); +} + int main(int argc, char *argv[]) { doQtRegistrations(); @@ -655,18 +679,9 @@ QObject::connect( state.mainWindow.gridMatrix, &MatrixEditor::valueChanged, - [&](const glm::mat4& newGridMatrix) + [&state] { - forEachModel(&state.documents, [&](const void*, const ModelData* data) - { - if (data->gridLayer != nullptr and data->tools != nullptr and data->canvas != nullptr) - { - data->gridLayer->setGridMatrix(newGridMatrix); - data->tools->setGridMatrix(newGridMatrix); - data->canvas->setModelViewOrigin(newGridMatrix[3]); - data->canvas->update(); - } - }); + update_model_grid_matrix(&state); } ); QObject::connect( @@ -677,6 +692,27 @@ cursor.removeSelectedText(); } ); + QObject::connect( + state.mainWindow.actionGridCoarse, + &QAction::triggered, + [&state]{ + set_grid_scale(&state, 5.0f); + } + ); + QObject::connect( + state.mainWindow.actionGridMedium, + &QAction::triggered, + [&state]{ + set_grid_scale(&state, 1.0f); + } + ); + QObject::connect( + state.mainWindow.actionGridFine, + &QAction::triggered, + [&state]{ + set_grid_scale(&state, 0.1f); + } + ); restoreSettings(&state); updateRenderPreferences(&state.mainWindow, &state.renderPreferences, &state.documents); const int result = app.exec();
--- a/src/mainwindow.ui Mon Apr 10 12:40:49 2023 +0300 +++ b/src/mainwindow.ui Mon Apr 10 14:18:11 2023 +0300 @@ -482,34 +482,34 @@ </property> </action> <action name="actionGridFine"> - <property name="checkable"> - <bool>true</bool> - </property> <property name="text"> <string>Fine grid</string> </property> + <property name="toolTip"> + <string>Set grid scaling to 0.1</string> + </property> <property name="shortcut"> <string>Ctrl+1</string> </property> </action> <action name="actionGridMedium"> - <property name="checkable"> - <bool>true</bool> - </property> <property name="text"> <string>Medium grid</string> </property> + <property name="toolTip"> + <string>Set grid scaling to 1</string> + </property> <property name="shortcut"> <string>Ctrl+2</string> </property> </action> <action name="actionGridCoarse"> - <property name="checkable"> - <bool>true</bool> - </property> <property name="text"> <string>Coarse grid</string> </property> + <property name="toolTip"> + <string>Set grid scaling to 5</string> + </property> <property name="shortcut"> <string>Ctrl+3</string> </property>