diff --git a/src/Gui/PythonConsole.cpp b/src/Gui/PythonConsole.cpp index ceb206b69d..022402722e 100644 --- a/src/Gui/PythonConsole.cpp +++ b/src/Gui/PythonConsole.cpp @@ -95,27 +95,12 @@ struct PythonConsoleP QString output, error, info, historyFile; QStringList statements; bool interactive; - QMap colormap; // Color map ParameterGrp::handle hGrpSettings; PythonConsoleP() { type = Normal; interactive = false; historyFile = QString::fromUtf8((App::Application::getUserAppDataDir() + "PythonHistory.log").c_str()); - colormap[QLatin1String("Text")] = qApp->palette().windowText().color(); - colormap[QLatin1String("Bookmark")] = Qt::cyan; - colormap[QLatin1String("Breakpoint")] = Qt::red; - colormap[QLatin1String("Keyword")] = Qt::blue; - colormap[QLatin1String("Comment")] = QColor(0, 170, 0); - colormap[QLatin1String("Block comment")] = QColor(160, 160, 164); - colormap[QLatin1String("Number")] = Qt::blue; - colormap[QLatin1String("String")] = Qt::red; - colormap[QLatin1String("Character")] = Qt::red; - colormap[QLatin1String("Class name")] = QColor(255, 170, 0); - colormap[QLatin1String("Define name")] = QColor(255, 170, 0); - colormap[QLatin1String("Operator")] = QColor(160, 160, 164); - colormap[QLatin1String("Python output")] = QColor(170, 170, 127); - colormap[QLatin1String("Python error")] = Qt::red; } }; @@ -522,7 +507,7 @@ PythonConsole::~PythonConsole() } /** Set new font and colors according to the parameters. */ -void PythonConsole::OnChange(Base::Subject &rCaller, const char* sReason ) +void PythonConsole::OnChange(Base::Subject &rCaller, const char* sReason) { const auto & rGrp = static_cast(rCaller); @@ -536,33 +521,6 @@ void PythonConsole::OnChange(Base::Subject &rCaller, const char* sR } } - if (strcmp(sReason, "FontSize") == 0 || strcmp(sReason, "Font") == 0) { - int fontSize = rGrp.GetInt("FontSize", 10); - QString fontFamily = QString::fromLatin1(rGrp.GetASCII("Font", "Courier").c_str()); - - QFont font(fontFamily, fontSize); - setFont(font); - QFontMetrics metric(font); - int width = QtTools::horizontalAdvance(metric, QLatin1String("0000")); -#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0) - setTabStopWidth(width); -#else - setTabStopDistance(width); -#endif - } - else { - QMap::Iterator it = d->colormap.find(QString::fromLatin1(sReason)); - if (it != d->colormap.end()) { - QColor color = it.value(); - unsigned int col = App::Color::asPackedRGB(color); - auto value = static_cast(col); - value = rGrp.GetUnsigned(sReason, value); - col = static_cast(value); - color.setRgb((col>>24)&0xff, (col>>16)&0xff, (col>>8)&0xff); - pythonSyntax->setColor(QString::fromLatin1(sReason), color); - } - } - if (strcmp(sReason, "PythonBlockCursor") == 0) { bool block = rGrp.GetBool("PythonBlockCursor", false); if (block) { @@ -572,6 +530,10 @@ void PythonConsole::OnChange(Base::Subject &rCaller, const char* sR setCursorWidth(1); } } + + if (strcmp(sReason, "EnableLineNumber") != 0) { + TextEditor::OnChange(rCaller, sReason); + } } /** diff --git a/src/Gui/PythonEditor.cpp b/src/Gui/PythonEditor.cpp index 4ec20d6dad..04f4f5dfc2 100644 --- a/src/Gui/PythonEditor.cpp +++ b/src/Gui/PythonEditor.cpp @@ -87,6 +87,25 @@ PythonEditor::~PythonEditor() delete d; } +void PythonEditor::OnChange(Base::Subject &rCaller, const char* sReason) +{ + const auto & rGrp = static_cast(rCaller); + + if (strcmp(sReason, "EnableBlockCursor") == 0 || + strcmp(sReason, "FontSize") == 0 || + strcmp(sReason, "Font") == 0) { + bool block = rGrp.GetBool("EnableBlockCursor", false); + if (block) { + setCursorWidth(QFontMetrics(font()).averageCharWidth()); + } + else { + setCursorWidth(1); + } + } + + TextEditor::OnChange(rCaller, sReason); +} + void PythonEditor::setFileName(const QString& fn) { d->filename = fn; diff --git a/src/Gui/PythonEditor.h b/src/Gui/PythonEditor.h index 8e442c9d46..432975d9df 100644 --- a/src/Gui/PythonEditor.h +++ b/src/Gui/PythonEditor.h @@ -44,6 +44,7 @@ public: explicit PythonEditor(QWidget *parent = nullptr); ~PythonEditor() override; + void OnChange( Base::Subject &rCaller,const char* rcReason ) override; void toggleBreakpoint(); void showDebugMarker(int line); void hideDebugMarker(); diff --git a/src/Gui/TextEdit.cpp b/src/Gui/TextEdit.cpp index 90dd2acc6c..64c7d56982 100644 --- a/src/Gui/TextEdit.cpp +++ b/src/Gui/TextEdit.cpp @@ -441,18 +441,6 @@ void TextEditor::OnChange(Base::Subject &rCaller,const char* sReaso } lineNumberArea->setGeometry(QRect(cr.left(), cr.top(), width, cr.height())); } - - if (strcmp(sReason, "EnableBlockCursor") == 0 || - strcmp(sReason, "FontSize") == 0 || - strcmp(sReason, "Font") == 0) { - bool block = hPrefGrp->GetBool("EnableBlockCursor", false); - if (block) { - setCursorWidth(QFontMetrics(font()).averageCharWidth()); - } - else { - setCursorWidth(1); - } - } } // ------------------------------------------------------------------------------