QCodeEdit 2.2
lib/document/qdocumentline.h
Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 2006-2009 fullmetalcoder <fullmetalcoder@hotmail.fr>
00004 **
00005 ** This file is part of the Edyuk project <http://edyuk.org>
00006 ** 
00007 ** This file may be used under the terms of the GNU General Public License
00008 ** version 3 as published by the Free Software Foundation and appearing in the
00009 ** file GPL.txt included in the packaging of this file.
00010 **
00011 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
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 indent() const;
00130         
00131         int nextNonSpaceChar(int pos) const;
00132         int previousNonSpaceChar(int pos) const;
00133 
00134         inline QString indentation() const
00135         { int idx = firstChar(); return idx != -1 ? text().left(idx) : text(); }
00136         
00137         inline bool isHidden() const
00138         { return hasFlag(Hidden); }
00139         
00140         bool hasFlag(State s) const;
00141         bool hasAnyFlag(int s) const;
00142         void setFlag(State s, bool y = true);
00143         
00144         QDocumentLine next() const;
00145         QDocumentLine previous() const;
00146         
00147         QDocument* document() const;
00148         
00149         int xToCursor(int x) const;
00150         int cursorToX(int cpos) const;
00151         
00152         int wrappedLineForCursor(int cpos) const;
00153         
00154         int documentOffsetToCursor(int x, int y) const;
00155         void cursorToDocumentOffset(int cpos, int& x, int& y) const;
00156         
00157         QPoint cursorToDocumentOffset(int cpos) const;
00158         
00159         void addMark(int id);
00160         void removeMark(int id);
00161         void toggleMark(int id);
00162         
00163         QList<int> marks() const;
00164         bool hasMark(int id) const;
00165         
00166         bool hasOverlay(int fid) const;
00167         QList<QFormatRange> overlays() const;
00168         
00169         void clearOverlays();
00170         void addOverlay(const QFormatRange& over);
00171         void removeOverlay(const QFormatRange& over);
00172         
00173         void setFormats(const QVector<int>& formats);
00174         
00175         const QVector<QParenthesis>& parentheses() const;
00176         void setParentheses(const QVector<QParenthesis>& parentheses);
00177         
00178         inline QDocumentLineHandle* handle() const
00179         { return m_handle; }
00180         
00181         QNFAMatchContext* matchContext();
00182         
00183     private:
00184         QDocumentLineHandle *m_handle;
00185 };
00186 
00187 Q_DECLARE_OPERATORS_FOR_FLAGS(QDocumentLine::States)
00188 
00189 #endif