Cura.qml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  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 QtQuick.Dialogs 1.1
  8. import UM 1.0 as UM
  9. UM.MainWindow {
  10. id: base
  11. visible: true
  12. //: Cura application window title
  13. title: qsTr("Cura");
  14. Item {
  15. id: backgroundItem;
  16. anchors.fill: parent;
  17. UM.ApplicationMenu {
  18. id: menu
  19. window: base
  20. Menu {
  21. //: File menu
  22. title: qsTr("&File");
  23. MenuItem { action: actions.open; }
  24. MenuItem { action: actions.save; }
  25. MenuSeparator { }
  26. MenuItem { action: actions.quit; }
  27. }
  28. Menu {
  29. //: Edit menu
  30. title: qsTr("&Edit");
  31. MenuItem { action: actions.undo; }
  32. MenuItem { action: actions.redo; }
  33. MenuSeparator { }
  34. MenuItem { action: actions.deleteSelection; }
  35. MenuItem { action: actions.deleteAll; }
  36. }
  37. Menu {
  38. id: machineMenu;
  39. //: Machine menu
  40. title: qsTr("&Machine");
  41. Instantiator {
  42. model: UM.Models.machinesModel
  43. MenuItem {
  44. text: model.name;
  45. checkable: true;
  46. checked: model.active;
  47. exclusiveGroup: machineMenuGroup;
  48. onTriggered: UM.Models.machinesModel.setActive(index)
  49. }
  50. onObjectAdded: machineMenu.insertItem(index, object)
  51. onObjectRemoved: machineMenu.removeItem(object)
  52. }
  53. ExclusiveGroup { id: machineMenuGroup; }
  54. MenuSeparator { }
  55. MenuItem { action: actions.addMachine; }
  56. MenuItem { action: actions.configureMachines; }
  57. }
  58. Menu {
  59. id: extension_menu
  60. //: Extensions menu
  61. title: qsTr("E&xtensions");
  62. Instantiator
  63. {
  64. model: UM.Models.extensionModel
  65. Menu
  66. {
  67. id: sub_menu
  68. title: model.name;
  69. Instantiator
  70. {
  71. model: actions
  72. MenuItem
  73. {
  74. text: model.text
  75. onTriggered: UM.Models.extensionModel.subMenuTriggered(name, model.text)
  76. }
  77. onObjectAdded: sub_menu.insertItem(index, object)
  78. onObjectRemoved: sub_menu.removeItem(object)
  79. }
  80. }
  81. onObjectAdded: extension_menu.insertItem(index, object)
  82. onObjectRemoved: extension_menu.removeItem(object)
  83. }
  84. }
  85. Menu {
  86. //: Settings menu
  87. title: qsTr("&Settings");
  88. MenuItem { action: actions.preferences; }
  89. }
  90. Menu {
  91. //: Help menu
  92. title: qsTr("&Help");
  93. MenuItem { action: actions.showEngineLog; }
  94. MenuItem { action: actions.documentation; }
  95. MenuItem { action: actions.reportBug; }
  96. MenuSeparator { }
  97. MenuItem { action: actions.about; }
  98. }
  99. }
  100. Item {
  101. id: contentItem;
  102. y: menu.height
  103. width: parent.width;
  104. height: parent.height - menu.height;
  105. Keys.forwardTo: menu
  106. DropArea {
  107. anchors.fill: parent;
  108. onDropped: {
  109. if(drop.urls.length > 0) {
  110. for(var i in drop.urls) {
  111. UM.MeshFileHandler.readLocalFile(drop.urls[i]);
  112. }
  113. }
  114. }
  115. }
  116. Sidebar {
  117. id: sidebar;
  118. anchors {
  119. top: parent.top;
  120. bottom: parent.bottom;
  121. right: parent.right;
  122. rightMargin: UM.Theme.sizes.window_margin.width;
  123. }
  124. width: UM.Theme.sizes.panel.width;
  125. addMachineAction: actions.addMachine;
  126. configureMachinesAction: actions.configureMachines;
  127. saveAction: actions.save;
  128. }
  129. UM.MessageStack {
  130. anchors {
  131. left: toolbar.right;
  132. leftMargin: UM.Theme.sizes.window_margin.width;
  133. right: sidebar.left;
  134. rightMargin: UM.Theme.sizes.window_margin.width;
  135. top: parent.verticalCenter;
  136. bottom: parent.bottom;
  137. }
  138. }
  139. Loader
  140. {
  141. id: view_panel
  142. //anchors.left: parent.left;
  143. //anchors.right: parent.right;
  144. //anchors.bottom: parent.bottom
  145. anchors.top: viewModeButton.bottom
  146. anchors.topMargin: UM.Theme.sizes.default_margin.height;
  147. anchors.right: sidebar.left;
  148. anchors.rightMargin: UM.Theme.sizes.window_margin.width;
  149. //anchors.bottom: buttons.top;
  150. //anchors.bottomMargin: UM.Theme.sizes.default_margin.height;
  151. height: childrenRect.height;
  152. source: UM.ActiveView.valid ? UM.ActiveView.activeViewPanel : "";
  153. }
  154. Button {
  155. id: openFileButton;
  156. iconSource: UM.Theme.icons.open;
  157. style: UM.Theme.styles.tool_button;
  158. anchors {
  159. top: parent.top;
  160. topMargin: UM.Theme.sizes.window_margin.height;
  161. left: parent.left;
  162. leftMargin: UM.Theme.sizes.window_margin.width;
  163. }
  164. action: actions.open;
  165. }
  166. Image {
  167. anchors {
  168. verticalCenter: openFileButton.verticalCenter;
  169. left: openFileButton.right;
  170. leftMargin: UM.Theme.sizes.window_margin.width;
  171. }
  172. source: UM.Theme.images.logo;
  173. width: UM.Theme.sizes.logo.width;
  174. height: UM.Theme.sizes.logo.height;
  175. sourceSize.width: width;
  176. sourceSize.height: height;
  177. }
  178. Button {
  179. anchors {
  180. top: parent.top;
  181. topMargin: UM.Theme.sizes.window_margin.height;
  182. right: sidebar.left;
  183. rightMargin: UM.Theme.sizes.window_margin.width;
  184. }
  185. id: viewModeButton
  186. //: View Mode toolbar button
  187. text: qsTr("View Mode");
  188. iconSource: UM.Theme.icons.viewmode;
  189. style: UM.Theme.styles.tool_button;
  190. menu: Menu {
  191. id: viewMenu;
  192. Instantiator {
  193. model: UM.Models.viewModel;
  194. MenuItem {
  195. text: model.name;
  196. checkable: true;
  197. checked: model.active;
  198. exclusiveGroup: viewMenuGroup;
  199. onTriggered: UM.Controller.setActiveView(model.id);
  200. }
  201. onObjectAdded: viewMenu.insertItem(index, object)
  202. onObjectRemoved: viewMenu.removeItem(object)
  203. }
  204. ExclusiveGroup { id: viewMenuGroup; }
  205. }
  206. }
  207. Toolbar {
  208. id: toolbar;
  209. anchors {
  210. left: parent.left;
  211. leftMargin: UM.Theme.sizes.window_margin.width;
  212. bottom: parent.bottom;
  213. bottomMargin: UM.Theme.sizes.window_margin.height;
  214. }
  215. }
  216. }
  217. }
  218. UM.PreferencesDialog {
  219. id: preferences
  220. Component.onCompleted: {
  221. //: View preferences page title
  222. insertPage(1, qsTr("View"), "view-preview", Qt.resolvedUrl("./ViewPage.qml"));
  223. }
  224. }
  225. Actions {
  226. id: actions;
  227. open.onTriggered: openDialog.open();
  228. save.onTriggered: saveDialog.open();
  229. quit.onTriggered: base.visible = false;
  230. undo.onTriggered: UM.OperationStack.undo();
  231. undo.enabled: UM.OperationStack.canUndo;
  232. redo.onTriggered: UM.OperationStack.redo();
  233. redo.enabled: UM.OperationStack.canRedo;
  234. deleteSelection.onTriggered: UM.Controller.removeSelection();
  235. deleteObject.onTriggered: {
  236. if(objectContextMenu.objectId != 0) {
  237. Printer.deleteObject(objectContextMenu.objectId);
  238. objectContextMenu.objectId = 0;
  239. }
  240. }
  241. multiplyObject.onTriggered: {
  242. if(objectContextMenu.objectId != 0) {
  243. Printer.multiplyObject(objectContextMenu.objectId, 1);
  244. objectContextMenu.objectId = 0;
  245. }
  246. }
  247. centerObject.onTriggered: {
  248. if(objectContextMenu.objectId != 0) {
  249. Printer.centerObject(objectContextMenu.objectId);
  250. objectContextMenu.objectId = 0;
  251. }
  252. }
  253. deleteAll.onTriggered: Printer.deleteAll()
  254. resetAllTranslation.onTriggered: Printer.resetAllTranslation()
  255. resetAll.onTriggered: Printer.resetAll()
  256. reloadAll.onTriggered: Printer.reloadAll()
  257. addMachine.onTriggered: addMachine.visible = true;
  258. preferences.onTriggered: preferences.visible = true;
  259. configureMachines.onTriggered: { preferences.visible = true; preferences.setPage(2); }
  260. documentation.onTriggered: Qt.openUrlExternally("https://ultimaker.com/en/support");
  261. reportBug.onTriggered: Qt.openUrlExternally("https://github.com/Ultimaker/Cura/issues");
  262. showEngineLog.onTriggered: engineLog.visible = true;
  263. about.onTriggered: aboutDialog.visible = true;
  264. }
  265. Menu {
  266. id: objectContextMenu;
  267. property variant objectId: -1;
  268. MenuItem { action: actions.centerObject; }
  269. MenuItem { action: actions.deleteObject; }
  270. MenuItem { action: actions.multiplyObject; }
  271. MenuItem { action: actions.splitObject; }
  272. MenuSeparator { }
  273. MenuItem { action: actions.deleteAll; }
  274. MenuItem { action: actions.reloadAll; }
  275. MenuItem { action: actions.resetAllTranslation; }
  276. MenuItem { action: actions.resetAll; }
  277. }
  278. Menu {
  279. id: contextMenu;
  280. MenuItem { action: actions.deleteAll; }
  281. MenuItem { action: actions.reloadAll; }
  282. MenuItem { action: actions.resetAllTranslation; }
  283. MenuItem { action: actions.resetAll; }
  284. }
  285. Connections {
  286. target: UM.Controller
  287. onContextMenuRequested: {
  288. if(objectId == 0) {
  289. contextMenu.popup();
  290. } else {
  291. objectContextMenu.objectId = objectId;
  292. objectContextMenu.popup();
  293. }
  294. }
  295. }
  296. FileDialog {
  297. id: openDialog;
  298. //: File open dialog title
  299. title: qsTr("Open File")
  300. modality: UM.Application.platform == "linux" ? Qt.NonModal : Qt.WindowModal;
  301. //TODO: Support multiple file selection, workaround bug in KDE file dialog
  302. //selectMultiple: true
  303. nameFilters: UM.MeshFileHandler.supportedReadFileTypes;
  304. onAccepted:
  305. {
  306. UM.MeshFileHandler.readLocalFile(fileUrl)
  307. }
  308. }
  309. FileDialog {
  310. id: saveDialog;
  311. //: File save dialog title
  312. title: qsTr("Save File");
  313. selectExisting: false;
  314. modality: UM.Application.platform == "linux" ? Qt.NonModal : Qt.WindowModal;
  315. nameFilters: UM.MeshFileHandler.supportedWriteFileTypes
  316. onAccepted:
  317. {
  318. UM.MeshFileHandler.writeLocalFile(fileUrl);
  319. }
  320. }
  321. EngineLog {
  322. id: engineLog;
  323. }
  324. AddMachineWizard {
  325. id: addMachine;
  326. }
  327. AboutDialog {
  328. id: aboutDialog
  329. }
  330. Connections {
  331. target: Printer
  332. onRequestAddPrinter: addMachine.visible = true;
  333. onWriteToLocalFileRequested: saveDialog.open();
  334. }
  335. Component.onCompleted: UM.Theme.load(UM.Resources.getPath(UM.Resources.ThemesLocation, "cura"))
  336. }