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