diff --git a/src/plugins/cppeditor/cppeditor.cpp b/src/plugins/cppeditor/cppeditor.cpp index f70a3a835bb..2588ce40b24 100644 --- a/src/plugins/cppeditor/cppeditor.cpp +++ b/src/plugins/cppeditor/cppeditor.cpp @@ -1534,11 +1534,6 @@ TextEditor::CompletionAssistProvider *CPPEditor::completionAssistProvider() void CPPEditorWidget::applyFontSettings() { - TextEditor::BaseTextEditorWidget::applyFontSettings(); - TextEditor::SyntaxHighlighter *highlighter = baseTextDocument()->syntaxHighlighter(); - if (!highlighter) - return; - const TextEditor::FontSettings &fs = baseTextDocument()->fontSettings(); m_semanticHighlightFormatMap[CppHighlightingSupport::TypeUse] = @@ -1562,16 +1557,8 @@ void CPPEditorWidget::applyFontSettings() m_semanticHighlightFormatMap[CppHighlightingSupport::StringUse] = fs.toTextCharFormat(TextEditor::C_STRING); - // Clear all additional formats since they may have changed - QTextBlock b = document()->firstBlock(); - while (b.isValid()) { - QList noFormats; - highlighter->setExtraAdditionalFormats(b, noFormats); - b = b.next(); - } - - // This also triggers an update of the additional formats - highlighter->rehighlight(); + // this also makes the document apply font settings + TextEditor::BaseTextEditorWidget::applyFontSettings(); } void CPPEditorWidget::unCommentSelection() @@ -2016,6 +2003,20 @@ CPPEditorDocument::CPPEditorDocument() this, SLOT(invalidateFormatterCache())); } +void CPPEditorDocument::applyFontSettings() +{ + if (TextEditor::SyntaxHighlighter *highlighter = syntaxHighlighter()) { + // Clear all additional formats since they may have changed + QTextBlock b = document()->firstBlock(); + while (b.isValid()) { + QList noFormats; + highlighter->setExtraAdditionalFormats(b, noFormats); + b = b.next(); + } + } + BaseTextDocument::applyFontSettings(); // rehighlights and updates additional formats +} + void CPPEditorDocument::invalidateFormatterCache() { CppTools::QtStyleCodeFormatter formatter; diff --git a/src/plugins/cppeditor/cppeditor.h b/src/plugins/cppeditor/cppeditor.h index 475e99e78cc..b6103acd262 100644 --- a/src/plugins/cppeditor/cppeditor.h +++ b/src/plugins/cppeditor/cppeditor.h @@ -77,6 +77,9 @@ class CPPEditorDocument : public TextEditor::BaseTextDocument public: CPPEditorDocument(); +protected: + void applyFontSettings(); + private slots: void invalidateFormatterCache(); }; diff --git a/src/plugins/pythoneditor/pythoneditorwidget.cpp b/src/plugins/pythoneditor/pythoneditorwidget.cpp index d93dc66e3df..e263ed445b3 100644 --- a/src/plugins/pythoneditor/pythoneditorwidget.cpp +++ b/src/plugins/pythoneditor/pythoneditorwidget.cpp @@ -85,20 +85,6 @@ void EditorWidget::unCommentSelection() Utils::unCommentSelection(this, m_commentDefinition); } -/** - Handles common IDE fonts&colors settings - (Tools -> Options -> Text editor -> Fonts and colors) - */ -void EditorWidget::applyFontSettings() -{ - TextEditor::BaseTextEditorWidget::applyFontSettings(); - - PythonHighlighter *highlighter = - qobject_cast(baseTextDocument()->syntaxHighlighter()); - if (highlighter) - highlighter->setFontSettings(baseTextDocument()->fontSettings()); -} - TextEditor::BaseTextEditor *EditorWidget::createEditor() { return new PythonEditor(this); diff --git a/src/plugins/pythoneditor/pythoneditorwidget.h b/src/plugins/pythoneditor/pythoneditorwidget.h index ad9fc5894eb..f9422d23a55 100644 --- a/src/plugins/pythoneditor/pythoneditorwidget.h +++ b/src/plugins/pythoneditor/pythoneditorwidget.h @@ -48,7 +48,6 @@ public: virtual void unCommentSelection(); protected: - void applyFontSettings(); TextEditor::BaseTextEditor *createEditor(); private: diff --git a/src/plugins/texteditor/basetextdocument.cpp b/src/plugins/texteditor/basetextdocument.cpp index 5002463be21..ae7b1ee70f7 100644 --- a/src/plugins/texteditor/basetextdocument.cpp +++ b/src/plugins/texteditor/basetextdocument.cpp @@ -79,6 +79,7 @@ public: TabSettings m_tabSettings; ExtraEncodingSettings m_extraEncodingSettings; FontSettings m_fontSettings; + bool m_fontSettingsNeedsApply; // for applying font settings delayed till an editor becomes visible QTextDocument *m_document; SyntaxHighlighter *m_highlighter; QScopedPointer m_indenter; @@ -88,6 +89,7 @@ public: }; BaseTextDocumentPrivate::BaseTextDocumentPrivate(BaseTextDocument *q) : + m_fontSettingsNeedsApply(false), m_document(new QTextDocument(q)), m_highlighter(0), m_indenter(new Indenter), @@ -237,9 +239,26 @@ void BaseTextDocument::setFontSettings(const FontSettings &fontSettings) if (fontSettings == d->m_fontSettings) return; d->m_fontSettings = fontSettings; + d->m_fontSettingsNeedsApply = true; emit fontSettingsChanged(); } +void BaseTextDocument::ensureFontSettingsApplied() +{ + if (!d->m_fontSettingsNeedsApply) + return; + d->m_fontSettingsNeedsApply = false; + applyFontSettings(); +} + +void BaseTextDocument::applyFontSettings() +{ + if (d->m_highlighter) { + d->m_highlighter->setFontSettings(d->m_fontSettings); + d->m_highlighter->rehighlight(); + } +} + const FontSettings &BaseTextDocument::fontSettings() const { return d->m_fontSettings; diff --git a/src/plugins/texteditor/basetextdocument.h b/src/plugins/texteditor/basetextdocument.h index 347097431cf..546fcf89f2e 100644 --- a/src/plugins/texteditor/basetextdocument.h +++ b/src/plugins/texteditor/basetextdocument.h @@ -112,6 +112,8 @@ public: bool reload(QString *errorString, QTextCodec *codec); void cleanWhitespace(const QTextCursor &cursor); + void ensureFontSettingsApplied(); + public slots: void setTabSettings(const TextEditor::TabSettings &tabSettings); void setFontSettings(const TextEditor::FontSettings &fontSettings); @@ -121,6 +123,9 @@ signals: void tabSettingsChanged(); void fontSettingsChanged(); +protected slots: + virtual void applyFontSettings(); + private: void cleanWhitespace(QTextCursor &cursor, bool cleanIndentation, bool inEntireDocument); void ensureFinalNewLine(QTextCursor &cursor); diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp index ec28a42f1ee..3727a0530a1 100644 --- a/src/plugins/texteditor/basetexteditor.cpp +++ b/src/plugins/texteditor/basetexteditor.cpp @@ -5429,11 +5429,7 @@ void BaseTextEditorWidget::applyFontSettings() slotUpdateExtraAreaWidth(); // Adjust to new font width updateCurrentLineHighlight(); // Make sure it takes the new color - SyntaxHighlighter *highlighter = baseTextDocument()->syntaxHighlighter(); - if (highlighter) { - highlighter->setFontSettings(fs); - highlighter->rehighlight(); - } + baseTextDocument()->ensureFontSettingsApplied(); } void BaseTextEditorWidget::setDisplaySettings(const DisplaySettings &ds)