Skip to content

Commit

Permalink
Add SettingsListSwitch, update text in PageSettingsSystem
Browse files Browse the repository at this point in the history
Part of #1232
  • Loading branch information
DanielMcInnes committed Jan 8, 2025
1 parent e5bd854 commit 35311d5
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 3 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ set (VENUS_QML_MODULE_SOURCES
components/listitems/core/SectionHeader.qml
components/listitems/core/SettingsListHeader.qml
components/listitems/core/SettingsListNavigation.qml
components/listitems/core/SettingsListSwitch.qml

components/widgets/AcWidget.qml
components/widgets/AcInputWidget.qml
Expand Down
91 changes: 91 additions & 0 deletions components/listitems/core/SettingsListSwitch.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
** Copyright (C) 2023 Victron Energy B.V.
** See LICENSE.txt for license information.
*/

import QtQuick
import Victron.VenusOS

ListItem {
id: root

property alias text: primary.text
property alias secondaryText: secondary.text
readonly property alias dataItem: dataItem
property alias checked: switchItem.checked
property alias checkable: switchItem.checkable
property bool updateDataOnClick: true
property bool invertSourceValue

property int valueTrue: 1
property int valueFalse: 0

signal clicked()

function _setChecked(c) {
if (updateDataOnClick) {
if (root.dataItem.uid.length > 0) {
if (invertSourceValue) {
dataItem.setValue(c ? valueFalse : valueTrue)
} else {
dataItem.setValue(c ? valueTrue : valueFalse)
}
}
}
clicked()
}

down: pressArea.containsPress
enabled: userHasWriteAccess && (dataItem.uid === "" || dataItem.isValid)

content.children: [
Switch {
id: switchItem

checked: invertSourceValue ? dataItem.value === valueFalse : dataItem.value === valueTrue
checkable: false
onClicked: root._setChecked(!checked)
}
]

Column {
anchors {
left: parent.left
leftMargin: Theme.geometry_listItem_content_horizontalMargin
verticalCenter: parent.verticalCenter
}

Label {
id: primary

font.pixelSize: Theme.font_size_body2
wrapMode: Text.Wrap
text: root.primaryText
}

Label {
id: secondary

font.pixelSize: Theme.font_size_body1
wrapMode: Text.Wrap
color: Theme.color_font_secondary
text: root.secondaryText
}
}

ListPressArea {
id: pressArea

radius: backgroundRect.radius
anchors {
fill: parent
bottomMargin: root.spacing
}

onClicked: root._setChecked(!switchItem.checked)
}

VeQuickItem {
id: dataItem
}
}
8 changes: 5 additions & 3 deletions pages/settings/PageSettingsSystem.qml
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,11 @@ Page {
pageSource: "/pages/settings/PageSettingsDvcc.qml"
}

ListSwitch {
//% "Has DC system"
text: qsTrId("settings_system_has_dc_system")
SettingsListSwitch {
//% "Display DC Loads"
text: qsTrId("settings_system_display_dc_loads")
//% "Calculated estimate of DC consumption"
secondaryText: qsTrId("settings_system_calculated_estimate_of_dc_consumption")
dataItem.uid: Global.systemSettings.serviceUid + "/Settings/SystemSetup/HasDcSystem"
}

Expand Down

0 comments on commit 35311d5

Please sign in to comment.