aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorW. J. van der Laan <laanwj@protonmail.com>2021-05-20 20:54:01 +0200
committerW. J. van der Laan <laanwj@protonmail.com>2021-05-20 22:09:15 +0200
commit710c8ba82953c5fdb7c3c8c9ad6ecf0fd88dface (patch)
treea8c190d94f7228477c93f9182cef8751f4dbb8f4
parent37e9f07996d3a7504ea54180d188ca91fdf0c884 (diff)
parent2a45134b5694c12546d77cdff541612881f7e3e7 (diff)
downloadbitcoin-710c8ba82953c5fdb7c3c8c9ad6ecf0fd88dface.tar.xz
Merge bitcoin-core/gui#281: set shortcuts for console's resize buttons
2a45134b5694c12546d77cdff541612881f7e3e7 qt: Add shortcuts for console font resize buttons (Hennadii Stepanov) a2e122f0fe72d695762db2b83905e246f451300c qt: Add GUIUtil::AddButtonShortcut (Hennadii Stepanov) 4ee9ee72363d46c5ba0c71b8d8283d9c5621e3ed 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 2a45134b5694c12546d77cdff541612881f7e3e7 Talkless: tACK 2a45134b5694c12546d77cdff541612881f7e3e7, tested on Debian Sid with Qt 5.15.2, shortcuts still work. Tree-SHA512: e894ccb7e5c695ba83998c21a474d6c587c9c849f12ced665c5e0034feb6b143e41b32ba135cab6cfab22cbf153d5a52b1083b2a278e6dfca3f5ad14c0f6c573
-rw-r--r--src/qt/guiutil.cpp6
-rw-r--r--src/qt/guiutil.h10
-rw-r--r--src/qt/rpcconsole.cpp41
3 files changed, 43 insertions, 14 deletions
diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp
index 998d38e10d..4691937380 100644
--- a/src/qt/guiutil.cpp
+++ b/src/qt/guiutil.cpp
@@ -29,6 +29,7 @@
#include <shlwapi.h>
#endif
+#include <QAbstractButton>
#include <QAbstractItemView>
#include <QApplication>
#include <QClipboard>
@@ -121,6 +122,11 @@ void setupAddressWidget(QValidatedLineEdit *widget, QWidget *parent)
widget->setCheckValidator(new BitcoinAddressCheckValidator(parent));
}
+void AddButtonShortcut(QAbstractButton* button, const QKeySequence& shortcut)
+{
+ QObject::connect(new QShortcut(shortcut, button), &QShortcut::activated, [button]() { button->animateClick(); });
+}
+
bool parseBitcoinURI(const QUrl &uri, SendCoinsRecipient *out)
{
// return if URI is not valid or is no bitcoin: URI
diff --git a/src/qt/guiutil.h b/src/qt/guiutil.h
index a1cf274354..9c2ad74e1e 100644
--- a/src/qt/guiutil.h
+++ b/src/qt/guiutil.h
@@ -36,10 +36,12 @@ namespace interfaces
}
QT_BEGIN_NAMESPACE
+class QAbstractButton;
class QAbstractItemView;
class QAction;
class QDateTime;
class QFont;
+class QKeySequence;
class QLineEdit;
class QMenu;
class QPoint;
@@ -65,6 +67,14 @@ namespace GUIUtil
// Set up widget for address
void setupAddressWidget(QValidatedLineEdit *widget, QWidget *parent);
+ /**
+ * Connects an additional shortcut to a QAbstractButton. Works around the
+ * one shortcut limitation of the button's shortcut property.
+ * @param[in] button QAbstractButton to assign shortcut to
+ * @param[in] shortcut QKeySequence to use as shortcut
+ */
+ void AddButtonShortcut(QAbstractButton* button, const QKeySequence& shortcut);
+
// Parse "bitcoin:" URI into recipient object, return true on successful parsing
bool parseBitcoinURI(const QUrl &uri, SendCoinsRecipient *out);
bool parseBitcoinURI(QString uri, SendCoinsRecipient *out);
diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp
index eed73e8ce3..afbdc07ba0 100644
--- a/src/qt/rpcconsole.cpp
+++ b/src/qt/rpcconsole.cpp
@@ -495,8 +495,18 @@ RPCConsole::RPCConsole(interfaces::Node& node, const PlatformStyle *_platformSty
ui->openDebugLogfileButton->setIcon(platformStyle->SingleColorIcon(":/icons/export"));
}
ui->clearButton->setIcon(platformStyle->SingleColorIcon(":/icons/remove"));
+
ui->fontBiggerButton->setIcon(platformStyle->SingleColorIcon(":/icons/fontbigger"));
+ //: 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+="));
+
ui->fontSmallerButton->setIcon(platformStyle->SingleColorIcon(":/icons/fontsmaller"));
+ //: 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);
@@ -806,20 +816,23 @@ void RPCConsole::clear(bool keep_prompt)
).arg(fixedFontInfo.family(), QString("%1pt").arg(consoleFontSize))
);
-#ifdef Q_OS_MAC
- QString clsKey = "(⌘)-L";
-#else
- QString clsKey = "Ctrl-L";
-#endif
-
- message(CMD_REPLY, (tr("Welcome to the %1 RPC console.").arg(PACKAGE_NAME) + "<br>" +
- tr("Use up and down arrows to navigate history, and %1 to clear screen.").arg("<b>"+clsKey+"</b>") + "<br>" +
- tr("Type %1 for an overview of available commands.").arg("<b>help</b>") + "<br>" +
- tr("For more information on using this console type %1.").arg("<b>help-console</b>") +
- "<br><span class=\"secwarning\"><br>" +
- 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.") +
- "</span>"),
- true);
+ message(CMD_REPLY,
+ tr("Welcome to the %1 RPC console.").arg(PACKAGE_NAME) +
+ "<br>" +
+ tr("Use up and down arrows to navigate history, and %1 to clear screen.")
+ .arg("<b>" + ui->clearButton->shortcut().toString(QKeySequence::NativeText) + "</b>") +
+ "<br>" +
+ tr("Use %1 and %2 to increase or decrease the font size.")
+ .arg("<b>" + ui->fontBiggerButton->shortcut().toString(QKeySequence::NativeText) + "</b>")
+ .arg("<b>" + ui->fontSmallerButton->shortcut().toString(QKeySequence::NativeText) + "</b>") +
+ "<br>" +
+ tr("Type %1 for an overview of available commands.").arg("<b>help</b>") +
+ "<br>" +
+ tr("For more information on using this console type %1.").arg("<b>help-console</b>") +
+ "<br><span class=\"secwarning\"><br>" +
+ 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.") +
+ "</span>",
+ true);
}
void RPCConsole::keyPressEvent(QKeyEvent *event)