Qt 4.8
qtextcontrol_p.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 QTEXTCONTROL_P_H
43 #define QTEXTCONTROL_P_H
44 
45 //
46 // W A R N I N G
47 // -------------
48 //
49 // This file is not part of the Qt API. It exists purely as an
50 // implementation detail. This header file may change from version to
51 // version without notice, or even be removed.
52 //
53 // We mean it.
54 //
55 
56 #include <QtGui/qtextdocument.h>
57 #include <QtGui/qtextoption.h>
58 #include <QtGui/qtextcursor.h>
59 #include <QtGui/qtextformat.h>
60 #include <QtGui/qtextedit.h>
61 #include <QtGui/qmenu.h>
62 #include <QtCore/qrect.h>
63 #include <QtGui/qabstracttextdocumentlayout.h>
64 #include <QtGui/qtextdocumentfragment.h>
65 #include <QtGui/qclipboard.h>
66 
67 #ifdef QT3_SUPPORT
68 #include <QtGui/qtextobject.h>
69 #include <QtGui/qtextlayout.h>
70 #endif
71 
73 
75 
76 QT_MODULE(Gui)
77 
78 class QStyleSheet;
79 class QTextDocument;
80 class QMenu;
82 class QMimeData;
84 class QEvent;
85 class QTimerEvent;
86 
88 {
89  Q_OBJECT
91 #ifndef QT_NO_TEXTHTMLPARSER
93 #endif
97  Qt::TextInteractionFlags textInteractionFlags;
100 public:
101  explicit QTextControl(QObject *parent = 0);
102  explicit QTextControl(const QString &text, QObject *parent = 0);
103  explicit QTextControl(QTextDocument *doc, QObject *parent = 0);
104  virtual ~QTextControl();
105 
106  void setDocument(QTextDocument *document);
107  QTextDocument *document() const;
108 
109  void setTextCursor(const QTextCursor &cursor);
110  QTextCursor textCursor() const;
111 
112  void setTextInteractionFlags(Qt::TextInteractionFlags flags);
113  Qt::TextInteractionFlags textInteractionFlags() const;
114 
115  void mergeCurrentCharFormat(const QTextCharFormat &modifier);
116 
117  void setCurrentCharFormat(const QTextCharFormat &format);
118  QTextCharFormat currentCharFormat() const;
119 
120  bool find(const QString &exp, QTextDocument::FindFlags options = 0);
121 
122  inline QString toPlainText() const
123  { return document()->toPlainText(); }
124 #ifndef QT_NO_TEXTHTMLPARSER
125  inline QString toHtml() const
126  { return document()->toHtml(); }
127 #endif
128 
129  virtual void ensureCursorVisible();
130 
131  virtual QVariant loadResource(int type, const QUrl &name);
132 #ifndef QT_NO_CONTEXTMENU
133  QMenu *createStandardContextMenu(const QPointF &pos, QWidget *parent);
134 #endif
135 
136  QTextCursor cursorForPosition(const QPointF &pos) const;
137  QRectF cursorRect(const QTextCursor &cursor) const;
138  QRectF cursorRect() const;
139  QRectF selectionRect(const QTextCursor &cursor) const;
140  QRectF selectionRect() const;
141 
142  QString anchorAt(const QPointF &pos) const;
143  QPointF anchorPosition(const QString &name) const;
144 
145  QString anchorAtCursor() const;
146 
147  bool overwriteMode() const;
148  void setOverwriteMode(bool overwrite);
149 
150  int cursorWidth() const;
151  void setCursorWidth(int width);
152 
153  bool acceptRichText() const;
154  void setAcceptRichText(bool accept);
155 
156 #ifndef QT_NO_TEXTEDIT
157  void setExtraSelections(const QList<QTextEdit::ExtraSelection> &selections);
158  QList<QTextEdit::ExtraSelection> extraSelections() const;
159 #endif
160 
161  void setTextWidth(qreal width);
162  qreal textWidth() const;
163  QSizeF size() const;
164 
165  void setOpenExternalLinks(bool open);
166  bool openExternalLinks() const;
167 
168  void setIgnoreUnusedNavigationEvents(bool ignore);
169  bool ignoreUnusedNavigationEvents() const;
170 
172 
173  bool canPaste() const;
174 
175  void setCursorIsFocusIndicator(bool b);
176  bool cursorIsFocusIndicator() const;
177 
178  void setDragEnabled(bool enabled);
179  bool isDragEnabled() const;
180 
181  bool isWordSelectionEnabled() const;
182  void setWordSelectionEnabled(bool enabled);
183 
184 #ifndef QT_NO_PRINTER
185  void print(QPrinter *printer) const;
186 #endif
187 
188  virtual int hitTest(const QPointF &point, Qt::HitTestAccuracy accuracy) const;
189  virtual QRectF blockBoundingRect(const QTextBlock &block) const;
191 
192 public Q_SLOTS:
193  void setPlainText(const QString &text);
194  void setHtml(const QString &text);
195 
196 #ifndef QT_NO_CLIPBOARD
197  void cut();
198  void copy();
199  void paste(QClipboard::Mode mode = QClipboard::Clipboard);
200 #endif
201 
202  void undo();
203  void redo();
204 
205  void clear();
206  void selectAll();
207 
208  void insertPlainText(const QString &text);
209 #ifndef QT_NO_TEXTHTMLPARSER
210  void insertHtml(const QString &text);
211 #endif
212 
213  void append(const QString &text);
214  void appendHtml(const QString &html);
215  void appendPlainText(const QString &text);
216 
217  void adjustSize();
218 
219 Q_SIGNALS:
220  void textChanged();
221  void undoAvailable(bool b);
222  void redoAvailable(bool b);
223  void currentCharFormatChanged(const QTextCharFormat &format);
224  void copyAvailable(bool b);
225  void selectionChanged();
226  void cursorPositionChanged();
227 
228  // control signals
229  void updateRequest(const QRectF &rect = QRectF());
230  void documentSizeChanged(const QSizeF &);
231  void blockCountChanged(int newBlockCount);
232  void visibilityRequest(const QRectF &rect);
233  void microFocusChanged();
234  void linkActivated(const QString &link);
235  void linkHovered(const QString &);
236  void modificationChanged(bool m);
237 
238 public:
239  // control properties
240  QPalette palette() const;
241  void setPalette(const QPalette &pal);
242 
243  virtual void processEvent(QEvent *e, const QMatrix &matrix, QWidget *contextWidget = 0);
244  void processEvent(QEvent *e, const QPointF &coordinateOffset = QPointF(), QWidget *contextWidget = 0);
245 
246  // control methods
247  void drawContents(QPainter *painter, const QRectF &rect = QRectF(), QWidget *widget = 0);
248 
249  void setFocus(bool focus, Qt::FocusReason = Qt::OtherFocusReason);
250 
251  virtual QVariant inputMethodQuery(Qt::InputMethodQuery property) const;
252 
253  virtual QMimeData *createMimeDataFromSelection() const;
254  virtual bool canInsertFromMimeData(const QMimeData *source) const;
255  virtual void insertFromMimeData(const QMimeData *source);
256 
257  bool setFocusToAnchor(const QTextCursor &newCursor);
258  bool setFocusToNextOrPreviousAnchor(bool next);
259  bool findNextPrevAnchor(const QTextCursor& from, bool next, QTextCursor& newAnchor);
260 
261 protected:
262  virtual void timerEvent(QTimerEvent *e);
263 
264  virtual bool event(QEvent *e);
265 
266 private:
268  Q_PRIVATE_SLOT(d_func(), void _q_updateCurrentCharFormatAndSelection())
269  Q_PRIVATE_SLOT(d_func(), void _q_emitCursorPosChanged(const QTextCursor &))
270  Q_PRIVATE_SLOT(d_func(), void _q_deleteSelected())
271  Q_PRIVATE_SLOT(d_func(), void _q_copyLink())
272  Q_PRIVATE_SLOT(d_func(), void _q_updateBlock(const QTextBlock &))
273  Q_PRIVATE_SLOT(d_func(), void _q_documentLayoutChanged())
274 };
275 
276 
277 #ifndef QT_NO_CONTEXTMENU
279 {
280  Q_OBJECT
281 public:
282  QUnicodeControlCharacterMenu(QObject *editWidget, QWidget *parent);
283 
284 private Q_SLOTS:
285  void menuActionTriggered();
286 
287 private:
289 };
290 #endif // QT_NO_CONTEXTMENU
291 
292 
293 // also used by QLabel
295 {
296 public:
297  inline QTextEditMimeData(const QTextDocumentFragment &aFragment) : fragment(aFragment) {}
298 
299  virtual QStringList formats() const;
300 protected:
301  virtual QVariant retrieveData(const QString &mimeType, QVariant::Type type) const;
302 private:
303  void setup() const;
304 
306 };
307 
309 
311 
312 #endif // QTEXTCONTROL_H
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
Mode
This enum type is used to control which part of the system clipboard is used by QClipboard::mimeData(...
Definition: qclipboard.h:71
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
QTextDocumentFragment fragment
int type
Definition: qmetatype.cpp:239
The QTextCharFormat class provides formatting information for characters in a QTextDocument.
Definition: qtextformat.h:372
double qreal
Definition: qglobal.h:1193
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QPointer< QWidget > widget
#define QT_MODULE(x)
Definition: qglobal.h:2783
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
The QMatrix class specifies 2D transformations of a coordinate system.
Definition: qmatrix.h:61
#define Q_GUI_EXPORT
Definition: qglobal.h:1450
HitTestAccuracy
Definition: qtextdocument.h:78
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
virtual void timerEvent(QTimerEvent *)
This event handler can be reimplemented in a subclass to receive timer events for the object...
Definition: qobject.cpp:1294
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
Qt::TextInteractionFlags textInteractionFlags
static void clear(QVariant::Private *d)
Definition: qvariant.cpp:197
static bool ignore(const char *test, const char *const *table)
Definition: qaxserver.cpp:660
#define Q_DISABLE_COPY(Class)
Disables the use of copy constructors and assignment operators for the given Class.
Definition: qglobal.h:2523
#define Q_PRIVATE_SLOT(d, signature)
Definition: qobjectdefs.h:73
The QAbstractScrollArea widget provides a scrolling area with on-demand scroll bars.
#define Q_SLOTS
Definition: qobjectdefs.h:71
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
virtual bool event(QEvent *)
This virtual function receives events to an object and should return true if the event e was recogniz...
Definition: qobject.cpp:1200
#define Q_SIGNALS
Definition: qobjectdefs.h:72
The QSizeF class defines the size of a two-dimensional object using floating point precision...
Definition: qsize.h:202
static QCursor * moveCursor
Definition: qdnd_x11.cpp:254
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
MoveMode
If the anchor() is kept where it is and the position() is moved, the text in between will be selected...
Definition: qtextcursor.h:85
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
The QTextCursor class offers an API to access and modify QTextDocuments.
Definition: qtextcursor.h:70
QString toHtml() const
bool ignoreUnusedNavigationEvents
const char * name
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
The QTextBlock class provides a container for text fragments in a QTextDocument.
Definition: qtextobject.h:199
Type
This enum type defines the types of variable that a QVariant can contain.
Definition: qvariant.h:95
The QMimeData class provides a container for data that records information about its MIME type...
Definition: qmimedata.h:57
bool openExternalLinks
#define Q_OBJECT
Definition: qobjectdefs.h:157
InputMethodQuery
Definition: qnamespace.h:1541
QString toPlainText() const
The QMenu class provides a menu widget for use in menu bars, context menus, and other popup menus...
Definition: qmenu.h:72
FocusReason
Definition: qnamespace.h:1521
The QTimerEvent class contains parameters that describe a timer event.
Definition: qcoreevent.h:341
The QAbstractTextDocumentLayout::PaintContext class is a convenience class defining the parameters us...
const char * property
Definition: qwizard.cpp:138
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...
#define Q_DECLARE_PRIVATE(Class)
Definition: qglobal.h:2467
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
#define QT_END_HEADER
Definition: qglobal.h:137
The QTextDocumentFragment class represents a piece of formatted text from a QTextDocument.
#define enabled
int open(const char *, int,...)
#define text
Definition: qobjectdefs.h:80
QTextEditMimeData(const QTextDocumentFragment &aFragment)
static void setup()
Definition: qtextcodec.cpp:718
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
The QPalette class contains color groups for each widget state.
Definition: qpalette.h:61