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!
61 graphicView->snapper.SetVisible();
62 graphicView->preview.SetVisible();
64 RS_DEBUG->print("ActionInterface::ActionInterface: Setting up action: \"%s\": OK", name);
70 ActionInterface::~ActionInterface()
72 // would be pure virtual now:
74 //JLH: Only it isn't pure virtual...
78 * Must be implemented to return the ID of this action.
80 * @todo no default implementation
82 RS2::ActionType ActionInterface::rtti()
84 return RS2::ActionNone;
88 * @return name of this action
90 QString ActionInterface::getName()
96 * Called to initiate an action. This function is often
97 * overwritten by the implementing action.
99 * @param status The status on which to initiate this action.
100 * default is 0 to begin the action.
102 void ActionInterface::init(int status/*= 0*/)
104 // RS_Snapper::init();
109 //graphicView->setMouseCursor(cursor);
110 updateMouseButtonHints();
114 else // status < 0, e.g. this action is finished
116 graphicView->snapper.SetVisible(false);
117 graphicView->preview.SetVisible(false);
122 * Called when the mouse moves and this is the current action.
123 * This function can be overwritten by the implementing action.
124 * The default implementation keeps track of the mouse position.
126 void ActionInterface::mouseMoveEvent(QMouseEvent *)
131 * Called when the left mouse button is pressed and this is the
133 * This function can be overwritten by the implementing action.
134 * The default implementation does nothing.
136 void ActionInterface::mousePressEvent(QMouseEvent *)
141 * Called when the left mouse button is released and this is
142 * the current action.
143 * This function can be overwritten by the implementing action.
144 * The default implementation does nothing.
146 void ActionInterface::mouseReleaseEvent(QMouseEvent *)
151 * Called when a key is pressed and this is the current action.
152 * This function can be overwritten by the implementing action.
153 * The default implementation does nothing.
155 void ActionInterface::keyPressEvent(QKeyEvent * e)
161 * Called when a key is released and this is the current action.
162 * This function can be overwritten by the implementing action.
163 * The default implementation does nothing.
165 void ActionInterface::keyReleaseEvent(QKeyEvent * e)
171 * Coordinate event. Triggered usually from a command line.
172 * This function can be overwritten by the implementing action.
173 * The default implementation does nothing.
175 void ActionInterface::coordinateEvent(Vector *)
180 * Called when a command from the command line is launched.
181 * and this is the current action.
182 * This function can be overwritten by the implementing action.
183 * The default implementation does nothing.
185 void ActionInterface::commandEvent(RS_CommandEvent *)
190 * Must be implemented to return the currently available commands
191 * for the command line.
193 QStringList ActionInterface::getAvailableCommands()
200 * Sets the current status (progress) of this action.
201 * The default implementation sets the class variable 'status' to the
202 * given value and finishes the action if 'status' is negative.
204 * @param status Status number. It's up to the action implementor
205 * what the action uses the status for. However, a
206 * negative status number finishes the action. Usually
207 * the status of an action increases for every step
208 * of progress and decreases when the user goes one
209 * step back (i.e. presses the right mouse button).
211 void ActionInterface::setStatus(int status)
213 this->status = status;
221 updateMouseButtonHints();
227 * @return Current status of this action.
229 int ActionInterface::getStatus()
235 * Triggers this action. This should be called after all
236 * data needed for this action was collected / set.
237 * The default implementation does nothing.
239 void ActionInterface::trigger()
244 * Should be overwritten to update the mouse button hints
245 * wherever they might needed.
247 void ActionInterface::updateMouseButtonHints()
252 * Should be overwritten to set the mouse cursor for this action.
254 void ActionInterface::updateMouseCursor()
259 * Should be overwritten to set the toolbar for this action.
261 void ActionInterface::updateToolBar()
266 * @return true, if the action is finished and can be deleted.
268 bool ActionInterface::isFinished()
274 * Forces a termination of the action without any cleanup.
276 void ActionInterface::setFinished()
282 * Finishes this action.
284 void ActionInterface::finish()
286 RS_DEBUG->print("ActionInterface::finish");
288 // graphicView->setMouseCursor(RS2::ArrowCursor);
289 //graphicView->requestToolBar(RS2::ToolBarMain);
291 //Maybe change this to SnapperOff()?
292 //jlh: deleteSnapper();
295 // RS_Snapper::finish(); // Sets RS_Snapper::finished = true
296 // I think this is where we want to update the screen...
297 // graphicView->redraw();
298 RS_DEBUG->print("ActionInterface::finish: OK");
302 * Called by the event handler to give this action a chance to
303 * communicate with its predecessor.
305 void ActionInterface::setPredecessor(ActionInterface * p)
311 * Suspends this action while another action takes place.
313 void ActionInterface::suspend()
315 // graphicView->setMouseCursor(RS2::ArrowCursor);
316 // RS_Snapper::suspend();
320 * Resumes an action after it was suspended.
322 void ActionInterface::resume()
326 // RS_Snapper::resume();
330 * Hides the tool options. Default implementation does nothing.
332 void ActionInterface::hideOptions()
334 // RS_Snapper::hideOptions();
338 * Shows the tool options. Default implementation does nothing.
340 void ActionInterface::showOptions()
342 // RS_Snapper::showOptions();
346 * Calls checkCommand() from the RS_COMMANDS module.
348 bool ActionInterface::checkCommand(const QString & cmd, const QString & str,
349 RS2::ActionType action)
351 return RS_COMMANDS->checkCommand(cmd, str, action);
355 * Calls command() from the RS_COMMANDS module.
357 QString ActionInterface::command(const QString & cmd)
359 return RS_COMMANDS->command(cmd);
363 * Calls msgAvailableCommands() from the RS_COMMANDS module.
365 QString ActionInterface::msgAvailableCommands()
367 return RS_COMMANDS->msgAvailableCommands();
370 // This is here to save some typing in all the action* classes derived from
371 // this one. May go away in the future.
372 Vector ActionInterface::snapPoint(QMouseEvent * e)
374 return graphicView->snapper.snapPoint(e);
377 RS_Entity * ActionInterface::catchEntity(QMouseEvent * e, RS2::ResolveLevel level/*= RS2::ResolveNone*/)
379 return graphicView->snapper.catchEntity(e, level);
382 RS_Entity * ActionInterface::catchEntity(Vector v, RS2::ResolveLevel level/*= RS2::ResolveNone*/)
384 return graphicView->snapper.catchEntity(v, level);
387 //dummy functions, will delete later...
388 void ActionInterface::drawSnapper(void)
392 void ActionInterface::deleteSnapper(void)
396 void ActionInterface::drawPreview(void)
400 void ActionInterface::clearPreview(void)
404 void ActionInterface::deletePreview(void)