]> Shamusworld >> Repos - architektonas/blob - src/actions/actionzoomwindow.cpp
e16c7ae0fdee768b64f2868b81c15c4a92c1afa8
[architektonas] / src / actions / actionzoomwindow.cpp
1 // actionzoomwindow.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 "actionzoomwindow.h"
16
17 #include "rs_dialogfactory.h"
18 #include "graphicview.h"
19 #include "rs_preview.h"
20
21 /**
22  * Default constructor.
23  *
24  * @param keepAspectRatio Keep the aspect ratio. true: the factors
25  *          in x and y will stay the same. false Exactly the chosen
26  *          area will be fit to the viewport.
27  */
28 ActionZoomWindow::ActionZoomWindow(RS_EntityContainer & container,
29         GraphicView & graphicView, bool keepAspectRatio):
30         ActionInterface("Zoom Window", container, graphicView)
31 {
32         this->keepAspectRatio = keepAspectRatio;
33 }
34
35 ActionZoomWindow::~ActionZoomWindow()
36 {
37 }
38
39 void ActionZoomWindow::init(int status)
40 {
41         RS_DEBUG->print("ActionZoomWindow::init()");
42         ActionInterface::init(status);
43         v1 = v2 = Vector(false);
44 /*      snapMode = RS2::SnapFree;
45         snapRes = RS2::RestrictNothing;*/
46 }
47
48 void ActionZoomWindow::trigger()
49 {
50         RS_DEBUG->print("ActionZoomWindow::trigger()");
51
52         ActionInterface::trigger();
53
54         if (v1.valid && v2.valid)
55         {
56                 deletePreview();
57                 deleteSnapper();
58
59                 if (graphicView->toGuiDX(v1.distanceTo(v2)) > 5)
60                 {
61                         graphicView->zoomWindow(v1, v2, keepAspectRatio);
62                         init();
63                 }
64         }
65 }
66
67 void ActionZoomWindow::mouseMoveEvent(QMouseEvent * e)
68 {
69         if (getStatus() == 1 && v1.valid)
70         {
71                 v2 = snapPoint(e);
72                 deletePreview();
73                 clearPreview();
74 /*              preview->addEntity(new RS_Line(preview,
75                                 RS_LineData(Vector(v1.x, v1.y), Vector(v2.x, v1.y))));
76                 preview->addEntity(new RS_Line(preview,
77                                 RS_LineData(Vector(v2.x, v1.y), Vector(v2.x, v2.y))));
78                 preview->addEntity(new RS_Line(preview,
79                                 RS_LineData(Vector(v2.x, v2.y), Vector(v1.x, v2.y))));
80                 preview->addEntity(new RS_Line(preview,
81                                 RS_LineData(Vector(v1.x, v2.y), Vector(v1.x, v1.y))));*/
82                 drawPreview();
83         }
84 }
85
86 void ActionZoomWindow::mousePressEvent(QMouseEvent * e)
87 {
88         if (e->button() == Qt::LeftButton)
89         {
90                 switch (getStatus())
91                 {
92                 case 0:
93                         v1 = snapPoint(e);
94                         setStatus(1);
95                         break;
96
97                 default:
98                         break;
99                 }
100         }
101
102         RS_DEBUG->print("ActionZoomWindow::mousePressEvent(): %f %f", v1.x, v1.y);
103 }
104
105 void ActionZoomWindow::mouseReleaseEvent(QMouseEvent * e)
106 {
107         RS_DEBUG->print("ActionZoomWindow::mouseReleaseEvent()");
108
109         if (e->button() == Qt::RightButton)
110         {
111                 if (getStatus() == 1)
112                         deletePreview();
113
114                 init(getStatus() - 1);
115         }
116         else if (e->button() == Qt::LeftButton)
117                 if (getStatus() == 1)
118                 {
119                         v2 = snapPoint(e);
120                         trigger();
121                 }
122 }
123
124 void ActionZoomWindow::updateMouseButtonHints()
125 {
126         RS_DEBUG->print("ActionZoomWindow::updateMouseButtonHints()");
127
128         switch (getStatus())
129         {
130         case 0:
131                 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first edge"), tr("Cancel"));
132                 break;
133
134         case 1:
135                 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify second edge"), tr("Back"));
136                 break;
137
138         default:
139                 RS_DIALOGFACTORY->updateMouseWidget("", "");
140                 break;
141         }
142 }
143
144 void ActionZoomWindow::updateMouseCursor()
145 {
146         graphicView->setMouseCursor(RS2::MagnifierCursor);
147 }
148
149