Skip to content

Commit

Permalink
Rework display ordering
Browse files Browse the repository at this point in the history
Also reworked settings visibility handling
  • Loading branch information
DonLakeFlyer committed Jan 6, 2025
1 parent 3b5402c commit 6c23b04
Showing 1 changed file with 104 additions and 130 deletions.
234 changes: 104 additions & 130 deletions src/UI/toolbar/BatteryIndicator.qml
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,15 @@ Item {
property Component expandedPageComponent

property var _activeVehicle: QGroundControl.multiVehicleManager.activeVehicle
property Fact _indicatorDisplay: QGroundControl.settingsManager.batteryIndicatorSettings.display
property var _batterySettings: QGroundControl.settingsManager.batteryIndicatorSettings
property Fact _indicatorDisplay: _batterySettings.valueDisplay
property bool _showPercentage: _indicatorDisplay.rawValue === 0
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

// 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
property int threshold1: _batterySettings.threshold1.rawValue
property int threshold2: _batterySettings.threshold2.rawValue

Row {
id: batteryIndicatorRow
Expand Down Expand Up @@ -118,7 +111,6 @@ Item {
}

function getBatterySvgSource() {

switch (battery.chargeState.rawValue) {
case MAVLink.MAV_BATTERY_CHARGE_STATE_OK:
if (!isNaN(battery.percentRemaining.rawValue)) {
Expand Down Expand Up @@ -209,8 +201,6 @@ Item {
ColumnLayout {
spacing: ScreenTools.defaultFontPixelHeight / 2

property var _activeVehicle: QGroundControl.multiVehicleManager.activeVehicle

Component {
id: batteryValuesAvailableComponent

Expand Down Expand Up @@ -296,144 +286,128 @@ Item {

FactPanelController { id: controller }

Loader {
Layout.fillWidth: true
sourceComponent: expandedPageComponent
}

SettingsGroupLayout {
Layout.fillWidth: true
heading: qsTr("Battery Display")
Layout.fillWidth: true

RowLayout {
Layout.fillWidth: true
LabelledFactComboBox {
id: editModeCheckBox
label: qsTr("Value")
fact: _fact
visible: _fact,visible

QGCLabel { Layout.fillWidth: true; text: qsTr("Battery Display") }
FactComboBox {
id: editModeCheckBox
fact: QGroundControl.settingsManager.batteryIndicatorSettings.display
sizeToContents: true
}
property Fact _fact: QGroundControl.settingsManager.batteryIndicatorSettings.valueDisplay
}

RowLayout {
Layout.fillWidth: true
ColumnLayout {
QGCLabel { text: qsTr("Coloring") }

QGCLabel { Layout.fillWidth: true; text: qsTr("Vehicle Power") }
QGCButton {
text: qsTr("Configure")
onClicked: {
mainWindow.showVehicleSetupTool(qsTr("Power"))
mainWindow.closeIndicatorDrawer()
}
}
}

}

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

// 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
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"
width: ScreenTools.defaultFontPixelWidth * 6
height: width
fillMode: Image.PreserveAspectFit
color: qgcPal.colorGreen
}
QGCLabel { text: qsTr("100%") }
}
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));
// Threshold 1
RowLayout {
spacing: ScreenTools.defaultFontPixelWidth * 0.05 // Tighter spacing for icon and field
QGCColoredImage {
source: "/qmlimages/BatteryYellowGreen.svg"
width: ScreenTools.defaultFontPixelWidth * 6
height: width
fillMode: Image.PreserveAspectFit
color: qgcPal.colorYellowGreen
}
FactTextField {
id: threshold1Field
fact: _batterySettings.threshold1
implicitWidth: ScreenTools.defaultFontPixelWidth * 5.5
height: ScreenTools.defaultFontPixelHeight * 1.5
enabled: fact.visible
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));
// Threshold 2
RowLayout {
spacing: ScreenTools.defaultFontPixelWidth * 0.05 // Tighter spacing for icon and field
QGCColoredImage {
source: "/qmlimages/BatteryYellow.svg"
width: ScreenTools.defaultFontPixelWidth * 6
height: width
fillMode: Image.PreserveAspectFit
color: qgcPal.colorYellow
}
FactTextField {
fact: _batterySettings.threshold2
implicitWidth: ScreenTools.defaultFontPixelWidth * 5.5
height: ScreenTools.defaultFontPixelHeight * 1.5
enabled: fact.visible
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
// Low state
RowLayout {
spacing: ScreenTools.defaultFontPixelWidth * 0.05 // Tighter spacing for icon and label
QGCColoredImage {
source: "/qmlimages/BatteryOrange.svg"
width: ScreenTools.defaultFontPixelWidth * 6
height: width
fillMode: Image.PreserveAspectFit
color: qgcPal.colorOrange
}
QGCLabel { text: qsTr("Low") }
}
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"
width: ScreenTools.defaultFontPixelWidth * 6
height: width
fillMode: Image.PreserveAspectFit
color: qgcPal.colorRed
}
QGCLabel { text: qsTr("Critical") }
}
QGCLabel { text: qsTr("Critical") }
}
}
}

Loader {
Layout.fillWidth: true
sourceComponent: expandedPageComponent
}

SettingsGroupLayout {
LabelledButton {
label: qsTr("Vehicle Power")
buttonText: qsTr("Configure")

onClicked: {
mainWindow.showVehicleSetupTool(qsTr("Power"))
mainWindow.closeIndicatorDrawer()
}
}
}
}
}
}

0 comments on commit 6c23b04

Please sign in to comment.