1 // rs_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 // (C) 2010 Underground Software
8 // JLH = James L. Hammons <jlhamm@acm.org>
11 // --- ---------- -----------------------------------------------------------
12 // JLH 06/05/2010 Added this text. :-)
15 #include "rs_actionzoomwindow.h"
17 #include "rs_dialogfactory.h"
18 #include "graphicview.h"
19 #include "rs_preview.h"
22 * Default constructor.
24 * @param keepAspectRatio Keep the aspect ratio. true: the factors
25 * in x and y will stay the same. false Exactly the chosen
26 * area will be fit to the viewport.
28 RS_ActionZoomWindow::RS_ActionZoomWindow(RS_EntityContainer & container,
29 GraphicView & graphicView, bool keepAspectRatio):
30 RS_PreviewActionInterface("Zoom Window", container, graphicView)
32 this->keepAspectRatio = keepAspectRatio;
35 RS_ActionZoomWindow::~RS_ActionZoomWindow()
39 void RS_ActionZoomWindow::init(int status)
41 RS_DEBUG->print("RS_ActionZoomWindow::init()");
43 RS_PreviewActionInterface::init(status);
44 v1 = v2 = Vector(false);
45 snapMode = RS2::SnapFree;
46 snapRes = RS2::RestrictNothing;
49 void RS_ActionZoomWindow::trigger()
51 RS_DEBUG->print("RS_ActionZoomWindow::trigger()");
53 RS_PreviewActionInterface::trigger();
55 if (v1.valid && v2.valid)
60 if (graphicView->toGuiDX(v1.distanceTo(v2)) > 5)
62 graphicView->zoomWindow(v1, v2, keepAspectRatio);
68 void RS_ActionZoomWindow::mouseMoveEvent(QMouseEvent * e)
70 if (getStatus() == 1 && v1.valid)
75 preview->addEntity(new RS_Line(preview,
76 RS_LineData(Vector(v1.x, v1.y), Vector(v2.x, v1.y))));
77 preview->addEntity(new RS_Line(preview,
78 RS_LineData(Vector(v2.x, v1.y), Vector(v2.x, v2.y))));
79 preview->addEntity(new RS_Line(preview,
80 RS_LineData(Vector(v2.x, v2.y), Vector(v1.x, v2.y))));
81 preview->addEntity(new RS_Line(preview,
82 RS_LineData(Vector(v1.x, v2.y), Vector(v1.x, v1.y))));
87 void RS_ActionZoomWindow::mousePressEvent(QMouseEvent * e)
89 if (e->button() == Qt::LeftButton)
103 RS_DEBUG->print("RS_ActionZoomWindow::mousePressEvent(): %f %f", v1.x, v1.y);
106 void RS_ActionZoomWindow::mouseReleaseEvent(QMouseEvent * e)
108 RS_DEBUG->print("RS_ActionZoomWindow::mouseReleaseEvent()");
110 if (e->button() == Qt::RightButton)
112 if (getStatus() == 1)
115 init(getStatus() - 1);
117 else if (e->button() == Qt::LeftButton)
118 if (getStatus() == 1)
125 void RS_ActionZoomWindow::updateMouseButtonHints()
127 RS_DEBUG->print("RS_ActionZoomWindow::updateMouseButtonHints()");
132 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first edge"), tr("Cancel"));
136 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify second edge"), tr("Back"));
140 RS_DIALOGFACTORY->updateMouseWidget("", "");
145 void RS_ActionZoomWindow::updateMouseCursor()
147 graphicView->setMouseCursor(RS2::MagnifierCursor);