ObjectSelector.qml 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. // Copyright (c) 2019 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.10
  4. import QtQuick.Controls 2.3
  5. import UM 1.2 as UM
  6. import Cura 1.0 as Cura
  7. Item
  8. {
  9. id: objectSelector
  10. width: UM.Theme.getSize("objects_menu_size").width
  11. property bool opened: UM.Preferences.getValue("cura/show_list_of_objects")
  12. // Eat up all the mouse events (we don't want the scene to react or have the scene context menu showing up)
  13. MouseArea
  14. {
  15. anchors.fill: parent
  16. acceptedButtons: Qt.AllButtons
  17. }
  18. Button
  19. {
  20. id: openCloseButton
  21. width: parent.width
  22. height: contentItem.height + bottomPadding
  23. hoverEnabled: true
  24. padding: 0
  25. bottomPadding: UM.Theme.getSize("narrow_margin").height / 2 | 0
  26. anchors
  27. {
  28. bottom: contents.top
  29. horizontalCenter: parent.horizontalCenter
  30. }
  31. contentItem: Item
  32. {
  33. width: parent.width
  34. height: label.height
  35. UM.RecolorImage
  36. {
  37. id: openCloseIcon
  38. width: UM.Theme.getSize("standard_arrow").width
  39. height: UM.Theme.getSize("standard_arrow").height
  40. sourceSize.width: width
  41. anchors.left: parent.left
  42. color: openCloseButton.hovered ? UM.Theme.getColor("small_button_text_hover") : UM.Theme.getColor("small_button_text")
  43. source: objectSelector.opened ? UM.Theme.getIcon("arrow_bottom") : UM.Theme.getIcon("arrow_top")
  44. }
  45. Label
  46. {
  47. id: label
  48. anchors.left: openCloseIcon.right
  49. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  50. text: catalog.i18nc("@label", "Object list")
  51. font: UM.Theme.getFont("default")
  52. color: openCloseButton.hovered ? UM.Theme.getColor("small_button_text_hover") : UM.Theme.getColor("small_button_text")
  53. renderType: Text.NativeRendering
  54. elide: Text.ElideRight
  55. }
  56. }
  57. background: Item {}
  58. onClicked:
  59. {
  60. UM.Preferences.setValue("cura/show_list_of_objects", !objectSelector.opened)
  61. objectSelector.opened = UM.Preferences.getValue("cura/show_list_of_objects")
  62. }
  63. }
  64. Rectangle
  65. {
  66. id: contents
  67. width: parent.width
  68. visible: objectSelector.opened
  69. height: visible ? listView.height : 0
  70. color: UM.Theme.getColor("main_background")
  71. border.width: UM.Theme.getSize("default_lining").width
  72. border.color: UM.Theme.getColor("lining")
  73. Behavior on height { NumberAnimation { duration: 100 } }
  74. anchors.bottom: parent.bottom
  75. ListView
  76. {
  77. id: listView
  78. clip: true
  79. anchors
  80. {
  81. left: parent.left
  82. right: parent.right
  83. margins: UM.Theme.getSize("default_lining").width
  84. }
  85. ScrollBar.vertical: ScrollBar
  86. {
  87. hoverEnabled: true
  88. }
  89. property real maximumHeight: UM.Theme.getSize("objects_menu_size").height
  90. height: Math.min(contentHeight, maximumHeight)
  91. model: Cura.ObjectsModel {}
  92. delegate: ObjectItemButton
  93. {
  94. id: modelButton
  95. Binding
  96. {
  97. target: modelButton
  98. property: "checked"
  99. value: model.selected
  100. }
  101. text: model.name
  102. width: listView.width
  103. }
  104. }
  105. }
  106. }