1 /****************************************************************************
2 ** $Id: rs_actionzoomwindow.cpp 1134 2004-07-13 23:26:13Z andrew $
4 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
6 ** This file is part of the qcadlib Library project.
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.
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.
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.
20 ** See http://www.ribbonsoft.com for further details.
22 ** Contact info@ribbonsoft.com if any conditions of this licensing are
25 **********************************************************************/
27 #include "rs_actionzoomwindow.h"
30 #include "rs_snapper.h"
36 * Default constructor.
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.
42 RS_ActionZoomWindow::RS_ActionZoomWindow(RS_EntityContainer & container,
43 RS_GraphicView& graphicView, bool keepAspectRatio):
44 RS_PreviewActionInterface("Zoom Window", container, graphicView)
46 this->keepAspectRatio = keepAspectRatio;
49 QAction* RS_ActionZoomWindow::createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/)
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"));
58 void RS_ActionZoomWindow::init(int status)
60 RS_DEBUG->print("RS_ActionZoomWindow::init()");
62 RS_PreviewActionInterface::init(status);
63 v1 = v2 = Vector(false);
64 snapMode = RS2::SnapFree;
65 snapRes = RS2::RestrictNothing;
68 void RS_ActionZoomWindow::trigger()
70 RS_DEBUG->print("RS_ActionZoomWindow::trigger()");
72 RS_PreviewActionInterface::trigger();
74 if (v1.valid && v2.valid)
79 if (graphicView->toGuiDX(v1.distanceTo(v2)) > 5)
81 graphicView->zoomWindow(v1, v2, keepAspectRatio);
87 void RS_ActionZoomWindow::mouseMoveEvent(QMouseEvent * e)
89 if (getStatus() == 1 && v1.valid)
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))));
106 void RS_ActionZoomWindow::mousePressEvent(QMouseEvent * e)
108 if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton)
122 RS_DEBUG->print("RS_ActionZoomWindow::mousePressEvent(): %f %f", v1.x, v1.y);
125 void RS_ActionZoomWindow::mouseReleaseEvent(QMouseEvent * e)
127 RS_DEBUG->print("RS_ActionZoomWindow::mouseReleaseEvent()");
129 if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton)
131 if (getStatus() == 1)
136 init(getStatus() - 1);
138 else if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton)
140 if (getStatus() == 1)
148 void RS_ActionZoomWindow::updateMouseButtonHints()
150 RS_DEBUG->print("RS_ActionZoomWindow::updateMouseButtonHints()");
155 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first edge"), tr("Cancel"));
158 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify second edge"), tr("Back"));
161 RS_DIALOGFACTORY->updateMouseWidget("", "");
166 void RS_ActionZoomWindow::updateMouseCursor()
168 graphicView->setMouseCursor(RS2::MagnifierCursor);