QCodeEdit  2.2
qdocumentcursor_p.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_P_H_
17 #define _QDOCUMENT_CURSOR_P_H_
18 
19 #include "qce-config.h"
20 
26 #include "qdocumentcursor.h"
27 
28 #include <QStack>
29 
30 #if QT_VERSION < 0x040400
31 #include <QAtomic>
32 #else
33 #include <QAtomicInt>
34 #endif
35 
36 class QPoint;
37 class QPolygon;
38 
39 class QDocument;
40 class QDocumentLine;
41 class QDocumentPrivate;
42 class QDocumentCommand;
44 
46 {
47  friend class QDocumentCursor;
48  friend class QDocumentPrivate;
49  friend class QDocumentCommand;
50 
51  public:
52  enum Flags
53  {
54  Silent = 1,
55  ColumnMemory = 2,
56  MoveWithinWrapped = 4
57  };
58 
59  QDocument* document() const;
60 
61  bool atEnd() const;
62  bool atStart() const;
63 
64  bool atBlockEnd() const;
65  bool atBlockStart() const;
66 
67  bool atLineEnd() const;
68  bool atLineStart() const;
69 
70  bool hasSelection() const;
71 
72  bool isSilent() const;
73  void setSilent(bool y);
74 
75  bool isAutoUpdated() const;
76  void setAutoUpdated(bool y);
77 
78  QDocumentLine line() const;
79  QDocumentLine anchorLine() const;
80 
81  int lineNumber() const;
82  int columnNumber() const;
83 
84  int anchorLineNumber() const;
85  int anchorColumnNumber() const;
86 
87  int visualColumnNumber() const;
88 
89  void setColumnNumber(int c, int m = QDocumentCursor::MoveAnchor);
90 
91  QPoint documentPosition() const;
92  QPoint anchorDocumentPosition() const;
93 
94  QPolygon documentRegion() const;
95 
96  int position() const;
97 
98  void shift(int offset);
99  void setPosition(int pos, int m);
100  bool movePosition(int offset, int op, int m);
101 
102  void insertText(const QString& s, bool keepAnchor = false);
103 
104  QChar nextChar() const;
105  QChar previousChar() const;
106 
107  void eraseLine();
108  void deleteChar();
109  void deletePreviousChar();
110 
111  QDocumentCursor selectionStart() const;
112  QDocumentCursor selectionEnd() const;
113 
114  bool eq(const QDocumentCursorHandle *h);
115  bool lt(const QDocumentCursorHandle *h);
116  bool gt(const QDocumentCursorHandle *h);
117 
118  QString selectedText() const;
119 
120  void clearSelection();
121  void removeSelectedText(bool keepAnchor = false);
122  void replaceSelectedText(const QString& text);
123 
124  void select(QDocumentCursor::SelectionType t);
125  void setSelectionBoundary(const QDocumentCursor& c);
126 
127  bool isWithinSelection(const QDocumentCursor& c) const;
128  QDocumentCursor intersect(const QDocumentCursor& c) const;
129 
130  void beginBoundary(int& begline, int& begcol) const;
131  void endBoundary(int& endline, int& endcol) const;
132  void substractBoundaries(int lbeg, int cbeg, int lend, int cend);
133  void boundaries(int& begline, int& begcol, int& endline, int& endcol) const;
134  void intersectBoundaries(int& lbeg, int& cbeg, int& lend, int& cend) const;
135  void intersectBoundaries(QDocumentCursorHandle *h, int& lbeg, int& cbeg, int& lend, int& cend) const;
136 
137  void beginEditBlock();
138  void endEditBlock();
139 
140  void moveTo(int line, int column);
141  void moveTo(const QDocumentCursor &c);
142 
143  void copy(const QDocumentCursorHandle *c);
144 
145  void refreshColumnMemory();
146  bool hasColumnMemory() const;
147  void setColumnMemory(bool y);
148 
149  virtual void execute(QDocumentCommand *c);
150 
151  inline void ref() { m_ref.ref(); }
152  inline void deref() { if ( m_ref ) m_ref.deref(); if ( !m_ref ) delete this; }
153 
154  inline bool hasFlag(int f) const { return m_flags & f; }
155  inline void setFlag(int f) { m_flags |= f; }
156  inline void clearFlag(int f) { m_flags &= ~f; }
157 
158  protected:
159  QDocumentCursorHandle(QDocument *d, int line = 0);
160  virtual ~QDocumentCursorHandle();
161 
162  QDocumentCursorHandle* clone() const;
163 
164  private:
165  int m_flags;
166  QDocument *m_doc;
167 #if QT_VERSION < 0x040400
168  QBasicAtomic m_ref;
169 #else
170  QAtomicInt m_ref;
171 #endif
172  int m_begOffset, m_endOffset, m_max, m_begLine, m_endLine;
173  QStack<QDocumentCommandBlock*> m_blocks;
174 };
175 
176 Q_DECLARE_TYPEINFO(QDocumentCursorHandle*, Q_PRIMITIVE_TYPE);
177 
178 #endif // !_QDOCUMENT_CURSOR_P_H_