QtGui/qtextedit.h Source File

qtextedit.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
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.
16 **
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.
24 **
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.
28 **
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.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QTEXTEDIT_H
43 #define QTEXTEDIT_H
44 
46 #include <QtGui/qtextdocument.h>
47 #include <QtGui/qtextoption.h>
48 #include <QtGui/qtextcursor.h>
49 #include <QtGui/qtextformat.h>
50 
51 #ifndef QT_NO_TEXTEDIT
52 
53 #ifdef QT3_SUPPORT
54 #include <QtGui/qtextobject.h>
55 #include <QtGui/qtextlayout.h>
56 #endif
57 
59 
61 
62 QT_MODULE(Gui)
63 
64 class QStyleSheet;
65 class QTextDocument;
66 class QMenu;
67 class QTextEditPrivate;
68 class QMimeData;
69 
70 class Q_GUI_EXPORT QTextEdit : public QAbstractScrollArea
71 {
72  Q_OBJECT
73  Q_DECLARE_PRIVATE(QTextEdit)
74  Q_FLAGS(AutoFormatting)
76  Q_PROPERTY(AutoFormatting autoFormatting READ autoFormatting WRITE setAutoFormatting)
77  Q_PROPERTY(bool tabChangesFocus READ tabChangesFocus WRITE setTabChangesFocus)
78  Q_PROPERTY(QString documentTitle READ documentTitle WRITE setDocumentTitle)
79  Q_PROPERTY(bool undoRedoEnabled READ isUndoRedoEnabled WRITE setUndoRedoEnabled)
80  Q_PROPERTY(LineWrapMode lineWrapMode READ lineWrapMode WRITE setLineWrapMode)
81  QDOC_PROPERTY(QTextOption::WrapMode wordWrapMode READ wordWrapMode WRITE setWordWrapMode)
82  Q_PROPERTY(int lineWrapColumnOrWidth READ lineWrapColumnOrWidth WRITE setLineWrapColumnOrWidth)
83  Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly)
84 #ifndef QT_NO_TEXTHTMLPARSER
85  Q_PROPERTY(QString html READ toHtml WRITE setHtml NOTIFY textChanged USER true)
86 #endif
87  Q_PROPERTY(QString plainText READ toPlainText WRITE setPlainText DESIGNABLE false)
88  Q_PROPERTY(bool overwriteMode READ overwriteMode WRITE setOverwriteMode)
89  Q_PROPERTY(int tabStopWidth READ tabStopWidth WRITE setTabStopWidth)
90  Q_PROPERTY(bool acceptRichText READ acceptRichText WRITE setAcceptRichText)
91  Q_PROPERTY(int cursorWidth READ cursorWidth WRITE setCursorWidth)
92  Q_PROPERTY(Qt::TextInteractionFlags textInteractionFlags READ textInteractionFlags WRITE setTextInteractionFlags)
93 public:
94  enum LineWrapMode {
98  FixedColumnWidth
99  };
100 
102  AutoNone = 0,
103  AutoBulletList = 0x00000001,
104  AutoAll = 0xffffffff
105  };
106 
107  Q_DECLARE_FLAGS(AutoFormatting, AutoFormattingFlag)
108 
109 #if defined(QT3_SUPPORT)
110  enum CursorAction {
111  MoveBackward,
112  MoveForward,
113  MoveWordBackward,
114  MoveWordForward,
115  MoveUp,
116  MoveDown,
117  MoveLineStart,
118  MoveLineEnd,
119  MoveHome,
120  MoveEnd,
121  MovePageUp,
122  MovePageDown
123 #if !defined(Q_MOC_RUN)
124  ,
125  MovePgUp = MovePageUp,
126  MovePgDown = MovePageDown
127 #endif
128  };
129 #endif
130 
131  explicit QTextEdit(QWidget *parent = 0);
132  explicit QTextEdit(const QString &text, QWidget *parent = 0);
133  virtual ~QTextEdit();
134 
135  void setDocument(QTextDocument *document);
136  QTextDocument *document() const;
137 
138  void setTextCursor(const QTextCursor &cursor);
139  QTextCursor textCursor() const;
140 
141  bool isReadOnly() const;
142  void setReadOnly(bool ro);
143 
144  void setTextInteractionFlags(Qt::TextInteractionFlags flags);
145  Qt::TextInteractionFlags textInteractionFlags() const;
146 
147  qreal fontPointSize() const;
148  QString fontFamily() const;
149  int fontWeight() const;
150  bool fontUnderline() const;
151  bool fontItalic() const;
152  QColor textColor() const;
153  QColor textBackgroundColor() const;
154  QFont currentFont() const;
155  Qt::Alignment alignment() const;
156 
157  void mergeCurrentCharFormat(const QTextCharFormat &modifier);
158 
159  void setCurrentCharFormat(const QTextCharFormat &format);
160  QTextCharFormat currentCharFormat() const;
161 
162  AutoFormatting autoFormatting() const;
163  void setAutoFormatting(AutoFormatting features);
164 
165  bool tabChangesFocus() const;
166  void setTabChangesFocus(bool b);
167 
168  inline void setDocumentTitle(const QString &title)
169  { document()->setMetaInformation(QTextDocument::DocumentTitle, title); }
170  inline QString documentTitle() const
171  { return document()->metaInformation(QTextDocument::DocumentTitle); }
172 
173  inline bool isUndoRedoEnabled() const
174  { return document()->isUndoRedoEnabled(); }
175  inline void setUndoRedoEnabled(bool enable)
176  { document()->setUndoRedoEnabled(enable); }
177 
178  LineWrapMode lineWrapMode() const;
179  void setLineWrapMode(LineWrapMode mode);
180 
181  int lineWrapColumnOrWidth() const;
182  void setLineWrapColumnOrWidth(int w);
183 
184  QTextOption::WrapMode wordWrapMode() const;
185  void setWordWrapMode(QTextOption::WrapMode policy);
186 
187  bool find(const QString &exp, QTextDocument::FindFlags options = 0);
188 
189  inline QString toPlainText() const
190  { return document()->toPlainText(); }
191 #ifndef QT_NO_TEXTHTMLPARSER
192  inline QString toHtml() const
193  { return document()->toHtml(); }
194 #endif
195 
196  void ensureCursorVisible();
197 
198  virtual QVariant loadResource(int type, const QUrl &name);
199 #ifndef QT_NO_CONTEXTMENU
200  QMenu *createStandardContextMenu();
201  QMenu *createStandardContextMenu(const QPoint &position);
202 #endif
203 
204  QTextCursor cursorForPosition(const QPoint &pos) const;
205  QRect cursorRect(const QTextCursor &cursor) const;
206  QRect cursorRect() const;
207 
208  QString anchorAt(const QPoint& pos) const;
209 
210  bool overwriteMode() const;
211  void setOverwriteMode(bool overwrite);
212 
213  int tabStopWidth() const;
214  void setTabStopWidth(int width);
215 
216  int cursorWidth() const;
217  void setCursorWidth(int width);
218 
219  bool acceptRichText() const;
220  void setAcceptRichText(bool accept);
221 
223  {
226  };
227  void setExtraSelections(const QList<ExtraSelection> &selections);
228  QList<ExtraSelection> extraSelections() const;
229 
231 
232  bool canPaste() const;
233 
234 #ifndef QT_NO_PRINTER
235  void print(QPrinter *printer) const;
236 #endif
237 
238 public Q_SLOTS:
239  void setFontPointSize(qreal s);
240  void setFontFamily(const QString &fontFamily);
241  void setFontWeight(int w);
242  void setFontUnderline(bool b);
243  void setFontItalic(bool b);
244  void setTextColor(const QColor &c);
245  void setTextBackgroundColor(const QColor &c);
246  void setCurrentFont(const QFont &f);
247  void setAlignment(Qt::Alignment a);
248 
249  void setPlainText(const QString &text);
250 #ifndef QT_NO_TEXTHTMLPARSER
251  void setHtml(const QString &text);
252 #endif
253  void setText(const QString &text);
254 
255 #ifndef QT_NO_CLIPBOARD
256  void cut();
257  void copy();
258  void paste();
259 #endif
260 
261  void undo();
262  void redo();
263 
264  void clear();
265  void selectAll();
266 
267  void insertPlainText(const QString &text);
268 #ifndef QT_NO_TEXTHTMLPARSER
269  void insertHtml(const QString &text);
270 #endif // QT_NO_TEXTHTMLPARSER
271 
272  void append(const QString &text);
273 
274  void scrollToAnchor(const QString &name);
275 
276  void zoomIn(int range = 1);
277  void zoomOut(int range = 1);
278 
279 Q_SIGNALS:
280  void textChanged();
281  void undoAvailable(bool b);
282  void redoAvailable(bool b);
283  void currentCharFormatChanged(const QTextCharFormat &format);
284  void copyAvailable(bool b);
285  void selectionChanged();
286  void cursorPositionChanged();
287 
288 protected:
289  virtual bool event(QEvent *e);
290  virtual void timerEvent(QTimerEvent *e);
291  virtual void keyPressEvent(QKeyEvent *e);
292  virtual void keyReleaseEvent(QKeyEvent *e);
293  virtual void resizeEvent(QResizeEvent *e);
294  virtual void paintEvent(QPaintEvent *e);
295  virtual void mousePressEvent(QMouseEvent *e);
296  virtual void mouseMoveEvent(QMouseEvent *e);
297  virtual void mouseReleaseEvent(QMouseEvent *e);
298  virtual void mouseDoubleClickEvent(QMouseEvent *e);
299  virtual bool focusNextPrevChild(bool next);
300 #ifndef QT_NO_CONTEXTMENU
301  virtual void contextMenuEvent(QContextMenuEvent *e);
302 #endif
303 #ifndef QT_NO_DRAGANDDROP
304  virtual void dragEnterEvent(QDragEnterEvent *e);
305  virtual void dragLeaveEvent(QDragLeaveEvent *e);
306  virtual void dragMoveEvent(QDragMoveEvent *e);
307  virtual void dropEvent(QDropEvent *e);
308 #endif
309  virtual void focusInEvent(QFocusEvent *e);
310  virtual void focusOutEvent(QFocusEvent *e);
311  virtual void showEvent(QShowEvent *);
312  virtual void changeEvent(QEvent *e);
313 #ifndef QT_NO_WHEELEVENT
314  virtual void wheelEvent(QWheelEvent *e);
315 #endif
316 
317  virtual QMimeData *createMimeDataFromSelection() const;
318  virtual bool canInsertFromMimeData(const QMimeData *source) const;
319  virtual void insertFromMimeData(const QMimeData *source);
320 
321  virtual void inputMethodEvent(QInputMethodEvent *);
322  QVariant inputMethodQuery(Qt::InputMethodQuery property) const;
323 
324  QTextEdit(QTextEditPrivate &dd, QWidget *parent);
325 
326  virtual void scrollContentsBy(int dx, int dy);
327 
328 #ifdef QT3_SUPPORT
329 Q_SIGNALS:
330  QT_MOC_COMPAT void currentFontChanged(const QFont &f);
331  QT_MOC_COMPAT void currentColorChanged(const QColor &c);
332 
333 public:
334  QT3_SUPPORT_CONSTRUCTOR QTextEdit(QWidget *parent, const char *name);
335  inline QT3_SUPPORT bool find(const QString &exp, bool cs, bool wo)
336  {
337  QTextDocument::FindFlags flags = 0;
338  if (cs)
340  if (wo)
342  return find(exp, flags);
343  }
344 
345  inline QT3_SUPPORT void sync() {}
346 
347  QT3_SUPPORT void moveCursor(CursorAction action, QTextCursor::MoveMode mode = QTextCursor::MoveAnchor);
348  QT3_SUPPORT void moveCursor(CursorAction action, bool select);
349 
350  enum KeyboardAction {
351  ActionBackspace,
352  ActionDelete,
353  ActionReturn,
354  ActionKill,
355  ActionWordBackspace,
356  ActionWordDelete
357  };
358 
359  QT3_SUPPORT void doKeyboardAction(KeyboardAction action);
360 
361  QT3_SUPPORT QString text() const;
362  QT3_SUPPORT void setTextFormat(Qt::TextFormat);
363  QT3_SUPPORT Qt::TextFormat textFormat() const;
364 
365  inline QT3_SUPPORT void setBold(bool b) { setFontWeight(b ? QFont::Bold : QFont::Normal); }
366  inline QT3_SUPPORT void setUnderline(bool b) { setFontUnderline(b); }
367  inline QT3_SUPPORT void setItalic(bool i) { setFontItalic(i); }
368  inline QT3_SUPPORT void setFamily(const QString &family) { setFontFamily(family); }
369  inline QT3_SUPPORT void setPointSize(int size) { setFontPointSize(size); }
370 
371  inline QT3_SUPPORT bool italic() const { return fontItalic(); }
372  inline QT3_SUPPORT bool bold() const { return fontWeight() >= QFont::Bold; }
373  inline QT3_SUPPORT bool underline() const { return fontUnderline(); }
374  inline QT3_SUPPORT QString family() const { return fontFamily(); }
375  inline QT3_SUPPORT int pointSize() const { return (int)(fontPointSize()+0.5); }
376 
377  inline QT3_SUPPORT bool hasSelectedText() const
378  { return textCursor().hasSelection(); }
379  inline QT3_SUPPORT QString selectedText() const
380  { return textCursor().selectedText(); }
381 
382  inline QT3_SUPPORT bool isUndoAvailable() const
383  { return document()->isUndoAvailable(); }
384  inline QT3_SUPPORT bool isRedoAvailable() const
385  { return document()->isRedoAvailable(); }
386 
387  inline QT3_SUPPORT void insert(const QString &text)
388  { insertPlainText(text); }
389 
390  inline QT3_SUPPORT bool isModified() const
391  { return document()->isModified(); }
392 
393  inline QT3_SUPPORT QColor color() const
394  { return textColor(); }
395 
396 public Q_SLOTS:
397  inline QT_MOC_COMPAT void setModified(bool m = true)
398  { document()->setModified(m); }
399 public:
400  inline QT3_SUPPORT void undo() const
401  { document()->undo(); }
402  inline QT3_SUPPORT void redo() const
403  { document()->redo(); }
404 
405 public Q_SLOTS:
406  inline QT_MOC_COMPAT void setColor(const QColor &c)
407  { setTextColor(c); }
408 
409 #endif
410 
411 private:
412  Q_DISABLE_COPY(QTextEdit)
413  Q_PRIVATE_SLOT(d_func(), void _q_repaintContents(const QRectF &r))
414  Q_PRIVATE_SLOT(d_func(), void _q_currentCharFormatChanged(const QTextCharFormat &))
415  Q_PRIVATE_SLOT(d_func(), void _q_adjustScrollbars())
416  Q_PRIVATE_SLOT(d_func(), void _q_ensureVisible(const QRectF &))
417  friend class QTextEditControl;
418  friend class QTextDocument;
419  friend class QTextControl;
420 };
421 
422 Q_DECLARE_OPERATORS_FOR_FLAGS(QTextEdit::AutoFormatting)
423 
425 
427 
428 #endif // QT_NO_TEXTEDIT
429 
430 #endif // QTEXTEDIT_H
GLuint GLuint GLsizei GLenum type
Definition: GLee.h:872
GLdouble GLdouble GLdouble r
Definition: GLee.h:1189
GLsizei GLsizei GLchar * source
Definition: GLee.h:1721
GLint mode
Definition: GLee.h:4479
int int int int * dy
Definition: GLee.h:10535
#define QT_END_NAMESPACE
Definition: qglobal.h:128
#define Q_PROPERTY(text)
Definition: qobjectdefs.h:80
#define QT_BEGIN_HEADER
Definition: qglobal.h:141
QString documentTitle() const
Definition: qtextedit.h:170
GLenum GLsizei width
Definition: GLee.h:873
Definition: qnamespace.h:54
#define Q_PRIVATE_SLOT(d, signature)
Definition: qobjectdefs.h:73
Definition: qcolor.h:67
QString toPlainText() const
Definition: qtextedit.h:189
#define Q_SLOTS
Definition: qobjectdefs.h:71
#define Q_SIGNALS
Definition: qobjectdefs.h:72
#define Q_ENUMS(x)
Definition: qobjectdefs.h:84
Definition: qpoint.h:53
bool isUndoRedoEnabled() const
Definition: qtextedit.h:173
#define QT_BEGIN_NAMESPACE
Definition: qglobal.h:127
GLenum GLsizei GLenum format
Definition: GLee.h:873
Definition: qfont.h:64
AutoFormattingFlag
Definition: qtextedit.h:101
Definition: qmenu.h:72
GLsizei range
Definition: GLee.h:4886
TextFormat
Definition: qnamespace.h:1310
InputMethodQuery
Definition: qnamespace.h:1541
#define Q_OBJECT
Definition: qobjectdefs.h:157
GLubyte GLubyte b
Definition: GLee.h:5404
Definition: qurl.h:61
Definition: qrect.h:58
Definition: qrect.h:511
const GLubyte * c
Definition: GLee.h:5419
GLuint const GLchar * name
Definition: GLee.h:1704
void setUndoRedoEnabled(bool enable)
Definition: qtextedit.h:175
GLubyte GLubyte GLubyte a
Definition: GLee.h:5404
int int int * dx
Definition: GLee.h:10535
#define Q_FLAGS(x)
Definition: qobjectdefs.h:85
GLubyte GLubyte GLubyte GLubyte w
Definition: GLee.h:1775
GLdouble s
Definition: GLee.h:1173
QTextCharFormat format
Definition: qtextedit.h:225
#define QT_END_HEADER
Definition: qglobal.h:142
GLclampf f
Definition: GLee.h:9303
GLsizeiptr size
Definition: GLee.h:1561
QString toHtml() const
Definition: qtextedit.h:192
void setDocumentTitle(const QString &title)
Definition: qtextedit.h:168
GLuint color
Definition: GLee.h:8456