AskOpenAsProjectOrModelsDialog.qml 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. // Copyright (c) 2015 Ultimaker B.V.
  2. // Cura is released under the terms of the AGPLv3 or higher.
  3. import QtQuick 2.2
  4. import QtQuick.Controls 1.1
  5. import QtQuick.Controls.Styles 1.1
  6. import QtQuick.Layouts 1.1
  7. import QtQuick.Dialogs 1.1
  8. import UM 1.3 as UM
  9. import Cura 1.0 as Cura
  10. UM.Dialog
  11. {
  12. // This dialog asks the user whether he/she wants to open a project file as a project or import models.
  13. id: base
  14. title: catalog.i18nc("@title:window", "Open project file")
  15. width: 420
  16. height: 140
  17. maximumHeight: height
  18. maximumWidth: width
  19. minimumHeight: height
  20. minimumWidth: width
  21. modality: UM.Application.platform == "linux" ? Qt.NonModal : Qt.WindowModal;
  22. property var fileUrl
  23. function loadProjectFile(projectFile)
  24. {
  25. UM.WorkspaceFileHandler.readLocalFile(projectFile);
  26. var meshName = backgroundItem.getMeshName(projectFile.toString());
  27. backgroundItem.hasMesh(decodeURIComponent(meshName));
  28. }
  29. function loadModelFiles(fileUrls)
  30. {
  31. for (var i in fileUrls)
  32. Printer.readLocalFile(fileUrls[i]);
  33. var meshName = backgroundItem.getMeshName(fileUrls[0].toString());
  34. backgroundItem.hasMesh(decodeURIComponent(meshName));
  35. }
  36. onVisibleChanged:
  37. {
  38. if (visible)
  39. {
  40. var rememberMyChoice = UM.Preferences.getValue("cura/choice_on_open_project") != "always_ask";
  41. rememberChoiceCheckBox.checked = rememberMyChoice;
  42. }
  43. }
  44. Column
  45. {
  46. anchors.fill: parent
  47. anchors.margins: UM.Theme.getSize("default_margin").width
  48. anchors.left: parent.left
  49. anchors.right: parent.right
  50. spacing: UM.Theme.getSize("default_margin").width
  51. Label
  52. {
  53. text: catalog.i18nc("@text:window", "This is a Cura project file. Would you like to open it as a project\nor import the models from it?")
  54. anchors.margins: UM.Theme.getSize("default_margin").width
  55. wrapMode: Text.WordWrap
  56. }
  57. CheckBox
  58. {
  59. id: rememberChoiceCheckBox
  60. text: catalog.i18nc("@text:window", "Remember my choice")
  61. anchors.margins: UM.Theme.getSize("default_margin").width
  62. checked: UM.Preferences.getValue("cura/choice_on_open_project") != "always_ask"
  63. }
  64. // Buttons
  65. Item
  66. {
  67. anchors.right: parent.right
  68. anchors.left: parent.left
  69. height: childrenRect.height
  70. Button
  71. {
  72. id: openAsProjectButton
  73. text: catalog.i18nc("@action:button", "Open as project");
  74. anchors.right: importModelsButton.left
  75. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  76. isDefault: true
  77. onClicked:
  78. {
  79. // update preference
  80. if (rememberChoiceCheckBox.checked)
  81. UM.Preferences.setValue("cura/choice_on_open_project", "open_as_project");
  82. // load this file as project
  83. base.hide();
  84. loadProjectFile(base.fileUrl);
  85. }
  86. }
  87. Button
  88. {
  89. id: importModelsButton
  90. text: catalog.i18nc("@action:button", "Import models");
  91. anchors.right: parent.right
  92. onClicked:
  93. {
  94. // update preference
  95. if (rememberChoiceCheckBox.checked)
  96. UM.Preferences.setValue("cura/choice_on_open_project", "open_as_model");
  97. // load models from this project file
  98. base.hide();
  99. loadModelFiles([base.fileUrl]);
  100. }
  101. }
  102. }
  103. }
  104. }