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 // (C) 2010 Underground Software
8 // JLH = James L. Hammons <jlhamm@acm.org>
11 // --- ---------- -----------------------------------------------------------
12 // JLH 05/22/2010 Added this text. :-)
15 #include "actioninterface.h"
19 #include "rs_entitycontainer.h"
20 #include "graphicview.h"
25 * Sets the entity container on which the action class inherited
26 * from this interface operates.
28 * @param name Action name. This can be used internally for
30 * @param container Entity container this action operates on.
31 * @param graphicView Graphic view instance this action operates on.
32 * Please note that an action belongs to this
34 * @param cursor Default mouse cursor for this action. If the action
35 * is suspended and resumed again the cursor will always
36 * be reset to the one given here.
38 ActionInterface::ActionInterface(const char * name, RS_EntityContainer & c,
39 GraphicView & v): graphicView(&v), container(&c)
41 RS_DEBUG->print("ActionInterface::ActionInterface: Setting up action: \"%s\"", name);
47 // Graphic provides a pointer to the graphic if the entity container is a
48 //graphic (i.e. can also hold layers).
49 graphic = c.getGraphic();
51 // Document pointer will be used for undo / redo
52 document = c.getDocument();
54 // This is here until I can figure out a better way to contain all of this
55 // circular referential nonsense that exists in this codebase. It will be
56 // expunged, by Grabthar's Hammer!
57 graphicView->snapper.SetContainer(container);
58 graphicView->snapper.SetGraphicView(graphicView); // <-- THIS is what I mean! INSANE!
60 RS_DEBUG->print("ActionInterface::ActionInterface: Setting up action: \"%s\": OK", name);
66 ActionInterface::~ActionInterface()
68 // would be pure virtual now:
70 //JLH: Only it isn't pure virtual...
74 * Must be implemented to return the ID of this action.
76 * @todo no default implementation
78 RS2::ActionType ActionInterface::rtti()
80 return RS2::ActionNone;
84 * @return name of this action
86 QString ActionInterface::getName()
92 * Called to initiate an action. This function is often
93 * overwritten by the implementing action.
95 * @param status The status on which to initiate this action.
96 * default is 0 to begin the action.
98 void ActionInterface::init(int status/*= 0*/)
100 // RS_Snapper::init();
105 //graphicView->setMouseCursor(cursor);
106 updateMouseButtonHints();
113 * Called when the mouse moves and this is the current action.
114 * This function can be overwritten by the implementing action.
115 * The default implementation keeps track of the mouse position.
117 void ActionInterface::mouseMoveEvent(QMouseEvent *)
122 * Called when the left mouse button is pressed and this is the
124 * This function can be overwritten by the implementing action.
125 * The default implementation does nothing.
127 void ActionInterface::mousePressEvent(QMouseEvent *)
132 * Called when the left mouse button is released and this is
133 * the current action.
134 * This function can be overwritten by the implementing action.
135 * The default implementation does nothing.
137 void ActionInterface::mouseReleaseEvent(QMouseEvent *)
142 * Called when a key is pressed and this is the current action.
143 * This function can be overwritten by the implementing action.
144 * The default implementation does nothing.
146 void ActionInterface::keyPressEvent(QKeyEvent * e)
152 * Called when a key is released and this is the current action.
153 * This function can be overwritten by the implementing action.
154 * The default implementation does nothing.
156 void ActionInterface::keyReleaseEvent(QKeyEvent * e)
162 * Coordinate event. Triggered usually from a command line.
163 * This function can be overwritten by the implementing action.
164 * The default implementation does nothing.
166 void ActionInterface::coordinateEvent(Vector *)
171 * Called when a command from the command line is launched.
172 * and this is the current action.
173 * This function can be overwritten by the implementing action.
174 * The default implementation does nothing.
176 void ActionInterface::commandEvent(RS_CommandEvent *)
181 * Must be implemented to return the currently available commands
182 * for the command line.
184 QStringList ActionInterface::getAvailableCommands()
191 * Sets the current status (progress) of this action.
192 * The default implementation sets the class variable 'status' to the
193 * given value and finishes the action if 'status' is negative.
195 * @param status Status number. It's up to the action implementor
196 * what the action uses the status for. However, a
197 * negative status number finishes the action. Usually
198 * the status of an action increases for every step
199 * of progress and decreases when the user goes one
200 * step back (i.e. presses the right mouse button).
202 void ActionInterface::setStatus(int status)
204 this->status = status;
212 updateMouseButtonHints();
218 * @return Current status of this action.
220 int ActionInterface::getStatus()
226 * Triggers this action. This should be called after all
227 * data needed for this action was collected / set.
228 * The default implementation does nothing.
230 void ActionInterface::trigger()
235 * Should be overwritten to update the mouse button hints
236 * wherever they might needed.
238 void ActionInterface::updateMouseButtonHints()
243 * Should be overwritten to set the mouse cursor for this action.
245 void ActionInterface::updateMouseCursor()
250 * Should be overwritten to set the toolbar for this action.
252 void ActionInterface::updateToolBar()
257 * @return true, if the action is finished and can be deleted.
259 bool ActionInterface::isFinished()
265 * Forces a termination of the action without any cleanup.
267 void ActionInterface::setFinished()
273 * Finishes this action.
275 void ActionInterface::finish()
277 RS_DEBUG->print("ActionInterface::finish");
279 // graphicView->setMouseCursor(RS2::ArrowCursor);
280 //graphicView->requestToolBar(RS2::ToolBarMain);
282 //Maybe change this to SnapperOff()?
283 //jlh: deleteSnapper();
286 // RS_Snapper::finish(); // Sets RS_Snapper::finished = true
287 // I think this is where we want to update the screen...
288 // graphicView->redraw();
289 RS_DEBUG->print("ActionInterface::finish: OK");
293 * Called by the event handler to give this action a chance to
294 * communicate with its predecessor.
296 void ActionInterface::setPredecessor(ActionInterface * p)
302 * Suspends this action while another action takes place.
304 void ActionInterface::suspend()
306 // graphicView->setMouseCursor(RS2::ArrowCursor);
307 // RS_Snapper::suspend();
311 * Resumes an action after it was suspended.
313 void ActionInterface::resume()
317 // RS_Snapper::resume();
321 * Hides the tool options. Default implementation does nothing.
323 void ActionInterface::hideOptions()
325 // RS_Snapper::hideOptions();
329 * Shows the tool options. Default implementation does nothing.
331 void ActionInterface::showOptions()
333 // RS_Snapper::showOptions();
337 * Calls checkCommand() from the RS_COMMANDS module.
339 bool ActionInterface::checkCommand(const QString & cmd, const QString & str,
340 RS2::ActionType action)
342 return RS_COMMANDS->checkCommand(cmd, str, action);
346 * Calls command() from the RS_COMMANDS module.
348 QString ActionInterface::command(const QString & cmd)
350 return RS_COMMANDS->command(cmd);
354 * Calls msgAvailableCommands() from the RS_COMMANDS module.
356 QString ActionInterface::msgAvailableCommands()
358 return RS_COMMANDS->msgAvailableCommands();
361 // This is here to save some typing in all the action* classes derived from
362 // this one. May go away in the future.
363 Vector ActionInterface::snapPoint(QMouseEvent * e)
365 return graphicView->snapper.snapPoint(e);
368 RS_Entity * ActionInterface::catchEntity(QMouseEvent * e, RS2::ResolveLevel level/*= RS2::ResolveNone*/)
370 return graphicView->snapper.catchEntity(e, level);
373 RS_Entity * ActionInterface::catchEntity(Vector v, RS2::ResolveLevel level/*= RS2::ResolveNone*/)
375 return graphicView->snapper.catchEntity(v, level);
378 //dummy functions, will delete later...
379 void ActionInterface::drawSnapper(void)
383 void ActionInterface::deleteSnapper(void)
387 void ActionInterface::drawPreview(void)
391 void ActionInterface::clearPreview(void)
395 void ActionInterface::deletePreview(void)