WIP: Complete add network and local printer flow

This commit is contained in:
Lipu Fei 2019-03-13 10:21:01 +01:00
parent cc35eb0195
commit 5fa2c72b0d
5 changed files with 51 additions and 13 deletions

View file

@ -16,7 +16,9 @@ ScrollView
{
id: base
property var currentItem: null
property var currentItem: (machineList.currentIndex >= 0)
? machineList.model.getItem(machineList.currentIndex)
: null
property string currentSection: preferredCategory
property string preferredCategory: "Ultimaker"
@ -36,7 +38,6 @@ ScrollView
var item = machineList.model.getItem(i)
if (item.section == base.currentSection)
{
base.currentItem = item
machineList.currentIndex = i
break
}

View file

@ -21,7 +21,9 @@ Item
height: networkPrinterScrollView.height + controlsRectangle.height
property alias maxItemCountAtOnce: networkPrinterScrollView.maxItemCountAtOnce
property var selectedItem: networkPrinterListView.model[networkPrinterListView.currentIndex]
property var currentItem: (networkPrinterListView.currentIndex >= 0)
? networkPrinterListView.model[networkPrinterListView.currentIndex]
: null
signal refreshButtonClicked()
signal addByIpButtonClicked()

View file

@ -38,6 +38,7 @@ Item
anchors.margins: 20
title: catalog.i18nc("@label", "Add a network printer")
contentShown: true // by default expand the network printer list
onClicked:
{
@ -97,7 +98,7 @@ Item
{
id: localPrinterListComponent
AddPrinterScrollView
AddLocalPrinterScrollView
{
id: localPrinterView
@ -112,10 +113,42 @@ Item
anchors.right: parent.right
anchors.bottom: parent.bottom
anchors.margins: 40
enabled: true // TODO
enabled:
{
// If the network printer dropdown is expanded, make sure that there is a selected item
if (addNetworkPrinterDropDown.contentShown)
{
return addNetworkPrinterDropDown.contentItem.currentItem != null
}
else
{
return addLocalPrinterDropDown.contentItem.currentItem != null
}
}
text: catalog.i18nc("@button", "Next")
width: 140
fixedWidthMode: true
onClicked: base.showNextPage()
onClicked:
{
// Create a network printer or a local printer according to the selection
if (addNetworkPrinterDropDown.contentShown)
{
// Create a network printer
const networkPrinterItem = addNetworkPrinterDropDown.contentItem.currentItem
CuraApplication.getDiscoveredPrinterModel().createMachineFromDiscoveredPrinter(networkPrinterItem)
}
else
{
// Create a local printer
const localPrinterItem = addLocalPrinterDropDown.contentItem.currentItem
Cura.MachineManager.addMachine(localPrinterItem.id)
}
// TODO: implement machine actions
// If we have created a machine, go to the last page, which is the "cloud" page.
base.gotoPage("cloud")
}
}
}

View file

@ -43,10 +43,7 @@ Cura.RoundedRectangle
onEntered: base.hovered = true
onExited: base.hovered = false
onClicked: {
base.contentShown = !base.contentShown
base.clicked()
}
onClicked: base.clicked()
}
Label

View file

@ -25,16 +25,21 @@ Item
height: header.contentShown ? (header.height + contentRectangle.height + 30) : header.height
property var contentComponent: null
property alias contentItem: contentLoader.item
property alias title: header.title
property alias contentShown: header.contentShown
property bool contentShown: false
signal clicked()
Connections
{
target: header
onClicked: base.clicked()
onClicked:
{
base.contentShown = !base.contentShown
clicked()
}
}
DropDownHeader
@ -45,7 +50,7 @@ Item
anchors.right: parent.right
height: UM.Theme.getSize("expandable_component_content_header").height
rightIconSource: contentShown ? UM.Theme.getIcon("arrow_bottom") : UM.Theme.getIcon("arrow_right")
contentShown: base.contentShown
}
Cura.RoundedRectangle