mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-13 09:47:50 -06:00
Remove extra ScrollView and customise ListView instead
Contributes to issue CURA-8686.
This commit is contained in:
parent
5b76cf5689
commit
f1db69a36a
1 changed files with 67 additions and 80 deletions
|
@ -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.
|
// Cura is released under the terms of the LGPLv3 or higher.
|
||||||
|
|
||||||
import QtQuick 2.10
|
import QtQuick 2.10
|
||||||
|
@ -17,7 +17,7 @@ Item
|
||||||
id: base
|
id: base
|
||||||
height: networkPrinterInfo.height + controlsRectangle.height
|
height: networkPrinterInfo.height + controlsRectangle.height
|
||||||
|
|
||||||
property alias maxItemCountAtOnce: networkPrinterScrollView.maxItemCountAtOnce
|
property alias maxItemCountAtOnce: networkPrinterListView.maxItemCountAtOnce
|
||||||
property var currentItem: (networkPrinterListView.currentIndex >= 0)
|
property var currentItem: (networkPrinterListView.currentIndex >= 0)
|
||||||
? networkPrinterListView.model[networkPrinterListView.currentIndex]
|
? networkPrinterListView.model[networkPrinterListView.currentIndex]
|
||||||
: null
|
: null
|
||||||
|
@ -29,7 +29,7 @@ Item
|
||||||
Item
|
Item
|
||||||
{
|
{
|
||||||
id: networkPrinterInfo
|
id: networkPrinterInfo
|
||||||
height: networkPrinterScrollView.visible ? networkPrinterScrollView.height : noPrinterLabel.height
|
height: networkPrinterListView.visible ? networkPrinterListView.height : noPrinterLabel.height
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
anchors.top: parent.top
|
anchors.top: parent.top
|
||||||
|
@ -44,104 +44,91 @@ Item
|
||||||
visible: networkPrinterListView.count == 0 // Do not show if there are discovered devices.
|
visible: networkPrinterListView.count == 0 // Do not show if there are discovered devices.
|
||||||
}
|
}
|
||||||
|
|
||||||
ScrollView
|
ListView
|
||||||
{
|
{
|
||||||
id: networkPrinterScrollView
|
id: networkPrinterListView
|
||||||
anchors.top: parent.top
|
anchors.top: parent.top
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
anchors.right: parent.right
|
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)
|
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
|
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.left: parent.left
|
||||||
anchors.fill: parent
|
anchors.leftMargin: UM.Theme.getSize("default_margin").width
|
||||||
model: contentLoader.enabled ? CuraApplication.getDiscoveredPrintersModel().discoveredPrinters: undefined
|
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"
|
Component.onCompleted:
|
||||||
section.criteria: ViewSection.FullString
|
{
|
||||||
section.delegate: sectionHeading
|
var toSelectIndex = -1
|
||||||
boundsBehavior: Flickable.StopAtBounds
|
// Select the first one that's not "unknown" and is the host a group by default.
|
||||||
flickDeceleration: 20000 // To prevent the flicking behavior.
|
for (var i = 0; i < count; i++)
|
||||||
cacheBuffer: 1000000 // Set a large cache to effectively just cache every list item.
|
|
||||||
|
|
||||||
Component.onCompleted:
|
|
||||||
{
|
{
|
||||||
var toSelectIndex = -1
|
if (!model[i].isUnknownMachineType && model[i].isHostOfGroup)
|
||||||
// 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)
|
toSelectIndex = i
|
||||||
{
|
break
|
||||||
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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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
|
delegate: Cura.MachineSelectorButton
|
||||||
{
|
{
|
||||||
anchors.left: parent.left
|
text: modelData.device.name
|
||||||
anchors.leftMargin: UM.Theme.getSize("default_margin").width
|
|
||||||
height: UM.Theme.getSize("setting_control").height
|
width: networkPrinterListView.width - networkPrinterScrollBar.width
|
||||||
text: section
|
outputDevice: modelData.device
|
||||||
color: UM.Theme.getColor("small_button_text")
|
|
||||||
}
|
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
|
networkPrinterListView.currentIndex = index
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue