SettingOptionalExtruder.qml 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. // Copyright (c) 2016 Ultimaker B.V.
  2. // Uranium is released under the terms of the AGPLv3 or higher.
  3. import QtQuick 2.1
  4. import QtQuick.Controls 1.1
  5. import QtQuick.Controls.Styles 1.1
  6. import UM 1.1 as UM
  7. import Cura 1.0 as Cura
  8. SettingItem
  9. {
  10. id: base
  11. property var focusItem: control
  12. contents: ComboBox
  13. {
  14. id: control
  15. anchors.fill: parent
  16. model: Cura.ExtrudersModel
  17. {
  18. onModelChanged: control.color = getItem(control.currentIndex).color
  19. addOptionalExtruder: true
  20. }
  21. textRole: "name"
  22. onActivated:
  23. {
  24. forceActiveFocus();
  25. propertyProvider.setPropertyValue("value", model.getItem(index).index);
  26. }
  27. onActiveFocusChanged:
  28. {
  29. if(activeFocus)
  30. {
  31. base.focusReceived();
  32. }
  33. }
  34. Keys.onTabPressed:
  35. {
  36. base.setActiveFocusToNextSetting(true)
  37. }
  38. Keys.onBacktabPressed:
  39. {
  40. base.setActiveFocusToNextSetting(false)
  41. }
  42. Binding
  43. {
  44. target: control
  45. property: "currentIndex"
  46. value:
  47. {
  48. if(propertyProvider.properties.value == -1)
  49. {
  50. return control.model.items.length - 1
  51. }
  52. return propertyProvider.properties.value
  53. }
  54. // Sometimes when the value is already changed, the model is still being built.
  55. // The when clause ensures that the current index is not updated when this happens.
  56. when: control.model.items.length > 0
  57. }
  58. MouseArea
  59. {
  60. anchors.fill: parent
  61. acceptedButtons: Qt.NoButton
  62. onWheel: wheel.accepted = true;
  63. }
  64. property string color: "#fff"
  65. Binding
  66. {
  67. // We override the color property's value when the ExtruderModel changes. So we need to use an
  68. // explicit binding here otherwise we do not handle value changes after the model changes.
  69. target: control
  70. property: "color"
  71. value: control.currentText != "" ? control.model.getItem(control.currentIndex).color : ""
  72. }
  73. style: ComboBoxStyle
  74. {
  75. background: Rectangle
  76. {
  77. color:
  78. {
  79. if(!enabled)
  80. {
  81. return UM.Theme.getColor("setting_control_disabled");
  82. }
  83. if(control.hovered || control.activeFocus)
  84. {
  85. return UM.Theme.getColor("setting_control_highlight");
  86. }
  87. return UM.Theme.getColor("setting_control");
  88. }
  89. border.width: UM.Theme.getSize("default_lining").width
  90. border.color:
  91. {
  92. if(!enabled)
  93. {
  94. return UM.Theme.getColor("setting_control_disabled_border")
  95. }
  96. if(control.hovered || control.activeFocus)
  97. {
  98. return UM.Theme.getColor("setting_control_border_highlight")
  99. }
  100. return UM.Theme.getColor("setting_control_border")
  101. }
  102. }
  103. label: Item
  104. {
  105. Label
  106. {
  107. anchors.verticalCenter: parent.verticalCenter
  108. width: parent.width - swatch.width - arrow.width;
  109. text: control.currentText
  110. font: UM.Theme.getFont("default")
  111. color: enabled ? UM.Theme.getColor("setting_control_text") : UM.Theme.getColor("setting_control_disabled_text")
  112. elide: Text.ElideRight
  113. verticalAlignment: Text.AlignVCenter
  114. }
  115. Rectangle
  116. {
  117. id: swatch
  118. height: UM.Theme.getSize("setting_control").height / 2
  119. width: height
  120. anchors
  121. {
  122. right: arrow.left;
  123. verticalCenter: parent.verticalCenter
  124. margins: UM.Theme.getSize("default_margin").width / 4
  125. }
  126. border.width: UM.Theme.getSize("default_lining").width * 2
  127. border.color: enabled ? UM.Theme.getColor("setting_control_border") : UM.Theme.getColor("setting_control_disabled_border")
  128. radius: width / 2
  129. color: control.color
  130. }
  131. UM.RecolorImage
  132. {
  133. id: arrow
  134. anchors.right: parent.right
  135. anchors.verticalCenter: parent.verticalCenter
  136. source: UM.Theme.getIcon("arrow_bottom")
  137. width: UM.Theme.getSize("standard_arrow").width
  138. height: UM.Theme.getSize("standard_arrow").height
  139. sourceSize.width: width + 5
  140. sourceSize.height: width + 5
  141. color: UM.Theme.getColor("setting_control_text")
  142. }
  143. }
  144. }
  145. }
  146. }