PackageCardHeader.qml 8.1 KB

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