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
} }
} }
} }
}
Item comboboxTitle: catalog.i18nc("@action:label", "Open With")
{ comboboxTooltipText: catalog.i18nc("@info:tooltip", "How should the conflict in the machine be resolved?")
width: parent.width combobox: Cura.ComboBox
height: childrenRect.height
UM.TooltipArea
{ {
anchors.right: parent.right id: machineResolveComboBox
anchors.top: parent.top model: manager.updatableMachinesModel
width: (parent.width / 3) | 0 textRole: "displayName"
height: visible ? comboboxHeight : 0 visible: workspaceDialog.visible && model.count > 1
visible: manager.qualityChangesConflict currentIndex: machineVisibleChanged()
text: catalog.i18nc("@info:tooltip", "How should the conflict in the profile be resolved?")
Cura.ComboBox onCurrentIndexChanged:
{ {
model: resolveStrategiesModel if (model.getItem(currentIndex).id == "new"
textRole: "label" && model.getItem(currentIndex).type == "default_option")
id: qualityChangesResolveComboBox
width: parent.width
height: UM.Theme.getSize("button").height
onActivated:
{ {
manager.setResolveStrategy("quality_changes", resolveStrategiesModel.get(index).key) manager.setResolveStrategy("machine", "new")
}
else
{
manager.setResolveStrategy("machine", "override")
manager.setMachineToOverride(model.getItem(currentIndex).id)
}
}
function machineVisibleChanged()
{
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 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
} }
} }
} }
comboboxTitle: catalog.i18nc("@action:label", "Open With")
comboboxTooltipText: catalog.i18nc("@info:tooltip", "How should the conflict in the profile be resolved?")
combobox: Cura.ComboBox
{
id: qualityChangesResolveComboBox
model: resolveStrategiesModel
textRole: "label"
visible: manager.qualityChangesConflict
// This is a hack. This will trigger onCurrentIndexChanged and set the index when this component in loaded
currentIndex:
{
currentIndex = 0
}
onCurrentIndexChanged:
{
manager.setResolveStrategy("quality_changes", resolveStrategiesModel.get(currentIndex).key)
}
}
} }
Item WorkspaceSection
{ {
width: parent.width id: materialSection
height: childrenRect.height title: catalog.i18nc("@action:label", "Material settings")
iconSource: UM.Theme.getIcon("Printer")
UM.TooltipArea content: Column
{ {
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
{
model: resolveStrategiesModel
textRole: "label"
id: materialResolveComboBox
width: parent.width
height: UM.Theme.getSize("button").height
onActivated:
{
manager.setResolveStrategy("material", resolveStrategiesModel.get(index).key)
}
}
}
Row
{
id: materialSettingsTitleRow
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", "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
} }
} }
} }
}
Item comboboxTitle: catalog.i18nc("@action:label", "Open With")
{ comboboxTooltipText: catalog.i18nc("@info:tooltip", "How should the conflict in the material be resolved?")
width: parent.width
height: childrenRect.height
Row combobox: Cura.ComboBox
{ {
id: visibilitySettingsTitleRow id: materialResolveComboBox
anchors.top: parent.top model: resolveStrategiesModel
anchors.bottomMargin: UM.Theme.getSize("default_margin").height textRole: "label"
spacing: UM.Theme.getSize("default_margin").width visible: manager.materialConflict
UM.ColorImage // This is a hack. This will trigger onCurrentIndexChanged and set the index when this component in loaded
currentIndex:
{ {
anchors.verticalCenter: parent.verticalCenter currentIndex = 0
source: UM.Theme.getIcon("Printer")
height: UM.Theme.getSize("medium_button_icon").height
width: height
} }
UM.Label
onCurrentIndexChanged:
{ {
text: catalog.i18nc("@action:label", "Setting visibility") manager.setResolveStrategy("material", resolveStrategiesModel.get(currentIndex).key)
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,24 +393,25 @@ UM.Dialog
} }
} }
} }
}
Row Row
{
id: clearBuildPlateWarning
width: parent.width
height: childrenRect.height
visible: manager.hasObjectsOnPlate
UM.ColorImage
{ {
width: parent.width width: warningLabel.height
height: childrenRect.height height: width
visible: manager.hasObjectsOnPlate source: UM.Theme.getIcon("Information")
UM.ColorImage color: UM.Theme.getColor("text")
{ }
width: warningLabel.height UM.Label
height: width {
source: UM.Theme.getIcon("Information") id: warningLabel
color: UM.Theme.getColor("text") text: catalog.i18nc("@action:warning", "Loading a project will clear all models on the build plate.")
}
UM.Label
{
id: warningLabel
text: catalog.i18nc("@action:warning", "Loading a project will clear all models on the build plate.")
}
} }
} }
} }

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
}
}