SaveButton.qml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  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. }
  78. Item {
  79. id: saveRow
  80. width: base.width
  81. height: saveToButton.height
  82. anchors.top: progressBar.bottom
  83. anchors.topMargin: UM.Theme.getSize("default_margin").height
  84. anchors.left: parent.left
  85. Row {
  86. id: additionalComponentsRow
  87. anchors.top: parent.top
  88. anchors.right: saveToButton.visible ? saveToButton.left : parent.right
  89. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  90. spacing: UM.Theme.getSize("default_margin").width
  91. }
  92. Connections {
  93. target: Printer
  94. onAdditionalComponentsChanged:
  95. {
  96. if(areaId == "saveButton") {
  97. for (var component in Printer.additionalComponents["saveButton"]) {
  98. Printer.additionalComponents["saveButton"][component].parent = additionalComponentsRow
  99. }
  100. }
  101. }
  102. }
  103. Connections {
  104. target: UM.Preferences
  105. onPreferenceChanged:
  106. {
  107. var autoSlice = UM.Preferences.getValue("general/auto_slice");
  108. prepareButton.autoSlice = autoSlice;
  109. saveToButton.autoSlice = autoSlice;
  110. }
  111. }
  112. // Prepare button, only shows if auto_slice is off
  113. Button {
  114. id: prepareButton
  115. tooltip: UM.OutputDeviceManager.activeDeviceDescription;
  116. // 1 = not started, 2 = Processing
  117. enabled: (base.backendState == 1 || base.backendState == 2) && base.activity == true
  118. visible: {
  119. return !autoSlice && (base.backendState == 1 || base.backendState == 2) && base.activity == true;
  120. }
  121. property bool autoSlice
  122. height: UM.Theme.getSize("save_button_save_to_button").height
  123. anchors.top: parent.top
  124. anchors.right: parent.right
  125. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  126. // 1 = not started, 5 = disabled
  127. text: [1, 5].indexOf(UM.Backend.state) != -1 ? catalog.i18nc("@label:Printjob", "Prepare") : catalog.i18nc("@label:Printjob", "Cancel")
  128. onClicked:
  129. {
  130. if ([1, 5].indexOf(UM.Backend.state) != -1) {
  131. backend.forceSlice();
  132. } else {
  133. backend.stopSlicing();
  134. }
  135. }
  136. style: ButtonStyle {
  137. background: Rectangle
  138. {
  139. border.width: UM.Theme.getSize("default_lining").width
  140. border.color:
  141. {
  142. if(!control.enabled)
  143. return UM.Theme.getColor("action_button_disabled_border");
  144. else if(control.pressed)
  145. return UM.Theme.getColor("action_button_active_border");
  146. else if(control.hovered)
  147. return UM.Theme.getColor("action_button_hovered_border");
  148. else
  149. return UM.Theme.getColor("action_button_border");
  150. }
  151. color:
  152. {
  153. if(!control.enabled)
  154. return UM.Theme.getColor("action_button_disabled");
  155. else if(control.pressed)
  156. return UM.Theme.getColor("action_button_active");
  157. else if(control.hovered)
  158. return UM.Theme.getColor("action_button_hovered");
  159. else
  160. return UM.Theme.getColor("action_button");
  161. }
  162. Behavior on color { ColorAnimation { duration: 50; } }
  163. implicitWidth: actualLabel.contentWidth + (UM.Theme.getSize("default_margin").width * 2)
  164. Label {
  165. id: actualLabel
  166. anchors.centerIn: parent
  167. color:
  168. {
  169. if(!control.enabled)
  170. return UM.Theme.getColor("action_button_disabled_text");
  171. else if(control.pressed)
  172. return UM.Theme.getColor("action_button_active_text");
  173. else if(control.hovered)
  174. return UM.Theme.getColor("action_button_hovered_text");
  175. else
  176. return UM.Theme.getColor("action_button_text");
  177. }
  178. font: UM.Theme.getFont("action_button")
  179. text: control.text;
  180. }
  181. }
  182. label: Item { }
  183. }
  184. }
  185. Button {
  186. id: saveToButton
  187. tooltip: UM.OutputDeviceManager.activeDeviceDescription;
  188. // 3 = done, 5 = disabled
  189. enabled: (base.backendState == 3 || base.backendState == 5) && base.activity == true
  190. visible: {
  191. return autoSlice || ((base.backendState == 3 || base.backendState == 5) && base.activity == true);
  192. }
  193. property bool autoSlice
  194. height: UM.Theme.getSize("save_button_save_to_button").height
  195. anchors.top: parent.top
  196. anchors.right: deviceSelectionMenu.visible ? deviceSelectionMenu.left : parent.right
  197. anchors.rightMargin: deviceSelectionMenu.visible ? -3 * UM.Theme.getSize("default_lining").width : UM.Theme.getSize("default_margin").width
  198. text: UM.OutputDeviceManager.activeDeviceShortDescription
  199. onClicked:
  200. {
  201. UM.OutputDeviceManager.requestWriteToDevice(UM.OutputDeviceManager.activeDevice, PrintInformation.jobName, { "filter_by_machine": true, "preferred_mimetype":Printer.preferredOutputMimetype })
  202. }
  203. style: ButtonStyle {
  204. background: Rectangle
  205. {
  206. border.width: UM.Theme.getSize("default_lining").width
  207. border.color:
  208. {
  209. if(!control.enabled)
  210. return UM.Theme.getColor("action_button_disabled_border");
  211. else if(control.pressed)
  212. return UM.Theme.getColor("action_button_active_border");
  213. else if(control.hovered)
  214. return UM.Theme.getColor("action_button_hovered_border");
  215. else
  216. return UM.Theme.getColor("action_button_border");
  217. }
  218. color:
  219. {
  220. if(!control.enabled)
  221. return UM.Theme.getColor("action_button_disabled");
  222. else if(control.pressed)
  223. return UM.Theme.getColor("action_button_active");
  224. else if(control.hovered)
  225. return UM.Theme.getColor("action_button_hovered");
  226. else
  227. return UM.Theme.getColor("action_button");
  228. }
  229. Behavior on color { ColorAnimation { duration: 50; } }
  230. implicitWidth: actualLabel.contentWidth + (UM.Theme.getSize("default_margin").width * 2)
  231. Label {
  232. id: actualLabel
  233. anchors.centerIn: parent
  234. color:
  235. {
  236. if(!control.enabled)
  237. return UM.Theme.getColor("action_button_disabled_text");
  238. else if(control.pressed)
  239. return UM.Theme.getColor("action_button_active_text");
  240. else if(control.hovered)
  241. return UM.Theme.getColor("action_button_hovered_text");
  242. else
  243. return UM.Theme.getColor("action_button_text");
  244. }
  245. font: UM.Theme.getFont("action_button")
  246. text: control.text;
  247. }
  248. }
  249. label: Item { }
  250. }
  251. }
  252. Button {
  253. id: deviceSelectionMenu
  254. tooltip: catalog.i18nc("@info:tooltip","Select the active output device");
  255. anchors.top: parent.top
  256. anchors.right: parent.right
  257. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  258. width: UM.Theme.getSize("save_button_save_to_button").height
  259. height: UM.Theme.getSize("save_button_save_to_button").height
  260. // 3 = Done, 5 = Disabled
  261. enabled: (base.backendState == 3 || base.backendState == 5) && base.activity == true
  262. visible: (devicesModel.deviceCount > 1) && (base.backendState == 3 || base.backendState == 5) && base.activity == true
  263. style: ButtonStyle {
  264. background: Rectangle {
  265. id: deviceSelectionIcon
  266. border.width: UM.Theme.getSize("default_lining").width
  267. border.color:
  268. {
  269. if(!control.enabled)
  270. return UM.Theme.getColor("action_button_disabled_border");
  271. else if(control.pressed)
  272. return UM.Theme.getColor("action_button_active_border");
  273. else if(control.hovered)
  274. return UM.Theme.getColor("action_button_hovered_border");
  275. else
  276. return UM.Theme.getColor("action_button_border");
  277. }
  278. color:
  279. {
  280. if(!control.enabled)
  281. return UM.Theme.getColor("action_button_disabled");
  282. else if(control.pressed)
  283. return UM.Theme.getColor("action_button_active");
  284. else if(control.hovered)
  285. return UM.Theme.getColor("action_button_hovered");
  286. else
  287. return UM.Theme.getColor("action_button");
  288. }
  289. Behavior on color { ColorAnimation { duration: 50; } }
  290. anchors.left: parent.left
  291. anchors.leftMargin: UM.Theme.getSize("save_button_text_margin").width / 2;
  292. width: parent.height
  293. height: parent.height
  294. UM.RecolorImage {
  295. anchors.verticalCenter: parent.verticalCenter
  296. anchors.horizontalCenter: parent.horizontalCenter
  297. width: UM.Theme.getSize("standard_arrow").width
  298. height: UM.Theme.getSize("standard_arrow").height
  299. sourceSize.width: width
  300. sourceSize.height: height
  301. color:
  302. {
  303. if(!control.enabled)
  304. return UM.Theme.getColor("action_button_disabled_text");
  305. else if(control.pressed)
  306. return UM.Theme.getColor("action_button_active_text");
  307. else if(control.hovered)
  308. return UM.Theme.getColor("action_button_hovered_text");
  309. else
  310. return UM.Theme.getColor("action_button_text");
  311. }
  312. source: UM.Theme.getIcon("arrow_bottom");
  313. }
  314. }
  315. label: Label{ }
  316. }
  317. menu: Menu {
  318. id: devicesMenu;
  319. Instantiator {
  320. model: devicesModel;
  321. MenuItem {
  322. text: model.description
  323. checkable: true;
  324. checked: model.id == UM.OutputDeviceManager.activeDevice;
  325. exclusiveGroup: devicesMenuGroup;
  326. onTriggered: {
  327. UM.OutputDeviceManager.setActiveDevice(model.id);
  328. }
  329. }
  330. onObjectAdded: devicesMenu.insertItem(index, object)
  331. onObjectRemoved: devicesMenu.removeItem(object)
  332. }
  333. ExclusiveGroup { id: devicesMenuGroup; }
  334. }
  335. }
  336. UM.OutputDevicesModel { id: devicesModel; }
  337. }
  338. }