Skip to content

Commit 04cb014

Browse files
feat(qt): add global zoom shortcuts
Add Ctrl++/Ctrl+=, Ctrl+-, and Ctrl+0 shortcuts for zooming in, out, and resetting font scale. Clamp range matches the CLI-accepted [-100, 100]. Shortcuts are disabled when -font-scale is CLI-overridden, consistent with the Appearance slider behavior.
1 parent 689fd57 commit 04cb014

3 files changed

Lines changed: 56 additions & 0 deletions

File tree

CLAUDE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ make -C depends -j"$(( $(nproc) - 1 ))" | tail 5
6363
--enable-werror
6464

6565
# Build with parallel jobs (leaving one core free)
66+
# NOTE: Individual object files cannot be built separately; always do a full build
6667
make -j"$(( $(nproc) - 1 ))"
6768
```
6869

src/qt/bitcoingui.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
#include <QVBoxLayout>
7272
#include <QWindow>
7373

74+
#include <algorithm>
7475
#include <functional>
7576

7677
namespace {
@@ -85,6 +86,10 @@ constexpr int GOV_CYCLE_FRAME_MS{STATUSBAR_ICON_CYCLE_MS / (GOV_CYCLE_FRAME_COUN
8586

8687
// Per-frame interval for the spinner animation
8788
constexpr int SPINNER_FRAME_MS{STATUSBAR_ICON_CYCLE_MS / SPINNER_FRAMES};
89+
90+
constexpr int FONT_SCALE_MIN{-100};
91+
constexpr int FONT_SCALE_MAX{100};
92+
constexpr int FONT_SCALE_SHORTCUT_STEP{3};
8893
} // anonymous namespace
8994

9095
const std::string BitcoinGUI::DEFAULT_UIPLATFORM =
@@ -517,12 +522,27 @@ void BitcoinGUI::createActions()
517522
m_mask_values_action->setStatusTip(tr("Mask the values in the Overview tab"));
518523
m_mask_values_action->setCheckable(true);
519524

525+
m_zoom_in_action = new QAction(tr("Zoom &In"), this);
526+
m_zoom_in_action->setShortcuts({QKeySequence(QKeySequence::ZoomIn), QKeySequence(tr("Ctrl+="))});
527+
m_zoom_in_action->setStatusTip(tr("Increase the font size"));
528+
529+
m_zoom_out_action = new QAction(tr("Zoom &Out"), this);
530+
m_zoom_out_action->setShortcuts({QKeySequence(QKeySequence::ZoomOut), QKeySequence(tr("Ctrl+_"))});
531+
m_zoom_out_action->setStatusTip(tr("Decrease the font size"));
532+
533+
m_zoom_reset_action = new QAction(tr("Reset &Zoom"), this);
534+
m_zoom_reset_action->setShortcut(QKeySequence(tr("Ctrl+0")));
535+
m_zoom_reset_action->setStatusTip(tr("Reset the font size to default"));
536+
520537
connect(quitAction, &QAction::triggered, this, &BitcoinGUI::quitRequested);
521538
connect(aboutAction, &QAction::triggered, this, &BitcoinGUI::aboutClicked);
522539
connect(aboutQtAction, &QAction::triggered, qApp, QApplication::aboutQt);
523540
connect(optionsAction, &QAction::triggered, this, &BitcoinGUI::optionsClicked);
524541
connect(showHelpMessageAction, &QAction::triggered, this, &BitcoinGUI::showHelpMessageClicked);
525542
connect(showCoinJoinHelpAction, &QAction::triggered, this, &BitcoinGUI::showCoinJoinHelpClicked);
543+
connect(m_zoom_in_action, &QAction::triggered, this, [this] { adjustFontScale(FONT_SCALE_SHORTCUT_STEP); });
544+
connect(m_zoom_out_action, &QAction::triggered, this, [this] { adjustFontScale(-FONT_SCALE_SHORTCUT_STEP); });
545+
connect(m_zoom_reset_action, &QAction::triggered, this, [this] { adjustFontScale(0); });
526546

527547
// Jump directly to tabs in RPC-console
528548
connect(openInfoAction, &QAction::triggered, this, &BitcoinGUI::showInfo);
@@ -677,6 +697,11 @@ void BitcoinGUI::createMenuBar()
677697
}
678698
settings->addAction(optionsAction);
679699

700+
QMenu* view = appMenuBar->addMenu(tr("&View"));
701+
view->addAction(m_zoom_in_action);
702+
view->addAction(m_zoom_out_action);
703+
view->addAction(m_zoom_reset_action);
704+
680705
QMenu* window_menu = appMenuBar->addMenu(tr("&Window"));
681706

682707
QAction* minimize_action = window_menu->addAction(tr("&Minimize"));
@@ -735,6 +760,30 @@ void BitcoinGUI::createMenuBar()
735760
help->addAction(aboutQtAction);
736761
}
737762

763+
void BitcoinGUI::adjustFontScale(int delta)
764+
{
765+
if (clientModel && clientModel->getOptionsModel() &&
766+
clientModel->getOptionsModel()->isOptionOverridden("-font-scale")) {
767+
return;
768+
}
769+
770+
const int current_scale{GUIUtil::g_font_registry.GetFontScale()};
771+
const int new_scale{delta == 0
772+
? GUIUtil::FontRegistry::DEFAULT_FONT_SCALE
773+
: std::clamp(current_scale + delta, FONT_SCALE_MIN, FONT_SCALE_MAX)};
774+
775+
if (new_scale == current_scale) {
776+
return;
777+
}
778+
779+
GUIUtil::g_font_registry.SetFontScale(new_scale);
780+
GUIUtil::updateFonts();
781+
782+
if (clientModel && clientModel->getOptionsModel()) {
783+
clientModel->getOptionsModel()->setOption(OptionsModel::FontScale, new_scale);
784+
}
785+
}
786+
738787
void BitcoinGUI::createToolBars()
739788
{
740789
#ifdef ENABLE_WALLET

src/qt/bitcoingui.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,9 @@ class BitcoinGUI : public QMainWindow
187187
QAction* m_close_all_wallets_action{nullptr};
188188
QAction* m_wallet_selector_action = nullptr;
189189
QAction* m_mask_values_action{nullptr};
190+
QAction* m_zoom_in_action{nullptr};
191+
QAction* m_zoom_out_action{nullptr};
192+
QAction* m_zoom_reset_action{nullptr};
190193

191194
QComboBox* m_wallet_selector = nullptr;
192195

@@ -262,6 +265,9 @@ class BitcoinGUI : public QMainWindow
262265
/** Update UI with latest network info from model. */
263266
void updateNetworkState();
264267

268+
/** Apply a global font scale delta or reset when delta is 0. */
269+
void adjustFontScale(int delta);
270+
265271
/** Regenerate all pre-cached governance clock pixmaps (e.g. after a theme change). */
266272
void refreshGovernanceCycleIcons();
267273

0 commit comments

Comments
 (0)