DraftMode.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /**
  2. * Copyright (c) 2011-2018 by Andrew Mustun. All rights reserved.
  3. *
  4. * This file is part of the QCAD project.
  5. *
  6. * QCAD is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * QCAD is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with QCAD.
  18. */
  19. include("scripts/View/View.js");
  20. /**
  21. * Helper class to update DraftMode button status when focus changes
  22. * (e.g. other view is activated).
  23. */
  24. function ToggleDraftModeFocusListener(action) {
  25. RViewFocusListenerAdapter.call(this);
  26. this.action = action;
  27. }
  28. ToggleDraftModeFocusListener.prototype = new RViewFocusListenerAdapter();
  29. ToggleDraftModeFocusListener.prototype.updateFocus = function(view) {
  30. if (isNull(view)) {
  31. this.action.checked = false;
  32. return;
  33. }
  34. var scene = view.getScene();
  35. if (isNull(scene)) {
  36. this.action.checked = false;
  37. return;
  38. }
  39. this.action.checked = scene.getDraftMode();
  40. };
  41. function DraftMode(guiAction) {
  42. View.call(this, guiAction);
  43. }
  44. DraftMode.prototype = new View();
  45. DraftMode.prototype.beginEvent = function() {
  46. View.prototype.beginEvent.call(this);
  47. var view = this.getDocumentInterface().getLastKnownViewWithFocus();
  48. if (!isNull(view)) {
  49. var scene = view.getScene();
  50. if (!isNull(scene)) {
  51. scene.toggleDraftMode();
  52. scene.regenerate();
  53. }
  54. }
  55. this.terminate();
  56. };
  57. DraftMode.prototype.finishEvent = function() {
  58. View.prototype.finishEvent.call(this);
  59. var view = this.getDocumentInterface().getLastKnownViewWithFocus();
  60. if (!isNull(view) && !isNull(this.getGuiAction())) {
  61. var scene = view.getScene();
  62. if (!isNull(scene)) {
  63. this.getGuiAction().setChecked(scene.getDraftMode());
  64. }
  65. }
  66. };
  67. DraftMode.init = function(basePath) {
  68. var action = new RGuiAction(qsTranslate("DraftMode", "&Draft Mode"), RMainWindowQt.getMainWindow());
  69. action.setRequiresDocument(true);
  70. action.setScriptFile(basePath + "/DraftMode.js");
  71. action.setIcon(basePath + "/DraftMode.svg");
  72. action.setDefaultShortcut(new QKeySequence("d,f"));
  73. action.setDefaultCommands(["draftmode", "df"]);
  74. action.setGroup("viewmodes");
  75. action.setNoState(true);
  76. action.setGroupSortOrder(3100);
  77. action.setSortOrder(100);
  78. action.setWidgetNames(["ViewMenu", "!ViewToolBar", "ViewToolsPanel", "ViewMatrixPanel"]);
  79. var appWin = EAction.getMainWindow();
  80. var fl = new ToggleDraftModeFocusListener(action);
  81. appWin.addViewFocusListener(fl);
  82. };