summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorKim Motoyoshi Kalland <kim.kalland@nokia.com>2010-10-26 13:21:58 +0200
committerKim Motoyoshi Kalland <kim.kalland@nokia.com>2010-10-26 15:57:11 +0200
commit51f85b2d5849457b747e5ec9b50977807ddb362d (patch)
tree21a4c9a80ce936e15a95aca94f91d5ed9da8fc0d /examples
parent3a333e916a8e9771cb47675213723870eebc87f1 (diff)
Added examples of how to use SceneGraphItem and QxPaintItem.
Diffstat (limited to 'examples')
-rw-r--r--examples/examples.pro2
-rw-r--r--examples/paintitem/main.cpp79
-rw-r--r--examples/paintitem/myfile.qml16
-rw-r--r--examples/paintitem/paintitem.pro16
-rw-r--r--examples/scenegraphitem/main.cpp96
-rw-r--r--examples/scenegraphitem/scenegraphitem.pro16
6 files changed, 225 insertions, 0 deletions
diff --git a/examples/examples.pro b/examples/examples.pro
new file mode 100644
index 0000000..bd7ea5b
--- /dev/null
+++ b/examples/examples.pro
@@ -0,0 +1,2 @@
+TEMPLATE = subdirs
+SUBDIRS += scenegraphitem paintitem
diff --git a/examples/paintitem/main.cpp b/examples/paintitem/main.cpp
new file mode 100644
index 0000000..17ccd54
--- /dev/null
+++ b/examples/paintitem/main.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 Qt scene graph research project.
+**
+** $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 <QtGui/qapplication.h>
+#include <QtDeclarative/qdeclarative.h>
+
+#include "qxgraphicsview.h"
+#include "qxpaintitem.h"
+
+class MyPaintItem : public QxPaintItem
+{
+ Q_OBJECT
+public:
+ virtual void paint(QPainter *p)
+ {
+ QRectF rect(x(), y(), width(), height());
+ rect.adjust(10, 10, -10, -10);
+ p->setPen(QPen(Qt::black, 20));
+ p->setBrush(Qt::yellow);
+ p->drawEllipse(rect);
+ p->setPen(Qt::black);
+ p->setFont(QFont(QLatin1String("Times"), qRound(rect.height() / 2)));
+ p->drawText(rect, Qt::AlignCenter, QLatin1String(":-)"));
+ }
+};
+
+int main(int argc, char ** argv)
+{
+ QApplication app(argc, argv);
+
+ qmlRegisterType<MyPaintItem>("MyModule", 1, 0, "MyPaintItem");
+
+ QxGraphicsView view;
+ view.setSource(QUrl::fromLocalFile("myfile.qml"));
+ view.show();
+ view.raise();
+
+ return app.exec();
+}
+
+#include "main.moc"
diff --git a/examples/paintitem/myfile.qml b/examples/paintitem/myfile.qml
new file mode 100644
index 0000000..f8709ed
--- /dev/null
+++ b/examples/paintitem/myfile.qml
@@ -0,0 +1,16 @@
+import Qt 4.7
+import MyModule 1.0
+
+Rectangle {
+ width: 480
+ height: 480
+ gradient: Gradient {
+ GradientStop { position: 0.0; color: "#00249a" }
+ GradientStop { position: 0.7; color: "#ffd94f" }
+ GradientStop { position: 1.0; color: "#ffa322" }
+ }
+ MyPaintItem {
+ anchors.fill: parent
+ anchors.margins: 0
+ }
+}
diff --git a/examples/paintitem/paintitem.pro b/examples/paintitem/paintitem.pro
new file mode 100644
index 0000000..05d2649
--- /dev/null
+++ b/examples/paintitem/paintitem.pro
@@ -0,0 +1,16 @@
+TEMPLATE = app
+TARGET = paintitem
+
+include(../../scenegraph_include.pri)
+
+macx: CONFIG -= app_bundle
+
+SOURCES += main.cpp
+
+CONFIG += console
+
+CONFIG(bundle) | symbian: include(../../bundle/bundle.pri)
+
+symbian {
+ TARGET.EPOCHEAPSIZE = 0x20000 0x5000000
+}
diff --git a/examples/scenegraphitem/main.cpp b/examples/scenegraphitem/main.cpp
new file mode 100644
index 0000000..d90016c
--- /dev/null
+++ b/examples/scenegraphitem/main.cpp
@@ -0,0 +1,96 @@
+/****************************************************************************
+**
+** 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 Qt scene graph research project.
+**
+** $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 <QtGui/qapplication.h>
+#include <QtGui/qgraphicsview.h>
+#include <QtGui/qgraphicsscene.h>
+#include <QtGui/qfiledialog.h>
+#include <QtDeclarative/qdeclarativeengine.h>
+#include <QtOpenGL/qgl.h>
+
+#include "scenegraphitem.h"
+
+class MyGraphicsView : public QGraphicsView
+{
+public:
+ MyGraphicsView(const QUrl &file, QWidget *parent = 0) : QGraphicsView(parent)
+ {
+ setViewport(new QGLWidget);
+ setScene(&scene);
+ scene.addItem(&item);
+ item.setFlag(QGraphicsItem::ItemClipsToShape, false);
+ item.setSource(file);
+ QObject::connect(item.engine(), SIGNAL(quit()), QCoreApplication::instance(), SLOT(quit()));
+ }
+
+protected:
+ QGraphicsScene scene;
+ SceneGraphItem item;
+};
+
+static QUrl displayFileDialog()
+{
+ QString fileName = QFileDialog::getOpenFileName(0, "Open QML file", QString(), "QML Files (*.qml)");
+ return fileName.isEmpty() ? QUrl() : QUrl::fromLocalFile(QFileInfo(fileName).canonicalFilePath());
+}
+
+int main(int argc, char ** argv)
+{
+ QUrl file;
+ for (int i = 1; i < argc; ++i) {
+ if (*argv[i] != '-' && QFileInfo(argv[i]).exists())
+ file = QUrl::fromLocalFile(argv[i]);
+ }
+
+ QApplication app(argc, argv);
+
+ if (file.isEmpty())
+ file = displayFileDialog();
+
+ if (file.isEmpty())
+ return 0;
+
+ MyGraphicsView view(file);
+ view.show();
+ view.raise();
+
+ return app.exec();
+}
diff --git a/examples/scenegraphitem/scenegraphitem.pro b/examples/scenegraphitem/scenegraphitem.pro
new file mode 100644
index 0000000..4b9b2f0
--- /dev/null
+++ b/examples/scenegraphitem/scenegraphitem.pro
@@ -0,0 +1,16 @@
+TEMPLATE = app
+TARGET = scenegraphitem
+
+include(../../scenegraph_include.pri)
+
+macx: CONFIG -= app_bundle
+
+SOURCES += main.cpp
+
+CONFIG += console
+
+CONFIG(bundle) | symbian: include(../../bundle/bundle.pri)
+
+symbian {
+ TARGET.EPOCHEAPSIZE = 0x20000 0x5000000
+}