--- a/src/main.cpp Mon Apr 10 14:46:36 2023 +0300 +++ b/src/main.cpp Tue Apr 11 11:11:28 2023 +0300 @@ -238,7 +238,7 @@ QAction* action = new QAction{editingModeInfo.name, parent}; action->setCheckable(true); action->setEnabled(false); - action->setData(static_cast<EditingMode>(i)); + action->setData(QVariant::fromValue(static_cast<editing_mode_e>(i))); action->setToolTip(editingModeInfo.tooltip); action->setIcon(QPixmap{editingModeInfo.icon}); ui->editingModesToolBar->addAction(action); @@ -371,7 +371,7 @@ &EditTools::suggestCursor, data->canvas.get(), &QWidget::setCursor); - data->tools->setEditMode(SelectMode); + data->tools->setEditMode(editing_mode_e::select); const QFileInfo fileInfo{*state->documents.modelPath(modelId)}; auto* const subWindow = createSubWindow<ModelSubWindow>(state->mainWindow.mdiArea, modelId); subWindow->setMinimumSize({96, 96}); @@ -468,13 +468,13 @@ } } -static void checkEditingModeAction(MainState* state, const EditingMode mode) +static void checkEditingModeAction(MainState* state, const editing_mode_e mode) { const bool hasDocument = currentModelData(&state->mainWindow, &state->documents) != nullptr; for (QAction* action : state->mainWindow.editingModesToolBar->actions()) { action->setEnabled(hasDocument); - action->setChecked(hasDocument and action->data().value<EditingMode>() == mode); + action->setChecked(hasDocument and action->data().value<editing_mode_e>() == mode); } } @@ -502,6 +502,18 @@ update_model_grid_matrix(state); } +static void replace_color_in_selected_code(QTextCursor* cursor, const ColorIndex color) +{ + const auto pattern = R"(^(\s*(?:1|2|3|4|5)\s+)\d+)"; + static const QRegularExpression regular_expression{pattern, QRegularExpression::MultilineOption}; + QString text = cursor->selectedText(); + // Qt has decided to be "smart" and uses strange unicode characters instead of newlines + text.replace("\u2029", "\n"); + text.replace(regular_expression, QStringLiteral(R"(\1%1)").arg(color.index)); + cursor->removeSelectedText(); + cursor->insertText(text); +} + int main(int argc, char *argv[]) { doQtRegistrations(); @@ -609,7 +621,7 @@ { if (ModelData* data = currentModelData(&state.mainWindow, &state.documents)) { - const EditingMode mode = action->data().value<EditingMode>(); + const editing_mode_e mode = action->data().value<editing_mode_e>(); data->tools->setEditMode(mode); checkEditingModeAction(&state, mode); } @@ -631,7 +643,7 @@ } else { - checkEditingModeAction(&state, EditingMode::SelectMode); + checkEditingModeAction(&state, editing_mode_e::select); } state.mainWindow.modelEdit->setEnabled(modelSubWindow != nullptr); }); @@ -713,6 +725,14 @@ set_grid_scale(&state, 0.1f); } ); + QObject::connect( + state.mainWindow.action_make_stuff_red, + &QAction::triggered, + [&state]{ + QTextCursor cursor = state.mainWindow.modelEdit->textCursor(); + replace_color_in_selected_code(&cursor, ColorIndex{4}); + } + ); restoreSettings(&state); updateRenderPreferences(&state.mainWindow, &state.renderPreferences, &state.documents); const int result = app.exec();