SettingComboBox.qml 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. ComboBox
  11. {
  12. // signal valueChanged(string value);
  13. // id: base
  14. model: definition.options
  15. textRole: "name";
  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 base.style.controlDisabledColor
  31. }
  32. if(control.hovered || base.activeFocus)
  33. {
  34. return base.style.controlHighlightColor
  35. }
  36. else
  37. {
  38. return base.style.controlColor
  39. }
  40. }
  41. border.width: base.style.controlBorderWidth;
  42. border.color: !enabled ? base.style.controlDisabledBorderColor : control.hovered ? base.style.controlBorderHighlightColor : base.style.controlBorderColor;
  43. }
  44. label: Item
  45. {
  46. Label
  47. {
  48. anchors.left: parent.left;
  49. anchors.leftMargin: base.style.controlBorderWidth
  50. anchors.right: downArrow.left;
  51. anchors.rightMargin: base.style.controlBorderWidth;
  52. anchors.verticalCenter: parent.verticalCenter;
  53. text: control.currentText;
  54. font: base.style.controlFont;
  55. color: !enabled ? base.style.controlDisabledTextColor : base.style.controlTextColor;
  56. elide: Text.ElideRight;
  57. verticalAlignment: Text.AlignVCenter;
  58. }
  59. UM.RecolorImage
  60. {
  61. id: downArrow
  62. anchors.right: parent.right;
  63. anchors.rightMargin: base.style.controlBorderWidth * 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: base.style.controlTextColor;
  71. }
  72. }
  73. }
  74. /*
  75. onActivated: {
  76. valueChanged(options.getItem(index).value);
  77. }
  78. onModelChanged: {
  79. updateCurrentIndex();
  80. }
  81. Component.onCompleted: {
  82. parent.parent.valueChanged.connect(updateCurrentIndex)
  83. }
  84. function updateCurrentIndex() {
  85. if (!options) {
  86. return;
  87. }
  88. for(var i = 0; i < options.rowCount(); ++i) {
  89. if(options.getItem(i).value == value) {
  90. currentIndex = i;
  91. return;
  92. }
  93. }
  94. currentIndex = -1;
  95. }*/
  96. }
  97. }