]> Shamusworld >> Repos - architektonas/blob - src/actions/rs_actionzoompan.cpp
e4ce07afef8e813f1e2ee97c309e933d4f6f5e06
[architektonas] / src / actions / rs_actionzoompan.cpp
1 // rs_actionzoompan.cpp
2 //
3 // Part of the Architektonas Project
4 // Originally part of QCad Community Edition by Andrew Mustun
5 // Extensively rewritten and refactored by James L. Hammons
6 // (C) 2010 Underground Software
7 //
8 // JLH = James L. Hammons <jlhamm@acm.org>
9 //
10 // Who  When        What
11 // ---  ----------  -----------------------------------------------------------
12 // JLH  06/05/2010  Added this text. :-)
13 //
14
15 #include "rs_actionzoompan.h"
16
17 #include "graphicview.h"
18
19 RS_ActionZoomPan::RS_ActionZoomPan(RS_EntityContainer & container, GraphicView & graphicView):
20         RS_ActionInterface("Zoom Pan", container, graphicView)
21 {
22 }
23
24 RS_ActionZoomPan::~RS_ActionZoomPan()
25 {
26 }
27
28 void RS_ActionZoomPan::init(int status)
29 {
30         RS_ActionInterface::init(status);
31         snapMode = RS2::SnapFree;
32         snapRes = RS2::RestrictNothing;
33         x1 = y1 = x2 = y2 = -1;
34 }
35
36 void RS_ActionZoomPan::trigger()
37 {
38         if (x1 >= 0)
39         {
40                 graphicView->zoomPan(x2 - x1, y2 - y1);
41                 x1 = x2;
42                 y1 = y2;
43         }
44 }
45
46 #define SCROLL_DELTA 4
47 void RS_ActionZoomPan::mouseMoveEvent(QMouseEvent * e)
48 {
49         x2 = e->x();
50         y2 = e->y();
51
52 //This is where we see if the delta was big enough to warrant a redraw...
53 //Dunno if this is needed anymore, the Qt rendering pipeline should be able to
54 //hang with this...
55 //      if (getStatus() == 1 && (abs(x2 - x1) > 7 || abs(y2 - y1) > 7))
56         if (getStatus() == 1 && (abs(x2 - x1) > SCROLL_DELTA || abs(y2 - y1) > SCROLL_DELTA))
57                 trigger();
58 }
59
60 void RS_ActionZoomPan::mousePressEvent(QMouseEvent * e)
61 {
62         if (e->button() == Qt::MidButton || e->button() == Qt::LeftButton)
63         {
64                 x1 = e->x();
65                 y1 = e->y();
66                 setStatus(1);
67         }
68 }
69
70 void RS_ActionZoomPan::mouseReleaseEvent(QMouseEvent * e)
71 {
72         if (e->button() == Qt::RightButton)
73                 init(getStatus() - 1);
74         else if (e->button() == Qt::MidButton)
75                 init(-1);
76         else
77                 setStatus(0);
78
79         //RS_DEBUG->print("RS_ActionZoomPan::mousePressEvent(): %f %f", v1.x, v1.y);
80 }
81
82 void RS_ActionZoomPan::updateMouseCursor()
83 {
84 #ifndef __APPLE__
85         graphicView->setMouseCursor(RS2::SizeAllCursor);
86 #endif
87 }