SettingComboBox.qml 6.0 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. background: Rectangle
  17. {
  18. color:
  19. {
  20. if (!enabled) {
  21. return UM.Theme.getColor("setting_control_disabled")
  22. }
  23. if (control.hovered || control.activeFocus) {
  24. return UM.Theme.getColor("setting_control_highlight")
  25. }
  26. return UM.Theme.getColor("setting_control")
  27. }
  28. border.width: UM.Theme.getSize("default_lining").width
  29. border.color:
  30. {
  31. if (!enabled) {
  32. return UM.Theme.getColor("setting_control_disabled_border")
  33. }
  34. if (control.hovered || control.activeFocus) {
  35. return UM.Theme.getColor("setting_control_border_highlight")
  36. }
  37. return UM.Theme.getColor("setting_control_border")
  38. }
  39. }
  40. indicator: UM.RecolorImage
  41. {
  42. id: downArrow
  43. x: control.width - width - control.rightPadding
  44. y: control.topPadding + Math.round((control.availableHeight - height) / 2)
  45. source: UM.Theme.getIcon("arrow_bottom")
  46. width: UM.Theme.getSize("standard_arrow").width
  47. height: UM.Theme.getSize("standard_arrow").height
  48. sourceSize.width: width + 5 * screenScaleFactor
  49. sourceSize.height: width + 5 * screenScaleFactor
  50. color: UM.Theme.getColor("setting_control_text")
  51. }
  52. contentItem: Label
  53. {
  54. anchors.left: parent.left
  55. anchors.leftMargin: UM.Theme.getSize("setting_unit_margin").width
  56. anchors.verticalCenter: parent.verticalCenter
  57. anchors.right: downArrow.left
  58. text: control.currentText
  59. textFormat: Text.PlainText
  60. renderType: Text.NativeRendering
  61. font: UM.Theme.getFont("default")
  62. color: !enabled ? UM.Theme.getColor("setting_control_disabled_text") : UM.Theme.getColor("setting_control_text")
  63. elide: Text.ElideRight
  64. verticalAlignment: Text.AlignVCenter
  65. }
  66. popup: Popup {
  67. y: control.height - UM.Theme.getSize("default_lining").height
  68. width: control.width
  69. implicitHeight: contentItem.implicitHeight + 2 * UM.Theme.getSize("default_lining").width
  70. padding: UM.Theme.getSize("default_lining").width
  71. contentItem: ListView {
  72. clip: true
  73. implicitHeight: contentHeight
  74. model: control.popup.visible ? control.delegateModel : null
  75. currentIndex: control.highlightedIndex
  76. ScrollIndicator.vertical: ScrollIndicator { }
  77. }
  78. background: Rectangle {
  79. color: UM.Theme.getColor("setting_control")
  80. border.color: UM.Theme.getColor("setting_control_border")
  81. }
  82. }
  83. delegate: ItemDelegate
  84. {
  85. width: control.width - 2 * UM.Theme.getSize("default_lining").width
  86. height: control.height
  87. highlighted: control.highlightedIndex == index
  88. contentItem: Label
  89. {
  90. // FIXME: Somehow the top/bottom anchoring is not correct on Linux and it results in invisible texts.
  91. anchors.fill: parent
  92. anchors.leftMargin: UM.Theme.getSize("setting_unit_margin").width
  93. anchors.rightMargin: UM.Theme.getSize("setting_unit_margin").width
  94. text: modelData.value
  95. textFormat: Text.PlainText
  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. }