Cura.qml 26 KB

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