SettingComboBox.qml 4.7 KB

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