QCodeEdit  2.2
qdocumentline.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_LINE_H_
17 #define _QDOCUMENT_LINE_H_
18 
19 #include "qce-config.h"
20 
26 #include "qformat.h"
27 
28 class QPoint;
29 class QString;
30 
31 class QDocument;
33 
34 struct QNFAMatchContext;
35 
37 {
38  enum Role
39  {
40  Open = 1,
41  Close = 2,
42  Indent = 4,
43  Fold = 8,
44  Match = 16
45  };
46 
47  inline QParenthesis()
48  : id(0), role(0), offset(0), length(0)
49  {}
50 
51  inline QParenthesis(int i, quint8 r, int pos, int len)
52  : id(i), role(r), offset(pos), length(len)
53  {}
54 
55  int id;
56  int role;
57  int offset;
58  int length;
59 };
60 
61 Q_DECLARE_TYPEINFO(QParenthesis, Q_MOVABLE_TYPE);
62 
64 {
65  friend class QDocumentLineHandle;
66  friend class QDocumentCursorHandle;
67 
68  public:
69  enum State
70  {
71  None = 0,
72  Hidden = 1,
73  CollapsedBlockStart = 2,
74  CollapsedBlockEnd = 4,
75 
76  LayoutDirty = 16,
77  FormatsApplied = 32
78  };
79 
80  Q_DECLARE_FLAGS(States, State);
81 
82  explicit QDocumentLine(QDocument *doc);
83  QDocumentLine(const QDocumentLine& line);
85 
86  ~QDocumentLine();
87 
88  bool isNull() const;
89  bool isValid() const;
90 
91  inline bool operator == (const QDocumentLineHandle* h) const
92  {
93  return m_handle == h;
94  }
95 
96  inline bool operator != (const QDocumentLineHandle* h) const
97  {
98  return m_handle != h;
99  }
100 
101  bool operator == (const QDocumentLine& l) const;
102  bool operator != (const QDocumentLine& l) const;
103 
104  bool operator < (const QDocumentLine& l) const;
105  bool operator >= (const QDocumentLine& l) const;
106 
107  bool operator > (const QDocumentLine& l) const;
108  bool operator <= (const QDocumentLine& l) const;
109 
110  QDocumentLine& operator ++ ();
111  QDocumentLine& operator -- ();
112 
113  void operator ++ (int);
114  void operator -- (int);
115 
116  QDocumentLine& operator = (const QDocumentLine& l);
117 
118  int lineNumber() const;
119  int position() const;
120 
121  QString text() const;
122 
123  int length() const;
124  int lineSpan() const;
125 
126  int firstChar() const;
127  int lastChar() const;
128 
129  int indent() const;
130 
131  int nextNonSpaceChar(int pos) const;
132  int previousNonSpaceChar(int pos) const;
133 
134  inline QString indentation() const
135  { int idx = firstChar(); return idx != -1 ? text().left(idx) : text(); }
136 
137  inline bool isHidden() const
138  { return hasFlag(Hidden); }
139 
140  bool hasFlag(State s) const;
141  bool hasAnyFlag(int s) const;
142  void setFlag(State s, bool y = true);
143 
144  QDocumentLine next() const;
145  QDocumentLine previous() const;
146 
147  QDocument* document() const;
148 
149  int xToCursor(int x) const;
150  int cursorToX(int cpos) const;
151 
152  int wrappedLineForCursor(int cpos) const;
153 
154  int documentOffsetToCursor(int x, int y) const;
155  void cursorToDocumentOffset(int cpos, int& x, int& y) const;
156 
157  QPoint cursorToDocumentOffset(int cpos) const;
158 
159  void addMark(int id);
160  void removeMark(int id);
161  void toggleMark(int id);
162 
163  QList<int> marks() const;
164  bool hasMark(int id) const;
165 
166  bool hasOverlay(int fid) const;
167  QList<QFormatRange> overlays() const;
168 
169  void clearOverlays();
170  void addOverlay(const QFormatRange& over);
171  void removeOverlay(const QFormatRange& over);
172 
173  void setFormats(const QVector<int>& formats);
174 
175  const QVector<QParenthesis>& parentheses() const;
176  void setParentheses(const QVector<QParenthesis>& parentheses);
177 
178  inline QDocumentLineHandle* handle() const
179  { return m_handle; }
180 
181  QNFAMatchContext* matchContext();
182 
183  private:
184  QDocumentLineHandle *m_handle;
185 };
186 
187 Q_DECLARE_OPERATORS_FOR_FLAGS(QDocumentLine::States)
188 
189 #endif