]> Shamusworld >> Repos - architektonas/blob - src/actions/rs_actionzoompan.cpp
Refactoring: Moved RS_GraphicView to GraphicView.
[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 void RS_ActionZoomPan::mouseMoveEvent(QMouseEvent * e)
47 {
48         x2 = e->x();
49         y2 = e->y();
50
51 //This is where we see if the delta was big enough to warrant a redraw...
52         if (getStatus() == 1 && (abs(x2 - x1) > 7 || abs(y2 - y1) > 7))
53                 trigger();
54 }
55
56 void RS_ActionZoomPan::mousePressEvent(QMouseEvent * e)
57 {
58         if (e->button() == Qt::MidButton || e->button() == Qt::LeftButton)
59         {
60                 x1 = e->x();
61                 y1 = e->y();
62                 setStatus(1);
63         }
64 }
65
66 void RS_ActionZoomPan::mouseReleaseEvent(QMouseEvent * e)
67 {
68         if (e->button() == Qt::RightButton)
69                 init(getStatus() - 1);
70         else if (e->button() == Qt::MidButton)
71                 init(-1);
72         else
73                 setStatus(0);
74
75         //RS_DEBUG->print("RS_ActionZoomPan::mousePressEvent(): %f %f", v1.x, v1.y);
76 }
77
78 void RS_ActionZoomPan::updateMouseCursor()
79 {
80 #ifndef __APPLE__
81         graphicView->setMouseCursor(RS2::SizeAllCursor);
82 #endif
83 }