SettingComboBox.qml 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. 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 !== undefined && 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. }