SettingComboBox.qml 5.6 KB

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