QCodeEdit
2.2
|
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_P_H_ 00017 #define _QDOCUMENT_LINE_P_H_ 00018 00019 #include "qce-config.h" 00020 00026 #include "qnfa.h" 00027 00028 #include "qformat.h" 00029 00030 #include "qdocumentline.h" 00031 00032 #include <QPair> 00033 #include <QList> 00034 #include <QString> 00035 #include <QVector> 00036 00037 #include <QTextLayout> 00038 00039 #if QT_VERSION < 0x040400 00040 #include <QAtomic> 00041 #else 00042 #include <QAtomicInt> 00043 #endif 00044 00045 typedef QVector<int> QSmallArray; 00046 typedef QVector<int> QMediumArray; 00047 00048 class QPoint; 00049 00050 class QDocument; 00051 class QDocumentLine; 00052 class QDocumentBuffer; 00053 class QDocumentPrivate; 00054 00055 class QCE_EXPORT QDocumentLineHandle 00056 { 00057 friend class QDocument; 00058 friend class QDocumentLine; 00059 friend class QDocumentBuffer; 00060 friend class QDocumentPrivate; 00061 00062 public: 00063 QDocumentLineHandle(QDocument *d); 00064 QDocumentLineHandle(const QString& s, QDocument *d); 00065 00066 int count() const; 00067 int length() const; 00068 00069 int position() const; 00070 00071 QString text() const; 00072 00073 int line() const; 00074 00075 int xToCursor(int x) const; 00076 int cursorToX(int i) const; 00077 00078 int wrappedLineForCursor(int cpos) const; 00079 00080 int documentOffsetToCursor(int x, int y) const; 00081 void cursorToDocumentOffset(int cpos, int& x, int& y) const; 00082 00083 QPoint cursorToDocumentOffset(int cpos) const; 00084 00085 int indent() const; 00086 00087 int nextNonSpaceChar(uint pos) const; 00088 int previousNonSpaceChar(int pos) const; 00089 00090 bool hasFlag(int flag) const; 00091 void setFlag(int flag, bool y = true) const; 00092 00093 QDocument* document() const; 00094 00095 QDocumentLineHandle* next() const; 00096 QDocumentLineHandle* previous() const; 00097 00098 void updateWrap() const; 00099 00100 void setFormats(const QVector<int>& formats); 00101 00102 void clearOverlays(); 00103 void addOverlay(const QFormatRange& over); 00104 void removeOverlay(const QFormatRange& over); 00105 00106 void shiftOverlays(int position, int offset); 00107 00108 void draw( QPainter *p, 00109 int xOffset, 00110 int vWidth, 00111 const QSmallArray& sel, 00112 const QSmallArray& cursors, 00113 const QPalette& pal, 00114 bool fullSel) const; 00115 00116 inline QString& textBuffer() { setFlag(QDocumentLine::LayoutDirty, true); return m_text; } 00117 00118 inline void ref() { m_ref.ref(); } 00119 inline void deref() { if ( m_ref ) m_ref.deref(); if ( !m_ref ) delete this; } 00120 00121 protected: 00122 ~QDocumentLineHandle(); 00123 00124 private: 00125 void layout() const; 00126 void applyOverlays() const; 00127 00128 QMediumArray compose() const; 00129 QList<QTextLayout::FormatRange> decorations() const; 00130 00131 QString m_text; 00132 QDocument *m_doc; 00133 #if QT_VERSION < 0x040400 00134 QBasicAtomic m_ref; 00135 #else 00136 QAtomicInt m_ref; 00137 #endif 00138 mutable int m_indent; 00139 mutable quint16 m_state; 00140 mutable QTextLayout *m_layout; 00141 mutable QVector<int> m_cache; 00142 mutable QVector< QPair<int, int> > m_frontiers; 00143 00144 QNFAMatchContext m_context; 00145 00146 QVector<int> m_formats; 00147 QVector<QParenthesis> m_parens; 00148 QList<QFormatRange> m_overlays; 00149 }; 00150 00151 Q_DECLARE_TYPEINFO(QDocumentLineHandle*, Q_PRIMITIVE_TYPE); 00152 00153 #endif // !_QDOCUMENT_LINE_P_H_