PluginBrowser.qml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. // Copyright (c) 2017 Ultimaker B.V.
  2. // PluginBrowser is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.2
  4. import QtQuick.Dialogs 1.1
  5. import QtQuick.Window 2.2
  6. import QtQuick.Controls 1.4
  7. import QtQuick.Controls.Styles 1.4
  8. // TODO: Switch to QtQuick.Controls 2.x and remove QtQuick.Controls.Styles
  9. import UM 1.1 as UM
  10. Window {
  11. id: base
  12. title: catalog.i18nc("@title:tab", "Plugins");
  13. modality: Qt.ApplicationModal
  14. width: 800 * screenScaleFactor
  15. height: 640 * screenScaleFactor
  16. minimumWidth: 350 * screenScaleFactor
  17. minimumHeight: 350 * screenScaleFactor
  18. color: UM.Theme.getColor("sidebar")
  19. Item {
  20. id: view
  21. anchors {
  22. fill: parent
  23. leftMargin: UM.Theme.getSize("default_margin").width
  24. rightMargin: UM.Theme.getSize("default_margin").width
  25. topMargin: UM.Theme.getSize("default_margin").height
  26. bottomMargin: UM.Theme.getSize("default_margin").height
  27. }
  28. Rectangle {
  29. id: topBar
  30. width: parent.width
  31. color: "transparent"
  32. height: childrenRect.height
  33. Row {
  34. spacing: 12
  35. height: childrenRect.height
  36. width: childrenRect.width
  37. anchors.horizontalCenter: parent.horizontalCenter
  38. Button {
  39. text: "Install"
  40. style: ButtonStyle {
  41. background: Rectangle {
  42. color: "transparent"
  43. implicitWidth: 96
  44. implicitHeight: 48
  45. Rectangle {
  46. visible: manager.viewing == "available" ? true : false
  47. color: UM.Theme.getColor("primary")
  48. anchors.bottom: parent.bottom
  49. width: parent.width
  50. height: 3
  51. }
  52. }
  53. label: Text {
  54. text: control.text
  55. color: UM.Theme.getColor("text")
  56. font {
  57. pixelSize: 15
  58. }
  59. verticalAlignment: Text.AlignVCenter
  60. horizontalAlignment: Text.AlignHCenter
  61. }
  62. }
  63. onClicked: manager.setView("available")
  64. }
  65. Button {
  66. text: "Manage"
  67. style: ButtonStyle {
  68. background: Rectangle {
  69. color: "transparent"
  70. implicitWidth: 96
  71. implicitHeight: 48
  72. Rectangle {
  73. visible: manager.viewing == "installed" ? true : false
  74. color: UM.Theme.getColor("primary")
  75. anchors.bottom: parent.bottom
  76. width: parent.width
  77. height: 3
  78. }
  79. }
  80. label: Text {
  81. text: control.text
  82. color: UM.Theme.getColor("text")
  83. font {
  84. pixelSize: 15
  85. }
  86. verticalAlignment: Text.AlignVCenter
  87. horizontalAlignment: Text.AlignHCenter
  88. }
  89. }
  90. onClicked: manager.setView("installed")
  91. }
  92. }
  93. }
  94. // Scroll view breaks in QtQuick.Controls 2.x
  95. ScrollView {
  96. id: installedPluginList
  97. width: parent.width
  98. height: 400
  99. anchors {
  100. top: topBar.bottom
  101. topMargin: UM.Theme.getSize("default_margin").height
  102. bottom: bottomBar.top
  103. bottomMargin: UM.Theme.getSize("default_margin").height
  104. }
  105. frameVisible: true
  106. ListView {
  107. id: pluginList
  108. property var activePlugin
  109. property var filter: "installed"
  110. anchors.fill: parent
  111. model: manager.pluginsModel
  112. delegate: PluginEntry {}
  113. }
  114. }
  115. Rectangle {
  116. id: bottomBar
  117. width: parent.width
  118. height: childrenRect.height
  119. color: "transparent"
  120. anchors.bottom: parent.bottom
  121. Label {
  122. visible: manager.restartRequired
  123. text: "You will need to restart Cura before changes in plugins have effect."
  124. height: 30
  125. verticalAlignment: Text.AlignVCenter
  126. }
  127. Button {
  128. id: restartChangedButton
  129. text: "Quit Cura"
  130. anchors.right: closeButton.left
  131. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  132. visible: manager.restartRequired
  133. iconName: "dialog-restart"
  134. onClicked: manager.restart()
  135. style: ButtonStyle {
  136. background: Rectangle {
  137. implicitWidth: 96
  138. implicitHeight: 30
  139. color: UM.Theme.getColor("primary")
  140. }
  141. label: Text {
  142. verticalAlignment: Text.AlignVCenter
  143. color: UM.Theme.getColor("button_text")
  144. font {
  145. pixelSize: 13
  146. bold: true
  147. }
  148. text: control.text
  149. horizontalAlignment: Text.AlignHCenter
  150. }
  151. }
  152. }
  153. Button {
  154. id: closeButton
  155. text: catalog.i18nc("@action:button", "Close")
  156. iconName: "dialog-close"
  157. onClicked: {
  158. if ( manager.isDownloading ) {
  159. manager.cancelDownload()
  160. }
  161. base.close();
  162. }
  163. anchors.right: parent.right
  164. style: ButtonStyle {
  165. background: Rectangle {
  166. color: "transparent"
  167. implicitWidth: 96
  168. implicitHeight: 30
  169. border {
  170. width: 1
  171. color: UM.Theme.getColor("lining")
  172. }
  173. }
  174. label: Text {
  175. verticalAlignment: Text.AlignVCenter
  176. color: UM.Theme.getColor("text")
  177. text: control.text
  178. horizontalAlignment: Text.AlignHCenter
  179. }
  180. }
  181. }
  182. }
  183. UM.I18nCatalog { id: catalog; name: "cura" }
  184. Connections {
  185. target: manager
  186. onShowLicenseDialog: {
  187. licenseDialog.pluginName = manager.getLicenseDialogPluginName();
  188. licenseDialog.licenseContent = manager.getLicenseDialogLicenseContent();
  189. licenseDialog.pluginFileLocation = manager.getLicenseDialogPluginFileLocation();
  190. licenseDialog.show();
  191. }
  192. }
  193. UM.Dialog {
  194. id: licenseDialog
  195. title: catalog.i18nc("@title:window", "Plugin License Agreement")
  196. minimumWidth: UM.Theme.getSize("license_window_minimum").width
  197. minimumHeight: UM.Theme.getSize("license_window_minimum").height
  198. width: minimumWidth
  199. height: minimumHeight
  200. property var pluginName;
  201. property var licenseContent;
  202. property var pluginFileLocation;
  203. Item
  204. {
  205. anchors.fill: parent
  206. Label
  207. {
  208. id: licenseTitle
  209. anchors.top: parent.top
  210. anchors.left: parent.left
  211. anchors.right: parent.right
  212. text: licenseDialog.pluginName + catalog.i18nc("@label", "This plugin contains a license.\nYou need to accept this license to install this plugin.\nDo you agree with the terms below?")
  213. wrapMode: Text.Wrap
  214. }
  215. TextArea
  216. {
  217. id: licenseText
  218. anchors.top: licenseTitle.bottom
  219. anchors.bottom: parent.bottom
  220. anchors.left: parent.left
  221. anchors.right: parent.right
  222. anchors.topMargin: UM.Theme.getSize("default_margin").height
  223. readOnly: true
  224. text: licenseDialog.licenseContent != null ? licenseDialog.licenseContent : ""
  225. }
  226. }
  227. rightButtons: [
  228. Button
  229. {
  230. id: acceptButton
  231. anchors.margins: UM.Theme.getSize("default_margin").width
  232. text: catalog.i18nc("@action:button", "Accept")
  233. onClicked:
  234. {
  235. licenseDialog.close();
  236. manager.installPlugin(licenseDialog.pluginFileLocation);
  237. }
  238. },
  239. Button
  240. {
  241. id: declineButton
  242. anchors.margins: UM.Theme.getSize("default_margin").width
  243. text: catalog.i18nc("@action:button", "Decline")
  244. onClicked:
  245. {
  246. licenseDialog.close();
  247. }
  248. }
  249. ]
  250. }
  251. Connections {
  252. target: manager
  253. onShowRestartDialog: {
  254. restartDialog.message = manager.getRestartDialogMessage();
  255. restartDialog.show();
  256. }
  257. }
  258. Window {
  259. id: restartDialog
  260. // title: catalog.i18nc("@title:tab", "Plugins");
  261. width: 360 * screenScaleFactor
  262. height: 120 * screenScaleFactor
  263. minimumWidth: 360 * screenScaleFactor
  264. minimumHeight: 120 * screenScaleFactor
  265. color: UM.Theme.getColor("sidebar")
  266. property var message;
  267. Text {
  268. id: message
  269. anchors {
  270. left: parent.left
  271. leftMargin: UM.Theme.getSize("default_margin").width
  272. top: parent.top
  273. topMargin: UM.Theme.getSize("default_margin").height
  274. }
  275. text: restartDialog.message != null ? restartDialog.message : ""
  276. }
  277. Button {
  278. id: laterButton
  279. text: "Later"
  280. onClicked: restartDialog.close();
  281. anchors {
  282. left: parent.left
  283. leftMargin: UM.Theme.getSize("default_margin").width
  284. bottom: parent.bottom
  285. bottomMargin: UM.Theme.getSize("default_margin").height
  286. }
  287. style: ButtonStyle {
  288. background: Rectangle {
  289. color: "transparent"
  290. implicitWidth: 96
  291. implicitHeight: 30
  292. border {
  293. width: 1
  294. color: UM.Theme.getColor("lining")
  295. }
  296. }
  297. label: Text {
  298. verticalAlignment: Text.AlignVCenter
  299. color: UM.Theme.getColor("text")
  300. text: control.text
  301. horizontalAlignment: Text.AlignHCenter
  302. }
  303. }
  304. }
  305. Button {
  306. id: restartButton
  307. text: "Quit Cura"
  308. anchors {
  309. right: parent.right
  310. rightMargin: UM.Theme.getSize("default_margin").width
  311. bottom: parent.bottom
  312. bottomMargin: UM.Theme.getSize("default_margin").height
  313. }
  314. onClicked: manager.restart()
  315. style: ButtonStyle {
  316. background: Rectangle {
  317. implicitWidth: 96
  318. implicitHeight: 30
  319. color: UM.Theme.getColor("primary")
  320. }
  321. label: Text {
  322. verticalAlignment: Text.AlignVCenter
  323. color: UM.Theme.getColor("button_text")
  324. font {
  325. pixelSize: 13
  326. bold: true
  327. }
  328. text: control.text
  329. horizontalAlignment: Text.AlignHCenter
  330. }
  331. }
  332. }
  333. }
  334. }
  335. }