PackageCardHeader.qml 9.7 KB

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