OnboardBanner.qml 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. // Copyright (c) 2021 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.15
  4. import QtQuick.Controls 2.15
  5. import QtQuick.Layouts 1.1
  6. import UM 1.6 as UM
  7. import Cura 1.6 as Cura
  8. // Onboarding banner.
  9. Rectangle
  10. {
  11. property alias icon: onboardingIcon.source
  12. property alias text: infoText.text
  13. property var onRemove
  14. property string readMoreUrl
  15. Layout.preferredHeight: childrenRect.height + 2 * UM.Theme.getSize("default_margin").height
  16. Layout.fillWidth: true
  17. Layout.margins: UM.Theme.getSize("default_margin").width
  18. color: UM.Theme.getColor("action_panel_secondary")
  19. // Icon
  20. UM.RecolorImage
  21. {
  22. id: onboardingIcon
  23. anchors
  24. {
  25. top: parent.top
  26. left: parent.left
  27. margins: UM.Theme.getSize("default_margin").width
  28. }
  29. width: UM.Theme.getSize("banner_icon_size").width
  30. height: UM.Theme.getSize("banner_icon_size").height
  31. }
  32. // Close button
  33. UM.SimpleButton
  34. {
  35. id: onboardingClose
  36. anchors
  37. {
  38. top: parent.top
  39. right: parent.right
  40. margins: UM.Theme.getSize("default_margin").width
  41. }
  42. width: UM.Theme.getSize("message_close").width
  43. height: UM.Theme.getSize("message_close").height
  44. color: UM.Theme.getColor("primary_text")
  45. hoverColor: UM.Theme.getColor("primary_text_hover")
  46. iconSource: UM.Theme.getIcon("Cancel")
  47. onClicked: onRemove()
  48. }
  49. // Body
  50. Label {
  51. id: infoText
  52. anchors
  53. {
  54. top: parent.top
  55. left: onboardingIcon.right
  56. right: onboardingClose.left
  57. margins: UM.Theme.getSize("default_margin").width
  58. }
  59. font: UM.Theme.getFont("default")
  60. renderType: Text.NativeRendering
  61. color: UM.Theme.getColor("primary_text")
  62. wrapMode: Text.Wrap
  63. elide: Text.ElideRight
  64. onLineLaidOut:
  65. {
  66. if(line.isLast)
  67. {
  68. // Check if read more button still fits after the body text
  69. if (line.implicitWidth + readMoreButton.width + UM.Theme.getSize("default_margin").width > width)
  70. {
  71. // If it does place it after the body text
  72. readMoreButton.anchors.bottomMargin = -(fontMetrics.height);
  73. readMoreButton.anchors.leftMargin = UM.Theme.getSize("thin_margin").width;
  74. }
  75. else
  76. {
  77. // Otherwise place it under the text
  78. readMoreButton.anchors.leftMargin = line.implicitWidth + UM.Theme.getSize("default_margin").width;
  79. readMoreButton.anchors.bottomMargin = 0;
  80. }
  81. }
  82. }
  83. }
  84. FontMetrics
  85. {
  86. id: fontMetrics
  87. font: UM.Theme.getFont("default")
  88. }
  89. Cura.TertiaryButton
  90. {
  91. id: readMoreButton
  92. anchors.left: infoText.left
  93. anchors.bottom: infoText.bottom
  94. text: "Learn More"
  95. textFont: UM.Theme.getFont("default")
  96. textColor: infoText.color
  97. leftPadding: 0
  98. rightPadding: 0
  99. iconSource: UM.Theme.getIcon("LinkExternal")
  100. isIconOnRightSide: true
  101. height: fontMetrics.height
  102. onClicked: Qt.openUrlExternally(readMoreUrl)
  103. }
  104. }