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