PackageCard.qml 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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. Item
  162. {
  163. id: descriptionArea
  164. height: descriptionLabel.height
  165. anchors
  166. {
  167. top: titleBar.bottom
  168. left: packageItem.right
  169. right: parent.right
  170. rightMargin: UM.Theme.getSize("default_margin").width
  171. leftMargin: UM.Theme.getSize("default_margin").width
  172. }
  173. Label
  174. {
  175. id: descriptionLabel
  176. width: parent.width
  177. property real lastLineWidth: 0; //Store the width of the last line, to properly position the elision.
  178. text: packageData.description
  179. font: UM.Theme.getFont("medium")
  180. color: UM.Theme.getColor("text")
  181. maximumLineCount: 2
  182. wrapMode: Text.Wrap
  183. elide: Text.ElideRight
  184. onLineLaidOut:
  185. {
  186. if(truncated && line.isLast)
  187. {
  188. let max_line_width = parent.width - readMoreButton.width - fontMetrics.advanceWidth("… ") - 2 * UM.Theme.getSize("default_margin").width;
  189. if(line.implicitWidth > max_line_width)
  190. {
  191. line.width = max_line_width;
  192. }
  193. else
  194. {
  195. line.width = line.implicitWidth - fontMetrics.advanceWidth("…"); //Truncate the ellipsis. We're adding this ourselves.
  196. }
  197. descriptionLabel.lastLineWidth = line.implicitWidth;
  198. }
  199. }
  200. }
  201. Label
  202. {
  203. id: tripleDotLabel
  204. anchors.left: parent.left
  205. anchors.leftMargin: descriptionLabel.lastLineWidth
  206. anchors.bottom: readMoreButton.bottom
  207. text: "… "
  208. font: descriptionLabel.font
  209. color: descriptionLabel.color
  210. visible: descriptionLabel.truncated
  211. }
  212. Cura.TertiaryButton
  213. {
  214. id: readMoreButton
  215. anchors.left: tripleDotLabel.right
  216. anchors.bottom: parent.bottom
  217. height: fontMetrics.height //Height of a single line.
  218. text: catalog.i18nc("@info", "Read more")
  219. iconSource: UM.Theme.getIcon("LinkExternal")
  220. visible: descriptionLabel.truncated
  221. enabled: visible
  222. leftPadding: UM.Theme.getSize("default_margin").width
  223. rightPadding: UM.Theme.getSize("wide_margin").width
  224. textFont: descriptionLabel.font
  225. isIconOnRightSide: true
  226. onClicked: Qt.openUrlExternally(packageData.packageInfoUrl)
  227. }
  228. }
  229. // Author and action buttons.
  230. RowLayout
  231. {
  232. id: authorAndActionButton
  233. width: parent.width
  234. anchors
  235. {
  236. bottom: parent.bottom
  237. left: packageItem.right
  238. margins: UM.Theme.getSize("default_margin").height
  239. }
  240. spacing: UM.Theme.getSize("narrow_margin").width
  241. Label
  242. {
  243. id: authorBy
  244. Layout.alignment: Qt.AlignTop
  245. text: catalog.i18nc("@label", "By")
  246. font: UM.Theme.getFont("default")
  247. color: UM.Theme.getColor("text")
  248. }
  249. Cura.TertiaryButton
  250. {
  251. Layout.fillWidth: true
  252. Layout.preferredHeight: authorBy.height
  253. Layout.alignment: Qt.AlignTop
  254. text: packageData.authorName
  255. textFont: UM.Theme.getFont("default_bold")
  256. textColor: UM.Theme.getColor("text") // override normal link color
  257. leftPadding: 0
  258. rightPadding: 0
  259. iconSource: UM.Theme.getIcon("LinkExternal")
  260. isIconOnRightSide: true
  261. onClicked: Qt.openUrlExternally(packageData.authorInfoUrl)
  262. }
  263. Cura.SecondaryButton
  264. {
  265. id: disableButton
  266. Layout.alignment: Qt.AlignTop
  267. text: catalog.i18nc("@button", "Disable")
  268. visible: false // not functional right now, also only when unfolding and required
  269. }
  270. Cura.SecondaryButton
  271. {
  272. id: uninstallButton
  273. Layout.alignment: Qt.AlignTop
  274. text: catalog.i18nc("@button", "Uninstall")
  275. visible: false // not functional right now, also only when unfolding and required
  276. }
  277. Cura.PrimaryButton
  278. {
  279. id: installButton
  280. Layout.alignment: Qt.AlignTop
  281. text: catalog.i18nc("@button", "Update") // OR Download, if new!
  282. visible: false // not functional right now, also only when unfolding and required
  283. }
  284. }
  285. FontMetrics
  286. {
  287. id: fontMetrics
  288. font: UM.Theme.getFont("medium")
  289. }
  290. }