SettingExtruder.qml 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. // Copyright (c) 2016 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. import Cura 1.0 as Cura
  7. SettingItem
  8. {
  9. id: base
  10. property var focusItem: control
  11. contents: ComboBox
  12. {
  13. id: control
  14. anchors.fill: parent
  15. model: Cura.ExtrudersModel {
  16. onModelChanged: {
  17. control.color = getItem(control.currentIndex).color;
  18. }
  19. }
  20. textRole: "name"
  21. onActivated:
  22. {
  23. if (model.getItem(index).enabled) {
  24. forceActiveFocus();
  25. propertyProvider.setPropertyValue("value", model.getItem(index).index);
  26. } else {
  27. currentIndex = propertyProvider.properties.value; // keep the old value
  28. }
  29. }
  30. onActiveFocusChanged:
  31. {
  32. if(activeFocus)
  33. {
  34. base.focusReceived();
  35. }
  36. }
  37. Keys.onTabPressed:
  38. {
  39. base.setActiveFocusToNextSetting(true)
  40. }
  41. Keys.onBacktabPressed:
  42. {
  43. base.setActiveFocusToNextSetting(false)
  44. }
  45. currentIndex: propertyProvider.properties.value
  46. MouseArea
  47. {
  48. anchors.fill: parent
  49. acceptedButtons: Qt.NoButton
  50. onWheel: wheel.accepted = true;
  51. }
  52. property string color: "#fff"
  53. Binding
  54. {
  55. // We override the color property's value when the ExtruderModel changes. So we need to use an
  56. // explicit binding here otherwise we do not handle value changes after the model changes.
  57. target: control
  58. property: "color"
  59. value: control.currentText != "" ? control.model.getItem(control.currentIndex).color : ""
  60. }
  61. Binding
  62. {
  63. target: control
  64. property: "currentIndex"
  65. value:
  66. {
  67. if(propertyProvider.properties.value == -1)
  68. {
  69. // TODO: accidently the extruder position is also the index. fix it
  70. return Cura.MachineManager.defaultExtruderPosition;
  71. }
  72. return propertyProvider.properties.value
  73. }
  74. // Sometimes when the value is already changed, the model is still being built.
  75. // The when clause ensures that the current index is not updated when this happens.
  76. when: control.model.items.length > 0
  77. }
  78. indicator: UM.RecolorImage
  79. {
  80. id: downArrow
  81. x: control.width - width - control.rightPadding
  82. y: control.topPadding + Math.round((control.availableHeight - height) / 2)
  83. source: UM.Theme.getIcon("arrow_bottom")
  84. width: UM.Theme.getSize("standard_arrow").width
  85. height: UM.Theme.getSize("standard_arrow").height
  86. sourceSize.width: width + 5 * screenScaleFactor
  87. sourceSize.height: width + 5 * screenScaleFactor
  88. color: UM.Theme.getColor("setting_control_text");
  89. }
  90. background: Rectangle
  91. {
  92. color:
  93. {
  94. if (!enabled)
  95. {
  96. return UM.Theme.getColor("setting_control_disabled");
  97. }
  98. if (control.hovered || base.activeFocus)
  99. {
  100. return UM.Theme.getColor("setting_control_highlight");
  101. }
  102. return UM.Theme.getColor("setting_control");
  103. }
  104. border.width: UM.Theme.getSize("default_lining").width
  105. border.color:
  106. {
  107. if (!enabled)
  108. {
  109. return UM.Theme.getColor("setting_control_disabled_border")
  110. }
  111. if (control.hovered || control.activeFocus)
  112. {
  113. return UM.Theme.getColor("setting_control_border_highlight")
  114. }
  115. return UM.Theme.getColor("setting_control_border")
  116. }
  117. }
  118. contentItem: Label
  119. {
  120. anchors.verticalCenter: parent.verticalCenter
  121. anchors.left: parent.left
  122. anchors.leftMargin: UM.Theme.getSize("setting_unit_margin").width
  123. anchors.right: downArrow.left
  124. rightPadding: swatch.width + UM.Theme.getSize("setting_unit_margin").width
  125. text: control.currentText
  126. renderType: Text.NativeRendering
  127. font: UM.Theme.getFont("default")
  128. color: enabled ? UM.Theme.getColor("setting_control_text") : UM.Theme.getColor("setting_control_disabled_text")
  129. elide: Text.ElideLeft
  130. verticalAlignment: Text.AlignVCenter
  131. background: Rectangle
  132. {
  133. id: swatch
  134. height: Math.round(UM.Theme.getSize("setting_control").height / 2)
  135. width: height
  136. anchors.right: parent.right
  137. anchors.verticalCenter: parent.verticalCenter
  138. anchors.margins: Math.round(UM.Theme.getSize("default_margin").width / 4)
  139. border.width: UM.Theme.getSize("default_lining").width
  140. border.color: enabled ? UM.Theme.getColor("setting_control_border") : UM.Theme.getColor("setting_control_disabled_border")
  141. radius: Math.round(width / 2)
  142. color: control.color
  143. }
  144. }
  145. popup: Popup {
  146. y: control.height - UM.Theme.getSize("default_lining").height
  147. width: control.width
  148. implicitHeight: contentItem.implicitHeight
  149. padding: UM.Theme.getSize("default_lining").width
  150. contentItem: ListView {
  151. clip: true
  152. implicitHeight: contentHeight
  153. model: control.popup.visible ? control.delegateModel : null
  154. currentIndex: control.highlightedIndex
  155. ScrollIndicator.vertical: ScrollIndicator { }
  156. }
  157. background: Rectangle {
  158. color: UM.Theme.getColor("setting_control")
  159. border.color: UM.Theme.getColor("setting_control_border")
  160. }
  161. }
  162. delegate: ItemDelegate
  163. {
  164. width: control.width - 2 * UM.Theme.getSize("default_lining").width
  165. height: control.height
  166. highlighted: control.highlightedIndex == index
  167. contentItem: Label
  168. {
  169. text: model.name
  170. renderType: Text.NativeRendering
  171. color: {
  172. if (model.enabled) {
  173. UM.Theme.getColor("setting_control_text")
  174. } else {
  175. UM.Theme.getColor("action_button_disabled_text");
  176. }
  177. }
  178. font: UM.Theme.getFont("default")
  179. elide: Text.ElideRight
  180. verticalAlignment: Text.AlignVCenter
  181. rightPadding: swatch.width + UM.Theme.getSize("setting_unit_margin").width
  182. background: Rectangle
  183. {
  184. id: swatch
  185. height: Math.round(UM.Theme.getSize("setting_control").height / 2)
  186. width: height
  187. anchors.right: parent.right
  188. anchors.verticalCenter: parent.verticalCenter
  189. anchors.margins: Math.round(UM.Theme.getSize("default_margin").width / 4)
  190. border.width: UM.Theme.getSize("default_lining").width
  191. border.color: enabled ? UM.Theme.getColor("setting_control_border") : UM.Theme.getColor("setting_control_disabled_border")
  192. radius: Math.round(width / 2)
  193. color: control.model.getItem(index).color
  194. }
  195. }
  196. background: Rectangle
  197. {
  198. color: parent.highlighted ? UM.Theme.getColor("setting_control_highlight") : "transparent"
  199. border.color: parent.highlighted ? UM.Theme.getColor("setting_control_border_highlight") : "transparent"
  200. }
  201. }
  202. }
  203. }