OnboardBanner.qml 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. implicitHeight: childrenRect.height + 2 * UM.Theme.getSize("default_margin").height
  16. color: UM.Theme.getColor("action_panel_secondary")
  17. // Icon
  18. UM.RecolorImage
  19. {
  20. id: onboardingIcon
  21. anchors
  22. {
  23. top: parent.top
  24. left: parent.left
  25. margins: UM.Theme.getSize("default_margin").width
  26. }
  27. width: UM.Theme.getSize("banner_icon_size").width
  28. height: UM.Theme.getSize("banner_icon_size").height
  29. }
  30. // Close button
  31. UM.SimpleButton
  32. {
  33. id: onboardingClose
  34. anchors
  35. {
  36. top: parent.top
  37. right: parent.right
  38. margins: UM.Theme.getSize("default_margin").width
  39. }
  40. width: UM.Theme.getSize("message_close").width
  41. height: UM.Theme.getSize("message_close").height
  42. color: UM.Theme.getColor("primary_text")
  43. hoverColor: UM.Theme.getColor("primary_text_hover")
  44. iconSource: UM.Theme.getIcon("Cancel")
  45. onClicked: onRemove()
  46. }
  47. // Body
  48. Label {
  49. id: infoText
  50. anchors
  51. {
  52. top: parent.top
  53. left: onboardingIcon.right
  54. right: onboardingClose.left
  55. margins: UM.Theme.getSize("default_margin").width
  56. }
  57. font: UM.Theme.getFont("default")
  58. renderType: Text.NativeRendering
  59. color: UM.Theme.getColor("primary_text")
  60. wrapMode: Text.Wrap
  61. elide: Text.ElideRight
  62. onLineLaidOut:
  63. {
  64. if(line.isLast)
  65. {
  66. // Check if read more button still fits after the body text
  67. if (line.implicitWidth + readMoreButton.width + UM.Theme.getSize("default_margin").width > width)
  68. {
  69. // If it does place it after the body text
  70. readMoreButton.anchors.bottomMargin = -(fontMetrics.height);
  71. readMoreButton.anchors.leftMargin = UM.Theme.getSize("thin_margin").width;
  72. }
  73. else
  74. {
  75. // Otherwise place it under the text
  76. readMoreButton.anchors.leftMargin = line.implicitWidth + UM.Theme.getSize("default_margin").width;
  77. readMoreButton.anchors.bottomMargin = 0;
  78. }
  79. }
  80. }
  81. }
  82. FontMetrics
  83. {
  84. id: fontMetrics
  85. font: UM.Theme.getFont("default")
  86. }
  87. Cura.TertiaryButton
  88. {
  89. id: readMoreButton
  90. anchors.left: infoText.left
  91. anchors.bottom: infoText.bottom
  92. text: "Learn More"
  93. textFont: UM.Theme.getFont("default")
  94. textColor: infoText.color
  95. leftPadding: 0
  96. rightPadding: 0
  97. iconSource: UM.Theme.getIcon("LinkExternal")
  98. isIconOnRightSide: true
  99. height: fontMetrics.height
  100. onClicked: Qt.openUrlExternally(readMoreUrl)
  101. }
  102. }