PackageCard.qml 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  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 - UM.Theme.getSize("narrow_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. // Separate column for icon on the left.
  39. Image
  40. {
  41. id: packageItem
  42. anchors
  43. {
  44. top: parent.top
  45. left: parent.left
  46. margins: UM.Theme.getSize("default_margin").width
  47. }
  48. width: UM.Theme.getSize("card_icon").width
  49. height: width
  50. source: packageData.iconUrl != "" ? packageData.iconUrl : "../images/placeholder.svg"
  51. }
  52. // Title row.
  53. RowLayout
  54. {
  55. id: titleBar
  56. anchors
  57. {
  58. left: packageItem.right
  59. right: parent.right
  60. top: parent.top
  61. topMargin: UM.Theme.getSize("default_margin").height
  62. leftMargin: UM.Theme.getSize("default_margin").width
  63. rightMargin:UM.Theme.getSize("thick_margin").width
  64. }
  65. Label
  66. {
  67. text: packageData.displayName
  68. font: UM.Theme.getFont("large_bold")
  69. color: UM.Theme.getColor("text")
  70. verticalAlignment: Text.AlignTop
  71. }
  72. Control
  73. {
  74. Layout.preferredWidth: UM.Theme.getSize("card_tiny_icon").width
  75. Layout.preferredHeight: UM.Theme.getSize("card_tiny_icon").height
  76. enabled: packageData.isCheckedByUltimaker
  77. visible: packageData.isCheckedByUltimaker
  78. Cura.ToolTip
  79. {
  80. tooltipText:
  81. {
  82. switch(packageData.packageType)
  83. {
  84. case "plugin": return catalog.i18nc("@info", "Ultimaker Verified Plug-in");
  85. case "material": return catalog.i18nc("@info", "Ultimaker Certified Material");
  86. default: return catalog.i18nc("@info", "Ultimaker Verified Package");
  87. }
  88. }
  89. visible: parent.hovered
  90. targetPoint: Qt.point(0, Math.round(parent.y + parent.height / 2))
  91. }
  92. Rectangle
  93. {
  94. anchors.fill: parent
  95. color: UM.Theme.getColor("action_button_hovered")
  96. radius: width
  97. UM.RecolorImage
  98. {
  99. anchors.fill: parent
  100. color: UM.Theme.getColor("primary")
  101. source: packageData.packageType == "plugin" ? UM.Theme.getIcon("CheckCircle") : UM.Theme.getIcon("Certified")
  102. }
  103. }
  104. //NOTE: Can we link to something here? (Probably a static link explaining what verified is):
  105. // onClicked: Qt.openUrlExternally( XXXXXX )
  106. }
  107. Control
  108. {
  109. Layout.preferredWidth: UM.Theme.getSize("card_tiny_icon").width
  110. Layout.preferredHeight: UM.Theme.getSize("card_tiny_icon").height
  111. Layout.alignment: Qt.AlignCenter
  112. enabled: false // remove!
  113. visible: false // replace packageInfo.XXXXXX
  114. // TODO: waiting for materials card implementation
  115. Cura.ToolTip
  116. {
  117. tooltipText: "" // TODO
  118. visible: parent.hovered
  119. }
  120. UM.RecolorImage
  121. {
  122. anchors.fill: parent
  123. color: UM.Theme.getColor("primary")
  124. source: UM.Theme.getIcon("CheckCircle") // TODO
  125. }
  126. // onClicked: Qt.openUrlExternally( XXXXXX ) // TODO
  127. }
  128. Label
  129. {
  130. id: packageVersionLabel
  131. text: packageData.packageVersion
  132. font: UM.Theme.getFont("default")
  133. color: UM.Theme.getColor("text")
  134. Layout.fillWidth: true
  135. }
  136. Button
  137. {
  138. id: externalLinkButton
  139. // For some reason if i set padding, they don't match up. If i set all of them explicitly, it does work?
  140. leftPadding: UM.Theme.getSize("narrow_margin").width
  141. rightPadding: UM.Theme.getSize("narrow_margin").width
  142. topPadding: UM.Theme.getSize("narrow_margin").width
  143. bottomPadding: UM.Theme.getSize("narrow_margin").width
  144. Layout.preferredWidth: UM.Theme.getSize("card_tiny_icon").width + 2 * padding
  145. Layout.preferredHeight: UM.Theme.getSize("card_tiny_icon").width + 2 * padding
  146. contentItem: UM.RecolorImage
  147. {
  148. source: UM.Theme.getIcon("LinkExternal")
  149. color: UM.Theme.getColor("icon")
  150. implicitWidth: UM.Theme.getSize("card_tiny_icon").width
  151. implicitHeight: UM.Theme.getSize("card_tiny_icon").height
  152. }
  153. background: Rectangle
  154. {
  155. color: externalLinkButton.hovered ? UM.Theme.getColor("action_button_hovered"): "transparent"
  156. radius: externalLinkButton.width / 2
  157. }
  158. onClicked: Qt.openUrlExternally(packageData.authorInfoUrl)
  159. }
  160. }
  161. // Description area
  162. Item
  163. {
  164. id: descriptionArea
  165. height: childrenRect.height > descriptionLabel.height ? childrenRect.height : descriptionLabel.height
  166. anchors
  167. {
  168. top: titleBar.bottom
  169. left: packageItem.right
  170. right: parent.right
  171. rightMargin: UM.Theme.getSize("default_margin").width
  172. leftMargin: UM.Theme.getSize("default_margin").width
  173. }
  174. Label
  175. {
  176. id: descriptionLabel
  177. width: parent.width
  178. property real lastLineWidth: 0; //Store the width of the last line, to properly position the elision.
  179. text: packageData.description
  180. font: UM.Theme.getFont("medium")
  181. color: UM.Theme.getColor("text")
  182. maximumLineCount: 2
  183. wrapMode: Text.Wrap
  184. elide: Text.ElideRight
  185. onLineLaidOut:
  186. {
  187. if(truncated && line.isLast)
  188. {
  189. let max_line_width = parent.width - readMoreButton.width - fontMetrics.advanceWidth("… ") - 2 * UM.Theme.getSize("default_margin").width;
  190. if(line.implicitWidth > max_line_width)
  191. {
  192. line.width = max_line_width;
  193. }
  194. else
  195. {
  196. line.width = line.implicitWidth - fontMetrics.advanceWidth("…"); //Truncate the ellipsis. We're adding this ourselves.
  197. }
  198. descriptionLabel.lastLineWidth = line.implicitWidth;
  199. }
  200. }
  201. }
  202. Label
  203. {
  204. id: tripleDotLabel
  205. anchors.left: parent.left
  206. anchors.leftMargin: descriptionLabel.lastLineWidth
  207. anchors.bottom: readMoreButton.bottom
  208. text: "… "
  209. font: descriptionLabel.font
  210. color: descriptionLabel.color
  211. visible: descriptionLabel.truncated
  212. }
  213. Cura.TertiaryButton
  214. {
  215. id: readMoreButton
  216. anchors.left: tripleDotLabel.right
  217. anchors.bottom: parent.bottom
  218. height: fontMetrics.height //Height of a single line.
  219. text: catalog.i18nc("@info", "Read more")
  220. iconSource: UM.Theme.getIcon("LinkExternal")
  221. visible: descriptionLabel.truncated
  222. enabled: visible
  223. leftPadding: UM.Theme.getSize("default_margin").width
  224. rightPadding: UM.Theme.getSize("wide_margin").width
  225. textFont: descriptionLabel.font
  226. isIconOnRightSide: true
  227. onClicked: Qt.openUrlExternally(packageData.packageInfoUrl)
  228. }
  229. }
  230. // Author and action buttons.
  231. RowLayout
  232. {
  233. id: authorAndActionButton
  234. width: parent.width
  235. anchors
  236. {
  237. bottom: parent.bottom
  238. left: packageItem.right
  239. right: parent.right
  240. margins: UM.Theme.getSize("default_margin").height
  241. }
  242. spacing: UM.Theme.getSize("narrow_margin").width
  243. Label
  244. {
  245. id: authorBy
  246. Layout.alignment: Qt.AlignVCenter
  247. text: catalog.i18nc("@label", "By")
  248. font: UM.Theme.getFont("default")
  249. color: UM.Theme.getColor("text")
  250. }
  251. Cura.TertiaryButton
  252. {
  253. Layout.fillWidth: true
  254. Layout.preferredHeight: authorBy.height
  255. Layout.alignment: Qt.AlignVCenter
  256. text: packageData.authorName
  257. textFont: UM.Theme.getFont("default_bold")
  258. textColor: UM.Theme.getColor("text") // override normal link color
  259. leftPadding: 0
  260. rightPadding: 0
  261. iconSource: UM.Theme.getIcon("LinkExternal")
  262. isIconOnRightSide: true
  263. onClicked: Qt.openUrlExternally(packageData.authorInfoUrl)
  264. }
  265. Cura.SecondaryButton
  266. {
  267. id: enableManageButton
  268. Layout.alignment: Qt.AlignTop
  269. text: packageData.enableManageButtonText
  270. visible: packageData.enableManageButtonVisible
  271. }
  272. Cura.SecondaryButton
  273. {
  274. id: installManageButton
  275. Layout.alignment: Qt.AlignTop
  276. text: packageData.installManageButtonText
  277. visible: packageData.installManageButtonVisible
  278. }
  279. Cura.PrimaryButton
  280. {
  281. id: updateManageButton
  282. Layout.alignment: Qt.AlignTop
  283. text: catalog.i18nc("@button", "Update") // OR Download, if new!
  284. visible: packageData.updateManageButtonVisible
  285. }
  286. }
  287. FontMetrics
  288. {
  289. id: fontMetrics
  290. font: UM.Theme.getFont("medium")
  291. }
  292. }