Sat, 08 Apr 2023 21:48:49 +0300
Made editor font configurable
Add grid matrix editor
--- 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<Setting::CodeEditorUseSystemFont>()) + { + font.setStyleHint(QFont::Monospace); + } + else + { + font.setFamily(setting<Setting::CodeEditorFontFamily>()); + font.setPointSize(setting<Setting::CodeEditorFontSize>()); + } + 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<EditTools>(); data->canvas = std::make_unique<PartRenderer>(model, &documents, colorTable); data->axesLayer = std::make_unique<AxesLayer>(); - 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<GridLayer>(); - 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<Setting::DrawAxes>()); @@ -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<Setting::MainWindowGeometry>()); mainWindow.restoreState(setting<Setting::MainWindowState>());
--- 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 @@ <x>0</x> <y>0</y> <width>959</width> - <height>600</height> + <height>695</height> </rect> </property> <property name="dockNestingEnabled"> @@ -45,7 +45,7 @@ <x>0</x> <y>0</y> <width>959</width> - <height>29</height> + <height>38</height> </rect> </property> <widget class="QMenu" name="menuFile"> @@ -265,6 +265,54 @@ <addaction name="actionGridCoarse"/> <addaction name="actionAdjustGridToView"/> </widget> + <widget class="QDockWidget" name="dockWidget"> + <property name="features"> + <set>QDockWidget::DockWidgetFloatable|QDockWidget::DockWidgetMovable</set> + </property> + <property name="windowTitle"> + <string>Grid matrix</string> + </property> + <attribute name="dockWidgetArea"> + <number>2</number> + </attribute> + <widget class="QWidget" name="dockWidgetContents_4"> + <layout class="QVBoxLayout" name="verticalLayout_5"> + <item> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="MatrixEditor" name="gridMatrix"/> + </item> + <item> + <spacer name="horizontalSpacer"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + </layout> + </item> + <item> + <spacer name="verticalSpacer"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>40</height> + </size> + </property> + </spacer> + </item> + </layout> + </widget> + </widget> <action name="actionQuit"> <property name="icon"> <iconset resource="../resources.qrc"> @@ -547,6 +595,13 @@ </property> </action> </widget> + <customwidgets> + <customwidget> + <class>MatrixEditor</class> + <extends>QWidget</extends> + <header>widgets/matrixeditor.h</header> + </customwidget> + </customwidgets> <resources> <include location="../resources.qrc"/> <include location="../resources.qrc"/>
--- 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{})
--- 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<Setting::LineThickness>(static_cast<GLfloat>(this->ui.lineThickness->value())); setSetting<Setting::LineAntiAliasing>(this->ui.lineAntiAliasing->isChecked()); setSetting<Setting::LogOpenGLDebugMessages>(this->ui.logOpenGLDebugMessages->isChecked()); + setSetting<Setting::CodeEditorUseSystemFont>(this->ui.codeEditorSystemFont->isChecked()); + setSetting<Setting::CodeEditorFontFamily>(this->ui.codeEditorFontFamily->currentText()); + setSetting<Setting::CodeEditorFontSize>(this->ui.codeEditorFontSize->value()); const int viewMode = this->ui.viewModeButtonGroup->checkedId(); if (viewMode != -1) { setSetting<Setting::ViewMode>(static_cast<QMdiArea::ViewMode>(viewMode)); @@ -127,6 +139,9 @@ this->ui.lineThickness->setValue(double_cast(setting<Setting::LineThickness>())); this->ui.lineAntiAliasing->setChecked(setting<Setting::LineAntiAliasing>()); this->ui.logOpenGLDebugMessages->setChecked(setting<Setting::LogOpenGLDebugMessages>()); + this->ui.codeEditorSystemFont->setChecked(setting<Setting::CodeEditorUseSystemFont>()); + this->ui.codeEditorFontFamily->setCurrentText(setting<Setting::CodeEditorFontFamily>()); + this->ui.codeEditorFontSize->setValue(setting<Setting::CodeEditorFontSize>()); auto* const viewModeButton = this->ui.viewModeButtonGroup->button(setting<Setting::ViewMode>()); if (viewModeButton != nullptr) { viewModeButton->setChecked(true);
--- 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 @@ <rect> <x>0</x> <y>0</y> - <width>694</width> - <height>558</height> + <width>680</width> + <height>560</height> </rect> </property> <layout class="QVBoxLayout" name="verticalLayout"> @@ -176,6 +176,66 @@ </item> </layout> </widget> + <widget class="QWidget" name="tab_3"> + <attribute name="title"> + <string>Code editor</string> + </attribute> + <layout class="QVBoxLayout" name="verticalLayout_6"> + <item> + <widget class="QGroupBox" name="groupBox_3"> + <property name="title"> + <string>Editor font</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout_5"> + <item> + <widget class="QCheckBox" name="codeEditorSystemFont"> + <property name="text"> + <string>Use system font</string> + </property> + </widget> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_2" stretch="1,0"> + <item> + <widget class="QFontComboBox" name="codeEditorFontFamily"> + <property name="fontFilters"> + <set>QFontComboBox::MonospacedFonts</set> + </property> + </widget> + </item> + <item> + <widget class="QSpinBox" name="codeEditorFontSize"> + <property name="suffix"> + <string>pt</string> + </property> + <property name="minimum"> + <number>4</number> + </property> + <property name="maximum"> + <number>100</number> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </widget> + </item> + <item> + <spacer name="verticalSpacer_3"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>263</height> + </size> + </property> + </spacer> + </item> + </layout> + </widget> <widget class="QWidget" name="tabLdrawLibraries"> <attribute name="title"> <string>LDraw parts libraries</string> @@ -252,8 +312,8 @@ <customwidgets> <customwidget> <class>ColorEdit</class> - <extends>QPushButton</extends> - <header>widgets/colorbutton.h</header> + <extends>QWidget</extends> + <header>widgets/coloredit.h</header> </customwidget> </customwidgets> <resources/>