Refactor workspace sections into separate qml file.

Refactor an existing hack to force trigger the onIndexChanged functions of the comboboxes.

CURA-9424
This commit is contained in:
Joey de l'Arago 2022-11-02 14:17:05 +01:00
parent f72c980c20
commit d12b59ec0f
2 changed files with 222 additions and 244 deletions

View file

@ -1,4 +1,4 @@
// Copyright (c) 2020 Ultimaker B.V. // Copyright (c) 2022 Ultimaker B.V.
// Cura is released under the terms of the LGPLv3 or higher. // Cura is released under the terms of the LGPLv3 or higher.
import QtQuick 2.10 import QtQuick 2.10
@ -28,9 +28,12 @@ UM.Dialog
{ {
if (visible) if (visible)
{ {
machineResolveComboBox.currentIndex = 0 // Force relead the comboboxes
qualityChangesResolveComboBox.currentIndex = 0 // Since this dialog is only created once the first time you open it, these comboxes need to be reloaded
materialResolveComboBox.currentIndex = 0 // each time it is shown after the first time so that the indexes will update correctly.
materialSection.reloadValues()
profileSection.reloadValues()
printerSection.reloadValues()
} }
} }
@ -89,111 +92,15 @@ UM.Dialog
} }
} }
Item WorkspaceSection
{ {
width: parent.width id: printerSection
height: childrenRect.height title: catalog.i18nc("@action:label", "Printer settings")
anchors.leftMargin: UM.Theme.getSize("default_margin") iconSource: UM.Theme.getIcon("Printer")
content: Column
UM.TooltipArea
{ {
id: machineResolveStrategyTooltip
anchors.top: parent.top
anchors.right: parent.right
width: (parent.width / 3) | 0
height: visible ? comboboxHeight : 0
visible: workspaceDialog.visible && machineResolveComboBox.model.count > 1
text: catalog.i18nc("@info:tooltip", "How should the conflict in the machine be resolved?")
UM.Label
{
id: open_with_label
anchors.top: parent.top
anchors.left: parent.left
anchors.bottomMargin: UM.Theme.getSize("default_margin").height
text: catalog.i18nc("@action:label", "Open With")
font: UM.Theme.getFont("default_bold")
}
Cura.ComboBox
{
id: machineResolveComboBox
anchors.top: open_with_label.bottom
anchors.left: parent.left
model: manager.updatableMachinesModel
visible: machineResolveStrategyTooltip.visible
textRole: "displayName"
width: parent.width
height: UM.Theme.getSize("button").height
onCurrentIndexChanged:
{
if (model.getItem(currentIndex).id == "new"
&& model.getItem(currentIndex).type == "default_option")
{
manager.setResolveStrategy("machine", "new")
}
else
{
manager.setResolveStrategy("machine", "override")
manager.setMachineToOverride(model.getItem(currentIndex).id)
}
}
onVisibleChanged:
{
if (!visible) {return}
currentIndex = 0
// If the project printer exists in Cura, set it as the default dropdown menu option.
// No need to check object 0, which is the "Create new" option
for (var i = 1; i < model.count; i++)
{
if (model.getItem(i).name == manager.machineName)
{
currentIndex = i
break
}
}
// The project printer does not exist in Cura. If there is at least one printer of the same
// type, select the first one, else set the index to "Create new"
if (currentIndex == 0 && model.count > 1)
{
currentIndex = 1
}
}
}
}
Row
{
id: printerSettingsTitleRow
anchors.top: parent.top
anchors.bottomMargin: UM.Theme.getSize("default_margin").height
spacing: UM.Theme.getSize("default_margin").width
UM.ColorImage
{
anchors.verticalCenter: parent.verticalCenter
source: UM.Theme.getIcon("Printer")
height: UM.Theme.getSize("medium_button_icon").height
width: height
}
UM.Label
{
text: catalog.i18nc("@action:label", "Printer settings")
anchors.verticalCenter: parent.verticalCenter
font: UM.Theme.getFont("default_bold")
}
}
Column
{
id: printerSettingsValuesTable
width: parent.width
height: childrenRect.height
spacing: UM.Theme.getSize("default_margin").height spacing: UM.Theme.getSize("default_margin").height
leftPadding: UM.Theme.getSize("medium_button_icon").width + UM.Theme.getSize("default_margin").width leftPadding: UM.Theme.getSize("medium_button_icon").width + UM.Theme.getSize("default_margin").width
anchors.top: printerSettingsTitleRow.bottom
Row Row
{ {
@ -230,65 +137,66 @@ UM.Dialog
} }
} }
} }
comboboxTitle: catalog.i18nc("@action:label", "Open With")
comboboxTooltipText: catalog.i18nc("@info:tooltip", "How should the conflict in the machine be resolved?")
combobox: Cura.ComboBox
{
id: machineResolveComboBox
model: manager.updatableMachinesModel
textRole: "displayName"
visible: workspaceDialog.visible && model.count > 1
currentIndex: machineVisibleChanged()
onCurrentIndexChanged:
{
if (model.getItem(currentIndex).id == "new"
&& model.getItem(currentIndex).type == "default_option")
{
manager.setResolveStrategy("machine", "new")
}
else
{
manager.setResolveStrategy("machine", "override")
manager.setMachineToOverride(model.getItem(currentIndex).id)
}
} }
Item function machineVisibleChanged()
{ {
width: parent.width if (!visible) {return}
height: childrenRect.height
UM.TooltipArea currentIndex = 0
// If the project printer exists in Cura, set it as the default dropdown menu option.
// No need to check object 0, which is the "Create new" option
for (var i = 1; i < model.count; i++)
{ {
anchors.right: parent.right if (model.getItem(i).name == manager.machineName)
anchors.top: parent.top
width: (parent.width / 3) | 0
height: visible ? comboboxHeight : 0
visible: manager.qualityChangesConflict
text: catalog.i18nc("@info:tooltip", "How should the conflict in the profile be resolved?")
Cura.ComboBox
{ {
model: resolveStrategiesModel currentIndex = i
textRole: "label" break
id: qualityChangesResolveComboBox }
width: parent.width }
height: UM.Theme.getSize("button").height // The project printer does not exist in Cura. If there is at least one printer of the same
onActivated: // type, select the first one, else set the index to "Create new"
if (currentIndex == 0 && model.count > 1)
{ {
manager.setResolveStrategy("quality_changes", resolveStrategiesModel.get(index).key) currentIndex = 1
}
} }
} }
} }
Row WorkspaceSection
{ {
id: profileSettingsTitleRow id: profileSection
anchors.top: parent.top title: catalog.i18nc("@action:label", "Profile settings")
anchors.bottomMargin: UM.Theme.getSize("default_margin").height iconSource: UM.Theme.getIcon("Printer")
spacing: UM.Theme.getSize("default_margin").width content: Column
UM.ColorImage
{
anchors.verticalCenter: parent.verticalCenter
source: UM.Theme.getIcon("Printer")
height: UM.Theme.getSize("medium_button_icon").height
width: height
}
UM.Label
{
text: catalog.i18nc("@action:label", "Profile settings")
anchors.verticalCenter: parent.verticalCenter
font: UM.Theme.getFont("default_bold")
}
}
Column
{ {
id: profileSettingsValuesTable id: profileSettingsValuesTable
width: parent.width
height: childrenRect.height
spacing: UM.Theme.getSize("default_margin").height spacing: UM.Theme.getSize("default_margin").height
leftPadding: UM.Theme.getSize("medium_button_icon").width + UM.Theme.getSize("default_margin").width leftPadding: UM.Theme.getSize("medium_button_icon").width + UM.Theme.getSize("default_margin").width
anchors.top: profileSettingsTitleRow.bottom
Row Row
{ {
@ -365,65 +273,38 @@ UM.Dialog
} }
} }
} }
}
Item comboboxTitle: catalog.i18nc("@action:label", "Open With")
{ comboboxTooltipText: catalog.i18nc("@info:tooltip", "How should the conflict in the profile be resolved?")
width: parent.width combobox: Cura.ComboBox
height: childrenRect.height
UM.TooltipArea
{
id: materialResolveTooltip
anchors.right: parent.right
anchors.top: parent.top
width: (parent.width / 3) | 0
height: visible ? comboboxHeight : 0
visible: manager.materialConflict
text: catalog.i18nc("@info:tooltip", "How should the conflict in the material be resolved?")
Cura.ComboBox
{ {
id: qualityChangesResolveComboBox
model: resolveStrategiesModel model: resolveStrategiesModel
textRole: "label" textRole: "label"
id: materialResolveComboBox visible: manager.qualityChangesConflict
width: parent.width
height: UM.Theme.getSize("button").height // This is a hack. This will trigger onCurrentIndexChanged and set the index when this component in loaded
onActivated: currentIndex:
{ {
manager.setResolveStrategy("material", resolveStrategiesModel.get(index).key) currentIndex = 0
}
onCurrentIndexChanged:
{
manager.setResolveStrategy("quality_changes", resolveStrategiesModel.get(currentIndex).key)
} }
} }
} }
Row WorkspaceSection
{ {
id: materialSettingsTitleRow id: materialSection
anchors.top: parent.top title: catalog.i18nc("@action:label", "Material settings")
anchors.bottomMargin: UM.Theme.getSize("default_margin").height iconSource: UM.Theme.getIcon("Printer")
spacing: UM.Theme.getSize("default_margin").width content: Column
UM.ColorImage
{ {
anchors.verticalCenter: parent.verticalCenter
source: UM.Theme.getIcon("Printer")
height: UM.Theme.getSize("medium_button_icon").height
width: height
}
UM.Label
{
text: catalog.i18nc("@action:label", "Material settings")
anchors.verticalCenter: parent.verticalCenter
font: UM.Theme.getFont("default_bold")
}
}
Column
{
width: parent.width
height: childrenRect.height
spacing: UM.Theme.getSize("default_margin").height spacing: UM.Theme.getSize("default_margin").height
leftPadding: UM.Theme.getSize("medium_button_icon").width + UM.Theme.getSize("default_margin").width leftPadding: UM.Theme.getSize("medium_button_icon").width + UM.Theme.getSize("default_margin").width
anchors.top: materialSettingsTitleRow.bottom
Repeater Repeater
{ {
@ -446,42 +327,39 @@ UM.Dialog
} }
} }
} }
comboboxTitle: catalog.i18nc("@action:label", "Open With")
comboboxTooltipText: catalog.i18nc("@info:tooltip", "How should the conflict in the material be resolved?")
combobox: Cura.ComboBox
{
id: materialResolveComboBox
model: resolveStrategiesModel
textRole: "label"
visible: manager.materialConflict
// This is a hack. This will trigger onCurrentIndexChanged and set the index when this component in loaded
currentIndex:
{
currentIndex = 0
} }
Item onCurrentIndexChanged:
{ {
width: parent.width manager.setResolveStrategy("material", resolveStrategiesModel.get(currentIndex).key)
height: childrenRect.height
Row
{
id: visibilitySettingsTitleRow
anchors.top: parent.top
anchors.bottomMargin: UM.Theme.getSize("default_margin").height
spacing: UM.Theme.getSize("default_margin").width
UM.ColorImage
{
anchors.verticalCenter: parent.verticalCenter
source: UM.Theme.getIcon("Printer")
height: UM.Theme.getSize("medium_button_icon").height
width: height
} }
UM.Label
{
text: catalog.i18nc("@action:label", "Setting visibility")
anchors.verticalCenter: parent.verticalCenter
font: UM.Theme.getFont("default_bold")
} }
} }
Column WorkspaceSection
{
id: visibilitySection
title: catalog.i18nc("@action:label", "Setting visibility")
iconSource: UM.Theme.getIcon("Printer")
content: Column
{ {
width: parent.width
height: childrenRect.height
spacing: UM.Theme.getSize("default_margin").height spacing: UM.Theme.getSize("default_margin").height
leftPadding: UM.Theme.getSize("medium_button_icon").width + UM.Theme.getSize("default_margin").width leftPadding: UM.Theme.getSize("medium_button_icon").width + UM.Theme.getSize("default_margin").width
anchors.top: visibilitySettingsTitleRow.bottom
Row Row
{ {
@ -515,9 +393,11 @@ UM.Dialog
} }
} }
} }
}
Row Row
{ {
id: clearBuildPlateWarning
width: parent.width width: parent.width
height: childrenRect.height height: childrenRect.height
visible: manager.hasObjectsOnPlate visible: manager.hasObjectsOnPlate
@ -537,7 +417,6 @@ UM.Dialog
} }
} }
} }
}
property bool warning: manager.missingPackages.length > 0 property bool warning: manager.missingPackages.length > 0

View file

@ -0,0 +1,99 @@
// Copyright (c) 2022 Ultimaker B.V.
// Cura is released under the terms of the LGPLv3 or higher.
import QtQuick 2.10
import QtQuick.Controls 2.3
import QtQuick.Layouts 1.3
import QtQuick.Window 2.2
import UM 1.5 as UM
import Cura 1.1 as Cura
Item
{
property alias title: sectionTitle.text
property alias iconSource: sectionTitleIcon.source
property Component content: Item { visible: false }
property alias comboboxTitle: comboboxLabel.text
property Component combobox: Item { visible: false }
property var comboboxTooltipText: ""
property var comboboxVisible: false
width: parent.width
height: childrenRect.height
anchors.leftMargin: UM.Theme.getSize("default_margin").width
UM.TooltipArea
{
id: comboboxTooltip
width: (parent.width / 3) | 0
height: visible ? UM.Theme.getSize("default_margin").heightcomboboxHeight : 0
anchors.top: parent.top
anchors.right: parent.right
visible: combobox.visible
text: comboboxTooltipText
UM.Label
{
id: comboboxLabel
anchors.top: parent.top
anchors.left: parent.left
anchors.bottomMargin: UM.Theme.getSize("default_margin").height
visible: combobox.visible
text: ""
font: UM.Theme.getFont("default_bold")
}
Loader
{
id: comboboxLoader
width: parent.width
height: UM.Theme.getSize("button").height
anchors.top: comboboxLabel.bottom
anchors.left: parent.left
sourceComponent: combobox
}
}
Row
{
id: sectionTitleRow
anchors.top: parent.top
anchors.bottomMargin: UM.Theme.getSize("default_margin").height
spacing: UM.Theme.getSize("default_margin").width
UM.ColorImage
{
id: sectionTitleIcon
anchors.verticalCenter: parent.verticalCenter
source: ""
height: UM.Theme.getSize("medium_button_icon").height
width: height
}
UM.Label
{
id: sectionTitle
text: ""
anchors.verticalCenter: parent.verticalCenter
font: UM.Theme.getFont("default_bold")
}
}
Loader
{
width: parent.width
height: content.height
anchors.top: sectionTitleRow.bottom
sourceComponent: content
}
function reloadValues()
{
comboboxLoader.sourceComponent = null
comboboxLoader.sourceComponent = combobox
}
}