QCodeEdit 2.2
|
00001 /**************************************************************************** 00002 ** 00003 ** Copyright (C) 2006-2009 fullmetalcoder <fullmetalcoder@hotmail.fr> 00004 ** 00005 ** This file is part of the Edyuk project <http://edyuk.org> 00006 ** 00007 ** This file may be used under the terms of the GNU General Public License 00008 ** version 3 as published by the Free Software Foundation and appearing in the 00009 ** file GPL.txt included in the packaging of this file. 00010 ** 00011 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00012 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00013 ** 00014 ****************************************************************************/ 00015 00016 #ifndef _QDOCUMENT_COMMAND_H_ 00017 #define _QDOCUMENT_COMMAND_H_ 00018 00019 #include "qce-config.h" 00020 00026 #include <QUndoCommand> 00027 00028 #include "qdocument.h" 00029 00030 class QDocumentLine; 00031 class QDocumentLineHandle; 00032 class QDocumentCursorHandle; 00033 00034 class QCE_EXPORT QDocumentCommand : public QUndoCommand 00035 { 00036 public: 00037 enum Command 00038 { 00039 None, 00040 Insert, 00041 Erase, 00042 Replace, 00043 Custom 00044 }; 00045 00046 struct TextCommandData 00047 { 00048 QString begin, end; 00049 int lineNumber, startOffset, endOffset; 00050 QList<QDocumentLineHandle*> handles; 00051 }; 00052 00053 QDocumentCommand(Command c, QDocument *d, QDocumentCommand *p = 0); 00054 virtual ~QDocumentCommand(); 00055 00056 virtual int id() const; 00057 00058 virtual bool mergeWith(const QUndoCommand *command); 00059 00060 virtual void redo(); 00061 virtual void undo(); 00062 00063 bool isSilent() const; 00064 void setSilent(bool y); 00065 00066 bool keepAnchor() const; 00067 void setKeepAnchor(bool y); 00068 00069 void setTargetCursor(QDocumentCursorHandle *h); 00070 00071 void setRedoOffset(int off); 00072 void setUndoOffset(int off); 00073 00074 static bool isAutoUpdated(const QDocumentCursorHandle *h); 00075 static void enableAutoUpdate(QDocumentCursorHandle *h); 00076 static void disableAutoUpdate(QDocumentCursorHandle *h); 00077 static void discardHandlesFromDocument(QDocument *d); 00078 00079 protected: 00080 bool m_state, m_first; 00081 QDocument *m_doc; 00082 int m_redoOffset, m_undoOffset; 00083 00084 void markRedone(QDocumentLineHandle *h, bool firstTime); 00085 void markUndone(QDocumentLineHandle *h); 00086 00087 void updateTarget(int l, int offset); 00088 00089 void insertText(int line, int pos, const QString& s); 00090 void removeText(int line, int pos, int length); 00091 00092 void insertLines(int after, const QList<QDocumentLineHandle*>& l); 00093 void removeLines(int after, int n); 00094 00095 void updateCursorsOnInsertion(int line, int column, int prefixLength, int numLines, int suffixLength); 00096 void updateCursorsOnDeletion(int line, int column, int prefixLength, int numLines, int suffixLength); 00097 00098 private: 00099 bool m_silent; 00100 bool m_keepAnchor; 00101 Command m_command; 00102 QDocumentCursorHandle *m_cursor; 00103 00104 static QList<QDocumentCursorHandle*> m_autoUpdated; 00105 }; 00106 00107 Q_DECLARE_TYPEINFO(QDocumentCommand::TextCommandData, Q_MOVABLE_TYPE); 00108 00109 class QCE_EXPORT QDocumentInsertCommand : public QDocumentCommand 00110 { 00111 public: 00112 QDocumentInsertCommand( int l, int offset, 00113 const QString& text, 00114 QDocument *doc, 00115 QDocumentCommand *p = 0); 00116 00117 virtual ~QDocumentInsertCommand(); 00118 00119 virtual bool mergeWith(const QUndoCommand *command); 00120 00121 virtual void redo(); 00122 virtual void undo(); 00123 00124 private: 00125 TextCommandData m_data; 00126 }; 00127 00128 class QCE_EXPORT QDocumentEraseCommand : public QDocumentCommand 00129 { 00130 public: 00131 QDocumentEraseCommand( int bl, int bo, 00132 int el, int eo, 00133 QDocument *doc, 00134 QDocumentCommand *p = 0); 00135 00136 virtual ~QDocumentEraseCommand(); 00137 00138 virtual bool mergeWith(const QUndoCommand *command); 00139 00140 virtual void redo(); 00141 virtual void undo(); 00142 00143 private: 00144 TextCommandData m_data; 00145 }; 00146 00147 class QCE_EXPORT QDocumentCommandBlock : public QDocumentCommand 00148 { 00149 public: 00150 QDocumentCommandBlock(QDocument *d); 00151 virtual ~QDocumentCommandBlock(); 00152 00153 virtual void redo(); 00154 virtual void undo(); 00155 00156 void setWeakLock(bool l); 00157 bool isWeakLocked() const; 00158 00159 virtual void addCommand(QDocumentCommand *c); 00160 virtual void removeCommand(QDocumentCommand *c); 00161 00162 private: 00163 bool m_weakLocked; 00164 QList<QDocumentCommand*> m_commands; 00165 }; 00166 00167 #endif