diff --git a/KelvinDashboardGUI/DapChainNodeNetworkExplorer.cpp b/KelvinDashboardGUI/DapChainNodeNetworkExplorer.cpp index 5dc391c8b662a83f20d6582c155a8f238b0d1735..272c0d8772e29b517fea8689727a091f725c02df 100644 --- a/KelvinDashboardGUI/DapChainNodeNetworkExplorer.cpp +++ b/KelvinDashboardGUI/DapChainNodeNetworkExplorer.cpp @@ -14,7 +14,7 @@ DapChainNodeNetworkExplorer::DapChainNodeNetworkExplorer(QQuickItem *parent) : QQuickPaintedItem(parent), m_model(nullptr), m_colorNormal(DEFAULT_NODE_COLOR), - m_colorActivated(DEFAULT_NODE_COLOR_HOVER), + m_colorFocused(DEFAULT_NODE_COLOR_HOVER), m_widthLine(DEFAULT_WIDTH_LINE), m_sizeNode(DEFAULT_NODE_SIZE) { @@ -25,6 +25,7 @@ DapChainNodeNetworkExplorer::DapChainNodeNetworkExplorer(QQuickItem *parent) : void DapChainNodeNetworkExplorer::mousePressEvent(QMouseEvent* event) { QQuickPaintedItem::mousePressEvent(event); + for(auto Node = m_nodeMap.begin(); Node != m_nodeMap.end(); Node++) { if (Node.value().State == DapNodeState::Selected) @@ -37,10 +38,12 @@ void DapChainNodeNetworkExplorer::mousePressEvent(QMouseEvent* event) { DapNodeData* nodeData = &Node.value(); nodeData->State = DapNodeState::Selected; - emit selectNode(event->x(), event->y(), Node.key(), nodeData->Alias, nodeData->AddressIpv4.toString()); - return; + m_currentSelectedNode = Node.key(); + emit selectNode(Node.key()); } } + + update(); } void DapChainNodeNetworkExplorer::wheelEvent(QWheelEvent* event) @@ -120,7 +123,7 @@ void DapChainNodeNetworkExplorer::paint(QPainter* painter) if(activatedNode != nullptr) { - QPen penActivated(QBrush(m_colorActivated), m_widthLine); + QPen penActivated(QBrush(m_colorFocused), m_widthLine); QPen penWhite(QBrush("#FFFFFF"), m_widthLine); QRect rect(activatedNode->Rect.center(), QSize(200, 15)); @@ -140,9 +143,9 @@ QColor DapChainNodeNetworkExplorer::getColorNormal() const return m_colorNormal; } -QColor DapChainNodeNetworkExplorer::getColorActivated() const +QColor DapChainNodeNetworkExplorer::getColorFocused() const { - return m_colorActivated; + return m_colorFocused; } int DapChainNodeNetworkExplorer::getWidthLine() const @@ -160,39 +163,73 @@ DapChainNodeNetworkModel* DapChainNodeNetworkExplorer::getModel() const return m_model; } -const DapNodeData* DapChainNodeNetworkExplorer::findNodeData(const QPoint& aPos) const + +int DapChainNodeNetworkExplorer::getSelectedNodePosX() const { - for(auto node = m_nodeMap.constBegin(); node != m_nodeMap.constEnd(); node++) - { - const DapNodeData* nodeData = &node.value(); - if(nodeData->Rect.contains(aPos)) return nodeData; - } + if(m_nodeMap.contains(m_currentSelectedNode)) + return m_nodeMap[m_currentSelectedNode].Rect.center().x(); + + return -1; +} + +int DapChainNodeNetworkExplorer::getSelectedNodePosY() const +{ + if(m_nodeMap.contains(m_currentSelectedNode)) + return m_nodeMap[m_currentSelectedNode].Rect.center().y(); + + return -1; +} + +QString DapChainNodeNetworkExplorer::getSelectedNodeAddress() const +{ + return m_currentSelectedNode; +} + +QString DapChainNodeNetworkExplorer::getSelectedNodeAlias() const +{ + if(m_nodeMap.contains(m_currentSelectedNode)) + return m_nodeMap[m_currentSelectedNode].Alias; + + return QString(); +} + +QString DapChainNodeNetworkExplorer::getSelectedNodeIpv4() const +{ + if(m_nodeMap.contains(m_currentSelectedNode)) + return m_nodeMap[m_currentSelectedNode].AddressIpv4.toString(); + + return QString(); +} - return nullptr; +QColor DapChainNodeNetworkExplorer::getColorOnline() const +{ + return m_colorOnline; } -//QPoint DapChainNodeNetworkExplorer::selectedNodePos() const -//{ -// if(m_selectedNode != nullptr) -// return m_selectedNode->Rect.center(); +QColor DapChainNodeNetworkExplorer::getColorOffline() const +{ + return m_colorOffline; +} -// return QPoint(-1, -1); -//} +QColor DapChainNodeNetworkExplorer::getColorSelect() const +{ + return m_colorSelect; +} -void DapChainNodeNetworkExplorer::setColorNormal(const QColor& AColorNormal) +void DapChainNodeNetworkExplorer::setColorNormal(const QColor& aColorNormal) { - if (m_colorNormal == AColorNormal) + if (m_colorNormal == aColorNormal) return; - m_colorNormal = AColorNormal; + m_colorNormal = aColorNormal; emit colorNormalChanged(m_colorNormal); } -void DapChainNodeNetworkExplorer::setColorActivated(const QColor& AColorActivated) +void DapChainNodeNetworkExplorer::setColorFocused(const QColor& aColorActivated) { - if (m_colorActivated == AColorActivated) return; - m_colorActivated = AColorActivated; - emit colorActivatedChanged(m_colorActivated); + if (m_colorFocused == aColorActivated) return; + m_colorFocused = aColorActivated; + emit colorFocusedChanged(m_colorFocused); } void DapChainNodeNetworkExplorer::setWidthLine(const int widthLine) @@ -218,6 +255,40 @@ void DapChainNodeNetworkExplorer::setModel(DapChainNodeNetworkModel* aModel) emit modelChanged(m_model); } +void DapChainNodeNetworkExplorer::setCurrentNodeStatus(const DapNodeStatus& aNodeStatus) +{ + qDebug() << "changed node status" << m_currentSelectedNode << (int)aNodeStatus; + if(m_nodeMap.contains(m_currentSelectedNode)) + m_nodeMap[m_currentSelectedNode].Status = aNodeStatus; +} + +void DapChainNodeNetworkExplorer::setColorOnline(const QColor& aColorOnline) +{ + if (m_colorOnline == aColorOnline) + return; + + m_colorOnline = aColorOnline; + emit colorOnlineChanged(m_colorOnline); +} + +void DapChainNodeNetworkExplorer::setColorOffline(const QColor& aColorOffline) +{ + if (m_colorOffline == aColorOffline) + return; + + m_colorOffline = aColorOffline; + emit colorOfflineChanged(m_colorOffline); +} + +void DapChainNodeNetworkExplorer::setColorSelect(const QColor& aColorSelect) +{ + if (m_colorSelect == aColorSelect) + return; + + m_colorSelect = aColorSelect; + emit colorSelectChanged(m_colorSelect); +} + void DapChainNodeNetworkExplorer::proccessCreateGraph() { if(m_model == nullptr) return; diff --git a/KelvinDashboardGUI/DapChainNodeNetworkExplorer.h b/KelvinDashboardGUI/DapChainNodeNetworkExplorer.h index 1ded229f5adca21974cdb62edd4dd78445ad4c15..67dbc48e7d5f9a44cc97b01f742f8e35d4137df7 100644 --- a/KelvinDashboardGUI/DapChainNodeNetworkExplorer.h +++ b/KelvinDashboardGUI/DapChainNodeNetworkExplorer.h @@ -15,7 +15,7 @@ enum class DapNodeState { Selected }; -enum class DapNodeStatus { +enum DapNodeStatus { Offline, Online }; @@ -57,19 +57,26 @@ struct DapNodeData { class DapChainNodeNetworkExplorer : public QQuickPaintedItem { Q_OBJECT + Q_ENUM(DapNodeStatus) + Q_PROPERTY(QColor colorSelect READ getColorSelect WRITE setColorSelect NOTIFY colorSelectChanged) Q_PROPERTY(QColor colorNormal READ getColorNormal WRITE setColorNormal NOTIFY colorNormalChanged) - Q_PROPERTY(QColor colorActivated READ getColorActivated WRITE setColorActivated NOTIFY colorActivatedChanged) + Q_PROPERTY(QColor colorFocused READ getColorFocused WRITE setColorFocused NOTIFY colorFocusedChanged) + Q_PROPERTY(QColor colorOnline READ getColorOnline WRITE setColorOnline NOTIFY colorOnlineChanged) + Q_PROPERTY(QColor colorOffline READ getColorOffline WRITE setColorOffline NOTIFY colorOfflineChanged) Q_PROPERTY(int widthLine READ getWidthLine WRITE setWidthLine NOTIFY widthLineChanged) Q_PROPERTY(int sizeNode READ getSizeNode WRITE setSizeNode NOTIFY sizeNodeChanged) - Q_PROPERTY(DapChainNodeNetworkModel* model READ getModel WRITE setModel NOTIFY modelChanged) private: + QString m_currentSelectedNode; DapChainNodeNetworkModel* m_model; QMap<QString /*Address*/, DapNodeData /*Data*/> m_nodeMap; + QColor m_colorOnline; + QColor m_colorOffline; + QColor m_colorSelect; QColor m_colorNormal; - QColor m_colorActivated; + QColor m_colorFocused; int m_widthLine; int m_sizeNode; @@ -81,19 +88,30 @@ protected: public: explicit DapChainNodeNetworkExplorer(QQuickItem *parent = nullptr); void paint(QPainter* painter); + DapNodeStatus getNodeStatus() const; + QColor getColorOnline() const; + QColor getColorOffline() const; + QColor getColorSelect() const; QColor getColorNormal() const; - QColor getColorActivated() const; + QColor getColorFocused() const; int getWidthLine() const; int getSizeNode() const; DapChainNodeNetworkModel* getModel() const; - const DapNodeData* findNodeData(const QPoint& aPos) const; -// Q_INVOKABLE QPoint selectedNodePos() const; + Q_INVOKABLE void setCurrentNodeStatus(const DapNodeStatus& aNodeStatus); + Q_INVOKABLE int getSelectedNodePosX() const; + Q_INVOKABLE int getSelectedNodePosY() const; + Q_INVOKABLE QString getSelectedNodeAddress() const; + Q_INVOKABLE QString getSelectedNodeAlias() const; + Q_INVOKABLE QString getSelectedNodeIpv4() const; public slots: - void setColorNormal(const QColor& AColorNormal); - void setColorActivated(const QColor& AColorActivated); + void setColorSelect(const QColor& aColorSelect); + void setColorNormal(const QColor& aColorNormal); + void setColorFocused(const QColor& aColorActivated); + void setColorOnline(const QColor& aColorOnline); + void setColorOffline(const QColor& aColorOffline); void setWidthLine(const int widthLine); void setSizeNode(const int sizeNode); @@ -103,14 +121,16 @@ private slots: void proccessCreateGraph(); signals: - void dataChanged(QVariant data); + void colorSelectChanged(QColor colorSelect); void colorNormalChanged(QColor colorNormal); - void colorActivatedChanged(QColor colorActivated); + void colorFocusedChanged(QColor colorActivated); + void colorOnlineChanged(QColor colorOnline); + void colorOfflineChanged(QColor colorOffline); void widthLineChanged(int widthLine); void sizeNodeChanged(int sizeNode); void modelChanged(DapChainNodeNetworkModel* model); - void selectNode(int posX, int posY, QString address, QString alias, QString ipv4); + void selectNode(QString address); void selectNodeChanged(); }; diff --git a/KelvinDashboardGUI/DapUiQmlWidgetNodeNetworkExplorer.qml b/KelvinDashboardGUI/DapUiQmlWidgetNodeNetworkExplorer.qml index 4b13a5fbc4a7adda24debf357953b1779b8db478..f015f1248e6cfe32d5786f54c0c668e62c558fcf 100644 --- a/KelvinDashboardGUI/DapUiQmlWidgetNodeNetworkExplorer.qml +++ b/KelvinDashboardGUI/DapUiQmlWidgetNodeNetworkExplorer.qml @@ -24,13 +24,9 @@ Page { transformOrigin: Item.TopLeft model: dapNodeNetworkModel onSelectNode: { - dapNodeNetworkMenu.x = posX; - dapNodeNetworkMenu.y = posY; + dapNodeNetworkMenu.x = getSelectedNodePosX(); + dapNodeNetworkMenu.y = getSelectedNodePosY(); dapNodeNetworkMenu.visible = true; - - dapDescriptionAddress.text = address; - dapDescriptionAlias.text = alias; - dapDescriptionIpv4.text = ipv4; } onSelectNodeChanged: { dapNodeNetworkDescription.visible = false; @@ -43,6 +39,9 @@ Page { text: qsTr("Show detalies") onTriggered: { dapNodeNetworkDescription.visible = true; + dapDescriptionAddress.text = dapGraphWidget.getSelectedNodeAddress(); + dapDescriptionAlias.text = dapGraphWidget.getSelectedNodeAlias(); + dapDescriptionIpv4.text = dapGraphWidget.getSelectedNodeIpv4(); } } @@ -50,7 +49,7 @@ Page { id: dapMenuItemStatus text: qsTr("Set status") onTriggered: { - + dapWidgetNodeStatus.visible = true; } } } @@ -73,16 +72,11 @@ Page { anchors.horizontalCenter: parent.horizontalCenter topPadding: 20 bottomPadding: 30 -// Layout.fillWidth: true -// Layout.alignment: Qt.AlignTop -// horizontalAlignment: Text.AlignHCenter -// verticalAlignment: Text.AlignVCenter font.pointSize: 24 text: qsTr("Description") } Column { -// Layout.columnSpan: 0 leftPadding: 30 Text { @@ -98,7 +92,6 @@ Page { Column { -// Layout.columnSpan: 0 leftPadding: 30 Text { @@ -113,7 +106,6 @@ Page { } Column { -// Layout.columnSpan: 0 leftPadding: 30 Text { @@ -129,4 +121,57 @@ Page { } } } + + Rectangle + { + id: dapWidgetNodeStatus + anchors.fill: parent + visible: false + color: "#B3B2B1" + opacity: 0.6 + } + + Rectangle { + anchors.centerIn: parent + visible: dapWidgetNodeStatus.visible + width: contentLayout.width + height: contentLayout.height + border.color: "#F3F2F1" + border.width: 1 + + ColumnLayout { + id: contentLayout + + Text { + Layout.fillWidth: true + leftPadding: 30 + rightPadding: 30 + topPadding: 15 + font.pointSize: 16 + text: qsTr("Choose status") + } + + RadioButton { + Layout.alignment: Qt.AlignCenter + text: qsTr("Offline") + } + + RadioButton { + Layout.alignment: Qt.AlignCenter + text: qsTr("Online") + onClicked: { + } + } + + Button { + Layout.fillWidth: true + text: qsTr("Ok") + + onClicked: { + dapWidgetNodeStatus.visible = false; + } + } + } + } + }