Cura.qml 15 KB

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