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.
This commit is contained in:
Diego Prado Gesto 2018-12-04 12:07:31 +01:00
parent a66bb4fab1
commit 692686597c
2 changed files with 48 additions and 43 deletions

View file

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

View file

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