diff --git a/KelvinDashboardGUI/DapChainNodeNetworkExplorer.cpp b/KelvinDashboardGUI/DapChainNodeNetworkExplorer.cpp index 0bda4628683fd6f893406fd2711661df7a76d9ed..5dc391c8b662a83f20d6582c155a8f238b0d1735 100644 --- a/KelvinDashboardGUI/DapChainNodeNetworkExplorer.cpp +++ b/KelvinDashboardGUI/DapChainNodeNetworkExplorer.cpp @@ -4,7 +4,7 @@ //#define VIRTUAL_COLUMN_NUMBER 5 //----------------------------------- -#define DESCRIPTION_NODE QString("Address: %1\nAlias: %2\nIPv4: %3") +//#define DESCRIPTION_NODE QString("Address: %1\nAlias: %2\nIPv4: %3") #define DEFAULT_NODE_COLOR_HOVER QColor("#FF0000") #define DEFAULT_NODE_COLOR QColor("#000000") #define DEFAULT_NODE_SIZE 50 @@ -18,36 +18,41 @@ DapChainNodeNetworkExplorer::DapChainNodeNetworkExplorer(QQuickItem *parent) : m_widthLine(DEFAULT_WIDTH_LINE), m_sizeNode(DEFAULT_NODE_SIZE) { -// setAcceptedMouseButtons(Qt::LeftButton); + setAcceptedMouseButtons(Qt::RightButton); setAcceptHoverEvents(true); } -//void DapChainNodeNetworkExplorer::mousePressEvent(QMouseEvent* event) -//{ -// QQuickPaintedItem::mousePressEvent(event); -// for(auto Node = m_nodeMap.constBegin(); Node != m_nodeMap.constEnd(); Node++) -// { -// if(Node.value().isFocus) -// { -// const DapNodeData* nodeData = &Node.value(); -// QString textToolTip = DESCRIPTION_NODE -// .arg(Node.key()) -// .arg(nodeData->Alias) -// .arg(nodeData->AddressIpv4.toString()); -// emit selectNode("Node description", textToolTip); -// return; -// } -// } -//} +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) + { + Node.value().State = DapNodeState::Normal; + emit selectNodeChanged(); + } + + if(Node.value().State == DapNodeState::Focused) + { + DapNodeData* nodeData = &Node.value(); + nodeData->State = DapNodeState::Selected; + emit selectNode(event->x(), event->y(), Node.key(), nodeData->Alias, nodeData->AddressIpv4.toString()); + return; + } + } +} void DapChainNodeNetworkExplorer::wheelEvent(QWheelEvent* event) { if(event->modifiers() == Qt::ControlModifier) { - if(event->delta() > 1) { + if(event->delta() > 1) + { if(scale() < 1.8) setScale(scale() + 0.1); } - else { + else + { if(scale() > 0.5) setScale(scale() - 0.1); } } @@ -59,17 +64,18 @@ void DapChainNodeNetworkExplorer::hoverMoveEvent(QHoverEvent* event) for(auto Node = m_nodeMap.begin(); Node != m_nodeMap.end(); Node++) { - DapNodeData* NodeData = &Node.value(); - if(NodeData->Rect.contains(event->pos())) + DapNodeData* nodeData = &Node.value(); + if(nodeData->Rect.contains(event->pos())) { - NodeData->isFocus = true; + if(nodeData->State == DapNodeState::Selected) return; + nodeData->State = DapNodeState::Focused; break; } else { - if(NodeData->isFocus) + if(nodeData->State == DapNodeState::Focused) { - NodeData->isFocus = false; + nodeData->State = DapNodeState::Normal; break; } } @@ -94,12 +100,20 @@ void DapChainNodeNetworkExplorer::paint(QPainter* painter) for(int i = 0; i < nodeData->Link.count(); i++) painter->drawLine(nodeData->Rect.center(), nodeData->Link.at(i)->Rect.center()); - if(nodeData->isFocus) + if(nodeData->State == DapNodeState::Focused) { address = node.key(); activatedNode = nodeData; continue; } + else if (nodeData->State == DapNodeState::Selected) + { + QPen penSelected(QBrush("#0000FF"), m_widthLine); + painter->setPen(penSelected); + painter->drawEllipse(nodeData->Rect); + painter->setPen(pen); + continue; + } painter->drawEllipse(nodeData->Rect); } @@ -118,18 +132,9 @@ void DapChainNodeNetworkExplorer::paint(QPainter* painter) painter->setPen(pen); painter->drawText(rect, activatedNode->Alias); -// painter->drawText(rect, DESCRIPTION_NODE -// .arg(address) -// .arg(activatedNode->Alias) -// .arg(activatedNode->AddressIpv4.toString())); } } -//QVariant DapChainNodeNetworkExplorer::getData() const -//{ -// return m_data; -//} - QColor DapChainNodeNetworkExplorer::getColorNormal() const { return m_colorNormal; @@ -155,43 +160,23 @@ DapChainNodeNetworkModel* DapChainNodeNetworkExplorer::getModel() const return m_model; } -//void DapChainNodeNetworkExplorer::setData(const QVariant& AData) +const DapNodeData* DapChainNodeNetworkExplorer::findNodeData(const QPoint& aPos) const +{ + for(auto node = m_nodeMap.constBegin(); node != m_nodeMap.constEnd(); node++) + { + const DapNodeData* nodeData = &node.value(); + if(nodeData->Rect.contains(aPos)) return nodeData; + } + + return nullptr; +} + +//QPoint DapChainNodeNetworkExplorer::selectedNodePos() const //{ -// if (m_data == AData) return; -// m_data = AData; -// m_nodeMap.clear(); -// emit dataChanged(m_data); - -// QMap<QString, QVariant> dataMap = m_data.toMap(); - -// int pointX = m_sizeNode; -// int heightConten = dataMap.count() * m_sizeNode; - -// QList<QString> addressList = dataMap.keys(); -// foreach(auto address, addressList) -// m_nodeMap[address] = DapNodeData(); - -// for(auto node = m_nodeMap.begin(); node != m_nodeMap.end(); node++) -// { -// DapNodeData* nodeData = &node.value(); -// QStringList nodeDataList = dataMap[node.key()].toStringList(); -// nodeData->Cell = nodeDataList.at(0).toUInt(); -// nodeData->AddressIpv4 = QHostAddress(nodeDataList.at(1)); -// nodeData->Alias = nodeDataList.at(2); - -// if(nodeDataList.at(3).toUInt() > 0) -// { -// for(int i = 4; i < nodeDataList.count(); i++) -// nodeData->Link.append(&m_nodeMap[nodeDataList.at(i)]); -// } - -// int posY = (qrand() % ((heightConten + 1) - m_sizeNode) + m_sizeNode); -// nodeData->Rect = QRect(pointX, posY, m_sizeNode, m_sizeNode); -// pointX += m_sizeNode * 2; -// } - -// setSize(QSize(pointX + m_sizeNode * 2, heightConten + m_sizeNode * 2)); -// update(); +// if(m_selectedNode != nullptr) +// return m_selectedNode->Rect.center(); + +// return QPoint(-1, -1); //} void DapChainNodeNetworkExplorer::setColorNormal(const QColor& AColorNormal) diff --git a/KelvinDashboardGUI/DapChainNodeNetworkExplorer.h b/KelvinDashboardGUI/DapChainNodeNetworkExplorer.h index 481358c586228cea2628ab6adcfd2d5fbcf7eb11..1ded229f5adca21974cdb62edd4dd78445ad4c15 100644 --- a/KelvinDashboardGUI/DapChainNodeNetworkExplorer.h +++ b/KelvinDashboardGUI/DapChainNodeNetworkExplorer.h @@ -9,8 +9,16 @@ #include "DapChainNodeNetworkModel.h" -//#include "DapChainNode.h" -//#include "DapNetworkType.h" +enum class DapNodeState { + Normal, + Focused, + Selected +}; + +enum class DapNodeStatus { + Offline, + Online +}; struct DapNodeData { quint32 Cell; @@ -18,11 +26,13 @@ struct DapNodeData { QString Alias; QVector<DapNodeData*> Link; QRect Rect; - bool isFocus; + DapNodeState State; + DapNodeStatus Status; DapNodeData() { - isFocus = false; + State = DapNodeState::Normal; + Status = DapNodeStatus::Offline; Link = QVector<DapNodeData*>(); } @@ -38,7 +48,8 @@ struct DapNodeData { AddressIpv4 = AData.AddressIpv4; Rect = AData.Rect; Link = AData.Link; - isFocus = AData.isFocus; + State = AData.State; + Status = AData.Status; return *this; } }; @@ -46,7 +57,6 @@ struct DapNodeData { class DapChainNodeNetworkExplorer : public QQuickPaintedItem { Q_OBJECT -// Q_PROPERTY(QVariant data READ getData WRITE setData NOTIFY dataChanged) Q_PROPERTY(QColor colorNormal READ getColorNormal WRITE setColorNormal NOTIFY colorNormalChanged) Q_PROPERTY(QColor colorActivated READ getColorActivated WRITE setColorActivated NOTIFY colorActivatedChanged) Q_PROPERTY(int widthLine READ getWidthLine WRITE setWidthLine NOTIFY widthLineChanged) @@ -55,7 +65,6 @@ class DapChainNodeNetworkExplorer : public QQuickPaintedItem Q_PROPERTY(DapChainNodeNetworkModel* model READ getModel WRITE setModel NOTIFY modelChanged) private: -// QVariant m_data; DapChainNodeNetworkModel* m_model; QMap<QString /*Address*/, DapNodeData /*Data*/> m_nodeMap; @@ -64,9 +73,8 @@ private: int m_widthLine; int m_sizeNode; - protected: -// void mousePressEvent(QMouseEvent* event); + void mousePressEvent(QMouseEvent* event); void wheelEvent(QWheelEvent* event); void hoverMoveEvent(QHoverEvent* event); @@ -80,6 +88,9 @@ public: DapChainNodeNetworkModel* getModel() const; + const DapNodeData* findNodeData(const QPoint& aPos) const; +// Q_INVOKABLE QPoint selectedNodePos() const; + public slots: void setColorNormal(const QColor& AColorNormal); void setColorActivated(const QColor& AColorActivated); @@ -99,7 +110,8 @@ signals: void sizeNodeChanged(int sizeNode); void modelChanged(DapChainNodeNetworkModel* model); - void selectNode(QString address, QString alias, QString ipv4); + void selectNode(int posX, int posY, QString address, QString alias, QString ipv4); + void selectNodeChanged(); }; #endif // DAPCHAINNODENETWORKEXPLORER_H diff --git a/KelvinDashboardGUI/DapUiQmlWidgetNodeNetworkExplorer.qml b/KelvinDashboardGUI/DapUiQmlWidgetNodeNetworkExplorer.qml index f9f2d07c78a0d4c6ba77d3e3d35c00ef6f4d44fd..4b13a5fbc4a7adda24debf357953b1779b8db478 100644 --- a/KelvinDashboardGUI/DapUiQmlWidgetNodeNetworkExplorer.qml +++ b/KelvinDashboardGUI/DapUiQmlWidgetNodeNetworkExplorer.qml @@ -1,31 +1,46 @@ -import QtQuick 2.9 +import QtQuick 2.13 import QtQuick.Controls 2.2 import QtQuick.Dialogs 1.2 +import QtQuick.Layouts 1.12 import NodeNetworkExplorer 1.0 Page { - Row { + RowLayout { anchors.fill: parent + spacing: 2 Flickable { id: dapExplorer - anchors.fill: parent + Layout.fillWidth: true + Layout.fillHeight: true contentWidth: dapGraphWidget.width * dapGraphWidget.scale contentHeight: dapGraphWidget.height * dapGraphWidget.scale - contentY: dapGraphWidget.height / 2 - height / 2 - contentX: dapGraphWidget.width / 2 - width / 2 + contentY: dapGraphWidget.height / 2 + contentX: dapGraphWidget.width / 2 DapUiQmlWidgetNodeNetwork { id: dapGraphWidget scale: 0.6 transformOrigin: Item.TopLeft model: dapNodeNetworkModel + onSelectNode: { + dapNodeNetworkMenu.x = posX; + dapNodeNetworkMenu.y = posY; + dapNodeNetworkMenu.visible = true; + + dapDescriptionAddress.text = address; + dapDescriptionAlias.text = alias; + dapDescriptionIpv4.text = ipv4; + } + onSelectNodeChanged: { + dapNodeNetworkDescription.visible = false; + } Menu { id: dapNodeNetworkMenu MenuItem { id: dapMenuItemDetails - text: "Show detalies" + text: qsTr("Show detalies") onTriggered: { dapNodeNetworkDescription.visible = true; } @@ -33,34 +48,85 @@ Page { MenuItem { id: dapMenuItemStatus - text: "Set status" + text: qsTr("Set status") onTriggered: { } } } - - MouseArea { - anchors.fill: parent; - acceptedButtons: Qt.RightButton - onReleased: { - dapNodeNetworkMenu.x = mouseX; - dapNodeNetworkMenu.y = mouseY; - dapNodeNetworkMenu.visible = true; - } - } } } Rectangle { id: dapNodeNetworkDescription - width: 300 -// anchors.top: parent.top -// anchors.right: parent.right -// anchors.bottom: parent.bottom + Layout.fillWidth: true + Layout.fillHeight: true visible: false - } + border.color: "#F3F2F1" + border.width: 1 + + Column { + anchors.fill: parent + + Text { + 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 { + text: qsTr("Address") + font.pointSize: 13 + } + + Text { + id: dapDescriptionAddress + font.pointSize: 8 + } + } + + + Column { +// Layout.columnSpan: 0 + leftPadding: 30 + + Text { + text: qsTr("Alias") + font.pointSize: 13 + } + + Text { + id: dapDescriptionAlias + font.pointSize: 8 + } + } + + Column { +// Layout.columnSpan: 0 + leftPadding: 30 + + Text { + text: qsTr("Ipv4") + font.pointSize: 13 + } + + Text { + id:dapDescriptionIpv4 + font.pointSize: 8 + } + } + } + } } }