ObjectSelector.qml 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. // Copyright (c) 2020 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("ChevronSingleDown") : UM.Theme.getIcon("ChevronSingleUp")
  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. property var extrudersModel: CuraApplication.getExtrudersModel()
  76. UM.SettingPropertyProvider
  77. {
  78. id: machineExtruderCount
  79. containerStack: Cura.MachineManager.activeMachine
  80. key: "machine_extruder_count"
  81. watchedProperties: [ "value" ]
  82. storeIndex: 0
  83. }
  84. ListView
  85. {
  86. id: listView
  87. clip: true
  88. anchors
  89. {
  90. left: parent.left
  91. right: parent.right
  92. margins: UM.Theme.getSize("default_lining").width
  93. }
  94. ScrollBar.vertical: ScrollBar
  95. {
  96. hoverEnabled: true
  97. }
  98. property real maximumHeight: UM.Theme.getSize("objects_menu_size").height
  99. height: Math.min(contentHeight, maximumHeight)
  100. model: Cura.ObjectsModel {}
  101. delegate: ObjectItemButton
  102. {
  103. id: modelButton
  104. Binding
  105. {
  106. target: modelButton
  107. property: "checked"
  108. value: model.selected
  109. }
  110. text: model.name
  111. width: listView.width
  112. property bool outsideBuildArea: model.outside_build_area
  113. property int perObjectSettingsCount: model.per_object_settings_count
  114. property string meshType: model.mesh_type
  115. property int extruderNumber: model.extruder_number
  116. property string extruderColor:
  117. {
  118. if (model.extruder_number == -1)
  119. {
  120. return "";
  121. }
  122. return contents.extrudersModel.getItem(model.extruder_number).color;
  123. }
  124. property bool showExtruderSwatches: machineExtruderCount.properties.value > 1
  125. }
  126. }
  127. }
  128. }