summaryrefslogtreecommitdiffstats
path: root/examples/declarative/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'examples/declarative/plugins')
-rw-r--r--examples/declarative/plugins/README9
-rw-r--r--examples/declarative/plugins/files/Clock.qml50
-rw-r--r--examples/declarative/plugins/files/center.pngbin0 -> 765 bytes
-rw-r--r--examples/declarative/plugins/files/clock.pngbin0 -> 20653 bytes
-rw-r--r--examples/declarative/plugins/files/hour.pngbin0 -> 625 bytes
-rw-r--r--examples/declarative/plugins/files/minute.pngbin0 -> 625 bytes
-rw-r--r--examples/declarative/plugins/plugin.cpp161
-rw-r--r--examples/declarative/plugins/plugins.pro15
-rw-r--r--examples/declarative/plugins/plugins.qml12
9 files changed, 247 insertions, 0 deletions
diff --git a/examples/declarative/plugins/README b/examples/declarative/plugins/README
new file mode 100644
index 0000000..621f570
--- /dev/null
+++ b/examples/declarative/plugins/README
@@ -0,0 +1,9 @@
+This example shows a module "com.nokia.TimeExample" that is implelement
+by a C++ plugin (providing the "Time" type), and by QML files (providing the
+"Clock" type).
+
+To run:
+
+ make install
+ qmlviewer plugins.qml
+
diff --git a/examples/declarative/plugins/files/Clock.qml b/examples/declarative/plugins/files/Clock.qml
new file mode 100644
index 0000000..01ec686
--- /dev/null
+++ b/examples/declarative/plugins/files/Clock.qml
@@ -0,0 +1,50 @@
+import Qt 4.6
+
+Item {
+ id: clock
+ width: 200; height: 200
+
+ property alias city: cityLabel.text
+ property var hours
+ property var minutes
+ property var shift : 0
+
+ Image { id: background; source: "clock.png" }
+
+ Image {
+ x: 92.5; y: 27
+ source: "hour.png"
+ smooth: true
+ transform: Rotation {
+ id: hourRotation
+ origin.x: 7.5; origin.y: 73; angle: 0
+ angle: SpringFollow {
+ spring: 2; damping: 0.2; modulus: 360
+ source: (clock.hours * 30) + (clock.minutes * 0.5)
+ }
+ }
+ }
+
+ Image {
+ x: 93.5; y: 17
+ source: "minute.png"
+ smooth: true
+ transform: Rotation {
+ id: minuteRotation
+ origin.x: 6.5; origin.y: 83; angle: 0
+ angle: SpringFollow {
+ spring: 2; damping: 0.2; modulus: 360
+ source: clock.minutes * 6
+ }
+ }
+ }
+
+ Image {
+ anchors.centerIn: background; source: "center.png"
+ }
+
+ Text {
+ id: cityLabel; font.bold: true; font.pixelSize: 14; y:200; color: "white"
+ anchors.horizontalCenter: parent.horizontalCenter
+ }
+}
diff --git a/examples/declarative/plugins/files/center.png b/examples/declarative/plugins/files/center.png
new file mode 100644
index 0000000..7fbd802
--- /dev/null
+++ b/examples/declarative/plugins/files/center.png
Binary files differ
diff --git a/examples/declarative/plugins/files/clock.png b/examples/declarative/plugins/files/clock.png
new file mode 100644
index 0000000..462edac
--- /dev/null
+++ b/examples/declarative/plugins/files/clock.png
Binary files differ
diff --git a/examples/declarative/plugins/files/hour.png b/examples/declarative/plugins/files/hour.png
new file mode 100644
index 0000000..f8061a1
--- /dev/null
+++ b/examples/declarative/plugins/files/hour.png
Binary files differ
diff --git a/examples/declarative/plugins/files/minute.png b/examples/declarative/plugins/files/minute.png
new file mode 100644
index 0000000..1297ec7
--- /dev/null
+++ b/examples/declarative/plugins/files/minute.png
Binary files differ
diff --git a/examples/declarative/plugins/plugin.cpp b/examples/declarative/plugins/plugin.cpp
new file mode 100644
index 0000000..f4aa36b
--- /dev/null
+++ b/examples/declarative/plugins/plugin.cpp
@@ -0,0 +1,161 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 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:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtDeclarative/qmlmoduleplugin.h>
+#include <QtDeclarative/qml.h>
+#include <qdebug.h>
+#include <qdatetime.h>
+#include <qbasictimer.h>
+#include <qapplication.h>
+
+// Implements a "Time" class with hour and minute properties
+// that change on-the-minute yet efficiently sleep the rest
+// of the time.
+
+class MinuteTimer : public QObject
+{
+ Q_OBJECT
+public:
+ MinuteTimer(QObject *parent) : QObject(parent)
+ {
+ }
+
+ void start()
+ {
+ if (!timer.isActive()) {
+ time = QTime::currentTime();
+ timer.start(60000-time.second()*1000, this);
+ }
+ }
+
+ void stop()
+ {
+ timer.stop();
+ }
+
+ int hour() const { return time.hour(); }
+ int minute() const { return time.minute(); }
+
+signals:
+ void timeChanged();
+
+protected:
+ void timerEvent(QTimerEvent *)
+ {
+ QTime now = QTime::currentTime();
+ if (now.second() == 59 && now.minute() == time.minute() && now.hour() == time.hour()) {
+ // just missed time tick over, force it, wait extra 0.5 seconds
+ time.addSecs(60);
+ timer.start(60500, this);
+ } else {
+ time = now;
+ timer.start(60000-time.second()*1000, this);
+ }
+ emit timeChanged();
+ }
+
+private:
+ QTime time;
+ QBasicTimer timer;
+};
+
+class Time : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(int hour READ hour NOTIFY timeChanged)
+ Q_PROPERTY(int minute READ minute NOTIFY timeChanged)
+
+public:
+ Time(QObject *parent=0) : QObject(parent)
+ {
+ if (++instances == 1) {
+ if (!timer)
+ timer = new MinuteTimer(qApp);
+ connect(timer, SIGNAL(timeChanged()), this, SIGNAL(timeChanged()));
+ timer->start();
+ }
+ }
+
+ ~Time()
+ {
+ if (--instances == 0) {
+ timer->stop();
+ }
+ }
+
+ int minute() const { return timer->minute(); }
+ int hour() const { return timer->hour(); }
+
+signals:
+ void timeChanged();
+
+private:
+ QTime t;
+ static MinuteTimer *timer;
+ static int instances;
+};
+
+int Time::instances=0;
+MinuteTimer *Time::timer=0;
+
+
+QML_DECLARE_TYPE(Time);
+
+
+class QExampleQmlPlugin : public QmlModulePlugin
+{
+ Q_OBJECT
+public:
+ QStringList keys() const
+ {
+ return QStringList() << QLatin1String("com.nokia.TimeExample");
+ }
+
+ void defineModule(const QString& uri)
+ {
+ Q_ASSERT(uri == QLatin1String("com.nokia.TimeExample"));
+ qmlRegisterType<Time>("com.nokia.TimeExample", 1, 0, "Time", "Time");
+ }
+};
+
+#include "plugin.moc"
+
+Q_EXPORT_PLUGIN2(qtimeexampleqmlplugin, QExampleQmlPlugin);
diff --git a/examples/declarative/plugins/plugins.pro b/examples/declarative/plugins/plugins.pro
new file mode 100644
index 0000000..84ab8da
--- /dev/null
+++ b/examples/declarative/plugins/plugins.pro
@@ -0,0 +1,15 @@
+TEMPLATE = lib
+TARGET = qtimeexampleqmlplugin
+CONFIG += qt plugin
+QT += declarative
+
+SOURCES += plugin.cpp
+
+target.path += $$[QT_INSTALL_PLUGINS]/qmlmodules
+sources.files += files/Clock.qml files/qmldir files/background.png files/center.png files/clock-night.png files/clock.png files/hour.png files/minute.png
+sources.path += $$[QT_INSTALL_DATA]/qml/com/nokia/TimeExample
+INSTALLS += target sources
+
+
+VERSION=1.0.0
+
diff --git a/examples/declarative/plugins/plugins.qml b/examples/declarative/plugins/plugins.qml
new file mode 100644
index 0000000..dbeb001
--- /dev/null
+++ b/examples/declarative/plugins/plugins.qml
@@ -0,0 +1,12 @@
+import com.nokia.TimeExample 1.0 // import types from the plugin
+import 'files' // import types from the 'files' directory
+
+Clock { // this class is defined in QML (files/Clock.qml)
+
+ Time { // this class is defined in C++ (plugins.cpp)
+ id: time
+ }
+
+ hours: time.hour
+ minutes: time.minute
+}