SingleSettingExtruderSelectorBar.qml 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Copyright (c) 2022 UltiMaker
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.12
  4. import QtQuick.Controls 2.12
  5. import QtQuick.Layouts 1.3
  6. import UM 1.5 as UM
  7. import Cura 1.5 as Cura
  8. // This component displays a row of extruder icons, clicking on the extruder will update the setting passed to "settingName"
  9. // with the index of that extruder.
  10. // This will only work for settings that take an extruder index.
  11. Row
  12. {
  13. id: extruderSelectionBar
  14. width: parent.width
  15. height: childrenRect.height
  16. spacing: 0
  17. property int selectedIndex: extruderSettingProvider.properties.value !== undefined ? extruderSettingProvider.properties.value : 0
  18. property alias model: extruderButtonRepeater.model
  19. property alias extruderSettingName: extruderSettingProvider.key
  20. property alias containerStack: extruderSettingProvider.containerStack
  21. property UM.SettingPropertyProvider extruderSettingProvider: UM.SettingPropertyProvider
  22. {
  23. id: extruderSettingProvider
  24. containerStack: Cura.MachineManager.activeMachine
  25. watchedProperties: [ "value" ]
  26. storeIndex: 0
  27. }
  28. function onClickExtruder(index)
  29. {
  30. forceActiveFocus();
  31. extruderSettingProvider.setPropertyValue("value", index);
  32. }
  33. Repeater
  34. {
  35. id: extruderButtonRepeater
  36. model: CuraApplication.getExtrudersModel()
  37. delegate: Item
  38. {
  39. width: {
  40. // This will "squish" the extruder buttons together when the fill up the horizontal space
  41. const maximum_width = Math.floor(extruderSelectionBar.width / extruderButtonRepeater.count);
  42. return Math.min(UM.Theme.getSize("large_button").width, maximum_width);
  43. }
  44. height: childrenRect.height
  45. Cura.ExtruderButton
  46. {
  47. anchors.margins: 0
  48. padding: 0
  49. extruder: model
  50. checked: extruder.index === selectedIndex
  51. iconScale: 0.8
  52. font: UM.Theme.getFont("tiny_emphasis")
  53. buttonSize: UM.Theme.getSize("small_button").width
  54. onClicked: extruder.enabled && onClickExtruder(extruder.index)
  55. }
  56. }
  57. }
  58. }