]> Shamusworld >> Repos - architektonas/blob - src/actions/rs_actionzoomwindow.cpp
Initial import
[architektonas] / src / actions / rs_actionzoomwindow.cpp
1 /****************************************************************************
2 ** $Id: rs_actionzoomwindow.cpp 1134 2004-07-13 23:26:13Z andrew $
3 **
4 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
5 **
6 ** This file is part of the qcadlib Library project.
7 **
8 ** This file may be distributed and/or modified under the terms of the
9 ** GNU General Public License version 2 as published by the Free Software
10 ** Foundation and appearing in the file LICENSE.GPL included in the
11 ** packaging of this file.
12 **
13 ** Licensees holding valid qcadlib Professional Edition licenses may use
14 ** this file in accordance with the qcadlib Commercial License
15 ** Agreement provided with the Software.
16 **
17 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
18 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 **
20 ** See http://www.ribbonsoft.com for further details.
21 **
22 ** Contact info@ribbonsoft.com if any conditions of this licensing are
23 ** not clear to you.
24 **
25 **********************************************************************/
26
27 #include "rs_actionzoomwindow.h"
28
29 #include "rs.h"
30 #include "rs_snapper.h"
31 #include "rs_point.h"
32 //Added by qt3to4:
33 //#include <QIcon>
34
35 /**
36  * Default constructor.
37  *
38  * @param keepAspectRatio Keep the aspect ratio. true: the factors
39  *          in x and y will stay the same. false Exactly the chosen
40  *          area will be fit to the viewport.
41  */
42 RS_ActionZoomWindow::RS_ActionZoomWindow(RS_EntityContainer & container,
43         RS_GraphicView& graphicView, bool keepAspectRatio):
44         RS_PreviewActionInterface("Zoom Window", container, graphicView)
45 {
46         this->keepAspectRatio = keepAspectRatio;
47 }
48
49 QAction* RS_ActionZoomWindow::createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/)
50 {
51         QAction * action = new QAction(QIcon(":/res/zoomwindow.png"), tr("&Window Zoom"), 0);
52 //      QAction* action = new QAction(tr("Window Zoom"), QPixmap::fromMimeSource("zoomwindow.png"),
53 //                                                                      tr("&Window Zoom"), QKeySequence(), NULL);
54         action->setStatusTip(tr("Zooms in a window"));
55         return action;
56 }
57
58 void RS_ActionZoomWindow::init(int status)
59 {
60         RS_DEBUG->print("RS_ActionZoomWindow::init()");
61
62         RS_PreviewActionInterface::init(status);
63         v1 = v2 = Vector(false);
64         snapMode = RS2::SnapFree;
65         snapRes = RS2::RestrictNothing;
66 }
67
68 void RS_ActionZoomWindow::trigger()
69 {
70         RS_DEBUG->print("RS_ActionZoomWindow::trigger()");
71
72         RS_PreviewActionInterface::trigger();
73
74         if (v1.valid && v2.valid)
75         {
76                 deletePreview();
77                 deleteSnapper();
78
79                 if (graphicView->toGuiDX(v1.distanceTo(v2)) > 5)
80                 {
81                         graphicView->zoomWindow(v1, v2, keepAspectRatio);
82                         init();
83                 }
84         }
85 }
86
87 void RS_ActionZoomWindow::mouseMoveEvent(QMouseEvent * e)
88 {
89         if (getStatus() == 1 && v1.valid)
90         {
91                 v2 = snapPoint(e);
92                 deletePreview();
93                 clearPreview();
94                 preview->addEntity(new RS_Line(preview,
95                         RS_LineData(Vector(v1.x, v1.y), Vector(v2.x, v1.y))));
96                 preview->addEntity(new RS_Line(preview,
97                         RS_LineData(Vector(v2.x, v1.y), Vector(v2.x, v2.y))));
98                 preview->addEntity(new RS_Line(preview,
99                         RS_LineData(Vector(v2.x, v2.y), Vector(v1.x, v2.y))));
100                 preview->addEntity(new RS_Line(preview,
101                         RS_LineData(Vector(v1.x, v2.y), Vector(v1.x, v1.y))));
102                 drawPreview();
103         }
104 }
105
106 void RS_ActionZoomWindow::mousePressEvent(QMouseEvent * e)
107 {
108         if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton)
109         {
110                 switch (getStatus())
111                 {
112                 case 0:
113                         v1 = snapPoint(e);
114                         setStatus(1);
115                         break;
116
117                 default:
118                         break;
119                 }
120         }
121
122         RS_DEBUG->print("RS_ActionZoomWindow::mousePressEvent(): %f %f", v1.x, v1.y);
123 }
124
125 void RS_ActionZoomWindow::mouseReleaseEvent(QMouseEvent * e)
126 {
127         RS_DEBUG->print("RS_ActionZoomWindow::mouseReleaseEvent()");
128
129         if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton)
130         {
131                 if (getStatus() == 1)
132                 {
133                         deletePreview();
134                 }
135
136                 init(getStatus() - 1);
137         }
138         else if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton)
139         {
140                 if (getStatus() == 1)
141                 {
142                         v2 = snapPoint(e);
143                         trigger();
144                 }
145         }
146 }
147
148 void RS_ActionZoomWindow::updateMouseButtonHints()
149 {
150         RS_DEBUG->print("RS_ActionZoomWindow::updateMouseButtonHints()");
151
152         switch (getStatus())
153         {
154         case 0:
155                 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first edge"), tr("Cancel"));
156                 break;
157         case 1:
158                 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify second edge"), tr("Back"));
159                 break;
160         default:
161                 RS_DIALOGFACTORY->updateMouseWidget("", "");
162                 break;
163         }
164 }
165
166 void RS_ActionZoomWindow::updateMouseCursor()
167 {
168         graphicView->setMouseCursor(RS2::MagnifierCursor);
169 }
170
171 // EOF