Add preferences for draggable/expandable-component. [CURA-6478]

This commit is contained in:
Remco Burema 2019-04-25 14:50:29 +02:00
parent baac2d1a0f
commit 194f01f840
4 changed files with 26 additions and 2 deletions

View file

@ -522,6 +522,10 @@ class CuraApplication(QtApplication):
preferences.addPreference("cura/use_multi_build_plate", False) preferences.addPreference("cura/use_multi_build_plate", False)
preferences.addPreference("view/settings_list_height", 400) preferences.addPreference("view/settings_list_height", 400)
preferences.addPreference("view/settings_visible", False) preferences.addPreference("view/settings_visible", False)
preferences.addPreference("view/settings_xpos", 0)
preferences.addPreference("view/settings_ypos", 56)
preferences.addPreference("view/colorscheme_xpos", 0)
preferences.addPreference("view/colorscheme_ypos", 56)
preferences.addPreference("cura/currency", "") preferences.addPreference("cura/currency", "")
preferences.addPreference("cura/material_settings", "{}") preferences.addPreference("cura/material_settings", "{}")

View file

@ -15,6 +15,8 @@ Cura.ExpandableComponent
{ {
id: base id: base
dragPreferencesNamePrefix: "view/colorscheme"
contentHeaderTitle: catalog.i18nc("@label", "Color scheme") contentHeaderTitle: catalog.i18nc("@label", "Color scheme")
Connections Connections

View file

@ -78,6 +78,9 @@ Item
property int shadowOffset: 2 property int shadowOffset: 2
// Prefix used for the dragged position preferences. Preferences not used if empty. Don't translate!
property var dragPreferencesNamePrefix: ""
function toggleContent() function toggleContent()
{ {
contentContainer.visible = !expanded contentContainer.visible = !expanded
@ -202,17 +205,19 @@ Item
Cura.RoundedRectangle Cura.RoundedRectangle
{ {
id: contentContainer id: contentContainer
property string dragPreferencesNameX: "_xpos"
property string dragPreferencesNameY: "_ypos"
visible: false visible: false
width: childrenRect.width width: childrenRect.width
height: childrenRect.height height: childrenRect.height
// Ensure that the content is located directly below the headerItem // Ensure that the content is located directly below the headerItem
y: background.height + base.shadowOffset + base.contentSpacingY y: dragPreferencesNamePrefix === "" ? (background.height + base.shadowOffset + base.contentSpacingY) : UM.Preferences.getValue(dragPreferencesNamePrefix + dragPreferencesNameY)
// Make the content aligned with the rest, using the property contentAlignment to decide whether is right or left. // Make the content aligned with the rest, using the property contentAlignment to decide whether is right or left.
// In case of right alignment, the 3x padding is due to left, right and padding between the button & text. // In case of right alignment, the 3x padding is due to left, right and padding between the button & text.
x: contentAlignment == ExpandableComponent.ContentAlignment.AlignRight ? -width + collapseButton.width + headerItemLoader.width + 3 * background.padding : 0 x: dragPreferencesNamePrefix === "" ? (contentAlignment == ExpandableComponent.ContentAlignment.AlignRight ? -width + collapseButton.width + headerItemLoader.width + 3 * background.padding : 0) : UM.Preferences.getValue(dragPreferencesNamePrefix + dragPreferencesNameX)
cornerSide: Cura.RoundedRectangle.Direction.All cornerSide: Cura.RoundedRectangle.Direction.All
color: contentBackgroundColor color: contentBackgroundColor
@ -231,6 +236,12 @@ Item
contentContainer.x = Math.max(minPt.x, Math.min(maxPt.x, posNewX)); contentContainer.x = Math.max(minPt.x, Math.min(maxPt.x, posNewX));
contentContainer.y = Math.max(initialY, Math.min(maxPt.y, posNewY)); contentContainer.y = Math.max(initialY, Math.min(maxPt.y, posNewY));
if (dragPreferencesNamePrefix !== "")
{
UM.Preferences.setValue(dragPreferencesNamePrefix + dragPreferencesNameX, contentContainer.x);
UM.Preferences.setValue(dragPreferencesNamePrefix + dragPreferencesNameY, contentContainer.y);
}
} }
ExpandableComponentHeader ExpandableComponentHeader
@ -309,6 +320,11 @@ Item
} }
} }
Component.onCompleted:
{
updateDragPosition();
}
// DO NOT MOVE UP IN THE CODE: This connection has to be here, after the definition of the content item. // DO NOT MOVE UP IN THE CODE: This connection has to be here, after the definition of the content item.
// Apparently the order in which these are handled matters and so the height is correctly updated if this is here. // Apparently the order in which these are handled matters and so the height is correctly updated if this is here.
Connections Connections

View file

@ -11,6 +11,8 @@ Cura.ExpandableComponent
{ {
id: printSetupSelector id: printSetupSelector
dragPreferencesNamePrefix: "view/settings"
property bool preSlicedData: PrintInformation.preSliced property bool preSlicedData: PrintInformation.preSliced
contentPadding: UM.Theme.getSize("default_lining").width contentPadding: UM.Theme.getSize("default_lining").width