SettingOptionalExtruder.qml 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. // Copyright (c) 2016 Ultimaker B.V.
  2. // Uranium is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.2
  4. import QtQuick.Controls 2.1
  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.floor((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. font: UM.Theme.getFont("default")
  121. color: enabled ? UM.Theme.getColor("setting_control_text") : UM.Theme.getColor("setting_control_disabled_text")
  122. elide: Text.ElideRight
  123. verticalAlignment: Text.AlignVCenter
  124. background: Rectangle
  125. {
  126. id: swatch
  127. height: Math.floor(UM.Theme.getSize("setting_control").height / 2)
  128. width: height
  129. anchors.right: parent.right
  130. anchors.verticalCenter: parent.verticalCenter
  131. anchors.margins: Math.floor(UM.Theme.getSize("default_margin").width / 4)
  132. border.width: UM.Theme.getSize("default_lining").width
  133. border.color: enabled ? UM.Theme.getColor("setting_control_border") : UM.Theme.getColor("setting_control_disabled_border")
  134. radius: Math.floor(width / 2)
  135. color: control.color
  136. }
  137. }
  138. popup: Popup {
  139. y: control.height - UM.Theme.getSize("default_lining").height
  140. width: control.width
  141. implicitHeight: contentItem.implicitHeight
  142. padding: UM.Theme.getSize("default_lining").width
  143. contentItem: ListView {
  144. clip: true
  145. implicitHeight: contentHeight
  146. model: control.popup.visible ? control.delegateModel : null
  147. currentIndex: control.highlightedIndex
  148. ScrollIndicator.vertical: ScrollIndicator { }
  149. }
  150. background: Rectangle {
  151. color: UM.Theme.getColor("setting_control")
  152. border.color: UM.Theme.getColor("setting_control_border")
  153. }
  154. }
  155. delegate: ItemDelegate
  156. {
  157. width: control.width - 2 * UM.Theme.getSize("default_lining").width
  158. height: control.height
  159. highlighted: control.highlightedIndex == index
  160. contentItem: Label
  161. {
  162. text: model.name
  163. color: UM.Theme.getColor("setting_control_text")
  164. font: UM.Theme.getFont("default")
  165. elide: Text.ElideRight
  166. verticalAlignment: Text.AlignVCenter
  167. rightPadding: swatch.width + UM.Theme.getSize("setting_unit_margin").width
  168. background: Rectangle
  169. {
  170. id: swatch
  171. height: Math.floor(UM.Theme.getSize("setting_control").height / 2)
  172. width: height
  173. anchors.right: parent.right
  174. anchors.verticalCenter: parent.verticalCenter
  175. anchors.margins: Math.floor(UM.Theme.getSize("default_margin").width / 4)
  176. border.width: UM.Theme.getSize("default_lining").width
  177. border.color: enabled ? UM.Theme.getColor("setting_control_border") : UM.Theme.getColor("setting_control_disabled_border")
  178. radius: Math.floor(width / 2)
  179. color: control.model.getItem(index).color
  180. }
  181. }
  182. background: Rectangle
  183. {
  184. color: parent.highlighted ? UM.Theme.getColor("setting_control_highlight") : "transparent"
  185. border.color: parent.highlighted ? UM.Theme.getColor("setting_control_border_highlight") : "transparent"
  186. }
  187. }
  188. }
  189. }