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,35 +44,37 @@ Item
visible: networkPrinterListView.count == 0 // Do not show if there are discovered devices.
}
ScrollView
{
id: networkPrinterScrollView
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)
visible: networkPrinterListView.count > 0
clip: true
ListView
{
id: networkPrinterListView
anchors.fill: parent
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
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
model: contentLoader.enabled ? CuraApplication.getDiscoveredPrintersModel().discoveredPrinters: undefined
cacheBuffer: 1000000 // Set a large cache to effectively just cache every list item.
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.
section.delegate: UM.Label
{
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")
}
Component.onCompleted:
{
@ -100,25 +102,11 @@ Item
}
}
Component
{
id: sectionHeading
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
width: networkPrinterListView.width - networkPrinterScrollBar.width
outputDevice: modelData.device
enabled: !modelData.isUnknownMachineType && modelData.isHostOfGroup
@ -137,11 +125,10 @@ Item
}
checkable: false
selected: ListView.view.currentIndex == model.index
selected: networkPrinterListView.currentIndex == model.index
onClicked:
{
ListView.view.currentIndex = index
}
networkPrinterListView.currentIndex = index
}
}
}