SettingComboBox.qml 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. // Copyright (c) 2015 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. SettingItem
  8. {
  9. id: base
  10. contents: ComboBox
  11. {
  12. id: control
  13. model: definition.options
  14. textRole: "value";
  15. anchors.fill: parent
  16. MouseArea
  17. {
  18. anchors.fill: parent;
  19. acceptedButtons: Qt.NoButton;
  20. onWheel: wheel.accepted = true;
  21. }
  22. style: ComboBoxStyle
  23. {
  24. background: Rectangle
  25. {
  26. color:
  27. {
  28. if (!enabled)
  29. {
  30. return UM.Theme.getColor("setting_control_disabled")
  31. }
  32. if(control.hovered || base.activeFocus)
  33. {
  34. return UM.Theme.getColor("setting_control_highlight")
  35. }
  36. else
  37. {
  38. return UM.Theme.getColor("setting_control")
  39. }
  40. }
  41. border.width: UM.Theme.getSize("default_lining").width;
  42. 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");
  43. }
  44. label: Item
  45. {
  46. Label
  47. {
  48. anchors.left: parent.left;
  49. anchors.leftMargin: UM.Theme.getSize("default_lining").width
  50. anchors.right: downArrow.left;
  51. anchors.rightMargin: UM.Theme.getSize("default_lining").width;
  52. anchors.verticalCenter: parent.verticalCenter;
  53. text: control.currentText;
  54. font: UM.Theme.getFont("default");
  55. color: !enabled ? UM.Theme.getColor("setting_control_disabled_text") : UM.Theme.getColor("setting_control_text");
  56. elide: Text.ElideRight;
  57. verticalAlignment: Text.AlignVCenter;
  58. }
  59. UM.RecolorImage
  60. {
  61. id: downArrow
  62. anchors.right: parent.right;
  63. anchors.rightMargin: UM.Theme.getSize("default_lining").width * 2;
  64. anchors.verticalCenter: parent.verticalCenter;
  65. source: UM.Theme.getIcon("arrow_bottom")
  66. width: UM.Theme.getSize("standard_arrow").width
  67. height: UM.Theme.getSize("standard_arrow").height
  68. sourceSize.width: width + 5
  69. sourceSize.height: width + 5
  70. color: UM.Theme.getColor("setting_control_text");
  71. }
  72. }
  73. }
  74. onActivated: { forceActiveFocus(); propertyProvider.setPropertyValue("value", definition.options[index].key) }
  75. Binding
  76. {
  77. target: control
  78. property: "currentIndex"
  79. value:
  80. {
  81. // FIXME this needs to go away once 'resolve' is combined with 'value' in our data model.
  82. var value;
  83. if ((base.resolve != "None") && (base.stackLevel != 0) && (base.stackLevel != 1)) {
  84. // We have a resolve function. Indicates that the setting is not settable per extruder and that
  85. // we have to choose between the resolved value (default) and the global value
  86. // (if user has explicitly set this).
  87. value = base.resolve;
  88. } else {
  89. value = propertyProvider.properties.value;
  90. }
  91. for(var i = 0; i < control.model.length; ++i) {
  92. if(control.model[i].key == value) {
  93. return i;
  94. }
  95. }
  96. return -1;
  97. }
  98. }
  99. }
  100. }