From 7e5b45a99c4d26869d829e2f16aa5f9fe2d2e735 Mon Sep 17 00:00:00 2001
From: Gus Grubba <gus@auterion.com>
Date: Sat, 27 Apr 2019 11:53:23 -0400
Subject: [PATCH] Fix indicator dropdowns x position on screen

---
 src/ui/MainRootWindow.qml                 | 10 +++++-----
 src/ui/toolbar/BatteryIndicator.qml       |  4 ++--
 src/ui/toolbar/GPSIndicator.qml           |  5 ++---
 src/ui/toolbar/GPSRTKIndicator.qml        |  5 ++---
 src/ui/toolbar/JoystickIndicator.qml      |  4 ++--
 src/ui/toolbar/RCRSSIIndicator.qml        |  4 ++--
 src/ui/toolbar/TelemetryRSSIIndicator.qml |  4 ++--
 7 files changed, 17 insertions(+), 19 deletions(-)

diff --git a/src/ui/MainRootWindow.qml b/src/ui/MainRootWindow.qml
index b6086f6..c1ef799 100644
--- a/src/ui/MainRootWindow.qml
+++ b/src/ui/MainRootWindow.qml
@@ -555,9 +555,9 @@ ApplicationWindow {
     //-------------------------------------------------------------------------
     //-- Indicator Popups
 
-    function showPopUp(dropItem, centerX) {
-        indicatorDropdown.centerX = centerX
+    function showPopUp(item, dropItem) {
         indicatorDropdown.currentIndicator = dropItem
+        indicatorDropdown.currentItem = item
         indicatorDropdown.open()
     }
 
@@ -567,8 +567,8 @@ ApplicationWindow {
         modal:          true
         focus:          true
         closePolicy:    Popup.CloseOnEscape | Popup.CloseOnPressOutside
-        property var    currentIndicator: null
-        property real   centerX: 0
+        property var    currentItem:        null
+        property var    currentIndicator:   null
         background: Rectangle {
             width:  loader.width
             height: loader.height
@@ -577,7 +577,7 @@ ApplicationWindow {
         Loader {
             id:             loader
             onLoaded: {
-                indicatorDropdown.x = mapFromGlobal(indicatorDropdown.centerX, 0).x
+                indicatorDropdown.x = mainWindow.contentItem.mapFromItem(indicatorDropdown.currentItem, 0, 0).x - (loader.width * 0.5)
             }
         }
         onOpened: {
diff --git a/src/ui/toolbar/BatteryIndicator.qml b/src/ui/toolbar/BatteryIndicator.qml
index 3bb83b4..7ed8b2c 100644
--- a/src/ui/toolbar/BatteryIndicator.qml
+++ b/src/ui/toolbar/BatteryIndicator.qml
@@ -19,6 +19,7 @@ import QGroundControl.Palette               1.0
 //-------------------------------------------------------------------------
 //-- Battery Indicator
 Item {
+    id:             _root
     anchors.top:    parent.top
     anchors.bottom: parent.bottom
     width:          batteryIndicatorRow.width
@@ -117,8 +118,7 @@ Item {
     MouseArea {
         anchors.fill:   parent
         onClicked: {
-            var centerX = mapToGlobal(x + (width / 2), 0).x
-            mainWindow.showPopUp(batteryInfo, centerX)
+            mainWindow.showPopUp(_root, batteryInfo)
         }
     }
 }
diff --git a/src/ui/toolbar/GPSIndicator.qml b/src/ui/toolbar/GPSIndicator.qml
index ac59b4a..020ea8c 100644
--- a/src/ui/toolbar/GPSIndicator.qml
+++ b/src/ui/toolbar/GPSIndicator.qml
@@ -19,7 +19,7 @@ import QGroundControl.Palette               1.0
 //-------------------------------------------------------------------------
 //-- GPS Indicator
 Item {
-    id:             satelitte
+    id:             _root
     width:          (gpsValuesColumn.x + gpsValuesColumn.width) * 1.1
     anchors.top:    parent.top
     anchors.bottom: parent.bottom
@@ -107,8 +107,7 @@ Item {
     MouseArea {
         anchors.fill:   parent
         onClicked: {
-            var centerX = mapToGlobal(x + (width / 2), 0).x
-            mainWindow.showPopUp(gpsInfo, centerX)
+            mainWindow.showPopUp(_root, gpsInfo)
         }
     }
 }
diff --git a/src/ui/toolbar/GPSRTKIndicator.qml b/src/ui/toolbar/GPSRTKIndicator.qml
index 8e11159..d67ae5d 100644
--- a/src/ui/toolbar/GPSRTKIndicator.qml
+++ b/src/ui/toolbar/GPSRTKIndicator.qml
@@ -18,7 +18,7 @@ import QGroundControl.Palette               1.0
 //-------------------------------------------------------------------------
 //-- GPS Indicator
 Item {
-    id:             satelitte
+    id:             _root
     width:          visible ? (gpsValuesColumn.x + gpsValuesColumn.width) * 1.1 : 0
     anchors.top:    parent.top
     anchors.bottom: parent.bottom
@@ -108,8 +108,7 @@ Item {
     MouseArea {
         anchors.fill:   parent
         onClicked: {
-            var centerX = mapToGlobal(x + (width / 2), 0).x
-            mainWindow.showPopUp(gpsInfo, centerX)
+            mainWindow.showPopUp(_root, gpsInfo)
         }
     }
 }
diff --git a/src/ui/toolbar/JoystickIndicator.qml b/src/ui/toolbar/JoystickIndicator.qml
index d7c4876..b094e54 100644
--- a/src/ui/toolbar/JoystickIndicator.qml
+++ b/src/ui/toolbar/JoystickIndicator.qml
@@ -18,6 +18,7 @@ import QGroundControl.Palette               1.0
 
 // Joystick Indicator
 Item {
+    id:             _root
     width:          joystickRow.width * 1.1
     anchors.top:    parent.top
     anchors.bottom: parent.bottom
@@ -90,8 +91,7 @@ Item {
     MouseArea {
         anchors.fill:   parent
         onClicked: {
-            var centerX = mapToGlobal(x + (width / 2), 0).x
-            mainWindow.showPopUp(joystickInfo, centerX)
+            mainWindow.showPopUp(_root, joystickInfo)
         }
     }
 }
diff --git a/src/ui/toolbar/RCRSSIIndicator.qml b/src/ui/toolbar/RCRSSIIndicator.qml
index 0f32a64..11ce9b3 100644
--- a/src/ui/toolbar/RCRSSIIndicator.qml
+++ b/src/ui/toolbar/RCRSSIIndicator.qml
@@ -19,6 +19,7 @@ import QGroundControl.Palette               1.0
 //-------------------------------------------------------------------------
 //-- RC RSSI Indicator
 Item {
+    id:             _root
     width:          rssiRow.width * 1.1
     anchors.top:    parent.top
     anchors.bottom: parent.bottom
@@ -92,8 +93,7 @@ Item {
     MouseArea {
         anchors.fill:   parent
         onClicked: {
-            var centerX = mapToGlobal(x + (width / 2), 0).x
-            mainWindow.showPopUp(rcRSSIInfo, centerX)
+            mainWindow.showPopUp(_root, rcRSSIInfo)
         }
     }
 }
diff --git a/src/ui/toolbar/TelemetryRSSIIndicator.qml b/src/ui/toolbar/TelemetryRSSIIndicator.qml
index 42cfc92..c2aaf8c 100644
--- a/src/ui/toolbar/TelemetryRSSIIndicator.qml
+++ b/src/ui/toolbar/TelemetryRSSIIndicator.qml
@@ -19,6 +19,7 @@ import QGroundControl.Palette               1.0
 //-------------------------------------------------------------------------
 //-- Telemetry RSSI
 Item {
+    id:             _root
     anchors.top:    parent.top
     anchors.bottom: parent.bottom
     width:          _hasTelemetry ? telemIcon.width * 1.1 : 0
@@ -83,8 +84,7 @@ Item {
     MouseArea {
         anchors.fill: parent
         onClicked: {
-            var centerX = mapToGlobal(x + (width / 2), 0).x
-            mainWindow.showPopUp(telemRSSIInfo, centerX)
+            mainWindow.showPopUp(_root, telemRSSIInfo)
         }
     }
 }