forked from qt-creator/qt-creator
TextEditors: Generalize update mechanism when editors become visible
Generalizes the special handling of font settings, which should only be applied (on the document) when an editor is or becomes visible. Change-Id: Icd1e3ba4355e1ff4a837c9679b537cc3f5ed7ea9 Reviewed-by: Fawzi Mohamed <fawzi.mohamed@digia.com>
This commit is contained in:
@@ -272,16 +272,15 @@ void BaseTextDocument::setFontSettings(const FontSettings &fontSettings)
|
|||||||
emit fontSettingsChanged();
|
emit fontSettingsChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseTextDocument::ensureFontSettingsApplied()
|
void BaseTextDocument::triggerPendingUpdates()
|
||||||
{
|
{
|
||||||
if (!d->m_fontSettingsNeedsApply)
|
if (d->m_fontSettingsNeedsApply)
|
||||||
return;
|
applyFontSettings();
|
||||||
d->m_fontSettingsNeedsApply = false;
|
|
||||||
applyFontSettings();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseTextDocument::applyFontSettings()
|
void BaseTextDocument::applyFontSettings()
|
||||||
{
|
{
|
||||||
|
d->m_fontSettingsNeedsApply = false;
|
||||||
if (d->m_highlighter) {
|
if (d->m_highlighter) {
|
||||||
d->m_highlighter->setFontSettings(d->m_fontSettings);
|
d->m_highlighter->setFontSettings(d->m_fontSettings);
|
||||||
d->m_highlighter->rehighlight();
|
d->m_highlighter->rehighlight();
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ public:
|
|||||||
bool reload(QString *errorString, QTextCodec *codec);
|
bool reload(QString *errorString, QTextCodec *codec);
|
||||||
void cleanWhitespace(const QTextCursor &cursor);
|
void cleanWhitespace(const QTextCursor &cursor);
|
||||||
|
|
||||||
void ensureFontSettingsApplied();
|
void triggerPendingUpdates();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setTabSettings(const TextEditor::TabSettings &tabSettings);
|
void setTabSettings(const TextEditor::TabSettings &tabSettings);
|
||||||
|
|||||||
@@ -5337,24 +5337,28 @@ void BaseTextEditorWidget::unCommentSelection()
|
|||||||
|
|
||||||
void BaseTextEditorWidget::showEvent(QShowEvent* e)
|
void BaseTextEditorWidget::showEvent(QShowEvent* e)
|
||||||
{
|
{
|
||||||
if (d->m_fontSettingsNeedsApply) {
|
triggerPendingUpdates();
|
||||||
applyFontSettings();
|
|
||||||
d->m_fontSettingsNeedsApply = false;
|
|
||||||
}
|
|
||||||
QPlainTextEdit::showEvent(e);
|
QPlainTextEdit::showEvent(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void BaseTextEditorWidget::applyFontSettingsDelayed()
|
void BaseTextEditorWidget::applyFontSettingsDelayed()
|
||||||
{
|
{
|
||||||
|
d->m_fontSettingsNeedsApply = true;
|
||||||
if (isVisible())
|
if (isVisible())
|
||||||
|
triggerPendingUpdates();
|
||||||
|
}
|
||||||
|
|
||||||
|
void BaseTextEditorWidget::triggerPendingUpdates()
|
||||||
|
{
|
||||||
|
if (d->m_fontSettingsNeedsApply)
|
||||||
applyFontSettings();
|
applyFontSettings();
|
||||||
else
|
baseTextDocument()->triggerPendingUpdates();
|
||||||
d->m_fontSettingsNeedsApply = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseTextEditorWidget::applyFontSettings()
|
void BaseTextEditorWidget::applyFontSettings()
|
||||||
{
|
{
|
||||||
|
d->m_fontSettingsNeedsApply = false;
|
||||||
const FontSettings &fs = baseTextDocument()->fontSettings();
|
const FontSettings &fs = baseTextDocument()->fontSettings();
|
||||||
const QTextCharFormat textFormat = fs.toTextCharFormat(C_TEXT);
|
const QTextCharFormat textFormat = fs.toTextCharFormat(C_TEXT);
|
||||||
const QTextCharFormat selectionFormat = fs.toTextCharFormat(C_SELECTION);
|
const QTextCharFormat selectionFormat = fs.toTextCharFormat(C_SELECTION);
|
||||||
@@ -5388,8 +5392,6 @@ void BaseTextEditorWidget::applyFontSettings()
|
|||||||
|
|
||||||
slotUpdateExtraAreaWidth(); // Adjust to new font width
|
slotUpdateExtraAreaWidth(); // Adjust to new font width
|
||||||
updateCurrentLineHighlight(); // Make sure it takes the new color
|
updateCurrentLineHighlight(); // Make sure it takes the new color
|
||||||
|
|
||||||
baseTextDocument()->ensureFontSettingsApplied();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseTextEditorWidget::setDisplaySettings(const DisplaySettings &ds)
|
void BaseTextEditorWidget::setDisplaySettings(const DisplaySettings &ds)
|
||||||
|
|||||||
@@ -343,6 +343,7 @@ private:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual BaseTextEditor *createEditor() = 0;
|
virtual BaseTextEditor *createEditor() = 0;
|
||||||
|
virtual void triggerPendingUpdates();
|
||||||
virtual void applyFontSettings();
|
virtual void applyFontSettings();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
|||||||
Reference in New Issue
Block a user