PackageCardHeader.qml 7.4 KB

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