aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/quick/items/items.pri2
-rw-r--r--src/quick/items/qquickitemsmodule.cpp4
-rw-r--r--src/quick/items/qquicktextdocument.cpp71
-rw-r--r--src/quick/items/qquicktextdocument.h86
-rw-r--r--src/quick/items/qquicktextedit.cpp20
-rw-r--r--src/quick/items/qquicktextedit_p.h5
-rw-r--r--src/quick/items/qquicktextedit_p_p.h2
-rw-r--r--tests/auto/quick/qquicktextdocument/data/text.qml6
-rw-r--r--tests/auto/quick/qquicktextdocument/qquicktextdocument.pro15
-rw-r--r--tests/auto/quick/qquicktextdocument/tst_qquicktextdocument.cpp87
-rw-r--r--tests/auto/quick/quick.pro1
11 files changed, 299 insertions, 0 deletions
diff --git a/src/quick/items/items.pri b/src/quick/items/items.pri
index 2183a2bc63..fe406ecaac 100644
--- a/src/quick/items/items.pri
+++ b/src/quick/items/items.pri
@@ -21,6 +21,7 @@ HEADERS += \
$$PWD/qquicktextinput_p_p.h \
$$PWD/qquicktextcontrol_p.h \
$$PWD/qquicktextcontrol_p_p.h \
+ $$PWD/qquicktextdocument.h \
$$PWD/qquicktextedit_p.h \
$$PWD/qquicktextedit_p_p.h \
$$PWD/qquicktextutil_p.h \
@@ -85,6 +86,7 @@ SOURCES += \
$$PWD/qquicktextnode.cpp \
$$PWD/qquicktextinput.cpp \
$$PWD/qquicktextcontrol.cpp \
+ $$PWD/qquicktextdocument.cpp \
$$PWD/qquicktextedit.cpp \
$$PWD/qquicktextutil.cpp \
$$PWD/qquickimagebase.cpp \
diff --git a/src/quick/items/qquickitemsmodule.cpp b/src/quick/items/qquickitemsmodule.cpp
index 71c23111d5..5321f5e588 100644
--- a/src/quick/items/qquickitemsmodule.cpp
+++ b/src/quick/items/qquickitemsmodule.cpp
@@ -49,6 +49,7 @@
#include "qquicktext_p.h"
#include "qquicktextinput_p.h"
#include "qquicktextedit_p.h"
+#include "qquicktextdocument.h"
#include "qquickimage_p.h"
#include "qquickborderimage_p.h"
#include "qquickscalegrid_p_p.h"
@@ -178,6 +179,9 @@ static void qt_quickitems_defineModule(const char *uri, int major, int minor)
qRegisterMetaType<QQuickAnchorLine>("QQuickAnchorLine");
QQmlMetaType::setQQuickAnchorLineCompareFunction(compareQQuickAnchorLines);
+ qmlRegisterType<QQuickTextDocument>();
+
+
qmlRegisterUncreatableType<QQuickKeyNavigationAttached>(uri,major,minor,"KeyNavigation",QQuickKeyNavigationAttached::tr("KeyNavigation is only available via attached properties"));
qmlRegisterUncreatableType<QQuickKeysAttached>(uri,major,minor,"Keys",QQuickKeysAttached::tr("Keys is only available via attached properties"));
qmlRegisterUncreatableType<QQuickLayoutMirroringAttached>(uri,major,minor,"LayoutMirroring", QQuickLayoutMirroringAttached::tr("LayoutMirroring is only available via attached properties"));
diff --git a/src/quick/items/qquicktextdocument.cpp b/src/quick/items/qquicktextdocument.cpp
new file mode 100644
index 0000000000..e29e48c5d0
--- /dev/null
+++ b/src/quick/items/qquicktextdocument.cpp
@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qquicktextdocument.h"
+
+#include "qquicktextedit_p.h"
+#include "qquicktextedit_p_p.h"
+#include "qquicktext_p_p.h"
+
+QT_BEGIN_NAMESPACE
+
+class QQuickTextDocumentPrivate : public QObjectPrivate
+{
+public:
+ QPointer<QTextDocument> document;
+};
+
+QQuickTextDocument::QQuickTextDocument(QQuickItem *parent)
+ : QObject(*(new QQuickTextDocumentPrivate), parent)
+{
+ Q_D(QQuickTextDocument);
+ Q_ASSERT(parent);
+ Q_ASSERT(qobject_cast<QQuickTextEdit*>(parent));
+ d->document = QPointer<QTextDocument>(qobject_cast<QQuickTextEdit*>(parent)->d_func()->document);
+}
+
+QTextDocument* QQuickTextDocument::textDocument() const
+{
+ Q_D(const QQuickTextDocument);
+ return d->document.data();
+}
+
+QT_END_NAMESPACE
diff --git a/src/quick/items/qquicktextdocument.h b/src/quick/items/qquicktextdocument.h
new file mode 100644
index 0000000000..25d3bbeaf0
--- /dev/null
+++ b/src/quick/items/qquicktextdocument.h
@@ -0,0 +1,86 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QQUICKTEXTDOCUMENT_H
+#define QQUICKTEXTDOCUMENT_H
+
+#include <QtGui/QTextDocument>
+#include <QtQuick/QQuickItem>
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \class QQuickTextDocument
+ \since 5.1
+ \brief The QQuickTextDocument class provides access to the QTextDocument of QQuickTextEdit
+ \inmodule QtQuick
+
+ This class provides access to the QTextDocument of QQuickTextEdit elements.
+ This is provided to allow usage of the \l{Rich Text Processing} functionalities of Qt.
+ You are not allowed to modify the document, but it can be used to output content, for example with \l{QTextDocumentWriter}),
+ or provide additional formatting, for example with \l{QSyntaxHighlighter}.
+
+ The class has to be used from C++ directly, using the property of the \l TextEdit.
+
+ Warning: The QTextDocument provided is used internally by QtQuick elements to provide text manipulation primitives.
+ You are not allowed to perform any modification of the internal state of the QTextDocument. If you do, the element
+ in question may stop functioning or crash.
+*/
+
+class QQuickTextDocumentPrivate;
+class Q_QUICK_EXPORT QQuickTextDocument : public QObject
+{
+ Q_OBJECT
+
+public:
+ QQuickTextDocument(QQuickItem *parent);
+ QTextDocument *textDocument() const;
+
+private:
+ Q_DISABLE_COPY(QQuickTextDocument)
+ Q_DECLARE_PRIVATE(QQuickTextDocument)
+};
+
+QT_END_NAMESPACE
+
+QML_DECLARE_TYPE(QQuickTextDocument)
+
+#endif
diff --git a/src/quick/items/qquicktextedit.cpp b/src/quick/items/qquicktextedit.cpp
index d543b6bd41..e051b5202c 100644
--- a/src/quick/items/qquicktextedit.cpp
+++ b/src/quick/items/qquicktextedit.cpp
@@ -61,6 +61,7 @@
#include <private/qtextengine_p.h>
#include <private/qsgadaptationlayer_p.h>
+#include "qquicktextdocument.h"
QT_BEGIN_NAMESPACE
@@ -2179,4 +2180,23 @@ void QQuickTextEdit::remove(int start, int end)
d->control->updateCursorRectangle(false);
}
+/*!
+ \qmlproperty TextDocument QtQuick2::TextEdit::textDocument
+ \since 5.1
+
+ Returns the QQuickTextDocument of this TextEdit.
+ It can be used to implement syntax highlighting using
+ \l QSyntaxHighlighter.
+
+ \sa QQuickTextDocument
+*/
+
+QQuickTextDocument *QQuickTextEdit::textDocument()
+{
+ Q_D(QQuickTextEdit);
+ if (!d->quickDocument)
+ d->quickDocument = new QQuickTextDocument(this);
+ return d->quickDocument;
+}
+
QT_END_NAMESPACE
diff --git a/src/quick/items/qquicktextedit_p.h b/src/quick/items/qquicktextedit_p.h
index 0538270cd4..744a7e290d 100644
--- a/src/quick/items/qquicktextedit_p.h
+++ b/src/quick/items/qquicktextedit_p.h
@@ -48,6 +48,7 @@
QT_BEGIN_NAMESPACE
+class QQuickTextDocument;
class QQuickTextEditPrivate;
class Q_QUICK_PRIVATE_EXPORT QQuickTextEdit : public QQuickImplicitSizeItem
{
@@ -99,6 +100,7 @@ class Q_QUICK_PRIVATE_EXPORT QQuickTextEdit : public QQuickImplicitSizeItem
#endif
Q_PROPERTY(QUrl baseUrl READ baseUrl WRITE setBaseUrl RESET resetBaseUrl NOTIFY baseUrlChanged)
Q_PROPERTY(RenderType renderType READ renderType WRITE setRenderType NOTIFY renderTypeChanged)
+ Q_PROPERTY(QQuickTextDocument *textDocument READ textDocument FINAL)
public:
QQuickTextEdit(QQuickItem *parent=0);
@@ -247,6 +249,8 @@ public:
Q_INVOKABLE QString getText(int start, int end) const;
Q_INVOKABLE QString getFormattedText(int start, int end) const;
+ QQuickTextDocument *textDocument();
+
Q_SIGNALS:
void textChanged();
void contentSizeChanged();
@@ -339,6 +343,7 @@ protected:
QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updatePaintNodeData);
friend class QQuickTextUtil;
+ friend class QQuickTextDocument;
private:
Q_DISABLE_COPY(QQuickTextEdit)
diff --git a/src/quick/items/qquicktextedit_p_p.h b/src/quick/items/qquicktextedit_p_p.h
index 597874d864..e4819e4d2d 100644
--- a/src/quick/items/qquicktextedit_p_p.h
+++ b/src/quick/items/qquicktextedit_p_p.h
@@ -73,6 +73,7 @@ public:
QQuickTextEditPrivate()
: color(QRgb(0xFF000000)), selectionColor(QRgb(0xFF000080)), selectedTextColor(QRgb(0xFFFFFFFF))
, textMargin(0.0), xoff(0), yoff(0), font(sourceFont), cursorComponent(0), cursorItem(0), document(0), control(0)
+ , quickDocument(0)
, lastSelectionStart(0), lastSelectionEnd(0), lineCount(0)
, hAlign(QQuickTextEdit::AlignLeft), vAlign(QQuickTextEdit::AlignTop)
, format(QQuickTextEdit::PlainText), wrapMode(QQuickTextEdit::NoWrap)
@@ -124,6 +125,7 @@ public:
QQuickItem* cursorItem;
QQuickTextDocumentWithImageResources *document;
QQuickTextControl *control;
+ QQuickTextDocument *quickDocument;
int lastSelectionStart;
int lastSelectionEnd;
diff --git a/tests/auto/quick/qquicktextdocument/data/text.qml b/tests/auto/quick/qquicktextdocument/data/text.qml
new file mode 100644
index 0000000000..43a8c6bb82
--- /dev/null
+++ b/tests/auto/quick/qquicktextdocument/data/text.qml
@@ -0,0 +1,6 @@
+import QtQuick 2.1
+
+TextEdit {
+ text: ""
+}
+
diff --git a/tests/auto/quick/qquicktextdocument/qquicktextdocument.pro b/tests/auto/quick/qquicktextdocument/qquicktextdocument.pro
new file mode 100644
index 0000000000..e6bfdbd099
--- /dev/null
+++ b/tests/auto/quick/qquicktextdocument/qquicktextdocument.pro
@@ -0,0 +1,15 @@
+CONFIG += testcase
+TARGET = tst_qquicktextdocument
+macx:CONFIG -= app_bundle
+
+SOURCES += tst_qquicktextdocument.cpp
+
+include (../../shared/util.pri)
+
+TESTDATA = data/*
+
+CONFIG += parallel_test
+
+QT += core-private gui-private qml-private quick-private testlib
+DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0
+
diff --git a/tests/auto/quick/qquicktextdocument/tst_qquicktextdocument.cpp b/tests/auto/quick/qquicktextdocument/tst_qquicktextdocument.cpp
new file mode 100644
index 0000000000..717496cf0e
--- /dev/null
+++ b/tests/auto/quick/qquicktextdocument/tst_qquicktextdocument.cpp
@@ -0,0 +1,87 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <qtest.h>
+#include <QtTest/QtTest>
+#include <QtQuick/QQuickTextDocument>
+#include <QtQuick/QQuickItem>
+#include <QtQuick/private/qquicktextedit_p.h>
+#include <QtGui/QTextDocument>
+#include <QtGui/QTextDocumentWriter>
+#include <QtQml/QQmlEngine>
+#include <QtQml/QQmlComponent>
+#include "../../shared/util.h"
+
+class tst_qquicktextdocument : public QQmlDataTest
+{
+ Q_OBJECT
+private slots:
+ void textDocumentWriter();
+};
+
+QString text = QStringLiteral("foo bar");
+
+void tst_qquicktextdocument::textDocumentWriter()
+{
+ QQmlEngine e;
+ QQmlComponent c(&e, testFileUrl("text.qml"));
+ QObject* o = c.create();
+ QVERIFY(o);
+ QQuickTextEdit *edit = qobject_cast<QQuickTextEdit*>(o);
+ QVERIFY(edit);
+
+ QQuickTextDocument* quickDocument = qobject_cast<QQuickTextDocument*>(edit->property("textDocument").value<QObject*>());
+ QVERIFY(quickDocument->textDocument() != 0);
+
+ QBuffer output;
+ output.open(QBuffer::ReadWrite);
+ QVERIFY(output.buffer().isEmpty());
+
+ edit->setProperty("text", QVariant(text));
+ QTextDocumentWriter writer(&output, "plaintext");
+ QVERIFY(writer.write(quickDocument->textDocument()));
+ QCOMPARE(output.buffer(), text.toLatin1());
+ delete o;
+}
+
+QTEST_MAIN(tst_qquicktextdocument)
+
+#include "tst_qquicktextdocument.moc"
diff --git a/tests/auto/quick/quick.pro b/tests/auto/quick/quick.pro
index 3ed6ca8c99..8ce17a10d0 100644
--- a/tests/auto/quick/quick.pro
+++ b/tests/auto/quick/quick.pro
@@ -60,6 +60,7 @@ QUICKTESTS = \
qquickshadereffect \
qquickspritesequence \
qquicktext \
+ qquicktextdocument \
qquicktextedit \
qquicktextinput \
qquickvisualdatamodel \