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/03/2010 Added this text. :-)
17 #include "actiondefault.h"
20 #include "commandevent.h"
22 #include "dialogfactory.h"
24 #include "modification.h"
26 #include "selection.h"
31 ActionDefault::ActionDefault(EntityContainer & container,
32 GraphicView & graphicView):
33 ActionInterface("Default", container, graphicView)
35 DEBUG->print("ActionDefault::ActionDefault");
36 DEBUG->print("ActionDefault::ActionDefault: OK");
39 ActionDefault::~ActionDefault()
43 /*virtual*/ RS2::ActionType ActionDefault::rtti()
45 return RS2::ActionDefault;
48 void ActionDefault::init(int status /*= 0*/)
50 DEBUG->print("ActionDefault::init");
52 ActionInterface::init(status);
53 v1 = v2 = Vector(false);
54 // graphicView->snapper.setSnapMode(RS2::SnapFree);
55 // graphicView->snapper.setSnapRestriction(RS2::RestrictNothing);
56 graphicView->setDefaultSnapMode(RS2::SnapFree);
57 graphicView->setSnapRestriction(RS2::RestrictNothing);
58 restrBak = RS2::RestrictNothing;
59 DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
61 DEBUG->print("ActionDefault::init: OK");
64 void ActionDefault::trigger()
66 ActionInterface::trigger();
69 void ActionDefault::keyPressEvent(QKeyEvent * e)
71 if (e->key() == Qt::Key_Shift)
73 // restrBak = graphicView->snapper.getSnapRestriction();
74 // graphicView->snapper.setSnapRestriction(RS2::RestrictOrthogonal);
75 restrBak = graphicView->getSnapRestriction();
76 graphicView->setSnapRestriction(RS2::RestrictOrthogonal);
80 void ActionDefault::keyReleaseEvent(QKeyEvent * e)
82 if (e->key() == Qt::Key_Shift)
83 // graphicView->snapper.setSnapRestriction(restrBak);
84 graphicView->setSnapRestriction(restrBak);
87 void ActionDefault::mouseMoveEvent(QMouseEvent * e)
89 Vector mouse = graphicView->toGraph(Vector(e->x(), e->y()));
90 Vector relMouse = mouse - graphicView->getRelativeZero();
91 DIALOGFACTORY->updateCoordinateWidget(mouse, relMouse);
98 if (graphicView->toGuiDX(v1.distanceTo(v2)) > 10)
100 // look for reference points to drag:
102 Vector ref = container->getNearestSelectedRef(v1, &dist);
104 if (ref.valid && graphicView->toGuiDX(dist) < 8)
106 DEBUG->print("ActionDefault::mouseMoveEvent: moving reference point");
107 setStatus(MovingRef);
109 graphicView->moveRelativeZero(v1);
113 // test for an entity to drag:
114 // Entity * en = graphicView->snapper.catchEntity(v1);
115 Entity * en = graphicView->CatchEntity(v1);
117 if (en && en->isSelected())
119 DEBUG->print("ActionDefault::mouseMoveEvent: moving entity");
121 v1 = en->getNearestRef(v1);
122 graphicView->moveRelativeZero(v1);
124 // no entity found. start area selection:
126 setStatus(SetCorner2);
136 // preview->addSelectionFrom(*container);
137 // preview->moveRef(v1, v2 - v1);
139 graphicView->preview.clear();
140 graphicView->preview.addSelectionFrom(*container);
141 graphicView->preview.moveRef(v1, v2 -v1);
142 // graphicView->snapper.SetVisible();
143 graphicView->SetSnapperVisible();
144 graphicView->preview.SetVisible();
145 graphicView->redraw();
152 // preview->addSelectionFrom(*container);
153 // preview->move(v2 - v1);
155 graphicView->preview.clear();
156 graphicView->preview.addSelectionFrom(*container);
157 graphicView->preview.move(v2 -v1);
158 // graphicView->snapper.SetVisible();
159 graphicView->SetSnapperVisible();
160 graphicView->preview.SetVisible();
161 graphicView->redraw();
169 graphicView->preview.clear();
171 graphicView->preview.addEntity(new Line(&(graphicView->preview),
172 LineData(Vector(v1.x, v1.y), Vector(v2.x, v1.y))));
173 graphicView->preview.addEntity(new Line(&(graphicView->preview),
174 LineData(Vector(v2.x, v1.y), Vector(v2.x, v2.y))));
175 graphicView->preview.addEntity(new Line(&(graphicView->preview),
176 LineData(Vector(v2.x, v2.y), Vector(v1.x, v2.y))));
177 graphicView->preview.addEntity(new Line(&(graphicView->preview),
178 LineData(Vector(v1.x, v2.y), Vector(v1.x, v1.y))));
180 graphicView->preview.SetVisible();
181 graphicView->redraw();
189 void ActionDefault::mousePressEvent(QMouseEvent * e)
191 if (e->button() == Qt::LeftButton)
196 v1 = graphicView->toGraph(e->x(), e->y());
206 Modification m(*container, graphicView);
209 data.useCurrentLayer = false;
210 data.useCurrentAttributes = false;
211 data.offset = v2 - v1;
214 DIALOGFACTORY->updateSelectionWidget(container->countSelected());
215 DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
225 Modification m(*container, graphicView);
228 data.offset = v2 - v1;
231 DIALOGFACTORY->updateSelectionWidget(container->countSelected());
232 DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
242 void ActionDefault::mouseReleaseEvent(QMouseEvent * e)
244 DEBUG->print("ActionDefault::mouseReleaseEvent()");
246 if (e->button() == Qt::LeftButton)
248 v2 = graphicView->toGraph(e->x(), e->y());
254 // select single entity:
255 // Entity * en = graphicView->snapper.catchEntity(e);
256 Entity * en = graphicView->CatchEntity(e);
264 Selection s(*container, graphicView);
266 DIALOGFACTORY->updateSelectionWidget(container->countSelected());
271 setStatus(SetCorner2);
277 v2 = graphicView->toGraph(e->x(), e->y());
283 graphicView->preview.SetVisible(false);
285 bool cross = (v2.y > v1.y);
286 Selection s(*container, graphicView);
287 s.selectWindow(v1, v2, true, cross);
289 DIALOGFACTORY->updateSelectionWidget(container->countSelected());
297 // Was either moving entity or point, so clear that shiatsu
298 // graphicView->snapper.SetVisible(false);
299 graphicView->SetSnapperVisible(false);
300 graphicView->preview.SetVisible(false);
301 graphicView->redraw();
305 else if (e->button() == Qt::RightButton)
316 DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
321 // graphicView->snapper.SetVisible(false);
322 graphicView->SetSnapperVisible(false);
323 graphicView->preview.SetVisible(false);
324 DIALOGFACTORY->requestPreviousMenu();
331 void ActionDefault::commandEvent(CommandEvent * e)
333 QString c = e->getCommand().toLower();
336 QStringList ActionDefault::getAvailableCommands()
343 void ActionDefault::updateMouseButtonHints()
348 DIALOGFACTORY->updateMouseWidget("", "");
352 DIALOGFACTORY->updateMouseWidget(tr("Drag to second point"), tr("Back"));
356 DIALOGFACTORY->updateMouseWidget("", "");
361 void ActionDefault::updateMouseCursor()
366 graphicView->setMouseCursor(RS2::ArrowCursor);
371 graphicView->setMouseCursor(RS2::SelectCursor);
379 void ActionDefault::updateToolBar()
388 DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);