SettingExtruder.qml 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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 + (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. font: UM.Theme.getFont("default")
  102. color: enabled ? UM.Theme.getColor("setting_control_text") : UM.Theme.getColor("setting_control_disabled_text")
  103. elide: Text.ElideLeft
  104. verticalAlignment: Text.AlignVCenter
  105. background: Rectangle
  106. {
  107. id: swatch
  108. height: Math.floor(UM.Theme.getSize("setting_control").height / 2)
  109. width: height
  110. anchors.right: parent.right
  111. anchors.verticalCenter: parent.verticalCenter
  112. anchors.margins: Math.floor(UM.Theme.getSize("default_margin").width / 4)
  113. border.width: UM.Theme.getSize("default_lining").width
  114. border.color: enabled ? UM.Theme.getColor("setting_control_border") : UM.Theme.getColor("setting_control_disabled_border")
  115. radius: Math.floor(width / 2)
  116. color: control.color
  117. }
  118. }
  119. popup: Popup {
  120. y: control.height - UM.Theme.getSize("default_lining").height
  121. width: control.width
  122. implicitHeight: contentItem.implicitHeight
  123. padding: UM.Theme.getSize("default_lining").width
  124. contentItem: ListView {
  125. clip: true
  126. implicitHeight: contentHeight
  127. model: control.popup.visible ? control.delegateModel : null
  128. currentIndex: control.highlightedIndex
  129. ScrollIndicator.vertical: ScrollIndicator { }
  130. }
  131. background: Rectangle {
  132. color: UM.Theme.getColor("setting_control")
  133. border.color: UM.Theme.getColor("setting_control_border")
  134. }
  135. }
  136. delegate: ItemDelegate
  137. {
  138. width: control.width - 2 * UM.Theme.getSize("default_lining").width
  139. height: control.height
  140. highlighted: control.highlightedIndex == index
  141. contentItem: Label
  142. {
  143. text: model.name
  144. color: UM.Theme.getColor("setting_control_text")
  145. font: UM.Theme.getFont("default")
  146. elide: Text.ElideRight
  147. verticalAlignment: Text.AlignVCenter
  148. rightPadding: swatch.width + UM.Theme.getSize("setting_unit_margin").width
  149. background: Rectangle
  150. {
  151. id: swatch
  152. height: Math.floor(UM.Theme.getSize("setting_control").height / 2)
  153. width: height
  154. anchors.right: parent.right
  155. anchors.verticalCenter: parent.verticalCenter
  156. anchors.margins: Math.floor(UM.Theme.getSize("default_margin").width / 4)
  157. border.width: UM.Theme.getSize("default_lining").width
  158. border.color: enabled ? UM.Theme.getColor("setting_control_border") : UM.Theme.getColor("setting_control_disabled_border")
  159. radius: Math.floor(width / 2)
  160. color: control.model.getItem(index).color
  161. }
  162. }
  163. background: Rectangle
  164. {
  165. color: parent.highlighted ? UM.Theme.getColor("setting_control_highlight") : "transparent"
  166. border.color: parent.highlighted ? UM.Theme.getColor("setting_control_border_highlight") : "transparent"
  167. }
  168. }
  169. }
  170. }