ObjectSelector.qml 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 ? scroll.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. ScrollView
  76. {
  77. id: scroll
  78. width: parent.width
  79. clip: true
  80. padding: UM.Theme.getSize("default_lining").width
  81. contentItem: ListView
  82. {
  83. id: listView
  84. // Can't use parent.width since the parent is the flickable component and not the ScrollView
  85. width: scroll.width - scroll.leftPadding - scroll.rightPadding
  86. property real maximumHeight: UM.Theme.getSize("objects_menu_size").height
  87. // We use an extra property here, since we only want to to be informed about the content size changes.
  88. onContentHeightChanged:
  89. {
  90. // It can sometimes happen that (due to animations / updates) the contentHeight is -1.
  91. // This can cause a bunch of updates to trigger oneother, leading to a weird loop.
  92. if(contentHeight >= 0)
  93. {
  94. scroll.height = Math.min(contentHeight, maximumHeight) + scroll.topPadding + scroll.bottomPadding
  95. }
  96. }
  97. Component.onCompleted:
  98. {
  99. scroll.height = Math.min(contentHeight, maximumHeight) + scroll.topPadding + scroll.bottomPadding
  100. }
  101. model: Cura.ObjectsModel {}
  102. delegate: ObjectItemButton
  103. {
  104. id: modelButton
  105. Binding
  106. {
  107. target: modelButton
  108. property: "checked"
  109. value: model.selected
  110. }
  111. text: model.name
  112. width: listView.width
  113. }
  114. }
  115. }
  116. }
  117. }