DropDownWidget.qml 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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.3 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. height: header.contentShown ? (header.height + contentRectangle.height) : 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. 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("arrow_bottom") : UM.Theme.getIcon("arrow_right")
  42. contentShown: base.contentShown
  43. }
  44. Cura.RoundedRectangle
  45. {
  46. id: contentRectangle
  47. anchors.top: header.bottom
  48. anchors.left: header.left
  49. anchors.right: header.right
  50. height: contentLoader.height
  51. border.width: UM.Theme.getSize("default_lining").width
  52. border.color: UM.Theme.getColor("lining")
  53. color: "white"
  54. radius: UM.Theme.getSize("default_radius").width
  55. visible: base.contentShown
  56. cornerSide: Cura.RoundedRectangle.Direction.Down
  57. Loader
  58. {
  59. id: contentLoader
  60. anchors.top: parent.top
  61. anchors.left: parent.left
  62. anchors.right: parent.right
  63. // Keep a small margin with the Rectangle container so its content will not overlap with the Rectangle
  64. // border.
  65. anchors.margins: UM.Theme.getSize("default_lining").width
  66. sourceComponent: base.contentComponent != null ? base.contentComponent : emptyComponent
  67. }
  68. // This is the empty component/placeholder that will be shown when the widget gets expanded.
  69. // It contains a text line "Empty"
  70. Component
  71. {
  72. id: emptyComponent
  73. Label
  74. {
  75. text: catalog.i18nc("@label", "Empty")
  76. height: UM.Theme.getSize("action_button").height
  77. horizontalAlignment: Text.AlignHCenter
  78. verticalAlignment: Text.AlignVCenter
  79. font: UM.Theme.getFont("medium")
  80. renderType: Text.NativeRendering
  81. }
  82. }
  83. }
  84. }