TextEditor: Make FontSettingsPage more like the other ones

Change-Id: I00d758bcdafd39b14498bdf182332ece53215d64
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
hjk
2020-01-24 17:57:27 +01:00
parent 03ddc603cf
commit 3e67c2ce92
4 changed files with 37 additions and 35 deletions

View File

@@ -327,11 +327,9 @@ bool FormatDescription::showControl(FormatDescription::ShowControls showControl)
}
// ------------ FontSettingsPage
FontSettingsPage::FontSettingsPage(const FormatDescriptions &fd,
Core::Id id,
QObject *parent) :
Core::IOptionsPage(parent),
d_ptr(new FontSettingsPagePrivate(fd, id, tr("Font && Colors"), TextEditor::Constants::TEXT_EDITOR_SETTINGS_CATEGORY))
FontSettingsPage::FontSettingsPage(const FormatDescriptions &fd) :
d_ptr(new FontSettingsPagePrivate(fd, Constants::TEXT_EDITOR_FONT_SETTINGS,
tr("Font && Colors"), TextEditor::Constants::TEXT_EDITOR_SETTINGS_CATEGORY))
{
setId(d_ptr->m_id);
setDisplayName(d_ptr->m_displayName);

View File

@@ -123,8 +123,7 @@ class TEXTEDITOR_EXPORT FontSettingsPage : public Core::IOptionsPage
Q_OBJECT
public:
FontSettingsPage(const FormatDescriptions &fd, Core::Id id, QObject *parent = nullptr);
explicit FontSettingsPage(const FormatDescriptions &fd);
~FontSettingsPage() override;
QWidget *widget() override;

View File

@@ -53,7 +53,6 @@
#include <QApplication>
using namespace TextEditor;
using namespace TextEditor::Constants;
using namespace TextEditor::Internal;
@@ -62,8 +61,10 @@ namespace Internal {
class TextEditorSettingsPrivate
{
Q_DECLARE_TR_FUNCTIONS(TextEditor::TextEditorSettings)
public:
FontSettingsPage *m_fontSettingsPage;
FontSettingsPage m_fontSettingsPage{initialFormats()};
BehaviorSettingsPage m_behaviorSettingsPage;
DisplaySettingsPage m_displaySettingsPage;
HighlighterSettingsPage m_highlighterSettingsPage;
@@ -75,23 +76,13 @@ public:
QMap<Core::Id, ICodeStylePreferences *> m_languageToCodeStyle;
QMap<Core::Id, CodeStylePool *> m_languageToCodeStylePool;
QMap<QString, Core::Id> m_mimeTypeToLanguage;
private:
static std::vector<FormatDescription> initialFormats();
};
} // namespace Internal
} // namespace TextEditor
static TextEditorSettingsPrivate *d = nullptr;
static TextEditorSettings *m_instance = nullptr;
TextEditorSettings::TextEditorSettings()
FormatDescriptions TextEditorSettingsPrivate::initialFormats()
{
QTC_ASSERT(!m_instance, return);
m_instance = this;
d = new Internal::TextEditorSettingsPrivate;
// Note: default background colors are coming from FormatDescription::background()
// Add font preference page
FormatDescriptions formatDescr;
formatDescr.reserve(C_LAST_STYLE_SENTINEL);
@@ -346,16 +337,29 @@ TextEditorSettings::TextEditorSettings()
outputArgumentFormat,
FormatDescription::ShowAllControls);
d->m_fontSettingsPage = new FontSettingsPage(formatDescr,
Constants::TEXT_EDITOR_FONT_SETTINGS,
this);
return formatDescr;
}
} // namespace Internal
static TextEditorSettingsPrivate *d = nullptr;
static TextEditorSettings *m_instance = nullptr;
TextEditorSettings::TextEditorSettings()
{
QTC_ASSERT(!m_instance, return);
m_instance = this;
d = new Internal::TextEditorSettingsPrivate;
// Note: default background colors are coming from FormatDescription::background()
auto updateGeneralMessagesFontSettings = []() {
Core::MessageManager::setFont(d->m_fontSettingsPage->fontSettings().font());
Core::MessageManager::setFont(d->m_fontSettingsPage.fontSettings().font());
};
connect(d->m_fontSettingsPage, &FontSettingsPage::changed,
connect(&d->m_fontSettingsPage, &FontSettingsPage::changed,
this, &TextEditorSettings::fontSettingsChanged);
connect(d->m_fontSettingsPage, &FontSettingsPage::changed,
connect(&d->m_fontSettingsPage, &FontSettingsPage::changed,
this, updateGeneralMessagesFontSettings);
updateGeneralMessagesFontSettings();
connect(&d->m_behaviorSettingsPage, &BehaviorSettingsPage::typingSettingsChanged,
@@ -400,7 +404,7 @@ TextEditorSettings *TextEditorSettings::instance()
const FontSettings &TextEditorSettings::fontSettings()
{
return d->m_fontSettingsPage->fontSettings();
return d->m_fontSettingsPage.fontSettings();
}
const TypingSettings &TextEditorSettings::typingSettings()
@@ -525,19 +529,21 @@ Core::Id TextEditorSettings::languageId(const QString &mimeType)
int TextEditorSettings::increaseFontZoom(int step)
{
auto &fs = const_cast<FontSettings&>(d->m_fontSettingsPage->fontSettings());
auto &fs = const_cast<FontSettings&>(d->m_fontSettingsPage.fontSettings());
const int previousZoom = fs.fontZoom();
const int newZoom = qMax(10, previousZoom + step);
if (newZoom != previousZoom) {
fs.setFontZoom(newZoom);
d->m_fontSettingsPage->saveSettings();
d->m_fontSettingsPage.saveSettings();
}
return newZoom;
}
void TextEditorSettings::resetFontZoom()
{
auto &fs = const_cast<FontSettings&>(d->m_fontSettingsPage->fontSettings());
auto &fs = const_cast<FontSettings&>(d->m_fontSettingsPage.fontSettings());
fs.setFontZoom(100);
d->m_fontSettingsPage->saveSettings();
d->m_fontSettingsPage.saveSettings();
}
} // TextEditor

View File

@@ -35,7 +35,6 @@ class QTextCharFormat;
QT_END_NAMESPACE
namespace Core { class ICore; }
namespace TextEditor { class FontSettingsPage; }
namespace VcsBase {