SettingComboBox.qml 5.9 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. 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. renderType: Text.NativeRendering
  60. font: UM.Theme.getFont("default")
  61. color: !enabled ? UM.Theme.getColor("setting_control_disabled_text") : UM.Theme.getColor("setting_control_text")
  62. elide: Text.ElideRight
  63. verticalAlignment: Text.AlignVCenter
  64. }
  65. popup: Popup {
  66. y: control.height - UM.Theme.getSize("default_lining").height
  67. width: control.width
  68. implicitHeight: contentItem.implicitHeight + 2 * UM.Theme.getSize("default_lining").width
  69. padding: UM.Theme.getSize("default_lining").width
  70. contentItem: ListView {
  71. clip: true
  72. implicitHeight: contentHeight
  73. model: control.popup.visible ? control.delegateModel : null
  74. currentIndex: control.highlightedIndex
  75. ScrollIndicator.vertical: ScrollIndicator { }
  76. }
  77. background: Rectangle {
  78. color: UM.Theme.getColor("setting_control")
  79. border.color: UM.Theme.getColor("setting_control_border")
  80. }
  81. }
  82. delegate: ItemDelegate
  83. {
  84. width: control.width - 2 * UM.Theme.getSize("default_lining").width
  85. height: control.height
  86. highlighted: control.highlightedIndex == index
  87. contentItem: Label
  88. {
  89. // FIXME: Somehow the top/bottom anchoring is not correct on Linux and it results in invisible texts.
  90. anchors.fill: parent
  91. anchors.leftMargin: UM.Theme.getSize("setting_unit_margin").width
  92. anchors.rightMargin: UM.Theme.getSize("setting_unit_margin").width
  93. text: modelData.value
  94. renderType: Text.NativeRendering
  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. }