File: qdocumentcursor.h

package info (click to toggle)
texstudio 2.11.2%2Bdebian-1
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 41,292 kB
  • ctags: 12,405
  • sloc: cpp: 93,072; xml: 10,217; ansic: 4,153; sh: 145; makefile: 56
file content (249 lines) | stat: -rw-r--r-- 7,428 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
/****************************************************************************
**
** Copyright (C) 2006-2009 fullmetalcoder <fullmetalcoder@hotmail.fr>
**
** This file is part of the Edyuk project <http://edyuk.org>
** 
** This file may be used under the terms of the GNU General Public License
** version 3 as published by the Free Software Foundation and appearing in the
** file GPL.txt included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
****************************************************************************/

#ifndef _QDOCUMENT_CURSOR_H_
#define _QDOCUMENT_CURSOR_H_

#include "qce-config.h"

#include "modifiedQObject.h"
#include <QMetaType>
#include <QPoint>

/*!
	\file qdocumentcursor.h
	\brief Definition of the QDocumentCursor class
*/

class QChar;
class QPoint;
class QString;
class QPolygon;

class QString;
class QChar;

class QDocument;
class QDocumentLine;
struct QDocumentSelection;
class QDocumentCursorHandle;

class QCE_EXPORT QDocumentCursor : public QObject
{
        Q_OBJECT
		Q_ENUMS(MoveOperation)
		Q_ENUMS(MoveMode MoveFlag)
		Q_ENUMS(SelectionType)
	public:
		enum MoveFlag
		{
			MoveAnchor	= 0,
			KeepAnchor	= 1,
			ThroughWrap	= 2,
			ThroughFolding  = 4
		};
		
		Q_DECLARE_FLAGS(MoveMode, MoveFlag);
		
		enum MoveOperation
		{
			NoMove,
			Up,
			Down,
			Left,
			PreviousCharacter,
			Right,
			NextCharacter,
			Start,
			StartOfLine,
			StartOfBlock = StartOfLine,
			StartOfWord,
			StartOfWordOrCommand,
			PreviousBlock,
			PreviousLine = PreviousBlock,
			PreviousWord,
			WordLeft,
			WordRight,
			End,
			EndOfLine,
			EndOfBlock = EndOfLine,
			EndOfWord,
			EndOfWordOrCommand,
			NextWord,
			NextBlock,
			NextLine = NextBlock
		};
		
		enum SelectionType
		{
			WordUnderCursor,
			WordOrCommandUnderCursor,
			LineUnderCursor
		};
		
		explicit QDocumentCursor(QDocument *doc);
		QDocumentCursor(const QDocumentCursor& cursor);
		QDocumentCursor(const QDocumentCursor& cursor, const bool cloneAutoUpdateFlag);
		QDocumentCursor(QDocument *doc, int line, int column = 0, int lineTo = -1, int columnTo = -1);
		//QDocumentCursor(const QDocumentLine& line, int column = 0);
		QDocumentCursor(QDocumentCursorHandle* handle = 0);
		QDocumentCursor(const QDocumentCursor& from, const QDocumentCursor& to);

		~QDocumentCursor();
		
		QDocumentCursor clone(bool cloneAutoUpdatedFlag) const;
		
		QDocumentCursor& operator = (const QDocumentCursor& c);
		
		bool operator == (const QDocumentCursor& c) const;
		bool operator != (const QDocumentCursor& c) const;
		
		bool operator < (const QDocumentCursor& c) const;
		bool operator > (const QDocumentCursor& c) const;
		
		bool operator <= (const QDocumentCursor& c) const;
		bool operator >= (const QDocumentCursor& c) const;
		
		Q_INVOKABLE bool beginBoundaryLarger (const QDocumentCursor& c) const;
		Q_INVOKABLE bool endBoundaryLarger (const QDocumentCursor& c) const;
		Q_INVOKABLE bool equalBoundaries(const QDocumentCursor& c) const;
		Q_INVOKABLE bool equal(const QDocumentCursor& c) const;
		
		void beginBoundary(int& begline, int& begcol) const;
		void endBoundary(int& endline, int& endcol) const;
		void boundaries(int& begline, int& begcol, int& endline, int& endcol) const;
		
		Q_INVOKABLE bool isNull() const;
		Q_INVOKABLE bool isValid() const;
		
		Q_INVOKABLE bool atEnd() const;
		Q_INVOKABLE bool atStart() const;
		
		Q_INVOKABLE bool atBlockEnd() const;
		Q_INVOKABLE bool atBlockStart() const;
		
		Q_INVOKABLE bool atLineEnd() const;
		Q_INVOKABLE bool atLineStart() const;
		
		Q_INVOKABLE bool hasSelection() const;
		Q_INVOKABLE bool isForwardSelection() const;
		
		Q_INVOKABLE bool isSilent() const;
		void setSilent(bool y);
		
		Q_INVOKABLE bool isAutoUpdated() const;
		void setAutoUpdated(bool y);

		Q_INVOKABLE bool isAutoErasable() const;
		void setAutoErasable(bool y);
		
		int position() const;
		
		Q_INVOKABLE int lineNumber() const;
		Q_INVOKABLE int columnNumber() const;
		
		Q_INVOKABLE int anchorLineNumber() const;
		Q_INVOKABLE int anchorColumnNumber() const;

		Q_INVOKABLE int startLineNumber() const;
		Q_INVOKABLE int startColumnNumber() const;

		Q_INVOKABLE int endLineNumber() const;
		Q_INVOKABLE int endColumnNumber() const;

		Q_INVOKABLE int visualColumnNumber() const;
		
		Q_INVOKABLE void setLineNumber(int c, MoveMode m = MoveAnchor);
		Q_INVOKABLE void setColumnNumber(int c, MoveMode m = MoveAnchor);
		Q_INVOKABLE void setAnchorLineNumber(int c) const;
		Q_INVOKABLE void setAnchorColumnNumber(int c) const;

		Q_INVOKABLE int wrappedLineOffset() const;
		Q_INVOKABLE int anchorWrappedLineOffset() const;
		
		Q_INVOKABLE QPoint documentPosition() const;
		Q_INVOKABLE QPoint anchorDocumentPosition() const;
		
		QPolygon documentRegion() const;
		
		QDocumentLine line() const;
		QDocumentLine anchorLine() const;
		
		Q_INVOKABLE void shift(int offset);
		Q_INVOKABLE void setPosition(int pos, MoveMode m = MoveAnchor);
		Q_INVOKABLE bool movePosition(int offset, MoveOperation op = NextCharacter, MoveMode m = MoveAnchor);
		
		Q_INVOKABLE void moveTo(int line, int column, MoveMode m = MoveAnchor);
		void moveTo(const QDocumentCursor &c, MoveMode m = MoveAnchor);
		//void moveTo(const QDocumentLine &l, int column, MoveMode m = MoveAnchor);
		
		Q_INVOKABLE void eraseLine();
		Q_INVOKABLE void insertLine(bool keepAnchor = false);
		Q_INVOKABLE void insertText(const QString& s, bool keepAnchor = false);
		
		QDocumentCursor selectionStart() const;
		QDocumentCursor selectionEnd() const;
		QDocumentCursor anchorCursor() const;
		
		Q_INVOKABLE QString selectedText() const;
		
		Q_INVOKABLE void clearSelection();
		Q_INVOKABLE void flipSelection();
		Q_INVOKABLE void removeSelectedText();
		Q_INVOKABLE void replaceSelectedText(const QString& text);
		
		Q_INVOKABLE void select(SelectionType t);
		Q_INVOKABLE void expandSelect(SelectionType t);
		Q_INVOKABLE void setSelectionBoundary(const QDocumentCursor& c);
		Q_INVOKABLE void select(int line, int column, int lineTo = -1, int columnTo = -1);
		Q_INVOKABLE void selectColumns(int column, int columnTo = -1);
		
		Q_INVOKABLE bool isWithinSelection(const QDocumentCursor& c) const;
		Q_INVOKABLE QDocumentCursor intersect(const QDocumentCursor& c) const;
		void intersectBoundaries(int& lbeg, int& cbeg, int& lend, int& cend) const;

		void getMatchingPair(QDocumentCursor& from, QDocumentCursor& to, bool maximal = true) const;

		Q_INVOKABLE QChar nextChar() const;
		Q_INVOKABLE QChar previousChar() const;
		
		Q_INVOKABLE void deleteChar();
		Q_INVOKABLE void deletePreviousChar();
		
		Q_INVOKABLE void beginEditBlock();
		Q_INVOKABLE void endEditBlock();
		
		void refreshColumnMemory();
		bool hasColumnMemory() const;
		void setColumnMemory(bool y);
		
		QDocumentSelection selection() const;
		
		bool isRTL() const;

		QDocument* document() const;
		
		inline QDocumentCursorHandle* handle() const
		{ return m_handle; }
		
		static void sort(QDocumentCursor& from, QDocumentCursor& to);

	private:
		QDocumentCursorHandle *m_handle;
};

Q_DECLARE_METATYPE(QDocumentCursor)

#endif