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"
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 RS_ActionInterface::RS_ActionInterface(const char * name,
39 RS_EntityContainer & container, GraphicView & graphicView):
40 RS_Snapper(container, graphicView)
42 RS_DEBUG->print("RS_ActionInterface::RS_ActionInterface: Setting up action: \"%s\"", name);
47 //triggerOnResume = false;
49 // graphic provides a pointer to the graphic if the
50 // entity container is a graphic (i.e. can also hold
52 graphic = container.getGraphic();
54 // document pointer will be used for undo / redo
55 document = container.getDocument();
57 //this->cursor = cursor;
58 //setSnapMode(graphicView.getDefaultSnapMode());
60 RS_DEBUG->print("RS_ActionInterface::RS_ActionInterface: Setting up action: \"%s\": OK", name);
66 RS_ActionInterface::~RS_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 RS_ActionInterface::rtti()
80 return RS2::ActionNone;
84 * @return name of this action
86 QString RS_ActionInterface::getName()
92 * Called to initiate an action. This funtcion 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 RS_ActionInterface::init(int status)
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 RS_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 RS_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 RS_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 RS_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 RS_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 RS_ActionInterface::coordinateEvent(RS_CoordinateEvent *)
167 void RS_ActionInterface::coordinateEvent(Vector *)
172 * Called when a command from the command line is launched.
173 * and this is the current action.
174 * This function can be overwritten by the implementing action.
175 * The default implementation does nothing.
177 void RS_ActionInterface::commandEvent(RS_CommandEvent *)
182 * Must be implemented to return the currently available commands
183 * for the command line.
185 QStringList RS_ActionInterface::getAvailableCommands()
192 * Sets the current status (progress) of this action.
193 * The default implementation sets the class variable 'status' to the
194 * given value and finishes the action if 'status' is negative.
196 * @param status Status number. It's up to the action implementor
197 * what the action uses the status for. However, a
198 * negative status number finishes the action. Usually
199 * the status of an action increases for every step
200 * of progress and decreases when the user goes one
201 * step back (i.e. presses the right mouse button).
203 void RS_ActionInterface::setStatus(int status)
205 this->status = status;
213 updateMouseButtonHints();
219 * @return Current status of this action.
221 int RS_ActionInterface::getStatus()
227 * Triggers this action. This should be called after all
228 * data needed for this action was collected / set.
229 * The default implementation does nothing.
231 void RS_ActionInterface::trigger()
236 * Should be overwritten to update the mouse button hints
237 * wherever they might needed.
239 void RS_ActionInterface::updateMouseButtonHints()
244 * Should be overwritten to set the mouse cursor for this action.
246 void RS_ActionInterface::updateMouseCursor()
251 * Should be overwritten to set the toolbar for this action.
253 void RS_ActionInterface::updateToolBar()
258 * @return true, if the action is finished and can be deleted.
260 bool RS_ActionInterface::isFinished()
266 * Forces a termination of the action without any cleanup.
268 void RS_ActionInterface::setFinished()
274 * Finishes this action.
276 void RS_ActionInterface::finish()
278 RS_DEBUG->print("RS_ActionInterface::finish");
280 graphicView->setMouseCursor(RS2::ArrowCursor);
281 //graphicView->requestToolBar(RS2::ToolBarMain);
283 //jlh: deleteSnapper();
286 RS_Snapper::finish();
287 RS_DEBUG->print("RS_ActionInterface::finish: OK");
291 * Called by the event handler to give this action a chance to
292 * communicate with its predecessor.
294 void RS_ActionInterface::setPredecessor(RS_ActionInterface * pre)
300 * Suspends this action while another action takes place.
302 void RS_ActionInterface::suspend()
304 graphicView->setMouseCursor(RS2::ArrowCursor);
305 RS_Snapper::suspend();
309 * Resumes an action after it was suspended.
311 void RS_ActionInterface::resume()
315 RS_Snapper::resume();
319 * Hides the tool options. Default implementation does nothing.
321 void RS_ActionInterface::hideOptions()
323 RS_Snapper::hideOptions();
327 * Shows the tool options. Default implementation does nothing.
329 void RS_ActionInterface::showOptions()
331 RS_Snapper::showOptions();
335 * Calls checkCommand() from the RS_COMMANDS module.
337 bool RS_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 RS_ActionInterface::command(const QString & cmd)
348 return RS_COMMANDS->command(cmd);
352 * Calls msgAvailableCommands() from the RS_COMMANDS module.
354 QString RS_ActionInterface::msgAvailableCommands()
356 return RS_COMMANDS->msgAvailableCommands();