SettingComboBox.qml 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. // Copyright (c) 2015 Ultimaker B.V.
  2. // Uranium is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.7
  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 + Math.round((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: downArrow.left
  64. text: control.currentText
  65. renderType: Text.NativeRendering
  66. font: UM.Theme.getFont("default")
  67. color: !enabled ? UM.Theme.getColor("setting_control_disabled_text") : UM.Theme.getColor("setting_control_text")
  68. elide: Text.ElideRight
  69. verticalAlignment: Text.AlignVCenter
  70. }
  71. popup: Popup {
  72. y: control.height - UM.Theme.getSize("default_lining").height
  73. width: control.width
  74. implicitHeight: contentItem.implicitHeight
  75. padding: UM.Theme.getSize("default_lining").width
  76. contentItem: ListView {
  77. clip: true
  78. implicitHeight: contentHeight
  79. model: control.popup.visible ? control.delegateModel : null
  80. currentIndex: control.highlightedIndex
  81. ScrollIndicator.vertical: ScrollIndicator { }
  82. }
  83. background: Rectangle {
  84. color: UM.Theme.getColor("setting_control")
  85. border.color: UM.Theme.getColor("setting_control_border")
  86. }
  87. }
  88. delegate: ItemDelegate
  89. {
  90. width: control.width - 2 * UM.Theme.getSize("default_lining").width
  91. height: control.height
  92. highlighted: control.highlightedIndex == index
  93. contentItem: Label
  94. {
  95. text: modelData.value
  96. renderType: Text.NativeRendering
  97. color: control.contentItem.color
  98. font: UM.Theme.getFont("default")
  99. elide: Text.ElideRight
  100. verticalAlignment: Text.AlignVCenter
  101. }
  102. background: Rectangle
  103. {
  104. color: parent.highlighted ? UM.Theme.getColor("setting_control_highlight") : "transparent"
  105. border.color: parent.highlighted ? UM.Theme.getColor("setting_control_border_highlight") : "transparent"
  106. }
  107. }
  108. onActivated:
  109. {
  110. forceActiveFocus()
  111. propertyProvider.setPropertyValue("value", definition.options[index].key)
  112. }
  113. onActiveFocusChanged:
  114. {
  115. if(activeFocus)
  116. {
  117. base.focusReceived()
  118. }
  119. }
  120. Keys.onTabPressed:
  121. {
  122. base.setActiveFocusToNextSetting(true)
  123. }
  124. Keys.onBacktabPressed:
  125. {
  126. base.setActiveFocusToNextSetting(false)
  127. }
  128. Binding
  129. {
  130. target: control
  131. property: "currentIndex"
  132. value:
  133. {
  134. // FIXME this needs to go away once 'resolve' is combined with 'value' in our data model.
  135. var value = undefined;
  136. if ((base.resolve != "None") && (base.stackLevel != 0) && (base.stackLevel != 1)) {
  137. // We have a resolve function. Indicates that the setting is not settable per extruder and that
  138. // we have to choose between the resolved value (default) and the global value
  139. // (if user has explicitly set this).
  140. value = base.resolve;
  141. }
  142. if (value == undefined) {
  143. value = propertyProvider.properties.value;
  144. }
  145. for(var i = 0; i < control.model.length; ++i) {
  146. if(control.model[i].key == value) {
  147. return i;
  148. }
  149. }
  150. return -1;
  151. }
  152. }
  153. }
  154. }