From e33288b7c8cf7b4f3e739cf2d2dcb086d4e782d0 Mon Sep 17 00:00:00 2001 From: ChrisTerBeke Date: Tue, 5 Dec 2017 10:56:59 +0100 Subject: [PATCH] Move sidebar target for plugins to only middle section --- cura/CuraApplication.py | 11 +---- cura/Settings/SettingsSidebarView.py | 28 ----------- cura/Sidebar/SidebarController.py | 9 +++- cura/Sidebar/SidebarControllerProxy.py | 5 +- cura/Sidebar/SidebarViewModel.py | 16 +++++-- resources/qml/Cura.qml | 24 ---------- resources/qml/Sidebar.qml | 66 +++++++++++++++++--------- 7 files changed, 67 insertions(+), 92 deletions(-) delete mode 100644 cura/Settings/SettingsSidebarView.py diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index e9e521fb49..997ed7782e 100755 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -79,7 +79,6 @@ from cura.Settings.ExtruderStack import ExtruderStack from cura.Sidebar.SidebarController import SidebarController from cura.Sidebar.SidebarControllerProxy import SidebarControllerProxy from cura.Sidebar.SidebarViewModel import SidebarViewModel -from cura.Settings.SettingsSidebarView import SettingsSidebarView from PyQt5.QtCore import QUrl, pyqtSignal, pyqtProperty, QEvent, Q_ENUMS from UM.FlameProfiler import pyqtSlot @@ -1319,16 +1318,10 @@ class CuraApplication(QtApplication): def _addProfileWriter(self, profile_writer): pass - ## Create and register the default sidebar component (settings) + ## Set the default sidebar view to "default" def _setDefaultSidebarView(self): - - # Register the default settings sidebar manually - settings_sidebar_view = SettingsSidebarView() - self._sidebar_controller.addSidebarView(settings_sidebar_view) - - # Set the default sidebar view depending on user preferences. preferences = Preferences.getInstance() - preferences.addPreference("cura/active_sidebar_view", settings_sidebar_view.getPluginId()) + preferences.addPreference("cura/active_sidebar_view", "default") active_sidebar_view = preferences.getValue("cura/active_sidebar_view") self._sidebar_controller.setActiveSidebarView(active_sidebar_view) diff --git a/cura/Settings/SettingsSidebarView.py b/cura/Settings/SettingsSidebarView.py deleted file mode 100644 index 8b861fbaf6..0000000000 --- a/cura/Settings/SettingsSidebarView.py +++ /dev/null @@ -1,28 +0,0 @@ -# Copyright (c) 2017 Ultimaker B.V. -from PyQt5.QtCore import QObject - -from UM.i18n import i18nCatalog - -from cura.Sidebar.SidebarView import SidebarView -i18n_catalog = i18nCatalog("cura") - -class SettingsSidebarView(QObject, SidebarView): - - def __init__(self, parent = None): - super().__init__(parent) - - ## As the default sidebar is not a plugin, we have a get plugin ID method to allow the sidebar view model to get the needed data. - def getPluginId(self): - return "default" - - ## As the default sidebar is not a plugin, we have a add meta data method here to allow the sidebar view model to get the needed data. - def getMetaData(self): - return { - "sidebar_view": { - "name": i18n_catalog.i18nc("@item:inmenu", "Print settings"), - "weight": 0 - } - } - - def getComponent(self): - return None diff --git a/cura/Sidebar/SidebarController.py b/cura/Sidebar/SidebarController.py index 420f00a489..a40ee07157 100644 --- a/cura/Sidebar/SidebarController.py +++ b/cura/Sidebar/SidebarController.py @@ -10,7 +10,7 @@ class SidebarController: def __init__(self, application): self._application = application - self._sidebar_views = {} + self._sidebar_views = {"default": {}} # default is needed for the default settings sidebar self._active_sidebar_view = None # Register the sidebar_view plugin type so plugins can expose custom sidebar views. @@ -51,6 +51,13 @@ class SidebarController: def getActiveSidebarView(self): return self._active_sidebar_view + ## Get the ID of the active sidebar view. + def getActiveSidebarViewId(self): + if self._active_sidebar_view: + if hasattr(self._active_sidebar_view, "getPluginId"): + return self._active_sidebar_view.getPluginId() + return "default" + ## Change the active sidebar view to one of the registered views. def setActiveSidebarView(self, sidebar_view_id: str): if sidebar_view_id in self._sidebar_views: diff --git a/cura/Sidebar/SidebarControllerProxy.py b/cura/Sidebar/SidebarControllerProxy.py index c373dc0a0a..a9b23fa08e 100644 --- a/cura/Sidebar/SidebarControllerProxy.py +++ b/cura/Sidebar/SidebarControllerProxy.py @@ -22,10 +22,7 @@ class SidebarControllerProxy(QObject): @pyqtProperty(str, notify = activeSidebarViewChanged) def activeSidebarId(self): - if self._controller.getActiveSidebarView() is not None: - return self._controller.getActiveSidebarView().getPluginId() - else: - return "default" + return self._controller.getActiveSidebarViewId() @pyqtSlot(str) def setActiveSidebarView(self, sidebar_view_id): diff --git a/cura/Sidebar/SidebarViewModel.py b/cura/Sidebar/SidebarViewModel.py index de0aae182c..f6dcb4455b 100644 --- a/cura/Sidebar/SidebarViewModel.py +++ b/cura/Sidebar/SidebarViewModel.py @@ -34,10 +34,18 @@ class SidebarViewModel(ListModel): current_view_id = current_view.getPluginId() for sidebar_view_id, sidebar_view in sidebar_views.items(): - if sidebar_view_id != "default": - sidebar_view_metadata = PluginRegistry.getInstance().getMetaData(sidebar_view_id).get("sidebar_view", {}) - else: - sidebar_view_metadata = sidebar_view.getMetaData().get("sidebar_view", {}) + + # Override fields for default settings sidebar + if sidebar_view_id == "default": + items.append({ + "id": "default", + "name": "Print settings", + "weight": 0, + "active": current_view_id == "default" + }) + continue + + sidebar_view_metadata = PluginRegistry.getInstance().getMetaData(sidebar_view_id).get("sidebar_view", {}) # Skip view modes that are marked as not visible if "visible" in sidebar_view_metadata and not sidebar_view_metadata["visible"]: diff --git a/resources/qml/Cura.qml b/resources/qml/Cura.qml index c08080f276..3e5527c75c 100644 --- a/resources/qml/Cura.qml +++ b/resources/qml/Cura.qml @@ -395,30 +395,6 @@ UM.MainWindow width: parent.width z: 1 monitoringPrint: base.showPrintMonitor - visible: Cura.SidebarController.activeSidebarId == "default" - } - - // The sidebarRepeater exposes sidebar views provided by plugins. - // Whenever a plugin sidebar view is active (e.g. not "default"), that sidebar view is shown. - Repeater - { - id: sidebarRepeater - - model: Cura.SidebarViewModel { } - - delegate: Loader - { - id: delegate - asynchronous: true - visible: model.active - - // dynamically get the component from the sidebar controller or set the default sidebar - sourceComponent: { - if (model.id !== "default") { - return Cura.SidebarController.getSidebarComponent(model.id) - } - } - } } } diff --git a/resources/qml/Sidebar.qml b/resources/qml/Sidebar.qml index bed5b4c873..9d0957806d 100644 --- a/resources/qml/Sidebar.qml +++ b/resources/qml/Sidebar.qml @@ -87,25 +87,6 @@ Rectangle } } - SidebarHeader { - id: header - width: parent.width - visible: machineExtruderCount.properties.value > 1 || Cura.MachineManager.hasMaterials || Cura.MachineManager.hasVariants - - onShowTooltip: base.showTooltip(item, location, text) - onHideTooltip: base.hideTooltip() - } - - Rectangle { - id: headerSeparator - width: parent.width - visible: settingsModeSelection.visible && header.visible - height: visible ? UM.Theme.getSize("sidebar_lining").height : 0 - color: UM.Theme.getColor("sidebar_lining") - anchors.top: header.bottom - anchors.topMargin: visible ? UM.Theme.getSize("sidebar_margin").height : 0 - } - onCurrentModeIndexChanged: { UM.Preferences.setValue("cura/active_mode", currentModeIndex); @@ -115,6 +96,24 @@ Rectangle } } + SidebarHeader { + id: header + width: parent.width + visible: (machineExtruderCount.properties.value > 1 || Cura.MachineManager.hasMaterials || Cura.MachineManager.hasVariants) && Cura.SidebarController.activeSidebarId == "default" + onShowTooltip: base.showTooltip(item, location, text) + onHideTooltip: base.hideTooltip() + } + + Rectangle { + id: headerSeparator + width: parent.width + visible: settingsModeSelection.visible && header.visible && Cura.SidebarController.activeSidebarId == "default" + height: visible ? UM.Theme.getSize("sidebar_lining").height : 0 + color: UM.Theme.getColor("sidebar_lining") + anchors.top: header.bottom + anchors.topMargin: visible ? UM.Theme.getSize("sidebar_margin").height : 0 + } + Label { id: settingsModeLabel text: !hideSettings ? catalog.i18nc("@label:listbox", "Print Setup") : catalog.i18nc("@label:listbox","Print Setup disabled\nG-code files cannot be modified"); @@ -125,7 +124,7 @@ Rectangle width: Math.floor(parent.width * 0.45) font: UM.Theme.getFont("large") color: UM.Theme.getColor("text") - visible: !monitoringPrint && !hideView + visible: !monitoringPrint && !hideView && Cura.SidebarController.activeSidebarId == "default" } Rectangle { @@ -147,7 +146,7 @@ Rectangle } } anchors.topMargin: UM.Theme.getSize("sidebar_margin").height - visible: !monitoringPrint && !hideSettings && !hideView + visible: !monitoringPrint && !hideSettings && !hideView && Cura.SidebarController.activeSidebarId == "default" Component{ id: wizardDelegate Button { @@ -228,7 +227,7 @@ Rectangle anchors.topMargin: UM.Theme.getSize("sidebar_margin").height anchors.left: base.left anchors.right: base.right - visible: !monitoringPrint && !hideSettings + visible: !monitoringPrint && !hideSettings && Cura.SidebarController.activeSidebarId == "default" delegate: StackViewDelegate { @@ -259,6 +258,29 @@ Rectangle } } + // The sidebarRepeater exposes sidebar views provided by plugins. + // Whenever a plugin sidebar view is active (e.g. not "default"), that sidebar view is shown. + Repeater + { + id: sidebarRepeater + + model: Cura.SidebarViewModel { } + + delegate: Loader + { + id: delegate + asynchronous: true + visible: model.active + + // dynamically get the component from the sidebar controller or set the default sidebar + sourceComponent: { + if (model.id !== "default") { + return Cura.SidebarController.getSidebarComponent(model.id) + } + } + } + } + Loader { id: controlItem