OnboardBanner.qml 3.1 KB

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