SettingComboBox.qml 2.1 KB

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