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