Cura.qml 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906
  1. // Copyright (c) 2022 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.7
  4. import QtQuick.Controls 2.15
  5. import QtQuick.Dialogs
  6. import UM 1.5 as UM
  7. import Cura 1.1 as Cura
  8. import "Dialogs"
  9. import "Menus"
  10. import "MainWindow"
  11. import "WelcomePages"
  12. UM.MainWindow
  13. {
  14. id: base
  15. // Cura application window title
  16. title:
  17. {
  18. let result = "";
  19. if(PrintInformation !== null && PrintInformation.jobName != "")
  20. {
  21. result += PrintInformation.jobName + " - ";
  22. }
  23. result += CuraApplication.applicationDisplayName;
  24. return result;
  25. }
  26. backgroundColor: UM.Theme.getColor("viewport_background")
  27. UM.I18nCatalog
  28. {
  29. id: catalog
  30. name: "cura"
  31. }
  32. function showTooltip(item, position, text)
  33. {
  34. tooltip.text = text;
  35. position = item.mapToItem(backgroundItem, position.x - UM.Theme.getSize("default_arrow").width, position.y);
  36. tooltip.show(position);
  37. }
  38. function hideTooltip()
  39. {
  40. tooltip.hide();
  41. }
  42. MouseArea
  43. {
  44. // Hack introduced when switching to qt6
  45. // We used to be able to let the main window's default handlers control this, but something seems to be changed
  46. // for qt6 in the ordering. TODO; We should find out what changed and have a less hacky fix for that.
  47. enabled: parent.visible
  48. anchors.fill: parent
  49. hoverEnabled: true
  50. acceptedButtons: Qt.AllButtons
  51. onPositionChanged: (mouse) => {base.mouseMoved(mouse);}
  52. onPressed: (mouse) => { base.mousePressed(mouse);}
  53. onReleased: (mouse) => { base.mouseReleased(mouse);}
  54. onWheel: (wheel) => {base.wheel(wheel)}
  55. }
  56. Rectangle
  57. {
  58. id: greyOutBackground
  59. anchors.fill: parent
  60. visible: welcomeDialogItem.visible
  61. color: UM.Theme.getColor("window_disabled_background")
  62. opacity: 0.7
  63. z: stageMenu.z + 1
  64. MouseArea
  65. {
  66. // Prevent all mouse events from passing through.
  67. enabled: parent.visible
  68. anchors.fill: parent
  69. hoverEnabled: true
  70. acceptedButtons: Qt.AllButtons
  71. }
  72. }
  73. WelcomeDialogItem
  74. {
  75. id: welcomeDialogItem
  76. visible: false
  77. z: greyOutBackground.z + 1
  78. }
  79. Component.onCompleted:
  80. {
  81. CuraApplication.setMinimumWindowSize(UM.Theme.getSize("window_minimum_size"))
  82. CuraApplication.purgeWindows()
  83. }
  84. Connections
  85. {
  86. // This connection is used when there is no ActiveMachine and the user is logged in
  87. target: CuraApplication
  88. function onShowAddPrintersUncancellableDialog()
  89. {
  90. Cura.Actions.parent = backgroundItem
  91. // Reuse the welcome dialog item to show "Add a printer" only.
  92. welcomeDialogItem.model = CuraApplication.getAddPrinterPagesModelWithoutCancel()
  93. welcomeDialogItem.progressBarVisible = false
  94. welcomeDialogItem.visible = true
  95. }
  96. }
  97. Connections
  98. {
  99. target: CuraApplication
  100. function onInitializationFinished()
  101. {
  102. // Workaround silly issues with QML Action's shortcut property.
  103. //
  104. // Currently, there is no way to define shortcuts as "Application Shortcut".
  105. // This means that all Actions are "Window Shortcuts". The code for this
  106. // implements a rather naive check that just checks if any of the action's parents
  107. // are a window. Since the "Actions" object is a singleton it has no parent by
  108. // default. If we set its parent to something contained in this window, the
  109. // shortcut will activate properly because one of its parents is a window.
  110. //
  111. // This has been fixed for QtQuick Controls 2 since the Shortcut item has a context property.
  112. Cura.Actions.parent = backgroundItem
  113. if (CuraApplication.shouldShowWelcomeDialog())
  114. {
  115. welcomeDialogItem.visible = true
  116. }
  117. else
  118. {
  119. welcomeDialogItem.visible = false
  120. }
  121. // Reuse the welcome dialog item to show "What's New" only.
  122. if (CuraApplication.shouldShowWhatsNewDialog())
  123. {
  124. welcomeDialogItem.model = CuraApplication.getWhatsNewPagesModel()
  125. welcomeDialogItem.progressBarVisible = false
  126. welcomeDialogItem.visible = true
  127. }
  128. // Reuse the welcome dialog item to show the "Add printers" dialog. Triggered when there is no active
  129. // machine and the user is logged in.
  130. if (!Cura.MachineManager.activeMachine && Cura.API.account.isLoggedIn)
  131. {
  132. welcomeDialogItem.model = CuraApplication.getAddPrinterPagesModelWithoutCancel()
  133. welcomeDialogItem.progressBarVisible = false
  134. welcomeDialogItem.visible = true
  135. }
  136. }
  137. }
  138. Item
  139. {
  140. id: backgroundItem
  141. anchors.fill: parent
  142. //DeleteSelection on the keypress backspace event
  143. Keys.onPressed: (event) =>
  144. {
  145. if (event.key == Qt.Key_Backspace)
  146. {
  147. Cura.Actions.deleteSelection.trigger()
  148. }
  149. }
  150. ApplicationMenu
  151. {
  152. id: applicationMenu
  153. }
  154. Item
  155. {
  156. id: headerBackground
  157. anchors
  158. {
  159. top: applicationMenu.bottom
  160. left: parent.left
  161. right: parent.right
  162. }
  163. height: stageMenu.source != "" ? Math.round(mainWindowHeader.height + stageMenu.height / 2) : mainWindowHeader.height
  164. Rectangle
  165. {
  166. anchors.fill: parent
  167. color: UM.Theme.getColor("main_window_header_background")
  168. }
  169. // This is a placeholder for adding a pattern in the header
  170. Image
  171. {
  172. id: backgroundPattern
  173. anchors.fill: parent
  174. fillMode: Image.Tile
  175. source: UM.Theme.getImage("header_pattern")
  176. horizontalAlignment: Image.AlignLeft
  177. verticalAlignment: Image.AlignTop
  178. }
  179. }
  180. MainWindowHeader
  181. {
  182. id: mainWindowHeader
  183. anchors
  184. {
  185. left: parent.left
  186. right: parent.right
  187. top: applicationMenu.bottom
  188. }
  189. }
  190. Item
  191. {
  192. id: contentItem
  193. anchors
  194. {
  195. top: mainWindowHeader.bottom
  196. bottom: parent.bottom
  197. left: parent.left
  198. right: parent.right
  199. }
  200. Keys.forwardTo: applicationMenu
  201. DropArea
  202. {
  203. // The drop area is here to handle files being dropped onto Cura.
  204. anchors.fill: parent
  205. onDropped: (drop) =>
  206. {
  207. if (drop.urls.length > 0)
  208. {
  209. var nonPackages = [];
  210. for (var i = 0; i < drop.urls.length; i++)
  211. {
  212. var filename = drop.urls[i];
  213. if (filename.toString().toLowerCase().endsWith(".curapackage"))
  214. {
  215. // Try to install plugin & close.
  216. CuraApplication.installPackageViaDragAndDrop(filename);
  217. packageInstallDialog.text = catalog.i18nc("@label", "This package will be installed after restarting.");
  218. packageInstallDialog.open();
  219. }
  220. else
  221. {
  222. nonPackages.push(filename);
  223. }
  224. }
  225. openDialog.handleOpenFileUrls(nonPackages);
  226. }
  227. }
  228. }
  229. ObjectSelector
  230. {
  231. id: objectSelector
  232. visible: CuraApplication.platformActivity
  233. anchors
  234. {
  235. bottom: jobSpecs.top
  236. left: toolbar.right
  237. leftMargin: UM.Theme.getSize("default_margin").width
  238. rightMargin: UM.Theme.getSize("default_margin").width
  239. bottomMargin: UM.Theme.getSize("narrow_margin").height
  240. }
  241. }
  242. JobSpecs
  243. {
  244. id: jobSpecs
  245. visible: CuraApplication.platformActivity
  246. anchors
  247. {
  248. left: toolbar.right
  249. bottom: viewOrientationControls.top
  250. leftMargin: UM.Theme.getSize("default_margin").width
  251. rightMargin: UM.Theme.getSize("default_margin").width
  252. bottomMargin: UM.Theme.getSize("thin_margin").width
  253. topMargin: UM.Theme.getSize("thin_margin").width
  254. }
  255. }
  256. ViewOrientationControls
  257. {
  258. id: viewOrientationControls
  259. anchors
  260. {
  261. left: toolbar.right
  262. bottom: parent.bottom
  263. margins: UM.Theme.getSize("default_margin").width
  264. }
  265. }
  266. Toolbar
  267. {
  268. // The toolbar is the left bar that is populated by all the tools
  269. // (which are dynamically populated by plugins)
  270. id: toolbar
  271. property int mouseX: base.mouseX
  272. property int mouseY: base.mouseY
  273. property bool tallerThanParent: height > parent.height
  274. z: 1 // Ensure toolbar and toolpanels are drawn on top
  275. anchors
  276. {
  277. verticalCenter: tallerThanParent ? undefined : parent.verticalCenter
  278. left: parent.left
  279. }
  280. visible: CuraApplication.platformActivity && !PrintInformation.preSliced
  281. }
  282. // A hint for the loaded content view. Overlay items / controls can safely be placed in this area
  283. Item {
  284. id: mainSafeArea
  285. anchors.left: viewOrientationControls.right
  286. anchors.right: main.right
  287. anchors.top: main.top
  288. anchors.bottom: main.bottom
  289. }
  290. Loader
  291. {
  292. // A stage can control this area. If nothing is set, it will therefore show the 3D view.
  293. id: main
  294. anchors
  295. {
  296. // Align to the top of the stageMenu since the stageMenu may not exist
  297. top: stageMenu.source ? stageMenu.verticalCenter : parent.top
  298. left: parent.left
  299. right: parent.right
  300. bottom: parent.bottom
  301. }
  302. source: UM.Controller.activeStage != null ? UM.Controller.activeStage.mainComponent : ""
  303. onLoaded: {
  304. if (main.item.safeArea !== undefined){
  305. main.item.safeArea = Qt.binding(function() { return mainSafeArea });
  306. }
  307. }
  308. }
  309. Loader
  310. {
  311. // The stage menu is, as the name implies, a menu that is defined by the active stage.
  312. // Note that this menu does not need to be set at all! It's perfectly acceptable to have a stage
  313. // without this menu!
  314. id: stageMenu
  315. anchors
  316. {
  317. left: parent.left
  318. right: parent.right
  319. top: parent.top
  320. }
  321. height: UM.Theme.getSize("stage_menu").height
  322. source: UM.Controller.activeStage != null ? UM.Controller.activeStage.stageMenuComponent : ""
  323. // HACK: This is to ensure that the parent never gets set to null, as this wreaks havoc on the focus.
  324. function onParentDestroyed()
  325. {
  326. printSetupSelector.parent = stageMenu
  327. printSetupSelector.visible = false
  328. }
  329. property Item oldParent: null
  330. // The printSetupSelector is defined here so that the setting list doesn't need to get re-instantiated
  331. // Every time the stage is changed.
  332. property var printSetupSelector: Cura.PrintSetupSelector
  333. {
  334. width: UM.Theme.getSize("print_setup_widget").width
  335. height: UM.Theme.getSize("stage_menu").height
  336. headerCornerSide: RoundedRectangle.Direction.Right
  337. onParentChanged:
  338. {
  339. if(stageMenu.oldParent !=null)
  340. {
  341. stageMenu.oldParent.Component.destruction.disconnect(stageMenu.onParentDestroyed)
  342. }
  343. stageMenu.oldParent = parent
  344. visible = parent != stageMenu
  345. parent.Component.destruction.connect(stageMenu.onParentDestroyed)
  346. }
  347. }
  348. }
  349. UM.MessageStack
  350. {
  351. anchors
  352. {
  353. horizontalCenter: parent.horizontalCenter
  354. top: parent.verticalCenter
  355. bottom: parent.bottom
  356. bottomMargin: UM.Theme.getSize("default_margin").height
  357. }
  358. primaryButton: Component
  359. {
  360. Cura.PrimaryButton
  361. {
  362. text: model.name
  363. iconSource: UM.Theme.getIcon(model.icon)
  364. height: UM.Theme.getSize("message_action_button").height
  365. }
  366. }
  367. secondaryButton: Component
  368. {
  369. Cura.SecondaryButton
  370. {
  371. text: model.name
  372. iconSource: UM.Theme.getIcon(model.icon)
  373. height: UM.Theme.getSize("message_action_button").height
  374. }
  375. }
  376. link: Component
  377. {
  378. Cura.TertiaryButton
  379. {
  380. text: model.name
  381. iconSource:
  382. {
  383. if (model.icon == null || model.icon == "")
  384. {
  385. return UM.Theme.getIcon("LinkExternal")
  386. }
  387. return UM.Theme.getIcon(model.icon)
  388. }
  389. height: UM.Theme.getSize("message_action_button").height
  390. }
  391. }
  392. }
  393. }
  394. PrintSetupTooltip
  395. {
  396. id: tooltip
  397. sourceWidth: UM.Theme.getSize("print_setup_widget").width
  398. }
  399. }
  400. UM.PreferencesDialog
  401. {
  402. id: preferences
  403. Component.onCompleted:
  404. {
  405. //; Remove & re-add the general page as we want to use our own instead of uranium standard.
  406. removePage(0);
  407. insertPage(0, catalog.i18nc("@title:tab","General"), Qt.resolvedUrl("Preferences/GeneralPage.qml"));
  408. removePage(1);
  409. insertPage(1, catalog.i18nc("@title:tab","Settings"), Qt.resolvedUrl("Preferences/SettingVisibilityPage.qml"));
  410. insertPage(2, catalog.i18nc("@title:tab", "Printers"), Qt.resolvedUrl("Preferences/MachinesPage.qml"));
  411. insertPage(3, catalog.i18nc("@title:tab", "Materials"), Qt.resolvedUrl("Preferences/Materials/MaterialsPage.qml"));
  412. insertPage(4, catalog.i18nc("@title:tab", "Profiles"), Qt.resolvedUrl("Preferences/ProfilesPage.qml"));
  413. currentPage = 0;
  414. }
  415. onVisibleChanged:
  416. {
  417. // When the dialog closes, switch to the General page.
  418. // This prevents us from having a heavy page like Setting Visibility active in the background.
  419. setPage(0);
  420. }
  421. }
  422. Connections
  423. {
  424. target: Cura.Actions.preferences
  425. function onTriggered() { preferences.visible = true }
  426. }
  427. Connections
  428. {
  429. target: CuraApplication
  430. function onShowPreferencesWindow() { preferences.visible = true }
  431. }
  432. Connections
  433. {
  434. target: Cura.Actions.addProfile
  435. function onTriggered()
  436. {
  437. preferences.show();
  438. preferences.setPage(4);
  439. // Create a new profile after a very short delay so the preference page has time to initiate
  440. createProfileTimer.start();
  441. }
  442. }
  443. Connections
  444. {
  445. target: Cura.Actions.configureMachines
  446. function onTriggered()
  447. {
  448. preferences.visible = true;
  449. preferences.setPage(2);
  450. }
  451. }
  452. Connections
  453. {
  454. target: Cura.Actions.manageProfiles
  455. function onTriggered()
  456. {
  457. preferences.visible = true;
  458. preferences.setPage(4);
  459. }
  460. }
  461. Connections
  462. {
  463. target: Cura.Actions.manageMaterials
  464. function onTriggered()
  465. {
  466. preferences.visible = true;
  467. preferences.setPage(3)
  468. }
  469. }
  470. Connections
  471. {
  472. target: Cura.Actions.configureSettingVisibility
  473. function onTriggered(source)
  474. {
  475. preferences.visible = true;
  476. preferences.setPage(1);
  477. if(source && source.key)
  478. {
  479. preferences.getCurrentItem().scrollToSection(source.key);
  480. }
  481. }
  482. }
  483. Timer
  484. {
  485. id: createProfileTimer
  486. repeat: false
  487. interval: 1
  488. onTriggered: preferences.getCurrentItem().createProfile()
  489. }
  490. // BlurSettings is a way to force the focus away from any of the setting items.
  491. // We need to do this in order to keep the bindings intact.
  492. Connections
  493. {
  494. target: Cura.MachineManager
  495. function onBlurSettings()
  496. {
  497. contentItem.forceActiveFocus()
  498. }
  499. }
  500. ContextMenu
  501. {
  502. id: contextMenu
  503. }
  504. onPreClosing: (close) =>
  505. {
  506. close.accepted = CuraApplication.getIsAllChecksPassed();
  507. if (!close.accepted)
  508. {
  509. CuraApplication.checkAndExitApplication();
  510. }
  511. }
  512. Cura.MessageDialog
  513. {
  514. id: exitConfirmationDialog
  515. title: catalog.i18nc("@title:window %1 is the application name", "Closing %1").arg(CuraApplication.applicationDisplayName)
  516. text: catalog.i18nc("@label %1 is the application name", "Are you sure you want to exit %1?").arg(CuraApplication.applicationDisplayName)
  517. standardButtons: Dialog.Yes | Dialog.No
  518. onAccepted: CuraApplication.callConfirmExitDialogCallback(true)
  519. onRejected: CuraApplication.callConfirmExitDialogCallback(false)
  520. onClosed:
  521. {
  522. if (!visible)
  523. {
  524. // reset the text to default because other modules may change the message text.
  525. text = catalog.i18nc("@label %1 is the application name", "Are you sure you want to exit %1?").arg(CuraApplication.applicationDisplayName);
  526. }
  527. }
  528. }
  529. Connections
  530. {
  531. target: CuraApplication
  532. function onShowConfirmExitDialog(message)
  533. {
  534. exitConfirmationDialog.text = message;
  535. exitConfirmationDialog.open();
  536. }
  537. }
  538. Connections
  539. {
  540. target: Cura.Actions.quit
  541. function onTriggered() { CuraApplication.checkAndExitApplication(); }
  542. }
  543. Connections
  544. {
  545. target: Cura.Actions.toggleFullScreen
  546. function onTriggered() { base.toggleFullscreen() }
  547. }
  548. Connections
  549. {
  550. target: Cura.Actions.exitFullScreen
  551. function onTriggered() { base.exitFullscreen() }
  552. }
  553. FileDialog
  554. {
  555. id: openDialog;
  556. //: File open dialog title
  557. title: catalog.i18nc("@title:window","Open file(s)")
  558. modality: Qt.WindowModal
  559. fileMode: FileDialog.OpenFiles
  560. nameFilters: UM.MeshFileHandler.supportedReadFileTypes;
  561. currentFolder: CuraApplication.getDefaultPath("dialog_load_path")
  562. onAccepted:
  563. {
  564. // Because several implementations of the file dialog only update the folder
  565. // when it is explicitly set.
  566. var f = currentFolder;
  567. currentFolder = f;
  568. CuraApplication.setDefaultPath("dialog_load_path", currentFolder);
  569. handleOpenFileUrls(selectedFiles);
  570. }
  571. // Yeah... I know... it is a mess to put all those things here.
  572. // There are lots of user interactions in this part of the logic, such as showing a warning dialog here and there,
  573. // etc. This means it will come back and forth from time to time between QML and Python. So, separating the logic
  574. // and view here may require more effort but make things more difficult to understand.
  575. function handleOpenFileUrls(fileUrlList)
  576. {
  577. // look for valid project files
  578. var projectFileUrlList = [];
  579. var hasGcode = false;
  580. var nonGcodeFileList = [];
  581. for (var i in fileUrlList)
  582. {
  583. var endsWithG = /\.g$/;
  584. var endsWithGcode = /\.gcode$/;
  585. if (endsWithG.test(fileUrlList[i]) || endsWithGcode.test(fileUrlList[i]))
  586. {
  587. continue;
  588. }
  589. else if (CuraApplication.checkIsValidProjectFile(fileUrlList[i]))
  590. {
  591. projectFileUrlList.push(fileUrlList[i]);
  592. }
  593. nonGcodeFileList.push(fileUrlList[i]);
  594. }
  595. hasGcode = nonGcodeFileList.length < fileUrlList.length;
  596. // show a warning if selected multiple files together with Gcode
  597. var hasProjectFile = projectFileUrlList.length > 0;
  598. var selectedMultipleFiles = fileUrlList.length > 1;
  599. if (selectedMultipleFiles && hasGcode)
  600. {
  601. infoMultipleFilesWithGcodeDialog.selectedMultipleFiles = selectedMultipleFiles;
  602. infoMultipleFilesWithGcodeDialog.hasProjectFile = hasProjectFile;
  603. infoMultipleFilesWithGcodeDialog.fileUrls = nonGcodeFileList.slice();
  604. infoMultipleFilesWithGcodeDialog.projectFileUrlList = projectFileUrlList.slice();
  605. infoMultipleFilesWithGcodeDialog.open();
  606. }
  607. else
  608. {
  609. handleOpenFiles(selectedMultipleFiles, hasProjectFile, fileUrlList, projectFileUrlList);
  610. }
  611. }
  612. function handleOpenFiles(selectedMultipleFiles, hasProjectFile, fileUrlList, projectFileUrlList)
  613. {
  614. // Make sure the files opened through the openFilesIncludingProjectDialog are added to the recent files list
  615. openFilesIncludingProjectsDialog.addToRecent = true;
  616. // we only allow opening one project file
  617. if (selectedMultipleFiles && hasProjectFile)
  618. {
  619. openFilesIncludingProjectsDialog.fileUrls = fileUrlList.slice();
  620. openFilesIncludingProjectsDialog.show();
  621. return;
  622. }
  623. if (hasProjectFile)
  624. {
  625. var projectFile = projectFileUrlList[0];
  626. // check preference
  627. var choice = UM.Preferences.getValue("cura/choice_on_open_project");
  628. if (choice == "open_as_project")
  629. {
  630. openFilesIncludingProjectsDialog.loadProjectFile(projectFile);
  631. }
  632. else if (choice == "open_as_model")
  633. {
  634. openFilesIncludingProjectsDialog.loadModelFiles([projectFile].slice());
  635. }
  636. else // always ask
  637. {
  638. // ask whether to open as project or as models
  639. askOpenAsProjectOrModelsDialog.fileUrl = projectFile;
  640. askOpenAsProjectOrModelsDialog.addToRecent = true;
  641. askOpenAsProjectOrModelsDialog.show();
  642. }
  643. }
  644. else
  645. {
  646. openFilesIncludingProjectsDialog.loadModelFiles(fileUrlList.slice());
  647. }
  648. }
  649. }
  650. Cura.MessageDialog
  651. {
  652. id: packageInstallDialog
  653. title: catalog.i18nc("@window:title", "Install Package")
  654. standardButtons: Dialog.Ok
  655. }
  656. Cura.MessageDialog
  657. {
  658. id: infoMultipleFilesWithGcodeDialog
  659. title: catalog.i18nc("@title:window", "Open File(s)")
  660. standardButtons: Dialog.Ok
  661. text: catalog.i18nc("@text:window", "We have found one or more G-Code files within the files you have selected. You can only open one G-Code file at a time. If you want to open a G-Code file, please just select only one.")
  662. property var selectedMultipleFiles
  663. property var hasProjectFile
  664. property var fileUrls
  665. property var projectFileUrlList
  666. onAccepted:
  667. {
  668. openDialog.handleOpenFiles(selectedMultipleFiles, hasProjectFile, fileUrls, projectFileUrlList);
  669. }
  670. }
  671. Connections
  672. {
  673. target: Cura.Actions.open
  674. function onTriggered() { openDialog.open() }
  675. }
  676. OpenFilesIncludingProjectsDialog
  677. {
  678. id: openFilesIncludingProjectsDialog
  679. }
  680. AskOpenAsProjectOrModelsDialog
  681. {
  682. id: askOpenAsProjectOrModelsDialog
  683. }
  684. Connections
  685. {
  686. target: CuraApplication
  687. function onOpenProjectFile(project_file, add_to_recent_files)
  688. {
  689. askOpenAsProjectOrModelsDialog.fileUrl = project_file;
  690. askOpenAsProjectOrModelsDialog.addToRecent = add_to_recent_files;
  691. askOpenAsProjectOrModelsDialog.show();
  692. }
  693. }
  694. Connections
  695. {
  696. target: Cura.Actions.showProfileFolder
  697. function onTriggered()
  698. {
  699. var path = UM.Resources.getPath(UM.Resources.Preferences, "");
  700. if(Qt.platform.os == "windows")
  701. {
  702. path = path.replace(/\\/g,"/");
  703. }
  704. Qt.openUrlExternally(path);
  705. if(Qt.platform.os == "linux")
  706. {
  707. Qt.openUrlExternally(UM.Resources.getPath(UM.Resources.Resources, ""));
  708. }
  709. }
  710. }
  711. Component
  712. {
  713. id: discardOrKeepProfileChangesDialogComponent
  714. DiscardOrKeepProfileChangesDialog { }
  715. }
  716. Loader
  717. {
  718. id: discardOrKeepProfileChangesDialogLoader
  719. }
  720. Connections
  721. {
  722. target: CuraApplication
  723. function onShowDiscardOrKeepProfileChanges()
  724. {
  725. discardOrKeepProfileChangesDialogLoader.sourceComponent = discardOrKeepProfileChangesDialogComponent
  726. discardOrKeepProfileChangesDialogLoader.item.show()
  727. }
  728. }
  729. Cura.WizardDialog
  730. {
  731. id: addMachineDialog
  732. title: catalog.i18nc("@title:window", "Add Printer")
  733. model: CuraApplication.getAddPrinterPagesModel()
  734. progressBarVisible: false
  735. }
  736. Cura.WizardDialog
  737. {
  738. id: whatsNewDialog
  739. title: catalog.i18nc("@title:window", "What's New")
  740. minimumWidth: UM.Theme.getSize("welcome_wizard_window").width
  741. minimumHeight: UM.Theme.getSize("welcome_wizard_window").height
  742. model: CuraApplication.getWhatsNewPagesModel()
  743. progressBarVisible: false
  744. visible: false
  745. }
  746. Connections
  747. {
  748. target: Cura.Actions.whatsNew
  749. function onTriggered() { whatsNewDialog.show() }
  750. }
  751. Connections
  752. {
  753. target: Cura.Actions.addMachine
  754. function onTriggered()
  755. {
  756. // Make sure to show from the first page when the dialog shows up.
  757. addMachineDialog.resetModelState()
  758. addMachineDialog.show()
  759. }
  760. }
  761. AboutDialog
  762. {
  763. id: aboutDialog
  764. }
  765. Connections
  766. {
  767. target: Cura.Actions.about
  768. function onTriggered() { aboutDialog.visible = true; }
  769. }
  770. Timer
  771. {
  772. id: startupTimer
  773. interval: 100
  774. repeat: false
  775. running: true
  776. onTriggered:
  777. {
  778. if (!base.visible)
  779. {
  780. base.visible = true
  781. }
  782. }
  783. }
  784. /**
  785. * Function to check whether a QML object has a certain type.
  786. * Taken from StackOverflow: https://stackoverflow.com/a/28384228 and
  787. * adapted to our code style.
  788. * Licensed under CC BY-SA 3.0.
  789. * \param obj The QtObject to get the name of.
  790. * \param class_name (str) The name of the class to check against. Has to be
  791. * the QtObject class name, not the QML entity name.
  792. */
  793. function qmlTypeOf(obj, class_name)
  794. {
  795. //className plus "(" is the class instance without modification.
  796. //className plus "_QML" is the class instance with user-defined properties.
  797. var str = obj.toString();
  798. return str.indexOf(class_name + "(") == 0 || str.indexOf(class_name + "_QML") == 0;
  799. }
  800. }