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_dialogfactory.h"
20 #include "rs_modification.h"
21 #include "rs_preview.h"
22 #include "rs_snapper.h"
23 #include "rs_selection.h"
28 RS_ActionDefault::RS_ActionDefault(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_PreviewActionInterface("Default",
29 container, graphicView)
31 RS_DEBUG->print("RS_ActionDefault::RS_ActionDefault");
32 RS_DEBUG->print("RS_ActionDefault::RS_ActionDefault: OK");
35 RS_ActionDefault::~RS_ActionDefault()
39 void RS_ActionDefault::init(int status)
41 RS_DEBUG->print("RS_ActionDefault::init");
43 RS_PreviewActionInterface::init(status);
44 v1 = v2 = Vector(false);
45 snapMode = RS2::SnapFree;
46 snapRes = RS2::RestrictNothing;
47 restrBak = RS2::RestrictNothing;
48 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
50 RS_DEBUG->print("RS_ActionDefault::init: OK");
53 void RS_ActionDefault::trigger()
55 RS_PreviewActionInterface::trigger();
58 void RS_ActionDefault::keyPressEvent(QKeyEvent * e)
60 if (e->key() == Qt::Key_Shift)
63 setSnapRestriction(RS2::RestrictOrthogonal);
67 void RS_ActionDefault::keyReleaseEvent(QKeyEvent * e)
69 if (e->key() == Qt::Key_Shift)
70 setSnapRestriction(restrBak);
73 void RS_ActionDefault::mouseMoveEvent(QMouseEvent * e)
75 Vector mouse = graphicView->toGraph(Vector(e->x(), e->y()));
76 Vector relMouse = mouse - graphicView->getRelativeZero();
78 RS_DIALOGFACTORY->updateCoordinateWidget(mouse, relMouse);
83 //v2 = graphicView->toGraph(e->x(), e->y());
86 if (graphicView->toGuiDX(v1.distanceTo(v2)) > 10)
88 // look for reference points to drag:
90 Vector ref = container->getNearestSelectedRef(v1, &dist);
92 if (ref.valid == true && graphicView->toGuiDX(dist) < 8)
94 RS_DEBUG->print("RS_ActionDefault::mouseMoveEvent: "
95 "moving reference point");
98 graphicView->moveRelativeZero(v1);
102 // test for an entity to drag:
103 RS_Entity * en = catchEntity(v1);
105 if (en != NULL && en->isSelected())
107 RS_DEBUG->print("RS_ActionDefault::mouseMoveEvent: "
110 v1 = en->getNearestRef(v1);
111 graphicView->moveRelativeZero(v1);
113 // no entity found. start area selection:
115 setStatus(SetCorner2);
125 preview->addSelectionFrom(*container);
126 preview->moveRef(v1, v2 - v1);
135 preview->addSelectionFrom(*container);
136 preview->move(v2 - v1);
151 preview->addEntity(new RS_Line(preview,
152 RS_LineData(Vector(v1.x, v1.y), Vector(v2.x, v1.y))));
153 preview->addEntity(new RS_Line(preview,
154 RS_LineData(Vector(v2.x, v1.y), Vector(v2.x, v2.y))));
155 preview->addEntity(new RS_Line(preview,
156 RS_LineData(Vector(v2.x, v2.y), Vector(v1.x, v2.y))));
157 preview->addEntity(new RS_Line(preview,
158 RS_LineData(Vector(v1.x, v2.y), Vector(v1.x, v1.y))));
167 void RS_ActionDefault::mousePressEvent(QMouseEvent * e)
169 if (e->button() == Qt::LeftButton)
174 v1 = graphicView->toGraph(e->x(), e->y());
184 RS_Modification m(*container, graphicView);
187 data.useCurrentLayer = false;
188 data.useCurrentAttributes = false;
189 data.offset = v2 - v1;
192 RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
193 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
203 RS_Modification m(*container, graphicView);
206 data.offset = v2 - v1;
208 //container->moveSelectedRef(v1, v2-v2);
210 RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
211 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
221 void RS_ActionDefault::mouseReleaseEvent(QMouseEvent * e)
223 RS_DEBUG->print("RS_ActionDefault::mouseReleaseEvent()");
225 if (e->button() == Qt::LeftButton)
227 v2 = graphicView->toGraph(e->x(), e->y());
233 // select single entity:
234 RS_Entity * en = catchEntity(e);
242 RS_Selection s(*container, graphicView);
245 RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
252 setStatus(SetCorner2);
259 v2 = graphicView->toGraph(e->x(), e->y());
262 //if (graphicView->toGuiDX(v1.distanceTo(v2))>20) {
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());
283 else if (e->button() == Qt::RightButton)
294 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
300 RS_DIALOGFACTORY->requestPreviousMenu();
307 void RS_ActionDefault::commandEvent(RS_CommandEvent * e)
309 QString c = e->getCommand().toLower();
311 // if the current action can't deal with the command,
312 // it might be intended to launch a new command
313 //if (!e.isAccepted()) {
314 // command for new action:
315 //RS2::ActionType type = RS_COMMANDS->cmdToAction(c);
316 //if (type!=RS2::ActionNone) {
317 //graphicView->setCurrentAction(type);
323 QStringList RS_ActionDefault::getAvailableCommands()
328 //cmd += "rectangle";
333 void RS_ActionDefault::updateMouseButtonHints()
338 RS_DIALOGFACTORY->updateMouseWidget("", "");
342 RS_DIALOGFACTORY->updateMouseWidget(tr("Choose second edge"), tr("Back"));
346 RS_DIALOGFACTORY->updateMouseWidget("", "");
351 void RS_ActionDefault::updateMouseCursor()
356 graphicView->setMouseCursor(RS2::ArrowCursor);
361 graphicView->setMouseCursor(RS2::SelectCursor);
369 void RS_ActionDefault::updateToolBar()
371 //RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
375 // would switch back to main in edit / measure / .. modes
376 //RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
381 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);