PackageCardHeader.qml 8.3 KB

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