Cura.qml 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883
  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. ObjectsList
  186. {
  187. id: objectsList
  188. visible: UM.Preferences.getValue("cura/use_multi_build_plate")
  189. anchors
  190. {
  191. bottom: viewOrientationControls.top
  192. left: toolbar.right
  193. margins: UM.Theme.getSize("default_margin").width
  194. }
  195. }
  196. JobSpecs
  197. {
  198. id: jobSpecs
  199. visible: CuraApplication.platformActivity
  200. anchors
  201. {
  202. left: parent.left
  203. bottom: viewOrientationControls.top
  204. margins: UM.Theme.getSize("default_margin").width
  205. bottomMargin: UM.Theme.getSize("thin_margin").width
  206. }
  207. }
  208. ViewOrientationControls
  209. {
  210. id: viewOrientationControls
  211. anchors
  212. {
  213. left: parent.left
  214. bottom: parent.bottom
  215. margins: UM.Theme.getSize("default_margin").width
  216. }
  217. }
  218. Cura.ActionPanelWidget
  219. {
  220. id: actionPanelWidget
  221. anchors.right: parent.right
  222. anchors.bottom: parent.bottom
  223. anchors.rightMargin: UM.Theme.getSize("thick_margin").width
  224. anchors.bottomMargin: UM.Theme.getSize("thick_margin").height
  225. /*
  226. Show this panel only if there is something on the build plate, and there is NOT an opaque item in front of the build plate.
  227. This cannot be solved by Z indexing! If you want to try solving this, please increase this counter when you're done:
  228. Number of people having tried to fix this by z-indexing: 2
  229. The problem arises from the following render order requirements:
  230. - The stage menu must be rendered above the stage main.
  231. - The stage main must be rendered above the action panel (because the monitor page must be rendered above the action panel).
  232. - The action panel must be rendered above the expandable components drop-down.
  233. However since the expandable components drop-downs are child elements of the stage menu,
  234. they can't be rendered lower than elements that are lower than the stage menu.
  235. Therefore we opted to forego the second requirement and hide the action panel instead when something obscures it (except the expandable components).
  236. We assume that QQuickRectangles are always opaque and any other item is not.
  237. */
  238. visible: CuraApplication.platformActivity && (main.item == null || !qmlTypeOf(main.item, "QQuickRectangle"))
  239. }
  240. Item
  241. {
  242. id: additionalComponents
  243. width: childrenRect.width
  244. anchors.right: actionPanelWidget.left
  245. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  246. anchors.bottom: actionPanelWidget.bottom
  247. anchors.bottomMargin: UM.Theme.getSize("thick_margin").height * 2
  248. visible: actionPanelWidget.visible
  249. Row
  250. {
  251. id: additionalComponentsRow
  252. anchors.verticalCenter: parent.verticalCenter
  253. spacing: UM.Theme.getSize("default_margin").width
  254. }
  255. }
  256. Component.onCompleted: contentItem.addAdditionalComponents()
  257. Connections
  258. {
  259. target: CuraApplication
  260. onAdditionalComponentsChanged: contentItem.addAdditionalComponents("saveButton")
  261. }
  262. function addAdditionalComponents()
  263. {
  264. for (var component in CuraApplication.additionalComponents["saveButton"])
  265. {
  266. CuraApplication.additionalComponents["saveButton"][component].parent = additionalComponentsRow
  267. }
  268. }
  269. Loader
  270. {
  271. // A stage can control this area. If nothing is set, it will therefore show the 3D view.
  272. id: main
  273. anchors
  274. {
  275. // Align to the top of the stageMenu since the stageMenu may not exist
  276. top: stageMenu.source ? stageMenu.verticalCenter : parent.top
  277. left: parent.left
  278. right: parent.right
  279. bottom: parent.bottom
  280. }
  281. source: UM.Controller.activeStage != null ? UM.Controller.activeStage.mainComponent : ""
  282. }
  283. Loader
  284. {
  285. // The stage menu is, as the name implies, a menu that is defined by the active stage.
  286. // Note that this menu does not need to be set at all! It's perfectly acceptable to have a stage
  287. // without this menu!
  288. id: stageMenu
  289. anchors
  290. {
  291. left: parent.left
  292. right: parent.right
  293. top: parent.top
  294. }
  295. height: UM.Theme.getSize("stage_menu").height
  296. source: UM.Controller.activeStage != null ? UM.Controller.activeStage.stageMenuComponent : ""
  297. // HACK: This is to ensure that the parent never gets set to null, as this wreaks havoc on the focus.
  298. function onParentDestroyed()
  299. {
  300. printSetupSelector.parent = stageMenu
  301. printSetupSelector.visible = false
  302. }
  303. property Item oldParent: null
  304. // The printSetupSelector is defined here so that the setting list doesn't need to get re-instantiated
  305. // Every time the stage is changed.
  306. property var printSetupSelector: Cura.PrintSetupSelector
  307. {
  308. width: UM.Theme.getSize("print_setup_widget").width
  309. height: UM.Theme.getSize("stage_menu").height
  310. headerCornerSide: RoundedRectangle.Direction.Right
  311. onParentChanged:
  312. {
  313. if(stageMenu.oldParent !=null)
  314. {
  315. stageMenu.oldParent.Component.destruction.disconnect(stageMenu.onParentDestroyed)
  316. }
  317. stageMenu.oldParent = parent
  318. visible = parent != stageMenu
  319. parent.Component.destruction.connect(stageMenu.onParentDestroyed)
  320. }
  321. }
  322. }
  323. UM.MessageStack
  324. {
  325. anchors
  326. {
  327. horizontalCenter: parent.horizontalCenter
  328. top: parent.verticalCenter
  329. bottom: parent.bottom
  330. bottomMargin: UM.Theme.getSize("default_margin").height
  331. }
  332. }
  333. }
  334. PrintSetupTooltip
  335. {
  336. id: tooltip
  337. }
  338. }
  339. UM.PreferencesDialog
  340. {
  341. id: preferences
  342. Component.onCompleted:
  343. {
  344. //; Remove & re-add the general page as we want to use our own instead of uranium standard.
  345. removePage(0);
  346. insertPage(0, catalog.i18nc("@title:tab","General"), Qt.resolvedUrl("Preferences/GeneralPage.qml"));
  347. removePage(1);
  348. insertPage(1, catalog.i18nc("@title:tab","Settings"), Qt.resolvedUrl("Preferences/SettingVisibilityPage.qml"));
  349. insertPage(2, catalog.i18nc("@title:tab", "Printers"), Qt.resolvedUrl("Preferences/MachinesPage.qml"));
  350. insertPage(3, catalog.i18nc("@title:tab", "Materials"), Qt.resolvedUrl("Preferences/Materials/MaterialsPage.qml"));
  351. insertPage(4, catalog.i18nc("@title:tab", "Profiles"), Qt.resolvedUrl("Preferences/ProfilesPage.qml"));
  352. //Force refresh
  353. setPage(0);
  354. }
  355. onVisibleChanged:
  356. {
  357. // When the dialog closes, switch to the General page.
  358. // This prevents us from having a heavy page like Setting Visiblity active in the background.
  359. setPage(0);
  360. }
  361. }
  362. Connections
  363. {
  364. target: Cura.Actions.preferences
  365. onTriggered: preferences.visible = true
  366. }
  367. Connections
  368. {
  369. target: CuraApplication
  370. onShowPreferencesWindow: preferences.visible = true
  371. }
  372. Connections
  373. {
  374. target: Cura.Actions.addProfile
  375. onTriggered:
  376. {
  377. preferences.show();
  378. preferences.setPage(4);
  379. // Create a new profile after a very short delay so the preference page has time to initiate
  380. createProfileTimer.start();
  381. }
  382. }
  383. Connections
  384. {
  385. target: Cura.Actions.configureMachines
  386. onTriggered:
  387. {
  388. preferences.visible = true;
  389. preferences.setPage(2);
  390. }
  391. }
  392. Connections
  393. {
  394. target: Cura.Actions.manageProfiles
  395. onTriggered:
  396. {
  397. preferences.visible = true;
  398. preferences.setPage(4);
  399. }
  400. }
  401. Connections
  402. {
  403. target: Cura.Actions.manageMaterials
  404. onTriggered:
  405. {
  406. preferences.visible = true;
  407. preferences.setPage(3)
  408. }
  409. }
  410. Connections
  411. {
  412. target: Cura.Actions.configureSettingVisibility
  413. onTriggered:
  414. {
  415. preferences.visible = true;
  416. preferences.setPage(1);
  417. if(source && source.key)
  418. {
  419. preferences.getCurrentItem().scrollToSection(source.key);
  420. }
  421. }
  422. }
  423. Timer
  424. {
  425. id: createProfileTimer
  426. repeat: false
  427. interval: 1
  428. onTriggered: preferences.getCurrentItem().createProfile()
  429. }
  430. // BlurSettings is a way to force the focus away from any of the setting items.
  431. // We need to do this in order to keep the bindings intact.
  432. Connections
  433. {
  434. target: Cura.MachineManager
  435. onBlurSettings:
  436. {
  437. contentItem.forceActiveFocus()
  438. }
  439. }
  440. ContextMenu
  441. {
  442. id: contextMenu
  443. }
  444. onPreClosing:
  445. {
  446. close.accepted = CuraApplication.getIsAllChecksPassed();
  447. if (!close.accepted)
  448. {
  449. CuraApplication.checkAndExitApplication();
  450. }
  451. }
  452. MessageDialog
  453. {
  454. id: exitConfirmationDialog
  455. title: catalog.i18nc("@title:window", "Closing Cura")
  456. text: catalog.i18nc("@label", "Are you sure you want to exit Cura?")
  457. icon: StandardIcon.Question
  458. modality: Qt.ApplicationModal
  459. standardButtons: StandardButton.Yes | StandardButton.No
  460. onYes: CuraApplication.callConfirmExitDialogCallback(true)
  461. onNo: CuraApplication.callConfirmExitDialogCallback(false)
  462. onRejected: CuraApplication.callConfirmExitDialogCallback(false)
  463. onVisibilityChanged:
  464. {
  465. if (!visible)
  466. {
  467. // reset the text to default because other modules may change the message text.
  468. text = catalog.i18nc("@label", "Are you sure you want to exit Cura?");
  469. }
  470. }
  471. }
  472. Connections
  473. {
  474. target: CuraApplication
  475. onShowConfirmExitDialog:
  476. {
  477. exitConfirmationDialog.text = message;
  478. exitConfirmationDialog.open();
  479. }
  480. }
  481. Connections
  482. {
  483. target: Cura.Actions.quit
  484. onTriggered: CuraApplication.checkAndExitApplication();
  485. }
  486. Connections
  487. {
  488. target: Cura.Actions.toggleFullScreen
  489. onTriggered: base.toggleFullscreen();
  490. }
  491. FileDialog
  492. {
  493. id: openDialog;
  494. //: File open dialog title
  495. title: catalog.i18nc("@title:window","Open file(s)")
  496. modality: UM.Application.platform == "linux" ? Qt.NonModal : Qt.WindowModal;
  497. selectMultiple: true
  498. nameFilters: UM.MeshFileHandler.supportedReadFileTypes;
  499. folder: CuraApplication.getDefaultPath("dialog_load_path")
  500. onAccepted:
  501. {
  502. // Because several implementations of the file dialog only update the folder
  503. // when it is explicitly set.
  504. var f = folder;
  505. folder = f;
  506. CuraApplication.setDefaultPath("dialog_load_path", folder);
  507. handleOpenFileUrls(fileUrls);
  508. }
  509. // Yeah... I know... it is a mess to put all those things here.
  510. // There are lots of user interactions in this part of the logic, such as showing a warning dialog here and there,
  511. // etc. This means it will come back and forth from time to time between QML and Python. So, separating the logic
  512. // and view here may require more effort but make things more difficult to understand.
  513. function handleOpenFileUrls(fileUrlList)
  514. {
  515. // look for valid project files
  516. var projectFileUrlList = [];
  517. var hasGcode = false;
  518. var nonGcodeFileList = [];
  519. for (var i in fileUrlList)
  520. {
  521. var endsWithG = /\.g$/;
  522. var endsWithGcode = /\.gcode$/;
  523. if (endsWithG.test(fileUrlList[i]) || endsWithGcode.test(fileUrlList[i]))
  524. {
  525. continue;
  526. }
  527. else if (CuraApplication.checkIsValidProjectFile(fileUrlList[i]))
  528. {
  529. projectFileUrlList.push(fileUrlList[i]);
  530. }
  531. nonGcodeFileList.push(fileUrlList[i]);
  532. }
  533. hasGcode = nonGcodeFileList.length < fileUrlList.length;
  534. // show a warning if selected multiple files together with Gcode
  535. var hasProjectFile = projectFileUrlList.length > 0;
  536. var selectedMultipleFiles = fileUrlList.length > 1;
  537. if (selectedMultipleFiles && hasGcode)
  538. {
  539. infoMultipleFilesWithGcodeDialog.selectedMultipleFiles = selectedMultipleFiles;
  540. infoMultipleFilesWithGcodeDialog.hasProjectFile = hasProjectFile;
  541. infoMultipleFilesWithGcodeDialog.fileUrls = nonGcodeFileList.slice();
  542. infoMultipleFilesWithGcodeDialog.projectFileUrlList = projectFileUrlList.slice();
  543. infoMultipleFilesWithGcodeDialog.open();
  544. }
  545. else
  546. {
  547. handleOpenFiles(selectedMultipleFiles, hasProjectFile, fileUrlList, projectFileUrlList);
  548. }
  549. }
  550. function handleOpenFiles(selectedMultipleFiles, hasProjectFile, fileUrlList, projectFileUrlList)
  551. {
  552. // we only allow opening one project file
  553. if (selectedMultipleFiles && hasProjectFile)
  554. {
  555. openFilesIncludingProjectsDialog.fileUrls = fileUrlList.slice();
  556. openFilesIncludingProjectsDialog.show();
  557. return;
  558. }
  559. if (hasProjectFile)
  560. {
  561. var projectFile = projectFileUrlList[0];
  562. // check preference
  563. var choice = UM.Preferences.getValue("cura/choice_on_open_project");
  564. if (choice == "open_as_project")
  565. {
  566. openFilesIncludingProjectsDialog.loadProjectFile(projectFile);
  567. }
  568. else if (choice == "open_as_model")
  569. {
  570. openFilesIncludingProjectsDialog.loadModelFiles([projectFile].slice());
  571. }
  572. else // always ask
  573. {
  574. // ask whether to open as project or as models
  575. askOpenAsProjectOrModelsDialog.fileUrl = projectFile;
  576. askOpenAsProjectOrModelsDialog.show();
  577. }
  578. }
  579. else
  580. {
  581. openFilesIncludingProjectsDialog.loadModelFiles(fileUrlList.slice());
  582. }
  583. }
  584. }
  585. MessageDialog
  586. {
  587. id: packageInstallDialog
  588. title: catalog.i18nc("@window:title", "Install Package");
  589. standardButtons: StandardButton.Ok
  590. modality: Qt.ApplicationModal
  591. }
  592. MessageDialog
  593. {
  594. id: infoMultipleFilesWithGcodeDialog
  595. title: catalog.i18nc("@title:window", "Open File(s)")
  596. icon: StandardIcon.Information
  597. standardButtons: StandardButton.Ok
  598. 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.")
  599. property var selectedMultipleFiles
  600. property var hasProjectFile
  601. property var fileUrls
  602. property var projectFileUrlList
  603. onAccepted:
  604. {
  605. openDialog.handleOpenFiles(selectedMultipleFiles, hasProjectFile, fileUrls, projectFileUrlList);
  606. }
  607. }
  608. Connections
  609. {
  610. target: Cura.Actions.open
  611. onTriggered: openDialog.open()
  612. }
  613. OpenFilesIncludingProjectsDialog
  614. {
  615. id: openFilesIncludingProjectsDialog
  616. }
  617. AskOpenAsProjectOrModelsDialog
  618. {
  619. id: askOpenAsProjectOrModelsDialog
  620. }
  621. Connections
  622. {
  623. target: CuraApplication
  624. onOpenProjectFile:
  625. {
  626. askOpenAsProjectOrModelsDialog.fileUrl = project_file;
  627. askOpenAsProjectOrModelsDialog.show();
  628. }
  629. }
  630. Connections
  631. {
  632. target: Cura.Actions.showProfileFolder
  633. onTriggered:
  634. {
  635. var path = UM.Resources.getPath(UM.Resources.Preferences, "");
  636. if(Qt.platform.os == "windows") {
  637. path = path.replace(/\\/g,"/");
  638. }
  639. Qt.openUrlExternally(path);
  640. if(Qt.platform.os == "linux") {
  641. Qt.openUrlExternally(UM.Resources.getPath(UM.Resources.Resources, ""));
  642. }
  643. }
  644. }
  645. AddMachineDialog
  646. {
  647. id: addMachineDialog
  648. onMachineAdded:
  649. {
  650. machineActionsWizard.firstRun = addMachineDialog.firstRun
  651. machineActionsWizard.start(id)
  652. }
  653. }
  654. // Dialog to handle first run machine actions
  655. UM.Wizard
  656. {
  657. id: machineActionsWizard;
  658. title: catalog.i18nc("@title:window", "Add Printer")
  659. property var machine;
  660. function start(id)
  661. {
  662. var actions = Cura.MachineActionManager.getFirstStartActions(id)
  663. resetPages() // Remove previous pages
  664. for (var i = 0; i < actions.length; i++)
  665. {
  666. actions[i].displayItem.reset()
  667. machineActionsWizard.appendPage(actions[i].displayItem, catalog.i18nc("@title", actions[i].label));
  668. }
  669. //Only start if there are actions to perform.
  670. if (actions.length > 0)
  671. {
  672. machineActionsWizard.currentPage = 0;
  673. show()
  674. }
  675. }
  676. }
  677. MessageDialog
  678. {
  679. id: messageDialog
  680. modality: Qt.ApplicationModal
  681. onAccepted: CuraApplication.messageBoxClosed(clickedButton)
  682. onApply: CuraApplication.messageBoxClosed(clickedButton)
  683. onDiscard: CuraApplication.messageBoxClosed(clickedButton)
  684. onHelp: CuraApplication.messageBoxClosed(clickedButton)
  685. onNo: CuraApplication.messageBoxClosed(clickedButton)
  686. onRejected: CuraApplication.messageBoxClosed(clickedButton)
  687. onReset: CuraApplication.messageBoxClosed(clickedButton)
  688. onYes: CuraApplication.messageBoxClosed(clickedButton)
  689. }
  690. Connections
  691. {
  692. target: CuraApplication
  693. onShowMessageBox:
  694. {
  695. messageDialog.title = title
  696. messageDialog.text = text
  697. messageDialog.informativeText = informativeText
  698. messageDialog.detailedText = detailedText
  699. messageDialog.standardButtons = buttons
  700. messageDialog.icon = icon
  701. messageDialog.visible = true
  702. }
  703. }
  704. DiscardOrKeepProfileChangesDialog
  705. {
  706. id: discardOrKeepProfileChangesDialog
  707. }
  708. Connections
  709. {
  710. target: CuraApplication
  711. onShowDiscardOrKeepProfileChanges:
  712. {
  713. discardOrKeepProfileChangesDialog.show()
  714. }
  715. }
  716. Connections
  717. {
  718. target: Cura.Actions.addMachine
  719. onTriggered: addMachineDialog.visible = true;
  720. }
  721. AboutDialog
  722. {
  723. id: aboutDialog
  724. }
  725. Connections
  726. {
  727. target: Cura.Actions.about
  728. onTriggered: aboutDialog.visible = true;
  729. }
  730. Connections
  731. {
  732. target: CuraApplication
  733. onRequestAddPrinter:
  734. {
  735. addMachineDialog.visible = true
  736. addMachineDialog.firstRun = false
  737. }
  738. }
  739. Timer
  740. {
  741. id: startupTimer;
  742. interval: 100;
  743. repeat: false;
  744. running: true;
  745. onTriggered:
  746. {
  747. if(!base.visible)
  748. {
  749. base.visible = true;
  750. }
  751. // check later if the user agreement dialog has been closed
  752. if (CuraApplication.needToShowUserAgreement)
  753. {
  754. restart();
  755. }
  756. else if(Cura.MachineManager.activeMachine == null)
  757. {
  758. addMachineDialog.open();
  759. }
  760. }
  761. }
  762. /**
  763. * Function to check whether a QML object has a certain type.
  764. * Taken from StackOverflow: https://stackoverflow.com/a/28384228 and
  765. * adapted to our code style.
  766. * Licensed under CC BY-SA 3.0.
  767. * \param obj The QtObject to get the name of.
  768. * \param class_name (str) The name of the class to check against. Has to be
  769. * the QtObject class name, not the QML entity name.
  770. */
  771. function qmlTypeOf(obj, class_name)
  772. {
  773. //className plus "(" is the class instance without modification.
  774. //className plus "_QML" is the class instance with user-defined properties.
  775. var str = obj.toString();
  776. return str.indexOf(class_name + "(") == 0 || str.indexOf(class_name + "_QML") == 0;
  777. }
  778. }