1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtGui module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #ifndef QQUICKTEXTCONTROL_P_H
43 #define QQUICKTEXTCONTROL_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 <QtCore/qrect.h>
61 #include <QtGui/qabstracttextdocumentlayout.h>
62 #include <QtGui/qtextdocumentfragment.h>
63 #include <QtGui/qclipboard.h>
64 #include <QtCore/qmimedata.h>
73 class QQuickTextControlPrivate;
74 class QAbstractScrollArea;
77 class QPagedPaintDevice;
79 class Q_AUTOTEST_EXPORT QQuickTextControl : public QObject
82 Q_DECLARE_PRIVATE(QQuickTextControl)
83 #ifndef QT_NO_TEXTHTMLPARSER
84 Q_PROPERTY(QString html READ toHtml WRITE setHtml NOTIFY textChanged USER true)
86 Q_PROPERTY(bool acceptRichText READ acceptRichText WRITE setAcceptRichText)
87 Q_PROPERTY(int cursorWidth READ cursorWidth WRITE setCursorWidth)
88 Q_PROPERTY(Qt::TextInteractionFlags textInteractionFlags READ textInteractionFlags WRITE setTextInteractionFlags)
90 explicit QQuickTextControl(QTextDocument *doc, QObject *parent = 0);
91 virtual ~QQuickTextControl();
93 void setView(QObject *view);
94 QObject *view() const;
96 QTextDocument *document() const;
98 void setTextCursor(const QTextCursor &cursor);
99 QTextCursor textCursor() const;
101 void setTextInteractionFlags(Qt::TextInteractionFlags flags);
102 Qt::TextInteractionFlags textInteractionFlags() const;
104 QString toPlainText() const;
106 #ifndef QT_NO_TEXTHTMLPARSER
107 QString toHtml() const;
110 QTextCursor cursorForPosition(const QPointF &pos) const;
111 QRectF cursorRect(const QTextCursor &cursor) const;
112 QRectF cursorRect() const;
113 QRectF selectionRect(const QTextCursor &cursor) const;
114 QRectF selectionRect() const;
116 QString anchorAt(const QPointF &pos) const;
118 QString anchorAtCursor() const;
120 int cursorWidth() const;
121 void setCursorWidth(int width);
123 bool acceptRichText() const;
124 void setAcceptRichText(bool accept);
126 void setTextWidth(qreal width);
127 qreal textWidth() const;
130 void setIgnoreUnusedNavigationEvents(bool ignore);
131 bool ignoreUnusedNavigationEvents() const;
133 void moveCursor(QTextCursor::MoveOperation op, QTextCursor::MoveMode mode = QTextCursor::MoveAnchor);
135 bool canPaste() const;
137 void setCursorIsFocusIndicator(bool b);
138 bool cursorIsFocusIndicator() const;
140 bool isWordSelectionEnabled() const;
141 void setWordSelectionEnabled(bool enabled);
143 virtual int hitTest(const QPointF &point, Qt::HitTestAccuracy accuracy) const;
144 virtual QRectF blockBoundingRect(const QTextBlock &block) const;
145 QAbstractTextDocumentLayout::PaintContext getPaintContext() const;
148 void setPlainText(const QString &text);
149 void setHtml(const QString &text);
151 #ifndef QT_NO_CLIPBOARD
154 void paste(QClipboard::Mode mode = QClipboard::Clipboard);
165 void undoAvailable(bool b);
166 void redoAvailable(bool b);
167 void currentCharFormatChanged(const QTextCharFormat &format);
168 void copyAvailable(bool b);
169 void selectionChanged();
170 void cursorPositionChanged();
173 void updateCursorRequest(const QRectF &rect = QRectF());
174 void updateRequest(const QRectF &rect = QRectF());
175 void documentSizeChanged(const QSizeF &);
176 void cursorRectangleChanged();
177 void linkActivated(const QString &link);
178 void linkHovered(const QString &);
181 // control properties
182 QPalette palette() const;
183 void setPalette(const QPalette &pal);
185 virtual void processEvent(QEvent *e, const QMatrix &matrix);
186 void processEvent(QEvent *e, const QPointF &coordinateOffset = QPointF());
189 void drawContents(QPainter *painter, const QRectF &rect = QRectF());
191 void setFocus(bool focus, Qt::FocusReason = Qt::OtherFocusReason);
193 virtual QVariant inputMethodQuery(Qt::InputMethodQuery property) const;
195 virtual QMimeData *createMimeDataFromSelection() const;
196 virtual bool canInsertFromMimeData(const QMimeData *source) const;
197 virtual void insertFromMimeData(const QMimeData *source);
199 bool cursorOn() const;
202 virtual void timerEvent(QTimerEvent *e);
204 virtual bool event(QEvent *e);
207 Q_DISABLE_COPY(QQuickTextControl)
208 Q_PRIVATE_SLOT(d_func(), void _q_updateCurrentCharFormatAndSelection())
209 Q_PRIVATE_SLOT(d_func(), void _q_emitCursorPosChanged(const QTextCursor &))
210 Q_PRIVATE_SLOT(d_func(), void _q_deleteSelected())
211 Q_PRIVATE_SLOT(d_func(), void _q_updateBlock(const QTextBlock &))
212 Q_PRIVATE_SLOT(d_func(), void _q_documentLayoutChanged())
216 // also used by QLabel
217 class QQuickTextEditMimeData : public QMimeData
220 inline QQuickTextEditMimeData(const QTextDocumentFragment &aFragment) : fragment(aFragment) {}
222 virtual QStringList formats() const;
224 virtual QVariant retrieveData(const QString &mimeType, QVariant::Type type) const;
228 mutable QTextDocumentFragment fragment;
235 #endif // QQuickTextControl_H