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.widgets.textedit;
15 extern(C++):
16 
17 import qt.config;
18 import qt.core.coreevent;
19 import qt.core.flags;
20 import qt.core.global;
21 import qt.core.list;
22 import qt.core.mimedata;
23 import qt.core.namespace;
24 import qt.core.point;
25 import qt.core.rect;
26 import qt.core.string;
27 import qt.core.url;
28 import qt.core.variant;
29 import qt.gui.color;
30 import qt.gui.event;
31 import qt.gui.font;
32 import qt.gui.pagedpaintdevice;
33 import qt.gui.textcursor;
34 import qt.gui.textdocument;
35 import qt.gui.textformat;
36 import qt.gui.textoption;
37 import qt.helpers;
38 import qt.widgets.abstractscrollarea;
39 import qt.widgets.widget;
40 version(QT_NO_CONTEXTMENU){}else
41     import qt.widgets.menu;
42 
43 /+ QT_REQUIRE_CONFIG(textedit); +/
44 
45 
46 extern(C++, class) struct QStyleSheet;
47 /+ class QTextDocument;
48 class QMenu; +/
49 extern(C++, class) struct QTextEditPrivate;
50 /+ class QMimeData;
51 class QPagedPaintDevice;
52 class QRegularExpression; +/
53 
54 class /+ Q_WIDGETS_EXPORT +/ QTextEdit : QAbstractScrollArea
55 {
56     mixin(Q_OBJECT);
57     /+ Q_DECLARE_PRIVATE(QTextEdit) +/
58     /+ Q_PROPERTY(AutoFormatting autoFormatting READ autoFormatting WRITE setAutoFormatting)
59     Q_PROPERTY(bool tabChangesFocus READ tabChangesFocus WRITE setTabChangesFocus)
60     Q_PROPERTY(QString documentTitle READ documentTitle WRITE setDocumentTitle)
61     Q_PROPERTY(bool undoRedoEnabled READ isUndoRedoEnabled WRITE setUndoRedoEnabled)
62     Q_PROPERTY(LineWrapMode lineWrapMode READ lineWrapMode WRITE setLineWrapMode)
63     QDOC_PROPERTY(QTextOption::WrapMode wordWrapMode READ wordWrapMode WRITE setWordWrapMode)
64     Q_PROPERTY(int lineWrapColumnOrWidth READ lineWrapColumnOrWidth WRITE setLineWrapColumnOrWidth)
65     Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly)
66 #if QT_CONFIG(textmarkdownreader) && QT_CONFIG(textmarkdownwriter)
67     Q_PROPERTY(QString markdown READ toMarkdown WRITE setMarkdown NOTIFY textChanged)
68 #endif
69 #ifndef QT_NO_TEXTHTMLPARSER
70     Q_PROPERTY(QString html READ toHtml WRITE setHtml NOTIFY textChanged USER true)
71 #endif
72     Q_PROPERTY(QString plainText READ toPlainText WRITE setPlainText DESIGNABLE false)
73     Q_PROPERTY(bool overwriteMode READ overwriteMode WRITE setOverwriteMode)
74 #if QT_DEPRECATED_SINCE(5, 10)
75     Q_PROPERTY(int tabStopWidth READ tabStopWidth WRITE setTabStopWidth)
76 #endif
77     Q_PROPERTY(qreal tabStopDistance READ tabStopDistance WRITE setTabStopDistance)
78     Q_PROPERTY(bool acceptRichText READ acceptRichText WRITE setAcceptRichText)
79     Q_PROPERTY(int cursorWidth READ cursorWidth WRITE setCursorWidth)
80     Q_PROPERTY(Qt::TextInteractionFlags textInteractionFlags READ textInteractionFlags WRITE setTextInteractionFlags)
81     Q_PROPERTY(QTextDocument *document READ document WRITE setDocument DESIGNABLE false)
82     Q_PROPERTY(QString placeholderText READ placeholderText WRITE setPlaceholderText) +/
83 public:
84     enum LineWrapMode {
85         NoWrap,
86         WidgetWidth,
87         FixedPixelWidth,
88         FixedColumnWidth
89     }
90     /+ Q_ENUM(LineWrapMode) +/
91 
92     enum AutoFormattingFlag {
93         AutoNone = 0,
94         AutoBulletList = 0x00000001,
95         AutoAll = 0xffffffff
96     }
97 
98     /+ Q_DECLARE_FLAGS(AutoFormatting, AutoFormattingFlag) +/
99 alias AutoFormatting = QFlags!(AutoFormattingFlag);    /+ Q_FLAG(AutoFormatting) +/
100 
101     /+ explicit +/this(QWidget parent = null);
102     /+ explicit +/this(ref const(QString) text, QWidget parent = null);
103     /+ virtual +/~this();
104 
105     final void setDocument(QTextDocument document);
106     final QTextDocument document() const;
107 
108     final void setPlaceholderText(ref const(QString) placeholderText);
109     final QString placeholderText() const;
110 
111     final void setTextCursor(ref const(QTextCursor) cursor);
112     final QTextCursor textCursor() const;
113 
114     final bool isReadOnly() const;
115     final void setReadOnly(bool ro);
116 
117     final void setTextInteractionFlags(/+ Qt:: +/qt.core.namespace.TextInteractionFlags flags);
118     final /+ Qt:: +/qt.core.namespace.TextInteractionFlags textInteractionFlags() const;
119 
120     final qreal fontPointSize() const;
121     final QString fontFamily() const;
122     final int fontWeight() const;
123     final bool fontUnderline() const;
124     final bool fontItalic() const;
125     final QColor textColor() const;
126     final QColor textBackgroundColor() const;
127     final QFont currentFont() const;
128     final /+ Qt:: +/qt.core.namespace.Alignment alignment() const;
129 
130     final void mergeCurrentCharFormat(ref const(QTextCharFormat) modifier);
131 
132     final void setCurrentCharFormat(ref const(QTextCharFormat) format);
133     final QTextCharFormat currentCharFormat() const;
134 
135     final AutoFormatting autoFormatting() const;
136     final void setAutoFormatting(AutoFormatting features);
137 
138     final bool tabChangesFocus() const;
139     final void setTabChangesFocus(bool b);
140 
141     pragma(inline, true) final void setDocumentTitle(ref const(QString) title)
142     { document().setMetaInformation(QTextDocument.MetaInformation.DocumentTitle, title); }
143     pragma(inline, true) final QString documentTitle() const
144     { return document().metaInformation(QTextDocument.MetaInformation.DocumentTitle); }
145 
146     pragma(inline, true) final bool isUndoRedoEnabled() const
147     { return document().isUndoRedoEnabled(); }
148     pragma(inline, true) final void setUndoRedoEnabled(bool enable)
149     { document().setUndoRedoEnabled(enable); }
150 
151     final LineWrapMode lineWrapMode() const;
152     final void setLineWrapMode(LineWrapMode mode);
153 
154     final int lineWrapColumnOrWidth() const;
155     final void setLineWrapColumnOrWidth(int w);
156 
157     final QTextOption.WrapMode wordWrapMode() const;
158     final void setWordWrapMode(QTextOption.WrapMode policy);
159 
160     /+ bool find(const QString &exp, QTextDocument::FindFlags options = QTextDocument::FindFlags()); +/
161 /+ #ifndef QT_NO_REGEXP +/
162     version(QT_NO_REGEXP){}else
163     {
164         /+ bool find(const QRegExp &exp, QTextDocument::FindFlags options = QTextDocument::FindFlags()); +/
165     }
166 /+ #endif
167 #if QT_CONFIG(regularexpression) +/
168     /+ bool find(const QRegularExpression &exp, QTextDocument::FindFlags options = QTextDocument::FindFlags()); +/
169 /+ #endif +/
170 
171     final QString toPlainText() const;
172 /+ #ifndef QT_NO_TEXTHTMLPARSER +/
173     version(QT_NO_TEXTHTMLPARSER){}else
174     {
175         final QString toHtml() const;
176     }
177 /+ #endif
178 #if QT_CONFIG(textmarkdownwriter) +/
179     final QString toMarkdown(QTextDocument.MarkdownFeatures features = QTextDocument.MarkdownFeature.MarkdownDialectGitHub) const;
180 /+ #endif +/
181 
182     final void ensureCursorVisible();
183 
184     /+ virtual +/ @QInvokable QVariant loadResource(int type, ref const(QUrl) name);
185     version(QT_NO_CONTEXTMENU){}else
186     {
187         final QMenu createStandardContextMenu();
188         final QMenu createStandardContextMenu(ref const(QPoint) position);
189     }
190 
191     final QTextCursor cursorForPosition(ref const(QPoint) pos) const;
192     final QRect cursorRect(ref const(QTextCursor) cursor) const;
193     final QRect cursorRect() const;
194 
195     final QString anchorAt(ref const(QPoint) pos) const;
196 
197     final bool overwriteMode() const;
198     final void setOverwriteMode(bool overwrite);
199 
200 /+ #if QT_DEPRECATED_SINCE(5, 10) +/
201     /+ QT_DEPRECATED +/ final int tabStopWidth() const;
202     /+ QT_DEPRECATED +/ final void setTabStopWidth(int width);
203 /+ #endif +/
204 
205     final qreal tabStopDistance() const;
206     final void setTabStopDistance(qreal distance);
207 
208     final int cursorWidth() const;
209     final void setCursorWidth(int width);
210 
211     final bool acceptRichText() const;
212     final void setAcceptRichText(bool accept);
213 
214     struct ExtraSelection
215     {
216         QTextCursor cursor;
217         QTextCharFormat format;
218     }
219     final void setExtraSelections(ref const(QList!(ExtraSelection)) selections);
220     final QList!(ExtraSelection) extraSelections() const;
221 
222     final void moveCursor(QTextCursor.MoveOperation operation, QTextCursor.MoveMode mode = QTextCursor.MoveMode.MoveAnchor);
223 
224     final bool canPaste() const;
225 
226     final void print(QPagedPaintDevice printer) const;
227 
228     override QVariant inputMethodQuery(/+ Qt:: +/qt.core.namespace.InputMethodQuery property) const;
229     @QInvokable final QVariant inputMethodQuery(/+ Qt:: +/qt.core.namespace.InputMethodQuery query, QVariant argument) const;
230 
231 public /+ Q_SLOTS +/:
232     @QSlot final void setFontPointSize(qreal s);
233     @QSlot final void setFontFamily(ref const(QString) fontFamily);
234     @QSlot final void setFontWeight(int w);
235     @QSlot final void setFontUnderline(bool b);
236     @QSlot final void setFontItalic(bool b);
237     @QSlot final void setTextColor(ref const(QColor) c);
238     @QSlot final void setTextBackgroundColor(ref const(QColor) c);
239     @QSlot final void setCurrentFont(ref const(QFont) f);
240     @QSlot final void setAlignment(/+ Qt:: +/qt.core.namespace.Alignment a);
241 
242     @QSlot final void setPlainText(ref const(QString) text);
243     final void setPlainText(const(QString) text)
244     {
245         setPlainText(text);
246     }
247 /+ #ifndef QT_NO_TEXTHTMLPARSER +/
248     version(QT_NO_TEXTHTMLPARSER){}else
249     {
250         @QSlot final void setHtml(ref const(QString) text);
251         final void setHtml(const(QString) text)
252         {
253             setHtml(text);
254         }
255     }
256 /+ #endif
257 #if QT_CONFIG(textmarkdownreader) +/
258     @QSlot final void setMarkdown(ref const(QString) markdown);
259     final void setMarkdown(const(QString) markdown)
260     {
261         setMarkdown(markdown);
262     }
263 /+ #endif +/
264     @QSlot final void setText(ref const(QString) text);
265     final void setText(const(QString) text)
266     {
267         setText(text);
268     }
269 
270     version(QT_NO_CLIPBOARD){}else
271     {
272         @QSlot final void cut();
273         /+ void copy(); +/
274         @QSlot final void paste();
275     }
276 
277     @QSlot final void undo();
278     @QSlot final void redo();
279 
280     @QSlot final void clear();
281     @QSlot final void selectAll();
282 
283     @QSlot final void insertPlainText(ref const(QString) text);
284     version(QT_NO_TEXTHTMLPARSER){}else
285     {
286         @QSlot final void insertHtml(ref const(QString) text);
287     }
288 
289     @QSlot final void append(ref const(QString) text);
290 
291     @QSlot final void scrollToAnchor(ref const(QString) name);
292 
293     @QSlot final void zoomIn(int range = 1);
294     @QSlot final void zoomOut(int range = 1);
295 
296 /+ Q_SIGNALS +/public:
297     @QSignal final void textChanged();
298     @QSignal final void undoAvailable(bool b);
299     @QSignal final void redoAvailable(bool b);
300     @QSignal final void currentCharFormatChanged(ref const(QTextCharFormat) format);
301     @QSignal final void copyAvailable(bool b);
302     @QSignal final void selectionChanged();
303     @QSignal final void cursorPositionChanged();
304 
305 protected:
306     /+ virtual +/ override bool event(QEvent e);
307     /+ virtual +/ override void timerEvent(QTimerEvent e);
308     /+ virtual +/ override void keyPressEvent(QKeyEvent e);
309     /+ virtual +/ override void keyReleaseEvent(QKeyEvent e);
310     /+ virtual +/ override void resizeEvent(QResizeEvent e);
311     /+ virtual +/ override void paintEvent(QPaintEvent e);
312     /+ virtual +/ override void mousePressEvent(QMouseEvent e);
313     /+ virtual +/ override void mouseMoveEvent(QMouseEvent e);
314     /+ virtual +/ override void mouseReleaseEvent(QMouseEvent e);
315     /+ virtual +/ override void mouseDoubleClickEvent(QMouseEvent e);
316     /+ virtual +/ override bool focusNextPrevChild(bool next);
317 /+ #ifndef QT_NO_CONTEXTMENU +/
318     version(QT_NO_CONTEXTMENU){}else
319     {
320         /+ virtual +/ override void contextMenuEvent(QContextMenuEvent e);
321     }
322 /+ #endif
323 #if QT_CONFIG(draganddrop) +/
324     /+ virtual +/ override void dragEnterEvent(QDragEnterEvent e);
325     /+ virtual +/ override void dragLeaveEvent(QDragLeaveEvent e);
326     /+ virtual +/ override void dragMoveEvent(QDragMoveEvent e);
327     /+ virtual +/ override void dropEvent(QDropEvent e);
328 /+ #endif +/
329     /+ virtual +/ override void focusInEvent(QFocusEvent e);
330     /+ virtual +/ override void focusOutEvent(QFocusEvent e);
331     /+ virtual +/ override void showEvent(QShowEvent );
332     /+ virtual +/ override void changeEvent(QEvent e);
333 /+ #if QT_CONFIG(wheelevent) +/
334     /+ virtual +/ override void wheelEvent(QWheelEvent e);
335 /+ #endif +/
336 
337     /+ virtual +/ QMimeData createMimeDataFromSelection() const;
338     mixin(mangleWindows("?canInsertFromMimeData@QTextEdit@@MEBA_NPEBVQMimeData@@@Z", q{
339     /+ virtual +/ bool canInsertFromMimeData(const(QMimeData) source) const;
340     }));
341     mixin(mangleWindows("?insertFromMimeData@QTextEdit@@MEAAXPEBVQMimeData@@@Z", q{
342     /+ virtual +/ void insertFromMimeData(const(QMimeData) source);
343     }));
344 
345     /+ virtual +/ override void inputMethodEvent(QInputMethodEvent );
346 
347     this(ref QTextEditPrivate dd, QWidget parent);
348 
349     /+ virtual +/ override void scrollContentsBy(int dx, int dy);
350     /+ virtual +/ void doSetTextCursor(ref const(QTextCursor) cursor);
351 
352     final void zoomInF(float range);
353 
354 private:
355     /+ Q_DISABLE_COPY(QTextEdit) +/
356     /+ Q_PRIVATE_SLOT(d_func(), void _q_repaintContents(const QRectF &r))
357     Q_PRIVATE_SLOT(d_func(), void _q_currentCharFormatChanged(const QTextCharFormat &))
358     Q_PRIVATE_SLOT(d_func(), void _q_adjustScrollbars())
359     Q_PRIVATE_SLOT(d_func(), void _q_ensureVisible(const QRectF &))
360     Q_PRIVATE_SLOT(d_func(), void _q_cursorPositionChanged())
361 #if QT_CONFIG(cursor)
362     Q_PRIVATE_SLOT(d_func(), void _q_hoveredBlockWithMarkerChanged(const QTextBlock &))
363 #endif +/
364     /+ friend class QTextEditControl; +/
365     /+ friend class QTextDocument; +/
366     /+ friend class QWidgetTextControl; +/
367 }
368 /+pragma(inline, true) QFlags!(QTextEdit.AutoFormatting.enum_type) operator |(QTextEdit.AutoFormatting.enum_type f1, QTextEdit.AutoFormatting.enum_type f2)/+noexcept+/{return QFlags!(QTextEdit.AutoFormatting.enum_type)(f1)|f2;}+/
369 /+pragma(inline, true) QFlags!(QTextEdit.AutoFormatting.enum_type) operator |(QTextEdit.AutoFormatting.enum_type f1, QFlags!(QTextEdit.AutoFormatting.enum_type) f2)/+noexcept+/{return f2|f1;}+/
370 /+pragma(inline, true) QIncompatibleFlag operator |(QTextEdit.AutoFormatting.enum_type f1, int f2)/+noexcept+/{return QIncompatibleFlag(int(f1)|f2);}+/
371 
372 /+ Q_DECLARE_OPERATORS_FOR_FLAGS(QTextEdit::AutoFormatting) +/