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): ActionInterface("Default",
34 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 // graphicView->snapper.SetVisible();
64 // graphicView->preview.SetVisible();
66 RS_DEBUG->print("ActionDefault::init: OK");
69 void ActionDefault::trigger()
71 ActionInterface::trigger();
74 void ActionDefault::keyPressEvent(QKeyEvent * e)
76 if (e->key() == Qt::Key_Shift)
78 restrBak = graphicView->snapper.getSnapRestriction();
79 graphicView->snapper.setSnapRestriction(RS2::RestrictOrthogonal);
83 void ActionDefault::keyReleaseEvent(QKeyEvent * e)
85 if (e->key() == Qt::Key_Shift)
86 graphicView->snapper.setSnapRestriction(restrBak);
89 void ActionDefault::mouseMoveEvent(QMouseEvent * e)
91 Vector mouse = graphicView->toGraph(Vector(e->x(), e->y()));
92 Vector relMouse = mouse - graphicView->getRelativeZero();
94 RS_DIALOGFACTORY->updateCoordinateWidget(mouse, relMouse);
101 if (graphicView->toGuiDX(v1.distanceTo(v2)) > 10)
103 // look for reference points to drag:
105 Vector ref = container->getNearestSelectedRef(v1, &dist);
107 if (ref.valid && graphicView->toGuiDX(dist) < 8)
109 RS_DEBUG->print("ActionDefault::mouseMoveEvent: moving reference point");
110 setStatus(MovingRef);
112 graphicView->moveRelativeZero(v1);
116 // test for an entity to drag:
117 RS_Entity * en = graphicView->snapper.catchEntity(v1);
119 if (en && en->isSelected())
121 RS_DEBUG->print("ActionDefault::mouseMoveEvent: moving entity");
123 v1 = en->getNearestRef(v1);
124 graphicView->moveRelativeZero(v1);
126 // no entity found. start area selection:
128 setStatus(SetCorner2);
138 // preview->addSelectionFrom(*container);
139 // preview->moveRef(v1, v2 - v1);
141 graphicView->preview.clear();
142 graphicView->preview.addSelectionFrom(*container);
143 graphicView->preview.moveRef(v1, v2 -v1);
144 graphicView->snapper.SetVisible();
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->preview.SetVisible();
161 graphicView->redraw();
169 graphicView->preview.clear();
171 graphicView->preview.addEntity(new RS_Line(&(graphicView->preview),
172 RS_LineData(Vector(v1.x, v1.y), Vector(v2.x, v1.y))));
173 graphicView->preview.addEntity(new RS_Line(&(graphicView->preview),
174 RS_LineData(Vector(v2.x, v1.y), Vector(v2.x, v2.y))));
175 graphicView->preview.addEntity(new RS_Line(&(graphicView->preview),
176 RS_LineData(Vector(v2.x, v2.y), Vector(v1.x, v2.y))));
177 graphicView->preview.addEntity(new RS_Line(&(graphicView->preview),
178 RS_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 RS_Modification m(*container, graphicView);
209 data.useCurrentLayer = false;
210 data.useCurrentAttributes = false;
211 data.offset = v2 - v1;
214 RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
215 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
225 RS_Modification m(*container, graphicView);
228 data.offset = v2 - v1;
231 RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
232 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
242 void ActionDefault::mouseReleaseEvent(QMouseEvent * e)
244 RS_DEBUG->print("ActionDefault::mouseReleaseEvent()");
246 if (e->button() == Qt::LeftButton)
248 v2 = graphicView->toGraph(e->x(), e->y());
254 // select single entity:
255 RS_Entity * en = graphicView->snapper.catchEntity(e);
263 RS_Selection s(*container, graphicView);
266 RS_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 RS_Selection s(*container, graphicView);
288 s.selectWindow(v1, v2, true, cross);
290 RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
298 // Was either moving entity or point, so clear that shiatsu
299 graphicView->snapper.SetVisible(false);
300 graphicView->preview.SetVisible(false);
301 graphicView->redraw();
305 else if (e->button() == Qt::RightButton)
316 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
321 graphicView->snapper.SetVisible(false);
322 graphicView->preview.SetVisible(false);
323 RS_DIALOGFACTORY->requestPreviousMenu();
330 void ActionDefault::commandEvent(RS_CommandEvent * e)
332 QString c = e->getCommand().toLower();
335 QStringList ActionDefault::getAvailableCommands()
342 void ActionDefault::updateMouseButtonHints()
347 RS_DIALOGFACTORY->updateMouseWidget("", "");
351 RS_DIALOGFACTORY->updateMouseWidget(tr("Drag to second point"), tr("Back"));
355 RS_DIALOGFACTORY->updateMouseWidget("", "");
360 void ActionDefault::updateMouseCursor()
365 graphicView->setMouseCursor(RS2::ArrowCursor);
370 graphicView->setMouseCursor(RS2::SelectCursor);
378 void ActionDefault::updateToolBar()
387 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);