From 3248a05819fccd54f71f6765ff5846b15c22b181 Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Mon, 29 Oct 2018 11:28:08 +0100 Subject: [PATCH 01/21] Add PreviewStagePlugin stubs Since we are going to move all the views into a seperate stage, we need to add another stage to do that. CURA-5829 --- cura/CuraApplication.py | 1 + plugins/MonitorStage/__init__.py | 4 +++- plugins/PreviewStage/PreviewStage.py | 13 +++++++++++++ plugins/PreviewStage/__init__.py | 22 ++++++++++++++++++++++ plugins/PreviewStage/plugin.json | 8 ++++++++ 5 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 plugins/PreviewStage/PreviewStage.py create mode 100644 plugins/PreviewStage/__init__.py create mode 100644 plugins/PreviewStage/plugin.json diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index 5824d21b1c..8f9816e968 100755 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -433,6 +433,7 @@ class CuraApplication(QtApplication): "XmlMaterialProfile", "Toolbox", "PrepareStage", + "PreviewStage", "MonitorStage", "LocalFileOutputDevice", "LocalContainerProvider", diff --git a/plugins/MonitorStage/__init__.py b/plugins/MonitorStage/__init__.py index bdaf53a36c..0468e6319b 100644 --- a/plugins/MonitorStage/__init__.py +++ b/plugins/MonitorStage/__init__.py @@ -7,14 +7,16 @@ from . import MonitorStage from UM.i18n import i18nCatalog i18n_catalog = i18nCatalog("cura") + def getMetaData(): return { "stage": { "name": i18n_catalog.i18nc("@item:inmenu", "Monitor"), - "weight": 1 + "weight": 2 } } + def register(app): return { "stage": MonitorStage.MonitorStage() diff --git a/plugins/PreviewStage/PreviewStage.py b/plugins/PreviewStage/PreviewStage.py new file mode 100644 index 0000000000..a51bf766b6 --- /dev/null +++ b/plugins/PreviewStage/PreviewStage.py @@ -0,0 +1,13 @@ +# Copyright (c) 2018 Ultimaker B.V. +# Cura is released under the terms of the LGPLv3 or higher. +from UM.Application import Application +from cura.Stages.CuraStage import CuraStage + + +class PreviewStage(CuraStage): + def __init__(self, parent = None) -> None: + super().__init__(parent) + Application.getInstance().engineCreatedSignal.connect(self._engineCreated) + + def _engineCreated(self): + return \ No newline at end of file diff --git a/plugins/PreviewStage/__init__.py b/plugins/PreviewStage/__init__.py new file mode 100644 index 0000000000..e03992fc00 --- /dev/null +++ b/plugins/PreviewStage/__init__.py @@ -0,0 +1,22 @@ +# Copyright (c) 2017 Ultimaker B.V. +# Cura is released under the terms of the LGPLv3 or higher. + +from . import PreviewStage + +from UM.i18n import i18nCatalog +i18n_catalog = i18nCatalog("cura") + + +def getMetaData(): + return { + "stage": { + "name": i18n_catalog.i18nc("@item:inmenu", "Preview"), + "weight": 1 + } + } + + +def register(app): + return { + "stage": PreviewStage.PreviewStage() + } diff --git a/plugins/PreviewStage/plugin.json b/plugins/PreviewStage/plugin.json new file mode 100644 index 0000000000..9349da2b0e --- /dev/null +++ b/plugins/PreviewStage/plugin.json @@ -0,0 +1,8 @@ +{ + "name": "Preview Stage", + "author": "Ultimaker B.V.", + "version": "1.0.0", + "description": "Provides a preview stage in Cura.", + "api": 5, + "i18n-catalog": "cura" +} \ No newline at end of file From 9cc7a7ca23df6427f5e921ca1594dfd8c3ed176a Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Mon, 29 Oct 2018 13:27:47 +0100 Subject: [PATCH 02/21] Moved view selection to previewStage CURA-5829 --- plugins/PreviewStage/PreviewMenu.qml | 77 ++++++++++++++++++++ plugins/PreviewStage/PreviewStage.py | 26 ++++++- plugins/PreviewStage/__init__.py | 2 +- resources/qml/Cura.qml | 62 ---------------- resources/qml/MainWindow/ApplicationMenu.qml | 2 - 5 files changed, 100 insertions(+), 69 deletions(-) create mode 100644 plugins/PreviewStage/PreviewMenu.qml diff --git a/plugins/PreviewStage/PreviewMenu.qml b/plugins/PreviewStage/PreviewMenu.qml new file mode 100644 index 0000000000..c364c4c3d7 --- /dev/null +++ b/plugins/PreviewStage/PreviewMenu.qml @@ -0,0 +1,77 @@ +import QtQuick 2.7 + +import QtQuick.Controls 1.4 + +import UM 1.3 as UM +import Cura 1.1 as Cura + +Item +{ + id: previewMenu + // This widget doesn't show tooltips by itself. Instead it emits signals so others can do something with it. + signal showTooltip(Item item, point location, string text) + signal hideTooltip() + + UM.I18nCatalog + { + id: catalog + name: "cura" + } + + Row + { + anchors.horizontalCenter: parent.horizontalCenter + ComboBox + { + // This item contains the views selector, a combobox that is dynamically created from + // the list of available Views (packages that create different visualizations of the + // scene). + id: viewModeButton + + style: UM.Theme.styles.combobox + + model: UM.ViewModel { } + textRole: "name" + + // update the model's active index + function updateItemActiveFlags() + { + currentIndex = getActiveIndex() + for (var i = 0; i < model.rowCount(); i++) + { + model.getItem(i).active = (i == currentIndex) + } + } + + // get the index of the active model item on start + function getActiveIndex() + { + for (var i = 0; i < model.rowCount(); i++) + { + print(model.getItem(i).active) + if (model.getItem(i).active) + { + return i; + } + } + return 0 + } + + onCurrentIndexChanged: + { + if (model.getItem(currentIndex).id != undefined) + { + UM.Controller.setActiveView(model.getItem(currentIndex).id) + } + } + currentIndex: getActiveIndex() + } + + Cura.PrintSetupSelector + { + width: UM.Theme.getSize("print_setup_widget").width + onShowTooltip: previewMenu.showTooltip(item, location, text) + onHideTooltip: previewMenu.hideTooltip() + } + } +} \ No newline at end of file diff --git a/plugins/PreviewStage/PreviewStage.py b/plugins/PreviewStage/PreviewStage.py index a51bf766b6..4c449e55f2 100644 --- a/plugins/PreviewStage/PreviewStage.py +++ b/plugins/PreviewStage/PreviewStage.py @@ -1,13 +1,31 @@ # Copyright (c) 2018 Ultimaker B.V. # Cura is released under the terms of the LGPLv3 or higher. +import os.path + from UM.Application import Application from cura.Stages.CuraStage import CuraStage +from typing import TYPE_CHECKING, Optional + +if TYPE_CHECKING: + from UM.View import View class PreviewStage(CuraStage): - def __init__(self, parent = None) -> None: + def __init__(self, application: Application, parent = None) -> None: super().__init__(parent) - Application.getInstance().engineCreatedSignal.connect(self._engineCreated) + self._application = application + self._application.engineCreatedSignal.connect(self._engineCreated) + self._previously_active_view = None # type: Optional[View] - def _engineCreated(self): - return \ No newline at end of file + def onStageSelected(self) -> None: + self._previously_active_view = self._application.getController().getActiveView() + + def onStageDeselected(self) -> None: + if self._previously_active_view is not None: + self._application.getController().setActiveView(self._previously_active_view.getPluginId()) + self._previously_active_view = None + + def _engineCreated(self) -> None: + menu_component_path = os.path.join(self._application.getPluginRegistry().getPluginPath(self.getPluginId()), + "PreviewMenu.qml") + self.addDisplayComponent("menu", menu_component_path) diff --git a/plugins/PreviewStage/__init__.py b/plugins/PreviewStage/__init__.py index e03992fc00..d58826934e 100644 --- a/plugins/PreviewStage/__init__.py +++ b/plugins/PreviewStage/__init__.py @@ -18,5 +18,5 @@ def getMetaData(): def register(app): return { - "stage": PreviewStage.PreviewStage() + "stage": PreviewStage.PreviewStage(app) } diff --git a/resources/qml/Cura.qml b/resources/qml/Cura.qml index 3e2515cb3e..c3d2c98ecc 100644 --- a/resources/qml/Cura.qml +++ b/resources/qml/Cura.qml @@ -230,68 +230,6 @@ UM.MainWindow } } - ComboBox - { - // This item contains the views selector, a combobox that is dynamically created from - // the list of available Views (packages that create different visualizations of the - // scene). - id: viewModeButton - - anchors.left: viewOrientationControls.right - anchors.bottom: viewOrientationControls.bottom - - style: UM.Theme.styles.combobox - - model: UM.ViewModel { } - textRole: "name" - - // update the model's active index - function updateItemActiveFlags() - { - currentIndex = getActiveIndex() - for (var i = 0; i < model.rowCount(); i++) - { - model.getItem(i).active = (i == currentIndex) - } - } - - // get the index of the active model item on start - function getActiveIndex () - { - for (var i = 0; i < model.rowCount(); i++) - { - if (model.getItem(i).active) - { - return i; - } - } - return 0 - } - - // set the active index - function setActiveIndex(index) - { - UM.Controller.setActiveView(index) - // the connection to UM.ActiveView will trigger update so there is no reason to call it manually here - } - - onCurrentIndexChanged: - { - if (model.getItem(currentIndex).id != undefined) - { - viewModeButton.setActiveIndex(model.getItem(currentIndex).id) - } - } - currentIndex: getActiveIndex() - - // watch the active view proxy for changes made from the menu item - Connections - { - target: UM.ActiveView - onActiveViewChanged: viewModeButton.updateItemActiveFlags() - } - } - Loader { id: viewPanel diff --git a/resources/qml/MainWindow/ApplicationMenu.qml b/resources/qml/MainWindow/ApplicationMenu.qml index d3bc115419..884609deee 100644 --- a/resources/qml/MainWindow/ApplicationMenu.qml +++ b/resources/qml/MainWindow/ApplicationMenu.qml @@ -45,8 +45,6 @@ Item MenuItem { action: Cura.Actions.unGroupObjects } } - ViewMenu { title: catalog.i18nc("@title:menu menubar:toplevel", "&View") } - SettingsMenu { title: catalog.i18nc("@title:menu menubar:toplevel", "&Settings") } Menu From ebe533bdc831c9872d3d0c352e73134656de253e Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Mon, 29 Oct 2018 13:39:00 +0100 Subject: [PATCH 03/21] Move active view panel to previewStage CURA-5829 --- plugins/PreviewStage/PreviewMenu.qml | 15 +++++++++++++++ resources/qml/Cura.qml | 16 ---------------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/plugins/PreviewStage/PreviewMenu.qml b/plugins/PreviewStage/PreviewMenu.qml index c364c4c3d7..0ab1c0be83 100644 --- a/plugins/PreviewStage/PreviewMenu.qml +++ b/plugins/PreviewStage/PreviewMenu.qml @@ -21,6 +21,8 @@ Item Row { anchors.horizontalCenter: parent.horizontalCenter + spacing: UM.Theme.getSize("default_margin").width + ComboBox { // This item contains the views selector, a combobox that is dynamically created from @@ -67,6 +69,19 @@ Item currentIndex: getActiveIndex() } + Loader + { + // TODO: Make this panel collapsable and ensure it has a standardised background. + id: viewPanel + + property var buttonTarget: Qt.point(viewModeButton.x + Math.round(viewModeButton.width / 2), viewModeButton.y + Math.round(viewModeButton.height / 2)) + + height: childrenRect.height + width: childrenRect.width + + source: UM.ActiveView.valid ? UM.ActiveView.activeViewPanel : "" + } + Cura.PrintSetupSelector { width: UM.Theme.getSize("print_setup_widget").width diff --git a/resources/qml/Cura.qml b/resources/qml/Cura.qml index c3d2c98ecc..9f53b75dd1 100644 --- a/resources/qml/Cura.qml +++ b/resources/qml/Cura.qml @@ -230,22 +230,6 @@ UM.MainWindow } } - Loader - { - id: viewPanel - - anchors.bottom: viewModeButton.top - anchors.topMargin: UM.Theme.getSize("default_margin").height - anchors.right: viewModeButton.right - - property var buttonTarget: Qt.point(viewModeButton.x + Math.round(viewModeButton.width / 2), viewModeButton.y + Math.round(viewModeButton.height / 2)) - - height: childrenRect.height - width: childrenRect.width - - source: UM.ActiveView.valid ? UM.ActiveView.activeViewPanel : "" - } - Cura.ActionPanelWidget { anchors.right: parent.right From fc6ad4f6233833a2b59d4086306a21e1de3427f4 Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Mon, 29 Oct 2018 13:41:46 +0100 Subject: [PATCH 04/21] Put back the view menu, since it did more than just show the views CURA-5829 --- resources/qml/MainWindow/ApplicationMenu.qml | 2 ++ resources/qml/Menus/ViewMenu.qml | 19 ------------------- 2 files changed, 2 insertions(+), 19 deletions(-) diff --git a/resources/qml/MainWindow/ApplicationMenu.qml b/resources/qml/MainWindow/ApplicationMenu.qml index 884609deee..d3bc115419 100644 --- a/resources/qml/MainWindow/ApplicationMenu.qml +++ b/resources/qml/MainWindow/ApplicationMenu.qml @@ -45,6 +45,8 @@ Item MenuItem { action: Cura.Actions.unGroupObjects } } + ViewMenu { title: catalog.i18nc("@title:menu menubar:toplevel", "&View") } + SettingsMenu { title: catalog.i18nc("@title:menu menubar:toplevel", "&Settings") } Menu diff --git a/resources/qml/Menus/ViewMenu.qml b/resources/qml/Menus/ViewMenu.qml index 593bd63bcc..33e8764cd8 100644 --- a/resources/qml/Menus/ViewMenu.qml +++ b/resources/qml/Menus/ViewMenu.qml @@ -15,25 +15,6 @@ Menu property var multiBuildPlateModel: CuraApplication.getMultiBuildPlateModel() - // main views - Instantiator - { - model: UM.ViewModel{} - MenuItem - { - text: model.name - checkable: true - checked: model.active - exclusiveGroup: group - onTriggered: UM.Controller.setActiveView(model.id) - } - onObjectAdded: base.insertItem(index, object) - onObjectRemoved: base.removeItem(object) - } - ExclusiveGroup { id: group } - - MenuSeparator {} - Menu { title: catalog.i18nc("@action:inmenu menubar:view","&Camera position"); From cfa962311bb45476fcc9e65dd24933bb9f2aa397 Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Mon, 29 Oct 2018 13:54:20 +0100 Subject: [PATCH 05/21] Fixed typing CURA-5829 --- plugins/PreviewStage/PreviewStage.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/plugins/PreviewStage/PreviewStage.py b/plugins/PreviewStage/PreviewStage.py index 4c449e55f2..e41d4a592f 100644 --- a/plugins/PreviewStage/PreviewStage.py +++ b/plugins/PreviewStage/PreviewStage.py @@ -2,16 +2,17 @@ # Cura is released under the terms of the LGPLv3 or higher. import os.path -from UM.Application import Application +from UM.Qt.QtApplication import QtApplication from cura.Stages.CuraStage import CuraStage from typing import TYPE_CHECKING, Optional if TYPE_CHECKING: - from UM.View import View + from UM.View.View import View + class PreviewStage(CuraStage): - def __init__(self, application: Application, parent = None) -> None: + def __init__(self, application: QtApplication, parent = None) -> None: super().__init__(parent) self._application = application self._application.engineCreatedSignal.connect(self._engineCreated) @@ -26,6 +27,7 @@ class PreviewStage(CuraStage): self._previously_active_view = None def _engineCreated(self) -> None: - menu_component_path = os.path.join(self._application.getPluginRegistry().getPluginPath(self.getPluginId()), - "PreviewMenu.qml") - self.addDisplayComponent("menu", menu_component_path) + plugin_path = self._application.getPluginRegistry().getPluginPath(self.getPluginId()) + if plugin_path is not None: + menu_component_path = os.path.join(plugin_path, "PreviewMenu.qml") + self.addDisplayComponent("menu", menu_component_path) From d8dd9bf3631bcfd5cd77d11cb41688127dd31e60 Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Mon, 29 Oct 2018 14:54:42 +0100 Subject: [PATCH 06/21] Set SolidView to invisible. Since we don't have a selector in the prepare stage anymore, solidview must be invisible CURA-5829 --- plugins/PreviewStage/PreviewMenu.qml | 1 - plugins/SolidView/__init__.py | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/PreviewStage/PreviewMenu.qml b/plugins/PreviewStage/PreviewMenu.qml index 0ab1c0be83..ae875fb0a2 100644 --- a/plugins/PreviewStage/PreviewMenu.qml +++ b/plugins/PreviewStage/PreviewMenu.qml @@ -50,7 +50,6 @@ Item { for (var i = 0; i < model.rowCount(); i++) { - print(model.getItem(i).active) if (model.getItem(i).active) { return i; diff --git a/plugins/SolidView/__init__.py b/plugins/SolidView/__init__.py index db2e48f489..34148fcf05 100644 --- a/plugins/SolidView/__init__.py +++ b/plugins/SolidView/__init__.py @@ -10,7 +10,8 @@ def getMetaData(): return { "view": { "name": i18n_catalog.i18nc("@item:inmenu", "Solid view"), - "weight": 0 + "weight": 0, + "visible": False } } From 0a3803d6651c66cb81fb9d2b82187fe79736aac3 Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Mon, 29 Oct 2018 16:21:16 +0100 Subject: [PATCH 07/21] Add CuraView, which does something similar to CuraStage So instead of relying on strange activeViewProxy, it's up to the CuraView to provide a set of components. These can subsequently be used by the active stage again. CURA-5829 --- cura/CuraView.py | 24 ++++++++++++++++++++++++ plugins/PreviewStage/PreviewMenu.qml | 2 +- plugins/SimulationView/SimulationView.py | 15 +++++++++++---- plugins/SimulationView/__init__.py | 3 +++ 4 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 cura/CuraView.py diff --git a/cura/CuraView.py b/cura/CuraView.py new file mode 100644 index 0000000000..978c651b43 --- /dev/null +++ b/cura/CuraView.py @@ -0,0 +1,24 @@ +# Copyright (c) 2018 Ultimaker B.V. +# Cura is released under the terms of the LGPLv3 or higher. + +from PyQt5.QtCore import pyqtProperty, QUrl + +from UM.View.View import View + + +# Since Cura has a few pre-defined "space claims" for the locations of certain components, we've provided some structure +# to indicate this. +# MainComponent works in the same way the MainComponent of a stage. +# the stageMenuComponent returns an item that should be used somehwere in the stage menu. It's up to the active stage +# to actually do something with this. +class CuraView(View): + def __init__(self, parent = None) -> None: + super().__init__(parent) + + @pyqtProperty(QUrl, constant = True) + def mainComponent(self) -> QUrl: + return self.getDisplayComponent("main") + + @pyqtProperty(QUrl, constant = True) + def stageMenuComponent(self) -> QUrl: + return self.getDisplayComponent("menu") \ No newline at end of file diff --git a/plugins/PreviewStage/PreviewMenu.qml b/plugins/PreviewStage/PreviewMenu.qml index ae875fb0a2..5ed0e697a9 100644 --- a/plugins/PreviewStage/PreviewMenu.qml +++ b/plugins/PreviewStage/PreviewMenu.qml @@ -78,7 +78,7 @@ Item height: childrenRect.height width: childrenRect.width - source: UM.ActiveView.valid ? UM.ActiveView.activeViewPanel : "" + source: UM.Controller.activeView != null && UM.Controller.activeView.stageMenuComponent != null ? UM.Controller.activeView.stageMenuComponent : "" } Cura.PrintSetupSelector diff --git a/plugins/SimulationView/SimulationView.py b/plugins/SimulationView/SimulationView.py index 0ae8b4d9e4..0ef08b22d7 100644 --- a/plugins/SimulationView/SimulationView.py +++ b/plugins/SimulationView/SimulationView.py @@ -26,8 +26,8 @@ from UM.View.GL.OpenGL import OpenGL from UM.View.GL.OpenGLContext import OpenGLContext from UM.View.GL.ShaderProgram import ShaderProgram -from UM.View.View import View from UM.i18n import i18nCatalog +from cura.CuraView import CuraView from cura.Scene.ConvexHullNode import ConvexHullNode from cura.CuraApplication import CuraApplication @@ -48,15 +48,15 @@ catalog = i18nCatalog("cura") ## View used to display g-code paths. -class SimulationView(View): +class SimulationView(CuraView): # Must match SimulationView.qml LAYER_VIEW_TYPE_MATERIAL_TYPE = 0 LAYER_VIEW_TYPE_LINE_TYPE = 1 LAYER_VIEW_TYPE_FEEDRATE = 2 LAYER_VIEW_TYPE_THICKNESS = 3 - def __init__(self) -> None: - super().__init__() + def __init__(self, parent = None) -> None: + super().__init__(parent) self._max_layers = 0 self._current_layer_num = 0 @@ -113,6 +113,13 @@ class SimulationView(View): self._wireprint_warning_message = Message(catalog.i18nc("@info:status", "Cura does not accurately display layers when Wire Printing is enabled"), title = catalog.i18nc("@info:title", "Simulation View")) + Application.getInstance().engineCreatedSignal.connect(self._onEngineCreated) + + def _onEngineCreated(self) -> None: + menu_component_path = os.path.join(PluginRegistry.getInstance().getPluginPath("SimulationView"), + "SimulationView.qml") + self.addDisplayComponent("menu", menu_component_path) + def _evaluateCompatibilityMode(self) -> bool: return OpenGLContext.isLegacyOpenGL() or bool(Application.getInstance().getPreferences().getValue("view/force_layer_view_compatibility_mode")) diff --git a/plugins/SimulationView/__init__.py b/plugins/SimulationView/__init__.py index 360fdc1de9..3f89ee490f 100644 --- a/plugins/SimulationView/__init__.py +++ b/plugins/SimulationView/__init__.py @@ -8,6 +8,7 @@ from . import SimulationViewProxy, SimulationView catalog = i18nCatalog("cura") + def getMetaData(): return { "view": { @@ -17,9 +18,11 @@ def getMetaData(): } } + def createSimulationViewProxy(engine, script_engine): return SimulationViewProxy.SimulationViewProxy() + def register(app): simulation_view = SimulationView.SimulationView() qmlRegisterSingletonType(SimulationViewProxy.SimulationViewProxy, "UM", 1, 0, "SimulationView", simulation_view.getProxy) From f7730302187667e74a883e061f237440a0b90521 Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Wed, 31 Oct 2018 09:37:21 +0100 Subject: [PATCH 08/21] Add main stage to previewStage so that SimulationView can use it CURA-5829 --- plugins/PreviewStage/PreviewMain.qml | 19 ++ plugins/PreviewStage/PreviewStage.py | 2 + plugins/SimulationView/SimulationView.py | 7 +- .../SimulationViewMainComponent.qml | 212 +++++++++++++++++ ...ew.qml => SimulationViewMenuComponent.qml} | 224 ------------------ plugins/SimulationView/__init__.py | 1 - resources/qml/Cura.qml | 57 +++-- 7 files changed, 272 insertions(+), 250 deletions(-) create mode 100644 plugins/PreviewStage/PreviewMain.qml create mode 100644 plugins/SimulationView/SimulationViewMainComponent.qml rename plugins/SimulationView/{SimulationView.qml => SimulationViewMenuComponent.qml} (75%) diff --git a/plugins/PreviewStage/PreviewMain.qml b/plugins/PreviewStage/PreviewMain.qml new file mode 100644 index 0000000000..df7e09225f --- /dev/null +++ b/plugins/PreviewStage/PreviewMain.qml @@ -0,0 +1,19 @@ +// Copyright (c) 2018 Ultimaker B.V. +// Cura is released under the terms of the LGPLv3 or higher. + +import QtQuick 2.4 +import QtQuick.Controls 1.2 +import QtQuick.Layouts 1.1 +import QtQuick.Controls.Styles 1.1 + +import UM 1.0 as UM +import Cura 1.0 as Cura + + +Loader +{ + id: previewMain + + source: UM.Controller.activeView != null && UM.Controller.activeView.mainComponent != null ? UM.Controller.activeView.mainComponent : "" + onSourceChanged: print("THE SOURCE IS", source) +} \ No newline at end of file diff --git a/plugins/PreviewStage/PreviewStage.py b/plugins/PreviewStage/PreviewStage.py index e41d4a592f..1aed95162a 100644 --- a/plugins/PreviewStage/PreviewStage.py +++ b/plugins/PreviewStage/PreviewStage.py @@ -30,4 +30,6 @@ class PreviewStage(CuraStage): plugin_path = self._application.getPluginRegistry().getPluginPath(self.getPluginId()) if plugin_path is not None: menu_component_path = os.path.join(plugin_path, "PreviewMenu.qml") + main_component_path = os.path.join(plugin_path, "PreviewMain.qml") self.addDisplayComponent("menu", menu_component_path) + self.addDisplayComponent("main", main_component_path) diff --git a/plugins/SimulationView/SimulationView.py b/plugins/SimulationView/SimulationView.py index 0ef08b22d7..f1bff5f3f7 100644 --- a/plugins/SimulationView/SimulationView.py +++ b/plugins/SimulationView/SimulationView.py @@ -117,7 +117,12 @@ class SimulationView(CuraView): def _onEngineCreated(self) -> None: menu_component_path = os.path.join(PluginRegistry.getInstance().getPluginPath("SimulationView"), - "SimulationView.qml") + "SimulationViewMenuComponent.qml") + + main_component_path = os.path.join(PluginRegistry.getInstance().getPluginPath("SimulationView"), + "SimulationViewMainComponent.qml") + + self.addDisplayComponent("main", main_component_path) self.addDisplayComponent("menu", menu_component_path) def _evaluateCompatibilityMode(self) -> bool: diff --git a/plugins/SimulationView/SimulationViewMainComponent.qml b/plugins/SimulationView/SimulationViewMainComponent.qml new file mode 100644 index 0000000000..a4ec411124 --- /dev/null +++ b/plugins/SimulationView/SimulationViewMainComponent.qml @@ -0,0 +1,212 @@ +// Copyright (c) 2018 Ultimaker B.V. +// Cura is released under the terms of the LGPLv3 or higher. + +import QtQuick 2.4 +import QtQuick.Controls 1.2 +import QtQuick.Layouts 1.1 +import QtQuick.Controls.Styles 1.1 + +import UM 1.0 as UM +import Cura 1.0 as Cura + +Item +{ + property bool is_simulation_playing: false + visible: UM.SimulationView.layerActivity && CuraApplication.platformActivity + + PathSlider + { + id: pathSlider + height: UM.Theme.getSize("slider_handle").width + width: 250 + + anchors.bottom: parent.bottom + anchors.bottomMargin: UM.Theme.getSize("default_margin").height + + anchors.horizontalCenter: parent.horizontalCenter + + visible: !UM.SimulationView.compatibilityMode + + // Custom properties + handleValue: UM.SimulationView.currentPath + maximumValue: UM.SimulationView.numPaths + handleSize: UM.Theme.getSize("slider_handle").width + trackThickness: UM.Theme.getSize("slider_groove").width + trackColor: UM.Theme.getColor("slider_groove") + trackBorderColor: UM.Theme.getColor("slider_groove_border") + handleColor: UM.Theme.getColor("slider_handle") + handleActiveColor: UM.Theme.getColor("slider_handle_active") + rangeColor: UM.Theme.getColor("slider_groove_fill") + + // Update values when layer data changes. + Connections + { + target: UM.SimulationView + onMaxPathsChanged: pathSlider.setHandleValue(UM.SimulationView.currentPath) + onCurrentPathChanged: + { + // Only pause the simulation when the layer was changed manually, not when the simulation is running + if (pathSlider.manuallyChanged) + { + playButton.pauseSimulation() + } + pathSlider.setHandleValue(UM.SimulationView.currentPath) + } + } + + // Ensure that the slider handlers show the correct value after switching views. + Component.onCompleted: + { + pathSlider.setHandleValue(UM.SimulationView.currentPath) + } + + } + + Button + { + id: playButton + iconSource: !is_simulation_playing ? "./resources/simulation_resume.svg": "./resources/simulation_pause.svg" + style: UM.Theme.styles.small_tool_button + visible: !UM.SimulationView.compatibilityMode + anchors + { + right: pathSlider.left + verticalCenter: pathSlider.verticalCenter + } + + onClicked: + { + if(is_simulation_playing) + { + pauseSimulation() + } else + { + resumeSimulation() + } + } + + function pauseSimulation() + { + UM.SimulationView.setSimulationRunning(false) + simulationTimer.stop() + is_simulation_playing = false + layerSlider.manuallyChanged = true + pathSlider.manuallyChanged = true + } + + function resumeSimulation() + { + UM.SimulationView.setSimulationRunning(true) + simulationTimer.start() + layerSlider.manuallyChanged = false + pathSlider.manuallyChanged = false + } + } + + Timer + { + id: simulationTimer + interval: 100 + running: false + repeat: true + onTriggered: + { + var currentPath = UM.SimulationView.currentPath + var numPaths = UM.SimulationView.numPaths + var currentLayer = UM.SimulationView.currentLayer + var numLayers = UM.SimulationView.numLayers + + // 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 (currentPath >= numPaths) + { + UM.SimulationView.setCurrentPath(0) + } + else + { + UM.SimulationView.setCurrentPath(currentPath + 1) + } + } + // If the simulation is already playing and we reach the end of a layer, then it automatically + // starts at the beginning of the next layer. + else + { + if (currentPath >= numPaths) + { + // At the end of the model, the simulation stops + if (currentLayer >= numLayers) + { + playButton.pauseSimulation() + } + else + { + UM.SimulationView.setCurrentLayer(currentLayer+1) + UM.SimulationView.setCurrentPath(0) + } + } + else + { + UM.SimulationView.setCurrentPath(currentPath+1) + } + } + // 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 + } + } + + LayerSlider + { + id: layerSlider + + width: UM.Theme.getSize("slider_handle").width + height: UM.Theme.getSize("layerview_menu_size").height + + anchors + { + right: parent.right + verticalCenter: parent.verticalCenter + rightMargin: UM.Theme.getSize("default_margin").width + } + + // Custom properties + upperValue: UM.SimulationView.currentLayer + lowerValue: UM.SimulationView.minimumLayer + maximumValue: UM.SimulationView.numLayers + handleSize: UM.Theme.getSize("slider_handle").width + trackThickness: UM.Theme.getSize("slider_groove").width + trackColor: UM.Theme.getColor("slider_groove") + trackBorderColor: UM.Theme.getColor("slider_groove_border") + upperHandleColor: UM.Theme.getColor("slider_handle") + lowerHandleColor: UM.Theme.getColor("slider_handle") + rangeHandleColor: UM.Theme.getColor("slider_groove_fill") + handleActiveColor: UM.Theme.getColor("slider_handle_active") + handleLabelWidth: UM.Theme.getSize("slider_layerview_background").width + + // Update values when layer data changes + Connections + { + target: UM.SimulationView + onMaxLayersChanged: layerSlider.setUpperValue(UM.SimulationView.currentLayer) + onMinimumLayerChanged: layerSlider.setLowerValue(UM.SimulationView.minimumLayer) + onCurrentLayerChanged: + { + // Only pause the simulation when the layer was changed manually, not when the simulation is running + if (layerSlider.manuallyChanged) + { + playButton.pauseSimulation() + } + layerSlider.setUpperValue(UM.SimulationView.currentLayer) + } + } + + // Make sure the slider handlers show the correct value after switching views + Component.onCompleted: + { + layerSlider.setLowerValue(UM.SimulationView.minimumLayer) + layerSlider.setUpperValue(UM.SimulationView.currentLayer) + } + } +} \ No newline at end of file diff --git a/plugins/SimulationView/SimulationView.qml b/plugins/SimulationView/SimulationViewMenuComponent.qml similarity index 75% rename from plugins/SimulationView/SimulationView.qml rename to plugins/SimulationView/SimulationViewMenuComponent.qml index 7a83a07ac1..91ef7a2794 100644 --- a/plugins/SimulationView/SimulationView.qml +++ b/plugins/SimulationView/SimulationViewMenuComponent.qml @@ -583,230 +583,6 @@ Item } } - Item - { - id: slidersBox - - width: parent.width - height: parent.height - visible: UM.SimulationView.layerActivity && CuraApplication.platformActivity - - anchors - { - top: parent.top - leftMargin: UM.Theme.getSize("slider_layerview_margin").height - left: parent.right - } - - PathSlider - { - id: pathSlider - - height: UM.Theme.getSize("slider_handle").width - anchors - { - verticalCenter: playButton.verticalCenter - left: playButton.right - leftMargin: UM.Theme.getSize("default_margin").width - right: parent.right - } - visible: !UM.SimulationView.compatibilityMode - - // custom properties - handleValue: UM.SimulationView.currentPath - maximumValue: UM.SimulationView.numPaths - handleSize: UM.Theme.getSize("slider_handle").width - trackThickness: UM.Theme.getSize("slider_groove").width - trackColor: UM.Theme.getColor("slider_groove") - trackBorderColor: UM.Theme.getColor("slider_groove_border") - handleColor: UM.Theme.getColor("slider_handle") - handleActiveColor: UM.Theme.getColor("slider_handle_active") - rangeColor: UM.Theme.getColor("slider_groove_fill") - - // update values when layer data changes - Connections - { - target: UM.SimulationView - onMaxPathsChanged: pathSlider.setHandleValue(UM.SimulationView.currentPath) - onCurrentPathChanged: - { - // Only pause the simulation when the layer was changed manually, not when the simulation is running - if (pathSlider.manuallyChanged) - { - playButton.pauseSimulation() - } - pathSlider.setHandleValue(UM.SimulationView.currentPath) - } - } - - // make sure the slider handlers show the correct value after switching views - Component.onCompleted: - { - pathSlider.setHandleValue(UM.SimulationView.currentPath) - } - } - - LayerSlider - { - id: layerSlider - - width: UM.Theme.getSize("slider_handle").width - height: UM.Theme.getSize("layerview_menu_size").height - - anchors - { - bottom: !UM.SimulationView.compatibilityMode ? pathSlider.top : parent.bottom - top: parent.top - bottomMargin: !UM.SimulationView.compatibilityMode ? UM.Theme.getSize("default_margin").height : 0 - left: parent.left - leftMargin: Math.round(UM.Theme.getSize("slider_layerview_margin").width / 2) - } - - // custom properties - upperValue: UM.SimulationView.currentLayer - lowerValue: UM.SimulationView.minimumLayer - maximumValue: UM.SimulationView.numLayers - handleSize: UM.Theme.getSize("slider_handle").width - trackThickness: UM.Theme.getSize("slider_groove").width - trackColor: UM.Theme.getColor("slider_groove") - trackBorderColor: UM.Theme.getColor("slider_groove_border") - upperHandleColor: UM.Theme.getColor("slider_handle") - lowerHandleColor: UM.Theme.getColor("slider_handle") - rangeHandleColor: UM.Theme.getColor("slider_groove_fill") - handleActiveColor: UM.Theme.getColor("slider_handle_active") - handleLabelWidth: UM.Theme.getSize("slider_layerview_background").width - - // update values when layer data changes - Connections - { - target: UM.SimulationView - onMaxLayersChanged: layerSlider.setUpperValue(UM.SimulationView.currentLayer) - onMinimumLayerChanged: layerSlider.setLowerValue(UM.SimulationView.minimumLayer) - onCurrentLayerChanged: - { - // Only pause the simulation when the layer was changed manually, not when the simulation is running - if (layerSlider.manuallyChanged) - { - playButton.pauseSimulation() - } - layerSlider.setUpperValue(UM.SimulationView.currentLayer) - } - } - - // make sure the slider handlers show the correct value after switching views - Component.onCompleted: - { - layerSlider.setLowerValue(UM.SimulationView.minimumLayer) - layerSlider.setUpperValue(UM.SimulationView.currentLayer) - } - } - - // Play simulation button - Button - { - id: playButton - iconSource: "./resources/simulation_resume.svg" - style: UM.Theme.styles.small_tool_button - visible: !UM.SimulationView.compatibilityMode - anchors - { - left: parent.left - bottom: parent.bottom - } - - property var status: 0 // indicates if it's stopped (0) or playing (1) - - onClicked: - { - switch(status) - { - case 0: - { - resumeSimulation() - break - } - case 1: - { - pauseSimulation() - break - } - } - } - - function pauseSimulation() - { - UM.SimulationView.setSimulationRunning(false) - iconSource = "./resources/simulation_resume.svg" - simulationTimer.stop() - status = 0 - layerSlider.manuallyChanged = true - pathSlider.manuallyChanged = true - } - - function resumeSimulation() - { - UM.SimulationView.setSimulationRunning(true) - iconSource = "./resources/simulation_pause.svg" - simulationTimer.start() - layerSlider.manuallyChanged = false - pathSlider.manuallyChanged = false - } - } - - Timer - { - id: simulationTimer - interval: 100 - running: false - repeat: true - onTriggered: - { - var currentPath = UM.SimulationView.currentPath - var numPaths = UM.SimulationView.numPaths - var currentLayer = UM.SimulationView.currentLayer - var numLayers = UM.SimulationView.numLayers - // 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 (playButton.status == 0) - { - if (currentPath >= numPaths) - { - UM.SimulationView.setCurrentPath(0) - } - else - { - UM.SimulationView.setCurrentPath(currentPath+1) - } - } - // If the simulation is already playing and we reach the end of a layer, then it automatically - // starts at the beginning of the next layer. - else - { - if (currentPath >= numPaths) - { - // At the end of the model, the simulation stops - if (currentLayer >= numLayers) - { - playButton.pauseSimulation() - } - else - { - UM.SimulationView.setCurrentLayer(currentLayer+1) - UM.SimulationView.setCurrentPath(0) - } - } - else - { - UM.SimulationView.setCurrentPath(currentPath+1) - } - } - // 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. - playButton.status = 1 - } - } - } - FontMetrics { id: fontMetrics diff --git a/plugins/SimulationView/__init__.py b/plugins/SimulationView/__init__.py index 3f89ee490f..b12e582441 100644 --- a/plugins/SimulationView/__init__.py +++ b/plugins/SimulationView/__init__.py @@ -13,7 +13,6 @@ def getMetaData(): return { "view": { "name": catalog.i18nc("@item:inlistbox", "Layer view"), - "view_panel": "SimulationView.qml", "weight": 2 } } diff --git a/resources/qml/Cura.qml b/resources/qml/Cura.qml index 9f53b75dd1..e49683cb8e 100644 --- a/resources/qml/Cura.qml +++ b/resources/qml/Cura.qml @@ -155,24 +155,6 @@ UM.MainWindow color: UM.Theme.getColor("main_window_header_background") } - Loader - { - // The stage menu is, as the name implies, a menu that is defined by the active stage. - // Note that this menu does not need to be set at all! It's perfectly acceptable to have a stage - // without this menu! - id: stageMenu - - anchors - { - left: parent.left - right: parent.right - top: parent.top - } - - height: UM.Theme.getSize("stage_menu").height - source: UM.Controller.activeStage != null ? UM.Controller.activeStage.stageMenuComponent : "" - } - Connections { target: stageMenu.item @@ -230,6 +212,22 @@ UM.MainWindow } } + Loader + { + id: viewPanel + + anchors.bottom: viewModeButton.top + anchors.topMargin: UM.Theme.getSize("default_margin").height + anchors.right: viewModeButton.right + + property var buttonTarget: Qt.point(viewModeButton.x + Math.round(viewModeButton.width / 2), viewModeButton.y + Math.round(viewModeButton.height / 2)) + + height: childrenRect.height + width: childrenRect.width + + source: UM.ActiveView.valid ? UM.ActiveView.activeViewPanel : "" + } + Cura.ActionPanelWidget { anchors.right: parent.right @@ -254,15 +252,26 @@ UM.MainWindow anchors.fill: parent - MouseArea + source: UM.Controller.activeStage != null ? UM.Controller.activeStage.mainComponent : "" + } + + + Loader + { + // The stage menu is, as the name implies, a menu that is defined by the active stage. + // Note that this menu does not need to be set at all! It's perfectly acceptable to have a stage + // without this menu! + id: stageMenu + + anchors { - visible: parent.source != "" - anchors.fill: parent - acceptedButtons: Qt.AllButtons - onWheel: wheel.accepted = true + left: parent.left + right: parent.right + top: parent.top } - source: UM.Controller.activeStage != null ? UM.Controller.activeStage.mainComponent : "" + height: UM.Theme.getSize("stage_menu").height + source: UM.Controller.activeStage != null ? UM.Controller.activeStage.stageMenuComponent : "" } UM.MessageStack From 3fc399a6443ffa0caf7fef0288c14b7b59c50cfe Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Wed, 31 Oct 2018 09:46:41 +0100 Subject: [PATCH 09/21] Moved default values into components CURA-5829 --- plugins/SimulationView/LayerSlider.qml | 22 +++++++++---------- plugins/SimulationView/PathSlider.qml | 14 ++++++------ .../SimulationViewMainComponent.qml | 16 -------------- .../SimulationViewMenuComponent.qml | 17 +++++++------- 4 files changed, 26 insertions(+), 43 deletions(-) diff --git a/plugins/SimulationView/LayerSlider.qml b/plugins/SimulationView/LayerSlider.qml index c30ea621c4..7a7aaa0649 100644 --- a/plugins/SimulationView/LayerSlider.qml +++ b/plugins/SimulationView/LayerSlider.qml @@ -13,22 +13,22 @@ Item { id: sliderRoot - // handle properties - property real handleSize: 10 + // Handle properties + property real handleSize: UM.Theme.getSize("slider_handle").width property real handleRadius: handleSize / 2 property real minimumRangeHandleSize: handleSize / 2 - property color upperHandleColor: "black" - property color lowerHandleColor: "black" - property color rangeHandleColor: "black" - property color handleActiveColor: "white" - property real handleLabelWidth: width + property color upperHandleColor: UM.Theme.getColor("slider_handle") + property color lowerHandleColor: UM.Theme.getColor("slider_handle") + property color rangeHandleColor: UM.Theme.getColor("slider_groove_fill") + property color handleActiveColor: UM.Theme.getColor("slider_handle_active") + property real handleLabelWidth: UM.Theme.getSize("slider_layerview_background").width property var activeHandle: upperHandle - // track properties - property real trackThickness: 4 // width of the slider track + // Track properties + property real trackThickness: UM.Theme.getSize("slider_groove").width // width of the slider track property real trackRadius: trackThickness / 2 - property color trackColor: "white" - property real trackBorderWidth: 1 // width of the slider track border + property color trackColor: UM.Theme.getColor("slider_groove") + property real trackBorderWidth: UM.Theme.getColor("slider_groove_border") property color trackBorderColor: "black" // value properties diff --git a/plugins/SimulationView/PathSlider.qml b/plugins/SimulationView/PathSlider.qml index f3c28fb5f7..701e54e398 100644 --- a/plugins/SimulationView/PathSlider.qml +++ b/plugins/SimulationView/PathSlider.qml @@ -14,19 +14,19 @@ Item id: sliderRoot // handle properties - property real handleSize: 10 + property real handleSize: UM.Theme.getSize("slider_handle").width property real handleRadius: handleSize / 2 - property color handleColor: "black" - property color handleActiveColor: "white" - property color rangeColor: "black" + property color handleColor: UM.Theme.getColor("slider_handle") + property color handleActiveColor: UM.Theme.getColor("slider_handle_active") + property color rangeColor: UM.Theme.getColor("slider_groove_fill") property real handleLabelWidth: width // track properties - property real trackThickness: 4 // width of the slider track + property real trackThickness: UM.Theme.getSize("slider_groove").width property real trackRadius: trackThickness / 2 - property color trackColor: "white" + property color trackColor: UM.Theme.getColor("slider_groove") property real trackBorderWidth: 1 // width of the slider track border - property color trackBorderColor: "black" + property color trackBorderColor: UM.Theme.getColor("slider_groove_border") // value properties property real maximumValue: 100 diff --git a/plugins/SimulationView/SimulationViewMainComponent.qml b/plugins/SimulationView/SimulationViewMainComponent.qml index a4ec411124..2484ec25ba 100644 --- a/plugins/SimulationView/SimulationViewMainComponent.qml +++ b/plugins/SimulationView/SimulationViewMainComponent.qml @@ -30,13 +30,6 @@ Item // Custom properties handleValue: UM.SimulationView.currentPath maximumValue: UM.SimulationView.numPaths - handleSize: UM.Theme.getSize("slider_handle").width - trackThickness: UM.Theme.getSize("slider_groove").width - trackColor: UM.Theme.getColor("slider_groove") - trackBorderColor: UM.Theme.getColor("slider_groove_border") - handleColor: UM.Theme.getColor("slider_handle") - handleActiveColor: UM.Theme.getColor("slider_handle_active") - rangeColor: UM.Theme.getColor("slider_groove_fill") // Update values when layer data changes. Connections @@ -175,15 +168,6 @@ Item upperValue: UM.SimulationView.currentLayer lowerValue: UM.SimulationView.minimumLayer maximumValue: UM.SimulationView.numLayers - handleSize: UM.Theme.getSize("slider_handle").width - trackThickness: UM.Theme.getSize("slider_groove").width - trackColor: UM.Theme.getColor("slider_groove") - trackBorderColor: UM.Theme.getColor("slider_groove_border") - upperHandleColor: UM.Theme.getColor("slider_handle") - lowerHandleColor: UM.Theme.getColor("slider_handle") - rangeHandleColor: UM.Theme.getColor("slider_groove_fill") - handleActiveColor: UM.Theme.getColor("slider_handle_active") - handleLabelWidth: UM.Theme.getSize("slider_layerview_background").width // Update values when layer data changes Connections diff --git a/plugins/SimulationView/SimulationViewMenuComponent.qml b/plugins/SimulationView/SimulationViewMenuComponent.qml index 91ef7a2794..a9c7305c17 100644 --- a/plugins/SimulationView/SimulationViewMenuComponent.qml +++ b/plugins/SimulationView/SimulationViewMenuComponent.qml @@ -216,15 +216,14 @@ Item onPreferenceChanged: { layerTypeCombobox.currentIndex = UM.SimulationView.compatibilityMode ? 1 : UM.Preferences.getValue("layerview/layer_view_type"); - layerTypeCombobox.updateLegends(layerTypeCombobox.currentIndex); - playButton.pauseSimulation(); - viewSettings.extruder_opacities = UM.Preferences.getValue("layerview/extruder_opacities").split("|"); - viewSettings.show_travel_moves = UM.Preferences.getValue("layerview/show_travel_moves"); - viewSettings.show_helpers = UM.Preferences.getValue("layerview/show_helpers"); - viewSettings.show_skin = UM.Preferences.getValue("layerview/show_skin"); - viewSettings.show_infill = UM.Preferences.getValue("layerview/show_infill"); - viewSettings.only_show_top_layers = UM.Preferences.getValue("view/only_show_top_layers"); - viewSettings.top_layer_count = UM.Preferences.getValue("view/top_layer_count"); + layerTypeCombobox.updateLegends(layerTypeCombobox.currentIndex) + viewSettings.extruder_opacities = UM.Preferences.getValue("layerview/extruder_opacities").split("|") + viewSettings.show_travel_moves = UM.Preferences.getValue("layerview/show_travel_moves") + viewSettings.show_helpers = UM.Preferences.getValue("layerview/show_helpers") + viewSettings.show_skin = UM.Preferences.getValue("layerview/show_skin") + viewSettings.show_infill = UM.Preferences.getValue("layerview/show_infill") + viewSettings.only_show_top_layers = UM.Preferences.getValue("view/only_show_top_layers") + viewSettings.top_layer_count = UM.Preferences.getValue("view/top_layer_count") } } From 15f586ffae119c9f2e948ce8718095156f6275e9 Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Wed, 31 Oct 2018 10:30:11 +0100 Subject: [PATCH 10/21] Fix the location of the simulation slider label CURA-5829 --- plugins/SimulationView/LayerSlider.qml | 16 ++++++++-------- .../SimulationViewMainComponent.qml | 4 ++-- plugins/SimulationView/__init__.py | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/plugins/SimulationView/LayerSlider.qml b/plugins/SimulationView/LayerSlider.qml index 7a7aaa0649..7916cd62b3 100644 --- a/plugins/SimulationView/LayerSlider.qml +++ b/plugins/SimulationView/LayerSlider.qml @@ -28,8 +28,8 @@ Item property real trackThickness: UM.Theme.getSize("slider_groove").width // width of the slider track property real trackRadius: trackThickness / 2 property color trackColor: UM.Theme.getColor("slider_groove") - property real trackBorderWidth: UM.Theme.getColor("slider_groove_border") - property color trackBorderColor: "black" + property real trackBorderWidth: 1 + property color trackBorderColor: UM.Theme.getColor("slider_groove_border") // value properties property real maximumValue: 100 @@ -80,7 +80,7 @@ Item return Math.min(Math.max(value, sliderRoot.minimumValue), sliderRoot.maximumValue) } - // slider track + // Slider track Rectangle { id: track @@ -106,7 +106,7 @@ Item anchors.horizontalCenter: sliderRoot.horizontalCenter visible: sliderRoot.layersVisible - // set the new value when dragging + // Set the new value when dragging function onHandleDragged() { sliderRoot.manuallyChanged = true @@ -169,7 +169,7 @@ Item height: sliderRoot.handleSize + UM.Theme.getSize("default_margin").height x: parent.x + parent.width + UM.Theme.getSize("default_margin").width anchors.verticalCenter: parent.verticalCenter - target: Qt.point(sliderRoot.width, y + height / 2) + target: Qt.point(sliderRoot.width + width, y + height / 2) visible: sliderRoot.activeHandle == parent // custom properties @@ -275,7 +275,7 @@ Item id: upperHandleLabel height: sliderRoot.handleSize + UM.Theme.getSize("default_margin").height - x: parent.x + parent.width + UM.Theme.getSize("default_margin").width + x: parent.x - parent.width - width anchors.verticalCenter: parent.verticalCenter target: Qt.point(sliderRoot.width, y + height / 2) visible: sliderRoot.activeHandle == parent @@ -385,9 +385,9 @@ Item id: lowerHandleLabel height: sliderRoot.handleSize + UM.Theme.getSize("default_margin").height - x: parent.x + parent.width + UM.Theme.getSize("default_margin").width + x: parent.x - parent.width - width anchors.verticalCenter: parent.verticalCenter - target: Qt.point(sliderRoot.width, y + height / 2) + target: Qt.point(sliderRoot.width + width, y + height / 2) visible: sliderRoot.activeHandle == parent // custom properties diff --git a/plugins/SimulationView/SimulationViewMainComponent.qml b/plugins/SimulationView/SimulationViewMainComponent.qml index 2484ec25ba..5c45da6b45 100644 --- a/plugins/SimulationView/SimulationViewMainComponent.qml +++ b/plugins/SimulationView/SimulationViewMainComponent.qml @@ -135,13 +135,13 @@ Item } else { - UM.SimulationView.setCurrentLayer(currentLayer+1) + UM.SimulationView.setCurrentLayer(currentLayer + 1) UM.SimulationView.setCurrentPath(0) } } else { - UM.SimulationView.setCurrentPath(currentPath+1) + UM.SimulationView.setCurrentPath(currentPath + 1) } } // The status must be set here instead of in the resumeSimulation function otherwise it won't work diff --git a/plugins/SimulationView/__init__.py b/plugins/SimulationView/__init__.py index b12e582441..1efb7fd650 100644 --- a/plugins/SimulationView/__init__.py +++ b/plugins/SimulationView/__init__.py @@ -13,7 +13,7 @@ def getMetaData(): return { "view": { "name": catalog.i18nc("@item:inlistbox", "Layer view"), - "weight": 2 + "weight": 0 } } From 1e9aff44f635b37efc0365cce15b6f25bb980c80 Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Wed, 31 Oct 2018 10:55:05 +0100 Subject: [PATCH 11/21] Fix QML warnings & errors CURA-5829 --- plugins/PreviewStage/PreviewMain.qml | 1 - .../SimulationViewMenuComponent.qml | 58 ++++++++----------- 2 files changed, 23 insertions(+), 36 deletions(-) diff --git a/plugins/PreviewStage/PreviewMain.qml b/plugins/PreviewStage/PreviewMain.qml index df7e09225f..04241783e9 100644 --- a/plugins/PreviewStage/PreviewMain.qml +++ b/plugins/PreviewStage/PreviewMain.qml @@ -15,5 +15,4 @@ Loader id: previewMain source: UM.Controller.activeView != null && UM.Controller.activeView.mainComponent != null ? UM.Controller.activeView.mainComponent : "" - onSourceChanged: print("THE SOURCE IS", source) } \ No newline at end of file diff --git a/plugins/SimulationView/SimulationViewMenuComponent.qml b/plugins/SimulationView/SimulationViewMenuComponent.qml index a9c7305c17..5a146910e7 100644 --- a/plugins/SimulationView/SimulationViewMenuComponent.qml +++ b/plugins/SimulationView/SimulationViewMenuComponent.qml @@ -70,7 +70,8 @@ Item border.width: UM.Theme.getSize("default_lining").width border.color: UM.Theme.getColor("lining") - Button { + Button + { id: collapseButton anchors.top: parent.top anchors.topMargin: Math.round(UM.Theme.getSize("default_margin").height + (UM.Theme.getSize("layerview_row").height - UM.Theme.getSize("default_margin").height) / 2) @@ -97,7 +98,7 @@ Item } } - ColumnLayout + Column { id: viewSettings @@ -126,11 +127,10 @@ Item Label { id: layerViewTypesLabel - anchors.left: parent.left text: catalog.i18nc("@label","Color scheme") font: UM.Theme.getFont("default"); visible: !UM.SimulationView.compatibilityMode - Layout.fillWidth: true + width: parent.width color: UM.Theme.getColor("setting_control_text") } @@ -162,13 +162,10 @@ Item ComboBox { id: layerTypeCombobox - anchors.left: parent.left - Layout.fillWidth: true - Layout.preferredWidth: UM.Theme.getSize("layerview_row").width + width: parent.width model: layerViewTypes visible: !UM.SimulationView.compatibilityMode style: UM.Theme.styles.combobox - anchors.right: parent.right onActivated: { @@ -194,14 +191,12 @@ Item Label { id: compatibilityModeLabel - anchors.left: parent.left text: catalog.i18nc("@label","Compatibility Mode") font: UM.Theme.getFont("default") color: UM.Theme.getColor("text") visible: UM.SimulationView.compatibilityMode - Layout.fillWidth: true - Layout.preferredHeight: UM.Theme.getSize("layerview_row").height - Layout.preferredWidth: UM.Theme.getSize("layerview_row").width + height: UM.Theme.getSize("layerview_row").height + width: parent.width } Item @@ -253,9 +248,9 @@ Item border.color: UM.Theme.getColor("lining") visible: !viewSettings.show_legend & !viewSettings.show_gradient } - Layout.fillWidth: true - Layout.preferredHeight: UM.Theme.getSize("layerview_row").height + UM.Theme.getSize("default_lining").height - Layout.preferredWidth: UM.Theme.getSize("layerview_row").width + height: UM.Theme.getSize("layerview_row").height + UM.Theme.getSize("default_lining").height + width: parent.width + style: UM.Theme.styles.checkbox Label { @@ -264,9 +259,9 @@ Item color: UM.Theme.getColor("setting_control_text") font: UM.Theme.getFont("default") anchors.verticalCenter: parent.verticalCenter - anchors.left: extrudersModelCheckBox.left; - anchors.right: extrudersModelCheckBox.right; - anchors.leftMargin: UM.Theme.getSize("checkbox").width + Math.round(UM.Theme.getSize("default_margin").width/2) + anchors.left: extrudersModelCheckBox.left + anchors.right: extrudersModelCheckBox.right + anchors.leftMargin: UM.Theme.getSize("checkbox").width + Math.round(UM.Theme.getSize("default_margin").width / 2) anchors.rightMargin: UM.Theme.getSize("default_margin").width * 2 } } @@ -325,9 +320,8 @@ Item border.color: UM.Theme.getColor("lining") visible: viewSettings.show_legend } - Layout.fillWidth: true - Layout.preferredHeight: UM.Theme.getSize("layerview_row").height + UM.Theme.getSize("default_lining").height - Layout.preferredWidth: UM.Theme.getSize("layerview_row").width + height: UM.Theme.getSize("layerview_row").height + UM.Theme.getSize("default_lining").height + width: parent.width style: UM.Theme.styles.checkbox Label { @@ -336,9 +330,9 @@ Item elide: Text.ElideRight color: UM.Theme.getColor("setting_control_text") anchors.verticalCenter: parent.verticalCenter - anchors.left: legendModelCheckBox.left; - anchors.right: legendModelCheckBox.right; - anchors.leftMargin: UM.Theme.getSize("checkbox").width + Math.round(UM.Theme.getSize("default_margin").width/2) + anchors.left: legendModelCheckBox.left + anchors.right: legendModelCheckBox.right + anchors.leftMargin: UM.Theme.getSize("checkbox").width + Math.round(UM.Theme.getSize("default_margin").width / 2) anchors.rightMargin: UM.Theme.getSize("default_margin").width * 2 } } @@ -349,7 +343,7 @@ Item checked: viewSettings.only_show_top_layers onClicked: { - UM.Preferences.setValue("view/only_show_top_layers", checked ? 1.0 : 0.0); + UM.Preferences.setValue("view/only_show_top_layers", checked ? 1.0 : 0.0) } text: catalog.i18nc("@label", "Only Show Top Layers") visible: UM.SimulationView.compatibilityMode @@ -360,7 +354,7 @@ Item checked: viewSettings.top_layer_count == 5 onClicked: { - UM.Preferences.setValue("view/top_layer_count", checked ? 5 : 1); + UM.Preferences.setValue("view/top_layer_count", checked ? 5 : 1) } text: catalog.i18nc("@label", "Show 5 Detailed Layers On Top") visible: UM.SimulationView.compatibilityMode @@ -401,9 +395,8 @@ Item border.color: UM.Theme.getColor("lining") visible: viewSettings.show_legend } - Layout.fillWidth: true - Layout.preferredHeight: UM.Theme.getSize("layerview_row").height + UM.Theme.getSize("default_lining").height - Layout.preferredWidth: UM.Theme.getSize("layerview_row").width + height: UM.Theme.getSize("layerview_row").height + UM.Theme.getSize("default_lining").height + width: parent.width color: UM.Theme.getColor("setting_control_text") font: UM.Theme.getFont("default") } @@ -416,11 +409,6 @@ Item visible: viewSettings.show_gradient width: parent.width height: UM.Theme.getSize("layerview_row").height - anchors - { - topMargin: UM.Theme.getSize("slider_layerview_margin").height - horizontalCenter: parent.horizontalCenter - } Label { @@ -503,7 +491,7 @@ Item // Gradient colors for feedrate Rectangle - { // In QML 5.9 can be changed by LinearGradient + { // In QML 5.9 can be changed by LinearGradient // Invert values because then the bar is rotated 90 degrees id: feedrateGradient visible: viewSettings.show_feedrate_gradient From 61442545cb99dc7379ea204f0496b1464c58da27 Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Wed, 31 Oct 2018 13:56:55 +0100 Subject: [PATCH 12/21] Fix codestyle CURA-5829 --- plugins/SimulationView/SimulationView.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/plugins/SimulationView/SimulationView.py b/plugins/SimulationView/SimulationView.py index f1bff5f3f7..6a0ffc1666 100644 --- a/plugins/SimulationView/SimulationView.py +++ b/plugins/SimulationView/SimulationView.py @@ -16,6 +16,7 @@ from UM.Mesh.MeshBuilder import MeshBuilder from UM.Message import Message from UM.Platform import Platform from UM.PluginRegistry import PluginRegistry +from UM.Qt.QtApplication import QtApplication from UM.Resources import Resources from UM.Scene.Iterator.DepthFirstIterator import DepthFirstIterator @@ -113,17 +114,15 @@ class SimulationView(CuraView): self._wireprint_warning_message = Message(catalog.i18nc("@info:status", "Cura does not accurately display layers when Wire Printing is enabled"), title = catalog.i18nc("@info:title", "Simulation View")) - Application.getInstance().engineCreatedSignal.connect(self._onEngineCreated) + QtApplication.getInstance().engineCreatedSignal.connect(self._onEngineCreated) def _onEngineCreated(self) -> None: - menu_component_path = os.path.join(PluginRegistry.getInstance().getPluginPath("SimulationView"), - "SimulationViewMenuComponent.qml") - - main_component_path = os.path.join(PluginRegistry.getInstance().getPluginPath("SimulationView"), - "SimulationViewMainComponent.qml") - - self.addDisplayComponent("main", main_component_path) - self.addDisplayComponent("menu", menu_component_path) + plugin_path = PluginRegistry.getInstance().getPluginPath(self.getPluginId()) + if plugin_path: + self.addDisplayComponent("main", os.path.join(plugin_path, "SimulationViewMainComponent.qml")) + self.addDisplayComponent("menu", os.path.join(plugin_path, "SimulationViewMenuComponent.qml")) + else: + Logger.log("e", "Unable to find the path for %s", self.getPluginId()) def _evaluateCompatibilityMode(self) -> bool: return OpenGLContext.isLegacyOpenGL() or bool(Application.getInstance().getPreferences().getValue("view/force_layer_view_compatibility_mode")) From 20b3b6da79aca7c42f935e3e9b6259918c72e63a Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Fri, 2 Nov 2018 15:11:49 +0100 Subject: [PATCH 13/21] Document PreviewStage.py Some stuff I had to ask the original implementer to explain to me. So I wrote that down so that the next guy doesn't have to do that. Contributes to issue CURA-5829. --- plugins/PreviewStage/PreviewMenu.qml | 3 +++ plugins/PreviewStage/PreviewStage.py | 16 ++++++++++++++++ plugins/PreviewStage/__init__.py | 2 +- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/plugins/PreviewStage/PreviewMenu.qml b/plugins/PreviewStage/PreviewMenu.qml index 5ed0e697a9..66f7d527d9 100644 --- a/plugins/PreviewStage/PreviewMenu.qml +++ b/plugins/PreviewStage/PreviewMenu.qml @@ -1,3 +1,6 @@ +// Copyright (c) 2018 Ultimaker B.V. +// Cura is released under the terms of the LGPLv3 or higher. + import QtQuick 2.7 import QtQuick.Controls 1.4 diff --git a/plugins/PreviewStage/PreviewStage.py b/plugins/PreviewStage/PreviewStage.py index 1aed95162a..1c487c8340 100644 --- a/plugins/PreviewStage/PreviewStage.py +++ b/plugins/PreviewStage/PreviewStage.py @@ -1,5 +1,6 @@ # Copyright (c) 2018 Ultimaker B.V. # Cura is released under the terms of the LGPLv3 or higher. + import os.path from UM.Qt.QtApplication import QtApplication @@ -11,6 +12,11 @@ if TYPE_CHECKING: from UM.View.View import View +## Displays a preview of what you're about to print. +# +# The Python component of this stage just loads PreviewMain.qml for display +# when the stage is selected, and makes sure that it reverts to the previous +# view when the previous stage is activated. class PreviewStage(CuraStage): def __init__(self, application: QtApplication, parent = None) -> None: super().__init__(parent) @@ -18,14 +24,24 @@ class PreviewStage(CuraStage): self._application.engineCreatedSignal.connect(self._engineCreated) self._previously_active_view = None # type: Optional[View] + ## When selecting the stage, remember which was the previous view so that + # we can revert to that view when we go out of the stage later. def onStageSelected(self) -> None: self._previously_active_view = self._application.getController().getActiveView() + ## Called when going to a different stage (away from the Preview Stage). + # + # When going to a different stage, the view should be reverted to what it + # was before. Normally, that just reverts it to solid view. def onStageDeselected(self) -> None: if self._previously_active_view is not None: self._application.getController().setActiveView(self._previously_active_view.getPluginId()) self._previously_active_view = None + ## Delayed load of the QML files. + # + # We need to make sure that the QML engine is running before we can load + # these. def _engineCreated(self) -> None: plugin_path = self._application.getPluginRegistry().getPluginPath(self.getPluginId()) if plugin_path is not None: diff --git a/plugins/PreviewStage/__init__.py b/plugins/PreviewStage/__init__.py index d58826934e..424f573e4a 100644 --- a/plugins/PreviewStage/__init__.py +++ b/plugins/PreviewStage/__init__.py @@ -1,4 +1,4 @@ -# Copyright (c) 2017 Ultimaker B.V. +# Copyright (c) 2018 Ultimaker B.V. # Cura is released under the terms of the LGPLv3 or higher. from . import PreviewStage From 4659b0d38717afb0b693545e19501831d5b79e06 Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Mon, 5 Nov 2018 11:36:58 +0100 Subject: [PATCH 14/21] Fix codestyle --- plugins/SimulationView/SimulationViewMainComponent.qml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/SimulationView/SimulationViewMainComponent.qml b/plugins/SimulationView/SimulationViewMainComponent.qml index 5c45da6b45..69984f85cb 100644 --- a/plugins/SimulationView/SimulationViewMainComponent.qml +++ b/plugins/SimulationView/SimulationViewMainComponent.qml @@ -72,7 +72,8 @@ Item if(is_simulation_playing) { pauseSimulation() - } else + } + else { resumeSimulation() } From f0e205423f24c4e10cb2d59f4b9ec98d69c58561 Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Mon, 5 Nov 2018 11:47:22 +0100 Subject: [PATCH 15/21] Pause simulation view when preferences have been changed. I accidentally removed this feature when working on CURA-5829, but it was spotted in the review. --- plugins/SimulationView/SimulationViewMainComponent.qml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/plugins/SimulationView/SimulationViewMainComponent.qml b/plugins/SimulationView/SimulationViewMainComponent.qml index 69984f85cb..f34208e1b5 100644 --- a/plugins/SimulationView/SimulationViewMainComponent.qml +++ b/plugins/SimulationView/SimulationViewMainComponent.qml @@ -61,6 +61,16 @@ Item iconSource: !is_simulation_playing ? "./resources/simulation_resume.svg": "./resources/simulation_pause.svg" style: UM.Theme.styles.small_tool_button visible: !UM.SimulationView.compatibilityMode + + Connections + { + target: UM.Preferences + onPreferenceChanged: + { + playButton.pauseSimulation() + } + } + anchors { right: pathSlider.left From 9f13de9f0d07fde160fc49c7ca9f1f0a62b77336 Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Mon, 5 Nov 2018 11:48:19 +0100 Subject: [PATCH 16/21] No longer create two instances of the setting view. This caused a bunch of issues with the getPluginId, as one of the instances didn't got added to the registry (and as such, never got an ID) CURA-5829 --- plugins/SimulationView/SimulationViewMenuComponent.qml | 2 +- plugins/SimulationView/__init__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/SimulationView/SimulationViewMenuComponent.qml b/plugins/SimulationView/SimulationViewMenuComponent.qml index 5a146910e7..b1613dff85 100644 --- a/plugins/SimulationView/SimulationViewMenuComponent.qml +++ b/plugins/SimulationView/SimulationViewMenuComponent.qml @@ -210,7 +210,7 @@ Item target: UM.Preferences onPreferenceChanged: { - layerTypeCombobox.currentIndex = UM.SimulationView.compatibilityMode ? 1 : UM.Preferences.getValue("layerview/layer_view_type"); + layerTypeCombobox.currentIndex = UM.SimulationView.compatibilityMode ? 1 : UM.Preferences.getValue("layerview/layer_view_type") layerTypeCombobox.updateLegends(layerTypeCombobox.currentIndex) viewSettings.extruder_opacities = UM.Preferences.getValue("layerview/extruder_opacities").split("|") viewSettings.show_travel_moves = UM.Preferences.getValue("layerview/show_travel_moves") diff --git a/plugins/SimulationView/__init__.py b/plugins/SimulationView/__init__.py index 1efb7fd650..420ee60660 100644 --- a/plugins/SimulationView/__init__.py +++ b/plugins/SimulationView/__init__.py @@ -25,4 +25,4 @@ def createSimulationViewProxy(engine, script_engine): def register(app): simulation_view = SimulationView.SimulationView() qmlRegisterSingletonType(SimulationViewProxy.SimulationViewProxy, "UM", 1, 0, "SimulationView", simulation_view.getProxy) - return { "view": SimulationView.SimulationView()} + return { "view": simulation_view} From 406dd68aa4151bdc40dde21f1b66e071038b9fbb Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Mon, 5 Nov 2018 11:54:55 +0100 Subject: [PATCH 17/21] Made path slider widht themable. CURA-5829 --- plugins/SimulationView/SimulationViewMainComponent.qml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/SimulationView/SimulationViewMainComponent.qml b/plugins/SimulationView/SimulationViewMainComponent.qml index f34208e1b5..784938e5c2 100644 --- a/plugins/SimulationView/SimulationViewMainComponent.qml +++ b/plugins/SimulationView/SimulationViewMainComponent.qml @@ -18,7 +18,7 @@ Item { id: pathSlider height: UM.Theme.getSize("slider_handle").width - width: 250 + width: UM.Theme.getSize("layerview_menu_size").width anchors.bottom: parent.bottom anchors.bottomMargin: UM.Theme.getSize("default_margin").height From 8106df1ae2659da6cf460cb49a23e631be202f3b Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Mon, 5 Nov 2018 16:26:35 +0100 Subject: [PATCH 18/21] Bit of QML cleanup --- .../SimulationViewMenuComponent.qml | 922 +++++++++--------- resources/themes/cura-light/theme.json | 2 - 2 files changed, 454 insertions(+), 470 deletions(-) diff --git a/plugins/SimulationView/SimulationViewMenuComponent.qml b/plugins/SimulationView/SimulationViewMenuComponent.qml index b1613dff85..62f353a241 100644 --- a/plugins/SimulationView/SimulationViewMenuComponent.qml +++ b/plugins/SimulationView/SimulationViewMenuComponent.qml @@ -9,32 +9,21 @@ import QtQuick.Controls.Styles 1.1 import UM 1.0 as UM import Cura 1.0 as Cura -Item +Rectangle { id: base - width: + + color: UM.Theme.getColor("tool_panel_background") + border.width: UM.Theme.getSize("default_lining").width + border.color: UM.Theme.getColor("lining") + + width: UM.Theme.getSize("layerview_menu_size").width + + height: { - if (UM.SimulationView.compatibilityMode) - { - return UM.Theme.getSize("layerview_menu_size_compatibility").width; - } - else - { - return UM.Theme.getSize("layerview_menu_size").width; - } - } - height: { if (viewSettings.collapsed) { - if (UM.SimulationView.compatibilityMode) - { - return UM.Theme.getSize("layerview_menu_size_compatibility_collapsed").height; - } - return UM.Theme.getSize("layerview_menu_size_collapsed").height; - } - else if (UM.SimulationView.compatibilityMode) - { - return UM.Theme.getSize("layerview_menu_size_compatibility").height; + return UM.Theme.getSize("layerview_menu_size_collapsed").height } else if (UM.Preferences.getValue("layerview/layer_view_type") == 0) { @@ -45,6 +34,7 @@ Item return UM.Theme.getSize("layerview_menu_size").height + UM.SimulationView.extruderCount * (UM.Theme.getSize("layerview_row").height + UM.Theme.getSize("layerview_row_spacing").height) } } + Behavior on height { NumberAnimation { duration: 100 } } property var buttonTarget: @@ -57,514 +47,510 @@ Item return Qt.point(0,0) } - Rectangle + Connections { - id: layerViewMenu - anchors.right: parent.right - anchors.top: parent.top - width: parent.width - height: parent.height - clip: true - z: layerSlider.z - 1 - color: UM.Theme.getColor("tool_panel_background") - border.width: UM.Theme.getSize("default_lining").width - border.color: UM.Theme.getColor("lining") - - Button + target: UM.Preferences + onPreferenceChanged: { - id: collapseButton - anchors.top: parent.top - anchors.topMargin: Math.round(UM.Theme.getSize("default_margin").height + (UM.Theme.getSize("layerview_row").height - UM.Theme.getSize("default_margin").height) / 2) - anchors.right: parent.right - anchors.rightMargin: UM.Theme.getSize("default_margin").width + layerTypeCombobox.currentIndex = UM.SimulationView.compatibilityMode ? 1 : UM.Preferences.getValue("layerview/layer_view_type") + layerTypeCombobox.updateLegends(layerTypeCombobox.currentIndex) + viewSettings.extruder_opacities = UM.Preferences.getValue("layerview/extruder_opacities").split("|") + viewSettings.show_travel_moves = UM.Preferences.getValue("layerview/show_travel_moves") + viewSettings.show_helpers = UM.Preferences.getValue("layerview/show_helpers") + viewSettings.show_skin = UM.Preferences.getValue("layerview/show_skin") + viewSettings.show_infill = UM.Preferences.getValue("layerview/show_infill") + viewSettings.only_show_top_layers = UM.Preferences.getValue("view/only_show_top_layers") + viewSettings.top_layer_count = UM.Preferences.getValue("view/top_layer_count") + } + } - width: UM.Theme.getSize("standard_arrow").width - height: UM.Theme.getSize("standard_arrow").height + Button + { + id: collapseButton - onClicked: viewSettings.collapsed = !viewSettings.collapsed - - style: ButtonStyle - { - background: UM.RecolorImage - { - width: control.width - height: control.height - sourceSize.width: width - sourceSize.height: width - color: UM.Theme.getColor("setting_control_text") - source: viewSettings.collapsed ? UM.Theme.getIcon("arrow_left") : UM.Theme.getIcon("arrow_bottom") - } - label: Label{ } - } + anchors + { + top: parent.top + topMargin: Math.round(UM.Theme.getSize("default_margin").height + (UM.Theme.getSize("layerview_row").height - UM.Theme.getSize("default_margin").height) / 2) + right: parent.right + rightMargin: UM.Theme.getSize("default_margin").width } - Column + width: UM.Theme.getSize("standard_arrow").width + height: UM.Theme.getSize("standard_arrow").height + + onClicked: viewSettings.collapsed = !viewSettings.collapsed + + style: ButtonStyle { - id: viewSettings - - property bool collapsed: false - property var extruder_opacities: UM.Preferences.getValue("layerview/extruder_opacities").split("|") - property bool show_travel_moves: UM.Preferences.getValue("layerview/show_travel_moves") - property bool show_helpers: UM.Preferences.getValue("layerview/show_helpers") - property bool show_skin: UM.Preferences.getValue("layerview/show_skin") - property bool show_infill: UM.Preferences.getValue("layerview/show_infill") - // if we are in compatibility mode, we only show the "line type" - property bool show_legend: UM.SimulationView.compatibilityMode ? true : UM.Preferences.getValue("layerview/layer_view_type") == 1 - property bool show_gradient: UM.SimulationView.compatibilityMode ? false : UM.Preferences.getValue("layerview/layer_view_type") == 2 || UM.Preferences.getValue("layerview/layer_view_type") == 3 - property bool show_feedrate_gradient: show_gradient && UM.Preferences.getValue("layerview/layer_view_type") == 2 - property bool show_thickness_gradient: show_gradient && UM.Preferences.getValue("layerview/layer_view_type") == 3 - property bool only_show_top_layers: UM.Preferences.getValue("view/only_show_top_layers") - property int top_layer_count: UM.Preferences.getValue("view/top_layer_count") - - anchors.top: parent.top - anchors.topMargin: UM.Theme.getSize("default_margin").height - anchors.left: parent.left - anchors.leftMargin: UM.Theme.getSize("default_margin").width - anchors.right: parent.right - anchors.rightMargin: UM.Theme.getSize("default_margin").width - spacing: UM.Theme.getSize("layerview_row_spacing").height - - Label + background: UM.RecolorImage { - id: layerViewTypesLabel - text: catalog.i18nc("@label","Color scheme") - font: UM.Theme.getFont("default"); - visible: !UM.SimulationView.compatibilityMode - width: parent.width - color: UM.Theme.getColor("setting_control_text") + width: control.width + height: control.height + sourceSize.width: width + sourceSize.height: width + color: UM.Theme.getColor("setting_control_text") + source: viewSettings.collapsed ? UM.Theme.getIcon("arrow_left") : UM.Theme.getIcon("arrow_bottom") } + label: Label{ } + } + } - ListModel // matches SimulationView.py + Column + { + id: viewSettings + + property bool collapsed: false + property var extruder_opacities: UM.Preferences.getValue("layerview/extruder_opacities").split("|") + property bool show_travel_moves: UM.Preferences.getValue("layerview/show_travel_moves") + property bool show_helpers: UM.Preferences.getValue("layerview/show_helpers") + property bool show_skin: UM.Preferences.getValue("layerview/show_skin") + property bool show_infill: UM.Preferences.getValue("layerview/show_infill") + + // If we are in compatibility mode, we only show the "line type" + property bool show_legend: UM.SimulationView.compatibilityMode ? true : UM.Preferences.getValue("layerview/layer_view_type") == 1 + property bool show_gradient: UM.SimulationView.compatibilityMode ? false : UM.Preferences.getValue("layerview/layer_view_type") == 2 || UM.Preferences.getValue("layerview/layer_view_type") == 3 + property bool show_feedrate_gradient: show_gradient && UM.Preferences.getValue("layerview/layer_view_type") == 2 + property bool show_thickness_gradient: show_gradient && UM.Preferences.getValue("layerview/layer_view_type") == 3 + property bool only_show_top_layers: UM.Preferences.getValue("view/only_show_top_layers") + property int top_layer_count: UM.Preferences.getValue("view/top_layer_count") + + anchors + { + top: parent.top + left: parent.left + right: parent.right + margins: UM.Theme.getSize("default_margin").height + } + + spacing: UM.Theme.getSize("layerview_row_spacing").height + + Label + { + id: layerViewTypesLabel + text: catalog.i18nc("@label","Color scheme") + font: UM.Theme.getFont("default"); + visible: !UM.SimulationView.compatibilityMode + width: parent.width + color: UM.Theme.getColor("setting_control_text") + } + + ListModel // matches SimulationView.py + { + id: layerViewTypes + } + + Component.onCompleted: + { + layerViewTypes.append({ + text: catalog.i18nc("@label:listbox", "Material Color"), + type_id: 0 + }) + layerViewTypes.append({ + text: catalog.i18nc("@label:listbox", "Line Type"), + type_id: 1 + }) + layerViewTypes.append({ + text: catalog.i18nc("@label:listbox", "Feedrate"), + type_id: 2 + }) + layerViewTypes.append({ + text: catalog.i18nc("@label:listbox", "Layer thickness"), + type_id: 3 // these ids match the switching in the shader + }) + } + + ComboBox + { + id: layerTypeCombobox + width: parent.width + model: layerViewTypes + visible: !UM.SimulationView.compatibilityMode + style: UM.Theme.styles.combobox + + onActivated: { - id: layerViewTypes + UM.Preferences.setValue("layerview/layer_view_type", index); } Component.onCompleted: { - layerViewTypes.append({ - text: catalog.i18nc("@label:listbox", "Material Color"), - type_id: 0 - }) - layerViewTypes.append({ - text: catalog.i18nc("@label:listbox", "Line Type"), - type_id: 1 - }) - layerViewTypes.append({ - text: catalog.i18nc("@label:listbox", "Feedrate"), - type_id: 2 - }) - layerViewTypes.append({ - text: catalog.i18nc("@label:listbox", "Layer thickness"), - type_id: 3 // these ids match the switching in the shader - }) + currentIndex = UM.SimulationView.compatibilityMode ? 1 : UM.Preferences.getValue("layerview/layer_view_type"); + updateLegends(currentIndex); } - ComboBox + function updateLegends(type_id) { - id: layerTypeCombobox - width: parent.width - model: layerViewTypes - visible: !UM.SimulationView.compatibilityMode - style: UM.Theme.styles.combobox + // Update the visibility of the legends. + viewSettings.show_legend = UM.SimulationView.compatibilityMode || (type_id == 1); + viewSettings.show_gradient = !UM.SimulationView.compatibilityMode && (type_id == 2 || type_id == 3); + viewSettings.show_feedrate_gradient = viewSettings.show_gradient && (type_id == 2); + viewSettings.show_thickness_gradient = viewSettings.show_gradient && (type_id == 3); + } + } - onActivated: + Label + { + id: compatibilityModeLabel + text: catalog.i18nc("@label","Compatibility Mode") + font: UM.Theme.getFont("default") + color: UM.Theme.getColor("text") + visible: UM.SimulationView.compatibilityMode + height: UM.Theme.getSize("layerview_row").height + width: parent.width + } + + Item // Spacer + { + height: Math.round(UM.Theme.getSize("default_margin").width / 2) + width: width + } + + Repeater + { + model: Cura.ExtrudersModel{} + + CheckBox + { + id: extrudersModelCheckBox + checked: viewSettings.extruder_opacities[index] > 0.5 || viewSettings.extruder_opacities[index] == undefined || viewSettings.extruder_opacities[index] == "" + height: UM.Theme.getSize("layerview_row").height + UM.Theme.getSize("default_lining").height + width: parent.width + visible: !UM.SimulationView.compatibilityMode + enabled: index < 4 + + onClicked: { - UM.Preferences.setValue("layerview/layer_view_type", index); + viewSettings.extruder_opacities[index] = checked ? 1.0 : 0.0 + UM.Preferences.setValue("layerview/extruder_opacities", viewSettings.extruder_opacities.join("|")); } + style: UM.Theme.styles.checkbox + + Rectangle + { + anchors.verticalCenter: parent.verticalCenter + anchors.right: extrudersModelCheckBox.right + width: UM.Theme.getSize("layerview_legend_size").width + height: UM.Theme.getSize("layerview_legend_size").height + color: model.color + radius: Math.round(width / 2) + border.width: UM.Theme.getSize("default_lining").width + border.color: UM.Theme.getColor("lining") + visible: !viewSettings.show_legend && !viewSettings.show_gradient + } + + Label + { + text: model.name + elide: Text.ElideRight + color: UM.Theme.getColor("setting_control_text") + font: UM.Theme.getFont("default") + anchors + { + verticalCenter: parent.verticalCenter + left: extrudersModelCheckBox.left + right: extrudersModelCheckBox.right + leftMargin: UM.Theme.getSize("checkbox").width + Math.round(UM.Theme.getSize("default_margin").width / 2) + rightMargin: UM.Theme.getSize("default_margin").width * 2 + } + + } + } + } + + Repeater + { + model: ListModel + { + id: typesLegendModel Component.onCompleted: { - currentIndex = UM.SimulationView.compatibilityMode ? 1 : UM.Preferences.getValue("layerview/layer_view_type"); - updateLegends(currentIndex); - } - - function updateLegends(type_id) - { - // update visibility of legends - viewSettings.show_legend = UM.SimulationView.compatibilityMode || (type_id == 1); - viewSettings.show_gradient = !UM.SimulationView.compatibilityMode && (type_id == 2 || type_id == 3); - viewSettings.show_feedrate_gradient = viewSettings.show_gradient && (type_id == 2); - viewSettings.show_thickness_gradient = viewSettings.show_gradient && (type_id == 3); + typesLegendModel.append({ + label: catalog.i18nc("@label", "Show Travels"), + initialValue: viewSettings.show_travel_moves, + preference: "layerview/show_travel_moves", + colorId: "layerview_move_combing" + }); + typesLegendModel.append({ + label: catalog.i18nc("@label", "Show Helpers"), + initialValue: viewSettings.show_helpers, + preference: "layerview/show_helpers", + colorId: "layerview_support" + }); + typesLegendModel.append({ + label: catalog.i18nc("@label", "Show Shell"), + initialValue: viewSettings.show_skin, + preference: "layerview/show_skin", + colorId: "layerview_inset_0" + }); + typesLegendModel.append({ + label: catalog.i18nc("@label", "Show Infill"), + initialValue: viewSettings.show_infill, + preference: "layerview/show_infill", + colorId: "layerview_infill" + }); } } - Label + CheckBox { - id: compatibilityModeLabel - text: catalog.i18nc("@label","Compatibility Mode") - font: UM.Theme.getFont("default") - color: UM.Theme.getColor("text") - visible: UM.SimulationView.compatibilityMode - height: UM.Theme.getSize("layerview_row").height + id: legendModelCheckBox + checked: model.initialValue + onClicked: UM.Preferences.setValue(model.preference, checked) + height: UM.Theme.getSize("layerview_row").height + UM.Theme.getSize("default_lining").height width: parent.width - } - Item - { - height: Math.round(UM.Theme.getSize("default_margin").width / 2) - width: width - } - - Connections - { - target: UM.Preferences - onPreferenceChanged: - { - layerTypeCombobox.currentIndex = UM.SimulationView.compatibilityMode ? 1 : UM.Preferences.getValue("layerview/layer_view_type") - layerTypeCombobox.updateLegends(layerTypeCombobox.currentIndex) - viewSettings.extruder_opacities = UM.Preferences.getValue("layerview/extruder_opacities").split("|") - viewSettings.show_travel_moves = UM.Preferences.getValue("layerview/show_travel_moves") - viewSettings.show_helpers = UM.Preferences.getValue("layerview/show_helpers") - viewSettings.show_skin = UM.Preferences.getValue("layerview/show_skin") - viewSettings.show_infill = UM.Preferences.getValue("layerview/show_infill") - viewSettings.only_show_top_layers = UM.Preferences.getValue("view/only_show_top_layers") - viewSettings.top_layer_count = UM.Preferences.getValue("view/top_layer_count") - } - } - - Repeater - { - model: Cura.ExtrudersModel{} - CheckBox - { - id: extrudersModelCheckBox - checked: viewSettings.extruder_opacities[index] > 0.5 || viewSettings.extruder_opacities[index] == undefined || viewSettings.extruder_opacities[index] == "" - onClicked: - { - viewSettings.extruder_opacities[index] = checked ? 1.0 : 0.0 - UM.Preferences.setValue("layerview/extruder_opacities", viewSettings.extruder_opacities.join("|")); - } - visible: !UM.SimulationView.compatibilityMode - enabled: index + 1 <= 4 - Rectangle - { - anchors.verticalCenter: parent.verticalCenter - anchors.right: extrudersModelCheckBox.right - width: UM.Theme.getSize("layerview_legend_size").width - height: UM.Theme.getSize("layerview_legend_size").height - color: model.color - radius: Math.round(width / 2) - border.width: UM.Theme.getSize("default_lining").width - border.color: UM.Theme.getColor("lining") - visible: !viewSettings.show_legend & !viewSettings.show_gradient - } - height: UM.Theme.getSize("layerview_row").height + UM.Theme.getSize("default_lining").height - width: parent.width - - style: UM.Theme.styles.checkbox - Label - { - text: model.name - elide: Text.ElideRight - color: UM.Theme.getColor("setting_control_text") - font: UM.Theme.getFont("default") - anchors.verticalCenter: parent.verticalCenter - anchors.left: extrudersModelCheckBox.left - anchors.right: extrudersModelCheckBox.right - anchors.leftMargin: UM.Theme.getSize("checkbox").width + Math.round(UM.Theme.getSize("default_margin").width / 2) - anchors.rightMargin: UM.Theme.getSize("default_margin").width * 2 - } - } - } - - Repeater - { - model: ListModel - { - id: typesLegendModel - Component.onCompleted: - { - typesLegendModel.append({ - label: catalog.i18nc("@label", "Show Travels"), - initialValue: viewSettings.show_travel_moves, - preference: "layerview/show_travel_moves", - colorId: "layerview_move_combing" - }); - typesLegendModel.append({ - label: catalog.i18nc("@label", "Show Helpers"), - initialValue: viewSettings.show_helpers, - preference: "layerview/show_helpers", - colorId: "layerview_support" - }); - typesLegendModel.append({ - label: catalog.i18nc("@label", "Show Shell"), - initialValue: viewSettings.show_skin, - preference: "layerview/show_skin", - colorId: "layerview_inset_0" - }); - typesLegendModel.append({ - label: catalog.i18nc("@label", "Show Infill"), - initialValue: viewSettings.show_infill, - preference: "layerview/show_infill", - colorId: "layerview_infill" - }); - } - } - - CheckBox - { - id: legendModelCheckBox - checked: model.initialValue - onClicked: - { - UM.Preferences.setValue(model.preference, checked); - } - Rectangle - { - anchors.verticalCenter: parent.verticalCenter - anchors.right: legendModelCheckBox.right - width: UM.Theme.getSize("layerview_legend_size").width - height: UM.Theme.getSize("layerview_legend_size").height - color: UM.Theme.getColor(model.colorId) - border.width: UM.Theme.getSize("default_lining").width - border.color: UM.Theme.getColor("lining") - visible: viewSettings.show_legend - } - height: UM.Theme.getSize("layerview_row").height + UM.Theme.getSize("default_lining").height - width: parent.width - style: UM.Theme.styles.checkbox - Label - { - text: label - font: UM.Theme.getFont("default") - elide: Text.ElideRight - color: UM.Theme.getColor("setting_control_text") - anchors.verticalCenter: parent.verticalCenter - anchors.left: legendModelCheckBox.left - anchors.right: legendModelCheckBox.right - anchors.leftMargin: UM.Theme.getSize("checkbox").width + Math.round(UM.Theme.getSize("default_margin").width / 2) - anchors.rightMargin: UM.Theme.getSize("default_margin").width * 2 - } - } - } - - CheckBox - { - checked: viewSettings.only_show_top_layers - onClicked: - { - UM.Preferences.setValue("view/only_show_top_layers", checked ? 1.0 : 0.0) - } - text: catalog.i18nc("@label", "Only Show Top Layers") - visible: UM.SimulationView.compatibilityMode style: UM.Theme.styles.checkbox - } - CheckBox - { - checked: viewSettings.top_layer_count == 5 - onClicked: - { - UM.Preferences.setValue("view/top_layer_count", checked ? 5 : 1) - } - text: catalog.i18nc("@label", "Show 5 Detailed Layers On Top") - visible: UM.SimulationView.compatibilityMode - style: UM.Theme.styles.checkbox - } - Repeater - { - model: ListModel + Rectangle { - id: typesLegendModelNoCheck - Component.onCompleted: - { - typesLegendModelNoCheck.append({ - label: catalog.i18nc("@label", "Top / Bottom"), - colorId: "layerview_skin", - }); - typesLegendModelNoCheck.append({ - label: catalog.i18nc("@label", "Inner Wall"), - colorId: "layerview_inset_x", - }); - } + anchors.verticalCenter: parent.verticalCenter + anchors.right: legendModelCheckBox.right + width: UM.Theme.getSize("layerview_legend_size").width + height: UM.Theme.getSize("layerview_legend_size").height + color: UM.Theme.getColor(model.colorId) + border.width: UM.Theme.getSize("default_lining").width + border.color: UM.Theme.getColor("lining") + visible: viewSettings.show_legend } Label { text: label - visible: viewSettings.show_legend - id: typesLegendModelLabel - Rectangle - { - anchors.verticalCenter: parent.verticalCenter - anchors.right: typesLegendModelLabel.right - width: UM.Theme.getSize("layerview_legend_size").width - height: UM.Theme.getSize("layerview_legend_size").height - color: UM.Theme.getColor(model.colorId) - border.width: UM.Theme.getSize("default_lining").width - border.color: UM.Theme.getColor("lining") - visible: viewSettings.show_legend - } - height: UM.Theme.getSize("layerview_row").height + UM.Theme.getSize("default_lining").height - width: parent.width - color: UM.Theme.getColor("setting_control_text") font: UM.Theme.getFont("default") + elide: Text.ElideRight + color: UM.Theme.getColor("setting_control_text") + anchors.verticalCenter: parent.verticalCenter + anchors.left: legendModelCheckBox.left + anchors.right: legendModelCheckBox.right + anchors.leftMargin: UM.Theme.getSize("checkbox").width + Math.round(UM.Theme.getSize("default_margin").width / 2) + anchors.rightMargin: UM.Theme.getSize("default_margin").width * 2 + } + } + } + + CheckBox + { + checked: viewSettings.only_show_top_layers + onClicked: UM.Preferences.setValue("view/only_show_top_layers", checked ? 1.0 : 0.0) + text: catalog.i18nc("@label", "Only Show Top Layers") + visible: UM.SimulationView.compatibilityMode + style: UM.Theme.styles.checkbox + } + + CheckBox + { + checked: viewSettings.top_layer_count == 5 + onClicked: UM.Preferences.setValue("view/top_layer_count", checked ? 5 : 1) + text: catalog.i18nc("@label", "Show 5 Detailed Layers On Top") + visible: UM.SimulationView.compatibilityMode + style: UM.Theme.styles.checkbox + } + + Repeater + { + model: ListModel + { + id: typesLegendModelNoCheck + Component.onCompleted: + { + typesLegendModelNoCheck.append({ + label: catalog.i18nc("@label", "Top / Bottom"), + colorId: "layerview_skin", + }); + typesLegendModelNoCheck.append({ + label: catalog.i18nc("@label", "Inner Wall"), + colorId: "layerview_inset_x", + }); } } - // Text for the minimum, maximum and units for the feedrates and layer thickness - Item + Label { - id: gradientLegend - visible: viewSettings.show_gradient + text: label + visible: viewSettings.show_legend + id: typesLegendModelLabel + + height: UM.Theme.getSize("layerview_row").height + UM.Theme.getSize("default_lining").height width: parent.width - height: UM.Theme.getSize("layerview_row").height + color: UM.Theme.getColor("setting_control_text") + font: UM.Theme.getFont("default") - Label + Rectangle { - text: minText() - anchors.left: parent.left - color: UM.Theme.getColor("setting_control_text") - font: UM.Theme.getFont("default") + anchors.verticalCenter: parent.verticalCenter + anchors.right: typesLegendModelLabel.right - function minText() - { - if (UM.SimulationView.layerActivity && CuraApplication.platformActivity) - { - // Feedrate selected - if (UM.Preferences.getValue("layerview/layer_view_type") == 2) - { - return parseFloat(UM.SimulationView.getMinFeedrate()).toFixed(2) - } - // Layer thickness selected - if (UM.Preferences.getValue("layerview/layer_view_type") == 3) - { - return parseFloat(UM.SimulationView.getMinThickness()).toFixed(2) - } - } - return catalog.i18nc("@label","min") - } - } + width: UM.Theme.getSize("layerview_legend_size").width + height: UM.Theme.getSize("layerview_legend_size").height - Label - { - text: unitsText() - anchors.horizontalCenter: parent.horizontalCenter - color: UM.Theme.getColor("setting_control_text") - font: UM.Theme.getFont("default") + color: UM.Theme.getColor(model.colorId) - function unitsText() - { - if (UM.SimulationView.layerActivity && CuraApplication.platformActivity) - { - // Feedrate selected - if (UM.Preferences.getValue("layerview/layer_view_type") == 2) - { - return "mm/s" - } - // Layer thickness selected - if (UM.Preferences.getValue("layerview/layer_view_type") == 3) - { - return "mm" - } - } - return "" - } - } - - Label - { - text: maxText() - anchors.right: parent.right - color: UM.Theme.getColor("setting_control_text") - font: UM.Theme.getFont("default") - - function maxText() - { - if (UM.SimulationView.layerActivity && CuraApplication.platformActivity) - { - // Feedrate selected - if (UM.Preferences.getValue("layerview/layer_view_type") == 2) - { - return parseFloat(UM.SimulationView.getMaxFeedrate()).toFixed(2) - } - // Layer thickness selected - if (UM.Preferences.getValue("layerview/layer_view_type") == 3) - { - return parseFloat(UM.SimulationView.getMaxThickness()).toFixed(2) - } - } - return catalog.i18nc("@label","max") - } + border.width: UM.Theme.getSize("default_lining").width + border.color: UM.Theme.getColor("lining") } } + } - // Gradient colors for feedrate - Rectangle - { // In QML 5.9 can be changed by LinearGradient - // Invert values because then the bar is rotated 90 degrees - id: feedrateGradient - visible: viewSettings.show_feedrate_gradient - anchors.left: parent.right - height: parent.width - width: Math.round(UM.Theme.getSize("layerview_row").height * 1.5) - border.width: UM.Theme.getSize("default_lining").width - border.color: UM.Theme.getColor("lining") - transform: Rotation {origin.x: 0; origin.y: 0; angle: 90} - gradient: Gradient - { - GradientStop - { - position: 0.000 - color: Qt.rgba(1, 0.5, 0, 1) - } - GradientStop - { - position: 0.625 - color: Qt.rgba(0.375, 0.5, 0, 1) - } - GradientStop - { - position: 0.75 - color: Qt.rgba(0.25, 1, 0, 1) - } - GradientStop - { - position: 1.0 - color: Qt.rgba(0, 0, 1, 1) - } - } - } + // Text for the minimum, maximum and units for the feedrates and layer thickness + Item + { + id: gradientLegend + visible: viewSettings.show_gradient + width: parent.width + height: UM.Theme.getSize("layerview_row").height - // Gradient colors for layer thickness (similar to parula colormap) - Rectangle // In QML 5.9 can be changed by LinearGradient + Label { - // Invert values because then the bar is rotated 90 degrees - id: thicknessGradient - visible: viewSettings.show_thickness_gradient - anchors.left: parent.right - height: parent.width - width: Math.round(UM.Theme.getSize("layerview_row").height * 1.5) - border.width: UM.Theme.getSize("default_lining").width - border.color: UM.Theme.getColor("lining") - transform: Rotation {origin.x: 0; origin.y: 0; angle: 90} - gradient: Gradient + text: { - GradientStop + if (UM.SimulationView.layerActivity && CuraApplication.platformActivity) { - position: 0.000 - color: Qt.rgba(1, 1, 0, 1) + // Feedrate selected + if (UM.Preferences.getValue("layerview/layer_view_type") == 2) + { + return parseFloat(UM.SimulationView.getMinFeedrate()).toFixed(2) + } + // Layer thickness selected + if (UM.Preferences.getValue("layerview/layer_view_type") == 3) + { + return parseFloat(UM.SimulationView.getMinThickness()).toFixed(2) + } } - GradientStop + return catalog.i18nc("@label","min") + } + anchors.left: parent.left + color: UM.Theme.getColor("setting_control_text") + font: UM.Theme.getFont("default") + } + + Label + { + text: { + if (UM.SimulationView.layerActivity && CuraApplication.platformActivity) { - position: 0.25 - color: Qt.rgba(1, 0.75, 0.25, 1) + // Feedrate selected + if (UM.Preferences.getValue("layerview/layer_view_type") == 2) + { + return "mm/s" + } + // Layer thickness selected + if (UM.Preferences.getValue("layerview/layer_view_type") == 3) + { + return "mm" + } } - GradientStop + return "" + } + + anchors.horizontalCenter: parent.horizontalCenter + color: UM.Theme.getColor("setting_control_text") + font: UM.Theme.getFont("default") + } + + Label + { + text: { + if (UM.SimulationView.layerActivity && CuraApplication.platformActivity) { - position: 0.5 - color: Qt.rgba(0, 0.75, 0.5, 1) - } - GradientStop - { - position: 0.75 - color: Qt.rgba(0, 0.375, 0.75, 1) - } - GradientStop - { - position: 1.0 - color: Qt.rgba(0, 0, 0.5, 1) + // Feedrate selected + if (UM.Preferences.getValue("layerview/layer_view_type") == 2) + { + return parseFloat(UM.SimulationView.getMaxFeedrate()).toFixed(2) + } + // Layer thickness selected + if (UM.Preferences.getValue("layerview/layer_view_type") == 3) + { + return parseFloat(UM.SimulationView.getMaxThickness()).toFixed(2) + } } + return catalog.i18nc("@label","max") + } + + anchors.right: parent.right + color: UM.Theme.getColor("setting_control_text") + font: UM.Theme.getFont("default") + } + } + + // Gradient colors for feedrate + Rectangle + { // In QML 5.9 can be changed by LinearGradient + // Invert values because then the bar is rotated 90 degrees + id: feedrateGradient + visible: viewSettings.show_feedrate_gradient + anchors.left: parent.right + height: parent.width + width: Math.round(UM.Theme.getSize("layerview_row").height * 1.5) + border.width: UM.Theme.getSize("default_lining").width + border.color: UM.Theme.getColor("lining") + transform: Rotation {origin.x: 0; origin.y: 0; angle: 90} + gradient: Gradient + { + GradientStop + { + position: 0.000 + color: Qt.rgba(1, 0.5, 0, 1) + } + GradientStop + { + position: 0.625 + color: Qt.rgba(0.375, 0.5, 0, 1) + } + GradientStop + { + position: 0.75 + color: Qt.rgba(0.25, 1, 0, 1) + } + GradientStop + { + position: 1.0 + color: Qt.rgba(0, 0, 1, 1) + } + } + } + + // Gradient colors for layer thickness (similar to parula colormap) + Rectangle // In QML 5.9 can be changed by LinearGradient + { + // Invert values because then the bar is rotated 90 degrees + id: thicknessGradient + visible: viewSettings.show_thickness_gradient + anchors.left: parent.right + height: parent.width + width: Math.round(UM.Theme.getSize("layerview_row").height * 1.5) + + border.width: UM.Theme.getSize("default_lining").width + border.color: UM.Theme.getColor("lining") + + transform: Rotation {origin.x: 0; origin.y: 0; angle: 90} + gradient: Gradient + { + GradientStop + { + position: 0.000 + color: Qt.rgba(1, 1, 0, 1) + } + GradientStop + { + position: 0.25 + color: Qt.rgba(1, 0.75, 0.25, 1) + } + GradientStop + { + position: 0.5 + color: Qt.rgba(0, 0.75, 0.5, 1) + } + GradientStop + { + position: 0.75 + color: Qt.rgba(0, 0.375, 0.75, 1) + } + GradientStop + { + position: 1.0 + color: Qt.rgba(0, 0, 0.5, 1) } } } diff --git a/resources/themes/cura-light/theme.json b/resources/themes/cura-light/theme.json index e8de7c98ac..f1e0c08874 100644 --- a/resources/themes/cura-light/theme.json +++ b/resources/themes/cura-light/theme.json @@ -452,8 +452,6 @@ "layerview_menu_size": [15, 20], "layerview_menu_size_material_color_mode": [15, 16], "layerview_menu_size_collapsed": [15, 6], - "layerview_menu_size_compatibility": [22, 22.0], - "layerview_menu_size_compatibility_collapsed": [15, 3.5], "layerview_legend_size": [1.0, 1.0], "layerview_row": [11.0, 1.5], "layerview_row_spacing": [0.0, 0.5], From 319d52a2f9d6013a9261da8d0ec2aab61165a54f Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Mon, 5 Nov 2018 16:59:06 +0100 Subject: [PATCH 19/21] Make collapsible simulation view collapse to right height CURA-5829 --- .../SimulationViewMenuComponent.qml | 49 +++++++++---------- 1 file changed, 22 insertions(+), 27 deletions(-) diff --git a/plugins/SimulationView/SimulationViewMenuComponent.qml b/plugins/SimulationView/SimulationViewMenuComponent.qml index 62f353a241..cb70d1d78e 100644 --- a/plugins/SimulationView/SimulationViewMenuComponent.qml +++ b/plugins/SimulationView/SimulationViewMenuComponent.qml @@ -19,21 +19,7 @@ Rectangle width: UM.Theme.getSize("layerview_menu_size").width - height: - { - if (viewSettings.collapsed) - { - return UM.Theme.getSize("layerview_menu_size_collapsed").height - } - else if (UM.Preferences.getValue("layerview/layer_view_type") == 0) - { - return UM.Theme.getSize("layerview_menu_size_material_color_mode").height + UM.SimulationView.extruderCount * (UM.Theme.getSize("layerview_row").height + UM.Theme.getSize("layerview_row_spacing").height) - } - else - { - return UM.Theme.getSize("layerview_menu_size").height + UM.SimulationView.extruderCount * (UM.Theme.getSize("layerview_row").height + UM.Theme.getSize("layerview_row_spacing").height) - } - } + height: viewSettings.collapsed ? layerViewTypesLabel.height + 2 * UM.Theme.getSize("default_margin").height : childrenRect.height Behavior on height { NumberAnimation { duration: 100 } } @@ -64,6 +50,23 @@ Rectangle } } + Label + { + id: layerViewTypesLabel + text: catalog.i18nc("@label","Color scheme") + font: UM.Theme.getFont("default"); + visible: !UM.SimulationView.compatibilityMode + color: UM.Theme.getColor("setting_control_text") + height: contentHeight + anchors + { + top: parent.top + margins: UM.Theme.getSize("default_margin").height + right: collapseButton.left + left: parent.left + } + } + Button { id: collapseButton @@ -71,9 +74,8 @@ Rectangle anchors { top: parent.top - topMargin: Math.round(UM.Theme.getSize("default_margin").height + (UM.Theme.getSize("layerview_row").height - UM.Theme.getSize("default_margin").height) / 2) + margins: UM.Theme.getSize("default_margin").width right: parent.right - rightMargin: UM.Theme.getSize("default_margin").width } width: UM.Theme.getSize("standard_arrow").width @@ -117,23 +119,16 @@ Rectangle anchors { - top: parent.top + top: layerViewTypesLabel.bottom left: parent.left right: parent.right margins: UM.Theme.getSize("default_margin").height + } spacing: UM.Theme.getSize("layerview_row_spacing").height - Label - { - id: layerViewTypesLabel - text: catalog.i18nc("@label","Color scheme") - font: UM.Theme.getFont("default"); - visible: !UM.SimulationView.compatibilityMode - width: parent.width - color: UM.Theme.getColor("setting_control_text") - } + visible: !collapsed ListModel // matches SimulationView.py { From f15d03d48c84855ca30ec60017e9f00837b686f3 Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Wed, 7 Nov 2018 16:30:52 +0100 Subject: [PATCH 20/21] Fix foldout of the layerview panel being too short or too long CURA-5829 --- .../SimulationViewMenuComponent.qml | 152 +++++++++--------- 1 file changed, 80 insertions(+), 72 deletions(-) diff --git a/plugins/SimulationView/SimulationViewMenuComponent.qml b/plugins/SimulationView/SimulationViewMenuComponent.qml index cb70d1d78e..1cbaffa65e 100644 --- a/plugins/SimulationView/SimulationViewMenuComponent.qml +++ b/plugins/SimulationView/SimulationViewMenuComponent.qml @@ -19,7 +19,7 @@ Rectangle width: UM.Theme.getSize("layerview_menu_size").width - height: viewSettings.collapsed ? layerViewTypesLabel.height + 2 * UM.Theme.getSize("default_margin").height : childrenRect.height + height: viewSettings.collapsed ? layerViewTypesLabel.height + 2 * UM.Theme.getSize("default_margin").height : childrenRect.height + 2 * UM.Theme.getSize("default_margin").height Behavior on height { NumberAnimation { duration: 100 } } @@ -469,83 +469,91 @@ Rectangle } } - // Gradient colors for feedrate - Rectangle - { // In QML 5.9 can be changed by LinearGradient - // Invert values because then the bar is rotated 90 degrees - id: feedrateGradient - visible: viewSettings.show_feedrate_gradient - anchors.left: parent.right - height: parent.width - width: Math.round(UM.Theme.getSize("layerview_row").height * 1.5) - border.width: UM.Theme.getSize("default_lining").width - border.color: UM.Theme.getColor("lining") - transform: Rotation {origin.x: 0; origin.y: 0; angle: 90} - gradient: Gradient - { - GradientStop + Item + { + // Another hack on top of the rotation of the gradient. + // Since we set the side of the panel to use childrenRect (and that uses the un-rotated height), add this + // wrapper item with the correct width & height so it doesn't get confused. + width: parent.width + height: feedrateGradient.visible || thicknessGradient.visible ? Math.round(UM.Theme.getSize("layerview_row").height * 1.5) : 0 + // Gradient colors for feedrate + Rectangle + { // In QML 5.9 can be changed by LinearGradient + // Invert values because then the bar is rotated 90 degrees + id: feedrateGradient + visible: viewSettings.show_feedrate_gradient + anchors.left: parent.right + height: parent.width + width: Math.round(UM.Theme.getSize("layerview_row").height * 1.5) + border.width: UM.Theme.getSize("default_lining").width + border.color: UM.Theme.getColor("lining") + transform: Rotation {origin.x: 0; origin.y: 0; angle: 90} + gradient: Gradient { - position: 0.000 - color: Qt.rgba(1, 0.5, 0, 1) - } - GradientStop - { - position: 0.625 - color: Qt.rgba(0.375, 0.5, 0, 1) - } - GradientStop - { - position: 0.75 - color: Qt.rgba(0.25, 1, 0, 1) - } - GradientStop - { - position: 1.0 - color: Qt.rgba(0, 0, 1, 1) + GradientStop + { + position: 0.000 + color: Qt.rgba(1, 0.5, 0, 1) + } + GradientStop + { + position: 0.625 + color: Qt.rgba(0.375, 0.5, 0, 1) + } + GradientStop + { + position: 0.75 + color: Qt.rgba(0.25, 1, 0, 1) + } + GradientStop + { + position: 1.0 + color: Qt.rgba(0, 0, 1, 1) + } } } - } - // Gradient colors for layer thickness (similar to parula colormap) - Rectangle // In QML 5.9 can be changed by LinearGradient - { - // Invert values because then the bar is rotated 90 degrees - id: thicknessGradient - visible: viewSettings.show_thickness_gradient - anchors.left: parent.right - height: parent.width - width: Math.round(UM.Theme.getSize("layerview_row").height * 1.5) - - border.width: UM.Theme.getSize("default_lining").width - border.color: UM.Theme.getColor("lining") - - transform: Rotation {origin.x: 0; origin.y: 0; angle: 90} - gradient: Gradient + // Gradient colors for layer thickness (similar to parula colormap) + Rectangle // In QML 5.9 can be changed by LinearGradient { - GradientStop + // Invert values because then the bar is rotated 90 degrees + id: thicknessGradient + visible: viewSettings.show_thickness_gradient + anchors.left: parent.right + height: parent.width + width: Math.round(UM.Theme.getSize("layerview_row").height * 1.5) + + border.width: UM.Theme.getSize("default_lining").width + border.color: UM.Theme.getColor("lining") + + transform: Rotation {origin.x: 0; origin.y: 0; angle: 90} + gradient: Gradient { - position: 0.000 - color: Qt.rgba(1, 1, 0, 1) - } - GradientStop - { - position: 0.25 - color: Qt.rgba(1, 0.75, 0.25, 1) - } - GradientStop - { - position: 0.5 - color: Qt.rgba(0, 0.75, 0.5, 1) - } - GradientStop - { - position: 0.75 - color: Qt.rgba(0, 0.375, 0.75, 1) - } - GradientStop - { - position: 1.0 - color: Qt.rgba(0, 0, 0.5, 1) + GradientStop + { + position: 0.000 + color: Qt.rgba(1, 1, 0, 1) + } + GradientStop + { + position: 0.25 + color: Qt.rgba(1, 0.75, 0.25, 1) + } + GradientStop + { + position: 0.5 + color: Qt.rgba(0, 0.75, 0.5, 1) + } + GradientStop + { + position: 0.75 + color: Qt.rgba(0, 0.375, 0.75, 1) + } + GradientStop + { + position: 1.0 + color: Qt.rgba(0, 0, 0.5, 1) + } } } } From 9f663cfd18b13f8504bf3d753166fe1f9a9b653c Mon Sep 17 00:00:00 2001 From: Diego Prado Gesto Date: Wed, 7 Nov 2018 17:25:43 +0100 Subject: [PATCH 21/21] Change the gradient for the LinearGradient that works in the new versions of Qt. I also changed it because we had a TODO here and I thought it was the right moment to do it. Contributes to CURA-5829. --- .../SimulationViewMenuComponent.qml | 139 ++++++++++-------- 1 file changed, 80 insertions(+), 59 deletions(-) diff --git a/plugins/SimulationView/SimulationViewMenuComponent.qml b/plugins/SimulationView/SimulationViewMenuComponent.qml index 1cbaffa65e..d251244c9f 100644 --- a/plugins/SimulationView/SimulationViewMenuComponent.qml +++ b/plugins/SimulationView/SimulationViewMenuComponent.qml @@ -5,6 +5,7 @@ import QtQuick 2.4 import QtQuick.Controls 1.2 import QtQuick.Layouts 1.1 import QtQuick.Controls.Styles 1.1 +import QtGraphicalEffects 1.0 import UM 1.0 as UM import Cura 1.0 as Cura @@ -469,75 +470,95 @@ Rectangle } } - Item + // Gradient colors for feedrate + Rectangle { - // Another hack on top of the rotation of the gradient. - // Since we set the side of the panel to use childrenRect (and that uses the un-rotated height), add this - // wrapper item with the correct width & height so it doesn't get confused. - width: parent.width - height: feedrateGradient.visible || thicknessGradient.visible ? Math.round(UM.Theme.getSize("layerview_row").height * 1.5) : 0 - // Gradient colors for feedrate - Rectangle - { // In QML 5.9 can be changed by LinearGradient - // Invert values because then the bar is rotated 90 degrees - id: feedrateGradient - visible: viewSettings.show_feedrate_gradient - anchors.left: parent.right - height: parent.width - width: Math.round(UM.Theme.getSize("layerview_row").height * 1.5) - border.width: UM.Theme.getSize("default_lining").width - border.color: UM.Theme.getColor("lining") - transform: Rotation {origin.x: 0; origin.y: 0; angle: 90} - gradient: Gradient - { - GradientStop - { - position: 0.000 - color: Qt.rgba(1, 0.5, 0, 1) - } - GradientStop - { - position: 0.625 - color: Qt.rgba(0.375, 0.5, 0, 1) - } - GradientStop - { - position: 0.75 - color: Qt.rgba(0.25, 1, 0, 1) - } - GradientStop - { - position: 1.0 - color: Qt.rgba(0, 0, 1, 1) - } - } - } + id: feedrateGradient + visible: viewSettings.show_feedrate_gradient + anchors.left: parent.left + anchors.right: parent.right + height: Math.round(UM.Theme.getSize("layerview_row").height * 1.5) + border.width: UM.Theme.getSize("default_lining").width + border.color: UM.Theme.getColor("lining") - // Gradient colors for layer thickness (similar to parula colormap) - Rectangle // In QML 5.9 can be changed by LinearGradient + LinearGradient { - // Invert values because then the bar is rotated 90 degrees - id: thicknessGradient - visible: viewSettings.show_thickness_gradient - anchors.left: parent.right - height: parent.width - width: Math.round(UM.Theme.getSize("layerview_row").height * 1.5) - - border.width: UM.Theme.getSize("default_lining").width - border.color: UM.Theme.getColor("lining") - - transform: Rotation {origin.x: 0; origin.y: 0; angle: 90} + anchors + { + left: parent.left + leftMargin: UM.Theme.getSize("default_lining").width + right: parent.right + rightMargin: UM.Theme.getSize("default_lining").width + top: parent.top + topMargin: UM.Theme.getSize("default_lining").width + bottom: parent.bottom + bottomMargin: UM.Theme.getSize("default_lining").width + } + start: Qt.point(0, 0) + end: Qt.point(parent.width, 0) gradient: Gradient { GradientStop { position: 0.000 - color: Qt.rgba(1, 1, 0, 1) + color: Qt.rgba(0, 0, 1, 1) } GradientStop { position: 0.25 - color: Qt.rgba(1, 0.75, 0.25, 1) + color: Qt.rgba(0.25, 1, 0, 1) + } + GradientStop + { + position: 0.375 + color: Qt.rgba(0.375, 0.5, 0, 1) + } + GradientStop + { + position: 1.0 + color: Qt.rgba(1, 0.5, 0, 1) + } + } + } + } + + // Gradient colors for layer thickness (similar to parula colormap) + Rectangle + { + id: thicknessGradient + visible: viewSettings.show_thickness_gradient + anchors.left: parent.left + anchors.right: parent.right + height: Math.round(UM.Theme.getSize("layerview_row").height * 1.5) + border.width: UM.Theme.getSize("default_lining").width + border.color: UM.Theme.getColor("lining") + + LinearGradient + { + anchors + { + left: parent.left + leftMargin: UM.Theme.getSize("default_lining").width + right: parent.right + rightMargin: UM.Theme.getSize("default_lining").width + top: parent.top + topMargin: UM.Theme.getSize("default_lining").width + bottom: parent.bottom + bottomMargin: UM.Theme.getSize("default_lining").width + } + start: Qt.point(0, 0) + end: Qt.point(parent.width, 0) + gradient: Gradient + { + GradientStop + { + position: 0.000 + color: Qt.rgba(0, 0, 0.5, 1) + } + GradientStop + { + position: 0.25 + color: Qt.rgba(0, 0.375, 0.75, 1) } GradientStop { @@ -547,12 +568,12 @@ Rectangle GradientStop { position: 0.75 - color: Qt.rgba(0, 0.375, 0.75, 1) + color: Qt.rgba(1, 0.75, 0.25, 1) } GradientStop { position: 1.0 - color: Qt.rgba(0, 0, 0.5, 1) + color: Qt.rgba(1, 1, 0, 1) } } }