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"
27 #include "selection.h"
32 ActionDefault::ActionDefault(EntityContainer & container,
33 GraphicView & graphicView):
34 ActionInterface("Default", container, graphicView)
36 DEBUG->print("ActionDefault::ActionDefault");
37 DEBUG->print("ActionDefault::ActionDefault: OK");
40 ActionDefault::~ActionDefault()
44 /*virtual*/ RS2::ActionType ActionDefault::rtti()
46 return RS2::ActionDefault;
49 void ActionDefault::init(int status /*= 0*/)
51 DEBUG->print("ActionDefault::init");
53 ActionInterface::init(status);
54 v1 = v2 = Vector(false);
55 // graphicView->snapper.setSnapMode(RS2::SnapFree);
56 // graphicView->snapper.setSnapRestriction(RS2::RestrictNothing);
57 graphicView->setDefaultSnapMode(RS2::SnapFree);
58 graphicView->setSnapRestriction(RS2::RestrictNothing);
59 restrBak = RS2::RestrictNothing;
60 DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
62 DEBUG->print("ActionDefault::init: OK");
65 void ActionDefault::trigger()
67 ActionInterface::trigger();
70 void ActionDefault::keyPressEvent(QKeyEvent * e)
72 if (e->key() == Qt::Key_Shift)
74 // restrBak = graphicView->snapper.getSnapRestriction();
75 // graphicView->snapper.setSnapRestriction(RS2::RestrictOrthogonal);
76 restrBak = graphicView->getSnapRestriction();
77 graphicView->setSnapRestriction(RS2::RestrictOrthogonal);
81 void ActionDefault::keyReleaseEvent(QKeyEvent * e)
83 if (e->key() == Qt::Key_Shift)
84 // graphicView->snapper.setSnapRestriction(restrBak);
85 graphicView->setSnapRestriction(restrBak);
88 void ActionDefault::mouseMoveEvent(QMouseEvent * e)
90 Vector mouse = graphicView->toGraph(Vector(e->x(), e->y()));
91 Vector relMouse = mouse - graphicView->getRelativeZero();
92 DIALOGFACTORY->updateCoordinateWidget(mouse, relMouse);
99 if (graphicView->toGuiDX(v1.distanceTo(v2)) > 10)
101 // look for reference points to drag:
103 Vector ref = container->getNearestSelectedRef(v1, &dist);
105 if (ref.valid && graphicView->toGuiDX(dist) < 8)
107 DEBUG->print("ActionDefault::mouseMoveEvent: moving reference point");
108 setStatus(MovingRef);
110 graphicView->moveRelativeZero(v1);
114 // test for an entity to drag:
115 // Entity * en = graphicView->snapper.catchEntity(v1);
116 Entity * en = graphicView->CatchEntity(v1);
118 if (en && en->isSelected())
120 DEBUG->print("ActionDefault::mouseMoveEvent: moving entity");
122 v1 = en->getNearestRef(v1);
123 graphicView->moveRelativeZero(v1);
125 // no entity found. start area selection:
127 setStatus(SetCorner2);
137 // preview->addSelectionFrom(*container);
138 // preview->moveRef(v1, v2 - v1);
140 graphicView->preview.clear();
141 graphicView->preview.addSelectionFrom(*container);
142 graphicView->preview.moveRef(v1, v2 -v1);
143 // graphicView->snapper.SetVisible();
144 graphicView->SetSnapperVisible();
145 graphicView->preview.SetVisible();
146 graphicView->redraw();
153 // preview->addSelectionFrom(*container);
154 // preview->move(v2 - v1);
156 graphicView->preview.clear();
157 graphicView->preview.addSelectionFrom(*container);
158 graphicView->preview.move(v2 -v1);
159 // graphicView->snapper.SetVisible();
160 graphicView->SetSnapperVisible();
161 graphicView->preview.SetVisible();
162 graphicView->redraw();
170 graphicView->preview.clear();
172 graphicView->preview.addEntity(new Line(&(graphicView->preview),
173 LineData(Vector(v1.x, v1.y), Vector(v2.x, v1.y))));
174 graphicView->preview.addEntity(new Line(&(graphicView->preview),
175 LineData(Vector(v2.x, v1.y), Vector(v2.x, v2.y))));
176 graphicView->preview.addEntity(new Line(&(graphicView->preview),
177 LineData(Vector(v2.x, v2.y), Vector(v1.x, v2.y))));
178 graphicView->preview.addEntity(new Line(&(graphicView->preview),
179 LineData(Vector(v1.x, v2.y), Vector(v1.x, v1.y))));
181 graphicView->preview.SetVisible();
182 graphicView->redraw();
190 void ActionDefault::mousePressEvent(QMouseEvent * e)
192 if (e->button() == Qt::LeftButton)
197 v1 = graphicView->toGraph(e->x(), e->y());
207 Modification m(*container, graphicView);
210 data.useCurrentLayer = false;
211 data.useCurrentAttributes = false;
212 data.offset = v2 - v1;
215 DIALOGFACTORY->updateSelectionWidget(container->countSelected());
216 DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
226 Modification m(*container, graphicView);
229 data.offset = v2 - v1;
232 DIALOGFACTORY->updateSelectionWidget(container->countSelected());
233 DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
243 void ActionDefault::mouseReleaseEvent(QMouseEvent * e)
245 DEBUG->print("ActionDefault::mouseReleaseEvent()");
247 if (e->button() == Qt::LeftButton)
249 v2 = graphicView->toGraph(e->x(), e->y());
255 // select single entity:
256 // Entity * en = graphicView->snapper.catchEntity(e);
257 Entity * en = graphicView->CatchEntity(e);
265 Selection s(*container, graphicView);
267 DIALOGFACTORY->updateSelectionWidget(container->countSelected());
272 setStatus(SetCorner2);
278 v2 = graphicView->toGraph(e->x(), e->y());
284 graphicView->preview.SetVisible(false);
286 bool cross = (v2.y > v1.y);
287 Selection s(*container, graphicView);
288 s.selectWindow(v1, v2, true, cross);
290 DIALOGFACTORY->updateSelectionWidget(container->countSelected());
298 // Was either moving entity or point, so clear that shiatsu
299 // graphicView->snapper.SetVisible(false);
300 graphicView->SetSnapperVisible(false);
301 graphicView->preview.SetVisible(false);
302 graphicView->redraw();
306 else if (e->button() == Qt::RightButton)
317 DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
322 // graphicView->snapper.SetVisible(false);
323 graphicView->SetSnapperVisible(false);
324 graphicView->preview.SetVisible(false);
325 DIALOGFACTORY->requestPreviousMenu();
332 void ActionDefault::commandEvent(CommandEvent * e)
334 QString c = e->getCommand().toLower();
337 QStringList ActionDefault::getAvailableCommands()
344 void ActionDefault::updateMouseButtonHints()
349 DIALOGFACTORY->updateMouseWidget("", "");
353 DIALOGFACTORY->updateMouseWidget(tr("Drag to second point"), tr("Back"));
357 DIALOGFACTORY->updateMouseWidget("", "");
362 void ActionDefault::updateMouseCursor()
367 graphicView->setMouseCursor(RS2::ArrowCursor);
372 graphicView->setMouseCursor(RS2::SelectCursor);
380 void ActionDefault::updateToolBar()
389 DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);