SettingComboBox.qml 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // Copyright (c) 2019 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.10
  4. import QtQuick.Controls 2.3
  5. import UM 1.3 as UM
  6. import "../Widgets" as Widgets
  7. SettingItem
  8. {
  9. id: base
  10. property var focusItem: control
  11. contents: Widgets.CuraComboBox
  12. {
  13. id: control
  14. model: definition.options
  15. textRole: "value"
  16. anchors.fill: parent
  17. onActivated:
  18. {
  19. forceActiveFocus()
  20. propertyProvider.setPropertyValue("value", definition.options[index].key)
  21. }
  22. onActiveFocusChanged:
  23. {
  24. if(activeFocus)
  25. {
  26. base.focusReceived()
  27. }
  28. }
  29. Keys.onTabPressed:
  30. {
  31. base.setActiveFocusToNextSetting(true)
  32. }
  33. Keys.onBacktabPressed:
  34. {
  35. base.setActiveFocusToNextSetting(false)
  36. }
  37. Binding
  38. {
  39. target: control
  40. property: "currentIndex"
  41. value:
  42. {
  43. // FIXME this needs to go away once 'resolve' is combined with 'value' in our data model.
  44. var value = undefined
  45. if ((base.resolve != "None") && (base.stackLevel != 0) && (base.stackLevel != 1))
  46. {
  47. // We have a resolve function. Indicates that the setting is not settable per extruder and that
  48. // we have to choose between the resolved value (default) and the global value
  49. // (if user has explicitly set this).
  50. value = base.resolve
  51. }
  52. if (value == undefined)
  53. {
  54. value = propertyProvider.properties.value
  55. }
  56. for (var i = 0; i < control.model.length; i++)
  57. {
  58. if (control.model[i].key == value)
  59. {
  60. return i
  61. }
  62. }
  63. return -1
  64. }
  65. }
  66. }
  67. }