aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/texteditor
diff options
context:
space:
mode:
authorDavid Schulz <david.schulz@qt.io>2024-02-23 12:36:11 +0100
committerDavid Schulz <david.schulz@qt.io>2024-02-23 12:01:29 +0000
commit8feb31b2ac194af3b5da09e6c1636a7953b40ffb (patch)
tree30f51dbd542cbbe298dce6ff789e5c7e753ecda2 /src/plugins/texteditor
parent9f7d8b06b26fc87e5f588519e53d39a0ed790142 (diff)
TextEditor: bound increase and decreaseFontZoom to a 10% grid
This allows to get back to a 100% font zoom with the keyboard shortcuts by zooming to an odd zoom factor by other means. Change-Id: Ie90853367b17c207e9c47fc108b8d6f451e0f838 Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
Diffstat (limited to 'src/plugins/texteditor')
-rw-r--r--src/plugins/texteditor/texteditor.cpp12
-rw-r--r--src/plugins/texteditor/texteditor.h2
-rw-r--r--src/plugins/texteditor/texteditoractionhandler.cpp4
-rw-r--r--src/plugins/texteditor/texteditorsettings.cpp31
-rw-r--r--src/plugins/texteditor/texteditorsettings.h2
5 files changed, 40 insertions, 11 deletions
diff --git a/src/plugins/texteditor/texteditor.cpp b/src/plugins/texteditor/texteditor.cpp
index c8ef69c63e..70239b286e 100644
--- a/src/plugins/texteditor/texteditor.cpp
+++ b/src/plugins/texteditor/texteditor.cpp
@@ -6891,6 +6891,18 @@ static void showZoomIndicator(QWidget *editor, const int newZoom)
Utils::FadingIndicator::SmallText);
}
+void TextEditorWidget::increaseFontZoom()
+{
+ d->clearVisibleFoldedBlock();
+ showZoomIndicator(this, TextEditorSettings::increaseFontZoom());
+}
+
+void TextEditorWidget::decreaseFontZoom()
+{
+ d->clearVisibleFoldedBlock();
+ showZoomIndicator(this, TextEditorSettings::decreaseFontZoom());
+}
+
void TextEditorWidget::zoomF(float delta)
{
d->clearVisibleFoldedBlock();
diff --git a/src/plugins/texteditor/texteditor.h b/src/plugins/texteditor/texteditor.h
index a2a1aafb2b..33b8cb84f0 100644
--- a/src/plugins/texteditor/texteditor.h
+++ b/src/plugins/texteditor/texteditor.h
@@ -349,6 +349,8 @@ public:
void pasteWithoutFormat();
void switchUtf8bom();
+ void increaseFontZoom();
+ void decreaseFontZoom();
void zoomF(float delta);
void zoomReset();
diff --git a/src/plugins/texteditor/texteditoractionhandler.cpp b/src/plugins/texteditor/texteditoractionhandler.cpp
index 2e48670bf4..240e8498ed 100644
--- a/src/plugins/texteditor/texteditoractionhandler.cpp
+++ b/src/plugins/texteditor/texteditoractionhandler.cpp
@@ -394,11 +394,11 @@ void TextEditorActionHandlerPrivate::createActions()
QKeySequence(),
G_EDIT_COLLAPSING, advancedEditMenu);
registerAction(INCREASE_FONT_SIZE,
- [] (TextEditorWidget *w) { w->zoomF(1.f); }, false, Tr::tr("Increase Font Size"),
+ [] (TextEditorWidget *w) { w->increaseFontZoom(); }, false, Tr::tr("Increase Font Size"),
QKeySequence(Tr::tr("Ctrl++")),
G_EDIT_FONT, advancedEditMenu);
registerAction(DECREASE_FONT_SIZE,
- [] (TextEditorWidget *w) { w->zoomF(-1.f); }, false, Tr::tr("Decrease Font Size"),
+ [] (TextEditorWidget *w) { w->decreaseFontZoom(); }, false, Tr::tr("Decrease Font Size"),
QKeySequence(Tr::tr("Ctrl+-")),
G_EDIT_FONT, advancedEditMenu);
registerAction(RESET_FONT_SIZE,
diff --git a/src/plugins/texteditor/texteditorsettings.cpp b/src/plugins/texteditor/texteditorsettings.cpp
index 1d7dd89386..811852b8a8 100644
--- a/src/plugins/texteditor/texteditorsettings.cpp
+++ b/src/plugins/texteditor/texteditorsettings.cpp
@@ -560,20 +560,33 @@ Utils::Id TextEditorSettings::languageId(const QString &mimeType)
return d->m_mimeTypeToLanguage.value(mimeType);
}
-static void setFontZoom(int zoom)
+static int setFontZoom(int zoom)
+{
+ zoom = qMax(10, zoom);
+ if (d->m_fontSettings.fontZoom() != zoom) {
+ d->m_fontSettings.setFontZoom(zoom);
+ d->m_fontSettings.toSettings(Core::ICore::settings());
+ emit textEditorSettings().fontSettingsChanged(d->m_fontSettings);
+ }
+ return zoom;
+}
+
+int TextEditorSettings::increaseFontZoom()
{
- d->m_fontSettings.setFontZoom(zoom);
- d->m_fontSettings.toSettings(Core::ICore::settings());
- emit textEditorSettings().fontSettingsChanged(d->m_fontSettings);
+ const int previousZoom = d->m_fontSettings.fontZoom();
+ return setFontZoom(previousZoom + 10 - previousZoom % 10);
}
-int TextEditorSettings::increaseFontZoom(int step)
+int TextEditorSettings::decreaseFontZoom()
{
const int previousZoom = d->m_fontSettings.fontZoom();
- const int newZoom = qMax(10, previousZoom + step);
- if (newZoom != previousZoom)
- setFontZoom(newZoom);
- return newZoom;
+ const int delta = previousZoom % 10;
+ return setFontZoom(previousZoom - (delta == 0 ? 10 : delta));
+}
+
+int TextEditorSettings::increaseFontZoom(int step)
+{
+ return setFontZoom(d->m_fontSettings.fontZoom() + step);
}
void TextEditorSettings::resetFontZoom()
diff --git a/src/plugins/texteditor/texteditorsettings.h b/src/plugins/texteditor/texteditorsettings.h
index 88dd057608..1599fcbba5 100644
--- a/src/plugins/texteditor/texteditorsettings.h
+++ b/src/plugins/texteditor/texteditorsettings.h
@@ -76,6 +76,8 @@ public:
static void registerMimeTypeForLanguageId(const char *mimeType, Utils::Id languageId);
static Utils::Id languageId(const QString &mimeType);
+ static int increaseFontZoom();
+ static int decreaseFontZoom();
static int increaseFontZoom(int step);
static void resetFontZoom();