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.plaintextedit;
15 extern(C++):
16 
17 import qt.config;
18 import qt.core.coreevent;
19 import qt.core.global;
20 import qt.core.list;
21 import qt.core.mimedata;
22 import qt.core.namespace;
23 import qt.core.point;
24 import qt.core.rect;
25 import qt.core.size;
26 import qt.core.string;
27 import qt.core.url;
28 import qt.core.variant;
29 import qt.gui.abstracttextdocumentlayout;
30 import qt.gui.event;
31 import qt.gui.pagedpaintdevice;
32 import qt.gui.painter;
33 import qt.gui.textcursor;
34 import qt.gui.textdocument;
35 import qt.gui.textformat;
36 import qt.gui.textobject;
37 import qt.gui.textoption;
38 import qt.helpers;
39 import qt.widgets.abstractscrollarea;
40 import qt.widgets.textedit;
41 import qt.widgets.widget;
42 version(QT_NO_CONTEXTMENU){}else
43     import qt.widgets.menu;
44 
45 /+ QT_REQUIRE_CONFIG(textedit);
46 
47 
48 class QStyleSheet;
49 class QTextDocument;
50 class QMenu; +/
51 extern(C++, class) struct QPlainTextEditPrivate;
52 /+ class QMimeData;
53 class QPagedPaintDevice;
54 class QRegularExpression; +/
55 
56 class /+ Q_WIDGETS_EXPORT +/ QPlainTextEdit : QAbstractScrollArea
57 {
58     mixin(Q_OBJECT);
59     /+ Q_DECLARE_PRIVATE(QPlainTextEdit) +/
60     /+ Q_PROPERTY(bool tabChangesFocus READ tabChangesFocus WRITE setTabChangesFocus)
61     Q_PROPERTY(QString documentTitle READ documentTitle WRITE setDocumentTitle)
62     Q_PROPERTY(bool undoRedoEnabled READ isUndoRedoEnabled WRITE setUndoRedoEnabled)
63     Q_PROPERTY(LineWrapMode lineWrapMode READ lineWrapMode WRITE setLineWrapMode)
64     QDOC_PROPERTY(QTextOption::WrapMode wordWrapMode READ wordWrapMode WRITE setWordWrapMode)
65     Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly)
66     Q_PROPERTY(QString plainText READ toPlainText WRITE setPlainText NOTIFY textChanged USER true)
67     Q_PROPERTY(bool overwriteMode READ overwriteMode WRITE setOverwriteMode)
68 #if QT_DEPRECATED_SINCE(5, 10)
69     Q_PROPERTY(int tabStopWidth READ tabStopWidth WRITE setTabStopWidth)
70 #endif
71     Q_PROPERTY(qreal tabStopDistance READ tabStopDistance WRITE setTabStopDistance)
72     Q_PROPERTY(int cursorWidth READ cursorWidth WRITE setCursorWidth)
73     Q_PROPERTY(Qt::TextInteractionFlags textInteractionFlags READ textInteractionFlags WRITE setTextInteractionFlags)
74     Q_PROPERTY(int blockCount READ blockCount)
75     Q_PROPERTY(int maximumBlockCount READ maximumBlockCount WRITE setMaximumBlockCount)
76     Q_PROPERTY(bool backgroundVisible READ backgroundVisible WRITE setBackgroundVisible)
77     Q_PROPERTY(bool centerOnScroll READ centerOnScroll WRITE setCenterOnScroll)
78     Q_PROPERTY(QString placeholderText READ placeholderText WRITE setPlaceholderText) +/
79 public:
80     enum LineWrapMode {
81         NoWrap,
82         WidgetWidth
83     }
84     /+ Q_ENUM(LineWrapMode) +/
85 
86     /+ explicit +/this(QWidget parent = null);
87     /+ explicit +/this(ref const(QString) text, QWidget parent = null);
88     /+ virtual +/~this();
89 
90     final void setDocument(QTextDocument document);
91     final QTextDocument document() const;
92 
93     final void setPlaceholderText(ref const(QString) placeholderText);
94     final QString placeholderText() const;
95 
96     final void setTextCursor(ref const(QTextCursor) cursor);
97     final QTextCursor textCursor() const;
98 
99     final bool isReadOnly() const;
100     final void setReadOnly(bool ro);
101 
102     final void setTextInteractionFlags(/+ Qt:: +/qt.core.namespace.TextInteractionFlags flags);
103     final /+ Qt:: +/qt.core.namespace.TextInteractionFlags textInteractionFlags() const;
104 
105     final void mergeCurrentCharFormat(ref const(QTextCharFormat) modifier);
106     final void setCurrentCharFormat(ref const(QTextCharFormat) format);
107     final QTextCharFormat currentCharFormat() const;
108 
109     final bool tabChangesFocus() const;
110     final void setTabChangesFocus(bool b);
111 
112     pragma(inline, true) final void setDocumentTitle(ref const(QString) title)
113     { document().setMetaInformation(QTextDocument.MetaInformation.DocumentTitle, title); }
114     pragma(inline, true) final QString documentTitle() const
115     { return document().metaInformation(QTextDocument.MetaInformation.DocumentTitle); }
116 
117     pragma(inline, true) final bool isUndoRedoEnabled() const
118     { return document().isUndoRedoEnabled(); }
119     pragma(inline, true) final void setUndoRedoEnabled(bool enable)
120     { document().setUndoRedoEnabled(enable); }
121 
122     pragma(inline, true) final void setMaximumBlockCount(int maximum)
123     { document().setMaximumBlockCount(maximum); }
124     pragma(inline, true) final int maximumBlockCount() const
125     { return document().maximumBlockCount(); }
126 
127 
128     final LineWrapMode lineWrapMode() const;
129     final void setLineWrapMode(LineWrapMode mode);
130 
131     final QTextOption.WrapMode wordWrapMode() const;
132     final void setWordWrapMode(QTextOption.WrapMode policy);
133 
134     final void setBackgroundVisible(bool visible);
135     final bool backgroundVisible() const;
136 
137     final void setCenterOnScroll(bool enabled);
138     final bool centerOnScroll() const;
139 
140     /+ bool find(const QString &exp, QTextDocument::FindFlags options = QTextDocument::FindFlags()); +/
141 /+ #ifndef QT_NO_REGEXP +/
142     version(QT_NO_REGEXP){}else
143     {
144         /+ bool find(const QRegExp &exp, QTextDocument::FindFlags options = QTextDocument::FindFlags()); +/
145     }
146 /+ #endif
147 #if QT_CONFIG(regularexpression) +/
148     /+ bool find(const QRegularExpression &exp, QTextDocument::FindFlags options = QTextDocument::FindFlags()); +/
149 /+ #endif +/
150 
151     pragma(inline, true) final QString toPlainText() const
152     { return document().toPlainText(); }
153 
154     final void ensureCursorVisible();
155 
156     /+ virtual +/ QVariant loadResource(int type, ref const(QUrl) name);
157     version(QT_NO_CONTEXTMENU){}else
158     {
159         final QMenu createStandardContextMenu();
160         final QMenu createStandardContextMenu(ref const(QPoint) position);
161     }
162 
163     final QTextCursor cursorForPosition(ref const(QPoint) pos) const;
164     final QRect cursorRect(ref const(QTextCursor) cursor) const;
165     final QRect cursorRect() const;
166 
167     final QString anchorAt(ref const(QPoint) pos) const;
168 
169     final bool overwriteMode() const;
170     final void setOverwriteMode(bool overwrite);
171 
172 /+ #if QT_DEPRECATED_SINCE(5, 10) +/
173     /+ QT_DEPRECATED +/ final int tabStopWidth() const;
174     /+ QT_DEPRECATED +/ final void setTabStopWidth(int width);
175 /+ #endif +/
176 
177     final qreal tabStopDistance() const;
178     final void setTabStopDistance(qreal distance);
179 
180     final int cursorWidth() const;
181     final void setCursorWidth(int width);
182 
183     final void setExtraSelections(ref const(QList!(QTextEdit.ExtraSelection)) selections);
184     final QList!(QTextEdit.ExtraSelection) extraSelections() const;
185 
186     final void moveCursor(QTextCursor.MoveOperation operation, QTextCursor.MoveMode mode = QTextCursor.MoveMode.MoveAnchor);
187 
188     final bool canPaste() const;
189 
190     final void print(QPagedPaintDevice printer) const;
191 
192     final int blockCount() const;
193     override QVariant inputMethodQuery(/+ Qt:: +/qt.core.namespace.InputMethodQuery property) const;
194     @QInvokable final QVariant inputMethodQuery(/+ Qt:: +/qt.core.namespace.InputMethodQuery query, QVariant argument) const;
195 
196 public /+ Q_SLOTS +/:
197 
198     @QSlot final void setPlainText(ref const(QString) text);
199     final void setPlainText(const QString s){setPlainText(s);}
200 
201     version(QT_NO_CLIPBOARD){}else
202     {
203         @QSlot final void cut();
204         /+ void copy(); +/
205         @QSlot final void paste();
206     }
207 
208     @QSlot final void undo();
209     @QSlot final void redo();
210 
211     @QSlot final void clear();
212     @QSlot final void selectAll();
213 
214     @QSlot final void insertPlainText(ref const(QString) text);
215 
216     @QSlot final void appendPlainText(ref const(QString) text);
217     @QSlot final void appendPlainText(const(QString) text)
218     {
219         appendPlainText(text);
220     }
221     @QSlot final void appendHtml(ref const(QString) html);
222 
223     @QSlot final void centerCursor();
224 
225     @QSlot final void zoomIn(int range = 1);
226     @QSlot final void zoomOut(int range = 1);
227 
228 /+ Q_SIGNALS +/public:
229     @QSignal final void textChanged();
230     @QSignal final void undoAvailable(bool b);
231     @QSignal final void redoAvailable(bool b);
232     @QSignal final void copyAvailable(bool b);
233     @QSignal final void selectionChanged();
234     @QSignal final void cursorPositionChanged();
235 
236     @QSignal final void updateRequest(ref const(QRect) rect, int dy);
237     @QSignal final void blockCountChanged(int newBlockCount);
238     @QSignal final void modificationChanged(bool);
239 
240 protected:
241     /+ virtual +/ override bool event(QEvent e);
242     /+ virtual +/ override void timerEvent(QTimerEvent e);
243     /+ virtual +/ override void keyPressEvent(QKeyEvent e);
244     /+ virtual +/ override void keyReleaseEvent(QKeyEvent e);
245     /+ virtual +/ override void resizeEvent(QResizeEvent e);
246     /+ virtual +/ override void paintEvent(QPaintEvent e);
247     /+ virtual +/ override void mousePressEvent(QMouseEvent e);
248     /+ virtual +/ override void mouseMoveEvent(QMouseEvent e);
249     /+ virtual +/ override void mouseReleaseEvent(QMouseEvent e);
250     /+ virtual +/ override void mouseDoubleClickEvent(QMouseEvent e);
251     /+ virtual +/ override bool focusNextPrevChild(bool next);
252 /+ #ifndef QT_NO_CONTEXTMENU +/
253     version(QT_NO_CONTEXTMENU){}else
254     {
255         /+ virtual +/ override void contextMenuEvent(QContextMenuEvent e);
256     }
257 /+ #endif
258 #if QT_CONFIG(draganddrop) +/
259     /+ virtual +/ override void dragEnterEvent(QDragEnterEvent e);
260     /+ virtual +/ override void dragLeaveEvent(QDragLeaveEvent e);
261     /+ virtual +/ override void dragMoveEvent(QDragMoveEvent e);
262     /+ virtual +/ override void dropEvent(QDropEvent e);
263 /+ #endif +/
264     /+ virtual +/ override void focusInEvent(QFocusEvent e);
265     /+ virtual +/ override void focusOutEvent(QFocusEvent e);
266     /+ virtual +/ override void showEvent(QShowEvent );
267     /+ virtual +/ override void changeEvent(QEvent e);
268 /+ #if QT_CONFIG(wheelevent) +/
269     /+ virtual +/ override void wheelEvent(QWheelEvent e);
270 /+ #endif +/
271 
272     /+ virtual +/ QMimeData createMimeDataFromSelection() const;
273     mixin(mangleWindows("?canInsertFromMimeData@QPlainTextEdit@@MEBA_NPEBVQMimeData@@@Z", q{
274     /+ virtual +/ bool canInsertFromMimeData(const(QMimeData) source) const;
275     }));
276     mixin(mangleWindows("?insertFromMimeData@QPlainTextEdit@@MEAAXPEBVQMimeData@@@Z", q{
277     /+ virtual +/ void insertFromMimeData(const(QMimeData) source);
278     }));
279 
280     /+ virtual +/ override void inputMethodEvent(QInputMethodEvent );
281 
282     this(ref QPlainTextEditPrivate dd, QWidget parent);
283 
284     /+ virtual +/ override void scrollContentsBy(int dx, int dy);
285     /+ virtual +/ void doSetTextCursor(ref const(QTextCursor) cursor);
286 
287     final QTextBlock firstVisibleBlock() const;
288     final QPointF contentOffset() const;
289     final QRectF blockBoundingRect(ref const(QTextBlock) block) const;
290     final QRectF blockBoundingGeometry(ref const(QTextBlock) block) const;
291     final QAbstractTextDocumentLayout.PaintContext getPaintContext() const;
292 
293     final void zoomInF(float range);
294 
295 private:
296     /+ Q_DISABLE_COPY(QPlainTextEdit) +/
297     /+ Q_PRIVATE_SLOT(d_func(), void _q_repaintContents(const QRectF &r))
298     Q_PRIVATE_SLOT(d_func(), void _q_textChanged())
299     Q_PRIVATE_SLOT(d_func(), void _q_adjustScrollbars())
300     Q_PRIVATE_SLOT(d_func(), void _q_verticalScrollbarActionTriggered(int))
301     Q_PRIVATE_SLOT(d_func(), void _q_cursorPositionChanged()) +/
302 
303     /+ friend class QPlainTextEditControl; +/
304 }
305 
306 
307 extern(C++, class) struct QPlainTextDocumentLayoutPrivate;
308 class /+ Q_WIDGETS_EXPORT +/ QPlainTextDocumentLayout : QAbstractTextDocumentLayout
309 {
310     mixin(Q_OBJECT);
311     /+ Q_DECLARE_PRIVATE(QPlainTextDocumentLayout) +/
312     /+ Q_PROPERTY(int cursorWidth READ cursorWidth WRITE setCursorWidth) +/
313 
314 public:
315     this(QTextDocument document);
316     ~this();
317 
318     override void draw(QPainter* , ref const(PaintContext) );
319     override int hitTest(ref const(QPointF) , /+ Qt:: +/qt.core.namespace.HitTestAccuracy ) const;
320 
321     override int pageCount() const;
322     override QSizeF documentSize() const;
323 
324     override QRectF frameBoundingRect(QTextFrame ) const;
325     override QRectF blockBoundingRect(ref const(QTextBlock) block) const;
326 
327     final void ensureBlockLayout(ref const(QTextBlock) block) const;
328 
329     final void setCursorWidth(int width);
330     final int cursorWidth() const;
331 
332     final void requestUpdate();
333 
334 protected:
335     override void documentChanged(int from, int /*charsRemoved*/, int charsAdded);
336 
337 
338 private:
339     final void setTextWidth(qreal newWidth);
340     final qreal textWidth() const;
341     final void layoutBlock(ref const(QTextBlock) block);
342     final qreal blockWidth(ref const(QTextBlock) block);
343 
344     final QPlainTextDocumentLayoutPrivate* priv() const;
345 
346     /+ friend class QPlainTextEdit; +/
347     /+ friend class QPlainTextEditPrivate; +/
348 }
349