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. // load the entire project
  25. function loadProjectFile() {
  26. // update preference
  27. if (rememberChoiceCheckBox.checked) {
  28. UM.Preferences.setValue("cura/choice_on_open_project", "open_as_project")
  29. }
  30. UM.WorkspaceFileHandler.readLocalFile(base.fileUrl)
  31. var meshName = backgroundItem.getMeshName(base.fileUrl.toString())
  32. backgroundItem.hasMesh(decodeURIComponent(meshName))
  33. base.hide()
  34. }
  35. // load the project file as separated models
  36. function loadModelFiles() {
  37. // update preference
  38. if (rememberChoiceCheckBox.checked) {
  39. UM.Preferences.setValue("cura/choice_on_open_project", "open_as_model")
  40. }
  41. CuraApplication.readLocalFile(base.fileUrl, true)
  42. var meshName = backgroundItem.getMeshName(base.fileUrl.toString())
  43. backgroundItem.hasMesh(decodeURIComponent(meshName))
  44. base.hide()
  45. }
  46. // override UM.Dialog accept
  47. function accept () {
  48. var openAsPreference = UM.Preferences.getValue("cura/choice_on_open_project")
  49. // when hitting 'enter', we always open as project unless open_as_model was explicitly stored as preference
  50. if (openAsPreference == "open_as_model") {
  51. loadModelFiles()
  52. } else {
  53. loadProjectFile()
  54. }
  55. }
  56. onVisibleChanged: {
  57. if (visible) {
  58. var rememberMyChoice = UM.Preferences.getValue("cura/choice_on_open_project") != "always_ask";
  59. rememberChoiceCheckBox.checked = rememberMyChoice;
  60. }
  61. }
  62. Column
  63. {
  64. anchors.fill: parent
  65. anchors.leftMargin: 20 * screenScaleFactor
  66. anchors.rightMargin: 20 * screenScaleFactor
  67. anchors.bottomMargin: 10 * screenScaleFactor
  68. spacing: 10 * screenScaleFactor
  69. Label
  70. {
  71. id: questionText
  72. 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?")
  73. anchors.left: parent.left
  74. anchors.right: parent.right
  75. font: UM.Theme.getFont("default")
  76. wrapMode: Text.WordWrap
  77. }
  78. CheckBox
  79. {
  80. id: rememberChoiceCheckBox
  81. text: catalog.i18nc("@text:window", "Remember my choice")
  82. checked: UM.Preferences.getValue("cura/choice_on_open_project") != "always_ask"
  83. style: CheckBoxStyle {
  84. label: Label {
  85. text: control.text
  86. font: UM.Theme.getFont("default")
  87. }
  88. }
  89. }
  90. // Buttons
  91. Item {
  92. id: buttonBar
  93. anchors.right: parent.right
  94. anchors.left: parent.left
  95. height: childrenRect.height
  96. Button {
  97. id: openAsProjectButton
  98. text: catalog.i18nc("@action:button", "Open as project")
  99. anchors.right: importModelsButton.left
  100. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  101. isDefault: true
  102. onClicked: loadProjectFile()
  103. }
  104. Button {
  105. id: importModelsButton
  106. text: catalog.i18nc("@action:button", "Import models")
  107. anchors.right: parent.right
  108. onClicked: loadModelFiles()
  109. }
  110. }
  111. }
  112. }