summaryrefslogtreecommitdiffstats
path: root/examples/declarative/cppextensions/qwidgets
diff options
context:
space:
mode:
Diffstat (limited to 'examples/declarative/cppextensions/qwidgets')
-rw-r--r--examples/declarative/cppextensions/qwidgets/QWidgets/qmldir1
-rw-r--r--examples/declarative/cppextensions/qwidgets/README6
-rw-r--r--examples/declarative/cppextensions/qwidgets/qwidgets.cpp96
-rw-r--r--examples/declarative/cppextensions/qwidgets/qwidgets.pro25
-rw-r--r--examples/declarative/cppextensions/qwidgets/qwidgets.qml110
-rw-r--r--examples/declarative/cppextensions/qwidgets/qwidgets.qmlproject16
6 files changed, 254 insertions, 0 deletions
diff --git a/examples/declarative/cppextensions/qwidgets/QWidgets/qmldir b/examples/declarative/cppextensions/qwidgets/QWidgets/qmldir
new file mode 100644
index 00000000..a7c1d95c
--- /dev/null
+++ b/examples/declarative/cppextensions/qwidgets/QWidgets/qmldir
@@ -0,0 +1 @@
+plugin qmlqwidgetsplugin
diff --git a/examples/declarative/cppextensions/qwidgets/README b/examples/declarative/cppextensions/qwidgets/README
new file mode 100644
index 00000000..e2f1b2ba
--- /dev/null
+++ b/examples/declarative/cppextensions/qwidgets/README
@@ -0,0 +1,6 @@
+This example shows how to embed QWidget-based objects into QML.
+
+To run:
+
+ make install
+ qml qwidgets.qml
diff --git a/examples/declarative/cppextensions/qwidgets/qwidgets.cpp b/examples/declarative/cppextensions/qwidgets/qwidgets.cpp
new file mode 100644
index 00000000..7781f126
--- /dev/null
+++ b/examples/declarative/cppextensions/qwidgets/qwidgets.cpp
@@ -0,0 +1,96 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtDeclarative/QDeclarativeExtensionPlugin>
+#include <QtDeclarative/qdeclarative.h>
+#include <QtGui/QGraphicsProxyWidget>
+#include <QtGui/QPushButton>
+#include <QDebug>
+
+class MyPushButton : public QGraphicsProxyWidget
+{
+ Q_OBJECT
+ Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
+
+public:
+ MyPushButton(QGraphicsItem* parent = 0)
+ : QGraphicsProxyWidget(parent)
+ {
+ widget = new QPushButton("MyPushButton");
+ widget->setAttribute(Qt::WA_NoSystemBackground);
+ setWidget(widget);
+
+ QObject::connect(widget, SIGNAL(clicked(bool)), this, SIGNAL(clicked(bool)));
+ }
+
+ QString text() const
+ {
+ return widget->text();
+ }
+
+ void setText(const QString& text)
+ {
+ if (text != widget->text()) {
+ widget->setText(text);
+ emit textChanged();
+ }
+ }
+
+Q_SIGNALS:
+ void clicked(bool);
+ void textChanged();
+
+private:
+ QPushButton *widget;
+};
+
+class QWidgetsPlugin : public QDeclarativeExtensionPlugin
+{
+ Q_OBJECT
+public:
+ void registerTypes(const char *uri)
+ {
+ qmlRegisterType<MyPushButton>(uri, 1, 0, "MyPushButton");
+ }
+};
+
+#include "qwidgets.moc"
+
+Q_EXPORT_PLUGIN2(qmlqwidgetsplugin, QWidgetsPlugin);
diff --git a/examples/declarative/cppextensions/qwidgets/qwidgets.pro b/examples/declarative/cppextensions/qwidgets/qwidgets.pro
new file mode 100644
index 00000000..d2721808
--- /dev/null
+++ b/examples/declarative/cppextensions/qwidgets/qwidgets.pro
@@ -0,0 +1,25 @@
+TEMPLATE = lib
+CONFIG += qt plugin
+QT += declarative
+
+DESTDIR = QWidgets
+TARGET = qmlqwidgetsplugin
+
+SOURCES += qwidgets.cpp
+
+sources.files += qwidgets.pro qwidgets.cpp qwidgets.qml
+sources.path += $$[QT_INSTALL_EXAMPLES]/declarative/cppextensions/plugins
+target.path += $$[QT_INSTALL_EXAMPLES]/declarative/cppextensions/plugins
+
+INSTALLS += sources target
+
+symbian:{
+ include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+ TARGET.EPOCALLOWDLLDATA = 1
+
+ importFiles.files = QWidgets/qmlqwidgetsplugin.dll QWidgets/qmldir
+ importFiles.path = QWidgets
+
+ DEPLOYMENT += importFiles
+}
+maemo5: include($$QT_SOURCE_TREE/examples/maemo5pkgrules.pri)
diff --git a/examples/declarative/cppextensions/qwidgets/qwidgets.qml b/examples/declarative/cppextensions/qwidgets/qwidgets.qml
new file mode 100644
index 00000000..cd7bf616
--- /dev/null
+++ b/examples/declarative/cppextensions/qwidgets/qwidgets.qml
@@ -0,0 +1,110 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 1.0
+import "QWidgets" 1.0
+
+Rectangle {
+ id: window
+
+ property int margin: 30
+
+ width: 640; height: 480
+ color: palette.window
+
+ SystemPalette { id: palette }
+
+ MyPushButton {
+ id: button1
+ x: margin; y: margin
+ text: "Right"
+ transformOriginPoint: Qt.point(width / 2, height / 2)
+
+ onClicked: window.state = "right"
+ }
+
+ MyPushButton {
+ id: button2
+ x: margin; y: margin + 30
+ text: "Bottom"
+ transformOriginPoint: Qt.point(width / 2, height / 2)
+
+ onClicked: window.state = "bottom"
+ }
+
+ MyPushButton {
+ id: button3
+ x: margin; y: margin + 60
+ text: "Quit"
+ transformOriginPoint: Qt.point(width / 2, height / 2)
+
+ onClicked: Qt.quit()
+ }
+
+ states: [
+ State {
+ name: "right"
+ PropertyChanges { target: button1; x: window.width - width - margin; text: "Left"; onClicked: window.state = "" }
+ PropertyChanges { target: button2; x: window.width - width - margin }
+ PropertyChanges { target: button3; x: window.width - width - margin }
+ PropertyChanges { target: window; color: Qt.darker(palette.window) }
+ },
+ State {
+ name: "bottom"
+ PropertyChanges { target: button1; y: window.height - height - margin; rotation: 180 }
+ PropertyChanges {
+ target: button2
+ x: button1.x + button1.width + 10; y: window.height - height - margin
+ rotation: 180
+ text: "Top"
+ onClicked: window.state = ""
+ }
+ PropertyChanges { target: button3; x: button2.x + button2.width + 10; y: window.height - height - margin; rotation: 180 }
+ PropertyChanges { target: window; color: Qt.lighter(palette.window) }
+ }
+ ]
+
+ transitions: Transition {
+ ParallelAnimation {
+ NumberAnimation { properties: "x,y,rotation"; duration: 600; easing.type: Easing.OutQuad }
+ ColorAnimation { target: window; duration: 600 }
+ }
+ }
+}
diff --git a/examples/declarative/cppextensions/qwidgets/qwidgets.qmlproject b/examples/declarative/cppextensions/qwidgets/qwidgets.qmlproject
new file mode 100644
index 00000000..d4909f86
--- /dev/null
+++ b/examples/declarative/cppextensions/qwidgets/qwidgets.qmlproject
@@ -0,0 +1,16 @@
+import QmlProject 1.0
+
+Project {
+ /* Include .qml, .js, and image files from current directory and subdirectories */
+ QmlFiles {
+ directory: "."
+ }
+ JavaScriptFiles {
+ directory: "."
+ }
+ ImageFiles {
+ directory: "."
+ }
+ /* List of plugin directories passed to QML runtime */
+ // importPaths: [ " ../exampleplugin " ]
+}