forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -349,6 +349,8 @@ public:
|
||||
void pasteWithoutFormat();
|
||||
void switchUtf8bom();
|
||||
|
||||
void increaseFontZoom();
|
||||
void decreaseFontZoom();
|
||||
void zoomF(float delta);
|
||||
void zoomReset();
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
d->m_fontSettings.setFontZoom(zoom);
|
||||
d->m_fontSettings.toSettings(Core::ICore::settings());
|
||||
emit textEditorSettings().fontSettingsChanged(d->m_fontSettings);
|
||||
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()
|
||||
{
|
||||
const int previousZoom = d->m_fontSettings.fontZoom();
|
||||
return setFontZoom(previousZoom + 10 - previousZoom % 10);
|
||||
}
|
||||
|
||||
int TextEditorSettings::decreaseFontZoom()
|
||||
{
|
||||
const int previousZoom = d->m_fontSettings.fontZoom();
|
||||
const int delta = previousZoom % 10;
|
||||
return setFontZoom(previousZoom - (delta == 0 ? 10 : delta));
|
||||
}
|
||||
|
||||
int TextEditorSettings::increaseFontZoom(int step)
|
||||
{
|
||||
const int previousZoom = d->m_fontSettings.fontZoom();
|
||||
const int newZoom = qMax(10, previousZoom + step);
|
||||
if (newZoom != previousZoom)
|
||||
setFontZoom(newZoom);
|
||||
return newZoom;
|
||||
return setFontZoom(d->m_fontSettings.fontZoom() + step);
|
||||
}
|
||||
|
||||
void TextEditorSettings::resetFontZoom()
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user