PanZoom.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. function PanZoom(guiAction) {
  21. View.call(this, guiAction);
  22. this.panning = false;
  23. this.panOrigin = new RVector();
  24. }
  25. PanZoom.prototype = new View();
  26. PanZoom.prototype.beginEvent = function() {
  27. View.prototype.beginEvent.call(this);
  28. this.getDocumentInterface().setClickMode(RAction.PickingDisabled);
  29. this.getDocumentInterface().setCursor(new QCursor(Qt.OpenHandCursor));
  30. };
  31. PanZoom.prototype.mousePressEvent = function(event) {
  32. if (event.button() == Qt.LeftButton) {
  33. this.panOrigin = event.getScreenPosition();
  34. this.panning = true;
  35. this.getDocumentInterface().setCursor(new QCursor(Qt.ClosedHandCursor));
  36. }
  37. else {
  38. View.prototype.mousePressEvent.call(this, event);
  39. }
  40. };
  41. PanZoom.prototype.mouseReleaseEvent = function(event) {
  42. if (event.button() == Qt.LeftButton) {
  43. this.panning = false;
  44. this.getDocumentInterface().setCursor(new QCursor(Qt.OpenHandCursor));
  45. }
  46. else {
  47. View.prototype.mouseReleaseEvent.call(this, event);
  48. }
  49. };
  50. PanZoom.prototype.mouseMoveEvent = function(event) {
  51. if (event.buttons().valueOf() & Qt.LeftButton.valueOf()) {
  52. if (this.panning == true) {
  53. var view = event.getGraphicsView();
  54. var panTarget = event.getScreenPosition();
  55. var panDelta = panTarget.operator_subtract(this.panOrigin);
  56. if (panDelta.x != 0 || panDelta.y != 0) {
  57. view.pan(panDelta);
  58. }
  59. this.panOrigin = panTarget;
  60. }
  61. }
  62. };
  63. PanZoom.prototype.finishEvent = function(event) {
  64. View.prototype.finishEvent.call(this);
  65. this.getDocumentInterface().setCursor(new QCursor(Qt.ArrowCursor));
  66. };