AskOpenAsProjectOrUcpOrImportModel.qml 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // Copyright (c) 2022 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.2
  4. import QtQuick.Controls 2.1
  5. import QtQuick.Layouts 1.1
  6. import UM 1.5 as UM
  7. import Cura 1.0 as Cura
  8. UM.Dialog
  9. {
  10. // This dialog asks the user whether he/she wants to open a project file as a project or import models.
  11. id: base
  12. title: catalog.i18nc("@title:window Don't translate 'Universal Cura Project'", "Open Universal Cura Project (UCP) file")
  13. width: UM.Theme.getSize("small_popup_dialog").width
  14. height: UM.Theme.getSize("small_popup_dialog").height
  15. backgroundColor: UM.Theme.getColor("main_background")
  16. maximumHeight: height
  17. maximumWidth: width
  18. minimumHeight: maximumHeight
  19. minimumWidth: maximumWidth
  20. modality: Qt.WindowModal
  21. property var fileUrl
  22. property var addToRecent: true //Whether to add this file to the recent files list after reading it.
  23. // load the project file as separated models
  24. function loadModelFiles() {
  25. CuraApplication.readLocalFile(base.fileUrl, "open_as_model", base.addToRecent)
  26. base.hide()
  27. }
  28. // load the project file as Universal cura project
  29. function loadUcpFiles() {
  30. CuraApplication.readLocalUcpFile(base.fileUrl, base.addToRecent)
  31. base.hide()
  32. }
  33. // override UM.Dialog accept
  34. function accept () {
  35. // when hitting 'enter', we always open as project unless open_as_model was explicitly stored as preference
  36. if (openAsPreference == "open_as_model") {
  37. loadModelFiles()
  38. } else{
  39. loadUcpFiles()
  40. }
  41. }
  42. Column
  43. {
  44. anchors.fill: parent
  45. spacing: UM.Theme.getSize("default_margin").height
  46. UM.Label
  47. {
  48. id: questionText
  49. width: parent.width
  50. text: catalog.i18nc("@text:window", "This is a Cura Universal project file. Would you like to open it as a Cura project or Cura Universal Project or import the models from it?")
  51. wrapMode: Text.WordWrap
  52. }
  53. }
  54. onAccepted: loadUcpFile()
  55. onRejected: loadModelFiles()
  56. buttonSpacing: UM.Theme.getSize("thin_margin").width
  57. rightButtons:
  58. [
  59. Cura.PrimaryButton
  60. {
  61. text: catalog.i18nc("@action:button", "Open as UCP")
  62. iconSource: UM.Theme.getIcon("CuraShareIcon")
  63. onClicked: loadUcpFiles()
  64. },
  65. Cura.SecondaryButton
  66. {
  67. text: catalog.i18nc("@action:button", "Import models")
  68. onClicked: loadModelFiles()
  69. }
  70. ]
  71. }