From c356b9d46f7e20dc92492b6dd3fd81dd650be133 Mon Sep 17 00:00:00 2001 From: Joey de l'Arago Date: Tue, 29 Nov 2022 16:59:27 +0100 Subject: [PATCH] Rename ExtruderSelectorBar -> SingleSettingExtruderSelectorBar to be inline with new single setting widgets. Move common functionality into SingleSettingExtruderSelectorBar Add adhesion settings CURA-9793 --- .../RecommendedAdhesionSelector.qml | 21 +++--- .../RecommendedSupportSelector.qml | 18 +----- resources/qml/Widgets/ExtruderSelectorBar.qml | 43 ------------- .../qml/Widgets/SingleSettingComboBox.qml | 2 +- .../SingleSettingExtruderSelectorBar.qml | 64 +++++++++++++++++++ resources/qml/qmldir | 6 +- 6 files changed, 79 insertions(+), 75 deletions(-) delete mode 100644 resources/qml/Widgets/ExtruderSelectorBar.qml create mode 100644 resources/qml/Widgets/SingleSettingExtruderSelectorBar.qml diff --git a/resources/qml/PrintSetupSelector/Recommended/RecommendedAdhesionSelector.qml b/resources/qml/PrintSetupSelector/Recommended/RecommendedAdhesionSelector.qml index 4eaf4f17ce..3ffb71e707 100644 --- a/resources/qml/PrintSetupSelector/Recommended/RecommendedAdhesionSelector.qml +++ b/resources/qml/PrintSetupSelector/Recommended/RecommendedAdhesionSelector.qml @@ -1,10 +1,11 @@ -// Copyright (c) 2022 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.Layouts 1.3 import UM 1.5 as UM -import Cura 1.0 as Cura +import Cura 1.7 as Cura RecommendedSettingSection @@ -32,16 +33,12 @@ RecommendedSettingSection curaRecommendedMode.setAdhesion(state) } - contents: RecommendedSettingItem - { - settingName: catalog.i18nc("@action:label", "Print with") - - settingControl: Rectangle + contents: [ + RecommendedSettingItem { - width: 20 - height: 20 - color: Qt.rgba(1, 0, 0, .5) + Layout.preferredHeight: childrenRect.height + settingName: catalog.i18nc("@action:label", "Print with") + settingControl: Cura.SingleSettingExtruderSelectorBar { extruderSettingName: "adhesion_extruder_nr" } } - } - + ] } diff --git a/resources/qml/PrintSetupSelector/Recommended/RecommendedSupportSelector.qml b/resources/qml/PrintSetupSelector/Recommended/RecommendedSupportSelector.qml index 359de13697..2a2ec08c70 100644 --- a/resources/qml/PrintSetupSelector/Recommended/RecommendedSupportSelector.qml +++ b/resources/qml/PrintSetupSelector/Recommended/RecommendedSupportSelector.qml @@ -1,4 +1,4 @@ -// Copyright (c) 2022 Ultimaker B.V. +// Copyright (c) 2022 UltiMaker B.V. // Cura is released under the terms of the LGPLv3 or higher. import QtQuick 2.10 @@ -24,9 +24,6 @@ RecommendedSettingSection supportEnabled.setPropertyValue("value", state) } - property var extruderModel: CuraApplication.getExtrudersModel() - - property UM.SettingPropertyProvider supportEnabled: UM.SettingPropertyProvider { id: supportEnabled @@ -68,19 +65,8 @@ RecommendedSettingSection { Layout.preferredHeight: childrenRect.height settingName: catalog.i18nc("@action:label", "Print with") - settingControl: Cura.ExtruderSelectorBar - { - model: extruderModel - selectedIndex: supportExtruderNr.properties.value !== undefined ? supportExtruderNr.properties.value : 0 - function onClickExtruder(index) - { - forceActiveFocus(); - supportExtruderNr.setPropertyValue("value", index); - } - } - + settingControl: Cura.SingleSettingExtruderSelectorBar { extruderSettingName: "support_extruder_nr" } }, - RecommendedSettingItem { settingName: catalog.i18nc("@action:label", "Placement") diff --git a/resources/qml/Widgets/ExtruderSelectorBar.qml b/resources/qml/Widgets/ExtruderSelectorBar.qml deleted file mode 100644 index 63d9ca9da4..0000000000 --- a/resources/qml/Widgets/ExtruderSelectorBar.qml +++ /dev/null @@ -1,43 +0,0 @@ -import QtQuick 2.12 -import QtQuick.Controls 2.12 -import QtQuick.Layouts 1.3 - -import UM 1.5 as UM -import Cura 1.5 as Cura - -Row -{ - id: extruderSelectionBar - - width: parent.width - height: childrenRect.height - spacing: 0 - - property alias model: extruderButtonRepeater.model - property int selectedIndex: 0 - function onClickExtruder(index) {} - - - Repeater - { - id: extruderButtonRepeater - - delegate: Item - { - width: { - const maximum_width = Math.floor(extruderSelectionBar.width / extruderButtonRepeater.count); - return Math.min(UM.Theme.getSize("large_button").width, maximum_width); - } - height: childrenRect.height - - Cura.ExtruderButton - { - extruder: model - checked: extruder.index == selectedIndex - iconScale: 0.6 - buttonSize: UM.Theme.getSize("large_button").width - onClicked: extruder.enabled && onClickExtruder(extruder.index) - } - } - } -} diff --git a/resources/qml/Widgets/SingleSettingComboBox.qml b/resources/qml/Widgets/SingleSettingComboBox.qml index c79ff591e8..be0b7782f0 100644 --- a/resources/qml/Widgets/SingleSettingComboBox.qml +++ b/resources/qml/Widgets/SingleSettingComboBox.qml @@ -19,7 +19,7 @@ Cura.ComboBox { id: comboboxModel // The propertyProvider has not loaded the setting when this components onComplete triggers. Populating the model - // is defered until propertyProvider signals "onIsValueUsedChanged". + // is defered until propertyProvider signals "onIsValueUsedChanged". The defered upate is triggered with this function. function updateModel() { clear() diff --git a/resources/qml/Widgets/SingleSettingExtruderSelectorBar.qml b/resources/qml/Widgets/SingleSettingExtruderSelectorBar.qml new file mode 100644 index 0000000000..c42b525f6b --- /dev/null +++ b/resources/qml/Widgets/SingleSettingExtruderSelectorBar.qml @@ -0,0 +1,64 @@ +import QtQuick 2.12 +import QtQuick.Controls 2.12 +import QtQuick.Layouts 1.3 + +import UM 1.5 as UM +import Cura 1.5 as Cura + +// This component displays a row of extruder icons, clicking on the extruder will update the setting passed to "settingName" +// with the index of that extruder. +// This will only work for settings that take an extruder index. +Row +{ + id: extruderSelectionBar + + width: parent.width + height: childrenRect.height + spacing: 0 + + property int selectedIndex: extruderSettingProvider.properties.value !== undefined ? extruderSettingProvider.properties.value : 0 + property alias model: extruderButtonRepeater.model + property alias extruderSettingName: extruderSettingProvider.key + property alias containerStack: extruderSettingProvider.containerStack + + property UM.SettingPropertyProvider extruderSettingProvider: UM.SettingPropertyProvider + { + id: extruderSettingProvider + containerStack: Cura.MachineManager.activeMachine + watchedProperties: [ "value" ] + storeIndex: 0 + } + + function onClickExtruder(index) + { + forceActiveFocus(); + extruderSettingProvider.setPropertyValue("value", index); + } + + + Repeater + { + id: extruderButtonRepeater + + model: CuraApplication.getExtrudersModel() + + delegate: Item + { + width: { + // This will "squish" the extruder buttons together when the fill up the horizontal space + const maximum_width = Math.floor(extruderSelectionBar.width / extruderButtonRepeater.count); + return Math.min(UM.Theme.getSize("large_button").width, maximum_width); + } + height: childrenRect.height + + Cura.ExtruderButton + { + extruder: model + checked: extruder.index == selectedIndex + iconScale: 0.6 + buttonSize: UM.Theme.getSize("large_button").width + onClicked: extruder.enabled && onClickExtruder(extruder.index) + } + } + } +} diff --git a/resources/qml/qmldir b/resources/qml/qmldir index da90f32145..4616b8c268 100644 --- a/resources/qml/qmldir +++ b/resources/qml/qmldir @@ -38,9 +38,9 @@ ScrollView 1.0 ScrollView.qml Menu 1.0 Menu.qml MenuItem 1.0 MenuItem.qml MenuSeparator 1.0 MenuSeparator.qml -ExtruderSelectorBar 1.6 ExtruderSelectorBar.qml -ExtruderButton 1.6 ExtruderButton.qml -SingleSettingComboBox 1.7 SingleSettingComboBox.qml +SingleSettingExtruderSelectorBar 1.7 SingleSettingExtruderSelectorBar.qml +ExtruderButton 1.7 ExtruderButton.qml +SingleSettingComboBox 1.7 SingleSettingComboBox.qml # Cura/MachineSettings