QCodeEdit  2.2
qdocumentcursor.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2006-2009 fullmetalcoder <fullmetalcoder@hotmail.fr>
4 **
5 ** This file is part of the Edyuk project <http://edyuk.org>
6 **
7 ** This file may be used under the terms of the GNU General Public License
8 ** version 3 as published by the Free Software Foundation and appearing in the
9 ** file GPL.txt included in the packaging of this file.
10 **
11 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13 **
14 ****************************************************************************/
15 
16 #ifndef _QDOCUMENT_CURSOR_H_
17 #define _QDOCUMENT_CURSOR_H_
18 
19 #include "qce-config.h"
20 
26 class QChar;
27 class QPoint;
28 class QString;
29 class QPolygon;
30 
31 class QDocument;
32 class QDocumentLine;
33 struct QDocumentSelection;
35 
37 {
38  public:
39  enum MoveFlag
40  {
41  MoveAnchor = 0,
42  KeepAnchor = 1,
43  ThroughWrap = 2
44  };
45 
46  Q_DECLARE_FLAGS(MoveMode, MoveFlag);
47 
48  enum MoveOperation
49  {
50  NoMove,
51  Up,
52  Down,
53  Left,
54  PreviousCharacter = Left,
55  Right,
56  NextCharacter = Right,
57  Start,
58  StartOfLine,
59  StartOfBlock = StartOfLine,
60  StartOfWord,
61  PreviousBlock,
62  PreviousLine = PreviousBlock,
63  PreviousWord,
64  WordLeft,
65  WordRight,
66  End,
67  EndOfLine,
68  EndOfBlock = EndOfLine,
69  EndOfWord,
70  NextWord,
71  NextBlock,
72  NextLine = NextBlock
73  };
74 
75  enum SelectionType
76  {
77  WordUnderCursor,
78  LineUnderCursor
79  };
80 
81  explicit QDocumentCursor(QDocument *doc);
82  QDocumentCursor(const QDocumentCursor& cursor);
83  QDocumentCursor(QDocument *doc, int line, int column = 0);
84  //QDocumentCursor(const QDocumentLine& line, int column = 0);
86 
87  ~QDocumentCursor();
88 
89  QDocumentCursor clone() const;
90 
91  QDocumentCursor& operator = (const QDocumentCursor& c);
92 
93  bool operator == (const QDocumentCursor& c) const;
94  bool operator != (const QDocumentCursor& c) const;
95 
96  bool operator < (const QDocumentCursor& c) const;
97  bool operator > (const QDocumentCursor& c) const;
98 
99  bool operator <= (const QDocumentCursor& c) const;
100  bool operator >= (const QDocumentCursor& c) const;
101 
102  bool isNull() const;
103  bool isValid() const;
104 
105  bool atEnd() const;
106  bool atStart() const;
107 
108  bool atBlockEnd() const;
109  bool atBlockStart() const;
110 
111  bool atLineEnd() const;
112  bool atLineStart() const;
113 
114  bool hasSelection() const;
115 
116  bool isSilent() const;
117  void setSilent(bool y);
118 
119  bool isAutoUpdated() const;
120  void setAutoUpdated(bool y);
121 
122  int position() const;
123 
124  int lineNumber() const;
125  int columnNumber() const;
126 
127  int anchorLineNumber() const;
128  int anchorColumnNumber() const;
129 
130  int visualColumnNumber() const;
131 
132  void setColumnNumber(int c, MoveMode m = MoveAnchor);
133 
134  int wrappedLineOffset() const;
135  int anchorWrappedLineOffset() const;
136 
137  QPoint documentPosition() const;
138  QPoint anchorDocumentPosition() const;
139 
140  QPolygon documentRegion() const;
141 
142  QDocumentLine line() const;
143  QDocumentLine anchorLine() const;
144 
145  void shift(int offset);
146  void setPosition(int pos, MoveMode m = MoveAnchor);
147  bool movePosition(int offset, MoveOperation op = NextCharacter, MoveMode m = MoveAnchor);
148 
149  void moveTo(int line, int column);
150  void moveTo(const QDocumentCursor &c);
151  void moveTo(const QDocumentLine &l, int column);
152 
153  void eraseLine();
154  void insertLine(bool keepAnchor = false);
155  void insertText(const QString& s, bool keepAnchor = false);
156 
157  QDocumentCursor selectionStart() const;
158  QDocumentCursor selectionEnd() const;
159 
160  QString selectedText() const;
161 
162  void clearSelection();
163  void removeSelectedText();
164  void replaceSelectedText(const QString& text);
165 
166  void select(SelectionType t);
167  void setSelectionBoundary(const QDocumentCursor& c);
168 
169  bool isWithinSelection(const QDocumentCursor& c) const;
170 
171  QChar nextChar() const;
172  QChar previousChar() const;
173 
174  void deleteChar();
175  void deletePreviousChar();
176 
177  void beginEditBlock();
178  void endEditBlock();
179 
180  void refreshColumnMemory();
181  bool hasColumnMemory() const;
182  void setColumnMemory(bool y);
183 
184  QDocumentSelection selection() const;
185 
186  QDocument* document() const;
187 
188  inline QDocumentCursorHandle* handle() const
189  { return m_handle; }
190 
191  private:
192  QDocumentCursorHandle *m_handle;
193 };
194 
195 #endif
#define QCE_EXPORT
Macro needed for cross-platform shared libraries creation.
Definition: qce-config.h:40
Utility file for shared library creation.
Definition: qdocumentcursor_p.h:45
A class storing a document.
Definition: qdocument.h:62
Definition: qdocument.h:43
A reference to line objects.
Definition: qdocumentline.h:63
A cursor to navigate within documents and edit them.
Definition: qdocumentcursor.h:36