SettingExtruder.qml 6.9 KB

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