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/03/2010 Added this text. :-)
15 #include "actiondefault.h"
18 #include "rs_commandevent.h"
19 #include "rs_dialogfactory.h"
21 #include "rs_modification.h"
22 #include "rs_preview.h"
23 #include "rs_snapper.h"
24 #include "rs_selection.h"
29 ActionDefault::ActionDefault(RS_EntityContainer & container,
30 GraphicView & graphicView): ActionInterface("Default",
31 container, graphicView)
33 RS_DEBUG->print("ActionDefault::ActionDefault");
34 RS_DEBUG->print("ActionDefault::ActionDefault: OK");
37 ActionDefault::~ActionDefault()
41 /*virtual*/ RS2::ActionType ActionDefault::rtti()
43 return RS2::ActionDefault;
46 void ActionDefault::init(int status /*= 0*/)
48 RS_DEBUG->print("ActionDefault::init");
50 ActionInterface::init(status);
51 v1 = v2 = Vector(false);
52 // snapMode = RS2::SnapFree;
53 // snapRes = RS2::RestrictNothing;
54 restrBak = RS2::RestrictNothing;
55 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
57 RS_DEBUG->print("ActionDefault::init: OK");
60 void ActionDefault::trigger()
62 ActionInterface::trigger();
65 void ActionDefault::keyPressEvent(QKeyEvent * e)
67 if (e->key() == Qt::Key_Shift)
69 // restrBak = snapRes;
70 // setSnapRestriction(RS2::RestrictOrthogonal);
74 void ActionDefault::keyReleaseEvent(QKeyEvent * e)
76 // if (e->key() == Qt::Key_Shift)
77 // setSnapRestriction(restrBak);
80 void ActionDefault::mouseMoveEvent(QMouseEvent * e)
82 Vector mouse = graphicView->toGraph(Vector(e->x(), e->y()));
83 Vector relMouse = mouse - graphicView->getRelativeZero();
85 RS_DIALOGFACTORY->updateCoordinateWidget(mouse, relMouse);
92 if (graphicView->toGuiDX(v1.distanceTo(v2)) > 10)
94 // look for reference points to drag:
96 Vector ref = container->getNearestSelectedRef(v1, &dist);
98 if (ref.valid && graphicView->toGuiDX(dist) < 8)
100 RS_DEBUG->print("ActionDefault::mouseMoveEvent: "
101 "moving reference point");
102 setStatus(MovingRef);
104 graphicView->moveRelativeZero(v1);
108 // test for an entity to drag:
109 RS_Entity * en = graphicView->snapper.catchEntity(v1);
111 if (en && en->isSelected())
113 RS_DEBUG->print("ActionDefault::mouseMoveEvent: "
116 v1 = en->getNearestRef(v1);
117 graphicView->moveRelativeZero(v1);
119 // no entity found. start area selection:
121 setStatus(SetCorner2);
132 // preview->addSelectionFrom(*container);
133 // preview->moveRef(v1, v2 - v1);
142 // preview->addSelectionFrom(*container);
143 // preview->move(v2 - v1);
155 // preview->addEntity(new RS_Line(preview,
156 // RS_LineData(Vector(v1.x, v1.y), Vector(v2.x, v1.y))));
157 // preview->addEntity(new RS_Line(preview,
158 // RS_LineData(Vector(v2.x, v1.y), Vector(v2.x, v2.y))));
159 // preview->addEntity(new RS_Line(preview,
160 // RS_LineData(Vector(v2.x, v2.y), Vector(v1.x, v2.y))));
161 // preview->addEntity(new RS_Line(preview,
162 // RS_LineData(Vector(v1.x, v2.y), Vector(v1.x, v1.y))));
171 void ActionDefault::mousePressEvent(QMouseEvent * e)
173 if (e->button() == Qt::LeftButton)
178 v1 = graphicView->toGraph(e->x(), e->y());
188 RS_Modification m(*container, graphicView);
191 data.useCurrentLayer = false;
192 data.useCurrentAttributes = false;
193 data.offset = v2 - v1;
196 RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
197 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
207 RS_Modification m(*container, graphicView);
210 data.offset = v2 - v1;
213 RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
214 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
224 void ActionDefault::mouseReleaseEvent(QMouseEvent * e)
226 RS_DEBUG->print("ActionDefault::mouseReleaseEvent()");
228 if (e->button() == Qt::LeftButton)
230 v2 = graphicView->toGraph(e->x(), e->y());
236 // select single entity:
237 RS_Entity * en = graphicView->snapper.catchEntity(e);
245 RS_Selection s(*container, graphicView);
248 RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
254 setStatus(SetCorner2);
260 v2 = graphicView->toGraph(e->x(), e->y());
267 bool cross = (v2.y > v1.y);
268 RS_Selection s(*container, graphicView);
269 s.selectWindow(v1, v2, true, cross);
271 RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
282 else if (e->button() == Qt::RightButton)
293 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
298 graphicView->snapper.SetVisible(false);
299 graphicView->preview.SetVisible(false);
300 RS_DIALOGFACTORY->requestPreviousMenu();
307 void ActionDefault::commandEvent(RS_CommandEvent * e)
309 QString c = e->getCommand().toLower();
312 QStringList ActionDefault::getAvailableCommands()
319 void ActionDefault::updateMouseButtonHints()
324 RS_DIALOGFACTORY->updateMouseWidget("", "");
328 RS_DIALOGFACTORY->updateMouseWidget(tr("Drag to second point"), tr("Back"));
332 RS_DIALOGFACTORY->updateMouseWidget("", "");
337 void ActionDefault::updateMouseCursor()
342 graphicView->setMouseCursor(RS2::ArrowCursor);
347 graphicView->setMouseCursor(RS2::SelectCursor);
355 void ActionDefault::updateToolBar()
364 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);