SettingComboBox.qml 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. radius: UM.Theme.getSize("setting_control_radius").width
  29. border.width: UM.Theme.getSize("default_lining").width
  30. border.color:
  31. {
  32. if (!enabled) {
  33. return UM.Theme.getColor("setting_control_disabled_border")
  34. }
  35. if (control.hovered || control.activeFocus) {
  36. return UM.Theme.getColor("setting_control_border_highlight")
  37. }
  38. return UM.Theme.getColor("setting_control_border")
  39. }
  40. }
  41. indicator: UM.RecolorImage
  42. {
  43. id: downArrow
  44. x: control.width - width - control.rightPadding
  45. y: control.topPadding + Math.round((control.availableHeight - height) / 2)
  46. source: UM.Theme.getIcon("arrow_bottom")
  47. width: UM.Theme.getSize("standard_arrow").width
  48. height: UM.Theme.getSize("standard_arrow").height
  49. sourceSize.width: width + 5 * screenScaleFactor
  50. sourceSize.height: width + 5 * screenScaleFactor
  51. color: UM.Theme.getColor("setting_control_button")
  52. }
  53. contentItem: Label
  54. {
  55. anchors.left: parent.left
  56. anchors.leftMargin: UM.Theme.getSize("setting_unit_margin").width
  57. anchors.verticalCenter: parent.verticalCenter
  58. anchors.right: downArrow.left
  59. text: control.currentText
  60. textFormat: Text.PlainText
  61. renderType: Text.NativeRendering
  62. font: UM.Theme.getFont("default")
  63. color: !enabled ? UM.Theme.getColor("setting_control_disabled_text") : UM.Theme.getColor("setting_control_text")
  64. elide: Text.ElideRight
  65. verticalAlignment: Text.AlignVCenter
  66. }
  67. popup: Popup {
  68. y: control.height - UM.Theme.getSize("default_lining").height
  69. width: control.width
  70. implicitHeight: contentItem.implicitHeight + 2 * UM.Theme.getSize("default_lining").width
  71. padding: UM.Theme.getSize("default_lining").width
  72. contentItem: ListView {
  73. clip: true
  74. implicitHeight: contentHeight
  75. model: control.popup.visible ? control.delegateModel : null
  76. currentIndex: control.highlightedIndex
  77. ScrollIndicator.vertical: ScrollIndicator { }
  78. }
  79. background: Rectangle {
  80. color: UM.Theme.getColor("setting_control")
  81. border.color: UM.Theme.getColor("setting_control_border")
  82. }
  83. }
  84. delegate: ItemDelegate
  85. {
  86. width: control.width - 2 * UM.Theme.getSize("default_lining").width
  87. height: control.height
  88. highlighted: control.highlightedIndex == index
  89. contentItem: Label
  90. {
  91. // FIXME: Somehow the top/bottom anchoring is not correct on Linux and it results in invisible texts.
  92. anchors.fill: parent
  93. anchors.leftMargin: UM.Theme.getSize("setting_unit_margin").width
  94. anchors.rightMargin: UM.Theme.getSize("setting_unit_margin").width
  95. text: modelData.value
  96. textFormat: Text.PlainText
  97. renderType: Text.NativeRendering
  98. color: control.contentItem.color
  99. font: UM.Theme.getFont("default")
  100. elide: Text.ElideRight
  101. verticalAlignment: Text.AlignVCenter
  102. }
  103. background: Rectangle
  104. {
  105. color: parent.highlighted ? UM.Theme.getColor("setting_control_highlight") : "transparent"
  106. border.color: parent.highlighted ? UM.Theme.getColor("setting_control_border_highlight") : "transparent"
  107. }
  108. }
  109. onActivated:
  110. {
  111. forceActiveFocus()
  112. propertyProvider.setPropertyValue("value", definition.options[index].key)
  113. }
  114. onActiveFocusChanged:
  115. {
  116. if(activeFocus)
  117. {
  118. base.focusReceived()
  119. }
  120. }
  121. Keys.onTabPressed:
  122. {
  123. base.setActiveFocusToNextSetting(true)
  124. }
  125. Keys.onBacktabPressed:
  126. {
  127. base.setActiveFocusToNextSetting(false)
  128. }
  129. Binding
  130. {
  131. target: control
  132. property: "currentIndex"
  133. value:
  134. {
  135. // FIXME this needs to go away once 'resolve' is combined with 'value' in our data model.
  136. var value = undefined;
  137. if ((base.resolve != "None") && (base.stackLevel != 0) && (base.stackLevel != 1)) {
  138. // We have a resolve function. Indicates that the setting is not settable per extruder and that
  139. // we have to choose between the resolved value (default) and the global value
  140. // (if user has explicitly set this).
  141. value = base.resolve;
  142. }
  143. if (value == undefined) {
  144. value = propertyProvider.properties.value;
  145. }
  146. for(var i = 0; i < control.model.length; ++i) {
  147. if(control.model[i].key == value) {
  148. return i;
  149. }
  150. }
  151. return -1;
  152. }
  153. }
  154. }
  155. }