Marketplace.qml 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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.15
  6. import QtQuick.Window 2.2
  7. import UM 1.2 as UM
  8. import Cura 1.6 as Cura
  9. Window
  10. {
  11. id: marketplaceDialog
  12. property variant catalog: UM.I18nCatalog { name: "cura" }
  13. signal searchStringChanged(string new_search)
  14. minimumWidth: UM.Theme.getSize("modal_window_minimum").width
  15. minimumHeight: UM.Theme.getSize("modal_window_minimum").height
  16. width: minimumWidth
  17. height: minimumHeight
  18. onVisibleChanged:
  19. {
  20. pageSelectionTabBar.currentIndex = 0; //Go back to the initial tab.
  21. while(contextStack.depth > 1)
  22. {
  23. contextStack.pop(); //Do NOT use the StackView.Immediate transition here, since it causes the window to stay empty. Seemingly a Qt bug: https://bugreports.qt.io/browse/QTBUG-60670?
  24. }
  25. }
  26. Connections
  27. {
  28. target: Cura.API.account
  29. function onLoginStateChanged()
  30. {
  31. close();
  32. }
  33. }
  34. title: "Marketplace" //Seen by Ultimaker as a brand name, so this doesn't get translated.
  35. modality: Qt.NonModal
  36. // Background color
  37. Rectangle
  38. {
  39. anchors.fill: parent
  40. color: UM.Theme.getColor("main_background")
  41. //The Marketplace can have a page in front of everything with package details. The stack view controls its visibility.
  42. StackView
  43. {
  44. id: contextStack
  45. anchors.fill: parent
  46. initialItem: packageBrowse
  47. ColumnLayout
  48. {
  49. id: packageBrowse
  50. spacing: UM.Theme.getSize("default_margin").height
  51. // Page title.
  52. Item
  53. {
  54. Layout.preferredWidth: parent.width
  55. Layout.preferredHeight: childrenRect.height + UM.Theme.getSize("default_margin").height
  56. Label
  57. {
  58. id: pageTitle
  59. anchors
  60. {
  61. left: parent.left
  62. leftMargin: UM.Theme.getSize("default_margin").width
  63. right: parent.right
  64. rightMargin: UM.Theme.getSize("default_margin").width
  65. bottom: parent.bottom
  66. }
  67. font: UM.Theme.getFont("large")
  68. color: UM.Theme.getColor("text")
  69. text: content.item ? content.item.pageTitle: catalog.i18nc("@title", "Loading...")
  70. }
  71. }
  72. OnboardBanner
  73. {
  74. visible: content.item && content.item.bannerVisible
  75. text: content.item && content.item.bannerText
  76. icon: content.item && content.item.bannerIcon
  77. onRemove: content.item && content.item.onRemoveBanner
  78. readMoreUrl: content.item && content.item.bannerReadMoreUrl
  79. }
  80. // Search & Top-Level Tabs
  81. Item
  82. {
  83. Layout.preferredHeight: childrenRect.height
  84. Layout.preferredWidth: parent.width - 2 * UM.Theme.getSize("thin_margin").width
  85. RowLayout
  86. {
  87. width: parent.width
  88. height: UM.Theme.getSize("button_icon").height + UM.Theme.getSize("default_margin").height
  89. spacing: UM.Theme.getSize("thin_margin").width
  90. Rectangle
  91. {
  92. color: "transparent"
  93. Layout.preferredHeight: parent.height
  94. Layout.preferredWidth: searchBar.visible ? UM.Theme.getSize("thin_margin").width : 0
  95. Layout.fillWidth: ! searchBar.visible
  96. }
  97. Cura.SearchBar
  98. {
  99. id: searchBar
  100. Layout.preferredHeight: UM.Theme.getSize("button_icon").height
  101. Layout.fillWidth: true
  102. onTextEdited: searchStringChanged(text)
  103. }
  104. // Page selection.
  105. TabBar
  106. {
  107. id: pageSelectionTabBar
  108. Layout.alignment: Qt.AlignRight
  109. height: UM.Theme.getSize("button_icon").height
  110. spacing: 0
  111. background: Rectangle { color: "transparent" }
  112. onCurrentIndexChanged:
  113. {
  114. searchBar.text = "";
  115. searchBar.visible = currentItem.hasSearch;
  116. content.source = currentItem.sourcePage;
  117. }
  118. PackageTypeTab
  119. {
  120. id: pluginTabText
  121. width: implicitWidth
  122. text: catalog.i18nc("@button", "Plugins")
  123. property string sourcePage: "Plugins.qml"
  124. property bool hasSearch: true
  125. }
  126. PackageTypeTab
  127. {
  128. id: materialsTabText
  129. width: implicitWidth
  130. text: catalog.i18nc("@button", "Materials")
  131. property string sourcePage: "Materials.qml"
  132. property bool hasSearch: true
  133. }
  134. ManagePackagesButton
  135. {
  136. property string sourcePage: "ManagedPackages.qml"
  137. property bool hasSearch: false
  138. }
  139. }
  140. TextMetrics
  141. {
  142. id: pluginTabTextMetrics
  143. text: pluginTabText.text
  144. font: pluginTabText.font
  145. }
  146. TextMetrics
  147. {
  148. id: materialsTabTextMetrics
  149. text: materialsTabText.text
  150. font: materialsTabText.font
  151. }
  152. }
  153. }
  154. FontMetrics
  155. {
  156. id: fontMetrics
  157. font: UM.Theme.getFont("default")
  158. }
  159. Cura.TertiaryButton
  160. {
  161. text: catalog.i18nc("@info", "Search in the browser")
  162. iconSource: UM.Theme.getIcon("LinkExternal")
  163. visible: pageSelectionTabBar.currentItem.hasSearch
  164. isIconOnRightSide: true
  165. height: fontMetrics.height
  166. textFont: fontMetrics.font
  167. textColor: UM.Theme.getColor("text")
  168. onClicked: content.item && Qt.openUrlExternally(content.item.searchInBrowserUrl)
  169. }
  170. // Page contents.
  171. Rectangle
  172. {
  173. Layout.preferredWidth: parent.width
  174. Layout.fillHeight: true
  175. color: UM.Theme.getColor("detail_background")
  176. // Page contents.
  177. Loader
  178. {
  179. id: content
  180. anchors.fill: parent
  181. anchors.margins: UM.Theme.getSize("default_margin").width
  182. source: "Plugins.qml"
  183. Connections
  184. {
  185. target: content
  186. function onLoaded()
  187. {
  188. pageTitle.text = content.item.pageTitle
  189. searchStringChanged.connect(handleSearchStringChanged)
  190. }
  191. function handleSearchStringChanged(new_search)
  192. {
  193. content.item.model.searchString = new_search
  194. }
  195. }
  196. }
  197. }
  198. }
  199. }
  200. }
  201. }