00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef _QDOCUMENT_LINE_H_
00017 #define _QDOCUMENT_LINE_H_
00018
00019 #include "qce-config.h"
00020
00026 #include "qformat.h"
00027
00028 class QPoint;
00029 class QString;
00030
00031 class QDocument;
00032 class QDocumentLineHandle;
00033
00034 struct QNFAMatchContext;
00035
00036 struct QParenthesis
00037 {
00038 enum Role
00039 {
00040 Open = 1,
00041 Close = 2,
00042 Indent = 4,
00043 Fold = 8,
00044 Match = 16
00045 };
00046
00047 inline QParenthesis()
00048 : id(0), role(0), offset(0), length(0)
00049 {}
00050
00051 inline QParenthesis(int i, quint8 r, int pos, int len)
00052 : id(i), role(r), offset(pos), length(len)
00053 {}
00054
00055 int id;
00056 int role;
00057 int offset;
00058 int length;
00059 };
00060
00061 Q_DECLARE_TYPEINFO(QParenthesis, Q_MOVABLE_TYPE);
00062
00063 class QCE_EXPORT QDocumentLine
00064 {
00065 friend class QDocumentLineHandle;
00066 friend class QDocumentCursorHandle;
00067
00068 public:
00069 enum State
00070 {
00071 None = 0,
00072 Hidden = 1,
00073 CollapsedBlockStart = 2,
00074 CollapsedBlockEnd = 4,
00075
00076 LayoutDirty = 16,
00077 FormatsApplied = 32
00078 };
00079
00080 Q_DECLARE_FLAGS(States, State);
00081
00082 explicit QDocumentLine(QDocument *doc);
00083 QDocumentLine(const QDocumentLine& line);
00084 QDocumentLine(QDocumentLineHandle *h = 0);
00085
00086 ~QDocumentLine();
00087
00088 bool isNull() const;
00089 bool isValid() const;
00090
00091 inline bool operator == (const QDocumentLineHandle* h) const
00092 {
00093 return m_handle == h;
00094 }
00095
00096 inline bool operator != (const QDocumentLineHandle* h) const
00097 {
00098 return m_handle != h;
00099 }
00100
00101 bool operator == (const QDocumentLine& l) const;
00102 bool operator != (const QDocumentLine& l) const;
00103
00104 bool operator < (const QDocumentLine& l) const;
00105 bool operator >= (const QDocumentLine& l) const;
00106
00107 bool operator > (const QDocumentLine& l) const;
00108 bool operator <= (const QDocumentLine& l) const;
00109
00110 QDocumentLine& operator ++ ();
00111 QDocumentLine& operator -- ();
00112
00113 void operator ++ (int);
00114 void operator -- (int);
00115
00116 QDocumentLine& operator = (const QDocumentLine& l);
00117
00118 int lineNumber() const;
00119 int position() const;
00120
00121 QString text() const;
00122
00123 int length() const;
00124 int lineSpan() const;
00125
00126 int firstChar() const;
00127 int lastChar() const;
00128
00129 int nextNonSpaceChar(int pos) const;
00130 int previousNonSpaceChar(int pos) const;
00131
00132 inline QString indentation() const
00133 { int idx = firstChar(); return idx != -1 ? text().left(idx) : text(); }
00134
00135 inline bool isHidden() const
00136 { return hasFlag(Hidden); }
00137
00138 bool hasFlag(State s) const;
00139 void setFlag(State s, bool y = true);
00140
00141 QDocumentLine next() const;
00142 QDocumentLine previous() const;
00143
00144 QDocument* document() const;
00145
00146 int xToCursor(int x) const;
00147 int cursorToX(int cpos) const;
00148
00149 int wrappedLineForCursor(int cpos) const;
00150
00151 int documentOffsetToCursor(int x, int y) const;
00152 void cursorToDocumentOffset(int cpos, int& x, int& y) const;
00153
00154 QPoint cursorToDocumentOffset(int cpos) const;
00155
00156 void addMark(int id);
00157 void removeMark(int id);
00158 void toggleMark(int id);
00159
00160 QList<int> marks() const;
00161 bool hasMark(int id) const;
00162
00163 void clearOverlays();
00164 void addOverlay(const QFormatRange& over);
00165 void removeOverlay(const QFormatRange& over);
00166
00167 void setFormats(const QVector<int>& formats);
00168
00169 const QVector<QParenthesis>& parentheses() const;
00170 void setParentheses(const QVector<QParenthesis>& parentheses);
00171
00172 inline QDocumentLineHandle* handle() const
00173 { return m_handle; }
00174
00175 QNFAMatchContext* matchContext();
00176
00177 private:
00178 QDocumentLineHandle *m_handle;
00179 };
00180
00181 Q_DECLARE_OPERATORS_FOR_FLAGS(QDocumentLine::States)
00182
00183 #endif