SettingComboBox.qml 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. // Copyright (c) 2015 Ultimaker B.V.
  2. // Uranium is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.1
  4. import QtQuick.Controls 2.0
  5. import UM 1.1 as UM
  6. SettingItem
  7. {
  8. id: base
  9. property var focusItem: control
  10. contents: ComboBox
  11. {
  12. id: control
  13. model: definition.options
  14. textRole: "value"
  15. anchors.fill: parent
  16. MouseArea
  17. {
  18. anchors.fill: parent
  19. acceptedButtons: Qt.NoButton
  20. onWheel: wheel.accepted = true
  21. }
  22. background: Rectangle
  23. {
  24. color:
  25. {
  26. if (!enabled) {
  27. return UM.Theme.getColor("setting_control_disabled")
  28. }
  29. if (control.hovered || control.activeFocus) {
  30. return UM.Theme.getColor("setting_control_highlight")
  31. }
  32. return UM.Theme.getColor("setting_control")
  33. }
  34. border.width: UM.Theme.getSize("default_lining").width
  35. border.color:
  36. {
  37. if (!enabled) {
  38. return UM.Theme.getColor("setting_control_disabled_border")
  39. }
  40. if (control.hovered || control.activeFocus) {
  41. return UM.Theme.getColor("setting_control_border_highlight")
  42. }
  43. return UM.Theme.getColor("setting_control_border")
  44. }
  45. }
  46. indicator: UM.RecolorImage
  47. {
  48. id: downArrow
  49. x: control.width - width - control.rightPadding
  50. y: control.topPadding + (control.availableHeight - height) / 2
  51. source: UM.Theme.getIcon("arrow_bottom")
  52. width: UM.Theme.getSize("standard_arrow").width
  53. height: UM.Theme.getSize("standard_arrow").height
  54. sourceSize.width: width + 5 * screenScaleFactor
  55. sourceSize.height: width + 5 * screenScaleFactor
  56. color: UM.Theme.getColor("setting_control_text")
  57. }
  58. contentItem: Label
  59. {
  60. anchors.left: parent.left
  61. anchors.leftMargin: UM.Theme.getSize("setting_unit_margin").width
  62. anchors.verticalCenter: parent.verticalCenter
  63. anchors.right: indicator.left
  64. text: control.currentText
  65. font: UM.Theme.getFont("default")
  66. color: !enabled ? UM.Theme.getColor("setting_control_disabled_text") : UM.Theme.getColor("setting_control_text")
  67. elide: Text.ElideRight
  68. verticalAlignment: Text.AlignVCenter
  69. }
  70. delegate: ItemDelegate
  71. {
  72. width: control.width
  73. height: control.height
  74. highlighted: control.highlightedIndex == index
  75. contentItem: Text
  76. {
  77. text: modelData.value
  78. color: control.contentItem.color
  79. font: UM.Theme.getFont("default")
  80. elide: Text.ElideRight
  81. verticalAlignment: Text.AlignVCenter
  82. }
  83. }
  84. onActivated:
  85. {
  86. forceActiveFocus()
  87. propertyProvider.setPropertyValue("value", definition.options[index].key)
  88. }
  89. onActiveFocusChanged:
  90. {
  91. if(activeFocus)
  92. {
  93. base.focusReceived()
  94. }
  95. }
  96. Keys.onTabPressed:
  97. {
  98. base.setActiveFocusToNextSetting(true)
  99. }
  100. Keys.onBacktabPressed:
  101. {
  102. base.setActiveFocusToNextSetting(false)
  103. }
  104. Binding
  105. {
  106. target: control
  107. property: "currentIndex"
  108. value:
  109. {
  110. // FIXME this needs to go away once 'resolve' is combined with 'value' in our data model.
  111. var value = undefined;
  112. if ((base.resolve != "None") && (base.stackLevel != 0) && (base.stackLevel != 1)) {
  113. // We have a resolve function. Indicates that the setting is not settable per extruder and that
  114. // we have to choose between the resolved value (default) and the global value
  115. // (if user has explicitly set this).
  116. value = base.resolve;
  117. }
  118. if (value == undefined) {
  119. value = propertyProvider.properties.value;
  120. }
  121. for(var i = 0; i < control.model.length; ++i) {
  122. if(control.model[i].key == value) {
  123. return i;
  124. }
  125. }
  126. return -1;
  127. }
  128. }
  129. }
  130. }