Moved view selection to previewStage

CURA-5829
This commit is contained in:
Jaime van Kessel 2018-10-29 13:27:47 +01:00
parent 3248a05819
commit 9cc7a7ca23
5 changed files with 100 additions and 69 deletions

View file

@ -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()
}
}
}

View file

@ -1,13 +1,31 @@
# Copyright (c) 2018 Ultimaker B.V. # Copyright (c) 2018 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher. # Cura is released under the terms of the LGPLv3 or higher.
import os.path
from UM.Application import Application from UM.Application import Application
from cura.Stages.CuraStage import CuraStage from cura.Stages.CuraStage import CuraStage
from typing import TYPE_CHECKING, Optional
if TYPE_CHECKING:
from UM.View import View
class PreviewStage(CuraStage): class PreviewStage(CuraStage):
def __init__(self, parent = None) -> None: def __init__(self, application: Application, parent = None) -> None:
super().__init__(parent) 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): def onStageSelected(self) -> None:
return 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)

View file

@ -18,5 +18,5 @@ def getMetaData():
def register(app): def register(app):
return { return {
"stage": PreviewStage.PreviewStage() "stage": PreviewStage.PreviewStage(app)
} }

View file

@ -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 Loader
{ {
id: viewPanel id: viewPanel

View file

@ -45,8 +45,6 @@ Item
MenuItem { action: Cura.Actions.unGroupObjects } MenuItem { action: Cura.Actions.unGroupObjects }
} }
ViewMenu { title: catalog.i18nc("@title:menu menubar:toplevel", "&View") }
SettingsMenu { title: catalog.i18nc("@title:menu menubar:toplevel", "&Settings") } SettingsMenu { title: catalog.i18nc("@title:menu menubar:toplevel", "&Settings") }
Menu Menu