Cura.qml 14 KB

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