Clean up Add Machine Wizard and use the new MachineDefintionsModel

This commit is contained in:
Arjen Hiemstra 2015-08-25 18:14:48 +02:00
parent b9a306865e
commit 9a88176f6f
2 changed files with 161 additions and 206 deletions

View file

@ -6,22 +6,27 @@ import QtQuick.Controls 1.1
import QtQuick.Layouts 1.1 import QtQuick.Layouts 1.1
import QtQuick.Window 2.1 import QtQuick.Window 2.1
import UM 1.0 as UM import UM 1.1 as UM
import Cura 1.0 as Cura import Cura 1.0 as Cura
import "WizardPages"
UM.Wizard UM.Wizard
{ {
//: Add Printer dialog title id: base;
wizardTitle: qsTr("Add Printer")
wizardPages: [ title: catalog.i18nc("@title", "Add Printer")
{
title: "Add Printer",
page: UM.Resources.getPath(Cura.ResourceTypes.QmlFiles, "WizardPages/AddMachine.qml")
}
]
// This part is optional // This part is optional
// This part checks whether there is a printer -> if not: some of the functions (delete for example) are disabled // This part checks whether there is a printer -> if not: some of the functions (delete for example) are disabled
property bool printer: true firstRun: false
firstRun: printer ? false : true
Component.onCompleted: {
base.appendPage(UM.Resources.getPath(Cura.ResourceTypes.QmlFiles, "WizardPages/AddMachine.qml"), catalog.i18nc("@title", "Add Printer"));
base.currentPage = 0;
}
Item {
UM.I18nCatalog { id: catalog; name: "cura"; }
}
} }

View file

@ -7,44 +7,34 @@ import QtQuick.Layouts 1.1
import QtQuick.Window 2.1 import QtQuick.Window 2.1
import QtQuick.Controls.Styles 1.1 import QtQuick.Controls.Styles 1.1
import UM 1.0 as UM import UM 1.1 as UM
import Cura 1.0 as Cura
import ".." import ".."
ColumnLayout Item
{ {
id: wizardPage id: base
property string title
property int pageWidth
property int pageHeight
property var manufacturers: wizardPage.lineManufacturers()
property int manufacturerIndex: 0
SystemPalette{id: palette} property string activeManufacturer: "Ultimaker";
signal reloadModel(var newModel)
width: wizardPage.pageWidth property variant wizard;
height: wizardPage.pageHeight
Connections Connections
{ {
target: elementRoot target: base.wizard
onNextClicked: //You can add functions here that get triggered when the final button is clicked in the wizard-element onNextClicked: //You can add functions here that get triggered when the final button is clicked in the wizard-element
{ {
saveMachine() saveMachine()
} }
} onBackClicked:
function lineManufacturers(manufacturer)
{ {
var manufacturers = [] var old_page_count = base.wizard.getPageCount()
for (var i = 0; i < UM.Models.availableMachinesModel.rowCount(); i++) // Delete old pages (if any)
for (var i = old_page_count - 1; i > 0; i--)
{ {
if (UM.Models.availableMachinesModel.getItem(i).manufacturer != manufacturers[manufacturers.length - 1]) base.wizard.removePage(i)
{
manufacturers.push(UM.Models.availableMachinesModel.getItem(i).manufacturer)
} }
} }
return manufacturers
} }
Label Label
@ -52,7 +42,7 @@ ColumnLayout
id: title id: title
anchors.left: parent.left anchors.left: parent.left
anchors.top: parent.top anchors.top: parent.top
text: parent.title text: catalog.i18nc("@title", "Add Printer")
font.pointSize: 18; font.pointSize: 18;
} }
@ -61,126 +51,89 @@ ColumnLayout
id: subTitle id: subTitle
anchors.left: parent.left anchors.left: parent.left
anchors.top: title.bottom anchors.top: title.bottom
//: Add Printer wizard page description text: catalog.i18nc("@label", "Please select the type of printer:");
text: qsTr("Please select the type of printer:");
} }
ScrollView ScrollView
{ {
id: machinesHolder id: machinesHolder
anchors.left: parent.left
anchors.top: subTitle.bottom
implicitWidth: wizardPage.width- UM.Theme.sizes.default_margin.width
implicitHeight: wizardPage.height - subTitle.height - title.height - (machineNameHolder.height * 2)
Component anchors{
{ left: parent.left;
id: machineDelegate top: subTitle.bottom;
ColumnLayout right: parent.right;
{ bottom: machineNameHolder.top;
id: machineLayout
spacing: 0
anchors.left: parent.left
anchors.leftMargin: UM.Theme.sizes.standard_list_lineheight.width
function showManufacturer()
{
if (model.manufacturer == UM.Models.availableMachinesModel.getItem(index - 1).manufacturer){
return false
} }
else{
return true ListView
}
}
height:
{ {
if (machineLayout.showManufacturer() & wizardPage.manufacturers[wizardPage.manufacturerIndex] == model.manufacturer) id: machineList
return UM.Theme.sizes.standard_list_lineheight.height * 2
if (wizardPage.manufacturers[wizardPage.manufacturerIndex] == model.manufacturer | machineLayout.showManufacturer()) model: UM.MachineDefinitionsModel { id: machineDefinitionsModel; showVariants: false; }
return UM.Theme.sizes.standard_list_lineheight.height * 1 focus: true
section.property: "manufacturer"
section.delegate: Button {
text: {
if (base,activeManufacturer == section)
return section + " ▼"
else else
return 0 return section + " ►"
} }
Behavior on height
{ style: ButtonStyle {
NumberAnimation { target: machineLayout; property: "height"; duration: 200} background: Rectangle {
}
Button
{
id: manufacturer
property color backgroundColor: "transparent"
height: UM.Theme.sizes.standard_list_lineheight.height
visible: machineLayout.showManufacturer()
anchors.top: machineLayout.top
anchors.topMargin: 0
text:
{
if (wizardPage.manufacturers[wizardPage.manufacturerIndex] == model.manufacturer)
return model.manufacturer + " ▼"
else
return model.manufacturer + " ►"
}
style: ButtonStyle
{
background: Rectangle
{
id: manufacturerBackground id: manufacturerBackground
opacity: 0.3 opacity: 0.3
border.width: 0 border.width: 0
color: manufacturer.backgroundColor color: control.hovered ? palette.light : "transparent";
height: UM.Theme.sizes.standard_list_lineheight.height height: UM.Theme.sizes.standard_list_lineheight.height
} }
label: Text label: Text {
{
renderType: Text.NativeRendering
horizontalAlignment: Text.AlignLeft horizontalAlignment: Text.AlignLeft
text: control.text text: control.text
color: palette.windowText color: palette.windowText
font.bold: true font.bold: true
} }
} }
MouseArea
{ onClicked: {
id: mousearea base.activeManufacturer = section;
hoverEnabled: true machineList.currentIndex = machineList.model.find("manufacturer", section)
anchors.fill: parent
onEntered: manufacturer.backgroundColor = palette.light
onExited: manufacturer.backgroundColor = "transparent"
onClicked:
{
wizardPage.manufacturerIndex = wizardPage.manufacturers.indexOf(model.manufacturer)
machineList.currentIndex = index
}
} }
} }
RadioButton delegate: RadioButton {
{
id: machineButton id: machineButton
opacity: wizardPage.manufacturers[wizardPage.manufacturerIndex] == model.manufacturer ? 1 : 0
height: wizardPage.manufacturers[wizardPage.manufacturerIndex] == model.manufacturer ? UM.Theme.sizes.standard_list_lineheight.height : 0
anchors.top: parent.top
anchors.topMargin: machineLayout.showManufacturer() ? manufacturer.height - 5 : 0
anchors.left: parent.left anchors.left: parent.left
anchors.leftMargin: UM.Theme.sizes.standard_list_lineheight.width anchors.leftMargin: UM.Theme.sizes.standard_list_lineheight.width
checked: machineList.currentIndex == index ? true : false
opacity: 1;
height: UM.Theme.sizes.standard_list_lineheight.height;
checked: ListView.isCurrentItem;
exclusiveGroup: printerGroup; exclusiveGroup: printerGroup;
text: model.name text: model.name
onClicked: machineList.currentIndex = index;
function getAnimationTime(time) onClicked: {
{ ListView.view.currentIndex = index;
if (machineButton.opacity == 0) if(model.pages.length > 0) {
return time base.wizard.nextAvailable = true;
else } else {
return 0 base.wizard.nextAvailable = false;
} }
}
Label Label
{ {
id: author id: author
visible: model.author != "Ultimaker" ? true : false // visible: model.author != "Ultimaker" ? true : false
height: wizardPage.manufacturers[wizardPage.manufacturerIndex] == model.manufacturer ? UM.Theme.sizes.standard_list_lineheight.height : 0
//: Printer profile caption meaning: this profile is supported by the community //: Printer profile caption meaning: this profile is supported by the community
text: qsTr("community supported profile"); // text: qsTr("community supported profile");
opacity: wizardPage.manufacturers[wizardPage.manufacturerIndex] == model.manufacturer ? 1 : 0 text: model.author;
anchors.left: machineButton.right anchors.left: machineButton.right
anchors.leftMargin: UM.Theme.sizes.standard_list_lineheight.height/2 anchors.leftMargin: UM.Theme.sizes.standard_list_lineheight.height/2
anchors.verticalCenter: machineButton.verticalCenter anchors.verticalCenter: machineButton.verticalCenter
@ -188,50 +141,43 @@ ColumnLayout
font: UM.Theme.fonts.caption; font: UM.Theme.fonts.caption;
color: palette.mid color: palette.mid
} }
Behavior on opacity
{ states: State {
SequentialAnimation name: "collapsed";
{ when: base.activeManufacturer != model.manufacturer;
PauseAnimation { duration: machineButton.getAnimationTime(100) }
NumberAnimation { properties:"opacity"; duration: machineButton.getAnimationTime(200) } PropertyChanges { target: machineButton; opacity: 0; height: 0; }
}
}
} }
transitions: [
Transition {
to: "collapsed";
SequentialAnimation {
NumberAnimation { property: "opacity"; duration: 75; }
NumberAnimation { property: "height"; duration: 75; }
}
},
Transition {
from: "collapsed";
SequentialAnimation {
NumberAnimation { property: "height"; duration: 75; }
NumberAnimation { property: "opacity"; duration: 75; }
} }
} }
]
ListView
{
id: machineList
property int currentIndex: 0
property int otherMachinesIndex:
{
for (var i = 0; i < UM.Models.availableMachinesModel.rowCount(); i++)
{
if (UM.Models.availableMachinesModel.getItem(i).manufacturer != "Ultimaker")
{
return i
} }
} }
} }
anchors.fill: parent
model: UM.Models.availableMachinesModel
delegate: machineDelegate
focus: true
}
}
Item Item
{ {
id: machineNameHolder id: machineNameHolder
height: childrenRect.height height: childrenRect.height
anchors.top: machinesHolder.bottom anchors.bottom: parent.bottom;
Label Label
{ {
id: insertNameLabel id: insertNameLabel
//: Add Printer wizard field label text: catalog.i18nc("@label", "Printer Name:");
text: qsTr("Printer Name:");
} }
TextField TextField
{ {
@ -242,39 +188,43 @@ ColumnLayout
} }
} }
ExclusiveGroup { id: printerGroup; }
function saveMachine() function saveMachine()
{ {
if(machineList.currentIndex != -1) if(machineList.currentIndex != -1)
{ {
UM.Models.availableMachinesModel.createMachine(machineList.currentIndex, machineName.text) var item = machineList.model.getItem(machineList.currentIndex);
var pages = UM.Models.availableMachinesModel.getItem(machineList.currentIndex).pages machineList.model.createInstance(machineName.text, item.id)
var old_page_count = elementRoot.getPageCount()
for(var i = 0; i < UM.Models.count; i++) var pages = machineList.model.getItem(machineList.currentIndex).pages
{
print(UM.Models.getItem(i)) console.log(pages)
} console.log(pages.length)
// Delete old pages (if any)
for (var i = old_page_count - 1; i > 0; i--)
{
elementRoot.removePage(i)
elementRoot.currentPage = 0
}
// Insert new pages (if any) // Insert new pages (if any)
for(var i = 0; i < pages.count; i++) for(var i = 0; i < pages.length; i++)
{ {
elementRoot.insertPage(pages.getItem(i).page + ".qml",pages.getItem(i).title,i + 1) console.log(pages[i])
switch(pages[i]) {
case "SelectUpgradedParts":
base.wizard.appendPage(UM.Resources.getPath(Cura.ResourceTypes.QmlFiles, "WizardPages/SelectUpgradedParts.qml"), catalog.i18nc("@title", "Select Upgraded Parts"));
break;
case "UpgradeFirmware":
base.wizard.appendPage(UM.Resources.getPath(Cura.ResourceTypes.QmlFiles, "WizardPages/UpgradeFirmware.qml"), catalog.i18nc("@title", "Upgrade Firmware"));
break;
case "UltimakerCheckup":
base.wizard.appendPage(UM.Resources.getPath(Cura.ResourceTypes.QmlFiles, "WizardPages/UltimakerCheckup.qml"), catalog.i18nc("@title", "Check Printer"));
break;
case "BedLeveling":
base.wizard.appendPage(UM.Resources.getPath(Cura.ResourceTypes.QmlFiles, "WizardPages/Bedleveling.qml"), catalog.i18nc("@title", "Bed Levelling"));
break;
default:
break;
}
}
}
} }
// Hack to ensure the current page is set correctly ExclusiveGroup { id: printerGroup; }
if(old_page_count == 1) UM.I18nCatalog { id: catalog; name: "cura"; }
{ SystemPalette { id: palette }
elementRoot.currentPage += 1
}
}
}
} }