From f2f084b67cf676ba14157eeed443d1914ad65e8f Mon Sep 17 00:00:00 2001
From: "aleksandr.ledyaev" <aleksandr.ledyaev@demlabs.net>
Date: Tue, 20 Oct 2020 19:24:40 +0300
Subject: [PATCH] [*] DapNetworkPopup.qml; DapNetworksList.qml [+]
 DapNetworkPopupButton.qml

---
 CellFrameDashboardGUI/qml.qrc                 |  1 +
 .../desktop/NetworksPanel/DapNetworkPopup.qml | 49 ++++++-------------
 .../NetworksPanel/DapNetworkPopupButton.qml   | 46 +++++++++++++++++
 .../desktop/NetworksPanel/DapNetworksList.qml |  8 ++-
 4 files changed, 69 insertions(+), 35 deletions(-)
 create mode 100644 CellFrameDashboardGUI/screen/desktop/NetworksPanel/DapNetworkPopupButton.qml

diff --git a/CellFrameDashboardGUI/qml.qrc b/CellFrameDashboardGUI/qml.qrc
index 3658e5a28..98aaec4bd 100755
--- a/CellFrameDashboardGUI/qml.qrc
+++ b/CellFrameDashboardGUI/qml.qrc
@@ -182,5 +182,6 @@
         <file>screen/desktop/NetworksPanel/DapNetworksList.qml</file>
         <file>screen/desktop/NetworksPanel/DapNetworkPopup.qml</file>
         <file>screen/desktop/NetworksPanel/DapNetworkName.qml</file>
+        <file>screen/desktop/NetworksPanel/DapNetworkPopupButton.qml</file>
     </qresource>
 </RCC>
diff --git a/CellFrameDashboardGUI/screen/desktop/NetworksPanel/DapNetworkPopup.qml b/CellFrameDashboardGUI/screen/desktop/NetworksPanel/DapNetworkPopup.qml
index 420a476a5..a7725eda4 100644
--- a/CellFrameDashboardGUI/screen/desktop/NetworksPanel/DapNetworkPopup.qml
+++ b/CellFrameDashboardGUI/screen/desktop/NetworksPanel/DapNetworkPopup.qml
@@ -17,13 +17,8 @@ Popup {
     property int linksCount
     property string nodeAddress
 
-    property bool mouseWasClicked
-
     function show(networkDelegateItem)
     {
-        if (mouseWasClicked)
-            return;
-
         networkDelegateItemCoords = Qt.binding(function() { return parent.mapFromItem(networkDelegateItem.parent, networkDelegateItem.x, networkDelegateItem.y) });
         networkDelegateItemWidth = Qt.binding(function() { return networkDelegateItem.width });
         networkDelegateItemHeight = Qt.binding(function() { return networkDelegateItem.height });
@@ -35,8 +30,6 @@ Popup {
         linksCount = Qt.binding(function() { return networkDelegateItem.linksCount });
         nodeAddress = Qt.binding(function() { return networkDelegateItem.nodeAddress });
 
-        mouseWasClicked = false;
-
         open();
     }
 
@@ -52,8 +45,6 @@ Popup {
         activeLinksCount = 0;
         linksCount = 0;
         nodeAddress = 0;
-
-        mouseWasClicked = false;
     }
 
     x: networkDelegateItemCoords.x
@@ -83,8 +74,8 @@ Popup {
             case "NET_STATE_OFFLINE":
                 return qsTr("OFFLINE");
             default:
-                if (control.state.length > 0)
-                    console.warn("Unknown network state: " + control.state);
+                if (state.length > 0)
+                    console.warn("Unknown network state: " + state);
                 return "";
             }
         }
@@ -92,19 +83,25 @@ Popup {
         implicitWidth: columnItem.width
         implicitHeight: columnItem.height
 
-        MouseArea {
-            id: contentItemMouseArea
-            width: parent.width
-            height: parent.height
-            hoverEnabled: true
-        }
-
         Column {
             id: columnItem
 
-            topPadding: 20 * pt
             spacing: Math.floor(control.networkDelegateItemHeight / 2)
 
+            Row {
+                DapNetworkPopupButton {
+                    width: contentItem.width / 2
+                    height: 24 * pt
+                    enabled: control.state == "NET_STATE_ONLINE" && control.targetState == "NET_STATE_ONLINE"
+                    text: qsTr("Sync network")
+                }
+                DapNetworkPopupButton {
+                    width: contentItem.width / 2
+                    height: 24 * pt
+                    text: control.state == "NET_STATE_OFFLINE" ? qsTr("On network") : qsTr("Off network")
+                }
+            }
+
             ColumnLayout {
                 width: contentItem.width
 
@@ -204,13 +201,6 @@ Popup {
                 textColor: "#070023"
                 name: control.name
                 state: control.state
-
-                MouseArea {
-                    id: networkNameMouseArea
-                    width: parent.width
-                    height: parent.height
-                    onClicked: control.mouseWasClicked = true
-                }
             }
         }
     }
@@ -235,11 +225,4 @@ Popup {
     }
 
     onClosed: release()
-
-    Timer {
-        running: !contentItemMouseArea.containsMouse && !btnCopyAddressMouseArea.containsMouse && control.visible && !control.mouseWasClicked
-        interval: 100
-        repeat: false
-        onTriggered: control.close();
-    }
 }
diff --git a/CellFrameDashboardGUI/screen/desktop/NetworksPanel/DapNetworkPopupButton.qml b/CellFrameDashboardGUI/screen/desktop/NetworksPanel/DapNetworkPopupButton.qml
new file mode 100644
index 000000000..59c1212e0
--- /dev/null
+++ b/CellFrameDashboardGUI/screen/desktop/NetworksPanel/DapNetworkPopupButton.qml
@@ -0,0 +1,46 @@
+import QtQuick 2.7
+
+Rectangle {
+    id: control
+
+    property alias text: _text.text
+
+    property bool highlight: enabled && (mouseArea.containsMouse || mouseArea.pressed)
+    property int spacing: 6 * pt
+
+    signal clicked
+
+    color: highlight ? "#D51F5D" : "#FFFFFF"
+
+    Rectangle {
+        id: icon
+        anchors.verticalCenter: control.verticalCenter
+        anchors.right: _text.left
+        anchors.rightMargin: control.spacing
+        width: 10
+        height: 10
+        color: control.enabled ? control.highlight ? "#FFFFFF" :  "#453F5A" : "gray"
+    }
+
+    Text {
+        id: _text
+
+        anchors.verticalCenter: control.verticalCenter
+        x: Math.floor(icon.width + control.spacing + (control.width - (width + icon.width + control.spacing)) * 0.5)
+        width: Math.min(implicitWidth, control.width - icon.width - control.spacing)
+        font: quicksandFonts.medium12
+        color: control.enabled ? control.highlight ? "#FFFFFF" :  "#453F5A" : "gray"
+        elide: Text.ElideRight
+    }
+
+    MouseArea {
+        id: mouseArea
+
+        anchors.fill: parent
+        hoverEnabled: true
+
+        onClicked: {
+
+        }
+    }
+}
diff --git a/CellFrameDashboardGUI/screen/desktop/NetworksPanel/DapNetworksList.qml b/CellFrameDashboardGUI/screen/desktop/NetworksPanel/DapNetworksList.qml
index eca98f73f..7b9500d29 100644
--- a/CellFrameDashboardGUI/screen/desktop/NetworksPanel/DapNetworksList.qml
+++ b/CellFrameDashboardGUI/screen/desktop/NetworksPanel/DapNetworksList.qml
@@ -46,6 +46,11 @@ Item {
         {
             model = networks;
 
+            // for set position of elements if there are less than 4
+            // [*][*][*][*] if 4+
+            // [ ][*][*][*] if 3
+            // [ ][*][*][ ] 2
+            // [ ][ ][ ][*] 1
             var visibleItems = networks.length;
             if (visibleItems >= 4) {
                 visibleItems = 4;
@@ -94,9 +99,8 @@ Item {
 
                 width: parent.width
                 height: parent.height
-                hoverEnabled: true
 
-                onEntered: {
+                onClicked: {
                     if (index >= listView.leftIndex && index < listView.leftIndex + listView.visibleItems) {
                         networkPanelPopup.show(delegateItem);
                     }
-- 
GitLab