2023-04-26 15:53:49 +00:00
|
|
|
import QtQuick 2.15
|
2024-06-12 08:52:11 +00:00
|
|
|
import QtQml 2.15
|
2023-04-26 15:53:49 +00:00
|
|
|
import QtQuick.Controls 2.15
|
2024-06-12 08:52:11 +00:00
|
|
|
import QtGraphicalEffects 1.15
|
2023-04-26 15:53:49 +00:00
|
|
|
|
|
|
|
import StatusQ.Components 0.1
|
|
|
|
import StatusQ.Controls 0.1
|
2024-06-12 08:52:11 +00:00
|
|
|
import StatusQ.Core.Theme 0.1
|
2023-04-26 15:53:49 +00:00
|
|
|
|
|
|
|
import utils 1.0
|
|
|
|
|
|
|
|
StatusListItem {
|
|
|
|
id: root
|
|
|
|
|
2024-06-12 08:52:11 +00:00
|
|
|
// input/output property
|
|
|
|
property int checkState: Qt.Unchecked
|
|
|
|
|
|
|
|
//input property
|
|
|
|
// Defines the next state of the checkbox when clicked
|
|
|
|
// By default, it toggles between checked and unchecked
|
|
|
|
property int nextCheckState: checkState === Qt.Checked ? Qt.Unchecked : Qt.Checked
|
|
|
|
|
|
|
|
required property string iconUrl
|
|
|
|
property bool showIndicator: true
|
|
|
|
property bool multiSelection: false
|
|
|
|
property bool interactive: true
|
2023-04-26 15:53:49 +00:00
|
|
|
|
2024-06-12 08:52:11 +00:00
|
|
|
// output signal
|
|
|
|
// Emitted when the checkbox is clicked
|
|
|
|
// This signal is useful when the check state needs to change
|
|
|
|
// only after processing the toggle event E.g backend call
|
|
|
|
signal toggled
|
|
|
|
|
|
|
|
objectName: root.title
|
2023-04-26 15:53:49 +00:00
|
|
|
asset.height: 24
|
|
|
|
asset.width: 24
|
|
|
|
asset.isImage: true
|
2024-06-12 08:52:11 +00:00
|
|
|
asset.name: root.iconUrl
|
2023-04-26 15:53:49 +00:00
|
|
|
onClicked: {
|
2024-06-12 08:52:11 +00:00
|
|
|
d.toggled()
|
2023-04-26 15:53:49 +00:00
|
|
|
}
|
|
|
|
|
2024-06-12 08:52:11 +00:00
|
|
|
leftPadding: 16
|
|
|
|
rightPadding: 16
|
2024-06-06 09:49:13 +00:00
|
|
|
statusListItemTitleArea.anchors.leftMargin: 12
|
2024-06-15 21:33:12 +00:00
|
|
|
highlighted: d.checkState !== Qt.Unchecked && !showIndicator
|
2024-06-12 08:52:11 +00:00
|
|
|
|
|
|
|
Binding on bgColor {
|
|
|
|
when: highlighted && !root.sensor.containsMouse
|
|
|
|
value: root.interactive ? Theme.palette.baseColor4 : Theme.palette.primaryColor3
|
|
|
|
restoreMode: Binding.RestoreBindingOrValue
|
|
|
|
}
|
|
|
|
|
|
|
|
onCheckStateChanged: {
|
|
|
|
if (checkState !== d.checkState) {
|
|
|
|
d.checkState = checkState
|
|
|
|
}
|
|
|
|
}
|
2024-06-06 09:49:13 +00:00
|
|
|
|
2023-04-26 15:53:49 +00:00
|
|
|
components: [
|
2024-06-12 08:52:11 +00:00
|
|
|
Loader {
|
|
|
|
id: indicatorLoader
|
|
|
|
sourceComponent: root.multiSelection ? checkBoxComponent : radioButtonComponent
|
|
|
|
active: root.showIndicator
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
Component {
|
|
|
|
id: checkBoxComponent
|
2023-04-26 15:53:49 +00:00
|
|
|
StatusCheckBox {
|
|
|
|
id: checkBox
|
2024-06-12 08:52:11 +00:00
|
|
|
|
|
|
|
objectName: "networkSelectionCheckbox_" + root.title
|
|
|
|
checkState: d.checkState
|
2023-04-26 15:53:49 +00:00
|
|
|
tristate: true
|
2024-06-12 08:52:11 +00:00
|
|
|
nextCheckState: () => d.checkState
|
|
|
|
enabled: root.interactive
|
|
|
|
|
|
|
|
onClicked: {
|
|
|
|
d.toggled()
|
2023-04-26 15:53:49 +00:00
|
|
|
}
|
2024-06-12 08:52:11 +00:00
|
|
|
}
|
|
|
|
}
|
2023-04-26 15:53:49 +00:00
|
|
|
|
2024-06-12 08:52:11 +00:00
|
|
|
Component {
|
|
|
|
id: radioButtonComponent
|
2023-04-26 15:53:49 +00:00
|
|
|
StatusRadioButton {
|
|
|
|
id: radioButton
|
2024-06-12 08:52:11 +00:00
|
|
|
objectName: "networkSelectionRadioButton_" + root.title
|
2023-04-26 15:53:49 +00:00
|
|
|
size: StatusRadioButton.Size.Large
|
2024-06-12 08:52:11 +00:00
|
|
|
checked: d.checkState !== Qt.Unchecked
|
|
|
|
enabled: root.interactive
|
2023-04-26 15:53:49 +00:00
|
|
|
|
2024-06-12 08:52:11 +00:00
|
|
|
onClicked: {
|
|
|
|
d.toggled()
|
2023-04-26 15:53:49 +00:00
|
|
|
}
|
|
|
|
}
|
2024-06-12 08:52:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QtObject {
|
|
|
|
id: d
|
|
|
|
property int checkState: root.checkState
|
|
|
|
|
|
|
|
function toggled() {
|
|
|
|
if (!root.interactive) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
d.checkState = root.nextCheckState
|
|
|
|
root.toggled()
|
|
|
|
}
|
|
|
|
|
|
|
|
onCheckStateChanged: {
|
|
|
|
if (checkState !== root.checkState) {
|
|
|
|
root.checkState = checkState
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-04-26 15:53:49 +00:00
|
|
|
}
|