Skip to content

Commit 827d9a3

Browse files
committed
qt: Replace NetworkToggleStatusBarControl with generic ClickableLabel
Generalize the clickable label functionality. We will use this to add similar functionality to the sync icon.
1 parent bc121b0 commit 827d9a3

File tree

4 files changed

+35
-31
lines changed

4 files changed

+35
-31
lines changed

src/qt/bitcoingui.cpp

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ BitcoinGUI::BitcoinGUI(const PlatformStyle *_platformStyle, const NetworkStyle *
199199
unitDisplayControl = new UnitDisplayStatusBarControl(platformStyle);
200200
labelWalletEncryptionIcon = new QLabel();
201201
labelWalletHDStatusIcon = new QLabel();
202-
connectionsControl = new NetworkToggleStatusBarControl();
202+
connectionsControl = new GUIUtil::ClickableLabel();
203203
labelBlocksIcon = new QLabel();
204204
if(enableWallet)
205205
{
@@ -244,6 +244,8 @@ BitcoinGUI::BitcoinGUI(const PlatformStyle *_platformStyle, const NetworkStyle *
244244
// Subscribe to notifications from core
245245
subscribeToCoreSignals();
246246

247+
connect(connectionsControl, SIGNAL(clicked(QPoint)), this, SLOT(toggleNetworkActive()));
248+
247249
modalOverlay = new ModalOverlay(this->centralWidget());
248250
#ifdef ENABLE_WALLET
249251
if(enableWallet)
@@ -490,7 +492,6 @@ void BitcoinGUI::setClientModel(ClientModel *_clientModel)
490492
}
491493
#endif // ENABLE_WALLET
492494
unitDisplayControl->setOptionsModel(_clientModel->getOptionsModel());
493-
connectionsControl->setClientModel(_clientModel);
494495

495496
OptionsModel* optionsModel = _clientModel->getOptionsModel();
496497
if(optionsModel)
@@ -517,7 +518,6 @@ void BitcoinGUI::setClientModel(ClientModel *_clientModel)
517518
walletFrame->setClientModel(nullptr);
518519
#endif // ENABLE_WALLET
519520
unitDisplayControl->setOptionsModel(nullptr);
520-
connectionsControl->setClientModel(nullptr);
521521
}
522522
}
523523

@@ -1171,6 +1171,13 @@ void BitcoinGUI::unsubscribeFromCoreSignals()
11711171
uiInterface.ThreadSafeQuestion.disconnect(boost::bind(ThreadSafeMessageBox, this, _1, _3, _4));
11721172
}
11731173

1174+
void BitcoinGUI::toggleNetworkActive()
1175+
{
1176+
if (clientModel) {
1177+
clientModel->setNetworkActive(!clientModel->getNetworkActive());
1178+
}
1179+
}
1180+
11741181
UnitDisplayStatusBarControl::UnitDisplayStatusBarControl(const PlatformStyle *platformStyle) :
11751182
optionsModel(0),
11761183
menu(0)
@@ -1244,16 +1251,3 @@ void UnitDisplayStatusBarControl::onMenuSelection(QAction* action)
12441251
optionsModel->setDisplayUnit(action->data());
12451252
}
12461253
}
1247-
1248-
void NetworkToggleStatusBarControl::mousePressEvent(QMouseEvent *event)
1249-
{
1250-
if (clientModel) {
1251-
clientModel->setNetworkActive(!clientModel->getNetworkActive());
1252-
}
1253-
}
1254-
1255-
/** Lets the control know about the Client Model */
1256-
void NetworkToggleStatusBarControl::setClientModel(ClientModel *_clientModel)
1257-
{
1258-
this->clientModel = _clientModel;
1259-
}

src/qt/bitcoingui.h

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ class PlatformStyle;
2626
class RPCConsole;
2727
class SendCoinsRecipient;
2828
class UnitDisplayStatusBarControl;
29-
class NetworkToggleStatusBarControl;
3029
class WalletFrame;
3130
class WalletModel;
3231
class HelpMessageDialog;
@@ -86,7 +85,7 @@ class BitcoinGUI : public QMainWindow
8685
UnitDisplayStatusBarControl *unitDisplayControl;
8786
QLabel *labelWalletEncryptionIcon;
8887
QLabel *labelWalletHDStatusIcon;
89-
NetworkToggleStatusBarControl *connectionsControl;
88+
QLabel *connectionsControl;
9089
QLabel *labelBlocksIcon;
9190
QLabel *progressBarLabel;
9291
QProgressBar *progressBar;
@@ -238,6 +237,9 @@ private Q_SLOTS:
238237
/** When hideTrayIcon setting is changed in OptionsModel hide or show the icon accordingly. */
239238
void setTrayIconVisible(bool);
240239

240+
/** Toggle networking */
241+
void toggleNetworkActive();
242+
241243
void showModalOverlay();
242244
};
243245

@@ -270,17 +272,4 @@ private Q_SLOTS:
270272
void onMenuSelection(QAction* action);
271273
};
272274

273-
class NetworkToggleStatusBarControl : public QLabel
274-
{
275-
Q_OBJECT
276-
277-
public:
278-
void setClientModel(ClientModel *clientModel);
279-
protected:
280-
void mousePressEvent(QMouseEvent *event);
281-
282-
private:
283-
ClientModel *clientModel;
284-
};
285-
286275
#endif // BITCOIN_QT_BITCOINGUI_H

src/qt/guiutil.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
#include <QSettings>
5656
#include <QTextDocument> // for Qt::mightBeRichText
5757
#include <QThread>
58+
#include <QMouseEvent>
5859

5960
#if QT_VERSION < 0x050000
6061
#include <QUrl>
@@ -986,4 +987,10 @@ QString formateNiceTimeOffset(qint64 secs)
986987
}
987988
return timeBehindText;
988989
}
990+
991+
void ClickableLabel::mousePressEvent(QMouseEvent *event)
992+
{
993+
Q_EMIT clicked(event->pos());
994+
}
995+
989996
} // namespace GUIUtil

src/qt/guiutil.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <QProgressBar>
1515
#include <QString>
1616
#include <QTableView>
17+
#include <QLabel>
1718

1819
#include <boost/filesystem.hpp>
1920

@@ -215,6 +216,19 @@ namespace GUIUtil
215216
typedef QProgressBar ProgressBar;
216217
#endif
217218

219+
class ClickableLabel : public QLabel
220+
{
221+
Q_OBJECT
222+
223+
Q_SIGNALS:
224+
/** Emitted when the label is clicked. The relative mouse coordinates of the click are
225+
* passed to the signal.
226+
*/
227+
void clicked(const QPoint& point);
228+
protected:
229+
void mousePressEvent(QMouseEvent *event);
230+
};
231+
218232
} // namespace GUIUtil
219233

220234
#endif // BITCOIN_QT_GUIUTIL_H

0 commit comments

Comments
 (0)