PackageCard.qml 10 KB

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