Skip to content

Commit

Permalink
[gui] Make proxy icon from statusbar clickable
Browse files Browse the repository at this point in the history
Clicking on the proxy icon will open settings showing the network tab
Create enum Tab in OptionsModel
Use new connect syntax
Use lambda for private slots
  • Loading branch information
mess110 committed Jul 24, 2018
1 parent 7ebd8c6 commit 6d5fcad
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 18 deletions.
32 changes: 19 additions & 13 deletions src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ BitcoinGUI::BitcoinGUI(interfaces::Node& node, const PlatformStyle *_platformSty
unitDisplayControl = new UnitDisplayStatusBarControl(platformStyle);
labelWalletEncryptionIcon = new QLabel();
labelWalletHDStatusIcon = new QLabel();
labelProxyIcon = new QLabel();
labelProxyIcon = new GUIUtil::ClickableLabel();
connectionsControl = new GUIUtil::ClickableLabel();
labelBlocksIcon = new GUIUtil::ClickableLabel();
if(enableWallet)
Expand Down Expand Up @@ -193,7 +193,12 @@ BitcoinGUI::BitcoinGUI(interfaces::Node& node, const PlatformStyle *_platformSty
// Subscribe to notifications from core
subscribeToCoreSignals();

connect(connectionsControl, SIGNAL(clicked(QPoint)), this, SLOT(toggleNetworkActive()));
connect(connectionsControl, &GUIUtil::ClickableLabel::clicked, [this] {
m_node.setNetworkActive(!m_node.getNetworkActive());
});
connect(labelProxyIcon, &GUIUtil::ClickableLabel::clicked, [this] {
openOptionsDialogWithTab(OptionsDialog::TAB_NETWORK);
});

modalOverlay = new ModalOverlay(this->centralWidget());
#ifdef ENABLE_WALLET
Expand Down Expand Up @@ -635,12 +640,7 @@ void BitcoinGUI::trayIconActivated(QSystemTrayIcon::ActivationReason reason)

void BitcoinGUI::optionsClicked()
{
if(!clientModel || !clientModel->getOptionsModel())
return;

OptionsDialog dlg(this, enableWallet);
dlg.setModel(clientModel->getOptionsModel());
dlg.exec();
openOptionsDialogWithTab(OptionsDialog::TAB_MAIN);
}

void BitcoinGUI::aboutClicked()
Expand Down Expand Up @@ -764,6 +764,17 @@ void BitcoinGUI::updateHeadersSyncProgressLabel()
progressBarLabel->setText(tr("Syncing Headers (%1%)...").arg(QString::number(100.0 / (headersTipHeight+estHeadersLeft)*headersTipHeight, 'f', 1)));
}

void BitcoinGUI::openOptionsDialogWithTab(OptionsDialog::Tab tab)
{
if (!clientModel || !clientModel->getOptionsModel())
return;

OptionsDialog dlg(this, enableWallet);
dlg.setCurrentTab(tab);
dlg.setModel(clientModel->getOptionsModel());
dlg.exec();
}

void BitcoinGUI::setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress, bool header)
{
if (modalOverlay)
Expand Down Expand Up @@ -1231,11 +1242,6 @@ void BitcoinGUI::unsubscribeFromCoreSignals()
m_handler_question->disconnect();
}

void BitcoinGUI::toggleNetworkActive()
{
m_node.setNetworkActive(!m_node.getNetworkActive());
}

UnitDisplayStatusBarControl::UnitDisplayStatusBarControl(const PlatformStyle *platformStyle) :
optionsModel(0),
menu(0)
Expand Down
16 changes: 11 additions & 5 deletions src/qt/bitcoingui.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include <config/bitcoin-config.h>
#endif

#include <qt/optionsdialog.h>

#include <amount.h>

#include <QLabel>
Expand Down Expand Up @@ -45,6 +47,10 @@ class QProgressBar;
class QProgressDialog;
QT_END_NAMESPACE

namespace GUIUtil {
class ClickableLabel;
}

/**
Bitcoin GUI main class. This class represents the main window of the Bitcoin UI. It communicates with both the client and
wallet models to give the user an up-to-date view of the current core state.
Expand Down Expand Up @@ -93,8 +99,8 @@ class BitcoinGUI : public QMainWindow
UnitDisplayStatusBarControl* unitDisplayControl = nullptr;
QLabel* labelWalletEncryptionIcon = nullptr;
QLabel* labelWalletHDStatusIcon = nullptr;
QLabel* labelProxyIcon = nullptr;
QLabel* connectionsControl = nullptr;
GUIUtil::ClickableLabel* labelProxyIcon = nullptr;
GUIUtil::ClickableLabel* connectionsControl = nullptr;
QLabel* labelBlocksIcon = nullptr;
QLabel* progressBarLabel = nullptr;
QProgressBar* progressBar = nullptr;
Expand Down Expand Up @@ -166,6 +172,9 @@ class BitcoinGUI : public QMainWindow

void updateHeadersSyncProgressLabel();

/** Open the OptionsDialog on the specified tab index */
void openOptionsDialogWithTab(OptionsDialog::Tab tab);

Q_SIGNALS:
/** Signal raised when a URI was entered or dragged to the GUI */
void receivedURI(const QString &uri);
Expand Down Expand Up @@ -266,9 +275,6 @@ 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();
};

Expand Down
10 changes: 10 additions & 0 deletions src/qt/optionsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,16 @@ void OptionsDialog::setModel(OptionsModel *_model)
connect(ui->thirdPartyTxUrls, SIGNAL(textChanged(const QString &)), this, SLOT(showRestartWarning()));
}

void OptionsDialog::setCurrentTab(OptionsDialog::Tab tab)
{
QWidget *tab_widget = nullptr;
if (tab == OptionsDialog::Tab::TAB_NETWORK) tab_widget = ui->tabNetwork;
if (tab == OptionsDialog::Tab::TAB_MAIN) tab_widget = ui->tabMain;
if (tab_widget && ui->tabWidget->currentWidget() != tab_widget) {
ui->tabWidget->setCurrentWidget(tab_widget);
}
}

void OptionsDialog::setMapper()
{
/* Main */
Expand Down
6 changes: 6 additions & 0 deletions src/qt/optionsdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,14 @@ class OptionsDialog : public QDialog
explicit OptionsDialog(QWidget *parent, bool enableWallet);
~OptionsDialog();

enum Tab {
TAB_MAIN,
TAB_NETWORK,
};

void setModel(OptionsModel *model);
void setMapper();
void setCurrentTab(OptionsDialog::Tab tab);

private Q_SLOTS:
/* set OK button state (enabled / disabled) */
Expand Down

0 comments on commit 6d5fcad

Please sign in to comment.