From 692686597cf9204748a25c38fc11392712e74ae4 Mon Sep 17 00:00:00 2001 From: Diego Prado Gesto Date: Tue, 4 Dec 2018 12:07:31 +0100 Subject: [PATCH] Fix an issues that didn't calculate the correct height of the popup when the custom mode was selected from previous runs. Contributes to CURA-5941. --- resources/qml/ExpandableComponent.qml | 42 ++++++++-------- .../PrintSetupSelectorContents.qml | 49 ++++++++++--------- 2 files changed, 48 insertions(+), 43 deletions(-) diff --git a/resources/qml/ExpandableComponent.qml b/resources/qml/ExpandableComponent.qml index 82747d1c5b..df7604015e 100644 --- a/resources/qml/ExpandableComponent.qml +++ b/resources/qml/ExpandableComponent.qml @@ -25,10 +25,7 @@ Item property alias headerItem: headerItemLoader.sourceComponent // The popupItem holds the QML item that is shown when the "open" button is pressed - property var popupItem - - // The popupItem holds the QML item that is shown when the "open" button is pressed - property var componentItem + property alias popupItem: popup.contentItem property color popupBackgroundColor: UM.Theme.getColor("action_button") @@ -87,23 +84,6 @@ Item } } - onPopupItemChanged: - { - // Since we want the size of the popup to be set by the size of the content, - // we need to do it like this. - popup.width = popupItem.width + 2 * popup.padding - popup.height = popupItem.height + 2 * popup.padding - popup.contentItem = popupItem - } - - Connections - { - // Since it could be that the popup is dynamically populated, we should also take these changes into account. - target: popupItem - onWidthChanged: popup.width = popupItem.width + 2 * popup.padding - onHeightChanged: popup.height = popupItem.height + 2 * popup.padding - } - implicitHeight: 100 * screenScaleFactor implicitWidth: 400 * screenScaleFactor @@ -202,5 +182,25 @@ Item border.color: UM.Theme.getColor("lining") radius: UM.Theme.getSize("default_radius").width } + + contentItem: Item { } + + onContentItemChanged: + { + // Since we want the size of the popup to be set by the size of the content, + // we need to do it like this. + popup.width = contentItem.width + 2 * popup.padding + popup.height = contentItem.height + 2 * popup.padding + } + } + + // DO NOT MOVE UP IN THE CODE: This connection has to be here, after the definition of the Popup item. + // Apparently the order in which these are handled matters and so the height is correctly updated if this is here. + Connections + { + // Since it could be that the popup is dynamically populated, we should also take these changes into account. + target: popup.contentItem + onWidthChanged: popup.width = popup.contentItem.width + 2 * popup.padding + onHeightChanged: popup.height = popup.contentItem.height + 2 * popup.padding } } diff --git a/resources/qml/PrintSetupSelector/PrintSetupSelectorContents.qml b/resources/qml/PrintSetupSelector/PrintSetupSelectorContents.qml index 358cba8ad0..a2856e1fe5 100644 --- a/resources/qml/PrintSetupSelector/PrintSetupSelectorContents.qml +++ b/resources/qml/PrintSetupSelector/PrintSetupSelectorContents.qml @@ -17,9 +17,26 @@ Item width: UM.Theme.getSize("print_setup_widget").width - 2 * UM.Theme.getSize("default_margin").width height: childrenRect.height - property int currentModeIndex: -1 + enum Mode + { + Recommended = 0, + Custom = 1 + } + + // Set the current mode index to the value that is stored in the preferences or Recommended mode otherwise. + property int currentModeIndex: + { + var index = Math.round(UM.Preferences.getValue("cura/active_mode")) + + if(index != null && !isNaN(index)) + { + return index + } + return PrintSetupSelectorContents.Mode.Recommended + } onCurrentModeIndexChanged: UM.Preferences.setValue("cura/active_mode", currentModeIndex) + // Header of the popup Rectangle { @@ -93,7 +110,9 @@ Item Item { id: contents - height: currentModeIndex == 0 ? recommendedPrintSetup.height : customPrintSetup.height + // Use the visible property instead of checking the currentModeIndex. That creates a binding that + // evaluates the new height every time the visible property changes. + height: recommendedPrintSetup.visible ? recommendedPrintSetup.height : customPrintSetup.height anchors { @@ -111,7 +130,7 @@ Item right: parent.right top: parent.top } - visible: currentModeIndex == 0 + visible: currentModeIndex == PrintSetupSelectorContents.Mode.Recommended } CustomPrintSetup @@ -123,7 +142,7 @@ Item right: parent.right top: parent.top } - visible: currentModeIndex == 1 + visible: currentModeIndex == PrintSetupSelectorContents.Mode.Custom } } @@ -160,8 +179,8 @@ Item rightPadding: UM.Theme.getSize("default_margin").width text: catalog.i18nc("@button", "Recommended") iconSource: UM.Theme.getIcon("arrow_left") - visible: currentModeIndex == 1 - onClicked: currentModeIndex = 0 + visible: currentModeIndex == PrintSetupSelectorContents.Mode.Custom + onClicked: currentModeIndex = PrintSetupSelectorContents.Mode.Recommended } Cura.SecondaryButton @@ -174,22 +193,8 @@ Item text: catalog.i18nc("@button", "Custom") iconSource: UM.Theme.getIcon("arrow_right") iconOnRightSide: true - visible: currentModeIndex == 0 - onClicked: currentModeIndex = 1 - } - } - - Component.onCompleted: - { - var index = Math.round(UM.Preferences.getValue("cura/active_mode")) - - if(index != null && !isNaN(index)) - { - currentModeIndex = index - } - else - { - currentModeIndex = 0 + visible: currentModeIndex == PrintSetupSelectorContents.Mode.Recommended + onClicked: currentModeIndex = PrintSetupSelectorContents.Mode.Custom } } } \ No newline at end of file