1 // rs_actioninterface.cpp
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 "rs_actioninterface.h"
20 * Sets the entity container on which the action class inherited
21 * from this interface operates.
23 * @param name Action name. This can be used internally for
25 * @param container Entity container this action operates on.
26 * @param graphicView Graphic view instance this action operates on.
27 * Please note that an action belongs to this
29 * @param cursor Default mouse cursor for this action. If the action
30 * is suspended and resumed again the cursor will always
31 * be reset to the one given here.
33 RS_ActionInterface::RS_ActionInterface(const char * name,
34 RS_EntityContainer & container, RS_GraphicView & graphicView):
35 RS_Snapper(container, graphicView)
37 RS_DEBUG->print("RS_ActionInterface::RS_ActionInterface: Setting up action: \"%s\"", name);
42 //triggerOnResume = false;
44 // graphic provides a pointer to the graphic if the
45 // entity container is a graphic (i.e. can also hold
47 graphic = container.getGraphic();
49 // document pointer will be used for undo / redo
50 document = container.getDocument();
52 //this->cursor = cursor;
53 //setSnapMode(graphicView.getDefaultSnapMode());
55 RS_DEBUG->print("RS_ActionInterface::RS_ActionInterface: Setting up action: \"%s\": OK", name);
61 RS_ActionInterface::~RS_ActionInterface()
63 //JLH: Only it isn't pure virtual...
64 // would be pure virtual now:
69 * Must be implemented to return the ID of this action.
71 * @todo no default implementation
73 RS2::ActionType RS_ActionInterface::rtti()
75 return RS2::ActionNone;
79 * @return name of this action
81 QString RS_ActionInterface::getName()
87 * Called to initiate an action. This funtcion is often
88 * overwritten by the implementing action.
90 * @param status The status on which to initiate this action.
91 * default is 0 to begin the action.
93 void RS_ActionInterface::init(int status)
100 //graphicView->setMouseCursor(cursor);
101 updateMouseButtonHints();
108 * Called when the mouse moves and this is the current action.
109 * This function can be overwritten by the implementing action.
110 * The default implementation keeps track of the mouse position.
112 void RS_ActionInterface::mouseMoveEvent(QMouseEvent *)
117 * Called when the left mouse button is pressed and this is the
119 * This function can be overwritten by the implementing action.
120 * The default implementation does nothing.
122 void RS_ActionInterface::mousePressEvent(QMouseEvent *)
127 * Called when the left mouse button is released and this is
128 * the current action.
129 * This function can be overwritten by the implementing action.
130 * The default implementation does nothing.
132 void RS_ActionInterface::mouseReleaseEvent(QMouseEvent *)
137 * Called when a key is pressed and this is the current action.
138 * This function can be overwritten by the implementing action.
139 * The default implementation does nothing.
141 void RS_ActionInterface::keyPressEvent(QKeyEvent * e)
147 * Called when a key is released and this is the current action.
148 * This function can be overwritten by the implementing action.
149 * The default implementation does nothing.
151 void RS_ActionInterface::keyReleaseEvent(QKeyEvent * e)
157 * Coordinate event. Triggered usually from a command line.
158 * This function can be overwritten by the implementing action.
159 * The default implementation does nothing.
161 void RS_ActionInterface::coordinateEvent(RS_CoordinateEvent *)
166 * Called when a command from the command line is launched.
167 * and this is the current action.
168 * This function can be overwritten by the implementing action.
169 * The default implementation does nothing.
171 void RS_ActionInterface::commandEvent(RS_CommandEvent *)
176 * Must be implemented to return the currently available commands
177 * for the command line.
179 QStringList RS_ActionInterface::getAvailableCommands()
186 * Sets the current status (progress) of this action.
187 * The default implementation sets the class variable 'status' to the
188 * given value and finishes the action if 'status' is negative.
190 * @param status Status number. It's up to the action implementor
191 * what the action uses the status for. However, a
192 * negative status number finishes the action. Usually
193 * the status of an action increases for every step
194 * of progress and decreases when the user goes one
195 * step back (i.e. presses the right mouse button).
197 void RS_ActionInterface::setStatus(int status)
199 this->status = status;
207 updateMouseButtonHints();
213 * @return Current status of this action.
215 int RS_ActionInterface::getStatus()
221 * Triggers this action. This should be called after all
222 * data needed for this action was collected / set.
223 * The default implementation does nothing.
225 void RS_ActionInterface::trigger()
230 * Should be overwritten to update the mouse button hints
231 * wherever they might needed.
233 void RS_ActionInterface::updateMouseButtonHints()
238 * Should be overwritten to set the mouse cursor for this action.
240 void RS_ActionInterface::updateMouseCursor()
245 * Should be overwritten to set the toolbar for this action.
247 void RS_ActionInterface::updateToolBar()
252 * @return true, if the action is finished and can be deleted.
254 bool RS_ActionInterface::isFinished()
260 * Forces a termination of the action without any cleanup.
262 void RS_ActionInterface::setFinished()
268 * Finishes this action.
270 void RS_ActionInterface::finish()
272 RS_DEBUG->print("RS_ActionInterface::finish");
274 graphicView->setMouseCursor(RS2::ArrowCursor);
275 //graphicView->requestToolBar(RS2::ToolBarMain);
277 //jlh: deleteSnapper();
280 RS_Snapper::finish();
281 RS_DEBUG->print("RS_ActionInterface::finish: OK");
285 * Called by the event handler to give this action a chance to
286 * communicate with its predecessor.
288 void RS_ActionInterface::setPredecessor(RS_ActionInterface * pre)
294 * Suspends this action while another action takes place.
296 void RS_ActionInterface::suspend()
298 graphicView->setMouseCursor(RS2::ArrowCursor);
299 RS_Snapper::suspend();
303 * Resumes an action after it was suspended.
305 void RS_ActionInterface::resume()
309 RS_Snapper::resume();
313 * Hides the tool options. Default implementation does nothing.
315 void RS_ActionInterface::hideOptions()
317 RS_Snapper::hideOptions();
321 * Shows the tool options. Default implementation does nothing.
323 void RS_ActionInterface::showOptions()
325 RS_Snapper::showOptions();
329 * Calls checkCommand() from the RS_COMMANDS module.
331 bool RS_ActionInterface::checkCommand(const QString & cmd, const QString & str,
332 RS2::ActionType action)
334 return RS_COMMANDS->checkCommand(cmd, str, action);
338 * Calls command() from the RS_COMMANDS module.
340 QString RS_ActionInterface::command(const QString & cmd)
342 return RS_COMMANDS->command(cmd);
346 * Calls msgAvailableCommands() from the RS_COMMANDS module.
348 QString RS_ActionInterface::msgAvailableCommands()
350 return RS_COMMANDS->msgAvailableCommands();