SettingOptionalExtruder.qml 7.5 KB

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