1 /****************************************************************************
2 **
3 ** DQt - D bindings for the Qt Toolkit
4 **
5 ** GNU Lesser General Public License Usage
6 ** This file may be used under the terms of the GNU Lesser
7 ** General Public License version 3 as published by the Free Software
8 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
9 ** packaging of this file. Please review the following information to
10 ** ensure the GNU Lesser General Public License version 3 requirements
11 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
12 **
13 ****************************************************************************/
14 module qt.gui.textdocument;
15 extern(C++):
16 
17 import qt.config;
18 import qt.core.bytearray;
19 import qt.core.flags;
20 import qt.core.global;
21 import qt.core.namespace;
22 import qt.core.object;
23 import qt.core.qchar;
24 import qt.core.rect;
25 import qt.core.size;
26 import qt.core.string;
27 import qt.core.textcodec;
28 import qt.core.url;
29 import qt.core.variant;
30 import qt.core.vector;
31 import qt.gui.abstracttextdocumentlayout;
32 import qt.gui.font;
33 import qt.gui.painter;
34 import qt.gui.textcursor;
35 import qt.gui.textformat;
36 import qt.gui.textobject;
37 import qt.gui.textoption;
38 import qt.helpers;
39 version(QT_NO_PRINTER){}else
40     import qt.gui.pagedpaintdevice;
41 
42 
43 extern(C++, class) struct QTextDocumentPrivate;
44 extern(C++, class) struct QTextFormatCollection;
45 /+ class QTextListFormat;
46 class QRect;
47 class QPainter;
48 class QPagedPaintDevice;
49 class QAbstractTextDocumentLayout;
50 class QPoint;
51 class QTextObject;
52 class QTextFormat;
53 class QTextFrame;
54 class QTextBlock;
55 class QTextCodec;
56 class QVariant;
57 class QRectF;
58 class QTextOption;
59 class QTextCursor;
60 
61 template<typename T> class QVector; +/
62 
63 extern(C++, "Qt")
64 {
65     /+ Q_GUI_EXPORT +/ bool mightBeRichText(ref const(QString));
66     /+ Q_GUI_EXPORT +/ QString convertFromPlainText(ref const(QString) plain, qt.core.namespace.WhiteSpaceMode mode = qt.core.namespace.WhiteSpaceMode.WhiteSpacePre);
67 
68 /+ #if QT_CONFIG(textcodec) || defined(Q_CLANG_QDOC) +/
69     /+ Q_GUI_EXPORT +/ QTextCodec codecForHtml(ref const(QByteArray) ba);
70 /+ #endif +/
71 }
72 
73 class /+ Q_GUI_EXPORT +/ QAbstractUndoItem
74 {
75 public:
76     /+ virtual +//*abstract*/ ~this(){}
77     /+ virtual +/ abstract void undo();
78     /+ virtual +/ abstract void redo();
79 }
80 
81 /+ class QTextDocumentPrivate; +/
82 
83 class /+ Q_GUI_EXPORT +/ QTextDocument : QObject
84 {
85     mixin(Q_OBJECT);
86 
87     /+ Q_PROPERTY(bool undoRedoEnabled READ isUndoRedoEnabled WRITE setUndoRedoEnabled)
88     Q_PROPERTY(bool modified READ isModified WRITE setModified DESIGNABLE false)
89     Q_PROPERTY(QSizeF pageSize READ pageSize WRITE setPageSize)
90     Q_PROPERTY(QFont defaultFont READ defaultFont WRITE setDefaultFont)
91     Q_PROPERTY(bool useDesignMetrics READ useDesignMetrics WRITE setUseDesignMetrics)
92     Q_PROPERTY(QSizeF size READ size)
93     Q_PROPERTY(qreal textWidth READ textWidth WRITE setTextWidth)
94     Q_PROPERTY(int blockCount READ blockCount)
95     Q_PROPERTY(qreal indentWidth READ indentWidth WRITE setIndentWidth)
96 #ifndef QT_NO_CSSPARSER
97     Q_PROPERTY(QString defaultStyleSheet READ defaultStyleSheet WRITE setDefaultStyleSheet)
98 #endif
99     Q_PROPERTY(int maximumBlockCount READ maximumBlockCount WRITE setMaximumBlockCount)
100     Q_PROPERTY(qreal documentMargin READ documentMargin WRITE setDocumentMargin)
101     QDOC_PROPERTY(QTextOption defaultTextOption READ defaultTextOption WRITE setDefaultTextOption)
102     Q_PROPERTY(QUrl baseUrl READ baseUrl WRITE setBaseUrl NOTIFY baseUrlChanged) +/
103 
104 public:
105     /+ explicit +/this(QObject parent = null);
106     /+ explicit +/this(ref const(QString) text, QObject parent = null);
107     ~this();
108 
109     final QTextDocument clone(QObject parent = null) const;
110 
111     final bool isEmpty() const;
112     /+ virtual +/ void clear();
113 
114     final void setUndoRedoEnabled(bool enable);
115     final bool isUndoRedoEnabled() const;
116 
117     final bool isUndoAvailable() const;
118     final bool isRedoAvailable() const;
119 
120     final int availableUndoSteps() const;
121     final int availableRedoSteps() const;
122 
123     final int revision() const;
124 
125     final void setDocumentLayout(QAbstractTextDocumentLayout layout);
126     final QAbstractTextDocumentLayout documentLayout() const;
127 
128     enum MetaInformation {
129         DocumentTitle,
130         DocumentUrl
131     }
132     final void setMetaInformation(MetaInformation info, ref const(QString) );
133     final QString metaInformation(MetaInformation info) const;
134 
135 /+ #ifndef QT_NO_TEXTHTMLPARSER +/
136     version(QT_NO_TEXTHTMLPARSER){}else
137     {
138         final QString toHtml(ref const(QByteArray) encoding = globalInitVar!QByteArray) const;
139         final void setHtml(ref const(QString) html);
140     }
141 /+ #endif
142 
143 #if QT_CONFIG(textmarkdownwriter) || QT_CONFIG(textmarkdownreader) +/
144     enum MarkdownFeature {
145         MarkdownNoHTML = 0x0020 | 0x0040,
146         MarkdownDialectCommonMark = 0,
147         MarkdownDialectGitHub = 0x0004 | 0x0008 | 0x0400 | 0x0100 | 0x0200 | 0x0800
148     }
149     /+ Q_DECLARE_FLAGS(MarkdownFeatures, MarkdownFeature) +/
150 alias MarkdownFeatures = QFlags!(MarkdownFeature);    /+ Q_FLAG(MarkdownFeatures) +/
151 /+ #endif
152 
153 #if QT_CONFIG(textmarkdownwriter) +/
154     final QString toMarkdown(MarkdownFeatures features = MarkdownFeature.MarkdownDialectGitHub) const;
155 /+ #endif
156 
157 #if QT_CONFIG(textmarkdownreader) +/
158     final void setMarkdown(ref const(QString) markdown, MarkdownFeatures features = MarkdownFeature.MarkdownDialectGitHub);
159 /+ #endif +/
160 
161     final QString toRawText() const;
162     final QString toPlainText() const;
163     final void setPlainText(ref const(QString) text);
164 
165     final QChar characterAt(int pos) const;
166 
167     enum FindFlag
168     {
169         FindBackward        = 0x00001,
170         FindCaseSensitively = 0x00002,
171         FindWholeWords      = 0x00004
172     }
173     /+ Q_DECLARE_FLAGS(FindFlags, FindFlag) +/
174 alias FindFlags = QFlags!(FindFlag);
175     /+ QTextCursor find(const QString &subString, int from = 0, FindFlags options = FindFlags()) const; +/
176     /+ QTextCursor find(const QString &subString, const QTextCursor &cursor, FindFlags options = FindFlags()) const; +/
177 
178 /+ #ifndef QT_NO_REGEXP +/
179     version(QT_NO_REGEXP){}else
180     {
181         /+ QTextCursor find(const QRegExp &expr, int from = 0, FindFlags options = FindFlags()) const; +/
182         /+ QTextCursor find(const QRegExp &expr, const QTextCursor &cursor, FindFlags options = FindFlags()) const; +/
183     }
184 /+ #endif
185 
186 #if QT_CONFIG(regularexpression) +/
187     /+ QTextCursor find(const QRegularExpression &expr, int from = 0, FindFlags options = FindFlags()) const; +/
188     /+ QTextCursor find(const QRegularExpression &expr, const QTextCursor &cursor, FindFlags options = FindFlags()) const; +/
189 /+ #endif +/
190 
191     final QTextFrame frameAt(int pos) const;
192     final QTextFrame rootFrame() const;
193 
194     final QTextObject object(int objectIndex) const;
195     final QTextObject objectForFormat(ref const(QTextFormat) ) const;
196 
197     final QTextBlock findBlock(int pos) const;
198     final QTextBlock findBlockByNumber(int blockNumber) const;
199     final QTextBlock findBlockByLineNumber(int blockNumber) const;
200     final QTextBlock begin() const;
201     final QTextBlock end() const;
202 
203     final QTextBlock firstBlock() const;
204     final QTextBlock lastBlock() const;
205 
206     final void setPageSize(ref const(QSizeF) size);
207     final QSizeF pageSize() const;
208 
209     final void setDefaultFont(ref const(QFont) font);
210     final QFont defaultFont() const;
211 
212     final int pageCount() const;
213 
214     final bool isModified() const;
215 
216     version(QT_NO_PRINTER){}else
217     {
218         final void print(QPagedPaintDevice printer) const;
219     }
220 
221     enum ResourceType {
222         UnknownResource = 0,
223         HtmlResource  = 1,
224         ImageResource = 2,
225         StyleSheetResource = 3,
226         MarkdownResource = 4,
227 
228         UserResource  = 100
229     }
230     /+ Q_ENUM(ResourceType) +/
231 
232     final QVariant resource(int type, ref const(QUrl) name) const;
233     final void addResource(int type, ref const(QUrl) name, ref const(QVariant) resource);
234 
235     final QVector!(QTextFormat) allFormats() const;
236 
237     final void markContentsDirty(int from, int length);
238 
239     final void setUseDesignMetrics(bool b);
240     final bool useDesignMetrics() const;
241 
242     final void drawContents(QPainter* painter, ref const(QRectF) rect = globalInitVar!QRectF);
243 
244     final void setTextWidth(qreal width);
245     final qreal textWidth() const;
246 
247     final qreal idealWidth() const;
248 
249     final qreal indentWidth() const;
250     final void setIndentWidth(qreal width);
251 
252     final qreal documentMargin() const;
253     final void setDocumentMargin(qreal margin);
254 
255     final void adjustSize();
256     final QSizeF size() const;
257 
258     final int blockCount() const;
259     final int lineCount() const;
260     final int characterCount() const;
261 
262     version(QT_NO_CSSPARSER){}else
263     {
264         final void setDefaultStyleSheet(ref const(QString) sheet);
265         final QString defaultStyleSheet() const;
266     }
267 
268     final void undo(QTextCursor* cursor);
269     final void redo(QTextCursor* cursor);
270 
271     enum Stacks {
272         UndoStack = 0x01,
273         RedoStack = 0x02,
274         UndoAndRedoStacks = Stacks.UndoStack | Stacks.RedoStack
275     }
276     final void clearUndoRedoStacks(Stacks historyToClear = Stacks.UndoAndRedoStacks);
277 
278     final int maximumBlockCount() const;
279     final void setMaximumBlockCount(int maximum);
280 
281     final QTextOption defaultTextOption() const;
282     final void setDefaultTextOption(ref const(QTextOption) option);
283 
284     final QUrl baseUrl() const;
285     final void setBaseUrl(ref const(QUrl) url);
286 
287     final /+ Qt:: +/qt.core.namespace.CursorMoveStyle defaultCursorMoveStyle() const;
288     final void setDefaultCursorMoveStyle(/+ Qt:: +/qt.core.namespace.CursorMoveStyle style);
289 
290 /+ Q_SIGNALS +/public:
291     @QSignal final void contentsChange(int from, int charsRemoved, int charsAdded);
292     @QSignal final void contentsChanged();
293     @QSignal final void undoAvailable(bool);
294     @QSignal final void redoAvailable(bool);
295     @QSignal final void undoCommandAdded();
296     @QSignal final void modificationChanged(bool m);
297     @QSignal final void cursorPositionChanged(ref const(QTextCursor) cursor);
298     @QSignal final void blockCountChanged(int newBlockCount);
299     @QSignal final void baseUrlChanged(ref const(QUrl) url);
300     @QSignal final void documentLayoutChanged();
301 
302 public /+ Q_SLOTS +/:
303     @QSlot final void undo();
304     @QSlot final void redo();
305     @QSlot final void appendUndoItem(QAbstractUndoItem );
306     @QSlot final void setModified(bool m = true);
307 
308 protected:
309     /+ virtual +/ QTextObject createObject(ref const(QTextFormat) f);
310     /+ virtual +/ @QInvokable QVariant loadResource(int type, ref const(QUrl) name);
311 
312     this(ref QTextDocumentPrivate dd, QObject parent);
313 public:
314     final QTextDocumentPrivate* docHandle() const;
315 private:
316     /+ Q_DISABLE_COPY(QTextDocument) +/
317     /+ Q_DECLARE_PRIVATE(QTextDocument) +/
318     /+ friend class QTextObjectPrivate; +/
319 }
320 /+pragma(inline, true) QFlags!(QTextDocument.FindFlags.enum_type) operator |(QTextDocument.FindFlags.enum_type f1, QTextDocument.FindFlags.enum_type f2)/+noexcept+/{return QFlags!(QTextDocument.FindFlags.enum_type)(f1)|f2;}+/
321 /+pragma(inline, true) QFlags!(QTextDocument.FindFlags.enum_type) operator |(QTextDocument.FindFlags.enum_type f1, QFlags!(QTextDocument.FindFlags.enum_type) f2)/+noexcept+/{return f2|f1;}+/
322 /+pragma(inline, true) QIncompatibleFlag operator |(QTextDocument.FindFlags.enum_type f1, int f2)/+noexcept+/{return QIncompatibleFlag(int(f1)|f2);}+/
323 
324 /+ Q_DECLARE_OPERATORS_FOR_FLAGS(QTextDocument::FindFlags) +/