2023-04-26 15:53:49 +00:00
|
|
|
import QtQuick 2.15
|
|
|
|
import QtQuick.Controls 2.15
|
|
|
|
|
|
|
|
import StatusQ.Components 0.1
|
|
|
|
import StatusQ.Controls 0.1
|
|
|
|
|
|
|
|
import utils 1.0
|
|
|
|
|
|
|
|
import "../stores/NetworkSelectPopup"
|
|
|
|
|
|
|
|
StatusListItem {
|
|
|
|
id: root
|
|
|
|
|
|
|
|
property var networkModel: null
|
|
|
|
property var singleSelection
|
|
|
|
property var radioButtonGroup
|
|
|
|
property bool useEnabledRole: true
|
|
|
|
|
|
|
|
signal toggleNetwork(var network, var model, int index)
|
|
|
|
|
|
|
|
/// Mirrors Nim's UxEnabledState enum from networks/item.nim
|
|
|
|
enum UxEnabledState {
|
|
|
|
Enabled,
|
|
|
|
AllEnabled,
|
|
|
|
Disabled
|
|
|
|
}
|
|
|
|
|
|
|
|
objectName: model.chainName
|
|
|
|
title: model.chainName
|
|
|
|
asset.height: 24
|
|
|
|
asset.width: 24
|
|
|
|
asset.isImage: true
|
|
|
|
asset.name: Style.svg(model.iconUrl)
|
|
|
|
onClicked: {
|
|
|
|
if(!root.singleSelection.enabled) {
|
|
|
|
checkBox.nextCheckState()
|
|
|
|
} else if(!radioButton.checked) { // Don't allow uncheck
|
2023-07-28 10:37:32 +00:00
|
|
|
root.toggleNetwork(({chainId: model.chainId, chainName: model.chainName, iconUrl: model.iconUrl}), root.networkModel, model.index)
|
2023-04-26 15:53:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
components: [
|
|
|
|
StatusCheckBox {
|
|
|
|
id: checkBox
|
2023-06-14 09:56:55 +00:00
|
|
|
objectName: "networkSelectionCheckbox_" + model.chainName
|
2023-04-26 15:53:49 +00:00
|
|
|
tristate: true
|
|
|
|
visible: !root.singleSelection.enabled
|
|
|
|
|
|
|
|
checkState: {
|
|
|
|
if(root.useEnabledRole) {
|
|
|
|
return model.isEnabled ? Qt.Checked : Qt.Unchecked
|
|
|
|
} else if(model.enabledState === NetworkSelectItemDelegate.Enabled) {
|
|
|
|
return Qt.Checked
|
|
|
|
} else {
|
|
|
|
if( model.enabledState === NetworkSelectItemDelegate.AllEnabled) {
|
|
|
|
return Qt.PartiallyChecked
|
|
|
|
} else {
|
|
|
|
return Qt.Unchecked
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nextCheckState: () => {
|
|
|
|
Qt.callLater(root.toggleNetwork, model, root.networkModel, model.index)
|
|
|
|
return Qt.PartiallyChecked
|
|
|
|
}
|
|
|
|
},
|
|
|
|
StatusRadioButton {
|
|
|
|
id: radioButton
|
|
|
|
visible: root.singleSelection.enabled
|
|
|
|
size: StatusRadioButton.Size.Large
|
|
|
|
ButtonGroup.group: root.radioButtonGroup
|
|
|
|
checked: root.singleSelection.currentModel === root.networkModel && root.singleSelection.currentIndex === model.index
|
|
|
|
|
2023-07-28 10:37:32 +00:00
|
|
|
onToggled: {
|
|
|
|
if(checked) {
|
2023-04-26 15:53:49 +00:00
|
|
|
root.toggleNetwork(({chainId: model.chainId, chainName: model.chainName, iconUrl: model.iconUrl}), root.networkModel, model.index)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|