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