From a91f5e7352ac2af01450aeb2a852641687c1e8d9 Mon Sep 17 00:00:00 2001 From: wmayer Date: Fri, 22 Apr 2022 14:33:44 +0200 Subject: [PATCH] Gui: do not reset tab size to 4 when creating new text editor --- src/Gui/DlgEditorImp.cpp | 15 +++++++++++++++ src/Gui/DlgEditorImp.h | 1 + src/Gui/TextEdit.cpp | 2 -- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/Gui/DlgEditorImp.cpp b/src/Gui/DlgEditorImp.cpp index f9963a829a..e7c45c52cd 100644 --- a/src/Gui/DlgEditorImp.cpp +++ b/src/Gui/DlgEditorImp.cpp @@ -29,6 +29,7 @@ #include "DlgEditorImp.h" #include "ui_DlgEditor.h" #include "PythonEditor.h" +#include "Tools.h" using namespace Gui; @@ -169,6 +170,17 @@ void DlgSettingsEditorImp::on_colorButton_changed() pythonSyntax->setColor( d->colormap[index].first, col ); } +void DlgSettingsEditorImp::setEditorTabWidth(int tabWidth) +{ + QFontMetrics metric(font()); + int fontSize = QtTools::horizontalAdvance(metric, QLatin1Char('0')); +#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0) + ui->textEdit1->setTabStopWidth(tabWidth * fontSize); +#else + ui->textEdit1->setTabStopDistance(tabWidth * fontSize); +#endif +} + void DlgSettingsEditorImp::saveSettings() { ui->EnableLineNumber->onSave(); @@ -188,6 +200,8 @@ void DlgSettingsEditorImp::saveSettings() hGrp->SetInt( "FontSize", ui->fontSize->value() ); hGrp->SetASCII( "Font", ui->fontFamily->currentText().toLatin1() ); + + setEditorTabWidth(ui->tabSize->value()); } void DlgSettingsEditorImp::loadSettings() @@ -200,6 +214,7 @@ void DlgSettingsEditorImp::loadSettings() ui->radioTabs->onRestore(); ui->radioSpaces->onRestore(); + setEditorTabWidth(ui->tabSize->value()); ui->textEdit1->setPlainText(QString::fromLatin1( "# Short Python sample\n" "import sys\n" diff --git a/src/Gui/DlgEditorImp.h b/src/Gui/DlgEditorImp.h index 70fa688e38..bf747c7e5b 100644 --- a/src/Gui/DlgEditorImp.h +++ b/src/Gui/DlgEditorImp.h @@ -60,6 +60,7 @@ protected Q_SLOTS: protected: void changeEvent(QEvent *e); + void setEditorTabWidth(int); private: std::unique_ptr ui; diff --git a/src/Gui/TextEdit.cpp b/src/Gui/TextEdit.cpp index 77c3826240..f47ef2f87b 100644 --- a/src/Gui/TextEdit.cpp +++ b/src/Gui/TextEdit.cpp @@ -228,8 +228,6 @@ TextEditor::TextEditor(QWidget* parent) setFont(serifFont); ParameterGrp::handle hPrefGrp = getWindowParameter(); - // set default to 4 characters - hPrefGrp->SetInt( "TabSize", 4 ); hPrefGrp->Attach( this ); // set colors and font