1 /**************************************************************************** 2 ** 3 ** This file is part of the LibreCAD project, a 2D CAD program 4 ** 5 ** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl) 6 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved. 7 ** 8 ** 9 ** This file may be distributed and/or modified under the terms of the 10 ** GNU General Public License version 2 as published by the Free Software 11 ** Foundation and appearing in the file gpl-2.0.txt included in the 12 ** packaging of this file. 13 ** 14 ** This program is distributed in the hope that it will be useful, 15 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 16 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 ** GNU General Public License for more details. 18 ** 19 ** You should have received a copy of the GNU General Public License 20 ** along with this program; if not, write to the Free Software 21 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 22 ** 23 ** This copyright notice MUST APPEAR in all copies of the script! 24 ** 25 **********************************************************************/ 26 27 28 #ifndef RS_ACTIONINTERFACE_H 29 #define RS_ACTIONINTERFACE_H 30 31 #include <QObject> 32 33 #include "rs_snapper.h" 34 35 class QKeyEvent; 36 class RS_CommandEvent; 37 class RS_CoordinateEvent; 38 class RS_Graphic; 39 class RS_Document; 40 class QAction; 41 42 /** 43 * This is the interface that must be implemented for all 44 * action classes. Action classes handle actions such 45 * as drawing lines, moving entities or zooming in. 46 * 47 * Inherited from QObject for Qt translation features. 48 * 49 * @author Andrew Mustun 50 */ 51 class RS_ActionInterface : public QObject, public RS_Snapper { 52 Q_OBJECT 53 public: 54 RS_ActionInterface(const char* name, 55 RS_EntityContainer& container, 56 RS_GraphicView& graphicView); 57 virtual ~RS_ActionInterface() = default; 58 59 virtual RS2::ActionType rtti() const; 60 61 void setName(const char* _name); 62 QString getName(); 63 64 virtual void init(int status=0); 65 virtual void mouseMoveEvent(QMouseEvent*); 66 virtual void mousePressEvent(QMouseEvent*); 67 68 virtual void mouseReleaseEvent(QMouseEvent*); 69 virtual void keyPressEvent(QKeyEvent* e); 70 virtual void keyReleaseEvent(QKeyEvent* e); 71 virtual void coordinateEvent(RS_CoordinateEvent*); 72 virtual void commandEvent(RS_CommandEvent*); 73 virtual QStringList getAvailableCommands(); 74 virtual void setStatus(int status); 75 virtual int getStatus(); 76 virtual void trigger(); 77 virtual void updateMouseButtonHints(); 78 virtual void updateMouseCursor(); 79 virtual bool isFinished(); 80 virtual void setFinished(); 81 virtual void finish(bool updateTB = true ); 82 virtual void setPredecessor(RS_ActionInterface* pre); 83 virtual void suspend(); 84 virtual void resume(); 85 virtual void hideOptions(); 86 virtual void showOptions(); 87 virtual void setActionType(RS2::ActionType actionType); 88 bool checkCommand(const QString& cmd, const QString& str, 89 RS2::ActionType action=RS2::ActionNone); 90 QString command(const QString& cmd); 91 QString msgAvailableCommands(); 92 93 private: 94 /** 95 * Current status of the action. After an action has 96 * been created the action status is set to 0. Actions 97 * that are terminated have a stats of -1. Other status 98 * numbers can be used to describe the stage this action 99 * is in. E.g. a window zoom consists of selecting the 100 * first corner (status 0), and selecting the second 101 * corner (status 1). 102 */ 103 int status; 104 105 protected: 106 /** Action name. Used internally for debugging */ 107 QString name; 108 109 /** 110 * This flag is set when the action has terminated and 111 * can be deleted. 112 */ 113 bool finished; 114 115 /** 116 * Pointer to the graphic is this container is a graphic. 117 * NULL otherwise 118 */ 119 RS_Graphic* graphic; 120 121 /** 122 * Pointer to the document (graphic or block) or NULL. 123 */ 124 RS_Document* document; 125 126 /** 127 * Pointer to the default mouse cursor for this action or NULL. 128 */ 129 //RS2::CursorType cursor; 130 131 /** 132 * Predecessor of this action or NULL. 133 */ 134 RS_ActionInterface* predecessor; 135 136 /** 137 * String prepended to the help text for currently available commands. 138 */ 139 //static QString msgAvailableCommands; 140 141 /** 142 * Command used for showing help for every action. 143 */ 144 //static QString cmdHelp; 145 146 /** 147 * Command for answering yes to a question. 148 */ 149 //static QString cmdYes; 150 //static QString cmdYes2; 151 152 /** 153 * Command for answering no to a question. 154 */ 155 //static QString cmdNo; 156 //static QString cmdNo2; 157 RS2::ActionType actionType; 158 }; 159 160 161 #endif 162