# HG changeset patch # User Teemu Piippo # Date 1680979729 -10800 # Node ID 65b4741b302d75761addf0ea5491cbbd8c74371b # Parent e81f4ad53efd146fafbabdc642adf1bbf8f3c54d Made editor font configurable Add grid matrix editor diff -r e81f4ad53efd -r 65b4741b302d src/main.cpp --- a/src/main.cpp Sat Apr 08 16:59:55 2023 +0300 +++ b/src/main.cpp Sat Apr 08 21:48:49 2023 +0300 @@ -323,6 +323,23 @@ }, action); } +QFont codeEditorFontFromSettings() +{ + QFont font{}; + if (setting()) + { + font.setStyleHint(QFont::Monospace); + } + else + { + font.setFamily(setting()); + font.setPointSize(setting()); + } + return font; +} + +constexpr glm::mat4 DEFAULT_GRID_MATRIX = {{1, 0, 0, 0}, {0, 0, 1, 0}, {0, 1, 0, 0}, {0, 0, 0, 1}}; + int main(int argc, char *argv[]) { doQtRegistrations(); @@ -377,10 +394,9 @@ data->tools = std::make_unique(); data->canvas = std::make_unique(model, &documents, colorTable); data->axesLayer = std::make_unique(); - constexpr glm::mat4 XZ = {{1, 0, 0, 0}, {0, 0, 1, 0}, {0, 1, 0, 0}, {0, 0, 0, 1}}; data->gridLayer = std::make_unique(); - data->gridLayer->setGridMatrix(XZ); - data->tools->setGridMatrix(XZ); + data->gridLayer->setGridMatrix(DEFAULT_GRID_MATRIX); + data->tools->setGridMatrix(DEFAULT_GRID_MATRIX); data->model = model; data->canvas->addRenderLayer(data->axesLayer.get()); data->canvas->setLayerEnabled(data->axesLayer.get(), setting()); @@ -669,6 +685,7 @@ checkEditingModeAction(data->tools->currentEditingMode()); mainWindow.modelEdit->setDocument(data->model); mainWindow.modelEdit->setTextCursor(*data->textcursor); + mainWindow.modelEdit->setFont(codeEditorFontFromSettings()); } } else { @@ -718,6 +735,23 @@ data->canvas->update(); } }); + QObject::connect( + mainWindow.gridMatrix, + &MatrixEditor::valueChanged, + [&](const glm::mat4& newGridMatrix) + { + forEachModel(&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->update(); + } + }); + } + ); + mainWindow.gridMatrix->setValue(DEFAULT_GRID_MATRIX); mainWindow.tabifyDockWidget(mainWindow.messageLogDock, mainWindow.toolOptionsDock); mainWindow.restoreGeometry(setting()); mainWindow.restoreState(setting()); diff -r e81f4ad53efd -r 65b4741b302d src/mainwindow.ui --- a/src/mainwindow.ui Sat Apr 08 16:59:55 2023 +0300 +++ b/src/mainwindow.ui Sat Apr 08 21:48:49 2023 +0300 @@ -7,7 +7,7 @@ 0 0 959 - 600 + 695 @@ -45,7 +45,7 @@ 0 0 959 - 29 + 38 @@ -265,6 +265,54 @@ + + + QDockWidget::DockWidgetFloatable|QDockWidget::DockWidgetMovable + + + Grid matrix + + + 2 + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + @@ -547,6 +595,13 @@ + + + MatrixEditor + QWidget +
widgets/matrixeditor.h
+
+
diff -r e81f4ad53efd -r 65b4741b302d src/settings.h --- a/src/settings.h Sat Apr 08 16:59:55 2023 +0300 +++ b/src/settings.h Sat Apr 08 21:48:49 2023 +0300 @@ -44,6 +44,11 @@ SETTING(LogOpenGLDebugMessages, false) SETTING(ToolButtonStyle, Qt::ToolButtonFollowStyle) +// Code editor options +SETTING(CodeEditorUseSystemFont, bool{true}) +SETTING(CodeEditorFontFamily, QString{""}) +SETTING(CodeEditorFontSize, int{10}) + // File management options SETTING(Libraries, Libraries{}) diff -r e81f4ad53efd -r 65b4741b302d src/settingseditor/settingseditor.cpp --- a/src/settingseditor/settingseditor.cpp Sat Apr 08 16:59:55 2023 +0300 +++ b/src/settingseditor/settingseditor.cpp Sat Apr 08 21:48:49 2023 +0300 @@ -46,6 +46,15 @@ this->ui.toolButtonStyle->addItem(tr("Text beside icon"), Qt::ToolButtonTextBesideIcon); this->ui.toolButtonStyle->addItem(tr("Text under icon"), Qt::ToolButtonTextUnderIcon); this->ui.toolButtonStyle->addItem(tr("Style default"), Qt::ToolButtonFollowStyle); + connect( + this->ui.codeEditorSystemFont, + &QCheckBox::stateChanged, + [this](int state){ + const bool checked = (state == Qt::Checked); + this->ui.codeEditorFontFamily->setEnabled(not checked); + this->ui.codeEditorFontSize->setEnabled(not checked); + } + ); this->loadSettings(); this->setWindowTitle(tr("Settings")); this->setWindowIcon(QIcon{":/icons/settings-outline.png"}); @@ -105,6 +114,9 @@ setSetting(static_cast(this->ui.lineThickness->value())); setSetting(this->ui.lineAntiAliasing->isChecked()); setSetting(this->ui.logOpenGLDebugMessages->isChecked()); + setSetting(this->ui.codeEditorSystemFont->isChecked()); + setSetting(this->ui.codeEditorFontFamily->currentText()); + setSetting(this->ui.codeEditorFontSize->value()); const int viewMode = this->ui.viewModeButtonGroup->checkedId(); if (viewMode != -1) { setSetting(static_cast(viewMode)); @@ -127,6 +139,9 @@ this->ui.lineThickness->setValue(double_cast(setting())); this->ui.lineAntiAliasing->setChecked(setting()); this->ui.logOpenGLDebugMessages->setChecked(setting()); + this->ui.codeEditorSystemFont->setChecked(setting()); + this->ui.codeEditorFontFamily->setCurrentText(setting()); + this->ui.codeEditorFontSize->setValue(setting()); auto* const viewModeButton = this->ui.viewModeButtonGroup->button(setting()); if (viewModeButton != nullptr) { viewModeButton->setChecked(true); diff -r e81f4ad53efd -r 65b4741b302d src/settingseditor/settingseditor.ui --- a/src/settingseditor/settingseditor.ui Sat Apr 08 16:59:55 2023 +0300 +++ b/src/settingseditor/settingseditor.ui Sat Apr 08 21:48:49 2023 +0300 @@ -30,8 +30,8 @@ 0 0 - 694 - 558 + 680 + 560 @@ -176,6 +176,66 @@ + + + Code editor + + + + + + Editor font + + + + + + Use system font + + + + + + + + + QFontComboBox::MonospacedFonts + + + + + + + pt + + + 4 + + + 100 + + + + + + + + + + + + Qt::Vertical + + + + 20 + 263 + + + + + + LDraw parts libraries @@ -252,8 +312,8 @@ ColorEdit - QPushButton -
widgets/colorbutton.h
+ QWidget +
widgets/coloredit.h