From a861b88de11ed317f32523e233eb0a3a0252aca9 Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Thu, 11 Oct 2018 15:03:37 +0200 Subject: [PATCH 1/2] Move most of the sidebarHeader items to materialAndVariantSelector CURA-5772 --- resources/qml/MaterialAndVariantSelector.qml | 349 +++++++++++++++++++ 1 file changed, 349 insertions(+) create mode 100644 resources/qml/MaterialAndVariantSelector.qml diff --git a/resources/qml/MaterialAndVariantSelector.qml b/resources/qml/MaterialAndVariantSelector.qml new file mode 100644 index 0000000000..3d2ef2e98f --- /dev/null +++ b/resources/qml/MaterialAndVariantSelector.qml @@ -0,0 +1,349 @@ +// 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.1 +import QtQuick.Controls.Styles 1.1 + +import UM 1.2 as UM +import Cura 1.0 as Cura + +import "Menus" // TODO: This needs to be fixed in the qmldir! + +Rectangle +{ + implicitWidth: parent.width + implicitHeight: parent.height + + id: base + + color: "purple" + // Height has an extra 2x margin for the top & bottom margin. + height: childrenRect.height + 2 * UM.Theme.getSize("default_margin").width + + Cura.ExtrudersModel { id: extrudersModel; } + + ListView + { + // Horizontal list that shows the extruders + id: extrudersList + visible: extrudersModel.items.length > 1 + property var index: 0 + + height: UM.Theme.getSize("sidebar_header_mode_tabs").height + boundsBehavior: Flickable.StopAtBounds + + anchors + { + left: parent.left + right: parent.right + top: parent.top + margins: UM.Theme.getSize("sidebar_margin").width + } + + ExclusiveGroup { id: extruderMenuGroup; } + + orientation: ListView.Horizontal + + model: extrudersModel + + Connections + { + target: Cura.MachineManager + onGlobalContainerChanged: forceActiveFocus() // Changing focus applies the currently-being-typed values so it can change the displayed setting values. + } + + delegate: Button + { + height: parent.height + width: Math.round(ListView.view.width / extrudersModel.rowCount()) + + text: model.name + tooltip: model.name + exclusiveGroup: extruderMenuGroup + checked: Cura.ExtruderManager.activeExtruderIndex == index + + property bool extruder_enabled: true + + MouseArea // TODO; This really should be fixed. It makes absolutely no sense to have a button AND a mouse area. + { + anchors.fill: parent + acceptedButtons: Qt.LeftButton | Qt.RightButton + onClicked: { + switch (mouse.button) { + case Qt.LeftButton: + extruder_enabled = Cura.MachineManager.getExtruder(model.index).isEnabled + if (extruder_enabled) + { + forceActiveFocus(); // Changing focus applies the currently-being-typed values so it can change the displayed setting values. + Cura.ExtruderManager.setActiveExtruderIndex(index); + } + break; + case Qt.RightButton: + extruder_enabled = Cura.MachineManager.getExtruder(model.index).isEnabled + extruderMenu.popup(); + break; + } + + } + } + + Menu + { + id: extruderMenu + + MenuItem + { + text: catalog.i18nc("@action:inmenu", "Enable Extruder") + onTriggered: Cura.MachineManager.setExtruderEnabled(model.index, true) + visible: !extruder_enabled // using an intermediate variable prevents an empty popup that occured now and then + } + + MenuItem + { + text: catalog.i18nc("@action:inmenu", "Disable Extruder") + onTriggered: Cura.MachineManager.setExtruderEnabled(model.index, false) + visible: extruder_enabled + enabled: Cura.MachineManager.numberExtrudersEnabled > 1 + } + } + + style: ButtonStyle + { + background: Rectangle + { + anchors.fill: parent + border.width: control.checked ? UM.Theme.getSize("default_lining").width * 2 : UM.Theme.getSize("default_lining").width + border.color: { + if (Cura.MachineManager.getExtruder(index).isEnabled) + { + if(control.checked || control.pressed) + { + return UM.Theme.getColor("action_button_active_border"); + } else if (control.hovered) + { + return UM.Theme.getColor("action_button_hovered_border") + } + return UM.Theme.getColor("action_button_border") + } + return UM.Theme.getColor("action_button_disabled_border") + } + color: { + if (Cura.MachineManager.getExtruder(index).isEnabled) + { + if(control.checked || control.pressed) + { + return UM.Theme.getColor("action_button_active"); + } else if (control.hovered) + { + return UM.Theme.getColor("action_button_hovered") + } + return UM.Theme.getColor("action_button") + } + return UM.Theme.getColor("action_button_disabled") + } + Behavior on color { ColorAnimation { duration: 50; } } + + Item + { + id: extruderButtonFace + anchors.centerIn: parent + width: childrenRect.width + + Label + { + // Static text that holds the "Extruder" label + id: extruderStaticText + anchors.verticalCenter: parent.verticalCenter + anchors.left: parent.left + + color: { + if (Cura.MachineManager.getExtruder(index).isEnabled) + { + if(control.checked || control.pressed) + { + return UM.Theme.getColor("action_button_active_text"); + } else if (control.hovered) + { + return UM.Theme.getColor("action_button_hovered_text") + } + return UM.Theme.getColor("action_button_text") + } + return UM.Theme.getColor("action_button_disabled_text") + } + + font: UM.Theme.getFont("large_nonbold") + text: catalog.i18nc("@label", "Extruder") + visible: width < (control.width - extruderIconItem.width - UM.Theme.getSize("default_margin").width) + elide: Text.ElideRight + } + + ExtruderIcon + { + // Round icon with the extruder number and material color indicator. + anchors.verticalCenter: parent.verticalCenter + anchors.left: extruderStaticText.right + width: control.height - Math.round(UM.Theme.getSize("default_margin").width / 2) + height: width + + checked: control.checked + material_color: model.color + text_color: extruderStaticText.color + } + } + } + + label: Item {} + } + } + } + + Item + { + id: materialRow + height: UM.Theme.getSize("sidebar_setup").height + visible: Cura.MachineManager.hasMaterials + + anchors + { + left: parent.left + right: parent.right + top: extrudersList.bottom + margins: UM.Theme.getSize("sidebar_margin").width + } + + Label + { + id: materialLabel + text: catalog.i18nc("@label", "Material"); + width: Math.round(parent.width * 0.45 - UM.Theme.getSize("default_margin").width) + height: parent.height + verticalAlignment: Text.AlignVCenter + font: UM.Theme.getFont("default"); + color: UM.Theme.getColor("text"); + } + + ToolButton + { + id: materialSelection + + property var activeExtruder: Cura.MachineManager.activeStack + property var hasActiveExtruder: activeExtruder != null + property var currentRootMaterialName: hasActiveExtruder ? activeExtruder.material.name : "" + + text: currentRootMaterialName + tooltip: currentRootMaterialName + visible: Cura.MachineManager.hasMaterials + + enabled: !extrudersList.visible || Cura.ExtruderManager.activeExtruderIndex > -1 + + height: UM.Theme.getSize("setting_control").height + width: Math.round(parent.width * 0.7) + UM.Theme.getSize("sidebar_margin").width + anchors.right: parent.right + style: UM.Theme.styles.sidebar_header_button + activeFocusOnPress: true; + menu: MaterialMenu + { + extruderIndex: Cura.ExtruderManager.activeExtruderIndex + } + + property var valueError: hasActiveExtruder ? Cura.ContainerManager.getContainerMetaDataEntry(activeExtruder.material.id, "compatible", "") != "True" : true + property var valueWarning: ! Cura.MachineManager.isActiveQualitySupported + } + } + + Item + { + id: variantRow + height: UM.Theme.getSize("sidebar_setup").height + visible: Cura.MachineManager.hasVariants + + anchors + { + left: parent.left + right: parent.right + top: materialRow.bottom + margins: UM.Theme.getSize("sidebar_margin").width + } + + Label + { + id: variantLabel + text: Cura.MachineManager.activeDefinitionVariantsName; + width: Math.round(parent.width * 0.45 - UM.Theme.getSize("default_margin").width) + height: parent.height + verticalAlignment: Text.AlignVCenter + font: UM.Theme.getFont("default"); + color: UM.Theme.getColor("text"); + } + + ToolButton + { + id: variantSelection + text: Cura.MachineManager.activeVariantName + tooltip: Cura.MachineManager.activeVariantName; + visible: Cura.MachineManager.hasVariants + + height: UM.Theme.getSize("setting_control").height + width: Math.round(parent.width * 0.7 + UM.Theme.getSize("sidebar_margin").width) + anchors.right: parent.right + style: UM.Theme.styles.sidebar_header_button + activeFocusOnPress: true; + + menu: NozzleMenu { extruderIndex: Cura.ExtruderManager.activeExtruderIndex } + } + } + + Item + { + id: materialCompatibilityLink + height: UM.Theme.getSize("sidebar_setup").height + + anchors.right: parent.right + anchors.top: variantRow.bottom + anchors.margins: UM.Theme.getSize("sidebar_margin").width + UM.RecolorImage + { + id: warningImage + + anchors.right: materialInfoLabel.left + anchors.rightMargin: UM.Theme.getSize("default_margin").width + + source: UM.Theme.getIcon("warning") + width: UM.Theme.getSize("section_icon").width + height: UM.Theme.getSize("section_icon").height + + sourceSize.width: width + sourceSize.height: height + + color: UM.Theme.getColor("material_compatibility_warning") + + visible: !Cura.MachineManager.isCurrentSetupSupported + } + + Label + { + id: materialInfoLabel + wrapMode: Text.WordWrap + text: "" + catalog.i18nc("@label", "Check compatibility") + "" + font: UM.Theme.getFont("default") + color: UM.Theme.getColor("text") + linkColor: UM.Theme.getColor("text_link") + + verticalAlignment: Text.AlignTop + + anchors.right: parent.right + + MouseArea + { + anchors.fill: parent + + onClicked: { + // open the material URL with web browser + Qt.openUrlExternally("https://ultimaker.com/incoming-links/cura/material-compatibilty"); + } + } + } + } + +} \ No newline at end of file From bb7582159910728976e4e020d0b61de2b0b08ce2 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Thu, 11 Oct 2018 13:44:10 +0200 Subject: [PATCH 2/2] Fix some code style Contributes to issue CURA-5784. --- resources/qml/Cura.qml | 22 ++++++++++++--------- resources/qml/Skeleton/ApplicationMenu.qml | 12 +++++------ resources/qml/Skeleton/ApplicationViews.qml | 16 ++++++++------- 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/resources/qml/Cura.qml b/resources/qml/Cura.qml index f040469916..8369c2a743 100644 --- a/resources/qml/Cura.qml +++ b/resources/qml/Cura.qml @@ -27,21 +27,25 @@ UM.MainWindow UM.I18nCatalog { id: catalog - name:"cura" + name: "cura" } onWidthChanged: { // If slidebar is collapsed then it should be invisible // otherwise after the main_window resize the sidebar will be fully re-drawn - if (sidebar.collapsed){ - if (sidebar.visible == true){ + if (sidebar.collapsed) + { + if (sidebar.visible == true) + { sidebar.visible = false sidebar.initialWidth = 0 } } - else{ - if (sidebar.visible == false){ + else + { + if (sidebar.visible == false) + { sidebar.visible = true sidebar.initialWidth = UM.Theme.getSize("sidebar").width } @@ -156,7 +160,7 @@ UM.MainWindow Button { id: openFileButton - text: catalog.i18nc("@action:button","Open File") + text: catalog.i18nc("@action:button", "Open File") iconSource: UM.Theme.getIcon("load") style: UM.Theme.styles.tool_button tooltip: "" @@ -352,10 +356,10 @@ UM.MainWindow { //; Remove & re-add the general page as we want to use our own instead of uranium standard. removePage(0); - insertPage(0, catalog.i18nc("@title:tab","General"), Qt.resolvedUrl("Preferences/GeneralPage.qml")); + insertPage(0, catalog.i18nc("@title:tab", "General"), Qt.resolvedUrl("Preferences/GeneralPage.qml")); removePage(1); - insertPage(1, catalog.i18nc("@title:tab","Settings"), Qt.resolvedUrl("Preferences/SettingVisibilityPage.qml")); + insertPage(1, catalog.i18nc("@title:tab", "Settings"), Qt.resolvedUrl("Preferences/SettingVisibilityPage.qml")); insertPage(2, catalog.i18nc("@title:tab", "Printers"), Qt.resolvedUrl("Preferences/MachinesPage.qml")); @@ -528,7 +532,7 @@ UM.MainWindow id: openDialog; //: File open dialog title - title: catalog.i18nc("@title:window","Open file(s)") + title: catalog.i18nc("@title:window", "Open file(s)") modality: UM.Application.platform == "linux" ? Qt.NonModal : Qt.WindowModal; selectMultiple: true nameFilters: UM.MeshFileHandler.supportedReadFileTypes; diff --git a/resources/qml/Skeleton/ApplicationMenu.qml b/resources/qml/Skeleton/ApplicationMenu.qml index a8774e8ceb..00859e2a45 100644 --- a/resources/qml/Skeleton/ApplicationMenu.qml +++ b/resources/qml/Skeleton/ApplicationMenu.qml @@ -27,7 +27,7 @@ Item Menu { id: fileMenu - title: catalog.i18nc("@title:menu menubar:toplevel","&File") + title: catalog.i18nc("@title:menu menubar:toplevel", "&File") MenuItem { @@ -46,7 +46,7 @@ Item MenuItem { id: saveWorkspaceMenu - text: catalog.i18nc("@title:menu menubar:file","&Save...") + text: catalog.i18nc("@title:menu menubar:file", "&Save...") onTriggered: { var args = { "filter_by_machine": false, "file_type": "workspace", "preferred_mimetypes": "application/vnd.ms-package.3dmanufacturing-3dmodel+xml" }; @@ -99,7 +99,7 @@ Item Menu { - title: catalog.i18nc("@title:menu menubar:toplevel","&Edit") + title: catalog.i18nc("@title:menu menubar:toplevel", "&Edit") MenuItem { action: Cura.Actions.undo } MenuItem { action: Cura.Actions.redo } @@ -181,7 +181,7 @@ Item Menu { id: extensionMenu - title: catalog.i18nc("@title:menu menubar:toplevel","E&xtensions") + title: catalog.i18nc("@title:menu menubar:toplevel", "E&xtensions") Instantiator { @@ -223,7 +223,7 @@ Item Menu { id: preferencesMenu - title: catalog.i18nc("@title:menu menubar:toplevel","P&references") + title: catalog.i18nc("@title:menu menubar:toplevel", "P&references") MenuItem { action: Cura.Actions.preferences } } @@ -231,7 +231,7 @@ Item Menu { id: helpMenu - title: catalog.i18nc("@title:menu menubar:toplevel","&Help") + title: catalog.i18nc("@title:menu menubar:toplevel", "&Help") MenuItem { action: Cura.Actions.showProfileFolder } MenuItem { action: Cura.Actions.documentation } diff --git a/resources/qml/Skeleton/ApplicationViews.qml b/resources/qml/Skeleton/ApplicationViews.qml index 94315a73fb..eb8ab16fae 100644 --- a/resources/qml/Skeleton/ApplicationViews.qml +++ b/resources/qml/Skeleton/ApplicationViews.qml @@ -11,9 +11,9 @@ import Cura 1.0 as Cura import "../components" -// This item contains the views selector, a combobox that is dinamically created from -// the list of available Views (packages that create different visualizactions of the -// scene. Aside the selector, there is a row of buttons that change the orientation of the view. +// 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). Aside from the selector, there is a row of buttons that change the orientation of the view. Item { id: applicationViewsSelector @@ -25,7 +25,8 @@ Item { id: viewModeButton - anchors { + anchors + { verticalCenter: parent.verticalCenter right: parent.right rightMargin: UM.Theme.getSize("default_margin").width @@ -51,15 +52,16 @@ Item { for (var i = 0; i < model.rowCount(); i++) { - if (model.getItem(i).active) { - return i + if (model.getItem(i).active) + { + return i; } } return 0 } // set the active index - function setActiveIndex (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