Browse Source

Rename ExtruderSelectorBar -> SingleSettingExtruderSelectorBar to be inline with new single setting widgets.

Move common functionality into SingleSettingExtruderSelectorBar

Add adhesion settings

CURA-9793
Joey de l'Arago 2 years ago
parent
commit
c356b9d46f

+ 9 - 12
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" }
         }
-    }
-
+    ]
 }

+ 2 - 16
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")

+ 0 - 43
resources/qml/Widgets/ExtruderSelectorBar.qml

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

+ 1 - 1
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()

+ 64 - 0
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)
+            }
+        }
+    }
+}

+ 3 - 3
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