AntialiasingMode.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 AntialiasingMode button status when focus changes
  22. * (e.g. other view is activated).
  23. */
  24. function ToggleAntialiasingModeFocusListener(action) {
  25. RViewFocusListenerAdapter.call(this);
  26. this.action = action;
  27. }
  28. ToggleAntialiasingModeFocusListener.prototype = new RViewFocusListenerAdapter();
  29. ToggleAntialiasingModeFocusListener.prototype.updateFocus = function(view) {
  30. if (isNull(view)) {
  31. this.action.checked = false;
  32. return;
  33. }
  34. this.action.checked = view.getAntialiasing();
  35. };
  36. function AntialiasingMode(guiAction) {
  37. View.call(this, guiAction);
  38. }
  39. AntialiasingMode.prototype = new View();
  40. AntialiasingMode.prototype.beginEvent = function() {
  41. View.prototype.beginEvent.call(this);
  42. var view = this.getDocumentInterface().getLastKnownViewWithFocus();
  43. if (!isNull(view)) {
  44. view.setAntialiasing(!view.getAntialiasing());
  45. view.regenerate(true);
  46. }
  47. this.terminate();
  48. };
  49. AntialiasingMode.prototype.finishEvent = function() {
  50. View.prototype.finishEvent.call(this);
  51. var view = this.getDocumentInterface().getLastKnownViewWithFocus();
  52. if (!isNull(view) && !isNull(this.getGuiAction())) {
  53. this.getGuiAction().setChecked(view.getAntialiasing());
  54. }
  55. };
  56. AntialiasingMode.init = function(basePath) {
  57. var action = new RGuiAction(qsTranslate("AntialiasingMode", "&Anti-aliasing"), RMainWindowQt.getMainWindow());
  58. action.setRequiresDocument(true);
  59. action.setScriptFile(basePath + "/AntialiasingMode.js");
  60. action.setIcon(basePath + "/AntialiasingMode.svg");
  61. action.setDefaultShortcut(new QKeySequence("n,t"));
  62. action.setDefaultCommands(["antialiasing", "nt"]);
  63. action.setNoState(true);
  64. action.setGroupSortOrder(3100);
  65. action.setSortOrder(300);
  66. action.setWidgetNames(["ViewMenu", "!ViewToolBar", "ViewToolsPanel", "ViewMatrixPanel"]);
  67. var appWin = EAction.getMainWindow();
  68. var fl = new ToggleAntialiasingModeFocusListener(action);
  69. appWin.addViewFocusListener(fl);
  70. };