Add printer name textfield into AddLocalPrinter

CURA-6435
This commit is contained in:
Lipu Fei 2019-04-05 09:08:07 +02:00
parent b68b154e59
commit 3fefb47426
2 changed files with 157 additions and 93 deletions

View file

@ -12,9 +12,12 @@ import Cura 1.0 as Cura
// This is the scroll view widget for adding a (local) printer. This scroll view shows a list view with printers // This is the scroll view widget for adding a (local) printer. This scroll view shows a list view with printers
// categorized into 3 categories: "Ultimaker", "Custom", and "Other". // categorized into 3 categories: "Ultimaker", "Custom", and "Other".
// //
ScrollView Item
{ {
UM.I18nCatalog { id: catalog; name: "cura" }
id: base id: base
height: childrenRect.height
// The currently selected machine item in the local machine list. // The currently selected machine item in the local machine list.
property var currentItem: (machineList.currentIndex >= 0) property var currentItem: (machineList.currentIndex >= 0)
@ -25,12 +28,15 @@ ScrollView
// By default (when this list shows up) we always expand the "Ultimaker" section. // By default (when this list shows up) we always expand the "Ultimaker" section.
property string preferredCategory: "Ultimaker" property string preferredCategory: "Ultimaker"
ScrollBar.horizontal.policy: ScrollBar.AlwaysOff
ScrollBar.vertical.policy: ScrollBar.AsNeeded
property int maxItemCountAtOnce: 10 // show at max 10 items at once, otherwise you need to scroll. property int maxItemCountAtOnce: 10 // show at max 10 items at once, otherwise you need to scroll.
height: maxItemCountAtOnce * UM.Theme.getSize("action_button").height
clip: true // User-editable printer name
property alias printerName: printerNameTextField.text
onCurrentItemChanged:
{
printerName = currentItem == null ? "" : currentItem.name
}
function updateCurrentItemUponSectionChange() function updateCurrentItemUponSectionChange()
{ {
@ -51,6 +57,29 @@ ScrollView
updateCurrentItemUponSectionChange() updateCurrentItemUponSectionChange()
} }
Item
{
id: localPrinterSelectionItem
anchors.left: parent.left
anchors.right: parent.right
anchors.top: parent.top
height: childrenRect.height
// ScrollView + ListView for selecting a local printer to add
ScrollView
{
id: scrollView
anchors.left: parent.left
anchors.right: parent.right
anchors.top: parent.top
height: maxItemCountAtOnce * UM.Theme.getSize("action_button").height
ScrollBar.horizontal.policy: ScrollBar.AlwaysOff
ScrollBar.vertical.policy: ScrollBar.AsNeeded
clip: true
ListView ListView
{ {
id: machineList id: machineList
@ -138,16 +167,50 @@ ScrollView
height: visible ? UM.Theme.getSize("standard_list_lineheight").height : 0 height: visible ? UM.Theme.getSize("standard_list_lineheight").height : 0
checked: ListView.view.currentIndex == index checked: ListView.view.currentIndex == index
onCheckedChanged:
{
if(checked)
{
machineList.currentIndex = index
}
}
text: name text: name
visible: base.currentSection == section visible: base.currentSection == section
onClicked: ListView.view.currentIndex = index onClicked: ListView.view.currentIndex = index
} }
} }
}
}
// Horizontal line
Rectangle
{
id: horizontalLine
anchors.top: localPrinterSelectionItem.bottom
anchors.left: parent.left
anchors.right: parent.right
height: UM.Theme.getSize("default_lining").height
color: UM.Theme.getColor("lining")
}
// User-editable printer name row
Row
{
anchors.top: horizontalLine.bottom
anchors.left: parent.left
anchors.right: parent.right
anchors.topMargin: UM.Theme.getSize("default_lining").height
anchors.leftMargin: UM.Theme.getSize("default_margin").width
spacing: UM.Theme.getSize("default_margin").width
Label
{
text: catalog.i18nc("@label", "Printer Name")
anchors.verticalCenter: parent.verticalCenter
font: UM.Theme.getFont("medium")
verticalAlignment: Text.AlignVCenter
renderType: Text.NativeRendering
}
Cura.TextField
{
id: printerNameTextField
anchors.verticalCenter: parent.verticalCenter
width: (parent.width / 2) | 0
}
}
} }

View file

@ -139,7 +139,8 @@ Item
{ {
// Create a local printer // Create a local printer
const localPrinterItem = addLocalPrinterDropDown.contentItem.currentItem const localPrinterItem = addLocalPrinterDropDown.contentItem.currentItem
Cura.MachineManager.addMachine(localPrinterItem.id) const printerName = addLocalPrinterDropDown.contentItem.printerName
Cura.MachineManager.addMachine(localPrinterItem.id, printerName)
base.showNextPage() base.showNextPage()
} }