ObjectSelector.qml 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. // Copyright (c) 2022 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.5 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.ColorImage
  36. {
  37. id: openCloseIcon
  38. width: UM.Theme.getSize("standard_arrow").width
  39. height: UM.Theme.getSize("standard_arrow").height
  40. anchors.left: parent.left
  41. color: openCloseButton.hovered ? UM.Theme.getColor("small_button_text_hover") : UM.Theme.getColor("small_button_text")
  42. source: objectSelector.opened ? UM.Theme.getIcon("ChevronSingleDown") : UM.Theme.getIcon("ChevronSingleUp")
  43. }
  44. UM.Label
  45. {
  46. id: label
  47. anchors.left: openCloseIcon.right
  48. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  49. text: catalog.i18nc("@label", "Object list")
  50. color: openCloseButton.hovered ? UM.Theme.getColor("small_button_text_hover") : UM.Theme.getColor("small_button_text")
  51. elide: Text.ElideRight
  52. }
  53. }
  54. background: Item {}
  55. onClicked:
  56. {
  57. UM.Preferences.setValue("cura/show_list_of_objects", !objectSelector.opened)
  58. objectSelector.opened = UM.Preferences.getValue("cura/show_list_of_objects")
  59. }
  60. }
  61. Rectangle
  62. {
  63. id: contents
  64. width: parent.width
  65. visible: objectSelector.opened
  66. height: visible ? listView.height + border.width * 2 : 0
  67. color: UM.Theme.getColor("main_background")
  68. border.width: UM.Theme.getSize("default_lining").width
  69. border.color: UM.Theme.getColor("lining")
  70. Behavior on height { NumberAnimation { duration: 100 } }
  71. anchors.bottom: parent.bottom
  72. property var extrudersModel: CuraApplication.getExtrudersModel()
  73. UM.SettingPropertyProvider
  74. {
  75. id: machineExtruderCount
  76. containerStack: Cura.MachineManager.activeMachine
  77. key: "machine_extruder_count"
  78. watchedProperties: [ "value" ]
  79. storeIndex: 0
  80. }
  81. ListView
  82. {
  83. id: listView
  84. anchors
  85. {
  86. left: parent.left
  87. right: parent.right
  88. top: parent.top
  89. margins: UM.Theme.getSize("default_lining").width
  90. }
  91. property real maximumHeight: UM.Theme.getSize("objects_menu_size").height
  92. height: Math.min(contentHeight, maximumHeight)
  93. ScrollBar.vertical: UM.ScrollBar
  94. {
  95. id: scrollBar
  96. }
  97. clip: true
  98. model: Cura.ObjectsModel {}
  99. delegate: ObjectItemButton
  100. {
  101. id: modelButton
  102. Binding
  103. {
  104. target: modelButton
  105. property: "checked"
  106. value: model.selected
  107. }
  108. text: model.name
  109. width: listView.width - scrollBar.width
  110. property bool outsideBuildArea: model.outside_build_area
  111. property int perObjectSettingsCount: model.per_object_settings_count
  112. property string meshType: model.mesh_type
  113. property int extruderNumber: model.extruder_number
  114. property string extruderColor:
  115. {
  116. if (model.extruder_number == -1)
  117. {
  118. return "";
  119. }
  120. return contents.extrudersModel.getItem(model.extruder_number).color;
  121. }
  122. property bool showExtruderSwatches: machineExtruderCount.properties.value > 1
  123. }
  124. }
  125. }
  126. }