PackageCardHeader.qml 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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. // As both the PackageCard and Package contain similar components; a package icon, title, author bar. These components
  9. // are combined into the reusable "PackageCardHeader" component
  10. Item
  11. {
  12. default property alias contents: contentItem.children
  13. property var packageData
  14. property bool showDisableButton: false
  15. property bool showInstallButton: false
  16. property bool showUpdateButton: false
  17. property string missingPackageReadMoreUrl: "https://support.ultimaker.com/hc/en-us/articles/360011968360-Using-the-Ultimaker-Marketplace?utm_source=cura&utm_medium=software&utm_campaign=load-file-material-missing"
  18. width: parent.width
  19. height: UM.Theme.getSize("card").height
  20. // card icon
  21. Item
  22. {
  23. id: packageItem
  24. anchors
  25. {
  26. top: parent.top
  27. left: parent.left
  28. margins: UM.Theme.getSize("default_margin").width
  29. }
  30. width: UM.Theme.getSize("card_icon").width
  31. height: width
  32. property bool packageHasIcon: packageData.iconUrl != ""
  33. Image
  34. {
  35. visible: parent.packageHasIcon
  36. anchors.fill: parent
  37. source: packageData.iconUrl
  38. }
  39. UM.ColorImage
  40. {
  41. visible: !parent.packageHasIcon
  42. anchors.fill: parent
  43. color: UM.Theme.getColor("text")
  44. source:
  45. {
  46. switch (packageData.packageType)
  47. {
  48. case "plugin":
  49. return Qt.resolvedUrl("../images/Plugin.svg");
  50. case "material":
  51. return Qt.resolvedUrl("../images/Spool.svg");
  52. default:
  53. return Qt.resolvedUrl("../images/placeholder.svg");
  54. }
  55. }
  56. }
  57. }
  58. ColumnLayout
  59. {
  60. anchors
  61. {
  62. left: packageItem.right
  63. leftMargin: UM.Theme.getSize("default_margin").width
  64. right: parent.right
  65. rightMargin: UM.Theme.getSize("default_margin").width
  66. top: parent.top
  67. topMargin: UM.Theme.getSize("narrow_margin").height
  68. }
  69. height: packageItem.height + packageItem.anchors.margins * 2
  70. // Title row.
  71. RowLayout
  72. {
  73. id: titleBar
  74. Layout.preferredWidth: parent.width
  75. Layout.preferredHeight: childrenRect.height
  76. UM.StatusIcon
  77. {
  78. width: UM.Theme.getSize("section_icon").width + UM.Theme.getSize("narrow_margin").width
  79. height: UM.Theme.getSize("section_icon").height
  80. status: UM.StatusIcon.Status.WARNING
  81. visible: packageData.isMissingPackageInformation
  82. }
  83. UM.Label
  84. {
  85. text: packageData.displayName
  86. font: UM.Theme.getFont("medium_bold")
  87. verticalAlignment: Text.AlignTop
  88. }
  89. VerifiedIcon
  90. {
  91. enabled: packageData.isCheckedByUltimaker
  92. visible: packageData.isCheckedByUltimaker
  93. }
  94. UM.Label
  95. {
  96. id: packageVersionLabel
  97. text: packageData.packageVersion
  98. Layout.fillWidth: true
  99. }
  100. Button
  101. {
  102. id: externalLinkButton
  103. visible: !packageData.isMissingPackageInformation
  104. // For some reason if i set padding, they don't match up. If i set all of them explicitly, it does work?
  105. leftPadding: UM.Theme.getSize("narrow_margin").width
  106. rightPadding: UM.Theme.getSize("narrow_margin").width
  107. topPadding: UM.Theme.getSize("narrow_margin").width
  108. bottomPadding: UM.Theme.getSize("narrow_margin").width
  109. width: UM.Theme.getSize("card_tiny_icon").width + 2 * padding
  110. height: UM.Theme.getSize("card_tiny_icon").width + 2 * padding
  111. contentItem: UM.ColorImage
  112. {
  113. source: UM.Theme.getIcon("LinkExternal")
  114. color: UM.Theme.getColor("icon")
  115. implicitWidth: UM.Theme.getSize("card_tiny_icon").width
  116. implicitHeight: UM.Theme.getSize("card_tiny_icon").height
  117. }
  118. background: Rectangle
  119. {
  120. color: externalLinkButton.hovered ? UM.Theme.getColor("action_button_hovered"): "transparent"
  121. radius: externalLinkButton.width / 2
  122. }
  123. onClicked: Qt.openUrlExternally(packageData.marketplaceURL)
  124. }
  125. }
  126. // When a package Card companent is created and children are provided to it they are rendered here
  127. Item {
  128. id: contentItem
  129. Layout.fillHeight: true
  130. Layout.preferredWidth: parent.width
  131. }
  132. // Author and action buttons.
  133. RowLayout
  134. {
  135. id: authorAndActionButton
  136. Layout.preferredWidth: parent.width
  137. Layout.preferredHeight: childrenRect.height
  138. spacing: UM.Theme.getSize("narrow_margin").width
  139. // label "By"
  140. UM.Label
  141. {
  142. id: authorBy
  143. visible: !packageData.isMissingPackageInformation
  144. Layout.alignment: Qt.AlignCenter
  145. text: catalog.i18nc("@label Is followed by the name of an author", "By")
  146. font: UM.Theme.getFont("default")
  147. color: UM.Theme.getColor("text")
  148. }
  149. // clickable author name
  150. Item
  151. {
  152. visible: !packageData.isMissingPackageInformation
  153. Layout.fillWidth: true
  154. implicitHeight: authorBy.height
  155. Layout.alignment: Qt.AlignTop
  156. Cura.TertiaryButton
  157. {
  158. text: packageData.authorName
  159. textFont: UM.Theme.getFont("default_bold")
  160. textColor: UM.Theme.getColor("text") // override normal link color
  161. leftPadding: 0
  162. rightPadding: 0
  163. iconSource: UM.Theme.getIcon("LinkExternal")
  164. isIconOnRightSide: true
  165. onClicked: Qt.openUrlExternally(packageData.authorInfoUrl)
  166. }
  167. }
  168. Item
  169. {
  170. visible: packageData.isMissingPackageInformation
  171. Layout.fillWidth: true
  172. implicitHeight: readMoreButton.height
  173. Layout.alignment: Qt.AlignTop
  174. Cura.TertiaryButton
  175. {
  176. id: readMoreButton
  177. text: catalog.i18nc("@button:label", "Learn More")
  178. leftPadding: 0
  179. rightPadding: 0
  180. iconSource: UM.Theme.getIcon("LinkExternal")
  181. isIconOnRightSide: true
  182. onClicked: Qt.openUrlExternally(missingPackageReadMoreUrl)
  183. }
  184. }
  185. ManageButton
  186. {
  187. id: enableManageButton
  188. visible: showDisableButton && packageData.isInstalled && !packageData.isToBeInstalled && packageData.packageType != "material" && !packageData.isMissingPackageInformation
  189. enabled: !packageData.busy
  190. button_style: !packageData.isActive
  191. Layout.alignment: Qt.AlignTop
  192. text: button_style ? catalog.i18nc("@button", "Enable") : catalog.i18nc("@button", "Disable")
  193. onClicked: packageData.isActive ? packageData.disable(): packageData.enable()
  194. }
  195. ManageButton
  196. {
  197. id: installManageButton
  198. visible: showInstallButton && (packageData.canDowngrade || !packageData.isBundled) && !packageData.isMissingPackageInformation
  199. enabled: !packageData.busy
  200. busy: packageData.busy
  201. button_style: !(packageData.isInstalled || packageData.isToBeInstalled)
  202. Layout.alignment: Qt.AlignTop
  203. text:
  204. {
  205. if (packageData.canDowngrade)
  206. {
  207. if (busy) { return catalog.i18nc("@button", "Downgrading..."); }
  208. else { return catalog.i18nc("@button", "Downgrade"); }
  209. }
  210. if (!(packageData.isInstalled || packageData.isToBeInstalled))
  211. {
  212. if (busy) { return catalog.i18nc("@button", "Installing..."); }
  213. else { return catalog.i18nc("@button", "Install"); }
  214. }
  215. else
  216. {
  217. return catalog.i18nc("@button", "Uninstall");
  218. }
  219. }
  220. onClicked: packageData.isInstalled || packageData.isToBeInstalled ? packageData.uninstall(): packageData.install()
  221. }
  222. ManageButton
  223. {
  224. id: updateManageButton
  225. visible: showUpdateButton && packageData.canUpdate && !packageData.isMissingPackageInformation
  226. enabled: !packageData.busy
  227. busy: packageData.busy
  228. Layout.alignment: Qt.AlignTop
  229. text: busy ? catalog.i18nc("@button", "Updating..."): catalog.i18nc("@button", "Update")
  230. onClicked: packageData.update()
  231. }
  232. }
  233. }
  234. }