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);
46 //triggerOnResume = false;
48 // Graphic provides a pointer to the graphic if the entity container is a
49 //graphic (i.e. can also hold layers).
50 graphic = c.getGraphic();
52 // Document pointer will be used for undo / redo
53 document = c.getDocument();
55 //this->cursor = cursor;
56 //setSnapMode(graphicView.getDefaultSnapMode());
58 RS_DEBUG->print("ActionInterface::ActionInterface: Setting up action: \"%s\": OK", name);
64 ActionInterface::~ActionInterface()
66 // would be pure virtual now:
68 //JLH: Only it isn't pure virtual...
72 * Must be implemented to return the ID of this action.
74 * @todo no default implementation
76 RS2::ActionType ActionInterface::rtti()
78 return RS2::ActionNone;
82 * @return name of this action
84 QString ActionInterface::getName()
90 * Called to initiate an action. This function is often
91 * overwritten by the implementing action.
93 * @param status The status on which to initiate this action.
94 * default is 0 to begin the action.
96 void ActionInterface::init(int status/*= 0*/)
98 // RS_Snapper::init();
103 //graphicView->setMouseCursor(cursor);
104 updateMouseButtonHints();
111 * Called when the mouse moves and this is the current action.
112 * This function can be overwritten by the implementing action.
113 * The default implementation keeps track of the mouse position.
115 void ActionInterface::mouseMoveEvent(QMouseEvent *)
120 * Called when the left mouse button is pressed and this is the
122 * This function can be overwritten by the implementing action.
123 * The default implementation does nothing.
125 void ActionInterface::mousePressEvent(QMouseEvent *)
130 * Called when the left mouse button is released and this is
131 * the current action.
132 * This function can be overwritten by the implementing action.
133 * The default implementation does nothing.
135 void ActionInterface::mouseReleaseEvent(QMouseEvent *)
140 * Called when a key is pressed and this is the current action.
141 * This function can be overwritten by the implementing action.
142 * The default implementation does nothing.
144 void ActionInterface::keyPressEvent(QKeyEvent * e)
150 * Called when a key is released and this is the current action.
151 * This function can be overwritten by the implementing action.
152 * The default implementation does nothing.
154 void ActionInterface::keyReleaseEvent(QKeyEvent * e)
160 * Coordinate event. Triggered usually from a command line.
161 * This function can be overwritten by the implementing action.
162 * The default implementation does nothing.
164 void ActionInterface::coordinateEvent(Vector *)
169 * Called when a command from the command line is launched.
170 * and this is the current action.
171 * This function can be overwritten by the implementing action.
172 * The default implementation does nothing.
174 void ActionInterface::commandEvent(RS_CommandEvent *)
179 * Must be implemented to return the currently available commands
180 * for the command line.
182 QStringList ActionInterface::getAvailableCommands()
189 * Sets the current status (progress) of this action.
190 * The default implementation sets the class variable 'status' to the
191 * given value and finishes the action if 'status' is negative.
193 * @param status Status number. It's up to the action implementor
194 * what the action uses the status for. However, a
195 * negative status number finishes the action. Usually
196 * the status of an action increases for every step
197 * of progress and decreases when the user goes one
198 * step back (i.e. presses the right mouse button).
200 void ActionInterface::setStatus(int status)
202 this->status = status;
210 updateMouseButtonHints();
216 * @return Current status of this action.
218 int ActionInterface::getStatus()
224 * Triggers this action. This should be called after all
225 * data needed for this action was collected / set.
226 * The default implementation does nothing.
228 void ActionInterface::trigger()
233 * Should be overwritten to update the mouse button hints
234 * wherever they might needed.
236 void ActionInterface::updateMouseButtonHints()
241 * Should be overwritten to set the mouse cursor for this action.
243 void ActionInterface::updateMouseCursor()
248 * Should be overwritten to set the toolbar for this action.
250 void ActionInterface::updateToolBar()
255 * @return true, if the action is finished and can be deleted.
257 bool ActionInterface::isFinished()
263 * Forces a termination of the action without any cleanup.
265 void ActionInterface::setFinished()
271 * Finishes this action.
273 void ActionInterface::finish()
275 RS_DEBUG->print("ActionInterface::finish");
277 // graphicView->setMouseCursor(RS2::ArrowCursor);
278 //graphicView->requestToolBar(RS2::ToolBarMain);
280 //Maybe change this to SnapperOff()?
281 //jlh: deleteSnapper();
284 // RS_Snapper::finish(); // Sets RS_Snapper::finished = true
285 // I think this is where we want to update the screen...
286 // graphicView->redraw();
287 RS_DEBUG->print("ActionInterface::finish: OK");
291 * Called by the event handler to give this action a chance to
292 * communicate with its predecessor.
294 void ActionInterface::setPredecessor(ActionInterface * p)
300 * Suspends this action while another action takes place.
302 void ActionInterface::suspend()
304 // graphicView->setMouseCursor(RS2::ArrowCursor);
305 // RS_Snapper::suspend();
309 * Resumes an action after it was suspended.
311 void ActionInterface::resume()
315 // RS_Snapper::resume();
319 * Hides the tool options. Default implementation does nothing.
321 void ActionInterface::hideOptions()
323 // RS_Snapper::hideOptions();
327 * Shows the tool options. Default implementation does nothing.
329 void ActionInterface::showOptions()
331 // RS_Snapper::showOptions();
335 * Calls checkCommand() from the RS_COMMANDS module.
337 bool ActionInterface::checkCommand(const QString & cmd, const QString & str,
338 RS2::ActionType action)
340 return RS_COMMANDS->checkCommand(cmd, str, action);
344 * Calls command() from the RS_COMMANDS module.
346 QString ActionInterface::command(const QString & cmd)
348 return RS_COMMANDS->command(cmd);
352 * Calls msgAvailableCommands() from the RS_COMMANDS module.
354 QString ActionInterface::msgAvailableCommands()
356 return RS_COMMANDS->msgAvailableCommands();
359 // This is here to save some typing in all the action* classes derived from
360 // this one. May go away in the future.
361 Vector ActionInterface::snapPoint(QMouseEvent * e)
363 return graphicView->snapper.snapPoint(e);
366 RS_Entity * ActionInterface::catchEntity(QMouseEvent * e, RS2::ResolveLevel level/*= RS2::ResolveNone*/)
368 return graphicView->snapper.catchEntity(e, level);
371 RS_Entity * ActionInterface::catchEntity(Vector v, RS2::ResolveLevel level/*= RS2::ResolveNone*/)
373 return graphicView->snapper.catchEntity(v, level);
376 //dummy functions, will delete later...
377 void ActionInterface::drawSnapper(void)
381 void ActionInterface::deleteSnapper(void)
385 void ActionInterface::drawPreview(void)
389 void ActionInterface::clearPreview(void)
393 void ActionInterface::deletePreview(void)