Cura.qml 16 KB

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