2023-04-05 11:10:44 +00:00
|
|
|
import QtQuick 2.15
|
|
|
|
import QtQuick.Controls 2.15
|
2022-02-15 13:19:45 +00:00
|
|
|
import QtQuick.Layouts 1.3
|
|
|
|
import QtGraphicalEffects 1.0
|
|
|
|
|
|
|
|
import StatusQ.Core 0.1
|
|
|
|
import StatusQ.Core.Theme 0.1
|
|
|
|
import StatusQ.Components 0.1
|
|
|
|
import StatusQ.Controls 0.1
|
2023-04-05 11:10:44 +00:00
|
|
|
import StatusQ.Popups.Dialog 0.1
|
2022-02-15 13:19:45 +00:00
|
|
|
|
|
|
|
import utils 1.0
|
|
|
|
|
2023-04-05 11:10:44 +00:00
|
|
|
import SortFilterProxyModel 0.2
|
|
|
|
|
|
|
|
import "./NetworkSelectPopup"
|
|
|
|
|
|
|
|
StatusDialog {
|
2022-11-12 09:18:18 +00:00
|
|
|
id: root
|
2023-04-05 11:10:44 +00:00
|
|
|
|
2022-02-15 13:19:45 +00:00
|
|
|
modal: false
|
2023-04-05 11:10:44 +00:00
|
|
|
standardButtons: Dialog.NoButton
|
|
|
|
|
|
|
|
anchors.centerIn: undefined
|
|
|
|
|
|
|
|
padding: 4
|
2022-02-15 13:19:45 +00:00
|
|
|
width: 360
|
2023-04-05 11:10:44 +00:00
|
|
|
implicitHeight: Math.min(432, scrollView.contentHeight + root.padding * 2)
|
|
|
|
|
|
|
|
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside
|
|
|
|
|
|
|
|
required property var layer1Networks
|
|
|
|
required property var layer2Networks
|
|
|
|
property var testNetworks: null
|
|
|
|
|
|
|
|
/// Grouped properties for single selection state. \c singleSelection.enabled is \c false by default
|
|
|
|
/// \see SingleSelectionInfo
|
|
|
|
property alias singleSelection: d.singleSelection
|
2022-08-05 12:07:03 +00:00
|
|
|
|
2023-04-05 11:10:44 +00:00
|
|
|
property bool useEnabledRole: true
|
2022-08-05 12:07:03 +00:00
|
|
|
|
2023-04-05 11:10:44 +00:00
|
|
|
/// \c network is a network.model.nim entry. \c model and \c index for the current selection
|
|
|
|
/// It is called for every toggled network if \c singleSelection.enabled is \c false
|
|
|
|
/// If \c singleSelection.enabled is \c true, it is called only for the selected network when the selection changes
|
|
|
|
/// \see SingleSelectionInfo
|
|
|
|
signal toggleNetwork(var network, var model, int index)
|
2022-02-17 09:15:37 +00:00
|
|
|
|
2023-04-05 11:10:44 +00:00
|
|
|
/// Mirrors Nim's UxEnabledState enum from networks/item.nim
|
|
|
|
enum UxEnabledState {
|
|
|
|
Enabled,
|
|
|
|
AllEnabled,
|
|
|
|
Disabled
|
|
|
|
}
|
|
|
|
|
|
|
|
QtObject {
|
|
|
|
id: d
|
2022-11-12 09:18:18 +00:00
|
|
|
|
2023-04-05 11:10:44 +00:00
|
|
|
property SingleSelectionInfo singleSelection: SingleSelectionInfo {}
|
|
|
|
property SingleSelectionInfo tmpObject: SingleSelectionInfo { enabled: true }
|
|
|
|
}
|
2023-02-22 17:11:13 +00:00
|
|
|
|
2022-02-15 13:19:45 +00:00
|
|
|
|
|
|
|
background: Rectangle {
|
|
|
|
radius: Style.current.radius
|
|
|
|
color: Style.current.background
|
|
|
|
border.color: Style.current.border
|
|
|
|
layer.enabled: true
|
|
|
|
layer.effect: DropShadow{
|
|
|
|
verticalOffset: 3
|
|
|
|
radius: 8
|
|
|
|
samples: 15
|
|
|
|
fast: true
|
|
|
|
cached: true
|
|
|
|
color: "#22000000"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-13 12:29:38 +00:00
|
|
|
contentItem: StatusScrollView {
|
2022-02-15 13:19:45 +00:00
|
|
|
id: scrollView
|
2023-04-05 11:10:44 +00:00
|
|
|
|
2022-11-12 09:18:18 +00:00
|
|
|
width: root.width
|
|
|
|
height: root.height
|
2022-12-20 15:23:49 +00:00
|
|
|
contentHeight: content.height
|
2023-02-22 17:11:13 +00:00
|
|
|
contentWidth: availableWidth
|
2022-08-05 12:07:03 +00:00
|
|
|
padding: 0
|
2022-02-15 13:19:45 +00:00
|
|
|
|
|
|
|
ScrollBar.horizontal.policy: ScrollBar.AlwaysOff
|
|
|
|
|
|
|
|
Column {
|
|
|
|
id: content
|
2022-12-20 15:23:49 +00:00
|
|
|
width: childrenRect.width
|
2022-08-05 12:07:03 +00:00
|
|
|
spacing: 4
|
2022-02-15 13:19:45 +00:00
|
|
|
|
2022-02-17 09:15:37 +00:00
|
|
|
Repeater {
|
|
|
|
id: chainRepeater1
|
2023-04-05 11:10:44 +00:00
|
|
|
|
2022-08-18 17:51:18 +00:00
|
|
|
width: parent.width
|
|
|
|
height: parent.height
|
2023-04-05 11:10:44 +00:00
|
|
|
|
2022-08-09 13:52:17 +00:00
|
|
|
objectName: "networkSelectPopupChainRepeaterLayer1"
|
2022-11-12 09:18:18 +00:00
|
|
|
model: root.layer1Networks
|
2022-02-17 09:15:37 +00:00
|
|
|
|
2023-04-05 11:10:44 +00:00
|
|
|
delegate: ChainItemDelegate {
|
|
|
|
networkModel: chainRepeater1.model
|
|
|
|
}
|
2022-02-17 09:15:37 +00:00
|
|
|
}
|
|
|
|
|
2022-05-18 21:58:07 +00:00
|
|
|
StatusBaseText {
|
|
|
|
font.pixelSize: Style.current.primaryTextFontSize
|
|
|
|
color: Theme.palette.baseColor1
|
|
|
|
text: qsTr("Layer 2")
|
2022-08-05 12:07:03 +00:00
|
|
|
height: 40
|
|
|
|
leftPadding: 16
|
|
|
|
topPadding: 10
|
|
|
|
verticalAlignment: Text.AlignVCenter
|
|
|
|
|
2022-05-18 21:58:07 +00:00
|
|
|
visible: chainRepeater2.count > 0
|
|
|
|
}
|
|
|
|
|
2022-02-17 09:15:37 +00:00
|
|
|
Repeater {
|
|
|
|
id: chainRepeater2
|
|
|
|
|
2023-04-05 11:10:44 +00:00
|
|
|
model: root.layer2Networks
|
|
|
|
delegate: ChainItemDelegate {
|
|
|
|
networkModel: chainRepeater2.model
|
|
|
|
}
|
2022-02-17 09:15:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Repeater {
|
|
|
|
id: chainRepeater3
|
2022-11-12 09:18:18 +00:00
|
|
|
model: root.testNetworks
|
2023-04-05 11:10:44 +00:00
|
|
|
delegate: ChainItemDelegate {
|
|
|
|
networkModel: chainRepeater3.model
|
|
|
|
}
|
2022-02-17 09:15:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-05 11:10:44 +00:00
|
|
|
component ChainItemDelegate: StatusListItem {
|
|
|
|
id: chainItemDelegate
|
|
|
|
|
|
|
|
property var networkModel: null
|
|
|
|
|
|
|
|
objectName: model.chainName
|
|
|
|
implicitHeight: 48
|
|
|
|
implicitWidth: scrollView.width
|
|
|
|
title: model.chainName
|
|
|
|
asset.height: 24
|
|
|
|
asset.width: 24
|
|
|
|
asset.isImage: true
|
|
|
|
asset.name: Style.svg(model.iconUrl)
|
|
|
|
onClicked: {
|
|
|
|
if(!d.singleSelection.enabled) {
|
|
|
|
checkBox.nextCheckState()
|
|
|
|
} else if(!radioButton.checked) { // Don't allow uncheck
|
|
|
|
radioButton.toggle()
|
2023-03-06 12:30:58 +00:00
|
|
|
}
|
2023-04-05 11:10:44 +00:00
|
|
|
}
|
2023-03-06 12:30:58 +00:00
|
|
|
|
2023-04-05 11:10:44 +00:00
|
|
|
components: [
|
|
|
|
StatusCheckBox {
|
|
|
|
id: checkBox
|
|
|
|
tristate: true
|
|
|
|
visible: !d.singleSelection.enabled
|
|
|
|
|
|
|
|
checkState: {
|
|
|
|
if(root.useEnabledRole) {
|
|
|
|
return model.isEnabled ? Qt.Checked : Qt.Unchecked
|
|
|
|
} else if(model.enabledState === NetworkSelectPopup.Enabled) {
|
|
|
|
return Qt.Checked
|
|
|
|
} else {
|
|
|
|
if( model.enabledState === NetworkSelectPopup.AllEnabled) {
|
|
|
|
return Qt.PartiallyChecked
|
2023-02-20 10:57:45 +00:00
|
|
|
} else {
|
2023-04-05 11:10:44 +00:00
|
|
|
return Qt.Unchecked
|
2022-05-18 21:58:07 +00:00
|
|
|
}
|
2022-02-15 13:19:45 +00:00
|
|
|
}
|
2023-04-05 11:10:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nextCheckState: () => {
|
|
|
|
Qt.callLater(root.toggleNetwork, model, chainItemDelegate.networkModel, model.index)
|
|
|
|
return Qt.PartiallyChecked
|
|
|
|
}
|
|
|
|
},
|
|
|
|
StatusRadioButton {
|
|
|
|
id: radioButton
|
|
|
|
visible: d.singleSelection.enabled
|
|
|
|
size: StatusRadioButton.Size.Large
|
|
|
|
ButtonGroup.group: radioBtnGroup
|
|
|
|
checked: d.singleSelection.currentModel === chainItemDelegate.networkModel && d.singleSelection.currentIndex === model.index
|
|
|
|
|
|
|
|
property SingleSelectionInfo exchangeObject: null
|
|
|
|
function setNewInfo(networkModel, index) {
|
|
|
|
d.tmpObject.currentModel = networkModel
|
|
|
|
d.tmpObject.currentIndex = index
|
|
|
|
exchangeObject = d.tmpObject
|
|
|
|
d.tmpObject = d.singleSelection
|
|
|
|
d.singleSelection = exchangeObject
|
|
|
|
exchangeObject = null
|
|
|
|
}
|
|
|
|
|
|
|
|
onCheckedChanged: {
|
|
|
|
if(checked && (d.singleSelection.currentModel !== chainItemDelegate.networkModel || d.singleSelection.currentIndex !== model.index)) {
|
|
|
|
setNewInfo(chainItemDelegate.networkModel, model.index)
|
|
|
|
root.toggleNetwork(model, chainItemDelegate.networkModel, model.index)
|
|
|
|
close()
|
2023-03-13 10:33:44 +00:00
|
|
|
}
|
2022-02-15 13:19:45 +00:00
|
|
|
}
|
2023-04-05 11:10:44 +00:00
|
|
|
}
|
|
|
|
]
|
2022-02-15 13:19:45 +00:00
|
|
|
}
|
2023-02-22 17:11:13 +00:00
|
|
|
|
|
|
|
ButtonGroup {
|
|
|
|
id: radioBtnGroup
|
|
|
|
}
|
2022-02-15 13:19:45 +00:00
|
|
|
}
|