Export QTextImageHandler and add accessor for image
[profile/ivi/qtbase.git] / src / gui / text / qtextcontrol_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 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 <QtCore/qrect.h>
61 #include <QtGui/qabstracttextdocumentlayout.h>
62 #include <QtGui/qtextdocumentfragment.h>
63 #include <QtGui/qclipboard.h>
64
65 QT_BEGIN_HEADER
66
67 QT_BEGIN_NAMESPACE
68
69 QT_MODULE(Gui)
70
71 class QStyleSheet;
72 class QTextDocument;
73 class QTextControlPrivate;
74 class QMimeData;
75 class QAbstractScrollArea;
76 class QEvent;
77 class QTimerEvent;
78 class QPagedPaintDevice;
79
80 class Q_GUI_EXPORT QTextControl : public QObject
81 {
82     Q_OBJECT
83     Q_DECLARE_PRIVATE(QTextControl)
84 #ifndef QT_NO_TEXTHTMLPARSER
85     Q_PROPERTY(QString html READ toHtml WRITE setHtml NOTIFY textChanged USER true)
86 #endif
87     Q_PROPERTY(bool overwriteMode READ overwriteMode WRITE setOverwriteMode)
88     Q_PROPERTY(bool acceptRichText READ acceptRichText WRITE setAcceptRichText)
89     Q_PROPERTY(int cursorWidth READ cursorWidth WRITE setCursorWidth)
90     Q_PROPERTY(Qt::TextInteractionFlags textInteractionFlags READ textInteractionFlags WRITE setTextInteractionFlags)
91     Q_PROPERTY(bool openExternalLinks READ openExternalLinks WRITE setOpenExternalLinks)
92     Q_PROPERTY(bool ignoreUnusedNavigationEvents READ ignoreUnusedNavigationEvents WRITE setIgnoreUnusedNavigationEvents)
93 public:
94     explicit QTextControl(QObject *parent = 0);
95     explicit QTextControl(const QString &text, QObject *parent = 0);
96     explicit QTextControl(QTextDocument *doc, QObject *parent = 0);
97     virtual ~QTextControl();
98
99     void setView(QObject *view);
100     QObject *view() const;
101
102     void setDocument(QTextDocument *document);
103     QTextDocument *document() const;
104
105     void setTextCursor(const QTextCursor &cursor);
106     QTextCursor textCursor() const;
107
108     void setTextInteractionFlags(Qt::TextInteractionFlags flags);
109     Qt::TextInteractionFlags textInteractionFlags() const;
110
111     void mergeCurrentCharFormat(const QTextCharFormat &modifier);
112
113     void setCurrentCharFormat(const QTextCharFormat &format);
114     QTextCharFormat currentCharFormat() const;
115
116     bool find(const QString &exp, QTextDocument::FindFlags options = 0);
117
118     inline QString toPlainText() const
119     { return document()->toPlainText(); }
120 #ifndef QT_NO_TEXTHTMLPARSER
121     inline QString toHtml() const
122     { return document()->toHtml(); }
123 #endif
124
125     virtual void ensureCursorVisible();
126
127     virtual QVariant loadResource(int type, const QUrl &name);
128
129     QTextCursor cursorForPosition(const QPointF &pos) const;
130     QRectF cursorRect(const QTextCursor &cursor) const;
131     QRectF cursorRect() const;
132     QRectF selectionRect(const QTextCursor &cursor) const;
133     QRectF selectionRect() const;
134
135     QString anchorAt(const QPointF &pos) const;
136     QPointF anchorPosition(const QString &name) const;
137
138     QString anchorAtCursor() const;
139
140     bool overwriteMode() const;
141     void setOverwriteMode(bool overwrite);
142
143     int cursorWidth() const;
144     void setCursorWidth(int width);
145
146     bool acceptRichText() const;
147     void setAcceptRichText(bool accept);
148
149     void setExtraSelections(const QVector<QAbstractTextDocumentLayout::Selection> &selections);
150     QVector<QAbstractTextDocumentLayout::Selection> extraSelections() const;
151
152     void setTextWidth(qreal width);
153     qreal textWidth() const;
154     QSizeF size() const;
155
156     void setOpenExternalLinks(bool open);
157     bool openExternalLinks() const;
158
159     void setIgnoreUnusedNavigationEvents(bool ignore);
160     bool ignoreUnusedNavigationEvents() const;
161
162     void moveCursor(QTextCursor::MoveOperation op, QTextCursor::MoveMode mode = QTextCursor::MoveAnchor);
163
164     bool canPaste() const;
165
166     void setCursorIsFocusIndicator(bool b);
167     bool cursorIsFocusIndicator() const;
168
169     void setDragEnabled(bool enabled);
170     bool isDragEnabled() const;
171
172     bool isWordSelectionEnabled() const;
173     void setWordSelectionEnabled(bool enabled);
174
175     void print(QPagedPaintDevice *printer) const;
176
177     virtual int hitTest(const QPointF &point, Qt::HitTestAccuracy accuracy) const;
178     virtual QRectF blockBoundingRect(const QTextBlock &block) const;
179     QAbstractTextDocumentLayout::PaintContext getPaintContext() const;
180
181 public Q_SLOTS:
182     void setPlainText(const QString &text);
183     void setHtml(const QString &text);
184
185 #ifndef QT_NO_CLIPBOARD
186     void cut();
187     void copy();
188     void paste(QClipboard::Mode mode = QClipboard::Clipboard);
189 #endif
190
191     void undo();
192     void redo();
193
194     void clear();
195     void selectAll();
196
197     void insertPlainText(const QString &text);
198 #ifndef QT_NO_TEXTHTMLPARSER
199     void insertHtml(const QString &text);
200 #endif
201
202     void append(const QString &text);
203     void appendHtml(const QString &html);
204     void appendPlainText(const QString &text);
205
206     void adjustSize();
207
208 Q_SIGNALS:
209     void textChanged();
210     void undoAvailable(bool b);
211     void redoAvailable(bool b);
212     void currentCharFormatChanged(const QTextCharFormat &format);
213     void copyAvailable(bool b);
214     void selectionChanged();
215     void cursorPositionChanged();
216
217     // control signals
218     void updateCursorRequest(const QRectF &rect = QRectF());
219     void updateRequest(const QRectF &rect = QRectF());
220     void documentSizeChanged(const QSizeF &);
221     void blockCountChanged(int newBlockCount);
222     void visibilityRequest(const QRectF &rect);
223     void microFocusChanged();
224     void linkActivated(const QString &link);
225     void linkHovered(const QString &);
226     void modificationChanged(bool m);
227
228 public:
229     // control properties
230     QPalette palette() const;
231     void setPalette(const QPalette &pal);
232
233     virtual void processEvent(QEvent *e, const QMatrix &matrix);
234     void processEvent(QEvent *e, const QPointF &coordinateOffset = QPointF());
235
236     // control methods
237     void drawContents(QPainter *painter, const QRectF &rect = QRectF());
238
239     void setFocus(bool focus, Qt::FocusReason = Qt::OtherFocusReason);
240
241     virtual QVariant inputMethodQuery(Qt::InputMethodQuery property) const;
242
243     virtual QMimeData *createMimeDataFromSelection() const;
244     virtual bool canInsertFromMimeData(const QMimeData *source) const;
245     virtual void insertFromMimeData(const QMimeData *source);
246
247     bool setFocusToAnchor(const QTextCursor &newCursor);
248     bool setFocusToNextOrPreviousAnchor(bool next);
249     bool findNextPrevAnchor(const QTextCursor& from, bool next, QTextCursor& newAnchor);
250
251     bool cursorOn() const;
252
253 protected:
254     virtual void timerEvent(QTimerEvent *e);
255
256     virtual bool event(QEvent *e);
257
258 private:
259     Q_DISABLE_COPY(QTextControl)
260     Q_PRIVATE_SLOT(d_func(), void _q_updateCurrentCharFormatAndSelection())
261     Q_PRIVATE_SLOT(d_func(), void _q_emitCursorPosChanged(const QTextCursor &))
262     Q_PRIVATE_SLOT(d_func(), void _q_deleteSelected())
263     Q_PRIVATE_SLOT(d_func(), void _q_copyLink())
264     Q_PRIVATE_SLOT(d_func(), void _q_updateBlock(const QTextBlock &))
265     Q_PRIVATE_SLOT(d_func(), void _q_documentLayoutChanged())
266 };
267
268
269 // also used by QLabel
270 class QTextEditMimeData : public QMimeData
271 {
272 public:
273     inline QTextEditMimeData(const QTextDocumentFragment &aFragment) : fragment(aFragment) {}
274
275     virtual QStringList formats() const;
276 protected:
277     virtual QVariant retrieveData(const QString &mimeType, QVariant::Type type) const;
278 private:
279     void setup() const;
280
281     mutable QTextDocumentFragment fragment;
282 };
283
284 QT_END_NAMESPACE
285
286 QT_END_HEADER
287
288 #endif // QTextControl_H