SettingExtruder.qml 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 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 { onModelChanged: control.color = getItem(control.currentIndex).color }
  17. textRole: "name"
  18. onActivated:
  19. {
  20. forceActiveFocus();
  21. propertyProvider.setPropertyValue("value", model.getItem(index).index);
  22. }
  23. onActiveFocusChanged:
  24. {
  25. if(activeFocus)
  26. {
  27. base.focusReceived();
  28. }
  29. }
  30. Keys.onTabPressed:
  31. {
  32. base.setActiveFocusToNextSetting(true)
  33. }
  34. Keys.onBacktabPressed:
  35. {
  36. base.setActiveFocusToNextSetting(false)
  37. }
  38. currentIndex: propertyProvider.properties.value
  39. MouseArea
  40. {
  41. anchors.fill: parent
  42. acceptedButtons: Qt.NoButton
  43. onWheel: wheel.accepted = true;
  44. }
  45. property string color: "#fff"
  46. Binding
  47. {
  48. // We override the color property's value when the ExtruderModel changes. So we need to use an
  49. // explicit binding here otherwise we do not handle value changes after the model changes.
  50. target: control
  51. property: "color"
  52. value: control.currentText != "" ? control.model.getItem(control.currentIndex).color : ""
  53. }
  54. style: ComboBoxStyle
  55. {
  56. background: Rectangle
  57. {
  58. color:
  59. {
  60. if(!enabled)
  61. {
  62. return UM.Theme.getColor("setting_control_disabled");
  63. }
  64. if(control.hovered || base.activeFocus)
  65. {
  66. return UM.Theme.getColor("setting_control_highlight");
  67. }
  68. return UM.Theme.getColor("setting_control");
  69. }
  70. border.width: UM.Theme.getSize("default_lining").width
  71. border.color:
  72. {
  73. if(!enabled)
  74. {
  75. return UM.Theme.getColor("setting_control_disabled_border")
  76. }
  77. if(control.hovered || control.activeFocus)
  78. {
  79. return UM.Theme.getColor("setting_control_border_highlight")
  80. }
  81. return UM.Theme.getColor("setting_control_border")
  82. }
  83. }
  84. label: Item
  85. {
  86. Label
  87. {
  88. id: extruderText
  89. anchors.verticalCenter: parent.verticalCenter
  90. text: control.currentText
  91. font: UM.Theme.getFont("default")
  92. color: enabled ? UM.Theme.getColor("setting_control_text") : UM.Theme.getColor("setting_control_disabled_text")
  93. elide: Text.ElideLeft
  94. verticalAlignment: Text.AlignVCenter
  95. }
  96. Rectangle
  97. {
  98. id: swatch
  99. height: UM.Theme.getSize("setting_control").height / 2
  100. width: height
  101. anchors
  102. {
  103. right: arrow.left
  104. verticalCenter: parent.verticalCenter
  105. margins: UM.Theme.getSize("default_margin").width / 4
  106. }
  107. border.width: UM.Theme.getSize("default_lining").width * 2
  108. border.color: enabled ? UM.Theme.getColor("setting_control_border") : UM.Theme.getColor("setting_control_disabled_border")
  109. radius: width / 2
  110. color: control.color
  111. }
  112. UM.RecolorImage
  113. {
  114. id: arrow
  115. anchors.right: parent.right
  116. anchors.verticalCenter: parent.verticalCenter
  117. source: UM.Theme.getIcon("arrow_bottom")
  118. width: UM.Theme.getSize("standard_arrow").width
  119. height: UM.Theme.getSize("standard_arrow").height
  120. sourceSize.width: width + 5 * screenScaleFactor
  121. sourceSize.height: width + 5 * screenScaleFactor
  122. color: UM.Theme.getColor("setting_control_text")
  123. }
  124. }
  125. }
  126. }
  127. }