]> Shamusworld >> Repos - architektonas/blob - src/actions/actionzoompan.cpp
74b3d824b4d0036f2fa044c76361858f5e796626
[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 // Portions copyright (C) 2001-2003 RibbonSoft
7 // Copyright (C) 2010 Underground Software
8 // See the README and GPLv2 files for licensing and warranty information
9 //
10 // JLH = James L. Hammons <jlhamm@acm.org>
11 //
12 // Who  When        What
13 // ---  ----------  -----------------------------------------------------------
14 // JLH  06/05/2010  Added this text. :-)
15 //
16
17 #include "actionzoompan.h"
18
19 #include "graphicview.h"
20
21 ActionZoomPan::ActionZoomPan(EntityContainer & container, GraphicView & graphicView):
22         ActionInterface("Zoom Pan", container, graphicView)
23 {
24         graphicView.snapper.SetVisible(false);
25         graphicView.preview.SetVisible(false);
26 }
27
28 ActionZoomPan::~ActionZoomPan()
29 {
30 }
31
32 void ActionZoomPan::init(int status)
33 {
34         ActionInterface::init(status);
35 /*      snapMode = RS2::SnapFree;
36         snapRes = RS2::RestrictNothing;*/
37         x1 = y1 = x2 = y2 = -1;
38 }
39
40 void ActionZoomPan::trigger()
41 {
42         if (x1 >= 0)
43         {
44                 graphicView->zoomPan(x2 - x1, y2 - y1);
45                 x1 = x2;
46                 y1 = y2;
47         }
48 }
49
50 #define SCROLL_DELTA 4
51 void ActionZoomPan::mouseMoveEvent(QMouseEvent * e)
52 {
53         x2 = e->x();
54         y2 = e->y();
55
56 //This is where we see if the delta was big enough to warrant a redraw...
57 //Dunno if this is needed anymore, the Qt rendering pipeline should be able to
58 //hang with this...
59 //      if (getStatus() == 1 && (abs(x2 - x1) > 7 || abs(y2 - y1) > 7))
60         if (getStatus() == 1 && (abs(x2 - x1) > SCROLL_DELTA || abs(y2 - y1) > SCROLL_DELTA))
61                 trigger();
62 }
63
64 void ActionZoomPan::mousePressEvent(QMouseEvent * e)
65 {
66         if (e->button() == Qt::LeftButton || e->button() == Qt::MidButton)
67         {
68                 x1 = e->x();
69                 y1 = e->y();
70                 setStatus(1);
71         }
72 }
73
74 void ActionZoomPan::mouseReleaseEvent(QMouseEvent * e)
75 {
76         // Right button? Why?
77         // Is this a regular tool? Is this why? (yup, it is. but lame nonetheless.)
78         // It doesn't revert the cursor correctly if this is not in...
79         // So... We need to fix this... [DONE]
80         /*if (e->button() == Qt::RightButton)
81                 init(getStatus() - 1);
82         else*/ if (e->button() == Qt::MidButton || e->button() == Qt::RightButton)
83                 init(-1);
84         else
85                 setStatus(0);   // Qt::LeftButton
86 }
87
88 void ActionZoomPan::updateMouseCursor()
89 {
90 #ifndef __APPLE__
91         graphicView->setMouseCursor(RS2::SizeAllCursor);
92 #endif
93 }