SettingExtruder.qml 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. contents: ComboBox
  12. {
  13. id: control
  14. model: Cura.ExtrudersModel
  15. {
  16. id: extruders_model
  17. onModelChanged: control.color = extruders_model.getItem(control.currentIndex).color
  18. }
  19. property string color:
  20. {
  21. var model_color = extruders_model.getItem(control.currentIndex).color;
  22. return (model_color) ? model_color : "";
  23. }
  24. textRole: "name"
  25. anchors.fill: parent
  26. onCurrentIndexChanged: updateCurrentColor();
  27. MouseArea
  28. {
  29. anchors.fill: parent
  30. acceptedButtons: Qt.NoButton
  31. onWheel: wheel.accepted = true;
  32. }
  33. style: ComboBoxStyle
  34. {
  35. background: Rectangle
  36. {
  37. color:
  38. {
  39. if (!enabled)
  40. {
  41. return UM.Theme.getColor("setting_control_disabled");
  42. }
  43. if(control.hovered || base.activeFocus)
  44. {
  45. return UM.Theme.getColor("setting_control_highlight");
  46. }
  47. else
  48. {
  49. return UM.Theme.getColor("setting_control");
  50. }
  51. }
  52. border.width: UM.Theme.getSize("default_lining").width
  53. border.color: !enabled ? UM.Theme.getColor("setting_control_disabled_border") : control.hovered ? UM.Theme.getColor("setting_control_border_highlight") : UM.Theme.getColor("setting_control_border")
  54. }
  55. label: Item
  56. {
  57. Rectangle
  58. {
  59. id: swatch
  60. height: UM.Theme.getSize("setting_control").height / 2
  61. width: height
  62. anchors.left: parent.left
  63. anchors.leftMargin: UM.Theme.getSize("default_lining").width
  64. anchors.verticalCenter: parent.verticalCenter
  65. color: control.color
  66. border.width: UM.Theme.getSize("default_lining").width
  67. border.color: !enabled ? UM.Theme.getColor("setting_control_disabled_border") : UM.Theme.getColor("setting_control_border")
  68. }
  69. Label
  70. {
  71. anchors.left: swatch.right
  72. anchors.leftMargin: UM.Theme.getSize("default_lining").width
  73. anchors.right: downArrow.left
  74. anchors.rightMargin: UM.Theme.getSize("default_lining").width
  75. anchors.verticalCenter: parent.verticalCenter
  76. text: control.currentText
  77. font: UM.Theme.getFont("default")
  78. color: !enabled ? UM.Theme.getColor("setting_control_disabled_text") : UM.Theme.getColor("setting_control_text")
  79. elide: Text.ElideRight
  80. verticalAlignment: Text.AlignVCenter
  81. }
  82. UM.RecolorImage
  83. {
  84. id: downArrow
  85. anchors.right: parent.right
  86. anchors.rightMargin: UM.Theme.getSize("default_lining").width * 2
  87. anchors.verticalCenter: parent.verticalCenter
  88. source: UM.Theme.getIcon("arrow_bottom")
  89. width: UM.Theme.getSize("standard_arrow").width
  90. height: UM.Theme.getSize("standard_arrow").height
  91. sourceSize.width: width + 5
  92. sourceSize.height: width + 5
  93. color: UM.Theme.getColor("setting_control_text")
  94. }
  95. }
  96. }
  97. onActivated:
  98. {
  99. forceActiveFocus();
  100. propertyProvider.setPropertyValue("value", extruders_model.getItem(index).index);
  101. control.color = extruders_model.getItem(index).color;
  102. }
  103. onModelChanged: updateCurrentIndex();
  104. Binding
  105. {
  106. target: control
  107. property: "currentIndex"
  108. value:
  109. {
  110. for(var i = 0; i < extruders_model.rowCount(); ++i)
  111. {
  112. if(extruders_model.getItem(i).index == propertyProvider.properties.value)
  113. {
  114. return i;
  115. }
  116. }
  117. return -1;
  118. }
  119. }
  120. // In some cases we want to update the current color without updating the currentIndex, so it's a seperate function.
  121. function updateCurrentColor()
  122. {
  123. for(var i = 0; i < extruders_model.rowCount(); ++i)
  124. {
  125. if(extruders_model.getItem(i).index == currentIndex)
  126. {
  127. control.color = extruders_model.getItem(i).color;
  128. return;
  129. }
  130. }
  131. }
  132. function updateCurrentIndex()
  133. {
  134. for(var i = 0; i < extruders_model.rowCount(); ++i)
  135. {
  136. if(extruders_model.getItem(i).index == propertyProvider.properties.value)
  137. {
  138. control.currentIndex = i;
  139. return;
  140. }
  141. }
  142. currentIndex = -1;
  143. }
  144. }
  145. }