]> Shamusworld >> Repos - architektonas/blob - src/actions/actionzoompan.cpp
In the middle of major refactoring...
[architektonas] / src / actions / actionzoompan.cpp
1 // 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 "actionzoompan.h"
16
17 #include "graphicview.h"
18
19 ActionZoomPan::ActionZoomPan(RS_EntityContainer & container, GraphicView & graphicView):
20         ActionInterface("Zoom Pan", container, graphicView)
21 {
22 }
23
24 ActionZoomPan::~ActionZoomPan()
25 {
26 }
27
28 void ActionZoomPan::init(int status)
29 {
30         ActionInterface::init(status);
31 /*      snapMode = RS2::SnapFree;
32         snapRes = RS2::RestrictNothing;*/
33         x1 = y1 = x2 = y2 = -1;
34 }
35
36 void 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 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 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 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
80 void ActionZoomPan::updateMouseCursor()
81 {
82 #ifndef __APPLE__
83         graphicView->setMouseCursor(RS2::SizeAllCursor);
84 #endif
85 }