Cura.qml 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960
  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.3 as UM
  9. import Cura 1.0 as Cura
  10. import "Menus"
  11. UM.MainWindow
  12. {
  13. id: base
  14. //: Cura application window title
  15. title: catalog.i18nc("@title:window","Cura");
  16. viewportRect: Qt.rect(0, 0, (base.width - sidebar.width) / base.width, 1.0)
  17. property bool monitoringPrint: false
  18. Component.onCompleted:
  19. {
  20. Printer.setMinimumWindowSize(UM.Theme.getSize("window_minimum_size"))
  21. // Workaround silly issues with QML Action's shortcut property.
  22. //
  23. // Currently, there is no way to define shortcuts as "Application Shortcut".
  24. // This means that all Actions are "Window Shortcuts". The code for this
  25. // implements a rather naive check that just checks if any of the action's parents
  26. // are a window. Since the "Actions" object is a singleton it has no parent by
  27. // default. If we set its parent to something contained in this window, the
  28. // shortcut will activate properly because one of its parents is a window.
  29. //
  30. // This has been fixed for QtQuick Controls 2 since the Shortcut item has a context property.
  31. Cura.Actions.parent = backgroundItem
  32. }
  33. Item
  34. {
  35. id: backgroundItem;
  36. anchors.fill: parent;
  37. UM.I18nCatalog{id: catalog; name:"cura"}
  38. signal hasMesh(string name) //this signal sends the filebase name so it can be used for the JobSpecs.qml
  39. function getMeshName(path){
  40. //takes the path the complete path of the meshname and returns only the filebase
  41. var fileName = path.slice(path.lastIndexOf("/") + 1)
  42. var fileBase = fileName.slice(0, fileName.indexOf("."))
  43. return fileBase
  44. }
  45. //DeleteSelection on the keypress backspace event
  46. Keys.onPressed: {
  47. if (event.key == Qt.Key_Backspace)
  48. {
  49. Cura.Actions.deleteSelection.trigger()
  50. }
  51. }
  52. UM.ApplicationMenu
  53. {
  54. id: menu
  55. window: base
  56. Menu
  57. {
  58. id: fileMenu
  59. title: catalog.i18nc("@title:menu menubar:toplevel","&File");
  60. MenuItem
  61. {
  62. action: Cura.Actions.newProject;
  63. }
  64. MenuItem
  65. {
  66. action: Cura.Actions.open;
  67. }
  68. RecentFilesMenu { }
  69. MenuSeparator { }
  70. MenuItem
  71. {
  72. text: catalog.i18nc("@action:inmenu menubar:file", "&Save Selection to File");
  73. enabled: UM.Selection.hasSelection;
  74. iconName: "document-save-as";
  75. onTriggered: UM.OutputDeviceManager.requestWriteSelectionToDevice("local_file", PrintInformation.jobName, { "filter_by_machine": false, "preferred_mimetype": "application/vnd.ms-package.3dmanufacturing-3dmodel+xml"});
  76. }
  77. MenuItem
  78. {
  79. id: saveAsMenu
  80. text: catalog.i18nc("@title:menu menubar:file", "Save &As...")
  81. onTriggered:
  82. {
  83. var localDeviceId = "local_file";
  84. UM.OutputDeviceManager.requestWriteToDevice(localDeviceId, PrintInformation.jobName, { "filter_by_machine": false, "preferred_mimetype": "application/vnd.ms-package.3dmanufacturing-3dmodel+xml"});
  85. }
  86. }
  87. MenuItem
  88. {
  89. id: saveWorkspaceMenu
  90. text: catalog.i18nc("@title:menu menubar:file","Save project")
  91. onTriggered:
  92. {
  93. if(UM.Preferences.getValue("cura/dialog_on_project_save"))
  94. {
  95. saveWorkspaceDialog.open()
  96. }
  97. else
  98. {
  99. UM.OutputDeviceManager.requestWriteToDevice("local_file", PrintInformation.jobName, { "filter_by_machine": false, "file_type": "workspace" })
  100. }
  101. }
  102. }
  103. MenuItem { action: Cura.Actions.reloadAll; }
  104. MenuSeparator { }
  105. MenuItem { action: Cura.Actions.quit; }
  106. }
  107. Menu
  108. {
  109. title: catalog.i18nc("@title:menu menubar:toplevel","&Edit");
  110. MenuItem { action: Cura.Actions.undo; }
  111. MenuItem { action: Cura.Actions.redo; }
  112. MenuSeparator { }
  113. MenuItem { action: Cura.Actions.selectAll; }
  114. MenuItem { action: Cura.Actions.deleteSelection; }
  115. MenuItem { action: Cura.Actions.deleteAll; }
  116. MenuItem { action: Cura.Actions.resetAllTranslation; }
  117. MenuItem { action: Cura.Actions.resetAll; }
  118. MenuSeparator { }
  119. MenuItem { action: Cura.Actions.groupObjects;}
  120. MenuItem { action: Cura.Actions.mergeObjects;}
  121. MenuItem { action: Cura.Actions.unGroupObjects;}
  122. }
  123. ViewMenu { title: catalog.i18nc("@title:menu", "&View") }
  124. Menu
  125. {
  126. id: settingsMenu
  127. title: catalog.i18nc("@title:menu", "&Settings")
  128. PrinterMenu { title: catalog.i18nc("@title:menu menubar:toplevel", "&Printer") }
  129. Instantiator
  130. {
  131. model: Cura.ExtrudersModel { simpleNames: true }
  132. Menu {
  133. title: model.name
  134. visible: machineExtruderCount.properties.value > 1
  135. NozzleMenu { title: Cura.MachineManager.activeDefinitionVariantsName; visible: Cura.MachineManager.hasVariants; extruderIndex: index }
  136. MaterialMenu { title: catalog.i18nc("@title:menu", "&Material"); visible: Cura.MachineManager.hasMaterials; extruderIndex: index }
  137. ProfileMenu { title: catalog.i18nc("@title:menu", "&Profile"); }
  138. MenuSeparator { }
  139. MenuItem { text: catalog.i18nc("@action:inmenu", "Set as Active Extruder"); onTriggered: ExtruderManager.setActiveExtruderIndex(model.index) }
  140. }
  141. onObjectAdded: settingsMenu.insertItem(index, object)
  142. onObjectRemoved: settingsMenu.removeItem(object)
  143. }
  144. NozzleMenu { title: Cura.MachineManager.activeDefinitionVariantsName; visible: machineExtruderCount.properties.value <= 1 && Cura.MachineManager.hasVariants }
  145. MaterialMenu { title: catalog.i18nc("@title:menu", "&Material"); visible: machineExtruderCount.properties.value <= 1 && Cura.MachineManager.hasMaterials }
  146. ProfileMenu { title: catalog.i18nc("@title:menu", "&Profile"); visible: machineExtruderCount.properties.value <= 1 }
  147. MenuSeparator { }
  148. MenuItem { action: Cura.Actions.configureSettingVisibility }
  149. }
  150. Menu
  151. {
  152. id: extension_menu
  153. title: catalog.i18nc("@title:menu menubar:toplevel","E&xtensions");
  154. Instantiator
  155. {
  156. id: extensions
  157. model: UM.ExtensionModel { }
  158. Menu
  159. {
  160. id: sub_menu
  161. title: model.name;
  162. visible: actions != null
  163. enabled:actions != null
  164. Instantiator
  165. {
  166. model: actions
  167. MenuItem
  168. {
  169. text: model.text
  170. onTriggered: extensions.model.subMenuTriggered(name, model.text)
  171. }
  172. onObjectAdded: sub_menu.insertItem(index, object)
  173. onObjectRemoved: sub_menu.removeItem(object)
  174. }
  175. }
  176. onObjectAdded: extension_menu.insertItem(index, object)
  177. onObjectRemoved: extension_menu.removeItem(object)
  178. }
  179. }
  180. Menu
  181. {
  182. title: catalog.i18nc("@title:menu menubar:toplevel","P&references");
  183. MenuItem { action: Cura.Actions.preferences; }
  184. }
  185. Menu
  186. {
  187. //: Help menu
  188. title: catalog.i18nc("@title:menu menubar:toplevel","&Help");
  189. MenuItem { action: Cura.Actions.showProfileFolder; }
  190. MenuItem { action: Cura.Actions.documentation; }
  191. MenuItem { action: Cura.Actions.reportBug; }
  192. MenuSeparator { }
  193. MenuItem { action: Cura.Actions.about; }
  194. }
  195. }
  196. UM.SettingPropertyProvider
  197. {
  198. id: machineExtruderCount
  199. containerStackId: Cura.MachineManager.activeMachineId
  200. key: "machine_extruder_count"
  201. watchedProperties: [ "value" ]
  202. storeIndex: 0
  203. }
  204. Item
  205. {
  206. id: contentItem;
  207. y: menu.height
  208. width: parent.width;
  209. height: parent.height - menu.height;
  210. Keys.forwardTo: menu
  211. DropArea
  212. {
  213. anchors.fill: parent;
  214. onDropped:
  215. {
  216. if (drop.urls.length > 0)
  217. {
  218. // Import models
  219. var imported_model = -1;
  220. for (var i in drop.urls)
  221. {
  222. // There is no endsWith in this version of JS...
  223. if ((drop.urls[i].length <= 12) || (drop.urls[i].substring(drop.urls[i].length-12) !== ".curaprofile")) {
  224. // Drop an object
  225. Printer.readLocalFile(drop.urls[i]);
  226. if (imported_model == -1)
  227. {
  228. imported_model = i;
  229. }
  230. }
  231. }
  232. // Import profiles
  233. var import_result = Cura.ContainerManager.importProfiles(drop.urls);
  234. if (import_result.message !== "") {
  235. messageDialog.text = import_result.message
  236. if (import_result.status == "ok")
  237. {
  238. messageDialog.icon = StandardIcon.Information
  239. }
  240. else
  241. {
  242. messageDialog.icon = StandardIcon.Critical
  243. }
  244. messageDialog.open()
  245. }
  246. if (imported_model != -1)
  247. {
  248. var meshName = backgroundItem.getMeshName(drop.urls[imported_model].toString())
  249. backgroundItem.hasMesh(decodeURIComponent(meshName))
  250. }
  251. }
  252. }
  253. }
  254. JobSpecs
  255. {
  256. id: jobSpecs
  257. anchors
  258. {
  259. bottom: parent.bottom;
  260. right: sidebar.left;
  261. bottomMargin: UM.Theme.getSize("default_margin").height;
  262. rightMargin: UM.Theme.getSize("default_margin").width;
  263. }
  264. }
  265. Loader
  266. {
  267. id: view_panel
  268. anchors.top: viewModeButton.bottom
  269. anchors.topMargin: UM.Theme.getSize("default_margin").height;
  270. anchors.left: viewModeButton.left;
  271. height: childrenRect.height;
  272. source: UM.ActiveView.valid ? UM.ActiveView.activeViewPanel : "";
  273. }
  274. Button
  275. {
  276. id: openFileButton;
  277. text: catalog.i18nc("@action:button","Open File");
  278. iconSource: UM.Theme.getIcon("load")
  279. style: UM.Theme.styles.tool_button
  280. tooltip: '';
  281. anchors
  282. {
  283. top: parent.top;
  284. left: parent.left;
  285. }
  286. action: Cura.Actions.open;
  287. }
  288. Image
  289. {
  290. id: logo
  291. anchors
  292. {
  293. left: parent.left
  294. leftMargin: UM.Theme.getSize("default_margin").width;
  295. bottom: parent.bottom
  296. bottomMargin: UM.Theme.getSize("default_margin").height;
  297. }
  298. source: UM.Theme.getImage("logo");
  299. width: UM.Theme.getSize("logo").width;
  300. height: UM.Theme.getSize("logo").height;
  301. z: -1;
  302. sourceSize.width: width;
  303. sourceSize.height: height;
  304. }
  305. Toolbar
  306. {
  307. id: toolbar;
  308. property int mouseX: base.mouseX
  309. property int mouseY: base.mouseY
  310. anchors {
  311. top: openFileButton.bottom;
  312. topMargin: UM.Theme.getSize("window_margin").height;
  313. left: parent.left;
  314. }
  315. }
  316. Sidebar
  317. {
  318. id: sidebar;
  319. anchors
  320. {
  321. top: parent.top;
  322. bottom: parent.bottom;
  323. right: parent.right;
  324. }
  325. z: 1
  326. onMonitoringPrintChanged: base.monitoringPrint = monitoringPrint
  327. width: UM.Theme.getSize("sidebar").width;
  328. }
  329. Button
  330. {
  331. id: viewModeButton
  332. anchors
  333. {
  334. top: toolbar.bottom;
  335. topMargin: UM.Theme.getSize("window_margin").height;
  336. left: parent.left;
  337. }
  338. text: catalog.i18nc("@action:button","View Mode");
  339. iconSource: UM.Theme.getIcon("viewmode");
  340. style: UM.Theme.styles.tool_button;
  341. tooltip: "";
  342. enabled: !PrintInformation.preSliced
  343. menu: ViewMenu { }
  344. }
  345. Rectangle
  346. {
  347. id: viewportOverlay
  348. color: UM.Theme.getColor("viewport_overlay")
  349. anchors
  350. {
  351. top: parent.top
  352. bottom: parent.bottom
  353. left:parent.left
  354. right: sidebar.left
  355. }
  356. visible: opacity > 0
  357. opacity: base.monitoringPrint ? 0.75 : 0
  358. Behavior on opacity { NumberAnimation { duration: 100; } }
  359. MouseArea {
  360. anchors.fill: parent
  361. acceptedButtons: Qt.AllButtons
  362. onWheel: wheel.accepted = true
  363. }
  364. }
  365. Image
  366. {
  367. id: cameraImage
  368. width: Math.min(viewportOverlay.width, sourceSize.width)
  369. height: sourceSize.height * width / sourceSize.width
  370. anchors.horizontalCenter: parent.horizontalCenter
  371. anchors.verticalCenter: parent.verticalCenter
  372. anchors.horizontalCenterOffset: - UM.Theme.getSize("sidebar").width / 2
  373. visible: base.monitoringPrint
  374. onVisibleChanged:
  375. {
  376. if(Cura.MachineManager.printerOutputDevices.length == 0 )
  377. {
  378. return;
  379. }
  380. if(visible)
  381. {
  382. Cura.MachineManager.printerOutputDevices[0].startCamera()
  383. } else
  384. {
  385. Cura.MachineManager.printerOutputDevices[0].stopCamera()
  386. }
  387. }
  388. source:
  389. {
  390. if(!base.monitoringPrint)
  391. {
  392. return "";
  393. }
  394. if(Cura.MachineManager.printerOutputDevices.length > 0 && Cura.MachineManager.printerOutputDevices[0].cameraImage)
  395. {
  396. return Cura.MachineManager.printerOutputDevices[0].cameraImage;
  397. }
  398. return "";
  399. }
  400. }
  401. UM.MessageStack
  402. {
  403. anchors
  404. {
  405. horizontalCenter: parent.horizontalCenter
  406. horizontalCenterOffset: -(UM.Theme.getSize("sidebar").width/ 2)
  407. top: parent.verticalCenter;
  408. bottom: parent.bottom;
  409. }
  410. }
  411. }
  412. }
  413. UM.PreferencesDialog
  414. {
  415. id: preferences
  416. Component.onCompleted:
  417. {
  418. //; Remove & re-add the general page as we want to use our own instead of uranium standard.
  419. removePage(0);
  420. insertPage(0, catalog.i18nc("@title:tab","General"), Qt.resolvedUrl("Preferences/GeneralPage.qml"));
  421. removePage(1);
  422. insertPage(1, catalog.i18nc("@title:tab","Settings"), Qt.resolvedUrl("Preferences/SettingVisibilityPage.qml"));
  423. insertPage(2, catalog.i18nc("@title:tab", "Printers"), Qt.resolvedUrl("Preferences/MachinesPage.qml"));
  424. insertPage(3, catalog.i18nc("@title:tab", "Materials"), Qt.resolvedUrl("Preferences/MaterialsPage.qml"));
  425. insertPage(4, catalog.i18nc("@title:tab", "Profiles"), Qt.resolvedUrl("Preferences/ProfilesPage.qml"));
  426. //Force refresh
  427. setPage(0);
  428. }
  429. onVisibleChanged:
  430. {
  431. // When the dialog closes, switch to the General page.
  432. // This prevents us from having a heavy page like Setting Visiblity active in the background.
  433. setPage(0);
  434. }
  435. }
  436. WorkspaceSummaryDialog
  437. {
  438. id: saveWorkspaceDialog
  439. onYes: UM.OutputDeviceManager.requestWriteToDevice("local_file", PrintInformation.jobName, { "filter_by_machine": false, "file_type": "workspace" })
  440. }
  441. Connections
  442. {
  443. target: Cura.Actions.preferences
  444. onTriggered: preferences.visible = true
  445. }
  446. MessageDialog
  447. {
  448. id: newProjectDialog
  449. modality: Qt.ApplicationModal
  450. title: catalog.i18nc("@title:window", "New project")
  451. text: catalog.i18nc("@info:question", "Are you sure you want to start a new project? This will clear the build plate and any unsaved settings.")
  452. standardButtons: StandardButton.Yes | StandardButton.No
  453. icon: StandardIcon.Question
  454. onYes:
  455. {
  456. Printer.deleteAll();
  457. Cura.Actions.resetProfile.trigger();
  458. }
  459. }
  460. Connections
  461. {
  462. target: Cura.Actions.newProject
  463. onTriggered:
  464. {
  465. if(Printer.platformActivity || Cura.MachineManager.hasUserSettings)
  466. {
  467. newProjectDialog.visible = true
  468. }
  469. }
  470. }
  471. Connections
  472. {
  473. target: Cura.Actions.addProfile
  474. onTriggered:
  475. {
  476. preferences.show();
  477. preferences.setPage(4);
  478. // Create a new profile after a very short delay so the preference page has time to initiate
  479. createProfileTimer.start();
  480. }
  481. }
  482. Connections
  483. {
  484. target: Cura.Actions.configureMachines
  485. onTriggered:
  486. {
  487. preferences.visible = true;
  488. preferences.setPage(2);
  489. }
  490. }
  491. Connections
  492. {
  493. target: Cura.Actions.manageProfiles
  494. onTriggered:
  495. {
  496. preferences.visible = true;
  497. preferences.setPage(4);
  498. }
  499. }
  500. Connections
  501. {
  502. target: Cura.Actions.manageMaterials
  503. onTriggered:
  504. {
  505. preferences.visible = true;
  506. preferences.setPage(3)
  507. }
  508. }
  509. Connections
  510. {
  511. target: Cura.Actions.configureSettingVisibility
  512. onTriggered:
  513. {
  514. preferences.visible = true;
  515. preferences.setPage(1);
  516. preferences.getCurrentItem().scrollToSection(source.key);
  517. }
  518. }
  519. Timer
  520. {
  521. id: createProfileTimer
  522. repeat: false
  523. interval: 1
  524. onTriggered: preferences.getCurrentItem().createProfile()
  525. }
  526. // BlurSettings is a way to force the focus away from any of the setting items.
  527. // We need to do this in order to keep the bindings intact.
  528. Connections
  529. {
  530. target: Cura.MachineManager
  531. onBlurSettings:
  532. {
  533. contentItem.forceActiveFocus()
  534. }
  535. }
  536. Menu
  537. {
  538. id: objectContextMenu;
  539. property variant objectId: -1;
  540. MenuItem { action: Cura.Actions.centerObject; }
  541. MenuItem { action: Cura.Actions.deleteObject; }
  542. MenuItem { action: Cura.Actions.multiplyObject; }
  543. MenuSeparator { }
  544. MenuItem { action: Cura.Actions.selectAll; }
  545. MenuItem { action: Cura.Actions.deleteAll; }
  546. MenuItem { action: Cura.Actions.reloadAll; }
  547. MenuItem { action: Cura.Actions.resetAllTranslation; }
  548. MenuItem { action: Cura.Actions.resetAll; }
  549. MenuSeparator { }
  550. MenuItem { action: Cura.Actions.groupObjects; }
  551. MenuItem { action: Cura.Actions.mergeObjects; }
  552. MenuItem { action: Cura.Actions.unGroupObjects; }
  553. Connections
  554. {
  555. target: Cura.Actions.deleteObject
  556. onTriggered:
  557. {
  558. if(objectContextMenu.objectId != 0)
  559. {
  560. Printer.deleteObject(objectContextMenu.objectId);
  561. objectContextMenu.objectId = 0;
  562. }
  563. }
  564. }
  565. MultiplyObjectOptions
  566. {
  567. id: multiplyObjectOptions
  568. }
  569. Connections
  570. {
  571. target: Cura.Actions.multiplyObject
  572. onTriggered:
  573. {
  574. if(objectContextMenu.objectId != 0)
  575. {
  576. multiplyObjectOptions.objectId = objectContextMenu.objectId;
  577. multiplyObjectOptions.visible = true;
  578. multiplyObjectOptions.reset();
  579. objectContextMenu.objectId = 0;
  580. }
  581. }
  582. }
  583. Connections
  584. {
  585. target: Cura.Actions.centerObject
  586. onTriggered:
  587. {
  588. if(objectContextMenu.objectId != 0)
  589. {
  590. Printer.centerObject(objectContextMenu.objectId);
  591. objectContextMenu.objectId = 0;
  592. }
  593. }
  594. }
  595. }
  596. Menu
  597. {
  598. id: contextMenu;
  599. MenuItem { action: Cura.Actions.selectAll; }
  600. MenuItem { action: Cura.Actions.deleteAll; }
  601. MenuItem { action: Cura.Actions.reloadAll; }
  602. MenuItem { action: Cura.Actions.resetAllTranslation; }
  603. MenuItem { action: Cura.Actions.resetAll; }
  604. MenuSeparator { }
  605. MenuItem { action: Cura.Actions.groupObjects; }
  606. MenuItem { action: Cura.Actions.mergeObjects; }
  607. MenuItem { action: Cura.Actions.unGroupObjects; }
  608. }
  609. Connections
  610. {
  611. target: UM.Controller
  612. onContextMenuRequested:
  613. {
  614. if(objectId == 0)
  615. {
  616. contextMenu.popup();
  617. } else
  618. {
  619. objectContextMenu.objectId = objectId;
  620. objectContextMenu.popup();
  621. }
  622. }
  623. }
  624. Connections
  625. {
  626. target: Cura.Actions.quit
  627. onTriggered: base.visible = false;
  628. }
  629. Connections
  630. {
  631. target: Cura.Actions.toggleFullScreen
  632. onTriggered: base.toggleFullscreen();
  633. }
  634. FileDialog
  635. {
  636. id: openDialog;
  637. //: File open dialog title
  638. title: catalog.i18nc("@title:window","Open file(s)")
  639. modality: UM.Application.platform == "linux" ? Qt.NonModal : Qt.WindowModal;
  640. selectMultiple: true
  641. nameFilters: UM.MeshFileHandler.supportedReadFileTypes;
  642. folder: CuraApplication.getDefaultPath("dialog_load_path")
  643. onAccepted:
  644. {
  645. // Because several implementations of the file dialog only update the folder
  646. // when it is explicitly set.
  647. var f = folder;
  648. folder = f;
  649. CuraApplication.setDefaultPath("dialog_load_path", folder);
  650. // look for valid project files
  651. var projectFileUrlList = [];
  652. for (var i in fileUrls)
  653. {
  654. if (CuraApplication.checkIsValidProjectFile(fileUrls[i]))
  655. projectFileUrlList.push(fileUrls[i]);
  656. }
  657. // we only allow opening one project file
  658. var selectedMultipleFiles = fileUrls.length > 1;
  659. var hasProjectFile = projectFileUrlList.length > 0;
  660. var selectedMultipleWithProjectFile = hasProjectFile && selectedMultipleFiles;
  661. if (selectedMultipleWithProjectFile)
  662. {
  663. openFilesIncludingProjectsDialog.fileUrls = fileUrls;
  664. openFilesIncludingProjectsDialog.show();
  665. return;
  666. }
  667. if (hasProjectFile)
  668. {
  669. var projectFile = projectFileUrlList[0];
  670. // check preference
  671. var choice = UM.Preferences.getValue("cura/choice_on_open_project");
  672. if (choice == "open_as_project")
  673. openFilesIncludingProjectsDialog.loadProjectFile(projectFile);
  674. else if (choice == "open_as_model")
  675. openFilesIncludingProjectsDialog.loadModelFiles([projectFile]);
  676. else // always ask
  677. {
  678. // ask whether to open as project or as models
  679. askOpenAsProjectOrModelsDialog.fileUrl = projectFile;
  680. askOpenAsProjectOrModelsDialog.show();
  681. }
  682. }
  683. else
  684. {
  685. openFilesIncludingProjectsDialog.loadModelFiles(fileUrls);
  686. }
  687. }
  688. }
  689. Connections
  690. {
  691. target: Cura.Actions.open
  692. onTriggered: openDialog.open()
  693. }
  694. OpenFilesIncludingProjectsDialog
  695. {
  696. id: openFilesIncludingProjectsDialog
  697. }
  698. AskOpenAsProjectOrModelsDialog
  699. {
  700. id: askOpenAsProjectOrModelsDialog
  701. }
  702. EngineLog
  703. {
  704. id: engineLog;
  705. }
  706. Connections
  707. {
  708. target: Cura.Actions.showProfileFolder
  709. onTriggered:
  710. {
  711. var path = UM.Resources.getPath(UM.Resources.Preferences, "");
  712. if(Qt.platform.os == "windows") {
  713. path = path.replace(/\\/g,"/");
  714. }
  715. Qt.openUrlExternally(path);
  716. }
  717. }
  718. AddMachineDialog
  719. {
  720. id: addMachineDialog
  721. onMachineAdded:
  722. {
  723. machineActionsWizard.firstRun = addMachineDialog.firstRun
  724. machineActionsWizard.start(id)
  725. }
  726. }
  727. // Dialog to handle first run machine actions
  728. UM.Wizard
  729. {
  730. id: machineActionsWizard;
  731. title: catalog.i18nc("@title:window", "Add Printer")
  732. property var machine;
  733. function start(id)
  734. {
  735. var actions = Cura.MachineActionManager.getFirstStartActions(id)
  736. resetPages() // Remove previous pages
  737. for (var i = 0; i < actions.length; i++)
  738. {
  739. actions[i].displayItem.reset()
  740. machineActionsWizard.appendPage(actions[i].displayItem, catalog.i18nc("@title", actions[i].label));
  741. }
  742. //Only start if there are actions to perform.
  743. if (actions.length > 0)
  744. {
  745. machineActionsWizard.currentPage = 0;
  746. show()
  747. }
  748. }
  749. }
  750. MessageDialog
  751. {
  752. id: messageDialog
  753. modality: Qt.ApplicationModal
  754. onAccepted: Printer.messageBoxClosed(clickedButton)
  755. onApply: Printer.messageBoxClosed(clickedButton)
  756. onDiscard: Printer.messageBoxClosed(clickedButton)
  757. onHelp: Printer.messageBoxClosed(clickedButton)
  758. onNo: Printer.messageBoxClosed(clickedButton)
  759. onRejected: Printer.messageBoxClosed(clickedButton)
  760. onReset: Printer.messageBoxClosed(clickedButton)
  761. onYes: Printer.messageBoxClosed(clickedButton)
  762. }
  763. Connections
  764. {
  765. target: Printer
  766. onShowMessageBox:
  767. {
  768. messageDialog.title = title
  769. messageDialog.text = text
  770. messageDialog.informativeText = informativeText
  771. messageDialog.detailedText = detailedText
  772. messageDialog.standardButtons = buttons
  773. messageDialog.icon = icon
  774. messageDialog.visible = true
  775. }
  776. }
  777. DiscardOrKeepProfileChangesDialog
  778. {
  779. id: discardOrKeepProfileChangesDialog
  780. }
  781. Connections
  782. {
  783. target: Printer
  784. onShowDiscardOrKeepProfileChanges:
  785. {
  786. discardOrKeepProfileChangesDialog.show()
  787. }
  788. }
  789. Connections
  790. {
  791. target: Cura.Actions.addMachine
  792. onTriggered: addMachineDialog.visible = true;
  793. }
  794. AboutDialog
  795. {
  796. id: aboutDialog
  797. }
  798. Connections
  799. {
  800. target: Cura.Actions.about
  801. onTriggered: aboutDialog.visible = true;
  802. }
  803. Connections
  804. {
  805. target: Printer
  806. onRequestAddPrinter:
  807. {
  808. addMachineDialog.visible = true
  809. addMachineDialog.firstRun = false
  810. }
  811. }
  812. Timer
  813. {
  814. id: startupTimer;
  815. interval: 100;
  816. repeat: false;
  817. running: true;
  818. onTriggered:
  819. {
  820. if(!base.visible)
  821. {
  822. base.visible = true;
  823. restart();
  824. }
  825. else if(Cura.MachineManager.activeMachineId == null || Cura.MachineManager.activeMachineId == "")
  826. {
  827. addMachineDialog.open();
  828. }
  829. }
  830. }
  831. }