1
/****************************************************************************
2
**
3
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4
** All rights reserved.
5
** Contact: Nokia Corporation (qt-info@nokia.com)
6
**
7
** This file is part of the QtGui module of the Qt Toolkit.
8
**
9
** $QT_BEGIN_LICENSE:LGPL$
10
** GNU Lesser General Public License Usage
11
** This file may be used under the terms of the GNU Lesser General Public
12
** License version 2.1 as published by the Free Software Foundation and
13
** appearing in the file LICENSE.LGPL included in the packaging of this
14
** file. Please review the following information to ensure the GNU Lesser
15
** General Public License version 2.1 requirements will be met:
16
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17
**
18
** In addition, as a special exception, Nokia gives you certain additional
19
** rights. These rights are described in the Nokia Qt LGPL Exception
20
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21
**
22
** GNU General Public License Usage
23
** Alternatively, this file may be used under the terms of the GNU General
24
** Public License version 3.0 as published by the Free Software Foundation
25
** and appearing in the file LICENSE.GPL included in the packaging of this
26
** file. Please review the following information to ensure the GNU General
27
** Public License version 3.0 requirements will be met:
28
** http://www.gnu.org/copyleft/gpl.html.
29
**
30
** Other Usage
31
** Alternatively, this file may be used in accordance with the terms and
32
** conditions contained in a signed written agreement between you and Nokia.
33
**
34
**
35
**
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
72
QT_BEGIN_HEADER
73
74
QT_BEGIN_NAMESPACE
75
76
QT_MODULE(Gui)
77
78
class QStyleSheet;
79
class QTextDocument;
80
class QMenu;
81
class QTextControlPrivate;
82
class QMimeData;
83
class QAbstractScrollArea;
84
class QEvent;
85
class QTimerEvent;
86
87
class Q_GUI_EXPORT QTextControl : public QObject
88
{
89
    Q_OBJECT
90
    Q_DECLARE_PRIVATE(QTextControl)
91
#ifndef QT_NO_TEXTHTMLPARSER
92
    Q_PROPERTY(QString html READ toHtml WRITE setHtml NOTIFY textChanged USER true)
93
#endif
94
    Q_PROPERTY(bool overwriteMode READ overwriteMode WRITE setOverwriteMode)
95
    Q_PROPERTY(bool acceptRichText READ acceptRichText WRITE setAcceptRichText)
96
    Q_PROPERTY(int cursorWidth READ cursorWidth WRITE setCursorWidth)
97
    Q_PROPERTY(Qt::TextInteractionFlags textInteractionFlags READ textInteractionFlags WRITE setTextInteractionFlags)
98
    Q_PROPERTY(bool openExternalLinks READ openExternalLinks WRITE setOpenExternalLinks)
99
    Q_PROPERTY(bool ignoreUnusedNavigationEvents READ ignoreUnusedNavigationEvents WRITE setIgnoreUnusedNavigationEvents)
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
171
    void moveCursor(QTextCursor::MoveOperation op, QTextCursor::MoveMode mode = QTextCursor::MoveAnchor);
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;
190
    QAbstractTextDocumentLayout::PaintContext getPaintContext(QWidget *widget) 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:
267
    Q_DISABLE_COPY(QTextControl)
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
278
class QUnicodeControlCharacterMenu : public QMenu
279
{
280
    Q_OBJECT
281
public:
282
    QUnicodeControlCharacterMenu(QObject *editWidget, QWidget *parent);
283
284
private Q_SLOTS:
285
    void menuActionTriggered();
286
287
private:
288
    QObject *editWidget;
289
};
290
#endif // QT_NO_CONTEXTMENU
291
292
293
// also used by QLabel
294
class QTextEditMimeData : public QMimeData
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
305
    mutable QTextDocumentFragment fragment;
306
};
307
308
QT_END_NAMESPACE
309
310
QT_END_HEADER
311
312
#endif // QTEXTCONTROL_H