From 7b8d13413b1fe5fe9050aa92c2a62c3fd6fb5193 Mon Sep 17 00:00:00 2001 From: jarolrod Date: Tue, 7 Feb 2023 16:20:37 -0500 Subject: [PATCH 1/4] qml: set and expose the current network name from the ChainModel --- src/qml/bitcoin.cpp | 1 + src/qml/chainmodel.cpp | 7 +++++++ src/qml/chainmodel.h | 6 ++++++ 3 files changed, 14 insertions(+) diff --git a/src/qml/bitcoin.cpp b/src/qml/bitcoin.cpp index 4dbd0501b1..cf98d54cfb 100644 --- a/src/qml/bitcoin.cpp +++ b/src/qml/bitcoin.cpp @@ -175,6 +175,7 @@ int QmlGuiMain(int argc, char* argv[]) // QObject::connect(&init_executor, &InitExecutor::runawayException, &node_model, &NodeModel::handleRunawayException); ChainModel chain_model{*chain}; + chain_model.setCurrentNetworkName(QString::fromStdString(gArgs.GetChainName())); QObject::connect(&node_model, &NodeModel::setTimeRatioList, &chain_model, &ChainModel::setTimeRatioList); QObject::connect(&node_model, &NodeModel::setTimeRatioListInitial, &chain_model, &ChainModel::setTimeRatioListInitial); diff --git a/src/qml/chainmodel.cpp b/src/qml/chainmodel.cpp index 80a237b794..5062ebb69b 100644 --- a/src/qml/chainmodel.cpp +++ b/src/qml/chainmodel.cpp @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -21,6 +22,12 @@ ChainModel::ChainModel(interfaces::Chain& chain) timer_thread->start(); } +void ChainModel::setCurrentNetworkName(QString network_name) +{ + m_current_network_name = network_name.toUpper(); + Q_EMIT currentNetworkNameChanged(); +} + void ChainModel::setTimeRatioList(int new_time) { if (m_time_ratio_list.isEmpty()) { diff --git a/src/qml/chainmodel.h b/src/qml/chainmodel.h index e8919acea1..c25d8d11a1 100644 --- a/src/qml/chainmodel.h +++ b/src/qml/chainmodel.h @@ -8,6 +8,7 @@ #include #include +#include #include #include @@ -21,11 +22,14 @@ static const int SECS_IN_12_HOURS = 43200; class ChainModel : public QObject { Q_OBJECT + Q_PROPERTY(QString currentNetworkName READ currentNetworkName WRITE setCurrentNetworkName NOTIFY currentNetworkNameChanged) Q_PROPERTY(QVariantList timeRatioList READ timeRatioList NOTIFY timeRatioListChanged) public: explicit ChainModel(interfaces::Chain& chain); + QString currentNetworkName() const { return m_current_network_name; }; + void setCurrentNetworkName(QString network_name); QVariantList timeRatioList() const { return m_time_ratio_list; }; int timestampAtMeridian(); @@ -38,8 +42,10 @@ public Q_SLOTS: Q_SIGNALS: void timeRatioListChanged(); + void currentNetworkNameChanged(); private: + QString m_current_network_name; /* time_ratio: Ratio between the time at which an event * happened and 12 hours. So, for example, if a block is * found at 4 am or pm, the time_ratio would be 0.3. From b48f4f2e740b92a699a54175544cd9cb5c7e8b1b Mon Sep 17 00:00:00 2001 From: jarolrod Date: Tue, 7 Feb 2023 16:34:07 -0500 Subject: [PATCH 2/4] qml: introduce amber color to our Theme file Represents the yellow-orange color used for the NetworkIndicator when the app is running on the Signet network. --- src/qml/controls/Theme.qml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/qml/controls/Theme.qml b/src/qml/controls/Theme.qml index 4227dac1ec..f271a975a4 100644 --- a/src/qml/controls/Theme.qml +++ b/src/qml/controls/Theme.qml @@ -16,6 +16,7 @@ Control { required property color red required property color green required property color blue + required property color amber required property color purple required property color neutral0 required property color neutral1 @@ -45,6 +46,7 @@ Control { red: "#EC6363" green: "#36B46B" blue: "#3CA3DE" + amber: "#C9B500" purple: "#C075DC" neutral0: "#000000" neutral1: "#1A1A1A" @@ -68,6 +70,7 @@ Control { red: "#EB5757" green: "#27AE60" blue: "#2D9CDB" + amber: "#C9B500" purple: "#BB6BD9" neutral0: "#FFFFFF" neutral1: "#F8F8F8" From 0e01340b8a4e60265b93290f6edbec0c667f9d16 Mon Sep 17 00:00:00 2001 From: jarolrod Date: Tue, 7 Feb 2023 16:36:24 -0500 Subject: [PATCH 3/4] qml: introduce NetworkIndicator component Signals to the user what network they are running under when not on the main network. --- src/Makefile.qt.include | 1 + src/qml/bitcoin_qml.qrc | 1 + src/qml/components/NetworkIndicator.qml | 69 +++++++++++++++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 src/qml/components/NetworkIndicator.qml diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index 80c9499bc1..33f089047b 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -335,6 +335,7 @@ QML_RES_QML = \ qml/components/ConnectionSettings.qml \ qml/components/DeveloperOptions.qml \ qml/components/PeersIndicator.qml \ + qml/components/NetworkIndicator.qml \ qml/components/StorageLocations.qml \ qml/components/StorageOptions.qml \ qml/components/StorageSettings.qml \ diff --git a/src/qml/bitcoin_qml.qrc b/src/qml/bitcoin_qml.qrc index d86d13767b..7ba8644c76 100644 --- a/src/qml/bitcoin_qml.qrc +++ b/src/qml/bitcoin_qml.qrc @@ -8,6 +8,7 @@ components/ConnectionSettings.qml components/PeersIndicator.qml components/DeveloperOptions.qml + components/NetworkIndicator.qml components/StorageLocations.qml components/StorageOptions.qml components/StorageSettings.qml diff --git a/src/qml/components/NetworkIndicator.qml b/src/qml/components/NetworkIndicator.qml new file mode 100644 index 0000000000..4576bb027e --- /dev/null +++ b/src/qml/components/NetworkIndicator.qml @@ -0,0 +1,69 @@ +// Copyright (c) 2023 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +import QtQuick 2.15 +import QtQuick.Controls 2.15 +import "../controls" +import "../components" + +import org.bitcoincore.qt 1.0 + +Button { + id: root + property color bgColor + property int textSize: 18 + font.family: "Inter" + font.styleName: "Regular" + font.pixelSize: root.textSize + padding: 7 + state: chainModel.currentNetworkName + contentItem: Text { + text: root.text + font: root.font + color: Theme.color.white + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + } + background: Rectangle { + id: bg + color: root.bgColor + radius: 2 + } + states: [ + State { + name: "MAIN" + PropertyChanges { + target: root + visible: false + } + }, + State { + name: "TEST" + PropertyChanges { + target: root + visible: true + text: qsTr("Test Network") + bgColor: Theme.color.green + } + }, + State { + name: "SIGNET" + PropertyChanges { + target: root + visible: true + text: qsTr("Signet Network") + bgColor: Theme.color.amber + } + }, + State { + name: "REGTEST" + PropertyChanges { + target: root + visible: true + text: qsTr("Regtest Mode") + bgColor: Theme.color.blue + } + } + ] +} From 01b3909f611b3a1db4d1d827350ab2b72c97e2f6 Mon Sep 17 00:00:00 2001 From: jarolrod Date: Tue, 7 Feb 2023 17:19:35 -0500 Subject: [PATCH 4/4] qml: use NetworkIndicator, change layout of NodeRunner to accommodate --- src/qml/components/BlockClock.qml | 1 - src/qml/pages/node/NodeRunner.qml | 9 ++++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/qml/components/BlockClock.qml b/src/qml/components/BlockClock.qml index 1c787254bb..3adc91fd11 100644 --- a/src/qml/components/BlockClock.qml +++ b/src/qml/components/BlockClock.qml @@ -13,7 +13,6 @@ import "../controls" Item { id: root - Layout.alignment: Qt.AlignCenter implicitWidth: 200 implicitHeight: 200 diff --git a/src/qml/pages/node/NodeRunner.qml b/src/qml/pages/node/NodeRunner.qml index c4ed4e3a10..eda06f3ce6 100644 --- a/src/qml/pages/node/NodeRunner.qml +++ b/src/qml/pages/node/NodeRunner.qml @@ -18,7 +18,14 @@ Page { Component.onCompleted: nodeModel.startNodeInitializionThread(); - BlockClock { + ColumnLayout { + spacing: 30 anchors.centerIn: parent + BlockClock { + Layout.alignment: Qt.AlignCenter + } + NetworkIndicator { + Layout.alignment: Qt.AlignCenter + } } }