Remove extra ScrollView and customise ListView instead

Contributes to issue CURA-8686.
This commit is contained in:
Ghostkeeper 2022-01-19 17:14:30 +01:00
parent 5b76cf5689
commit f1db69a36a
No known key found for this signature in database
GPG key ID: D2A8871EE34EC59A

View file

@ -1,4 +1,4 @@
// Copyright (c) 2021 Ultimaker B.V.
// Copyright (c) 2022 Ultimaker B.V.
// Cura is released under the terms of the LGPLv3 or higher.
import QtQuick 2.10
@ -17,7 +17,7 @@ Item
id: base
height: networkPrinterInfo.height + controlsRectangle.height
property alias maxItemCountAtOnce: networkPrinterScrollView.maxItemCountAtOnce
property alias maxItemCountAtOnce: networkPrinterListView.maxItemCountAtOnce
property var currentItem: (networkPrinterListView.currentIndex >= 0)
? networkPrinterListView.model[networkPrinterListView.currentIndex]
: null
@ -29,7 +29,7 @@ Item
Item
{
id: networkPrinterInfo
height: networkPrinterScrollView.visible ? networkPrinterScrollView.height : noPrinterLabel.height
height: networkPrinterListView.visible ? networkPrinterListView.height : noPrinterLabel.height
anchors.left: parent.left
anchors.right: parent.right
anchors.top: parent.top
@ -44,104 +44,91 @@ Item
visible: networkPrinterListView.count == 0 // Do not show if there are discovered devices.
}
ScrollView
ListView
{
id: networkPrinterScrollView
id: networkPrinterListView
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
ScrollBar.horizontal.policy: ScrollBar.AsNeeded
ScrollBar.vertical.policy: ScrollBar.AsNeeded
property int maxItemCountAtOnce: 8 // show at max 8 items at once, otherwise you need to scroll.
height: Math.min(contentHeight, (maxItemCountAtOnce * UM.Theme.getSize("action_button").height) - UM.Theme.getSize("default_margin").height)
ScrollBar.vertical: UM.ScrollBar
{
id: networkPrinterScrollBar
}
clip: true
property int maxItemCountAtOnce: 8 // show at max 8 items at once, otherwise you need to scroll.
visible: networkPrinterListView.count > 0
clip: true
model: contentLoader.enabled ? CuraApplication.getDiscoveredPrintersModel().discoveredPrinters: undefined
cacheBuffer: 1000000 // Set a large cache to effectively just cache every list item.
ListView
section.property: "modelData.sectionName"
section.criteria: ViewSection.FullString
section.delegate: UM.Label
{
id: networkPrinterListView
anchors.fill: parent
model: contentLoader.enabled ? CuraApplication.getDiscoveredPrintersModel().discoveredPrinters: undefined
anchors.left: parent.left
anchors.leftMargin: UM.Theme.getSize("default_margin").width
anchors.right: networkPrinterScrollBar.left
anchors.rightMargin: UM.Theme.getSize("default_margin").width
height: UM.Theme.getSize("setting_control").height
text: section
color: UM.Theme.getColor("small_button_text")
}
section.property: "modelData.sectionName"
section.criteria: ViewSection.FullString
section.delegate: sectionHeading
boundsBehavior: Flickable.StopAtBounds
flickDeceleration: 20000 // To prevent the flicking behavior.
cacheBuffer: 1000000 // Set a large cache to effectively just cache every list item.
Component.onCompleted:
Component.onCompleted:
{
var toSelectIndex = -1
// Select the first one that's not "unknown" and is the host a group by default.
for (var i = 0; i < count; i++)
{
var toSelectIndex = -1
// Select the first one that's not "unknown" and is the host a group by default.
for (var i = 0; i < count; i++)
if (!model[i].isUnknownMachineType && model[i].isHostOfGroup)
{
if (!model[i].isUnknownMachineType && model[i].isHostOfGroup)
{
toSelectIndex = i
break
}
}
currentIndex = toSelectIndex
}
// CURA-6483 For some reason currentIndex can be reset to 0. This check is here to prevent automatically
// selecting an unknown or non-host printer.
onCurrentIndexChanged:
{
var item = model[currentIndex]
if (!item || item.isUnknownMachineType || !item.isHostOfGroup)
{
currentIndex = -1
toSelectIndex = i
break
}
}
currentIndex = toSelectIndex
}
Component
// CURA-6483 For some reason currentIndex can be reset to 0. This check is here to prevent automatically
// selecting an unknown or non-host printer.
onCurrentIndexChanged:
{
var item = model[currentIndex]
if (!item || item.isUnknownMachineType || !item.isHostOfGroup)
{
id: sectionHeading
currentIndex = -1
}
}
UM.Label
{
anchors.left: parent.left
anchors.leftMargin: UM.Theme.getSize("default_margin").width
height: UM.Theme.getSize("setting_control").height
text: section
color: UM.Theme.getColor("small_button_text")
}
delegate: Cura.MachineSelectorButton
{
text: modelData.device.name
width: networkPrinterListView.width - networkPrinterScrollBar.width
outputDevice: modelData.device
enabled: !modelData.isUnknownMachineType && modelData.isHostOfGroup
printerTypeLabelAutoFit: true
// update printer types for all items in the list
updatePrinterTypesOnlyWhenChecked: false
updatePrinterTypesFunction: updateMachineTypes
// show printer type as it is
printerTypeLabelConversionFunction: function(value) { return value }
function updateMachineTypes()
{
printerTypesList = [ modelData.readableMachineType ]
}
delegate: Cura.MachineSelectorButton
checkable: false
selected: networkPrinterListView.currentIndex == model.index
onClicked:
{
text: modelData.device.name
width: networkPrinterListView.width
outputDevice: modelData.device
enabled: !modelData.isUnknownMachineType && modelData.isHostOfGroup
printerTypeLabelAutoFit: true
// update printer types for all items in the list
updatePrinterTypesOnlyWhenChecked: false
updatePrinterTypesFunction: updateMachineTypes
// show printer type as it is
printerTypeLabelConversionFunction: function(value) { return value }
function updateMachineTypes()
{
printerTypesList = [ modelData.readableMachineType ]
}
checkable: false
selected: ListView.view.currentIndex == model.index
onClicked:
{
ListView.view.currentIndex = index
}
networkPrinterListView.currentIndex = index
}
}
}