From f6aec24062d35a2daf918f603cce76dc439b9a92 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Sat, 1 May 2021 16:40:28 +0300 Subject: [PATCH] qt: Add "Alternating Row Color" settings for the Peers Tab Github-Pull: gui#307 Rebased-From: b124c2fe600b343a2bc66ff8eb0aaf43aa99f4db --- src/qt/forms/debugwindow.ui | 6 ------ src/qt/forms/optionsdialog.ui | 14 ++++++++++++-- src/qt/optionsdialog.cpp | 1 + src/qt/optionsmodel.cpp | 13 +++++++++++++ src/qt/optionsmodel.h | 4 ++++ src/qt/rpcconsole.cpp | 9 +++++++++ src/qt/rpcconsole.h | 1 + 7 files changed, 40 insertions(+), 8 deletions(-) diff --git a/src/qt/forms/debugwindow.ui b/src/qt/forms/debugwindow.ui index f1b66341d1..5249c588cc 100644 --- a/src/qt/forms/debugwindow.ui +++ b/src/qt/forms/debugwindow.ui @@ -893,9 +893,6 @@ false - - true - Qt::ElideMiddle @@ -957,9 +954,6 @@ false - - true - true diff --git a/src/qt/forms/optionsdialog.ui b/src/qt/forms/optionsdialog.ui index 6be47e94fe..7b7454e3ae 100644 --- a/src/qt/forms/optionsdialog.ui +++ b/src/qt/forms/optionsdialog.ui @@ -6,8 +6,8 @@ 0 0 - 560 - 440 + 646 + 529 @@ -871,6 +871,16 @@ + + + + Alternate the row colors for the "Peers" and "Banned peers" tables in the Peers tab. + + + Alternate row colors in the Peers tab + + + diff --git a/src/qt/optionsdialog.cpp b/src/qt/optionsdialog.cpp index 6dec4b2e42..c8c113e68e 100644 --- a/src/qt/optionsdialog.cpp +++ b/src/qt/optionsdialog.cpp @@ -272,6 +272,7 @@ void OptionsDialog::setMapper() #endif /* Display */ + mapper->addMapping(ui->peersTabAlternatingRowColors, OptionsModel::PeersTabAlternatingRowColors); mapper->addMapping(ui->lang, OptionsModel::Language); mapper->addMapping(ui->unit, OptionsModel::DisplayUnit); mapper->addMapping(ui->thirdPartyTxUrls, OptionsModel::ThirdPartyTxUrls); diff --git a/src/qt/optionsmodel.cpp b/src/qt/optionsmodel.cpp index bee8fafddc..e57ff4c5df 100644 --- a/src/qt/optionsmodel.cpp +++ b/src/qt/optionsmodel.cpp @@ -221,6 +221,12 @@ bool OptionsModel::Init(bilingual_str& error) m_use_embedded_monospaced_font = settings.value("UseEmbeddedMonospacedFont").toBool(); Q_EMIT useEmbeddedMonospacedFontChanged(m_use_embedded_monospaced_font); + if (!settings.contains("PeersTabAlternatingRowColors")) { + settings.setValue("PeersTabAlternatingRowColors", "false"); + } + m_peers_tab_alternating_row_colors = settings.value("PeersTabAlternatingRowColors").toBool(); + Q_EMIT peersTabAlternatingRowColorsChanged(m_peers_tab_alternating_row_colors); + m_mask_values = settings.value("mask_values", false).toBool(); return true; @@ -429,6 +435,8 @@ QVariant OptionsModel::getOption(OptionID option, const std::string& suffix) con return QString::fromStdString(SettingToString(setting(), "")); case UseEmbeddedMonospacedFont: return m_use_embedded_monospaced_font; + case PeersTabAlternatingRowColors: + return m_peers_tab_alternating_row_colors; case CoinControlFeatures: return fCoinControlFeatures; case EnablePSBTControls: @@ -591,6 +599,11 @@ bool OptionsModel::setOption(OptionID option, const QVariant& value, const std:: settings.setValue("UseEmbeddedMonospacedFont", m_use_embedded_monospaced_font); Q_EMIT useEmbeddedMonospacedFontChanged(m_use_embedded_monospaced_font); break; + case PeersTabAlternatingRowColors: + m_peers_tab_alternating_row_colors = value.toBool(); + settings.setValue("PeersTabAlternatingRowColors", m_peers_tab_alternating_row_colors); + Q_EMIT peersTabAlternatingRowColorsChanged(m_peers_tab_alternating_row_colors); + break; case CoinControlFeatures: fCoinControlFeatures = value.toBool(); settings.setValue("fCoinControlFeatures", fCoinControlFeatures); diff --git a/src/qt/optionsmodel.h b/src/qt/optionsmodel.h index f28a1087ba..d9d46677e1 100644 --- a/src/qt/optionsmodel.h +++ b/src/qt/optionsmodel.h @@ -61,6 +61,7 @@ public: ThirdPartyTxUrls, // QString Language, // QString UseEmbeddedMonospacedFont, // bool + PeersTabAlternatingRowColors, // bool CoinControlFeatures, // bool SubFeeFromAmount, // bool ThreadsScriptVerif, // int @@ -94,6 +95,7 @@ public: BitcoinUnit getDisplayUnit() const { return m_display_bitcoin_unit; } QString getThirdPartyTxUrls() const { return strThirdPartyTxUrls; } bool getUseEmbeddedMonospacedFont() const { return m_use_embedded_monospaced_font; } + bool getPeersTabAlternatingRowColors() const { return m_peers_tab_alternating_row_colors; } bool getCoinControlFeatures() const { return fCoinControlFeatures; } bool getSubFeeFromAmount() const { return m_sub_fee_from_amount; } bool getEnablePSBTControls() const { return m_enable_psbt_controls; } @@ -121,6 +123,7 @@ private: BitcoinUnit m_display_bitcoin_unit; QString strThirdPartyTxUrls; bool m_use_embedded_monospaced_font; + bool m_peers_tab_alternating_row_colors; bool fCoinControlFeatures; bool m_sub_fee_from_amount; bool m_enable_psbt_controls; @@ -140,6 +143,7 @@ Q_SIGNALS: void coinControlFeaturesChanged(bool); void showTrayIconChanged(bool); void useEmbeddedMonospacedFontChanged(bool); + void peersTabAlternatingRowColorsChanged(bool); }; #endif // BITCOIN_QT_OPTIONSMODEL_H diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp index 76500a4a36..c25f550b15 100644 --- a/src/qt/rpcconsole.cpp +++ b/src/qt/rpcconsole.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -488,6 +489,7 @@ RPCConsole::RPCConsole(interfaces::Node& node, const PlatformStyle *_platformSty m_peer_widget_header_state = settings.value("PeersTabPeerHeaderState").toByteArray(); m_banlist_widget_header_state = settings.value("PeersTabBanlistHeaderState").toByteArray(); + m_alternating_row_colors = settings.value("PeersTabAlternatingRowColors").toBool(); constexpr QChar nonbreaking_hyphen(8209); const std::vector CONNECTION_TYPE_DOC{ @@ -672,6 +674,11 @@ void RPCConsole::setClientModel(ClientModel *model, int bestblock_height, int64_ connect(model, &ClientModel::mempoolSizeChanged, this, &RPCConsole::setMempoolSize); + connect(model->getOptionsModel(), &OptionsModel::peersTabAlternatingRowColorsChanged, [this](bool alternating_row_colors) { + ui->peerWidget->setAlternatingRowColors(alternating_row_colors); + ui->banlistWidget->setAlternatingRowColors(alternating_row_colors); + }); + // set up peer table ui->peerWidget->setModel(model->peerTableSortProxy()); ui->peerWidget->verticalHeader()->hide(); @@ -687,6 +694,7 @@ void RPCConsole::setClientModel(ClientModel *model, int bestblock_height, int64_ ui->peerWidget->horizontalHeader()->setSectionResizeMode(PeerTableModel::Age, QHeaderView::ResizeToContents); ui->peerWidget->horizontalHeader()->setStretchLastSection(true); ui->peerWidget->setItemDelegateForColumn(PeerTableModel::NetNodeId, new PeerIdViewDelegate(this)); + ui->peerWidget->setAlternatingRowColors(m_alternating_row_colors); // create peer table context menu peersTableContextMenu = new QMenu(this); @@ -719,6 +727,7 @@ void RPCConsole::setClientModel(ClientModel *model, int bestblock_height, int64_ } ui->banlistWidget->horizontalHeader()->setSectionResizeMode(BanTableModel::Address, QHeaderView::ResizeToContents); ui->banlistWidget->horizontalHeader()->setStretchLastSection(true); + ui->banlistWidget->setAlternatingRowColors(m_alternating_row_colors); // create ban table context menu banTableContextMenu = new QMenu(this); diff --git a/src/qt/rpcconsole.h b/src/qt/rpcconsole.h index 32a7520491..79bce3e44b 100644 --- a/src/qt/rpcconsole.h +++ b/src/qt/rpcconsole.h @@ -175,6 +175,7 @@ private: bool m_is_executing{false}; QByteArray m_peer_widget_header_state; QByteArray m_banlist_widget_header_state; + bool m_alternating_row_colors{false}; /** Update UI with latest network info from model. */ void updateNetworkState();