From 5bb23e4c6f335eca18b73dfb5517bbabd85d6782 Mon Sep 17 00:00:00 2001 From: Nino van Hooff Date: Mon, 7 Oct 2019 15:22:04 +0200 Subject: [PATCH 1/6] Make the height of the layer slider dynamic Prevents the action panel from overlapping the layer slider CURA-6853 --- plugins/PreviewStage/PreviewMain.qml | 1 + plugins/SimulationView/LayerSlider.qml | 5 +++++ plugins/SimulationView/SimulationView.py | 2 +- plugins/SimulationView/SimulationViewMainComponent.qml | 10 +++++++++- 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/plugins/PreviewStage/PreviewMain.qml b/plugins/PreviewStage/PreviewMain.qml index 6b5ce2436b..cd448dc0b6 100644 --- a/plugins/PreviewStage/PreviewMain.qml +++ b/plugins/PreviewStage/PreviewMain.qml @@ -13,6 +13,7 @@ Item { Loader { + property var panelTop: actionPanelWidget.y id: previewMain anchors.fill: parent diff --git a/plugins/SimulationView/LayerSlider.qml b/plugins/SimulationView/LayerSlider.qml index 88f298d1f5..d2af1e223b 100644 --- a/plugins/SimulationView/LayerSlider.qml +++ b/plugins/SimulationView/LayerSlider.qml @@ -176,6 +176,11 @@ Item } } + onHeightChanged : { + print("new height:" + height) + //rangeHandle.onHandleDragged() + } + // Upper handle Rectangle { diff --git a/plugins/SimulationView/SimulationView.py b/plugins/SimulationView/SimulationView.py index 28d5a74523..3a7cb0d2fe 100644 --- a/plugins/SimulationView/SimulationView.py +++ b/plugins/SimulationView/SimulationView.py @@ -48,7 +48,7 @@ if TYPE_CHECKING: catalog = i18nCatalog("cura") -## View used to display g-code paths. +## The preview layer view. It is used to display g-code paths. class SimulationView(CuraView): # Must match SimulationViewMenuComponent.qml LAYER_VIEW_TYPE_MATERIAL_TYPE = 0 diff --git a/plugins/SimulationView/SimulationViewMainComponent.qml b/plugins/SimulationView/SimulationViewMainComponent.qml index 58901652d3..51fc70ade8 100644 --- a/plugins/SimulationView/SimulationViewMainComponent.qml +++ b/plugins/SimulationView/SimulationViewMainComponent.qml @@ -14,6 +14,7 @@ Item property bool is_simulation_playing: false visible: UM.SimulationView.layerActivity && CuraApplication.platformActivity + // A slider which lets users trace a single layer (XY movements) PathSlider { id: pathSlider @@ -170,18 +171,24 @@ Item } } + // Scrolls trough Z layers LayerSlider { + property var preferredHeight: UM.Theme.getSize("slider_layerview_size").height + property double heightMargin: UM.Theme.getSize("default_margin").height id: layerSlider width: UM.Theme.getSize("slider_handle").width - height: UM.Theme.getSize("slider_layerview_size").height + height: preferredHeight + heightMargin * 2 < panelTop ? preferredHeight : panelTop - heightMargin * 2 anchors { right: parent.right verticalCenter: parent.verticalCenter + verticalCenterOffset: -(parent.height - panelTop) / 2 // center between parent top and panelTop rightMargin: UM.Theme.getSize("default_margin").width + bottomMargin: heightMargin + topMargin: heightMargin } // Custom properties @@ -209,6 +216,7 @@ Item // Make sure the slider handlers show the correct value after switching views Component.onCompleted: { + print("paneltop", panelTop, "screenscaleFactor") layerSlider.setLowerValue(UM.SimulationView.minimumLayer) layerSlider.setUpperValue(UM.SimulationView.currentLayer) } From f090450bba2349bb3b81a713f5d617d7f7316ee6 Mon Sep 17 00:00:00 2001 From: Nino van Hooff Date: Mon, 7 Oct 2019 16:27:25 +0200 Subject: [PATCH 2/6] Fix pixel-position of layer slider after the window was resized. CURA-6853 --- plugins/SimulationView/LayerSlider.qml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/SimulationView/LayerSlider.qml b/plugins/SimulationView/LayerSlider.qml index d2af1e223b..9706b04e03 100644 --- a/plugins/SimulationView/LayerSlider.qml +++ b/plugins/SimulationView/LayerSlider.qml @@ -177,8 +177,8 @@ Item } onHeightChanged : { - print("new height:" + height) - //rangeHandle.onHandleDragged() + // After a height change, the pixel-position of the lower handle is out of sync with the property value + setLowerValue(lowerValue) } // Upper handle @@ -338,7 +338,7 @@ Item // set the slider position based on the lower value function setValue(value) { - + print("lower handle set value: " + value) // Normalize values between range, since using arrow keys will create out-of-the-range values value = sliderRoot.normalizeValue(value) From 4148f56d2b58465055914910f08e1a92fe657586 Mon Sep 17 00:00:00 2001 From: Nino van Hooff Date: Wed, 9 Oct 2019 16:51:28 +0200 Subject: [PATCH 3/6] Remove external dependency from SimulationViewMainComponent Previously, panelTop had to be defined externally whenever SimulationViewMainComponent was used. I renamed it and set a default so the binding by a parent is optional. CURA-6853 --- plugins/PreviewStage/PreviewMain.qml | 9 ++++++++- plugins/SimulationView/LayerSlider.qml | 1 - plugins/SimulationView/SimulationViewMainComponent.qml | 10 +++++++--- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/plugins/PreviewStage/PreviewMain.qml b/plugins/PreviewStage/PreviewMain.qml index cd448dc0b6..a065a751ac 100644 --- a/plugins/PreviewStage/PreviewMain.qml +++ b/plugins/PreviewStage/PreviewMain.qml @@ -13,11 +13,18 @@ Item { Loader { - property var panelTop: actionPanelWidget.y id: previewMain anchors.fill: parent source: UM.Controller.activeView != null && UM.Controller.activeView.mainComponent != null ? UM.Controller.activeView.mainComponent : "" + + // Indicate that the layer slider should stay above the action panel + Binding + { + target: previewMain.item + property: "layerSliderSafeYMax" + value: actionPanelWidget.y + } } Cura.ActionPanelWidget diff --git a/plugins/SimulationView/LayerSlider.qml b/plugins/SimulationView/LayerSlider.qml index 9706b04e03..15b0fdbe12 100644 --- a/plugins/SimulationView/LayerSlider.qml +++ b/plugins/SimulationView/LayerSlider.qml @@ -338,7 +338,6 @@ Item // set the slider position based on the lower value function setValue(value) { - print("lower handle set value: " + value) // Normalize values between range, since using arrow keys will create out-of-the-range values value = sliderRoot.normalizeValue(value) diff --git a/plugins/SimulationView/SimulationViewMainComponent.qml b/plugins/SimulationView/SimulationViewMainComponent.qml index 51fc70ade8..c115dafe26 100644 --- a/plugins/SimulationView/SimulationViewMainComponent.qml +++ b/plugins/SimulationView/SimulationViewMainComponent.qml @@ -12,6 +12,11 @@ import Cura 1.0 as Cura Item { property bool is_simulation_playing: false + // By default, the layer slider can extend to the entire height of the parent + // A parent may bind this property to indicate the bottom of a safe area + // for the Layer slider + property var layerSliderSafeYMax: parent.height + visible: UM.SimulationView.layerActivity && CuraApplication.platformActivity // A slider which lets users trace a single layer (XY movements) @@ -179,13 +184,13 @@ Item id: layerSlider width: UM.Theme.getSize("slider_handle").width - height: preferredHeight + heightMargin * 2 < panelTop ? preferredHeight : panelTop - heightMargin * 2 + height: preferredHeight + heightMargin * 2 < layerSliderSafeYMax ? preferredHeight : layerSliderSafeYMax - heightMargin * 2 anchors { right: parent.right verticalCenter: parent.verticalCenter - verticalCenterOffset: -(parent.height - panelTop) / 2 // center between parent top and panelTop + verticalCenterOffset: -(parent.height - layerSliderSafeYMax) / 2 // center between parent top and layerSliderSafeYMax rightMargin: UM.Theme.getSize("default_margin").width bottomMargin: heightMargin topMargin: heightMargin @@ -216,7 +221,6 @@ Item // Make sure the slider handlers show the correct value after switching views Component.onCompleted: { - print("paneltop", panelTop, "screenscaleFactor") layerSlider.setLowerValue(UM.SimulationView.minimumLayer) layerSlider.setUpperValue(UM.SimulationView.currentLayer) } From 87bbf3259791efc1724f3509f0db239b6af1794e Mon Sep 17 00:00:00 2001 From: Nino van Hooff Date: Wed, 9 Oct 2019 16:53:19 +0200 Subject: [PATCH 4/6] Rename is_simulation_playing CURA-6853 --- .../SimulationView/SimulationViewMainComponent.qml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/SimulationView/SimulationViewMainComponent.qml b/plugins/SimulationView/SimulationViewMainComponent.qml index c115dafe26..ddbb5b6224 100644 --- a/plugins/SimulationView/SimulationViewMainComponent.qml +++ b/plugins/SimulationView/SimulationViewMainComponent.qml @@ -11,7 +11,7 @@ import Cura 1.0 as Cura Item { - property bool is_simulation_playing: false + property bool isSimulationPlaying: false // By default, the layer slider can extend to the entire height of the parent // A parent may bind this property to indicate the bottom of a safe area // for the Layer slider @@ -64,7 +64,7 @@ Item UM.SimpleButton { id: playButton - iconSource: !is_simulation_playing ? "./resources/simulation_resume.svg": "./resources/simulation_pause.svg" + iconSource: !isSimulationPlaying ? "./resources/simulation_resume.svg": "./resources/simulation_pause.svg" width: UM.Theme.getSize("small_button").width height: UM.Theme.getSize("small_button").height hoverColor: UM.Theme.getColor("slider_handle_active") @@ -94,7 +94,7 @@ Item onClicked: { - if(is_simulation_playing) + if(isSimulationPlaying) { pauseSimulation() } @@ -108,7 +108,7 @@ Item { UM.SimulationView.setSimulationRunning(false) simulationTimer.stop() - is_simulation_playing = false + isSimulationPlaying = false layerSlider.manuallyChanged = true pathSlider.manuallyChanged = true } @@ -137,7 +137,7 @@ Item // When the user plays the simulation, if the path slider is at the end of this layer, we start // the simulation at the beginning of the current layer. - if (!is_simulation_playing) + if (!isSimulationPlaying) { if (currentPath >= numPaths) { @@ -172,7 +172,7 @@ Item } // The status must be set here instead of in the resumeSimulation function otherwise it won't work // correctly, because part of the logic is in this trigger function. - is_simulation_playing = true + isSimulationPlaying = true } } From 664ed4a6a67fce8a86fb0f1d049931a1d0193b56 Mon Sep 17 00:00:00 2001 From: Nino van Hooff Date: Thu, 17 Oct 2019 12:52:30 +0200 Subject: [PATCH 5/6] Take a more generic approach to safe areas for the SimulationView Re-implements layer slider positioning CURA-6853 --- plugins/PreviewStage/PreviewMain.qml | 16 +++++++++++++--- .../SimulationViewMainComponent.qml | 12 ++++++++---- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/plugins/PreviewStage/PreviewMain.qml b/plugins/PreviewStage/PreviewMain.qml index a065a751ac..1b8387644d 100644 --- a/plugins/PreviewStage/PreviewMain.qml +++ b/plugins/PreviewStage/PreviewMain.qml @@ -11,6 +11,17 @@ import Cura 1.0 as Cura Item { + + // Subtract the actionPanel from the safe area. This way the view won't draw interface elements under/over it + Item { + id: safeArea + visible: false + anchors.left: parent.left + anchors.right: actionPanelWidget.left + anchors.top: parent.top + anchors.bottom: actionPanelWidget.top + } + Loader { id: previewMain @@ -18,12 +29,11 @@ Item source: UM.Controller.activeView != null && UM.Controller.activeView.mainComponent != null ? UM.Controller.activeView.mainComponent : "" - // Indicate that the layer slider should stay above the action panel Binding { target: previewMain.item - property: "layerSliderSafeYMax" - value: actionPanelWidget.y + property: "safeArea" + value:safeArea } } diff --git a/plugins/SimulationView/SimulationViewMainComponent.qml b/plugins/SimulationView/SimulationViewMainComponent.qml index ddbb5b6224..65621605df 100644 --- a/plugins/SimulationView/SimulationViewMainComponent.qml +++ b/plugins/SimulationView/SimulationViewMainComponent.qml @@ -11,11 +11,14 @@ import Cura 1.0 as Cura Item { + // An Item whose bounds are guaranteed to be safe for overlays to be placed. + // Defaults to parent, ie. the entire available area + // eg. the layer slider will not be placed in this area. + property var safeArea: parent + + property bool isSimulationPlaying: false - // By default, the layer slider can extend to the entire height of the parent - // A parent may bind this property to indicate the bottom of a safe area - // for the Layer slider - property var layerSliderSafeYMax: parent.height + readonly property var layerSliderSafeYMax: safeArea.y + safeArea.height visible: UM.SimulationView.layerActivity && CuraApplication.platformActivity @@ -221,6 +224,7 @@ Item // Make sure the slider handlers show the correct value after switching views Component.onCompleted: { + print("safeArea: " + safeArea, "layerSliderSafeYMax", layerSliderSafeYMax) layerSlider.setLowerValue(UM.SimulationView.minimumLayer) layerSlider.setUpperValue(UM.SimulationView.currentLayer) } From 9d931d8d2b91ab044d83d0e237e8a206765da997 Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Mon, 21 Oct 2019 14:24:52 +0200 Subject: [PATCH 6/6] Remove stray print statement CURA-6853 --- plugins/SimulationView/SimulationViewMainComponent.qml | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/SimulationView/SimulationViewMainComponent.qml b/plugins/SimulationView/SimulationViewMainComponent.qml index 65621605df..cd7d108370 100644 --- a/plugins/SimulationView/SimulationViewMainComponent.qml +++ b/plugins/SimulationView/SimulationViewMainComponent.qml @@ -224,7 +224,6 @@ Item // Make sure the slider handlers show the correct value after switching views Component.onCompleted: { - print("safeArea: " + safeArea, "layerSliderSafeYMax", layerSliderSafeYMax) layerSlider.setLowerValue(UM.SimulationView.minimumLayer) layerSlider.setUpperValue(UM.SimulationView.currentLayer) }