Skip to content

Commit c52b756

Browse files
laanwjknst
authored andcommitted
Merge bitcoin-core/gui#281: set shortcuts for console's resize buttons
2a45134 qt: Add shortcuts for console font resize buttons (Hennadii Stepanov) a2e122f qt: Add GUIUtil::AddButtonShortcut (Hennadii Stepanov) 4ee9ee7 qt: Use native presentation of shortcut (Hennadii Stepanov) Pull request description: On `master` the only way to resize the console font is to manually move your mouse and click the resize buttons. This PR introduces convenient keyboard shortcuts to resize the console font. The common resize shortcuts for applications are `Ctrl+=`/`Ctrl++` and `Ctrl+-`/`Ctrl+_`. This means that the resize QPushButtons need two shortcuts each, but you cannot assign multiple shortcuts to a QPushButton. See: https://doc.qt.io/qt-5/qabstractbutton.html#shortcut-prop To get around this, we introduce a new function in `guiutil`, which connects a supplied `QKeySequence` shortcut to a `QAbstractButton`. This function can be reused in other situations where more than one shortcut is needed for a button. | PR on macOS | PR on Linux | | ---------------- | ------------ | | ![mac-resize-shortcuts](https://user-images.githubusercontent.com/23396902/114750132-a2752580-9d21-11eb-9542-15716f2c257d.gif) | ![linux-resize-shortcuts](https://user-images.githubusercontent.com/23396902/114750165-aacd6080-9d21-11eb-8abc-5388690dcf0b.gif) | ACKs for top commit: hebasto: re-ACK 2a45134 Talkless: tACK 2a45134, tested on Debian Sid with Qt 5.15.2, shortcuts still work. Tree-SHA512: e894ccb7e5c695ba83998c21a474d6c587c9c849f12ced665c5e0034feb6b143e41b32ba135cab6cfab22cbf153d5a52b1083b2a278e6dfca3f5ad14c0f6c573
1 parent b442a59 commit c52b756

File tree

3 files changed

+41
-14
lines changed

3 files changed

+41
-14
lines changed

src/qt/guiutil.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,11 @@ void setupAppearance(QWidget* parent, OptionsModel* model)
340340
}
341341
}
342342

343+
void AddButtonShortcut(QAbstractButton* button, const QKeySequence& shortcut)
344+
{
345+
QObject::connect(new QShortcut(shortcut, button), &QShortcut::activated, [button]() { button->animateClick(); });
346+
}
347+
343348
bool parseBitcoinURI(const QUrl &uri, SendCoinsRecipient *out)
344349
{
345350
// return if URI is not valid or is no dash: URI

src/qt/guiutil.h

+9
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class QAction;
4444
class QButtonGroup;
4545
class QDateTime;
4646
class QFont;
47+
class QKeySequence;
4748
class QLineEdit;
4849
class QMenu;
4950
class QPoint;
@@ -135,6 +136,14 @@ namespace GUIUtil
135136
// Setup appearance settings if not done yet
136137
void setupAppearance(QWidget* parent, OptionsModel* model);
137138

139+
/**
140+
* Connects an additional shortcut to a QAbstractButton. Works around the
141+
* one shortcut limitation of the button's shortcut property.
142+
* @param[in] button QAbstractButton to assign shortcut to
143+
* @param[in] shortcut QKeySequence to use as shortcut
144+
*/
145+
void AddButtonShortcut(QAbstractButton* button, const QKeySequence& shortcut);
146+
138147
// Parse "dash:" URI into recipient object, return true on successful parsing
139148
bool parseBitcoinURI(const QUrl &uri, SendCoinsRecipient *out);
140149
bool parseBitcoinURI(QString uri, SendCoinsRecipient *out);

src/qt/rpcconsole.cpp

+27-14
Original file line numberDiff line numberDiff line change
@@ -936,20 +936,23 @@ void RPCConsole::clear(bool keep_prompt)
936936
).arg(consoleFontSize)
937937
);
938938

939-
#ifdef Q_OS_MAC
940-
QString clsKey = "(⌘)-L";
941-
#else
942-
QString clsKey = "Ctrl-L";
943-
#endif
944-
945-
message(CMD_REPLY, (tr("Welcome to the %1 RPC console.").arg(PACKAGE_NAME) + "<br>" +
946-
tr("Use up and down arrows to navigate history, and %1 to clear screen.").arg("<b>"+clsKey+"</b>") + "<br>" +
947-
tr("Type %1 for an overview of available commands.").arg("<b>help</b>") + "<br>" +
948-
tr("For more information on using this console type %1.").arg("<b>help-console</b>") +
949-
"<br><span class=\"secwarning\"><br>" +
950-
tr("WARNING: Scammers have been active, telling users to type commands here, stealing their wallet contents. Do not use this console without fully understanding the ramifications of a command.") +
951-
"</span>"),
952-
true);
939+
message(CMD_REPLY,
940+
tr("Welcome to the %1 RPC console.").arg(PACKAGE_NAME) +
941+
"<br>" +
942+
tr("Use up and down arrows to navigate history, and %1 to clear screen.")
943+
.arg("<b>" + ui->clearButton->shortcut().toString(QKeySequence::NativeText) + "</b>") +
944+
"<br>" +
945+
tr("Use %1 and %2 to increase or decrease the font size.")
946+
.arg("<b>" + ui->fontBiggerButton->shortcut().toString(QKeySequence::NativeText) + "</b>")
947+
.arg("<b>" + ui->fontSmallerButton->shortcut().toString(QKeySequence::NativeText) + "</b>") +
948+
"<br>" +
949+
tr("Type %1 for an overview of available commands.").arg("<b>help</b>") +
950+
"<br>" +
951+
tr("For more information on using this console type %1.").arg("<b>help-console</b>") +
952+
"<br><span class=\"secwarning\"><br>" +
953+
tr("WARNING: Scammers have been active, telling users to type commands here, stealing their wallet contents. Do not use this console without fully understanding the ramifications of a command.") +
954+
"</span>",
955+
true);
953956
}
954957

955958
void RPCConsole::keyPressEvent(QKeyEvent *event)
@@ -1285,8 +1288,18 @@ void RPCConsole::setButtonIcons()
12851288
{
12861289
const QSize consoleButtonsSize(BUTTON_ICONSIZE * 0.8, BUTTON_ICONSIZE * 0.8);
12871290
GUIUtil::setIcon(ui->clearButton, "remove", GUIUtil::ThemedColor::RED, consoleButtonsSize);
1291+
12881292
GUIUtil::setIcon(ui->fontBiggerButton, "fontbigger", GUIUtil::ThemedColor::BLUE, consoleButtonsSize);
1293+
//: Main shortcut to increase the RPC console font size.
1294+
ui->fontBiggerButton->setShortcut(tr("Ctrl++"));
1295+
//: Secondary shortcut to increase the RPC console font size.
1296+
GUIUtil::AddButtonShortcut(ui->fontBiggerButton, tr("Ctrl+="));
1297+
12891298
GUIUtil::setIcon(ui->fontSmallerButton, "fontsmaller", GUIUtil::ThemedColor::BLUE, consoleButtonsSize);
1299+
//: Main shortcut to decrease the RPC console font size.
1300+
ui->fontSmallerButton->setShortcut(tr("Ctrl+-"));
1301+
//: Secondary shortcut to decrease the RPC console font size.
1302+
GUIUtil::AddButtonShortcut(ui->fontSmallerButton, tr("Ctrl+_"));
12901303
}
12911304

12921305
void RPCConsole::reloadThemedWidgets()

0 commit comments

Comments
 (0)