From da8411eb42c86963202076e054e686e47b3dcd82 Mon Sep 17 00:00:00 2001 From: Kevin Krammer Date: Tue, 6 Nov 2012 08:51:14 +0100 Subject: [PATCH] Export editor controller class --- examples/text-editor/editor.cpp | 20 ++++++++++++++++++++ examples/text-editor/editor.h | 23 +++++++++++++++++++++++ examples/text-editor/main.cpp | 5 +++++ examples/text-editor/main.qml | 3 +++ examples/text-editor/text-editor.pro | 6 +++++- 5 files changed, 56 insertions(+), 1 deletions(-) create mode 100644 examples/text-editor/editor.cpp create mode 100644 examples/text-editor/editor.h diff --git a/examples/text-editor/editor.cpp b/examples/text-editor/editor.cpp new file mode 100644 index 0000000..f14e868 --- /dev/null +++ b/examples/text-editor/editor.cpp @@ -0,0 +1,20 @@ +#include "editor.h" + +#include + +Editor::Editor(QObject *parent) + : QObject(parent) + , m_document(new QTextDocument) +{ +} + +Editor::~Editor() +{ + delete m_document; +} + +QTextDocument *Editor::document() const +{ + return m_document; +} + diff --git a/examples/text-editor/editor.h b/examples/text-editor/editor.h new file mode 100644 index 0000000..9080db2 --- /dev/null +++ b/examples/text-editor/editor.h @@ -0,0 +1,23 @@ +#ifndef EDITOR_H +#define EDITOR_H + +#include + +class QTextDocument; + +class Editor : public QObject +{ + Q_OBJECT + Q_PROPERTY(QTextDocument* document READ document CONSTANT) + + public: + explicit Editor(QObject *parent = 0); + ~Editor(); + + QTextDocument *document() const; + + private: + QTextDocument *m_document; +}; + +#endif // EDITOR_H diff --git a/examples/text-editor/main.cpp b/examples/text-editor/main.cpp index bb72b1e..f2f20c6 100644 --- a/examples/text-editor/main.cpp +++ b/examples/text-editor/main.cpp @@ -18,6 +18,8 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +#include "editor.h" + #include "declarativewidgetsdocument.h" #include @@ -34,6 +36,9 @@ int main(int argc, char **argv) DeclarativeWidgetsDocument document(documentUrl); QObject::connect(document.engine(), SIGNAL(quit()), &app, SLOT(quit())); + Editor editor; + document.setContextProperty("_editor", &editor); + QWidget *widget = document.create(); if (!widget) qFatal("Failed to create widget from document"); diff --git a/examples/text-editor/main.qml b/examples/text-editor/main.qml index c31671c..03316ed 100644 --- a/examples/text-editor/main.qml +++ b/examples/text-editor/main.qml @@ -1,3 +1,4 @@ +import QtQuick 1.0 import QtGui 1.0 MainWindow { @@ -141,4 +142,6 @@ MainWindow { text: "Pos:" } } + + Component.onCompleted: textEdit.document = _editor.document } diff --git a/examples/text-editor/text-editor.pro b/examples/text-editor/text-editor.pro index d960ab0..7a9e6f3 100644 --- a/examples/text-editor/text-editor.pro +++ b/examples/text-editor/text-editor.pro @@ -9,10 +9,14 @@ QT += declarative # Input SOURCES += \ - main.cpp + main.cpp \ + editor.cpp RESOURCES += \ text-editor.qrc OTHER_FILES += \ main.qml + +HEADERS += \ + editor.h -- 1.7.2.5