1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtGui module of the Qt Toolkit.
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.
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.
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.
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.
40 ****************************************************************************/
42 #ifndef QTEXTCONTROL_P_H
43 #define QTEXTCONTROL_P_H
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.
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>
68 #include <QtGui/qtextobject.h>
69 #include <QtGui/qtextlayout.h>
81 class QTextControlPrivate;
83 class QAbstractScrollArea;
87 class Q_GUI_EXPORT QTextControl : public QObject
90 Q_DECLARE_PRIVATE(QTextControl)
91 #ifndef QT_NO_TEXTHTMLPARSER
92 Q_PROPERTY(QString html READ toHtml WRITE setHtml NOTIFY textChanged USER true)
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)
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();
106 void setDocument(QTextDocument *document);
107 QTextDocument *document() const;
109 void setTextCursor(const QTextCursor &cursor);
110 QTextCursor textCursor() const;
112 void setTextInteractionFlags(Qt::TextInteractionFlags flags);
113 Qt::TextInteractionFlags textInteractionFlags() const;
115 void mergeCurrentCharFormat(const QTextCharFormat &modifier);
117 void setCurrentCharFormat(const QTextCharFormat &format);
118 QTextCharFormat currentCharFormat() const;
120 bool find(const QString &exp, QTextDocument::FindFlags options = 0);
122 inline QString toPlainText() const
123 { return document()->toPlainText(); }
124 #ifndef QT_NO_TEXTHTMLPARSER
125 inline QString toHtml() const
126 { return document()->toHtml(); }
129 virtual void ensureCursorVisible();
131 virtual QVariant loadResource(int type, const QUrl &name);
132 #ifndef QT_NO_CONTEXTMENU
133 QMenu *createStandardContextMenu(const QPointF &pos, QWidget *parent);
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;
142 QString anchorAt(const QPointF &pos) const;
143 QPointF anchorPosition(const QString &name) const;
145 QString anchorAtCursor() const;
147 bool overwriteMode() const;
148 void setOverwriteMode(bool overwrite);
150 int cursorWidth() const;
151 void setCursorWidth(int width);
153 bool acceptRichText() const;
154 void setAcceptRichText(bool accept);
156 #ifndef QT_NO_TEXTEDIT
157 void setExtraSelections(const QList<QTextEdit::ExtraSelection> &selections);
158 QList<QTextEdit::ExtraSelection> extraSelections() const;
161 void setTextWidth(qreal width);
162 qreal textWidth() const;
165 void setOpenExternalLinks(bool open);
166 bool openExternalLinks() const;
168 void setIgnoreUnusedNavigationEvents(bool ignore);
169 bool ignoreUnusedNavigationEvents() const;
171 void moveCursor(QTextCursor::MoveOperation op, QTextCursor::MoveMode mode = QTextCursor::MoveAnchor);
173 bool canPaste() const;
175 void setCursorIsFocusIndicator(bool b);
176 bool cursorIsFocusIndicator() const;
178 void setDragEnabled(bool enabled);
179 bool isDragEnabled() const;
181 bool isWordSelectionEnabled() const;
182 void setWordSelectionEnabled(bool enabled);
184 #ifndef QT_NO_PRINTER
185 void print(QPrinter *printer) const;
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;
193 void setPlainText(const QString &text);
194 void setHtml(const QString &text);
196 #ifndef QT_NO_CLIPBOARD
199 void paste(QClipboard::Mode mode = QClipboard::Clipboard);
208 void insertPlainText(const QString &text);
209 #ifndef QT_NO_TEXTHTMLPARSER
210 void insertHtml(const QString &text);
213 void append(const QString &text);
214 void appendHtml(const QString &html);
215 void appendPlainText(const QString &text);
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();
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);
239 // control properties
240 QPalette palette() const;
241 void setPalette(const QPalette &pal);
243 virtual void processEvent(QEvent *e, const QMatrix &matrix, QWidget *contextWidget = 0);
244 void processEvent(QEvent *e, const QPointF &coordinateOffset = QPointF(), QWidget *contextWidget = 0);
247 void drawContents(QPainter *painter, const QRectF &rect = QRectF(), QWidget *widget = 0);
249 void setFocus(bool focus, Qt::FocusReason = Qt::OtherFocusReason);
251 virtual QVariant inputMethodQuery(Qt::InputMethodQuery property) const;
253 virtual QMimeData *createMimeDataFromSelection() const;
254 virtual bool canInsertFromMimeData(const QMimeData *source) const;
255 virtual void insertFromMimeData(const QMimeData *source);
257 bool setFocusToAnchor(const QTextCursor &newCursor);
258 bool setFocusToNextOrPreviousAnchor(bool next);
259 bool findNextPrevAnchor(const QTextCursor& from, bool next, QTextCursor& newAnchor);
262 virtual void timerEvent(QTimerEvent *e);
264 virtual bool event(QEvent *e);
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())
277 #ifndef QT_NO_CONTEXTMENU
278 class QUnicodeControlCharacterMenu : public QMenu
282 QUnicodeControlCharacterMenu(QObject *editWidget, QWidget *parent);
285 void menuActionTriggered();
290 #endif // QT_NO_CONTEXTMENU
293 // also used by QLabel
294 class QTextEditMimeData : public QMimeData
297 inline QTextEditMimeData(const QTextDocumentFragment &aFragment) : fragment(aFragment) {}
299 virtual QStringList formats() const;
301 virtual QVariant retrieveData(const QString &mimeType, QVariant::Type type) const;
305 mutable QTextDocumentFragment fragment;
312 #endif // QTEXTCONTROL_H