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_CURSOR_H_ 00017 #define _QDOCUMENT_CURSOR_H_ 00018 00019 #include "qce-config.h" 00020 00026 class QChar; 00027 class QPoint; 00028 class QString; 00029 class QPolygon; 00030 00031 class QDocument; 00032 class QDocumentLine; 00033 struct QDocumentSelection; 00034 class QDocumentCursorHandle; 00035 00036 class QCE_EXPORT QDocumentCursor 00037 { 00038 public: 00039 enum MoveFlag 00040 { 00041 MoveAnchor = 0, 00042 KeepAnchor = 1, 00043 ThroughWrap = 2 00044 }; 00045 00046 Q_DECLARE_FLAGS(MoveMode, MoveFlag); 00047 00048 enum MoveOperation 00049 { 00050 NoMove, 00051 Up, 00052 Down, 00053 Left, 00054 PreviousCharacter = Left, 00055 Right, 00056 NextCharacter = Right, 00057 Start, 00058 StartOfLine, 00059 StartOfBlock = StartOfLine, 00060 StartOfWord, 00061 PreviousBlock, 00062 PreviousLine = PreviousBlock, 00063 PreviousWord, 00064 WordLeft, 00065 WordRight, 00066 End, 00067 EndOfLine, 00068 EndOfBlock = EndOfLine, 00069 EndOfWord, 00070 NextWord, 00071 NextBlock, 00072 NextLine = NextBlock 00073 }; 00074 00075 enum SelectionType 00076 { 00077 WordUnderCursor, 00078 LineUnderCursor 00079 }; 00080 00081 explicit QDocumentCursor(QDocument *doc); 00082 QDocumentCursor(const QDocumentCursor& cursor); 00083 QDocumentCursor(QDocument *doc, int line, int column = 0); 00084 //QDocumentCursor(const QDocumentLine& line, int column = 0); 00085 QDocumentCursor(QDocumentCursorHandle* handle = 0); 00086 00087 ~QDocumentCursor(); 00088 00089 QDocumentCursor clone() const; 00090 00091 QDocumentCursor& operator = (const QDocumentCursor& c); 00092 00093 bool operator == (const QDocumentCursor& c) const; 00094 bool operator != (const QDocumentCursor& c) const; 00095 00096 bool operator < (const QDocumentCursor& c) const; 00097 bool operator > (const QDocumentCursor& c) const; 00098 00099 bool operator <= (const QDocumentCursor& c) const; 00100 bool operator >= (const QDocumentCursor& c) const; 00101 00102 bool isNull() const; 00103 bool isValid() const; 00104 00105 bool atEnd() const; 00106 bool atStart() const; 00107 00108 bool atBlockEnd() const; 00109 bool atBlockStart() const; 00110 00111 bool atLineEnd() const; 00112 bool atLineStart() const; 00113 00114 bool hasSelection() const; 00115 00116 bool isSilent() const; 00117 void setSilent(bool y); 00118 00119 bool isAutoUpdated() const; 00120 void setAutoUpdated(bool y); 00121 00122 int position() const; 00123 00124 int lineNumber() const; 00125 int columnNumber() const; 00126 00127 int anchorLineNumber() const; 00128 int anchorColumnNumber() const; 00129 00130 int visualColumnNumber() const; 00131 00132 void setColumnNumber(int c, MoveMode m = MoveAnchor); 00133 00134 int wrappedLineOffset() const; 00135 int anchorWrappedLineOffset() const; 00136 00137 QPoint documentPosition() const; 00138 QPoint anchorDocumentPosition() const; 00139 00140 QPolygon documentRegion() const; 00141 00142 QDocumentLine line() const; 00143 QDocumentLine anchorLine() const; 00144 00145 void shift(int offset); 00146 void setPosition(int pos, MoveMode m = MoveAnchor); 00147 bool movePosition(int offset, MoveOperation op = NextCharacter, MoveMode m = MoveAnchor); 00148 00149 void moveTo(int line, int column); 00150 void moveTo(const QDocumentCursor &c); 00151 void moveTo(const QDocumentLine &l, int column); 00152 00153 void eraseLine(); 00154 void insertLine(bool keepAnchor = false); 00155 void insertText(const QString& s, bool keepAnchor = false); 00156 00157 QDocumentCursor selectionStart() const; 00158 QDocumentCursor selectionEnd() const; 00159 00160 QString selectedText() const; 00161 00162 void clearSelection(); 00163 void removeSelectedText(); 00164 void replaceSelectedText(const QString& text); 00165 00166 void select(SelectionType t); 00167 void setSelectionBoundary(const QDocumentCursor& c); 00168 00169 bool isWithinSelection(const QDocumentCursor& c) const; 00170 00171 QChar nextChar() const; 00172 QChar previousChar() const; 00173 00174 void deleteChar(); 00175 void deletePreviousChar(); 00176 00177 void beginEditBlock(); 00178 void endEditBlock(); 00179 00180 void refreshColumnMemory(); 00181 bool hasColumnMemory() const; 00182 void setColumnMemory(bool y); 00183 00184 QDocumentSelection selection() const; 00185 00186 QDocument* document() const; 00187 00188 inline QDocumentCursorHandle* handle() const 00189 { return m_handle; } 00190 00191 private: 00192 QDocumentCursorHandle *m_handle; 00193 }; 00194 00195 #endif