From c13deba1ea080946e1e62ed9d4c76eb0ad89b142 Mon Sep 17 00:00:00 2001 From: Remco Burema Date: Wed, 30 Nov 2022 12:40:07 +0100 Subject: [PATCH] Build correct states for safe profiles flow (except actual safe). Re-use Discard Or Keep dialogue, but have different buttons. (Safe to New/Override instead of Keep/Discard.) The actual safa action is still the old one though (for either new button, it still goes to the old 'make a new profile' action). Besides that, some cosmetics have to be done to the texts as well still. part of CURA-9347 --- cura/CuraApplication.py | 2 +- resources/qml/Cura.qml | 4 +- .../DiscardOrKeepProfileChangesDialog.qml | 48 +++++++++++++++++-- .../ProfileWarningReset.qml | 2 +- 4 files changed, 50 insertions(+), 6 deletions(-) diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index f2d945ba26..8939aec07a 100755 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -709,8 +709,8 @@ class CuraApplication(QtApplication): self.showMessageBox.emit(title, text, informativeText, detailedText, buttons, icon) showDiscardOrKeepProfileChanges = pyqtSignal() + showCompareAndSaveProfileChanges = pyqtSignal(str) - @pyqtSlot() def discardOrKeepProfileChanges(self) -> bool: has_user_interaction = False choice = self.getPreferences().getValue("cura/choice_on_profile_override") diff --git a/resources/qml/Cura.qml b/resources/qml/Cura.qml index 2ec342f502..55da131df0 100644 --- a/resources/qml/Cura.qml +++ b/resources/qml/Cura.qml @@ -816,11 +816,13 @@ UM.MainWindow Connections { target: CuraApplication - function onShowDiscardOrKeepProfileChanges() + function onShowCompareAndSaveProfileChanges(profileState) { discardOrKeepProfileChangesDialogLoader.sourceComponent = discardOrKeepProfileChangesDialogComponent + discardOrKeepProfileChangesDialogLoader.item.state = profileState discardOrKeepProfileChangesDialogLoader.item.show() } + function onShowDiscardOrKeepProfileChanges() { onShowCompareAndSaveProfileChanges("") } } Cura.WizardDialog diff --git a/resources/qml/Dialogs/DiscardOrKeepProfileChangesDialog.qml b/resources/qml/Dialogs/DiscardOrKeepProfileChangesDialog.qml index 0fecb6b662..461765df07 100644 --- a/resources/qml/Dialogs/DiscardOrKeepProfileChangesDialog.qml +++ b/resources/qml/Dialogs/DiscardOrKeepProfileChangesDialog.qml @@ -12,8 +12,10 @@ UM.Dialog id: base title: catalog.i18nc("@title:window", "Discard or Keep changes") - onAccepted: CuraApplication.discardOrKeepProfileChangesClosed("discard") - onRejected: CuraApplication.discardOrKeepProfileChangesClosed("keep") + property alias state: alternateStates.state + + onAccepted: alternateStates.state == "" ? CuraApplication.discardOrKeepProfileChangesClosed("discard") : Cura.Actions.addProfile.trigger() + onRejected: alternateStates.state == "" ? CuraApplication.discardOrKeepProfileChangesClosed("keep") : Cura.Actions.addProfile.trigger() minimumWidth: UM.Theme.getSize("popup_dialog").width minimumHeight: UM.Theme.getSize("popup_dialog").height @@ -98,9 +100,26 @@ UM.Dialog buttonSpacing: UM.Theme.getSize("thin_margin").width - leftButtons: [ + Rectangle + { + // Use a rectangle to get access to states. For some reason top-levels like Dialog/Window ect. don't have them. + // NOTE: The default state is 'switch profiles', alternate states are used for 'save from [built-in|custom]'. + id: alternateStates + width: 0 + height: 0 + states: + [ + State { name: "saveFromBuiltIn" }, + State { name: "saveFromCustom" } + ] + } + + leftButtons: + [ Cura.ComboBox { + visible: alternateStates.state == "" + implicitHeight: UM.Theme.getSize("combobox").height implicitWidth: UM.Theme.getSize("combobox").width @@ -136,6 +155,13 @@ UM.Dialog discardButton.enabled = true; } } + }, + Rectangle + { + // Workaround: If this placeholder isn't in here, then on repeated state-changes of the window, the rightButtons will be in the center (despite initially showing up right). + visible: alternateStates.state != "" + implicitHeight: UM.Theme.getSize("combobox").height + implicitWidth: UM.Theme.getSize("combobox").width } ] @@ -146,12 +172,28 @@ UM.Dialog id: discardButton text: catalog.i18nc("@action:button", "Discard changes") onClicked: base.accept() + visible: alternateStates.state == "" }, Cura.SecondaryButton { id: keepButton text: catalog.i18nc("@action:button", "Keep changes") onClicked: base.reject() + visible: alternateStates.state == "" + }, + Cura.SecondaryButton + { + id: overwriteButton + text: catalog.i18nc("@action:button", "Save as new custom profile") + onClicked: base.accept() + visible: alternateStates.state != "" + }, + Cura.PrimaryButton + { + id: saveButton + text: catalog.i18nc("@action:button", "Save changes") + onClicked: base.reject() + visible: alternateStates.state == "saveFromCustom" } ] } diff --git a/resources/qml/PrintSetupSelector/ProfileWarningReset.qml b/resources/qml/PrintSetupSelector/ProfileWarningReset.qml index 4702f3dba8..17d59981fa 100644 --- a/resources/qml/PrintSetupSelector/ProfileWarningReset.qml +++ b/resources/qml/PrintSetupSelector/ProfileWarningReset.qml @@ -139,7 +139,7 @@ Item hoverColor: UM.Theme.getColor("primary_hover") enabled: Cura.SimpleModeSettingsManager.isProfileCustomized - onClicked: Cura.MachineManager.hasCustomQuality ? CuraApplication.discardOrKeepProfileChanges() : Cura.Actions.addProfile.trigger() + onClicked: CuraApplication.showCompareAndSaveProfileChanges(Cura.MachineManager.hasCustomQuality ? "saveFromCustom" : "saveFromBuiltIn") UM.ToolTip {