Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions doc/release-notes-7216.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
GUI changes
-----------

- The Window menu has new Zoom In, Zoom Out and Reset Zoom entries that change
the font scale of the whole application, bound to the platform zoom
shortcuts (Ctrl++ / Ctrl+= and Ctrl+- / Ctrl+_; Cmd on macOS) and Ctrl+0.
The new scale is saved like the Appearance tab's font scale setting. Like
that slider, the entries are disabled when `-font-scale` is given on the
command line. Inside the RPC console window the zoom-in/out keys still resize
only the console text, and when the console is the main window
(`-disablewallet` or builds without wallet support) the keys stay with the
console while the menu entries keep zooming the whole application. (#7216)

- The font scale range is now -50 to 100, both for `-font-scale` and the
Appearance tab slider, which used to stop at -30 and 30. `-font-scale` values
below -50 on the command line or in the configuration file, which earlier
versions accepted down to -100 although they shrank text towards zero size,
are now rejected at startup. A font scale saved in `settings.json`
outside the range is clamped on load and the clamped value is saved. (#7216)
1 change: 1 addition & 0 deletions src/qt/appearancewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ AppearanceWidget::AppearanceWidget(QWidget* parent) :
prevWeightBoldArg{GUIUtil::currentWeightArg(GUIUtil::FontWeight::Bold)}
{
ui->setupUi(this);
ui->fontScaleSlider->setRange(GUIUtil::FONT_SCALE_MIN, GUIUtil::FONT_SCALE_MAX);

for (const QString& entry : GUIUtil::listThemes()) {
ui->theme->addItem(entry, QVariant(entry));
Expand Down
15 changes: 5 additions & 10 deletions src/qt/bitcoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ static void SetupUIArgs(ArgsManager& argsman)
if (selectable) selectable_fonts.push_back(name);
}
argsman.AddArg("-font-family", QObject::tr("Set the font family. Possible values: %1. (default: %2)").arg(Join(selectable_fonts, ", ")).arg(GUIUtil::defaultFontFamily()).toStdString(), ArgsManager::ALLOW_ANY, OptionsCategory::GUI);
argsman.AddArg("-font-scale", QObject::tr("Set a scale factor which gets applied to the base font size. Possible range %1 (smallest fonts) to %2 (largest fonts). (default: %3)").arg(-100).arg(100).arg(GUIUtil::defaultFontScale()).toStdString(), ArgsManager::ALLOW_ANY, OptionsCategory::GUI);
argsman.AddArg("-font-scale", QObject::tr("Set a scale factor which gets applied to the base font size. Possible range %1 (smallest fonts) to %2 (largest fonts). (default: %3)").arg(GUIUtil::FONT_SCALE_MIN).arg(GUIUtil::FONT_SCALE_MAX).arg(GUIUtil::defaultFontScale()).toStdString(), ArgsManager::ALLOW_ANY, OptionsCategory::GUI);
argsman.AddArg("-font-weight-bold", QObject::tr("Set the font weight for bold texts. Possible range %1 to %2 (default: %3)").arg(0).arg(8).arg(GUIUtil::defaultWeightArg(GUIUtil::FontWeight::Bold)).toStdString(), ArgsManager::ALLOW_ANY, OptionsCategory::GUI);
argsman.AddArg("-font-weight-normal", QObject::tr("Set the font weight for normal texts. Possible range %1 to %2 (default: %3)").arg(0).arg(8).arg(GUIUtil::defaultWeightArg(GUIUtil::FontWeight::Normal)).toStdString(), ArgsManager::ALLOW_ANY, OptionsCategory::GUI);
argsman.AddArg("-lang=<lang>", QObject::tr("Set language, for example \"de_DE\" (default: system locale)").toStdString(), ArgsManager::ALLOW_ANY, OptionsCategory::GUI);
Expand Down Expand Up @@ -720,15 +720,10 @@ int GuiMain(int argc, char* argv[])
}
}
// Validate/set font scale
if (gArgs.IsArgSet("-font-scale")) {
const int nScaleMin = -100, nScaleMax = 100;
int nScale = gArgs.GetIntArg("-font-scale", GUIUtil::fontScale());
if (nScale < nScaleMin || nScale > nScaleMax) {
QMessageBox::critical(nullptr, PACKAGE_NAME,
QObject::tr("Error: Specified font-scale invalid. Valid range %1 to %2.").arg(nScaleMin).arg(nScaleMax));
return EXIT_FAILURE;
}
GUIUtil::setFontScale(nScale);
if (!GUIUtil::setFontScaleFromArg()) {
QMessageBox::critical(nullptr, PACKAGE_NAME,
QObject::tr("Error: Specified font-scale invalid. Valid range %1 to %2.").arg(GUIUtil::FONT_SCALE_MIN).arg(GUIUtil::FONT_SCALE_MAX));
return EXIT_FAILURE;
}
// Apply font changes
GUIUtil::updateFonts();
Expand Down
78 changes: 78 additions & 0 deletions src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
#include <QVBoxLayout>
#include <QWindow>

#include <algorithm>
#include <functional>

namespace {
Expand All @@ -88,6 +89,8 @@ constexpr int GOV_CYCLE_FRAME_MS{STATUSBAR_ICON_CYCLE_MS / (GOV_CYCLE_FRAME_COUN

// Per-frame interval for the spinner animation
constexpr int SPINNER_FRAME_MS{STATUSBAR_ICON_CYCLE_MS / SPINNER_FRAMES};

constexpr int FONT_SCALE_SHORTCUT_STEP{3};
Comment thread
PastaPastaPasta marked this conversation as resolved.
} // anonymous namespace

BitcoinGUI::BitcoinGUI(interfaces::Node& node, const NetworkStyle* networkStyle, QWidget* parent) :
Expand Down Expand Up @@ -514,12 +517,53 @@ void BitcoinGUI::createActions()
m_mask_values_action->setStatusTip(tr("Mask the values in the Overview tab"));
m_mask_values_action->setCheckable(true);

m_zoom_in_action = new QAction(tr("Zoom &In"), this);
m_zoom_in_action->setObjectName("zoomInAction");
m_zoom_in_action->setStatusTip(tr("Increase the font size"));

m_zoom_out_action = new QAction(tr("Zoom &Out"), this);
m_zoom_out_action->setObjectName("zoomOutAction");
m_zoom_out_action->setStatusTip(tr("Decrease the font size"));
Comment thread
PastaPastaPasta marked this conversation as resolved.

// Without a wallet the RPC console is the central widget and already binds these keys to its own font size
if (walletFrame) {
m_zoom_in_action->setShortcuts({QKeySequence(QKeySequence::ZoomIn), QKeySequence(tr("Ctrl+="))});
m_zoom_out_action->setShortcuts({QKeySequence(QKeySequence::ZoomOut), QKeySequence(tr("Ctrl+_"))});
}

m_zoom_reset_action = new QAction(tr("Reset &Zoom"), this);
m_zoom_reset_action->setObjectName("zoomResetAction");
m_zoom_reset_action->setShortcut(QKeySequence(tr("Ctrl+0")));
m_zoom_reset_action->setStatusTip(tr("Reset the font size to default"));
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Comment thread
PastaPastaPasta marked this conversation as resolved.

// Enabled by setClientModel() once the font scale can be persisted
for (QAction* action : {m_zoom_in_action, m_zoom_out_action, m_zoom_reset_action}) {
action->setEnabled(false);
}

connect(quitAction, &QAction::triggered, this, &BitcoinGUI::quitRequested);
connect(aboutAction, &QAction::triggered, this, &BitcoinGUI::aboutClicked);
connect(aboutQtAction, &QAction::triggered, qApp, QApplication::aboutQt);
connect(optionsAction, &QAction::triggered, this, &BitcoinGUI::optionsClicked);
connect(showHelpMessageAction, &QAction::triggered, this, &BitcoinGUI::showHelpMessageClicked);
connect(showCoinJoinHelpAction, &QAction::triggered, this, &BitcoinGUI::showCoinJoinHelpClicked);
// The macOS menu bar keeps these shortcuts live while the separate RPC console window has focus,
// so let them resize the console text there like its own shortcuts do on other platforms
connect(m_zoom_in_action, &QAction::triggered, this, [this] {
if (rpcConsole->isWindow() && rpcConsole->isActiveWindow()) {
rpcConsole->fontBigger();
} else {
adjustFontScale(FONT_SCALE_SHORTCUT_STEP);
}
});
connect(m_zoom_out_action, &QAction::triggered, this, [this] {
if (rpcConsole->isWindow() && rpcConsole->isActiveWindow()) {
rpcConsole->fontSmaller();
} else {
adjustFontScale(-FONT_SCALE_SHORTCUT_STEP);
}
});
connect(m_zoom_reset_action, &QAction::triggered, this, [this] { adjustFontScale(0); });

// Jump directly to tabs in RPC-console
connect(openInfoAction, &QAction::triggered, this, &BitcoinGUI::showInfo);
Expand Down Expand Up @@ -706,6 +750,11 @@ void BitcoinGUI::createMenuBar()
});
#endif

window_menu->addSeparator();
window_menu->addAction(m_zoom_in_action);
window_menu->addAction(m_zoom_out_action);
window_menu->addAction(m_zoom_reset_action);

if (walletFrame) {
#ifdef Q_OS_MACOS
window_menu->addSeparator();
Expand Down Expand Up @@ -737,6 +786,27 @@ void BitcoinGUI::createMenuBar()
help->addAction(aboutQtAction);
}

void BitcoinGUI::adjustFontScale(int delta)
{
const int current_scale{GUIUtil::fontScale()};
const int new_scale{delta == 0
? GUIUtil::defaultFontScale()
: std::clamp(current_scale + delta, GUIUtil::FONT_SCALE_MIN, GUIUtil::FONT_SCALE_MAX)};

if (new_scale == current_scale) {
return;
}

GUIUtil::setFontScale(new_scale);
GUIUtil::updateFonts();
updateWidth();

// With -nosettings there is no settings file to write, so the zoom only lasts for this session
if (clientModel && clientModel->getOptionsModel() && gArgs.GetSettingsPath()) {
clientModel->getOptionsModel()->setOption(OptionsModel::FontScale, new_scale);
}
}

void BitcoinGUI::createToolBars()
{
#ifdef ENABLE_WALLET
Expand Down Expand Up @@ -926,6 +996,11 @@ void BitcoinGUI::setClientModel(ClientModel *_clientModel, interfaces::BlockAndH
unitDisplayControl->setOptionsModel(optionsModel);
m_mask_values_action->setChecked(optionsModel->getOption(OptionsModel::OptionID::MaskValues).toBool());

const bool font_scale_overridden{optionsModel->isOptionOverridden("-font-scale")};
for (QAction* action : {m_zoom_in_action, m_zoom_out_action, m_zoom_reset_action}) {
action->setEnabled(!font_scale_overridden);
}

connect(optionsModel, &OptionsModel::displayUnitChanged, this, [this]() { m_last_gov_cycle_height.reset(); updateGovernanceCycleIcon(); });
connect(optionsModel, &OptionsModel::showCoinJoinChanged, this, &BitcoinGUI::updateCoinJoinVisibility);
connect(optionsModel, &OptionsModel::showGovernanceChanged, this, &BitcoinGUI::updateGovernanceVisibility);
Expand Down Expand Up @@ -955,6 +1030,9 @@ void BitcoinGUI::setClientModel(ClientModel *_clientModel, interfaces::BlockAndH
}
#endif // ENABLE_WALLET
unitDisplayControl->setOptionsModel(nullptr);
for (QAction* action : {m_zoom_in_action, m_zoom_out_action, m_zoom_reset_action}) {
action->setEnabled(false);
}

#ifdef Q_OS_MACOS
if(dockIconMenu)
Expand Down
6 changes: 6 additions & 0 deletions src/qt/bitcoingui.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ class BitcoinGUI : public QMainWindow
QAction* m_mask_values_action{nullptr};
QAction* m_migrate_wallet_action{nullptr};
QMenu* m_migrate_wallet_menu{nullptr};
QAction* m_zoom_in_action{nullptr};
QAction* m_zoom_out_action{nullptr};
QAction* m_zoom_reset_action{nullptr};

QComboBox* m_wallet_selector = nullptr;

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

/** Apply a global font scale delta or reset when delta is 0. */
void adjustFontScale(int delta);

/** Regenerate all pre-cached governance clock pixmaps (e.g. after a theme change). */
void refreshGovernanceCycleIcons();

Expand Down
4 changes: 2 additions & 2 deletions src/qt/forms/appearancewidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,10 @@
</size>
</property>
<property name="minimum">
<number>-30</number>
<number>-50</number>
</property>
<property name="maximum">
<number>30</number>
<number>100</number>
Comment thread
coderabbitai[bot] marked this conversation as resolved.
</property>
<property name="singleStep">
<number>10</number>
Expand Down
6 changes: 6 additions & 0 deletions src/qt/guiutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,14 @@ namespace GUIUtil
/** Known fonts and their "selectable in UI" flag, in registration order. */
const std::vector<std::pair<QString, /*selectable=*/bool>>& knownFonts();

/** Supported font scale range; much below the minimum text becomes unreadably small. */
constexpr int FONT_SCALE_MIN{-50};
constexpr int FONT_SCALE_MAX{100};
void setFontScale(int font_scale);
int fontScale();
/** Apply `-font-scale` from the command line, config file or settings.json.
* Returns false if it is out of range (no state change in that case). */
bool setFontScaleFromArg();

/* Weight operations expressed as caller-friendly arg ints 0..8 -- the format used by
* `-font-weight-*` CLI args and QSettings persistence. */
Expand Down
10 changes: 10 additions & 0 deletions src/qt/guiutil_font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <QWidget>

#include <cmath>
#include <cstdint>
#include <map>
#include <memory>
#include <optional>
Expand Down Expand Up @@ -580,6 +581,15 @@ const std::vector<std::pair<QString, bool>>& knownFonts() { return g_fonts_known
void setFontScale(int font_scale) { g_font_registry.SetFontScale(font_scale); }
int fontScale() { return g_font_registry.GetFontScale(); }

bool setFontScaleFromArg()
{
if (!gArgs.IsArgSet("-font-scale")) return true;
const int64_t font_scale{gArgs.GetIntArg("-font-scale", fontScale())};
if (font_scale < FONT_SCALE_MIN || font_scale > FONT_SCALE_MAX) return false;
setFontScale(static_cast<int>(font_scale));
return true;
}

int currentWeightArg(FontWeight slot)
{
return weightToArg(slot == FontWeight::Bold ? g_font_registry.GetWeightBold()
Expand Down
31 changes: 25 additions & 6 deletions src/qt/optionsmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@

#include <univalue.h>

#include <algorithm>

const char *DEFAULT_GUI_PROXY_HOST = "127.0.0.1";

static QString GetDefaultProxyAddress();
Expand Down Expand Up @@ -115,6 +117,14 @@ static void UpdateRwSetting(interfaces::Node& node, OptionsModel::OptionID optio
}
}

//! Whether settings.json holds the setting, which then takes precedence over the config file.
static bool IsSettingsFileValue(const std::string& name)
{
bool found{false};
gArgs.LockSettings([&](const util::Settings& settings) { found = settings.rw_settings.count(name) > 0; });
return found;
}

//! Convert enabled/size values to bitcoin -prune setting.
static util::SettingsValue PruneSetting(bool prune_enabled, int prune_size_gb)
{
Expand Down Expand Up @@ -278,15 +288,24 @@ bool OptionsModel::Init(bilingual_str& error)
}

// Font Scale
if (node().isSettingIgnored("font-scale")) {
const bool font_scale_overridden{node().isSettingIgnored("font-scale")};
if (font_scale_overridden) {
addOverriddenOption("-font-scale");
}
int64_t font_scale;
try {
font_scale = SettingToInt(node().getPersistentSetting("font-scale"), GUIUtil::defaultFontScale());
} catch (const std::exception& e) {
return setting_error("font-scale", e);
}
const int clamped_scale{static_cast<int>(std::clamp<int64_t>(font_scale, GUIUtil::FONT_SCALE_MIN, GUIUtil::FONT_SCALE_MAX))};
// Save a clamped settings.json value so the -font-scale validation at startup accepts it;
// an out-of-range config file value is left for that validation to reject.
if (clamped_scale != font_scale && !font_scale_overridden && IsSettingsFileValue("font-scale")) {
UpdateRwSetting(node(), FontScale, /*suffix=*/"", clamped_scale);
}
if (GUIUtil::fontsLoaded()) {
try {
GUIUtil::setFontScale(SettingToInt(node().getPersistentSetting("font-scale"), GUIUtil::defaultFontScale()));
} catch (const std::exception& e) {
return setting_error("font-scale", e);
}
GUIUtil::setFontScale(clamped_scale);
}

// Font Weight (Normal)
Expand Down
19 changes: 10 additions & 9 deletions src/qt/rpcconsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,16 @@ RPCConsole::RPCConsole(interfaces::Node& node, QWidget* parent, Qt::WindowFlags

setButtonIcons();

// Not in setButtonIcons(): it re-runs on theme changes and would stack duplicate QShortcuts.
//: Main shortcut to increase the RPC console font size.
ui->fontBiggerButton->setShortcut(tr("Ctrl++"));
//: Secondary shortcut to increase the RPC console font size.
GUIUtil::AddButtonShortcut(ui->fontBiggerButton, tr("Ctrl+="));
//: Main shortcut to decrease the RPC console font size.
ui->fontSmallerButton->setShortcut(tr("Ctrl+-"));
//: Secondary shortcut to decrease the RPC console font size.
GUIUtil::AddButtonShortcut(ui->fontSmallerButton, tr("Ctrl+_"));

// Install event filter for up and down arrow
ui->lineEdit->installEventFilter(this);
ui->lineEdit->setMaxLength(16 * 1024 * 1024);
Expand Down Expand Up @@ -1342,16 +1352,7 @@ void RPCConsole::setButtonIcons()
GUIUtil::setIcon(ui->clearButton, "remove", GUIUtil::ThemedColor::RED, consoleButtonsSize);

GUIUtil::setIcon(ui->fontBiggerButton, "fontbigger", GUIUtil::ThemedColor::BLUE, consoleButtonsSize);
//: Main shortcut to increase the RPC console font size.
ui->fontBiggerButton->setShortcut(tr("Ctrl++"));
//: Secondary shortcut to increase the RPC console font size.
GUIUtil::AddButtonShortcut(ui->fontBiggerButton, tr("Ctrl+="));

GUIUtil::setIcon(ui->fontSmallerButton, "fontsmaller", GUIUtil::ThemedColor::BLUE, consoleButtonsSize);
//: Main shortcut to decrease the RPC console font size.
ui->fontSmallerButton->setShortcut(tr("Ctrl+-"));
//: Secondary shortcut to decrease the RPC console font size.
GUIUtil::AddButtonShortcut(ui->fontSmallerButton, tr("Ctrl+_"));
Comment on lines -1345 to -1354

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shortcut Ctrl++ doesn't work when RPC Console is open (no zoom for main window); but shortcut for font bigger / font smaller is removed by this PR.

Could you revert these changes?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted in e4498de (fix(qt): restore RPC console font-size shortcuts). The console shortcuts are registered like on develop again: setShortcut("Ctrl++") / setShortcut("Ctrl+-") plus the Ctrl+= / Ctrl+_ secondaries, all with the normal window context, so they fire from the command line and message view. The only remaining change is that they are registered once in the constructor instead of in setButtonIcons() (which re-ran on every theme change and stacked duplicate QShortcuts for the secondary keys).

With the console in its own window, Ctrl++ there resizes the console text and Ctrl++ in the main window zooms the whole UI. With -disablewallet (console embedded in the main window) the zoom actions don't bind those keys, so the console keeps them. On macOS the main menu bar stays active over the console window, so the zoom actions forward to the console font there. I couldn't drive the GUI interactively on this machine, so I'm leaving this open for you to re-check on your setup.


🤖 Posted autonomously by Codex on behalf of pasta.

}

void RPCConsole::reloadThemedWidgets()
Expand Down
Loading
Loading