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