From 2bad5c5cd32f400ab017f55d6b9c114505eabf59 Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Tue, 11 Jan 2022 10:31:39 +0100 Subject: [PATCH] Update the settings menu to controls 2 CURA-8683 --- resources/qml/MainWindow/ApplicationMenu.qml | 13 +++ resources/qml/Menus/LocalPrinterMenu.qml | 25 ------ resources/qml/Menus/MaterialMenu.qml | 46 +++++------ resources/qml/Menus/NetworkPrinterMenu.qml | 32 -------- resources/qml/Menus/NozzleMenu.qml | 31 ++++--- resources/qml/Menus/PrinterMenu.qml | 85 +++++++++++++------- resources/qml/Menus/SettingsMenu.qml | 28 ++++--- resources/qml/Widgets/MenuItem.qml | 1 + 8 files changed, 121 insertions(+), 140 deletions(-) delete mode 100644 resources/qml/Menus/LocalPrinterMenu.qml delete mode 100644 resources/qml/Menus/NetworkPrinterMenu.qml diff --git a/resources/qml/MainWindow/ApplicationMenu.qml b/resources/qml/MainWindow/ApplicationMenu.qml index cb84e8be37..3689c0c457 100644 --- a/resources/qml/MainWindow/ApplicationMenu.qml +++ b/resources/qml/MainWindow/ApplicationMenu.qml @@ -51,6 +51,19 @@ Item EditMenu {} ViewMenu {} + + SettingsMenu + { + //On MacOS, don't translate the "Settings" word. + //Qt moves the "settings" entry to a different place, and if it got renamed can't find it again when it + //attempts to delete the item upon closing the application, causing a crash. + //In the new location, these items are translated automatically according to the system's language. + //For more information, see: + //- https://doc.qt.io/qt-5/macos-issues.html#menu-bar + //- https://doc.qt.io/qt-5/qmenubar.html#qmenubar-as-a-global-menu-bar + title: (Qt.platform.os == "osx") ? "&Settings" : catalog.i18nc("@title:menu menubar:toplevel", "&Settings") + } + } /*UM.ApplicationMenu diff --git a/resources/qml/Menus/LocalPrinterMenu.qml b/resources/qml/Menus/LocalPrinterMenu.qml deleted file mode 100644 index bd6c57d744..0000000000 --- a/resources/qml/Menus/LocalPrinterMenu.qml +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) 2018 Ultimaker B.V. -// Cura is released under the terms of the LGPLv3 or higher. - -import QtQuick 2.2 -import QtQuick.Controls 1.4 - -import UM 1.2 as UM -import Cura 1.0 as Cura - -Instantiator -{ - model: Cura.GlobalStacksModel {} - - MenuItem - { - text: model.name - checkable: true - checked: Cura.MachineManager.activeMachine !== null ? Cura.MachineManager.activeMachine.id == model.id: false - exclusiveGroup: group - visible: !model.hasRemoteConnection - onTriggered: Cura.MachineManager.setActiveMachine(model.id) - } - onObjectAdded: menu.insertItem(index, object) - onObjectRemoved: menu.removeItem(object) -} diff --git a/resources/qml/Menus/MaterialMenu.qml b/resources/qml/Menus/MaterialMenu.qml index b4f15fad00..b21cbbdafd 100644 --- a/resources/qml/Menus/MaterialMenu.qml +++ b/resources/qml/Menus/MaterialMenu.qml @@ -1,13 +1,13 @@ -//Copyright (c) 2020 Ultimaker B.V. +//Copyright (c) 2022 Ultimaker B.V. //Cura is released under the terms of the LGPLv3 or higher. import QtQuick 2.7 -import QtQuick.Controls 1.4 +import QtQuick.Controls 2.4 -import UM 1.2 as UM +import UM 1.6 as UM import Cura 1.0 as Cura -Menu +UM.Menu { id: menu title: catalog.i18nc("@label:category menu label", "Material") @@ -49,23 +49,24 @@ Menu enabled: updateModels } - MenuItem + UM.MenuItem { text: catalog.i18nc("@label:category menu label", "Favorites") enabled: false visible: favoriteMaterialsModel.items.length > 0 + height: visible ? implicitHeight: 0 } + Instantiator { model: favoriteMaterialsModel - delegate: MenuItem + delegate: UM.MenuItem { text: model.brand + " " + model.name checkable: true enabled: isActiveExtruderEnabled checked: model.root_material_id === menu.currentRootMaterialId onTriggered: Cura.MachineManager.setMaterial(extruderIndex, model.container_node) - exclusiveGroup: favoriteGroup // One favorite and one item from the others can be active at the same time. } onObjectAdded: menu.insertItem(index, object) onObjectRemoved: menu.removeItem(index) @@ -81,13 +82,12 @@ Menu Instantiator { model: genericMaterialsModel - delegate: MenuItem + delegate: UM.MenuItem { text: model.name checkable: true enabled: isActiveExtruderEnabled checked: model.root_material_id === menu.currentRootMaterialId - exclusiveGroup: group onTriggered: Cura.MachineManager.setMaterial(extruderIndex, model.container_node) } onObjectAdded: genericMenu.insertItem(index, object) @@ -100,7 +100,7 @@ Menu Instantiator { model: brandModel - Menu + UM.Menu { id: brandMenu title: brandName @@ -120,47 +120,37 @@ Menu Instantiator { model: brandMaterialColors - delegate: MenuItem + delegate: UM.MenuItem { text: model.name checkable: true enabled: isActiveExtruderEnabled checked: model.id === menu.activeMaterialId - exclusiveGroup: group + onTriggered: Cura.MachineManager.setMaterial(extruderIndex, model.container_node) } onObjectAdded: brandMaterialsMenu.insertItem(index, object) onObjectRemoved: brandMaterialsMenu.removeItem(object) } } - onObjectAdded: brandMenu.insertItem(index, object) - onObjectRemoved: brandMenu.removeItem(object) + onObjectAdded: brandMenu.insertMenu(index, object) + onObjectRemoved: brandMenu.removeMenu(object) } } - onObjectAdded: menu.insertItem(index, object) - onObjectRemoved: menu.removeItem(object) - } - - ExclusiveGroup - { - id: group - } - - ExclusiveGroup - { - id: favoriteGroup + onObjectAdded: menu.insertMenu(index, object) + onObjectRemoved: menu.removeMenu(object) } MenuSeparator {} - MenuItem + UM.MenuItem { action: Cura.Actions.manageMaterials } MenuSeparator {} - MenuItem + UM.MenuItem { action: Cura.Actions.marketplaceMaterials } diff --git a/resources/qml/Menus/NetworkPrinterMenu.qml b/resources/qml/Menus/NetworkPrinterMenu.qml deleted file mode 100644 index 845159f3b2..0000000000 --- a/resources/qml/Menus/NetworkPrinterMenu.qml +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) 2018 Ultimaker B.V. -// Cura is released under the terms of the LGPLv3 or higher. - -import QtQuick 2.2 -import QtQuick.Controls 1.4 - -import UM 1.2 as UM -import Cura 1.0 as Cura - -Instantiator -{ - model: Cura.GlobalStacksModel {} - MenuItem - { - property string connectGroupName: - { - if("group_name" in model.metadata) - { - return model.metadata["group_name"] - } - return "" - } - text: connectGroupName - checkable: true - visible: model.hasRemoteConnection - checked: Cura.MachineManager.activeMachineNetworkGroupName == connectGroupName - exclusiveGroup: group - onTriggered: Cura.MachineManager.setActiveMachine(model.id) - } - onObjectAdded: menu.insertItem(index, object) - onObjectRemoved: menu.removeItem(object) -} diff --git a/resources/qml/Menus/NozzleMenu.qml b/resources/qml/Menus/NozzleMenu.qml index 3ec48ab302..e2c5199211 100644 --- a/resources/qml/Menus/NozzleMenu.qml +++ b/resources/qml/Menus/NozzleMenu.qml @@ -1,15 +1,15 @@ -// Copyright (c) 2017 Ultimaker B.V. +// Copyright (c) 2022 Ultimaker B.V. // Cura is released under the terms of the LGPLv3 or higher. import QtQuick 2.10 -import QtQuick.Controls 1.4 +import QtQuick.Controls 2.4 -import UM 1.2 as UM +import UM 1.5 as UM import Cura 1.0 as Cura -Menu +UM.Menu { - id: menu + id: nozzleMenu title: "Nozzle" property int extruderIndex: 0 @@ -23,12 +23,13 @@ Menu { model: nozzleModel - MenuItem + UM.MenuItem { text: model.hotend_name checkable: true - checked: { - var activeMachine = Cura.MachineManager.activeMachine + property var activeMachine: Cura.MachineManager.activeMachine + checked: + { if (activeMachine === null) { return false @@ -36,10 +37,8 @@ Menu var extruder = Cura.MachineManager.activeMachine.extruderList[extruderIndex] return (extruder === undefined) ? false : (extruder.variant.name == model.hotend_name) } - exclusiveGroup: group enabled: { - var activeMachine = Cura.MachineManager.activeMachine if (activeMachine === null) { return false @@ -47,14 +46,14 @@ Menu var extruder = Cura.MachineManager.activeMachine.extruderList[extruderIndex] return (extruder === undefined) ? false : extruder.isEnabled } - onTriggered: { - Cura.MachineManager.setVariant(menu.extruderIndex, model.container_node); - } + onTriggered:Cura.MachineManager.setVariant(nozzleMenu.extruderIndex, model.container_node) } - onObjectAdded: menu.insertItem(index, object); - onObjectRemoved: menu.removeItem(object); + onObjectAdded: + { + nozzleMenu.insertItem(index, object) + } + onObjectRemoved: nozzleMenu.removeItem(object) } - ExclusiveGroup { id: group } } diff --git a/resources/qml/Menus/PrinterMenu.qml b/resources/qml/Menus/PrinterMenu.qml index 98f72c128d..58c15201a2 100644 --- a/resources/qml/Menus/PrinterMenu.qml +++ b/resources/qml/Menus/PrinterMenu.qml @@ -1,60 +1,89 @@ -// Copyright (c) 2018 Ultimaker B.V. +// Copyright (c) 2022 Ultimaker B.V. // Cura is released under the terms of the LGPLv3 or higher. import QtQuick 2.2 -import QtQuick.Controls 1.4 +import QtQuick.Controls 2.4 -import UM 1.2 as UM +import UM 1.6 as UM import Cura 1.0 as Cura Menu { id: menu -// TODO Enable custom style to the menu -// style: MenuStyle -// { -// frame: Rectangle -// { -// color: "white" -// } -// } - MenuItem + UM.MenuItem { + id: networkEnabledPrinterItem text: catalog.i18nc("@label:category menu label", "Network enabled printers") enabled: false - visible: networkPrinterMenu.count > 0 + visible: networKPrinterInstantiator.count > 0 } - NetworkPrinterMenu + Instantiator { - id: networkPrinterMenu + id: networKPrinterInstantiator + model: Cura.GlobalStacksModel {filterOnlineOnly: true} + UM.MenuItem + { + property string connectGroupName: + { + if("group_name" in model.metadata) + { + return model.metadata["group_name"] + } + return "" + } + text: connectGroupName + checkable: true + checked: Cura.MachineManager.activeMachineNetworkGroupName == connectGroupName + onTriggered: + { + print(typeof(model.id)) + Cura.MachineManager.someFunction("YAY") + Cura.MachineManager.setActiveMachine(model.id) + } + } + onObjectAdded: menu.insertItem(2, object) + onObjectRemoved: menu.removeItem(object) } MenuSeparator { - visible: networkPrinterMenu.count > 0 + visible: networKPrinterInstantiator.count > 0 } - MenuItem - { - text: catalog.i18nc("@label:category menu label", "Local printers") - enabled: false - visible: localPrinterMenu.count > 0 - } - - LocalPrinterMenu + UM.MenuItem { id: localPrinterMenu + text: catalog.i18nc("@label:category menu label", "Local printers") + enabled: false + visible: localPrinterInstantiator.count > 0 } - ExclusiveGroup { id: group; } + Instantiator + { + id: localPrinterInstantiator + model: Cura.GlobalStacksModel {} + + UM.MenuItem + { + text: model.name + checkable: true + checked: Cura.MachineManager.activeMachine !== null ? Cura.MachineManager.activeMachine.id == model.id: false + visible: !model.hasRemoteConnection + height: visible ? implicitHeight: 0 + onTriggered: Cura.MachineManager.setActiveMachine(model.id) + } + // A bit hackish, but we have 2 items at the end, put them before that + onObjectAdded: menu.insertItem(menu.count - 2, object) + onObjectRemoved: menu.removeItem(object) + } MenuSeparator { - visible: localPrinterMenu.count > 0 + visible: localPrinterInstantiator.count > 0 } - MenuItem { action: Cura.Actions.addMachine; } - MenuItem { action: Cura.Actions.configureMachines; } + UM.MenuItem { action: Cura.Actions.addMachine } + UM.MenuItem { action: Cura.Actions.configureMachines } } diff --git a/resources/qml/Menus/SettingsMenu.qml b/resources/qml/Menus/SettingsMenu.qml index 939ade5847..e25686f601 100644 --- a/resources/qml/Menus/SettingsMenu.qml +++ b/resources/qml/Menus/SettingsMenu.qml @@ -2,9 +2,9 @@ //Cura is released under the terms of the LGPLv3 or higher. import QtQuick 2.2 -import QtQuick.Controls 1.4 +import QtQuick.Controls 2.4 -import UM 1.2 as UM +import UM 1.5 as UM import Cura 1.0 as Cura Menu @@ -23,11 +23,16 @@ Menu { title: modelData.name property var extruder: (base.activeMachine === null) ? null : activeMachine.extruderList[model.index] - NozzleMenu { title: Cura.MachineManager.activeDefinitionVariantsName; visible: Cura.MachineManager.activeMachine.hasVariants; extruderIndex: index } + NozzleMenu + { + title: Cura.MachineManager.activeDefinitionVariantsName + shouldBeVisible: activeMachine.hasVariants + extruderIndex: index + } MaterialMenu { title: catalog.i18nc("@title:menu", "&Material") - visible: Cura.MachineManager.activeMachine.hasMaterials + shouldBeVisible: activeMachine.hasMaterials extruderIndex: index updateModels: false onAboutToShow: updateModels = true @@ -39,33 +44,34 @@ Menu visible: Cura.MachineManager.activeMachine.hasVariants || Cura.MachineManager.activeMachine.hasMaterials } - MenuItem + UM.MenuItem { text: catalog.i18nc("@action:inmenu", "Set as Active Extruder") onTriggered: Cura.ExtruderManager.setActiveExtruderIndex(model.index) } - MenuItem + UM.MenuItem { text: catalog.i18nc("@action:inmenu", "Enable Extruder") onTriggered: Cura.MachineManager.setExtruderEnabled(model.index, true) visible: (extruder === null || extruder === undefined) ? false : !extruder.isEnabled + height: visible ? implicitHeight: 0 } - MenuItem + UM.MenuItem { text: catalog.i18nc("@action:inmenu", "Disable Extruder") onTriggered: Cura.MachineManager.setExtruderEnabled(index, false) visible: (extruder === null || extruder === undefined) ? false : extruder.isEnabled enabled: Cura.MachineManager.numberExtrudersEnabled > 1 + height: visible ? implicitHeight: 0 } - } - onObjectAdded: base.insertItem(index, object) - onObjectRemoved: base.removeItem(object) + onObjectAdded: base.insertMenu(index, object) + onObjectRemoved: base.removeMenu(object) } MenuSeparator { } - MenuItem { action: Cura.Actions.configureSettingVisibility } + UM.MenuItem { action: Cura.Actions.configureSettingVisibility } } \ No newline at end of file diff --git a/resources/qml/Widgets/MenuItem.qml b/resources/qml/Widgets/MenuItem.qml index f0824b4d98..8861da1eac 100644 --- a/resources/qml/Widgets/MenuItem.qml +++ b/resources/qml/Widgets/MenuItem.qml @@ -15,6 +15,7 @@ MenuItem implicitHeight: UM.Theme.getSize("setting_control").height + UM.Theme.getSize("narrow_margin").height opacity: enabled ? 1.0 : 0.5 + height: visible ? implicitHeight: 0 arrow: UM.RecolorImage {