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 05/22/2010 Added this text. :-)
17 #include "actioninterface.h"
21 #include "rs_entitycontainer.h"
22 #include "graphicview.h"
27 * Sets the entity container on which the action class inherited
28 * from this interface operates.
30 * @param name Action name. This can be used internally for
32 * @param container Entity container this action operates on.
33 * @param graphicView Graphic view instance this action operates on.
34 * Please note that an action belongs to this
36 * @param cursor Default mouse cursor for this action. If the action
37 * is suspended and resumed again the cursor will always
38 * be reset to the one given here.
40 ActionInterface::ActionInterface(const char * name, RS_EntityContainer & c,
41 GraphicView & v): graphicView(&v), container(&c)
43 RS_DEBUG->print("ActionInterface::ActionInterface: Setting up action: \"%s\"", name);
49 // Graphic provides a pointer to the graphic if the entity container is a
50 //graphic (i.e. can also hold layers).
51 graphic = c.getGraphic();
53 // Document pointer will be used for undo / redo
54 document = c.getDocument();
56 // This is here until I can figure out a better way to contain all of this
57 // circular referential nonsense that exists in this codebase. It will be
58 // expunged, by Grabthar's Hammer!
59 graphicView->snapper.SetContainer(container);
60 graphicView->snapper.SetGraphicView(graphicView); // <-- THIS is what I mean! INSANE!
62 RS_DEBUG->print("ActionInterface::ActionInterface: Setting up action: \"%s\": OK", name);
68 ActionInterface::~ActionInterface()
70 // would be pure virtual now:
72 //JLH: Only it isn't pure virtual...
76 * Must be implemented to return the ID of this action.
78 * @todo no default implementation
80 RS2::ActionType ActionInterface::rtti()
82 return RS2::ActionNone;
86 * @return name of this action
88 QString ActionInterface::getName()
94 * Called to initiate an action. This function is often
95 * overwritten by the implementing action.
97 * @param status The status on which to initiate this action.
98 * default is 0 to begin the action.
100 void ActionInterface::init(int status/*= 0*/)
102 // RS_Snapper::init();
107 //graphicView->setMouseCursor(cursor);
108 updateMouseButtonHints();
115 * Called when the mouse moves and this is the current action.
116 * This function can be overwritten by the implementing action.
117 * The default implementation keeps track of the mouse position.
119 void ActionInterface::mouseMoveEvent(QMouseEvent *)
124 * Called when the left mouse button is pressed and this is the
126 * This function can be overwritten by the implementing action.
127 * The default implementation does nothing.
129 void ActionInterface::mousePressEvent(QMouseEvent *)
134 * Called when the left mouse button is released and this is
135 * the current action.
136 * This function can be overwritten by the implementing action.
137 * The default implementation does nothing.
139 void ActionInterface::mouseReleaseEvent(QMouseEvent *)
144 * Called when a key is pressed and this is the current action.
145 * This function can be overwritten by the implementing action.
146 * The default implementation does nothing.
148 void ActionInterface::keyPressEvent(QKeyEvent * e)
154 * Called when a key is released and this is the current action.
155 * This function can be overwritten by the implementing action.
156 * The default implementation does nothing.
158 void ActionInterface::keyReleaseEvent(QKeyEvent * e)
164 * Coordinate event. Triggered usually from a command line.
165 * This function can be overwritten by the implementing action.
166 * The default implementation does nothing.
168 void ActionInterface::coordinateEvent(Vector *)
173 * Called when a command from the command line is launched.
174 * and this is the current action.
175 * This function can be overwritten by the implementing action.
176 * The default implementation does nothing.
178 void ActionInterface::commandEvent(RS_CommandEvent *)
183 * Must be implemented to return the currently available commands
184 * for the command line.
186 QStringList ActionInterface::getAvailableCommands()
193 * Sets the current status (progress) of this action.
194 * The default implementation sets the class variable 'status' to the
195 * given value and finishes the action if 'status' is negative.
197 * @param status Status number. It's up to the action implementor
198 * what the action uses the status for. However, a
199 * negative status number finishes the action. Usually
200 * the status of an action increases for every step
201 * of progress and decreases when the user goes one
202 * step back (i.e. presses the right mouse button).
204 void ActionInterface::setStatus(int status)
206 this->status = status;
214 updateMouseButtonHints();
220 * @return Current status of this action.
222 int ActionInterface::getStatus()
228 * Triggers this action. This should be called after all
229 * data needed for this action was collected / set.
230 * The default implementation does nothing.
232 void ActionInterface::trigger()
237 * Should be overwritten to update the mouse button hints
238 * wherever they might needed.
240 void ActionInterface::updateMouseButtonHints()
245 * Should be overwritten to set the mouse cursor for this action.
247 void ActionInterface::updateMouseCursor()
252 * Should be overwritten to set the toolbar for this action.
254 void ActionInterface::updateToolBar()
259 * @return true, if the action is finished and can be deleted.
261 bool ActionInterface::isFinished()
267 * Forces a termination of the action without any cleanup.
269 void ActionInterface::setFinished()
275 * Finishes this action.
277 void ActionInterface::finish()
279 RS_DEBUG->print("ActionInterface::finish");
281 // graphicView->setMouseCursor(RS2::ArrowCursor);
282 //graphicView->requestToolBar(RS2::ToolBarMain);
284 //Maybe change this to SnapperOff()?
285 //jlh: deleteSnapper();
288 // RS_Snapper::finish(); // Sets RS_Snapper::finished = true
289 // I think this is where we want to update the screen...
290 // graphicView->redraw();
291 RS_DEBUG->print("ActionInterface::finish: OK");
295 * Called by the event handler to give this action a chance to
296 * communicate with its predecessor.
298 void ActionInterface::setPredecessor(ActionInterface * p)
304 * Suspends this action while another action takes place.
306 void ActionInterface::suspend()
308 // graphicView->setMouseCursor(RS2::ArrowCursor);
309 // RS_Snapper::suspend();
313 * Resumes an action after it was suspended.
315 void ActionInterface::resume()
319 // RS_Snapper::resume();
323 * Hides the tool options. Default implementation does nothing.
325 void ActionInterface::hideOptions()
327 // RS_Snapper::hideOptions();
331 * Shows the tool options. Default implementation does nothing.
333 void ActionInterface::showOptions()
335 // RS_Snapper::showOptions();
339 * Calls checkCommand() from the RS_COMMANDS module.
341 bool ActionInterface::checkCommand(const QString & cmd, const QString & str,
342 RS2::ActionType action)
344 return RS_COMMANDS->checkCommand(cmd, str, action);
348 * Calls command() from the RS_COMMANDS module.
350 QString ActionInterface::command(const QString & cmd)
352 return RS_COMMANDS->command(cmd);
356 * Calls msgAvailableCommands() from the RS_COMMANDS module.
358 QString ActionInterface::msgAvailableCommands()
360 return RS_COMMANDS->msgAvailableCommands();
363 // This is here to save some typing in all the action* classes derived from
364 // this one. May go away in the future.
365 Vector ActionInterface::snapPoint(QMouseEvent * e)
367 return graphicView->snapper.snapPoint(e);
370 RS_Entity * ActionInterface::catchEntity(QMouseEvent * e, RS2::ResolveLevel level/*= RS2::ResolveNone*/)
372 return graphicView->snapper.catchEntity(e, level);
375 RS_Entity * ActionInterface::catchEntity(Vector v, RS2::ResolveLevel level/*= RS2::ResolveNone*/)
377 return graphicView->snapper.catchEntity(v, level);
380 //dummy functions, will delete later...
381 void ActionInterface::drawSnapper(void)
385 void ActionInterface::deleteSnapper(void)
389 void ActionInterface::drawPreview(void)
393 void ActionInterface::clearPreview(void)
397 void ActionInterface::deletePreview(void)