Commit 3fa6b673 authored by Eike Ziller's avatar Eike Ziller

TextEditors: Move font settings to document

Change-Id: I325764cbaa9684fa2758b0ea6c6ea58de142cb73
Reviewed-by: default avatarEike Ziller <eike.ziller@digia.com>
parent b59d61e2
......@@ -1529,13 +1529,14 @@ TextEditor::CompletionAssistProvider *CPPEditor::completionAssistProvider()
return CppModelManagerInterface::instance()->cppEditorSupport(this)->completionAssistProvider();
}
void CPPEditorWidget::setFontSettings(const TextEditor::FontSettings &fs)
void CPPEditorWidget::applyFontSettings()
{
TextEditor::BaseTextEditorWidget::setFontSettings(fs);
TextEditor::BaseTextEditorWidget::applyFontSettings();
TextEditor::SyntaxHighlighter *highlighter = baseTextDocument()->syntaxHighlighter();
if (!highlighter)
return;
const TextEditor::FontSettings &fs = baseTextDocument()->fontSettings();
m_occurrencesFormat = fs.toTextCharFormat(TextEditor::C_OCCURRENCES);
m_occurrencesUnusedFormat = fs.toTextCharFormat(TextEditor::C_OCCURRENCES_UNUSED);
m_occurrencesUnusedFormat.setUnderlineStyle(QTextCharFormat::WaveUnderline);
......
......@@ -145,7 +145,6 @@ Q_SIGNALS:
void outlineModelIndexChanged(const QModelIndex &index);
public Q_SLOTS:
virtual void setFontSettings(const TextEditor::FontSettings &);
void setSortedOutline(bool sort);
void switchDeclarationDefinition(bool inNextSplit);
void renameSymbolUnderCursor();
......@@ -162,6 +161,7 @@ protected:
void contextMenuEvent(QContextMenuEvent *);
void keyPressEvent(QKeyEvent *e);
void applyFontSettings();
TextEditor::BaseTextEditor *createEditor();
const CPlusPlus::Macro *findCanonicalMacro(const QTextCursor &cursor,
......
......@@ -497,7 +497,7 @@ void CppCodeStylePreferencesWidget::decorateEditors(const TextEditor::FontSettin
}
foreach (TextEditor::SnippetEditorWidget *editor, m_previews) {
editor->setFontSettings(fontSettings);
editor->baseTextDocument()->setFontSettings(fontSettings);
if (provider)
provider->decorateEditor(editor);
}
......
......@@ -185,7 +185,6 @@ public:
public slots:
void setDisplaySettings(const DisplaySettings &ds);
void setFontSettings(const TextEditor::FontSettings &fs);
signals:
void jumpToOriginalFileRequested(int diffFileIndex,
......@@ -194,6 +193,7 @@ signals:
protected:
virtual int extraAreaWidth(int *markWidthPtr = 0) const { return BaseTextEditorWidget::extraAreaWidth(markWidthPtr); }
void applyFontSettings();
BaseTextEditor *createEditor() { return new DiffViewEditorEditable(this); }
virtual QString lineNumber(int blockNumber) const;
virtual int lineNumberDigits() const;
......@@ -356,9 +356,10 @@ void DiffViewEditorWidget::setDisplaySettings(const DisplaySettings &ds)
BaseTextEditorWidget::setDisplaySettings(settings);
}
void DiffViewEditorWidget::setFontSettings(const TextEditor::FontSettings &fs)
void DiffViewEditorWidget::applyFontSettings()
{
BaseTextEditorWidget::setFontSettings(fs);
BaseTextEditorWidget::applyFontSettings();
const TextEditor::FontSettings &fs = baseTextDocument()->fontSettings();
m_fileLineForeground = fs.formatFor(C_DIFF_FILE_LINE).foreground();
m_chunkLineForeground = fs.formatFor(C_DIFF_CONTEXT_LINE).foreground();
m_textForeground = fs.toTextCharFormat(C_TEXT).foreground().color();
......@@ -1578,8 +1579,8 @@ static QTextCharFormat fullWidthFormatForTextStyle(const TextEditor::FontSetting
void DiffEditorWidget::setFontSettings(const TextEditor::FontSettings &fontSettings)
{
m_leftEditor->setFontSettings(fontSettings);
m_rightEditor->setFontSettings(fontSettings);
m_leftEditor->baseTextDocument()->setFontSettings(fontSettings);
m_rightEditor->baseTextDocument()->setFontSettings(fontSettings);
m_fileLineFormat = fullWidthFormatForTextStyle(fontSettings, C_DIFF_FILE_LINE);
m_chunkLineFormat = fullWidthFormatForTextStyle(fontSettings, C_DIFF_CONTEXT_LINE);
......
......@@ -125,7 +125,7 @@ DiffShowEditor::DiffShowEditor(DiffEditorWidget *editorWidget)
m_diffShowWidget, SLOT(setFontSettings(TextEditor::FontSettings)));
m_diffShowWidget->setDisplaySettings(TextEditorSettings::displaySettings());
m_diffShowWidget->setCodeStyle(TextEditorSettings::codeStyle());
m_diffShowWidget->setFontSettings(TextEditorSettings::fontSettings());
m_diffShowWidget->baseTextDocument()->setFontSettings(TextEditorSettings::fontSettings());
}
DiffShowEditor::~DiffShowEditor()
......
......@@ -71,7 +71,7 @@ EnvironmentItemsWidget::EnvironmentItemsWidget(QWidget *parent) :
QWidget(parent), d(new EnvironmentItemsWidgetPrivate)
{
d->m_editor = new TextEditor::SnippetEditorWidget(this);
d->m_editor->setFontSettings(TextEditor::TextEditorSettings::fontSettings());
d->m_editor->baseTextDocument()->setFontSettings(TextEditor::TextEditorSettings::fontSettings());
QVBoxLayout *layout = new QVBoxLayout(this);
layout->addWidget(d->m_editor);
}
......
......@@ -89,14 +89,14 @@ void EditorWidget::unCommentSelection()
Handles common IDE fonts&colors settings
(Tools -> Options -> Text editor -> Fonts and colors)
*/
void EditorWidget::setFontSettings(const TextEditor::FontSettings &fs)
void EditorWidget::applyFontSettings()
{
TextEditor::BaseTextEditorWidget::setFontSettings(fs);
TextEditor::BaseTextEditorWidget::applyFontSettings();
PythonHighlighter *highlighter =
qobject_cast<PythonHighlighter *>(baseTextDocument()->syntaxHighlighter());
if (highlighter)
highlighter->setFontSettings(fs);
highlighter->setFontSettings(baseTextDocument()->fontSettings());
}
TextEditor::BaseTextEditor *EditorWidget::createEditor()
......
......@@ -47,10 +47,8 @@ public:
virtual void unCommentSelection();
public slots:
virtual void setFontSettings(const TextEditor::FontSettings &);
protected:
void applyFontSettings();
TextEditor::BaseTextEditor *createEditor();
private:
......
......@@ -997,10 +997,11 @@ void QmlJSTextEditorWidget::setSelectedElements()
emit selectedElementsChanged(offsets, wordAtCursor);
}
void QmlJSTextEditorWidget::setFontSettings(const TextEditor::FontSettings &fs)
void QmlJSTextEditorWidget::applyFontSettings()
{
TextEditor::BaseTextEditorWidget::setFontSettings(fs);
TextEditor::BaseTextEditorWidget::applyFontSettings();
const TextEditor::FontSettings &fs = baseTextDocument()->fontSettings();
m_occurrencesFormat = fs.toTextCharFormat(TextEditor::C_OCCURRENCES);
m_occurrencesUnusedFormat = fs.toTextCharFormat(TextEditor::C_OCCURRENCES_UNUSED);
m_occurrencesUnusedFormat.setUnderlineStyle(QTextCharFormat::WaveUnderline);
......
......@@ -135,7 +135,6 @@ public slots:
void findUsages();
void renameUsages();
void showContextPane();
virtual void setFontSettings(const TextEditor::FontSettings &);
signals:
void outlineModelIndexChanged(const QModelIndex &index);
......@@ -168,6 +167,7 @@ protected:
void wheelEvent(QWheelEvent *event);
void resizeEvent(QResizeEvent *event);
void scrollContentsBy(int dx, int dy);
void applyFontSettings();
TextEditor::BaseTextEditor *createEditor();
void createToolBar(QmlJSEditor *editable);
TextEditor::BaseTextEditorWidget::Link findLinkAt(const QTextCursor &cursor,
......
......@@ -107,7 +107,7 @@ void QmlJSCodeStylePreferencesWidget::decorateEditor(const TextEditor::FontSetti
}
}
m_ui->previewTextEdit->setFontSettings(fontSettings);
m_ui->previewTextEdit->baseTextDocument()->setFontSettings(fontSettings);
if (provider)
provider->decorateEditor(m_ui->previewTextEdit);
}
......
......@@ -33,6 +33,7 @@
#include "basetexteditor.h"
#include "convenience.h"
#include "extraencodingsettings.h"
#include "fontsettings.h"
#include "indenter.h"
#include "storagesettings.h"
#include "syntaxhighlighter.h"
......@@ -77,6 +78,7 @@ public:
StorageSettings m_storageSettings;
TabSettings m_tabSettings;
ExtraEncodingSettings m_extraEncodingSettings;
FontSettings m_fontSettings;
QTextDocument *m_document;
SyntaxHighlighter *m_highlighter;
QScopedPointer<Indenter> m_indenter;
......@@ -230,6 +232,19 @@ const TabSettings &BaseTextDocument::tabSettings() const
return d->m_tabSettings;
}
void BaseTextDocument::setFontSettings(const FontSettings &fontSettings)
{
if (fontSettings == d->m_fontSettings)
return;
d->m_fontSettings = fontSettings;
emit fontSettingsChanged();
}
const FontSettings &BaseTextDocument::fontSettings() const
{
return d->m_fontSettings;
}
void BaseTextDocument::setExtraEncodingSettings(const ExtraEncodingSettings &extraEncodingSettings)
{
d->m_extraEncodingSettings = extraEncodingSettings;
......
......@@ -43,6 +43,7 @@ namespace TextEditor {
class BaseTextDocumentPrivate;
class ExtraEncodingSettings;
class FontSettings;
class ITextMarkable;
class Indenter;
class StorageSettings;
......@@ -71,6 +72,7 @@ public:
const StorageSettings &storageSettings() const;
const TabSettings &tabSettings() const;
const ExtraEncodingSettings &extraEncodingSettings() const;
const FontSettings &fontSettings() const;
void setIndenter(Indenter *indenter);
Indenter *indenter() const;
......@@ -112,10 +114,12 @@ public:
public slots:
void setTabSettings(const TextEditor::TabSettings &tabSettings);
void setFontSettings(const TextEditor::FontSettings &fontSettings);
signals:
void mimeTypeChanged();
void tabSettingsChanged();
void fontSettingsChanged();
private:
void cleanWhitespace(QTextCursor &cursor, bool cleanIndentation, bool inEntireDocument);
......
......@@ -2347,6 +2347,7 @@ BaseTextEditorWidgetPrivate::BaseTextEditorWidgetPrivate()
m_parenthesesMatchingTimer(0),
m_extraArea(0),
m_codeStylePreferences(0),
m_fontSettingsNeedsApply(true), // apply when making visible the first time, for the split case
extraAreaSelectionAnchorBlockNumber(-1),
extraAreaToggleMarkBlockNumber(-1),
extraAreaHighlightFoldedBlockNumber(-1),
......@@ -2404,6 +2405,7 @@ void BaseTextEditorWidgetPrivate::setupDocumentSignals()
QObject::connect(m_document.data(), SIGNAL(aboutToReload()), q, SLOT(documentAboutToBeReloaded()));
QObject::connect(m_document.data(), SIGNAL(reloadFinished(bool)), q, SLOT(documentReloadFinished(bool)));
QObject::connect(m_document.data(), SIGNAL(tabSettingsChanged()), q, SLOT(updateTabStops()));
QObject::connect(m_document.data(), SIGNAL(fontSettingsChanged()), q, SLOT(applyFontSettingsDelayed()));
q->slotUpdateExtraAreaWidth();
}
......@@ -5363,25 +5365,25 @@ void BaseTextEditorWidget::unCommentSelection()
void BaseTextEditorWidget::showEvent(QShowEvent* e)
{
if (!d->m_fontSettings.isEmpty()) {
setFontSettings(d->m_fontSettings);
d->m_fontSettings.clear();
if (d->m_fontSettingsNeedsApply) {
applyFontSettings();
d->m_fontSettingsNeedsApply = false;
}
QPlainTextEdit::showEvent(e);
}
void BaseTextEditorWidget::setFontSettingsIfVisible(const TextEditor::FontSettings &fs)
void BaseTextEditorWidget::applyFontSettingsDelayed()
{
if (!isVisible()) {
d->m_fontSettings = fs;
return;
}
setFontSettings(fs);
if (isVisible())
applyFontSettings();
else
d->m_fontSettingsNeedsApply = true;
}
void BaseTextEditorWidget::setFontSettings(const TextEditor::FontSettings &fs)
void BaseTextEditorWidget::applyFontSettings()
{
const FontSettings &fs = baseTextDocument()->fontSettings();
const QTextCharFormat textFormat = fs.toTextCharFormat(C_TEXT);
const QTextCharFormat selectionFormat = fs.toTextCharFormat(C_SELECTION);
const QTextCharFormat lineNumberFormat = fs.toTextCharFormat(C_LINE_NUMBER);
......
......@@ -343,6 +343,7 @@ private:
protected:
virtual BaseTextEditor *createEditor() = 0;
virtual void applyFontSettings();
private slots:
void editorContentsChange(int position, int charsRemoved, int charsAdded);
......@@ -412,8 +413,6 @@ public slots:
virtual void format();
virtual void rewrapParagraph();
virtual void unCommentSelection();
virtual void setFontSettings(const TextEditor::FontSettings &);
void setFontSettingsIfVisible(const TextEditor::FontSettings &);
virtual void setDisplaySettings(const TextEditor::DisplaySettings &);
virtual void setMarginSettings(const TextEditor::MarginSettings &);
virtual void setBehaviorSettings(const TextEditor::BehaviorSettings &);
......@@ -547,6 +546,7 @@ private:
private slots:
void handleBlockSelection(int diff_row, int diff_col);
void updateTabStops();
void applyFontSettingsDelayed();
// parentheses matcher
void _q_matchParentheses();
......
......@@ -138,7 +138,7 @@ public:
ICodeStylePreferences *m_codeStylePreferences;
DisplaySettings m_displaySettings;
MarginSettings m_marginSettings;
FontSettings m_fontSettings;
bool m_fontSettingsNeedsApply;
BehaviorSettings m_behaviorSettings;
int extraAreaSelectionAnchorBlockNumber;
......
......@@ -54,7 +54,7 @@ CodeStyleEditor::CodeStyleEditor(ICodeStylePreferencesFactory *factory,
CodeStyleSelectorWidget *selector = new CodeStyleSelectorWidget(factory, this);
selector->setCodeStyle(codeStyle);
m_preview = new SnippetEditorWidget(this);
m_preview->setFontSettings(TextEditorSettings::fontSettings());
m_preview->baseTextDocument()->setFontSettings(TextEditorSettings::fontSettings());
DisplaySettings displaySettings = m_preview->displaySettings();
displaySettings.m_visualizeWhitespace = true;
m_preview->setDisplaySettings(displaySettings);
......
......@@ -171,7 +171,7 @@ void PlainTextEditorWidget::configure(const MimeType &mimeType)
}
}
setFontSettings(TextEditorSettings::fontSettings());
baseTextDocument()->setFontSettings(TextEditorSettings::fontSettings());
emit configured(editor());
}
......
......@@ -335,7 +335,7 @@ void SnippetsSettingsPagePrivate::configureUi(QWidget *w)
foreach (ISnippetProvider *provider, providers) {
m_ui.groupCombo->addItem(provider->displayName(), provider->groupId());
SnippetEditorWidget *snippetEditor = new SnippetEditorWidget(w);
snippetEditor->setFontSettings(TextEditorSettings::fontSettings());
snippetEditor->baseTextDocument()->setFontSettings(TextEditorSettings::fontSettings());
provider->decorateEditor(snippetEditor);
m_ui.snippetsEditorStack->insertWidget(m_ui.groupCombo->count() - 1, snippetEditor);
connect(snippetEditor, SIGNAL(snippetContentChanged()), this, SLOT(setSnippetContent()));
......@@ -541,7 +541,7 @@ void SnippetsSettingsPagePrivate::decorateEditors(const TextEditor::FontSettings
ExtensionSystem::PluginManager::getObjects<ISnippetProvider>();
for (int i = 0; i < m_ui.groupCombo->count(); ++i) {
SnippetEditorWidget *snippetEditor = editorAt(i);
snippetEditor->setFontSettings(fontSettings);
snippetEditor->baseTextDocument()->setFontSettings(fontSettings);
const QString &id = m_ui.groupCombo->itemData(i).toString();
// This list should be quite short... Re-iterating over it is ok.
foreach (const ISnippetProvider *provider, providers) {
......
......@@ -335,7 +335,7 @@ void TextEditorSettings::initializeEditor(BaseTextEditorWidget *editor)
{
// Connect to settings change signals
connect(m_instance, SIGNAL(fontSettingsChanged(TextEditor::FontSettings)),
editor, SLOT(setFontSettingsIfVisible(TextEditor::FontSettings)));
editor->baseTextDocument(), SLOT(setFontSettings(TextEditor::FontSettings)));
connect(m_instance, SIGNAL(typingSettingsChanged(TextEditor::TypingSettings)),
editor, SLOT(setTypingSettings(TextEditor::TypingSettings)));
connect(m_instance, SIGNAL(storageSettingsChanged(TextEditor::StorageSettings)),
......@@ -357,7 +357,7 @@ void TextEditorSettings::initializeEditor(BaseTextEditorWidget *editor)
m_instance, SLOT(zoomResetRequested()));
// Apply current settings
editor->setFontSettings(fontSettings());
editor->baseTextDocument()->setFontSettings(fontSettings());
editor->baseTextDocument()->setTabSettings(codeStyle()->tabSettings()); // also set through code style ???
editor->setTypingSettings(typingSettings());
editor->setStorageSettings(storageSettings());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment