PackageCard.qml 3.4 KB

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