Make support selector functional

CURA-9793
This commit is contained in:
Joey de l'Arago 2022-11-28 16:38:44 +01:00
parent 87ff294990
commit 5d5915e49e
2 changed files with 18 additions and 185 deletions

View file

@ -57,188 +57,18 @@ RecommendedSettingSection
RecommendedSettingItem
{
settingName: catalog.i18nc("@action:label", "Print with")
settingControl: Cura.ExtruderSelectorBar { model: extruderModel }
settingControl: Cura.ExtruderSelectorBar
{
model: extruderModel
selectedIndex: (supportExtruderNr.properties.value !== undefined) ? supportExtruderNr.properties.value : 0
function onClickExtruder(index)
{
forceActiveFocus();
supportExtruderNr.setPropertyValue("value", index);
}
}
Layout.preferredHeight: childrenRect.height
// ComboBox
// {
// id: supportExtruderCombobox
//
// // height: UM.Theme.getSize("print_setup_big_item").height
//
// enabled: recommendedPrintSetup.settingsEnabled
// visible: (supportEnabled.properties.value == "True") && (extrudersEnabledCount.properties.value > 1)
// textRole: "name" // this solves that the combobox isn't populated in the first time Cura is started
//
// model: extruderModel
//
// // knowing the extruder position, try to find the item index in the model
// function getIndexByPosition(position)
// {
// var itemIndex = -1 // if position is not found, return -1
// for (var item_index in model.items)
// {
// var item = model.getItem(item_index)
// if (item.index == position)
// {
// itemIndex = item_index
// break
// }
// }
// return itemIndex
// }
//
// onActivated:
// {
// if (model.getItem(index).enabled)
// {
// forceActiveFocus();
// supportExtruderNr.setPropertyValue("value", model.getItem(index).index);
// } else
// {
// currentIndex = supportExtruderNr.properties.value; // keep the old value
// }
// }
//
// // currentIndex: (supportExtruderNr.properties.value !== undefined) ? supportExtruderNr.properties.value : 0
//
// property string color: "#fff"
// Connections
// {
// target: extruderModel
// function onModelChanged()
// {
// var maybeColor = supportExtruderCombobox.model.getItem(supportExtruderCombobox.currentIndex).color
// if (maybeColor)
// {
// supportExtruderCombobox.color = maybeColor
// }
// }
// }
// onCurrentIndexChanged:
// {
// var maybeColor = supportExtruderCombobox.model.getItem(supportExtruderCombobox.currentIndex).color
// if(maybeColor)
// {
// supportExtruderCombobox.color = maybeColor
// }
// }
//
// Binding
// {
// target: supportExtruderCombobox
// property: "currentIndex"
// value: supportExtruderCombobox.getIndexByPosition(supportExtruderNr.properties.value)
// // Sometimes when the value is already changed, the model is still being built.
// // The when clause ensures that the current index is not updated when this happens.
// when: supportExtruderCombobox.model.count > 0
// }
//
// indicator: UM.ColorImage
// {
// id: downArrow
// x: supportExtruderCombobox.width - width - supportExtruderCombobox.rightPadding
// y: supportExtruderCombobox.topPadding + Math.round((supportExtruderCombobox.availableHeight - height) / 2)
//
// source: UM.Theme.getIcon("ChevronSingleDown")
// width: UM.Theme.getSize("standard_arrow").width
// height: UM.Theme.getSize("standard_arrow").height
//
// color: UM.Theme.getColor("setting_control_button")
// }
//
// contentItem: UM.Label
// {
// anchors.verticalCenter: parent.verticalCenter
// anchors.left: parent.left
// anchors.leftMargin: UM.Theme.getSize("setting_unit_margin").width
// anchors.right: downArrow.left
// rightPadding: swatch.width + UM.Theme.getSize("setting_unit_margin").width
//
// text: supportExtruderCombobox.currentText
// textFormat: Text.PlainText
// color: enabled ? UM.Theme.getColor("setting_control_text") : UM.Theme.getColor("setting_control_disabled_text")
//
// elide: Text.ElideLeft
//
//
// background: Rectangle
// {
// id: swatch
// height: Math.round(parent.height / 2)
// width: height
// radius: Math.round(width / 2)
// anchors.right: parent.right
// anchors.verticalCenter: parent.verticalCenter
// anchors.rightMargin: UM.Theme.getSize("thin_margin").width
//
// color: supportExtruderCombobox.color
// }
// }
//
// popup: Popup
// {
// y: supportExtruderCombobox.height - UM.Theme.getSize("default_lining").height
// width: supportExtruderCombobox.width
// implicitHeight: contentItem.implicitHeight + 2 * UM.Theme.getSize("default_lining").width
// padding: UM.Theme.getSize("default_lining").width
//
// contentItem: ListView
// {
// implicitHeight: contentHeight
//
// ScrollBar.vertical: UM.ScrollBar {}
// clip: true
// model: supportExtruderCombobox.popup.visible ? supportExtruderCombobox.delegateModel : null
// currentIndex: supportExtruderCombobox.highlightedIndex
// }
//
// background: Rectangle
// {
// color: UM.Theme.getColor("setting_control")
// border.color: UM.Theme.getColor("setting_control_border")
// }
// }
//
// delegate: ItemDelegate
// {
// width: supportExtruderCombobox.width - 2 * UM.Theme.getSize("default_lining").width
// height: supportExtruderCombobox.height
// highlighted: supportExtruderCombobox.highlightedIndex == index
//
// contentItem: UM.Label
// {
// anchors.fill: parent
// anchors.leftMargin: UM.Theme.getSize("setting_unit_margin").width
// anchors.rightMargin: UM.Theme.getSize("setting_unit_margin").width
//
// text: model.name
// color: model.enabled ? UM.Theme.getColor("setting_control_text"): UM.Theme.getColor("action_button_disabled_text")
//
// elide: Text.ElideRight
// rightPadding: swatch.width + UM.Theme.getSize("setting_unit_margin").width
//
// background: Rectangle
// {
// id: swatch
// height: Math.round(parent.height / 2)
// width: height
// radius: Math.round(width / 2)
// anchors.right: parent.right
// anchors.verticalCenter: parent.verticalCenter
// anchors.rightMargin: UM.Theme.getSize("thin_margin").width
//
// color: supportExtruderCombobox.model.getItem(index).color
// }
// }
//
// background: Rectangle
// {
// color: parent.highlighted ? UM.Theme.getColor("setting_control_highlight") : "transparent"
// border.color: parent.highlighted ? UM.Theme.getColor("setting_control_border_highlight") : "transparent"
// }
// }
// }
},
RecommendedSettingItem

View file

@ -8,11 +8,15 @@ import Cura 1.5 as Cura
Row
{
id: extruderSelectionBar
property alias model: extruderButtonRepeater.model
spacing: 0
width: parent.width
height: childrenRect.height
spacing: 0
property alias model: extruderButtonRepeater.model
property int selectedIndex: 0
function onClickExtruder(index) {}
Repeater
{
@ -24,16 +28,15 @@ Row
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
isTopElement: extrudersModel.getItem(0).id == model.id
isBottomElement: extrudersModel.getItem(extrudersModel.rowCount() - 1).id == model.id
checked: extruder.index == selectedIndex
iconScale: 0.6
buttonSize: UM.Theme.getSize("large_button").width
onClicked: extruder.enabled && onClickExtruder(extruder.index)
}
}
}