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_H_ 00017 #define _QDOCUMENT_H_ 00018 00019 #include "qce-config.h" 00020 00028 #include <QList> 00029 #include <QVector> 00030 #include <QLinkedList> 00031 00032 #include <QObject> 00033 #include <QPalette> 00034 #include <QMetaType> 00035 00036 class QFont; 00037 class QRect; 00038 class QPrinter; 00039 class QDateTime; 00040 class QFormatScheme; 00041 class QLanguageDefinition; 00042 00043 struct QCE_EXPORT QDocumentSelection 00044 { 00045 int start, end; 00046 int startLine, endLine; 00047 }; 00048 00049 class QDocumentLine; 00050 class QDocumentCursor; 00051 class QDocumentPrivate; 00052 class QDocumentCommand; 00053 class QDocumentLineHandle; 00054 class QDocumentCursorHandle; 00055 00056 typedef QVector<QDocumentLineHandle*>::iterator QDocumentIterator; 00057 typedef QVector<QDocumentLineHandle*>::const_iterator QDocumentConstIterator; 00058 00059 Q_DECLARE_METATYPE(QDocumentIterator) 00060 Q_DECLARE_METATYPE(QDocumentConstIterator) 00061 00062 class QCE_EXPORT QDocument : public QObject 00063 { 00064 friend class QMatcher; 00065 friend class QDocumentPrivate; 00066 friend class QDocumentCommand; 00067 00068 Q_OBJECT 00069 00070 public: 00071 struct PaintContext 00072 { 00073 int width; 00074 int height; 00075 int xoffset; 00076 int yoffset; 00077 QPalette palette; 00078 bool blinkingCursor; 00079 bool fillCursorRect; 00080 QList<QDocumentCursorHandle*> extra; 00081 QList<QDocumentCursorHandle*> cursors; 00082 QList<QDocumentSelection> selections; 00083 }; 00084 00085 enum LineEnding 00086 { 00087 Conservative, 00088 Local, 00089 Unix, 00090 Windows, 00091 Mac, // backward compat only : use OldMac instead (more self-explanatory) 00092 OldMac = Mac 00093 }; 00094 00095 enum TextProcessing 00096 { 00097 RemoveTrailingWS = 1, 00098 PreserveIndent = 2, 00099 RestoreTrailingIndent = 4 00100 }; 00101 00102 enum WhiteSpaceFlag 00103 { 00104 ShowNone = 0x00, 00105 ShowTrailing = 0x01, 00106 ShowLeading = 0x02, 00107 ShowTabs = 0x04 00108 }; 00109 00110 Q_DECLARE_FLAGS(WhiteSpaceMode, WhiteSpaceFlag) 00111 00112 explicit QDocument(QObject *p = 0); 00113 virtual ~QDocument(); 00114 00115 QString text(int mode) const; 00116 QString text(bool removeTrailing = false, bool preserveIndent = true) const; 00117 void setText(const QString& s); 00118 00119 void startChunkLoading(); 00120 void stopChunkLoading(); 00121 void addChunk(const QString& txt); 00122 00123 LineEnding lineEnding() const; 00124 LineEnding originalLineEnding() const; 00125 void setLineEnding(LineEnding le); 00126 00127 QDateTime lastModified() const; 00128 void setLastModified(const QDateTime& d); 00129 00130 bool canUndo() const; 00131 bool canRedo() const; 00132 00133 int width() const; 00134 int height() const; 00135 int widthConstraint() const; 00136 00137 int lines() const; 00138 int lineCount() const; 00139 int visualLines() const; 00140 int visualLineCount() const; 00141 00142 int visualLineNumber(int textLineNumber) const; 00143 int textLineNumber(int visualLineNumber) const; 00144 00145 int y(int line) const; 00146 int lineNumber(int ypos, int *wrap = 0) const; 00147 int y(const QDocumentLine& l) const; 00148 00149 QRect lineRect(int line) const; 00150 QRect lineRect(const QDocumentLine& l) const; 00151 00152 QDocumentCursor* editCursor() const; 00153 void setEditCursor(QDocumentCursor *c); 00154 00155 QLanguageDefinition* languageDefinition() const; 00156 void setLanguageDefinition(QLanguageDefinition *l); 00157 00158 int maxMarksPerLine() const; 00159 int findNextMark(int id, int from = 0, int until = -1) const; 00160 int findPreviousMark(int id, int from = -1, int until = 0) const; 00161 00162 QDocumentLine lineAt(const QPoint& p) const; 00163 void cursorForDocumentPosition(const QPoint& p, int& line, int& column) const; 00164 QDocumentCursor cursorAt(const QPoint& p) const; 00165 00166 QDocumentLine line(int line) const; 00167 QDocumentLine line(QDocumentConstIterator iterator) const; 00168 00169 QDocumentCursor cursor(int line, int column = 0) const; 00170 00171 QDocumentLine findLine(int& position) const; 00172 00173 bool isLineModified(const QDocumentLine& l) const; 00174 bool hasLineEverBeenModified(const QDocumentLine& l) const; 00175 00176 virtual void draw(QPainter *p, PaintContext& cxt); 00177 00178 void execute(QDocumentCommand *cmd); 00179 00180 inline QDocumentPrivate* impl() { return m_impl; } 00181 00182 QDocumentConstIterator begin() const; 00183 QDocumentConstIterator end() const; 00184 00185 QDocumentConstIterator iterator(int ln) const; 00186 QDocumentConstIterator iterator(const QDocumentLine& l) const; 00187 00188 void beginMacro(); 00189 void endMacro(); 00190 00191 QFormatScheme* formatScheme() const; 00192 void setFormatScheme(QFormatScheme *f); 00193 00194 int getNextGroupId(); 00195 void releaseGroupId(int groupId); 00196 void clearMatches(int groupId); 00197 void flushMatches(int groupId); 00198 void addMatch(int groupId, int line, int pos, int len, int format); 00199 00200 static QFont font(); 00201 static void setFont(const QFont& f); 00202 static const QFontMetrics& fontMetrics(); 00203 00204 static LineEnding defaultLineEnding(); 00205 static void setDefaultLineEnding(LineEnding le); 00206 00207 static int tabStop(); 00208 static void setTabStop(int n); 00209 00210 static WhiteSpaceMode showSpaces(); 00211 static void setShowSpaces(WhiteSpaceMode y); 00212 00213 static QFormatScheme* defaultFormatScheme(); 00214 static void setDefaultFormatScheme(QFormatScheme *f); 00215 00216 static QFormatScheme* formatFactory(); 00217 static void setFormatFactory(QFormatScheme *f); 00218 00219 static int screenLength(const QChar *d, int l, int tabStop); 00220 static QString screenable(const QChar *d, int l, int tabStop); 00221 00222 inline void markViewDirty() { formatsChanged(); } 00223 00224 bool isClean() const; 00225 00226 public slots: 00227 void clear(); 00228 00229 void undo(); 00230 void redo(); 00231 00232 void setClean(); 00233 00234 void highlight(); 00235 00236 void print(QPrinter *p); 00237 00238 void clearWidthConstraint(); 00239 void setWidthConstraint(int width); 00240 00241 signals: 00242 void cleanChanged(bool m); 00243 00244 void undoAvailable(bool y); 00245 void redoAvailable(bool y); 00246 00247 void formatsChanged(); 00248 void contentsChanged(); 00249 00250 void formatsChange (int line, int lines); 00251 void contentsChange(int line, int lines); 00252 00253 void widthChanged(int width); 00254 void heightChanged(int height); 00255 void sizeChanged(const QSize& s); 00256 00257 void lineCountChanged(int n); 00258 void visualLineCountChanged(int n); 00259 00260 void lineDeleted(QDocumentLineHandle *h); 00261 void markChanged(QDocumentLineHandle *l, int m, bool on); 00262 00263 void lineEndingChanged(int lineEnding); 00264 00265 private: 00266 QString m_leftOver; 00267 QDocumentPrivate *m_impl; 00268 }; 00269 00270 Q_DECLARE_OPERATORS_FOR_FLAGS(QDocument::WhiteSpaceMode) 00271 00272 #endif 00273