From 89e6313143589500a6f9cd77475ee79de0f2d845 Mon Sep 17 00:00:00 2001 From: Arjen Hiemstra Date: Tue, 25 Apr 2017 16:11:31 +0200 Subject: [PATCH] Add buttons to select the extruder for the selection to the toolbar Contributes to CURA-3577 --- resources/qml/ExtruderButton.qml | 86 ++++++++++++++++++++++++++++++++ resources/qml/Toolbar.qml | 22 +++++++- 2 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 resources/qml/ExtruderButton.qml diff --git a/resources/qml/ExtruderButton.qml b/resources/qml/ExtruderButton.qml new file mode 100644 index 0000000000..8a088890a9 --- /dev/null +++ b/resources/qml/ExtruderButton.qml @@ -0,0 +1,86 @@ +// Copyright (c) 2017 Ultimaker B.V. +// Cura is released under the terms of the AGPLv3 or higher. + +import QtQuick 2.2 +import QtQuick.Controls 1.1 + +import UM 1.2 as UM +import Cura 1.0 as Cura + +Button +{ + id: base + + property var extruder; + + text: catalog.i18ncp("@label", "Print Selected Model with %1", "Print Selected Models With %1", UM.Selection.selectionCount).arg(extruder.name) + + style: UM.Theme.styles.tool_button; + iconSource: checked ? UM.Theme.getIcon("material_selected") : UM.Theme.getIcon("material_not_selected"); + + checkable: true; + checked: ExtruderManager.selectedObjectExtruders.indexOf(extruder.id) != -1 + enabled: UM.Selection.hasSelection + + property color customColor: base.hovered ? UM.Theme.getColor("button_hover") : UM.Theme.getColor("button"); + + Rectangle + { + anchors.fill: parent + anchors.margins: UM.Theme.getSize("default_lining").width; + + color: "transparent" + + border.width: base.checked ? UM.Theme.getSize("default_lining").width : 0; + border.color: UM.Theme.getColor("button_text") + } + + Item + { + anchors + { + right: parent.right; + top: parent.top; + margins: UM.Theme.getSize("default_lining").width * 3 + } + width: UM.Theme.getSize("default_margin").width + height: UM.Theme.getSize("default_margin").height + + Text + { + anchors.centerIn: parent; + text: index + 1; + color: parent.enabled ? UM.Theme.getColor("button_text") : UM.Theme.getColor("button_disabled_text") + font: UM.Theme.getFont("default_bold"); + } + } + + Rectangle + { + anchors + { + left: parent.left; + top: parent.top; + margins: UM.Theme.getSize("default_lining").width * 3 + } + + color: model.color + + width: UM.Theme.getSize("default_margin").width + height: UM.Theme.getSize("default_margin").height + + border.width: UM.Theme.getSize("default_lining").width + border.color: UM.Theme.getColor("lining"); + } + + // See line 51, same workaround + MouseArea + { + anchors.fill: parent; + onClicked: + { + forceActiveFocus() //First grab focus, so all the text fields are updated + CuraActions.setExtruderForSelection(extruder.id); + } + } +} diff --git a/resources/qml/Toolbar.qml b/resources/qml/Toolbar.qml index 6363aa4e42..0f930d532b 100644 --- a/resources/qml/Toolbar.qml +++ b/resources/qml/Toolbar.qml @@ -6,7 +6,8 @@ import QtQuick.Controls 1.1 import QtQuick.Controls.Styles 1.1 import QtQuick.Layouts 1.1 -import UM 1.0 as UM +import UM 1.2 as UM +import Cura 1.0 as Cura Item { @@ -67,6 +68,14 @@ Item } } } + + Item { height: UM.Theme.getSize("default_margin").height; width: 1; visible: machineExtruderCount.properties.value > 1 } + + Repeater + { + model: Cura.ExtrudersModel { id: extrudersModel } + ExtruderButton { extruder: model } + } } UM.PointingRectangle @@ -147,4 +156,15 @@ Item visible: toolHint.text != ""; } + + UM.SettingPropertyProvider + { + id: machineExtruderCount + + containerStackId: Cura.MachineManager.activeMachineId + key: "machine_extruder_count" + watchedProperties: [ "value" ] + } + + UM.I18nCatalog { id: catalog; name: "cura" } }