SettingExtruder.qml 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. }
  18. textRole: "name"
  19. anchors.fill: parent
  20. MouseArea
  21. {
  22. anchors.fill: parent
  23. acceptedButtons: Qt.NoButton
  24. onWheel: wheel.accepted = true;
  25. }
  26. style: ComboBoxStyle
  27. {
  28. background: Rectangle
  29. {
  30. color:
  31. {
  32. if (!enabled)
  33. {
  34. return UM.Theme.getColor("setting_control_disabled");
  35. }
  36. if(control.hovered || base.activeFocus)
  37. {
  38. return UM.Theme.getColor("setting_control_highlight");
  39. }
  40. else
  41. {
  42. return UM.Theme.getColor("setting_control");
  43. }
  44. }
  45. border.width: UM.Theme.getSize("default_lining").width
  46. 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")
  47. }
  48. label: Item
  49. {
  50. Rectangle
  51. {
  52. id: swatch
  53. height: UM.Theme.getSize("setting_control").height / 2
  54. width: height
  55. anchors.left: parent.left
  56. anchors.leftMargin: UM.Theme.getSize("default_lining").width
  57. anchors.verticalCenter: parent.verticalCenter
  58. color: extruders_model.getItem(control.currentIndex).colour
  59. border.width: UM.Theme.getSize("default_lining").width
  60. border.color: !enabled ? UM.Theme.getColor("setting_control_disabled_border") : UM.Theme.getColor("setting_control_border")
  61. }
  62. Label
  63. {
  64. anchors.left: swatch.right
  65. anchors.leftMargin: UM.Theme.getSize("default_lining").width
  66. anchors.right: downArrow.left
  67. anchors.rightMargin: UM.Theme.getSize("default_lining").width
  68. anchors.verticalCenter: parent.verticalCenter
  69. text: control.currentText
  70. font: UM.Theme.getFont("default")
  71. color: !enabled ? UM.Theme.getColor("setting_control_disabled_text") : UM.Theme.getColor("setting_control_text")
  72. elide: Text.ElideRight
  73. verticalAlignment: Text.AlignVCenter
  74. }
  75. UM.RecolorImage
  76. {
  77. id: downArrow
  78. anchors.right: parent.right
  79. anchors.rightMargin: UM.Theme.getSize("default_lining").width * 2
  80. anchors.verticalCenter: parent.verticalCenter
  81. source: UM.Theme.getIcon("arrow_bottom")
  82. width: UM.Theme.getSize("standard_arrow").width
  83. height: UM.Theme.getSize("standard_arrow").height
  84. sourceSize.width: width + 5
  85. sourceSize.height: width + 5
  86. color: UM.Theme.getColor("setting_control_text")
  87. }
  88. }
  89. }
  90. onActivated: { forceActiveFocus(); provider.setPropertyValue("value", extruders_model.getItem(index).index) };
  91. onModelChanged: updateCurrentIndex();
  92. Connections
  93. {
  94. target: provider
  95. onPropertiesChanged: control.updateCurrentIndex();
  96. }
  97. function updateCurrentIndex()
  98. {
  99. for(var i = 0; i < extruders_model.rowCount(); ++i)
  100. {
  101. if(extruders_model.getItem(i).index == provider.properties.value)
  102. {
  103. currentIndex = i;
  104. return;
  105. }
  106. }
  107. currentIndex = -1;
  108. }
  109. }
  110. }