PackageCard.qml 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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 var packageData
  11. width: parent ? parent.width - UM.Theme.getSize("default_margin").width : 0
  12. height: UM.Theme.getSize("card").height
  13. color: UM.Theme.getColor("main_background")
  14. radius: UM.Theme.getSize("default_radius").width
  15. states:
  16. [
  17. State
  18. {
  19. name: "Folded"
  20. when: true // TODO
  21. PropertyChanges
  22. {
  23. target: descriptionArea
  24. visible: true
  25. }
  26. },
  27. State
  28. {
  29. name: "Header"
  30. when: false // TODO
  31. PropertyChanges
  32. {
  33. target: descriptionArea
  34. visible: false
  35. }
  36. }
  37. ]
  38. Image //Separate column for icon on the left.
  39. {
  40. id: packageItem
  41. anchors
  42. {
  43. top: parent.top
  44. left: parent.left
  45. margins: UM.Theme.getSize("default_margin").width
  46. }
  47. width: UM.Theme.getSize("card_icon").width
  48. height: width
  49. source: packageData.iconUrl != "" ? packageData.iconUrl : "../images/placeholder.svg"
  50. }
  51. RowLayout //Title row.
  52. {
  53. id: titleBar
  54. anchors
  55. {
  56. left: packageItem.right
  57. right: parent.right
  58. top: parent.top
  59. topMargin: UM.Theme.getSize("default_margin").height
  60. leftMargin: UM.Theme.getSize("default_margin").width
  61. rightMargin:UM.Theme.getSize("thick_margin").width
  62. }
  63. Label
  64. {
  65. text: packageData.displayName
  66. font: UM.Theme.getFont("large_bold")
  67. color: UM.Theme.getColor("text")
  68. verticalAlignment: Text.AlignTop
  69. }
  70. Control
  71. {
  72. Layout.preferredWidth: UM.Theme.getSize("card_tiny_icon").width
  73. Layout.preferredHeight: UM.Theme.getSize("card_tiny_icon").height
  74. enabled: packageData.isVerified
  75. visible: packageData.isVerified
  76. Cura.ToolTip
  77. {
  78. tooltipText: catalog.i18nc("@info", "Verified")
  79. visible: parent.hovered
  80. }
  81. Rectangle
  82. {
  83. anchors.fill: parent
  84. color: UM.Theme.getColor("action_button_hovered")
  85. radius: width
  86. UM.RecolorImage
  87. {
  88. anchors.fill: parent
  89. color: UM.Theme.getColor("primary")
  90. source: UM.Theme.getIcon("CheckCircle")
  91. }
  92. }
  93. //NOTE: Can we link to something here? (Probably a static link explaining what verified is):
  94. // onClicked: Qt.openUrlExternally( XXXXXX )
  95. }
  96. Control
  97. {
  98. Layout.preferredWidth: UM.Theme.getSize("card_tiny_icon").width
  99. Layout.preferredHeight: UM.Theme.getSize("card_tiny_icon").height
  100. Layout.alignment: Qt.AlignCenter
  101. enabled: false // remove!
  102. visible: false // replace packageInfo.XXXXXX
  103. // TODO: waiting for materials card implementation
  104. Cura.ToolTip
  105. {
  106. tooltipText: "" // TODO
  107. visible: parent.hovered
  108. }
  109. UM.RecolorImage
  110. {
  111. anchors.fill: parent
  112. color: UM.Theme.getColor("primary")
  113. source: UM.Theme.getIcon("CheckCircle") // TODO
  114. }
  115. // onClicked: Qt.openUrlExternally( XXXXXX ) // TODO
  116. }
  117. Label
  118. {
  119. id: packageVersionLabel
  120. text: packageData.packageVersion
  121. font: UM.Theme.getFont("default")
  122. color: UM.Theme.getColor("text")
  123. Layout.fillWidth: true
  124. }
  125. UM.SimpleButton
  126. {
  127. id: externalLinkButton
  128. Layout.preferredWidth: UM.Theme.getSize("card_tiny_icon").width
  129. Layout.preferredHeight: UM.Theme.getSize("card_tiny_icon").height
  130. Layout.alignment: Qt.AlignTop
  131. iconSource: UM.Theme.getIcon("LinkExternal")
  132. hoverColor: UM.Theme.getColor("text_link")
  133. onClicked: Qt.openUrlExternally(packageData.packageInfoUrl)
  134. }
  135. }
  136. Item
  137. {
  138. id: descriptionArea
  139. height: descriptionLabel.height
  140. anchors
  141. {
  142. top: titleBar.bottom
  143. left: packageItem.right
  144. right: parent.right
  145. rightMargin: UM.Theme.getSize("default_margin").width
  146. leftMargin: UM.Theme.getSize("default_margin").width
  147. }
  148. Label
  149. {
  150. id: descriptionLabel
  151. width: parent.width
  152. property real lastLineWidth: 0; //Store the width of the last line, to properly position the elision.
  153. text: packageData.description
  154. font: UM.Theme.getFont("medium")
  155. color: UM.Theme.getColor("text")
  156. maximumLineCount: 2
  157. wrapMode: Text.Wrap
  158. elide: Text.ElideRight
  159. onLineLaidOut:
  160. {
  161. if(truncated && line.isLast)
  162. {
  163. let max_line_width = parent.width - readMoreButton.width - fontMetrics.advanceWidth("… ") - 2 * UM.Theme.getSize("default_margin").width;
  164. if(line.implicitWidth > max_line_width)
  165. {
  166. line.width = max_line_width;
  167. }
  168. else
  169. {
  170. line.width = line.implicitWidth - fontMetrics.advanceWidth("…"); //Truncate the ellipsis. We're adding this ourselves.
  171. }
  172. descriptionLabel.lastLineWidth = line.implicitWidth;
  173. }
  174. }
  175. }
  176. Label
  177. {
  178. id: tripleDotLabel
  179. anchors.left: parent.left
  180. anchors.leftMargin: descriptionLabel.lastLineWidth
  181. anchors.bottom: readMoreButton.bottom
  182. text: "… "
  183. font: descriptionLabel.font
  184. color: descriptionLabel.color
  185. visible: descriptionLabel.truncated
  186. }
  187. Cura.TertiaryButton
  188. {
  189. id: readMoreButton
  190. anchors.left: tripleDotLabel.right
  191. anchors.bottom: parent.bottom
  192. height: fontMetrics.height //Height of a single line.
  193. text: catalog.i18nc("@info", "Read more")
  194. iconSource: UM.Theme.getIcon("LinkExternal")
  195. visible: descriptionLabel.truncated
  196. enabled: visible
  197. leftPadding: UM.Theme.getSize("default_margin").width
  198. rightPadding: UM.Theme.getSize("wide_margin").width
  199. textFont: descriptionLabel.font
  200. isIconOnRightSide: true
  201. // NOTE: Is this the right URL for this action?
  202. onClicked: Qt.openUrlExternally(packageData.packageInfoUrl)
  203. }
  204. }
  205. RowLayout //Author and action buttons.
  206. {
  207. id: authorAndACtionButton
  208. width: parent.width
  209. anchors
  210. {
  211. bottom: parent.bottom
  212. left: packageItem.right
  213. margins: UM.Theme.getSize("default_margin").height
  214. }
  215. spacing: UM.Theme.getSize("narrow_margin").width
  216. Label
  217. {
  218. id: authorBy
  219. Layout.alignment: Qt.AlignTop
  220. text: catalog.i18nc("@label", "By")
  221. font: UM.Theme.getFont("default")
  222. color: UM.Theme.getColor("text")
  223. }
  224. Cura.TertiaryButton
  225. {
  226. Layout.fillWidth: true
  227. Layout.preferredHeight: authorBy.height
  228. Layout.alignment: Qt.AlignTop
  229. text: packageData.authorName
  230. textFont: UM.Theme.getFont("default_bold")
  231. textColor: UM.Theme.getColor("text") // override normal link color
  232. leftPadding: 0
  233. rightPadding: 0
  234. iconSource: UM.Theme.getIcon("LinkExternal")
  235. isIconOnRightSide: true
  236. onClicked: Qt.openUrlExternally(packageData.authorInfoUrl)
  237. }
  238. Cura.SecondaryButton
  239. {
  240. id: disableButton
  241. Layout.alignment: Qt.AlignTop
  242. text: catalog.i18nc("@button", "Disable")
  243. visible: false // not functional right now, also only when unfolding and required
  244. }
  245. Cura.SecondaryButton
  246. {
  247. id: uninstallButton
  248. Layout.alignment: Qt.AlignTop
  249. text: catalog.i18nc("@button", "Uninstall")
  250. visible: false // not functional right now, also only when unfolding and required
  251. }
  252. Cura.PrimaryButton
  253. {
  254. id: installButton
  255. Layout.alignment: Qt.AlignTop
  256. text: catalog.i18nc("@button", "Update") // OR Download, if new!
  257. visible: false // not functional right now, also only when unfolding and required
  258. }
  259. }
  260. FontMetrics
  261. {
  262. id: fontMetrics
  263. font: UM.Theme.getFont("medium")
  264. }
  265. }