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_P_H_ 17 #define _QDOCUMENT_P_H_ 18 19 #include "qce-config.h" 20 21 /*! 22 \file qdocument_p.h 23 \brief Definition of the private document API 24 */ 25 26 #include "qdocument.h" 27 #include "qdocumentline.h" 28 #include "qdocumentcursor.h" 29 30 #include <QHash> 31 #include <QFont> 32 #include <QStack> 33 #include <QQueue> 34 #include <QDateTime> 35 #include <QUndoStack> 36 #include <QStringList> 37 #include <QFontMetrics> 38 #include <QUndoCommand> 39 40 class QDocument; 41 class QDocumentBuffer; 42 class QDocumentPrivate; 43 class QDocumentCommand; 44 class QDocumentCommandBlock; 45 46 class QLanguageDefinition; 47 48 Q_DECLARE_TYPEINFO(QDocumentSelection, Q_PRIMITIVE_TYPE); 49 50 #include "qdocumentline_p.h" 51 52 #include "qdocumentcursor_p.h" 53 54 class QCE_EXPORT QDocumentPrivate 55 { 56 friend class QEditConfig; 57 58 friend class QDocument; 59 friend class QDocumentCommand; 60 friend class QDocumentLineHandle; 61 friend class QDocumentCursorHandle; 62 63 public: 64 QDocumentPrivate(QDocument *d); 65 ~QDocumentPrivate(); 66 67 void execute(QDocumentCommand *cmd); 68 69 void draw(QPainter *p, QDocument::PaintContext& cxt); 70 71 QDocumentLineHandle* lineForPosition(int& position) const; 72 int position(const QDocumentLineHandle *l) const; 73 74 QDocumentLineHandle* at(int line) const; 75 int indexOf(const QDocumentLineHandle *l) const; 76 77 QDocumentIterator index(const QDocumentLineHandle *l); 78 QDocumentConstIterator index(const QDocumentLineHandle *l) const; 79 80 QDocumentLineHandle* next(const QDocumentLineHandle *l) const; 81 QDocumentLineHandle* previous(const QDocumentLineHandle *l) const; 82 83 void adjustWidth(int l); 84 //int checkWidth(QDocumentLineHandle *l, int w); 85 //int checkWidth(QDocumentLineHandle *l, const QString& s); 86 87 void setWidth(); 88 void setHeight(); 89 90 static void setFont(const QFont& f); 91 92 void beginChangeBlock(); 93 void endChangeBlock(); 94 maxMarksPerLine()95 inline int maxMarksPerLine() const 96 { return m_maxMarksPerLine; } 97 hasMarks()98 inline bool hasMarks() const 99 { return m_marks.count(); } 100 101 QList<int> marks(QDocumentLineHandle *h) const; 102 103 void addMark(QDocumentLineHandle *h, int mid); 104 void toggleMark(QDocumentLineHandle *h, int mid); 105 void removeMark(QDocumentLineHandle *h, int mid); 106 107 int findNextMark(int id, int from = 0, int until = -1); 108 int findPreviousMark(int id, int from = -1, int until = 0); 109 110 int getNextGroupId(); 111 void releaseGroupId(int groupId); 112 void clearMatches(int gid); 113 void flushMatches(int gid); 114 void addMatch(int gid, int line, int pos, int len, int format); 115 116 void emitFormatsChange (int line, int lines); 117 void emitContentsChange(int line, int lines); 118 119 int visualLine(int textLine) const; 120 int textLine(int visualLine, int *wrap = 0) const; 121 void hideEvent(int line, int count); 122 void showEvent(int line, int count); 123 124 void setWidth(int width); 125 126 void emitFormatsChanged(); 127 void emitContentsChanged(); 128 129 void emitLineDeleted(QDocumentLineHandle *h); 130 void emitMarkChanged(QDocumentLineHandle *l, int m, bool on); 131 begin()132 inline QDocumentIterator begin() { return m_lines.begin(); } end()133 inline QDocumentIterator end() { return m_lines.end(); } 134 constBegin()135 inline QDocumentConstIterator constBegin() const { return m_lines.constBegin(); } constEnd()136 inline QDocumentConstIterator constEnd() const { return m_lines.constEnd(); } 137 138 protected: 139 void updateHidden(int line, int count); 140 void updateWrapped(int line, int count); 141 142 void insertLines(int after, const QList<QDocumentLineHandle*>& l); 143 void removeLines(int after, int n); 144 145 void emitWidthChanged(); 146 void emitHeightChanged(); 147 148 void updateFormatCache(); 149 void setFormatScheme(QFormatScheme *f); 150 void tunePainter(QPainter *p, int fid); 151 152 private: 153 QDocument *m_doc; 154 QUndoStack m_commands; 155 QDocumentCursor *m_editCursor; 156 157 bool m_suspend, m_deleting; 158 QStack<QDocumentCommandBlock*> m_macros; 159 160 QMap<int, int> m_hidden; 161 QMap<int, int> m_wrapped; 162 QVector< QPair<QDocumentLineHandle*, int> > m_largest; 163 164 struct Match 165 { 166 int line; 167 QFormatRange range; 168 QDocumentLineHandle *h; 169 }; 170 171 struct MatchList : QList<Match> 172 { MatchListMatchList173 MatchList() : index(0) {} 174 175 int index; 176 }; 177 178 int m_lastGroupId; 179 QList<int> m_freeGroupIds; 180 QHash<int, MatchList> m_matches; 181 182 bool m_constrained; 183 int m_width, m_height; 184 185 int m_tabStop; 186 static int m_defaultTabStop; 187 188 static QFont *m_font; 189 static bool m_fixedPitch; 190 static QFontMetrics *m_fontMetrics; 191 static int m_leftMargin; 192 static QDocument::WhiteSpaceMode m_showSpaces; 193 static QDocument::LineEnding m_defaultLineEnding; 194 static int m_lineHeight; 195 static int m_lineSpacing; 196 static int m_spaceWidth; 197 static int m_ascent; 198 static int m_descent; 199 static int m_leading; 200 static int m_wrapMargin; 201 202 QFormatScheme *m_formatScheme; 203 QLanguageDefinition *m_language; 204 static QFormatScheme *m_defaultFormatScheme; 205 206 QVector<QFont> m_fonts; 207 208 static QList<QDocumentPrivate*> m_documents; 209 210 int m_maxMarksPerLine; 211 QHash<QDocumentLineHandle*, QList<int> > m_marks; 212 QHash<QDocumentLineHandle*, QPair<int, int> > m_status; 213 214 int _nix, _dos, _mac; 215 QString m_lineEndingString; 216 QDocument::LineEnding m_lineEnding; 217 218 QDateTime m_lastModified; 219 220 QDocumentBuffer *m_buffer; 221 QVector<QDocumentLineHandle*> m_lines; 222 }; 223 224 #endif 225