SaveButton.qml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. // Copyright (c) 2015 Ultimaker B.V.
  2. // Cura is released under the terms of the AGPLv3 or higher.
  3. import QtQuick 2.2
  4. import QtQuick.Controls 1.1
  5. import QtQuick.Controls.Styles 1.1
  6. import QtQuick.Layouts 1.1
  7. import UM 1.1 as UM
  8. Item {
  9. id: base;
  10. UM.I18nCatalog { id: catalog; name:"cura"}
  11. property real progress: UM.Backend.progress;
  12. property int backendState: UM.Backend.state;
  13. property var backend: CuraApplication.getBackend();
  14. property bool activity: Printer.platformActivity;
  15. property int totalHeight: childrenRect.height + UM.Theme.getSize("default_margin").height
  16. property string fileBaseName
  17. property string statusText:
  18. {
  19. if(!activity)
  20. {
  21. return catalog.i18nc("@label:PrintjobStatus", "Please load a 3d model");
  22. }
  23. switch(base.backendState)
  24. {
  25. case 1:
  26. return catalog.i18nc("@label:PrintjobStatus", "Ready to slice");
  27. case 2:
  28. return catalog.i18nc("@label:PrintjobStatus", "Slicing...");
  29. case 3:
  30. return catalog.i18nc("@label:PrintjobStatus %1 is target operation","Ready to %1").arg(UM.OutputDeviceManager.activeDeviceShortDescription);
  31. case 4:
  32. return catalog.i18nc("@label:PrintjobStatus", "Unable to Slice");
  33. case 5:
  34. return catalog.i18nc("@label:PrintjobStatus", "Slicing unavailable");
  35. default:
  36. return "";
  37. }
  38. }
  39. Label {
  40. id: statusLabel
  41. width: parent.width - 2 * UM.Theme.getSize("default_margin").width
  42. anchors.top: parent.top
  43. anchors.left: parent.left
  44. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  45. color: UM.Theme.getColor("text")
  46. font: UM.Theme.getFont("large")
  47. text: statusText;
  48. }
  49. Rectangle {
  50. id: progressBar
  51. width: parent.width - 2 * UM.Theme.getSize("default_margin").width
  52. height: UM.Theme.getSize("progressbar").height
  53. anchors.top: statusLabel.bottom
  54. anchors.topMargin: UM.Theme.getSize("default_margin").height/4
  55. anchors.left: parent.left
  56. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  57. radius: UM.Theme.getSize("progressbar_radius").width
  58. color: UM.Theme.getColor("progressbar_background")
  59. Rectangle {
  60. width: Math.max(parent.width * base.progress)
  61. height: parent.height
  62. color: UM.Theme.getColor("progressbar_control")
  63. radius: UM.Theme.getSize("progressbar_radius").width
  64. visible: base.backendState == 2 ? true : false
  65. }
  66. }
  67. // Shortcut for "save as/print/..."
  68. Action {
  69. shortcut: "Ctrl+P"
  70. onTriggered:
  71. {
  72. // only work when the button is enabled
  73. if (saveToButton.enabled)
  74. saveToButton.clicked();
  75. }
  76. }
  77. Item {
  78. id: saveRow
  79. width: base.width
  80. height: saveToButton.height
  81. anchors.top: progressBar.bottom
  82. anchors.topMargin: UM.Theme.getSize("default_margin").height
  83. anchors.left: parent.left
  84. Row {
  85. id: additionalComponentsRow
  86. anchors.top: parent.top
  87. anchors.right: saveToButton.visible ? saveToButton.left : parent.right
  88. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  89. spacing: UM.Theme.getSize("default_margin").width
  90. }
  91. Connections {
  92. target: Printer
  93. onAdditionalComponentsChanged:
  94. {
  95. if(areaId == "saveButton") {
  96. for (var component in Printer.additionalComponents["saveButton"]) {
  97. Printer.additionalComponents["saveButton"][component].parent = additionalComponentsRow
  98. }
  99. }
  100. }
  101. }
  102. Connections {
  103. target: UM.Preferences
  104. onPreferenceChanged:
  105. {
  106. var autoSlice = UM.Preferences.getValue("general/auto_slice");
  107. prepareButton.autoSlice = autoSlice;
  108. saveToButton.autoSlice = autoSlice;
  109. }
  110. }
  111. // Prepare button, only shows if auto_slice is off
  112. Button {
  113. id: prepareButton
  114. tooltip: UM.OutputDeviceManager.activeDeviceDescription;
  115. // 1 = not started, 2 = Processing
  116. enabled: (base.backendState == 1 || base.backendState == 2) && base.activity == true
  117. visible: {
  118. return !autoSlice && (base.backendState == 1 || base.backendState == 2) && base.activity == true;
  119. }
  120. property bool autoSlice
  121. height: UM.Theme.getSize("save_button_save_to_button").height
  122. anchors.top: parent.top
  123. anchors.right: parent.right
  124. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  125. // 1 = not started, 5 = disabled
  126. text: [1, 5].indexOf(UM.Backend.state) != -1 ? catalog.i18nc("@label:Printjob", "Prepare") : catalog.i18nc("@label:Printjob", "Cancel")
  127. onClicked:
  128. {
  129. if ([1, 5].indexOf(UM.Backend.state) != -1) {
  130. backend.forceSlice();
  131. } else {
  132. backend.stopSlicing();
  133. }
  134. }
  135. style: ButtonStyle {
  136. background: Rectangle
  137. {
  138. border.width: UM.Theme.getSize("default_lining").width
  139. border.color:
  140. {
  141. if(!control.enabled)
  142. return UM.Theme.getColor("action_button_disabled_border");
  143. else if(control.pressed)
  144. return UM.Theme.getColor("action_button_active_border");
  145. else if(control.hovered)
  146. return UM.Theme.getColor("action_button_hovered_border");
  147. else
  148. return UM.Theme.getColor("action_button_border");
  149. }
  150. color:
  151. {
  152. if(!control.enabled)
  153. return UM.Theme.getColor("action_button_disabled");
  154. else if(control.pressed)
  155. return UM.Theme.getColor("action_button_active");
  156. else if(control.hovered)
  157. return UM.Theme.getColor("action_button_hovered");
  158. else
  159. return UM.Theme.getColor("action_button");
  160. }
  161. Behavior on color { ColorAnimation { duration: 50; } }
  162. implicitWidth: actualLabel.contentWidth + (UM.Theme.getSize("default_margin").width * 2)
  163. Label {
  164. id: actualLabel
  165. anchors.centerIn: parent
  166. color:
  167. {
  168. if(!control.enabled)
  169. return UM.Theme.getColor("action_button_disabled_text");
  170. else if(control.pressed)
  171. return UM.Theme.getColor("action_button_active_text");
  172. else if(control.hovered)
  173. return UM.Theme.getColor("action_button_hovered_text");
  174. else
  175. return UM.Theme.getColor("action_button_text");
  176. }
  177. font: UM.Theme.getFont("action_button")
  178. text: control.text;
  179. }
  180. }
  181. label: Item { }
  182. }
  183. }
  184. Button {
  185. id: saveToButton
  186. tooltip: UM.OutputDeviceManager.activeDeviceDescription;
  187. // 3 = done, 5 = disabled
  188. enabled: (base.backendState == 3 || base.backendState == 5) && base.activity == true
  189. visible: {
  190. return autoSlice || ((base.backendState == 3 || base.backendState == 5) && base.activity == true);
  191. }
  192. property bool autoSlice
  193. height: UM.Theme.getSize("save_button_save_to_button").height
  194. anchors.top: parent.top
  195. anchors.right: deviceSelectionMenu.visible ? deviceSelectionMenu.left : parent.right
  196. anchors.rightMargin: deviceSelectionMenu.visible ? -3 * UM.Theme.getSize("default_lining").width : UM.Theme.getSize("default_margin").width
  197. text: UM.OutputDeviceManager.activeDeviceShortDescription
  198. onClicked:
  199. {
  200. UM.OutputDeviceManager.requestWriteToDevice(UM.OutputDeviceManager.activeDevice, PrintInformation.jobName, { "filter_by_machine": true, "preferred_mimetype":Printer.preferredOutputMimetype })
  201. }
  202. style: ButtonStyle {
  203. background: Rectangle
  204. {
  205. border.width: UM.Theme.getSize("default_lining").width
  206. border.color:
  207. {
  208. if(!control.enabled)
  209. return UM.Theme.getColor("action_button_disabled_border");
  210. else if(control.pressed)
  211. return UM.Theme.getColor("action_button_active_border");
  212. else if(control.hovered)
  213. return UM.Theme.getColor("action_button_hovered_border");
  214. else
  215. return UM.Theme.getColor("action_button_border");
  216. }
  217. color:
  218. {
  219. if(!control.enabled)
  220. return UM.Theme.getColor("action_button_disabled");
  221. else if(control.pressed)
  222. return UM.Theme.getColor("action_button_active");
  223. else if(control.hovered)
  224. return UM.Theme.getColor("action_button_hovered");
  225. else
  226. return UM.Theme.getColor("action_button");
  227. }
  228. Behavior on color { ColorAnimation { duration: 50; } }
  229. implicitWidth: actualLabel.contentWidth + (UM.Theme.getSize("default_margin").width * 2)
  230. Label {
  231. id: actualLabel
  232. anchors.centerIn: parent
  233. color:
  234. {
  235. if(!control.enabled)
  236. return UM.Theme.getColor("action_button_disabled_text");
  237. else if(control.pressed)
  238. return UM.Theme.getColor("action_button_active_text");
  239. else if(control.hovered)
  240. return UM.Theme.getColor("action_button_hovered_text");
  241. else
  242. return UM.Theme.getColor("action_button_text");
  243. }
  244. font: UM.Theme.getFont("action_button")
  245. text: control.text;
  246. }
  247. }
  248. label: Item { }
  249. }
  250. }
  251. Button {
  252. id: deviceSelectionMenu
  253. tooltip: catalog.i18nc("@info:tooltip","Select the active output device");
  254. anchors.top: parent.top
  255. anchors.right: parent.right
  256. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  257. width: UM.Theme.getSize("save_button_save_to_button").height
  258. height: UM.Theme.getSize("save_button_save_to_button").height
  259. // 3 = Done, 5 = Disabled
  260. enabled: (base.backendState == 3 || base.backendState == 5) && base.activity == true
  261. visible: (devicesModel.deviceCount > 1) && (base.backendState == 3 || base.backendState == 5) && base.activity == true
  262. style: ButtonStyle {
  263. background: Rectangle {
  264. id: deviceSelectionIcon
  265. border.width: UM.Theme.getSize("default_lining").width
  266. border.color:
  267. {
  268. if(!control.enabled)
  269. return UM.Theme.getColor("action_button_disabled_border");
  270. else if(control.pressed)
  271. return UM.Theme.getColor("action_button_active_border");
  272. else if(control.hovered)
  273. return UM.Theme.getColor("action_button_hovered_border");
  274. else
  275. return UM.Theme.getColor("action_button_border");
  276. }
  277. color:
  278. {
  279. if(!control.enabled)
  280. return UM.Theme.getColor("action_button_disabled");
  281. else if(control.pressed)
  282. return UM.Theme.getColor("action_button_active");
  283. else if(control.hovered)
  284. return UM.Theme.getColor("action_button_hovered");
  285. else
  286. return UM.Theme.getColor("action_button");
  287. }
  288. Behavior on color { ColorAnimation { duration: 50; } }
  289. anchors.left: parent.left
  290. anchors.leftMargin: UM.Theme.getSize("save_button_text_margin").width / 2;
  291. width: parent.height
  292. height: parent.height
  293. UM.RecolorImage {
  294. anchors.verticalCenter: parent.verticalCenter
  295. anchors.horizontalCenter: parent.horizontalCenter
  296. width: UM.Theme.getSize("standard_arrow").width
  297. height: UM.Theme.getSize("standard_arrow").height
  298. sourceSize.width: width
  299. sourceSize.height: height
  300. color:
  301. {
  302. if(!control.enabled)
  303. return UM.Theme.getColor("action_button_disabled_text");
  304. else if(control.pressed)
  305. return UM.Theme.getColor("action_button_active_text");
  306. else if(control.hovered)
  307. return UM.Theme.getColor("action_button_hovered_text");
  308. else
  309. return UM.Theme.getColor("action_button_text");
  310. }
  311. source: UM.Theme.getIcon("arrow_bottom");
  312. }
  313. }
  314. label: Label{ }
  315. }
  316. menu: Menu {
  317. id: devicesMenu;
  318. Instantiator {
  319. model: devicesModel;
  320. MenuItem {
  321. text: model.description
  322. checkable: true;
  323. checked: model.id == UM.OutputDeviceManager.activeDevice;
  324. exclusiveGroup: devicesMenuGroup;
  325. onTriggered: {
  326. UM.OutputDeviceManager.setActiveDevice(model.id);
  327. }
  328. }
  329. onObjectAdded: devicesMenu.insertItem(index, object)
  330. onObjectRemoved: devicesMenu.removeItem(object)
  331. }
  332. ExclusiveGroup { id: devicesMenuGroup; }
  333. }
  334. }
  335. UM.OutputDevicesModel { id: devicesModel; }
  336. }
  337. }