summaryrefslogtreecommitdiff
path: root/doc/src/snippets/declarative/qtbinding
diff options
context:
space:
mode:
Diffstat (limited to 'doc/src/snippets/declarative/qtbinding')
-rw-r--r--doc/src/snippets/declarative/qtbinding/contextproperties/contextproperties.pro2
-rw-r--r--doc/src/snippets/declarative/qtbinding/contextproperties/main.cpp79
-rw-r--r--doc/src/snippets/declarative/qtbinding/contextproperties/main.qml15
-rw-r--r--doc/src/snippets/declarative/qtbinding/custompalette/custompalette.h80
-rw-r--r--doc/src/snippets/declarative/qtbinding/custompalette/custompalette.pro3
-rw-r--r--doc/src/snippets/declarative/qtbinding/custompalette/main.cpp62
-rw-r--r--doc/src/snippets/declarative/qtbinding/custompalette/main.qml22
-rw-r--r--doc/src/snippets/declarative/qtbinding/resources/example.qrc10
-rw-r--r--doc/src/snippets/declarative/qtbinding/resources/images/background.png0
-rw-r--r--doc/src/snippets/declarative/qtbinding/resources/main.cpp58
-rw-r--r--doc/src/snippets/declarative/qtbinding/resources/main.qml7
-rw-r--r--doc/src/snippets/declarative/qtbinding/resources/resources.pro4
-rw-r--r--doc/src/snippets/declarative/qtbinding/stopwatch/main.cpp63
-rw-r--r--doc/src/snippets/declarative/qtbinding/stopwatch/main.qml18
-rw-r--r--doc/src/snippets/declarative/qtbinding/stopwatch/stopwatch.cpp63
-rw-r--r--doc/src/snippets/declarative/qtbinding/stopwatch/stopwatch.h62
-rw-r--r--doc/src/snippets/declarative/qtbinding/stopwatch/stopwatch.pro3
17 files changed, 551 insertions, 0 deletions
diff --git a/doc/src/snippets/declarative/qtbinding/contextproperties/contextproperties.pro b/doc/src/snippets/declarative/qtbinding/contextproperties/contextproperties.pro
new file mode 100644
index 0000000000..68eeaf211b
--- /dev/null
+++ b/doc/src/snippets/declarative/qtbinding/contextproperties/contextproperties.pro
@@ -0,0 +1,2 @@
+QT += declarative
+SOURCES += main.cpp
diff --git a/doc/src/snippets/declarative/qtbinding/contextproperties/main.cpp b/doc/src/snippets/declarative/qtbinding/contextproperties/main.cpp
new file mode 100644
index 0000000000..4073a6cc20
--- /dev/null
+++ b/doc/src/snippets/declarative/qtbinding/contextproperties/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 documentation 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 <QDeclarativeComponent>
+#include <QDeclarativeEngine>
+
+//![0]
+#include <QApplication>
+#include <QDeclarativeView>
+#include <QDeclarativeContext>
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ QDeclarativeView view;
+ QDeclarativeContext *context = view.rootContext();
+ context->setContextProperty("backgroundColor",
+ QColor(Qt::yellow));
+
+ view.setSource(QUrl::fromLocalFile("main.qml"));
+ view.show();
+
+ return app.exec();
+}
+//![0]
+
+static void alternative()
+{
+ // Alternatively, if we don't actually want to display main.qml:
+//![1]
+ QDeclarativeEngine engine;
+ QDeclarativeContext *windowContext = new QDeclarativeContext(engine.rootContext());
+ windowContext->setContextProperty("backgroundColor", QColor(Qt::yellow));
+
+ QDeclarativeComponent component(&engine, "main.qml");
+ QObject *window = component.create(windowContext);
+//![1]
+}
+
+
diff --git a/doc/src/snippets/declarative/qtbinding/contextproperties/main.qml b/doc/src/snippets/declarative/qtbinding/contextproperties/main.qml
new file mode 100644
index 0000000000..1053f7337d
--- /dev/null
+++ b/doc/src/snippets/declarative/qtbinding/contextproperties/main.qml
@@ -0,0 +1,15 @@
+//![0]
+import Qt 4.7
+
+Rectangle {
+ width: 300
+ height: 300
+
+ color: backgroundColor
+
+ Text {
+ anchors.centerIn: parent
+ text: "Hello Yellow World!"
+ }
+}
+//![0]
diff --git a/doc/src/snippets/declarative/qtbinding/custompalette/custompalette.h b/doc/src/snippets/declarative/qtbinding/custompalette/custompalette.h
new file mode 100644
index 0000000000..d0d253a602
--- /dev/null
+++ b/doc/src/snippets/declarative/qtbinding/custompalette/custompalette.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 documentation 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 <QObject>
+#include <QColor>
+
+//![0]
+class CustomPalette : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(QColor background READ background WRITE setBackground NOTIFY backgroundChanged)
+ Q_PROPERTY(QColor text READ text WRITE setText NOTIFY textChanged)
+
+public:
+ CustomPalette() : m_background(Qt::white), m_text(Qt::black) {}
+
+ QColor background() const { return m_background; }
+ void setBackground(const QColor &c) {
+ if (c != m_background) {
+ m_background = c;
+ emit backgroundChanged();
+ }
+ }
+
+ QColor text() const { return m_text; }
+ void setText(const QColor &c) {
+ if (c != m_text) {
+ m_text = c;
+ emit textChanged();
+ }
+ }
+
+signals:
+ void textChanged();
+ void backgroundChanged();
+
+private:
+ QColor m_background;
+ QColor m_text;
+};
+
+//![0]
diff --git a/doc/src/snippets/declarative/qtbinding/custompalette/custompalette.pro b/doc/src/snippets/declarative/qtbinding/custompalette/custompalette.pro
new file mode 100644
index 0000000000..e6af0d033e
--- /dev/null
+++ b/doc/src/snippets/declarative/qtbinding/custompalette/custompalette.pro
@@ -0,0 +1,3 @@
+QT += declarative
+HEADERS += custompalette.h
+SOURCES += main.cpp
diff --git a/doc/src/snippets/declarative/qtbinding/custompalette/main.cpp b/doc/src/snippets/declarative/qtbinding/custompalette/main.cpp
new file mode 100644
index 0000000000..dc651f6d68
--- /dev/null
+++ b/doc/src/snippets/declarative/qtbinding/custompalette/main.cpp
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** 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 documentation 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 <QDeclarativeView>
+#include <QDeclarativeContext>
+
+#include "custompalette.h"
+
+//![0]
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ QDeclarativeView view;
+ view.rootContext()->setContextProperty("palette", new CustomPalette);
+
+ view.setSource(QUrl::fromLocalFile("main.qml"));
+ view.show();
+
+ return app.exec();
+}
+//![0]
+
diff --git a/doc/src/snippets/declarative/qtbinding/custompalette/main.qml b/doc/src/snippets/declarative/qtbinding/custompalette/main.qml
new file mode 100644
index 0000000000..f1a3b4f8c0
--- /dev/null
+++ b/doc/src/snippets/declarative/qtbinding/custompalette/main.qml
@@ -0,0 +1,22 @@
+//![0]
+import Qt 4.7
+
+Rectangle {
+ width: 240
+ height: 320
+ color: palette.background
+
+ Text {
+ anchors.centerIn: parent
+ color: palette.text
+ text: "Click me to change color!"
+ }
+
+ MouseArea {
+ anchors.fill: parent
+ onClicked: {
+ palette.text = "blue";
+ }
+ }
+}
+//![0]
diff --git a/doc/src/snippets/declarative/qtbinding/resources/example.qrc b/doc/src/snippets/declarative/qtbinding/resources/example.qrc
new file mode 100644
index 0000000000..5e4941512b
--- /dev/null
+++ b/doc/src/snippets/declarative/qtbinding/resources/example.qrc
@@ -0,0 +1,10 @@
+<!DOCTYPE RCC>
+<RCC version="1.0">
+
+<qresource prefix="/">
+ <file>main.qml</file>
+ <file>images/background.png</file>
+</qresource>
+
+</RCC>
+
diff --git a/doc/src/snippets/declarative/qtbinding/resources/images/background.png b/doc/src/snippets/declarative/qtbinding/resources/images/background.png
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/doc/src/snippets/declarative/qtbinding/resources/images/background.png
diff --git a/doc/src/snippets/declarative/qtbinding/resources/main.cpp b/doc/src/snippets/declarative/qtbinding/resources/main.cpp
new file mode 100644
index 0000000000..5459b9e289
--- /dev/null
+++ b/doc/src/snippets/declarative/qtbinding/resources/main.cpp
@@ -0,0 +1,58 @@
+/****************************************************************************
+**
+** 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 documentation 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 <QDeclarativeView>
+#include <QDeclarativeContext>
+
+//![0]
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ QDeclarativeView view;
+ view.setSource(QUrl("qrc:/main.qml"));
+ view.show();
+
+ return app.exec();
+}
+//![0]
+
diff --git a/doc/src/snippets/declarative/qtbinding/resources/main.qml b/doc/src/snippets/declarative/qtbinding/resources/main.qml
new file mode 100644
index 0000000000..dfe923f84a
--- /dev/null
+++ b/doc/src/snippets/declarative/qtbinding/resources/main.qml
@@ -0,0 +1,7 @@
+//![0]
+import Qt 4.7
+
+Image {
+ source: "images/background.png"
+}
+//![0]
diff --git a/doc/src/snippets/declarative/qtbinding/resources/resources.pro b/doc/src/snippets/declarative/qtbinding/resources/resources.pro
new file mode 100644
index 0000000000..cc01ee126f
--- /dev/null
+++ b/doc/src/snippets/declarative/qtbinding/resources/resources.pro
@@ -0,0 +1,4 @@
+QT += declarative
+
+SOURCES += main.cpp
+RESOURCES += example.qrc
diff --git a/doc/src/snippets/declarative/qtbinding/stopwatch/main.cpp b/doc/src/snippets/declarative/qtbinding/stopwatch/main.cpp
new file mode 100644
index 0000000000..537a2888ff
--- /dev/null
+++ b/doc/src/snippets/declarative/qtbinding/stopwatch/main.cpp
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** 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 documentation 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 "stopwatch.h"
+
+#include <QDeclarativeView>
+#include <QDeclarativeContext>
+#include <QApplication>
+
+//![0]
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ QDeclarativeView view;
+ view.rootContext()->setContextProperty("stopwatch",
+ new Stopwatch);
+
+ view.setSource(QUrl::fromLocalFile("main.qml"));
+ view.show();
+
+ return app.exec();
+}
+//![0]
+
diff --git a/doc/src/snippets/declarative/qtbinding/stopwatch/main.qml b/doc/src/snippets/declarative/qtbinding/stopwatch/main.qml
new file mode 100644
index 0000000000..2efa542d78
--- /dev/null
+++ b/doc/src/snippets/declarative/qtbinding/stopwatch/main.qml
@@ -0,0 +1,18 @@
+//![0]
+import Qt 4.7
+
+Rectangle {
+ width: 300
+ height: 300
+
+ MouseArea {
+ anchors.fill: parent
+ onClicked: {
+ if (stopwatch.isRunning())
+ stopwatch.stop()
+ else
+ stopwatch.start();
+ }
+ }
+}
+//![0]
diff --git a/doc/src/snippets/declarative/qtbinding/stopwatch/stopwatch.cpp b/doc/src/snippets/declarative/qtbinding/stopwatch/stopwatch.cpp
new file mode 100644
index 0000000000..4954a5f52f
--- /dev/null
+++ b/doc/src/snippets/declarative/qtbinding/stopwatch/stopwatch.cpp
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** 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 documentation 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 "stopwatch.h"
+
+Stopwatch::Stopwatch()
+ : m_running(false)
+{
+}
+
+bool Stopwatch::isRunning() const
+{
+ return m_running;
+}
+
+void Stopwatch::start()
+{
+ m_running = true;
+}
+
+void Stopwatch::stop()
+{
+ m_running = false;
+}
+
diff --git a/doc/src/snippets/declarative/qtbinding/stopwatch/stopwatch.h b/doc/src/snippets/declarative/qtbinding/stopwatch/stopwatch.h
new file mode 100644
index 0000000000..8d17121b1c
--- /dev/null
+++ b/doc/src/snippets/declarative/qtbinding/stopwatch/stopwatch.h
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** 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 documentation 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 <QObject>
+
+//![0]
+class Stopwatch : public QObject
+{
+ Q_OBJECT
+public:
+ Stopwatch();
+
+ Q_INVOKABLE bool isRunning() const;
+
+public slots:
+ void start();
+ void stop();
+
+private:
+ bool m_running;
+};
+
+//![0]
+
diff --git a/doc/src/snippets/declarative/qtbinding/stopwatch/stopwatch.pro b/doc/src/snippets/declarative/qtbinding/stopwatch/stopwatch.pro
new file mode 100644
index 0000000000..d803e6a351
--- /dev/null
+++ b/doc/src/snippets/declarative/qtbinding/stopwatch/stopwatch.pro
@@ -0,0 +1,3 @@
+QT += declarative
+HEADERS += stopwatch.h
+SOURCES += main.cpp stopwatch.cpp