Allow the printers selection list to reize

CURA-10896
This commit is contained in:
Erwan MATHIEU 2023-08-30 13:17:20 +02:00
parent 6075a5b583
commit 742e11327e
3 changed files with 72 additions and 70 deletions

View file

@ -3,6 +3,7 @@
import QtQuick 2.10 import QtQuick 2.10
import QtQuick.Controls 2.3 import QtQuick.Controls 2.3
import QtQuick.Layouts 2.3
import UM 1.5 as UM import UM 1.5 as UM
import Cura 1.1 as Cura import Cura 1.1 as Cura
@ -15,9 +16,7 @@ import Cura 1.1 as Cura
Item Item
{ {
id: base id: base
height: networkPrinterInfo.height + controlsRectangle.height
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,35 +28,32 @@ Item
Item Item
{ {
id: networkPrinterInfo id: networkPrinterInfo
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
anchors.bottom: separator.top
UM.Label UM.Label
{ {
id: noPrinterLabel id: noPrinterLabel
height: UM.Theme.getSize("setting_control").height + UM.Theme.getSize("default_margin").height height: UM.Theme.getSize("setting_control").height + UM.Theme.getSize("default_margin").height
anchors.left: parent.left anchors.fill: parent
anchors.leftMargin: UM.Theme.getSize("default_margin").width anchors.margins: UM.Theme.getSize("default_margin").width
text: catalog.i18nc("@label", "There is no printer found over your network.") text: catalog.i18nc("@label", "There is no printer found over your network.")
visible: networkPrinterListView.count == 0 // Do not show if there are discovered devices. visible: networkPrinterListView.count == 0 // Do not show if there are discovered devices.
verticalAlignment: Text.AlignTop
} }
ListView ListView
{ {
id: networkPrinterListView id: networkPrinterListView
anchors.top: parent.top anchors.fill: parent
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 ScrollBar.vertical: UM.ScrollBar
{ {
id: networkPrinterScrollBar id: networkPrinterScrollBar
} }
clip: true 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
model: contentLoader.enabled ? CuraApplication.getDiscoveredPrintersModel().discoveredPrinters: undefined model: contentLoader.enabled ? CuraApplication.getDiscoveredPrintersModel().discoveredPrinters: undefined
@ -138,7 +134,7 @@ Item
{ {
id: separator id: separator
anchors.left: parent.left anchors.left: parent.left
anchors.top: networkPrinterInfo.bottom anchors.bottom: controlsRectangle.top
anchors.right: parent.right anchors.right: parent.right
height: UM.Theme.getSize("default_lining").height height: UM.Theme.getSize("default_lining").height
color: UM.Theme.getColor("lining") color: UM.Theme.getColor("lining")
@ -149,7 +145,7 @@ Item
id: controlsRectangle id: controlsRectangle
anchors.left: parent.left anchors.left: parent.left
anchors.right: parent.right anchors.right: parent.right
anchors.top: separator.bottom anchors.bottom: parent.bottom
height: UM.Theme.getSize("message_action_button").height + UM.Theme.getSize("default_margin").height height: UM.Theme.getSize("message_action_button").height + UM.Theme.getSize("default_margin").height

View file

@ -3,6 +3,7 @@
import QtQuick 2.10 import QtQuick 2.10
import QtQuick.Controls 2.3 import QtQuick.Controls 2.3
import QtQuick.Layouts 2.3
import UM 1.5 as UM import UM 1.5 as UM
import Cura 1.1 as Cura import Cura 1.1 as Cura
@ -17,14 +18,23 @@ Item
property var goToUltimakerPrinter property var goToUltimakerPrinter
ColumnLayout
{
anchors.top: parent.top
anchors.topMargin: UM.Theme.getSize("wide_margin").height
anchors.bottom: backButton.top
anchors.bottomMargin: UM.Theme.getSize("default_margin").height
anchors.left: parent.left
anchors.right: parent.right
spacing: UM.Theme.getSize("default_margin").height
DropDownWidget DropDownWidget
{ {
id: addNetworkPrinterDropDown id: addNetworkPrinterDropDown
anchors.top: parent.top Layout.fillWidth: true
anchors.left: parent.left Layout.fillHeight: contentShown
anchors.right: parent.right
anchors.topMargin: UM.Theme.getSize("wide_margin").height
title: catalog.i18nc("@label", "Add a networked printer") title: catalog.i18nc("@label", "Add a networked printer")
contentShown: true // by default expand the network printer list contentShown: true // by default expand the network printer list
@ -42,8 +52,6 @@ Item
{ {
id: networkPrinterScrollView id: networkPrinterScrollView
maxItemCountAtOnce: 9 // show at max 9 items at once, otherwise you need to scroll.
onRefreshButtonClicked: onRefreshButtonClicked:
{ {
UM.OutputDeviceManager.startDiscovery() UM.OutputDeviceManager.startDiscovery()
@ -70,10 +78,8 @@ Item
{ {
id: addLocalPrinterDropDown id: addLocalPrinterDropDown
anchors.top: addNetworkPrinterDropDown.bottom Layout.fillWidth: true
anchors.left: parent.left Layout.fillHeight: contentShown
anchors.right: parent.right
anchors.topMargin: UM.Theme.getSize("default_margin").height
title: catalog.i18nc("@label", "Add a non-networked printer") title: catalog.i18nc("@label", "Add a non-networked printer")
@ -89,7 +95,7 @@ Item
AddLocalPrinterScrollView AddLocalPrinterScrollView
{ {
id: localPrinterView id: localPrinterView
height: backButton.y - addLocalPrinterDropDown.y - UM.Theme.getSize("expandable_component_content_header").height - UM.Theme.getSize("default_margin").height }
} }
} }
} }

View file

@ -22,7 +22,7 @@ Item
id: base id: base
implicitWidth: 200 * screenScaleFactor implicitWidth: 200 * screenScaleFactor
height: header.contentShown ? (header.height + contentRectangle.height) : header.height implicitHeight: contentShown ? (header.height + contentRectangle.implicitHeight) : header.height
property var contentComponent: null property var contentComponent: null
property alias contentItem: contentLoader.item property alias contentItem: contentLoader.item
@ -56,12 +56,14 @@ Item
Cura.RoundedRectangle Cura.RoundedRectangle
{ {
id: contentRectangle id: contentRectangle
anchors.top: header.bottom
// Move up a bit (exactly the width of the border) to avoid double line // Move up a bit (exactly the width of the border) to avoid double line
y: header.height - UM.Theme.getSize("default_lining").width anchors.topMargin: -UM.Theme.getSize("default_lining").width
anchors.left: header.left anchors.left: header.left
anchors.right: header.right anchors.right: header.right
anchors.bottom: parent.bottom
// Add 2x lining, because it needs a bit of space on the top and the bottom. // Add 2x lining, because it needs a bit of space on the top and the bottom.
height: contentLoader.item ? contentLoader.item.height + 2 * UM.Theme.getSize("thick_lining").height : 0 anchors.bottomMargin: UM.Theme.getSize("thick_lining").height
border.width: UM.Theme.getSize("default_lining").width border.width: UM.Theme.getSize("default_lining").width
border.color: UM.Theme.getColor("lining") border.color: UM.Theme.getColor("lining")
@ -73,9 +75,7 @@ Item
Loader Loader
{ {
id: contentLoader id: contentLoader
anchors.top: parent.top anchors.fill: parent
anchors.left: parent.left
anchors.right: parent.right
// Keep a small margin with the Rectangle container so its content will not overlap with the Rectangle // Keep a small margin with the Rectangle container so its content will not overlap with the Rectangle
// border. // border.
anchors.margins: UM.Theme.getSize("default_lining").width anchors.margins: UM.Theme.getSize("default_lining").width