SettingComboBox.qml 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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(); provider.setPropertyValue("value", definition.options[index].key) }
  75. onModelChanged: updateCurrentIndex();
  76. Connections
  77. {
  78. target: provider
  79. onPropertiesChanged: control.updateCurrentIndex()
  80. }
  81. function updateCurrentIndex() {
  82. for(var i = 0; i < definition.options.length; ++i) {
  83. if(definition.options[i].key == provider.properties.value) {
  84. currentIndex = i;
  85. return;
  86. }
  87. }
  88. currentIndex = -1;
  89. }
  90. }
  91. }