OnboardBanner.qml 3.2 KB

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