mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-04-30 15:54:32 +08:00

We need to make this a reusable component at some point, I think. This is the first time we're using the QtQuick2 version of ScrollView. Contributes to issue CURA-5876.
102 lines
3.1 KiB
QML
102 lines
3.1 KiB
QML
// Copyright (c) 2018 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 Cura 1.0 as Cura
|
|
|
|
Column
|
|
{
|
|
id: base
|
|
property var outputDevice: null
|
|
height: childrenRect.height + 2 * padding
|
|
spacing: Math.round(UM.Theme.getSize("default_margin").height / 2)
|
|
|
|
function forceModelUpdate()
|
|
{
|
|
// FIXME For now the model should be removed and then created again, otherwise changes in the printer don't automatically update the UI
|
|
configurationList.model = []
|
|
if (outputDevice)
|
|
{
|
|
configurationList.model = outputDevice.uniqueConfigurations
|
|
}
|
|
}
|
|
|
|
ScrollView
|
|
{
|
|
id: container
|
|
width: parent.width
|
|
readonly property int maximumHeight: 350 * screenScaleFactor
|
|
height: Math.round(Math.min(configurationList.height, maximumHeight))
|
|
contentHeight: configurationList.height
|
|
clip: true
|
|
|
|
ScrollBar.vertical.policy: (configurationList.height > maximumHeight) ? ScrollBar.AlwaysOn : ScrollBar.AlwaysOff //The AsNeeded policy also hides it when the cursor is away, and we don't want that.
|
|
ScrollBar.vertical.background: Rectangle
|
|
{
|
|
implicitWidth: UM.Theme.getSize("scrollbar").width
|
|
radius: width / 2
|
|
color: UM.Theme.getColor("scrollbar_background")
|
|
}
|
|
ScrollBar.vertical.contentItem: Rectangle
|
|
{
|
|
implicitWidth: UM.Theme.getSize("scrollbar").width
|
|
radius: width / 2
|
|
color: UM.Theme.getColor(parent.pressed ? "scrollbar_handle_down" : parent.hovered ? "scrollbar_handle_hover" : "scrollbar_handle")
|
|
}
|
|
|
|
ButtonGroup
|
|
{
|
|
buttons: configurationList.children
|
|
}
|
|
|
|
ListView
|
|
{
|
|
id: configurationList
|
|
spacing: Math.round(UM.Theme.getSize("default_margin").height / 2)
|
|
width: container.width - ((height > container.maximumHeight) ? container.ScrollBar.vertical.background.width : 0) //Make room for scroll bar if there is any.
|
|
contentHeight: childrenRect.height
|
|
height: childrenRect.height
|
|
|
|
section.property: "modelData.printerType"
|
|
section.criteria: ViewSection.FullString
|
|
section.delegate: Item
|
|
{
|
|
height: printerTypeLabel.height + UM.Theme.getSize("default_margin").height
|
|
Cura.PrinterTypeLabel
|
|
{
|
|
id: printerTypeLabel
|
|
text: Cura.MachineManager.getAbbreviatedMachineName(section)
|
|
}
|
|
}
|
|
|
|
model: (outputDevice != null) ? outputDevice.uniqueConfigurations : []
|
|
|
|
delegate: ConfigurationItem
|
|
{
|
|
width: parent.width
|
|
configuration: modelData
|
|
}
|
|
}
|
|
}
|
|
|
|
Connections
|
|
{
|
|
target: outputDevice
|
|
onUniqueConfigurationsChanged:
|
|
{
|
|
forceModelUpdate()
|
|
}
|
|
}
|
|
|
|
Connections
|
|
{
|
|
target: Cura.MachineManager
|
|
onOutputDevicesChanged:
|
|
{
|
|
forceModelUpdate()
|
|
}
|
|
}
|
|
} |