From 827d9a3be8209587c532f061753e99730b9be4c4 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Thu, 24 Nov 2016 14:26:20 +0100 Subject: qt: Replace NetworkToggleStatusBarControl with generic ClickableLabel Generalize the clickable label functionality. We will use this to add similar functionality to the sync icon. --- src/qt/bitcoingui.cpp | 26 ++++++++++---------------- src/qt/bitcoingui.h | 19 ++++--------------- src/qt/guiutil.cpp | 7 +++++++ src/qt/guiutil.h | 14 ++++++++++++++ 4 files changed, 35 insertions(+), 31 deletions(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 6112a1d256..0f046f30e9 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -199,7 +199,7 @@ BitcoinGUI::BitcoinGUI(const PlatformStyle *_platformStyle, const NetworkStyle * unitDisplayControl = new UnitDisplayStatusBarControl(platformStyle); labelWalletEncryptionIcon = new QLabel(); labelWalletHDStatusIcon = new QLabel(); - connectionsControl = new NetworkToggleStatusBarControl(); + connectionsControl = new GUIUtil::ClickableLabel(); labelBlocksIcon = new QLabel(); if(enableWallet) { @@ -244,6 +244,8 @@ BitcoinGUI::BitcoinGUI(const PlatformStyle *_platformStyle, const NetworkStyle * // Subscribe to notifications from core subscribeToCoreSignals(); + connect(connectionsControl, SIGNAL(clicked(QPoint)), this, SLOT(toggleNetworkActive())); + modalOverlay = new ModalOverlay(this->centralWidget()); #ifdef ENABLE_WALLET if(enableWallet) @@ -490,7 +492,6 @@ void BitcoinGUI::setClientModel(ClientModel *_clientModel) } #endif // ENABLE_WALLET unitDisplayControl->setOptionsModel(_clientModel->getOptionsModel()); - connectionsControl->setClientModel(_clientModel); OptionsModel* optionsModel = _clientModel->getOptionsModel(); if(optionsModel) @@ -517,7 +518,6 @@ void BitcoinGUI::setClientModel(ClientModel *_clientModel) walletFrame->setClientModel(nullptr); #endif // ENABLE_WALLET unitDisplayControl->setOptionsModel(nullptr); - connectionsControl->setClientModel(nullptr); } } @@ -1171,6 +1171,13 @@ void BitcoinGUI::unsubscribeFromCoreSignals() uiInterface.ThreadSafeQuestion.disconnect(boost::bind(ThreadSafeMessageBox, this, _1, _3, _4)); } +void BitcoinGUI::toggleNetworkActive() +{ + if (clientModel) { + clientModel->setNetworkActive(!clientModel->getNetworkActive()); + } +} + UnitDisplayStatusBarControl::UnitDisplayStatusBarControl(const PlatformStyle *platformStyle) : optionsModel(0), menu(0) @@ -1244,16 +1251,3 @@ void UnitDisplayStatusBarControl::onMenuSelection(QAction* action) optionsModel->setDisplayUnit(action->data()); } } - -void NetworkToggleStatusBarControl::mousePressEvent(QMouseEvent *event) -{ - if (clientModel) { - clientModel->setNetworkActive(!clientModel->getNetworkActive()); - } -} - -/** Lets the control know about the Client Model */ -void NetworkToggleStatusBarControl::setClientModel(ClientModel *_clientModel) -{ - this->clientModel = _clientModel; -} diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index 1b02e77fc4..59540bfe6b 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -26,7 +26,6 @@ class PlatformStyle; class RPCConsole; class SendCoinsRecipient; class UnitDisplayStatusBarControl; -class NetworkToggleStatusBarControl; class WalletFrame; class WalletModel; class HelpMessageDialog; @@ -86,7 +85,7 @@ private: UnitDisplayStatusBarControl *unitDisplayControl; QLabel *labelWalletEncryptionIcon; QLabel *labelWalletHDStatusIcon; - NetworkToggleStatusBarControl *connectionsControl; + QLabel *connectionsControl; QLabel *labelBlocksIcon; QLabel *progressBarLabel; QProgressBar *progressBar; @@ -238,6 +237,9 @@ private Q_SLOTS: /** When hideTrayIcon setting is changed in OptionsModel hide or show the icon accordingly. */ void setTrayIconVisible(bool); + /** Toggle networking */ + void toggleNetworkActive(); + void showModalOverlay(); }; @@ -270,17 +272,4 @@ private Q_SLOTS: void onMenuSelection(QAction* action); }; -class NetworkToggleStatusBarControl : public QLabel -{ - Q_OBJECT - -public: - void setClientModel(ClientModel *clientModel); -protected: - void mousePressEvent(QMouseEvent *event); - -private: - ClientModel *clientModel; -}; - #endif // BITCOIN_QT_BITCOINGUI_H diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp index 130cfc6e7d..b2e8119299 100644 --- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -55,6 +55,7 @@ #include #include // for Qt::mightBeRichText #include +#include #if QT_VERSION < 0x050000 #include @@ -986,4 +987,10 @@ QString formateNiceTimeOffset(qint64 secs) } return timeBehindText; } + +void ClickableLabel::mousePressEvent(QMouseEvent *event) +{ + Q_EMIT clicked(event->pos()); +} + } // namespace GUIUtil diff --git a/src/qt/guiutil.h b/src/qt/guiutil.h index 8f1f3fbb2c..9a17d24f07 100644 --- a/src/qt/guiutil.h +++ b/src/qt/guiutil.h @@ -14,6 +14,7 @@ #include #include #include +#include #include @@ -215,6 +216,19 @@ namespace GUIUtil typedef QProgressBar ProgressBar; #endif + class ClickableLabel : public QLabel + { + Q_OBJECT + + Q_SIGNALS: + /** Emitted when the label is clicked. The relative mouse coordinates of the click are + * passed to the signal. + */ + void clicked(const QPoint& point); + protected: + void mousePressEvent(QMouseEvent *event); + }; + } // namespace GUIUtil #endif // BITCOIN_QT_GUIUTIL_H -- cgit v1.2.3 From 042f9fa071fd76ab310cd47b73d0e620a7850660 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Thu, 24 Nov 2016 14:37:36 +0100 Subject: qt: Show progress overlay when clicking spinner icon Bring up the modal progress overlay when the user clicks the spinner icon in the task bar. I think this is the intuitive thing to do when that icon is clicked. --- src/qt/bitcoingui.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 0f046f30e9..54ed867de0 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -200,7 +200,7 @@ BitcoinGUI::BitcoinGUI(const PlatformStyle *_platformStyle, const NetworkStyle * labelWalletEncryptionIcon = new QLabel(); labelWalletHDStatusIcon = new QLabel(); connectionsControl = new GUIUtil::ClickableLabel(); - labelBlocksIcon = new QLabel(); + labelBlocksIcon = new GUIUtil::ClickableLabel(); if(enableWallet) { frameBlocksLayout->addStretch(); @@ -248,8 +248,10 @@ BitcoinGUI::BitcoinGUI(const PlatformStyle *_platformStyle, const NetworkStyle * modalOverlay = new ModalOverlay(this->centralWidget()); #ifdef ENABLE_WALLET - if(enableWallet) + if(enableWallet) { connect(walletFrame, SIGNAL(requestedSyncWarningInfo()), this, SLOT(showModalOverlay())); + connect(labelBlocksIcon, SIGNAL(clicked(QPoint)), this, SLOT(showModalOverlay())); + } #endif } -- cgit v1.2.3