PackageCardHeader.qml 8.2 KB

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