PackageCard.qml 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. Rectangle
  9. {
  10. property alias packageData: packageCardHeader.packageData
  11. property alias showUpdateButton: packageCardHeader.showUpdateButton
  12. property alias showDisableButton: packageCardHeader.showDisableButton
  13. property alias showInstallButton: packageCardHeader.showInstallButton
  14. height: childrenRect.height
  15. color: UM.Theme.getColor("main_background")
  16. radius: UM.Theme.getSize("default_radius").width
  17. PackageCardHeader
  18. {
  19. id: packageCardHeader
  20. Item
  21. {
  22. id: shortDescription
  23. anchors.fill: parent
  24. Label
  25. {
  26. id: descriptionLabel
  27. width: parent.width
  28. property real lastLineWidth: 0; //Store the width of the last line, to properly position the elision.
  29. text: packageData.description
  30. textFormat: Text.PlainText //Must be plain text, or we won't get onLineLaidOut signals. Don't auto-detect!
  31. font: UM.Theme.getFont("default")
  32. color: UM.Theme.getColor("text")
  33. maximumLineCount: 2
  34. wrapMode: Text.Wrap
  35. elide: Text.ElideRight
  36. visible: text !== ""
  37. onLineLaidOut:
  38. {
  39. if(truncated && line.isLast)
  40. {
  41. let max_line_width = parent.width - readMoreButton.width - fontMetrics.advanceWidth("… ") - 2 * UM.Theme.getSize("default_margin").width;
  42. if(line.implicitWidth > max_line_width)
  43. {
  44. line.width = max_line_width;
  45. }
  46. else
  47. {
  48. line.width = line.implicitWidth - fontMetrics.advanceWidth("…"); //Truncate the ellipsis. We're adding this ourselves.
  49. }
  50. descriptionLabel.lastLineWidth = line.implicitWidth;
  51. }
  52. }
  53. }
  54. Label
  55. {
  56. id: tripleDotLabel
  57. anchors.left: parent.left
  58. anchors.leftMargin: descriptionLabel.lastLineWidth
  59. anchors.bottom: descriptionLabel.bottom
  60. text: "… "
  61. font: descriptionLabel.font
  62. color: descriptionLabel.color
  63. visible: descriptionLabel.truncated && descriptionLabel.text !== ""
  64. }
  65. Cura.TertiaryButton
  66. {
  67. id: readMoreButton
  68. anchors.right: parent.right
  69. anchors.bottom: descriptionLabel.bottom
  70. height: fontMetrics.height //Height of a single line.
  71. text: catalog.i18nc("@info", "Read more")
  72. iconSource: UM.Theme.getIcon("LinkExternal")
  73. visible: descriptionLabel.truncated && descriptionLabel.text !== ""
  74. enabled: visible
  75. leftPadding: UM.Theme.getSize("default_margin").width
  76. rightPadding: UM.Theme.getSize("wide_margin").width
  77. textFont: descriptionLabel.font
  78. isIconOnRightSide: true
  79. onClicked: Qt.openUrlExternally(packageData.packageInfoUrl)
  80. }
  81. }
  82. }
  83. FontMetrics
  84. {
  85. id: fontMetrics
  86. font: UM.Theme.getFont("default")
  87. }
  88. }