Skip to content

Commit 710c8ba

Browse files
committed
Merge bitcoin-core#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
2 parents 37e9f07 + 2a45134 commit 710c8ba

File tree

3 files changed

+43
-14
lines changed

3 files changed

+43
-14
lines changed

src/qt/guiutil.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <shlwapi.h>
3030
#endif
3131

32+
#include <QAbstractButton>
3233
#include <QAbstractItemView>
3334
#include <QApplication>
3435
#include <QClipboard>
@@ -121,6 +122,11 @@ void setupAddressWidget(QValidatedLineEdit *widget, QWidget *parent)
121122
widget->setCheckValidator(new BitcoinAddressCheckValidator(parent));
122123
}
123124

125+
void AddButtonShortcut(QAbstractButton* button, const QKeySequence& shortcut)
126+
{
127+
QObject::connect(new QShortcut(shortcut, button), &QShortcut::activated, [button]() { button->animateClick(); });
128+
}
129+
124130
bool parseBitcoinURI(const QUrl &uri, SendCoinsRecipient *out)
125131
{
126132
// return if URI is not valid or is no bitcoin: URI

src/qt/guiutil.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@ namespace interfaces
3636
}
3737

3838
QT_BEGIN_NAMESPACE
39+
class QAbstractButton;
3940
class QAbstractItemView;
4041
class QAction;
4142
class QDateTime;
4243
class QFont;
44+
class QKeySequence;
4345
class QLineEdit;
4446
class QMenu;
4547
class QPoint;
@@ -65,6 +67,14 @@ namespace GUIUtil
6567
// Set up widget for address
6668
void setupAddressWidget(QValidatedLineEdit *widget, QWidget *parent);
6769

70+
/**
71+
* Connects an additional shortcut to a QAbstractButton. Works around the
72+
* one shortcut limitation of the button's shortcut property.
73+
* @param[in] button QAbstractButton to assign shortcut to
74+
* @param[in] shortcut QKeySequence to use as shortcut
75+
*/
76+
void AddButtonShortcut(QAbstractButton* button, const QKeySequence& shortcut);
77+
6878
// Parse "bitcoin:" URI into recipient object, return true on successful parsing
6979
bool parseBitcoinURI(const QUrl &uri, SendCoinsRecipient *out);
7080
bool parseBitcoinURI(QString uri, SendCoinsRecipient *out);

src/qt/rpcconsole.cpp

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -495,8 +495,18 @@ RPCConsole::RPCConsole(interfaces::Node& node, const PlatformStyle *_platformSty
495495
ui->openDebugLogfileButton->setIcon(platformStyle->SingleColorIcon(":/icons/export"));
496496
}
497497
ui->clearButton->setIcon(platformStyle->SingleColorIcon(":/icons/remove"));
498+
498499
ui->fontBiggerButton->setIcon(platformStyle->SingleColorIcon(":/icons/fontbigger"));
500+
//: Main shortcut to increase the RPC console font size.
501+
ui->fontBiggerButton->setShortcut(tr("Ctrl++"));
502+
//: Secondary shortcut to increase the RPC console font size.
503+
GUIUtil::AddButtonShortcut(ui->fontBiggerButton, tr("Ctrl+="));
504+
499505
ui->fontSmallerButton->setIcon(platformStyle->SingleColorIcon(":/icons/fontsmaller"));
506+
//: Main shortcut to decrease the RPC console font size.
507+
ui->fontSmallerButton->setShortcut(tr("Ctrl+-"));
508+
//: Secondary shortcut to decrease the RPC console font size.
509+
GUIUtil::AddButtonShortcut(ui->fontSmallerButton, tr("Ctrl+_"));
500510

501511
// Install event filter for up and down arrow
502512
ui->lineEdit->installEventFilter(this);
@@ -806,20 +816,23 @@ void RPCConsole::clear(bool keep_prompt)
806816
).arg(fixedFontInfo.family(), QString("%1pt").arg(consoleFontSize))
807817
);
808818

809-
#ifdef Q_OS_MAC
810-
QString clsKey = "(⌘)-L";
811-
#else
812-
QString clsKey = "Ctrl-L";
813-
#endif
814-
815-
message(CMD_REPLY, (tr("Welcome to the %1 RPC console.").arg(PACKAGE_NAME) + "<br>" +
816-
tr("Use up and down arrows to navigate history, and %1 to clear screen.").arg("<b>"+clsKey+"</b>") + "<br>" +
817-
tr("Type %1 for an overview of available commands.").arg("<b>help</b>") + "<br>" +
818-
tr("For more information on using this console type %1.").arg("<b>help-console</b>") +
819-
"<br><span class=\"secwarning\"><br>" +
820-
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.") +
821-
"</span>"),
822-
true);
819+
message(CMD_REPLY,
820+
tr("Welcome to the %1 RPC console.").arg(PACKAGE_NAME) +
821+
"<br>" +
822+
tr("Use up and down arrows to navigate history, and %1 to clear screen.")
823+
.arg("<b>" + ui->clearButton->shortcut().toString(QKeySequence::NativeText) + "</b>") +
824+
"<br>" +
825+
tr("Use %1 and %2 to increase or decrease the font size.")
826+
.arg("<b>" + ui->fontBiggerButton->shortcut().toString(QKeySequence::NativeText) + "</b>")
827+
.arg("<b>" + ui->fontSmallerButton->shortcut().toString(QKeySequence::NativeText) + "</b>") +
828+
"<br>" +
829+
tr("Type %1 for an overview of available commands.").arg("<b>help</b>") +
830+
"<br>" +
831+
tr("For more information on using this console type %1.").arg("<b>help-console</b>") +
832+
"<br><span class=\"secwarning\"><br>" +
833+
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.") +
834+
"</span>",
835+
true);
823836
}
824837

825838
void RPCConsole::keyPressEvent(QKeyEvent *event)

0 commit comments

Comments
 (0)