Use re-useable scrollbar and remove ScrollView

The machine selector has the scroll view inside of the listview. It just needs to use our new scrollbar element instead of the default.

Contributes to issue CURA-8686.
This commit is contained in:
Ghostkeeper 2022-01-19 14:32:12 +01:00
parent 7e1b92953c
commit c57126fb00
No known key found for this signature in database
GPG key ID: D2A8871EE34EC59A
2 changed files with 22 additions and 33 deletions

View file

@ -1,10 +1,10 @@
// Copyright (c) 2018 Ultimaker B.V.
// Copyright (c) 2022 Ultimaker B.V.
// Cura is released under the terms of the LGPLv3 or higher.
import QtQuick 2.7
import QtQuick.Controls 2.3
import UM 1.2 as UM
import UM 1.5 as UM
import Cura 1.1 as Cura
Cura.ExpandablePopup
@ -193,42 +193,27 @@ Cura.ExpandablePopup
{
id: popup
width: UM.Theme.getSize("machine_selector_widget_content").width
height: Math.min(machineSelectorList.contentHeight + separator.height + buttonRow.height, UM.Theme.getSize("machine_selector_widget_content").height) //Maximum height is the theme entry.
ScrollView
MachineSelectorList
{
id: scroll
width: parent.width
clip: true
leftPadding: UM.Theme.getSize("default_lining").width
rightPadding: UM.Theme.getSize("default_lining").width
MachineSelectorList
id: machineSelectorList
anchors
{
id: machineSelectorList
// Can't use parent.width since the parent is the flickable component and not the ScrollView
width: scroll.width - scroll.leftPadding - scroll.rightPadding
property real maximumHeight: UM.Theme.getSize("machine_selector_widget_content").height - buttonRow.height
// We use an extra property here, since we only want to to be informed about the content size changes.
onContentHeightChanged:
{
scroll.height = Math.min(contentHeight, maximumHeight)
popup.height = scroll.height + buttonRow.height
}
Component.onCompleted:
{
scroll.height = Math.min(contentHeight, maximumHeight)
popup.height = scroll.height + buttonRow.height
}
left: parent.left
leftMargin: UM.Theme.getSize("default_lining").width
right: parent.right
rightMargin: UM.Theme.getSize("default_lining").width
top: parent.top
bottom: separator.top
}
clip: true
}
Rectangle
{
id: separator
anchors.top: scroll.bottom
anchors.bottom: buttonRow.top
width: parent.width
height: UM.Theme.getSize("default_lining").height
color: UM.Theme.getColor("lining")
@ -238,8 +223,7 @@ Cura.ExpandablePopup
{
id: buttonRow
// The separator is inside the buttonRow. This is to avoid some weird behaviours with the scroll bar.
anchors.top: separator.top
anchors.bottom: parent.bottom
anchors.horizontalCenter: parent.horizontalCenter
padding: UM.Theme.getSize("default_margin").width
spacing: UM.Theme.getSize("default_margin").width

View file

@ -14,10 +14,15 @@ ListView
section.property: "hasRemoteConnection"
property real contentHeight: childrenRect.height
ScrollBar.vertical: UM.ScrollBar
{
id: scrollBar
}
section.delegate: UM.Label
{
text: section == "true" ? catalog.i18nc("@label", "Connected printers") : catalog.i18nc("@label", "Preset printers")
width: parent.width
width: parent.width - scrollBar.width
height: UM.Theme.getSize("action_button").height
leftPadding: UM.Theme.getSize("default_margin").width
font: UM.Theme.getFont("medium")
@ -27,7 +32,7 @@ ListView
delegate: MachineSelectorButton
{
text: model.name ? model.name : ""
width: listView.width
width: listView.width - scrollBar.width
outputDevice: Cura.MachineManager.printerOutputDevices.length >= 1 ? Cura.MachineManager.printerOutputDevices[0] : null
checked: Cura.MachineManager.activeMachine ? Cura.MachineManager.activeMachine.id == model.id : false