WindowZoom.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 WindowZoom(guiAction) {
  21. View.call(this, guiAction);
  22. this.view = undefined;
  23. this.v1 = RVector.invalid;
  24. this.v2 = RVector.invalid;
  25. this.s1 = RVector.invalid;
  26. this.s2 = RVector.invalid;
  27. if (RSettings.getBoolValue("GraphicsView/SystemCursors", false)===true) {
  28. this.cursor = new QCursor(Qt.CrossCursor);
  29. }
  30. else {
  31. var bitmap, mask;
  32. if (RSettings.getDevicePixelRatio()===2 && RS.getSystemId()!=="osx") {
  33. bitmap = new QBitmap(WindowZoom.includeBasePath + "/WindowZoomCursor@2x.png", "PNG");
  34. mask = new QBitmap(WindowZoom.includeBasePath + "/WindowZoomCursorMask@2x.png", "PNG");
  35. this.cursor = new QCursor(bitmap, mask, 24, 24);
  36. }
  37. else {
  38. bitmap = new QBitmap(WindowZoom.includeBasePath + "/WindowZoomCursor.png", "PNG");
  39. mask = new QBitmap(WindowZoom.includeBasePath + "/WindowZoomCursorMask.png", "PNG");
  40. this.cursor = new QCursor(bitmap, mask, 12, 12);
  41. }
  42. }
  43. }
  44. WindowZoom.prototype = new View();
  45. WindowZoom.includeBasePath = includeBasePath;
  46. WindowZoom.State = {
  47. SettingCorner1 : 0,
  48. SettingCorner2 : 1
  49. };
  50. WindowZoom.viewEquals = function(v1, v2) {
  51. if (RSettings.getQtVersion() >= 0x060000) {
  52. return v1.getAddress() == v2.getAddress();
  53. }
  54. else {
  55. return v1 == v2;
  56. }
  57. };
  58. WindowZoom.prototype.beginEvent = function() {
  59. View.prototype.beginEvent.call(this);
  60. this.setState(WindowZoom.State.SettingCorner1);
  61. };
  62. WindowZoom.prototype.setState = function(state) {
  63. View.prototype.setState.call(this, state);
  64. this.getDocumentInterface().setClickMode(RAction.PickingDisabled);
  65. this.setCursor(this.cursor, "WindowZoomCursor");
  66. };
  67. WindowZoom.prototype.mousePressEvent = function(event) {
  68. this.view = event.getGraphicsView();
  69. if (event.button() == Qt.LeftButton) {
  70. if (this.state == WindowZoom.State.SettingCorner1) {
  71. this.v1 = event.getModelPosition();
  72. this.s1 = event.getScreenPosition();
  73. this.state = WindowZoom.State.SettingCorner2;
  74. }
  75. }
  76. };
  77. WindowZoom.prototype.mouseReleaseEvent = function(event) {
  78. if (!WindowZoom.viewEquals(this.view, event.getGraphicsView())) {
  79. return;
  80. }
  81. if (event.button() == Qt.LeftButton) {
  82. if (this.state == WindowZoom.State.SettingCorner2) {
  83. this.v2 = event.getModelPosition();
  84. this.s2 = event.getScreenPosition();
  85. if (this.s1.getDistanceTo(this.s2) > 5) {
  86. var di = this.getDocumentInterface();
  87. di.clearPreview();
  88. di.zoomTo(new RBox(this.v1, this.v2));
  89. di.repaintViews();
  90. this.state = WindowZoom.State.SettingCorner1;
  91. }
  92. }
  93. }
  94. else {
  95. View.prototype.mouseReleaseEvent.call(this, event);
  96. }
  97. };
  98. WindowZoom.prototype.mouseMoveEvent = function(event) {
  99. if (this.state == WindowZoom.State.SettingCorner2 && this.v1.isValid()) {
  100. if (WindowZoom.viewEquals(this.view, event.getGraphicsView())) {
  101. this.v2 = event.getModelPosition();
  102. }
  103. this.getDocumentInterface().addZoomBoxToPreview(
  104. new RBox(this.v1, this.v2));
  105. }
  106. };
  107. WindowZoom.prototype.finishEvent = function(event) {
  108. View.prototype.finishEvent.call(this);
  109. this.setCursor(new QCursor(Qt.ArrowCursor));
  110. };