AskOpenAsProjectOrModelsDialog.qml 4.1 KB

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