1
/****************************************************************************
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4
** Contact: http://www.qt-project.org/legal
6
** This file is part of the QtGui module of the Qt Toolkit.
8
** $QT_BEGIN_LICENSE:LGPL$
9
** Commercial License Usage
10
** Licensees holding valid commercial Qt licenses may use this file in
11
** accordance with the commercial license agreement provided with the
12
** Software or, alternatively, in accordance with the terms contained in
13
** a written agreement between you and Digia. For licensing terms and
14
** conditions see http://qt.digia.com/licensing. For further information
15
** use the contact form at http://qt.digia.com/contact-us.
17
** GNU Lesser General Public License Usage
18
** Alternatively, this file may be used under the terms of the GNU Lesser
19
** General Public License version 2.1 as published by the Free Software
20
** Foundation and appearing in the file LICENSE.LGPL included in the
21
** packaging of this file. Please review the following information to
22
** ensure the GNU Lesser General Public License version 2.1 requirements
23
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25
** In addition, as a special exception, Digia gives you certain additional
26
** rights. These rights are described in the Digia Qt LGPL Exception
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29
** GNU General Public License Usage
30
** Alternatively, this file may be used under the terms of the GNU
31
** General Public License version 3.0 as published by the Free Software
32
** Foundation and appearing in the file LICENSE.GPL included in the
33
** packaging of this file. Please review the following information to
34
** ensure the GNU General Public License version 3.0 requirements will be
35
** met: http://www.gnu.org/copyleft/gpl.html.
40
****************************************************************************/
45
#include <QtWidgets/qabstractscrollarea.h>
46
#include <QtGui/qtextdocument.h>
47
#include <QtGui/qtextoption.h>
48
#include <QtGui/qtextcursor.h>
49
#include <QtGui/qtextformat.h>
51
#ifndef QT_NO_TEXTEDIT
62
class QTextEditPrivate;
64
class QPagedPaintDevice;
66
class Q_WIDGETS_EXPORT QTextEdit : public QAbstractScrollArea
69
Q_DECLARE_PRIVATE(QTextEdit)
70
Q_FLAGS(AutoFormatting)
72
Q_PROPERTY(AutoFormatting autoFormatting READ autoFormatting WRITE setAutoFormatting)
73
Q_PROPERTY(bool tabChangesFocus READ tabChangesFocus WRITE setTabChangesFocus)
74
Q_PROPERTY(QString documentTitle READ documentTitle WRITE setDocumentTitle)
75
Q_PROPERTY(bool undoRedoEnabled READ isUndoRedoEnabled WRITE setUndoRedoEnabled)
76
Q_PROPERTY(LineWrapMode lineWrapMode READ lineWrapMode WRITE setLineWrapMode)
77
QDOC_PROPERTY(QTextOption::WrapMode wordWrapMode READ wordWrapMode WRITE setWordWrapMode)
78
Q_PROPERTY(int lineWrapColumnOrWidth READ lineWrapColumnOrWidth WRITE setLineWrapColumnOrWidth)
79
Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly)
80
#ifndef QT_NO_TEXTHTMLPARSER
81
Q_PROPERTY(QString html READ toHtml WRITE setHtml NOTIFY textChanged USER true)
83
Q_PROPERTY(QString plainText READ toPlainText WRITE setPlainText DESIGNABLE false)
84
Q_PROPERTY(bool overwriteMode READ overwriteMode WRITE setOverwriteMode)
85
Q_PROPERTY(int tabStopWidth READ tabStopWidth WRITE setTabStopWidth)
86
Q_PROPERTY(bool acceptRichText READ acceptRichText WRITE setAcceptRichText)
87
Q_PROPERTY(int cursorWidth READ cursorWidth WRITE setCursorWidth)
88
Q_PROPERTY(Qt::TextInteractionFlags textInteractionFlags READ textInteractionFlags WRITE setTextInteractionFlags)
89
Q_PROPERTY(QTextDocument *document READ document WRITE setDocument)
98
enum AutoFormattingFlag {
100
AutoBulletList = 0x00000001,
104
Q_DECLARE_FLAGS(AutoFormatting, AutoFormattingFlag)
106
explicit QTextEdit(QWidget *parent = 0);
107
explicit QTextEdit(const QString &text, QWidget *parent = 0);
108
virtual ~QTextEdit();
110
void setDocument(QTextDocument *document);
111
QTextDocument *document() const;
113
void setTextCursor(const QTextCursor &cursor);
114
QTextCursor textCursor() const;
116
bool isReadOnly() const;
117
void setReadOnly(bool ro);
119
void setTextInteractionFlags(Qt::TextInteractionFlags flags);
120
Qt::TextInteractionFlags textInteractionFlags() const;
122
qreal fontPointSize() const;
123
QString fontFamily() const;
124
int fontWeight() const;
125
bool fontUnderline() const;
126
bool fontItalic() const;
127
QColor textColor() const;
128
QColor textBackgroundColor() const;
129
QFont currentFont() const;
130
Qt::Alignment alignment() const;
132
void mergeCurrentCharFormat(const QTextCharFormat &modifier);
134
void setCurrentCharFormat(const QTextCharFormat &format);
135
QTextCharFormat currentCharFormat() const;
137
AutoFormatting autoFormatting() const;
138
void setAutoFormatting(AutoFormatting features);
140
bool tabChangesFocus() const;
141
void setTabChangesFocus(bool b);
143
inline void setDocumentTitle(const QString &title)
144
{ document()->setMetaInformation(QTextDocument::DocumentTitle, title); }
145
inline QString documentTitle() const
146
{ return document()->metaInformation(QTextDocument::DocumentTitle); }
148
inline bool isUndoRedoEnabled() const
149
{ return document()->isUndoRedoEnabled(); }
150
inline void setUndoRedoEnabled(bool enable)
151
{ document()->setUndoRedoEnabled(enable); }
153
LineWrapMode lineWrapMode() const;
154
void setLineWrapMode(LineWrapMode mode);
156
int lineWrapColumnOrWidth() const;
157
void setLineWrapColumnOrWidth(int w);
159
QTextOption::WrapMode wordWrapMode() const;
160
void setWordWrapMode(QTextOption::WrapMode policy);
162
bool find(const QString &exp, QTextDocument::FindFlags options = 0);
164
QString toPlainText() const;
165
#ifndef QT_NO_TEXTHTMLPARSER
166
QString toHtml() const;
169
void ensureCursorVisible();
171
Q_INVOKABLE virtual QVariant loadResource(int type, const QUrl &name);
172
#ifndef QT_NO_CONTEXTMENU
173
QMenu *createStandardContextMenu();
174
QMenu *createStandardContextMenu(const QPoint &position);
177
QTextCursor cursorForPosition(const QPoint &pos) const;
178
QRect cursorRect(const QTextCursor &cursor) const;
179
QRect cursorRect() const;
181
QString anchorAt(const QPoint& pos) const;
183
bool overwriteMode() const;
184
void setOverwriteMode(bool overwrite);
186
int tabStopWidth() const;
187
void setTabStopWidth(int width);
189
int cursorWidth() const;
190
void setCursorWidth(int width);
192
bool acceptRichText() const;
193
void setAcceptRichText(bool accept);
195
struct ExtraSelection
198
QTextCharFormat format;
200
void setExtraSelections(const QList<ExtraSelection> &selections);
201
QList<ExtraSelection> extraSelections() const;
203
void moveCursor(QTextCursor::MoveOperation operation, QTextCursor::MoveMode mode = QTextCursor::MoveAnchor);
205
bool canPaste() const;
207
void print(QPagedPaintDevice *printer) const;
209
QVariant inputMethodQuery(Qt::InputMethodQuery property) const;
212
void setFontPointSize(qreal s);
213
void setFontFamily(const QString &fontFamily);
214
void setFontWeight(int w);
215
void setFontUnderline(bool b);
216
void setFontItalic(bool b);
217
void setTextColor(const QColor &c);
218
void setTextBackgroundColor(const QColor &c);
219
void setCurrentFont(const QFont &f);
220
void setAlignment(Qt::Alignment a);
222
void setPlainText(const QString &text);
223
#ifndef QT_NO_TEXTHTMLPARSER
224
void setHtml(const QString &text);
226
void setText(const QString &text);
228
#ifndef QT_NO_CLIPBOARD
240
void insertPlainText(const QString &text);
241
#ifndef QT_NO_TEXTHTMLPARSER
242
void insertHtml(const QString &text);
243
#endif // QT_NO_TEXTHTMLPARSER
245
void append(const QString &text);
247
void scrollToAnchor(const QString &name);
249
void zoomIn(int range = 1);
250
void zoomOut(int range = 1);
254
void undoAvailable(bool b);
255
void redoAvailable(bool b);
256
void currentCharFormatChanged(const QTextCharFormat &format);
257
void copyAvailable(bool b);
258
void selectionChanged();
259
void cursorPositionChanged();
262
virtual bool event(QEvent *e);
263
virtual void timerEvent(QTimerEvent *e);
264
virtual void keyPressEvent(QKeyEvent *e);
265
virtual void keyReleaseEvent(QKeyEvent *e);
266
virtual void resizeEvent(QResizeEvent *e);
267
virtual void paintEvent(QPaintEvent *e);
268
virtual void mousePressEvent(QMouseEvent *e);
269
virtual void mouseMoveEvent(QMouseEvent *e);
270
virtual void mouseReleaseEvent(QMouseEvent *e);
271
virtual void mouseDoubleClickEvent(QMouseEvent *e);
272
virtual bool focusNextPrevChild(bool next);
273
#ifndef QT_NO_CONTEXTMENU
274
virtual void contextMenuEvent(QContextMenuEvent *e);
276
#ifndef QT_NO_DRAGANDDROP
277
virtual void dragEnterEvent(QDragEnterEvent *e);
278
virtual void dragLeaveEvent(QDragLeaveEvent *e);
279
virtual void dragMoveEvent(QDragMoveEvent *e);
280
virtual void dropEvent(QDropEvent *e);
282
virtual void focusInEvent(QFocusEvent *e);
283
virtual void focusOutEvent(QFocusEvent *e);
284
virtual void showEvent(QShowEvent *);
285
virtual void changeEvent(QEvent *e);
286
#ifndef QT_NO_WHEELEVENT
287
virtual void wheelEvent(QWheelEvent *e);
290
virtual QMimeData *createMimeDataFromSelection() const;
291
virtual bool canInsertFromMimeData(const QMimeData *source) const;
292
virtual void insertFromMimeData(const QMimeData *source);
294
virtual void inputMethodEvent(QInputMethodEvent *);
296
QTextEdit(QTextEditPrivate &dd, QWidget *parent);
298
virtual void scrollContentsBy(int dx, int dy);
299
virtual void doSetTextCursor(const QTextCursor &cursor);
302
Q_DISABLE_COPY(QTextEdit)
303
Q_PRIVATE_SLOT(d_func(), void _q_repaintContents(const QRectF &r))
304
Q_PRIVATE_SLOT(d_func(), void _q_currentCharFormatChanged(const QTextCharFormat &))
305
Q_PRIVATE_SLOT(d_func(), void _q_adjustScrollbars())
306
Q_PRIVATE_SLOT(d_func(), void _q_ensureVisible(const QRectF &))
307
Q_PRIVATE_SLOT(d_func(), void _q_cursorPositionChanged())
308
friend class QTextEditControl;
309
friend class QTextDocument;
310
friend class QWidgetTextControl;
313
Q_DECLARE_OPERATORS_FOR_FLAGS(QTextEdit::AutoFormatting)
319
#endif // QT_NO_TEXTEDIT
321
#endif // QTEXTEDIT_H