SettingExtruder.qml 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. // Copyright (c) 2016 Ultimaker B.V.
  2. // Uranium is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.1
  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: Item
  94. {
  95. Label
  96. {
  97. id: extruderText
  98. anchors.verticalCenter: parent.verticalCenter
  99. anchors.left: parent.left
  100. anchors.leftMargin: UM.Theme.getSize("setting_unit_margin").width
  101. anchors.right: swatch.left
  102. text: control.currentText
  103. font: UM.Theme.getFont("default")
  104. color: enabled ? UM.Theme.getColor("setting_control_text") : UM.Theme.getColor("setting_control_disabled_text")
  105. elide: Text.ElideLeft
  106. verticalAlignment: Text.AlignVCenter
  107. }
  108. Rectangle
  109. {
  110. id: swatch
  111. height: UM.Theme.getSize("setting_control").height / 2
  112. width: height
  113. anchors.right: parent.right
  114. anchors.rightMargin: control.indicator.width + UM.Theme.getSize("setting_unit_margin").width
  115. anchors.verticalCenter: parent.verticalCenter
  116. anchors.margins: UM.Theme.getSize("default_margin").width / 4
  117. border.width: UM.Theme.getSize("default_lining").width
  118. border.color: enabled ? UM.Theme.getColor("setting_control_border") : UM.Theme.getColor("setting_control_disabled_border")
  119. radius: width / 2
  120. color: control.color
  121. }
  122. }
  123. delegate: ItemDelegate
  124. {
  125. width: control.width
  126. height: control.height
  127. highlighted: control.highlightedIndex == index
  128. contentItem: Text
  129. {
  130. text: model.name
  131. color: UM.Theme.getColor("setting_control_text")
  132. font: UM.Theme.getFont("default")
  133. elide: Text.ElideRight
  134. verticalAlignment: Text.AlignVCenter
  135. }
  136. }
  137. }
  138. }