Cura.qml 29 KB

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