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 "rs_commandevent.h"
22 #include "rs_dialogfactory.h"
24 #include "rs_modification.h"
25 #include "rs_preview.h"
26 #include "rs_snapper.h"
27 #include "rs_selection.h"
32 ActionDefault::ActionDefault(RS_EntityContainer & container,
33 GraphicView & graphicView):
34 ActionInterface("Default", container, graphicView)
36 RS_DEBUG->print("ActionDefault::ActionDefault");
38 // graphicView.snapper.SetVisible();
39 // graphicView.preview.SetVisible();
40 RS_DEBUG->print("ActionDefault::ActionDefault: OK");
43 ActionDefault::~ActionDefault()
47 /*virtual*/ RS2::ActionType ActionDefault::rtti()
49 return RS2::ActionDefault;
52 void ActionDefault::init(int status /*= 0*/)
54 RS_DEBUG->print("ActionDefault::init");
56 ActionInterface::init(status);
57 v1 = v2 = Vector(false);
58 graphicView->snapper.setSnapMode(RS2::SnapFree);
59 graphicView->snapper.setSnapRestriction(RS2::RestrictNothing);
60 restrBak = RS2::RestrictNothing;
61 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
63 RS_DEBUG->print("ActionDefault::init: OK");
66 void ActionDefault::trigger()
68 ActionInterface::trigger();
71 void ActionDefault::keyPressEvent(QKeyEvent * e)
73 if (e->key() == Qt::Key_Shift)
75 restrBak = graphicView->snapper.getSnapRestriction();
76 graphicView->snapper.setSnapRestriction(RS2::RestrictOrthogonal);
80 void ActionDefault::keyReleaseEvent(QKeyEvent * e)
82 if (e->key() == Qt::Key_Shift)
83 graphicView->snapper.setSnapRestriction(restrBak);
86 void ActionDefault::mouseMoveEvent(QMouseEvent * e)
88 Vector mouse = graphicView->toGraph(Vector(e->x(), e->y()));
89 Vector relMouse = mouse - graphicView->getRelativeZero();
91 RS_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 RS_DEBUG->print("ActionDefault::mouseMoveEvent: moving reference point");
107 setStatus(MovingRef);
109 graphicView->moveRelativeZero(v1);
113 // test for an entity to drag:
114 RS_Entity * en = graphicView->snapper.catchEntity(v1);
116 if (en && en->isSelected())
118 RS_DEBUG->print("ActionDefault::mouseMoveEvent: moving entity");
120 v1 = en->getNearestRef(v1);
121 graphicView->moveRelativeZero(v1);
123 // no entity found. start area selection:
125 setStatus(SetCorner2);
135 // preview->addSelectionFrom(*container);
136 // preview->moveRef(v1, v2 - v1);
138 graphicView->preview.clear();
139 graphicView->preview.addSelectionFrom(*container);
140 graphicView->preview.moveRef(v1, v2 -v1);
141 graphicView->snapper.SetVisible();
142 graphicView->preview.SetVisible();
143 graphicView->redraw();
150 // preview->addSelectionFrom(*container);
151 // preview->move(v2 - v1);
153 graphicView->preview.clear();
154 graphicView->preview.addSelectionFrom(*container);
155 graphicView->preview.move(v2 -v1);
156 graphicView->snapper.SetVisible();
157 graphicView->preview.SetVisible();
158 graphicView->redraw();
166 graphicView->preview.clear();
168 graphicView->preview.addEntity(new RS_Line(&(graphicView->preview),
169 RS_LineData(Vector(v1.x, v1.y), Vector(v2.x, v1.y))));
170 graphicView->preview.addEntity(new RS_Line(&(graphicView->preview),
171 RS_LineData(Vector(v2.x, v1.y), Vector(v2.x, v2.y))));
172 graphicView->preview.addEntity(new RS_Line(&(graphicView->preview),
173 RS_LineData(Vector(v2.x, v2.y), Vector(v1.x, v2.y))));
174 graphicView->preview.addEntity(new RS_Line(&(graphicView->preview),
175 RS_LineData(Vector(v1.x, v2.y), Vector(v1.x, v1.y))));
177 graphicView->preview.SetVisible();
178 graphicView->redraw();
186 void ActionDefault::mousePressEvent(QMouseEvent * e)
188 if (e->button() == Qt::LeftButton)
193 v1 = graphicView->toGraph(e->x(), e->y());
203 RS_Modification m(*container, graphicView);
206 data.useCurrentLayer = false;
207 data.useCurrentAttributes = false;
208 data.offset = v2 - v1;
211 RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
212 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
222 RS_Modification m(*container, graphicView);
225 data.offset = v2 - v1;
228 RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
229 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
239 void ActionDefault::mouseReleaseEvent(QMouseEvent * e)
241 RS_DEBUG->print("ActionDefault::mouseReleaseEvent()");
243 if (e->button() == Qt::LeftButton)
245 v2 = graphicView->toGraph(e->x(), e->y());
251 // select single entity:
252 RS_Entity * en = graphicView->snapper.catchEntity(e);
260 RS_Selection s(*container, graphicView);
263 RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
269 setStatus(SetCorner2);
275 v2 = graphicView->toGraph(e->x(), e->y());
281 graphicView->preview.SetVisible(false);
283 bool cross = (v2.y > v1.y);
284 RS_Selection s(*container, graphicView);
285 s.selectWindow(v1, v2, true, cross);
287 RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
295 // Was either moving entity or point, so clear that shiatsu
296 graphicView->snapper.SetVisible(false);
297 graphicView->preview.SetVisible(false);
298 graphicView->redraw();
302 else if (e->button() == Qt::RightButton)
313 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
318 graphicView->snapper.SetVisible(false);
319 graphicView->preview.SetVisible(false);
320 RS_DIALOGFACTORY->requestPreviousMenu();
327 void ActionDefault::commandEvent(RS_CommandEvent * e)
329 QString c = e->getCommand().toLower();
332 QStringList ActionDefault::getAvailableCommands()
339 void ActionDefault::updateMouseButtonHints()
344 RS_DIALOGFACTORY->updateMouseWidget("", "");
348 RS_DIALOGFACTORY->updateMouseWidget(tr("Drag to second point"), tr("Back"));
352 RS_DIALOGFACTORY->updateMouseWidget("", "");
357 void ActionDefault::updateMouseCursor()
362 graphicView->setMouseCursor(RS2::ArrowCursor);
367 graphicView->setMouseCursor(RS2::SelectCursor);
375 void ActionDefault::updateToolBar()
384 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);