1 // actionzoomwindow.cpp
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
10 // JLH = James L. Hammons <jlhamm@acm.org>
13 // --- ---------- -----------------------------------------------------------
14 // JLH 06/05/2010 Added this text. :-)
17 #include "actionzoomwindow.h"
19 #include "rs_dialogfactory.h"
20 #include "graphicview.h"
21 #include "rs_preview.h"
24 * Default constructor.
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.
30 ActionZoomWindow::ActionZoomWindow(RS_EntityContainer & container,
31 GraphicView & graphicView, bool keepAspectRatio):
32 ActionInterface("Zoom Window", container, graphicView)
34 this->keepAspectRatio = keepAspectRatio;
37 ActionZoomWindow::~ActionZoomWindow()
41 void ActionZoomWindow::init(int status)
43 RS_DEBUG->print("ActionZoomWindow::init()");
44 ActionInterface::init(status);
45 v1 = v2 = Vector(false);
46 /* snapMode = RS2::SnapFree;
47 snapRes = RS2::RestrictNothing;*/
50 void ActionZoomWindow::trigger()
52 RS_DEBUG->print("ActionZoomWindow::trigger()");
54 ActionInterface::trigger();
56 if (v1.valid && v2.valid)
61 if (graphicView->toGuiDX(v1.distanceTo(v2)) > 5)
63 graphicView->zoomWindow(v1, v2, keepAspectRatio);
69 void ActionZoomWindow::mouseMoveEvent(QMouseEvent * e)
71 if (getStatus() == 1 && v1.valid)
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))));*/
88 void ActionZoomWindow::mousePressEvent(QMouseEvent * e)
90 if (e->button() == Qt::LeftButton)
104 RS_DEBUG->print("ActionZoomWindow::mousePressEvent(): %f %f", v1.x, v1.y);
107 void ActionZoomWindow::mouseReleaseEvent(QMouseEvent * e)
109 RS_DEBUG->print("ActionZoomWindow::mouseReleaseEvent()");
111 if (e->button() == Qt::RightButton)
113 if (getStatus() == 1)
116 init(getStatus() - 1);
118 else if (e->button() == Qt::LeftButton)
119 if (getStatus() == 1)
126 void ActionZoomWindow::updateMouseButtonHints()
128 RS_DEBUG->print("ActionZoomWindow::updateMouseButtonHints()");
133 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first edge"), tr("Cancel"));
137 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify second edge"), tr("Back"));
141 RS_DIALOGFACTORY->updateMouseWidget("", "");
146 void ActionZoomWindow::updateMouseCursor()
148 graphicView->setMouseCursor(RS2::MagnifierCursor);