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"
21 #include "rs_dialogfactory.h"
23 #include "rs_modification.h"
24 #include "rs_preview.h"
25 #include "rs_snapper.h"
26 #include "rs_selection.h"
31 ActionDefault::ActionDefault(RS_EntityContainer & container,
32 GraphicView & graphicView): ActionInterface("Default",
33 container, graphicView)
35 RS_DEBUG->print("ActionDefault::ActionDefault");
37 graphicView.snapper.SetVisible();
38 graphicView.preview.SetVisible();
39 RS_DEBUG->print("ActionDefault::ActionDefault: OK");
42 ActionDefault::~ActionDefault()
46 /*virtual*/ RS2::ActionType ActionDefault::rtti()
48 return RS2::ActionDefault;
51 void ActionDefault::init(int status /*= 0*/)
53 RS_DEBUG->print("ActionDefault::init");
55 ActionInterface::init(status);
56 v1 = v2 = Vector(false);
57 graphicView->snapper.setSnapMode(RS2::SnapFree);
58 graphicView->snapper.setSnapRestriction(RS2::RestrictNothing);
59 restrBak = RS2::RestrictNothing;
60 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
62 // graphicView->snapper.SetVisible();
63 // graphicView->preview.SetVisible();
65 RS_DEBUG->print("ActionDefault::init: OK");
68 void ActionDefault::trigger()
70 ActionInterface::trigger();
73 void ActionDefault::keyPressEvent(QKeyEvent * e)
75 if (e->key() == Qt::Key_Shift)
77 restrBak = graphicView->snapper.getSnapRestriction();
78 graphicView->snapper.setSnapRestriction(RS2::RestrictOrthogonal);
82 void ActionDefault::keyReleaseEvent(QKeyEvent * e)
84 if (e->key() == Qt::Key_Shift)
85 graphicView->snapper.setSnapRestriction(restrBak);
88 void ActionDefault::mouseMoveEvent(QMouseEvent * e)
90 Vector mouse = graphicView->toGraph(Vector(e->x(), e->y()));
91 Vector relMouse = mouse - graphicView->getRelativeZero();
93 RS_DIALOGFACTORY->updateCoordinateWidget(mouse, relMouse);
100 if (graphicView->toGuiDX(v1.distanceTo(v2)) > 10)
102 // look for reference points to drag:
104 Vector ref = container->getNearestSelectedRef(v1, &dist);
106 if (ref.valid && graphicView->toGuiDX(dist) < 8)
108 RS_DEBUG->print("ActionDefault::mouseMoveEvent: moving reference point");
109 setStatus(MovingRef);
111 graphicView->moveRelativeZero(v1);
115 // test for an entity to drag:
116 RS_Entity * en = graphicView->snapper.catchEntity(v1);
118 if (en && en->isSelected())
120 RS_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->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->preview.SetVisible();
160 graphicView->redraw();
168 graphicView->preview.clear();
170 graphicView->preview.addEntity(new RS_Line(&(graphicView->preview),
171 RS_LineData(Vector(v1.x, v1.y), Vector(v2.x, v1.y))));
172 graphicView->preview.addEntity(new RS_Line(&(graphicView->preview),
173 RS_LineData(Vector(v2.x, v1.y), Vector(v2.x, v2.y))));
174 graphicView->preview.addEntity(new RS_Line(&(graphicView->preview),
175 RS_LineData(Vector(v2.x, v2.y), Vector(v1.x, v2.y))));
176 graphicView->preview.addEntity(new RS_Line(&(graphicView->preview),
177 RS_LineData(Vector(v1.x, v2.y), Vector(v1.x, v1.y))));
179 graphicView->preview.SetVisible();
180 graphicView->redraw();
188 void ActionDefault::mousePressEvent(QMouseEvent * e)
190 if (e->button() == Qt::LeftButton)
195 v1 = graphicView->toGraph(e->x(), e->y());
205 RS_Modification m(*container, graphicView);
208 data.useCurrentLayer = false;
209 data.useCurrentAttributes = false;
210 data.offset = v2 - v1;
213 RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
214 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
224 RS_Modification m(*container, graphicView);
227 data.offset = v2 - v1;
230 RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
231 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
241 void ActionDefault::mouseReleaseEvent(QMouseEvent * e)
243 RS_DEBUG->print("ActionDefault::mouseReleaseEvent()");
245 if (e->button() == Qt::LeftButton)
247 v2 = graphicView->toGraph(e->x(), e->y());
253 // select single entity:
254 RS_Entity * en = graphicView->snapper.catchEntity(e);
262 RS_Selection s(*container, graphicView);
265 RS_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 RS_Selection s(*container, graphicView);
287 s.selectWindow(v1, v2, true, cross);
289 RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
297 // Was either moving entity or point, so clear that shiatsu
298 graphicView->snapper.SetVisible(false);
299 graphicView->preview.SetVisible(false);
300 graphicView->redraw();
304 else if (e->button() == Qt::RightButton)
315 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
320 graphicView->snapper.SetVisible(false);
321 graphicView->preview.SetVisible(false);
322 RS_DIALOGFACTORY->requestPreviousMenu();
329 void ActionDefault::commandEvent(RS_CommandEvent * e)
331 QString c = e->getCommand().toLower();
334 QStringList ActionDefault::getAvailableCommands()
341 void ActionDefault::updateMouseButtonHints()
346 RS_DIALOGFACTORY->updateMouseWidget("", "");
350 RS_DIALOGFACTORY->updateMouseWidget(tr("Drag to second point"), tr("Back"));
354 RS_DIALOGFACTORY->updateMouseWidget("", "");
359 void ActionDefault::updateMouseCursor()
364 graphicView->setMouseCursor(RS2::ArrowCursor);
369 graphicView->setMouseCursor(RS2::SelectCursor);
377 void ActionDefault::updateToolBar()
386 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);