QCodeEdit  2.2
qdocumentline_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_LINE_P_H_
17 #define _QDOCUMENT_LINE_P_H_
18 
19 #include "qce-config.h"
20 
26 #include "qnfa.h"
27 
28 #include "qformat.h"
29 
30 #include "qdocumentline.h"
31 
32 #include <QPair>
33 #include <QList>
34 #include <QString>
35 #include <QVector>
36 
37 #include <QTextLayout>
38 
39 #if QT_VERSION < 0x040400
40 #include <QAtomic>
41 #else
42 #include <QAtomicInt>
43 #endif
44 
47 
48 class QPoint;
49 
50 class QDocument;
51 class QDocumentLine;
52 class QDocumentBuffer;
53 class QDocumentPrivate;
54 
56 {
57  friend class QDocument;
58  friend class QDocumentLine;
59  friend class QDocumentBuffer;
60  friend class QDocumentPrivate;
61 
62  public:
64  QDocumentLineHandle(const QString& s, QDocument *d);
65 
66  int count() const;
67  int length() const;
68 
69  int position() const;
70 
71  QString text() const;
72 
73  int line() const;
74 
75  int xToCursor(int x) const;
76  int cursorToX(int i) const;
77 
78  int wrappedLineForCursor(int cpos) const;
79 
80  int documentOffsetToCursor(int x, int y) const;
81  void cursorToDocumentOffset(int cpos, int& x, int& y) const;
82 
83  QPoint cursorToDocumentOffset(int cpos) const;
84 
85  int indent() const;
86 
87  int nextNonSpaceChar(uint pos) const;
88  int previousNonSpaceChar(int pos) const;
89 
90  bool hasFlag(int flag) const;
91  void setFlag(int flag, bool y = true) const;
92 
93  QDocument* document() const;
94 
95  QDocumentLineHandle* next() const;
96  QDocumentLineHandle* previous() const;
97 
98  void updateWrap() const;
99 
100  void setFormats(const QVector<int>& formats);
101 
102  void clearOverlays();
103  void addOverlay(const QFormatRange& over);
104  void removeOverlay(const QFormatRange& over);
105 
106  void shiftOverlays(int position, int offset);
107 
108  void draw( QPainter *p,
109  int xOffset,
110  int vWidth,
111  const QSmallArray& sel,
112  const QSmallArray& cursors,
113  const QPalette& pal,
114  bool fullSel) const;
115 
116  inline QString& textBuffer() { setFlag(QDocumentLine::LayoutDirty, true); return m_text; }
117 
118  inline void ref() { m_ref.ref(); }
119  inline void deref() { if ( m_ref ) m_ref.deref(); if ( !m_ref ) delete this; }
120 
121  protected:
123 
124  private:
125  void layout() const;
126  void applyOverlays() const;
127 
128  QMediumArray compose() const;
129  QList<QTextLayout::FormatRange> decorations() const;
130 
131  QString m_text;
132  QDocument *m_doc;
133 #if QT_VERSION < 0x040400
134  QBasicAtomic m_ref;
135 #else
136  QAtomicInt m_ref;
137 #endif
138  mutable int m_indent;
139  mutable quint16 m_state;
140  mutable QTextLayout *m_layout;
141  mutable QVector<int> m_cache;
142  mutable QVector< QPair<int, int> > m_frontiers;
143 
144  QNFAMatchContext m_context;
145 
146  QVector<int> m_formats;
147  QVector<QParenthesis> m_parens;
148  QList<QFormatRange> m_overlays;
149 };
150 
151 Q_DECLARE_TYPEINFO(QDocumentLineHandle*, Q_PRIMITIVE_TYPE);
152 
153 #endif // !_QDOCUMENT_LINE_P_H_
#define QCE_EXPORT
Macro needed for cross-platform shared libraries creation.
Definition: qce-config.h:40
Utility file for shared library creation.
Definition of the QDocumentLine class.
A class storing a document.
Definition: qdocument.h:62
Definition: qformat.h:155
Definition: qdocument_p.h:54
Private implementation of a document line.
Definition: qdocumentline_p.h:55
Definition of the QFormat class.
Definition of the core QNFA syntax engine.
Definition: qnfa.h:131
A reference to line objects.
Definition: qdocumentline.h:63
Definition: qdocumentbuffer.h:27