QCodeEdit  2.2
qdocument.h
Go to the documentation of this file.
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_H_
17 #define _QDOCUMENT_H_
18 
19 #include "qce-config.h"
20 
28 #include <QList>
29 #include <QVector>
30 #include <QLinkedList>
31 
32 #include <QObject>
33 #include <QPalette>
34 #include <QMetaType>
35 
36 class QFont;
37 class QRect;
38 class QPrinter;
39 class QDateTime;
40 class QFormatScheme;
42 
44 {
45  int start, end;
46  int startLine, endLine;
47 };
48 
49 class QDocumentLine;
50 class QDocumentCursor;
51 class QDocumentPrivate;
52 class QDocumentCommand;
55 
56 typedef QVector<QDocumentLineHandle*>::iterator QDocumentIterator;
57 typedef QVector<QDocumentLineHandle*>::const_iterator QDocumentConstIterator;
58 
59 Q_DECLARE_METATYPE(QDocumentIterator)
60 Q_DECLARE_METATYPE(QDocumentConstIterator)
61 
63 {
64  friend class QMatcher;
65  friend class QDocumentPrivate;
66  friend class QDocumentCommand;
67 
68  Q_OBJECT
69 
70  public:
71  struct PaintContext
72  {
73  int width;
74  int height;
75  int xoffset;
76  int yoffset;
77  QPalette palette;
78  bool blinkingCursor;
79  bool fillCursorRect;
82  QList<QDocumentSelection> selections;
83  };
84 
85  enum LineEnding
86  {
87  Conservative,
88  Local,
89  Unix,
90  Windows,
91  Mac, // backward compat only : use OldMac instead (more self-explanatory)
92  OldMac = Mac
93  };
94 
95  enum TextProcessing
96  {
97  RemoveTrailingWS = 1,
98  PreserveIndent = 2,
99  RestoreTrailingIndent = 4
100  };
101 
102  enum WhiteSpaceFlag
103  {
104  ShowNone = 0x00,
105  ShowTrailing = 0x01,
106  ShowLeading = 0x02,
107  ShowTabs = 0x04
108  };
109 
110  Q_DECLARE_FLAGS(WhiteSpaceMode, WhiteSpaceFlag)
111 
112  explicit QDocument(QObject *p = 0);
113  virtual ~QDocument();
114 
115  QString text(int mode) const;
116  QString text(bool removeTrailing = false, bool preserveIndent = true) const;
117  void setText(const QString& s);
118 
119  void startChunkLoading();
120  void stopChunkLoading();
121  void addChunk(const QString& txt);
122 
123  LineEnding lineEnding() const;
124  LineEnding originalLineEnding() const;
125  void setLineEnding(LineEnding le);
126 
127  QDateTime lastModified() const;
128  void setLastModified(const QDateTime& d);
129 
130  bool canUndo() const;
131  bool canRedo() const;
132 
133  int width() const;
134  int height() const;
135  int widthConstraint() const;
136 
137  int lines() const;
138  int lineCount() const;
139  int visualLines() const;
140  int visualLineCount() const;
141 
142  int visualLineNumber(int textLineNumber) const;
143  int textLineNumber(int visualLineNumber) const;
144 
145  int y(int line) const;
146  int lineNumber(int ypos, int *wrap = 0) const;
147  int y(const QDocumentLine& l) const;
148 
149  QRect lineRect(int line) const;
150  QRect lineRect(const QDocumentLine& l) const;
151 
152  QDocumentCursor* editCursor() const;
153  void setEditCursor(QDocumentCursor *c);
154 
155  QLanguageDefinition* languageDefinition() const;
156  void setLanguageDefinition(QLanguageDefinition *l);
157 
158  int maxMarksPerLine() const;
159  int findNextMark(int id, int from = 0, int until = -1) const;
160  int findPreviousMark(int id, int from = -1, int until = 0) const;
161 
162  QDocumentLine lineAt(const QPoint& p) const;
163  void cursorForDocumentPosition(const QPoint& p, int& line, int& column) const;
164  QDocumentCursor cursorAt(const QPoint& p) const;
165 
166  QDocumentLine line(int line) const;
167  QDocumentLine line(QDocumentConstIterator iterator) const;
168 
169  QDocumentCursor cursor(int line, int column = 0) const;
170 
171  QDocumentLine findLine(int& position) const;
172 
173  bool isLineModified(const QDocumentLine& l) const;
174  bool hasLineEverBeenModified(const QDocumentLine& l) const;
175 
176  virtual void draw(QPainter *p, PaintContext& cxt);
177 
178  void execute(QDocumentCommand *cmd);
179 
180  inline QDocumentPrivate* impl() { return m_impl; }
181 
182  QDocumentConstIterator begin() const;
183  QDocumentConstIterator end() const;
184 
185  QDocumentConstIterator iterator(int ln) const;
186  QDocumentConstIterator iterator(const QDocumentLine& l) const;
187 
188  void beginMacro();
189  void endMacro();
190 
191  QFormatScheme* formatScheme() const;
192  void setFormatScheme(QFormatScheme *f);
193 
194  int getNextGroupId();
195  void releaseGroupId(int groupId);
196  void clearMatches(int groupId);
197  void flushMatches(int groupId);
198  void addMatch(int groupId, int line, int pos, int len, int format);
199 
200  static QFont font();
201  static void setFont(const QFont& f);
202  static const QFontMetrics& fontMetrics();
203 
204  static LineEnding defaultLineEnding();
205  static void setDefaultLineEnding(LineEnding le);
206 
207  static int tabStop();
208  static void setTabStop(int n);
209 
210  static WhiteSpaceMode showSpaces();
211  static void setShowSpaces(WhiteSpaceMode y);
212 
213  static QFormatScheme* defaultFormatScheme();
214  static void setDefaultFormatScheme(QFormatScheme *f);
215 
216  static QFormatScheme* formatFactory();
217  static void setFormatFactory(QFormatScheme *f);
218 
219  static int screenLength(const QChar *d, int l, int tabStop);
220  static QString screenable(const QChar *d, int l, int tabStop);
221 
222  inline void markViewDirty() { formatsChanged(); }
223 
224  bool isClean() const;
225 
226  public slots:
227  void clear();
228 
229  void undo();
230  void redo();
231 
232  void setClean();
233 
234  void highlight();
235 
236  void print(QPrinter *p);
237 
238  void clearWidthConstraint();
239  void setWidthConstraint(int width);
240 
241  signals:
242  void cleanChanged(bool m);
243 
244  void undoAvailable(bool y);
245  void redoAvailable(bool y);
246 
247  void formatsChanged();
248  void contentsChanged();
249 
250  void formatsChange (int line, int lines);
251  void contentsChange(int line, int lines);
252 
253  void widthChanged(int width);
254  void heightChanged(int height);
255  void sizeChanged(const QSize& s);
256 
257  void lineCountChanged(int n);
258  void visualLineCountChanged(int n);
259 
260  void lineDeleted(QDocumentLineHandle *h);
261  void markChanged(QDocumentLineHandle *l, int m, bool on);
262 
263  void lineEndingChanged(int lineEnding);
264 
265  private:
266  QString m_leftOver;
267  QDocumentPrivate *m_impl;
268 };
269 
270 Q_DECLARE_OPERATORS_FOR_FLAGS(QDocument::WhiteSpaceMode)
271 
272 #endif
273 
#define QCE_EXPORT
Macro needed for cross-platform shared libraries creation.
Definition: qce-config.h:40
Utility file for shared library creation.
A class storing a document.
Definition: qdocument.h:62
Definition: qdocumentcursor_p.h:45
Definition: qdocument.h:43
Definition: qformat.h:29
The base class for document editing command.
Definition: qdocumentcommand.h:34
A storage/configuration class for shared highlighting formats.
Definition: qformatscheme.h:41
Definition: qdocument_p.h:54
Definition: qdocument.h:71
Private implementation of a document line.
Definition: qdocumentline_p.h:55
A reference to line objects.
Definition: qdocumentline.h:63
Interface for language definition.
Definition: qlanguagedefinition.h:40
A cursor to navigate within documents and edit them.
Definition: qdocumentcursor.h:36