diff options
Diffstat (limited to 'examples/declarative/cppextensions')
121 files changed, 6669 insertions, 0 deletions
diff --git a/examples/declarative/cppextensions/cppextensions.pro b/examples/declarative/cppextensions/cppextensions.pro new file mode 100644 index 0000000..caa6092 --- /dev/null +++ b/examples/declarative/cppextensions/cppextensions.pro @@ -0,0 +1,10 @@ +TEMPLATE = subdirs + +SUBDIRS += \ + imageprovider \ + plugins \ + proxyviewer \ + proxywidgets \ + qgraphicslayouts \ + referenceexamples + diff --git a/examples/declarative/cppextensions/cppextensions.qmlproject b/examples/declarative/cppextensions/cppextensions.qmlproject new file mode 100644 index 0000000..d4909f8 --- /dev/null +++ b/examples/declarative/cppextensions/cppextensions.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 " ] +} diff --git a/examples/declarative/cppextensions/imageprovider/ImageProviderCore/qmldir b/examples/declarative/cppextensions/imageprovider/ImageProviderCore/qmldir new file mode 100644 index 0000000..1028590 --- /dev/null +++ b/examples/declarative/cppextensions/imageprovider/ImageProviderCore/qmldir @@ -0,0 +1,2 @@ +plugin imageprovider + diff --git a/examples/declarative/cppextensions/imageprovider/imageprovider-example.qml b/examples/declarative/cppextensions/imageprovider/imageprovider-example.qml new file mode 100644 index 0000000..d774112 --- /dev/null +++ b/examples/declarative/cppextensions/imageprovider/imageprovider-example.qml @@ -0,0 +1,25 @@ +import Qt 4.7 +import "ImageProviderCore" +//![0] +ListView { + width: 100; height: 100 + anchors.fill: parent + + model: myModel + + delegate: Component { + Item { + width: 100 + height: 50 + Text { + text: "Loading..." + anchors.centerIn: parent + } + Image { + source: modelData + sourceSize: "50x25" + } + } + } +} +//![0] diff --git a/examples/declarative/cppextensions/imageprovider/imageprovider.cpp b/examples/declarative/cppextensions/imageprovider/imageprovider.cpp new file mode 100644 index 0000000..4c4aa94 --- /dev/null +++ b/examples/declarative/cppextensions/imageprovider/imageprovider.cpp @@ -0,0 +1,118 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the demonstration applications 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 <qdeclarativeextensionplugin.h> + +#include <qdeclarativeengine.h> +#include <qdeclarativecontext.h> +#include <qdeclarative.h> +#include <qdeclarativeitem.h> +#include <qdeclarativeimageprovider.h> +#include <qdeclarativeview.h> +#include <QImage> +#include <QPainter> + +/* + This example illustrates using a QDeclarativeImageProvider to serve + images asynchronously. +*/ + +//![0] +class ColorImageProvider : public QDeclarativeImageProvider +{ +public: + // This is run in a low priority thread. + QImage request(const QString &id, QSize *size, const QSize &req_size) + { + if (size) *size = QSize(100,50); + QImage image( + req_size.width() > 0 ? req_size.width() : 100, + req_size.height() > 0 ? req_size.height() : 50, + QImage::Format_RGB32); + image.fill(QColor(id).rgba()); + QPainter p(&image); + QFont f = p.font(); + f.setPixelSize(30); + p.setFont(f); + p.setPen(Qt::black); + if (req_size.isValid()) + p.scale(req_size.width()/100.0, req_size.height()/50.0); + p.drawText(QRectF(0,0,100,50),Qt::AlignCenter,id); + return image; + } +}; + + +class ImageProviderExtensionPlugin : public QDeclarativeExtensionPlugin +{ + Q_OBJECT +public: + void registerTypes(const char *uri) { + Q_UNUSED(uri); + + } + + void initializeEngine(QDeclarativeEngine *engine, const char *uri) { + Q_UNUSED(uri); + + engine->addImageProvider("colors", new ColorImageProvider); + + QStringList dataList; + dataList.append("image://colors/red"); + dataList.append("image://colors/green"); + dataList.append("image://colors/blue"); + dataList.append("image://colors/brown"); + dataList.append("image://colors/orange"); + dataList.append("image://colors/purple"); + dataList.append("image://colors/yellow"); + + QDeclarativeContext *ctxt = engine->rootContext(); + ctxt->setContextProperty("myModel", QVariant::fromValue(dataList)); + } + +}; + +#include "imageprovider.moc" + +Q_EXPORT_PLUGIN(ImageProviderExtensionPlugin); +//![0] + diff --git a/examples/declarative/cppextensions/imageprovider/imageprovider.pro b/examples/declarative/cppextensions/imageprovider/imageprovider.pro new file mode 100644 index 0000000..945a301 --- /dev/null +++ b/examples/declarative/cppextensions/imageprovider/imageprovider.pro @@ -0,0 +1,25 @@ +TEMPLATE = lib +TARGET = imageprovider +QT += declarative +CONFIG += qt plugin + +TARGET = $$qtLibraryTarget($$TARGET) +DESTDIR = ImageProviderCore + +# Input +SOURCES += imageprovider.cpp + +sources.files = $$SOURCES imageprovider.qml imageprovider.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/declarative/imageprovider + +target.path = $$[QT_INSTALL_EXAMPLES]/declarative/imageprovider/ImageProviderCore + +ImageProviderCore_sources.files = \ + ImageProviderCore/qmldir +ImageProviderCore_sources.path = $$[QT_INSTALL_EXAMPLES]/declarative/imageprovider/ImageProviderCore + +symbian:{ + TARGET.EPOCALLOWDLLDATA=1 +} + +INSTALLS = sources ImageProviderCore_sources target diff --git a/examples/declarative/cppextensions/imageprovider/imageprovider.qmlproject b/examples/declarative/cppextensions/imageprovider/imageprovider.qmlproject new file mode 100644 index 0000000..d4909f8 --- /dev/null +++ b/examples/declarative/cppextensions/imageprovider/imageprovider.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 " ] +} diff --git a/examples/declarative/cppextensions/plugins/README b/examples/declarative/cppextensions/plugins/README new file mode 100644 index 0000000..fe519f8 --- /dev/null +++ b/examples/declarative/cppextensions/plugins/README @@ -0,0 +1,9 @@ +This example shows a module "com.nokia.TimeExample" that is implemented +by a C++ plugin (providing the "Time" type), and by QML files (providing the +"Clock" type). + +To run: + + make install + qml -I . plugins.qml + diff --git a/examples/declarative/cppextensions/plugins/com/nokia/TimeExample/Clock.qml b/examples/declarative/cppextensions/plugins/com/nokia/TimeExample/Clock.qml new file mode 100644 index 0000000..0048372 --- /dev/null +++ b/examples/declarative/cppextensions/plugins/com/nokia/TimeExample/Clock.qml @@ -0,0 +1,50 @@ +import Qt 4.7 + +Rectangle { + id: clock + width: 200; height: 200; color: "gray" + + property alias city: cityLabel.text + property variant hours + property variant minutes + property variant 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 + SpringFollow on angle { + spring: 2; damping: 0.2; modulus: 360 + to: (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 + SpringFollow on angle { + spring: 2; damping: 0.2; modulus: 360 + to: 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/cppextensions/plugins/com/nokia/TimeExample/center.png b/examples/declarative/cppextensions/plugins/com/nokia/TimeExample/center.png Binary files differnew file mode 100644 index 0000000..7fbd802 --- /dev/null +++ b/examples/declarative/cppextensions/plugins/com/nokia/TimeExample/center.png diff --git a/examples/declarative/cppextensions/plugins/com/nokia/TimeExample/clock.png b/examples/declarative/cppextensions/plugins/com/nokia/TimeExample/clock.png Binary files differnew file mode 100644 index 0000000..462edac --- /dev/null +++ b/examples/declarative/cppextensions/plugins/com/nokia/TimeExample/clock.png diff --git a/examples/declarative/cppextensions/plugins/com/nokia/TimeExample/hour.png b/examples/declarative/cppextensions/plugins/com/nokia/TimeExample/hour.png Binary files differnew file mode 100644 index 0000000..f8061a1 --- /dev/null +++ b/examples/declarative/cppextensions/plugins/com/nokia/TimeExample/hour.png diff --git a/examples/declarative/cppextensions/plugins/com/nokia/TimeExample/minute.png b/examples/declarative/cppextensions/plugins/com/nokia/TimeExample/minute.png Binary files differnew file mode 100644 index 0000000..1297ec7 --- /dev/null +++ b/examples/declarative/cppextensions/plugins/com/nokia/TimeExample/minute.png diff --git a/examples/declarative/cppextensions/plugins/com/nokia/TimeExample/qmldir b/examples/declarative/cppextensions/plugins/com/nokia/TimeExample/qmldir new file mode 100644 index 0000000..e9ef115 --- /dev/null +++ b/examples/declarative/cppextensions/plugins/com/nokia/TimeExample/qmldir @@ -0,0 +1,2 @@ +Clock 1.0 Clock.qml +plugin qtimeexampleqmlplugin diff --git a/examples/declarative/cppextensions/plugins/plugin.cpp b/examples/declarative/cppextensions/plugins/plugin.cpp new file mode 100644 index 0000000..fb51b0c --- /dev/null +++ b/examples/declarative/cppextensions/plugins/plugin.cpp @@ -0,0 +1,152 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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/QDeclarativeExtensionPlugin> +#include <QtDeclarative/qdeclarative.h> +#include <qdebug.h> +#include <qdatetime.h> +#include <qbasictimer.h> +#include <qapplication.h> + +// Implements a "TimeModel" 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 TimeModel : public QObject +{ + Q_OBJECT + Q_PROPERTY(int hour READ hour NOTIFY timeChanged) + Q_PROPERTY(int minute READ minute NOTIFY timeChanged) + +public: + TimeModel(QObject *parent=0) : QObject(parent) + { + if (++instances == 1) { + if (!timer) + timer = new MinuteTimer(qApp); + connect(timer, SIGNAL(timeChanged()), this, SIGNAL(timeChanged())); + timer->start(); + } + } + + ~TimeModel() + { + 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 TimeModel::instances=0; +MinuteTimer *TimeModel::timer=0; + +class QExampleQmlPlugin : public QDeclarativeExtensionPlugin +{ + Q_OBJECT +public: + void registerTypes(const char *uri) + { + Q_ASSERT(uri == QLatin1String("com.nokia.TimeExample")); + qmlRegisterType<TimeModel>(uri, 1, 0, "Time"); + } +}; + +#include "plugin.moc" + +Q_EXPORT_PLUGIN2(qtimeexampleqmlplugin, QExampleQmlPlugin); diff --git a/examples/declarative/cppextensions/plugins/plugins.pro b/examples/declarative/cppextensions/plugins/plugins.pro new file mode 100644 index 0000000..b501ae3 --- /dev/null +++ b/examples/declarative/cppextensions/plugins/plugins.pro @@ -0,0 +1,31 @@ +TEMPLATE = lib +DESTDIR = com/nokia/TimeExample +TARGET = qtimeexampleqmlplugin +CONFIG += qt plugin +QT += declarative + +SOURCES += plugin.cpp + +qdeclarativesources.files += \ + com/nokia/TimeExample/qmldir \ + com/nokia/TimeExample/center.png \ + com/nokia/TimeExample/clock.png \ + com/nokia/TimeExample/Clock.qml \ + com/nokia/TimeExample/hour.png \ + com/nokia/TimeExample/minute.png + +qdeclarativesources.path += $$[QT_INSTALL_EXAMPLES]/declarative/plugins/com/nokia/TimeExample + +sources.files += plugins.pro plugin.cpp plugins.qml README +sources.path += $$[QT_INSTALL_EXAMPLES]/declarative/plugins + +target.path += $$[QT_INSTALL_EXAMPLES]/declarative/plugins/com/nokia/TimeExample + +symbian:{ + TARGET.EPOCALLOWDLLDATA=1 +} + + +INSTALLS += qdeclarativesources sources target + +symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) diff --git a/examples/declarative/cppextensions/plugins/plugins.qml b/examples/declarative/cppextensions/plugins/plugins.qml new file mode 100644 index 0000000..449cd9a --- /dev/null +++ b/examples/declarative/cppextensions/plugins/plugins.qml @@ -0,0 +1,11 @@ +import com.nokia.TimeExample 1.0 // import types from the plugin + +Clock { // this class is defined in QML (com/nokia/TimeExample/Clock.qml) + + Time { // this class is defined in C++ (plugin.cpp) + id: time + } + + hours: time.hour + minutes: time.minute +} diff --git a/examples/declarative/cppextensions/plugins/plugins.qmlproject b/examples/declarative/cppextensions/plugins/plugins.qmlproject new file mode 100644 index 0000000..d4909f8 --- /dev/null +++ b/examples/declarative/cppextensions/plugins/plugins.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 " ] +} diff --git a/examples/declarative/cppextensions/proxyviewer/main.cpp b/examples/declarative/cppextensions/proxyviewer/main.cpp new file mode 100644 index 0000000..b82d2c9 --- /dev/null +++ b/examples/declarative/cppextensions/proxyviewer/main.cpp @@ -0,0 +1,109 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the demonstration applications 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 <QApplication> +#include <QNetworkAccessManager> +#include <QNetworkProxy> + +#include <QDeclarativeEngine> +#include <QDeclarativeNetworkAccessManagerFactory> +#include <QDeclarativeView> + + +/* + This example illustrates using a QNetworkAccessManagerFactory to + create a QNetworkAccessManager with a proxy. + + Usage: + proxyviewer [-host <proxy> -port <port>] [file] +*/ + +static QString proxyHost; +static int proxyPort = 0; + +class MyNetworkAccessManagerFactory : public QDeclarativeNetworkAccessManagerFactory +{ +public: + virtual QNetworkAccessManager *create(QObject *parent); +}; + +QNetworkAccessManager *MyNetworkAccessManagerFactory::create(QObject *parent) +{ + QNetworkAccessManager *nam = new QNetworkAccessManager(parent); + if (!proxyHost.isEmpty()) { + qDebug() << "Created QNetworkAccessManager using proxy" << (proxyHost + ":" + QString::number(proxyPort)); + QNetworkProxy proxy(QNetworkProxy::HttpCachingProxy, proxyHost, proxyPort); + nam->setProxy(proxy); + } + + return nam; +} + +int main(int argc, char ** argv) +{ + QUrl source("qrc:view.qml"); + + QApplication app(argc, argv); + + for (int i = 1; i < argc; ++i) { + QString arg(argv[i]); + if (arg == "-host" && i < argc-1) { + proxyHost = argv[++i]; + } else if (arg == "-port" && i < argc-1) { + arg = argv[++i]; + proxyPort = arg.toInt(); + } else if (arg[0] != '-') { + source = QUrl::fromLocalFile(arg); + } else { + qWarning() << "Usage: proxyviewer [-host <proxy> -port <port>] [file]"; + exit(1); + } + } + + QDeclarativeView view; + view.engine()->setNetworkAccessManagerFactory(new MyNetworkAccessManagerFactory); + + view.setSource(source); + view.show(); + + return app.exec(); +} + diff --git a/examples/declarative/cppextensions/proxyviewer/proxyviewer.pro b/examples/declarative/cppextensions/proxyviewer/proxyviewer.pro new file mode 100644 index 0000000..b6bfa7f --- /dev/null +++ b/examples/declarative/cppextensions/proxyviewer/proxyviewer.pro @@ -0,0 +1,9 @@ +TEMPLATE = app +TARGET = proxyviewer +DEPENDPATH += . +INCLUDEPATH += . +QT += declarative network + +# Input +SOURCES += main.cpp +RESOURCES += proxyviewer.qrc diff --git a/examples/declarative/cppextensions/proxyviewer/proxyviewer.qrc b/examples/declarative/cppextensions/proxyviewer/proxyviewer.qrc new file mode 100644 index 0000000..17e9301 --- /dev/null +++ b/examples/declarative/cppextensions/proxyviewer/proxyviewer.qrc @@ -0,0 +1,5 @@ +<!DOCTYPE RCC><RCC version="1.0"> +<qresource> + <file>view.qml</file> +</qresource> +</RCC> diff --git a/examples/declarative/cppextensions/proxyviewer/view.qml b/examples/declarative/cppextensions/proxyviewer/view.qml new file mode 100644 index 0000000..7f1bdef --- /dev/null +++ b/examples/declarative/cppextensions/proxyviewer/view.qml @@ -0,0 +1,7 @@ +import Qt 4.7 + +Image { + width: 100 + height: 100 + source: "http://qt.nokia.com/logo.png" +} diff --git a/examples/declarative/cppextensions/proxywidgets/ProxyWidgets/qmldir b/examples/declarative/cppextensions/proxywidgets/ProxyWidgets/qmldir new file mode 100644 index 0000000..e55267c --- /dev/null +++ b/examples/declarative/cppextensions/proxywidgets/ProxyWidgets/qmldir @@ -0,0 +1 @@ +plugin proxywidgetsplugin diff --git a/examples/declarative/cppextensions/proxywidgets/README b/examples/declarative/cppextensions/proxywidgets/README new file mode 100644 index 0000000..f50fa22 --- /dev/null +++ b/examples/declarative/cppextensions/proxywidgets/README @@ -0,0 +1,4 @@ +To run: + + make install + qml proxywidgets.qml diff --git a/examples/declarative/cppextensions/proxywidgets/proxywidgets.cpp b/examples/declarative/cppextensions/proxywidgets/proxywidgets.cpp new file mode 100644 index 0000000..067eb2c --- /dev/null +++ b/examples/declarative/cppextensions/proxywidgets/proxywidgets.cpp @@ -0,0 +1,97 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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/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 ProxyWidgetsPlugin : public QDeclarativeExtensionPlugin +{ + Q_OBJECT +public: + void registerTypes(const char *uri) + { + qmlRegisterType<MyPushButton>(uri, 1, 0, "MyPushButton"); + } +}; + +#include "proxywidgets.moc" + +Q_EXPORT_PLUGIN2(proxywidgetsplugin, ProxyWidgetsPlugin); diff --git a/examples/declarative/cppextensions/proxywidgets/proxywidgets.pro b/examples/declarative/cppextensions/proxywidgets/proxywidgets.pro new file mode 100644 index 0000000..cb07d80 --- /dev/null +++ b/examples/declarative/cppextensions/proxywidgets/proxywidgets.pro @@ -0,0 +1,21 @@ +TEMPLATE = lib +DESTDIR = ProxyWidgets +TARGET = proxywidgetsplugin +CONFIG += qt plugin +QT += declarative + +SOURCES += proxywidgets.cpp + +sources.files += proxywidgets.pro proxywidgets.cpp proxywidgets.qml + +sources.path += $$[QT_INSTALL_EXAMPLES]/declarative/plugins + +target.path += $$[QT_INSTALL_EXAMPLES]/declarative/plugins + +INSTALLS += sources target + +symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) + +symbian:{ + TARGET.EPOCALLOWDLLDATA = 1 +}
\ No newline at end of file diff --git a/examples/declarative/cppextensions/proxywidgets/proxywidgets.qml b/examples/declarative/cppextensions/proxywidgets/proxywidgets.qml new file mode 100644 index 0000000..88de37f --- /dev/null +++ b/examples/declarative/cppextensions/proxywidgets/proxywidgets.qml @@ -0,0 +1,70 @@ +import Qt 4.7 +import "ProxyWidgets" 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/proxywidgets/proxywidgets.qmlproject b/examples/declarative/cppextensions/proxywidgets/proxywidgets.qmlproject new file mode 100644 index 0000000..d4909f8 --- /dev/null +++ b/examples/declarative/cppextensions/proxywidgets/proxywidgets.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 " ] +} diff --git a/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicslayouts.cpp b/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicslayouts.cpp new file mode 100644 index 0000000..25cf994 --- /dev/null +++ b/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicslayouts.cpp @@ -0,0 +1,366 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module 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 "graphicslayouts_p.h" + +#include <QtGui/qgraphicswidget.h> +#include <QtCore/qdebug.h> + +QT_BEGIN_NAMESPACE + +LinearLayoutAttached::LinearLayoutAttached(QObject *parent) +: QObject(parent), _stretch(1), _alignment(Qt::AlignCenter), _spacing(0) +{ +} + +void LinearLayoutAttached::setStretchFactor(int f) +{ + if (_stretch == f) + return; + + _stretch = f; + emit stretchChanged(reinterpret_cast<QGraphicsLayoutItem*>(parent()), _stretch); +} + +void LinearLayoutAttached::setSpacing(int s) +{ + if (_spacing == s) + return; + + _spacing = s; + emit spacingChanged(reinterpret_cast<QGraphicsLayoutItem*>(parent()), _spacing); +} + +void LinearLayoutAttached::setAlignment(Qt::Alignment a) +{ + if (_alignment == a) + return; + + _alignment = a; + emit alignmentChanged(reinterpret_cast<QGraphicsLayoutItem*>(parent()), _alignment); +} + +QGraphicsLinearLayoutStretchItemObject::QGraphicsLinearLayoutStretchItemObject(QObject *parent) + : QObject(parent) +{ +} + +QSizeF QGraphicsLinearLayoutStretchItemObject::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const +{ +Q_UNUSED(which); +Q_UNUSED(constraint); +return QSizeF(); +} + + +QGraphicsLinearLayoutObject::QGraphicsLinearLayoutObject(QObject *parent) +: QObject(parent) +{ +} + +QGraphicsLinearLayoutObject::~QGraphicsLinearLayoutObject() +{ +} + +void QGraphicsLinearLayoutObject::insertLayoutItem(int index, QGraphicsLayoutItem *item) +{ +insertItem(index, item); + +//connect attached properties +if (LinearLayoutAttached *obj = attachedProperties.value(item)) { + setStretchFactor(item, obj->stretchFactor()); + setAlignment(item, obj->alignment()); + updateSpacing(item, obj->spacing()); + QObject::connect(obj, SIGNAL(stretchChanged(QGraphicsLayoutItem*,int)), + this, SLOT(updateStretch(QGraphicsLayoutItem*,int))); + QObject::connect(obj, SIGNAL(alignmentChanged(QGraphicsLayoutItem*,Qt::Alignment)), + this, SLOT(updateAlignment(QGraphicsLayoutItem*,Qt::Alignment))); + QObject::connect(obj, SIGNAL(spacingChanged(QGraphicsLayoutItem*,int)), + this, SLOT(updateSpacing(QGraphicsLayoutItem*,int))); + //### need to disconnect when widget is removed? +} +} + +//### is there a better way to do this? +void QGraphicsLinearLayoutObject::clearChildren() +{ +for (int i = 0; i < count(); ++i) + removeAt(i); +} + +qreal QGraphicsLinearLayoutObject::contentsMargin() const +{ + qreal a,b,c,d; + getContentsMargins(&a, &b, &c, &d); + if(a==b && a==c && a==d) + return a; + return -1; +} + +void QGraphicsLinearLayoutObject::setContentsMargin(qreal m) +{ + setContentsMargins(m,m,m,m); +} + +void QGraphicsLinearLayoutObject::updateStretch(QGraphicsLayoutItem *item, int stretch) +{ +QGraphicsLinearLayout::setStretchFactor(item, stretch); +} + +void QGraphicsLinearLayoutObject::updateSpacing(QGraphicsLayoutItem* item, int spacing) +{ + for(int i=0; i < count(); i++){ + if(itemAt(i) == item){ //I do not see the reverse function, which is why we must loop over all items + QGraphicsLinearLayout::setItemSpacing(i, spacing); + return; + } + } +} + +void QGraphicsLinearLayoutObject::updateAlignment(QGraphicsLayoutItem *item, Qt::Alignment alignment) +{ +QGraphicsLinearLayout::setAlignment(item, alignment); +} + +QHash<QGraphicsLayoutItem*, LinearLayoutAttached*> QGraphicsLinearLayoutObject::attachedProperties; +LinearLayoutAttached *QGraphicsLinearLayoutObject::qmlAttachedProperties(QObject *obj) +{ +// ### This is not allowed - you must attach to any object +if (!qobject_cast<QGraphicsLayoutItem*>(obj)) + return 0; +LinearLayoutAttached *rv = new LinearLayoutAttached(obj); +attachedProperties.insert(qobject_cast<QGraphicsLayoutItem*>(obj), rv); +return rv; +} + +////////////////////////////////////////////////////////////////////////////////////////////////////// +// QGraphicsGridLayout-related classes +////////////////////////////////////////////////////////////////////////////////////////////////////// +GridLayoutAttached::GridLayoutAttached(QObject *parent) +: QObject(parent), _row(-1), _column(-1), _rowspan(1), _colspan(1), _alignment(-1), _rowstretch(-1), + _colstretch(-1), _rowspacing(-1), _colspacing(-1), _rowprefheight(-1), _rowmaxheight(-1), _rowminheight(-1), + _rowfixheight(-1), _colprefwidth(-1), _colmaxwidth(-1), _colminwidth(-1), _colfixwidth(-1) +{ +} + +void GridLayoutAttached::setRow(int r) +{ + if (_row == r) + return; + + _row = r; + //emit rowChanged(reinterpret_cast<QGraphicsLayoutItem*>(parent()), _row); +} + +void GridLayoutAttached::setColumn(int c) +{ + if (_column == c) + return; + + _column = c; + //emit columnChanged(reinterpret_cast<QGraphicsLayoutItem*>(parent()), _column); +} + +void GridLayoutAttached::setRowSpan(int rs) +{ + if (_rowspan == rs) + return; + + _rowspan = rs; + //emit rowSpanChanged(reinterpret_cast<QGraphicsLayoutItem*>(parent()), _rowSpan); +} + +void GridLayoutAttached::setColumnSpan(int cs) +{ + if (_colspan == cs) + return; + + _colspan = cs; + //emit columnSpanChanged(reinterpret_cast<QGraphicsLayoutItem*>(parent()), _columnSpan); +} + +void GridLayoutAttached::setAlignment(Qt::Alignment a) +{ + if (_alignment == a) + return; + + _alignment = a; + emit alignmentChanged(reinterpret_cast<QGraphicsLayoutItem*>(parent()), _alignment); +} + +void GridLayoutAttached::setRowStretchFactor(int f) +{ + _rowstretch = f; +} + +void GridLayoutAttached::setColumnStretchFactor(int f) +{ + _colstretch = f; +} + +void GridLayoutAttached::setRowSpacing(int s) +{ + _rowspacing = s; +} + +void GridLayoutAttached::setColumnSpacing(int s) +{ + _colspacing = s; +} + + +QGraphicsGridLayoutObject::QGraphicsGridLayoutObject(QObject *parent) +: QObject(parent) +{ +} + +QGraphicsGridLayoutObject::~QGraphicsGridLayoutObject() +{ +} + +void QGraphicsGridLayoutObject::addWidget(QGraphicsWidget *wid) +{ +//use attached properties +if (QObject *obj = attachedProperties.value(qobject_cast<QGraphicsLayoutItem*>(wid))) { + int row = static_cast<GridLayoutAttached *>(obj)->row(); + int column = static_cast<GridLayoutAttached *>(obj)->column(); + int rowSpan = static_cast<GridLayoutAttached *>(obj)->rowSpan(); + int columnSpan = static_cast<GridLayoutAttached *>(obj)->columnSpan(); + if (row == -1 || column == -1) { + qWarning() << "Must set row and column for an item in a grid layout"; + return; + } + addItem(wid, row, column, rowSpan, columnSpan); +} +} + +void QGraphicsGridLayoutObject::addLayoutItem(QGraphicsLayoutItem *item) +{ +//use attached properties +if (GridLayoutAttached *obj = attachedProperties.value(item)) { + int row = obj->row(); + int column = obj->column(); + int rowSpan = obj->rowSpan(); + int columnSpan = obj->columnSpan(); + Qt::Alignment alignment = obj->alignment(); + if (row == -1 || column == -1) { + qWarning() << "Must set row and column for an item in a grid layout"; + return; + } + if(obj->rowSpacing() != -1) + setRowSpacing(row, obj->rowSpacing()); + if(obj->columnSpacing() != -1) + setColumnSpacing(column, obj->columnSpacing()); + if(obj->rowStretchFactor() != -1) + setRowStretchFactor(row, obj->rowStretchFactor()); + if(obj->columnStretchFactor() != -1) + setColumnStretchFactor(column, obj->columnStretchFactor()); + if(obj->rowPreferredHeight() != -1) + setRowPreferredHeight(row, obj->rowPreferredHeight()); + if(obj->rowMaximumHeight() != -1) + setRowMaximumHeight(row, obj->rowMaximumHeight()); + if(obj->rowMinimumHeight() != -1) + setRowMinimumHeight(row, obj->rowMinimumHeight()); + if(obj->rowFixedHeight() != -1) + setRowFixedHeight(row, obj->rowFixedHeight()); + if(obj->columnPreferredWidth() != -1) + setColumnPreferredWidth(row, obj->columnPreferredWidth()); + if(obj->columnMaximumWidth() != -1) + setColumnMaximumWidth(row, obj->columnMaximumWidth()); + if(obj->columnMinimumWidth() != -1) + setColumnMinimumWidth(row, obj->columnMinimumWidth()); + if(obj->columnFixedWidth() != -1) + setColumnFixedWidth(row, obj->columnFixedWidth()); + addItem(item, row, column, rowSpan, columnSpan); + if (alignment != -1) + setAlignment(item,alignment); + QObject::connect(obj, SIGNAL(alignmentChanged(QGraphicsLayoutItem*,Qt::Alignment)), + this, SLOT(updateAlignment(QGraphicsLayoutItem*,Qt::Alignment))); + //### need to disconnect when widget is removed? +} +} + +//### is there a better way to do this? +void QGraphicsGridLayoutObject::clearChildren() +{ +for (int i = 0; i < count(); ++i) + removeAt(i); +} + +qreal QGraphicsGridLayoutObject::spacing() const +{ +if (verticalSpacing() == horizontalSpacing()) + return verticalSpacing(); +return -1; //### +} + +qreal QGraphicsGridLayoutObject::contentsMargin() const +{ + qreal a,b,c,d; + getContentsMargins(&a, &b, &c, &d); + if(a==b && a==c && a==d) + return a; + return -1; +} + +void QGraphicsGridLayoutObject::setContentsMargin(qreal m) +{ + setContentsMargins(m,m,m,m); +} + + +void QGraphicsGridLayoutObject::updateAlignment(QGraphicsLayoutItem *item, Qt::Alignment alignment) +{ +QGraphicsGridLayout::setAlignment(item, alignment); +} + +QHash<QGraphicsLayoutItem*, GridLayoutAttached*> QGraphicsGridLayoutObject::attachedProperties; +GridLayoutAttached *QGraphicsGridLayoutObject::qmlAttachedProperties(QObject *obj) +{ +// ### This is not allowed - you must attach to any object +if (!qobject_cast<QGraphicsLayoutItem*>(obj)) + return 0; +GridLayoutAttached *rv = new GridLayoutAttached(obj); +attachedProperties.insert(qobject_cast<QGraphicsLayoutItem*>(obj), rv); +return rv; +} + +QT_END_NAMESPACE diff --git a/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicslayouts.pro b/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicslayouts.pro new file mode 100644 index 0000000..e5d91b2 --- /dev/null +++ b/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicslayouts.pro @@ -0,0 +1,13 @@ +TEMPLATE = app +TARGET = graphicslayouts +QT += declarative + +SOURCES += \ + graphicslayouts.cpp \ + main.cpp + +HEADERS += \ + graphicslayouts_p.h + +RESOURCES += \ + graphicslayouts.qrc diff --git a/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicslayouts.qml b/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicslayouts.qml new file mode 100644 index 0000000..fcd78d5 --- /dev/null +++ b/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicslayouts.qml @@ -0,0 +1,77 @@ +import Qt 4.7 +import GraphicsLayouts 4.7 + +Item { + id: resizable + + width: 800 + height: 400 + + QGraphicsWidget { + size.width: parent.width/2 + size.height: parent.height + + layout: QGraphicsLinearLayout { + LayoutItem { + minimumSize: "100x100" + maximumSize: "300x300" + preferredSize: "100x100" + Rectangle { color: "yellow"; anchors.fill: parent } + } + LayoutItem { + minimumSize: "100x100" + maximumSize: "400x400" + preferredSize: "200x200" + Rectangle { color: "green"; anchors.fill: parent } + } + } + } + QGraphicsWidget { + x: parent.width/2 + size.width: parent.width/2 + size.height: parent.height + + layout: QGraphicsGridLayout { + LayoutItem { + QGraphicsGridLayout.row: 0 + QGraphicsGridLayout.column: 0 + minimumSize: "100x100" + maximumSize: "300x300" + preferredSize: "100x100" + Rectangle { color: "red"; anchors.fill: parent } + } + LayoutItem { + QGraphicsGridLayout.row: 1 + QGraphicsGridLayout.column: 0 + minimumSize: "100x100" + maximumSize: "200x200" + preferredSize: "100x100" + Rectangle { color: "orange"; anchors.fill: parent } + } + LayoutItem { + QGraphicsGridLayout.row: 2 + QGraphicsGridLayout.column: 0 + minimumSize: "100x100" + maximumSize: "300x300" + preferredSize: "200x200" + Rectangle { color: "yellow"; anchors.fill: parent } + } + LayoutItem { + QGraphicsGridLayout.row: 0 + QGraphicsGridLayout.column: 1 + minimumSize: "100x100" + maximumSize: "200x200" + preferredSize: "200x200" + Rectangle { color: "green"; anchors.fill: parent } + } + LayoutItem { + QGraphicsGridLayout.row: 1 + QGraphicsGridLayout.column: 1 + minimumSize: "100x100" + maximumSize: "400x400" + preferredSize: "200x200" + Rectangle { color: "blue"; anchors.fill: parent } + } + } + } +} diff --git a/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicslayouts.qrc b/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicslayouts.qrc new file mode 100644 index 0000000..a199f8d --- /dev/null +++ b/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicslayouts.qrc @@ -0,0 +1,5 @@ +<!DOCTYPE RCC><RCC version="1.0"> +<qresource> + <file>graphicslayouts.qml</file> +</qresource> +</RCC> diff --git a/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicslayouts_p.h b/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicslayouts_p.h new file mode 100644 index 0000000..ea9c614 --- /dev/null +++ b/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicslayouts_p.h @@ -0,0 +1,303 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module 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$ +** +****************************************************************************/ + +#ifndef GRAPHICSLAYOUTS_H +#define GRAPHICSLAYOUTS_H + +#include <QtGui/QGraphicsLinearLayout> +#include <QtGui/QGraphicsGridLayout> +#include <qdeclarative.h> + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QGraphicsLinearLayoutStretchItemObject : public QObject, public QGraphicsLayoutItem +{ + Q_OBJECT + Q_INTERFACES(QGraphicsLayoutItem) +public: + QGraphicsLinearLayoutStretchItemObject(QObject *parent = 0); + + virtual QSizeF sizeHint(Qt::SizeHint, const QSizeF &) const; +}; + +class LinearLayoutAttached; +class QGraphicsLinearLayoutObject : public QObject, public QGraphicsLinearLayout +{ + Q_OBJECT + Q_INTERFACES(QGraphicsLayout QGraphicsLayoutItem) + + Q_PROPERTY(QDeclarativeListProperty<QGraphicsLayoutItem> children READ children) + Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation) + Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing) + Q_PROPERTY(qreal contentsMargin READ contentsMargin WRITE setContentsMargin) + Q_CLASSINFO("DefaultProperty", "children") +public: + QGraphicsLinearLayoutObject(QObject * = 0); + ~QGraphicsLinearLayoutObject(); + + QDeclarativeListProperty<QGraphicsLayoutItem> children() { return QDeclarativeListProperty<QGraphicsLayoutItem>(this, 0, children_append, children_count, children_at, children_clear); } + + static LinearLayoutAttached *qmlAttachedProperties(QObject *); + + qreal contentsMargin() const; + void setContentsMargin(qreal); + +private Q_SLOTS: + void updateStretch(QGraphicsLayoutItem*,int); + void updateSpacing(QGraphicsLayoutItem*,int); + void updateAlignment(QGraphicsLayoutItem*,Qt::Alignment); + +private: + friend class LinearLayoutAttached; + void clearChildren(); + void insertLayoutItem(int, QGraphicsLayoutItem *); + static QHash<QGraphicsLayoutItem*, LinearLayoutAttached*> attachedProperties; + + static void children_append(QDeclarativeListProperty<QGraphicsLayoutItem> *prop, QGraphicsLayoutItem *item) { + static_cast<QGraphicsLinearLayoutObject*>(prop->object)->insertLayoutItem(-1, item); + } + + static void children_clear(QDeclarativeListProperty<QGraphicsLayoutItem> *prop) { + static_cast<QGraphicsLinearLayoutObject*>(prop->object)->clearChildren(); + } + + static int children_count(QDeclarativeListProperty<QGraphicsLayoutItem> *prop) { + return static_cast<QGraphicsLinearLayoutObject*>(prop->object)->count(); + } + + static QGraphicsLayoutItem *children_at(QDeclarativeListProperty<QGraphicsLayoutItem> *prop, int index) { + return static_cast<QGraphicsLinearLayoutObject*>(prop->object)->itemAt(index); + } +}; + +class GridLayoutAttached; +class QGraphicsGridLayoutObject : public QObject, public QGraphicsGridLayout +{ + Q_OBJECT + Q_INTERFACES(QGraphicsLayout QGraphicsLayoutItem) + + Q_PROPERTY(QDeclarativeListProperty<QGraphicsLayoutItem> children READ children) + Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing) + Q_PROPERTY(qreal contentsMargin READ contentsMargin WRITE setContentsMargin) + Q_PROPERTY(qreal verticalSpacing READ verticalSpacing WRITE setVerticalSpacing) + Q_PROPERTY(qreal horizontalSpacing READ horizontalSpacing WRITE setHorizontalSpacing) + Q_CLASSINFO("DefaultProperty", "children") +public: + QGraphicsGridLayoutObject(QObject * = 0); + ~QGraphicsGridLayoutObject(); + + QDeclarativeListProperty<QGraphicsLayoutItem> children() { return QDeclarativeListProperty<QGraphicsLayoutItem>(this, 0, children_append, children_count, children_at, children_clear); } + + qreal spacing() const; + qreal contentsMargin() const; + void setContentsMargin(qreal); + + static GridLayoutAttached *qmlAttachedProperties(QObject *); + +private Q_SLOTS: + void updateAlignment(QGraphicsLayoutItem*,Qt::Alignment); + +private: + friend class GraphicsLayoutAttached; + void addWidget(QGraphicsWidget *); + void clearChildren(); + void addLayoutItem(QGraphicsLayoutItem *); + static QHash<QGraphicsLayoutItem*, GridLayoutAttached*> attachedProperties; + + static void children_append(QDeclarativeListProperty<QGraphicsLayoutItem> *prop, QGraphicsLayoutItem *item) { + static_cast<QGraphicsGridLayoutObject*>(prop->object)->addLayoutItem(item); + } + + static void children_clear(QDeclarativeListProperty<QGraphicsLayoutItem> *prop) { + static_cast<QGraphicsGridLayoutObject*>(prop->object)->clearChildren(); + } + + static int children_count(QDeclarativeListProperty<QGraphicsLayoutItem> *prop) { + return static_cast<QGraphicsGridLayoutObject*>(prop->object)->count(); + } + + static QGraphicsLayoutItem *children_at(QDeclarativeListProperty<QGraphicsLayoutItem> *prop, int index) { + return static_cast<QGraphicsGridLayoutObject*>(prop->object)->itemAt(index); + } +}; + +class LinearLayoutAttached : public QObject +{ + Q_OBJECT + + Q_PROPERTY(int stretchFactor READ stretchFactor WRITE setStretchFactor NOTIFY stretchChanged) + Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged) + Q_PROPERTY(int spacing READ spacing WRITE setSpacing NOTIFY spacingChanged) +public: + LinearLayoutAttached(QObject *parent); + + int stretchFactor() const { return _stretch; } + void setStretchFactor(int f); + Qt::Alignment alignment() const { return _alignment; } + void setAlignment(Qt::Alignment a); + int spacing() const { return _spacing; } + void setSpacing(int s); + +Q_SIGNALS: + void stretchChanged(QGraphicsLayoutItem*,int); + void alignmentChanged(QGraphicsLayoutItem*,Qt::Alignment); + void spacingChanged(QGraphicsLayoutItem*,int); + +private: + int _stretch; + Qt::Alignment _alignment; + int _spacing; +}; + +class GridLayoutAttached : public QObject +{ + Q_OBJECT + + Q_PROPERTY(int row READ row WRITE setRow) + Q_PROPERTY(int column READ column WRITE setColumn) + Q_PROPERTY(int rowSpan READ rowSpan WRITE setRowSpan) + Q_PROPERTY(int columnSpan READ columnSpan WRITE setColumnSpan) + Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment) + Q_PROPERTY(int rowStretchFactor READ rowStretchFactor WRITE setRowStretchFactor) + Q_PROPERTY(int columnStretchFactor READ columnStretchFactor WRITE setColumnStretchFactor) + Q_PROPERTY(int rowSpacing READ rowSpacing WRITE setRowSpacing) + Q_PROPERTY(int columnSpacing READ columnSpacing WRITE setColumnSpacing) + Q_PROPERTY(int rowPreferredHeight READ rowPreferredHeight WRITE setRowPreferredHeight) + Q_PROPERTY(int rowMinimumHeight READ rowMinimumHeight WRITE setRowMinimumHeight) + Q_PROPERTY(int rowMaximumHeight READ rowMaximumHeight WRITE setRowMaximumHeight) + Q_PROPERTY(int rowFixedHeight READ rowFixedHeight WRITE setRowFixedHeight) + Q_PROPERTY(int columnPreferredWidth READ columnPreferredWidth WRITE setColumnPreferredWidth) + Q_PROPERTY(int columnMaximumWidth READ columnMaximumWidth WRITE setColumnMaximumWidth) + Q_PROPERTY(int columnMinimumWidth READ columnMinimumWidth WRITE setColumnMinimumWidth) + Q_PROPERTY(int columnFixedWidth READ columnFixedWidth WRITE setColumnFixedWidth) + +public: + GridLayoutAttached(QObject *parent); + + int row() const { return _row; } + void setRow(int r); + + int column() const { return _column; } + void setColumn(int c); + + int rowSpan() const { return _rowspan; } + void setRowSpan(int rs); + + int columnSpan() const { return _colspan; } + void setColumnSpan(int cs); + + Qt::Alignment alignment() const { return _alignment; } + void setAlignment(Qt::Alignment a); + + int rowStretchFactor() const { return _rowstretch; } + void setRowStretchFactor(int f); + int columnStretchFactor() const { return _colstretch; } + void setColumnStretchFactor(int f); + + int rowSpacing() const { return _rowspacing; } + void setRowSpacing(int s); + int columnSpacing() const { return _colspacing; } + void setColumnSpacing(int s); + + int rowPreferredHeight() const { return _rowprefheight; } + void setRowPreferredHeight(int s) { _rowprefheight = s; } + + int rowMaximumHeight() const { return _rowmaxheight; } + void setRowMaximumHeight(int s) { _rowmaxheight = s; } + + int rowMinimumHeight() const { return _rowminheight; } + void setRowMinimumHeight(int s) { _rowminheight = s; } + + int rowFixedHeight() const { return _rowfixheight; } + void setRowFixedHeight(int s) { _rowfixheight = s; } + + int columnPreferredWidth() const { return _colprefwidth; } + void setColumnPreferredWidth(int s) { _colprefwidth = s; } + + int columnMaximumWidth() const { return _colmaxwidth; } + void setColumnMaximumWidth(int s) { _colmaxwidth = s; } + + int columnMinimumWidth() const { return _colminwidth; } + void setColumnMinimumWidth(int s) { _colminwidth = s; } + + int columnFixedWidth() const { return _colfixwidth; } + void setColumnFixedWidth(int s) { _colfixwidth = s; } + +Q_SIGNALS: + void alignmentChanged(QGraphicsLayoutItem*,Qt::Alignment); + +private: + int _row; + int _column; + int _rowspan; + int _colspan; + Qt::Alignment _alignment; + int _rowstretch; + int _colstretch; + int _rowspacing; + int _colspacing; + int _rowprefheight; + int _rowmaxheight; + int _rowminheight; + int _rowfixheight; + int _colprefwidth; + int _colmaxwidth; + int _colminwidth; + int _colfixwidth; +}; + +QT_END_NAMESPACE + +QML_DECLARE_INTERFACE(QGraphicsLayoutItem) +QML_DECLARE_INTERFACE(QGraphicsLayout) +QML_DECLARE_TYPE(QGraphicsLinearLayoutStretchItemObject) +QML_DECLARE_TYPE(QGraphicsLinearLayoutObject) +QML_DECLARE_TYPEINFO(QGraphicsLinearLayoutObject, QML_HAS_ATTACHED_PROPERTIES) +QML_DECLARE_TYPE(QGraphicsGridLayoutObject) +QML_DECLARE_TYPEINFO(QGraphicsGridLayoutObject, QML_HAS_ATTACHED_PROPERTIES) + +QT_END_HEADER + +#endif // GRAPHICSLAYOUTS_H diff --git a/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/main.cpp b/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/main.cpp new file mode 100644 index 0000000..89b69bf --- /dev/null +++ b/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/main.cpp @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** 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 plugins 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 <QApplication> +#include <QtDeclarative/qdeclarative.h> +#include "graphicslayouts_p.h" +#include <QtDeclarative/QDeclarativeView> + +int main(int argc, char* argv[]) +{ + QApplication app(argc, argv); + QDeclarativeView view; + qmlRegisterInterface<QGraphicsLayoutItem>("QGraphicsLayoutItem"); + qmlRegisterInterface<QGraphicsLayout>("QGraphicsLayout"); + qmlRegisterType<QGraphicsLinearLayoutStretchItemObject>("GraphicsLayouts",4,7,"QGraphicsLinearLayoutStretchItem"); + qmlRegisterType<QGraphicsLinearLayoutObject>("GraphicsLayouts",4,7,"QGraphicsLinearLayout"); + qmlRegisterType<QGraphicsGridLayoutObject>("GraphicsLayouts",4,7,"QGraphicsGridLayout"); + view.setSource(QUrl(":graphicslayouts.qml")); + view.show(); + return app.exec(); +}; + diff --git a/examples/declarative/cppextensions/qgraphicslayouts/layoutItem/layoutItem.pro b/examples/declarative/cppextensions/qgraphicslayouts/layoutItem/layoutItem.pro new file mode 100644 index 0000000..4a3fc73 --- /dev/null +++ b/examples/declarative/cppextensions/qgraphicslayouts/layoutItem/layoutItem.pro @@ -0,0 +1,13 @@ +###################################################################### +# Automatically generated by qmake (2.01a) Tue May 4 13:36:26 2010 +###################################################################### + +TEMPLATE = app +TARGET = +DEPENDPATH += . +INCLUDEPATH += . +QT += declarative + +# Input +SOURCES += main.cpp +RESOURCES += layoutItem.qrc diff --git a/examples/declarative/cppextensions/qgraphicslayouts/layoutItem/layoutItem.qml b/examples/declarative/cppextensions/qgraphicslayouts/layoutItem/layoutItem.qml new file mode 100644 index 0000000..460c564 --- /dev/null +++ b/examples/declarative/cppextensions/qgraphicslayouts/layoutItem/layoutItem.qml @@ -0,0 +1,15 @@ +import Qt 4.7 + +LayoutItem {//Sized by the layout + id: resizable + minimumSize: "100x100" + maximumSize: "300x300" + preferredSize: "100x100" + Rectangle { color: "yellow"; anchors.fill: parent } + Rectangle { + width: 100; height: 100; + anchors.top: parent.top; + anchors.right: parent.right; + color: "green"; + } +} diff --git a/examples/declarative/cppextensions/qgraphicslayouts/layoutItem/layoutItem.qrc b/examples/declarative/cppextensions/qgraphicslayouts/layoutItem/layoutItem.qrc new file mode 100644 index 0000000..deb0fba --- /dev/null +++ b/examples/declarative/cppextensions/qgraphicslayouts/layoutItem/layoutItem.qrc @@ -0,0 +1,5 @@ +<!DOCTYPE RCC><RCC version="1.0"> +<qresource> + <file>layoutItem.qml</file> +</qresource> +</RCC> diff --git a/examples/declarative/cppextensions/qgraphicslayouts/layoutItem/main.cpp b/examples/declarative/cppextensions/qgraphicslayouts/layoutItem/main.cpp new file mode 100644 index 0000000..a104251 --- /dev/null +++ b/examples/declarative/cppextensions/qgraphicslayouts/layoutItem/main.cpp @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 <QApplication> +#include <QGraphicsView> +#include <QGraphicsScene> +#include <QGraphicsWidget> +#include <QGraphicsLinearLayout> +#include <QDeclarativeComponent> +#include <QDeclarativeEngine> + +/* This example demonstrates using a LayoutItem to let QML snippets integrate + nicely with existing QGraphicsView applications designed with GraphicsLayouts +*/ +int main(int argc, char* argv[]) +{ + QApplication app(argc, argv); + //Set up a graphics scene with a QGraphicsWidget and Layout + QGraphicsView view; + QGraphicsScene scene; + QGraphicsWidget *widget = new QGraphicsWidget(); + QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(); + widget->setLayout(layout); + scene.addItem(widget); + view.setScene(&scene); + //Add the QML snippet into the layout + QDeclarativeEngine engine; + QDeclarativeComponent c(&engine, QUrl(":layoutItem.qml")); + QGraphicsLayoutItem* obj = qobject_cast<QGraphicsLayoutItem*>(c.create()); + layout->addItem(obj); + + widget->setGeometry(QRectF(0,0, 400,400)); + view.show(); + return app.exec(); +} diff --git a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslayouts.qmlproject b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslayouts.qmlproject new file mode 100644 index 0000000..d4909f8 --- /dev/null +++ b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslayouts.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 " ] +} diff --git a/examples/declarative/cppextensions/referenceexamples/adding/adding.pro b/examples/declarative/cppextensions/referenceexamples/adding/adding.pro new file mode 100644 index 0000000..6072de4 --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/adding/adding.pro @@ -0,0 +1,15 @@ +TEMPLATE = app +TARGET = adding +DEPENDPATH += . +INCLUDEPATH += . +QT += declarative + +# Input +SOURCES += main.cpp \ + person.cpp +HEADERS += person.h +RESOURCES += adding.qrc +target.path = $$[QT_INSTALL_EXAMPLES]/declarative/extending/adding +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS adding.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/declarative/extending/adding +INSTALLS += target sources diff --git a/examples/declarative/cppextensions/referenceexamples/adding/adding.qrc b/examples/declarative/cppextensions/referenceexamples/adding/adding.qrc new file mode 100644 index 0000000..e2fa01d --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/adding/adding.qrc @@ -0,0 +1,5 @@ +<!DOCTYPE RCC><RCC version="1.0"> +<qresource> + <file>example.qml</file> +</qresource> +</RCC> diff --git a/examples/declarative/cppextensions/referenceexamples/adding/example.qml b/examples/declarative/cppextensions/referenceexamples/adding/example.qml new file mode 100644 index 0000000..dc891e7 --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/adding/example.qml @@ -0,0 +1,8 @@ +// ![0] +import People 1.0 + +Person { + name: "Bob Jones" + shoeSize: 12 +} +// ![0] diff --git a/examples/declarative/cppextensions/referenceexamples/adding/main.cpp b/examples/declarative/cppextensions/referenceexamples/adding/main.cpp new file mode 100644 index 0000000..7b33895 --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/adding/main.cpp @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 <QCoreApplication> +#include <QDeclarativeEngine> +#include <QDeclarativeComponent> +#include <QDebug> +#include "person.h" + +int main(int argc, char ** argv) +{ + QCoreApplication app(argc, argv); +//![0] + qmlRegisterType<Person>("People", 1,0, "Person"); +//![0] + + QDeclarativeEngine engine; + QDeclarativeComponent component(&engine, ":example.qml"); + Person *person = qobject_cast<Person *>(component.create()); + if (person) { + qWarning() << "The person's name is" << person->name(); + qWarning() << "They wear a" << person->shoeSize() << "sized shoe"; + } else { + qWarning() << "An error occured"; + } + + return 0; +} diff --git a/examples/declarative/cppextensions/referenceexamples/adding/person.cpp b/examples/declarative/cppextensions/referenceexamples/adding/person.cpp new file mode 100644 index 0000000..cdf08e0 --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/adding/person.cpp @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 "person.h" + +// ![0] +Person::Person(QObject *parent) +: QObject(parent), m_shoeSize(0) +{ +} + +QString Person::name() const +{ + return m_name; +} + +void Person::setName(const QString &n) +{ + m_name = n; +} + +int Person::shoeSize() const +{ + return m_shoeSize; +} + +void Person::setShoeSize(int s) +{ + m_shoeSize = s; +} + +// ![0] diff --git a/examples/declarative/cppextensions/referenceexamples/adding/person.h b/examples/declarative/cppextensions/referenceexamples/adding/person.h new file mode 100644 index 0000000..d6de9a9 --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/adding/person.h @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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$ +** +****************************************************************************/ +#ifndef PERSON_H +#define PERSON_H + +#include <QObject> +// ![0] +class Person : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString name READ name WRITE setName) + Q_PROPERTY(int shoeSize READ shoeSize WRITE setShoeSize) +public: + Person(QObject *parent = 0); + + QString name() const; + void setName(const QString &); + + int shoeSize() const; + void setShoeSize(int); + +private: + QString m_name; + int m_shoeSize; +}; +// ![0] + +#endif // PERSON_H diff --git a/examples/declarative/cppextensions/referenceexamples/attached/attached.pro b/examples/declarative/cppextensions/referenceexamples/attached/attached.pro new file mode 100644 index 0000000..f6d76ed --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/attached/attached.pro @@ -0,0 +1,17 @@ +TEMPLATE = app +TARGET = attached +DEPENDPATH += . +INCLUDEPATH += . +QT += declarative + +# Input +SOURCES += main.cpp \ + person.cpp \ + birthdayparty.cpp +HEADERS += person.h \ + birthdayparty.h +RESOURCES += attached.qrc +target.path = $$[QT_INSTALL_EXAMPLES]/declarative/extending/attached +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS attached.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/declarative/extending/attached +INSTALLS += target sources diff --git a/examples/declarative/cppextensions/referenceexamples/attached/attached.qrc b/examples/declarative/cppextensions/referenceexamples/attached/attached.qrc new file mode 100644 index 0000000..e2fa01d --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/attached/attached.qrc @@ -0,0 +1,5 @@ +<!DOCTYPE RCC><RCC version="1.0"> +<qresource> + <file>example.qml</file> +</qresource> +</RCC> diff --git a/examples/declarative/cppextensions/referenceexamples/attached/birthdayparty.cpp b/examples/declarative/cppextensions/referenceexamples/attached/birthdayparty.cpp new file mode 100644 index 0000000..7fa1748 --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/attached/birthdayparty.cpp @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 "birthdayparty.h" + +BirthdayPartyAttached::BirthdayPartyAttached(QObject *object) +: QObject(object) +{ +} + +QDate BirthdayPartyAttached::rsvp() const +{ + return m_rsvp; +} + +void BirthdayPartyAttached::setRsvp(const QDate &d) +{ + m_rsvp = d; +} + +BirthdayParty::BirthdayParty(QObject *parent) +: QObject(parent), m_host(0) +{ +} + +Person *BirthdayParty::host() const +{ + return m_host; +} + +void BirthdayParty::setHost(Person *c) +{ + m_host = c; +} + +QDeclarativeListProperty<Person> BirthdayParty::guests() +{ + return QDeclarativeListProperty<Person>(this, m_guests); +} + +int BirthdayParty::guestCount() const +{ + return m_guests.count(); +} + +Person *BirthdayParty::guest(int index) const +{ + return m_guests.at(index); +} + +BirthdayPartyAttached *BirthdayParty::qmlAttachedProperties(QObject *object) +{ + return new BirthdayPartyAttached(object); +} + diff --git a/examples/declarative/cppextensions/referenceexamples/attached/birthdayparty.h b/examples/declarative/cppextensions/referenceexamples/attached/birthdayparty.h new file mode 100644 index 0000000..1c66f8c --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/attached/birthdayparty.h @@ -0,0 +1,87 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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$ +** +****************************************************************************/ +#ifndef BIRTHDAYPARTY_H +#define BIRTHDAYPARTY_H + +#include <QObject> +#include <QDate> +#include <qdeclarative.h> +#include "person.h" + +class BirthdayPartyAttached : public QObject +{ + Q_OBJECT + Q_PROPERTY(QDate rsvp READ rsvp WRITE setRsvp) +public: + BirthdayPartyAttached(QObject *object); + + QDate rsvp() const; + void setRsvp(const QDate &); + +private: + QDate m_rsvp; +}; + +class BirthdayParty : public QObject +{ + Q_OBJECT + Q_PROPERTY(Person *host READ host WRITE setHost) + Q_PROPERTY(QDeclarativeListProperty<Person> guests READ guests) + Q_CLASSINFO("DefaultProperty", "guests") +public: + BirthdayParty(QObject *parent = 0); + + Person *host() const; + void setHost(Person *); + + QDeclarativeListProperty<Person> guests(); + int guestCount() const; + Person *guest(int) const; + + static BirthdayPartyAttached *qmlAttachedProperties(QObject *); +private: + Person *m_host; + QList<Person *> m_guests; +}; + +QML_DECLARE_TYPEINFO(BirthdayParty, QML_HAS_ATTACHED_PROPERTIES) + +#endif // BIRTHDAYPARTY_H diff --git a/examples/declarative/cppextensions/referenceexamples/attached/example.qml b/examples/declarative/cppextensions/referenceexamples/attached/example.qml new file mode 100644 index 0000000..50f0a32 --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/attached/example.qml @@ -0,0 +1,31 @@ +import People 1.0 + +BirthdayParty { + host: Boy { + name: "Bob Jones" + shoe { size: 12; color: "white"; brand: "Nike"; price: 90.0 } + } + + // ![1] + Boy { + name: "Leo Hodges" + shoe { size: 10; color: "black"; brand: "Reebok"; price: 59.95 } + + BirthdayParty.rsvp: "2009-07-06" + } + // ![1] + Boy { + name: "Jack Smith" + shoe { size: 8; color: "blue"; brand: "Puma"; price: 19.95 } + } + Girl { + name: "Anne Brown" + shoe.size: 7 + shoe.color: "red" + shoe.brand: "Marc Jacobs" + shoe.price: 699.99 + + BirthdayParty.rsvp: "2009-07-01" + } +} + diff --git a/examples/declarative/cppextensions/referenceexamples/attached/main.cpp b/examples/declarative/cppextensions/referenceexamples/attached/main.cpp new file mode 100644 index 0000000..f1055ae --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/attached/main.cpp @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 <QCoreApplication> +#include <QDeclarativeEngine> +#include <QDeclarativeComponent> +#include <QDebug> +#include "birthdayparty.h" +#include "person.h" + +int main(int argc, char ** argv) +{ + QCoreApplication app(argc, argv); + + qmlRegisterType<BirthdayPartyAttached>(); + qmlRegisterType<BirthdayParty>("People", 1,0, "BirthdayParty"); + qmlRegisterType<ShoeDescription>(); + qmlRegisterType<Person>(); + qmlRegisterType<Boy>("People", 1,0, "Boy"); + qmlRegisterType<Girl>("People", 1,0, "Girl"); + + QDeclarativeEngine engine; + QDeclarativeComponent component(&engine, ":example.qml"); + BirthdayParty *party = qobject_cast<BirthdayParty *>(component.create()); + + if (party && party->host()) { + qWarning() << party->host()->name() << "is having a birthday!"; + + if (qobject_cast<Boy *>(party->host())) + qWarning() << "He is inviting:"; + else + qWarning() << "She is inviting:"; + + for (int ii = 0; ii < party->guestCount(); ++ii) { + Person *guest = party->guest(ii); + + QDate rsvpDate; + QObject *attached = + qmlAttachedPropertiesObject<BirthdayParty>(guest, false); + if (attached) + rsvpDate = attached->property("rsvp").toDate(); + + if (rsvpDate.isNull()) + qWarning() << " " << guest->name() << "RSVP date: Hasn't RSVP'd"; + else + qWarning() << " " << guest->name() << "RSVP date:" << qPrintable(rsvpDate.toString()); + } + + } else { + qWarning() << "An error occured"; + } + + return 0; +} diff --git a/examples/declarative/cppextensions/referenceexamples/attached/person.cpp b/examples/declarative/cppextensions/referenceexamples/attached/person.cpp new file mode 100644 index 0000000..0a9e508 --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/attached/person.cpp @@ -0,0 +1,119 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 "person.h" + +ShoeDescription::ShoeDescription(QObject *parent) +: QObject(parent), m_size(0), m_price(0) +{ +} + +int ShoeDescription::size() const +{ + return m_size; +} + +void ShoeDescription::setSize(int s) +{ + m_size = s; +} + +QColor ShoeDescription::color() const +{ + return m_color; +} + +void ShoeDescription::setColor(const QColor &c) +{ + m_color = c; +} + +QString ShoeDescription::brand() const +{ + return m_brand; +} + +void ShoeDescription::setBrand(const QString &b) +{ + m_brand = b; +} + +qreal ShoeDescription::price() const +{ + return m_price; +} + +void ShoeDescription::setPrice(qreal p) +{ + m_price = p; +} + +Person::Person(QObject *parent) +: QObject(parent) +{ +} + +QString Person::name() const +{ + return m_name; +} + +void Person::setName(const QString &n) +{ + m_name = n; +} + +ShoeDescription *Person::shoe() +{ + return &m_shoe; +} + + +Boy::Boy(QObject * parent) +: Person(parent) +{ +} + + +Girl::Girl(QObject * parent) +: Person(parent) +{ +} + diff --git a/examples/declarative/cppextensions/referenceexamples/attached/person.h b/examples/declarative/cppextensions/referenceexamples/attached/person.h new file mode 100644 index 0000000..2f444c5 --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/attached/person.h @@ -0,0 +1,106 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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$ +** +****************************************************************************/ +#ifndef PERSON_H +#define PERSON_H + +#include <QObject> +#include <QColor> + +class ShoeDescription : public QObject +{ + Q_OBJECT + Q_PROPERTY(int size READ size WRITE setSize) + Q_PROPERTY(QColor color READ color WRITE setColor) + Q_PROPERTY(QString brand READ brand WRITE setBrand) + Q_PROPERTY(qreal price READ price WRITE setPrice) +public: + ShoeDescription(QObject *parent = 0); + + int size() const; + void setSize(int); + + QColor color() const; + void setColor(const QColor &); + + QString brand() const; + void setBrand(const QString &); + + qreal price() const; + void setPrice(qreal); +private: + int m_size; + QColor m_color; + QString m_brand; + qreal m_price; +}; + +class Person : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString name READ name WRITE setName) + Q_PROPERTY(ShoeDescription *shoe READ shoe) +public: + Person(QObject *parent = 0); + + QString name() const; + void setName(const QString &); + + ShoeDescription *shoe(); +private: + QString m_name; + ShoeDescription m_shoe; +}; + +class Boy : public Person +{ + Q_OBJECT +public: + Boy(QObject * parent = 0); +}; + +class Girl : public Person +{ + Q_OBJECT +public: + Girl(QObject * parent = 0); +}; + +#endif // PERSON_H diff --git a/examples/declarative/cppextensions/referenceexamples/binding/binding.pro b/examples/declarative/cppextensions/referenceexamples/binding/binding.pro new file mode 100644 index 0000000..896ce25 --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/binding/binding.pro @@ -0,0 +1,19 @@ +TEMPLATE = app +TARGET = binding +DEPENDPATH += . +INCLUDEPATH += . +QT += declarative + +# Input +SOURCES += main.cpp \ + person.cpp \ + birthdayparty.cpp \ + happybirthdaysong.cpp +HEADERS += person.h \ + birthdayparty.h \ + happybirthdaysong.h +RESOURCES += binding.qrc +target.path = $$[QT_INSTALL_EXAMPLES]/declarative/extending/binding +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS binding.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/declarative/extending/binding +INSTALLS += target sources diff --git a/examples/declarative/cppextensions/referenceexamples/binding/binding.qrc b/examples/declarative/cppextensions/referenceexamples/binding/binding.qrc new file mode 100644 index 0000000..e2fa01d --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/binding/binding.qrc @@ -0,0 +1,5 @@ +<!DOCTYPE RCC><RCC version="1.0"> +<qresource> + <file>example.qml</file> +</qresource> +</RCC> diff --git a/examples/declarative/cppextensions/referenceexamples/binding/birthdayparty.cpp b/examples/declarative/cppextensions/referenceexamples/binding/birthdayparty.cpp new file mode 100644 index 0000000..000bb1f --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/binding/birthdayparty.cpp @@ -0,0 +1,114 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 "birthdayparty.h" + +BirthdayPartyAttached::BirthdayPartyAttached(QObject *object) +: QObject(object) +{ +} + +QDate BirthdayPartyAttached::rsvp() const +{ + return m_rsvp; +} + +void BirthdayPartyAttached::setRsvp(const QDate &d) +{ + if (d != m_rsvp) { + m_rsvp = d; + emit rsvpChanged(); + } +} + + +BirthdayParty::BirthdayParty(QObject *parent) +: QObject(parent), m_host(0) +{ +} + +Person *BirthdayParty::host() const +{ + return m_host; +} + +void BirthdayParty::setHost(Person *c) +{ + if (c == m_host) return; + m_host = c; + emit hostChanged(); +} + +QDeclarativeListProperty<Person> BirthdayParty::guests() +{ + return QDeclarativeListProperty<Person>(this, m_guests); +} + +int BirthdayParty::guestCount() const +{ + return m_guests.count(); +} + +Person *BirthdayParty::guest(int index) const +{ + return m_guests.at(index); +} + +void BirthdayParty::startParty() +{ + QTime time = QTime::currentTime(); + emit partyStarted(time); +} + +QString BirthdayParty::announcement() const +{ + return QString(); +} + +void BirthdayParty::setAnnouncement(const QString &speak) +{ + qWarning() << qPrintable(speak); +} + +BirthdayPartyAttached *BirthdayParty::qmlAttachedProperties(QObject *object) +{ + return new BirthdayPartyAttached(object); +} + diff --git a/examples/declarative/cppextensions/referenceexamples/binding/birthdayparty.h b/examples/declarative/cppextensions/referenceexamples/binding/birthdayparty.h new file mode 100644 index 0000000..c3f033e --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/binding/birthdayparty.h @@ -0,0 +1,103 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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$ +** +****************************************************************************/ +#ifndef BIRTHDAYPARTY_H +#define BIRTHDAYPARTY_H + +#include <QObject> +#include <QDate> +#include <QDebug> +#include <qdeclarative.h> +#include "person.h" + +class BirthdayPartyAttached : public QObject +{ + Q_OBJECT + Q_PROPERTY(QDate rsvp READ rsvp WRITE setRsvp NOTIFY rsvpChanged) +public: + BirthdayPartyAttached(QObject *object); + + QDate rsvp() const; + void setRsvp(const QDate &); + +signals: + void rsvpChanged(); + +private: + QDate m_rsvp; +}; + +class BirthdayParty : public QObject +{ + Q_OBJECT +// ![0] + Q_PROPERTY(Person *host READ host WRITE setHost NOTIFY hostChanged) +// ![0] + Q_PROPERTY(QDeclarativeListProperty<Person> guests READ guests) + Q_PROPERTY(QString announcement READ announcement WRITE setAnnouncement) + Q_CLASSINFO("DefaultProperty", "guests") +public: + BirthdayParty(QObject *parent = 0); + + Person *host() const; + void setHost(Person *); + + QDeclarativeListProperty<Person> guests(); + int guestCount() const; + Person *guest(int) const; + + QString announcement() const; + void setAnnouncement(const QString &); + + static BirthdayPartyAttached *qmlAttachedProperties(QObject *); + + void startParty(); +signals: + void partyStarted(const QTime &time); + void hostChanged(); + +private: + Person *m_host; + QList<Person *> m_guests; +}; + +QML_DECLARE_TYPEINFO(BirthdayParty, QML_HAS_ATTACHED_PROPERTIES) + +#endif // BIRTHDAYPARTY_H diff --git a/examples/declarative/cppextensions/referenceexamples/binding/example.qml b/examples/declarative/cppextensions/referenceexamples/binding/example.qml new file mode 100644 index 0000000..82eb3be --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/binding/example.qml @@ -0,0 +1,37 @@ +import People 1.0 + +// ![0] +BirthdayParty { + id: theParty + + HappyBirthdaySong on announcement { name: theParty.host.name } + + host: Boy { + name: "Bob Jones" + shoe { size: 12; color: "white"; brand: "Nike"; price: 90.0 } + } +// ![0] + onPartyStarted: console.log("This party started rockin' at " + time); + + + Boy { + name: "Leo Hodges" + BirthdayParty.rsvp: "2009-07-06" + shoe { size: 10; color: "black"; brand: "Reebok"; price: 59.95 } + } + Boy { + name: "Jack Smith" + shoe { size: 8; color: "blue"; brand: "Puma"; price: 19.95 } + } + Girl { + name: "Anne Brown" + BirthdayParty.rsvp: "2009-07-01" + shoe.size: 7 + shoe.color: "red" + shoe.brand: "Marc Jacobs" + shoe.price: 699.99 + } + +// ![1] +} +// ![1] diff --git a/examples/declarative/cppextensions/referenceexamples/binding/happybirthdaysong.cpp b/examples/declarative/cppextensions/referenceexamples/binding/happybirthdaysong.cpp new file mode 100644 index 0000000..a40e7fb --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/binding/happybirthdaysong.cpp @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 "happybirthdaysong.h" +#include <QTimer> + +HappyBirthdaySong::HappyBirthdaySong(QObject *parent) +: QObject(parent), m_line(-1) +{ + setName(QString()); + QTimer *timer = new QTimer(this); + QObject::connect(timer, SIGNAL(timeout()), this, SLOT(advance())); + timer->start(1000); +} + +void HappyBirthdaySong::setTarget(const QDeclarativeProperty &p) +{ + m_target = p; +} + +QString HappyBirthdaySong::name() const +{ + return m_name; +} + +void HappyBirthdaySong::setName(const QString &name) +{ + if (m_name == name) + return; + + m_name = name; + + m_lyrics.clear(); + m_lyrics << "Happy birthday to you,"; + m_lyrics << "Happy birthday to you,"; + m_lyrics << "Happy birthday dear " + m_name + ","; + m_lyrics << "Happy birthday to you!"; + m_lyrics << ""; + + emit nameChanged(); +} + +void HappyBirthdaySong::advance() +{ + m_line = (m_line + 1) % m_lyrics.count(); + + m_target.write(m_lyrics.at(m_line)); +} + diff --git a/examples/declarative/cppextensions/referenceexamples/binding/happybirthdaysong.h b/examples/declarative/cppextensions/referenceexamples/binding/happybirthdaysong.h new file mode 100644 index 0000000..e825b86 --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/binding/happybirthdaysong.h @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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$ +** +****************************************************************************/ +#ifndef HAPPYBIRTHDAYSONG_H +#define HAPPYBIRTHDAYSONG_H + +#include <QDeclarativePropertyValueSource> +#include <QDeclarativeProperty> + +#include <QStringList> + +class HappyBirthdaySong : public QObject, public QDeclarativePropertyValueSource +{ + Q_OBJECT + Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) + Q_INTERFACES(QDeclarativePropertyValueSource) +public: + HappyBirthdaySong(QObject *parent = 0); + + virtual void setTarget(const QDeclarativeProperty &); + + QString name() const; + void setName(const QString &); + +private slots: + void advance(); + +signals: + void nameChanged(); +private: + int m_line; + QStringList m_lyrics; + QDeclarativeProperty m_target; + QString m_name; +}; + +#endif // HAPPYBIRTHDAYSONG_H + diff --git a/examples/declarative/cppextensions/referenceexamples/binding/main.cpp b/examples/declarative/cppextensions/referenceexamples/binding/main.cpp new file mode 100644 index 0000000..2495676 --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/binding/main.cpp @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 <QCoreApplication> +#include <QDeclarativeEngine> +#include <QDeclarativeComponent> +#include <QDebug> +#include "birthdayparty.h" +#include "happybirthdaysong.h" +#include "person.h" + +int main(int argc, char ** argv) +{ + QCoreApplication app(argc, argv); + qmlRegisterType<BirthdayPartyAttached>(); + qmlRegisterType<BirthdayParty>("People", 1,0, "BirthdayParty"); + qmlRegisterType<HappyBirthdaySong>("People", 1,0, "HappyBirthdaySong"); + qmlRegisterType<ShoeDescription>(); + qmlRegisterType<Person>(); + qmlRegisterType<Boy>("People", 1,0, "Boy"); + qmlRegisterType<Girl>("People", 1,0, "Girl"); + + QDeclarativeEngine engine; + QDeclarativeComponent component(&engine, ":example.qml"); + BirthdayParty *party = qobject_cast<BirthdayParty *>(component.create()); + + if (party && party->host()) { + qWarning() << party->host()->name() << "is having a birthday!"; + + if (qobject_cast<Boy *>(party->host())) + qWarning() << "He is inviting:"; + else + qWarning() << "She is inviting:"; + + for (int ii = 0; ii < party->guestCount(); ++ii) { + Person *guest = party->guest(ii); + + QDate rsvpDate; + QObject *attached = + qmlAttachedPropertiesObject<BirthdayParty>(guest, false); + if (attached) + rsvpDate = attached->property("rsvp").toDate(); + + if (rsvpDate.isNull()) + qWarning() << " " << guest->name() << "RSVP date: Hasn't RSVP'd"; + else + qWarning() << " " << guest->name() << "RSVP date:" << qPrintable(rsvpDate.toString()); + } + + party->startParty(); + } else { + qWarning() << "An error occured"; + } + + return app.exec(); +} diff --git a/examples/declarative/cppextensions/referenceexamples/binding/person.cpp b/examples/declarative/cppextensions/referenceexamples/binding/person.cpp new file mode 100644 index 0000000..9a2248f --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/binding/person.cpp @@ -0,0 +1,139 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 "person.h" + +ShoeDescription::ShoeDescription(QObject *parent) +: QObject(parent), m_size(0), m_price(0) +{ +} + +int ShoeDescription::size() const +{ + return m_size; +} + +void ShoeDescription::setSize(int s) +{ + if (m_size == s) + return; + + m_size = s; + emit shoeChanged(); +} + +QColor ShoeDescription::color() const +{ + return m_color; +} + +void ShoeDescription::setColor(const QColor &c) +{ + if (m_color == c) + return; + + m_color = c; + emit shoeChanged(); +} + +QString ShoeDescription::brand() const +{ + return m_brand; +} + +void ShoeDescription::setBrand(const QString &b) +{ + if (m_brand == b) + return; + + m_brand = b; + emit shoeChanged(); +} + +qreal ShoeDescription::price() const +{ + return m_price; +} + +void ShoeDescription::setPrice(qreal p) +{ + if (m_price == p) + return; + + m_price = p; + emit shoeChanged(); +} + +Person::Person(QObject *parent) +: QObject(parent) +{ +} + +QString Person::name() const +{ + return m_name; +} + +void Person::setName(const QString &n) +{ + if (m_name == n) + return; + + m_name = n; + emit nameChanged(); +} + +ShoeDescription *Person::shoe() +{ + return &m_shoe; +} + + +Boy::Boy(QObject * parent) +: Person(parent) +{ +} + + +Girl::Girl(QObject * parent) +: Person(parent) +{ +} + diff --git a/examples/declarative/cppextensions/referenceexamples/binding/person.h b/examples/declarative/cppextensions/referenceexamples/binding/person.h new file mode 100644 index 0000000..2a68da0 --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/binding/person.h @@ -0,0 +1,114 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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$ +** +****************************************************************************/ +#ifndef PERSON_H +#define PERSON_H + +#include <QObject> +#include <QColor> + +class ShoeDescription : public QObject +{ + Q_OBJECT + Q_PROPERTY(int size READ size WRITE setSize NOTIFY shoeChanged) + Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY shoeChanged) + Q_PROPERTY(QString brand READ brand WRITE setBrand NOTIFY shoeChanged) + Q_PROPERTY(qreal price READ price WRITE setPrice NOTIFY shoeChanged) +public: + ShoeDescription(QObject *parent = 0); + + int size() const; + void setSize(int); + + QColor color() const; + void setColor(const QColor &); + + QString brand() const; + void setBrand(const QString &); + + qreal price() const; + void setPrice(qreal); +signals: + void shoeChanged(); + +private: + int m_size; + QColor m_color; + QString m_brand; + qreal m_price; +}; + +class Person : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) +// ![0] + Q_PROPERTY(ShoeDescription *shoe READ shoe CONSTANT) +// ![0] +public: + Person(QObject *parent = 0); + + QString name() const; + void setName(const QString &); + + ShoeDescription *shoe(); +signals: + void nameChanged(); + +private: + QString m_name; + ShoeDescription m_shoe; +}; + +class Boy : public Person +{ + Q_OBJECT +public: + Boy(QObject * parent = 0); +}; + +class Girl : public Person +{ + Q_OBJECT +public: + Girl(QObject * parent = 0); +}; + +#endif // PERSON_H diff --git a/examples/declarative/cppextensions/referenceexamples/coercion/birthdayparty.cpp b/examples/declarative/cppextensions/referenceexamples/coercion/birthdayparty.cpp new file mode 100644 index 0000000..4f415a3 --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/coercion/birthdayparty.cpp @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 "birthdayparty.h" + +BirthdayParty::BirthdayParty(QObject *parent) +: QObject(parent), m_host(0) +{ +} + +Person *BirthdayParty::host() const +{ + return m_host; +} + +void BirthdayParty::setHost(Person *c) +{ + m_host = c; +} + +QDeclarativeListProperty<Person> BirthdayParty::guests() +{ + return QDeclarativeListProperty<Person>(this, m_guests); +} + +int BirthdayParty::guestCount() const +{ + return m_guests.count(); +} + +Person *BirthdayParty::guest(int index) const +{ + return m_guests.at(index); +} + diff --git a/examples/declarative/cppextensions/referenceexamples/coercion/birthdayparty.h b/examples/declarative/cppextensions/referenceexamples/coercion/birthdayparty.h new file mode 100644 index 0000000..ee77e9a --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/coercion/birthdayparty.h @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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$ +** +****************************************************************************/ +#ifndef BIRTHDAYPARTY_H +#define BIRTHDAYPARTY_H + +#include <QObject> +#include <QDeclarativeListProperty> +#include "person.h" + +class BirthdayParty : public QObject +{ + Q_OBJECT +// ![0] + Q_PROPERTY(Person *host READ host WRITE setHost) + Q_PROPERTY(QDeclarativeListProperty<Person> guests READ guests) +// ![0] +public: + BirthdayParty(QObject *parent = 0); + + Person *host() const; + void setHost(Person *); + + QDeclarativeListProperty<Person> guests(); + int guestCount() const; + Person *guest(int) const; + +private: + Person *m_host; + QList<Person *> m_guests; +}; + +#endif // BIRTHDAYPARTY_H diff --git a/examples/declarative/cppextensions/referenceexamples/coercion/coercion.pro b/examples/declarative/cppextensions/referenceexamples/coercion/coercion.pro new file mode 100644 index 0000000..c8daed8 --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/coercion/coercion.pro @@ -0,0 +1,17 @@ +TEMPLATE = app +TARGET = coercion +DEPENDPATH += . +INCLUDEPATH += . +QT += declarative + +# Input +SOURCES += main.cpp \ + person.cpp \ + birthdayparty.cpp +HEADERS += person.h \ + birthdayparty.h +RESOURCES += coercion.qrc +target.path = $$[QT_INSTALL_EXAMPLES]/declarative/extending/coercion +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS coercion.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/declarative/extending/coercion +INSTALLS += target sources diff --git a/examples/declarative/cppextensions/referenceexamples/coercion/coercion.qrc b/examples/declarative/cppextensions/referenceexamples/coercion/coercion.qrc new file mode 100644 index 0000000..e2fa01d --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/coercion/coercion.qrc @@ -0,0 +1,5 @@ +<!DOCTYPE RCC><RCC version="1.0"> +<qresource> + <file>example.qml</file> +</qresource> +</RCC> diff --git a/examples/declarative/cppextensions/referenceexamples/coercion/example.qml b/examples/declarative/cppextensions/referenceexamples/coercion/example.qml new file mode 100644 index 0000000..7b45950 --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/coercion/example.qml @@ -0,0 +1,15 @@ +import People 1.0 + +// ![0] +BirthdayParty { + host: Boy { + name: "Bob Jones" + shoeSize: 12 + } + guests: [ + Boy { name: "Leo Hodges" }, + Boy { name: "Jack Smith" }, + Girl { name: "Anne Brown" } + ] +} +// ![0] diff --git a/examples/declarative/cppextensions/referenceexamples/coercion/main.cpp b/examples/declarative/cppextensions/referenceexamples/coercion/main.cpp new file mode 100644 index 0000000..2c7b545 --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/coercion/main.cpp @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 <QCoreApplication> +#include <QDeclarativeEngine> +#include <QDeclarativeComponent> +#include <QDebug> +#include "birthdayparty.h" +#include "person.h" + +int main(int argc, char ** argv) +{ + QCoreApplication app(argc, argv); + + qmlRegisterType<BirthdayParty>("People", 1,0, "BirthdayParty"); +// ![0] + qmlRegisterType<Person>(); +// ![0] + qmlRegisterType<Boy>("People", 1,0, "Boy"); + qmlRegisterType<Girl>("People", 1,0, "Girl"); + + QDeclarativeEngine engine; + QDeclarativeComponent component(&engine, ":example.qml"); + BirthdayParty *party = qobject_cast<BirthdayParty *>(component.create()); + + if (party && party->host()) { + qWarning() << party->host()->name() << "is having a birthday!"; + + if (qobject_cast<Boy *>(party->host())) + qWarning() << "He is inviting:"; + else + qWarning() << "She is inviting:"; + + for (int ii = 0; ii < party->guestCount(); ++ii) + qWarning() << " " << party->guest(ii)->name(); + } else { + qWarning() << "An error occured"; + } + + return 0; +} diff --git a/examples/declarative/cppextensions/referenceexamples/coercion/person.cpp b/examples/declarative/cppextensions/referenceexamples/coercion/person.cpp new file mode 100644 index 0000000..5b5203a --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/coercion/person.cpp @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 "person.h" + +Person::Person(QObject *parent) +: QObject(parent), m_shoeSize(0) +{ +} + +QString Person::name() const +{ + return m_name; +} + +void Person::setName(const QString &n) +{ + m_name = n; +} + +int Person::shoeSize() const +{ + return m_shoeSize; +} + +void Person::setShoeSize(int s) +{ + m_shoeSize = s; +} + +// ![1] +Boy::Boy(QObject * parent) +: Person(parent) +{ +} + + +Girl::Girl(QObject * parent) +: Person(parent) +{ +} + +// ![1] diff --git a/examples/declarative/cppextensions/referenceexamples/coercion/person.h b/examples/declarative/cppextensions/referenceexamples/coercion/person.h new file mode 100644 index 0000000..1c95da7 --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/coercion/person.h @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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$ +** +****************************************************************************/ +#ifndef PERSON_H +#define PERSON_H + +#include <QObject> + +class Person : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString name READ name WRITE setName) + Q_PROPERTY(int shoeSize READ shoeSize WRITE setShoeSize) +public: + Person(QObject *parent = 0); + + QString name() const; + void setName(const QString &); + + int shoeSize() const; + void setShoeSize(int); +private: + QString m_name; + int m_shoeSize; +}; + + +// ![0] +class Boy : public Person +{ + Q_OBJECT +public: + Boy(QObject * parent = 0); +}; + + +class Girl : public Person +{ + Q_OBJECT +public: + Girl(QObject * parent = 0); +}; + +// ![0] + +#endif // PERSON_H diff --git a/examples/declarative/cppextensions/referenceexamples/default/birthdayparty.cpp b/examples/declarative/cppextensions/referenceexamples/default/birthdayparty.cpp new file mode 100644 index 0000000..4f415a3 --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/default/birthdayparty.cpp @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 "birthdayparty.h" + +BirthdayParty::BirthdayParty(QObject *parent) +: QObject(parent), m_host(0) +{ +} + +Person *BirthdayParty::host() const +{ + return m_host; +} + +void BirthdayParty::setHost(Person *c) +{ + m_host = c; +} + +QDeclarativeListProperty<Person> BirthdayParty::guests() +{ + return QDeclarativeListProperty<Person>(this, m_guests); +} + +int BirthdayParty::guestCount() const +{ + return m_guests.count(); +} + +Person *BirthdayParty::guest(int index) const +{ + return m_guests.at(index); +} + diff --git a/examples/declarative/cppextensions/referenceexamples/default/birthdayparty.h b/examples/declarative/cppextensions/referenceexamples/default/birthdayparty.h new file mode 100644 index 0000000..9741040 --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/default/birthdayparty.h @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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$ +** +****************************************************************************/ +#ifndef BIRTHDAYPARTY_H +#define BIRTHDAYPARTY_H + +#include <QObject> +#include <QDeclarativeListProperty> +#include "person.h" + +// ![0] +class BirthdayParty : public QObject +{ + Q_OBJECT + Q_PROPERTY(Person *host READ host WRITE setHost) + Q_PROPERTY(QDeclarativeListProperty<Person> guests READ guests) + Q_CLASSINFO("DefaultProperty", "guests") +public: + BirthdayParty(QObject *parent = 0); + + Person *host() const; + void setHost(Person *); + + QDeclarativeListProperty<Person> guests(); + int guestCount() const; + Person *guest(int) const; + +private: + Person *m_host; + QList<Person *> m_guests; +}; +// ![0] + +#endif // BIRTHDAYPARTY_H diff --git a/examples/declarative/cppextensions/referenceexamples/default/default.pro b/examples/declarative/cppextensions/referenceexamples/default/default.pro new file mode 100644 index 0000000..32aff0b --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/default/default.pro @@ -0,0 +1,17 @@ +TEMPLATE = app +TARGET = default +DEPENDPATH += . +INCLUDEPATH += . +QT += declarative + +# Input +SOURCES += main.cpp \ + person.cpp \ + birthdayparty.cpp +HEADERS += person.h \ + birthdayparty.h +RESOURCES += default.qrc +target.path = $$[QT_INSTALL_EXAMPLES]/declarative/extending/default +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS default.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/declarative/extending/default +INSTALLS += target sources diff --git a/examples/declarative/cppextensions/referenceexamples/default/default.qrc b/examples/declarative/cppextensions/referenceexamples/default/default.qrc new file mode 100644 index 0000000..e2fa01d --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/default/default.qrc @@ -0,0 +1,5 @@ +<!DOCTYPE RCC><RCC version="1.0"> +<qresource> + <file>example.qml</file> +</qresource> +</RCC> diff --git a/examples/declarative/cppextensions/referenceexamples/default/example.qml b/examples/declarative/cppextensions/referenceexamples/default/example.qml new file mode 100644 index 0000000..c0f3cbb --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/default/example.qml @@ -0,0 +1,14 @@ +import People 1.0 + +// ![0] +BirthdayParty { + host: Boy { + name: "Bob Jones" + shoeSize: 12 + } + + Boy { name: "Leo Hodges" } + Boy { name: "Jack Smith" } + Girl { name: "Anne Brown" } +} +// ![0] diff --git a/examples/declarative/cppextensions/referenceexamples/default/main.cpp b/examples/declarative/cppextensions/referenceexamples/default/main.cpp new file mode 100644 index 0000000..2ffd180 --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/default/main.cpp @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 <QCoreApplication> +#include <QDeclarativeEngine> +#include <QDeclarativeComponent> +#include <QDebug> +#include "birthdayparty.h" +#include "person.h" + +int main(int argc, char ** argv) +{ + QCoreApplication app(argc, argv); + + qmlRegisterType<BirthdayParty>("People", 1,0, "BirthdayParty"); + qmlRegisterType<Person>(); + qmlRegisterType<Boy>("People", 1,0, "Boy"); + qmlRegisterType<Girl>("People", 1,0, "Girl"); + + QDeclarativeEngine engine; + QDeclarativeComponent component(&engine, ":example.qml"); + BirthdayParty *party = qobject_cast<BirthdayParty *>(component.create()); + + if (party && party->host()) { + qWarning() << party->host()->name() << "is having a birthday!"; + + if (qobject_cast<Boy *>(party->host())) + qWarning() << "He is inviting:"; + else + qWarning() << "She is inviting:"; + + for (int ii = 0; ii < party->guestCount(); ++ii) + qWarning() << " " << party->guest(ii)->name(); + } else { + qWarning() << "An error occured"; + } + + return 0; +} diff --git a/examples/declarative/cppextensions/referenceexamples/default/person.cpp b/examples/declarative/cppextensions/referenceexamples/default/person.cpp new file mode 100644 index 0000000..69216d3 --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/default/person.cpp @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 "person.h" + +Person::Person(QObject *parent) +: QObject(parent), m_shoeSize(0) +{ +} + +QString Person::name() const +{ + return m_name; +} + +void Person::setName(const QString &n) +{ + m_name = n; +} + +int Person::shoeSize() const +{ + return m_shoeSize; +} + +void Person::setShoeSize(int s) +{ + m_shoeSize = s; +} + + +Boy::Boy(QObject * parent) +: Person(parent) +{ +} + + +Girl::Girl(QObject * parent) +: Person(parent) +{ +} + diff --git a/examples/declarative/cppextensions/referenceexamples/default/person.h b/examples/declarative/cppextensions/referenceexamples/default/person.h new file mode 100644 index 0000000..3e56860 --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/default/person.h @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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$ +** +****************************************************************************/ +#ifndef PERSON_H +#define PERSON_H + +#include <QObject> + +class Person : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString name READ name WRITE setName) + Q_PROPERTY(int shoeSize READ shoeSize WRITE setShoeSize) +public: + Person(QObject *parent = 0); + + QString name() const; + void setName(const QString &); + + int shoeSize() const; + void setShoeSize(int); +private: + QString m_name; + int m_shoeSize; +}; + +class Boy : public Person +{ + Q_OBJECT +public: + Boy(QObject * parent = 0); +}; + +class Girl : public Person +{ + Q_OBJECT +public: + Girl(QObject * parent = 0); +}; + +#endif // PERSON_H diff --git a/examples/declarative/cppextensions/referenceexamples/extended/example.qml b/examples/declarative/cppextensions/referenceexamples/extended/example.qml new file mode 100644 index 0000000..985ce20 --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/extended/example.qml @@ -0,0 +1,7 @@ +import People 1.0 + +// ![0] +QLineEdit { + leftMargin: 20 +} +// ![0] diff --git a/examples/declarative/cppextensions/referenceexamples/extended/extended.pro b/examples/declarative/cppextensions/referenceexamples/extended/extended.pro new file mode 100644 index 0000000..97af286 --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/extended/extended.pro @@ -0,0 +1,15 @@ +TEMPLATE = app +TARGET = extended +DEPENDPATH += . +INCLUDEPATH += . +QT += declarative + +# Input +SOURCES += main.cpp \ + lineedit.cpp +HEADERS += lineedit.h +RESOURCES += extended.qrc +target.path = $$[QT_INSTALL_EXAMPLES]/declarative/extending/extended +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS extended.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/declarative/extending/extended +INSTALLS += target sources diff --git a/examples/declarative/cppextensions/referenceexamples/extended/extended.qrc b/examples/declarative/cppextensions/referenceexamples/extended/extended.qrc new file mode 100644 index 0000000..e2fa01d --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/extended/extended.qrc @@ -0,0 +1,5 @@ +<!DOCTYPE RCC><RCC version="1.0"> +<qresource> + <file>example.qml</file> +</qresource> +</RCC> diff --git a/examples/declarative/cppextensions/referenceexamples/extended/lineedit.cpp b/examples/declarative/cppextensions/referenceexamples/extended/lineedit.cpp new file mode 100644 index 0000000..0e521ec --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/extended/lineedit.cpp @@ -0,0 +1,105 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 "lineedit.h" +#include <qdeclarative.h> + +LineEditExtension::LineEditExtension(QObject *object) +: QObject(object), m_lineedit(static_cast<QLineEdit *>(object)) +{ +} + +int LineEditExtension::leftMargin() const +{ + int l, r, t, b; + m_lineedit->getTextMargins(&l, &t, &r, &b); + return l; +} + +void LineEditExtension::setLeftMargin(int m) +{ + int l, r, t, b; + m_lineedit->getTextMargins(&l, &t, &r, &b); + m_lineedit->setTextMargins(m, t, r, b); +} + +int LineEditExtension::rightMargin() const +{ + int l, r, t, b; + m_lineedit->getTextMargins(&l, &t, &r, &b); + return r; +} + +void LineEditExtension::setRightMargin(int m) +{ + int l, r, t, b; + m_lineedit->getTextMargins(&l, &t, &r, &b); + m_lineedit->setTextMargins(l, t, m, b); +} + +int LineEditExtension::topMargin() const +{ + int l, r, t, b; + m_lineedit->getTextMargins(&l, &t, &r, &b); + return t; +} + +void LineEditExtension::setTopMargin(int m) +{ + int l, r, t, b; + m_lineedit->getTextMargins(&l, &t, &r, &b); + m_lineedit->setTextMargins(l, m, r, b); +} + +int LineEditExtension::bottomMargin() const +{ + int l, r, t, b; + m_lineedit->getTextMargins(&l, &t, &r, &b); + return b; +} + +void LineEditExtension::setBottomMargin(int m) +{ + int l, r, t, b; + m_lineedit->getTextMargins(&l, &t, &r, &b); + m_lineedit->setTextMargins(l, t, r, m); +} + + diff --git a/examples/declarative/cppextensions/referenceexamples/extended/lineedit.h b/examples/declarative/cppextensions/referenceexamples/extended/lineedit.h new file mode 100644 index 0000000..3a464b0 --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/extended/lineedit.h @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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$ +** +****************************************************************************/ +#ifndef LINEEDIT_H +#define LINEEDIT_H + +#include <QLineEdit> + +class LineEditExtension : public QObject +{ + Q_OBJECT + Q_PROPERTY(int leftMargin READ leftMargin WRITE setLeftMargin NOTIFY marginsChanged) + Q_PROPERTY(int rightMargin READ rightMargin WRITE setRightMargin NOTIFY marginsChanged) + Q_PROPERTY(int topMargin READ topMargin WRITE setTopMargin NOTIFY marginsChanged) + Q_PROPERTY(int bottomMargin READ bottomMargin WRITE setBottomMargin NOTIFY marginsChanged) +public: + LineEditExtension(QObject *); + + int leftMargin() const; + void setLeftMargin(int); + + int rightMargin() const; + void setRightMargin(int); + + int topMargin() const; + void setTopMargin(int); + + int bottomMargin() const; + void setBottomMargin(int); +signals: + void marginsChanged(); + +private: + QLineEdit *m_lineedit; +}; + +#endif // LINEEDIT_H diff --git a/examples/declarative/cppextensions/referenceexamples/extended/main.cpp b/examples/declarative/cppextensions/referenceexamples/extended/main.cpp new file mode 100644 index 0000000..ca7242d --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/extended/main.cpp @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 <QApplication> +#include <QDeclarativeEngine> +#include <QDeclarativeComponent> +#include <QDebug> +#include <QLineEdit> +#include "lineedit.h" + +int main(int argc, char ** argv) +{ + QApplication app(argc, argv); + + qmlRegisterExtendedType<QLineEdit, LineEditExtension>("People", 1,0, "QLineEdit"); + + QDeclarativeEngine engine; + QDeclarativeComponent component(&engine, ":example.qml"); + QLineEdit *edit = qobject_cast<QLineEdit *>(component.create()); + + if (edit) { + edit->show(); + return app.exec(); + } else { + qWarning() << "An error occured"; + return 0; + } +} diff --git a/examples/declarative/cppextensions/referenceexamples/grouped/birthdayparty.cpp b/examples/declarative/cppextensions/referenceexamples/grouped/birthdayparty.cpp new file mode 100644 index 0000000..4f415a3 --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/grouped/birthdayparty.cpp @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 "birthdayparty.h" + +BirthdayParty::BirthdayParty(QObject *parent) +: QObject(parent), m_host(0) +{ +} + +Person *BirthdayParty::host() const +{ + return m_host; +} + +void BirthdayParty::setHost(Person *c) +{ + m_host = c; +} + +QDeclarativeListProperty<Person> BirthdayParty::guests() +{ + return QDeclarativeListProperty<Person>(this, m_guests); +} + +int BirthdayParty::guestCount() const +{ + return m_guests.count(); +} + +Person *BirthdayParty::guest(int index) const +{ + return m_guests.at(index); +} + diff --git a/examples/declarative/cppextensions/referenceexamples/grouped/birthdayparty.h b/examples/declarative/cppextensions/referenceexamples/grouped/birthdayparty.h new file mode 100644 index 0000000..31d21b2 --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/grouped/birthdayparty.h @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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$ +** +****************************************************************************/ +#ifndef BIRTHDAYPARTY_H +#define BIRTHDAYPARTY_H + +#include <QObject> +#include <QDeclarativeListProperty> +#include "person.h" + +class BirthdayParty : public QObject +{ + Q_OBJECT + Q_PROPERTY(Person *host READ host WRITE setHost) + Q_PROPERTY(QDeclarativeListProperty<Person> guests READ guests) + Q_CLASSINFO("DefaultProperty", "guests") +public: + BirthdayParty(QObject *parent = 0); + + Person *host() const; + void setHost(Person *); + + QDeclarativeListProperty<Person> guests(); + int guestCount() const; + Person *guest(int) const; + +private: + Person *m_host; + QList<Person *> m_guests; +}; + + +#endif // BIRTHDAYPARTY_H diff --git a/examples/declarative/cppextensions/referenceexamples/grouped/example.qml b/examples/declarative/cppextensions/referenceexamples/grouped/example.qml new file mode 100644 index 0000000..91b7a06 --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/grouped/example.qml @@ -0,0 +1,33 @@ +import People 1.0 + +// ![0] +BirthdayParty { + host: Boy { + name: "Bob Jones" + shoe { size: 12; color: "white"; brand: "Nike"; price: 90.0 } + } + + Boy { + name: "Leo Hodges" + shoe { size: 10; color: "black"; brand: "Reebok"; price: 59.95 } + } + // ![1] + Boy { + name: "Jack Smith" + shoe { + size: 8 + color: "blue" + brand: "Puma" + price: 19.95 + } + } + // ![1] + Girl { + name: "Anne Brown" + shoe.size: 7 + shoe.color: "red" + shoe.brand: "Marc Jacobs" + shoe.price: 699.99 + } +} +// ![0] diff --git a/examples/declarative/cppextensions/referenceexamples/grouped/grouped.pro b/examples/declarative/cppextensions/referenceexamples/grouped/grouped.pro new file mode 100644 index 0000000..576e1d2 --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/grouped/grouped.pro @@ -0,0 +1,17 @@ +TEMPLATE = app +TARGET = grouped +DEPENDPATH += . +INCLUDEPATH += . +QT += declarative + +# Input +SOURCES += main.cpp \ + person.cpp \ + birthdayparty.cpp +HEADERS += person.h \ + birthdayparty.h +RESOURCES += grouped.qrc +target.path = $$[QT_INSTALL_EXAMPLES]/declarative/extending/grouped +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS grouped.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/declarative/extending/grouped +INSTALLS += target sources diff --git a/examples/declarative/cppextensions/referenceexamples/grouped/grouped.qrc b/examples/declarative/cppextensions/referenceexamples/grouped/grouped.qrc new file mode 100644 index 0000000..e2fa01d --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/grouped/grouped.qrc @@ -0,0 +1,5 @@ +<!DOCTYPE RCC><RCC version="1.0"> +<qresource> + <file>example.qml</file> +</qresource> +</RCC> diff --git a/examples/declarative/cppextensions/referenceexamples/grouped/main.cpp b/examples/declarative/cppextensions/referenceexamples/grouped/main.cpp new file mode 100644 index 0000000..baf32cf --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/grouped/main.cpp @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 <QCoreApplication> +#include <QDeclarativeEngine> +#include <QDeclarativeComponent> +#include <QDebug> +#include "birthdayparty.h" +#include "person.h" + +int main(int argc, char ** argv) +{ + QCoreApplication app(argc, argv); + + qmlRegisterType<BirthdayParty>("People", 1,0, "BirthdayParty"); + qmlRegisterType<ShoeDescription>(); + qmlRegisterType<Person>(); + qmlRegisterType<Boy>("People", 1,0, "Boy"); + qmlRegisterType<Girl>("People", 1,0, "Girl"); + + QDeclarativeEngine engine; + QDeclarativeComponent component(&engine, ":example.qml"); + BirthdayParty *party = qobject_cast<BirthdayParty *>(component.create()); + + if (party && party->host()) { + qWarning() << party->host()->name() << "is having a birthday!"; + + if (qobject_cast<Boy *>(party->host())) + qWarning() << "He is inviting:"; + else + qWarning() << "She is inviting:"; + + Person *bestShoe = 0; + for (int ii = 0; ii < party->guestCount(); ++ii) { + Person *guest = party->guest(ii); + qWarning() << " " << guest->name(); + + if (!bestShoe || bestShoe->shoe()->price() < guest->shoe()->price()) + bestShoe = guest; + } + if (bestShoe) + qWarning() << bestShoe->name() << "is wearing the best shoes!"; + + } else { + qWarning() << "An error occured"; + } + + return 0; +} diff --git a/examples/declarative/cppextensions/referenceexamples/grouped/person.cpp b/examples/declarative/cppextensions/referenceexamples/grouped/person.cpp new file mode 100644 index 0000000..0a9e508 --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/grouped/person.cpp @@ -0,0 +1,119 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 "person.h" + +ShoeDescription::ShoeDescription(QObject *parent) +: QObject(parent), m_size(0), m_price(0) +{ +} + +int ShoeDescription::size() const +{ + return m_size; +} + +void ShoeDescription::setSize(int s) +{ + m_size = s; +} + +QColor ShoeDescription::color() const +{ + return m_color; +} + +void ShoeDescription::setColor(const QColor &c) +{ + m_color = c; +} + +QString ShoeDescription::brand() const +{ + return m_brand; +} + +void ShoeDescription::setBrand(const QString &b) +{ + m_brand = b; +} + +qreal ShoeDescription::price() const +{ + return m_price; +} + +void ShoeDescription::setPrice(qreal p) +{ + m_price = p; +} + +Person::Person(QObject *parent) +: QObject(parent) +{ +} + +QString Person::name() const +{ + return m_name; +} + +void Person::setName(const QString &n) +{ + m_name = n; +} + +ShoeDescription *Person::shoe() +{ + return &m_shoe; +} + + +Boy::Boy(QObject * parent) +: Person(parent) +{ +} + + +Girl::Girl(QObject * parent) +: Person(parent) +{ +} + diff --git a/examples/declarative/cppextensions/referenceexamples/grouped/person.h b/examples/declarative/cppextensions/referenceexamples/grouped/person.h new file mode 100644 index 0000000..a031e69 --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/grouped/person.h @@ -0,0 +1,108 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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$ +** +****************************************************************************/ +#ifndef PERSON_H +#define PERSON_H + +#include <QObject> +#include <QColor> + +class ShoeDescription : public QObject +{ + Q_OBJECT + Q_PROPERTY(int size READ size WRITE setSize) + Q_PROPERTY(QColor color READ color WRITE setColor) + Q_PROPERTY(QString brand READ brand WRITE setBrand) + Q_PROPERTY(qreal price READ price WRITE setPrice) +public: + ShoeDescription(QObject *parent = 0); + + int size() const; + void setSize(int); + + QColor color() const; + void setColor(const QColor &); + + QString brand() const; + void setBrand(const QString &); + + qreal price() const; + void setPrice(qreal); +private: + int m_size; + QColor m_color; + QString m_brand; + qreal m_price; +}; + +class Person : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString name READ name WRITE setName) +// ![1] + Q_PROPERTY(ShoeDescription *shoe READ shoe) +// ![1] +public: + Person(QObject *parent = 0); + + QString name() const; + void setName(const QString &); + + ShoeDescription *shoe(); +private: + QString m_name; + ShoeDescription m_shoe; +}; + +class Boy : public Person +{ + Q_OBJECT +public: + Boy(QObject * parent = 0); +}; + +class Girl : public Person +{ + Q_OBJECT +public: + Girl(QObject * parent = 0); +}; + +#endif // PERSON_H diff --git a/examples/declarative/cppextensions/referenceexamples/properties/birthdayparty.cpp b/examples/declarative/cppextensions/referenceexamples/properties/birthdayparty.cpp new file mode 100644 index 0000000..27d17a1 --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/properties/birthdayparty.cpp @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 "birthdayparty.h" + +BirthdayParty::BirthdayParty(QObject *parent) +: QObject(parent), m_host(0) +{ +} + +// ![0] +Person *BirthdayParty::host() const +{ + return m_host; +} + +void BirthdayParty::setHost(Person *c) +{ + m_host = c; +} + +QDeclarativeListProperty<Person> BirthdayParty::guests() +{ + return QDeclarativeListProperty<Person>(this, m_guests); +} + +int BirthdayParty::guestCount() const +{ + return m_guests.count(); +} + +Person *BirthdayParty::guest(int index) const +{ + return m_guests.at(index); +} +// ![0] + diff --git a/examples/declarative/cppextensions/referenceexamples/properties/birthdayparty.h b/examples/declarative/cppextensions/referenceexamples/properties/birthdayparty.h new file mode 100644 index 0000000..39ce9ba --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/properties/birthdayparty.h @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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$ +** +****************************************************************************/ +#ifndef BIRTHDAYPARTY_H +#define BIRTHDAYPARTY_H + +#include <QObject> +#include <QDeclarativeListProperty> +#include "person.h" + +// ![0] +class BirthdayParty : public QObject +{ + Q_OBJECT +// ![0] +// ![1] + Q_PROPERTY(Person *host READ host WRITE setHost) +// ![1] +// ![2] + Q_PROPERTY(QDeclarativeListProperty<Person> guests READ guests) +// ![2] +// ![3] +public: + BirthdayParty(QObject *parent = 0); + + Person *host() const; + void setHost(Person *); + + QDeclarativeListProperty<Person> guests(); + int guestCount() const; + Person *guest(int) const; + +private: + Person *m_host; + QList<Person *> m_guests; +}; +// ![3] + +#endif // BIRTHDAYPARTY_H diff --git a/examples/declarative/cppextensions/referenceexamples/properties/example.qml b/examples/declarative/cppextensions/referenceexamples/properties/example.qml new file mode 100644 index 0000000..35abdd6 --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/properties/example.qml @@ -0,0 +1,15 @@ +import People 1.0 + +// ![0] +BirthdayParty { + host: Person { + name: "Bob Jones" + shoeSize: 12 + } + guests: [ + Person { name: "Leo Hodges" }, + Person { name: "Jack Smith" }, + Person { name: "Anne Brown" } + ] +} +// ![0] diff --git a/examples/declarative/cppextensions/referenceexamples/properties/main.cpp b/examples/declarative/cppextensions/referenceexamples/properties/main.cpp new file mode 100644 index 0000000..85e9584 --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/properties/main.cpp @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 <QCoreApplication> +#include <QDeclarativeEngine> +#include <QDeclarativeComponent> +#include <QDebug> +#include "birthdayparty.h" +#include "person.h" + +int main(int argc, char ** argv) +{ + QCoreApplication app(argc, argv); + + qmlRegisterType<BirthdayParty>("People", 1,0, "BirthdayParty"); + qmlRegisterType<Person>("People", 1,0, "Person"); + + QDeclarativeEngine engine; + QDeclarativeComponent component(&engine, ":example.qml"); + BirthdayParty *party = qobject_cast<BirthdayParty *>(component.create()); + + if (party && party->host()) { + qWarning() << party->host()->name() << "is having a birthday!"; + qWarning() << "They are inviting:"; + for (int ii = 0; ii < party->guestCount(); ++ii) + qWarning() << " " << party->guest(ii)->name(); + } else { + qWarning() << "An error occured"; + } + + return 0; +} diff --git a/examples/declarative/cppextensions/referenceexamples/properties/person.cpp b/examples/declarative/cppextensions/referenceexamples/properties/person.cpp new file mode 100644 index 0000000..92c54f5 --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/properties/person.cpp @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 "person.h" + +Person::Person(QObject *parent) +: QObject(parent), m_shoeSize(0) +{ +} + +QString Person::name() const +{ + return m_name; +} + +void Person::setName(const QString &n) +{ + m_name = n; +} + +int Person::shoeSize() const +{ + return m_shoeSize; +} + +void Person::setShoeSize(int s) +{ + m_shoeSize = s; +} + diff --git a/examples/declarative/cppextensions/referenceexamples/properties/person.h b/examples/declarative/cppextensions/referenceexamples/properties/person.h new file mode 100644 index 0000000..0029b09 --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/properties/person.h @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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$ +** +****************************************************************************/ +#ifndef PERSON_H +#define PERSON_H + +#include <QObject> + +class Person : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString name READ name WRITE setName) + Q_PROPERTY(int shoeSize READ shoeSize WRITE setShoeSize) +public: + Person(QObject *parent = 0); + + QString name() const; + void setName(const QString &); + + int shoeSize() const; + void setShoeSize(int); +private: + QString m_name; + int m_shoeSize; +}; + +#endif // PERSON_H diff --git a/examples/declarative/cppextensions/referenceexamples/properties/properties.pro b/examples/declarative/cppextensions/referenceexamples/properties/properties.pro new file mode 100644 index 0000000..a8f4301 --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/properties/properties.pro @@ -0,0 +1,18 @@ +TEMPLATE = app +TARGET = properties +DEPENDPATH += . +INCLUDEPATH += . +QT += declarative + +# Input +SOURCES += main.cpp \ + person.cpp \ + birthdayparty.cpp +HEADERS += person.h \ + birthdayparty.h +RESOURCES += properties.qrc + +target.path = $$[QT_INSTALL_EXAMPLES]/declarative/extending/properties +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS properties.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/declarative/extending/properties +INSTALLS += target sources diff --git a/examples/declarative/cppextensions/referenceexamples/properties/properties.qrc b/examples/declarative/cppextensions/referenceexamples/properties/properties.qrc new file mode 100644 index 0000000..e2fa01d --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/properties/properties.qrc @@ -0,0 +1,5 @@ +<!DOCTYPE RCC><RCC version="1.0"> +<qresource> + <file>example.qml</file> +</qresource> +</RCC> diff --git a/examples/declarative/cppextensions/referenceexamples/referenceexamples.pro b/examples/declarative/cppextensions/referenceexamples/referenceexamples.pro new file mode 100644 index 0000000..169c7ab --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/referenceexamples.pro @@ -0,0 +1,13 @@ +TEMPLATE = subdirs + +SUBDIRS += \ + adding \ + attached \ + binding \ + coercion \ + default \ + extended \ + grouped \ + properties \ + signal \ + valuesource diff --git a/examples/declarative/cppextensions/referenceexamples/referenceexamples.qmlproject b/examples/declarative/cppextensions/referenceexamples/referenceexamples.qmlproject new file mode 100644 index 0000000..d4909f8 --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/referenceexamples.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 " ] +} diff --git a/examples/declarative/cppextensions/referenceexamples/signal/birthdayparty.cpp b/examples/declarative/cppextensions/referenceexamples/signal/birthdayparty.cpp new file mode 100644 index 0000000..740c8c9 --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/signal/birthdayparty.cpp @@ -0,0 +1,99 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 "birthdayparty.h" + +BirthdayPartyAttached::BirthdayPartyAttached(QObject *object) +: QObject(object) +{ +} + +QDate BirthdayPartyAttached::rsvp() const +{ + return m_rsvp; +} + +void BirthdayPartyAttached::setRsvp(const QDate &d) +{ + m_rsvp = d; +} + + +BirthdayParty::BirthdayParty(QObject *parent) +: QObject(parent), m_host(0) +{ +} + +Person *BirthdayParty::host() const +{ + return m_host; +} + +void BirthdayParty::setHost(Person *c) +{ + m_host = c; +} + +QDeclarativeListProperty<Person> BirthdayParty::guests() +{ + return QDeclarativeListProperty<Person>(this, m_guests); +} + +int BirthdayParty::guestCount() const +{ + return m_guests.count(); +} + +Person *BirthdayParty::guest(int index) const +{ + return m_guests.at(index); +} + +void BirthdayParty::startParty() +{ + QTime time = QTime::currentTime(); + emit partyStarted(time); +} + +BirthdayPartyAttached *BirthdayParty::qmlAttachedProperties(QObject *object) +{ + return new BirthdayPartyAttached(object); +} + diff --git a/examples/declarative/cppextensions/referenceexamples/signal/birthdayparty.h b/examples/declarative/cppextensions/referenceexamples/signal/birthdayparty.h new file mode 100644 index 0000000..ae4dd39 --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/signal/birthdayparty.h @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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$ +** +****************************************************************************/ +#ifndef BIRTHDAYPARTY_H +#define BIRTHDAYPARTY_H + +#include <QObject> +#include <QDate> +#include <qdeclarative.h> +#include "person.h" + +class BirthdayPartyAttached : public QObject +{ + Q_OBJECT + Q_PROPERTY(QDate rsvp READ rsvp WRITE setRsvp) +public: + BirthdayPartyAttached(QObject *object); + + QDate rsvp() const; + void setRsvp(const QDate &); + +private: + QDate m_rsvp; +}; + +class BirthdayParty : public QObject +{ + Q_OBJECT + Q_PROPERTY(Person *host READ host WRITE setHost) + Q_PROPERTY(QDeclarativeListProperty<Person> guests READ guests) + Q_CLASSINFO("DefaultProperty", "guests") +public: + BirthdayParty(QObject *parent = 0); + + Person *host() const; + void setHost(Person *); + + QDeclarativeListProperty<Person> guests(); + int guestCount() const; + Person *guest(int) const; + + static BirthdayPartyAttached *qmlAttachedProperties(QObject *); + + void startParty(); +// ![0] +signals: + void partyStarted(const QTime &time); +// ![0] + +private: + Person *m_host; + QList<Person *> m_guests; +}; +QML_DECLARE_TYPEINFO(BirthdayParty, QML_HAS_ATTACHED_PROPERTIES) + +#endif // BIRTHDAYPARTY_H diff --git a/examples/declarative/cppextensions/referenceexamples/signal/example.qml b/examples/declarative/cppextensions/referenceexamples/signal/example.qml new file mode 100644 index 0000000..83d6a23 --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/signal/example.qml @@ -0,0 +1,32 @@ +import People 1.0 + +// ![0] +BirthdayParty { + onPartyStarted: console.log("This party started rockin' at " + time); +// ![0] + + host: Boy { + name: "Bob Jones" + shoe { size: 12; color: "white"; brand: "Nike"; price: 90.0 } + } + + Boy { + name: "Leo Hodges" + BirthdayParty.rsvp: "2009-07-06" + shoe { size: 10; color: "black"; brand: "Reebok"; price: 59.95 } + } + Boy { + name: "Jack Smith" + shoe { size: 8; color: "blue"; brand: "Puma"; price: 19.95 } + } + Girl { + name: "Anne Brown" + BirthdayParty.rsvp: "2009-07-01" + shoe.size: 7 + shoe.color: "red" + shoe.brand: "Marc Jacobs" + shoe.price: 699.99 + } +// ![1] +} +// ![1] diff --git a/examples/declarative/cppextensions/referenceexamples/signal/main.cpp b/examples/declarative/cppextensions/referenceexamples/signal/main.cpp new file mode 100644 index 0000000..453f688 --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/signal/main.cpp @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 <QCoreApplication> +#include <QDeclarativeEngine> +#include <QDeclarativeComponent> +#include <QDebug> +#include "birthdayparty.h" +#include "person.h" + +int main(int argc, char ** argv) +{ + QCoreApplication app(argc, argv); + + qmlRegisterType<BirthdayPartyAttached>(); + qmlRegisterType<BirthdayParty>("People", 1,0, "BirthdayParty"); + qmlRegisterType<ShoeDescription>(); + qmlRegisterType<Person>(); + qmlRegisterType<Boy>("People", 1,0, "Boy"); + qmlRegisterType<Girl>("People", 1,0, "Girl"); + + QDeclarativeEngine engine; + QDeclarativeComponent component(&engine, ":example.qml"); + BirthdayParty *party = qobject_cast<BirthdayParty *>(component.create()); + + if (party && party->host()) { + qWarning() << party->host()->name() << "is having a birthday!"; + + if (qobject_cast<Boy *>(party->host())) + qWarning() << "He is inviting:"; + else + qWarning() << "She is inviting:"; + + for (int ii = 0; ii < party->guestCount(); ++ii) { + Person *guest = party->guest(ii); + + QDate rsvpDate; + QObject *attached = + qmlAttachedPropertiesObject<BirthdayParty>(guest, false); + if (attached) + rsvpDate = attached->property("rsvp").toDate(); + + if (rsvpDate.isNull()) + qWarning() << " " << guest->name() << "RSVP date: Hasn't RSVP'd"; + else + qWarning() << " " << guest->name() << "RSVP date:" << qPrintable(rsvpDate.toString()); + } + + party->startParty(); + } else { + qWarning() << "An error occured"; + } + + return 0; +} diff --git a/examples/declarative/cppextensions/referenceexamples/signal/person.cpp b/examples/declarative/cppextensions/referenceexamples/signal/person.cpp new file mode 100644 index 0000000..0a9e508 --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/signal/person.cpp @@ -0,0 +1,119 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 "person.h" + +ShoeDescription::ShoeDescription(QObject *parent) +: QObject(parent), m_size(0), m_price(0) +{ +} + +int ShoeDescription::size() const +{ + return m_size; +} + +void ShoeDescription::setSize(int s) +{ + m_size = s; +} + +QColor ShoeDescription::color() const +{ + return m_color; +} + +void ShoeDescription::setColor(const QColor &c) +{ + m_color = c; +} + +QString ShoeDescription::brand() const +{ + return m_brand; +} + +void ShoeDescription::setBrand(const QString &b) +{ + m_brand = b; +} + +qreal ShoeDescription::price() const +{ + return m_price; +} + +void ShoeDescription::setPrice(qreal p) +{ + m_price = p; +} + +Person::Person(QObject *parent) +: QObject(parent) +{ +} + +QString Person::name() const +{ + return m_name; +} + +void Person::setName(const QString &n) +{ + m_name = n; +} + +ShoeDescription *Person::shoe() +{ + return &m_shoe; +} + + +Boy::Boy(QObject * parent) +: Person(parent) +{ +} + + +Girl::Girl(QObject * parent) +: Person(parent) +{ +} + diff --git a/examples/declarative/cppextensions/referenceexamples/signal/person.h b/examples/declarative/cppextensions/referenceexamples/signal/person.h new file mode 100644 index 0000000..2f444c5 --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/signal/person.h @@ -0,0 +1,106 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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$ +** +****************************************************************************/ +#ifndef PERSON_H +#define PERSON_H + +#include <QObject> +#include <QColor> + +class ShoeDescription : public QObject +{ + Q_OBJECT + Q_PROPERTY(int size READ size WRITE setSize) + Q_PROPERTY(QColor color READ color WRITE setColor) + Q_PROPERTY(QString brand READ brand WRITE setBrand) + Q_PROPERTY(qreal price READ price WRITE setPrice) +public: + ShoeDescription(QObject *parent = 0); + + int size() const; + void setSize(int); + + QColor color() const; + void setColor(const QColor &); + + QString brand() const; + void setBrand(const QString &); + + qreal price() const; + void setPrice(qreal); +private: + int m_size; + QColor m_color; + QString m_brand; + qreal m_price; +}; + +class Person : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString name READ name WRITE setName) + Q_PROPERTY(ShoeDescription *shoe READ shoe) +public: + Person(QObject *parent = 0); + + QString name() const; + void setName(const QString &); + + ShoeDescription *shoe(); +private: + QString m_name; + ShoeDescription m_shoe; +}; + +class Boy : public Person +{ + Q_OBJECT +public: + Boy(QObject * parent = 0); +}; + +class Girl : public Person +{ + Q_OBJECT +public: + Girl(QObject * parent = 0); +}; + +#endif // PERSON_H diff --git a/examples/declarative/cppextensions/referenceexamples/signal/signal.pro b/examples/declarative/cppextensions/referenceexamples/signal/signal.pro new file mode 100644 index 0000000..6367a38 --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/signal/signal.pro @@ -0,0 +1,17 @@ +TEMPLATE = app +TARGET = signal +DEPENDPATH += . +INCLUDEPATH += . +QT += declarative + +# Input +SOURCES += main.cpp \ + person.cpp \ + birthdayparty.cpp +HEADERS += person.h \ + birthdayparty.h +RESOURCES += signal.qrc +target.path = $$[QT_INSTALL_EXAMPLES]/declarative/extending/signal +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS signal.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/declarative/extending/signal +INSTALLS += target sources diff --git a/examples/declarative/cppextensions/referenceexamples/signal/signal.qrc b/examples/declarative/cppextensions/referenceexamples/signal/signal.qrc new file mode 100644 index 0000000..e2fa01d --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/signal/signal.qrc @@ -0,0 +1,5 @@ +<!DOCTYPE RCC><RCC version="1.0"> +<qresource> + <file>example.qml</file> +</qresource> +</RCC> diff --git a/examples/declarative/cppextensions/referenceexamples/valuesource/birthdayparty.cpp b/examples/declarative/cppextensions/referenceexamples/valuesource/birthdayparty.cpp new file mode 100644 index 0000000..b915f4f --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/valuesource/birthdayparty.cpp @@ -0,0 +1,109 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 "birthdayparty.h" + +BirthdayPartyAttached::BirthdayPartyAttached(QObject *object) +: QObject(object) +{ +} + +QDate BirthdayPartyAttached::rsvp() const +{ + return m_rsvp; +} + +void BirthdayPartyAttached::setRsvp(const QDate &d) +{ + m_rsvp = d; +} + + +BirthdayParty::BirthdayParty(QObject *parent) +: QObject(parent), m_host(0) +{ +} + +Person *BirthdayParty::host() const +{ + return m_host; +} + +void BirthdayParty::setHost(Person *c) +{ + m_host = c; +} + +QDeclarativeListProperty<Person> BirthdayParty::guests() +{ + return QDeclarativeListProperty<Person>(this, m_guests); +} + +int BirthdayParty::guestCount() const +{ + return m_guests.count(); +} + +Person *BirthdayParty::guest(int index) const +{ + return m_guests.at(index); +} + +void BirthdayParty::startParty() +{ + QTime time = QTime::currentTime(); + emit partyStarted(time); +} + +QString BirthdayParty::announcement() const +{ + return QString(); +} + +void BirthdayParty::setAnnouncement(const QString &speak) +{ + qWarning() << qPrintable(speak); +} + +BirthdayPartyAttached *BirthdayParty::qmlAttachedProperties(QObject *object) +{ + return new BirthdayPartyAttached(object); +} + diff --git a/examples/declarative/cppextensions/referenceexamples/valuesource/birthdayparty.h b/examples/declarative/cppextensions/referenceexamples/valuesource/birthdayparty.h new file mode 100644 index 0000000..5f25781 --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/valuesource/birthdayparty.h @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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$ +** +****************************************************************************/ +#ifndef BIRTHDAYPARTY_H +#define BIRTHDAYPARTY_H + +#include <QObject> +#include <QDate> +#include <QDebug> +#include <qdeclarative.h> +#include "person.h" + +class BirthdayPartyAttached : public QObject +{ + Q_OBJECT + Q_PROPERTY(QDate rsvp READ rsvp WRITE setRsvp) +public: + BirthdayPartyAttached(QObject *object); + + QDate rsvp() const; + void setRsvp(const QDate &); + +private: + QDate m_rsvp; +}; + +class BirthdayParty : public QObject +{ + Q_OBJECT + Q_PROPERTY(Person *host READ host WRITE setHost) + Q_PROPERTY(QDeclarativeListProperty<Person> guests READ guests) +// ![0] + Q_PROPERTY(QString announcement READ announcement WRITE setAnnouncement) +// ![0] + Q_CLASSINFO("DefaultProperty", "guests") +public: + BirthdayParty(QObject *parent = 0); + + Person *host() const; + void setHost(Person *); + + QDeclarativeListProperty<Person> guests(); + int guestCount() const; + Person *guest(int) const; + + QString announcement() const; + void setAnnouncement(const QString &); + + static BirthdayPartyAttached *qmlAttachedProperties(QObject *); + + void startParty(); +signals: + void partyStarted(const QTime &time); + +private: + Person *m_host; + QList<Person *> m_guests; +}; +QML_DECLARE_TYPEINFO(BirthdayParty, QML_HAS_ATTACHED_PROPERTIES) + +#endif // BIRTHDAYPARTY_H diff --git a/examples/declarative/cppextensions/referenceexamples/valuesource/example.qml b/examples/declarative/cppextensions/referenceexamples/valuesource/example.qml new file mode 100644 index 0000000..5b8c8af --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/valuesource/example.qml @@ -0,0 +1,36 @@ +import People 1.0 + +// ![0] +BirthdayParty { + HappyBirthdaySong on announcement { name: "Bob Jones" } +// ![0] + + onPartyStarted: console.log("This party started rockin' at " + time); + + + host: Boy { + name: "Bob Jones" + shoe { size: 12; color: "white"; brand: "Nike"; price: 90.0 } + } + + Boy { + name: "Leo Hodges" + BirthdayParty.rsvp: "2009-07-06" + shoe { size: 10; color: "black"; brand: "Reebok"; price: 59.95 } + } + Boy { + name: "Jack Smith" + shoe { size: 8; color: "blue"; brand: "Puma"; price: 19.95 } + } + Girl { + name: "Anne Brown" + BirthdayParty.rsvp: "2009-07-01" + shoe.size: 7 + shoe.color: "red" + shoe.brand: "Marc Jacobs" + shoe.price: 699.99 + } + +// ![1] +} +// ![1] diff --git a/examples/declarative/cppextensions/referenceexamples/valuesource/happybirthdaysong.cpp b/examples/declarative/cppextensions/referenceexamples/valuesource/happybirthdaysong.cpp new file mode 100644 index 0000000..8ea5c2b --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/valuesource/happybirthdaysong.cpp @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 "happybirthdaysong.h" +#include <QTimer> + +HappyBirthdaySong::HappyBirthdaySong(QObject *parent) +: QObject(parent), m_line(-1) +{ + setName(QString()); + QTimer *timer = new QTimer(this); + QObject::connect(timer, SIGNAL(timeout()), this, SLOT(advance())); + timer->start(1000); +} + +void HappyBirthdaySong::setTarget(const QDeclarativeProperty &p) +{ + m_target = p; +} + +QString HappyBirthdaySong::name() const +{ + return m_name; +} + +void HappyBirthdaySong::setName(const QString &name) +{ + m_name = name; + + m_lyrics.clear(); + m_lyrics << "Happy birthday to you,"; + m_lyrics << "Happy birthday to you,"; + m_lyrics << "Happy birthday dear " + m_name + ","; + m_lyrics << "Happy birthday to you!"; + m_lyrics << ""; +} + +void HappyBirthdaySong::advance() +{ + m_line = (m_line + 1) % m_lyrics.count(); + + m_target.write(m_lyrics.at(m_line)); +} + diff --git a/examples/declarative/cppextensions/referenceexamples/valuesource/happybirthdaysong.h b/examples/declarative/cppextensions/referenceexamples/valuesource/happybirthdaysong.h new file mode 100644 index 0000000..3d07909 --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/valuesource/happybirthdaysong.h @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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$ +** +****************************************************************************/ +#ifndef HAPPYBIRTHDAYSONG_H +#define HAPPYBIRTHDAYSONG_H + +#include <QDeclarativePropertyValueSource> +#include <QDeclarativeProperty> +#include <qdeclarative.h> + +#include <QStringList> + +// ![0] +class HappyBirthdaySong : public QObject, public QDeclarativePropertyValueSource +{ + Q_OBJECT + Q_INTERFACES(QDeclarativePropertyValueSource) +// ![0] + Q_PROPERTY(QString name READ name WRITE setName) +// ![1] +public: + HappyBirthdaySong(QObject *parent = 0); + + virtual void setTarget(const QDeclarativeProperty &); +// ![1] + + QString name() const; + void setName(const QString &); + +private slots: + void advance(); + +private: + int m_line; + QStringList m_lyrics; + QDeclarativeProperty m_target; + QString m_name; +// ![2] +}; +// ![2] + +#endif // HAPPYBIRTHDAYSONG_H + diff --git a/examples/declarative/cppextensions/referenceexamples/valuesource/main.cpp b/examples/declarative/cppextensions/referenceexamples/valuesource/main.cpp new file mode 100644 index 0000000..00840ee --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/valuesource/main.cpp @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 <QCoreApplication> +#include <QDeclarativeEngine> +#include <QDeclarativeComponent> +#include <QDebug> +#include "birthdayparty.h" +#include "happybirthdaysong.h" +#include "person.h" + +int main(int argc, char ** argv) +{ + QCoreApplication app(argc, argv); + + qmlRegisterType<BirthdayPartyAttached>(); + qmlRegisterType<BirthdayParty>("People", 1,0, "BirthdayParty"); + qmlRegisterType<HappyBirthdaySong>("People", 1,0, "HappyBirthdaySong"); + qmlRegisterType<ShoeDescription>(); + qmlRegisterType<Person>(); + qmlRegisterType<Boy>("People", 1,0, "Boy"); + qmlRegisterType<Girl>("People", 1,0, "Girl"); + + QDeclarativeEngine engine; + QDeclarativeComponent component(&engine, ":example.qml"); + BirthdayParty *party = qobject_cast<BirthdayParty *>(component.create()); + + if (party && party->host()) { + qWarning() << party->host()->name() << "is having a birthday!"; + + if (qobject_cast<Boy *>(party->host())) + qWarning() << "He is inviting:"; + else + qWarning() << "She is inviting:"; + + for (int ii = 0; ii < party->guestCount(); ++ii) { + Person *guest = party->guest(ii); + + QDate rsvpDate; + QObject *attached = + qmlAttachedPropertiesObject<BirthdayParty>(guest, false); + if (attached) + rsvpDate = attached->property("rsvp").toDate(); + + if (rsvpDate.isNull()) + qWarning() << " " << guest->name() << "RSVP date: Hasn't RSVP'd"; + else + qWarning() << " " << guest->name() << "RSVP date:" << qPrintable(rsvpDate.toString()); + } + + party->startParty(); + } else { + qWarning() << "An error occured"; + } + + return app.exec(); +} diff --git a/examples/declarative/cppextensions/referenceexamples/valuesource/person.cpp b/examples/declarative/cppextensions/referenceexamples/valuesource/person.cpp new file mode 100644 index 0000000..0a9e508 --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/valuesource/person.cpp @@ -0,0 +1,119 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 "person.h" + +ShoeDescription::ShoeDescription(QObject *parent) +: QObject(parent), m_size(0), m_price(0) +{ +} + +int ShoeDescription::size() const +{ + return m_size; +} + +void ShoeDescription::setSize(int s) +{ + m_size = s; +} + +QColor ShoeDescription::color() const +{ + return m_color; +} + +void ShoeDescription::setColor(const QColor &c) +{ + m_color = c; +} + +QString ShoeDescription::brand() const +{ + return m_brand; +} + +void ShoeDescription::setBrand(const QString &b) +{ + m_brand = b; +} + +qreal ShoeDescription::price() const +{ + return m_price; +} + +void ShoeDescription::setPrice(qreal p) +{ + m_price = p; +} + +Person::Person(QObject *parent) +: QObject(parent) +{ +} + +QString Person::name() const +{ + return m_name; +} + +void Person::setName(const QString &n) +{ + m_name = n; +} + +ShoeDescription *Person::shoe() +{ + return &m_shoe; +} + + +Boy::Boy(QObject * parent) +: Person(parent) +{ +} + + +Girl::Girl(QObject * parent) +: Person(parent) +{ +} + diff --git a/examples/declarative/cppextensions/referenceexamples/valuesource/person.h b/examples/declarative/cppextensions/referenceexamples/valuesource/person.h new file mode 100644 index 0000000..2f444c5 --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/valuesource/person.h @@ -0,0 +1,106 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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$ +** +****************************************************************************/ +#ifndef PERSON_H +#define PERSON_H + +#include <QObject> +#include <QColor> + +class ShoeDescription : public QObject +{ + Q_OBJECT + Q_PROPERTY(int size READ size WRITE setSize) + Q_PROPERTY(QColor color READ color WRITE setColor) + Q_PROPERTY(QString brand READ brand WRITE setBrand) + Q_PROPERTY(qreal price READ price WRITE setPrice) +public: + ShoeDescription(QObject *parent = 0); + + int size() const; + void setSize(int); + + QColor color() const; + void setColor(const QColor &); + + QString brand() const; + void setBrand(const QString &); + + qreal price() const; + void setPrice(qreal); +private: + int m_size; + QColor m_color; + QString m_brand; + qreal m_price; +}; + +class Person : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString name READ name WRITE setName) + Q_PROPERTY(ShoeDescription *shoe READ shoe) +public: + Person(QObject *parent = 0); + + QString name() const; + void setName(const QString &); + + ShoeDescription *shoe(); +private: + QString m_name; + ShoeDescription m_shoe; +}; + +class Boy : public Person +{ + Q_OBJECT +public: + Boy(QObject * parent = 0); +}; + +class Girl : public Person +{ + Q_OBJECT +public: + Girl(QObject * parent = 0); +}; + +#endif // PERSON_H diff --git a/examples/declarative/cppextensions/referenceexamples/valuesource/valuesource.pro b/examples/declarative/cppextensions/referenceexamples/valuesource/valuesource.pro new file mode 100644 index 0000000..0626c98 --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/valuesource/valuesource.pro @@ -0,0 +1,19 @@ +TEMPLATE = app +TARGET = valuesource +DEPENDPATH += . +INCLUDEPATH += . +QT += declarative + +# Input +SOURCES += main.cpp \ + person.cpp \ + birthdayparty.cpp \ + happybirthdaysong.cpp +HEADERS += person.h \ + birthdayparty.h \ + happybirthdaysong.h +RESOURCES += valuesource.qrc +target.path = $$[QT_INSTALL_EXAMPLES]/declarative/extending/valuesource +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS valuesource.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/declarative/extending/valuesource +INSTALLS += target sources diff --git a/examples/declarative/cppextensions/referenceexamples/valuesource/valuesource.qrc b/examples/declarative/cppextensions/referenceexamples/valuesource/valuesource.qrc new file mode 100644 index 0000000..e2fa01d --- /dev/null +++ b/examples/declarative/cppextensions/referenceexamples/valuesource/valuesource.qrc @@ -0,0 +1,5 @@ +<!DOCTYPE RCC><RCC version="1.0"> +<qresource> + <file>example.qml</file> +</qresource> +</RCC> |