forked from qt-creator/qt-creator
TextEditor: Make FontSettingsPage more like the other ones
Change-Id: I00d758bcdafd39b14498bdf182332ece53215d64 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -327,11 +327,9 @@ bool FormatDescription::showControl(FormatDescription::ShowControls showControl)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ------------ FontSettingsPage
|
// ------------ FontSettingsPage
|
||||||
FontSettingsPage::FontSettingsPage(const FormatDescriptions &fd,
|
FontSettingsPage::FontSettingsPage(const FormatDescriptions &fd) :
|
||||||
Core::Id id,
|
d_ptr(new FontSettingsPagePrivate(fd, Constants::TEXT_EDITOR_FONT_SETTINGS,
|
||||||
QObject *parent) :
|
tr("Font && Colors"), TextEditor::Constants::TEXT_EDITOR_SETTINGS_CATEGORY))
|
||||||
Core::IOptionsPage(parent),
|
|
||||||
d_ptr(new FontSettingsPagePrivate(fd, id, tr("Font && Colors"), TextEditor::Constants::TEXT_EDITOR_SETTINGS_CATEGORY))
|
|
||||||
{
|
{
|
||||||
setId(d_ptr->m_id);
|
setId(d_ptr->m_id);
|
||||||
setDisplayName(d_ptr->m_displayName);
|
setDisplayName(d_ptr->m_displayName);
|
||||||
|
@@ -123,8 +123,7 @@ class TEXTEDITOR_EXPORT FontSettingsPage : public Core::IOptionsPage
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FontSettingsPage(const FormatDescriptions &fd, Core::Id id, QObject *parent = nullptr);
|
explicit FontSettingsPage(const FormatDescriptions &fd);
|
||||||
|
|
||||||
~FontSettingsPage() override;
|
~FontSettingsPage() override;
|
||||||
|
|
||||||
QWidget *widget() override;
|
QWidget *widget() override;
|
||||||
|
@@ -53,7 +53,6 @@
|
|||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
|
||||||
using namespace TextEditor;
|
|
||||||
using namespace TextEditor::Constants;
|
using namespace TextEditor::Constants;
|
||||||
using namespace TextEditor::Internal;
|
using namespace TextEditor::Internal;
|
||||||
|
|
||||||
@@ -62,8 +61,10 @@ namespace Internal {
|
|||||||
|
|
||||||
class TextEditorSettingsPrivate
|
class TextEditorSettingsPrivate
|
||||||
{
|
{
|
||||||
|
Q_DECLARE_TR_FUNCTIONS(TextEditor::TextEditorSettings)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FontSettingsPage *m_fontSettingsPage;
|
FontSettingsPage m_fontSettingsPage{initialFormats()};
|
||||||
BehaviorSettingsPage m_behaviorSettingsPage;
|
BehaviorSettingsPage m_behaviorSettingsPage;
|
||||||
DisplaySettingsPage m_displaySettingsPage;
|
DisplaySettingsPage m_displaySettingsPage;
|
||||||
HighlighterSettingsPage m_highlighterSettingsPage;
|
HighlighterSettingsPage m_highlighterSettingsPage;
|
||||||
@@ -75,23 +76,13 @@ public:
|
|||||||
QMap<Core::Id, ICodeStylePreferences *> m_languageToCodeStyle;
|
QMap<Core::Id, ICodeStylePreferences *> m_languageToCodeStyle;
|
||||||
QMap<Core::Id, CodeStylePool *> m_languageToCodeStylePool;
|
QMap<Core::Id, CodeStylePool *> m_languageToCodeStylePool;
|
||||||
QMap<QString, Core::Id> m_mimeTypeToLanguage;
|
QMap<QString, Core::Id> m_mimeTypeToLanguage;
|
||||||
|
|
||||||
|
private:
|
||||||
|
static std::vector<FormatDescription> initialFormats();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
FormatDescriptions TextEditorSettingsPrivate::initialFormats()
|
||||||
} // namespace TextEditor
|
|
||||||
|
|
||||||
|
|
||||||
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()
|
|
||||||
|
|
||||||
// Add font preference page
|
// Add font preference page
|
||||||
FormatDescriptions formatDescr;
|
FormatDescriptions formatDescr;
|
||||||
formatDescr.reserve(C_LAST_STYLE_SENTINEL);
|
formatDescr.reserve(C_LAST_STYLE_SENTINEL);
|
||||||
@@ -346,16 +337,29 @@ TextEditorSettings::TextEditorSettings()
|
|||||||
outputArgumentFormat,
|
outputArgumentFormat,
|
||||||
FormatDescription::ShowAllControls);
|
FormatDescription::ShowAllControls);
|
||||||
|
|
||||||
d->m_fontSettingsPage = new FontSettingsPage(formatDescr,
|
return formatDescr;
|
||||||
Constants::TEXT_EDITOR_FONT_SETTINGS,
|
}
|
||||||
this);
|
|
||||||
|
} // 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 = []() {
|
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);
|
this, &TextEditorSettings::fontSettingsChanged);
|
||||||
connect(d->m_fontSettingsPage, &FontSettingsPage::changed,
|
connect(&d->m_fontSettingsPage, &FontSettingsPage::changed,
|
||||||
this, updateGeneralMessagesFontSettings);
|
this, updateGeneralMessagesFontSettings);
|
||||||
updateGeneralMessagesFontSettings();
|
updateGeneralMessagesFontSettings();
|
||||||
connect(&d->m_behaviorSettingsPage, &BehaviorSettingsPage::typingSettingsChanged,
|
connect(&d->m_behaviorSettingsPage, &BehaviorSettingsPage::typingSettingsChanged,
|
||||||
@@ -400,7 +404,7 @@ TextEditorSettings *TextEditorSettings::instance()
|
|||||||
|
|
||||||
const FontSettings &TextEditorSettings::fontSettings()
|
const FontSettings &TextEditorSettings::fontSettings()
|
||||||
{
|
{
|
||||||
return d->m_fontSettingsPage->fontSettings();
|
return d->m_fontSettingsPage.fontSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
const TypingSettings &TextEditorSettings::typingSettings()
|
const TypingSettings &TextEditorSettings::typingSettings()
|
||||||
@@ -525,19 +529,21 @@ Core::Id TextEditorSettings::languageId(const QString &mimeType)
|
|||||||
|
|
||||||
int TextEditorSettings::increaseFontZoom(int step)
|
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 previousZoom = fs.fontZoom();
|
||||||
const int newZoom = qMax(10, previousZoom + step);
|
const int newZoom = qMax(10, previousZoom + step);
|
||||||
if (newZoom != previousZoom) {
|
if (newZoom != previousZoom) {
|
||||||
fs.setFontZoom(newZoom);
|
fs.setFontZoom(newZoom);
|
||||||
d->m_fontSettingsPage->saveSettings();
|
d->m_fontSettingsPage.saveSettings();
|
||||||
}
|
}
|
||||||
return newZoom;
|
return newZoom;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextEditorSettings::resetFontZoom()
|
void TextEditorSettings::resetFontZoom()
|
||||||
{
|
{
|
||||||
auto &fs = const_cast<FontSettings&>(d->m_fontSettingsPage->fontSettings());
|
auto &fs = const_cast<FontSettings&>(d->m_fontSettingsPage.fontSettings());
|
||||||
fs.setFontZoom(100);
|
fs.setFontZoom(100);
|
||||||
d->m_fontSettingsPage->saveSettings();
|
d->m_fontSettingsPage.saveSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // TextEditor
|
||||||
|
@@ -35,7 +35,6 @@ class QTextCharFormat;
|
|||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
namespace Core { class ICore; }
|
namespace Core { class ICore; }
|
||||||
namespace TextEditor { class FontSettingsPage; }
|
|
||||||
|
|
||||||
namespace VcsBase {
|
namespace VcsBase {
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user