123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911 |
- import QtQuick 2.7
- import QtQuick.Controls 2.15
- import QtQuick.Dialogs 1.2
- import QtGraphicalEffects 1.0
- import UM 1.5 as UM
- import Cura 1.1 as Cura
- import "Dialogs"
- import "Menus"
- import "MainWindow"
- import "WelcomePages"
- UM.MainWindow
- {
- id: base
-
- title:
- {
- let result = "";
- if(PrintInformation !== null && PrintInformation.jobName != "")
- {
- result += PrintInformation.jobName + " - ";
- }
- result += CuraApplication.applicationDisplayName;
- return result;
- }
- backgroundColor: UM.Theme.getColor("viewport_background")
- UM.I18nCatalog
- {
- id: catalog
- name: "cura"
- }
- function showTooltip(item, position, text)
- {
- tooltip.text = text;
- position = item.mapToItem(backgroundItem, position.x - UM.Theme.getSize("default_arrow").width, position.y);
- tooltip.show(position);
- }
- function hideTooltip()
- {
- tooltip.hide();
- }
- Rectangle
- {
- id: greyOutBackground
- anchors.fill: parent
- visible: welcomeDialogItem.visible
- color: UM.Theme.getColor("window_disabled_background")
- opacity: 0.7
- z: stageMenu.z + 1
- MouseArea
- {
-
- enabled: parent.visible
- anchors.fill: parent
- hoverEnabled: true
- acceptedButtons: Qt.AllButtons
- }
- }
- WelcomeDialogItem
- {
- id: welcomeDialogItem
- visible: false
- z: greyOutBackground.z + 1
- }
- Component.onCompleted:
- {
- CuraApplication.setMinimumWindowSize(UM.Theme.getSize("window_minimum_size"))
- CuraApplication.purgeWindows()
- }
- Connections
- {
-
- target: CuraApplication
- function onShowAddPrintersUncancellableDialog()
- {
- Cura.Actions.parent = backgroundItem
-
- welcomeDialogItem.model = CuraApplication.getAddPrinterPagesModelWithoutCancel()
- welcomeDialogItem.progressBarVisible = false
- welcomeDialogItem.visible = true
- }
- }
- Connections
- {
- target: CuraApplication
- function onInitializationFinished()
- {
-
-
-
-
-
-
-
-
-
-
- Cura.Actions.parent = backgroundItem
- if (CuraApplication.shouldShowWelcomeDialog())
- {
- welcomeDialogItem.visible = true
- }
- else
- {
- welcomeDialogItem.visible = false
- }
-
- if (CuraApplication.shouldShowWhatsNewDialog())
- {
- welcomeDialogItem.model = CuraApplication.getWhatsNewPagesModel()
- welcomeDialogItem.progressBarVisible = false
- welcomeDialogItem.visible = true
- }
-
-
- if (!Cura.MachineManager.activeMachine && Cura.API.account.isLoggedIn)
- {
- welcomeDialogItem.model = CuraApplication.getAddPrinterPagesModelWithoutCancel()
- welcomeDialogItem.progressBarVisible = false
- welcomeDialogItem.visible = true
- }
- }
- }
- Item
- {
- id: backgroundItem
- anchors.fill: parent
-
- Keys.onPressed:
- {
- if (event.key == Qt.Key_Backspace)
- {
- Cura.Actions.deleteSelection.trigger()
- }
- }
- ApplicationMenu
- {
- id: applicationMenu
- }
- Item
- {
- id: headerBackground
- anchors
- {
- top: applicationMenu.bottom
- left: parent.left
- right: parent.right
- }
- height: stageMenu.source != "" ? Math.round(mainWindowHeader.height + stageMenu.height / 2) : mainWindowHeader.height
- LinearGradient
- {
- anchors.fill: parent
- start: Qt.point(0, 0)
- end: Qt.point(parent.width, 0)
- gradient: Gradient
- {
- GradientStop
- {
- position: 0.0
- color: UM.Theme.getColor("main_window_header_background")
- }
- GradientStop
- {
- position: 0.5
- color: UM.Theme.getColor("main_window_header_background_gradient")
- }
- GradientStop
- {
- position: 1.0
- color: UM.Theme.getColor("main_window_header_background")
- }
- }
- }
-
- Image
- {
- id: backgroundPattern
- anchors.fill: parent
- fillMode: Image.Tile
- source: UM.Theme.getImage("header_pattern")
- horizontalAlignment: Image.AlignLeft
- verticalAlignment: Image.AlignTop
- }
- }
- MainWindowHeader
- {
- id: mainWindowHeader
- anchors
- {
- left: parent.left
- right: parent.right
- top: applicationMenu.bottom
- }
- }
- Item
- {
- id: contentItem
- anchors
- {
- top: mainWindowHeader.bottom
- bottom: parent.bottom
- left: parent.left
- right: parent.right
- }
- Keys.forwardTo: applicationMenu
- DropArea
- {
-
- anchors.fill: parent
- onDropped:
- {
- if (drop.urls.length > 0)
- {
- var nonPackages = [];
- for (var i = 0; i < drop.urls.length; i++)
- {
- var filename = drop.urls[i];
- if (filename.toLowerCase().endsWith(".curapackage"))
- {
-
- CuraApplication.installPackageViaDragAndDrop(filename);
- packageInstallDialog.text = catalog.i18nc("@label", "This package will be installed after restarting.");
- packageInstallDialog.open();
- }
- else
- {
- nonPackages.push(filename);
- }
- }
- openDialog.handleOpenFileUrls(nonPackages);
- }
- }
- }
- ObjectSelector
- {
- id: objectSelector
- visible: CuraApplication.platformActivity
- anchors
- {
- bottom: jobSpecs.top
- left: toolbar.right
- leftMargin: UM.Theme.getSize("default_margin").width
- rightMargin: UM.Theme.getSize("default_margin").width
- bottomMargin: UM.Theme.getSize("narrow_margin").height
- }
- }
- JobSpecs
- {
- id: jobSpecs
- visible: CuraApplication.platformActivity
- anchors
- {
- left: toolbar.right
- bottom: viewOrientationControls.top
- leftMargin: UM.Theme.getSize("default_margin").width
- rightMargin: UM.Theme.getSize("default_margin").width
- bottomMargin: UM.Theme.getSize("thin_margin").width
- topMargin: UM.Theme.getSize("thin_margin").width
- }
- }
- ViewOrientationControls
- {
- id: viewOrientationControls
- anchors
- {
- left: toolbar.right
- bottom: parent.bottom
- margins: UM.Theme.getSize("default_margin").width
- }
- }
- Toolbar
- {
-
-
- id: toolbar
- property int mouseX: base.mouseX
- property int mouseY: base.mouseY
- anchors
- {
- verticalCenter: parent.verticalCenter
- left: parent.left
- }
- visible: CuraApplication.platformActivity && !PrintInformation.preSliced
- }
-
- Item {
- id: mainSafeArea
- anchors.left: viewOrientationControls.right
- anchors.right: main.right
- anchors.top: main.top
- anchors.bottom: main.bottom
- }
- Loader
- {
-
- id: main
- anchors
- {
-
- top: stageMenu.source ? stageMenu.verticalCenter : parent.top
- left: parent.left
- right: parent.right
- bottom: parent.bottom
- }
- source: UM.Controller.activeStage != null ? UM.Controller.activeStage.mainComponent : ""
- onLoaded: {
- if (main.item.safeArea !== undefined){
- main.item.safeArea = Qt.binding(function() { return mainSafeArea });
- }
- }
- }
- Loader
- {
-
-
-
- id: stageMenu
- anchors
- {
- left: parent.left
- right: parent.right
- top: parent.top
- }
- height: UM.Theme.getSize("stage_menu").height
- source: UM.Controller.activeStage != null ? UM.Controller.activeStage.stageMenuComponent : ""
-
- function onParentDestroyed()
- {
- printSetupSelector.parent = stageMenu
- printSetupSelector.visible = false
- }
- property Item oldParent: null
-
-
- property var printSetupSelector: Cura.PrintSetupSelector
- {
- width: UM.Theme.getSize("print_setup_widget").width
- height: UM.Theme.getSize("stage_menu").height
- headerCornerSide: RoundedRectangle.Direction.Right
- onParentChanged:
- {
- if(stageMenu.oldParent !=null)
- {
- stageMenu.oldParent.Component.destruction.disconnect(stageMenu.onParentDestroyed)
- }
- stageMenu.oldParent = parent
- visible = parent != stageMenu
- parent.Component.destruction.connect(stageMenu.onParentDestroyed)
- }
- }
- }
- UM.MessageStack
- {
- anchors
- {
- horizontalCenter: parent.horizontalCenter
- top: parent.verticalCenter
- bottom: parent.bottom
- bottomMargin: UM.Theme.getSize("default_margin").height
- }
- primaryButton: Component
- {
- Cura.PrimaryButton
- {
- text: model.name
- iconSource: UM.Theme.getIcon(model.icon)
- height: UM.Theme.getSize("message_action_button").height
- }
- }
- secondaryButton: Component
- {
- Cura.SecondaryButton
- {
- text: model.name
- iconSource: UM.Theme.getIcon(model.icon)
- height: UM.Theme.getSize("message_action_button").height
- }
- }
- link: Component
- {
- Cura.TertiaryButton
- {
- text: model.name
- iconSource:
- {
- if (model.icon == null || model.icon == "")
- {
- return UM.Theme.getIcon("LinkExternal")
- }
- return UM.Theme.getIcon(model.icon)
- }
- height: UM.Theme.getSize("message_action_button").height
- }
- }
- }
- }
- PrintSetupTooltip
- {
- id: tooltip
- sourceWidth: UM.Theme.getSize("print_setup_widget").width
- }
- }
- UM.PreferencesDialog
- {
- id: preferences
- Component.onCompleted:
- {
-
- removePage(0);
- insertPage(0, catalog.i18nc("@title:tab","General"), Qt.resolvedUrl("Preferences/GeneralPage.qml"));
- removePage(1);
- insertPage(1, catalog.i18nc("@title:tab","Settings"), Qt.resolvedUrl("Preferences/SettingVisibilityPage.qml"));
- insertPage(2, catalog.i18nc("@title:tab", "Printers"), Qt.resolvedUrl("Preferences/MachinesPage.qml"));
- insertPage(3, catalog.i18nc("@title:tab", "Materials"), Qt.resolvedUrl("Preferences/Materials/MaterialsPage.qml"));
- insertPage(4, catalog.i18nc("@title:tab", "Profiles"), Qt.resolvedUrl("Preferences/ProfilesPage.qml"));
- currentPage = 0;
- }
- onVisibleChanged:
- {
-
-
- setPage(0);
- }
- }
- Connections
- {
- target: Cura.Actions.preferences
- function onTriggered() { preferences.visible = true }
- }
- Connections
- {
- target: CuraApplication
- function onShowPreferencesWindow() { preferences.visible = true }
- }
- Connections
- {
- target: Cura.Actions.addProfile
- function onTriggered()
- {
- preferences.show();
- preferences.setPage(4);
-
- createProfileTimer.start();
- }
- }
- Connections
- {
- target: Cura.Actions.configureMachines
- function onTriggered()
- {
- preferences.visible = true;
- preferences.setPage(2);
- }
- }
- Connections
- {
- target: Cura.Actions.manageProfiles
- function onTriggered()
- {
- preferences.visible = true;
- preferences.setPage(4);
- }
- }
- Connections
- {
- target: Cura.Actions.manageMaterials
- function onTriggered()
- {
- preferences.visible = true;
- preferences.setPage(3)
- }
- }
- Connections
- {
- target: Cura.Actions.configureSettingVisibility
- function onTriggered(source)
- {
- preferences.visible = true;
- preferences.setPage(1);
- if(source && source.key)
- {
- preferences.getCurrentItem().scrollToSection(source.key);
- }
- }
- }
- Timer
- {
- id: createProfileTimer
- repeat: false
- interval: 1
- onTriggered: preferences.getCurrentItem().createProfile()
- }
-
-
- Connections
- {
- target: Cura.MachineManager
- function onBlurSettings()
- {
- contentItem.forceActiveFocus()
- }
- }
- ContextMenu
- {
- id: contextMenu
- }
- onPreClosing:
- {
- close.accepted = CuraApplication.getIsAllChecksPassed();
- if (!close.accepted)
- {
- CuraApplication.checkAndExitApplication();
- }
- }
- Cura.MessageDialog
- {
- id: exitConfirmationDialog
- title: catalog.i18nc("@title:window %1 is the application name", "Closing %1").arg(CuraApplication.applicationDisplayName)
- text: catalog.i18nc("@label %1 is the application name", "Are you sure you want to exit %1?").arg(CuraApplication.applicationDisplayName)
- standardButtons: Dialog.Yes | Dialog.No
- onAccepted: CuraApplication.callConfirmExitDialogCallback(true)
- onRejected: CuraApplication.callConfirmExitDialogCallback(false)
- onClosed:
- {
- if (!visible)
- {
-
- text = catalog.i18nc("@label %1 is the application name", "Are you sure you want to exit %1?").arg(CuraApplication.applicationDisplayName);
- }
- }
- }
- Connections
- {
- target: CuraApplication
- function onShowConfirmExitDialog(message)
- {
- exitConfirmationDialog.text = message;
- exitConfirmationDialog.open();
- }
- }
- Connections
- {
- target: Cura.Actions.quit
- function onTriggered() { CuraApplication.checkAndExitApplication(); }
- }
- Connections
- {
- target: Cura.Actions.toggleFullScreen
- function onTriggered() { base.toggleFullscreen() }
- }
- Connections
- {
- target: Cura.Actions.exitFullScreen
- function onTriggered() { base.exitFullscreen() }
- }
- FileDialog
- {
- id: openDialog;
-
- title: catalog.i18nc("@title:window","Open file(s)")
- modality: Qt.WindowModal
- selectMultiple: true
- nameFilters: UM.MeshFileHandler.supportedReadFileTypes;
- folder:
- {
-
- folder = CuraApplication.getDefaultPath("dialog_load_path");
- return CuraApplication.getDefaultPath("dialog_load_path");
- }
- onAccepted:
- {
-
-
- var f = folder;
- folder = f;
- CuraApplication.setDefaultPath("dialog_load_path", folder);
- handleOpenFileUrls(fileUrls);
- }
-
-
-
-
- function handleOpenFileUrls(fileUrlList)
- {
-
- var projectFileUrlList = [];
- var hasGcode = false;
- var nonGcodeFileList = [];
- for (var i in fileUrlList)
- {
- var endsWithG = /\.g$/;
- var endsWithGcode = /\.gcode$/;
- if (endsWithG.test(fileUrlList[i]) || endsWithGcode.test(fileUrlList[i]))
- {
- continue;
- }
- else if (CuraApplication.checkIsValidProjectFile(fileUrlList[i]))
- {
- projectFileUrlList.push(fileUrlList[i]);
- }
- nonGcodeFileList.push(fileUrlList[i]);
- }
- hasGcode = nonGcodeFileList.length < fileUrlList.length;
-
- var hasProjectFile = projectFileUrlList.length > 0;
- var selectedMultipleFiles = fileUrlList.length > 1;
- if (selectedMultipleFiles && hasGcode)
- {
- infoMultipleFilesWithGcodeDialog.selectedMultipleFiles = selectedMultipleFiles;
- infoMultipleFilesWithGcodeDialog.hasProjectFile = hasProjectFile;
- infoMultipleFilesWithGcodeDialog.fileUrls = nonGcodeFileList.slice();
- infoMultipleFilesWithGcodeDialog.projectFileUrlList = projectFileUrlList.slice();
- infoMultipleFilesWithGcodeDialog.open();
- }
- else
- {
- handleOpenFiles(selectedMultipleFiles, hasProjectFile, fileUrlList, projectFileUrlList);
- }
- }
- function handleOpenFiles(selectedMultipleFiles, hasProjectFile, fileUrlList, projectFileUrlList)
- {
-
- openFilesIncludingProjectsDialog.addToRecent = true;
-
- if (selectedMultipleFiles && hasProjectFile)
- {
- openFilesIncludingProjectsDialog.fileUrls = fileUrlList.slice();
- openFilesIncludingProjectsDialog.show();
- return;
- }
- if (hasProjectFile)
- {
- var projectFile = projectFileUrlList[0];
-
- var choice = UM.Preferences.getValue("cura/choice_on_open_project");
- if (choice == "open_as_project")
- {
- openFilesIncludingProjectsDialog.loadProjectFile(projectFile);
- }
- else if (choice == "open_as_model")
- {
- openFilesIncludingProjectsDialog.loadModelFiles([projectFile].slice());
- }
- else
- {
-
- askOpenAsProjectOrModelsDialog.fileUrl = projectFile;
- askOpenAsProjectOrModelsDialog.addToRecent = true;
- askOpenAsProjectOrModelsDialog.show();
- }
- }
- else
- {
- openFilesIncludingProjectsDialog.loadModelFiles(fileUrlList.slice());
- }
- }
- }
- Cura.MessageDialog
- {
- id: packageInstallDialog
- title: catalog.i18nc("@window:title", "Install Package")
- standardButtons: StandardButton.Ok
- }
- Cura.MessageDialog
- {
- id: infoMultipleFilesWithGcodeDialog
- title: catalog.i18nc("@title:window", "Open File(s)")
- standardButtons: Dialog.Ok
- 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.")
- property var selectedMultipleFiles
- property var hasProjectFile
- property var fileUrls
- property var projectFileUrlList
- onAccepted:
- {
- openDialog.handleOpenFiles(selectedMultipleFiles, hasProjectFile, fileUrls, projectFileUrlList);
- }
- }
- Connections
- {
- target: Cura.Actions.open
- function onTriggered() { openDialog.open() }
- }
- OpenFilesIncludingProjectsDialog
- {
- id: openFilesIncludingProjectsDialog
- }
- AskOpenAsProjectOrModelsDialog
- {
- id: askOpenAsProjectOrModelsDialog
- }
- Connections
- {
- target: CuraApplication
- function onOpenProjectFile(project_file, add_to_recent_files)
- {
- askOpenAsProjectOrModelsDialog.fileUrl = project_file;
- askOpenAsProjectOrModelsDialog.addToRecent = add_to_recent_files;
- askOpenAsProjectOrModelsDialog.show();
- }
- }
- Connections
- {
- target: Cura.Actions.showProfileFolder
- function onTriggered()
- {
- var path = UM.Resources.getPath(UM.Resources.Preferences, "");
- if(Qt.platform.os == "windows")
- {
- path = path.replace(/\\/g,"/");
- }
- Qt.openUrlExternally(path);
- if(Qt.platform.os == "linux")
- {
- Qt.openUrlExternally(UM.Resources.getPath(UM.Resources.Resources, ""));
- }
- }
- }
- Component
- {
- id: discardOrKeepProfileChangesDialogComponent
- DiscardOrKeepProfileChangesDialog { }
- }
- Loader
- {
- id: discardOrKeepProfileChangesDialogLoader
- }
- Connections
- {
- target: CuraApplication
- function onShowDiscardOrKeepProfileChanges()
- {
- discardOrKeepProfileChangesDialogLoader.sourceComponent = discardOrKeepProfileChangesDialogComponent
- discardOrKeepProfileChangesDialogLoader.item.show()
- }
- }
- Cura.WizardDialog
- {
- id: addMachineDialog
- title: catalog.i18nc("@title:window", "Add Printer")
- model: CuraApplication.getAddPrinterPagesModel()
- progressBarVisible: false
- }
- Cura.WizardDialog
- {
- id: whatsNewDialog
- title: catalog.i18nc("@title:window", "What's New")
- minimumWidth: UM.Theme.getSize("welcome_wizard_window").width
- minimumHeight: UM.Theme.getSize("welcome_wizard_window").height
- model: CuraApplication.getWhatsNewPagesModel()
- progressBarVisible: false
- visible: false
- }
- Connections
- {
- target: Cura.Actions.whatsNew
- function onTriggered() { whatsNewDialog.show() }
- }
- Connections
- {
- target: Cura.Actions.addMachine
- function onTriggered()
- {
-
- addMachineDialog.resetModelState()
- addMachineDialog.show()
- }
- }
- AboutDialog
- {
- id: aboutDialog
- }
- Connections
- {
- target: Cura.Actions.about
- function onTriggered() { aboutDialog.visible = true; }
- }
- Timer
- {
- id: startupTimer
- interval: 100
- repeat: false
- running: true
- onTriggered:
- {
- if (!base.visible)
- {
- base.visible = true
- }
- }
- }
-
- function qmlTypeOf(obj, class_name)
- {
-
-
- var str = obj.toString();
- return str.indexOf(class_name + "(") == 0 || str.indexOf(class_name + "_QML") == 0;
- }
- }
|