-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add SettingsListSwitch, update text in PageSettingsSystem
Part of #1232
- Loading branch information
1 parent
e5bd854
commit 35311d5
Showing
3 changed files
with
97 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters