From dc2148c93a701a4aa7b2aa7e364b94653a838a49 Mon Sep 17 00:00:00 2001 From: Paschalis Date: Sun, 15 Sep 2024 18:00:33 +0300 Subject: [PATCH 01/18] Enhance battery indicator visuals - Added new SVG images for different battery levels: Critical, Low, Orange, Yellow, YellowGreen, and Green. - Updated QGCPalette.cc and QGCPalette.h to include new color definitions for the battery levels. - Modified BatteryIndicator.qml to use the new SVG images and color codes. - Updated qgcimages.qrc to include the new SVG images in the resources. --- qgcimages.qrc | 6 ++ src/QmlControls/QGCPalette.cc | 1 + src/QmlControls/QGCPalette.h | 1 + src/UI/toolbar/BatteryIndicator.qml | 76 +++++++++++--- src/UI/toolbar/Images/BatteryCritical.svg | 87 ++++++++++++++++ src/UI/toolbar/Images/BatteryGreen.svg | 102 +++++++++++++++++++ src/UI/toolbar/Images/BatteryLow.svg | 70 +++++++++++++ src/UI/toolbar/Images/BatteryOrange.svg | 78 ++++++++++++++ src/UI/toolbar/Images/BatteryYellow.svg | 86 ++++++++++++++++ src/UI/toolbar/Images/BatteryYellowGreen.svg | 94 +++++++++++++++++ 10 files changed, 588 insertions(+), 13 deletions(-) create mode 100644 src/UI/toolbar/Images/BatteryCritical.svg create mode 100644 src/UI/toolbar/Images/BatteryGreen.svg create mode 100644 src/UI/toolbar/Images/BatteryLow.svg create mode 100644 src/UI/toolbar/Images/BatteryOrange.svg create mode 100644 src/UI/toolbar/Images/BatteryYellow.svg create mode 100644 src/UI/toolbar/Images/BatteryYellowGreen.svg diff --git a/qgcimages.qrc b/qgcimages.qrc index 20f5b1ed135..41592fbca10 100644 --- a/qgcimages.qrc +++ b/qgcimages.qrc @@ -61,6 +61,12 @@ src/FlightMap/Images/attitudePointer.svg src/FlightMap/Images/AwarenessAircraft.svg src/UI/toolbar/Images/Battery.svg + src/UI/toolbar/Images/BatteryGreen.svg + src/UI/toolbar/Images/BatteryYellowGreen.svg + src/UI/toolbar/Images/BatteryYellow.svg + src/UI/toolbar/Images/BatteryOrange.svg + src/UI/toolbar/Images/BatteryLow.svg + src/UI/toolbar/Images/BatteryCritical.svg resources/camera.svg src/Camera/images/camera_photo.svg src/Camera/images/camera_video.svg diff --git a/src/QmlControls/QGCPalette.cc b/src/QmlControls/QGCPalette.cc index ab13c7c27e9..0ea3f7cc136 100644 --- a/src/QmlControls/QGCPalette.cc +++ b/src/QmlControls/QGCPalette.cc @@ -69,6 +69,7 @@ void QGCPalette::_buildMap() DECLARE_QGC_COLOR(mapIndicator, "#585858", "#be781c", "#585858", "#be781c") DECLARE_QGC_COLOR(mapIndicatorChild, "#585858", "#766043", "#585858", "#766043") DECLARE_QGC_COLOR(colorGreen, "#009431", "#009431", "#00e04b", "#00e04b") + DECLARE_QGC_COLOR(colorYellow, "#ffff00", "#ffff00", "#ffc107", "#ffc107") DECLARE_QGC_COLOR(colorOrange, "#b95604", "#b95604", "#de8500", "#de8500") DECLARE_QGC_COLOR(colorRed, "#ed3939", "#ed3939", "#f32836", "#f32836") DECLARE_QGC_COLOR(colorGrey, "#808080", "#808080", "#bfbfbf", "#bfbfbf") diff --git a/src/QmlControls/QGCPalette.h b/src/QmlControls/QGCPalette.h index 477646fd9ec..85a41f74fe4 100644 --- a/src/QmlControls/QGCPalette.h +++ b/src/QmlControls/QGCPalette.h @@ -138,6 +138,7 @@ class QGCPalette : public QObject DEFINE_QGC_COLOR(brandingPurple, setBrandingPurple) DEFINE_QGC_COLOR(brandingBlue, setBrandingBlue) DEFINE_QGC_COLOR(colorGreen, setColorGreen) + DEFINE_QGC_COLOR(colorYellow, setColorYellow) DEFINE_QGC_COLOR(colorOrange, setColorOrange) DEFINE_QGC_COLOR(colorRed, setColorRed) DEFINE_QGC_COLOR(colorGrey, setColorGrey) diff --git a/src/UI/toolbar/BatteryIndicator.qml b/src/UI/toolbar/BatteryIndicator.qml index 8c28875562a..c1819bc9a74 100644 --- a/src/UI/toolbar/BatteryIndicator.qml +++ b/src/UI/toolbar/BatteryIndicator.qml @@ -79,19 +79,69 @@ Item { anchors.top: parent.top anchors.bottom: parent.bottom + // function getBatteryColor() { + // switch (battery.chargeState.rawValue) { + // case MAVLink.MAV_BATTERY_CHARGE_STATE_OK: + // case MAVLink.MAV_BATTERY_CHARGE_STATE_LOW: + // case MAVLink.MAV_BATTERY_CHARGE_STATE_CRITICAL: + // if (!isNaN(battery.percentRemaining.rawValue)) { + // // Check percentage and return appropriate color + // if (battery.percentRemaining.rawValue > 80) { + // return qgcPal.colorGreen // Green for battery > 80% + // } else if (battery.percentRemaining.rawValue > 60) { + // return "#9ACD32" // Yellow-Green for 61% - 80% + // } else if (battery.percentRemaining.rawValue > 40) { + // return qgcPal.colorYellow // Yellow for 41% - 60% + // } else if (battery.percentRemaining.rawValue > 20) { + // return qgcPal.colorOrange // Orange for 21% - 40% + // }else { + // return qgcPal.colorRed + // } + // } + // break; + // case MAVLink.MAV_BATTERY_CHARGE_STATE_EMERGENCY: + // case MAVLink.MAV_BATTERY_CHARGE_STATE_FAILED: + // case MAVLink.MAV_BATTERY_CHARGE_STATE_UNHEALTHY: + // return qgcPal.colorRed // Red for emergency states + // default: + // return qgcPal.text // Default color for undefined states + // } + // } function getBatteryColor() { - switch (battery.chargeState.rawValue) { - case MAVLink.MAV_BATTERY_CHARGE_STATE_OK: - return qgcPal.text - case MAVLink.MAV_BATTERY_CHARGE_STATE_LOW: - return qgcPal.colorOrange - case MAVLink.MAV_BATTERY_CHARGE_STATE_CRITICAL: - case MAVLink.MAV_BATTERY_CHARGE_STATE_EMERGENCY: - case MAVLink.MAV_BATTERY_CHARGE_STATE_FAILED: - case MAVLink.MAV_BATTERY_CHARGE_STATE_UNHEALTHY: - return qgcPal.colorRed - default: - return qgcPal.text + if (!isNaN(battery.percentRemaining.rawValue)) { + if (battery.percentRemaining.rawValue > 80) { + return qgcPal.colorGreen // Green for battery > 80% + } else if (battery.percentRemaining.rawValue > 60) { + return "#9ACD32" // Yellow-Green for 61% - 80% + } else if (battery.percentRemaining.rawValue > 40) { + return qgcPal.colorYellow // Yellow for 41% - 60% + } else if (battery.percentRemaining.rawValue > 20) { + return qgcPal.colorOrange // Orange for 21% - 40% + } else { + return qgcPal.colorRed // Red for 0% - 20% + } + } else { + return qgcPal.text // Default color for undefined states + } + } + + function getBatterySvgSource() { + if (!isNaN(battery.percentRemaining.rawValue)) { + if (battery.percentRemaining.rawValue > 80) { + return "/qmlimages/BatteryGreen.svg" // Green for battery > 80% + } else if (battery.percentRemaining.rawValue > 60) { + return "/qmlimages/BatteryYellowGreen.svg" // Yellow-Green for 61% - 80% + } else if (battery.percentRemaining.rawValue > 40) { + return "/qmlimages/BatteryYellow.svg" // Yellow for 41% - 60% + } else if (battery.percentRemaining.rawValue > 20) { + return "/qmlimages/BatteryOrange.svg" // Orange for 21% - 40% + } else if (battery.percentRemaining.rawValue > 10) { + return "/qmlimages/BatteryLow.svg" // Red for 11% - 20% + } else { + return "/qmlimages/BatteryCritical.svg" // Exclamation mark for 0% - 10% + } + } else { + return "/qmlimages/Battery.svg" // Fallback if percentage is unavailable } } @@ -124,7 +174,7 @@ Item { anchors.bottom: parent.bottom width: height sourceSize.width: width - source: "/qmlimages/Battery.svg" + source: getBatterySvgSource() fillMode: Image.PreserveAspectFit color: getBatteryColor() } diff --git a/src/UI/toolbar/Images/BatteryCritical.svg b/src/UI/toolbar/Images/BatteryCritical.svg new file mode 100644 index 00000000000..bd2bf9c31d9 --- /dev/null +++ b/src/UI/toolbar/Images/BatteryCritical.svg @@ -0,0 +1,87 @@ + + + + + + + + + diff --git a/src/UI/toolbar/Images/BatteryGreen.svg b/src/UI/toolbar/Images/BatteryGreen.svg new file mode 100644 index 00000000000..c6095d2c461 --- /dev/null +++ b/src/UI/toolbar/Images/BatteryGreen.svg @@ -0,0 +1,102 @@ + + + + + + + + + diff --git a/src/UI/toolbar/Images/BatteryLow.svg b/src/UI/toolbar/Images/BatteryLow.svg new file mode 100644 index 00000000000..28e83e3128a --- /dev/null +++ b/src/UI/toolbar/Images/BatteryLow.svg @@ -0,0 +1,70 @@ + + + + + + + + + diff --git a/src/UI/toolbar/Images/BatteryOrange.svg b/src/UI/toolbar/Images/BatteryOrange.svg new file mode 100644 index 00000000000..1bd9fe32fc0 --- /dev/null +++ b/src/UI/toolbar/Images/BatteryOrange.svg @@ -0,0 +1,78 @@ + + + + + + + + + diff --git a/src/UI/toolbar/Images/BatteryYellow.svg b/src/UI/toolbar/Images/BatteryYellow.svg new file mode 100644 index 00000000000..49a3c6e4daf --- /dev/null +++ b/src/UI/toolbar/Images/BatteryYellow.svg @@ -0,0 +1,86 @@ + + + + + + + + + diff --git a/src/UI/toolbar/Images/BatteryYellowGreen.svg b/src/UI/toolbar/Images/BatteryYellowGreen.svg new file mode 100644 index 00000000000..83ca709523d --- /dev/null +++ b/src/UI/toolbar/Images/BatteryYellowGreen.svg @@ -0,0 +1,94 @@ + + + + + + + + + From feb382cee7b1b6a664b06951a87dea0b77649f9c Mon Sep 17 00:00:00 2001 From: Paschalis Date: Tue, 17 Sep 2024 21:29:31 +0300 Subject: [PATCH 02/18] Added colorYellow and colorYellowGreen to QGCPalette and updated BatteryIndicator to use predefined palette colors --- src/QmlControls/QGCPalette.cc | 3 ++- src/QmlControls/QGCPalette.h | 1 + src/UI/toolbar/BatteryIndicator.qml | 30 +---------------------------- 3 files changed, 4 insertions(+), 30 deletions(-) diff --git a/src/QmlControls/QGCPalette.cc b/src/QmlControls/QGCPalette.cc index 0ea3f7cc136..87a7fc95d37 100644 --- a/src/QmlControls/QGCPalette.cc +++ b/src/QmlControls/QGCPalette.cc @@ -69,7 +69,8 @@ void QGCPalette::_buildMap() DECLARE_QGC_COLOR(mapIndicator, "#585858", "#be781c", "#585858", "#be781c") DECLARE_QGC_COLOR(mapIndicatorChild, "#585858", "#766043", "#585858", "#766043") DECLARE_QGC_COLOR(colorGreen, "#009431", "#009431", "#00e04b", "#00e04b") - DECLARE_QGC_COLOR(colorYellow, "#ffff00", "#ffff00", "#ffc107", "#ffc107") + DECLARE_QGC_COLOR(colorYellow, "#ffff00", "#ffff00", "#ffff00", "#ffff00") + DECLARE_QGC_COLOR(colorYellowGreen, "#9acd32", "#9acd32", "#9acd32", "#9acd32") DECLARE_QGC_COLOR(colorOrange, "#b95604", "#b95604", "#de8500", "#de8500") DECLARE_QGC_COLOR(colorRed, "#ed3939", "#ed3939", "#f32836", "#f32836") DECLARE_QGC_COLOR(colorGrey, "#808080", "#808080", "#bfbfbf", "#bfbfbf") diff --git a/src/QmlControls/QGCPalette.h b/src/QmlControls/QGCPalette.h index 85a41f74fe4..5ba2c53f744 100644 --- a/src/QmlControls/QGCPalette.h +++ b/src/QmlControls/QGCPalette.h @@ -139,6 +139,7 @@ class QGCPalette : public QObject DEFINE_QGC_COLOR(brandingBlue, setBrandingBlue) DEFINE_QGC_COLOR(colorGreen, setColorGreen) DEFINE_QGC_COLOR(colorYellow, setColorYellow) + DEFINE_QGC_COLOR(colorYellowGreen, setColorYellowGreen) DEFINE_QGC_COLOR(colorOrange, setColorOrange) DEFINE_QGC_COLOR(colorRed, setColorRed) DEFINE_QGC_COLOR(colorGrey, setColorGrey) diff --git a/src/UI/toolbar/BatteryIndicator.qml b/src/UI/toolbar/BatteryIndicator.qml index c1819bc9a74..bfa1303b6fa 100644 --- a/src/UI/toolbar/BatteryIndicator.qml +++ b/src/UI/toolbar/BatteryIndicator.qml @@ -79,40 +79,12 @@ Item { anchors.top: parent.top anchors.bottom: parent.bottom - // function getBatteryColor() { - // switch (battery.chargeState.rawValue) { - // case MAVLink.MAV_BATTERY_CHARGE_STATE_OK: - // case MAVLink.MAV_BATTERY_CHARGE_STATE_LOW: - // case MAVLink.MAV_BATTERY_CHARGE_STATE_CRITICAL: - // if (!isNaN(battery.percentRemaining.rawValue)) { - // // Check percentage and return appropriate color - // if (battery.percentRemaining.rawValue > 80) { - // return qgcPal.colorGreen // Green for battery > 80% - // } else if (battery.percentRemaining.rawValue > 60) { - // return "#9ACD32" // Yellow-Green for 61% - 80% - // } else if (battery.percentRemaining.rawValue > 40) { - // return qgcPal.colorYellow // Yellow for 41% - 60% - // } else if (battery.percentRemaining.rawValue > 20) { - // return qgcPal.colorOrange // Orange for 21% - 40% - // }else { - // return qgcPal.colorRed - // } - // } - // break; - // case MAVLink.MAV_BATTERY_CHARGE_STATE_EMERGENCY: - // case MAVLink.MAV_BATTERY_CHARGE_STATE_FAILED: - // case MAVLink.MAV_BATTERY_CHARGE_STATE_UNHEALTHY: - // return qgcPal.colorRed // Red for emergency states - // default: - // return qgcPal.text // Default color for undefined states - // } - // } function getBatteryColor() { if (!isNaN(battery.percentRemaining.rawValue)) { if (battery.percentRemaining.rawValue > 80) { return qgcPal.colorGreen // Green for battery > 80% } else if (battery.percentRemaining.rawValue > 60) { - return "#9ACD32" // Yellow-Green for 61% - 80% + return qgcPal.colorYellowGreen // Yellow-Green for 61% - 80% } else if (battery.percentRemaining.rawValue > 40) { return qgcPal.colorYellow // Yellow for 41% - 60% } else if (battery.percentRemaining.rawValue > 20) { From ae4249a97c75988447049ac78ced75a28a1add36 Mon Sep 17 00:00:00 2001 From: Paschalis Date: Tue, 17 Sep 2024 23:41:56 +0300 Subject: [PATCH 03/18] Update color definitions for improved visibility for light theme --- src/QmlControls/QGCPalette.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/QmlControls/QGCPalette.cc b/src/QmlControls/QGCPalette.cc index 87a7fc95d37..cc4faa51884 100644 --- a/src/QmlControls/QGCPalette.cc +++ b/src/QmlControls/QGCPalette.cc @@ -68,11 +68,11 @@ void QGCPalette::_buildMap() DECLARE_QGC_COLOR(mapButtonHighlight, "#585858", "#be781c", "#585858", "#be781c") DECLARE_QGC_COLOR(mapIndicator, "#585858", "#be781c", "#585858", "#be781c") DECLARE_QGC_COLOR(mapIndicatorChild, "#585858", "#766043", "#585858", "#766043") - DECLARE_QGC_COLOR(colorGreen, "#009431", "#009431", "#00e04b", "#00e04b") - DECLARE_QGC_COLOR(colorYellow, "#ffff00", "#ffff00", "#ffff00", "#ffff00") - DECLARE_QGC_COLOR(colorYellowGreen, "#9acd32", "#9acd32", "#9acd32", "#9acd32") - DECLARE_QGC_COLOR(colorOrange, "#b95604", "#b95604", "#de8500", "#de8500") - DECLARE_QGC_COLOR(colorRed, "#ed3939", "#ed3939", "#f32836", "#f32836") + DECLARE_QGC_COLOR(colorGreen, "#005c1f", "#005c1f", "#00e04b", "#00e04b") + DECLARE_QGC_COLOR(colorYellow, "#6c6c00", "#6c6c00", "#ffff00", "#ffff00") + DECLARE_QGC_COLOR(colorYellowGreen, "#4a6b2d", "#4a6b2d", "#9acd32", "#9acd32") + DECLARE_QGC_COLOR(colorOrange, "#b04818", "#b04818", "#de8500", "#de8500") + DECLARE_QGC_COLOR(colorRed, "#c81010", "#c81010", "#f32836", "#f32836") DECLARE_QGC_COLOR(colorGrey, "#808080", "#808080", "#bfbfbf", "#bfbfbf") DECLARE_QGC_COLOR(colorBlue, "#1a72ff", "#1a72ff", "#536dff", "#536dff") DECLARE_QGC_COLOR(alertBackground, "#eecc44", "#eecc44", "#eecc44", "#eecc44") From c6ab475232ce5d6f0f86e784e7c14ca9fe2a382e Mon Sep 17 00:00:00 2001 From: Paschalis Date: Wed, 18 Sep 2024 15:24:25 +0300 Subject: [PATCH 04/18] Apply battery colors only in dark theme --- src/UI/toolbar/BatteryIndicator.qml | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/UI/toolbar/BatteryIndicator.qml b/src/UI/toolbar/BatteryIndicator.qml index bfa1303b6fa..259405de4f3 100644 --- a/src/UI/toolbar/BatteryIndicator.qml +++ b/src/UI/toolbar/BatteryIndicator.qml @@ -80,20 +80,26 @@ Item { anchors.bottom: parent.bottom function getBatteryColor() { - if (!isNaN(battery.percentRemaining.rawValue)) { - if (battery.percentRemaining.rawValue > 80) { - return qgcPal.colorGreen // Green for battery > 80% - } else if (battery.percentRemaining.rawValue > 60) { - return qgcPal.colorYellowGreen // Yellow-Green for 61% - 80% - } else if (battery.percentRemaining.rawValue > 40) { - return qgcPal.colorYellow // Yellow for 41% - 60% - } else if (battery.percentRemaining.rawValue > 20) { - return qgcPal.colorOrange // Orange for 21% - 40% + if (qgcPal.globalTheme === QGCPalette.Dark) { + // Apply the battery color logic only for the dark theme + if (!isNaN(battery.percentRemaining.rawValue)) { + if (battery.percentRemaining.rawValue > 80) { + return qgcPal.colorGreen // Green for battery > 80% + } else if (battery.percentRemaining.rawValue > 60) { + return qgcPal.colorYellowGreen // Yellow-Green for 61% - 80% + } else if (battery.percentRemaining.rawValue > 40) { + return qgcPal.colorYellow // Yellow for 41% - 60% + } else if (battery.percentRemaining.rawValue > 20) { + return qgcPal.colorOrange // Orange for 21% - 40% + } else { + return qgcPal.colorRed // Red for 0% - 20% + } } else { - return qgcPal.colorRed // Red for 0% - 20% + return qgcPal.text // Default color for undefined states } } else { - return qgcPal.text // Default color for undefined states + // For light theme, return a default color + return qgcPal.text // Use a neutral color for light theme } } From c7be67c941a1a3f16d2f5cb34dc03e42748f96b8 Mon Sep 17 00:00:00 2001 From: Paschalis Date: Fri, 20 Sep 2024 22:18:26 +0300 Subject: [PATCH 05/18] Update qgcimages.qrc to include new battery icons. --- qgcimages.qrc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/qgcimages.qrc b/qgcimages.qrc index 41592fbca10..9a3f38fd7c4 100644 --- a/qgcimages.qrc +++ b/qgcimages.qrc @@ -67,6 +67,8 @@ src/UI/toolbar/Images/BatteryOrange.svg src/UI/toolbar/Images/BatteryLow.svg src/UI/toolbar/Images/BatteryCritical.svg + src/UI/toolbar/Images/BatteryConf.svg + src/UI/toolbar/Images/BatteryConfLight.svg resources/camera.svg src/Camera/images/camera_photo.svg src/Camera/images/camera_video.svg From e047024699926961ba95626f0dfd3ca99cbb0506 Mon Sep 17 00:00:00 2001 From: Paschalis Date: Fri, 20 Sep 2024 22:18:43 +0300 Subject: [PATCH 06/18] Add battery configuration settings for dark and light themes. --- .../BatteryIndicator.SettingsGroup.json | 39 ++++++++++++------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/src/Settings/BatteryIndicator.SettingsGroup.json b/src/Settings/BatteryIndicator.SettingsGroup.json index 973ffa81438..63da266e1ba 100644 --- a/src/Settings/BatteryIndicator.SettingsGroup.json +++ b/src/Settings/BatteryIndicator.SettingsGroup.json @@ -1,15 +1,28 @@ { - "version": 1, - "fileType": "FactMetaData", - "QGC.MetaData.Facts": -[ -{ - "name": "display", - "shortDesc": "Select values to display in indicator", - "enumStrings": "Percentage,Voltage,Percentage and Voltage", - "enumValues": "0,1,2", - "type": "uint32", - "default": false -} -] + "version": 1, + "fileType": "FactMetaData", + "QGC.MetaData.Facts": [ + { + "name": "display", + "shortDesc": "Select values to display in indicator", + "enumStrings": "Percentage,Voltage,Percentage and Voltage", + "enumValues": "0,1,2", + "type": "uint32", + "default": false + }, + { + "name": "threshold1", + "shortDesc": "Battery level threshold 1", + "type": "uint32", + "default": 80, + "units": "%" + }, + { + "name": "threshold2", + "shortDesc": "Battery level threshold 2", + "type": "uint32", + "default": 60, + "units": "%" + } + ] } From 7bda84d6086b8261847ea0958ddbaf33df117d9c Mon Sep 17 00:00:00 2001 From: Paschalis Date: Fri, 20 Sep 2024 22:19:01 +0300 Subject: [PATCH 07/18] Implement logic for configurable battery thresholds. --- src/Settings/BatteryIndicatorSettings.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Settings/BatteryIndicatorSettings.cc b/src/Settings/BatteryIndicatorSettings.cc index d33483e3a65..f478b1a5494 100644 --- a/src/Settings/BatteryIndicatorSettings.cc +++ b/src/Settings/BatteryIndicatorSettings.cc @@ -17,3 +17,5 @@ DECLARE_SETTINGGROUP(BatteryIndicator, "BatteryIndicator") } DECLARE_SETTINGSFACT(BatteryIndicatorSettings, display) +DECLARE_SETTINGSFACT(BatteryIndicatorSettings, threshold1) +DECLARE_SETTINGSFACT(BatteryIndicatorSettings, threshold2) From cf43592d0d9fd67cb0514b238c88818602063606 Mon Sep 17 00:00:00 2001 From: Paschalis Date: Fri, 20 Sep 2024 22:19:38 +0300 Subject: [PATCH 08/18] Add header definitions for battery indicator settings. --- src/Settings/BatteryIndicatorSettings.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Settings/BatteryIndicatorSettings.h b/src/Settings/BatteryIndicatorSettings.h index 59c7f8eef5c..7a55f201b81 100644 --- a/src/Settings/BatteryIndicatorSettings.h +++ b/src/Settings/BatteryIndicatorSettings.h @@ -19,4 +19,6 @@ class BatteryIndicatorSettings : public SettingsGroup DEFINE_SETTING_NAME_GROUP() DEFINE_SETTINGFACT(display) + DEFINE_SETTINGFACT(threshold1) + DEFINE_SETTINGFACT(threshold2) }; From 0b8cfbcf04458dcb6e7c8bc7f82b79574b3c723d Mon Sep 17 00:00:00 2001 From: Paschalis Date: Fri, 20 Sep 2024 22:19:54 +0300 Subject: [PATCH 09/18] Improve battery indicator with dark theme support and configurable colors. --- src/UI/toolbar/BatteryIndicator.qml | 234 +++++++++++++++++++++++----- 1 file changed, 199 insertions(+), 35 deletions(-) diff --git a/src/UI/toolbar/BatteryIndicator.qml b/src/UI/toolbar/BatteryIndicator.qml index 259405de4f3..72ab83d4466 100644 --- a/src/UI/toolbar/BatteryIndicator.qml +++ b/src/UI/toolbar/BatteryIndicator.qml @@ -37,6 +37,13 @@ Item { property bool _showVoltage: _indicatorDisplay.rawValue === 1 property bool _showBoth: _indicatorDisplay.rawValue === 2 + // Fetch battery settings + property var batterySettings: QGroundControl.settingsManager.batteryIndicatorSettings + + // Properties to hold the thresholds + property int threshold1: batterySettings.threshold1.rawValue + property int threshold2: batterySettings.threshold2.rawValue + Row { id: batteryIndicatorRow anchors.top: parent.top @@ -80,46 +87,60 @@ Item { anchors.bottom: parent.bottom function getBatteryColor() { - if (qgcPal.globalTheme === QGCPalette.Dark) { - // Apply the battery color logic only for the dark theme - if (!isNaN(battery.percentRemaining.rawValue)) { - if (battery.percentRemaining.rawValue > 80) { - return qgcPal.colorGreen // Green for battery > 80% - } else if (battery.percentRemaining.rawValue > 60) { - return qgcPal.colorYellowGreen // Yellow-Green for 61% - 80% - } else if (battery.percentRemaining.rawValue > 40) { - return qgcPal.colorYellow // Yellow for 41% - 60% - } else if (battery.percentRemaining.rawValue > 20) { - return qgcPal.colorOrange // Orange for 21% - 40% + switch (battery.chargeState.rawValue) { + case MAVLink.MAV_BATTERY_CHARGE_STATE_OK: + if (qgcPal.globalTheme === QGCPalette.Dark) { + // Apply the battery color logic only for the dark theme + if (!isNaN(battery.percentRemaining.rawValue)) { + if (battery.percentRemaining.rawValue > threshold1) { + return qgcPal.colorGreen + } else if (battery.percentRemaining.rawValue > threshold2) { + return qgcPal.colorYellowGreen + } else { + return qgcPal.colorYellow + } + } else { + return qgcPal.text + } } else { - return qgcPal.colorRed // Red for 0% - 20% + // For light theme, return a default color + return qgcPal.text } - } else { - return qgcPal.text // Default color for undefined states - } - } else { - // For light theme, return a default color - return qgcPal.text // Use a neutral color for light theme + case MAVLink.MAV_BATTERY_CHARGE_STATE_LOW: + return qgcPal.colorOrange + case MAVLink.MAV_BATTERY_CHARGE_STATE_CRITICAL: + case MAVLink.MAV_BATTERY_CHARGE_STATE_EMERGENCY: + case MAVLink.MAV_BATTERY_CHARGE_STATE_FAILED: + case MAVLink.MAV_BATTERY_CHARGE_STATE_UNHEALTHY: + return qgcPal.colorRed + default: + return qgcPal.text } - } + } function getBatterySvgSource() { - if (!isNaN(battery.percentRemaining.rawValue)) { - if (battery.percentRemaining.rawValue > 80) { - return "/qmlimages/BatteryGreen.svg" // Green for battery > 80% - } else if (battery.percentRemaining.rawValue > 60) { - return "/qmlimages/BatteryYellowGreen.svg" // Yellow-Green for 61% - 80% - } else if (battery.percentRemaining.rawValue > 40) { - return "/qmlimages/BatteryYellow.svg" // Yellow for 41% - 60% - } else if (battery.percentRemaining.rawValue > 20) { - return "/qmlimages/BatteryOrange.svg" // Orange for 21% - 40% - } else if (battery.percentRemaining.rawValue > 10) { - return "/qmlimages/BatteryLow.svg" // Red for 11% - 20% - } else { - return "/qmlimages/BatteryCritical.svg" // Exclamation mark for 0% - 10% - } - } else { - return "/qmlimages/Battery.svg" // Fallback if percentage is unavailable + + switch (battery.chargeState.rawValue) { + case MAVLink.MAV_BATTERY_CHARGE_STATE_OK: + if (!isNaN(battery.percentRemaining.rawValue)) { + if (battery.percentRemaining.rawValue > threshold1) { + return "/qmlimages/BatteryGreen.svg" + } else if (battery.percentRemaining.rawValue > threshold2) { + return "/qmlimages/BatteryYellowGreen.svg" + } else { + return "/qmlimages/BatteryYellow.svg" + } + } + case MAVLink.MAV_BATTERY_CHARGE_STATE_LOW: + return "/qmlimages/BatteryOrange.svg" // Low with orange svg + case MAVLink.MAV_BATTERY_CHARGE_STATE_CRITICAL: + return "/qmlimages/BatteryLow.svg" // Critical with red svg + case MAVLink.MAV_BATTERY_CHARGE_STATE_EMERGENCY: + case MAVLink.MAV_BATTERY_CHARGE_STATE_FAILED: + case MAVLink.MAV_BATTERY_CHARGE_STATE_UNHEALTHY: + return "/qmlimages/BatteryCritical.svg" // Exclamation mark + default: + return "/qmlimages/Battery.svg" // Fallback if percentage is unavailable } } @@ -268,6 +289,7 @@ Item { } } + Component { id: batteryExpandedComponent @@ -306,6 +328,148 @@ Item { } } } + + } + + SettingsGroupLayout { + Layout.fillWidth: true + + RowLayout { + Layout.fillWidth: true + spacing: ScreenTools.defaultFontPixelWidth * 3 // Adjust this value for more space + + ColumnLayout { + spacing: ScreenTools.defaultFontPixelWidth * 3 // Adjust this value for more space + Layout.fillWidth: true + + LabelledLabel { + labelText: "Light Theme " + Layout.alignment: Qt.AlignHCenter // Center align the text + } + } + + ColumnLayout { + spacing: ScreenTools.defaultFontPixelWidth / 2 + Layout.fillWidth: true + + LabelledLabel { + labelText: "Dark Theme " + Layout.alignment: Qt.AlignHCenter // Center align the text + } + } + } + + RowLayout { + spacing: ScreenTools.defaultFontPixelHeight / 2 + Layout.fillWidth: true + + // First ColumnLayout (Battery Image Display) + ColumnLayout { + Layout.fillWidth: true + //spacing: ScreenTools.defaultFontPixelHeight / 2 + + QGCColoredImage { + source: "/qmlimages/BatteryConfLight.svg" + height: ScreenTools.defaultFontPixelHeight * 5 + width: ScreenTools.defaultFontPixelWidth * 15 + fillMode: Image.PreserveAspectFit + color: Qt.color("transparent") // Optional, if needed + + } + } + + // Second ColumnLayout (Thresholds and Labels) + ColumnLayout { + Layout.fillWidth: true + + LabelledLabel { + label: "100%" + } + + LabelledLabel { + label: " 15%" + } + + LabelledLabel { + label: " 7%" + } + } + + ColumnLayout { + Layout.fillWidth: true + //spacing: ScreenTools.defaultFontPixelHeight / 2 + + QGCColoredImage { + source: "/qmlimages/BatteryConf.svg" + height: ScreenTools.defaultFontPixelHeight * 5 + width: ScreenTools.defaultFontPixelWidth * 15 + fillMode: Image.PreserveAspectFit + color: Qt.color("transparent") // Optional, if needed + } + } + // Second ColumnLayout (Thresholds and Labels) + ColumnLayout { + Layout.fillWidth: true + + LabelledLabel { + label: " 100%" + } + + Row { + //spacing: ScreenTools.defaultFontPixelHeight / 2 + Layout.fillWidth: true + + FactTextField { + id: threshold1Field + fact: batterySettings.threshold1 + validator: IntValidator { bottom: 16 } // Value is at least 16 + width: ScreenTools.defaultFontPixelWidth * 6 + height: ScreenTools.defaultFontPixelHeight * 1.5 + onEditingFinished: { + let newValue = parseInt(text); + if (newValue > batterySettings.threshold2.rawValue) { + batterySettings.threshold1.rawValue = newValue; + } else { + // Adjust value if invalid + batterySettings.threshold1.rawValue = batterySettings.threshold2.rawValue - 1; + text = batterySettings.threshold1.rawValue.toString(); // Update displayed text + } + } + } + } + + Row { + //spacing: ScreenTools.defaultFontPixelHeight / 2 + Layout.fillWidth: true + spacing: ScreenTools.defaultFontPixelWidth * 5 + + FactTextField { + id: threshold2Field + fact: batterySettings.threshold2 + validator: IntValidator { bottom: 16 } + width: ScreenTools.defaultFontPixelWidth * 6 + height: ScreenTools.defaultFontPixelHeight * 1.5 + onEditingFinished: { + let newValue = parseInt(text); + if (newValue < batterySettings.threshold1.rawValue) { + batterySettings.threshold2.rawValue = newValue; + } else { + batterySettings.threshold2.rawValue = batterySettings.threshold1.rawValue - 1; + text = batterySettings.threshold2.rawValue.toString(); + } + } + } + } + + LabelledLabel { + label: " 15%" + } + + LabelledLabel { + label: " 7%" + } + } + } } } } From fb186df217a820d2385ddc2aff3461255c724d29 Mon Sep 17 00:00:00 2001 From: Paschalis Date: Fri, 20 Sep 2024 22:20:15 +0300 Subject: [PATCH 10/18] Fix SVG file namespace issues in TelemRSSI.svg. --- src/UI/toolbar/Images/TelemRSSI.svg | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/UI/toolbar/Images/TelemRSSI.svg b/src/UI/toolbar/Images/TelemRSSI.svg index 077fa362211..c134a3cb72c 100644 --- a/src/UI/toolbar/Images/TelemRSSI.svg +++ b/src/UI/toolbar/Images/TelemRSSI.svg @@ -1,6 +1,6 @@ - + From 5138b77843075d730c4883e40bbeb1b330007b1b Mon Sep 17 00:00:00 2001 From: Paschalis Date: Fri, 20 Sep 2024 22:20:52 +0300 Subject: [PATCH 11/18] Add new battery configuration icons for light and dark themes (BatteryConf.svg, BatteryConfLight.svg). --- src/UI/toolbar/Images/BatteryConf.svg | 105 +++++++++++++++++++++ src/UI/toolbar/Images/BatteryConfLight.svg | 105 +++++++++++++++++++++ 2 files changed, 210 insertions(+) create mode 100644 src/UI/toolbar/Images/BatteryConf.svg create mode 100644 src/UI/toolbar/Images/BatteryConfLight.svg diff --git a/src/UI/toolbar/Images/BatteryConf.svg b/src/UI/toolbar/Images/BatteryConf.svg new file mode 100644 index 00000000000..34e3f27d811 --- /dev/null +++ b/src/UI/toolbar/Images/BatteryConf.svg @@ -0,0 +1,105 @@ + + + + + + + + + diff --git a/src/UI/toolbar/Images/BatteryConfLight.svg b/src/UI/toolbar/Images/BatteryConfLight.svg new file mode 100644 index 00000000000..c8e8519fced --- /dev/null +++ b/src/UI/toolbar/Images/BatteryConfLight.svg @@ -0,0 +1,105 @@ + + + + + + + + + From 81ee7dbc0a9188eb3c10a1b8c3a68f8971521ab0 Mon Sep 17 00:00:00 2001 From: Paschalis Date: Sun, 22 Sep 2024 01:22:03 +0300 Subject: [PATCH 12/18] Modify palette, battery indicator, and update images. --- qgcimages.qrc | 4 +- src/QmlControls/QGCPalette.cc | 10 +- src/UI/toolbar/BatteryIndicator.qml | 235 +++++++++------------- src/UI/toolbar/Images/BatteryCritical.svg | 43 ++-- 4 files changed, 118 insertions(+), 174 deletions(-) diff --git a/qgcimages.qrc b/qgcimages.qrc index 9a3f38fd7c4..89b8ab7e649 100644 --- a/qgcimages.qrc +++ b/qgcimages.qrc @@ -65,10 +65,8 @@ src/UI/toolbar/Images/BatteryYellowGreen.svg src/UI/toolbar/Images/BatteryYellow.svg src/UI/toolbar/Images/BatteryOrange.svg - src/UI/toolbar/Images/BatteryLow.svg src/UI/toolbar/Images/BatteryCritical.svg - src/UI/toolbar/Images/BatteryConf.svg - src/UI/toolbar/Images/BatteryConfLight.svg + src/UI/toolbar/Images/BatteryEMERGENCY.svg resources/camera.svg src/Camera/images/camera_photo.svg src/Camera/images/camera_video.svg diff --git a/src/QmlControls/QGCPalette.cc b/src/QmlControls/QGCPalette.cc index cc4faa51884..c2ba0255a7b 100644 --- a/src/QmlControls/QGCPalette.cc +++ b/src/QmlControls/QGCPalette.cc @@ -68,11 +68,11 @@ void QGCPalette::_buildMap() DECLARE_QGC_COLOR(mapButtonHighlight, "#585858", "#be781c", "#585858", "#be781c") DECLARE_QGC_COLOR(mapIndicator, "#585858", "#be781c", "#585858", "#be781c") DECLARE_QGC_COLOR(mapIndicatorChild, "#585858", "#766043", "#585858", "#766043") - DECLARE_QGC_COLOR(colorGreen, "#005c1f", "#005c1f", "#00e04b", "#00e04b") - DECLARE_QGC_COLOR(colorYellow, "#6c6c00", "#6c6c00", "#ffff00", "#ffff00") - DECLARE_QGC_COLOR(colorYellowGreen, "#4a6b2d", "#4a6b2d", "#9acd32", "#9acd32") - DECLARE_QGC_COLOR(colorOrange, "#b04818", "#b04818", "#de8500", "#de8500") - DECLARE_QGC_COLOR(colorRed, "#c81010", "#c81010", "#f32836", "#f32836") + DECLARE_QGC_COLOR(colorGreen, "#008f2d", "#008f2d", "#00e04b", "#00e04b") + DECLARE_QGC_COLOR(colorYellow, "#a2a200", "#a2a200", "#ffff00", "#ffff00") + DECLARE_QGC_COLOR(colorYellowGreen, "#799f26", "#799f26", "#9dbe2f", "#9dbe2f") + DECLARE_QGC_COLOR(colorOrange, "#bf7539", "#bf7539", "#de8500", "#de8500") + DECLARE_QGC_COLOR(colorRed, "#b52b2b", "#b52b2b", "#f32836", "#f32836") DECLARE_QGC_COLOR(colorGrey, "#808080", "#808080", "#bfbfbf", "#bfbfbf") DECLARE_QGC_COLOR(colorBlue, "#1a72ff", "#1a72ff", "#536dff", "#536dff") DECLARE_QGC_COLOR(alertBackground, "#eecc44", "#eecc44", "#eecc44", "#eecc44") diff --git a/src/UI/toolbar/BatteryIndicator.qml b/src/UI/toolbar/BatteryIndicator.qml index 72ab83d4466..c591cb93cfe 100644 --- a/src/UI/toolbar/BatteryIndicator.qml +++ b/src/UI/toolbar/BatteryIndicator.qml @@ -89,21 +89,15 @@ Item { function getBatteryColor() { switch (battery.chargeState.rawValue) { case MAVLink.MAV_BATTERY_CHARGE_STATE_OK: - if (qgcPal.globalTheme === QGCPalette.Dark) { - // Apply the battery color logic only for the dark theme - if (!isNaN(battery.percentRemaining.rawValue)) { - if (battery.percentRemaining.rawValue > threshold1) { - return qgcPal.colorGreen - } else if (battery.percentRemaining.rawValue > threshold2) { - return qgcPal.colorYellowGreen - } else { - return qgcPal.colorYellow - } + if (!isNaN(battery.percentRemaining.rawValue)) { + if (battery.percentRemaining.rawValue > threshold1) { + return qgcPal.colorGreen + } else if (battery.percentRemaining.rawValue > threshold2) { + return qgcPal.colorYellowGreen } else { - return qgcPal.text + return qgcPal.colorYellow } } else { - // For light theme, return a default color return qgcPal.text } case MAVLink.MAV_BATTERY_CHARGE_STATE_LOW: @@ -134,11 +128,11 @@ Item { case MAVLink.MAV_BATTERY_CHARGE_STATE_LOW: return "/qmlimages/BatteryOrange.svg" // Low with orange svg case MAVLink.MAV_BATTERY_CHARGE_STATE_CRITICAL: - return "/qmlimages/BatteryLow.svg" // Critical with red svg + return "/qmlimages/BatteryCritical.svg" // Critical with red svg case MAVLink.MAV_BATTERY_CHARGE_STATE_EMERGENCY: case MAVLink.MAV_BATTERY_CHARGE_STATE_FAILED: case MAVLink.MAV_BATTERY_CHARGE_STATE_UNHEALTHY: - return "/qmlimages/BatteryCritical.svg" // Exclamation mark + return "/qmlimages/BatteryEMERGENCY.svg" // Exclamation mark default: return "/qmlimages/Battery.svg" // Fallback if percentage is unavailable } @@ -187,7 +181,7 @@ Item { QGCLabel { Layout.alignment: Qt.AlignHCenter verticalAlignment: Text.AlignVCenter - color: getBatteryColor() + color: qgcPal.text text: getBatteryPercentageText() font.pointSize: _showBoth ? ScreenTools.defaultFontPointSize : ScreenTools.mediumFontPointSize visible: _showBoth || _showPercentage @@ -196,7 +190,7 @@ Item { QGCLabel { Layout.alignment: Qt.AlignHCenter font.pointSize: _showBoth ? ScreenTools.defaultFontPointSize : ScreenTools.mediumFontPointSize - color: getBatteryColor() + color: qgcPal.text text: getBatteryVoltageText() visible: _showBoth || _showVoltage } @@ -332,144 +326,113 @@ Item { } SettingsGroupLayout { + heading: qsTr("Battery State Display") Layout.fillWidth: true - + spacing: ScreenTools.defaultFontPixelWidth * 0.5 + RowLayout { - Layout.fillWidth: true - spacing: ScreenTools.defaultFontPixelWidth * 3 // Adjust this value for more space - - ColumnLayout { - spacing: ScreenTools.defaultFontPixelWidth * 3 // Adjust this value for more space - Layout.fillWidth: true - - LabelledLabel { - labelText: "Light Theme " - Layout.alignment: Qt.AlignHCenter // Center align the text - } + //Layout.fillWidth: true + + QGCColoredImage { + source: "/qmlimages/BatteryGreen.svg" + height: ScreenTools.defaultFontPixelHeight * 5 + width: ScreenTools.defaultFontPixelWidth * 7 + fillMode: Image.PreserveAspectFit + color: qgcPal.colorGreen } - ColumnLayout { - spacing: ScreenTools.defaultFontPixelWidth / 2 - Layout.fillWidth: true - - LabelledLabel { - labelText: "Dark Theme " - Layout.alignment: Qt.AlignHCenter // Center align the text - } + QGCLabel { + Layout.preferredWidth: ScreenTools.defaultFontPixelWidth * 3.5 + text: qsTr("100%") + Layout.leftMargin: -13 } - } - - RowLayout { - spacing: ScreenTools.defaultFontPixelHeight / 2 - Layout.fillWidth: true - - // First ColumnLayout (Battery Image Display) - ColumnLayout { - Layout.fillWidth: true - //spacing: ScreenTools.defaultFontPixelHeight / 2 - QGCColoredImage { - source: "/qmlimages/BatteryConfLight.svg" - height: ScreenTools.defaultFontPixelHeight * 5 - width: ScreenTools.defaultFontPixelWidth * 15 - fillMode: Image.PreserveAspectFit - color: Qt.color("transparent") // Optional, if needed - - } + QGCColoredImage { + source: "/qmlimages/BatteryYellowGreen.svg" + height: ScreenTools.defaultFontPixelHeight * 5 + width: ScreenTools.defaultFontPixelWidth * 7 + fillMode: Image.PreserveAspectFit + color: qgcPal.colorYellowGreen } - - // Second ColumnLayout (Thresholds and Labels) - ColumnLayout { - Layout.fillWidth: true - - LabelledLabel { - label: "100%" - } - LabelledLabel { - label: " 15%" - } - - LabelledLabel { - label: " 7%" - } - } - - ColumnLayout { - Layout.fillWidth: true - //spacing: ScreenTools.defaultFontPixelHeight / 2 - - QGCColoredImage { - source: "/qmlimages/BatteryConf.svg" - height: ScreenTools.defaultFontPixelHeight * 5 - width: ScreenTools.defaultFontPixelWidth * 15 - fillMode: Image.PreserveAspectFit - color: Qt.color("transparent") // Optional, if needed - } + FactTextField { + id: threshold1Field + fact: batterySettings.threshold1 + validator: IntValidator { bottom: 16 } // Value is at least 16 + implicitWidth: ScreenTools.defaultFontPixelWidth * 6 // Reduced width + Layout.leftMargin: -10 + //Layout.preferredWidth: ScreenTools.defaultFontPixelWidth * 2 // Reduced width using Layout.preferredWidth + height: ScreenTools.defaultFontPixelHeight * 1.5 + onEditingFinished: { + let newValue = parseInt(text); + if (newValue > batterySettings.threshold2.rawValue) { + batterySettings.threshold1.rawValue = newValue; + } else { + // Adjust value if invalid + batterySettings.threshold1.rawValue = batterySettings.threshold2.rawValue - 1; + text = batterySettings.threshold1.rawValue.toString(); // Update displayed text + } + } } - // Second ColumnLayout (Thresholds and Labels) - ColumnLayout { - Layout.fillWidth: true - LabelledLabel { - label: " 100%" - } + QGCColoredImage { + source: "/qmlimages/BatteryYellow.svg" + height: ScreenTools.defaultFontPixelHeight * 5 + width: ScreenTools.defaultFontPixelWidth * 7 + fillMode: Image.PreserveAspectFit + color: qgcPal.colorYellow + } - Row { - //spacing: ScreenTools.defaultFontPixelHeight / 2 - Layout.fillWidth: true - - FactTextField { - id: threshold1Field - fact: batterySettings.threshold1 - validator: IntValidator { bottom: 16 } // Value is at least 16 - width: ScreenTools.defaultFontPixelWidth * 6 - height: ScreenTools.defaultFontPixelHeight * 1.5 - onEditingFinished: { - let newValue = parseInt(text); - if (newValue > batterySettings.threshold2.rawValue) { - batterySettings.threshold1.rawValue = newValue; - } else { - // Adjust value if invalid - batterySettings.threshold1.rawValue = batterySettings.threshold2.rawValue - 1; - text = batterySettings.threshold1.rawValue.toString(); // Update displayed text - } - } + FactTextField { + id: threshold2Field + fact: batterySettings.threshold2 + validator: IntValidator { bottom: 16 } + implicitWidth: ScreenTools.defaultFontPixelWidth * 6 + Layout.leftMargin: -10 + height: ScreenTools.defaultFontPixelHeight * 1.5 + onEditingFinished: { + let newValue = parseInt(text); + if (newValue < batterySettings.threshold1.rawValue) { + batterySettings.threshold2.rawValue = newValue; + } else { + batterySettings.threshold2.rawValue = batterySettings.threshold1.rawValue - 1; + text = batterySettings.threshold2.rawValue.toString(); } } + } - Row { - //spacing: ScreenTools.defaultFontPixelHeight / 2 - Layout.fillWidth: true - spacing: ScreenTools.defaultFontPixelWidth * 5 - - FactTextField { - id: threshold2Field - fact: batterySettings.threshold2 - validator: IntValidator { bottom: 16 } - width: ScreenTools.defaultFontPixelWidth * 6 - height: ScreenTools.defaultFontPixelHeight * 1.5 - onEditingFinished: { - let newValue = parseInt(text); - if (newValue < batterySettings.threshold1.rawValue) { - batterySettings.threshold2.rawValue = newValue; - } else { - batterySettings.threshold2.rawValue = batterySettings.threshold1.rawValue - 1; - text = batterySettings.threshold2.rawValue.toString(); - } - } - } - } + QGCColoredImage { + source: "/qmlimages/BatteryOrange.svg" + height: ScreenTools.defaultFontPixelHeight * 5 + width: ScreenTools.defaultFontPixelWidth * 7 + fillMode: Image.PreserveAspectFit + color: qgcPal.colorOrange + } - LabelledLabel { - label: " 15%" - } + QGCLabel { + Layout.preferredWidth: ScreenTools.defaultFontPixelWidth * 2.5 + text: qsTr("Low") + Layout.leftMargin: -13 + } - LabelledLabel { - label: " 7%" - } + QGCColoredImage { + source: "/qmlimages/BatteryCritical.svg" + height: ScreenTools.defaultFontPixelHeight * 5 + width: ScreenTools.defaultFontPixelWidth * 7 + fillMode: Image.PreserveAspectFit + color: qgcPal.colorRed } + + QGCLabel { + Layout.preferredWidth: ScreenTools.defaultFontPixelWidth * 3.5 + text: qsTr("Critical") + Layout.leftMargin: -13 + } + } + + + } } } diff --git a/src/UI/toolbar/Images/BatteryCritical.svg b/src/UI/toolbar/Images/BatteryCritical.svg index bd2bf9c31d9..28e83e3128a 100644 --- a/src/UI/toolbar/Images/BatteryCritical.svg +++ b/src/UI/toolbar/Images/BatteryCritical.svg @@ -5,7 +5,7 @@ viewBox="0 0 72 72" xml:space="preserve" id="svg3" - sodipodi:docname="BatteryCritical.svg" + sodipodi:docname="BatteryOrange (Copy).svg" inkscape:version="1.2.2 (b0a8486541, 2022-12-01)" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" @@ -20,9 +20,9 @@ inkscape:pageopacity="0" inkscape:pagecheckerboard="0" inkscape:deskcolor="#d1d1d1" - inkscape:zoom="8.0000004" - inkscape:cx="43.624998" - inkscape:cy="44.687498" + inkscape:zoom="11.313709" + inkscape:cx="49.055531" + inkscape:cy="32.129163" inkscape:window-width="1854" inkscape:window-height="1011" inkscape:window-x="66" @@ -59,29 +59,12 @@ x="60.300751" y="9.0425482" ry="3.3637743" - rx="3.8661225" /> + rx="3.8661225" /> From 4f78b5ab1b9cacf9889e54876f1ad5a2f6a1ee4e Mon Sep 17 00:00:00 2001 From: Paschalis Date: Sun, 22 Sep 2024 01:23:01 +0300 Subject: [PATCH 13/18] Remove unnecessary battery images. --- src/UI/toolbar/Images/BatteryConf.svg | 105 --------------------- src/UI/toolbar/Images/BatteryConfLight.svg | 105 --------------------- src/UI/toolbar/Images/BatteryLow.svg | 70 -------------- 3 files changed, 280 deletions(-) delete mode 100644 src/UI/toolbar/Images/BatteryConf.svg delete mode 100644 src/UI/toolbar/Images/BatteryConfLight.svg delete mode 100644 src/UI/toolbar/Images/BatteryLow.svg diff --git a/src/UI/toolbar/Images/BatteryConf.svg b/src/UI/toolbar/Images/BatteryConf.svg deleted file mode 100644 index 34e3f27d811..00000000000 --- a/src/UI/toolbar/Images/BatteryConf.svg +++ /dev/null @@ -1,105 +0,0 @@ - - - - - - - - - diff --git a/src/UI/toolbar/Images/BatteryConfLight.svg b/src/UI/toolbar/Images/BatteryConfLight.svg deleted file mode 100644 index c8e8519fced..00000000000 --- a/src/UI/toolbar/Images/BatteryConfLight.svg +++ /dev/null @@ -1,105 +0,0 @@ - - - - - - - - - diff --git a/src/UI/toolbar/Images/BatteryLow.svg b/src/UI/toolbar/Images/BatteryLow.svg deleted file mode 100644 index 28e83e3128a..00000000000 --- a/src/UI/toolbar/Images/BatteryLow.svg +++ /dev/null @@ -1,70 +0,0 @@ - - - - - - - - - From 012cbb43bfc06696a7692ddf7de08d2b0d52e759 Mon Sep 17 00:00:00 2001 From: Paschalis Date: Sun, 22 Sep 2024 01:23:24 +0300 Subject: [PATCH 14/18] Add BatteryEMERGENCY.svg image. --- src/UI/toolbar/Images/BatteryEMERGENCY.svg | 87 ++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 src/UI/toolbar/Images/BatteryEMERGENCY.svg diff --git a/src/UI/toolbar/Images/BatteryEMERGENCY.svg b/src/UI/toolbar/Images/BatteryEMERGENCY.svg new file mode 100644 index 00000000000..bd2bf9c31d9 --- /dev/null +++ b/src/UI/toolbar/Images/BatteryEMERGENCY.svg @@ -0,0 +1,87 @@ + + + + + + + + + From 7563664202c4cbc3617372c69e93d13e5d344e4b Mon Sep 17 00:00:00 2001 From: Paschalis Date: Sun, 22 Sep 2024 01:23:51 +0300 Subject: [PATCH 15/18] Update ChangeLog with new battery display feature. --- ChangeLog.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 948495bb9ec..4fa9a949533 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -4,11 +4,13 @@ Note: This file only contains high level features or important fixes. ## 5.0 - Daily Build -* New combined compass and attitude instrument -* You can select between multiple instruments by clicking on the instrument conntrol on a desktop build or press and hold on mobile builds -* Support for Fly View and Joystick custom mavlink actions has changed. Both the name and formation of the command file is different now. Go to QGC docs to understand how it works now. -* Support for setting individual Mavlink message rates in the Mavlink Inspector. -* Support for Mavlink 2 signing +* Introduced a new combined compass and attitude instrument for enhanced navigation. +* Select between multiple instruments by clicking the instrument control on desktop or pressing and holding on mobile. +* Updated support for Fly View and Joystick custom MAVLink actions; command file names and formats have changed—refer to QGC docs for details. +* Added functionality for setting individual MAVLink message rates in the MAVLink Inspector. +* Enabled support for MAVLink 2 signing. +* Dynamic battery display that reduces the number of bars based on battery percentage, with configurable states (100%, Config 1, Config 2, Low, Critical) for clearer status indication. + ## 4.1 From 0f5c193db0529832ab61735bd2b41ef4e7d100ec Mon Sep 17 00:00:00 2001 From: Paschalis Date: Mon, 23 Sep 2024 20:12:51 +0300 Subject: [PATCH 16/18] Updated BatteryIndicatorSettings and UI for dynamic visibility and validation --- src/Settings/BatteryIndicatorSettings.cc | 46 ++++++ src/Settings/BatteryIndicatorSettings.h | 17 ++- src/UI/toolbar/BatteryIndicator.qml | 173 +++++++++++------------ 3 files changed, 145 insertions(+), 91 deletions(-) diff --git a/src/Settings/BatteryIndicatorSettings.cc b/src/Settings/BatteryIndicatorSettings.cc index f478b1a5494..d9f91b4616f 100644 --- a/src/Settings/BatteryIndicatorSettings.cc +++ b/src/Settings/BatteryIndicatorSettings.cc @@ -9,6 +9,7 @@ #include "BatteryIndicatorSettings.h" +#include #include DECLARE_SETTINGGROUP(BatteryIndicator, "BatteryIndicator") @@ -19,3 +20,48 @@ DECLARE_SETTINGGROUP(BatteryIndicator, "BatteryIndicator") DECLARE_SETTINGSFACT(BatteryIndicatorSettings, display) DECLARE_SETTINGSFACT(BatteryIndicatorSettings, threshold1) DECLARE_SETTINGSFACT(BatteryIndicatorSettings, threshold2) + +// Set threshold1 with validation +void BatteryIndicatorSettings::setThreshold1(int value) { + // Ensure value is at least 16 and less than 100 + if (value < 16) { + threshold1()->setRawValue(17); + } else if (value > 99) { + threshold1()->setRawValue(99); + } else { + // Check if value is greater than threshold2 + if (value > threshold2()->rawValue().toInt()) { + threshold1()->setRawValue(value); + } else { + // Ensure threshold1 is greater than threshold2 + threshold1()->setRawValue(threshold2()->rawValue().toInt() + 1); + } + } +} + +// Set threshold2 with validation +void BatteryIndicatorSettings::setThreshold2(int value) { + // Ensure value is greater than 15 + if (value <= 15) { + threshold2()->setRawValue(16); // Adjust to the minimum valid value + return; + } + + // Check if value is less than threshold1 + if (value < threshold1()->rawValue().toInt()) { + threshold2()->setRawValue(value); + } else { + // Ensure threshold2 is less than threshold1 + threshold2()->setRawValue(threshold1()->rawValue().toInt() - 1); + } +} + +bool BatteryIndicatorSettings::visible() const { + QSettings settings; + return settings.value("ShowBatterySettings", true).toBool(); +} + +bool BatteryIndicatorSettings::thresholdEditable() const { + QSettings settings; + return settings.value("ThresholdEditable", true).toBool(); +} diff --git a/src/Settings/BatteryIndicatorSettings.h b/src/Settings/BatteryIndicatorSettings.h index 7a55f201b81..40b48476fa7 100644 --- a/src/Settings/BatteryIndicatorSettings.h +++ b/src/Settings/BatteryIndicatorSettings.h @@ -21,4 +21,19 @@ class BatteryIndicatorSettings : public SettingsGroup DEFINE_SETTINGFACT(display) DEFINE_SETTINGFACT(threshold1) DEFINE_SETTINGFACT(threshold2) -}; + + Q_PROPERTY(bool visible READ visible NOTIFY visibleChanged) + Q_PROPERTY(bool thresholdEditable READ thresholdEditable NOTIFY thresholdEditableChanged) + + // Setters for thresholds + // Expose setters to QML + Q_INVOKABLE void setThreshold1(int value); + Q_INVOKABLE void setThreshold2(int value); + + bool visible() const; // Group visibility + bool thresholdEditable() const; // Single editable property for both thresholds + +signals: + void visibleChanged(); + void thresholdEditableChanged(); +}; \ No newline at end of file diff --git a/src/UI/toolbar/BatteryIndicator.qml b/src/UI/toolbar/BatteryIndicator.qml index c591cb93cfe..c4d0946b258 100644 --- a/src/UI/toolbar/BatteryIndicator.qml +++ b/src/UI/toolbar/BatteryIndicator.qml @@ -44,6 +44,8 @@ Item { property int threshold1: batterySettings.threshold1.rawValue property int threshold2: batterySettings.threshold2.rawValue + property bool thresholdVisible: batterySettings.thresholdEditable + Row { id: batteryIndicatorRow anchors.top: parent.top @@ -153,7 +155,7 @@ Item { return qsTr("n/a") } - function getBatteryVoltageText() { + function getBatteryVoltageText() { if (!isNaN(battery.voltage.rawValue)) { return battery.voltage.valueString + battery.voltage.units } else if (battery.chargeState.rawValue !== MAVLink.MAV_BATTERY_CHARGE_STATE_UNDEFINED) { @@ -283,7 +285,6 @@ Item { } } - Component { id: batteryExpandedComponent @@ -326,113 +327,105 @@ Item { } SettingsGroupLayout { - heading: qsTr("Battery State Display") + heading: qsTr("Battery State Display") Layout.fillWidth: true - spacing: ScreenTools.defaultFontPixelWidth * 0.5 + spacing: ScreenTools.defaultFontPixelHeight * 0.05 // Reduced outer spacing + visible: batterySettings.visible // Control visibility of the entire group RowLayout { - //Layout.fillWidth: true - - QGCColoredImage { - source: "/qmlimages/BatteryGreen.svg" - height: ScreenTools.defaultFontPixelHeight * 5 - width: ScreenTools.defaultFontPixelWidth * 7 - fillMode: Image.PreserveAspectFit - color: qgcPal.colorGreen - } - - QGCLabel { - Layout.preferredWidth: ScreenTools.defaultFontPixelWidth * 3.5 - text: qsTr("100%") - Layout.leftMargin: -13 - } - - QGCColoredImage { - source: "/qmlimages/BatteryYellowGreen.svg" - height: ScreenTools.defaultFontPixelHeight * 5 - width: ScreenTools.defaultFontPixelWidth * 7 - fillMode: Image.PreserveAspectFit - color: qgcPal.colorYellowGreen + spacing: ScreenTools.defaultFontPixelWidth * 0.05 // Reduced spacing between elements + + // Battery 100% + RowLayout { + spacing: ScreenTools.defaultFontPixelWidth * 0.05 // Tighter spacing for icon and label + QGCColoredImage { + source: "/qmlimages/BatteryGreen.svg" + height: ScreenTools.defaultFontPixelHeight * 5 + width: ScreenTools.defaultFontPixelWidth * 6 + fillMode: Image.PreserveAspectFit + color: qgcPal.colorGreen + } + QGCLabel { text: qsTr("100%") } } - FactTextField { - id: threshold1Field - fact: batterySettings.threshold1 - validator: IntValidator { bottom: 16 } // Value is at least 16 - implicitWidth: ScreenTools.defaultFontPixelWidth * 6 // Reduced width - Layout.leftMargin: -10 - //Layout.preferredWidth: ScreenTools.defaultFontPixelWidth * 2 // Reduced width using Layout.preferredWidth - height: ScreenTools.defaultFontPixelHeight * 1.5 - onEditingFinished: { - let newValue = parseInt(text); - if (newValue > batterySettings.threshold2.rawValue) { - batterySettings.threshold1.rawValue = newValue; - } else { - // Adjust value if invalid - batterySettings.threshold1.rawValue = batterySettings.threshold2.rawValue - 1; - text = batterySettings.threshold1.rawValue.toString(); // Update displayed text + // Threshold 1 + RowLayout { + spacing: ScreenTools.defaultFontPixelWidth * 0.05 // Tighter spacing for icon and field + QGCColoredImage { + source: "/qmlimages/BatteryYellowGreen.svg" + height: ScreenTools.defaultFontPixelHeight * 5 + width: ScreenTools.defaultFontPixelWidth * 6 + fillMode: Image.PreserveAspectFit + color: qgcPal.colorYellowGreen + } + FactTextField { + id: threshold1Field + fact: batterySettings.threshold1 + implicitWidth: ScreenTools.defaultFontPixelWidth * 5.5 + height: ScreenTools.defaultFontPixelHeight * 1.5 + visible: thresholdVisible + onEditingFinished: { + batterySettings.setThreshold1(parseInt(text)); } - } + } } - - QGCColoredImage { - source: "/qmlimages/BatteryYellow.svg" - height: ScreenTools.defaultFontPixelHeight * 5 - width: ScreenTools.defaultFontPixelWidth * 7 - fillMode: Image.PreserveAspectFit - color: qgcPal.colorYellow + QGCLabel { + visible: !thresholdVisible + text: qsTr("") + batterySettings.threshold1.rawValue.toString() + qsTr("%") } - FactTextField { - id: threshold2Field - fact: batterySettings.threshold2 - validator: IntValidator { bottom: 16 } - implicitWidth: ScreenTools.defaultFontPixelWidth * 6 - Layout.leftMargin: -10 - height: ScreenTools.defaultFontPixelHeight * 1.5 - onEditingFinished: { - let newValue = parseInt(text); - if (newValue < batterySettings.threshold1.rawValue) { - batterySettings.threshold2.rawValue = newValue; - } else { - batterySettings.threshold2.rawValue = batterySettings.threshold1.rawValue - 1; - text = batterySettings.threshold2.rawValue.toString(); + // Threshold 2 + RowLayout { + spacing: ScreenTools.defaultFontPixelWidth * 0.05 // Tighter spacing for icon and field + QGCColoredImage { + source: "/qmlimages/BatteryYellow.svg" + height: ScreenTools.defaultFontPixelHeight * 5 + width: ScreenTools.defaultFontPixelWidth * 6 + fillMode: Image.PreserveAspectFit + color: qgcPal.colorYellow + } + FactTextField { + id: threshold2Field + fact: batterySettings.threshold2 + implicitWidth: ScreenTools.defaultFontPixelWidth * 5.5 + height: ScreenTools.defaultFontPixelHeight * 1.5 + visible: thresholdVisible + onEditingFinished: { + batterySettings.setThreshold2(parseInt(text)); } } } - - QGCColoredImage { - source: "/qmlimages/BatteryOrange.svg" - height: ScreenTools.defaultFontPixelHeight * 5 - width: ScreenTools.defaultFontPixelWidth * 7 - fillMode: Image.PreserveAspectFit - color: qgcPal.colorOrange - } - QGCLabel { - Layout.preferredWidth: ScreenTools.defaultFontPixelWidth * 2.5 - text: qsTr("Low") - Layout.leftMargin: -13 + visible: !thresholdVisible + text: qsTr("") + batterySettings.threshold2.rawValue.toString() + qsTr("%") } - QGCColoredImage { - source: "/qmlimages/BatteryCritical.svg" - height: ScreenTools.defaultFontPixelHeight * 5 - width: ScreenTools.defaultFontPixelWidth * 7 - fillMode: Image.PreserveAspectFit - color: qgcPal.colorRed + // Low state + RowLayout { + spacing: ScreenTools.defaultFontPixelWidth * 0.05 // Tighter spacing for icon and label + QGCColoredImage { + source: "/qmlimages/BatteryOrange.svg" + height: ScreenTools.defaultFontPixelHeight * 5 + width: ScreenTools.defaultFontPixelWidth * 6 + fillMode: Image.PreserveAspectFit + color: qgcPal.colorOrange + } + QGCLabel { text: qsTr("Low") } } - QGCLabel { - Layout.preferredWidth: ScreenTools.defaultFontPixelWidth * 3.5 - text: qsTr("Critical") - Layout.leftMargin: -13 + // Critical state + RowLayout { + spacing: ScreenTools.defaultFontPixelWidth * 0.05 // Tighter spacing for icon and label + QGCColoredImage { + source: "/qmlimages/BatteryCritical.svg" + height: ScreenTools.defaultFontPixelHeight * 5 + width: ScreenTools.defaultFontPixelWidth * 6 + fillMode: Image.PreserveAspectFit + color: qgcPal.colorRed + } + QGCLabel { text: qsTr("Critical") } } - } - - - } } } From c2ce804d8928a1b6aeceff27a86bec96f62d9b06 Mon Sep 17 00:00:00 2001 From: Paschalis Date: Sat, 28 Sep 2024 21:39:37 +0300 Subject: [PATCH 17/18] feat: Update battery indicator settings and visibility logic - Modified BatteryIndicator.SettingsGroup.json to adjust default values for thresholds and visibility. - Updated BatteryIndicatorSettings.cc and BatteryIndicatorSettings.h to include validation logic and visibility management for threshold settings. - Updated BatteryIndicator.qml to dynamically toggle between FactTextField and QGCLabel based on visibility settings. --- .../BatteryIndicator.SettingsGroup.json | 18 ++ src/Settings/BatteryIndicatorSettings.cc | 65 ++++-- src/Settings/BatteryIndicatorSettings.h | 43 ++-- src/UI/toolbar/BatteryIndicator.qml | 196 +++++++++--------- 4 files changed, 193 insertions(+), 129 deletions(-) diff --git a/src/Settings/BatteryIndicator.SettingsGroup.json b/src/Settings/BatteryIndicator.SettingsGroup.json index 63da266e1ba..7432d864b9d 100644 --- a/src/Settings/BatteryIndicator.SettingsGroup.json +++ b/src/Settings/BatteryIndicator.SettingsGroup.json @@ -23,6 +23,24 @@ "type": "uint32", "default": 60, "units": "%" + }, + { + "name": "threshold1visible", + "shortDesc": "Controls the visibility of the 'threshold1visible'", + "type": "bool", + "default": true + }, + { + "name": "threshold2visible", + "shortDesc": "Controls the visibility of the 'threshold2visible'", + "type": "bool", + "default": true + }, + { + "name": "battery_state_display", + "shortDesc": "Controls the visibility of the 'Battery State Display'", + "type": "bool", + "default": true } ] } diff --git a/src/Settings/BatteryIndicatorSettings.cc b/src/Settings/BatteryIndicatorSettings.cc index d9f91b4616f..217a7d2cca8 100644 --- a/src/Settings/BatteryIndicatorSettings.cc +++ b/src/Settings/BatteryIndicatorSettings.cc @@ -12,22 +12,67 @@ #include #include +// Declare the settings group for Battery Indicator DECLARE_SETTINGGROUP(BatteryIndicator, "BatteryIndicator") { + // Register the BatteryIndicatorSettings type for QML use qmlRegisterUncreatableType("QGroundControl.SettingsManager", 1, 0, "BatteryIndicatorSettings", "Reference only"); } -DECLARE_SETTINGSFACT(BatteryIndicatorSettings, display) -DECLARE_SETTINGSFACT(BatteryIndicatorSettings, threshold1) -DECLARE_SETTINGSFACT(BatteryIndicatorSettings, threshold2) +// Declare standard setting facts for the BatteryIndicatorSettings +DECLARE_SETTINGSFACT(BatteryIndicatorSettings, display) // Visibility of battery indicator +DECLARE_SETTINGSFACT(BatteryIndicatorSettings, battery_state_display) // Battery state display mode + +// Declare visibility settings for threshold editability +DECLARE_SETTINGSFACT(BatteryIndicatorSettings, threshold1visible) // Determines if the FactTextField for threshold 1 is visible (editable) +DECLARE_SETTINGSFACT(BatteryIndicatorSettings, threshold2visible) // Determines if the FactTextField for threshold 2 is visible (editable) + +DECLARE_SETTINGSFACT_NO_FUNC(BatteryIndicatorSettings, threshold1) +{ + if (!_threshold1Fact) { + _threshold1Fact = _createSettingsFact(threshold1Name); + connect(_threshold1Fact, &SettingsFact::rawValueChanged, this, &BatteryIndicatorSettings::_threshold1Changed); + } + return _threshold1Fact; +} + +DECLARE_SETTINGSFACT_NO_FUNC(BatteryIndicatorSettings, threshold2) +{ + if (!_threshold2Fact) { + _threshold2Fact = _createSettingsFact(threshold2Name); + connect(_threshold2Fact, &SettingsFact::rawValueChanged, this, &BatteryIndicatorSettings::_threshold2Changed); + } + return _threshold2Fact; +} + +// Change handlers for thresholds +void BatteryIndicatorSettings::_threshold1Changed() { + validateThreshold1(); // Call validation when threshold1 value changes +} + +void BatteryIndicatorSettings::_threshold2Changed() { + validateThreshold2(); // Call validation when threshold2 value changes +} + +// Validate threshold1 value +void BatteryIndicatorSettings::validateThreshold1() { + int value = threshold1()->rawValue().toInt(); + setThreshold1(value); // Call the setter with the current value +} + +// Validate threshold2 value +void BatteryIndicatorSettings::validateThreshold2() { + int value = threshold2()->rawValue().toInt(); + setThreshold2(value); // Call the setter with the current value +} // Set threshold1 with validation void BatteryIndicatorSettings::setThreshold1(int value) { // Ensure value is at least 16 and less than 100 if (value < 16) { - threshold1()->setRawValue(17); + threshold1()->setRawValue(17); // Adjust to minimum valid value } else if (value > 99) { - threshold1()->setRawValue(99); + threshold1()->setRawValue(99); // Cap at maximum valid value } else { // Check if value is greater than threshold2 if (value > threshold2()->rawValue().toInt()) { @@ -55,13 +100,3 @@ void BatteryIndicatorSettings::setThreshold2(int value) { threshold2()->setRawValue(threshold1()->rawValue().toInt() - 1); } } - -bool BatteryIndicatorSettings::visible() const { - QSettings settings; - return settings.value("ShowBatterySettings", true).toBool(); -} - -bool BatteryIndicatorSettings::thresholdEditable() const { - QSettings settings; - return settings.value("ThresholdEditable", true).toBool(); -} diff --git a/src/Settings/BatteryIndicatorSettings.h b/src/Settings/BatteryIndicatorSettings.h index 40b48476fa7..fd442e2f045 100644 --- a/src/Settings/BatteryIndicatorSettings.h +++ b/src/Settings/BatteryIndicatorSettings.h @@ -14,26 +14,31 @@ class BatteryIndicatorSettings : public SettingsGroup { Q_OBJECT + public: BatteryIndicatorSettings(QObject* parent = nullptr); + DEFINE_SETTING_NAME_GROUP() - DEFINE_SETTINGFACT(display) - DEFINE_SETTINGFACT(threshold1) - DEFINE_SETTINGFACT(threshold2) - - Q_PROPERTY(bool visible READ visible NOTIFY visibleChanged) - Q_PROPERTY(bool thresholdEditable READ thresholdEditable NOTIFY thresholdEditableChanged) - - // Setters for thresholds - // Expose setters to QML - Q_INVOKABLE void setThreshold1(int value); - Q_INVOKABLE void setThreshold2(int value); - - bool visible() const; // Group visibility - bool thresholdEditable() const; // Single editable property for both thresholds - -signals: - void visibleChanged(); - void thresholdEditableChanged(); -}; \ No newline at end of file + // Standard setting facts + DEFINE_SETTINGFACT(display) // Visibility of battery indicator + DEFINE_SETTINGFACT(battery_state_display) // Battery state display mode + + // Define visibility settings for threshold editability + DEFINE_SETTINGFACT(threshold1visible) // Determines if the FactTextField for threshold 1 is visible (editable) + DEFINE_SETTINGFACT(threshold2visible) // Determines if the FactTextField for threshold 2 is visible (editable) + + // Define setting facts for thresholds + DEFINE_SETTINGFACT(threshold1) // First threshold for battery level + DEFINE_SETTINGFACT(threshold2) // Second threshold for battery level + Q_INVOKABLE void setThreshold1(int value); // Set threshold1 with validation + Q_INVOKABLE void setThreshold2(int value); // Set threshold2 with validation + +private: + void validateThreshold1(); // Validate threshold1 value + void validateThreshold2(); // Validate threshold2 value + + // Change handlers for thresholds + void _threshold1Changed(); + void _threshold2Changed(); +}; diff --git a/src/UI/toolbar/BatteryIndicator.qml b/src/UI/toolbar/BatteryIndicator.qml index c4d0946b258..fc7041ec8a8 100644 --- a/src/UI/toolbar/BatteryIndicator.qml +++ b/src/UI/toolbar/BatteryIndicator.qml @@ -44,7 +44,10 @@ Item { property int threshold1: batterySettings.threshold1.rawValue property int threshold2: batterySettings.threshold2.rawValue - property bool thresholdVisible: batterySettings.thresholdEditable + // Control visibility based on battery state display setting + property bool batteryState: batterySettings.battery_state_display.rawValue + property bool threshold1visible: batterySettings.threshold1visible.rawValue + property bool threshold2visible: batterySettings.threshold2visible.rawValue Row { id: batteryIndicatorRow @@ -327,106 +330,109 @@ Item { } SettingsGroupLayout { - heading: qsTr("Battery State Display") - Layout.fillWidth: true - spacing: ScreenTools.defaultFontPixelHeight * 0.05 // Reduced outer spacing - visible: batterySettings.visible // Control visibility of the entire group - - RowLayout { - spacing: ScreenTools.defaultFontPixelWidth * 0.05 // Reduced spacing between elements - - // Battery 100% - RowLayout { - spacing: ScreenTools.defaultFontPixelWidth * 0.05 // Tighter spacing for icon and label - QGCColoredImage { - source: "/qmlimages/BatteryGreen.svg" - height: ScreenTools.defaultFontPixelHeight * 5 - width: ScreenTools.defaultFontPixelWidth * 6 - fillMode: Image.PreserveAspectFit - color: qgcPal.colorGreen - } - QGCLabel { text: qsTr("100%") } - } + heading: qsTr("Battery State Display") + Layout.fillWidth: true + spacing: ScreenTools.defaultFontPixelHeight * 0.05 // Reduced outer spacing + visible: batteryState // Control visibility of the entire group - // Threshold 1 - RowLayout { - spacing: ScreenTools.defaultFontPixelWidth * 0.05 // Tighter spacing for icon and field - QGCColoredImage { - source: "/qmlimages/BatteryYellowGreen.svg" - height: ScreenTools.defaultFontPixelHeight * 5 - width: ScreenTools.defaultFontPixelWidth * 6 - fillMode: Image.PreserveAspectFit - color: qgcPal.colorYellowGreen - } - FactTextField { - id: threshold1Field - fact: batterySettings.threshold1 - implicitWidth: ScreenTools.defaultFontPixelWidth * 5.5 - height: ScreenTools.defaultFontPixelHeight * 1.5 - visible: thresholdVisible - onEditingFinished: { - batterySettings.setThreshold1(parseInt(text)); - } - } - } - QGCLabel { - visible: !thresholdVisible - text: qsTr("") + batterySettings.threshold1.rawValue.toString() + qsTr("%") - } + RowLayout { + spacing: ScreenTools.defaultFontPixelWidth * 0.05 // Reduced spacing between elements - // Threshold 2 - RowLayout { - spacing: ScreenTools.defaultFontPixelWidth * 0.05 // Tighter spacing for icon and field - QGCColoredImage { - source: "/qmlimages/BatteryYellow.svg" - height: ScreenTools.defaultFontPixelHeight * 5 - width: ScreenTools.defaultFontPixelWidth * 6 - fillMode: Image.PreserveAspectFit - color: qgcPal.colorYellow - } - FactTextField { - id: threshold2Field - fact: batterySettings.threshold2 - implicitWidth: ScreenTools.defaultFontPixelWidth * 5.5 - height: ScreenTools.defaultFontPixelHeight * 1.5 - visible: thresholdVisible - onEditingFinished: { - batterySettings.setThreshold2(parseInt(text)); - } - } - } - QGCLabel { - visible: !thresholdVisible - text: qsTr("") + batterySettings.threshold2.rawValue.toString() + qsTr("%") - } + // Battery 100% + RowLayout { + spacing: ScreenTools.defaultFontPixelWidth * 0.05 // Tighter spacing for icon and label + QGCColoredImage { + source: "/qmlimages/BatteryGreen.svg" + height: ScreenTools.defaultFontPixelHeight * 5 + width: ScreenTools.defaultFontPixelWidth * 6 + fillMode: Image.PreserveAspectFit + color: qgcPal.colorGreen + } + QGCLabel { text: qsTr("100%") } + } - // Low state - RowLayout { - spacing: ScreenTools.defaultFontPixelWidth * 0.05 // Tighter spacing for icon and label - QGCColoredImage { - source: "/qmlimages/BatteryOrange.svg" - height: ScreenTools.defaultFontPixelHeight * 5 - width: ScreenTools.defaultFontPixelWidth * 6 - fillMode: Image.PreserveAspectFit - color: qgcPal.colorOrange - } - QGCLabel { text: qsTr("Low") } - } + // Threshold 1 + RowLayout { + spacing: ScreenTools.defaultFontPixelWidth * 0.05 // Tighter spacing for icon and field + QGCColoredImage { + source: "/qmlimages/BatteryYellowGreen.svg" + height: ScreenTools.defaultFontPixelHeight * 5 + width: ScreenTools.defaultFontPixelWidth * 6 + fillMode: Image.PreserveAspectFit + color: qgcPal.colorYellowGreen + } + FactTextField { + id: threshold1Field + fact: batterySettings.threshold1 + implicitWidth: ScreenTools.defaultFontPixelWidth * 5.5 + height: ScreenTools.defaultFontPixelHeight * 1.5 + visible: threshold1visible + onEditingFinished: { + // Validate and set the new threshold value + batterySettings.setThreshold1(parseInt(text)); + } + } + } + QGCLabel { + visible: !threshold1visible + text: qsTr("") + batterySettings.threshold1.rawValue.toString() + qsTr("%") + } - // Critical state - RowLayout { - spacing: ScreenTools.defaultFontPixelWidth * 0.05 // Tighter spacing for icon and label - QGCColoredImage { - source: "/qmlimages/BatteryCritical.svg" - height: ScreenTools.defaultFontPixelHeight * 5 - width: ScreenTools.defaultFontPixelWidth * 6 - fillMode: Image.PreserveAspectFit - color: qgcPal.colorRed - } - QGCLabel { text: qsTr("Critical") } - } + // Threshold 2 + RowLayout { + spacing: ScreenTools.defaultFontPixelWidth * 0.05 // Tighter spacing for icon and field + QGCColoredImage { + source: "/qmlimages/BatteryYellow.svg" + height: ScreenTools.defaultFontPixelHeight * 5 + width: ScreenTools.defaultFontPixelWidth * 6 + fillMode: Image.PreserveAspectFit + color: qgcPal.colorYellow + } + FactTextField { + id: threshold2Field + fact: batterySettings.threshold2 + implicitWidth: ScreenTools.defaultFontPixelWidth * 5.5 + height: ScreenTools.defaultFontPixelHeight * 1.5 + visible: threshold2visible + onEditingFinished: { + // Validate and set the new threshold value + batterySettings.setThreshold2(parseInt(text)); } } } + QGCLabel { + visible: !threshold2visible + text: qsTr("") + batterySettings.threshold2.rawValue.toString() + qsTr("%") + } + + // Low state + RowLayout { + spacing: ScreenTools.defaultFontPixelWidth * 0.05 // Tighter spacing for icon and label + QGCColoredImage { + source: "/qmlimages/BatteryOrange.svg" + height: ScreenTools.defaultFontPixelHeight * 5 + width: ScreenTools.defaultFontPixelWidth * 6 + fillMode: Image.PreserveAspectFit + color: qgcPal.colorOrange + } + QGCLabel { text: qsTr("Low") } + } + + // Critical state + RowLayout { + spacing: ScreenTools.defaultFontPixelWidth * 0.05 // Tighter spacing for icon and label + QGCColoredImage { + source: "/qmlimages/BatteryCritical.svg" + height: ScreenTools.defaultFontPixelHeight * 5 + width: ScreenTools.defaultFontPixelWidth * 6 + fillMode: Image.PreserveAspectFit + color: qgcPal.colorRed + } + QGCLabel { text: qsTr("Critical") } + } + } +} + + } } } From 80806a39b94121c1dde2545f9810b9aa1dc309a7 Mon Sep 17 00:00:00 2001 From: Paschalis Date: Sat, 28 Sep 2024 22:04:01 +0300 Subject: [PATCH 18/18] Adjusted spacing in BatteryIndicator.qml for better code readability --- src/UI/toolbar/BatteryIndicator.qml | 192 ++++++++++++++-------------- 1 file changed, 96 insertions(+), 96 deletions(-) diff --git a/src/UI/toolbar/BatteryIndicator.qml b/src/UI/toolbar/BatteryIndicator.qml index fc7041ec8a8..62df9061c17 100644 --- a/src/UI/toolbar/BatteryIndicator.qml +++ b/src/UI/toolbar/BatteryIndicator.qml @@ -330,108 +330,108 @@ Item { } SettingsGroupLayout { - heading: qsTr("Battery State Display") - Layout.fillWidth: true - spacing: ScreenTools.defaultFontPixelHeight * 0.05 // Reduced outer spacing - visible: batteryState // Control visibility of the entire group - - RowLayout { - spacing: ScreenTools.defaultFontPixelWidth * 0.05 // Reduced spacing between elements + heading: qsTr("Battery State Display") + Layout.fillWidth: true + spacing: ScreenTools.defaultFontPixelHeight * 0.05 // Reduced outer spacing + visible: batteryState // Control visibility of the entire group - // Battery 100% - RowLayout { - spacing: ScreenTools.defaultFontPixelWidth * 0.05 // Tighter spacing for icon and label - QGCColoredImage { - source: "/qmlimages/BatteryGreen.svg" - height: ScreenTools.defaultFontPixelHeight * 5 - width: ScreenTools.defaultFontPixelWidth * 6 - fillMode: Image.PreserveAspectFit - color: qgcPal.colorGreen - } - QGCLabel { text: qsTr("100%") } - } + RowLayout { + spacing: ScreenTools.defaultFontPixelWidth * 0.05 // Reduced spacing between elements + + // Battery 100% + RowLayout { + spacing: ScreenTools.defaultFontPixelWidth * 0.05 // Tighter spacing for icon and label + QGCColoredImage { + source: "/qmlimages/BatteryGreen.svg" + height: ScreenTools.defaultFontPixelHeight * 5 + width: ScreenTools.defaultFontPixelWidth * 6 + fillMode: Image.PreserveAspectFit + color: qgcPal.colorGreen + } + QGCLabel { text: qsTr("100%") } + } - // Threshold 1 - RowLayout { - spacing: ScreenTools.defaultFontPixelWidth * 0.05 // Tighter spacing for icon and field - QGCColoredImage { - source: "/qmlimages/BatteryYellowGreen.svg" - height: ScreenTools.defaultFontPixelHeight * 5 - width: ScreenTools.defaultFontPixelWidth * 6 - fillMode: Image.PreserveAspectFit - color: qgcPal.colorYellowGreen - } - FactTextField { - id: threshold1Field - fact: batterySettings.threshold1 - implicitWidth: ScreenTools.defaultFontPixelWidth * 5.5 - height: ScreenTools.defaultFontPixelHeight * 1.5 - visible: threshold1visible - onEditingFinished: { - // Validate and set the new threshold value - batterySettings.setThreshold1(parseInt(text)); - } - } - } - QGCLabel { - visible: !threshold1visible - text: qsTr("") + batterySettings.threshold1.rawValue.toString() + qsTr("%") - } + // Threshold 1 + RowLayout { + spacing: ScreenTools.defaultFontPixelWidth * 0.05 // Tighter spacing for icon and field + QGCColoredImage { + source: "/qmlimages/BatteryYellowGreen.svg" + height: ScreenTools.defaultFontPixelHeight * 5 + width: ScreenTools.defaultFontPixelWidth * 6 + fillMode: Image.PreserveAspectFit + color: qgcPal.colorYellowGreen + } + FactTextField { + id: threshold1Field + fact: batterySettings.threshold1 + implicitWidth: ScreenTools.defaultFontPixelWidth * 5.5 + height: ScreenTools.defaultFontPixelHeight * 1.5 + visible: threshold1visible + onEditingFinished: { + // Validate and set the new threshold value + batterySettings.setThreshold1(parseInt(text)); + } + } + } + QGCLabel { + visible: !threshold1visible + text: qsTr("") + batterySettings.threshold1.rawValue.toString() + qsTr("%") + } - // Threshold 2 - RowLayout { - spacing: ScreenTools.defaultFontPixelWidth * 0.05 // Tighter spacing for icon and field - QGCColoredImage { - source: "/qmlimages/BatteryYellow.svg" - height: ScreenTools.defaultFontPixelHeight * 5 - width: ScreenTools.defaultFontPixelWidth * 6 - fillMode: Image.PreserveAspectFit - color: qgcPal.colorYellow - } - FactTextField { - id: threshold2Field - fact: batterySettings.threshold2 - implicitWidth: ScreenTools.defaultFontPixelWidth * 5.5 - height: ScreenTools.defaultFontPixelHeight * 1.5 - visible: threshold2visible - onEditingFinished: { - // Validate and set the new threshold value - batterySettings.setThreshold2(parseInt(text)); - } - } - } - QGCLabel { - visible: !threshold2visible - text: qsTr("") + batterySettings.threshold2.rawValue.toString() + qsTr("%") - } + // Threshold 2 + RowLayout { + spacing: ScreenTools.defaultFontPixelWidth * 0.05 // Tighter spacing for icon and field + QGCColoredImage { + source: "/qmlimages/BatteryYellow.svg" + height: ScreenTools.defaultFontPixelHeight * 5 + width: ScreenTools.defaultFontPixelWidth * 6 + fillMode: Image.PreserveAspectFit + color: qgcPal.colorYellow + } + FactTextField { + id: threshold2Field + fact: batterySettings.threshold2 + implicitWidth: ScreenTools.defaultFontPixelWidth * 5.5 + height: ScreenTools.defaultFontPixelHeight * 1.5 + visible: threshold2visible + onEditingFinished: { + // Validate and set the new threshold value + batterySettings.setThreshold2(parseInt(text)); + } + } + } + QGCLabel { + visible: !threshold2visible + text: qsTr("") + batterySettings.threshold2.rawValue.toString() + qsTr("%") + } - // Low state - RowLayout { - spacing: ScreenTools.defaultFontPixelWidth * 0.05 // Tighter spacing for icon and label - QGCColoredImage { - source: "/qmlimages/BatteryOrange.svg" - height: ScreenTools.defaultFontPixelHeight * 5 - width: ScreenTools.defaultFontPixelWidth * 6 - fillMode: Image.PreserveAspectFit - color: qgcPal.colorOrange - } - QGCLabel { text: qsTr("Low") } - } + // Low state + RowLayout { + spacing: ScreenTools.defaultFontPixelWidth * 0.05 // Tighter spacing for icon and label + QGCColoredImage { + source: "/qmlimages/BatteryOrange.svg" + height: ScreenTools.defaultFontPixelHeight * 5 + width: ScreenTools.defaultFontPixelWidth * 6 + fillMode: Image.PreserveAspectFit + color: qgcPal.colorOrange + } + QGCLabel { text: qsTr("Low") } + } - // Critical state - RowLayout { - spacing: ScreenTools.defaultFontPixelWidth * 0.05 // Tighter spacing for icon and label - QGCColoredImage { - source: "/qmlimages/BatteryCritical.svg" - height: ScreenTools.defaultFontPixelHeight * 5 - width: ScreenTools.defaultFontPixelWidth * 6 - fillMode: Image.PreserveAspectFit - color: qgcPal.colorRed + // Critical state + RowLayout { + spacing: ScreenTools.defaultFontPixelWidth * 0.05 // Tighter spacing for icon and label + QGCColoredImage { + source: "/qmlimages/BatteryCritical.svg" + height: ScreenTools.defaultFontPixelHeight * 5 + width: ScreenTools.defaultFontPixelWidth * 6 + fillMode: Image.PreserveAspectFit + color: qgcPal.colorRed + } + QGCLabel { text: qsTr("Critical") } + } + } } - QGCLabel { text: qsTr("Critical") } - } - } -} } }