DropDownWidget.qml 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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.1 as Cura
  7. //
  8. // This is the dropdown list widget in the welcome wizard. The dropdown list has a header bar which is always present,
  9. // and its content whose visibility can be toggled by clicking on the header bar. The content is displayed as an
  10. // expandable dropdown box that will appear below the header bar.
  11. //
  12. // The content is configurable via the property "contentComponent", which will be loaded by a Loader when set.
  13. //
  14. Item
  15. {
  16. UM.I18nCatalog { id: catalog; name: "cura" }
  17. id: base
  18. implicitWidth: 200 * screenScaleFactor
  19. implicitHeight: contentShown ? (header.height + contentRectangle.implicitHeight) : header.height
  20. property var contentComponent: null
  21. property alias contentItem: contentLoader.item
  22. property alias title: header.title
  23. property bool contentShown: false // indicates if this dropdown widget is expanded to show its content
  24. signal clicked()
  25. Connections
  26. {
  27. target: header
  28. function onClicked()
  29. {
  30. base.contentShown = !base.contentShown
  31. clicked()
  32. }
  33. }
  34. DropDownHeader
  35. {
  36. id: header
  37. anchors.top: parent.top
  38. anchors.left: parent.left
  39. anchors.right: parent.right
  40. height: UM.Theme.getSize("expandable_component_content_header").height
  41. rightIconSource: contentShown ? UM.Theme.getIcon("ChevronSingleDown") : UM.Theme.getIcon("ChevronSingleLeft")
  42. contentShown: base.contentShown
  43. }
  44. Cura.RoundedRectangle
  45. {
  46. id: contentRectangle
  47. anchors.top: header.bottom
  48. // Move up a bit (exactly the width of the border) to avoid double line
  49. anchors.topMargin: -UM.Theme.getSize("default_lining").width
  50. anchors.left: header.left
  51. anchors.right: header.right
  52. anchors.bottom: parent.bottom
  53. // Add 2x lining, because it needs a bit of space on the top and the bottom.
  54. anchors.bottomMargin: UM.Theme.getSize("thick_lining").height
  55. border.width: UM.Theme.getSize("default_lining").width
  56. border.color: UM.Theme.getColor("lining")
  57. color: UM.Theme.getColor("main_background")
  58. radius: UM.Theme.getSize("default_radius").width
  59. visible: base.contentShown
  60. cornerSide: Cura.RoundedRectangle.Direction.Down
  61. Loader
  62. {
  63. id: contentLoader
  64. anchors.fill: parent
  65. // Keep a small margin with the Rectangle container so its content will not overlap with the Rectangle
  66. // border.
  67. anchors.margins: UM.Theme.getSize("default_lining").width
  68. sourceComponent: base.contentComponent != null ? base.contentComponent : emptyComponent
  69. }
  70. // This is the empty component/placeholder that will be shown when the widget gets expanded.
  71. // It contains a text line "Empty"
  72. Component
  73. {
  74. id: emptyComponent
  75. UM.Label
  76. {
  77. text: catalog.i18nc("@label", "Empty")
  78. height: UM.Theme.getSize("action_button").height
  79. horizontalAlignment: Text.AlignHCenter
  80. font: UM.Theme.getFont("medium")
  81. }
  82. }
  83. }
  84. }