1 // rs_actiondefault.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/03/2010 Added this text. :-)
15 #include "rs_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 RS_ActionDefault::RS_ActionDefault(RS_EntityContainer & container, GraphicView & graphicView): RS_PreviewActionInterface("Default",
30 container, graphicView)
32 RS_DEBUG->print("RS_ActionDefault::RS_ActionDefault");
33 RS_DEBUG->print("RS_ActionDefault::RS_ActionDefault: OK");
36 RS_ActionDefault::~RS_ActionDefault()
40 void RS_ActionDefault::init(int status)
42 RS_DEBUG->print("RS_ActionDefault::init");
44 RS_PreviewActionInterface::init(status);
45 v1 = v2 = Vector(false);
46 snapMode = RS2::SnapFree;
47 snapRes = RS2::RestrictNothing;
48 restrBak = RS2::RestrictNothing;
49 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
51 RS_DEBUG->print("RS_ActionDefault::init: OK");
54 void RS_ActionDefault::trigger()
56 RS_PreviewActionInterface::trigger();
59 void RS_ActionDefault::keyPressEvent(QKeyEvent * e)
61 if (e->key() == Qt::Key_Shift)
64 setSnapRestriction(RS2::RestrictOrthogonal);
68 void RS_ActionDefault::keyReleaseEvent(QKeyEvent * e)
70 if (e->key() == Qt::Key_Shift)
71 setSnapRestriction(restrBak);
74 void RS_ActionDefault::mouseMoveEvent(QMouseEvent * e)
76 Vector mouse = graphicView->toGraph(Vector(e->x(), e->y()));
77 Vector relMouse = mouse - graphicView->getRelativeZero();
79 RS_DIALOGFACTORY->updateCoordinateWidget(mouse, relMouse);
84 //v2 = graphicView->toGraph(e->x(), e->y());
87 if (graphicView->toGuiDX(v1.distanceTo(v2)) > 10)
89 // look for reference points to drag:
91 Vector ref = container->getNearestSelectedRef(v1, &dist);
93 if (ref.valid == true && graphicView->toGuiDX(dist) < 8)
95 RS_DEBUG->print("RS_ActionDefault::mouseMoveEvent: "
96 "moving reference point");
99 graphicView->moveRelativeZero(v1);
103 // test for an entity to drag:
104 RS_Entity * en = catchEntity(v1);
106 if (en != NULL && en->isSelected())
108 RS_DEBUG->print("RS_ActionDefault::mouseMoveEvent: "
111 v1 = en->getNearestRef(v1);
112 graphicView->moveRelativeZero(v1);
114 // no entity found. start area selection:
116 setStatus(SetCorner2);
126 preview->addSelectionFrom(*container);
127 preview->moveRef(v1, v2 - v1);
136 preview->addSelectionFrom(*container);
137 preview->move(v2 - v1);
152 preview->addEntity(new RS_Line(preview,
153 RS_LineData(Vector(v1.x, v1.y), Vector(v2.x, v1.y))));
154 preview->addEntity(new RS_Line(preview,
155 RS_LineData(Vector(v2.x, v1.y), Vector(v2.x, v2.y))));
156 preview->addEntity(new RS_Line(preview,
157 RS_LineData(Vector(v2.x, v2.y), Vector(v1.x, v2.y))));
158 preview->addEntity(new RS_Line(preview,
159 RS_LineData(Vector(v1.x, v2.y), Vector(v1.x, v1.y))));
168 void RS_ActionDefault::mousePressEvent(QMouseEvent * e)
170 if (e->button() == Qt::LeftButton)
175 v1 = graphicView->toGraph(e->x(), e->y());
185 RS_Modification m(*container, graphicView);
188 data.useCurrentLayer = false;
189 data.useCurrentAttributes = false;
190 data.offset = v2 - v1;
193 RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
194 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
204 RS_Modification m(*container, graphicView);
207 data.offset = v2 - v1;
209 //container->moveSelectedRef(v1, v2-v2);
211 RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
212 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
222 void RS_ActionDefault::mouseReleaseEvent(QMouseEvent * e)
224 RS_DEBUG->print("RS_ActionDefault::mouseReleaseEvent()");
226 if (e->button() == Qt::LeftButton)
228 v2 = graphicView->toGraph(e->x(), e->y());
234 // select single entity:
235 RS_Entity * en = catchEntity(e);
243 RS_Selection s(*container, graphicView);
246 RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
253 setStatus(SetCorner2);
260 v2 = graphicView->toGraph(e->x(), e->y());
263 //if (graphicView->toGuiDX(v1.distanceTo(v2))>20) {
268 bool cross = (v2.y > v1.y);
269 RS_Selection s(*container, graphicView);
270 s.selectWindow(v1, v2, true, cross);
272 RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
284 else if (e->button() == Qt::RightButton)
295 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
301 RS_DIALOGFACTORY->requestPreviousMenu();
308 void RS_ActionDefault::commandEvent(RS_CommandEvent * e)
310 QString c = e->getCommand().toLower();
312 // if the current action can't deal with the command,
313 // it might be intended to launch a new command
314 //if (!e.isAccepted()) {
315 // command for new action:
316 //RS2::ActionType type = RS_COMMANDS->cmdToAction(c);
317 //if (type!=RS2::ActionNone) {
318 //graphicView->setCurrentAction(type);
324 QStringList RS_ActionDefault::getAvailableCommands()
329 //cmd += "rectangle";
334 void RS_ActionDefault::updateMouseButtonHints()
339 RS_DIALOGFACTORY->updateMouseWidget("", "");
343 RS_DIALOGFACTORY->updateMouseWidget(tr("Choose second edge"), tr("Back"));
347 RS_DIALOGFACTORY->updateMouseWidget("", "");
352 void RS_ActionDefault::updateMouseCursor()
357 graphicView->setMouseCursor(RS2::ArrowCursor);
362 graphicView->setMouseCursor(RS2::SelectCursor);
370 void RS_ActionDefault::updateToolBar()
372 //RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
376 // would switch back to main in edit / measure / .. modes
377 //RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
382 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);