From 0d8a94c74a8799b278d32d9cf0c32dee7cd35d11 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Mon, 1 Mar 2010 16:45:59 +1000 Subject: Export QDeclarativeWorkerScript and QDeclarativeWorkerListModel and call other usual macros. --- src/declarative/qml/qdeclarativeworkerscript_p.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/declarative/qml/qdeclarativeworkerscript_p.h b/src/declarative/qml/qdeclarativeworkerscript_p.h index 8ebd2c1..a810801 100644 --- a/src/declarative/qml/qdeclarativeworkerscript_p.h +++ b/src/declarative/qml/qdeclarativeworkerscript_p.h @@ -61,8 +61,12 @@ #include #include +QT_BEGIN_HEADER + QT_BEGIN_NAMESPACE +QT_MODULE(Declarative) + class QDeclarativeWorkerScript; class QDeclarativeWorkerScriptEnginePrivate; class QDeclarativeWorkerScriptEngine : public QThread @@ -84,7 +88,7 @@ private: QDeclarativeWorkerScriptEnginePrivate *d; }; -class QDeclarativeWorkerScript : public QObject, public QDeclarativeParserStatus +class Q_DECLARATIVE_EXPORT QDeclarativeWorkerScript : public QObject, public QDeclarativeParserStatus { Q_OBJECT Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) @@ -115,7 +119,7 @@ private: }; class QDeclarativeWorkerListModelAgent; -class QDeclarativeWorkerListModel : public QListModelInterface +class Q_DECLARATIVE_EXPORT QDeclarativeWorkerListModel : public QListModelInterface { Q_OBJECT Q_PROPERTY(int count READ count NOTIFY countChanged) @@ -157,4 +161,6 @@ QT_END_NAMESPACE QML_DECLARE_TYPE(QDeclarativeWorkerScript); QML_DECLARE_TYPE(QDeclarativeWorkerListModel); +QT_END_HEADER + #endif // QDECLARATIVEWORKERSCRIPT_P_H -- cgit v0.12 From 32cdbb6de84eab0c3619d36f3091e68e93caf3e9 Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Mon, 1 Mar 2010 19:11:41 +1000 Subject: use ParentAnimation --- examples/declarative/package/Delegate.qml | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/examples/declarative/package/Delegate.qml b/examples/declarative/package/Delegate.qml index 4109633..62198d0 100644 --- a/examples/declarative/package/Delegate.qml +++ b/examples/declarative/package/Delegate.qml @@ -2,24 +2,26 @@ import Qt 4.6 //![0] Package { - Text { id: listDelegate; width: 200; height: 25; text: "Empty"; Package.name: "list" } - Text { id: gridDelegate; width: 100; height: 50; text: "Empty"; Package.name: "grid" } + Text { id: listDelegate; width: 200; height: 25; text: 'Empty'; Package.name: 'list' } + Text { id: gridDelegate; width: 100; height: 50; text: 'Empty'; Package.name: 'grid' } Rectangle { id: wrapper width: 200; height: 25 - color: "lightsteelblue" + color: 'lightsteelblue' + Text { text: display; anchors.centerIn: parent } MouseRegion { anchors.fill: parent onClicked: { - if (wrapper.state == "inList") - wrapper.state = "inGrid"; + if (wrapper.state == 'inList') + wrapper.state = 'inGrid'; else - wrapper.state = "inList"; + wrapper.state = 'inList'; } } - state: "inList" + + state: 'inList' states: [ State { name: 'inList' @@ -27,15 +29,17 @@ Package { }, State { name: 'inGrid' - ParentChange { target: wrapper; parent: gridDelegate } - PropertyChanges { target: wrapper; x: 0; y: 0; width: gridDelegate.width; height: gridDelegate.height } + ParentChange { + target: wrapper; parent: gridDelegate + x: 0; y: 0; width: gridDelegate.width; height: gridDelegate.height + } } ] + transitions: [ Transition { - SequentialAnimation { - ParentAction { target: wrapper } - NumberAnimation { targets: wrapper; properties: 'x,y,width,height'; duration: 300 } + ParentAnimation { + NumberAnimation { properties: 'x,y,width,height'; duration: 300 } } } ] -- cgit v0.12 From cab1428311067872b811679e72e0ad457d76a24f Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Tue, 2 Mar 2010 01:01:58 +1000 Subject: Document TextEdit::textMargin --- src/declarative/graphicsitems/qdeclarativetextedit.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/declarative/graphicsitems/qdeclarativetextedit.cpp b/src/declarative/graphicsitems/qdeclarativetextedit.cpp index 8e44b26..be73b39 100644 --- a/src/declarative/graphicsitems/qdeclarativetextedit.cpp +++ b/src/declarative/graphicsitems/qdeclarativetextedit.cpp @@ -613,6 +613,11 @@ void QDeclarativeTextEdit::setPersistentSelection(bool on) emit persistentSelectionChanged(d->persistentSelection); } +/* + \qmlproperty number TextEdit::textMargin + + The margin, in pixels, around the text in the TextEdit. +*/ qreal QDeclarativeTextEdit::textMargin() const { Q_D(const QDeclarativeTextEdit); -- cgit v0.12 From 7024111f8615b84741640e8dbbb1dd9482c9e1ea Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Mon, 1 Mar 2010 19:07:41 +0100 Subject: Expand documention of status property with examples Task-number: QTBUG-8542 --- src/declarative/graphicsitems/qdeclarativeimage.cpp | 10 ++++++++++ src/declarative/graphicsitems/qdeclarativeloader.cpp | 9 +++++++++ src/declarative/util/qdeclarativefontloader.cpp | 10 ++++++++++ src/declarative/util/qdeclarativexmllistmodel.cpp | 12 +++++++++++- 4 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/declarative/graphicsitems/qdeclarativeimage.cpp b/src/declarative/graphicsitems/qdeclarativeimage.cpp index 99ab053..2739ab8 100644 --- a/src/declarative/graphicsitems/qdeclarativeimage.cpp +++ b/src/declarative/graphicsitems/qdeclarativeimage.cpp @@ -232,6 +232,16 @@ qreal QDeclarativeImage::paintedHeight() const \o Error - an error occurred while loading the image \endlist + Note that a change in the status property does not cause anything to happen + (although it reflects what has happened with the image internally). If you wish + to react to the change in status you need to do it yourself, for example in one + of the following ways: + \list + \o Create a state, so that a state change occurs, e.g. State{name: 'loaded'; when: image.status = Image.Ready;} + \o Do something inside the onStatusChanged signal handler, e.g. Image{id: image; onStatusChanged: if(image.status == Image.Ready) console.log('Loaded');} + \o Bind to the status variable somewhere, e.g. Text{text: if(image.status!=Image.Ready){'Not Loaded';}else{'Loaded';}} + \endlist + \sa progress */ diff --git a/src/declarative/graphicsitems/qdeclarativeloader.cpp b/src/declarative/graphicsitems/qdeclarativeloader.cpp index bd89321..b0499d7 100644 --- a/src/declarative/graphicsitems/qdeclarativeloader.cpp +++ b/src/declarative/graphicsitems/qdeclarativeloader.cpp @@ -320,6 +320,15 @@ void QDeclarativeLoaderPrivate::_q_sourceLoaded() \o Error - an error occurred while loading the QML source \endlist + Note that a change in the status property does not cause anything to happen + (although it reflects what has happened to the loader internally). If you wish + to react to the change in status you need to do it yourself, for example in one + of the following ways: + \list + \o Create a state, so that a state change occurs, e.g. State{name: 'loaded'; when: loader.status = Loader.Ready;} + \o Do something inside the onStatusChanged signal handler, e.g. Loader{id: loader; onStatusChanged: if(loader.status == Loader.Ready) console.log('Loaded');} + \o Bind to the status variable somewhere, e.g. Text{text: if(loader.status!=Loader.Ready){'Not Loaded';}else{'Loaded';}} + \endlist \sa progress */ diff --git a/src/declarative/util/qdeclarativefontloader.cpp b/src/declarative/util/qdeclarativefontloader.cpp index 4d12ae1..8f5f537 100644 --- a/src/declarative/util/qdeclarativefontloader.cpp +++ b/src/declarative/util/qdeclarativefontloader.cpp @@ -189,6 +189,16 @@ void QDeclarativeFontLoader::setName(const QString &name) \o Loading - the font is currently being loaded \o Error - an error occurred while loading the font \endlist + + Note that a change in the status property does not cause anything to happen + (although it reflects what has happened to the font loader internally). If you wish + to react to the change in status you need to do it yourself, for example in one + of the following ways: + \list + \o Create a state, so that a state change occurs, e.g. State{name: 'loaded'; when: loader.status = FontLoader.Ready;} + \o Do something inside the onStatusChanged signal handler, e.g. FontLoader{id: loader; onStatusChanged: if(loader.status == FontLoader.Ready) console.log('Loaded');} + \o Bind to the status variable somewhere, e.g. Text{text: if(loader.status!=FontLoader.Ready){'Not Loaded';}else{'Loaded';}} + \endlist */ QDeclarativeFontLoader::Status QDeclarativeFontLoader::status() const { diff --git a/src/declarative/util/qdeclarativexmllistmodel.cpp b/src/declarative/util/qdeclarativexmllistmodel.cpp index 162a669..d260ada 100644 --- a/src/declarative/util/qdeclarativexmllistmodel.cpp +++ b/src/declarative/util/qdeclarativexmllistmodel.cpp @@ -647,11 +647,21 @@ void QDeclarativeXmlListModel::setNamespaceDeclarations(const QString &declarati This property holds the status of data source loading. It can be one of: \list \o Null - no data source has been set - \o Ready - nthe data source has been loaded + \o Ready - the data source has been loaded \o Loading - the data source is currently being loaded \o Error - an error occurred while loading the data source \endlist + Note that a change in the status property does not cause anything to happen + (although it reflects what has happened to the XmlListModel internally). If you wish + to react to the change in status you need to do it yourself, for example in one + of the following ways: + \list + \o Create a state, so that a state change occurs, e.g. State{name: 'loaded'; when: xmlListModel.status = XmlListModel.Ready;} + \o Do something inside the onStatusChanged signal handler, e.g. XmlListModel{id: xmlListModel; onStatusChanged: if(xmlListModel.status == XmlListModel.Ready) console.log('Loaded');} + \o Bind to the status variable somewhere, e.g. Text{text: if(xmlListModel.status!=XmlListModel.Ready){'Not Loaded';}else{'Loaded';}} + \endlist + \sa progress */ -- cgit v0.12 From e1aa5c3641ba3945e2e6a7b4c37c394eece53dd0 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Tue, 2 Mar 2010 09:11:13 +1000 Subject: Setting the same source again causes reload. Task-number: QTBUG-8623 --- src/declarative/util/qdeclarativeview.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/declarative/util/qdeclarativeview.cpp b/src/declarative/util/qdeclarativeview.cpp index 6fe5bf3..a3c372d 100644 --- a/src/declarative/util/qdeclarativeview.cpp +++ b/src/declarative/util/qdeclarativeview.cpp @@ -282,13 +282,14 @@ QDeclarativeView::~QDeclarativeView() /*! Sets the source to the \a url, loads the QML component and instantiates it. + + Calling this methods multiple times with the same url will result + in the QML being reloaded. */ void QDeclarativeView::setSource(const QUrl& url) { - if (url != d->source) { - d->source = url; - d->execute(); - } + d->source = url; + d->execute(); } /*! -- cgit v0.12 From 001d1a2eac5b0fe63ae9809c4c69065b7ae14f38 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Tue, 2 Mar 2010 09:33:27 +1000 Subject: Reapply "Some animation cleanup/refactoring." This reverts commit 543c4b82e6d6cc4a396b1c105d7321643b6ef4c6. Conflicts: src/declarative/util/qdeclarativeanimation.cpp --- src/declarative/util/qdeclarativeanimation.cpp | 11 ++++++----- src/declarative/util/qdeclarativeanimation_p_p.h | 21 ++++++++++++++------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/declarative/util/qdeclarativeanimation.cpp b/src/declarative/util/qdeclarativeanimation.cpp index 10230d3..ebf1a20 100644 --- a/src/declarative/util/qdeclarativeanimation.cpp +++ b/src/declarative/util/qdeclarativeanimation.cpp @@ -1573,7 +1573,8 @@ QDeclarativeSequentialAnimation::QDeclarativeSequentialAnimation(QObject *parent QDeclarativeAnimationGroup(parent) { Q_D(QDeclarativeAnimationGroup); - d->ag = new QSequentialAnimationGroup(this); + d->ag = new QSequentialAnimationGroup; + QDeclarative_setParent_noEvent(d->ag, this); } QDeclarativeSequentialAnimation::~QDeclarativeSequentialAnimation() @@ -1638,7 +1639,8 @@ QDeclarativeParallelAnimation::QDeclarativeParallelAnimation(QObject *parent) : QDeclarativeAnimationGroup(parent) { Q_D(QDeclarativeAnimationGroup); - d->ag = new QParallelAnimationGroup(this); + d->ag = new QParallelAnimationGroup; + QDeclarative_setParent_noEvent(d->ag, this); } QDeclarativeParallelAnimation::~QDeclarativeParallelAnimation() @@ -1797,7 +1799,7 @@ QDeclarativePropertyAnimation::~QDeclarativePropertyAnimation() void QDeclarativePropertyAnimationPrivate::init() { Q_Q(QDeclarativePropertyAnimation); - va = new QDeclarativeTimeLineValueAnimator; + va = new QDeclarativeBulkValueAnimator; QDeclarative_setParent_noEvent(va, q); } @@ -2213,7 +2215,7 @@ QAbstractAnimation *QDeclarativePropertyAnimation::qtAnimation() return d->va; } -struct PropertyUpdater : public QDeclarativeTimeLineValue +struct PropertyUpdater : public QDeclarativeBulkValueUpdater { QDeclarativeStateActions actions; int interpolatorType; //for Number/ColorAnimation @@ -2231,7 +2233,6 @@ struct PropertyUpdater : public QDeclarativeTimeLineValue wasDeleted = &deleted; if (reverse) //QVariantAnimation sends us 1->0 when reversed, but we are expecting 0->1 v = 1 - v; - QDeclarativeTimeLineValue::setValue(v); for (int ii = 0; ii < actions.count(); ++ii) { QDeclarativeAction &action = actions[ii]; diff --git a/src/declarative/util/qdeclarativeanimation_p_p.h b/src/declarative/util/qdeclarativeanimation_p_p.h index e582066..ae82a90 100644 --- a/src/declarative/util/qdeclarativeanimation_p_p.h +++ b/src/declarative/util/qdeclarativeanimation_p_p.h @@ -149,14 +149,21 @@ private: bool running; }; -//animates QDeclarativeTimeLineValue (assumes start and end values will be reals or compatible) -class QDeclarativeTimeLineValueAnimator : public QVariantAnimation +class QDeclarativeBulkValueUpdater +{ +public: + virtual ~QDeclarativeBulkValueUpdater() {} + virtual void setValue(qreal value) = 0; +}; + +//animates QDeclarativeBulkValueUpdater (assumes start and end values will be reals or compatible) +class QDeclarativeBulkValueAnimator : public QVariantAnimation { Q_OBJECT public: - QDeclarativeTimeLineValueAnimator(QObject *parent = 0) : QVariantAnimation(parent), animValue(0), fromSourced(0), policy(KeepWhenStopped) {} - ~QDeclarativeTimeLineValueAnimator() { if (policy == DeleteWhenStopped) { delete animValue; animValue = 0; } } - void setAnimValue(QDeclarativeTimeLineValue *value, DeletionPolicy p) + QDeclarativeBulkValueAnimator(QObject *parent = 0) : QVariantAnimation(parent), animValue(0), fromSourced(0), policy(KeepWhenStopped) {} + ~QDeclarativeBulkValueAnimator() { if (policy == DeleteWhenStopped) { delete animValue; animValue = 0; } } + void setAnimValue(QDeclarativeBulkValueUpdater *value, DeletionPolicy p) { if (state() == Running) stop(); @@ -193,7 +200,7 @@ protected: } private: - QDeclarativeTimeLineValue *animValue; + QDeclarativeBulkValueUpdater *animValue; bool *fromSourced; DeletionPolicy policy; }; @@ -352,7 +359,7 @@ public: int interpolatorType; QVariantAnimation::Interpolator interpolator; - QDeclarativeTimeLineValueAnimator *va; + QDeclarativeBulkValueAnimator *va; static QVariant interpolateVariant(const QVariant &from, const QVariant &to, qreal progress); static void convertVariant(QVariant &variant, int type); -- cgit v0.12 From d943ce63bd962763205796cfb5bf960e1228a0b3 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Tue, 2 Mar 2010 09:49:27 +1000 Subject: Replace remaining QGuard usage with QDeclarativeGuard. --- src/declarative/graphicsitems/qdeclarativegridview.cpp | 3 ++- src/declarative/graphicsitems/qdeclarativelistview.cpp | 3 ++- src/declarative/graphicsitems/qdeclarativepathview_p_p.h | 3 ++- src/declarative/util/qdeclarativeview.cpp | 5 +++-- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativegridview.cpp b/src/declarative/graphicsitems/qdeclarativegridview.cpp index b43b30b..8d778f8 100644 --- a/src/declarative/graphicsitems/qdeclarativegridview.cpp +++ b/src/declarative/graphicsitems/qdeclarativegridview.cpp @@ -45,6 +45,7 @@ #include "qdeclarativeflickable_p_p.h" #include +#include #include #include @@ -251,7 +252,7 @@ public: } } - QGuard model; + QDeclarativeGuard model; QVariant modelVariant; QList visibleItems; QHash unrequestedItems; diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp index 03303a0..02a8493 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview.cpp +++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp @@ -47,6 +47,7 @@ #include #include #include +#include #include #include @@ -429,7 +430,7 @@ public: virtual void flickX(qreal velocity); virtual void flickY(qreal velocity); - QGuard model; + QDeclarativeGuard model; QVariant modelVariant; QList visibleItems; QHash unrequestedItems; diff --git a/src/declarative/graphicsitems/qdeclarativepathview_p_p.h b/src/declarative/graphicsitems/qdeclarativepathview_p_p.h index ca50910..6344a8a 100644 --- a/src/declarative/graphicsitems/qdeclarativepathview_p_p.h +++ b/src/declarative/graphicsitems/qdeclarativepathview_p_p.h @@ -60,6 +60,7 @@ #include #include +#include #include @@ -132,7 +133,7 @@ public: int pathOffset; int requestedIndex; QList items; - QGuard model; + QDeclarativeGuard model; QVariant modelVariant; enum MovementReason { Other, Key, Mouse }; MovementReason moveReason; diff --git a/src/declarative/util/qdeclarativeview.cpp b/src/declarative/util/qdeclarativeview.cpp index a3c372d..f08e634 100644 --- a/src/declarative/util/qdeclarativeview.cpp +++ b/src/declarative/util/qdeclarativeview.cpp @@ -51,6 +51,7 @@ #include #include #include +#include #include #include @@ -136,8 +137,8 @@ public: QDeclarativeView *q; - QGuard root; - QGuard qmlRoot; + QDeclarativeGuard root; + QDeclarativeGuard qmlRoot; QUrl source; -- cgit v0.12 From 759888f3074deace6550a8b878d8464903dcfa09 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Tue, 2 Mar 2010 09:58:50 +1000 Subject: Test GridView.onAdd & GridView.onRemove. Reduce wait()s --- .../qdeclarativegridview/data/gridview.qml | 6 +++ .../tst_qdeclarativegridview.cpp | 59 ++++++++++++---------- 2 files changed, 39 insertions(+), 26 deletions(-) diff --git a/tests/auto/declarative/qdeclarativegridview/data/gridview.qml b/tests/auto/declarative/qdeclarativegridview/data/gridview.qml index 344b4b5..ba6b807 100644 --- a/tests/auto/declarative/qdeclarativegridview/data/gridview.qml +++ b/tests/auto/declarative/qdeclarativegridview/data/gridview.qml @@ -1,6 +1,10 @@ import Qt 4.6 Rectangle { + id: root + property int added: -1 + property var removed + width: 240 height: 320 color: "#ffffff" @@ -33,6 +37,8 @@ Rectangle { text: number } color: GridView.isCurrentItem ? "lightsteelblue" : "white" + GridView.onAdd: root.added = index + GridView.onRemove: root.removed = name } } ] diff --git a/tests/auto/declarative/qdeclarativegridview/tst_qdeclarativegridview.cpp b/tests/auto/declarative/qdeclarativegridview/tst_qdeclarativegridview.cpp index 2a60fee..7a6a060 100644 --- a/tests/auto/declarative/qdeclarativegridview/tst_qdeclarativegridview.cpp +++ b/tests/auto/declarative/qdeclarativegridview/tst_qdeclarativegridview.cpp @@ -47,6 +47,7 @@ #include #include #include +#include #include #include @@ -253,7 +254,7 @@ void tst_QDeclarativeGridView::inserted() model.insertItem(1, "Will", "9876"); // let transitions settle. - QTest::qWait(300); + QTest::qWait(100); QCOMPARE(viewport->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item @@ -264,6 +265,10 @@ void tst_QDeclarativeGridView::inserted() QVERIFY(number != 0); QCOMPARE(number->text(), model.number(1)); + // Checks that onAdd is called + int added = canvas->rootObject()->property("added").toInt(); + QCOMPARE(added, 1); + // Confirm items positioned correctly for (int i = 0; i < model.count(); ++i) { QDeclarativeItem *item = findItem(viewport, "wrapper", i); @@ -274,7 +279,7 @@ void tst_QDeclarativeGridView::inserted() model.insertItem(0, "Foo", "1111"); // zero index, and current item // let transitions settle. - QTest::qWait(300); + QTest::qWait(100); QCOMPARE(viewport->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item @@ -296,14 +301,14 @@ void tst_QDeclarativeGridView::inserted() for (int i = model.count(); i < 30; ++i) model.insertItem(i, "Hello", QString::number(i)); - QTest::qWait(300); + QTest::qWait(100); gridview->setContentY(120); - QTest::qWait(300); + QTest::qWait(100); // Insert item outside visible area model.insertItem(1, "Hello", "1324"); - QTest::qWait(300); + QTest::qWait(100); QVERIFY(gridview->contentY() == 120); @@ -334,7 +339,7 @@ void tst_QDeclarativeGridView::removed() model.removeItem(1); // let transitions settle. - QTest::qWait(300); + QTest::qWait(100); QDeclarativeText *name = findItem(viewport, "textName", 1); QVERIFY(name != 0); @@ -343,6 +348,10 @@ void tst_QDeclarativeGridView::removed() QVERIFY(number != 0); QCOMPARE(number->text(), model.number(1)); + // Checks that onRemove is called + QString removed = canvas->rootObject()->property("removed").toString(); + QCOMPARE(removed, QString("Item1")); + // Confirm items positioned correctly int itemCount = findItems(viewport, "wrapper").count(); for (int i = 0; i < model.count() && i < itemCount; ++i) { @@ -357,7 +366,7 @@ void tst_QDeclarativeGridView::removed() model.removeItem(0); // let transitions settle. - QTest::qWait(300); + QTest::qWait(100); name = findItem(viewport, "textName", 0); QVERIFY(name != 0); @@ -379,7 +388,7 @@ void tst_QDeclarativeGridView::removed() // Remove items not visible model.removeItem(25); // let transitions settle. - QTest::qWait(300); + QTest::qWait(100); // Confirm items positioned correctly itemCount = findItems(viewport, "wrapper").count(); @@ -393,11 +402,11 @@ void tst_QDeclarativeGridView::removed() // Remove items before visible gridview->setContentY(120); - QTest::qWait(500); + QTest::qWait(100); gridview->setCurrentIndex(10); // let transitions settle. - QTest::qWait(300); + QTest::qWait(100); // Setting currentIndex above shouldn't cause view to scroll QCOMPARE(gridview->contentY(), 120.0); @@ -405,7 +414,7 @@ void tst_QDeclarativeGridView::removed() model.removeItem(1); // let transitions settle. - QTest::qWait(300); + QTest::qWait(100); // Confirm items positioned correctly for (int i = 6; i < 18; ++i) { @@ -419,14 +428,14 @@ void tst_QDeclarativeGridView::removed() // Remove currentIndex QDeclarativeItem *oldCurrent = gridview->currentItem(); model.removeItem(9); - QTest::qWait(500); + QTest::qWait(100); QCOMPARE(gridview->currentIndex(), 9); QVERIFY(gridview->currentItem() != oldCurrent); gridview->setContentY(0); // let transitions settle. - QTest::qWait(300); + QTest::qWait(100); // Confirm items positioned correctly itemCount = findItems(viewport, "wrapper").count(); @@ -440,7 +449,7 @@ void tst_QDeclarativeGridView::removed() // remove item outside current view. gridview->setCurrentIndex(32); - QTest::qWait(500); + QTest::qWait(100); gridview->setContentY(240); model.removeItem(30); @@ -448,21 +457,21 @@ void tst_QDeclarativeGridView::removed() // remove current item beyond visible items. gridview->setCurrentIndex(20); - QTest::qWait(500); + QTest::qWait(100); gridview->setContentY(0); model.removeItem(20); - QTest::qWait(500); + QTest::qWait(100); QCOMPARE(gridview->currentIndex(), 20); QVERIFY(gridview->currentItem() != 0); // remove item before current, but visible gridview->setCurrentIndex(8); - QTest::qWait(500); + QTest::qWait(100); gridview->setContentY(240); oldCurrent = gridview->currentItem(); model.removeItem(6); - QTest::qWait(500); + QTest::qWait(100); QCOMPARE(gridview->currentIndex(), 7); QVERIFY(gridview->currentItem() == oldCurrent); @@ -494,7 +503,7 @@ void tst_QDeclarativeGridView::moved() model.moveItem(1, 8); // let transitions settle. - QTest::qWait(300); + QTest::qWait(100); QDeclarativeText *name = findItem(viewport, "textName", 1); QVERIFY(name != 0); @@ -526,7 +535,7 @@ void tst_QDeclarativeGridView::moved() model.moveItem(1, 25); // let transitions settle. - QTest::qWait(300); + QTest::qWait(100); // Confirm items positioned correctly and indexes correct itemCount = findItems(viewport, "wrapper").count()-1; @@ -548,7 +557,7 @@ void tst_QDeclarativeGridView::moved() model.moveItem(28, 8); // let transitions settle. - QTest::qWait(300); + QTest::qWait(100); // Confirm items positioned correctly and indexes correct for (int i = 6; i < model.count()-6 && i < itemCount+6; ++i) { @@ -591,7 +600,7 @@ void tst_QDeclarativeGridView::currentIndex() QDeclarativeItem *viewport = gridview->viewport(); QVERIFY(viewport != 0); - QTest::qWait(500); + QTest::qWait(300); // current item should be third item QCOMPARE(gridview->currentIndex(), 5); @@ -618,7 +627,7 @@ void tst_QDeclarativeGridView::currentIndex() QCOMPARE(gridview->currentIndex(), 0); gridview->setCurrentIndex(model.count()-1); - QTest::qWait(500); + QTest::qWait(100); QCOMPARE(gridview->currentIndex(), model.count()-1); gridview->moveCurrentIndexRight(); @@ -677,8 +686,6 @@ void tst_QDeclarativeGridView::currentIndex() // turn off auto highlight gridview->setHighlightFollowsCurrentItem(false); QVERIFY(gridview->highlightFollowsCurrentItem() == false); - - QTest::qWait(500); QVERIFY(gridview->highlightItem()); qreal hlPosX = gridview->highlightItem()->x(); qreal hlPosY = gridview->highlightItem()->y(); @@ -729,7 +736,7 @@ void tst_QDeclarativeGridView::changeFlow() } ctxt->setContextProperty("testTopToBottom", QVariant(true)); - QTest::qWait(500); + QTest::qWait(100); // Confirm items positioned correctly and indexes correct itemCount = findItems(viewport, "wrapper").count(); -- cgit v0.12 From 7ac4de570aa37d4b6a30e2e935ebab3642415f74 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Tue, 2 Mar 2010 10:36:47 +1000 Subject: Minor optimization. --- src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp index cd72ef9..47ba917 100644 --- a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp +++ b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp @@ -53,6 +53,7 @@ #include #include #include +#include #include #include @@ -984,8 +985,8 @@ QDeclarativeItem *QDeclarativeVisualDataModel::item(int index, const QByteArray if (complete) d->m_delegate->completeCreate(); if (nobj) { - ctxt->setParent(nobj); - data->setParent(nobj); + QDeclarative_setParent_noEvent(ctxt, nobj); + QDeclarative_setParent_noEvent(data, nobj); d->m_cache.insertItem(index, nobj); if (QDeclarativePackage *package = qobject_cast(nobj)) emit createdPackage(index, package); -- cgit v0.12 From 21c15c9efb1b34df6b990c69479979a336267d1b Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Tue, 2 Mar 2010 10:37:17 +1000 Subject: Fix warning. --- src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp index 47ba917..59d6db8 100644 --- a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp +++ b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp @@ -1269,7 +1269,6 @@ void QDeclarativeVisualDataModel::_q_dataChanged(const QModelIndex &begin, const void QDeclarativeVisualDataModel::_q_modelReset() { - Q_D(QDeclarativeVisualDataModel); emit modelReset(); } -- cgit v0.12 From 2790cb59f6877c1027c833578b72e168c912758a Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 2 Mar 2010 10:47:10 +1000 Subject: Make "on" syntax mandatory for value sources and interceptors Where you would have written x: NumberAnimation {} y: Behavior {} you now must write NumberAnimation on x {} Behavior on y {} This change also makes the parser more strict with respect to multiple assignments to a single property - they're no longer allowed. For example this x: 10 x: 11 is now an error. --- demos/declarative/flickr/common/Loading.qml | 2 +- demos/declarative/flickr/mobile/GridDelegate.qml | 2 +- demos/declarative/flickr/mobile/ImageDetails.qml | 2 +- demos/declarative/flickr/mobile/ListDelegate.qml | 4 +- demos/declarative/minehunt/main.cpp | 5 +- demos/declarative/minehunt/minehunt.qml | 2 +- demos/declarative/samegame/content/BoomBlock.qml | 6 +- demos/declarative/samegame/content/Dialog.qml | 2 +- demos/declarative/samegame/samegame.qml | 2 +- demos/declarative/snake/content/Cookie.qml | 2 +- demos/declarative/snake/content/Link.qml | 8 +- demos/declarative/snake/content/Skull.qml | 6 +- demos/declarative/snake/content/snake.js | 4 +- demos/declarative/snake/snake.qml | 6 +- demos/declarative/twitter/content/FatDelegate.qml | 2 +- demos/declarative/twitter/content/Loading.qml | 2 +- demos/declarative/twitter/twitter.qml | 2 +- .../declarative/animations/color-animation.qml | 10 +- .../declarative/animations/property-animation.qml | 2 +- .../declarative/aspectratio/face_fit_animated.qml | 2 +- examples/declarative/behaviours/behavior.qml | 6 +- examples/declarative/behaviours/test.qml | 102 ---------- .../border-image/content/MyBorderImage.qml | 4 +- examples/declarative/clocks/content/Clock.qml | 6 +- examples/declarative/connections/connections.qml | 2 +- examples/declarative/dial/content/Dial.qml | 2 +- examples/declarative/effects/effects.qml | 4 +- examples/declarative/fillmode/fillmode.qml | 2 +- examples/declarative/fonts/banner.qml | 2 +- examples/declarative/fonts/hello.qml | 4 +- examples/declarative/layouts/positioners.qml | 20 +- .../listview/content/ClickAutoRepeating.qml | 2 +- examples/declarative/listview/highlight.qml | 2 +- examples/declarative/parallax/qml/Smiley.qml | 2 +- .../progressbar/content/ProgressBar.qml | 2 +- examples/declarative/progressbar/progressbars.qml | 6 +- examples/declarative/snow/ImageBatch.qml | 72 ------- examples/declarative/snow/Loading.qml | 8 - examples/declarative/snow/create.js | 12 -- examples/declarative/snow/pics/loading.png | Bin 761 -> 0 bytes examples/declarative/snow/snow.qml | 69 ------- .../tutorials/samegame/samegame3/Dialog.qml | 2 +- .../samegame/samegame4/content/BoomBlock.qml | 6 +- .../samegame/samegame4/content/Dialog.qml | 2 +- examples/declarative/tvtennis/tvtennis.qml | 8 +- examples/declarative/velocity/Day.qml | 2 +- src/declarative/qml/qdeclarativecompiler.cpp | 209 ++++++++++++--------- src/declarative/qml/qdeclarativecompiler_p.h | 5 + src/declarative/qml/qdeclarativedom.cpp | 14 +- src/declarative/qml/qdeclarativeparser.cpp | 9 +- src/declarative/qml/qdeclarativeparser_p.h | 3 + src/declarative/qml/qdeclarativescriptparser.cpp | 66 +++++-- tests/auto/declarative/examples/tst_examples.cpp | 1 - .../qdeclarativeanimations/data/badtype1.qml | 2 +- .../qdeclarativeanimations/data/badtype2.qml | 2 +- .../qdeclarativeanimations/data/badtype3.qml | 2 +- .../qdeclarativeanimations/data/dontAutoStart.qml | 2 +- .../qdeclarativeanimations/data/dontStart.qml | 2 +- .../qdeclarativeanimations/data/properties.qml | 2 +- .../qdeclarativeanimations/data/properties2.qml | 2 +- .../qdeclarativeanimations/data/properties3.qml | 2 +- .../qdeclarativeanimations/data/properties4.qml | 2 +- .../qdeclarativeanimations/data/properties5.qml | 2 +- .../qdeclarativeanimations/data/valuesource.qml | 2 +- .../qdeclarativeanimations/data/valuesource2.qml | 2 +- .../qdeclarativebehaviors/data/binding.qml | 2 +- .../qdeclarativebehaviors/data/color.qml | 2 +- .../qdeclarativebehaviors/data/cpptrigger.qml | 2 +- .../qdeclarativebehaviors/data/disabled.qml | 2 +- .../qdeclarativebehaviors/data/dontStart.qml | 2 +- .../qdeclarativebehaviors/data/empty.qml | 2 +- .../qdeclarativebehaviors/data/explicit.qml | 2 +- .../qdeclarativebehaviors/data/groupProperty.qml | 2 +- .../qdeclarativebehaviors/data/groupProperty2.qml | 2 +- .../qdeclarativebehaviors/data/loop.qml | 2 +- .../qdeclarativebehaviors/data/nonSelecting2.qml | 2 +- .../qdeclarativebehaviors/data/parent.qml | 2 +- .../data/reassignedAnimation.qml | 2 +- .../qdeclarativebehaviors/data/scripttrigger.qml | 2 +- .../qdeclarativebehaviors/data/simple.qml | 2 +- .../tst_qdeclarativebehaviors.cpp | 2 +- .../qdeclarativedom/tst_qdeclarativedom.cpp | 72 +++---- .../qdeclarativelanguage/data/assignBasicTypes.qml | 2 - .../data/component.3.errors.txt | 2 +- .../data/doubleSignal.errors.txt | 2 +- .../data/invalidGroupedProperty.6.errors.txt | 2 +- .../data/invalidID.4.errors.txt | 2 +- .../data/listAssignment.3.errors.txt | 2 +- .../data/multiSet.1.errors.txt | 1 + .../qdeclarativelanguage/data/multiSet.1.qml | 7 + .../data/multiSet.10.errors.txt | 1 + .../qdeclarativelanguage/data/multiSet.10.qml | 6 + .../data/multiSet.2.errors.txt | 1 + .../qdeclarativelanguage/data/multiSet.2.qml | 7 + .../data/multiSet.3.errors.txt | 1 + .../qdeclarativelanguage/data/multiSet.3.qml | 7 + .../data/multiSet.4.errors.txt | 1 + .../qdeclarativelanguage/data/multiSet.4.qml | 7 + .../data/multiSet.5.errors.txt | 1 + .../qdeclarativelanguage/data/multiSet.5.qml | 6 + .../data/multiSet.6.errors.txt | 1 + .../qdeclarativelanguage/data/multiSet.6.qml | 7 + .../data/multiSet.7.errors.txt | 1 + .../qdeclarativelanguage/data/multiSet.7.qml | 7 + .../data/multiSet.8.errors.txt | 1 + .../qdeclarativelanguage/data/multiSet.8.qml | 8 + .../data/multiSet.9.errors.txt | 1 + .../qdeclarativelanguage/data/multiSet.9.qml | 6 + .../data/propertyValueSource.2.qml | 2 +- .../data/propertyValueSource.qml | 2 +- .../qdeclarativelanguage/data/script.8.errors.txt | 2 +- .../declarative/qdeclarativelanguage/testtypes.h | 5 + .../tst_qdeclarativelanguage.cpp | 11 ++ .../qdeclarativeparticles/data/particles.qml | 2 +- .../qdeclarativepathview/data/pathview2.qml | 2 +- .../qdeclarativepathview/data/pathview3.qml | 2 +- .../data/valueInterceptors.qml | 2 +- .../qdeclarativevaluetypes/data/valueSources.qml | 2 +- .../tst_qdeclarativevaluetypes.cpp | 3 +- tools/qml/qfxtester.h | 4 +- 120 files changed, 454 insertions(+), 532 deletions(-) delete mode 100644 examples/declarative/behaviours/test.qml delete mode 100644 examples/declarative/snow/ImageBatch.qml delete mode 100644 examples/declarative/snow/Loading.qml delete mode 100644 examples/declarative/snow/create.js delete mode 100644 examples/declarative/snow/pics/loading.png delete mode 100644 examples/declarative/snow/snow.qml create mode 100644 tests/auto/declarative/qdeclarativelanguage/data/multiSet.1.errors.txt create mode 100644 tests/auto/declarative/qdeclarativelanguage/data/multiSet.1.qml create mode 100644 tests/auto/declarative/qdeclarativelanguage/data/multiSet.10.errors.txt create mode 100644 tests/auto/declarative/qdeclarativelanguage/data/multiSet.10.qml create mode 100644 tests/auto/declarative/qdeclarativelanguage/data/multiSet.2.errors.txt create mode 100644 tests/auto/declarative/qdeclarativelanguage/data/multiSet.2.qml create mode 100644 tests/auto/declarative/qdeclarativelanguage/data/multiSet.3.errors.txt create mode 100644 tests/auto/declarative/qdeclarativelanguage/data/multiSet.3.qml create mode 100644 tests/auto/declarative/qdeclarativelanguage/data/multiSet.4.errors.txt create mode 100644 tests/auto/declarative/qdeclarativelanguage/data/multiSet.4.qml create mode 100644 tests/auto/declarative/qdeclarativelanguage/data/multiSet.5.errors.txt create mode 100644 tests/auto/declarative/qdeclarativelanguage/data/multiSet.5.qml create mode 100644 tests/auto/declarative/qdeclarativelanguage/data/multiSet.6.errors.txt create mode 100644 tests/auto/declarative/qdeclarativelanguage/data/multiSet.6.qml create mode 100644 tests/auto/declarative/qdeclarativelanguage/data/multiSet.7.errors.txt create mode 100644 tests/auto/declarative/qdeclarativelanguage/data/multiSet.7.qml create mode 100644 tests/auto/declarative/qdeclarativelanguage/data/multiSet.8.errors.txt create mode 100644 tests/auto/declarative/qdeclarativelanguage/data/multiSet.8.qml create mode 100644 tests/auto/declarative/qdeclarativelanguage/data/multiSet.9.errors.txt create mode 100644 tests/auto/declarative/qdeclarativelanguage/data/multiSet.9.qml diff --git a/demos/declarative/flickr/common/Loading.qml b/demos/declarative/flickr/common/Loading.qml index 174cd21..938a080 100644 --- a/demos/declarative/flickr/common/Loading.qml +++ b/demos/declarative/flickr/common/Loading.qml @@ -2,7 +2,7 @@ import Qt 4.6 Image { id: loading; source: "pics/loading.png"; transformOrigin: "Center" - rotation: NumberAnimation { + NumberAnimation on rotation { from: 0; to: 360; running: loading.visible == true; repeat: true; duration: 900 } } diff --git a/demos/declarative/flickr/mobile/GridDelegate.qml b/demos/declarative/flickr/mobile/GridDelegate.qml index 7634573..291d874 100644 --- a/demos/declarative/flickr/mobile/GridDelegate.qml +++ b/demos/declarative/flickr/mobile/GridDelegate.qml @@ -23,7 +23,7 @@ Item { anchors.centerIn: parent scale: 0.0 - scale: Behavior { NumberAnimation { easing.type: "InOutQuad"} } + Behavior on scale { NumberAnimation { easing.type: "InOutQuad"} } id: scaleMe Rectangle { height: 79; width: 79; id: blackRect; anchors.centerIn: parent; color: "black"; smooth: true } diff --git a/demos/declarative/flickr/mobile/ImageDetails.qml b/demos/declarative/flickr/mobile/ImageDetails.qml index 8749b4c..f1b3c7d 100644 --- a/demos/declarative/flickr/mobile/ImageDetails.qml +++ b/demos/declarative/flickr/mobile/ImageDetails.qml @@ -45,7 +45,7 @@ Flipable { Text { color: "white"; elide: Text.ElideRight; text: "Author: " + container.photoAuthor } Text { color: "white"; elide: Text.ElideRight; text: "Published: " + container.photoDate } Text { color: "white"; elide: Text.ElideRight; text: container.photoTags == "" ? "" : "Tags: " } - Text { color: "white"; elide: Text.ElideRight; elide: Text.ElideRight; text: container.photoTags } + Text { color: "white"; elide: Text.ElideRight; text: container.photoTags } } } diff --git a/demos/declarative/flickr/mobile/ListDelegate.qml b/demos/declarative/flickr/mobile/ListDelegate.qml index 75c4572..381664b 100644 --- a/demos/declarative/flickr/mobile/ListDelegate.qml +++ b/demos/declarative/flickr/mobile/ListDelegate.qml @@ -15,8 +15,8 @@ Component { Column { x: 92; width: wrapper.ListView.view.width - 95; y: 15; spacing: 2 Text { text: title; color: "white"; width: parent.width; font.bold: true; elide: Text.ElideRight; style: Text.Raised; styleColor: "black" } - Text { text: photoAuthor; color: "white"; width: parent.width; elide: Text.ElideLeft; color: "#cccccc"; style: Text.Raised; styleColor: "black" } - Text { text: photoDate; color: "white"; width: parent.width; elide: Text.ElideRight; color: "#cccccc"; style: Text.Raised; styleColor: "black" } + Text { text: photoAuthor; width: parent.width; elide: Text.ElideLeft; color: "#cccccc"; style: Text.Raised; styleColor: "black" } + Text { text: photoDate; width: parent.width; elide: Text.ElideRight; color: "#cccccc"; style: Text.Raised; styleColor: "black" } } } } diff --git a/demos/declarative/minehunt/main.cpp b/demos/declarative/minehunt/main.cpp index 0e99731..c8b4b54 100644 --- a/demos/declarative/minehunt/main.cpp +++ b/demos/declarative/minehunt/main.cpp @@ -100,8 +100,8 @@ public: MyWidget(int = 370, int = 480, QWidget *parent=0, Qt::WindowFlags flags=0); ~MyWidget(); - Q_PROPERTY(QList *tiles READ tiles CONSTANT); - QList *tiles() { return &_tiles; } + Q_PROPERTY(QDeclarativeListProperty tiles READ tiles CONSTANT); + QDeclarativeListProperty tiles() { return QDeclarativeListProperty(this, _tiles); } Q_PROPERTY(bool isPlaying READ isPlaying NOTIFY isPlayingChanged); bool isPlaying() {return playing;} @@ -168,7 +168,6 @@ MyWidget::MyWidget(int width, int height, QWidget *parent, Qt::WindowFlags flags QDeclarativeContext *ctxt = canvas->rootContext(); ctxt->addDefaultObject(this); - ctxt->setContextProperty("tiles", QVariant::fromValue*>(&_tiles));//QTBUG-5675 canvas->setSource(QUrl::fromLocalFile(fileName)); } diff --git a/demos/declarative/minehunt/minehunt.qml b/demos/declarative/minehunt/minehunt.qml index 617a6ed..c54e741 100644 --- a/demos/declarative/minehunt/minehunt.qml +++ b/demos/declarative/minehunt/minehunt.qml @@ -32,7 +32,7 @@ Item { anchors.verticalCenter: parent.verticalCenter source: "pics/flag.png" opacity: model.hasFlag - opacity: Behavior { + Behavior on opacity { NumberAnimation { property: "opacity" duration: 250 diff --git a/demos/declarative/samegame/content/BoomBlock.qml b/demos/declarative/samegame/content/BoomBlock.qml index 723e62a..e48194a 100644 --- a/demos/declarative/samegame/content/BoomBlock.qml +++ b/demos/declarative/samegame/content/BoomBlock.qml @@ -7,8 +7,8 @@ Item { id:block property int targetX: 0 property int targetY: 0 - x: SpringFollow { enabled: spawned; source: targetX; spring: 2; damping: 0.2 } - y: SpringFollow { source: targetY; spring: 2; damping: 0.2 } + SpringFollow on x { enabled: spawned; source: targetX; spring: 2; damping: 0.2 } + SpringFollow on y { source: targetY; spring: 2; damping: 0.2 } Image { id: img source: { @@ -21,7 +21,7 @@ Item { id:block } } opacity: 0 - opacity: Behavior { NumberAnimation { duration: 200 } } + Behavior on opacity { NumberAnimation { duration: 200 } } anchors.fill: parent } diff --git a/demos/declarative/samegame/content/Dialog.qml b/demos/declarative/samegame/content/Dialog.qml index 7769328..6d5d6b5 100644 --- a/demos/declarative/samegame/content/Dialog.qml +++ b/demos/declarative/samegame/content/Dialog.qml @@ -14,7 +14,7 @@ Rectangle { property Item text: myText color: "white"; border.width: 1; width: myText.width + 20; height: myText.height + 40; opacity: 0 - opacity: Behavior { + Behavior on opacity { NumberAnimation { duration: 1000 } } Text { id: myText; anchors.centerIn: parent; text: "Hello World!" } diff --git a/demos/declarative/samegame/samegame.qml b/demos/declarative/samegame/samegame.qml index 50f6293..c81f292 100644 --- a/demos/declarative/samegame/samegame.qml +++ b/demos/declarative/samegame/samegame.qml @@ -39,7 +39,7 @@ Rectangle { Dialog { id: scoreName; anchors.centerIn: parent; z: 22; property int initialWidth: 0 - width: Behavior{NumberAnimation{} enabled: initialWidth!=0} + Behavior on width {NumberAnimation{} enabled: initialWidth!=0} Text { id: spacer anchors.left: scoreName.left diff --git a/demos/declarative/snake/content/Cookie.qml b/demos/declarative/snake/content/Cookie.qml index 7f0aadf..0ea95cb 100644 --- a/demos/declarative/snake/content/Cookie.qml +++ b/demos/declarative/snake/content/Cookie.qml @@ -17,7 +17,7 @@ Item { anchors.fill: parent source: "pics/cookie.png" opacity: 0 - opacity: Behavior { NumberAnimation { duration: 100 } } + Behavior on opacity { NumberAnimation { duration: 100 } } Text { font.bold: true anchors.verticalCenter: parent.verticalCenter diff --git a/demos/declarative/snake/content/Link.qml b/demos/declarative/snake/content/Link.qml index 1b3f7bf..31ac4b9 100644 --- a/demos/declarative/snake/content/Link.qml +++ b/demos/declarative/snake/content/Link.qml @@ -13,8 +13,8 @@ Item { id:link x: margin - 3 + gridSize * column y: margin - 3 + gridSize * row - x: Behavior { NumberAnimation { duration: spawned ? heartbeatInterval : 0} } - y: Behavior { NumberAnimation { duration: spawned ? heartbeatInterval : 0 } } + Behavior on x { NumberAnimation { duration: spawned ? heartbeatInterval : 0} } + Behavior on y { NumberAnimation { duration: spawned ? heartbeatInterval : 0 } } Item { @@ -35,7 +35,7 @@ Item { id:link id: actualImageRotation origin.x: width/2; origin.y: height/2; angle: rotation * 90 - angle: Behavior{ NumberAnimation { duration: spawned ? 200 : 0} } + Behavior on angle { NumberAnimation { duration: spawned ? 200 : 0} } } } @@ -44,7 +44,7 @@ Item { id:link } opacity: 0 - opacity: Behavior { NumberAnimation { duration: 200 } } + Behavior on opacity { NumberAnimation { duration: 200 } } } diff --git a/demos/declarative/snake/content/Skull.qml b/demos/declarative/snake/content/Skull.qml index 585e7d3..821996a 100644 --- a/demos/declarative/snake/content/Skull.qml +++ b/demos/declarative/snake/content/Skull.qml @@ -9,11 +9,11 @@ Image { x: margin + column * gridSize + 2 y: margin + row * gridSize - 3 - x: Behavior { NumberAnimation { duration: spawned ? halfbeatInterval : 0} } - y: Behavior { NumberAnimation { duration: spawned ? halfbeatInterval : 0 } } + Behavior on x { NumberAnimation { duration: spawned ? halfbeatInterval : 0} } + Behavior on y { NumberAnimation { duration: spawned ? halfbeatInterval : 0 } } opacity: spawned ? 1 : 0 - opacity: Behavior { NumberAnimation { duration: 200 } } + Behavior on opacity { NumberAnimation { duration: 200 } } source: "pics/skull.png" width: 24 diff --git a/demos/declarative/snake/content/snake.js b/demos/declarative/snake/content/snake.js index a65aebc..12176c7 100644 --- a/demos/declarative/snake/content/snake.js +++ b/demos/declarative/snake/content/snake.js @@ -54,7 +54,7 @@ function startNewGame() } else { if(linkComponent.isReady == false){ if(linkComponent.isError == true) - print(linkComponent.errorString()); + print(linkComponent.errorsString()); else print("Still loading linkComponent"); continue;//TODO: Better error handling? @@ -295,7 +295,7 @@ function createCookie(value) { if(cookieComponent.isReady == false){ if(cookieComponent.isError == true) - print(cookieComponent.errorString()); + print(cookieComponent.errorsString()); else print("Still loading cookieComponent"); return;//TODO: Better error handling? diff --git a/demos/declarative/snake/snake.qml b/demos/declarative/snake/snake.qml index 09b6b7f..f9d02c7 100644 --- a/demos/declarative/snake/snake.qml +++ b/demos/declarative/snake/snake.qml @@ -65,7 +65,7 @@ Rectangle { anchors.fill: parent anchors.horizontalCenter: parent.horizontalCenter anchors.verticalCenter: parent.verticalCenter - opacity: Behavior { NumberAnimation { duration: 500 } } + Behavior on opacity { NumberAnimation { duration: 500 } } Text { color: "white" @@ -121,7 +121,7 @@ Rectangle { Rectangle { id: progressBar opacity: 0 - opacity: Behavior { NumberAnimation { duration: 200 } } + Behavior on opacity { NumberAnimation { duration: 200 } } color: "transparent" border.width: 2 border.color: "#221edd" @@ -137,7 +137,7 @@ Rectangle { id: progressIndicator color: "#221edd"; width: 0; - width: Behavior { NumberAnimation { duration: startHeartbeatTimer.running ? 1000 : 0}} + Behavior on width { NumberAnimation { duration: startHeartbeatTimer.running ? 1000 : 0}} height: 30; } } diff --git a/demos/declarative/twitter/content/FatDelegate.qml b/demos/declarative/twitter/content/FatDelegate.qml index 2b9288b..0f013e6 100644 --- a/demos/declarative/twitter/content/FatDelegate.qml +++ b/demos/declarative/twitter/content/FatDelegate.qml @@ -37,7 +37,7 @@ Component { + ''+userScreenName + " from " +source + "
" + addTags(statusText) + ""; textFormat: Qt.RichText - color: "white"; color: "#cccccc"; style: Text.Raised; styleColor: "black"; wrap: true + color: "#cccccc"; style: Text.Raised; styleColor: "black"; wrap: true anchors.left: whiteRect.right; anchors.right: blackRect.right; anchors.leftMargin: 6; anchors.rightMargin: 6 onLinkActivated: handleLink(link) } diff --git a/demos/declarative/twitter/content/Loading.qml b/demos/declarative/twitter/content/Loading.qml index 3151415..76bf64b 100644 --- a/demos/declarative/twitter/content/Loading.qml +++ b/demos/declarative/twitter/content/Loading.qml @@ -2,7 +2,7 @@ import Qt 4.6 Image { id: loading; source: "images/loading.png"; transformOrigin: "Center" - rotation: NumberAnimation { + NumberAnimation on rotation { from: 0; to: 360; running: loading.visible == true; repeat: true; duration: 900 } } diff --git a/demos/declarative/twitter/twitter.qml b/demos/declarative/twitter/twitter.qml index b091b03..0ea1309 100644 --- a/demos/declarative/twitter/twitter.qml +++ b/demos/declarative/twitter/twitter.qml @@ -35,7 +35,7 @@ Item { Text { width: 180 text: "Could not access twitter using this screen name and password pair."; - color: "white"; color: "#cccccc"; style: Text.Raised; styleColor: "black"; wrap: true + color: "#cccccc"; style: Text.Raised; styleColor: "black"; wrap: true visible: rssModel.status==XmlListModel.Error; anchors.centerIn: parent } diff --git a/examples/declarative/animations/color-animation.qml b/examples/declarative/animations/color-animation.qml index 7171a69..6740522 100644 --- a/examples/declarative/animations/color-animation.qml +++ b/examples/declarative/animations/color-animation.qml @@ -10,7 +10,7 @@ Item { gradient: Gradient { GradientStop { position: 0.0 - color: SequentialAnimation { + SequentialAnimation on color { repeat: true ColorAnimation { from: "DeepSkyBlue"; to: "#0E1533"; duration: 5000 } ColorAnimation { from: "#0E1533"; to: "DeepSkyBlue"; duration: 5000 } @@ -18,7 +18,7 @@ Item { } GradientStop { position: 1.0 - color: SequentialAnimation { + SequentialAnimation on color { repeat: true ColorAnimation { from: "SkyBlue"; to: "#437284"; duration: 5000 } ColorAnimation { from: "#437284"; to: "SkyBlue"; duration: 5000 } @@ -31,7 +31,7 @@ Item { Item { width: parent.width; height: 2 * parent.height transformOrigin: Item.Center - rotation: NumberAnimation { from: 0; to: 360; duration: 10000; repeat: true } + NumberAnimation on rotation { from: 0; to: 360; duration: 10000; repeat: true } Image { source: "images/sun.png"; y: 10; anchors.horizontalCenter: parent.horizontalCenter transformOrigin: Item.Center; rotation: -3 * parent.rotation @@ -44,7 +44,7 @@ Item { x: 0; y: parent.height/2; width: parent.width; height: parent.height/2 source: "images/star.png"; angleDeviation: 360; velocity: 0 velocityDeviation: 0; count: parent.width / 10; fadeInDuration: 2800 - opacity: SequentialAnimation { + SequentialAnimation on opacity { repeat: true NumberAnimation { from: 0; to: 1; duration: 5000 } NumberAnimation { from: 1; to: 0; duration: 5000 } @@ -58,7 +58,7 @@ Item { gradient: Gradient { GradientStop { position: 0.0 - color: SequentialAnimation { + SequentialAnimation on color { repeat: true ColorAnimation { from: "ForestGreen"; to: "#001600"; duration: 5000 } ColorAnimation { from: "#001600"; to: "ForestGreen"; duration: 5000 } diff --git a/examples/declarative/animations/property-animation.qml b/examples/declarative/animations/property-animation.qml index 537ee26..4428f34 100644 --- a/examples/declarative/animations/property-animation.qml +++ b/examples/declarative/animations/property-animation.qml @@ -42,7 +42,7 @@ Item { // Animate the y property. Setting repeat to true makes the // animation repeat indefinitely, otherwise it would only run once. - y: SequentialAnimation { + SequentialAnimation on y { repeat: true // Move from minHeight to maxHeight in 300ms, using the OutExpo easing function diff --git a/examples/declarative/aspectratio/face_fit_animated.qml b/examples/declarative/aspectratio/face_fit_animated.qml index 90ea516..79e99e9 100644 --- a/examples/declarative/aspectratio/face_fit_animated.qml +++ b/examples/declarative/aspectratio/face_fit_animated.qml @@ -18,7 +18,7 @@ Rectangle { source: "pics/face.png" x: (parent.width-width*scale)/2 y: (parent.height-height*scale)/2 - scale: SpringFollow { + SpringFollow on scale { source: Math.max(Math.min(face.parent.width/face.width*1.333,face.parent.height/face.height), Math.min(face.parent.width/face.width,face.parent.height/face.height*1.333)) spring: 1 diff --git a/examples/declarative/behaviours/behavior.qml b/examples/declarative/behaviours/behavior.qml index 2732c0a..c84bf62 100644 --- a/examples/declarative/behaviours/behavior.qml +++ b/examples/declarative/behaviours/behavior.qml @@ -50,12 +50,12 @@ Rectangle { radius: 5 border.width: 10; border.color: "white"; x: 100-37; y: 100-25 - x: Behavior { NumberAnimation { duration: 300 } } - y: Behavior { NumberAnimation { duration: 300 } } + Behavior on x { NumberAnimation { duration: 300 } } + Behavior on y { NumberAnimation { duration: 300 } } Text { id: focusText text: focusRect.text; - text: Behavior { + Behavior on text { SequentialAnimation { NumberAnimation { target: focusText; property: "opacity"; to: 0; duration: 150 } PropertyAction {} diff --git a/examples/declarative/behaviours/test.qml b/examples/declarative/behaviours/test.qml deleted file mode 100644 index 8fffd59..0000000 --- a/examples/declarative/behaviours/test.qml +++ /dev/null @@ -1,102 +0,0 @@ -import Qt 4.6 - -Rectangle { - color: "lightsteelblue" - width: 800 - height: 600 - id: page - MouseArea { - anchors.fill: parent - onClicked: { bluerect.parent = page; console.log(mouseX); bluerect.x = mouseX; } - } - MyRect { - color: "green" - x: 200 - y: 200 - } - MyRect { - color: "red" - x: 400 - y: 200 - } - MyRect { - color: "yellow" - x: 400 - y: 400 - } - MyRect { - color: "orange" - x: 400 - y: 500 - } - MyRect { - color: "pink" - x: 400 - y: 0 - } - MyRect { - color: "lightsteelblue" - x: 100 - y: 500 - } - MyRect { - color: "black" - x: 0 - y: 200 - } - MyRect { - color: "white" - x: 400 - y: 0 - } - Rectangle { - color: "blue" - x: 0 - y: 0 - width: 100 - height: 100 - id: bluerect - x: Behavior { - ParallelAnimation { - SequentialAnimation { - NumberAnimation { - target: bluerect - property: "y" - from: 0 - to: 10 - easing.type: "OutBounce" - easing.amplitude: 30 - duration: 250 - } - NumberAnimation { - target: bluerect - property: "y" - from: 10 - to: 0 - easing.type: "OutBounce" - easing.amplitude: 30 - duration: 250 - } - } - NumberAnimation { duration: 500 } - } - } - parent: Behavior { - SequentialAnimation { - NumberAnimation { - target: bluerect - property: "opacity" - to: 0 - duration: 150 - } - PropertyAction {} - NumberAnimation { - target: bluerect - property: "opacity" - to: 1 - duration: 150 - } - } - } - } -} diff --git a/examples/declarative/border-image/content/MyBorderImage.qml b/examples/declarative/border-image/content/MyBorderImage.qml index ca886e9..5621e18 100644 --- a/examples/declarative/border-image/content/MyBorderImage.qml +++ b/examples/declarative/border-image/content/MyBorderImage.qml @@ -17,13 +17,13 @@ Item { BorderImage { id: image; x: container.width / 2 - width / 2; y: container.height / 2 - height / 2 - width: SequentialAnimation { + SequentialAnimation on width { repeat: true NumberAnimation { from: container.minWidth; to: container.maxWidth; duration: 2000; easing.type: "InOutQuad"} NumberAnimation { from: container.maxWidth; to: container.minWidth; duration: 2000; easing.type: "InOutQuad" } } - height: SequentialAnimation { + SequentialAnimation on height { repeat: true NumberAnimation { from: container.minHeight; to: container.maxHeight; duration: 2000; easing.type: "InOutQuad"} NumberAnimation { from: container.maxHeight; to: container.minHeight; duration: 2000; easing.type: "InOutQuad" } diff --git a/examples/declarative/clocks/content/Clock.qml b/examples/declarative/clocks/content/Clock.qml index 0c6836f..75a1cf5 100644 --- a/examples/declarative/clocks/content/Clock.qml +++ b/examples/declarative/clocks/content/Clock.qml @@ -34,7 +34,7 @@ Item { transform: Rotation { id: hourRotation origin.x: 7.5; origin.y: 73; angle: 0 - angle: SpringFollow { + SpringFollow on angle { spring: 2; damping: 0.2; modulus: 360 source: (clock.hours * 30) + (clock.minutes * 0.5) } @@ -48,7 +48,7 @@ Item { transform: Rotation { id: minuteRotation origin.x: 6.5; origin.y: 83; angle: 0 - angle: SpringFollow { + SpringFollow on angle { spring: 2; damping: 0.2; modulus: 360 source: clock.minutes * 6 } @@ -62,7 +62,7 @@ Item { transform: Rotation { id: secondRotation origin.x: 2.5; origin.y: 80; angle: 0 - angle: SpringFollow { + SpringFollow on angle { spring: 5; damping: 0.25; modulus: 360 source: clock.seconds * 6 } diff --git a/examples/declarative/connections/connections.qml b/examples/declarative/connections/connections.qml index 4692343..c35bda5 100644 --- a/examples/declarative/connections/connections.qml +++ b/examples/declarative/connections/connections.qml @@ -10,7 +10,7 @@ Rectangle { Image { id: image; source: "content/bg1.jpg"; anchors.centerIn: parent; transformOrigin: Item.Center rotation: window.angle - rotation: Behavior { NumberAnimation { easing.type: "OutCubic"; duration: 300 } } + Behavior on rotation { NumberAnimation { easing.type: "OutCubic"; duration: 300 } } } Button { diff --git a/examples/declarative/dial/content/Dial.qml b/examples/declarative/dial/content/Dial.qml index 6fd0f39..ad4717a 100644 --- a/examples/declarative/dial/content/Dial.qml +++ b/examples/declarative/dial/content/Dial.qml @@ -26,7 +26,7 @@ Item { id: needleRotation origin.x: 7; origin.y: 65 angle: -130 - angle: SpringFollow { + SpringFollow on angle { spring: 1.4 damping: .15 source: Math.min(Math.max(-130, root.value*2.6 - 130), 133) diff --git a/examples/declarative/effects/effects.qml b/examples/declarative/effects/effects.qml index 0674433..997d7de 100644 --- a/examples/declarative/effects/effects.qml +++ b/examples/declarative/effects/effects.qml @@ -11,7 +11,7 @@ Rectangle { source: "pic.png" effect: Blur { - blurRadius: NumberAnimation { + NumberAnimation on blurRadius { id: blurEffect running: false from: 0; to: 10 @@ -33,7 +33,7 @@ Rectangle { effect: DropShadow { blurRadius: 3 offset.x: 3 - offset.y: NumberAnimation { id: dropShadowEffect; from: 0; to: 10; duration: 1000; running: false; repeat: true; } + NumberAnimation on offset.y { id: dropShadowEffect; from: 0; to: 10; duration: 1000; running: false; repeat: true; } } MouseArea { anchors.fill: parent; onClicked: dropShadowEffect.running = !dropShadowEffect.running } diff --git a/examples/declarative/fillmode/fillmode.qml b/examples/declarative/fillmode/fillmode.qml index ec3717f..ab0f81c 100644 --- a/examples/declarative/fillmode/fillmode.qml +++ b/examples/declarative/fillmode/fillmode.qml @@ -4,7 +4,7 @@ Image { width: 400 height: 250 source: "face.png" - fillMode: SequentialAnimation { + SequentialAnimation on fillMode { repeat: true PropertyAction { value: Image.Stretch } PropertyAction { target: label; property: "text"; value: "Stretch" } diff --git a/examples/declarative/fonts/banner.qml b/examples/declarative/fonts/banner.qml index 00b8660..7989f80 100644 --- a/examples/declarative/fonts/banner.qml +++ b/examples/declarative/fonts/banner.qml @@ -10,7 +10,7 @@ Rectangle { Row { y: -screen.height / 4.5 - x: NumberAnimation { from: 0; to: -text.width; duration: 6000; repeat: true } + NumberAnimation on x { from: 0; to: -text.width; duration: 6000; repeat: true } Text { id: text; font.pixelSize: screen.pixelSize; color: screen.textColor; text: screen.text } Text { font.pixelSize: screen.pixelSize; color: screen.textColor; text: screen.text } Text { font.pixelSize: screen.pixelSize; color: screen.textColor; text: screen.text } diff --git a/examples/declarative/fonts/hello.qml b/examples/declarative/fonts/hello.qml index fcc9580..334409e 100644 --- a/examples/declarative/fonts/hello.qml +++ b/examples/declarative/fonts/hello.qml @@ -9,7 +9,7 @@ Rectangle { id: text; color: "white"; anchors.centerIn: parent text: "Hello world!"; font.pixelSize: 60 - font.letterSpacing: SequentialAnimation { + SequentialAnimation on font.letterSpacing { repeat: true; NumberAnimation { from: 100; to: 300; easing.type: "InQuad"; duration: 3000 } ScriptAction { script: { @@ -17,7 +17,7 @@ Rectangle { container.x = (screen.width / 4) + (Math.random() * screen.width / 2) } } } - opacity: SequentialAnimation { + SequentialAnimation on opacity { repeat: true; NumberAnimation { from: 1; to: 0; duration: 2600 } PauseAnimation { duration: 400 } diff --git a/examples/declarative/layouts/positioners.qml b/examples/declarative/layouts/positioners.qml index 7146702..bce53bd 100644 --- a/examples/declarative/layouts/positioners.qml +++ b/examples/declarative/layouts/positioners.qml @@ -21,11 +21,11 @@ Rectangle { } Rectangle { color: "red"; width: 100; height: 50; border.color: "black"; radius: 15 } Rectangle { id: blueV1; color: "lightsteelblue"; width: 100; height: 50; border.color: "black"; radius: 15 - opacity: Behavior{NumberAnimation{}} + Behavior on opacity {NumberAnimation{}} } Rectangle { color: "green"; width: 100; height: 50; border.color: "black"; radius: 15 } Rectangle { id: blueV2; color: "lightsteelblue"; width: 100; height: 50; border.color: "black"; radius: 15 - opacity: Behavior{NumberAnimation{}} + Behavior on opacity {NumberAnimation{}} } Rectangle { color: "orange"; width: 100; height: 50; border.color: "black"; radius: 15 } } @@ -45,11 +45,11 @@ Rectangle { } Rectangle { color: "red"; width: 50; height: 100; border.color: "black"; radius: 15 } Rectangle { id: blueH1; color: "lightsteelblue"; width: 50; height: 100; border.color: "black"; radius: 15 - opacity: Behavior{NumberAnimation{}} + Behavior on opacity {NumberAnimation{}} } Rectangle { color: "green"; width: 50; height: 100; border.color: "black"; radius: 15 } Rectangle { id: blueH2; color: "lightsteelblue"; width: 50; height: 100; border.color: "black"; radius: 15 - opacity: Behavior{NumberAnimation{}} + Behavior on opacity {NumberAnimation{}} } Rectangle { color: "orange"; width: 50; height: 100; border.color: "black"; radius: 15 } } @@ -113,15 +113,15 @@ Rectangle { Rectangle { color: "red"; width: 50; height: 50; border.color: "black"; radius: 15 } Rectangle { id: blueG1; color: "lightsteelblue"; width: 50; height: 50; border.color: "black"; radius: 15 - opacity: Behavior{NumberAnimation{}} + Behavior on opacity {NumberAnimation{}} } Rectangle { color: "green"; width: 50; height: 50; border.color: "black"; radius: 15 } Rectangle { id: blueG2; color: "lightsteelblue"; width: 50; height: 50; border.color: "black"; radius: 15 - opacity: Behavior{NumberAnimation{}} + Behavior on opacity {NumberAnimation{}} } Rectangle { color: "orange"; width: 50; height: 50; border.color: "black"; radius: 15 } Rectangle { id: blueG3; color: "lightsteelblue"; width: 50; height: 50; border.color: "black"; radius: 15 - opacity: Behavior{NumberAnimation{}} + Behavior on opacity {NumberAnimation{}} } Rectangle { color: "red"; width: 50; height: 50; border.color: "black"; radius: 15 } Rectangle { color: "green"; width: 50; height: 50; border.color: "black"; radius: 15 } @@ -147,15 +147,15 @@ Rectangle { } Rectangle { color: "red"; width: 50; height: 50; border.color: "black"; radius: 15 } Rectangle { id: blueF1; color: "lightsteelblue"; width: 60; height: 50; border.color: "black"; radius: 15 - opacity: Behavior{NumberAnimation{}} + Behavior on opacity {NumberAnimation{}} } Rectangle { color: "green"; width: 30; height: 50; border.color: "black"; radius: 15 } Rectangle { id: blueF2; color: "lightsteelblue"; width: 60; height: 50; border.color: "black"; radius: 15 - opacity: Behavior{NumberAnimation{}} + Behavior on opacity {NumberAnimation{}} } Rectangle { color: "orange"; width: 50; height: 50; border.color: "black"; radius: 15 } Rectangle { id: blueF3; color: "lightsteelblue"; width: 40; height: 50; border.color: "black"; radius: 15 - opacity: Behavior{NumberAnimation{}} + Behavior on opacity {NumberAnimation{}} } Rectangle { color: "red"; width: 80; height: 50; border.color: "black"; radius: 15 } } diff --git a/examples/declarative/listview/content/ClickAutoRepeating.qml b/examples/declarative/listview/content/ClickAutoRepeating.qml index 0850f4e..5240e65 100644 --- a/examples/declarative/listview/content/ClickAutoRepeating.qml +++ b/examples/declarative/listview/content/ClickAutoRepeating.qml @@ -10,7 +10,7 @@ Item { signal released signal clicked - isPressed: SequentialAnimation { + SequentialAnimation on isPressed { running: false id: autoRepeat PropertyAction { target: page; property: "isPressed"; value: true } diff --git a/examples/declarative/listview/highlight.qml b/examples/declarative/listview/highlight.qml index be1f62d..5e4911d 100644 --- a/examples/declarative/listview/highlight.qml +++ b/examples/declarative/listview/highlight.qml @@ -44,7 +44,7 @@ Rectangle { id: petHighlight Rectangle { width: 200; height: 50; color: "#FFFF88" - y: SpringFollow { source: list1.currentItem.y; spring: 3; damping: 0.1 } + SpringFollow on y { source: list1.currentItem.y; spring: 3; damping: 0.1 } } } ListView { diff --git a/examples/declarative/parallax/qml/Smiley.qml b/examples/declarative/parallax/qml/Smiley.qml index 81eadda..4442d5e 100644 --- a/examples/declarative/parallax/qml/Smiley.qml +++ b/examples/declarative/parallax/qml/Smiley.qml @@ -24,7 +24,7 @@ Item { // Animate the y property. Setting repeat to true makes the // animation repeat indefinitely, otherwise it would only run once. - y: SequentialAnimation { + SequentialAnimation on y { repeat: true // Move from minHeight to maxHeight in 300ms, using the OutExpo easing function diff --git a/examples/declarative/progressbar/content/ProgressBar.qml b/examples/declarative/progressbar/content/ProgressBar.qml index bfc801c..65c80b2 100644 --- a/examples/declarative/progressbar/content/ProgressBar.qml +++ b/examples/declarative/progressbar/content/ProgressBar.qml @@ -21,7 +21,7 @@ Item { id: highlight; radius: 1 anchors.left: parent.left; anchors.top: parent.top; anchors.bottom: parent.bottom anchors.leftMargin: 3; anchors.topMargin: 3; anchors.bottomMargin: 3 - width: EaseFollow { source: highlight.widthDest; velocity: 1200 } + EaseFollow on width { source: highlight.widthDest; velocity: 1200 } gradient: Gradient { GradientStop { id: g1; position: 0.0 } GradientStop { id: g2; position: 1.0 } diff --git a/examples/declarative/progressbar/progressbars.qml b/examples/declarative/progressbar/progressbars.qml index 6530c3d..a66d544 100644 --- a/examples/declarative/progressbar/progressbars.qml +++ b/examples/declarative/progressbar/progressbars.qml @@ -14,9 +14,9 @@ Rectangle { ProgressBar { property int r: Math.floor(Math.random() * 5000 + 1000) width: main.width - 20 - value: NumberAnimation { duration: r; from: 0; to: 100; repeat: true } - color: ColorAnimation { duration: r; from: "lightsteelblue"; to: "thistle"; repeat: true } - secondColor: ColorAnimation { duration: r; from: "steelblue"; to: "#CD96CD"; repeat: true } + NumberAnimation on value { duration: r; from: 0; to: 100; repeat: true } + ColorAnimation on color { duration: r; from: "lightsteelblue"; to: "thistle"; repeat: true } + ColorAnimation on secondColor { duration: r; from: "steelblue"; to: "#CD96CD"; repeat: true } } } } diff --git a/examples/declarative/snow/ImageBatch.qml b/examples/declarative/snow/ImageBatch.qml deleted file mode 100644 index c2a2674..0000000 --- a/examples/declarative/snow/ImageBatch.qml +++ /dev/null @@ -1,72 +0,0 @@ -import Qt 4.6 - -GridView { - id: grid - property int offset: 0 - property var ref - property bool isSelected: ref.selectedItemColumn >= offset && ref.selectedItemColumn < offset + 5 - - currentIndex: (ref.selectedItemColumn - offset) + ref.selectedItemRow * 5 - - property int imageWidth: ref.imageWidth - property int imageHeight: ref.imageHeight - - width: 5 * imageWidth - height: 4 * imageHeight - cellWidth: imageWidth - cellHeight: imageHeight - - states: State { - name: "selected"; when: grid.isSelected - PropertyChanges { target: grid; z: 150 } - } - transitions: Transition { - SequentialAnimation { - PauseAnimation { duration: 150 } - PropertyAction { properties: "z" } - } - } - model: XmlListModel { - property string tags : "" - source: "http://api.flickr.com/services/feeds/photos_public.gne?"+(tags ? "tags="+tags+"&" : "")+"format=rss2" - query: "/rss/channel/item" - namespaceDeclarations: "declare namespace media=\"http://search.yahoo.com/mrss/\";" - - XmlRole { name: "url"; query: "media:content/@url/string()" } - } - - delegate: Item { - id: root - property bool isSelected: GridView.isCurrentItem && grid.isSelected - transformOrigin: Item.Center - width: grid.imageWidth; height: grid.imageHeight; - - Image { id: flickrImage; source: url; fillMode: Image.PreserveAspectFit; smooth: true; anchors.fill: parent; - opacity: (status == Image.Ready)?1:0; opacity: Behavior { NumberAnimation { } } } - Loading { anchors.centerIn: parent; visible: flickrImage.status!=1 } - - states: State { - name: "selected" - when: root.isSelected - PropertyChanges { target: root; scale: 3; z: 100 } - } - transitions: [ - Transition { - to: "selected" - SequentialAnimation { - PauseAnimation { duration: 150 } - PropertyAction { properties: "z" } - NumberAnimation { properties: "scale"; duration: 150; } - } - }, - Transition { - from: "selected" - SequentialAnimation { - NumberAnimation { properties: "scale"; duration: 150 } - PropertyAction { properties: "z" } - } - } - ] - } -} - diff --git a/examples/declarative/snow/Loading.qml b/examples/declarative/snow/Loading.qml deleted file mode 100644 index 238d9c7..0000000 --- a/examples/declarative/snow/Loading.qml +++ /dev/null @@ -1,8 +0,0 @@ -import Qt 4.6 - -Image { - id: loading; source: "pics/loading.png"; transformOrigin: Item.Center - rotation: NumberAnimation { - id: rotationAnimation; from: 0; to: 360; running: loading.visible == true; repeat: true; duration: 900 - } -} diff --git a/examples/declarative/snow/create.js b/examples/declarative/snow/create.js deleted file mode 100644 index 2bdae4a..0000000 --- a/examples/declarative/snow/create.js +++ /dev/null @@ -1,12 +0,0 @@ -var myComponent = null; - -function createNewBlock() { - if (myComponent == null) - myComponent = createComponent("ImageBatch.qml"); - - var obj = myComponent.createObject(); - obj.parent = layout; - obj.offset = maximumColumn + 1; - obj.ref = imagePanel; - maximumColumn += 5; -} diff --git a/examples/declarative/snow/pics/loading.png b/examples/declarative/snow/pics/loading.png deleted file mode 100644 index 0296cfe..0000000 Binary files a/examples/declarative/snow/pics/loading.png and /dev/null differ diff --git a/examples/declarative/snow/snow.qml b/examples/declarative/snow/snow.qml deleted file mode 100644 index 39c9c43..0000000 --- a/examples/declarative/snow/snow.qml +++ /dev/null @@ -1,69 +0,0 @@ -import Qt 4.6 - -Rectangle { - id: imagePanel - width: 1024 - height: 768 - color: "black" - - property int maximumColumn: 4 - property int selectedItemRow: 0 - property int selectedItemColumn: 0 - - Script { source: "create.js" } - - onSelectedItemColumnChanged: if (selectedItemColumn == maximumColumn) createNewBlock(); - - property int imageWidth: 200 - property int imageHeight: 200 - - property int selectedX: selectedItemColumn * imageWidth - property int selectedY: selectedItemRow * imageHeight - - Item { - anchors.centerIn: parent - Row { - id: layout - property real targetX: -(selectedX + imageWidth / 2) - - property real targetDeform: 0 - property bool slowDeform: true - - property real deform: 0 - deform: SpringFollow { - id: deformFollow; source: layout.targetDeform; velocity: layout.slowDeform?0.1:2 - onSyncChanged: if(inSync) { layout.slowDeform = true; layout.targetDeform = 0; } - } - - ImageBatch { offset: 0; ref: imagePanel } - - x: SpringFollow { source: layout.targetX; velocity: 1000 } - y: SpringFollow { source: -(selectedY + imageHeight / 2); velocity: 500 } - } - - transform: Rotation { - axis.y: 1; axis.z: 0 - angle: layout.deform * -100 - } - } - - Script { - function left() { - if (selectedItemColumn <= 0) return; - selectedItemColumn -= 1; - layout.slowDeform = false; - layout.targetDeform = Math.max(Math.min(layout.deform - 0.1, -0.1), -0.4); - } - function right() { - selectedItemColumn += 1; - layout.slowDeform = false; - layout.targetDeform = Math.min(Math.max(layout.deform + 0.1, 0.1), 0.4); - } - } - - focus: true - Keys.onLeftPressed: "left()" - Keys.onRightPressed: "right()" - Keys.onUpPressed: "if (selectedItemRow > 0) selectedItemRow = selectedItemRow - 1" - Keys.onDownPressed: "if (selectedItemRow < 3) selectedItemRow = selectedItemRow + 1" -} diff --git a/examples/declarative/tutorials/samegame/samegame3/Dialog.qml b/examples/declarative/tutorials/samegame/samegame3/Dialog.qml index 9d35832..36178ec 100644 --- a/examples/declarative/tutorials/samegame/samegame3/Dialog.qml +++ b/examples/declarative/tutorials/samegame/samegame3/Dialog.qml @@ -14,7 +14,7 @@ Rectangle { signal closed(); color: "white"; border.width: 1; width: myText.width + 20; height: 60; opacity: 0 - opacity: Behavior { + Behavior on opacity { NumberAnimation { duration: 1000 } } Text { id: myText; anchors.centerIn: parent; text: "Hello World!" } diff --git a/examples/declarative/tutorials/samegame/samegame4/content/BoomBlock.qml b/examples/declarative/tutorials/samegame/samegame4/content/BoomBlock.qml index 4c2ba43..1e3a0ed 100644 --- a/examples/declarative/tutorials/samegame/samegame4/content/BoomBlock.qml +++ b/examples/declarative/tutorials/samegame/samegame4/content/BoomBlock.qml @@ -8,8 +8,8 @@ Item { id:block property int targetX: 0 property int targetY: 0 - x: SpringFollow { enabled: spawned; source: targetX; spring: 2; damping: 0.2 } - y: SpringFollow { source: targetY; spring: 2; damping: 0.2 } + SpringFollow on x { enabled: spawned; source: targetX; spring: 2; damping: 0.2 } + SpringFollow on y { source: targetY; spring: 2; damping: 0.2 } //![1] //![2] @@ -24,7 +24,7 @@ Item { id:block } } opacity: 0 - opacity: Behavior { NumberAnimation { properties:"opacity"; duration: 200 } } + Behavior on opacity { NumberAnimation { properties:"opacity"; duration: 200 } } anchors.fill: parent } //![2] diff --git a/examples/declarative/tutorials/samegame/samegame4/content/Dialog.qml b/examples/declarative/tutorials/samegame/samegame4/content/Dialog.qml index ed9fd32..831c03b 100644 --- a/examples/declarative/tutorials/samegame/samegame4/content/Dialog.qml +++ b/examples/declarative/tutorials/samegame/samegame4/content/Dialog.qml @@ -13,7 +13,7 @@ Rectangle { signal closed(); color: "white"; border.width: 1; width: myText.width + 20; height: 60; opacity: 0 - opacity: Behavior { + Behavior on opacity { NumberAnimation { duration: 1000 } } Text { id: myText; anchors.centerIn: parent; text: "Hello World!" } diff --git a/examples/declarative/tvtennis/tvtennis.qml b/examples/declarative/tvtennis/tvtennis.qml index 4bd5319..1585c7b 100644 --- a/examples/declarative/tvtennis/tvtennis.qml +++ b/examples/declarative/tvtennis/tvtennis.qml @@ -16,7 +16,7 @@ Rectangle { x: 20; width: 20; height: 20; z: 1 // Move the ball to the right and back to the left repeatedly - x: SequentialAnimation { + SequentialAnimation on x { repeat: true NumberAnimation { to: page.width - 40; duration: 2000 } ScriptAction { script: Qt.playSound('paddle.wav') } @@ -27,7 +27,7 @@ Rectangle { } // Make y follow the target y coordinate, with a velocity of 200 - y: SpringFollow { source: ball.targetY; velocity: 200 } + SpringFollow on y { source: ball.targetY; velocity: 200 } // Detect the ball hitting the top or bottom of the view and bounce it onYChanged: { @@ -47,7 +47,7 @@ Rectangle { id: leftBat color: "Lime" x: 2; width: 20; height: 90 - y: SpringFollow { + SpringFollow on y { source: ball.y - 45; velocity: 300 enabled: ball.direction == 'left' } @@ -56,7 +56,7 @@ Rectangle { id: rightBat color: "Lime" x: page.width - 22; width: 20; height: 90 - y: SpringFollow { + SpringFollow on y { source: ball.y-45; velocity: 300 enabled: ball.direction == 'right' } diff --git a/examples/declarative/velocity/Day.qml b/examples/declarative/velocity/Day.qml index c39f99b..7424f60 100644 --- a/examples/declarative/velocity/Day.qml +++ b/examples/declarative/velocity/Day.qml @@ -24,7 +24,7 @@ Rectangle { id: stickyPage x: Math.random() * 200 + 100 y: Math.random() * 300 + 50 - rotation: SpringFollow { + SpringFollow on rotation { source: -flickable.horizontalVelocity / 100 spring: 2.0; damping: 0.1 } diff --git a/src/declarative/qml/qdeclarativecompiler.cpp b/src/declarative/qml/qdeclarativecompiler.cpp index 5da207d..a9809c0 100644 --- a/src/declarative/qml/qdeclarativecompiler.cpp +++ b/src/declarative/qml/qdeclarativecompiler.cpp @@ -718,6 +718,7 @@ bool QDeclarativeCompiler::buildObject(Object *obj, const BindingContext &ctxt) BindingContext objCtxt(obj); // Create the synthesized meta object, ignoring aliases + COMPILE_CHECK(checkDynamicMeta(obj)); COMPILE_CHECK(mergeDynamicMetaProperties(obj)); COMPILE_CHECK(buildDynamicMeta(obj, IgnoreAliases)); @@ -1623,6 +1624,10 @@ void QDeclarativeCompiler::genPropertyAssignment(QDeclarativeParser::Property *p for (int ii = 0; ii < prop->values.count(); ++ii) { QDeclarativeParser::Value *v = prop->values.at(ii); + Q_ASSERT(v->type == Value::CreatedObject || + v->type == Value::PropertyBinding || + v->type == Value::Literal); + if (v->type == Value::CreatedObject) { genObject(v->object); @@ -1652,7 +1657,27 @@ void QDeclarativeCompiler::genPropertyAssignment(QDeclarativeParser::Property *p output->bytecode << store; } - } else if (v->type == Value::ValueSource) { + } else if (v->type == Value::PropertyBinding) { + + genBindingAssignment(v, prop, obj, valueTypeProperty); + + } else if (v->type == Value::Literal) { + + QMetaProperty mp = obj->metaObject()->property(prop->index); + genLiteralAssignment(mp, v); + + } + + } + + for (int ii = 0; ii < prop->onValues.count(); ++ii) { + + QDeclarativeParser::Value *v = prop->onValues.at(ii); + + Q_ASSERT(v->type == Value::ValueSource || + v->type == Value::ValueInterceptor); + + if (v->type == Value::ValueSource) { genObject(v->object); QDeclarativeInstruction store; @@ -1685,16 +1710,6 @@ void QDeclarativeCompiler::genPropertyAssignment(QDeclarativeParser::Property *p QDeclarativeType *valueType = toQmlType(v->object); store.assignValueInterceptor.castValue = valueType->propertyValueInterceptorCast(); output->bytecode << store; - - } else if (v->type == Value::PropertyBinding) { - - genBindingAssignment(v, prop, obj, valueTypeProperty); - - } else if (v->type == Value::Literal) { - - QMetaProperty mp = obj->metaObject()->property(prop->index); - genLiteralAssignment(mp, v); - } } @@ -1793,8 +1808,8 @@ bool QDeclarativeCompiler::buildAttachedProperty(QDeclarativeParser::Property *p // } // font is a nested property. pointSize and family are not. bool QDeclarativeCompiler::buildGroupedProperty(QDeclarativeParser::Property *prop, - QDeclarativeParser::Object *obj, - const BindingContext &ctxt) + QDeclarativeParser::Object *obj, + const BindingContext &ctxt) { Q_ASSERT(prop->type != 0); Q_ASSERT(prop->index != -1); @@ -1829,9 +1844,9 @@ bool QDeclarativeCompiler::buildGroupedProperty(QDeclarativeParser::Property *pr } bool QDeclarativeCompiler::buildValueTypeProperty(QObject *type, - QDeclarativeParser::Object *obj, - QDeclarativeParser::Object *baseObj, - const BindingContext &ctxt) + QDeclarativeParser::Object *obj, + QDeclarativeParser::Object *baseObj, + const BindingContext &ctxt) { if (obj->defaultProperty) COMPILE_EXCEPTION(obj, QCoreApplication::translate("QDeclarativeCompiler","Invalid property use")); @@ -1848,37 +1863,36 @@ bool QDeclarativeCompiler::buildValueTypeProperty(QObject *type, if (prop->value) COMPILE_EXCEPTION(prop, QCoreApplication::translate("QDeclarativeCompiler","Property assignment expected")); - if (prop->values.count() != 1) + if (prop->values.count() > 1) { COMPILE_EXCEPTION(prop, QCoreApplication::translate("QDeclarativeCompiler","Single property assignment expected")); + } else if (prop->values.count()) { + Value *value = prop->values.at(0); - Value *value = prop->values.at(0); - - if (value->object) { - bool isPropertyValue = output->types.at(value->object->type).type->propertyValueSourceCast() != -1; - bool isPropertyInterceptor = output->types.at(value->object->type).type->propertyValueInterceptorCast() != -1; - if (!isPropertyValue && !isPropertyInterceptor) { + if (value->object) { COMPILE_EXCEPTION(prop, QCoreApplication::translate("QDeclarativeCompiler","Unexpected object assignment")); - } else { - COMPILE_CHECK(buildObject(value->object, ctxt)); - - if (isPropertyInterceptor && baseObj->synthdata.isEmpty()) - buildDynamicMeta(baseObj, ForceCreation); - value->type = isPropertyValue ? Value::ValueSource : Value::ValueInterceptor; + } else if (value->value.isScript()) { + // ### Check for writability + BindingReference reference; + reference.expression = value->value; + reference.property = prop; + reference.value = value; + reference.bindingContext = ctxt; + reference.bindingContext.owner++; + addBindingReference(reference); + value->type = Value::PropertyBinding; + } else { + COMPILE_CHECK(testLiteralAssignment(p, value)); + value->type = Value::Literal; } - } else if (value->value.isScript()) { - // ### Check for writability - BindingReference reference; - reference.expression = value->value; - reference.property = prop; - reference.value = value; - reference.bindingContext = ctxt; - reference.bindingContext.owner++; - addBindingReference(reference); - value->type = Value::PropertyBinding; - } else { - COMPILE_CHECK(testLiteralAssignment(p, value)); - value->type = Value::Literal; } + + for (int ii = 0; ii < prop->onValues.count(); ++ii) { + Value *v = prop->onValues.at(ii); + Q_ASSERT(v->object); + + COMPILE_CHECK(buildPropertyOnAssignment(prop, obj, baseObj, v, ctxt)); + } + obj->addValueProperty(prop); } @@ -1886,13 +1900,11 @@ bool QDeclarativeCompiler::buildValueTypeProperty(QObject *type, } // Build assignments to QML lists. QML lists are properties of type -// QList * and QDeclarativeList *. -// -// QList * types can accept a list of objects, or a single binding -// QDeclarativeList * types can accept a list of objects +// QDeclarativeListProperty. List properties can accept a list of +// objects, or a single binding. bool QDeclarativeCompiler::buildListProperty(QDeclarativeParser::Property *prop, - QDeclarativeParser::Object *obj, - const BindingContext &ctxt) + QDeclarativeParser::Object *obj, + const BindingContext &ctxt) { Q_ASSERT(QDeclarativeEnginePrivate::get(engine)->isList(prop->type)); @@ -1950,20 +1962,6 @@ bool QDeclarativeCompiler::buildScriptStringProperty(QDeclarativeParser::Propert } // Compile regular property assignments of the form "property: " -// -// ### The following problems exist -// -// There is no distinction between how "lists" of values are specified. This -// Item { -// children: Item {} -// children: Item {} -// } -// is identical to -// Item { -// children: [ Item {}, Item {} ] -// } -// -// We allow assignming multiple values to single value properties bool QDeclarativeCompiler::buildPropertyAssignment(QDeclarativeParser::Property *prop, QDeclarativeParser::Object *obj, const BindingContext &ctxt) @@ -1983,14 +1981,21 @@ bool QDeclarativeCompiler::buildPropertyAssignment(QDeclarativeParser::Property } } + for (int ii = 0; ii < prop->onValues.count(); ++ii) { + Value *v = prop->onValues.at(ii); + + Q_ASSERT(v->object); + COMPILE_CHECK(buildPropertyOnAssignment(prop, obj, obj, v, ctxt)); + } + return true; } // Compile assigning a single object instance to a regular property bool QDeclarativeCompiler::buildPropertyObjectAssignment(QDeclarativeParser::Property *prop, - QDeclarativeParser::Object *obj, - QDeclarativeParser::Value *v, - const BindingContext &ctxt) + QDeclarativeParser::Object *obj, + QDeclarativeParser::Value *v, + const BindingContext &ctxt) { Q_ASSERT(prop->index != -1); Q_ASSERT(v->object->type != -1); @@ -2019,15 +2024,6 @@ bool QDeclarativeCompiler::buildPropertyObjectAssignment(QDeclarativeParser::Pro v->object->metatype = output->types.at(v->object->type).metaObject(); Q_ASSERT(v->object->metaObject()); - // Will be true if the assigned type inherits QDeclarativePropertyValueSource - bool isPropertyValue = false; - // Will be true if the assigned type inherits QDeclarativePropertyValueInterceptor - bool isPropertyInterceptor = false; - if (QDeclarativeType *valueType = toQmlType(v->object)) { - isPropertyValue = valueType->propertyValueSourceCast() != -1; - isPropertyInterceptor = valueType->propertyValueInterceptorCast() != -1; - } - // We want to raw metaObject here as the raw metaobject is the // actual property type before we applied any extensions that might // effect the properties on the type, but don't effect assignability @@ -2063,13 +2059,6 @@ bool QDeclarativeCompiler::buildPropertyObjectAssignment(QDeclarativeParser::Pro component->getDefaultProperty()->addValue(componentValue); v->object = component; COMPILE_CHECK(buildPropertyObjectAssignment(prop, obj, v, ctxt)); - } else if (isPropertyValue || isPropertyInterceptor) { - // Assign as a property value source - COMPILE_CHECK(buildObject(v->object, ctxt)); - - if (isPropertyInterceptor && prop->parent->synthdata.isEmpty()) - buildDynamicMeta(prop->parent, ForceCreation); - v->type = isPropertyValue ? Value::ValueSource : Value::ValueInterceptor; } else { COMPILE_EXCEPTION(v->object, QCoreApplication::translate("QDeclarativeCompiler","Cannot assign object to property")); } @@ -2078,6 +2067,55 @@ bool QDeclarativeCompiler::buildPropertyObjectAssignment(QDeclarativeParser::Pro return true; } +// Compile assigning a single object instance to a regular property using the "on" syntax. +// +// For example: +// Item { +// NumberAnimation on x { } +// } +bool QDeclarativeCompiler::buildPropertyOnAssignment(QDeclarativeParser::Property *prop, + QDeclarativeParser::Object *obj, + QDeclarativeParser::Object *baseObj, + QDeclarativeParser::Value *v, + const BindingContext &ctxt) +{ + Q_ASSERT(prop->index != -1); + Q_ASSERT(v->object->type != -1); + + if (!obj->metaObject()->property(prop->index).isWritable()) + COMPILE_EXCEPTION(v, QCoreApplication::translate("QDeclarativeCompiler","Invalid property assignment: \"%1\" is a read-only property").arg(QString::fromUtf8(prop->name))); + + + // Normally buildObject() will set this up, but we need the static + // meta object earlier to test for assignability. It doesn't matter + // that there may still be outstanding synthesized meta object changes + // on this type, as they are not relevant for assignability testing + v->object->metatype = output->types.at(v->object->type).metaObject(); + Q_ASSERT(v->object->metaObject()); + + // Will be true if the assigned type inherits QDeclarativePropertyValueSource + bool isPropertyValue = false; + // Will be true if the assigned type inherits QDeclarativePropertyValueInterceptor + bool isPropertyInterceptor = false; + if (QDeclarativeType *valueType = toQmlType(v->object)) { + isPropertyValue = valueType->propertyValueSourceCast() != -1; + isPropertyInterceptor = valueType->propertyValueInterceptorCast() != -1; + } + + if (isPropertyValue || isPropertyInterceptor) { + // Assign as a property value source + COMPILE_CHECK(buildObject(v->object, ctxt)); + + if (isPropertyInterceptor && prop->parent->synthdata.isEmpty()) + buildDynamicMeta(baseObj, ForceCreation); + v->type = isPropertyValue ? Value::ValueSource : Value::ValueInterceptor; + } else { + COMPILE_EXCEPTION(v, QCoreApplication::translate("QDeclarativeCompiler","\"%1\" cannot operate on \"%2\"").arg(v->object->typeName.constData()).arg(prop->name.constData())); + } + + return true; +} + // Compile assigning a literal or binding to a regular property bool QDeclarativeCompiler::buildPropertyLiteralAssignment(QDeclarativeParser::Property *prop, QDeclarativeParser::Object *obj, @@ -2203,10 +2241,13 @@ bool QDeclarativeCompiler::mergeDynamicMetaProperties(QDeclarativeParser::Object continue; Property *property = 0; - if (p.isDefaultProperty) + if (p.isDefaultProperty) { property = obj->getDefaultProperty(); - else + } else { property = obj->getProperty(p.name); + if (!property->values.isEmpty()) + COMPILE_EXCEPTION(property, QCoreApplication::translate("QDeclarativeCompiler","Property value set multiple times")); + } if (property->value) COMPILE_EXCEPTION(property, QCoreApplication::translate("QDeclarativeCompiler","Invalid property nesting")); @@ -2233,8 +2274,6 @@ bool QDeclarativeCompiler::buildDynamicMeta(QDeclarativeParser::Object *obj, Dyn obj->dynamicSlots.isEmpty()) return true; - COMPILE_CHECK(checkDynamicMeta(obj)); - QByteArray dynamicData(sizeof(QDeclarativeVMEMetaData), (char)0); QByteArray newClassName = obj->metatype->className(); diff --git a/src/declarative/qml/qdeclarativecompiler_p.h b/src/declarative/qml/qdeclarativecompiler_p.h index 2ea3366..93a3f83 100644 --- a/src/declarative/qml/qdeclarativecompiler_p.h +++ b/src/declarative/qml/qdeclarativecompiler_p.h @@ -219,6 +219,11 @@ private: QDeclarativeParser::Object *obj, QDeclarativeParser::Value *value, const BindingContext &ctxt); + bool buildPropertyOnAssignment(QDeclarativeParser::Property *prop, + QDeclarativeParser::Object *obj, + QDeclarativeParser::Object *baseObj, + QDeclarativeParser::Value *value, + const BindingContext &ctxt); bool buildPropertyLiteralAssignment(QDeclarativeParser::Property *prop, QDeclarativeParser::Object *obj, QDeclarativeParser::Value *value, diff --git a/src/declarative/qml/qdeclarativedom.cpp b/src/declarative/qml/qdeclarativedom.cpp index 6c81f34..5b43109 100644 --- a/src/declarative/qml/qdeclarativedom.cpp +++ b/src/declarative/qml/qdeclarativedom.cpp @@ -374,7 +374,10 @@ QDeclarativeDomValue QDeclarativeDomProperty::value() const QDeclarativeDomValue rv; if (d->property) { rv.d->property = d->property; - rv.d->value = d->property->values.at(0); + if (d->property->values.count()) + rv.d->value = d->property->values.at(0); + else + rv.d->value = d->property->onValues.at(0); rv.d->property->addref(); rv.d->value->addref(); } @@ -1346,7 +1349,7 @@ QDeclarativeDomValue::Type QDeclarativeDomValue::type() const { if (d->property) if (QDeclarativeMetaType::isList(d->property->type) || - (d->property && d->property->values.count() > 1)) + (d->property && (d->property->values.count() + d->property->onValues.count()) > 1)) return List; QDeclarativeParser::Value *value = d->value; @@ -1628,6 +1631,13 @@ QList QDeclarativeDomList::values() const rv << v; } + for (int ii = 0; ii < d->property->onValues.count(); ++ii) { + QDeclarativeDomValue v; + v.d->value = d->property->onValues.at(ii); + v.d->value->addref(); + rv << v; + } + return rv; } diff --git a/src/declarative/qml/qdeclarativeparser.cpp b/src/declarative/qml/qdeclarativeparser.cpp index 5ac49d5..0e3d856 100644 --- a/src/declarative/qml/qdeclarativeparser.cpp +++ b/src/declarative/qml/qdeclarativeparser.cpp @@ -221,6 +221,8 @@ QDeclarativeParser::Property::~Property() { foreach(Value *value, values) value->release(); + foreach(Value *value, onValues) + value->release(); if (value) value->release(); } @@ -235,9 +237,14 @@ void QDeclarativeParser::Property::addValue(Value *v) values << v; } +void QDeclarativeParser::Property::addOnValue(Value *v) +{ + onValues << v; +} + bool QDeclarativeParser::Property::isEmpty() const { - return !value && values.isEmpty(); + return !value && values.isEmpty() && onValues.isEmpty(); } QDeclarativeParser::Value::Value() diff --git a/src/declarative/qml/qdeclarativeparser_p.h b/src/declarative/qml/qdeclarativeparser_p.h index aae507e..d0d7de1 100644 --- a/src/declarative/qml/qdeclarativeparser_p.h +++ b/src/declarative/qml/qdeclarativeparser_p.h @@ -320,6 +320,7 @@ namespace QDeclarativeParser Object *getValue(); void addValue(Value *v); + void addOnValue(Value *v); // The QVariant::Type of the property, or 0 (QVariant::Invalid) if // unknown. @@ -333,6 +334,8 @@ namespace QDeclarativeParser // The list of values assigned to this property. Content in values // and value are mutually exclusive QList values; + // The list of values assigned to this property using the "on" syntax + QList onValues; // The accessed property. This is used to represent dot properties. // Content in value and values are mutually exclusive. Object *value; diff --git a/src/declarative/qml/qdeclarativescriptparser.cpp b/src/declarative/qml/qdeclarativescriptparser.cpp index f4c9cdd..a4b3668 100644 --- a/src/declarative/qml/qdeclarativescriptparser.cpp +++ b/src/declarative/qml/qdeclarativescriptparser.cpp @@ -106,12 +106,12 @@ public: void operator()(const QString &code, AST::Node *node); protected: - Object *defineObjectBinding(AST::UiQualifiedId *propertyName, + Object *defineObjectBinding(AST::UiQualifiedId *propertyName, bool onAssignment, AST::UiQualifiedId *objectTypeName, LocationSpan location, AST::UiObjectInitializer *initializer = 0); - Object *defineObjectBinding_helper(AST::UiQualifiedId *propertyName, + Object *defineObjectBinding_helper(AST::UiQualifiedId *propertyName, bool onAssignment, const QString &objectType, AST::SourceLocation typeLocation, LocationSpan location, @@ -243,6 +243,7 @@ QString ProcessAST::asString(AST::UiQualifiedId *node) const Object * ProcessAST::defineObjectBinding_helper(AST::UiQualifiedId *propertyName, + bool onAssignment, const QString &objectType, AST::SourceLocation typeLocation, LocationSpan location, @@ -254,10 +255,19 @@ ProcessAST::defineObjectBinding_helper(AST::UiQualifiedId *propertyName, (lastTypeDot >= 0 && objectType.at(lastTypeDot+1).isUpper())); int propertyCount = 0; - for (; propertyName; propertyName = propertyName->next){ + for (AST::UiQualifiedId *name = propertyName; name; name = name->next){ ++propertyCount; - _stateStack.pushProperty(propertyName->name->asString(), - this->location(propertyName)); + _stateStack.pushProperty(name->name->asString(), + this->location(name)); + } + + if (!onAssignment && propertyCount && currentProperty() && currentProperty()->values.count()) { + QDeclarativeError error; + error.setDescription(QCoreApplication::translate("QDeclarativeParser","Property value set multiple times")); + error.setLine(this->location(propertyName).start.line); + error.setColumn(this->location(propertyName).start.column); + _parser->_errors << error; + return 0; } if (!isType) { @@ -327,7 +337,10 @@ ProcessAST::defineObjectBinding_helper(AST::UiQualifiedId *propertyName, Value *v = new Value; v->object = obj; v->location = obj->location; - prop->addValue(v); + if (onAssignment) + prop->addOnValue(v); + else + prop->addValue(v); while (propertyCount--) _stateStack.pop(); @@ -363,7 +376,7 @@ ProcessAST::defineObjectBinding_helper(AST::UiQualifiedId *propertyName, } } -Object *ProcessAST::defineObjectBinding(AST::UiQualifiedId *qualifiedId, +Object *ProcessAST::defineObjectBinding(AST::UiQualifiedId *qualifiedId, bool onAssignment, AST::UiQualifiedId *objectTypeName, LocationSpan location, AST::UiObjectInitializer *initializer) @@ -395,7 +408,7 @@ Object *ProcessAST::defineObjectBinding(AST::UiQualifiedId *qualifiedId, } - return defineObjectBinding_helper(qualifiedId, objectType, typeLocation, location, initializer); + return defineObjectBinding_helper(qualifiedId, onAssignment, objectType, typeLocation, location, initializer); } LocationSpan ProcessAST::location(AST::UiQualifiedId *id) @@ -623,7 +636,7 @@ bool ProcessAST::visit(AST::UiObjectDefinition *node) LocationSpan l = location(node->firstSourceLocation(), node->lastSourceLocation()); - defineObjectBinding(/*propertyName = */ 0, + defineObjectBinding(/*propertyName = */ 0, false, node->qualifiedTypeNameId, l, node->initializer); @@ -638,7 +651,7 @@ bool ProcessAST::visit(AST::UiObjectBinding *node) LocationSpan l = location(node->qualifiedTypeNameId->identifierToken, node->initializer->rbraceToken); - defineObjectBinding(node->qualifiedId, + defineObjectBinding(node->qualifiedId, node->hasOnToken, node->qualifiedTypeNameId, l, node->initializer); @@ -674,14 +687,23 @@ bool ProcessAST::visit(AST::UiScriptBinding *node) { int propertyCount = 0; AST::UiQualifiedId *propertyName = node->qualifiedId; - for (; propertyName; propertyName = propertyName->next){ + for (AST::UiQualifiedId *name = propertyName; name; name = name->next){ ++propertyCount; - _stateStack.pushProperty(propertyName->name->asString(), - location(propertyName)); + _stateStack.pushProperty(name->name->asString(), + location(name)); } Property *prop = currentProperty(); + if (prop->values.count()) { + QDeclarativeError error; + error.setDescription(QCoreApplication::translate("QDeclarativeParser","Property value set multiple times")); + error.setLine(this->location(propertyName).start.line); + error.setColumn(this->location(propertyName).start.column); + _parser->_errors << error; + return 0; + } + QDeclarativeParser::Variant primitive; if (AST::ExpressionStatement *stmt = AST::cast(node->statement)) { @@ -724,16 +746,26 @@ bool ProcessAST::visit(AST::UiArrayBinding *node) { int propertyCount = 0; AST::UiQualifiedId *propertyName = node->qualifiedId; - for (; propertyName; propertyName = propertyName->next){ + for (AST::UiQualifiedId *name = propertyName; name; name = name->next){ ++propertyCount; - _stateStack.pushProperty(propertyName->name->asString(), - location(propertyName)); + _stateStack.pushProperty(name->name->asString(), + location(name)); + } + + Property* prop = currentProperty(); + + if (prop->values.count()) { + QDeclarativeError error; + error.setDescription(QCoreApplication::translate("QDeclarativeParser","Property value set multiple times")); + error.setLine(this->location(propertyName).start.line); + error.setColumn(this->location(propertyName).start.column); + _parser->_errors << error; + return 0; } accept(node->members); // For the DOM, store the position of the T_LBRACKET upto the T_RBRACKET as the range: - Property* prop = currentProperty(); prop->listValueRange.offset = node->lbracketToken.offset; prop->listValueRange.length = node->rbracketToken.offset + node->rbracketToken.length - node->lbracketToken.offset; diff --git a/tests/auto/declarative/examples/tst_examples.cpp b/tests/auto/declarative/examples/tst_examples.cpp index 6160e7c..106a4e0 100644 --- a/tests/auto/declarative/examples/tst_examples.cpp +++ b/tests/auto/declarative/examples/tst_examples.cpp @@ -190,7 +190,6 @@ void tst_examples::examples() << "-scriptopts" << "play,testerror,exitoncomplete,exitonfailure" << file; QProcess p; -qDebug() << qmlruntime << arguments; p.start(qmlruntime, arguments); QVERIFY(p.waitForFinished()); QCOMPARE(p.exitStatus(), QProcess::NormalExit); diff --git a/tests/auto/declarative/qdeclarativeanimations/data/badtype1.qml b/tests/auto/declarative/qdeclarativeanimations/data/badtype1.qml index 6381df3..2629cf4 100644 --- a/tests/auto/declarative/qdeclarativeanimations/data/badtype1.qml +++ b/tests/auto/declarative/qdeclarativeanimations/data/badtype1.qml @@ -7,6 +7,6 @@ Rectangle { color: "red" width: 50; height: 50 x: 100; y: 100 - x: PropertyAnimation { from: "blue"; to: "green"; } + PropertyAnimation on x { from: "blue"; to: "green"; } } } diff --git a/tests/auto/declarative/qdeclarativeanimations/data/badtype2.qml b/tests/auto/declarative/qdeclarativeanimations/data/badtype2.qml index 8d57e41..1543a2a 100644 --- a/tests/auto/declarative/qdeclarativeanimations/data/badtype2.qml +++ b/tests/auto/declarative/qdeclarativeanimations/data/badtype2.qml @@ -7,6 +7,6 @@ Rectangle { color: "red" width: 50; height: 50 x: 100; y: 100 - x: NumberAnimation { from: "blue"; to: "green"; } + NumberAnimation on x { from: "blue"; to: "green"; } } } diff --git a/tests/auto/declarative/qdeclarativeanimations/data/badtype3.qml b/tests/auto/declarative/qdeclarativeanimations/data/badtype3.qml index c4867c3..aa98c33 100644 --- a/tests/auto/declarative/qdeclarativeanimations/data/badtype3.qml +++ b/tests/auto/declarative/qdeclarativeanimations/data/badtype3.qml @@ -5,7 +5,7 @@ Rectangle { height: 320 Rectangle { color: "red" - color: ColorAnimation { from: 10; to: 15; } + ColorAnimation on color { from: 10; to: 15; } width: 50; height: 50 x: 100; y: 100 } diff --git a/tests/auto/declarative/qdeclarativeanimations/data/dontAutoStart.qml b/tests/auto/declarative/qdeclarativeanimations/data/dontAutoStart.qml index d9660b6..3f00e68 100644 --- a/tests/auto/declarative/qdeclarativeanimations/data/dontAutoStart.qml +++ b/tests/auto/declarative/qdeclarativeanimations/data/dontAutoStart.qml @@ -9,7 +9,7 @@ Rectangle { id: redRect width: 100; height: 100 color: Qt.rgba(1,0,0) - x: Behavior { + Behavior on x { NumberAnimation { objectName: "MyAnim"; target: redRect; property: "y"; to: 300; repeat: true} } diff --git a/tests/auto/declarative/qdeclarativeanimations/data/dontStart.qml b/tests/auto/declarative/qdeclarativeanimations/data/dontStart.qml index 36417db..efed058 100644 --- a/tests/auto/declarative/qdeclarativeanimations/data/dontStart.qml +++ b/tests/auto/declarative/qdeclarativeanimations/data/dontStart.qml @@ -9,7 +9,7 @@ Rectangle { id: redRect width: 100; height: 100 color: Qt.rgba(1,0,0) - x: SequentialAnimation { + SequentialAnimation on x { running: false NumberAnimation { objectName: "MyAnim"; running: true } } diff --git a/tests/auto/declarative/qdeclarativeanimations/data/properties.qml b/tests/auto/declarative/qdeclarativeanimations/data/properties.qml index 7e73f57..4437815 100644 --- a/tests/auto/declarative/qdeclarativeanimations/data/properties.qml +++ b/tests/auto/declarative/qdeclarativeanimations/data/properties.qml @@ -9,6 +9,6 @@ Rectangle { color: "red" width: 50; height: 50 x: 100; y: 100 - x: NumberAnimation { to: 200 } + NumberAnimation on x { to: 200 } } } diff --git a/tests/auto/declarative/qdeclarativeanimations/data/properties2.qml b/tests/auto/declarative/qdeclarativeanimations/data/properties2.qml index 6c96155..b1f2020 100644 --- a/tests/auto/declarative/qdeclarativeanimations/data/properties2.qml +++ b/tests/auto/declarative/qdeclarativeanimations/data/properties2.qml @@ -9,6 +9,6 @@ Rectangle { color: "red" width: 50; height: 50 x: 100; y: 100 - x: NumberAnimation { targets: theRect; properties: "x"; to: 200; } + NumberAnimation on x { targets: theRect; properties: "x"; to: 200; } } } diff --git a/tests/auto/declarative/qdeclarativeanimations/data/properties3.qml b/tests/auto/declarative/qdeclarativeanimations/data/properties3.qml index ff08885..0a0ed6f 100644 --- a/tests/auto/declarative/qdeclarativeanimations/data/properties3.qml +++ b/tests/auto/declarative/qdeclarativeanimations/data/properties3.qml @@ -9,6 +9,6 @@ Rectangle { color: "red" width: 50; height: 50 x: 100; y: 100 - x: NumberAnimation { target: theRect; property: "x"; to: 300; } + NumberAnimation on x { target: theRect; property: "x"; to: 300; } } } diff --git a/tests/auto/declarative/qdeclarativeanimations/data/properties4.qml b/tests/auto/declarative/qdeclarativeanimations/data/properties4.qml index dab7e5f..a90f004 100644 --- a/tests/auto/declarative/qdeclarativeanimations/data/properties4.qml +++ b/tests/auto/declarative/qdeclarativeanimations/data/properties4.qml @@ -9,6 +9,6 @@ Rectangle { color: "red" width: 50; height: 50 x: 100; y: 100 - x: NumberAnimation { target: theRect; property: "y"; to: 200; } + NumberAnimation on x { target: theRect; property: "y"; to: 200; } } } diff --git a/tests/auto/declarative/qdeclarativeanimations/data/properties5.qml b/tests/auto/declarative/qdeclarativeanimations/data/properties5.qml index 38396b1..7d3cec9 100644 --- a/tests/auto/declarative/qdeclarativeanimations/data/properties5.qml +++ b/tests/auto/declarative/qdeclarativeanimations/data/properties5.qml @@ -9,6 +9,6 @@ Rectangle { color: "red" width: 50; height: 50 x: 100; y: 100 - x: NumberAnimation { targets: theRect; properties: "y"; to: 200; } + NumberAnimation on x { targets: theRect; properties: "y"; to: 200; } } } diff --git a/tests/auto/declarative/qdeclarativeanimations/data/valuesource.qml b/tests/auto/declarative/qdeclarativeanimations/data/valuesource.qml index c35063d..2260440 100644 --- a/tests/auto/declarative/qdeclarativeanimations/data/valuesource.qml +++ b/tests/auto/declarative/qdeclarativeanimations/data/valuesource.qml @@ -9,6 +9,6 @@ Rectangle { color: "red" width: 50; height: 50 x: 100; y: 100 - x: NumberAnimation { id: anim; objectName: "MyAnim"; to: 200 } + NumberAnimation on x { id: anim; objectName: "MyAnim"; to: 200 } } } diff --git a/tests/auto/declarative/qdeclarativeanimations/data/valuesource2.qml b/tests/auto/declarative/qdeclarativeanimations/data/valuesource2.qml index 1a60542..36d6c72 100644 --- a/tests/auto/declarative/qdeclarativeanimations/data/valuesource2.qml +++ b/tests/auto/declarative/qdeclarativeanimations/data/valuesource2.qml @@ -9,6 +9,6 @@ Rectangle { color: "red" width: 50; height: 50 x: 100; y: 100 - x: NumberAnimation { id: anim; objectName: "MyAnim"; running: false; to: 200 } + NumberAnimation on x { id: anim; objectName: "MyAnim"; running: false; to: 200 } } } diff --git a/tests/auto/declarative/qdeclarativebehaviors/data/binding.qml b/tests/auto/declarative/qdeclarativebehaviors/data/binding.qml index 201da37..e982f21 100644 --- a/tests/auto/declarative/qdeclarativebehaviors/data/binding.qml +++ b/tests/auto/declarative/qdeclarativebehaviors/data/binding.qml @@ -9,7 +9,7 @@ Rectangle { objectName: "MyRect" width: 100; height: 100; color: "green" x: basex - x: Behavior { NumberAnimation { duration: 500; } } + Behavior on x { NumberAnimation { duration: 500; } } } MouseArea { id: clicker diff --git a/tests/auto/declarative/qdeclarativebehaviors/data/color.qml b/tests/auto/declarative/qdeclarativebehaviors/data/color.qml index 91dbbd1..f2f4742 100644 --- a/tests/auto/declarative/qdeclarativebehaviors/data/color.qml +++ b/tests/auto/declarative/qdeclarativebehaviors/data/color.qml @@ -7,7 +7,7 @@ Rectangle { objectName: "MyRect" width: 100; height: 100; color: "green" - color: Behavior { ColorAnimation { duration: 500; } } + Behavior on color { ColorAnimation { duration: 500; } } } MouseArea { id: clicker diff --git a/tests/auto/declarative/qdeclarativebehaviors/data/cpptrigger.qml b/tests/auto/declarative/qdeclarativebehaviors/data/cpptrigger.qml index 8d032f0..3ea9376 100644 --- a/tests/auto/declarative/qdeclarativebehaviors/data/cpptrigger.qml +++ b/tests/auto/declarative/qdeclarativebehaviors/data/cpptrigger.qml @@ -6,6 +6,6 @@ Rectangle { id: rect objectName: "MyRect" width: 100; height: 100; color: "green" - x: Behavior { NumberAnimation { duration: 500; } } + Behavior on x { NumberAnimation { duration: 500; } } } } diff --git a/tests/auto/declarative/qdeclarativebehaviors/data/disabled.qml b/tests/auto/declarative/qdeclarativebehaviors/data/disabled.qml index 3c7078a..1403eb9 100644 --- a/tests/auto/declarative/qdeclarativebehaviors/data/disabled.qml +++ b/tests/auto/declarative/qdeclarativebehaviors/data/disabled.qml @@ -6,7 +6,7 @@ Rectangle { id: rect objectName: "MyRect" width: 100; height: 100; color: "green" - x: Behavior { + Behavior on x { objectName: "MyBehavior"; enabled: false NumberAnimation { duration: 200; } diff --git a/tests/auto/declarative/qdeclarativebehaviors/data/dontStart.qml b/tests/auto/declarative/qdeclarativebehaviors/data/dontStart.qml index ba7cc9c..12b1b7b 100644 --- a/tests/auto/declarative/qdeclarativebehaviors/data/dontStart.qml +++ b/tests/auto/declarative/qdeclarativebehaviors/data/dontStart.qml @@ -9,7 +9,7 @@ Rectangle { id: redRect width: 100; height: 100 color: Qt.rgba(1,0,0) - x: Behavior { + Behavior on x { NumberAnimation { objectName: "MyAnim"; running: true } } diff --git a/tests/auto/declarative/qdeclarativebehaviors/data/empty.qml b/tests/auto/declarative/qdeclarativebehaviors/data/empty.qml index 95d934a..5e30f03 100644 --- a/tests/auto/declarative/qdeclarativebehaviors/data/empty.qml +++ b/tests/auto/declarative/qdeclarativebehaviors/data/empty.qml @@ -6,7 +6,7 @@ Rectangle { id: rect objectName: "MyRect" width: 100; height: 100; color: "green" - x: Behavior {} + Behavior on x {} } MouseArea { id: clicker diff --git a/tests/auto/declarative/qdeclarativebehaviors/data/explicit.qml b/tests/auto/declarative/qdeclarativebehaviors/data/explicit.qml index 1b2025a..ca0ea54 100644 --- a/tests/auto/declarative/qdeclarativebehaviors/data/explicit.qml +++ b/tests/auto/declarative/qdeclarativebehaviors/data/explicit.qml @@ -6,7 +6,7 @@ Rectangle { id: rect objectName: "MyRect" width: 100; height: 100; color: "green" - x: Behavior { + Behavior on x { objectName: "MyBehavior"; NumberAnimation { target: rect; property: "x"; duration: 500; } } diff --git a/tests/auto/declarative/qdeclarativebehaviors/data/groupProperty.qml b/tests/auto/declarative/qdeclarativebehaviors/data/groupProperty.qml index 14883d4..a6c4ed9 100644 --- a/tests/auto/declarative/qdeclarativebehaviors/data/groupProperty.qml +++ b/tests/auto/declarative/qdeclarativebehaviors/data/groupProperty.qml @@ -6,7 +6,7 @@ Rectangle { id: rect objectName: "MyRect" width: 100; height: 100; color: "green" - pos: Behavior { PropertyAnimation { duration: 500; } } + Behavior on pos { PropertyAnimation { duration: 500; } } } MouseArea { id: clicker diff --git a/tests/auto/declarative/qdeclarativebehaviors/data/groupProperty2.qml b/tests/auto/declarative/qdeclarativebehaviors/data/groupProperty2.qml index b43ddbc..2dda220 100644 --- a/tests/auto/declarative/qdeclarativebehaviors/data/groupProperty2.qml +++ b/tests/auto/declarative/qdeclarativebehaviors/data/groupProperty2.qml @@ -6,7 +6,7 @@ Rectangle { id: rect objectName: "MyRect" width: 100; height: 100; color: "green" - pos.x: Behavior { NumberAnimation { duration: 500; } } + Behavior on pos.x { NumberAnimation { duration: 500; } } } MouseArea { id: clicker diff --git a/tests/auto/declarative/qdeclarativebehaviors/data/loop.qml b/tests/auto/declarative/qdeclarativebehaviors/data/loop.qml index 5f2c057..6187768 100644 --- a/tests/auto/declarative/qdeclarativebehaviors/data/loop.qml +++ b/tests/auto/declarative/qdeclarativebehaviors/data/loop.qml @@ -6,7 +6,7 @@ Rectangle { id: rect objectName: "MyRect" width: 100; height: 100; color: "green" - x: Behavior { NumberAnimation { duration: 200; } } + Behavior on x { NumberAnimation { duration: 200; } } onXChanged: x = 100; } states: State { diff --git a/tests/auto/declarative/qdeclarativebehaviors/data/nonSelecting2.qml b/tests/auto/declarative/qdeclarativebehaviors/data/nonSelecting2.qml index f267a05..640a7d1 100644 --- a/tests/auto/declarative/qdeclarativebehaviors/data/nonSelecting2.qml +++ b/tests/auto/declarative/qdeclarativebehaviors/data/nonSelecting2.qml @@ -6,7 +6,7 @@ Rectangle { id: rect objectName: "MyRect" width: 100; height: 100; color: "green" - x: Behavior { + Behavior on x { objectName: "MyBehavior"; NumberAnimation { targets: rect; properties: "y"; duration: 200; } } diff --git a/tests/auto/declarative/qdeclarativebehaviors/data/parent.qml b/tests/auto/declarative/qdeclarativebehaviors/data/parent.qml index 7c7fdcb..3860ec7 100644 --- a/tests/auto/declarative/qdeclarativebehaviors/data/parent.qml +++ b/tests/auto/declarative/qdeclarativebehaviors/data/parent.qml @@ -6,7 +6,7 @@ Rectangle { id: rect objectName: "MyRect" width: 100; height: 100; color: "green" - parent: Behavior { + Behavior on parent { SequentialAnimation { PauseAnimation { duration: 500 } PropertyAction {} diff --git a/tests/auto/declarative/qdeclarativebehaviors/data/reassignedAnimation.qml b/tests/auto/declarative/qdeclarativebehaviors/data/reassignedAnimation.qml index ba744b1..6419a6b 100644 --- a/tests/auto/declarative/qdeclarativebehaviors/data/reassignedAnimation.qml +++ b/tests/auto/declarative/qdeclarativebehaviors/data/reassignedAnimation.qml @@ -6,7 +6,7 @@ Rectangle { id: rect objectName: "MyRect" width: 100; height: 100; color: "green" - x: Behavior { + Behavior on x { objectName: "MyBehavior" NumberAnimation { duration: 200 } NumberAnimation { duration: 1000 } diff --git a/tests/auto/declarative/qdeclarativebehaviors/data/scripttrigger.qml b/tests/auto/declarative/qdeclarativebehaviors/data/scripttrigger.qml index a91ca88..b22441a 100644 --- a/tests/auto/declarative/qdeclarativebehaviors/data/scripttrigger.qml +++ b/tests/auto/declarative/qdeclarativebehaviors/data/scripttrigger.qml @@ -11,6 +11,6 @@ Rectangle { id: rect objectName: "MyRect" width: 100; height: 100; color: "green" - x: Behavior { NumberAnimation { duration: 500; } } + Behavior on x { NumberAnimation { duration: 500; } } } } diff --git a/tests/auto/declarative/qdeclarativebehaviors/data/simple.qml b/tests/auto/declarative/qdeclarativebehaviors/data/simple.qml index ac98ed0..c28fa9a 100644 --- a/tests/auto/declarative/qdeclarativebehaviors/data/simple.qml +++ b/tests/auto/declarative/qdeclarativebehaviors/data/simple.qml @@ -6,7 +6,7 @@ Rectangle { id: rect objectName: "MyRect" width: 100; height: 100; color: "green" - x: Behavior { + Behavior on x { objectName: "MyBehavior"; NumberAnimation { duration: 500; } } diff --git a/tests/auto/declarative/qdeclarativebehaviors/tst_qdeclarativebehaviors.cpp b/tests/auto/declarative/qdeclarativebehaviors/tst_qdeclarativebehaviors.cpp index f87330d..0bf0b81 100644 --- a/tests/auto/declarative/qdeclarativebehaviors/tst_qdeclarativebehaviors.cpp +++ b/tests/auto/declarative/qdeclarativebehaviors/tst_qdeclarativebehaviors.cpp @@ -260,7 +260,7 @@ void tst_qdeclarativebehaviors::reassignedAnimation() { QDeclarativeEngine engine; QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/reassignedAnimation.qml")); - QTest::ignoreMessage(QtWarningMsg, QString("QML Behavior (" + QUrl::fromLocalFile(SRCDIR "/data/reassignedAnimation.qml").toString() + ":9:12) Cannot change the animation assigned to a Behavior.").toUtf8().constData()); + QTest::ignoreMessage(QtWarningMsg, QString("QML Behavior (" + QUrl::fromLocalFile(SRCDIR "/data/reassignedAnimation.qml").toString() + ":9:9) Cannot change the animation assigned to a Behavior.").toUtf8().constData()); QDeclarativeRectangle *rect = qobject_cast(c.create()); QVERIFY(rect); QCOMPARE(qobject_cast( diff --git a/tests/auto/declarative/qdeclarativedom/tst_qdeclarativedom.cpp b/tests/auto/declarative/qdeclarativedom/tst_qdeclarativedom.cpp index 9543280..6cd0bdb 100644 --- a/tests/auto/declarative/qdeclarativedom/tst_qdeclarativedom.cpp +++ b/tests/auto/declarative/qdeclarativedom/tst_qdeclarativedom.cpp @@ -274,7 +274,7 @@ void tst_qdeclarativedom::loadComposite() void tst_qdeclarativedom::testValueSource() { QByteArray qml = "import Qt 4.6\n" - "Rectangle { height: SpringFollow { spring: 1.4; damping: .15; source: Math.min(Math.max(-130, value*2.2 - 130), 133); }}"; + "Rectangle { SpringFollow on height { spring: 1.4; damping: .15; source: Math.min(Math.max(-130, value*2.2 - 130), 133); }}"; QDeclarativeEngine freshEngine; QDeclarativeDomDocument document; @@ -306,7 +306,7 @@ void tst_qdeclarativedom::testValueSource() void tst_qdeclarativedom::testValueInterceptor() { QByteArray qml = "import Qt 4.6\n" - "Rectangle { height: Behavior { NumberAnimation { duration: 100 } } }"; + "Rectangle { Behavior on height { NumberAnimation { duration: 100 } } }"; QDeclarativeEngine freshEngine; QDeclarativeDomDocument document; @@ -823,8 +823,8 @@ void tst_qdeclarativedom::copy() " property int a: 10\n" " x: 10\n" " y: x + 10\n" - " z: NumberAnimation {}\n" - " opacity: Behavior {}\n" + " NumberAnimation on z {}\n" + " Behavior on opacity {}\n" " Component {\n" " Item{}\n" " }\n" @@ -1193,18 +1193,18 @@ void tst_qdeclarativedom::copy() void tst_qdeclarativedom::position() { QByteArray qml = "import Qt 4.6\n" - /*14*/ "Item {\n" - /*21*/ " id: myItem\n" - /*36*/ " property int a: 10\n" - /*59*/ " x: 10\n" - /*69*/ " y: x + 10\n" - /*83*/ " z: NumberAnimation {}\n" - /*109*/ " opacity: Behavior {}\n" - /*134*/ " Component {\n" - /*150*/ " Item{}\n" - /*165*/ " }\n" - /*171*/ " children: [ Item{}, Item{} ]\n" - /*204*/ "}\n"; + "Item {\n" + " id: myItem\n" + " property int a: 10\n" + " x: 10\n" + " y: x + 10\n" + " NumberAnimation on z {}\n" + " Behavior on opacity {}\n" + " Component {\n" + " Item{}\n" + " }\n" + " children: [ Item{}, Item{} ]\n" + "}\n"; QDeclarativeDomDocument document; @@ -1227,19 +1227,19 @@ void tst_qdeclarativedom::position() QCOMPARE(y.length(), 1); QDeclarativeDomProperty z = root.property("z"); - QCOMPARE(z.position(), 87); + QCOMPARE(z.position(), 106); QCOMPARE(z.length(), 1); QDeclarativeDomProperty opacity = root.property("opacity"); - QCOMPARE(opacity.position(), 113); + QCOMPARE(opacity.position(), 127); QCOMPARE(opacity.length(), 7); QDeclarativeDomProperty data = root.property("data"); - QCOMPARE(data.position(), 138); + QCOMPARE(data.position(), 142); QCOMPARE(data.length(), 0); QDeclarativeDomProperty children = root.property("children"); - QCOMPARE(children.position(), 175); + QCOMPARE(children.position(), 179); QCOMPARE(children.length(), 8); QDeclarativeDomList dataList = data.value().toList(); @@ -1249,30 +1249,30 @@ void tst_qdeclarativedom::position() // All QDeclarativeDomObject QCOMPARE(root.position(), 14); - QCOMPARE(root.length(), 191); + QCOMPARE(root.length(), 195); QDeclarativeDomObject numberAnimation = z.value().toValueSource().object(); - QCOMPARE(numberAnimation.position(), 90); - QCOMPARE(numberAnimation.length(), 18); + QCOMPARE(numberAnimation.position(), 87); + QCOMPARE(numberAnimation.length(), 23); QDeclarativeDomObject behavior = opacity.value().toValueInterceptor().object(); - QCOMPARE(behavior.position(), 122); - QCOMPARE(behavior.length(), 11); + QCOMPARE(behavior.position(), 115); + QCOMPARE(behavior.length(), 22); QDeclarativeDomObject component = dataList.values().at(0).toObject(); - QCOMPARE(component.position(), 138); + QCOMPARE(component.position(), 142); QCOMPARE(component.length(), 32); QDeclarativeDomObject componentRoot = component.toComponent().componentRoot(); - QCOMPARE(componentRoot.position(), 158); + QCOMPARE(componentRoot.position(), 162); QCOMPARE(componentRoot.length(), 6); QDeclarativeDomObject child1 = childrenList.values().at(0).toObject(); - QCOMPARE(child1.position(), 187); + QCOMPARE(child1.position(), 191); QCOMPARE(child1.length(), 6); QDeclarativeDomObject child2 = childrenList.values().at(1).toObject(); - QCOMPARE(child2.position(), 195); + QCOMPARE(child2.position(), 199); QCOMPARE(child2.length(), 6); // All QDeclarativeDomValue @@ -1285,23 +1285,23 @@ void tst_qdeclarativedom::position() QCOMPARE(yValue.length(), 6); QDeclarativeDomValue zValue = z.value(); - QCOMPARE(zValue.position(), 90); - QCOMPARE(zValue.length(), 18); + QCOMPARE(zValue.position(), 87); + QCOMPARE(zValue.length(), 23); QDeclarativeDomValue opacityValue = opacity.value(); - QCOMPARE(opacityValue.position(), 122); - QCOMPARE(opacityValue.length(), 11); + QCOMPARE(opacityValue.position(), 115); + QCOMPARE(opacityValue.length(), 22); QDeclarativeDomValue dataValue = data.value(); - QCOMPARE(dataValue.position(), 138); + QCOMPARE(dataValue.position(), 142); QCOMPARE(dataValue.length(), 32); QDeclarativeDomValue child1Value = childrenList.values().at(0); - QCOMPARE(child1Value.position(), 187); + QCOMPARE(child1Value.position(), 191); QCOMPARE(child1Value.length(), 6); QDeclarativeDomValue child2Value = childrenList.values().at(1); - QCOMPARE(child2Value.position(), 195); + QCOMPARE(child2Value.position(), 199); QCOMPARE(child2Value.length(), 6); // All QDeclarativeDomList diff --git a/tests/auto/declarative/qdeclarativelanguage/data/assignBasicTypes.qml b/tests/auto/declarative/qdeclarativelanguage/data/assignBasicTypes.qml index c86c96b..9fe0ded 100644 --- a/tests/auto/declarative/qdeclarativelanguage/data/assignBasicTypes.qml +++ b/tests/auto/declarative/qdeclarativelanguage/data/assignBasicTypes.qml @@ -10,8 +10,6 @@ MyTypeObject { floatProperty: 8.5 colorProperty: "red" dateProperty: "1982-11-25" - timeProperty: "11:11:31" - timeProperty: "11:11:32" timeProperty: "11:11:32" dateTimeProperty: "2009-05-12T13:22:01" pointProperty: "99,13" diff --git a/tests/auto/declarative/qdeclarativelanguage/data/component.3.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/component.3.errors.txt index 9a13142..450fc16 100644 --- a/tests/auto/declarative/qdeclarativelanguage/data/component.3.errors.txt +++ b/tests/auto/declarative/qdeclarativelanguage/data/component.3.errors.txt @@ -1 +1 @@ -6:9:Invalid component id specification +6:9:Property value set multiple times diff --git a/tests/auto/declarative/qdeclarativelanguage/data/doubleSignal.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/doubleSignal.errors.txt index 2aea251..e1f7ec5 100644 --- a/tests/auto/declarative/qdeclarativelanguage/data/doubleSignal.errors.txt +++ b/tests/auto/declarative/qdeclarativelanguage/data/doubleSignal.errors.txt @@ -1 +1 @@ -5:5:Incorrectly specified signal +5:5:Property value set multiple times diff --git a/tests/auto/declarative/qdeclarativelanguage/data/invalidGroupedProperty.6.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/invalidGroupedProperty.6.errors.txt index 8331725..e1f7ec5 100644 --- a/tests/auto/declarative/qdeclarativelanguage/data/invalidGroupedProperty.6.errors.txt +++ b/tests/auto/declarative/qdeclarativelanguage/data/invalidGroupedProperty.6.errors.txt @@ -1 +1 @@ -5:18:Single property assignment expected +5:5:Property value set multiple times diff --git a/tests/auto/declarative/qdeclarativelanguage/data/invalidID.4.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/invalidID.4.errors.txt index cfe8756..c721fe9 100644 --- a/tests/auto/declarative/qdeclarativelanguage/data/invalidID.4.errors.txt +++ b/tests/auto/declarative/qdeclarativelanguage/data/invalidID.4.errors.txt @@ -1 +1 @@ -4:5:Invalid use of id property +4:5:Property value set multiple times diff --git a/tests/auto/declarative/qdeclarativelanguage/data/listAssignment.3.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/listAssignment.3.errors.txt index 8c7b7e9..c721fe9 100644 --- a/tests/auto/declarative/qdeclarativelanguage/data/listAssignment.3.errors.txt +++ b/tests/auto/declarative/qdeclarativelanguage/data/listAssignment.3.errors.txt @@ -1 +1 @@ -4:15:Can only assign one binding to lists +4:5:Property value set multiple times diff --git a/tests/auto/declarative/qdeclarativelanguage/data/multiSet.1.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/multiSet.1.errors.txt new file mode 100644 index 0000000..e1f7ec5 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/multiSet.1.errors.txt @@ -0,0 +1 @@ +5:5:Property value set multiple times diff --git a/tests/auto/declarative/qdeclarativelanguage/data/multiSet.1.qml b/tests/auto/declarative/qdeclarativelanguage/data/multiSet.1.qml new file mode 100644 index 0000000..649c49e --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/multiSet.1.qml @@ -0,0 +1,7 @@ +import Test 1.0 + +MyTypeObject { + intProperty: 10 + intProperty: 11 +} + diff --git a/tests/auto/declarative/qdeclarativelanguage/data/multiSet.10.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/multiSet.10.errors.txt new file mode 100644 index 0000000..e1f7ec5 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/multiSet.10.errors.txt @@ -0,0 +1 @@ +5:5:Property value set multiple times diff --git a/tests/auto/declarative/qdeclarativelanguage/data/multiSet.10.qml b/tests/auto/declarative/qdeclarativelanguage/data/multiSet.10.qml new file mode 100644 index 0000000..bc21db9 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/multiSet.10.qml @@ -0,0 +1,6 @@ +import Test 1.0 + +MyTypeObject { + property int a: 10 + a: 11 +} diff --git a/tests/auto/declarative/qdeclarativelanguage/data/multiSet.2.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/multiSet.2.errors.txt new file mode 100644 index 0000000..e1f7ec5 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/multiSet.2.errors.txt @@ -0,0 +1 @@ +5:5:Property value set multiple times diff --git a/tests/auto/declarative/qdeclarativelanguage/data/multiSet.2.qml b/tests/auto/declarative/qdeclarativelanguage/data/multiSet.2.qml new file mode 100644 index 0000000..abcd216 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/multiSet.2.qml @@ -0,0 +1,7 @@ +import Test 1.0 + +MyTypeObject { + intProperty: 10 + intProperty: a + 10 +} + diff --git a/tests/auto/declarative/qdeclarativelanguage/data/multiSet.3.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/multiSet.3.errors.txt new file mode 100644 index 0000000..e1f7ec5 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/multiSet.3.errors.txt @@ -0,0 +1 @@ +5:5:Property value set multiple times diff --git a/tests/auto/declarative/qdeclarativelanguage/data/multiSet.3.qml b/tests/auto/declarative/qdeclarativelanguage/data/multiSet.3.qml new file mode 100644 index 0000000..77eaba0 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/multiSet.3.qml @@ -0,0 +1,7 @@ +import Test 1.0 + +MyTypeObject { + intProperty: a + 10 + intProperty: 10 +} + diff --git a/tests/auto/declarative/qdeclarativelanguage/data/multiSet.4.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/multiSet.4.errors.txt new file mode 100644 index 0000000..e1f7ec5 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/multiSet.4.errors.txt @@ -0,0 +1 @@ +5:5:Property value set multiple times diff --git a/tests/auto/declarative/qdeclarativelanguage/data/multiSet.4.qml b/tests/auto/declarative/qdeclarativelanguage/data/multiSet.4.qml new file mode 100644 index 0000000..c16d04f --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/multiSet.4.qml @@ -0,0 +1,7 @@ +import Test 1.0 + +MyTypeObject { + intProperty: 10 + intProperty: MyTypeObject {} +} + diff --git a/tests/auto/declarative/qdeclarativelanguage/data/multiSet.5.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/multiSet.5.errors.txt new file mode 100644 index 0000000..e1f7ec5 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/multiSet.5.errors.txt @@ -0,0 +1 @@ +5:5:Property value set multiple times diff --git a/tests/auto/declarative/qdeclarativelanguage/data/multiSet.5.qml b/tests/auto/declarative/qdeclarativelanguage/data/multiSet.5.qml new file mode 100644 index 0000000..2980c5b --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/multiSet.5.qml @@ -0,0 +1,6 @@ +import Test 1.0 + +MyContainer { + children: MyContainer {} + children: MyContainer {} +} diff --git a/tests/auto/declarative/qdeclarativelanguage/data/multiSet.6.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/multiSet.6.errors.txt new file mode 100644 index 0000000..e1f7ec5 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/multiSet.6.errors.txt @@ -0,0 +1 @@ +5:5:Property value set multiple times diff --git a/tests/auto/declarative/qdeclarativelanguage/data/multiSet.6.qml b/tests/auto/declarative/qdeclarativelanguage/data/multiSet.6.qml new file mode 100644 index 0000000..492c720 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/multiSet.6.qml @@ -0,0 +1,7 @@ +import Test 1.0 + +MyContainer { + children: MyContainer {} + children: [ MyContainer {}, MyContainer {} ] +} + diff --git a/tests/auto/declarative/qdeclarativelanguage/data/multiSet.7.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/multiSet.7.errors.txt new file mode 100644 index 0000000..e1f7ec5 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/multiSet.7.errors.txt @@ -0,0 +1 @@ +5:5:Property value set multiple times diff --git a/tests/auto/declarative/qdeclarativelanguage/data/multiSet.7.qml b/tests/auto/declarative/qdeclarativelanguage/data/multiSet.7.qml new file mode 100644 index 0000000..2a9c1d0 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/multiSet.7.qml @@ -0,0 +1,7 @@ +import Test 1.0 + +MyContainer { + children: [ MyContainer {}, MyContainer {} ] + children: MyContainer {} +} + diff --git a/tests/auto/declarative/qdeclarativelanguage/data/multiSet.8.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/multiSet.8.errors.txt new file mode 100644 index 0000000..450fc16 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/multiSet.8.errors.txt @@ -0,0 +1 @@ +6:9:Property value set multiple times diff --git a/tests/auto/declarative/qdeclarativelanguage/data/multiSet.8.qml b/tests/auto/declarative/qdeclarativelanguage/data/multiSet.8.qml new file mode 100644 index 0000000..052437e --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/multiSet.8.qml @@ -0,0 +1,8 @@ +import Test 1.0 + +MyTypeObject { + grouped { + value: 10 + value: 11 + } +} diff --git a/tests/auto/declarative/qdeclarativelanguage/data/multiSet.9.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/multiSet.9.errors.txt new file mode 100644 index 0000000..e1f7ec5 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/multiSet.9.errors.txt @@ -0,0 +1 @@ +5:5:Property value set multiple times diff --git a/tests/auto/declarative/qdeclarativelanguage/data/multiSet.9.qml b/tests/auto/declarative/qdeclarativelanguage/data/multiSet.9.qml new file mode 100644 index 0000000..e2e954f --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/multiSet.9.qml @@ -0,0 +1,6 @@ +import Test 1.0 + +MyTypeObject { + grouped.value: 10 + grouped.value: 11 +} diff --git a/tests/auto/declarative/qdeclarativelanguage/data/propertyValueSource.2.qml b/tests/auto/declarative/qdeclarativelanguage/data/propertyValueSource.2.qml index 57a6070..e48526a 100644 --- a/tests/auto/declarative/qdeclarativelanguage/data/propertyValueSource.2.qml +++ b/tests/auto/declarative/qdeclarativelanguage/data/propertyValueSource.2.qml @@ -1,5 +1,5 @@ import Test 1.0 MyTypeObject { - intProperty : MyCompositeValueSource {} + MyCompositeValueSource on intProperty {} } diff --git a/tests/auto/declarative/qdeclarativelanguage/data/propertyValueSource.qml b/tests/auto/declarative/qdeclarativelanguage/data/propertyValueSource.qml index ad71fcf..22aa682 100644 --- a/tests/auto/declarative/qdeclarativelanguage/data/propertyValueSource.qml +++ b/tests/auto/declarative/qdeclarativelanguage/data/propertyValueSource.qml @@ -1,4 +1,4 @@ import Test 1.0 MyTypeObject { - intProperty : MyPropertyValueSource {} + MyPropertyValueSource on intProperty {} } diff --git a/tests/auto/declarative/qdeclarativelanguage/data/script.8.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/script.8.errors.txt index b5bf1a8..450fc16 100644 --- a/tests/auto/declarative/qdeclarativelanguage/data/script.8.errors.txt +++ b/tests/auto/declarative/qdeclarativelanguage/data/script.8.errors.txt @@ -1 +1 @@ -6:9:Invalid Script source value +6:9:Property value set multiple times diff --git a/tests/auto/declarative/qdeclarativelanguage/testtypes.h b/tests/auto/declarative/qdeclarativelanguage/testtypes.h index 8ac7aa6..ec2c5f7 100644 --- a/tests/auto/declarative/qdeclarativelanguage/testtypes.h +++ b/tests/auto/declarative/qdeclarativelanguage/testtypes.h @@ -166,11 +166,16 @@ class MyGroupedObject : public QObject { Q_OBJECT Q_PROPERTY(QDeclarativeScriptString script READ script WRITE setScript); + Q_PROPERTY(int value READ value WRITE setValue); public: QDeclarativeScriptString script() const { return m_script; } void setScript(const QDeclarativeScriptString &s) { m_script = s; } + int value() const { return m_value; } + void setValue(int v) { m_value = v; } + private: + int m_value; QDeclarativeScriptString m_script; }; diff --git a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp index 1ba4454..39f5223 100644 --- a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp +++ b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp @@ -288,6 +288,17 @@ void tst_qdeclarativelanguage::errors_data() QTest::newRow("Component.5") << "component.5.qml" << "component.5.errors.txt" << false; QTest::newRow("Component.6") << "component.6.qml" << "component.6.errors.txt" << false; + QTest::newRow("MultiSet.1") << "multiSet.1.qml" << "multiSet.1.errors.txt" << false; + QTest::newRow("MultiSet.2") << "multiSet.2.qml" << "multiSet.2.errors.txt" << false; + QTest::newRow("MultiSet.3") << "multiSet.3.qml" << "multiSet.3.errors.txt" << false; + QTest::newRow("MultiSet.4") << "multiSet.4.qml" << "multiSet.4.errors.txt" << false; + QTest::newRow("MultiSet.5") << "multiSet.5.qml" << "multiSet.5.errors.txt" << false; + QTest::newRow("MultiSet.6") << "multiSet.6.qml" << "multiSet.6.errors.txt" << false; + QTest::newRow("MultiSet.7") << "multiSet.7.qml" << "multiSet.7.errors.txt" << false; + QTest::newRow("MultiSet.8") << "multiSet.8.qml" << "multiSet.8.errors.txt" << false; + QTest::newRow("MultiSet.9") << "multiSet.9.qml" << "multiSet.9.errors.txt" << false; + QTest::newRow("MultiSet.10") << "multiSet.10.qml" << "multiSet.10.errors.txt" << false; + QTest::newRow("invalidAttachedProperty.1") << "invalidAttachedProperty.1.qml" << "invalidAttachedProperty.1.errors.txt" << false; QTest::newRow("invalidAttachedProperty.2") << "invalidAttachedProperty.2.qml" << "invalidAttachedProperty.2.errors.txt" << false; QTest::newRow("invalidAttachedProperty.3") << "invalidAttachedProperty.3.qml" << "invalidAttachedProperty.3.errors.txt" << false; diff --git a/tests/auto/declarative/qdeclarativeparticles/data/particles.qml b/tests/auto/declarative/qdeclarativeparticles/data/particles.qml index c58927e..0d42645 100644 --- a/tests/auto/declarative/qdeclarativeparticles/data/particles.qml +++ b/tests/auto/declarative/qdeclarativeparticles/data/particles.qml @@ -8,7 +8,7 @@ Rectangle{ objectName: "particles" width:1; height:1; anchors.centerIn: parent; opacity: 1 lifeSpan: 100; lifeSpanDeviation: 20; count:1000; - fadeInDuration: 20; fadeOutDuration: 20; count: -1; emissionRate: 1000 + fadeInDuration: 20; fadeOutDuration: 20; emissionRate: 1000 angle: 0; angleDeviation: 360; velocity: 500; velocityDeviation:30 source: "particle.png" } diff --git a/tests/auto/declarative/qdeclarativepathview/data/pathview2.qml b/tests/auto/declarative/qdeclarativepathview/data/pathview2.qml index 0d5c98b..c825292 100644 --- a/tests/auto/declarative/qdeclarativepathview/data/pathview2.qml +++ b/tests/auto/declarative/qdeclarativepathview/data/pathview2.qml @@ -1,7 +1,7 @@ import Qt 4.6 PathView { - id: photoPathView; model: rssModel; delegate: photoDelegate + id: photoPathView y: 100; width: 800; height: 330; pathItemCount: 10; z: 1 path: Path { diff --git a/tests/auto/declarative/qdeclarativepathview/data/pathview3.qml b/tests/auto/declarative/qdeclarativepathview/data/pathview3.qml index 412cca2..af3ae13 100644 --- a/tests/auto/declarative/qdeclarativepathview/data/pathview3.qml +++ b/tests/auto/declarative/qdeclarativepathview/data/pathview3.qml @@ -1,7 +1,7 @@ import Qt 4.6 PathView { - id: photoPathView; model: rssModel; delegate: photoDelegate + id: photoPathView y: 100; width: 800; height: 330; pathItemCount: 4; offset: 10 dragMargin: 24; snapPosition: 50 diff --git a/tests/auto/declarative/qdeclarativevaluetypes/data/valueInterceptors.qml b/tests/auto/declarative/qdeclarativevaluetypes/data/valueInterceptors.qml index 026ae83..0897847 100644 --- a/tests/auto/declarative/qdeclarativevaluetypes/data/valueInterceptors.qml +++ b/tests/auto/declarative/qdeclarativevaluetypes/data/valueInterceptors.qml @@ -3,6 +3,6 @@ import Test 1.0 MyTypeObject { property int value: 13; - rect.x: MyOffsetValueInterceptor {} + MyOffsetValueInterceptor on rect.x {} rect.x: value } diff --git a/tests/auto/declarative/qdeclarativevaluetypes/data/valueSources.qml b/tests/auto/declarative/qdeclarativevaluetypes/data/valueSources.qml index d4d4391..717f350 100644 --- a/tests/auto/declarative/qdeclarativevaluetypes/data/valueSources.qml +++ b/tests/auto/declarative/qdeclarativevaluetypes/data/valueSources.qml @@ -1,5 +1,5 @@ import Test 1.0 MyTypeObject { - rect.x: MyConstantValueSource {} + MyConstantValueSource on rect.x {} } diff --git a/tests/auto/declarative/qdeclarativevaluetypes/tst_qdeclarativevaluetypes.cpp b/tests/auto/declarative/qdeclarativevaluetypes/tst_qdeclarativevaluetypes.cpp index 69646b9..8732215 100644 --- a/tests/auto/declarative/qdeclarativevaluetypes/tst_qdeclarativevaluetypes.cpp +++ b/tests/auto/declarative/qdeclarativevaluetypes/tst_qdeclarativevaluetypes.cpp @@ -502,10 +502,9 @@ void tst_qdeclarativevaluetypes::valueInterceptors() QDeclarativeComponent component(&engine, TEST_FILE("valueInterceptors.qml")); MyTypeObject *object = qobject_cast(component.create()); checkNoErrors(component); - QEXPECT_FAIL("", "QT-2920", Abort); QVERIFY(object != 0); - QCOMPARE(object->rect().x(), 26); + QCOMPARE(object->rect().x(), 13); object->setProperty("value", 99); diff --git a/tools/qml/qfxtester.h b/tools/qml/qfxtester.h index 1a9f077..6521409 100644 --- a/tools/qml/qfxtester.h +++ b/tools/qml/qfxtester.h @@ -54,12 +54,12 @@ QT_BEGIN_NAMESPACE class QDeclarativeVisualTest : public QObject { Q_OBJECT - Q_PROPERTY(QList* events READ events CONSTANT) + Q_PROPERTY(QDeclarativeListProperty events READ events CONSTANT) Q_CLASSINFO("DefaultProperty", "events") public: QDeclarativeVisualTest() {} - QList *events() { return &m_events; } + QDeclarativeListProperty events() { return QDeclarativeListProperty(this, m_events); } int count() const { return m_events.count(); } QObject *event(int idx) { return m_events.at(idx); } -- cgit v0.12 From a9d327db7e77cc167172ad3199b6ffbc1c9da74f Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 2 Mar 2010 11:17:02 +1000 Subject: Add accessor operations to VisualItemModel::children --- src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp index 59d6db8..a0aed46 100644 --- a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp +++ b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp @@ -81,6 +81,14 @@ public: static_cast(prop->data)->emitChildrenChanged(); } + static int children_count(QDeclarativeListProperty *prop) { + return static_cast(prop->data)->children.count(); + } + + static QDeclarativeItem *children_at(QDeclarativeListProperty *prop, int index) { + return static_cast(prop->data)->children.at(index); + } + void itemAppended() { Q_Q(QDeclarativeVisualItemModel); QDeclarativeVisualItemModelAttached *attached = QDeclarativeVisualItemModelAttached::properties(children.last()); @@ -136,7 +144,8 @@ QDeclarativeVisualItemModel::QDeclarativeVisualItemModel() QDeclarativeListProperty QDeclarativeVisualItemModel::children() { Q_D(QDeclarativeVisualItemModel); - return QDeclarativeListProperty(this, d, QDeclarativeVisualItemModelPrivate::children_append); + return QDeclarativeListProperty(this, d, d->children_append, + d->children_count, d->children_at); } /*! -- cgit v0.12 From ffe622b5424bd13155fea01116ed6504f06d9d83 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Mon, 1 Mar 2010 15:55:03 +1000 Subject: Example of text focus. Task-number: QT-448 --- examples/declarative/focusscope/test5.qml | 83 +++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 examples/declarative/focusscope/test5.qml diff --git a/examples/declarative/focusscope/test5.qml b/examples/declarative/focusscope/test5.qml new file mode 100644 index 0000000..da98350 --- /dev/null +++ b/examples/declarative/focusscope/test5.qml @@ -0,0 +1,83 @@ +import Qt 4.6 + +Rectangle { + color: "white" + width: 800 + height: 600 + + Keys.onReturnPressed: console.log("Error - Root") + + FocusScope { + id: myScope + focus: true + + Keys.onReturnPressed: console.log("Error - FocusScope") + + Rectangle { + height: 120 + width: 420 + + color: "transparent" + border.width: 5 + border.color: myScope.wantsFocus?"blue":"black" + + Rectangle { + x: 10; y: 10 + width: 100; height: 100; color: "green" + border.width: 5 + border.color: item1.wantsFocus?"blue":"black" + } + + TextEdit { + id: item1 + x: 20; y: 20 + width: 90; height: 90 + color: "white" + font.pixelSize: 20 + Keys.onReturnPressed: console.log("Top Left"); + KeyNavigation.right: item2 + focus: true + wrap: true + text: "Box 1" + } + + Rectangle { + id: item2 + x: 310; y: 10 + width: 100; height: 100; color: "green" + border.width: 5 + border.color: wantsFocus?"blue":"black" + KeyNavigation.left: item1 + Keys.onReturnPressed: console.log("Top Right"); + + Rectangle { + width: 50; height: 50; anchors.centerIn: parent + color: parent.focus?"red":"transparent" + } + } + } + KeyNavigation.down: item3 + } + + Text { x:100; y:170; text: "Blue border indicates scoped focus\nBlack border indicates NOT scoped focus\nRed box or flashing cursor indicates active focus\nUse arrow keys to navigate\nPress Ctrl-Return to print currently focused item" } + + Rectangle { + x: 10; y: 300 + width: 100; height: 100; color: "green" + border.width: 5 + border.color: item3.wantsFocus?"blue":"black" + } + + TextEdit { + id: item3 + x: 20; y: 310 + width: 90; height: 90 + color: "white" + font.pixelSize: 20 + text: "Box 3" + + Keys.onReturnPressed: console.log("Bottom Left"); + KeyNavigation.up: myScope + wrap: true + } +} -- cgit v0.12 From 2de0a9ff40c6dcbfca5dc75aae7ac0a294618f4a Mon Sep 17 00:00:00 2001 From: Joona Petrell Date: Fri, 26 Feb 2010 16:34:28 +1000 Subject: Add NOTIFY signals to list, grid and path views Reviewed-by: akennedy --- .../graphicsitems/qdeclarativegridview.cpp | 12 +- .../graphicsitems/qdeclarativegridview_p.h | 20 ++- .../graphicsitems/qdeclarativelistview.cpp | 24 ++- .../graphicsitems/qdeclarativelistview_p.h | 38 +++-- src/declarative/graphicsitems/qdeclarativepath.cpp | 11 +- src/declarative/graphicsitems/qdeclarativepath_p.h | 11 +- .../graphicsitems/qdeclarativepathview.cpp | 26 +++- .../graphicsitems/qdeclarativepathview_p.h | 18 ++- .../qdeclarativegridview/data/propertychanges.qml | 69 +++++++++ .../tst_qdeclarativegridview.cpp | 125 +++++++++++++-- .../qdeclarativelistview/data/propertychanges.qml | 71 +++++++++ .../tst_qdeclarativelistview.cpp | 168 +++++++++++++++++++-- .../qdeclarativepathview/data/displaypath.qml | 2 +- .../qdeclarativepathview/data/pathview.qml | 2 +- .../qdeclarativepathview/data/pathview3.qml | 2 +- .../qdeclarativepathview/data/propertychanges.qml | 115 ++++++++++++++ .../tst_qdeclarativepathview.cpp | 167 +++++++++++++++++++- 17 files changed, 815 insertions(+), 66 deletions(-) create mode 100644 tests/auto/declarative/qdeclarativegridview/data/propertychanges.qml create mode 100644 tests/auto/declarative/qdeclarativelistview/data/propertychanges.qml create mode 100644 tests/auto/declarative/qdeclarativepathview/data/propertychanges.qml diff --git a/src/declarative/graphicsitems/qdeclarativegridview.cpp b/src/declarative/graphicsitems/qdeclarativegridview.cpp index b43b30b..a7376cc 100644 --- a/src/declarative/graphicsitems/qdeclarativegridview.cpp +++ b/src/declarative/graphicsitems/qdeclarativegridview.cpp @@ -618,7 +618,7 @@ void QDeclarativeGridViewPrivate::createHighlight() } } if (changed) - emit q->highlightChanged(); + emit q->highlightItemChanged(); } void QDeclarativeGridViewPrivate::updateHighlight() @@ -784,6 +784,8 @@ QVariant QDeclarativeGridView::model() const void QDeclarativeGridView::setModel(const QVariant &model) { Q_D(QDeclarativeGridView); + if (d->modelVariant == model) + return; if (d->model) { disconnect(d->model, SIGNAL(itemsInserted(int,int)), this, SLOT(itemsInserted(int,int))); disconnect(d->model, SIGNAL(itemsRemoved(int,int)), this, SLOT(itemsRemoved(int,int))); @@ -828,6 +830,7 @@ void QDeclarativeGridView::setModel(const QVariant &model) connect(d->model, SIGNAL(destroyingItem(QDeclarativeItem*)), this, SLOT(destroyingItem(QDeclarativeItem*))); emit countChanged(); } + emit modelChanged(); } /*! @@ -871,6 +874,7 @@ void QDeclarativeGridView::setDelegate(QDeclarativeComponent *delegate) d->moveReason = QDeclarativeGridViewPrivate::SetIndex; d->updateCurrent(d->currentIndex); } + emit delegateChanged(); } } @@ -966,6 +970,7 @@ void QDeclarativeGridView::setHighlight(QDeclarativeComponent *highlight) if (highlight != d->highlightComponent) { d->highlightComponent = highlight; d->updateCurrent(d->currentIndex); + emit highlightChanged(); } } @@ -1039,6 +1044,7 @@ void QDeclarativeGridView::setFlow(Flow flow) d->updateGrid(); refill(); d->updateCurrent(d->currentIndex); + emit flowChanged(); } } @@ -1058,7 +1064,10 @@ bool QDeclarativeGridView::isWrapEnabled() const void QDeclarativeGridView::setWrapEnabled(bool wrap) { Q_D(QDeclarativeGridView); + if (d->wrap == wrap) + return; d->wrap = wrap; + emit keyNavigationWrapsChanged(); } /*! @@ -1082,6 +1091,7 @@ void QDeclarativeGridView::setCacheBuffer(int buffer) d->buffer = buffer; if (isComponentComplete()) refill(); + emit cacheBufferChanged(); } } diff --git a/src/declarative/graphicsitems/qdeclarativegridview_p.h b/src/declarative/graphicsitems/qdeclarativegridview_p.h index b488475..d463a46 100644 --- a/src/declarative/graphicsitems/qdeclarativegridview_p.h +++ b/src/declarative/graphicsitems/qdeclarativegridview_p.h @@ -57,19 +57,19 @@ class Q_DECLARATIVE_EXPORT QDeclarativeGridView : public QDeclarativeFlickable Q_OBJECT Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarativeGridView) - Q_PROPERTY(QVariant model READ model WRITE setModel) - Q_PROPERTY(QDeclarativeComponent *delegate READ delegate WRITE setDelegate) + Q_PROPERTY(QVariant model READ model WRITE setModel NOTIFY modelChanged) + Q_PROPERTY(QDeclarativeComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged) Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) Q_PROPERTY(QDeclarativeItem *currentItem READ currentItem NOTIFY currentIndexChanged) Q_PROPERTY(int count READ count NOTIFY countChanged) - Q_PROPERTY(QDeclarativeComponent *highlight READ highlight WRITE setHighlight) - Q_PROPERTY(QDeclarativeItem *highlightItem READ highlightItem NOTIFY highlightChanged) + Q_PROPERTY(QDeclarativeComponent *highlight READ highlight WRITE setHighlight NOTIFY highlightChanged) + Q_PROPERTY(QDeclarativeItem *highlightItem READ highlightItem NOTIFY highlightItemChanged) Q_PROPERTY(bool highlightFollowsCurrentItem READ highlightFollowsCurrentItem WRITE setHighlightFollowsCurrentItem) - Q_PROPERTY(Flow flow READ flow WRITE setFlow) - Q_PROPERTY(bool keyNavigationWraps READ isWrapEnabled WRITE setWrapEnabled) - Q_PROPERTY(int cacheBuffer READ cacheBuffer WRITE setCacheBuffer) + Q_PROPERTY(Flow flow READ flow WRITE setFlow NOTIFY flowChanged) + Q_PROPERTY(bool keyNavigationWraps READ isWrapEnabled WRITE setWrapEnabled NOTIFY keyNavigationWrapsChanged) + Q_PROPERTY(int cacheBuffer READ cacheBuffer WRITE setCacheBuffer NOTIFY cacheBufferChanged) Q_PROPERTY(int cellWidth READ cellWidth WRITE setCellWidth NOTIFY cellWidthChanged) Q_PROPERTY(int cellHeight READ cellHeight WRITE setCellHeight NOTIFY cellHeightChanged) Q_CLASSINFO("DefaultProperty", "data") @@ -129,6 +129,12 @@ Q_SIGNALS: void cellWidthChanged(); void cellHeightChanged(); void highlightChanged(); + void highlightItemChanged(); + void modelChanged(); + void delegateChanged(); + void flowChanged(); + void keyNavigationWrapsChanged(); + void cacheBufferChanged(); protected: virtual void viewportMoved(); diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp index 03303a0..e7fff90 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview.cpp +++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp @@ -816,7 +816,7 @@ void QDeclarativeListViewPrivate::createHighlight() } } if (changed) - emit q->highlightChanged(); + emit q->highlightItemChanged(); } void QDeclarativeListViewPrivate::updateHighlight() @@ -1473,6 +1473,8 @@ QVariant QDeclarativeListView::model() const void QDeclarativeListView::setModel(const QVariant &model) { Q_D(QDeclarativeListView); + if (d->modelVariant == model) + return; if (d->model) { disconnect(d->model, SIGNAL(itemsInserted(int,int)), this, SLOT(itemsInserted(int,int))); disconnect(d->model, SIGNAL(itemsRemoved(int,int)), this, SLOT(itemsRemoved(int,int))); @@ -1517,6 +1519,7 @@ void QDeclarativeListView::setModel(const QVariant &model) connect(d->model, SIGNAL(destroyingItem(QDeclarativeItem*)), this, SLOT(destroyingItem(QDeclarativeItem*))); emit countChanged(); } + emit modelChanged(); } /*! @@ -1563,6 +1566,7 @@ void QDeclarativeListView::setDelegate(QDeclarativeComponent *delegate) d->updateCurrent(d->currentIndex); } } + emit delegateChanged(); } /*! @@ -1663,6 +1667,7 @@ void QDeclarativeListView::setHighlight(QDeclarativeComponent *highlight) d->createHighlight(); if (d->currentItem) d->updateHighlight(); + emit highlightChanged(); } } @@ -1700,6 +1705,7 @@ void QDeclarativeListView::setHighlightFollowsCurrentItem(bool autoHighlight) d->highlightSizeAnimator->setEnabled(d->autoHighlight); } d->updateHighlight(); + emit highlightFollowsCurrentItemChanged(); } } @@ -1745,8 +1751,11 @@ qreal QDeclarativeListView::preferredHighlightBegin() const void QDeclarativeListView::setPreferredHighlightBegin(qreal start) { Q_D(QDeclarativeListView); + if (d->highlightRangeStart == start) + return; d->highlightRangeStart = start; d->haveHighlightRange = d->highlightRange != NoHighlightRange && d->highlightRangeStart <= d->highlightRangeEnd; + emit preferredHighlightBeginChanged(); } qreal QDeclarativeListView::preferredHighlightEnd() const @@ -1758,8 +1767,11 @@ qreal QDeclarativeListView::preferredHighlightEnd() const void QDeclarativeListView::setPreferredHighlightEnd(qreal end) { Q_D(QDeclarativeListView); + if (d->highlightRangeEnd == end) + return; d->highlightRangeEnd = end; d->haveHighlightRange = d->highlightRange != NoHighlightRange && d->highlightRangeStart <= d->highlightRangeEnd; + emit preferredHighlightEndChanged(); } QDeclarativeListView::HighlightRangeMode QDeclarativeListView::highlightRangeMode() const @@ -1771,8 +1783,11 @@ QDeclarativeListView::HighlightRangeMode QDeclarativeListView::highlightRangeMod void QDeclarativeListView::setHighlightRangeMode(HighlightRangeMode mode) { Q_D(QDeclarativeListView); + if (d->highlightRange == mode) + return; d->highlightRange = mode; d->haveHighlightRange = d->highlightRange != NoHighlightRange && d->highlightRangeStart <= d->highlightRangeEnd; + emit highlightRangeModeChanged(); } /*! @@ -1848,7 +1863,10 @@ bool QDeclarativeListView::isWrapEnabled() const void QDeclarativeListView::setWrapEnabled(bool wrap) { Q_D(QDeclarativeListView); + if (d->wrap == wrap) + return; d->wrap = wrap; + emit keyNavigationWrapsChanged(); } /*! @@ -1874,6 +1892,7 @@ void QDeclarativeListView::setCacheBuffer(int b) d->bufferMode = QDeclarativeListViewPrivate::BufferBefore | QDeclarativeListViewPrivate::BufferAfter; refill(); } + emit cacheBufferChanged(); } } @@ -1998,6 +2017,7 @@ void QDeclarativeListView::setSnapMode(SnapMode mode) Q_D(QDeclarativeListView); if (d->snapMode != mode) { d->snapMode = mode; + emit snapModeChanged(); } } @@ -2020,6 +2040,7 @@ void QDeclarativeListView::setFooter(QDeclarativeComponent *footer) d->maxExtentDirty = true; d->updateFooter(); d->updateViewport(); + emit footerChanged(); } } @@ -2043,6 +2064,7 @@ void QDeclarativeListView::setHeader(QDeclarativeComponent *header) d->updateHeader(); d->updateFooter(); d->updateViewport(); + emit headerChanged(); } } diff --git a/src/declarative/graphicsitems/qdeclarativelistview_p.h b/src/declarative/graphicsitems/qdeclarativelistview_p.h index 5e3edb0..f9b7b50 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview_p.h +++ b/src/declarative/graphicsitems/qdeclarativelistview_p.h @@ -91,33 +91,33 @@ class Q_DECLARATIVE_EXPORT QDeclarativeListView : public QDeclarativeFlickable Q_OBJECT Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarativeListView) - Q_PROPERTY(QVariant model READ model WRITE setModel) - Q_PROPERTY(QDeclarativeComponent *delegate READ delegate WRITE setDelegate) + Q_PROPERTY(QVariant model READ model WRITE setModel NOTIFY modelChanged) + Q_PROPERTY(QDeclarativeComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged) Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) Q_PROPERTY(QDeclarativeItem *currentItem READ currentItem NOTIFY currentIndexChanged) Q_PROPERTY(int count READ count NOTIFY countChanged) - Q_PROPERTY(QDeclarativeComponent *highlight READ highlight WRITE setHighlight) - Q_PROPERTY(QDeclarativeItem *highlightItem READ highlightItem NOTIFY highlightChanged) - Q_PROPERTY(bool highlightFollowsCurrentItem READ highlightFollowsCurrentItem WRITE setHighlightFollowsCurrentItem) + Q_PROPERTY(QDeclarativeComponent *highlight READ highlight WRITE setHighlight NOTIFY highlightChanged) + Q_PROPERTY(QDeclarativeItem *highlightItem READ highlightItem NOTIFY highlightItemChanged) + Q_PROPERTY(bool highlightFollowsCurrentItem READ highlightFollowsCurrentItem WRITE setHighlightFollowsCurrentItem NOTIFY highlightFollowsCurrentItemChanged) Q_PROPERTY(qreal highlightMoveSpeed READ highlightMoveSpeed WRITE setHighlightMoveSpeed NOTIFY highlightMoveSpeedChanged) Q_PROPERTY(qreal highlightResizeSpeed READ highlightResizeSpeed WRITE setHighlightResizeSpeed NOTIFY highlightResizeSpeedChanged) - Q_PROPERTY(qreal preferredHighlightBegin READ preferredHighlightBegin WRITE setPreferredHighlightBegin) - Q_PROPERTY(qreal preferredHighlightEnd READ preferredHighlightEnd WRITE setPreferredHighlightEnd) - Q_PROPERTY(HighlightRangeMode highlightRangeMode READ highlightRangeMode WRITE setHighlightRangeMode) + Q_PROPERTY(qreal preferredHighlightBegin READ preferredHighlightBegin WRITE setPreferredHighlightBegin NOTIFY preferredHighlightBeginChanged) + Q_PROPERTY(qreal preferredHighlightEnd READ preferredHighlightEnd WRITE setPreferredHighlightEnd NOTIFY preferredHighlightEndChanged) + Q_PROPERTY(HighlightRangeMode highlightRangeMode READ highlightRangeMode WRITE setHighlightRangeMode NOTIFY highlightRangeModeChanged) Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing NOTIFY spacingChanged) Q_PROPERTY(Orientation orientation READ orientation WRITE setOrientation NOTIFY orientationChanged) - Q_PROPERTY(bool keyNavigationWraps READ isWrapEnabled WRITE setWrapEnabled) - Q_PROPERTY(int cacheBuffer READ cacheBuffer WRITE setCacheBuffer) + Q_PROPERTY(bool keyNavigationWraps READ isWrapEnabled WRITE setWrapEnabled NOTIFY keyNavigationWrapsChanged) + Q_PROPERTY(int cacheBuffer READ cacheBuffer WRITE setCacheBuffer NOTIFY cacheBufferChanged) Q_PROPERTY(QDeclarativeViewSection *section READ sectionCriteria CONSTANT) Q_PROPERTY(QString currentSection READ currentSection NOTIFY currentSectionChanged) - Q_PROPERTY(SnapMode snapMode READ snapMode WRITE setSnapMode) + Q_PROPERTY(SnapMode snapMode READ snapMode WRITE setSnapMode NOTIFY snapModeChanged) - Q_PROPERTY(QDeclarativeComponent *header READ header WRITE setHeader) - Q_PROPERTY(QDeclarativeComponent *footer READ footer WRITE setFooter) + Q_PROPERTY(QDeclarativeComponent *header READ header WRITE setHeader NOTIFY headerChanged) + Q_PROPERTY(QDeclarativeComponent *footer READ footer WRITE setFooter NOTIFY footerChanged) Q_ENUMS(HighlightRangeMode) Q_ENUMS(Orientation) @@ -205,6 +205,18 @@ Q_SIGNALS: void highlightMoveSpeedChanged(); void highlightResizeSpeedChanged(); void highlightChanged(); + void highlightItemChanged(); + void modelChanged(); + void delegateChanged(); + void highlightFollowsCurrentItemChanged(); + void preferredHighlightBeginChanged(); + void preferredHighlightEndChanged(); + void highlightRangeModeChanged(); + void keyNavigationWrapsChanged(); + void cacheBufferChanged(); + void snapModeChanged(); + void headerChanged(); + void footerChanged(); protected: virtual void viewportMoved(); diff --git a/src/declarative/graphicsitems/qdeclarativepath.cpp b/src/declarative/graphicsitems/qdeclarativepath.cpp index 48f112a..80586b8 100644 --- a/src/declarative/graphicsitems/qdeclarativepath.cpp +++ b/src/declarative/graphicsitems/qdeclarativepath.cpp @@ -114,7 +114,10 @@ qreal QDeclarativePath::startX() const void QDeclarativePath::setStartX(qreal x) { Q_D(QDeclarativePath); + if (qFuzzyCompare(x, d->startX)) + return; d->startX = x; + emit startXChanged(); } qreal QDeclarativePath::startY() const @@ -126,7 +129,10 @@ qreal QDeclarativePath::startY() const void QDeclarativePath::setStartY(qreal y) { Q_D(QDeclarativePath); + if (qFuzzyCompare(y, d->startY)) + return; d->startY = y; + emit startYChanged(); } /*! @@ -522,7 +528,10 @@ QString QDeclarativePathAttribute::name() const void QDeclarativePathAttribute::setName(const QString &name) { - _name = name; + if (_name == name) + return; + _name = name; + emit nameChanged(); } /*! diff --git a/src/declarative/graphicsitems/qdeclarativepath_p.h b/src/declarative/graphicsitems/qdeclarativepath_p.h index b3139f8..d7cfca1 100644 --- a/src/declarative/graphicsitems/qdeclarativepath_p.h +++ b/src/declarative/graphicsitems/qdeclarativepath_p.h @@ -67,7 +67,7 @@ class Q_DECLARATIVE_EXPORT QDeclarativePathAttribute : public QDeclarativePathEl { Q_OBJECT - Q_PROPERTY(QString name READ name WRITE setName) + Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY changed) public: QDeclarativePathAttribute(QObject *parent=0) : QDeclarativePathElement(parent), _value(0) {} @@ -79,6 +79,9 @@ public: qreal value() const; void setValue(qreal value); +Q_SIGNALS: + void nameChanged(); + private: QString _name; qreal _value; @@ -190,8 +193,8 @@ class Q_DECLARATIVE_EXPORT QDeclarativePath : public QObject, public QDeclarativ Q_INTERFACES(QDeclarativeParserStatus) Q_PROPERTY(QDeclarativeListProperty pathElements READ pathElements) - Q_PROPERTY(qreal startX READ startX WRITE setStartX) - Q_PROPERTY(qreal startY READ startY WRITE setStartY) + Q_PROPERTY(qreal startX READ startX WRITE setStartX NOTIFY startXChanged) + Q_PROPERTY(qreal startY READ startY WRITE setStartY NOTIFY startYChanged) Q_PROPERTY(bool closed READ isClosed NOTIFY changed) Q_CLASSINFO("DefaultProperty", "pathElements") Q_INTERFACES(QDeclarativeParserStatus) @@ -216,6 +219,8 @@ public: Q_SIGNALS: void changed(); + void startXChanged(); + void startYChanged(); protected: virtual void componentComplete(); diff --git a/src/declarative/graphicsitems/qdeclarativepathview.cpp b/src/declarative/graphicsitems/qdeclarativepathview.cpp index f1b0213..50aa9ef 100644 --- a/src/declarative/graphicsitems/qdeclarativepathview.cpp +++ b/src/declarative/graphicsitems/qdeclarativepathview.cpp @@ -203,6 +203,9 @@ QVariant QDeclarativePathView::model() const void QDeclarativePathView::setModel(const QVariant &model) { Q_D(QDeclarativePathView); + if (d->modelVariant == model) + return; + if (d->model) { disconnect(d->model, SIGNAL(itemsInserted(int,int)), this, SLOT(itemsInserted(int,int))); disconnect(d->model, SIGNAL(itemsRemoved(int,int)), this, SLOT(itemsRemoved(int,int))); @@ -242,6 +245,7 @@ void QDeclarativePathView::setModel(const QVariant &model) d->pathOffset = 0; d->regenerate(); d->fixOffset(); + emit modelChanged(); } /*! @@ -269,9 +273,12 @@ QDeclarativePath *QDeclarativePathView::path() const void QDeclarativePathView::setPath(QDeclarativePath *path) { Q_D(QDeclarativePathView); + if (d->path == path) + return; d->path = path; connect(d->path, SIGNAL(changed()), this, SLOT(refill())); d->regenerate(); + emit pathChanged(); } /*! @@ -333,7 +340,7 @@ void QDeclarativePathViewPrivate::setOffset(qreal o) /*! \qmlproperty real PathView::snapPosition - This property determines the position (0-100) the nearest item will snap to. + This property determines the position (0.0-1.0) the nearest item will snap to. */ qreal QDeclarativePathView::snapPosition() const { @@ -344,8 +351,12 @@ qreal QDeclarativePathView::snapPosition() const void QDeclarativePathView::setSnapPosition(qreal pos) { Q_D(QDeclarativePathView); - d->snapPos = pos/100; + qreal normalizedPos = pos - int(pos); + if (qFuzzyCompare(normalizedPos, d->snapPos)) + return; + d->snapPos = normalizedPos; d->fixOffset(); + emit snapPositionChanged(); } /*! @@ -365,7 +376,10 @@ qreal QDeclarativePathView::dragMargin() const void QDeclarativePathView::setDragMargin(qreal dragMargin) { Q_D(QDeclarativePathView); + if (d->dragMargin == dragMargin) + return; d->dragMargin = dragMargin; + emit dragMarginChanged(); } /*! @@ -392,16 +406,19 @@ QDeclarativeComponent *QDeclarativePathView::delegate() const return 0; } -void QDeclarativePathView::setDelegate(QDeclarativeComponent *c) +void QDeclarativePathView::setDelegate(QDeclarativeComponent *delegate) { Q_D(QDeclarativePathView); + if (delegate == this->delegate()) + return; if (!d->ownModel) { d->model = new QDeclarativeVisualDataModel(qmlContext(this)); d->ownModel = true; } if (QDeclarativeVisualDataModel *dataModel = qobject_cast(d->model)) { - dataModel->setDelegate(c); + dataModel->setDelegate(delegate); d->regenerate(); + emit delegateChanged(); } } @@ -422,6 +439,7 @@ void QDeclarativePathView::setPathItemCount(int i) return; d->pathItems = i; d->regenerate(); + pathItemCountChanged(); } QPointF QDeclarativePathViewPrivate::pointNear(const QPointF &point, qreal *nearPercent) const diff --git a/src/declarative/graphicsitems/qdeclarativepathview_p.h b/src/declarative/graphicsitems/qdeclarativepathview_p.h index 709a4fc..df9c6ae 100644 --- a/src/declarative/graphicsitems/qdeclarativepathview_p.h +++ b/src/declarative/graphicsitems/qdeclarativepathview_p.h @@ -56,15 +56,15 @@ class Q_DECLARATIVE_EXPORT QDeclarativePathView : public QDeclarativeItem { Q_OBJECT - Q_PROPERTY(QVariant model READ model WRITE setModel) - Q_PROPERTY(QDeclarativePath *path READ path WRITE setPath) + Q_PROPERTY(QVariant model READ model WRITE setModel NOTIFY modelChanged) + Q_PROPERTY(QDeclarativePath *path READ path WRITE setPath NOTIFY pathChanged) Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) Q_PROPERTY(qreal offset READ offset WRITE setOffset NOTIFY offsetChanged) - Q_PROPERTY(qreal snapPosition READ snapPosition WRITE setSnapPosition) - Q_PROPERTY(qreal dragMargin READ dragMargin WRITE setDragMargin) + Q_PROPERTY(qreal snapPosition READ snapPosition WRITE setSnapPosition NOTIFY snapPositionChanged) + Q_PROPERTY(qreal dragMargin READ dragMargin WRITE setDragMargin NOTIFY dragMarginChanged) Q_PROPERTY(int count READ count) - Q_PROPERTY(QDeclarativeComponent *delegate READ delegate WRITE setDelegate) - Q_PROPERTY(int pathItemCount READ pathItemCount WRITE setPathItemCount) + Q_PROPERTY(QDeclarativeComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged) + Q_PROPERTY(int pathItemCount READ pathItemCount WRITE setPathItemCount NOTIFY pathItemCountChanged) public: QDeclarativePathView(QDeclarativeItem *parent=0); @@ -101,6 +101,12 @@ public: Q_SIGNALS: void currentIndexChanged(); void offsetChanged(); + void modelChanged(); + void pathChanged(); + void dragMarginChanged(); + void snapPositionChanged(); + void delegateChanged(); + void pathItemCountChanged(); protected: void mousePressEvent(QGraphicsSceneMouseEvent *event); diff --git a/tests/auto/declarative/qdeclarativegridview/data/propertychanges.qml b/tests/auto/declarative/qdeclarativegridview/data/propertychanges.qml new file mode 100644 index 0000000..da2e8d0 --- /dev/null +++ b/tests/auto/declarative/qdeclarativegridview/data/propertychanges.qml @@ -0,0 +1,69 @@ +import Qt 4.6 + +Rectangle { + width: 360; height: 120; color: "white" + Component { + id: delegate + Item { + id: wrapper + width: 180; height: 40; + Column { + x: 5; y: 5 + Text { text: 'Name: ' + name } + Text { text: 'Number: ' + number } + } + } + } + Component { + id: highlightRed + Rectangle { + color: "red" + radius: 10 + opacity: 0.5 + } + } + GridView { + cellWidth:180 + cellHeight:40 + objectName: "gridView" + anchors.fill: parent + model: listModel + delegate: delegate + highlight: highlightRed + focus: true + keyNavigationWraps: true + cacheBuffer: 10 + flow: GridView.LeftToRight + } + + data:[ + ListModel { + id: listModel + ListElement { + name: "Bill Smith" + number: "555 3264" + } + ListElement { + name: "John Brown" + number: "555 8426" + } + ListElement { + name: "Sam Wise" + number: "555 0473" + } + }, + ListModel { + objectName: "alternateModel" + ListElement { + name: "Jack" + number: "555 8426" + } + ListElement { + name: "Mary" + number: "555 3264" + } + } + ] +} + + \ No newline at end of file diff --git a/tests/auto/declarative/qdeclarativegridview/tst_qdeclarativegridview.cpp b/tests/auto/declarative/qdeclarativegridview/tst_qdeclarativegridview.cpp index 2a60fee..cc65d32 100644 --- a/tests/auto/declarative/qdeclarativegridview/tst_qdeclarativegridview.cpp +++ b/tests/auto/declarative/qdeclarativegridview/tst_qdeclarativegridview.cpp @@ -39,16 +39,17 @@ ** ****************************************************************************/ -#include -#include -#include #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include class tst_QDeclarativeGridView : public QObject { @@ -66,6 +67,9 @@ private slots: void currentIndex(); void defaultValues(); void properties(); + void propertyChanges(); + void componentChanges(); + void modelChanges(); void positionViewAtIndex(); void resetModel(); void QTBUG_8456(); @@ -91,7 +95,7 @@ public: setRoleNames(roles); } - int rowCount(const QModelIndex &parent=QModelIndex()) const { return list.count(); } + int rowCount(const QModelIndex &parent=QModelIndex()) const { Q_UNUSED(parent); return list.count(); } QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const { QVariant rv; if (role == Name) @@ -796,6 +800,107 @@ void tst_QDeclarativeGridView::properties() delete obj; } +void tst_QDeclarativeGridView::propertyChanges() +{ + QDeclarativeView *canvas = createView(); + QVERIFY(canvas); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/propertychanges.qml")); + + QDeclarativeGridView *gridView = canvas->rootObject()->findChild("gridView"); + QVERIFY(gridView); + + QSignalSpy keyNavigationWrapsSpy(gridView, SIGNAL(keyNavigationWrapsChanged())); + QSignalSpy cacheBufferSpy(gridView, SIGNAL(cacheBufferChanged())); + QSignalSpy flowSpy(gridView, SIGNAL(flowChanged())); + + QCOMPARE(gridView->isWrapEnabled(), true); + QCOMPARE(gridView->cacheBuffer(), 10); + QCOMPARE(gridView->flow(), QDeclarativeGridView::LeftToRight); + + gridView->setWrapEnabled(false); + gridView->setCacheBuffer(3); + gridView->setFlow(QDeclarativeGridView::TopToBottom); + + QCOMPARE(gridView->isWrapEnabled(), false); + QCOMPARE(gridView->cacheBuffer(), 3); + QCOMPARE(gridView->flow(), QDeclarativeGridView::TopToBottom); + + QCOMPARE(keyNavigationWrapsSpy.count(),1); + QCOMPARE(cacheBufferSpy.count(),1); + QCOMPARE(flowSpy.count(),1); + + gridView->setWrapEnabled(false); + gridView->setCacheBuffer(3); + gridView->setFlow(QDeclarativeGridView::TopToBottom); + + QCOMPARE(keyNavigationWrapsSpy.count(),1); + QCOMPARE(cacheBufferSpy.count(),1); + QCOMPARE(flowSpy.count(),1); + + delete canvas; +} + +void tst_QDeclarativeGridView::componentChanges() +{ + QDeclarativeView *canvas = createView(); + QVERIFY(canvas); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/propertychanges.qml")); + + QDeclarativeGridView *gridView = canvas->rootObject()->findChild("gridView"); + QVERIFY(gridView); + + QDeclarativeComponent component(canvas->engine()); + component.setData("import Qt 4.6; Rectangle { color: \"blue\"; }", QUrl::fromLocalFile("")); + + QDeclarativeComponent delegateComponent(canvas->engine()); + delegateComponent.setData("import Qt 4.6; Text { text: 'Name: ' + name }", QUrl::fromLocalFile("")); + + QSignalSpy highlightSpy(gridView, SIGNAL(highlightChanged())); + QSignalSpy delegateSpy(gridView, SIGNAL(delegateChanged())); + + gridView->setHighlight(&component); + gridView->setDelegate(&delegateComponent); + + QCOMPARE(gridView->highlight(), &component); + QCOMPARE(gridView->delegate(), &delegateComponent); + + QCOMPARE(highlightSpy.count(),1); + QCOMPARE(delegateSpy.count(),1); + + gridView->setHighlight(&component); + gridView->setDelegate(&delegateComponent); + + QCOMPARE(highlightSpy.count(),1); + QCOMPARE(delegateSpy.count(),1); + delete canvas; +} + +void tst_QDeclarativeGridView::modelChanges() +{ + QDeclarativeView *canvas = createView(); + QVERIFY(canvas); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/propertychanges.qml")); + + QDeclarativeGridView *gridView = canvas->rootObject()->findChild("gridView"); + QVERIFY(gridView); + + QDeclarativeListModel *alternateModel = canvas->rootObject()->findChild("alternateModel"); + QVERIFY(alternateModel); + QVariant modelVariant = QVariant::fromValue(alternateModel); + QSignalSpy modelSpy(gridView, SIGNAL(modelChanged())); + + gridView->setModel(modelVariant); + QCOMPARE(gridView->model(), modelVariant); + QCOMPARE(modelSpy.count(),1); + + gridView->setModel(modelVariant); + QCOMPARE(modelSpy.count(),1); + + gridView->setModel(QVariant()); + QCOMPARE(modelSpy.count(),2); + delete canvas; +} + void tst_QDeclarativeGridView::positionViewAtIndex() { QDeclarativeView *canvas = createView(); diff --git a/tests/auto/declarative/qdeclarativelistview/data/propertychanges.qml b/tests/auto/declarative/qdeclarativelistview/data/propertychanges.qml new file mode 100644 index 0000000..a41f003 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelistview/data/propertychanges.qml @@ -0,0 +1,71 @@ +import Qt 4.6 + +Rectangle { + width: 180; height: 120; color: "white" + Component { + id: delegate + Item { + id: wrapper + width: 180; height: 40; + Column { + x: 5; y: 5 + Text { text: 'Name: ' + name } + Text { text: 'Number: ' + number } + } + } + } + Component { + id: highlightRed + Rectangle { + color: "red" + radius: 10 + opacity: 0.5 + } + } + ListView { + objectName: "listView" + anchors.fill: parent + model: listModel + delegate: delegate + highlight: highlightRed + focus: true + highlightFollowsCurrentItem: true + preferredHighlightBegin: 0.0 + preferredHighlightEnd: 0.0 + highlightRangeMode: ListView.ApplyRange + keyNavigationWraps: true + cacheBuffer: 10 + snapMode: ListView.SnapToItem + } + + data:[ + ListModel { + id: listModel + ListElement { + name: "Bill Smith" + number: "555 3264" + } + ListElement { + name: "John Brown" + number: "555 8426" + } + ListElement { + name: "Sam Wise" + number: "555 0473" + } + }, + ListModel { + objectName: "alternateModel" + ListElement { + name: "Jack" + number: "555 8426" + } + ListElement { + name: "Mary" + number: "555 3264" + } + } + ] +} + + \ No newline at end of file diff --git a/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp b/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp index f15f26b..a36224f 100644 --- a/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp +++ b/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp @@ -38,15 +38,18 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ + #include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include class tst_QDeclarativeListView : public QObject { @@ -82,6 +85,9 @@ private slots: void cacheBuffer(); void positionViewAtIndex(); void resetModel(); + void propertyChanges(); + void componentChanges(); + void modelChanges(); private: template void items(); @@ -240,7 +246,7 @@ public: setRoleNames(roles); } - int rowCount(const QModelIndex &parent=QModelIndex()) const { return list.count(); } + int rowCount(const QModelIndex &parent=QModelIndex()) const { Q_UNUSED(parent); return list.count(); } QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const { QVariant rv; if (role == Name) @@ -379,6 +385,7 @@ void tst_QDeclarativeListView::items() delete canvas; } + template void tst_QDeclarativeListView::changed() { @@ -1275,6 +1282,149 @@ void tst_QDeclarativeListView::resetModel() } } +void tst_QDeclarativeListView::propertyChanges() +{ + QDeclarativeView *canvas = createView(); + QVERIFY(canvas); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/propertychanges.qml")); + + QDeclarativeListView *listView = canvas->rootObject()->findChild("listView"); + QVERIFY(listView); + + QSignalSpy highlightFollowsCurrentItemSpy(listView, SIGNAL(highlightFollowsCurrentItemChanged())); + QSignalSpy preferredHighlightBeginSpy(listView, SIGNAL(preferredHighlightBeginChanged())); + QSignalSpy preferredHighlightEndSpy(listView, SIGNAL(preferredHighlightEndChanged())); + QSignalSpy highlightRangeModeSpy(listView, SIGNAL(highlightRangeModeChanged())); + QSignalSpy keyNavigationWrapsSpy(listView, SIGNAL(keyNavigationWrapsChanged())); + QSignalSpy cacheBufferSpy(listView, SIGNAL(cacheBufferChanged())); + QSignalSpy snapModeSpy(listView, SIGNAL(snapModeChanged())); + + QCOMPARE(listView->highlightFollowsCurrentItem(), true); + QCOMPARE(listView->preferredHighlightBegin(), 0.0); + QCOMPARE(listView->preferredHighlightEnd(), 0.0); + QCOMPARE(listView->highlightRangeMode(), QDeclarativeListView::ApplyRange); + QCOMPARE(listView->isWrapEnabled(), true); + QCOMPARE(listView->cacheBuffer(), 10); + QCOMPARE(listView->snapMode(), QDeclarativeListView::SnapToItem); + + listView->setHighlightFollowsCurrentItem(false); + listView->setPreferredHighlightBegin(1.0); + listView->setPreferredHighlightEnd(1.0); + listView->setHighlightRangeMode(QDeclarativeListView::StrictlyEnforceRange); + listView->setWrapEnabled(false); + listView->setCacheBuffer(3); + listView->setSnapMode(QDeclarativeListView::SnapOneItem); + + QCOMPARE(listView->highlightFollowsCurrentItem(), false); + QCOMPARE(listView->preferredHighlightBegin(), 1.0); + QCOMPARE(listView->preferredHighlightEnd(), 1.0); + QCOMPARE(listView->highlightRangeMode(), QDeclarativeListView::StrictlyEnforceRange); + QCOMPARE(listView->isWrapEnabled(), false); + QCOMPARE(listView->cacheBuffer(), 3); + QCOMPARE(listView->snapMode(), QDeclarativeListView::SnapOneItem); + + QCOMPARE(highlightFollowsCurrentItemSpy.count(),1); + QCOMPARE(preferredHighlightBeginSpy.count(),1); + QCOMPARE(preferredHighlightEndSpy.count(),1); + QCOMPARE(highlightRangeModeSpy.count(),1); + QCOMPARE(keyNavigationWrapsSpy.count(),1); + QCOMPARE(cacheBufferSpy.count(),1); + QCOMPARE(snapModeSpy.count(),1); + + listView->setHighlightFollowsCurrentItem(false); + listView->setPreferredHighlightBegin(1.0); + listView->setPreferredHighlightEnd(1.0); + listView->setHighlightRangeMode(QDeclarativeListView::StrictlyEnforceRange); + listView->setWrapEnabled(false); + listView->setCacheBuffer(3); + listView->setSnapMode(QDeclarativeListView::SnapOneItem); + + QCOMPARE(highlightFollowsCurrentItemSpy.count(),1); + QCOMPARE(preferredHighlightBeginSpy.count(),1); + QCOMPARE(preferredHighlightEndSpy.count(),1); + QCOMPARE(highlightRangeModeSpy.count(),1); + QCOMPARE(keyNavigationWrapsSpy.count(),1); + QCOMPARE(cacheBufferSpy.count(),1); + QCOMPARE(snapModeSpy.count(),1); + + delete canvas; +} + +void tst_QDeclarativeListView::componentChanges() +{ + QDeclarativeView *canvas = createView(); + QVERIFY(canvas); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/propertychanges.qml")); + + QDeclarativeListView *listView = canvas->rootObject()->findChild("listView"); + QVERIFY(listView); + + QDeclarativeComponent component(canvas->engine()); + component.setData("import Qt 4.6; Rectangle { color: \"blue\"; }", QUrl::fromLocalFile("")); + + QDeclarativeComponent delegateComponent(canvas->engine()); + delegateComponent.setData("import Qt 4.6; Text { text: 'Name: ' + name }", QUrl::fromLocalFile("")); + + QSignalSpy highlightSpy(listView, SIGNAL(highlightChanged())); + QSignalSpy delegateSpy(listView, SIGNAL(delegateChanged())); + QSignalSpy headerSpy(listView, SIGNAL(headerChanged())); + QSignalSpy footerSpy(listView, SIGNAL(footerChanged())); + + listView->setHighlight(&component); + listView->setHeader(&component); + listView->setFooter(&component); + listView->setDelegate(&delegateComponent); + + QCOMPARE(listView->highlight(), &component); + QCOMPARE(listView->header(), &component); + QCOMPARE(listView->footer(), &component); + QCOMPARE(listView->delegate(), &delegateComponent); + + QCOMPARE(highlightSpy.count(),1); + QCOMPARE(delegateSpy.count(),1); + QCOMPARE(headerSpy.count(),1); + QCOMPARE(footerSpy.count(),1); + + listView->setHighlight(&component); + listView->setHeader(&component); + listView->setFooter(&component); + listView->setDelegate(&delegateComponent); + + QCOMPARE(highlightSpy.count(),1); + QCOMPARE(delegateSpy.count(),1); + QCOMPARE(headerSpy.count(),1); + QCOMPARE(footerSpy.count(),1); + + delete canvas; +} + +void tst_QDeclarativeListView::modelChanges() +{ + QDeclarativeView *canvas = createView(); + QVERIFY(canvas); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/propertychanges.qml")); + + QDeclarativeListView *listView = canvas->rootObject()->findChild("listView"); + QVERIFY(listView); + + QDeclarativeListModel *alternateModel = canvas->rootObject()->findChild("alternateModel"); + QVERIFY(alternateModel); + QVariant modelVariant = QVariant::fromValue(alternateModel); + QSignalSpy modelSpy(listView, SIGNAL(modelChanged())); + + listView->setModel(modelVariant); + QCOMPARE(listView->model(), modelVariant); + QCOMPARE(modelSpy.count(),1); + + listView->setModel(modelVariant); + QCOMPARE(modelSpy.count(),1); + + listView->setModel(QVariant()); + QCOMPARE(modelSpy.count(),2); + + delete canvas; +} + void tst_QDeclarativeListView::qListModelInterface_items() { items(); diff --git a/tests/auto/declarative/qdeclarativepathview/data/displaypath.qml b/tests/auto/declarative/qdeclarativepathview/data/displaypath.qml index 627f38a..ab1538b 100644 --- a/tests/auto/declarative/qdeclarativepathview/data/displaypath.qml +++ b/tests/auto/declarative/qdeclarativepathview/data/displaypath.qml @@ -33,7 +33,7 @@ Rectangle { height: 320 model: testModel delegate: delegate - snapPosition: 0.01 + snapPosition: 0.0001 path: Path { startY: 120 startX: 160 diff --git a/tests/auto/declarative/qdeclarativepathview/data/pathview.qml b/tests/auto/declarative/qdeclarativepathview/data/pathview.qml index 8fa8d59..c5d88cd 100644 --- a/tests/auto/declarative/qdeclarativepathview/data/pathview.qml +++ b/tests/auto/declarative/qdeclarativepathview/data/pathview.qml @@ -39,7 +39,7 @@ Rectangle { height: 320 model: testModel delegate: delegate - snapPosition: 0.01 + snapPosition: 0.0001 path: Path { startY: 120 startX: 160 diff --git a/tests/auto/declarative/qdeclarativepathview/data/pathview3.qml b/tests/auto/declarative/qdeclarativepathview/data/pathview3.qml index af3ae13..f8ed29f 100644 --- a/tests/auto/declarative/qdeclarativepathview/data/pathview3.qml +++ b/tests/auto/declarative/qdeclarativepathview/data/pathview3.qml @@ -3,7 +3,7 @@ import Qt 4.6 PathView { id: photoPathView y: 100; width: 800; height: 330; pathItemCount: 4; offset: 10 - dragMargin: 24; snapPosition: 50 + dragMargin: 24; snapPosition: 0.50 path: Path { startX: -50; startY: 40; diff --git a/tests/auto/declarative/qdeclarativepathview/data/propertychanges.qml b/tests/auto/declarative/qdeclarativepathview/data/propertychanges.qml new file mode 100644 index 0000000..db70b7b --- /dev/null +++ b/tests/auto/declarative/qdeclarativepathview/data/propertychanges.qml @@ -0,0 +1,115 @@ +import Qt 4.6 + +Rectangle { + width: 350; height: 220; color: "white" + Component { + id: myDelegate + Item { + id: wrapper + width: 180; height: 40; + opacity: PathView.opacity + Column { + x: 5; y: 5 + Text { text: 'Name: ' + name } + Text { text: 'Number: ' + number } + } + } + } + + PathView { + snapPosition: 0.1 + dragMargin: 5.0 + id: pathView + objectName: "pathView" + anchors.fill: parent + model: listModel + delegate: myDelegate + focus: true + path: Path { + id: myPath + objectName: "path" + startX: 220; startY: 200 + PathAttribute { name: "opacity"; value: 1.0; objectName: "pathAttribute"; } + PathQuad { x: 220; y: 25; controlX: 260; controlY: 75 } + PathAttribute { name: "opacity"; value: 0.3 } + PathQuad { x: 220; y: 200; controlX: -20; controlY: 75 } + } + Timer { + interval: 2000; running: true; repeat: true + onTriggered: { + if (pathView.path == alternatePath) + pathView.path = myPath; + else + pathView.path = alternatePath; + } + } + } + + data:[ + ListModel { + id: listModel + ListElement { + name: "Bill Smith" + number: "555 3264" + } + ListElement { + name: "John Brown" + number: "555 8426" + } + ListElement { + name: "Sam Wise" + number: "555 0473" + } + ListElement { + name: "Bill Smith" + number: "555 3264" + } + ListElement { + name: "John Brown" + number: "555 8426" + } + ListElement { + name: "Sam Wise" + number: "555 0473" + } + ListElement { + name: "Bill Smith" + number: "555 3264" + } + ListElement { + name: "John Brown" + number: "555 8426" + } + ListElement { + name: "Sam Wise" + number: "555 0473" + } + }, + ListModel { + objectName: "alternateModel" + ListElement { + name: "Jack" + number: "555 8426" + } + ListElement { + name: "Mary" + number: "555 3264" + } + }, + Path { + id: alternatePath + objectName: "alternatePath" + startX: 100; startY: 40 + PathAttribute { name: "opacity"; value: 0.0 } + PathLine { x: 100; y: 160 } + PathAttribute { name: "opacity"; value: 0.2 } + PathLine { x: 300; y: 160 } + PathAttribute { name: "opacity"; value: 0.0 } + PathLine { x: 300; y: 40 } + PathAttribute { name: "opacity"; value: 0.2 } + PathLine { x: 100; y: 40 } + } + ] +} + + diff --git a/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp b/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp index 79bc607..fa4e9d3 100644 --- a/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp +++ b/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp @@ -38,20 +38,23 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ -#include -#include -#include -#include -#include + +#include +#include #include #include -#include +#include +#include +#include +#include #include #include +#include +#include #include #include #include -#include + #include "../../../shared/util.h" class tst_QDeclarativePathView : public QObject @@ -69,6 +72,11 @@ private slots: void path(); void pathMoved(); void resetModel(); + void propertyChanges(); + void pathChanges(); + void componentChanges(); + void modelChanges(); + private: QDeclarativeView *createView(); @@ -120,7 +128,7 @@ public: setRoleNames(roles); } - int rowCount(const QModelIndex &parent=QModelIndex()) const { return list.count(); } + int rowCount(const QModelIndex &parent=QModelIndex()) const { Q_UNUSED(parent); return list.count(); } QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const { QVariant rv; if (role == Name) @@ -465,6 +473,149 @@ void tst_QDeclarativePathView::resetModel() } } +void tst_QDeclarativePathView::propertyChanges() +{ + QDeclarativeView *canvas = createView(); + QVERIFY(canvas); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/propertychanges.qml")); + + QDeclarativePathView *pathView = canvas->rootObject()->findChild("pathView"); + QVERIFY(pathView); + + QSignalSpy snapPositionSpy(pathView, SIGNAL(snapPositionChanged())); + QSignalSpy dragMarginSpy(pathView, SIGNAL(dragMarginChanged())); + + QCOMPARE(pathView->snapPosition(), 0.1); + QCOMPARE(pathView->dragMargin(), 5.0); + + pathView->setSnapPosition(0.4); + pathView->setDragMargin(20.0); + + QCOMPARE(pathView->snapPosition(), 0.4); + QCOMPARE(pathView->dragMargin(), 20.0); + + QCOMPARE(snapPositionSpy.count(), 1); + QCOMPARE(dragMarginSpy.count(), 1); + + pathView->setSnapPosition(0.4); + pathView->setDragMargin(20.0); + + QCOMPARE(snapPositionSpy.count(), 1); + QCOMPARE(dragMarginSpy.count(), 1); + delete canvas; +} + +void tst_QDeclarativePathView::pathChanges() +{ + QDeclarativeView *canvas = createView(); + QVERIFY(canvas); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/propertychanges.qml")); + + QDeclarativePathView *pathView = canvas->rootObject()->findChild("pathView"); + QVERIFY(pathView); + + QDeclarativePath *path = canvas->rootObject()->findChild("path"); + QVERIFY(path); + + QSignalSpy startXSpy(path, SIGNAL(startXChanged())); + QSignalSpy startYSpy(path, SIGNAL(startYChanged())); + + QCOMPARE(path->startX(), 220.0); + QCOMPARE(path->startY(), 200.0); + + path->setStartX(240.0); + path->setStartY(220.0); + + QCOMPARE(path->startX(), 240.0); + QCOMPARE(path->startY(), 220.0); + + QCOMPARE(startXSpy.count(),1); + QCOMPARE(startYSpy.count(),1); + + path->setStartX(240); + path->setStartY(220); + + QCOMPARE(startXSpy.count(),1); + QCOMPARE(startYSpy.count(),1); + + QDeclarativePath *alternatePath = canvas->rootObject()->findChild("alternatePath"); + QVERIFY(alternatePath); + + QSignalSpy pathSpy(pathView, SIGNAL(pathChanged())); + + QCOMPARE(pathView->path(), path); + + pathView->setPath(alternatePath); + QCOMPARE(pathView->path(), alternatePath); + QCOMPARE(pathSpy.count(),1); + + pathView->setPath(alternatePath); + QCOMPARE(pathSpy.count(),1); + + QDeclarativePathAttribute *pathAttribute = canvas->rootObject()->findChild("pathAttribute"); + QVERIFY(pathAttribute); + + QSignalSpy nameSpy(pathAttribute, SIGNAL(nameChanged())); + QCOMPARE(pathAttribute->name(), QString("opacity")); + + pathAttribute->setName("scale"); + QCOMPARE(pathAttribute->name(), QString("scale")); + QCOMPARE(nameSpy.count(),1); + + pathAttribute->setName("scale"); + QCOMPARE(nameSpy.count(),1); + delete canvas; +} + +void tst_QDeclarativePathView::componentChanges() +{ + QDeclarativeView *canvas = createView(); + QVERIFY(canvas); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/propertychanges.qml")); + + QDeclarativePathView *pathView = canvas->rootObject()->findChild("pathView"); + QVERIFY(pathView); + + QDeclarativeComponent delegateComponent(canvas->engine()); + delegateComponent.setData("import Qt 4.6; Text { text: 'Name: ' + name }", QUrl::fromLocalFile("")); + + QSignalSpy delegateSpy(pathView, SIGNAL(delegateChanged())); + + pathView->setDelegate(&delegateComponent); + QCOMPARE(pathView->delegate(), &delegateComponent); + QCOMPARE(delegateSpy.count(),1); + + pathView->setDelegate(&delegateComponent); + QCOMPARE(delegateSpy.count(),1); + delete canvas; +} + +void tst_QDeclarativePathView::modelChanges() +{ + QDeclarativeView *canvas = createView(); + QVERIFY(canvas); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/propertychanges.qml")); + + QDeclarativePathView *pathView = canvas->rootObject()->findChild("pathView"); + QVERIFY(pathView); + + QDeclarativeListModel *alternateModel = canvas->rootObject()->findChild("alternateModel"); + QVERIFY(alternateModel); + QVariant modelVariant = QVariant::fromValue(alternateModel); + QSignalSpy modelSpy(pathView, SIGNAL(modelChanged())); + + pathView->setModel(modelVariant); + QCOMPARE(pathView->model(), modelVariant); + QCOMPARE(modelSpy.count(),1); + + pathView->setModel(modelVariant); + QCOMPARE(modelSpy.count(),1); + + pathView->setModel(QVariant()); + QCOMPARE(modelSpy.count(),2); + + delete canvas; +} QDeclarativeView *tst_QDeclarativePathView::createView() { -- cgit v0.12 From 8da93faace82eb2bc86e76c0ad0a0c5c95e3b8bf Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Tue, 2 Mar 2010 12:07:40 +1000 Subject: Add docs and tests for WorkerListModel. Task-number: QT-2807 --- doc/src/declarative/elements.qdoc | 2 + examples/declarative/workerlistmodel/dataloader.js | 14 ++ .../declarative/workerlistmodel/timedisplay.qml | 33 ++++ src/declarative/qml/qdeclarativeworkerscript.cpp | 137 ++++++++++++++- src/declarative/qml/qdeclarativeworkerscript_p.h | 9 +- .../qdeclarativeworkerlistmodel/data/model.qml | 14 ++ .../qdeclarativeworkerlistmodel/data/script.js | 6 + .../qdeclarativeworkerlistmodel.pro | 9 + .../tst_qdeclarativeworkerlistmodel.cpp | 193 +++++++++++++++++++++ 9 files changed, 414 insertions(+), 3 deletions(-) create mode 100644 examples/declarative/workerlistmodel/dataloader.js create mode 100644 examples/declarative/workerlistmodel/timedisplay.qml create mode 100644 tests/auto/declarative/qdeclarativeworkerlistmodel/data/model.qml create mode 100644 tests/auto/declarative/qdeclarativeworkerlistmodel/data/script.js create mode 100644 tests/auto/declarative/qdeclarativeworkerlistmodel/qdeclarativeworkerlistmodel.pro create mode 100644 tests/auto/declarative/qdeclarativeworkerlistmodel/tst_qdeclarativeworkerlistmodel.cpp diff --git a/doc/src/declarative/elements.qdoc b/doc/src/declarative/elements.qdoc index 1fd4dad..6cca39b 100644 --- a/doc/src/declarative/elements.qdoc +++ b/doc/src/declarative/elements.qdoc @@ -91,6 +91,7 @@ The following table lists the QML elements provided by the Qt Declarative module \o \l VisualDataModel \o \l Package \o \l XmlListModel and XmlRole +\o \l WorkerListModel \o \l DateTimeFormatter \o \l NumberFormatter \endlist @@ -102,6 +103,7 @@ The following table lists the QML elements provided by the Qt Declarative module \o \l Component \o \l Timer \o \l QtObject +\o \l WorkerScript \endlist \endtable diff --git a/examples/declarative/workerlistmodel/dataloader.js b/examples/declarative/workerlistmodel/dataloader.js new file mode 100644 index 0000000..eac7478 --- /dev/null +++ b/examples/declarative/workerlistmodel/dataloader.js @@ -0,0 +1,14 @@ +// ![0] +WorkerScript.onMessage = function(msg) { + console.log("Worker told to", msg.action); + + if (msg.action == 'appendCurrentTime') { + var data = {'time': new Date().toTimeString()}; + msg.model.append(data); + msg.model.sync(); // updates the changes to the list + + var msgToSend = {'msg': 'Model updated!'}; + WorkerScript.sendMessage(msgToSend); + } +} +// ![0] diff --git a/examples/declarative/workerlistmodel/timedisplay.qml b/examples/declarative/workerlistmodel/timedisplay.qml new file mode 100644 index 0000000..3bf2630 --- /dev/null +++ b/examples/declarative/workerlistmodel/timedisplay.qml @@ -0,0 +1,33 @@ +// ![0] +import Qt 4.6 + +ListView { + width: 200 + height: 300 + + model: listModel + delegate: Component { + Text { text: time } + } + + WorkerListModel { id: listModel } + + WorkerScript { + id: worker + source: "dataloader.js" + onMessage: { + console.log("Worker said", messageObject.msg); + } + } + + Timer { + id: timer + interval: 2000; repeat: true; running: true; triggeredOnStart: true + + onTriggered: { + var msg = {'action': 'appendCurrentTime', 'model': listModel}; + worker.sendMessage(msg); + } + } +} +// ![0] diff --git a/src/declarative/qml/qdeclarativeworkerscript.cpp b/src/declarative/qml/qdeclarativeworkerscript.cpp index 03151e4..c1d090e 100644 --- a/src/declarative/qml/qdeclarativeworkerscript.cpp +++ b/src/declarative/qml/qdeclarativeworkerscript.cpp @@ -841,6 +841,41 @@ bool QDeclarativeWorkerListModelAgent::event(QEvent *e) return QObject::event(e); } +/*! + \qmlclass WorkerListModel QDeclarativeWorkerListModel + \brief The WorkerListModel element provides a threaded list model. + + Use WorkerListModel together with WorkerScript to define a list model + that is controlled by a separate thread. This is useful if list modification + operations are synchronous and take some time: using WorkerListModel + moves these operations to a different thread and avoids blocking of the + main GUI thread. + + The thread that creates the WorkerListModel can modify the model for any + initial set-up requirements. However, once the model has been modified by + the associated WorkerScript, the model can only be modified by that worker + script and becomes read-only to all other threads. + + Here is an example application that uses WorkerScript to append the + current time to a WorkerListModel: + + \snippet examples/declarative/workerlistmodel/timedisplay.qml 0 + + The included file, \tt dataloader.js, looks like this: + + \snippet examples/declarative/workerlistmodel/dataloader.js 0 + + The application's \tt Timer object periodically sends a message to the + worker script by calling \tt WorkerScript::sendMessage(). When this message + is received, \tt WorkerScript.onMessage() is invoked in + \tt dataloader.js, which appends the current time to the worker list + model. + + Note that unlike ListModel, WorkerListModel does not have \tt move() and + \tt setProperty() methods. + + \sa WorkerScript, ListModel +*/ QDeclarativeWorkerListModel::QDeclarativeWorkerListModel(QObject *parent) : QListModelInterface(parent), m_agent(0) { @@ -854,6 +889,14 @@ QDeclarativeWorkerListModel::~QDeclarativeWorkerListModel() } } +/*! + \qmlmethod WorkerListModel::clear() + + Deletes all content from the model. The properties are cleared such that + different properties may be set on subsequent additions. + + \sa append() remove() +*/ void QDeclarativeWorkerListModel::clear() { if (m_agent) { @@ -869,6 +912,13 @@ void QDeclarativeWorkerListModel::clear() } } +/*! + \qmlmethod WorkerListModel::remove(int index) + + Deletes the content at \a index from the model. + + \sa clear() +*/ void QDeclarativeWorkerListModel::remove(int index) { if (m_agent) { @@ -884,6 +934,18 @@ void QDeclarativeWorkerListModel::remove(int index) emit countChanged(); } +/*! + \qmlmethod WorkerListModel::append(jsobject dict) + + Adds a new item to the end of the list model, with the + values in \a dict. + + \code + FruitModel.append({"cost": 5.95, "name":"Pizza"}) + \endcode + + \sa set() remove() +*/ void QDeclarativeWorkerListModel::append(const QScriptValue &value) { if (m_agent) { @@ -914,6 +976,21 @@ void QDeclarativeWorkerListModel::append(const QScriptValue &value) emit countChanged(); } +/*! + \qmlmethod WorkerListModel::insert(int index, jsobject dict) + + Adds a new item to the list model at position \a index, with the + values in \a dict. + + \code + FruitModel.insert(2, {"cost": 5.95, "name":"Pizza"}) + \endcode + + The \a index must be to an existing item in the list, or one past + the end of the list (equivalent to append). + + \sa set() append() +*/ void QDeclarativeWorkerListModel::insert(int index, const QScriptValue &value) { if (m_agent) { @@ -946,6 +1023,30 @@ void QDeclarativeWorkerListModel::insert(int index, const QScriptValue &value) emit countChanged(); } +/*! + \qmlmethod object ListModel::get(int index) + + Returns the item at \a index in the list model. + + \code + FruitModel.append({"cost": 5.95, "name":"Jackfruit"}) + FruitModel.get(0).cost + \endcode + + The \a index must be an element in the list. + + Note that properties of the returned object that are themselves objects + will also be models, and this get() method is used to access elements: + + \code + FruitModel.append(..., "attributes": + [{"name":"spikes","value":"7mm"}, + {"name":"color","value":"green"}]); + FruitModel.get(0).attributes.get(1).value; // == "green" + \endcode + + \sa append() +*/ QScriptValue QDeclarativeWorkerListModel::get(int index) const { QDeclarativeEngine *engine = qmlEngine(this); @@ -962,6 +1063,21 @@ QScriptValue QDeclarativeWorkerListModel::get(int index) const return rv; } +/*! + \qmlmethod WorkerListModel::set(int index, jsobject dict) + + Changes the item at \a index in the list model with the + values in \a dict. Properties not appearing in \a valuemap + are left unchanged. + + \code + FruitModel.set(3, {"cost": 5.95, "name":"Pizza"}) + \endcode + + The \a index must be an element in the list. + + \sa append() +*/ void QDeclarativeWorkerListModel::set(int index, const QScriptValue &value) { if (m_agent) { @@ -995,6 +1111,22 @@ void QDeclarativeWorkerListModel::set(int index, const QScriptValue &value) } } +/*! + \qmlmethod WorkerListModel::sync() + + Writes any unsaved changes to the list model. This must be called after + changes have been made to the list model in the worker script. + + Note that this method can only be called from the associated worker script. +*/ +void QDeclarativeWorkerListModel::sync() +{ + // This is really a dummy method to make it look like sync() exists in + // WorkerListModel (and not QDeclarativeWorkerListModelAgent) and to let + // us document sync(). + qmlInfo(this) << "sync() can only be called from a WorkerScript"; +} + QDeclarativeWorkerListModelAgent *QDeclarativeWorkerListModel::agent() { if (!m_agent) @@ -1013,6 +1145,10 @@ QString QDeclarativeWorkerListModel::toString(int role) const return m_roles.value(role); } +/*! + \qmlproperty int ListModel::count + The number of data entries in the model. +*/ int QDeclarativeWorkerListModel::count() const { return m_values.count(); @@ -1038,4 +1174,3 @@ QT_END_NAMESPACE #include "qdeclarativeworkerscript.moc" - diff --git a/src/declarative/qml/qdeclarativeworkerscript_p.h b/src/declarative/qml/qdeclarativeworkerscript_p.h index 8ebd2c1..01cc72a 100644 --- a/src/declarative/qml/qdeclarativeworkerscript_p.h +++ b/src/declarative/qml/qdeclarativeworkerscript_p.h @@ -61,6 +61,8 @@ #include #include +QT_BEGIN_HEADER + QT_BEGIN_NAMESPACE class QDeclarativeWorkerScript; @@ -84,7 +86,7 @@ private: QDeclarativeWorkerScriptEnginePrivate *d; }; -class QDeclarativeWorkerScript : public QObject, public QDeclarativeParserStatus +class Q_DECLARATIVE_EXPORT QDeclarativeWorkerScript : public QObject, public QDeclarativeParserStatus { Q_OBJECT Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) @@ -115,7 +117,7 @@ private: }; class QDeclarativeWorkerListModelAgent; -class QDeclarativeWorkerListModel : public QListModelInterface +class Q_DECLARATIVE_EXPORT QDeclarativeWorkerListModel : public QListModelInterface { Q_OBJECT Q_PROPERTY(int count READ count NOTIFY countChanged) @@ -130,6 +132,7 @@ public: Q_INVOKABLE void insert(int index, const QScriptValue&); Q_INVOKABLE QScriptValue get(int index) const; Q_INVOKABLE void set(int index, const QScriptValue &); + Q_INVOKABLE void sync(); QDeclarativeWorkerListModelAgent *agent(); @@ -157,4 +160,6 @@ QT_END_NAMESPACE QML_DECLARE_TYPE(QDeclarativeWorkerScript); QML_DECLARE_TYPE(QDeclarativeWorkerListModel); +QT_END_HEADER + #endif // QDECLARATIVEWORKERSCRIPT_P_H diff --git a/tests/auto/declarative/qdeclarativeworkerlistmodel/data/model.qml b/tests/auto/declarative/qdeclarativeworkerlistmodel/data/model.qml new file mode 100644 index 0000000..be94e00 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeworkerlistmodel/data/model.qml @@ -0,0 +1,14 @@ +import Qt 4.6 + +Item { + property alias model: model + + WorkerListModel { id: model } + + function workerModifyModel(cmd) { worker.sendMessage({'command': cmd, 'model': model}) } + + WorkerScript { + id: worker + source: "script.js" + } +} diff --git a/tests/auto/declarative/qdeclarativeworkerlistmodel/data/script.js b/tests/auto/declarative/qdeclarativeworkerlistmodel/data/script.js new file mode 100644 index 0000000..8ee62b4 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeworkerlistmodel/data/script.js @@ -0,0 +1,6 @@ +WorkerScript.onMessage = function(msg) { + eval("msg.model." + msg.command) + msg.model.sync() +} + + diff --git a/tests/auto/declarative/qdeclarativeworkerlistmodel/qdeclarativeworkerlistmodel.pro b/tests/auto/declarative/qdeclarativeworkerlistmodel/qdeclarativeworkerlistmodel.pro new file mode 100644 index 0000000..960dbe1 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeworkerlistmodel/qdeclarativeworkerlistmodel.pro @@ -0,0 +1,9 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += declarative +QT += script +macx:CONFIG -= app_bundle + +SOURCES += tst_qdeclarativeworkerlistmodel.cpp + +# Define SRCDIR equal to test's source directory +DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/auto/declarative/qdeclarativeworkerlistmodel/tst_qdeclarativeworkerlistmodel.cpp b/tests/auto/declarative/qdeclarativeworkerlistmodel/tst_qdeclarativeworkerlistmodel.cpp new file mode 100644 index 0000000..11a7447 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeworkerlistmodel/tst_qdeclarativeworkerlistmodel.cpp @@ -0,0 +1,193 @@ +/**************************************************************************** +** +** 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 test suite 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 +#include + +#include +#include +#include + +#include +#include +#include "../../../shared/util.h" + + + +class tst_QDeclarativeWorkerListModel : public QObject +{ + Q_OBJECT +public: + tst_QDeclarativeWorkerListModel() {} +private slots: + void clear(); + void remove(); + void append(); + void insert(); + void get(); + void set(); + +private: + QByteArray modificationWarning() const { + QString file = QUrl::fromLocalFile(SRCDIR "/data/model.qml").toString(); + return QString("QML WorkerListModel (" + file + ":6:5) List can only be modified from a WorkerScript").toUtf8(); + } + + QDeclarativeEngine m_engine; +}; + +void tst_QDeclarativeWorkerListModel::clear() +{ + QDeclarativeComponent component(&m_engine, SRCDIR "/data/model.qml"); + QDeclarativeItem *item = qobject_cast(component.create()); + QVERIFY(item != 0); + QDeclarativeWorkerListModel *model = item->property("model").value(); + QVERIFY(model != 0); + + QCOMPARE(model->count(), 0); + QVERIFY(QMetaObject::invokeMethod(item, "workerModifyModel", Q_ARG(QVariant, "append({'name': 'A'})"))); + QTRY_COMPARE(model->count(), 1); + + QTest::ignoreMessage(QtWarningMsg, modificationWarning().constData()); + model->clear(); + QCOMPARE(model->count(), 1); + + QVERIFY(QMetaObject::invokeMethod(item, "workerModifyModel", Q_ARG(QVariant, "clear()"))); + QTRY_COMPARE(model->count(), 0); + + qApp->processEvents(); +} + +void tst_QDeclarativeWorkerListModel::remove() +{ + QDeclarativeComponent component(&m_engine, SRCDIR "/data/model.qml"); + QDeclarativeItem *item = qobject_cast(component.create()); + QVERIFY(item != 0); + QDeclarativeWorkerListModel *model = item->property("model").value(); + QVERIFY(model != 0); + + QVERIFY(QMetaObject::invokeMethod(item, "workerModifyModel", Q_ARG(QVariant, "append({'name': 'A'})"))); + QTRY_COMPARE(model->count(), 1); + + QTest::ignoreMessage(QtWarningMsg, modificationWarning().constData()); + model->remove(0); + QCOMPARE(model->count(), 1); + + QVERIFY(QMetaObject::invokeMethod(item, "workerModifyModel", Q_ARG(QVariant, "remove(0)"))); + QTRY_COMPARE(model->count(), 0); + + qApp->processEvents(); +} + +void tst_QDeclarativeWorkerListModel::append() +{ + QDeclarativeComponent component(&m_engine, SRCDIR "/data/model.qml"); + QDeclarativeItem *item = qobject_cast(component.create()); + QVERIFY(item != 0); + QDeclarativeWorkerListModel *model = item->property("model").value(); + QVERIFY(model != 0); + + QVERIFY(QMetaObject::invokeMethod(item, "workerModifyModel", Q_ARG(QVariant, "append({'name': 'A'})"))); + QTRY_COMPARE(model->count(), 1); + + QTest::ignoreMessage(QtWarningMsg, modificationWarning().constData()); + model->append(QScriptValue(1)); + QCOMPARE(model->count(), 1); + + qApp->processEvents(); +} + +void tst_QDeclarativeWorkerListModel::insert() +{ + QDeclarativeComponent component(&m_engine, SRCDIR "/data/model.qml"); + QDeclarativeItem *item = qobject_cast(component.create()); + QVERIFY(item != 0); + QDeclarativeWorkerListModel *model = item->property("model").value(); + QVERIFY(model != 0); + + QVERIFY(QMetaObject::invokeMethod(item, "workerModifyModel", Q_ARG(QVariant, "insert(0, {'name': 'A'})"))); + QTRY_COMPARE(model->count(), 1); + + QTest::ignoreMessage(QtWarningMsg, modificationWarning().constData()); + model->insert(0, QScriptValue(1)); + QCOMPARE(model->count(), 1); + + qApp->processEvents(); +} + +void tst_QDeclarativeWorkerListModel::get() +{ + QDeclarativeComponent component(&m_engine, SRCDIR "/data/model.qml"); + QDeclarativeItem *item = qobject_cast(component.create()); + QVERIFY(item != 0); + QDeclarativeWorkerListModel *model = item->property("model").value(); + QVERIFY(model != 0); + + QVERIFY(QMetaObject::invokeMethod(item, "workerModifyModel", Q_ARG(QVariant, "append({'name': 'A'})"))); + QTRY_COMPARE(model->count(), 1); + QCOMPARE(model->get(0).property("name").toString(), QString("A")); + + qApp->processEvents(); +} + +void tst_QDeclarativeWorkerListModel::set() +{ + QDeclarativeComponent component(&m_engine, SRCDIR "/data/model.qml"); + QDeclarativeItem *item = qobject_cast(component.create()); + QVERIFY(item != 0); + QDeclarativeWorkerListModel *model = item->property("model").value(); + QVERIFY(model != 0); + + QVERIFY(QMetaObject::invokeMethod(item, "workerModifyModel", Q_ARG(QVariant, "append({'name': 'A'})"))); + QTRY_COMPARE(model->count(), 1); + + QTest::ignoreMessage(QtWarningMsg, modificationWarning().constData()); + model->set(0, QScriptValue(1)); + + QVERIFY(QMetaObject::invokeMethod(item, "workerModifyModel", Q_ARG(QVariant, "set(0, {'name': 'Z'})"))); + QTRY_COMPARE(model->get(0).property("name").toString(), QString("Z")); + + qApp->processEvents(); +} + +QTEST_MAIN(tst_QDeclarativeWorkerListModel) + +#include "tst_qdeclarativeworkerlistmodel.moc" + -- cgit v0.12 From e71f8823d22c99a4da7de4f49463a05427186c0f Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Mon, 1 Mar 2010 15:55:03 +1000 Subject: Example of text focus. Task-number: QT-448 --- examples/declarative/focusscope/test5.qml | 83 +++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 examples/declarative/focusscope/test5.qml diff --git a/examples/declarative/focusscope/test5.qml b/examples/declarative/focusscope/test5.qml new file mode 100644 index 0000000..da98350 --- /dev/null +++ b/examples/declarative/focusscope/test5.qml @@ -0,0 +1,83 @@ +import Qt 4.6 + +Rectangle { + color: "white" + width: 800 + height: 600 + + Keys.onReturnPressed: console.log("Error - Root") + + FocusScope { + id: myScope + focus: true + + Keys.onReturnPressed: console.log("Error - FocusScope") + + Rectangle { + height: 120 + width: 420 + + color: "transparent" + border.width: 5 + border.color: myScope.wantsFocus?"blue":"black" + + Rectangle { + x: 10; y: 10 + width: 100; height: 100; color: "green" + border.width: 5 + border.color: item1.wantsFocus?"blue":"black" + } + + TextEdit { + id: item1 + x: 20; y: 20 + width: 90; height: 90 + color: "white" + font.pixelSize: 20 + Keys.onReturnPressed: console.log("Top Left"); + KeyNavigation.right: item2 + focus: true + wrap: true + text: "Box 1" + } + + Rectangle { + id: item2 + x: 310; y: 10 + width: 100; height: 100; color: "green" + border.width: 5 + border.color: wantsFocus?"blue":"black" + KeyNavigation.left: item1 + Keys.onReturnPressed: console.log("Top Right"); + + Rectangle { + width: 50; height: 50; anchors.centerIn: parent + color: parent.focus?"red":"transparent" + } + } + } + KeyNavigation.down: item3 + } + + Text { x:100; y:170; text: "Blue border indicates scoped focus\nBlack border indicates NOT scoped focus\nRed box or flashing cursor indicates active focus\nUse arrow keys to navigate\nPress Ctrl-Return to print currently focused item" } + + Rectangle { + x: 10; y: 300 + width: 100; height: 100; color: "green" + border.width: 5 + border.color: item3.wantsFocus?"blue":"black" + } + + TextEdit { + id: item3 + x: 20; y: 310 + width: 90; height: 90 + color: "white" + font.pixelSize: 20 + text: "Box 3" + + Keys.onReturnPressed: console.log("Bottom Left"); + KeyNavigation.up: myScope + wrap: true + } +} -- cgit v0.12 From 05f9a6aa5d6e4f20eb4dacff3acea9d186867ab1 Mon Sep 17 00:00:00 2001 From: Joona Petrell Date: Fri, 26 Feb 2010 16:34:28 +1000 Subject: Add NOTIFY signals to list, grid and path views Reviewed-by: akennedy --- .../graphicsitems/qdeclarativegridview.cpp | 12 +- .../graphicsitems/qdeclarativegridview_p.h | 20 ++- .../graphicsitems/qdeclarativelistview.cpp | 24 ++- .../graphicsitems/qdeclarativelistview_p.h | 38 +++-- src/declarative/graphicsitems/qdeclarativepath.cpp | 11 +- src/declarative/graphicsitems/qdeclarativepath_p.h | 11 +- .../graphicsitems/qdeclarativepathview.cpp | 26 +++- .../graphicsitems/qdeclarativepathview_p.h | 18 ++- .../qdeclarativegridview/data/propertychanges.qml | 69 +++++++++ .../tst_qdeclarativegridview.cpp | 122 ++++++++++++++- .../qdeclarativelistview/data/propertychanges.qml | 71 +++++++++ .../tst_qdeclarativelistview.cpp | 168 +++++++++++++++++++-- .../qdeclarativepathview/data/displaypath.qml | 2 +- .../qdeclarativepathview/data/pathview.qml | 2 +- .../qdeclarativepathview/data/pathview3.qml | 2 +- .../qdeclarativepathview/data/propertychanges.qml | 115 ++++++++++++++ .../tst_qdeclarativepathview.cpp | 167 +++++++++++++++++++- 17 files changed, 818 insertions(+), 60 deletions(-) create mode 100644 tests/auto/declarative/qdeclarativegridview/data/propertychanges.qml create mode 100644 tests/auto/declarative/qdeclarativelistview/data/propertychanges.qml create mode 100644 tests/auto/declarative/qdeclarativepathview/data/propertychanges.qml diff --git a/src/declarative/graphicsitems/qdeclarativegridview.cpp b/src/declarative/graphicsitems/qdeclarativegridview.cpp index 8d778f8..090c46d 100644 --- a/src/declarative/graphicsitems/qdeclarativegridview.cpp +++ b/src/declarative/graphicsitems/qdeclarativegridview.cpp @@ -619,7 +619,7 @@ void QDeclarativeGridViewPrivate::createHighlight() } } if (changed) - emit q->highlightChanged(); + emit q->highlightItemChanged(); } void QDeclarativeGridViewPrivate::updateHighlight() @@ -785,6 +785,8 @@ QVariant QDeclarativeGridView::model() const void QDeclarativeGridView::setModel(const QVariant &model) { Q_D(QDeclarativeGridView); + if (d->modelVariant == model) + return; if (d->model) { disconnect(d->model, SIGNAL(itemsInserted(int,int)), this, SLOT(itemsInserted(int,int))); disconnect(d->model, SIGNAL(itemsRemoved(int,int)), this, SLOT(itemsRemoved(int,int))); @@ -829,6 +831,7 @@ void QDeclarativeGridView::setModel(const QVariant &model) connect(d->model, SIGNAL(destroyingItem(QDeclarativeItem*)), this, SLOT(destroyingItem(QDeclarativeItem*))); emit countChanged(); } + emit modelChanged(); } /*! @@ -872,6 +875,7 @@ void QDeclarativeGridView::setDelegate(QDeclarativeComponent *delegate) d->moveReason = QDeclarativeGridViewPrivate::SetIndex; d->updateCurrent(d->currentIndex); } + emit delegateChanged(); } } @@ -967,6 +971,7 @@ void QDeclarativeGridView::setHighlight(QDeclarativeComponent *highlight) if (highlight != d->highlightComponent) { d->highlightComponent = highlight; d->updateCurrent(d->currentIndex); + emit highlightChanged(); } } @@ -1040,6 +1045,7 @@ void QDeclarativeGridView::setFlow(Flow flow) d->updateGrid(); refill(); d->updateCurrent(d->currentIndex); + emit flowChanged(); } } @@ -1059,7 +1065,10 @@ bool QDeclarativeGridView::isWrapEnabled() const void QDeclarativeGridView::setWrapEnabled(bool wrap) { Q_D(QDeclarativeGridView); + if (d->wrap == wrap) + return; d->wrap = wrap; + emit keyNavigationWrapsChanged(); } /*! @@ -1083,6 +1092,7 @@ void QDeclarativeGridView::setCacheBuffer(int buffer) d->buffer = buffer; if (isComponentComplete()) refill(); + emit cacheBufferChanged(); } } diff --git a/src/declarative/graphicsitems/qdeclarativegridview_p.h b/src/declarative/graphicsitems/qdeclarativegridview_p.h index b488475..d463a46 100644 --- a/src/declarative/graphicsitems/qdeclarativegridview_p.h +++ b/src/declarative/graphicsitems/qdeclarativegridview_p.h @@ -57,19 +57,19 @@ class Q_DECLARATIVE_EXPORT QDeclarativeGridView : public QDeclarativeFlickable Q_OBJECT Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarativeGridView) - Q_PROPERTY(QVariant model READ model WRITE setModel) - Q_PROPERTY(QDeclarativeComponent *delegate READ delegate WRITE setDelegate) + Q_PROPERTY(QVariant model READ model WRITE setModel NOTIFY modelChanged) + Q_PROPERTY(QDeclarativeComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged) Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) Q_PROPERTY(QDeclarativeItem *currentItem READ currentItem NOTIFY currentIndexChanged) Q_PROPERTY(int count READ count NOTIFY countChanged) - Q_PROPERTY(QDeclarativeComponent *highlight READ highlight WRITE setHighlight) - Q_PROPERTY(QDeclarativeItem *highlightItem READ highlightItem NOTIFY highlightChanged) + Q_PROPERTY(QDeclarativeComponent *highlight READ highlight WRITE setHighlight NOTIFY highlightChanged) + Q_PROPERTY(QDeclarativeItem *highlightItem READ highlightItem NOTIFY highlightItemChanged) Q_PROPERTY(bool highlightFollowsCurrentItem READ highlightFollowsCurrentItem WRITE setHighlightFollowsCurrentItem) - Q_PROPERTY(Flow flow READ flow WRITE setFlow) - Q_PROPERTY(bool keyNavigationWraps READ isWrapEnabled WRITE setWrapEnabled) - Q_PROPERTY(int cacheBuffer READ cacheBuffer WRITE setCacheBuffer) + Q_PROPERTY(Flow flow READ flow WRITE setFlow NOTIFY flowChanged) + Q_PROPERTY(bool keyNavigationWraps READ isWrapEnabled WRITE setWrapEnabled NOTIFY keyNavigationWrapsChanged) + Q_PROPERTY(int cacheBuffer READ cacheBuffer WRITE setCacheBuffer NOTIFY cacheBufferChanged) Q_PROPERTY(int cellWidth READ cellWidth WRITE setCellWidth NOTIFY cellWidthChanged) Q_PROPERTY(int cellHeight READ cellHeight WRITE setCellHeight NOTIFY cellHeightChanged) Q_CLASSINFO("DefaultProperty", "data") @@ -129,6 +129,12 @@ Q_SIGNALS: void cellWidthChanged(); void cellHeightChanged(); void highlightChanged(); + void highlightItemChanged(); + void modelChanged(); + void delegateChanged(); + void flowChanged(); + void keyNavigationWrapsChanged(); + void cacheBufferChanged(); protected: virtual void viewportMoved(); diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp index 02a8493..a05e638 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview.cpp +++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp @@ -817,7 +817,7 @@ void QDeclarativeListViewPrivate::createHighlight() } } if (changed) - emit q->highlightChanged(); + emit q->highlightItemChanged(); } void QDeclarativeListViewPrivate::updateHighlight() @@ -1474,6 +1474,8 @@ QVariant QDeclarativeListView::model() const void QDeclarativeListView::setModel(const QVariant &model) { Q_D(QDeclarativeListView); + if (d->modelVariant == model) + return; if (d->model) { disconnect(d->model, SIGNAL(itemsInserted(int,int)), this, SLOT(itemsInserted(int,int))); disconnect(d->model, SIGNAL(itemsRemoved(int,int)), this, SLOT(itemsRemoved(int,int))); @@ -1518,6 +1520,7 @@ void QDeclarativeListView::setModel(const QVariant &model) connect(d->model, SIGNAL(destroyingItem(QDeclarativeItem*)), this, SLOT(destroyingItem(QDeclarativeItem*))); emit countChanged(); } + emit modelChanged(); } /*! @@ -1564,6 +1567,7 @@ void QDeclarativeListView::setDelegate(QDeclarativeComponent *delegate) d->updateCurrent(d->currentIndex); } } + emit delegateChanged(); } /*! @@ -1664,6 +1668,7 @@ void QDeclarativeListView::setHighlight(QDeclarativeComponent *highlight) d->createHighlight(); if (d->currentItem) d->updateHighlight(); + emit highlightChanged(); } } @@ -1701,6 +1706,7 @@ void QDeclarativeListView::setHighlightFollowsCurrentItem(bool autoHighlight) d->highlightSizeAnimator->setEnabled(d->autoHighlight); } d->updateHighlight(); + emit highlightFollowsCurrentItemChanged(); } } @@ -1746,8 +1752,11 @@ qreal QDeclarativeListView::preferredHighlightBegin() const void QDeclarativeListView::setPreferredHighlightBegin(qreal start) { Q_D(QDeclarativeListView); + if (d->highlightRangeStart == start) + return; d->highlightRangeStart = start; d->haveHighlightRange = d->highlightRange != NoHighlightRange && d->highlightRangeStart <= d->highlightRangeEnd; + emit preferredHighlightBeginChanged(); } qreal QDeclarativeListView::preferredHighlightEnd() const @@ -1759,8 +1768,11 @@ qreal QDeclarativeListView::preferredHighlightEnd() const void QDeclarativeListView::setPreferredHighlightEnd(qreal end) { Q_D(QDeclarativeListView); + if (d->highlightRangeEnd == end) + return; d->highlightRangeEnd = end; d->haveHighlightRange = d->highlightRange != NoHighlightRange && d->highlightRangeStart <= d->highlightRangeEnd; + emit preferredHighlightEndChanged(); } QDeclarativeListView::HighlightRangeMode QDeclarativeListView::highlightRangeMode() const @@ -1772,8 +1784,11 @@ QDeclarativeListView::HighlightRangeMode QDeclarativeListView::highlightRangeMod void QDeclarativeListView::setHighlightRangeMode(HighlightRangeMode mode) { Q_D(QDeclarativeListView); + if (d->highlightRange == mode) + return; d->highlightRange = mode; d->haveHighlightRange = d->highlightRange != NoHighlightRange && d->highlightRangeStart <= d->highlightRangeEnd; + emit highlightRangeModeChanged(); } /*! @@ -1849,7 +1864,10 @@ bool QDeclarativeListView::isWrapEnabled() const void QDeclarativeListView::setWrapEnabled(bool wrap) { Q_D(QDeclarativeListView); + if (d->wrap == wrap) + return; d->wrap = wrap; + emit keyNavigationWrapsChanged(); } /*! @@ -1875,6 +1893,7 @@ void QDeclarativeListView::setCacheBuffer(int b) d->bufferMode = QDeclarativeListViewPrivate::BufferBefore | QDeclarativeListViewPrivate::BufferAfter; refill(); } + emit cacheBufferChanged(); } } @@ -1999,6 +2018,7 @@ void QDeclarativeListView::setSnapMode(SnapMode mode) Q_D(QDeclarativeListView); if (d->snapMode != mode) { d->snapMode = mode; + emit snapModeChanged(); } } @@ -2021,6 +2041,7 @@ void QDeclarativeListView::setFooter(QDeclarativeComponent *footer) d->maxExtentDirty = true; d->updateFooter(); d->updateViewport(); + emit footerChanged(); } } @@ -2044,6 +2065,7 @@ void QDeclarativeListView::setHeader(QDeclarativeComponent *header) d->updateHeader(); d->updateFooter(); d->updateViewport(); + emit headerChanged(); } } diff --git a/src/declarative/graphicsitems/qdeclarativelistview_p.h b/src/declarative/graphicsitems/qdeclarativelistview_p.h index 5e3edb0..f9b7b50 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview_p.h +++ b/src/declarative/graphicsitems/qdeclarativelistview_p.h @@ -91,33 +91,33 @@ class Q_DECLARATIVE_EXPORT QDeclarativeListView : public QDeclarativeFlickable Q_OBJECT Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarativeListView) - Q_PROPERTY(QVariant model READ model WRITE setModel) - Q_PROPERTY(QDeclarativeComponent *delegate READ delegate WRITE setDelegate) + Q_PROPERTY(QVariant model READ model WRITE setModel NOTIFY modelChanged) + Q_PROPERTY(QDeclarativeComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged) Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) Q_PROPERTY(QDeclarativeItem *currentItem READ currentItem NOTIFY currentIndexChanged) Q_PROPERTY(int count READ count NOTIFY countChanged) - Q_PROPERTY(QDeclarativeComponent *highlight READ highlight WRITE setHighlight) - Q_PROPERTY(QDeclarativeItem *highlightItem READ highlightItem NOTIFY highlightChanged) - Q_PROPERTY(bool highlightFollowsCurrentItem READ highlightFollowsCurrentItem WRITE setHighlightFollowsCurrentItem) + Q_PROPERTY(QDeclarativeComponent *highlight READ highlight WRITE setHighlight NOTIFY highlightChanged) + Q_PROPERTY(QDeclarativeItem *highlightItem READ highlightItem NOTIFY highlightItemChanged) + Q_PROPERTY(bool highlightFollowsCurrentItem READ highlightFollowsCurrentItem WRITE setHighlightFollowsCurrentItem NOTIFY highlightFollowsCurrentItemChanged) Q_PROPERTY(qreal highlightMoveSpeed READ highlightMoveSpeed WRITE setHighlightMoveSpeed NOTIFY highlightMoveSpeedChanged) Q_PROPERTY(qreal highlightResizeSpeed READ highlightResizeSpeed WRITE setHighlightResizeSpeed NOTIFY highlightResizeSpeedChanged) - Q_PROPERTY(qreal preferredHighlightBegin READ preferredHighlightBegin WRITE setPreferredHighlightBegin) - Q_PROPERTY(qreal preferredHighlightEnd READ preferredHighlightEnd WRITE setPreferredHighlightEnd) - Q_PROPERTY(HighlightRangeMode highlightRangeMode READ highlightRangeMode WRITE setHighlightRangeMode) + Q_PROPERTY(qreal preferredHighlightBegin READ preferredHighlightBegin WRITE setPreferredHighlightBegin NOTIFY preferredHighlightBeginChanged) + Q_PROPERTY(qreal preferredHighlightEnd READ preferredHighlightEnd WRITE setPreferredHighlightEnd NOTIFY preferredHighlightEndChanged) + Q_PROPERTY(HighlightRangeMode highlightRangeMode READ highlightRangeMode WRITE setHighlightRangeMode NOTIFY highlightRangeModeChanged) Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing NOTIFY spacingChanged) Q_PROPERTY(Orientation orientation READ orientation WRITE setOrientation NOTIFY orientationChanged) - Q_PROPERTY(bool keyNavigationWraps READ isWrapEnabled WRITE setWrapEnabled) - Q_PROPERTY(int cacheBuffer READ cacheBuffer WRITE setCacheBuffer) + Q_PROPERTY(bool keyNavigationWraps READ isWrapEnabled WRITE setWrapEnabled NOTIFY keyNavigationWrapsChanged) + Q_PROPERTY(int cacheBuffer READ cacheBuffer WRITE setCacheBuffer NOTIFY cacheBufferChanged) Q_PROPERTY(QDeclarativeViewSection *section READ sectionCriteria CONSTANT) Q_PROPERTY(QString currentSection READ currentSection NOTIFY currentSectionChanged) - Q_PROPERTY(SnapMode snapMode READ snapMode WRITE setSnapMode) + Q_PROPERTY(SnapMode snapMode READ snapMode WRITE setSnapMode NOTIFY snapModeChanged) - Q_PROPERTY(QDeclarativeComponent *header READ header WRITE setHeader) - Q_PROPERTY(QDeclarativeComponent *footer READ footer WRITE setFooter) + Q_PROPERTY(QDeclarativeComponent *header READ header WRITE setHeader NOTIFY headerChanged) + Q_PROPERTY(QDeclarativeComponent *footer READ footer WRITE setFooter NOTIFY footerChanged) Q_ENUMS(HighlightRangeMode) Q_ENUMS(Orientation) @@ -205,6 +205,18 @@ Q_SIGNALS: void highlightMoveSpeedChanged(); void highlightResizeSpeedChanged(); void highlightChanged(); + void highlightItemChanged(); + void modelChanged(); + void delegateChanged(); + void highlightFollowsCurrentItemChanged(); + void preferredHighlightBeginChanged(); + void preferredHighlightEndChanged(); + void highlightRangeModeChanged(); + void keyNavigationWrapsChanged(); + void cacheBufferChanged(); + void snapModeChanged(); + void headerChanged(); + void footerChanged(); protected: virtual void viewportMoved(); diff --git a/src/declarative/graphicsitems/qdeclarativepath.cpp b/src/declarative/graphicsitems/qdeclarativepath.cpp index 48f112a..80586b8 100644 --- a/src/declarative/graphicsitems/qdeclarativepath.cpp +++ b/src/declarative/graphicsitems/qdeclarativepath.cpp @@ -114,7 +114,10 @@ qreal QDeclarativePath::startX() const void QDeclarativePath::setStartX(qreal x) { Q_D(QDeclarativePath); + if (qFuzzyCompare(x, d->startX)) + return; d->startX = x; + emit startXChanged(); } qreal QDeclarativePath::startY() const @@ -126,7 +129,10 @@ qreal QDeclarativePath::startY() const void QDeclarativePath::setStartY(qreal y) { Q_D(QDeclarativePath); + if (qFuzzyCompare(y, d->startY)) + return; d->startY = y; + emit startYChanged(); } /*! @@ -522,7 +528,10 @@ QString QDeclarativePathAttribute::name() const void QDeclarativePathAttribute::setName(const QString &name) { - _name = name; + if (_name == name) + return; + _name = name; + emit nameChanged(); } /*! diff --git a/src/declarative/graphicsitems/qdeclarativepath_p.h b/src/declarative/graphicsitems/qdeclarativepath_p.h index b3139f8..d7cfca1 100644 --- a/src/declarative/graphicsitems/qdeclarativepath_p.h +++ b/src/declarative/graphicsitems/qdeclarativepath_p.h @@ -67,7 +67,7 @@ class Q_DECLARATIVE_EXPORT QDeclarativePathAttribute : public QDeclarativePathEl { Q_OBJECT - Q_PROPERTY(QString name READ name WRITE setName) + Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY changed) public: QDeclarativePathAttribute(QObject *parent=0) : QDeclarativePathElement(parent), _value(0) {} @@ -79,6 +79,9 @@ public: qreal value() const; void setValue(qreal value); +Q_SIGNALS: + void nameChanged(); + private: QString _name; qreal _value; @@ -190,8 +193,8 @@ class Q_DECLARATIVE_EXPORT QDeclarativePath : public QObject, public QDeclarativ Q_INTERFACES(QDeclarativeParserStatus) Q_PROPERTY(QDeclarativeListProperty pathElements READ pathElements) - Q_PROPERTY(qreal startX READ startX WRITE setStartX) - Q_PROPERTY(qreal startY READ startY WRITE setStartY) + Q_PROPERTY(qreal startX READ startX WRITE setStartX NOTIFY startXChanged) + Q_PROPERTY(qreal startY READ startY WRITE setStartY NOTIFY startYChanged) Q_PROPERTY(bool closed READ isClosed NOTIFY changed) Q_CLASSINFO("DefaultProperty", "pathElements") Q_INTERFACES(QDeclarativeParserStatus) @@ -216,6 +219,8 @@ public: Q_SIGNALS: void changed(); + void startXChanged(); + void startYChanged(); protected: virtual void componentComplete(); diff --git a/src/declarative/graphicsitems/qdeclarativepathview.cpp b/src/declarative/graphicsitems/qdeclarativepathview.cpp index f1b0213..50aa9ef 100644 --- a/src/declarative/graphicsitems/qdeclarativepathview.cpp +++ b/src/declarative/graphicsitems/qdeclarativepathview.cpp @@ -203,6 +203,9 @@ QVariant QDeclarativePathView::model() const void QDeclarativePathView::setModel(const QVariant &model) { Q_D(QDeclarativePathView); + if (d->modelVariant == model) + return; + if (d->model) { disconnect(d->model, SIGNAL(itemsInserted(int,int)), this, SLOT(itemsInserted(int,int))); disconnect(d->model, SIGNAL(itemsRemoved(int,int)), this, SLOT(itemsRemoved(int,int))); @@ -242,6 +245,7 @@ void QDeclarativePathView::setModel(const QVariant &model) d->pathOffset = 0; d->regenerate(); d->fixOffset(); + emit modelChanged(); } /*! @@ -269,9 +273,12 @@ QDeclarativePath *QDeclarativePathView::path() const void QDeclarativePathView::setPath(QDeclarativePath *path) { Q_D(QDeclarativePathView); + if (d->path == path) + return; d->path = path; connect(d->path, SIGNAL(changed()), this, SLOT(refill())); d->regenerate(); + emit pathChanged(); } /*! @@ -333,7 +340,7 @@ void QDeclarativePathViewPrivate::setOffset(qreal o) /*! \qmlproperty real PathView::snapPosition - This property determines the position (0-100) the nearest item will snap to. + This property determines the position (0.0-1.0) the nearest item will snap to. */ qreal QDeclarativePathView::snapPosition() const { @@ -344,8 +351,12 @@ qreal QDeclarativePathView::snapPosition() const void QDeclarativePathView::setSnapPosition(qreal pos) { Q_D(QDeclarativePathView); - d->snapPos = pos/100; + qreal normalizedPos = pos - int(pos); + if (qFuzzyCompare(normalizedPos, d->snapPos)) + return; + d->snapPos = normalizedPos; d->fixOffset(); + emit snapPositionChanged(); } /*! @@ -365,7 +376,10 @@ qreal QDeclarativePathView::dragMargin() const void QDeclarativePathView::setDragMargin(qreal dragMargin) { Q_D(QDeclarativePathView); + if (d->dragMargin == dragMargin) + return; d->dragMargin = dragMargin; + emit dragMarginChanged(); } /*! @@ -392,16 +406,19 @@ QDeclarativeComponent *QDeclarativePathView::delegate() const return 0; } -void QDeclarativePathView::setDelegate(QDeclarativeComponent *c) +void QDeclarativePathView::setDelegate(QDeclarativeComponent *delegate) { Q_D(QDeclarativePathView); + if (delegate == this->delegate()) + return; if (!d->ownModel) { d->model = new QDeclarativeVisualDataModel(qmlContext(this)); d->ownModel = true; } if (QDeclarativeVisualDataModel *dataModel = qobject_cast(d->model)) { - dataModel->setDelegate(c); + dataModel->setDelegate(delegate); d->regenerate(); + emit delegateChanged(); } } @@ -422,6 +439,7 @@ void QDeclarativePathView::setPathItemCount(int i) return; d->pathItems = i; d->regenerate(); + pathItemCountChanged(); } QPointF QDeclarativePathViewPrivate::pointNear(const QPointF &point, qreal *nearPercent) const diff --git a/src/declarative/graphicsitems/qdeclarativepathview_p.h b/src/declarative/graphicsitems/qdeclarativepathview_p.h index 709a4fc..df9c6ae 100644 --- a/src/declarative/graphicsitems/qdeclarativepathview_p.h +++ b/src/declarative/graphicsitems/qdeclarativepathview_p.h @@ -56,15 +56,15 @@ class Q_DECLARATIVE_EXPORT QDeclarativePathView : public QDeclarativeItem { Q_OBJECT - Q_PROPERTY(QVariant model READ model WRITE setModel) - Q_PROPERTY(QDeclarativePath *path READ path WRITE setPath) + Q_PROPERTY(QVariant model READ model WRITE setModel NOTIFY modelChanged) + Q_PROPERTY(QDeclarativePath *path READ path WRITE setPath NOTIFY pathChanged) Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) Q_PROPERTY(qreal offset READ offset WRITE setOffset NOTIFY offsetChanged) - Q_PROPERTY(qreal snapPosition READ snapPosition WRITE setSnapPosition) - Q_PROPERTY(qreal dragMargin READ dragMargin WRITE setDragMargin) + Q_PROPERTY(qreal snapPosition READ snapPosition WRITE setSnapPosition NOTIFY snapPositionChanged) + Q_PROPERTY(qreal dragMargin READ dragMargin WRITE setDragMargin NOTIFY dragMarginChanged) Q_PROPERTY(int count READ count) - Q_PROPERTY(QDeclarativeComponent *delegate READ delegate WRITE setDelegate) - Q_PROPERTY(int pathItemCount READ pathItemCount WRITE setPathItemCount) + Q_PROPERTY(QDeclarativeComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged) + Q_PROPERTY(int pathItemCount READ pathItemCount WRITE setPathItemCount NOTIFY pathItemCountChanged) public: QDeclarativePathView(QDeclarativeItem *parent=0); @@ -101,6 +101,12 @@ public: Q_SIGNALS: void currentIndexChanged(); void offsetChanged(); + void modelChanged(); + void pathChanged(); + void dragMarginChanged(); + void snapPositionChanged(); + void delegateChanged(); + void pathItemCountChanged(); protected: void mousePressEvent(QGraphicsSceneMouseEvent *event); diff --git a/tests/auto/declarative/qdeclarativegridview/data/propertychanges.qml b/tests/auto/declarative/qdeclarativegridview/data/propertychanges.qml new file mode 100644 index 0000000..da2e8d0 --- /dev/null +++ b/tests/auto/declarative/qdeclarativegridview/data/propertychanges.qml @@ -0,0 +1,69 @@ +import Qt 4.6 + +Rectangle { + width: 360; height: 120; color: "white" + Component { + id: delegate + Item { + id: wrapper + width: 180; height: 40; + Column { + x: 5; y: 5 + Text { text: 'Name: ' + name } + Text { text: 'Number: ' + number } + } + } + } + Component { + id: highlightRed + Rectangle { + color: "red" + radius: 10 + opacity: 0.5 + } + } + GridView { + cellWidth:180 + cellHeight:40 + objectName: "gridView" + anchors.fill: parent + model: listModel + delegate: delegate + highlight: highlightRed + focus: true + keyNavigationWraps: true + cacheBuffer: 10 + flow: GridView.LeftToRight + } + + data:[ + ListModel { + id: listModel + ListElement { + name: "Bill Smith" + number: "555 3264" + } + ListElement { + name: "John Brown" + number: "555 8426" + } + ListElement { + name: "Sam Wise" + number: "555 0473" + } + }, + ListModel { + objectName: "alternateModel" + ListElement { + name: "Jack" + number: "555 8426" + } + ListElement { + name: "Mary" + number: "555 3264" + } + } + ] +} + + \ No newline at end of file diff --git a/tests/auto/declarative/qdeclarativegridview/tst_qdeclarativegridview.cpp b/tests/auto/declarative/qdeclarativegridview/tst_qdeclarativegridview.cpp index 7a6a060..5d57bb4 100644 --- a/tests/auto/declarative/qdeclarativegridview/tst_qdeclarativegridview.cpp +++ b/tests/auto/declarative/qdeclarativegridview/tst_qdeclarativegridview.cpp @@ -39,10 +39,8 @@ ** ****************************************************************************/ -#include -#include -#include #include +<<<<<<< HEAD #include #include #include @@ -50,6 +48,18 @@ #include #include #include +======= +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +>>>>>>> Add NOTIFY signals to list, grid and path views class tst_QDeclarativeGridView : public QObject { @@ -67,6 +77,9 @@ private slots: void currentIndex(); void defaultValues(); void properties(); + void propertyChanges(); + void componentChanges(); + void modelChanges(); void positionViewAtIndex(); void resetModel(); void QTBUG_8456(); @@ -92,7 +105,7 @@ public: setRoleNames(roles); } - int rowCount(const QModelIndex &parent=QModelIndex()) const { return list.count(); } + int rowCount(const QModelIndex &parent=QModelIndex()) const { Q_UNUSED(parent); return list.count(); } QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const { QVariant rv; if (role == Name) @@ -803,6 +816,107 @@ void tst_QDeclarativeGridView::properties() delete obj; } +void tst_QDeclarativeGridView::propertyChanges() +{ + QDeclarativeView *canvas = createView(); + QVERIFY(canvas); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/propertychanges.qml")); + + QDeclarativeGridView *gridView = canvas->rootObject()->findChild("gridView"); + QVERIFY(gridView); + + QSignalSpy keyNavigationWrapsSpy(gridView, SIGNAL(keyNavigationWrapsChanged())); + QSignalSpy cacheBufferSpy(gridView, SIGNAL(cacheBufferChanged())); + QSignalSpy flowSpy(gridView, SIGNAL(flowChanged())); + + QCOMPARE(gridView->isWrapEnabled(), true); + QCOMPARE(gridView->cacheBuffer(), 10); + QCOMPARE(gridView->flow(), QDeclarativeGridView::LeftToRight); + + gridView->setWrapEnabled(false); + gridView->setCacheBuffer(3); + gridView->setFlow(QDeclarativeGridView::TopToBottom); + + QCOMPARE(gridView->isWrapEnabled(), false); + QCOMPARE(gridView->cacheBuffer(), 3); + QCOMPARE(gridView->flow(), QDeclarativeGridView::TopToBottom); + + QCOMPARE(keyNavigationWrapsSpy.count(),1); + QCOMPARE(cacheBufferSpy.count(),1); + QCOMPARE(flowSpy.count(),1); + + gridView->setWrapEnabled(false); + gridView->setCacheBuffer(3); + gridView->setFlow(QDeclarativeGridView::TopToBottom); + + QCOMPARE(keyNavigationWrapsSpy.count(),1); + QCOMPARE(cacheBufferSpy.count(),1); + QCOMPARE(flowSpy.count(),1); + + delete canvas; +} + +void tst_QDeclarativeGridView::componentChanges() +{ + QDeclarativeView *canvas = createView(); + QVERIFY(canvas); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/propertychanges.qml")); + + QDeclarativeGridView *gridView = canvas->rootObject()->findChild("gridView"); + QVERIFY(gridView); + + QDeclarativeComponent component(canvas->engine()); + component.setData("import Qt 4.6; Rectangle { color: \"blue\"; }", QUrl::fromLocalFile("")); + + QDeclarativeComponent delegateComponent(canvas->engine()); + delegateComponent.setData("import Qt 4.6; Text { text: 'Name: ' + name }", QUrl::fromLocalFile("")); + + QSignalSpy highlightSpy(gridView, SIGNAL(highlightChanged())); + QSignalSpy delegateSpy(gridView, SIGNAL(delegateChanged())); + + gridView->setHighlight(&component); + gridView->setDelegate(&delegateComponent); + + QCOMPARE(gridView->highlight(), &component); + QCOMPARE(gridView->delegate(), &delegateComponent); + + QCOMPARE(highlightSpy.count(),1); + QCOMPARE(delegateSpy.count(),1); + + gridView->setHighlight(&component); + gridView->setDelegate(&delegateComponent); + + QCOMPARE(highlightSpy.count(),1); + QCOMPARE(delegateSpy.count(),1); + delete canvas; +} + +void tst_QDeclarativeGridView::modelChanges() +{ + QDeclarativeView *canvas = createView(); + QVERIFY(canvas); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/propertychanges.qml")); + + QDeclarativeGridView *gridView = canvas->rootObject()->findChild("gridView"); + QVERIFY(gridView); + + QDeclarativeListModel *alternateModel = canvas->rootObject()->findChild("alternateModel"); + QVERIFY(alternateModel); + QVariant modelVariant = QVariant::fromValue(alternateModel); + QSignalSpy modelSpy(gridView, SIGNAL(modelChanged())); + + gridView->setModel(modelVariant); + QCOMPARE(gridView->model(), modelVariant); + QCOMPARE(modelSpy.count(),1); + + gridView->setModel(modelVariant); + QCOMPARE(modelSpy.count(),1); + + gridView->setModel(QVariant()); + QCOMPARE(modelSpy.count(),2); + delete canvas; +} + void tst_QDeclarativeGridView::positionViewAtIndex() { QDeclarativeView *canvas = createView(); diff --git a/tests/auto/declarative/qdeclarativelistview/data/propertychanges.qml b/tests/auto/declarative/qdeclarativelistview/data/propertychanges.qml new file mode 100644 index 0000000..a41f003 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelistview/data/propertychanges.qml @@ -0,0 +1,71 @@ +import Qt 4.6 + +Rectangle { + width: 180; height: 120; color: "white" + Component { + id: delegate + Item { + id: wrapper + width: 180; height: 40; + Column { + x: 5; y: 5 + Text { text: 'Name: ' + name } + Text { text: 'Number: ' + number } + } + } + } + Component { + id: highlightRed + Rectangle { + color: "red" + radius: 10 + opacity: 0.5 + } + } + ListView { + objectName: "listView" + anchors.fill: parent + model: listModel + delegate: delegate + highlight: highlightRed + focus: true + highlightFollowsCurrentItem: true + preferredHighlightBegin: 0.0 + preferredHighlightEnd: 0.0 + highlightRangeMode: ListView.ApplyRange + keyNavigationWraps: true + cacheBuffer: 10 + snapMode: ListView.SnapToItem + } + + data:[ + ListModel { + id: listModel + ListElement { + name: "Bill Smith" + number: "555 3264" + } + ListElement { + name: "John Brown" + number: "555 8426" + } + ListElement { + name: "Sam Wise" + number: "555 0473" + } + }, + ListModel { + objectName: "alternateModel" + ListElement { + name: "Jack" + number: "555 8426" + } + ListElement { + name: "Mary" + number: "555 3264" + } + } + ] +} + + \ No newline at end of file diff --git a/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp b/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp index f15f26b..a36224f 100644 --- a/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp +++ b/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp @@ -38,15 +38,18 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ + #include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include class tst_QDeclarativeListView : public QObject { @@ -82,6 +85,9 @@ private slots: void cacheBuffer(); void positionViewAtIndex(); void resetModel(); + void propertyChanges(); + void componentChanges(); + void modelChanges(); private: template void items(); @@ -240,7 +246,7 @@ public: setRoleNames(roles); } - int rowCount(const QModelIndex &parent=QModelIndex()) const { return list.count(); } + int rowCount(const QModelIndex &parent=QModelIndex()) const { Q_UNUSED(parent); return list.count(); } QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const { QVariant rv; if (role == Name) @@ -379,6 +385,7 @@ void tst_QDeclarativeListView::items() delete canvas; } + template void tst_QDeclarativeListView::changed() { @@ -1275,6 +1282,149 @@ void tst_QDeclarativeListView::resetModel() } } +void tst_QDeclarativeListView::propertyChanges() +{ + QDeclarativeView *canvas = createView(); + QVERIFY(canvas); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/propertychanges.qml")); + + QDeclarativeListView *listView = canvas->rootObject()->findChild("listView"); + QVERIFY(listView); + + QSignalSpy highlightFollowsCurrentItemSpy(listView, SIGNAL(highlightFollowsCurrentItemChanged())); + QSignalSpy preferredHighlightBeginSpy(listView, SIGNAL(preferredHighlightBeginChanged())); + QSignalSpy preferredHighlightEndSpy(listView, SIGNAL(preferredHighlightEndChanged())); + QSignalSpy highlightRangeModeSpy(listView, SIGNAL(highlightRangeModeChanged())); + QSignalSpy keyNavigationWrapsSpy(listView, SIGNAL(keyNavigationWrapsChanged())); + QSignalSpy cacheBufferSpy(listView, SIGNAL(cacheBufferChanged())); + QSignalSpy snapModeSpy(listView, SIGNAL(snapModeChanged())); + + QCOMPARE(listView->highlightFollowsCurrentItem(), true); + QCOMPARE(listView->preferredHighlightBegin(), 0.0); + QCOMPARE(listView->preferredHighlightEnd(), 0.0); + QCOMPARE(listView->highlightRangeMode(), QDeclarativeListView::ApplyRange); + QCOMPARE(listView->isWrapEnabled(), true); + QCOMPARE(listView->cacheBuffer(), 10); + QCOMPARE(listView->snapMode(), QDeclarativeListView::SnapToItem); + + listView->setHighlightFollowsCurrentItem(false); + listView->setPreferredHighlightBegin(1.0); + listView->setPreferredHighlightEnd(1.0); + listView->setHighlightRangeMode(QDeclarativeListView::StrictlyEnforceRange); + listView->setWrapEnabled(false); + listView->setCacheBuffer(3); + listView->setSnapMode(QDeclarativeListView::SnapOneItem); + + QCOMPARE(listView->highlightFollowsCurrentItem(), false); + QCOMPARE(listView->preferredHighlightBegin(), 1.0); + QCOMPARE(listView->preferredHighlightEnd(), 1.0); + QCOMPARE(listView->highlightRangeMode(), QDeclarativeListView::StrictlyEnforceRange); + QCOMPARE(listView->isWrapEnabled(), false); + QCOMPARE(listView->cacheBuffer(), 3); + QCOMPARE(listView->snapMode(), QDeclarativeListView::SnapOneItem); + + QCOMPARE(highlightFollowsCurrentItemSpy.count(),1); + QCOMPARE(preferredHighlightBeginSpy.count(),1); + QCOMPARE(preferredHighlightEndSpy.count(),1); + QCOMPARE(highlightRangeModeSpy.count(),1); + QCOMPARE(keyNavigationWrapsSpy.count(),1); + QCOMPARE(cacheBufferSpy.count(),1); + QCOMPARE(snapModeSpy.count(),1); + + listView->setHighlightFollowsCurrentItem(false); + listView->setPreferredHighlightBegin(1.0); + listView->setPreferredHighlightEnd(1.0); + listView->setHighlightRangeMode(QDeclarativeListView::StrictlyEnforceRange); + listView->setWrapEnabled(false); + listView->setCacheBuffer(3); + listView->setSnapMode(QDeclarativeListView::SnapOneItem); + + QCOMPARE(highlightFollowsCurrentItemSpy.count(),1); + QCOMPARE(preferredHighlightBeginSpy.count(),1); + QCOMPARE(preferredHighlightEndSpy.count(),1); + QCOMPARE(highlightRangeModeSpy.count(),1); + QCOMPARE(keyNavigationWrapsSpy.count(),1); + QCOMPARE(cacheBufferSpy.count(),1); + QCOMPARE(snapModeSpy.count(),1); + + delete canvas; +} + +void tst_QDeclarativeListView::componentChanges() +{ + QDeclarativeView *canvas = createView(); + QVERIFY(canvas); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/propertychanges.qml")); + + QDeclarativeListView *listView = canvas->rootObject()->findChild("listView"); + QVERIFY(listView); + + QDeclarativeComponent component(canvas->engine()); + component.setData("import Qt 4.6; Rectangle { color: \"blue\"; }", QUrl::fromLocalFile("")); + + QDeclarativeComponent delegateComponent(canvas->engine()); + delegateComponent.setData("import Qt 4.6; Text { text: 'Name: ' + name }", QUrl::fromLocalFile("")); + + QSignalSpy highlightSpy(listView, SIGNAL(highlightChanged())); + QSignalSpy delegateSpy(listView, SIGNAL(delegateChanged())); + QSignalSpy headerSpy(listView, SIGNAL(headerChanged())); + QSignalSpy footerSpy(listView, SIGNAL(footerChanged())); + + listView->setHighlight(&component); + listView->setHeader(&component); + listView->setFooter(&component); + listView->setDelegate(&delegateComponent); + + QCOMPARE(listView->highlight(), &component); + QCOMPARE(listView->header(), &component); + QCOMPARE(listView->footer(), &component); + QCOMPARE(listView->delegate(), &delegateComponent); + + QCOMPARE(highlightSpy.count(),1); + QCOMPARE(delegateSpy.count(),1); + QCOMPARE(headerSpy.count(),1); + QCOMPARE(footerSpy.count(),1); + + listView->setHighlight(&component); + listView->setHeader(&component); + listView->setFooter(&component); + listView->setDelegate(&delegateComponent); + + QCOMPARE(highlightSpy.count(),1); + QCOMPARE(delegateSpy.count(),1); + QCOMPARE(headerSpy.count(),1); + QCOMPARE(footerSpy.count(),1); + + delete canvas; +} + +void tst_QDeclarativeListView::modelChanges() +{ + QDeclarativeView *canvas = createView(); + QVERIFY(canvas); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/propertychanges.qml")); + + QDeclarativeListView *listView = canvas->rootObject()->findChild("listView"); + QVERIFY(listView); + + QDeclarativeListModel *alternateModel = canvas->rootObject()->findChild("alternateModel"); + QVERIFY(alternateModel); + QVariant modelVariant = QVariant::fromValue(alternateModel); + QSignalSpy modelSpy(listView, SIGNAL(modelChanged())); + + listView->setModel(modelVariant); + QCOMPARE(listView->model(), modelVariant); + QCOMPARE(modelSpy.count(),1); + + listView->setModel(modelVariant); + QCOMPARE(modelSpy.count(),1); + + listView->setModel(QVariant()); + QCOMPARE(modelSpy.count(),2); + + delete canvas; +} + void tst_QDeclarativeListView::qListModelInterface_items() { items(); diff --git a/tests/auto/declarative/qdeclarativepathview/data/displaypath.qml b/tests/auto/declarative/qdeclarativepathview/data/displaypath.qml index 627f38a..ab1538b 100644 --- a/tests/auto/declarative/qdeclarativepathview/data/displaypath.qml +++ b/tests/auto/declarative/qdeclarativepathview/data/displaypath.qml @@ -33,7 +33,7 @@ Rectangle { height: 320 model: testModel delegate: delegate - snapPosition: 0.01 + snapPosition: 0.0001 path: Path { startY: 120 startX: 160 diff --git a/tests/auto/declarative/qdeclarativepathview/data/pathview.qml b/tests/auto/declarative/qdeclarativepathview/data/pathview.qml index 8fa8d59..c5d88cd 100644 --- a/tests/auto/declarative/qdeclarativepathview/data/pathview.qml +++ b/tests/auto/declarative/qdeclarativepathview/data/pathview.qml @@ -39,7 +39,7 @@ Rectangle { height: 320 model: testModel delegate: delegate - snapPosition: 0.01 + snapPosition: 0.0001 path: Path { startY: 120 startX: 160 diff --git a/tests/auto/declarative/qdeclarativepathview/data/pathview3.qml b/tests/auto/declarative/qdeclarativepathview/data/pathview3.qml index af3ae13..f8ed29f 100644 --- a/tests/auto/declarative/qdeclarativepathview/data/pathview3.qml +++ b/tests/auto/declarative/qdeclarativepathview/data/pathview3.qml @@ -3,7 +3,7 @@ import Qt 4.6 PathView { id: photoPathView y: 100; width: 800; height: 330; pathItemCount: 4; offset: 10 - dragMargin: 24; snapPosition: 50 + dragMargin: 24; snapPosition: 0.50 path: Path { startX: -50; startY: 40; diff --git a/tests/auto/declarative/qdeclarativepathview/data/propertychanges.qml b/tests/auto/declarative/qdeclarativepathview/data/propertychanges.qml new file mode 100644 index 0000000..db70b7b --- /dev/null +++ b/tests/auto/declarative/qdeclarativepathview/data/propertychanges.qml @@ -0,0 +1,115 @@ +import Qt 4.6 + +Rectangle { + width: 350; height: 220; color: "white" + Component { + id: myDelegate + Item { + id: wrapper + width: 180; height: 40; + opacity: PathView.opacity + Column { + x: 5; y: 5 + Text { text: 'Name: ' + name } + Text { text: 'Number: ' + number } + } + } + } + + PathView { + snapPosition: 0.1 + dragMargin: 5.0 + id: pathView + objectName: "pathView" + anchors.fill: parent + model: listModel + delegate: myDelegate + focus: true + path: Path { + id: myPath + objectName: "path" + startX: 220; startY: 200 + PathAttribute { name: "opacity"; value: 1.0; objectName: "pathAttribute"; } + PathQuad { x: 220; y: 25; controlX: 260; controlY: 75 } + PathAttribute { name: "opacity"; value: 0.3 } + PathQuad { x: 220; y: 200; controlX: -20; controlY: 75 } + } + Timer { + interval: 2000; running: true; repeat: true + onTriggered: { + if (pathView.path == alternatePath) + pathView.path = myPath; + else + pathView.path = alternatePath; + } + } + } + + data:[ + ListModel { + id: listModel + ListElement { + name: "Bill Smith" + number: "555 3264" + } + ListElement { + name: "John Brown" + number: "555 8426" + } + ListElement { + name: "Sam Wise" + number: "555 0473" + } + ListElement { + name: "Bill Smith" + number: "555 3264" + } + ListElement { + name: "John Brown" + number: "555 8426" + } + ListElement { + name: "Sam Wise" + number: "555 0473" + } + ListElement { + name: "Bill Smith" + number: "555 3264" + } + ListElement { + name: "John Brown" + number: "555 8426" + } + ListElement { + name: "Sam Wise" + number: "555 0473" + } + }, + ListModel { + objectName: "alternateModel" + ListElement { + name: "Jack" + number: "555 8426" + } + ListElement { + name: "Mary" + number: "555 3264" + } + }, + Path { + id: alternatePath + objectName: "alternatePath" + startX: 100; startY: 40 + PathAttribute { name: "opacity"; value: 0.0 } + PathLine { x: 100; y: 160 } + PathAttribute { name: "opacity"; value: 0.2 } + PathLine { x: 300; y: 160 } + PathAttribute { name: "opacity"; value: 0.0 } + PathLine { x: 300; y: 40 } + PathAttribute { name: "opacity"; value: 0.2 } + PathLine { x: 100; y: 40 } + } + ] +} + + diff --git a/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp b/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp index 79bc607..fa4e9d3 100644 --- a/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp +++ b/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp @@ -38,20 +38,23 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ -#include -#include -#include -#include -#include + +#include +#include #include #include -#include +#include +#include +#include +#include #include #include +#include +#include #include #include #include -#include + #include "../../../shared/util.h" class tst_QDeclarativePathView : public QObject @@ -69,6 +72,11 @@ private slots: void path(); void pathMoved(); void resetModel(); + void propertyChanges(); + void pathChanges(); + void componentChanges(); + void modelChanges(); + private: QDeclarativeView *createView(); @@ -120,7 +128,7 @@ public: setRoleNames(roles); } - int rowCount(const QModelIndex &parent=QModelIndex()) const { return list.count(); } + int rowCount(const QModelIndex &parent=QModelIndex()) const { Q_UNUSED(parent); return list.count(); } QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const { QVariant rv; if (role == Name) @@ -465,6 +473,149 @@ void tst_QDeclarativePathView::resetModel() } } +void tst_QDeclarativePathView::propertyChanges() +{ + QDeclarativeView *canvas = createView(); + QVERIFY(canvas); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/propertychanges.qml")); + + QDeclarativePathView *pathView = canvas->rootObject()->findChild("pathView"); + QVERIFY(pathView); + + QSignalSpy snapPositionSpy(pathView, SIGNAL(snapPositionChanged())); + QSignalSpy dragMarginSpy(pathView, SIGNAL(dragMarginChanged())); + + QCOMPARE(pathView->snapPosition(), 0.1); + QCOMPARE(pathView->dragMargin(), 5.0); + + pathView->setSnapPosition(0.4); + pathView->setDragMargin(20.0); + + QCOMPARE(pathView->snapPosition(), 0.4); + QCOMPARE(pathView->dragMargin(), 20.0); + + QCOMPARE(snapPositionSpy.count(), 1); + QCOMPARE(dragMarginSpy.count(), 1); + + pathView->setSnapPosition(0.4); + pathView->setDragMargin(20.0); + + QCOMPARE(snapPositionSpy.count(), 1); + QCOMPARE(dragMarginSpy.count(), 1); + delete canvas; +} + +void tst_QDeclarativePathView::pathChanges() +{ + QDeclarativeView *canvas = createView(); + QVERIFY(canvas); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/propertychanges.qml")); + + QDeclarativePathView *pathView = canvas->rootObject()->findChild("pathView"); + QVERIFY(pathView); + + QDeclarativePath *path = canvas->rootObject()->findChild("path"); + QVERIFY(path); + + QSignalSpy startXSpy(path, SIGNAL(startXChanged())); + QSignalSpy startYSpy(path, SIGNAL(startYChanged())); + + QCOMPARE(path->startX(), 220.0); + QCOMPARE(path->startY(), 200.0); + + path->setStartX(240.0); + path->setStartY(220.0); + + QCOMPARE(path->startX(), 240.0); + QCOMPARE(path->startY(), 220.0); + + QCOMPARE(startXSpy.count(),1); + QCOMPARE(startYSpy.count(),1); + + path->setStartX(240); + path->setStartY(220); + + QCOMPARE(startXSpy.count(),1); + QCOMPARE(startYSpy.count(),1); + + QDeclarativePath *alternatePath = canvas->rootObject()->findChild("alternatePath"); + QVERIFY(alternatePath); + + QSignalSpy pathSpy(pathView, SIGNAL(pathChanged())); + + QCOMPARE(pathView->path(), path); + + pathView->setPath(alternatePath); + QCOMPARE(pathView->path(), alternatePath); + QCOMPARE(pathSpy.count(),1); + + pathView->setPath(alternatePath); + QCOMPARE(pathSpy.count(),1); + + QDeclarativePathAttribute *pathAttribute = canvas->rootObject()->findChild("pathAttribute"); + QVERIFY(pathAttribute); + + QSignalSpy nameSpy(pathAttribute, SIGNAL(nameChanged())); + QCOMPARE(pathAttribute->name(), QString("opacity")); + + pathAttribute->setName("scale"); + QCOMPARE(pathAttribute->name(), QString("scale")); + QCOMPARE(nameSpy.count(),1); + + pathAttribute->setName("scale"); + QCOMPARE(nameSpy.count(),1); + delete canvas; +} + +void tst_QDeclarativePathView::componentChanges() +{ + QDeclarativeView *canvas = createView(); + QVERIFY(canvas); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/propertychanges.qml")); + + QDeclarativePathView *pathView = canvas->rootObject()->findChild("pathView"); + QVERIFY(pathView); + + QDeclarativeComponent delegateComponent(canvas->engine()); + delegateComponent.setData("import Qt 4.6; Text { text: 'Name: ' + name }", QUrl::fromLocalFile("")); + + QSignalSpy delegateSpy(pathView, SIGNAL(delegateChanged())); + + pathView->setDelegate(&delegateComponent); + QCOMPARE(pathView->delegate(), &delegateComponent); + QCOMPARE(delegateSpy.count(),1); + + pathView->setDelegate(&delegateComponent); + QCOMPARE(delegateSpy.count(),1); + delete canvas; +} + +void tst_QDeclarativePathView::modelChanges() +{ + QDeclarativeView *canvas = createView(); + QVERIFY(canvas); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/propertychanges.qml")); + + QDeclarativePathView *pathView = canvas->rootObject()->findChild("pathView"); + QVERIFY(pathView); + + QDeclarativeListModel *alternateModel = canvas->rootObject()->findChild("alternateModel"); + QVERIFY(alternateModel); + QVariant modelVariant = QVariant::fromValue(alternateModel); + QSignalSpy modelSpy(pathView, SIGNAL(modelChanged())); + + pathView->setModel(modelVariant); + QCOMPARE(pathView->model(), modelVariant); + QCOMPARE(modelSpy.count(),1); + + pathView->setModel(modelVariant); + QCOMPARE(modelSpy.count(),1); + + pathView->setModel(QVariant()); + QCOMPARE(modelSpy.count(),2); + + delete canvas; +} QDeclarativeView *tst_QDeclarativePathView::createView() { -- cgit v0.12 From 657e7881c11f2f7b313ebd303e7be8f7a28e309e Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Tue, 2 Mar 2010 13:52:55 +1000 Subject: Forgot to add qworkerlistmodel test dir to declarative.pro --- tests/auto/declarative/declarative.pro | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/declarative/declarative.pro index 42ff523..38c75a8 100644 --- a/tests/auto/declarative/declarative.pro +++ b/tests/auto/declarative/declarative.pro @@ -55,6 +55,7 @@ SUBDIRS += \ qdeclarativexmllistmodel \ # Cover qpacketprotocol \ # Cover qdeclarativerepeater \ # Cover + qdeclarativeworkerlistmodel \ # Cover qdeclarativevaluetypes \ # Cover qdeclarativexmlhttprequest \ # Cover qdeclarativeimageprovider \ # Cover -- cgit v0.12 From 3507c6fbbb585ea3b7f6a13b16fa216aea4574ab Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Tue, 2 Mar 2010 14:35:02 +1000 Subject: Make test more reliable. --- .../qdeclarativeanimations/tst_qdeclarativeanimations.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/auto/declarative/qdeclarativeanimations/tst_qdeclarativeanimations.cpp b/tests/auto/declarative/qdeclarativeanimations/tst_qdeclarativeanimations.cpp index 53c63b5..0c166df 100644 --- a/tests/auto/declarative/qdeclarativeanimations/tst_qdeclarativeanimations.cpp +++ b/tests/auto/declarative/qdeclarativeanimations/tst_qdeclarativeanimations.cpp @@ -221,17 +221,17 @@ void tst_qdeclarativeanimations::resume() QVERIFY(animation.from() == 10); animation.start(); - QTest::qWait(100); + QTest::qWait(200); animation.pause(); qreal x = rect.x(); - QVERIFY(x != qreal(200)); + QVERIFY(x != qreal(200) && x != qreal(10)); QVERIFY(animation.isRunning()); QVERIFY(animation.isPaused()); animation.resume(); QVERIFY(animation.isRunning()); QVERIFY(!animation.isPaused()); - QTest::qWait(100); + QTest::qWait(200); animation.stop(); QVERIFY(rect.x() > x); } -- cgit v0.12 From 861a9f127e04aa135649ed64f268d72da6a35fd9 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Tue, 2 Mar 2010 14:48:07 +1000 Subject: Add autotests for script block scoping. --- .../qdeclarativeecmascript/data/scriptScope.1.qml | 13 ++++++++++ .../qdeclarativeecmascript/data/scriptScope.2.qml | 11 +++++++++ .../qdeclarativeecmascript/data/scriptScope.js | 5 ++++ .../tst_qdeclarativeecmascript.cpp | 28 ++++++++++++++++++++++ 4 files changed, 57 insertions(+) create mode 100644 tests/auto/declarative/qdeclarativeecmascript/data/scriptScope.1.qml create mode 100644 tests/auto/declarative/qdeclarativeecmascript/data/scriptScope.2.qml create mode 100644 tests/auto/declarative/qdeclarativeecmascript/data/scriptScope.js diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/scriptScope.1.qml b/tests/auto/declarative/qdeclarativeecmascript/data/scriptScope.1.qml new file mode 100644 index 0000000..9b11fa9 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeecmascript/data/scriptScope.1.qml @@ -0,0 +1,13 @@ +import Qt.test 1.0 + +MyQmlObject { + property string result + + Script{ + function f() { + result = b + } + + } + onArgumentSignal: f() +} diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/scriptScope.2.qml b/tests/auto/declarative/qdeclarativeecmascript/data/scriptScope.2.qml new file mode 100644 index 0000000..ec727e2 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeecmascript/data/scriptScope.2.qml @@ -0,0 +1,11 @@ +import Qt.test 1.0 + +MyQmlObject { + property string result + property string aProp: "hello" + + Script{ + source: "scriptScope.js" + } + onBasicSignal: f() +} diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/scriptScope.js b/tests/auto/declarative/qdeclarativeecmascript/data/scriptScope.js new file mode 100644 index 0000000..5689930 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeecmascript/data/scriptScope.js @@ -0,0 +1,5 @@ +var aProp = "world"; + +function f() { + result = aProp; +} diff --git a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp index 60c380c..8e7944d 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp +++ b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp @@ -122,6 +122,7 @@ private slots: void listToVariant(); void multiEngineObject(); void deletedObject(); + void scriptScope(); void bug1(); @@ -1657,6 +1658,33 @@ void tst_qdeclarativeecmascript::deletedObject() delete object; } +void tst_qdeclarativeecmascript::scriptScope() +{ + { + QDeclarativeComponent component(&engine, TEST_FILE("scriptScope.1.qml")); + + MyQmlObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + emit object->argumentSignal(19, "Hello world!", 10.3); + QEXPECT_FAIL("", "QTBUG-8641", Continue); + QCOMPARE(object->property("result").toString(), QLatin1String("undefined")); + + delete object; + } + + { + QDeclarativeComponent component(&engine, TEST_FILE("scriptScope.2.qml")); + + MyQmlObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + emit object->basicSignal(); + QEXPECT_FAIL("", "QTBUG-8641", Continue); + QCOMPARE(object->property("result").toString(), QLatin1String("world")); + + delete object; + } +} + QTEST_MAIN(tst_qdeclarativeecmascript) #include "tst_qdeclarativeecmascript.moc" -- cgit v0.12 From 685c0b930a1d1ecfdcc78aa688a333564cc9ca5b Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Tue, 2 Mar 2010 15:08:11 +1000 Subject: Optimization. --- src/declarative/qml/qdeclarativepropertycache.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/declarative/qml/qdeclarativepropertycache.cpp b/src/declarative/qml/qdeclarativepropertycache.cpp index 08b47b7..fea59e5 100644 --- a/src/declarative/qml/qdeclarativepropertycache.cpp +++ b/src/declarative/qml/qdeclarativepropertycache.cpp @@ -155,9 +155,9 @@ QDeclarativePropertyCache::Data QDeclarativePropertyCache::create(const QMetaObj int parenIdx = methodName.indexOf(QLatin1Char('(')); Q_ASSERT(parenIdx != -1); - methodName = methodName.left(parenIdx); + QStringRef methodNameRef = methodName.leftRef(parenIdx); - if (methodName == property) { + if (methodNameRef == property) { rv.load(m); return rv; } -- cgit v0.12 From c139d16df004721894c08e2c86ab2b3078c1d170 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Tue, 2 Mar 2010 15:47:19 +1000 Subject: missed file --- .../declarative/qdeclarativewebview/data/forward.png | Bin 0 -> 2377 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/auto/declarative/qdeclarativewebview/data/forward.png diff --git a/tests/auto/declarative/qdeclarativewebview/data/forward.png b/tests/auto/declarative/qdeclarativewebview/data/forward.png new file mode 100644 index 0000000..a82533e Binary files /dev/null and b/tests/auto/declarative/qdeclarativewebview/data/forward.png differ -- cgit v0.12 From 26e6b837ceb90ed3d0df63b39a1cd0ec4dc7aeae Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Tue, 2 Mar 2010 15:54:14 +1000 Subject: follow syntax change --- demos/declarative/webbrowser/content/fieldtext/FieldText.qml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demos/declarative/webbrowser/content/fieldtext/FieldText.qml b/demos/declarative/webbrowser/content/fieldtext/FieldText.qml index 19b6acc..d282209 100644 --- a/demos/declarative/webbrowser/content/fieldtext/FieldText.qml +++ b/demos/declarative/webbrowser/content/fieldtext/FieldText.qml @@ -85,7 +85,7 @@ Item { font.bold: true text: label opacity: textEdit.text == '' ? 1 : 0 - opacity: Behavior { + Behavior on opacity { NumberAnimation { property: "opacity" duration: 250 -- cgit v0.12 From feb79bba984520fa30bad83eb4a6f34cfb86a697 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Tue, 2 Mar 2010 15:55:06 +1000 Subject: Move WebView to an extension plugin. Using WebView now requires: import org.webkit 1.0 Task-number: QT-2995 --- demos/declarative/flickr/common/ImageDetails.qml | 1 + .../webbrowser/content/FlickableWebView.qml | 1 + demos/declarative/webbrowser/webbrowser.qml | 1 + examples/declarative/webview/autosize.qml | 1 + examples/declarative/webview/content/FieldText.qml | 2 +- .../declarative/webview/content/Mapping/Map.qml | 1 + examples/declarative/webview/evalandattach.qml | 1 + examples/declarative/webview/googleMaps.qml | 1 + examples/declarative/webview/inline-html.qml | 1 + examples/declarative/webview/newwindows.qml | 1 + .../declarative/webview/qdeclarative-in-html.qml | 1 + examples/declarative/webview/transparent.qml | 1 + imports/org/webkit/qmldir | 1 + src/declarative/graphicsitems/graphicsitems.pri | 7 - .../graphicsitems/qdeclarativeitemsmodule.cpp | 3 - .../graphicsitems/qdeclarativewebview.cpp | 1338 ------------------- .../graphicsitems/qdeclarativewebview_p.h | 286 ----- .../graphicsitems/qdeclarativewebview_p_p.h | 151 --- .../qdeclarativemodules/qdeclarativemodules.pro | 1 + .../qdeclarativemodules/webkitqmlplugin/plugin.cpp | 66 + .../webkitqmlplugin/qdeclarativewebview.cpp | 1340 ++++++++++++++++++++ .../webkitqmlplugin/qdeclarativewebview_p.h | 285 +++++ .../webkitqmlplugin/qdeclarativewebview_p_p.h | 151 +++ .../webkitqmlplugin/webkitqmlplugin.pro | 18 + .../declarative/qdeclarativewebview/data/basic.qml | 1 + .../qdeclarativewebview/data/elements.qml | 1 + .../qdeclarativewebview/data/javaScript.qml | 1 + .../qdeclarativewebview/data/loadError.qml | 1 + .../qdeclarativewebview/data/newwindows.qml | 1 + .../qdeclarativewebview/data/propertychanges.qml | 3 +- .../qdeclarativewebview/data/sethtml.qml | 1 + .../qdeclarativewebview/qdeclarativewebview.pro | 3 +- .../declarative/qdeclarativewebview/testtypes.cpp | 52 - .../declarative/qdeclarativewebview/testtypes.h | 66 - .../tst_qdeclarativewebview.cpp | 346 ++--- .../visual/qfxwebview/autosize/autosize.qml | 1 + .../visual/webview/embedding/nesting.qml | 1 + .../webview/javascript/evaluateJavaScript.qml | 1 + .../visual/webview/javascript/windowObjects.qml | 1 + .../visual/webview/settings/fontFamily.qml | 1 + .../visual/webview/settings/fontSize.qml | 1 + .../visual/webview/settings/noAutoLoadImages.qml | 1 + .../visual/webview/settings/setFontFamily.qml | 1 + .../visual/webview/zooming/pageWidth.qml | 1 + .../visual/webview/zooming/renderControl.qml | 1 + .../visual/webview/zooming/resolution.qml | 1 + .../visual/webview/zooming/zoomTextOnly.qml | 1 + .../declarative/visual/webview/zooming/zooming.qml | 1 + 48 files changed, 2072 insertions(+), 2077 deletions(-) create mode 100644 imports/org/webkit/qmldir delete mode 100644 src/declarative/graphicsitems/qdeclarativewebview.cpp delete mode 100644 src/declarative/graphicsitems/qdeclarativewebview_p.h delete mode 100644 src/declarative/graphicsitems/qdeclarativewebview_p_p.h create mode 100644 src/plugins/qdeclarativemodules/webkitqmlplugin/plugin.cpp create mode 100644 src/plugins/qdeclarativemodules/webkitqmlplugin/qdeclarativewebview.cpp create mode 100644 src/plugins/qdeclarativemodules/webkitqmlplugin/qdeclarativewebview_p.h create mode 100644 src/plugins/qdeclarativemodules/webkitqmlplugin/qdeclarativewebview_p_p.h create mode 100644 src/plugins/qdeclarativemodules/webkitqmlplugin/webkitqmlplugin.pro delete mode 100644 tests/auto/declarative/qdeclarativewebview/testtypes.cpp delete mode 100644 tests/auto/declarative/qdeclarativewebview/testtypes.h diff --git a/demos/declarative/flickr/common/ImageDetails.qml b/demos/declarative/flickr/common/ImageDetails.qml index 9604f10..862eeb1 100644 --- a/demos/declarative/flickr/common/ImageDetails.qml +++ b/demos/declarative/flickr/common/ImageDetails.qml @@ -1,4 +1,5 @@ import Qt 4.6 +import org.webkit 1.0 Flipable { id: container diff --git a/demos/declarative/webbrowser/content/FlickableWebView.qml b/demos/declarative/webbrowser/content/FlickableWebView.qml index 76a5813..cf4c825 100644 --- a/demos/declarative/webbrowser/content/FlickableWebView.qml +++ b/demos/declarative/webbrowser/content/FlickableWebView.qml @@ -1,4 +1,5 @@ import Qt 4.6 +import org.webkit 1.0 Flickable { property alias title: webView.title diff --git a/demos/declarative/webbrowser/webbrowser.qml b/demos/declarative/webbrowser/webbrowser.qml index 6a427f4..b6cccb0 100644 --- a/demos/declarative/webbrowser/webbrowser.qml +++ b/demos/declarative/webbrowser/webbrowser.qml @@ -1,4 +1,5 @@ import Qt 4.6 +import org.webkit 1.0 import "content" diff --git a/examples/declarative/webview/autosize.qml b/examples/declarative/webview/autosize.qml index 74c6844..3c00ee6 100644 --- a/examples/declarative/webview/autosize.qml +++ b/examples/declarative/webview/autosize.qml @@ -1,4 +1,5 @@ import Qt 4.6 +import org.webkit 1.0 // The WebView size is determined by the width, height, // preferredWidth, and preferredHeight properties. diff --git a/examples/declarative/webview/content/FieldText.qml b/examples/declarative/webview/content/FieldText.qml index 19b6acc..d282209 100644 --- a/examples/declarative/webview/content/FieldText.qml +++ b/examples/declarative/webview/content/FieldText.qml @@ -85,7 +85,7 @@ Item { font.bold: true text: label opacity: textEdit.text == '' ? 1 : 0 - opacity: Behavior { + Behavior on opacity { NumberAnimation { property: "opacity" duration: 250 diff --git a/examples/declarative/webview/content/Mapping/Map.qml b/examples/declarative/webview/content/Mapping/Map.qml index 2e98940..6c3b021 100644 --- a/examples/declarative/webview/content/Mapping/Map.qml +++ b/examples/declarative/webview/content/Mapping/Map.qml @@ -1,4 +1,5 @@ import Qt 4.6 +import org.webkit 1.0 Item { id: page diff --git a/examples/declarative/webview/evalandattach.qml b/examples/declarative/webview/evalandattach.qml index 94301cd..d219d84 100644 --- a/examples/declarative/webview/evalandattach.qml +++ b/examples/declarative/webview/evalandattach.qml @@ -1,4 +1,5 @@ import Qt 4.6 +import org.webkit 1.0 Item { height: 640 diff --git a/examples/declarative/webview/googleMaps.qml b/examples/declarative/webview/googleMaps.qml index 1886961..a04fecb 100644 --- a/examples/declarative/webview/googleMaps.qml +++ b/examples/declarative/webview/googleMaps.qml @@ -6,6 +6,7 @@ // order to create a Map. import Qt 4.6 +import org.webkit 1.0 import "content/Mapping" Map { diff --git a/examples/declarative/webview/inline-html.qml b/examples/declarative/webview/inline-html.qml index 23b4555..41dfec3 100644 --- a/examples/declarative/webview/inline-html.qml +++ b/examples/declarative/webview/inline-html.qml @@ -1,4 +1,5 @@ import Qt 4.6 +import org.webkit 1.0 // Inline HTML with loose formatting can be // set on the html property. diff --git a/examples/declarative/webview/newwindows.qml b/examples/declarative/webview/newwindows.qml index 5dd4cd5..c62aba6 100644 --- a/examples/declarative/webview/newwindows.qml +++ b/examples/declarative/webview/newwindows.qml @@ -4,6 +4,7 @@ // allow it on WebView with settings.javascriptCanOpenWindows: true import Qt 4.6 +import org.webkit 1.0 Grid { columns: 3 diff --git a/examples/declarative/webview/qdeclarative-in-html.qml b/examples/declarative/webview/qdeclarative-in-html.qml index 77180ec..172ea4b 100644 --- a/examples/declarative/webview/qdeclarative-in-html.qml +++ b/examples/declarative/webview/qdeclarative-in-html.qml @@ -1,4 +1,5 @@ import Qt 4.6 +import org.webkit 1.0 // The WebView supports QML data through the HTML OBJECT tag Rectangle { diff --git a/examples/declarative/webview/transparent.qml b/examples/declarative/webview/transparent.qml index 9332f3e..5530819 100644 --- a/examples/declarative/webview/transparent.qml +++ b/examples/declarative/webview/transparent.qml @@ -1,4 +1,5 @@ import Qt 4.6 +import org.webkit 1.0 // The WebView background is transparent // if the HTML does not specify a background diff --git a/imports/org/webkit/qmldir b/imports/org/webkit/qmldir new file mode 100644 index 0000000..258aa2c --- /dev/null +++ b/imports/org/webkit/qmldir @@ -0,0 +1 @@ +plugin webkitqmlplugin diff --git a/src/declarative/graphicsitems/graphicsitems.pri b/src/declarative/graphicsitems/graphicsitems.pri index 7a85f00..3ff92b1 100644 --- a/src/declarative/graphicsitems/graphicsitems.pri +++ b/src/declarative/graphicsitems/graphicsitems.pri @@ -84,10 +84,3 @@ SOURCES += \ $$PWD/qdeclarativegraphicsobjectcontainer.cpp \ $$PWD/qdeclarativeparticles.cpp \ $$PWD/qdeclarativelayoutitem.cpp \ - -contains(QT_CONFIG, webkit) { - QT+=webkit - SOURCES += $$PWD/qdeclarativewebview.cpp - HEADERS += $$PWD/qdeclarativewebview_p.h - HEADERS += $$PWD/qdeclarativewebview_p_p.h -} diff --git a/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp b/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp index f3b9385..e0ae2eb 100644 --- a/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp +++ b/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp @@ -139,9 +139,6 @@ void QDeclarativeItemModule::defineModule() QML_REGISTER_TYPE(Qt,4,6,VisibleArea,QDeclarativeFlickableVisibleArea); QML_REGISTER_TYPE(Qt,4,6,VisualDataModel,QDeclarativeVisualDataModel); QML_REGISTER_TYPE(Qt,4,6,VisualItemModel,QDeclarativeVisualItemModel); -#ifdef QT_WEBKIT_LIB - QML_REGISTER_TYPE(Qt,4,6,WebView,QDeclarativeWebView); -#endif QML_REGISTER_NOCREATE_TYPE(QDeclarativeAnchors); QML_REGISTER_NOCREATE_TYPE(QGraphicsEffect); diff --git a/src/declarative/graphicsitems/qdeclarativewebview.cpp b/src/declarative/graphicsitems/qdeclarativewebview.cpp deleted file mode 100644 index a2b16ba..0000000 --- a/src/declarative/graphicsitems/qdeclarativewebview.cpp +++ /dev/null @@ -1,1338 +0,0 @@ -/**************************************************************************** -** -** 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 "qdeclarativewebview_p.h" -#include "qdeclarativewebview_p_p.h" - -#include "qdeclarativepainteditem_p_p.h" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -static const int MAX_DOUBLECLICK_TIME=500; // XXX need better gesture system - -class QDeclarativeWebViewPrivate : public QDeclarativePaintedItemPrivate -{ - Q_DECLARE_PUBLIC(QDeclarativeWebView) - -public: - QDeclarativeWebViewPrivate() - : QDeclarativePaintedItemPrivate(), page(0), preferredwidth(0), preferredheight(0), - progress(1.0), status(QDeclarativeWebView::Null), pending(PendingNone), - newWindowComponent(0), newWindowParent(0), - pressTime(400), - rendering(true) - { - } - - QUrl url; // page url might be different if it has not loaded yet - QWebPage *page; - - int preferredwidth, preferredheight; - qreal progress; - QDeclarativeWebView::Status status; - QString statusText; - enum { PendingNone, PendingUrl, PendingHtml, PendingContent } pending; - QUrl pending_url; - QString pending_string; - QByteArray pending_data; - mutable QDeclarativeWebSettings settings; - QDeclarativeComponent *newWindowComponent; - QDeclarativeItem *newWindowParent; - - QBasicTimer pressTimer; - QPoint pressPoint; - int pressTime; // milliseconds before it's a "hold" - - - static void windowObjects_append(QDeclarativeListProperty *prop, QObject *o) { - static_cast(prop->data)->windowObjects.append(o); - static_cast(prop->data)->updateWindowObjects(); - } - - void updateWindowObjects(); - QObjectList windowObjects; - - bool rendering; -}; - -/*! - \qmlclass WebView QDeclarativeWebView - \since 4.7 - \brief The WebView item allows you to add web content to a canvas. - \inherits Item - - A WebView renders web content based on a URL. - - If the width and height of the item is not set, they will - dynamically adjust to a size appropriate for the content. - This width may be large for typical online web pages. - - If the preferredWidth is set, the width will be this amount or larger, - usually laying out the web content to fit the preferredWidth. - - \qml - WebView { - url: "http://www.nokia.com" - width: 490 - height: 400 - scale: 0.5 - smooth: false - smoothCache: true - } - \endqml - - \image webview.png - - The item includes no scrolling, scaling, - toolbars, etc., those must be implemented around WebView. See the WebBrowser example - for a demonstration of this. -*/ - -/*! - \internal - \class QDeclarativeWebView - \brief The QDeclarativeWebView class allows you to add web content to a QDeclarativeView. - - A WebView renders web content base on a URL. - - \image webview.png - - The item includes no scrolling, scaling, - toolbars, etc., those must be implemented around WebView. See the WebBrowser example - for a demonstration of this. - - A QDeclarativeWebView object can be instantiated in Qml using the tag \l WebView. -*/ - -QDeclarativeWebView::QDeclarativeWebView(QDeclarativeItem *parent) - : QDeclarativePaintedItem(*(new QDeclarativeWebViewPrivate), parent) -{ - init(); -} - -QDeclarativeWebView::~QDeclarativeWebView() -{ - Q_D(QDeclarativeWebView); - delete d->page; -} - -void QDeclarativeWebView::init() -{ - Q_D(QDeclarativeWebView); - - QWebSettings::enablePersistentStorage(); - - setAcceptHoverEvents(true); - setAcceptedMouseButtons(Qt::LeftButton); - setFlag(QGraphicsItem::ItemHasNoContents, false); - - d->page = 0; -} - -void QDeclarativeWebView::componentComplete() -{ - QDeclarativePaintedItem::componentComplete(); - Q_D(QDeclarativeWebView); - switch (d->pending) { - case QDeclarativeWebViewPrivate::PendingUrl: - setUrl(d->pending_url); - break; - case QDeclarativeWebViewPrivate::PendingHtml: - setHtml(d->pending_string, d->pending_url); - break; - case QDeclarativeWebViewPrivate::PendingContent: - setContent(d->pending_data, d->pending_string, d->pending_url); - break; - default: - break; - } - d->pending = QDeclarativeWebViewPrivate::PendingNone; - d->updateWindowObjects(); -} - -QDeclarativeWebView::Status QDeclarativeWebView::status() const -{ - Q_D(const QDeclarativeWebView); - return d->status; -} - - -/*! - \qmlproperty real WebView::progress - This property holds the progress of loading the current URL, from 0 to 1. - - If you just want to know when progress gets to 1, use - WebView::onLoadFinished() or WebView::onLoadFailed() instead. -*/ -qreal QDeclarativeWebView::progress() const -{ - Q_D(const QDeclarativeWebView); - return d->progress; -} - -void QDeclarativeWebView::doLoadStarted() -{ - Q_D(QDeclarativeWebView); - - if (!d->url.isEmpty()) { - d->status = Loading; - emit statusChanged(d->status); - } - emit loadStarted(); -} - -void QDeclarativeWebView::doLoadProgress(int p) -{ - Q_D(QDeclarativeWebView); - if (d->progress == p/100.0) - return; - d->progress = p/100.0; - emit progressChanged(); -} - -void QDeclarativeWebView::pageUrlChanged() -{ - Q_D(QDeclarativeWebView); - - page()->setViewportSize(QSize( - d->preferredwidth>0 ? d->preferredwidth : width(), - d->preferredheight>0 ? d->preferredheight : height())); - expandToWebPage(); - - if ((d->url.isEmpty() && page()->mainFrame()->url() != QUrl(QLatin1String("about:blank"))) - || (d->url != page()->mainFrame()->url() && !page()->mainFrame()->url().isEmpty())) - { - d->url = page()->mainFrame()->url(); - if (d->url == QUrl(QLatin1String("about:blank"))) - d->url = QUrl(); - emit urlChanged(); - } -} - -void QDeclarativeWebView::doLoadFinished(bool ok) -{ - Q_D(QDeclarativeWebView); - - if (title().isEmpty()) - pageUrlChanged(); // XXX bug 232556 - pages with no title never get urlChanged() - - if (ok) { - d->status = d->url.isEmpty() ? Null : Ready; - emit loadFinished(); - } else { - d->status = Error; - emit loadFailed(); - } - emit statusChanged(d->status); -} - -/*! - \qmlproperty url WebView::url - This property holds the URL to the page displayed in this item. It can be set, - but also can change spontaneously (eg. because of network redirection). - - If the url is empty, the page is blank. - - The url is always absolute (QML will resolve relative URL strings in the context - of the containing QML document). -*/ -QUrl QDeclarativeWebView::url() const -{ - Q_D(const QDeclarativeWebView); - return d->url; -} - -void QDeclarativeWebView::setUrl(const QUrl &url) -{ - Q_D(QDeclarativeWebView); - if (url == d->url) - return; - - if (isComponentComplete()) { - d->url = url; - page()->setViewportSize(QSize( - d->preferredwidth>0 ? d->preferredwidth : width(), - d->preferredheight>0 ? d->preferredheight : height())); - QUrl seturl = url; - if (seturl.isEmpty()) - seturl = QUrl(QLatin1String("about:blank")); - - Q_ASSERT(!seturl.isRelative()); - - page()->mainFrame()->load(seturl); - - emit urlChanged(); - } else { - d->pending = d->PendingUrl; - d->pending_url = url; - } -} - -/*! - \qmlproperty int WebView::preferredWidth - This property holds the ideal width for displaying the current URL. -*/ -int QDeclarativeWebView::preferredWidth() const -{ - Q_D(const QDeclarativeWebView); - return d->preferredwidth; -} - -void QDeclarativeWebView::setPreferredWidth(int iw) -{ - Q_D(QDeclarativeWebView); - if (d->preferredwidth == iw) return; - d->preferredwidth = iw; - //expandToWebPage(); - emit preferredWidthChanged(); -} - -/*! - \qmlproperty int WebView::preferredHeight - This property holds the ideal height for displaying the current URL. - This only affects the area zoomed by heuristicZoom(). -*/ -int QDeclarativeWebView::preferredHeight() const -{ - Q_D(const QDeclarativeWebView); - return d->preferredheight; -} -void QDeclarativeWebView::setPreferredHeight(int ih) -{ - Q_D(QDeclarativeWebView); - if (d->preferredheight == ih) return; - d->preferredheight = ih; - emit preferredHeightChanged(); -} - -/*! - \qmlmethod bool WebView::evaluateJavaScript(string) - - Evaluates the \a scriptSource JavaScript inside the context of the - main web frame, and returns the result of the last executed statement. - - Note that this JavaScript does \e not have any access to QML objects - except as made available as windowObjects. -*/ -QVariant QDeclarativeWebView::evaluateJavaScript(const QString &scriptSource) -{ - return this->page()->mainFrame()->evaluateJavaScript(scriptSource); -} - -void QDeclarativeWebView::focusChanged(bool hasFocus) -{ - QFocusEvent e(hasFocus ? QEvent::FocusIn : QEvent::FocusOut); - page()->event(&e); - QDeclarativeItem::focusChanged(hasFocus); -} - -void QDeclarativeWebView::initialLayout() -{ - // nothing useful to do at this point -} - -void QDeclarativeWebView::noteContentsSizeChanged(const QSize&) -{ - expandToWebPage(); -} - -void QDeclarativeWebView::expandToWebPage() -{ - Q_D(QDeclarativeWebView); - QSize cs = page()->mainFrame()->contentsSize(); - if (cs.width() < d->preferredwidth) - cs.setWidth(d->preferredwidth); - if (cs.height() < d->preferredheight) - cs.setHeight(d->preferredheight); - if (widthValid()) - cs.setWidth(width()); - if (heightValid()) - cs.setHeight(height()); - if (cs != page()->viewportSize()) { - page()->setViewportSize(cs); - } - if (cs != contentsSize()) - setContentsSize(cs); -} - -void QDeclarativeWebView::geometryChanged(const QRectF &newGeometry, - const QRectF &oldGeometry) -{ - if (newGeometry.size() != oldGeometry.size()) - expandToWebPage(); - QDeclarativePaintedItem::geometryChanged(newGeometry, oldGeometry); -} - -void QDeclarativeWebView::paintPage(const QRect& r) -{ - dirtyCache(r); - update(); -} - -/*! - \qmlproperty list WebView::javaScriptWindowObjects - - This property is a list of object that are available from within - the webview's JavaScript context. - - The \a object will be inserted as a child of the frame's window - object, under the name given by the attached property \c WebView.windowObjectName. - - \qml - WebView { - javaScriptWindowObjects: Object { - WebView.windowObjectName: "coordinates" - } - } - \endqml - - Properties of the object will be exposed as JavaScript properties and slots as - JavaScript methods. - - If Javascript is not enabled for this page, then this property does nothing. -*/ -QDeclarativeListProperty QDeclarativeWebView::javaScriptWindowObjects() -{ - Q_D(QDeclarativeWebView); - return QDeclarativeListProperty(this, d, &QDeclarativeWebViewPrivate::windowObjects_append); -} - -QDeclarativeWebViewAttached *QDeclarativeWebView::qmlAttachedProperties(QObject *o) -{ - return new QDeclarativeWebViewAttached(o); -} - -void QDeclarativeWebViewPrivate::updateWindowObjects() -{ - Q_Q(QDeclarativeWebView); - if (!q->isComponentComplete() || !page) - return; - - for (int ii = 0; ii < windowObjects.count(); ++ii) { - QObject *object = windowObjects.at(ii); - QDeclarativeWebViewAttached *attached = static_cast(qmlAttachedPropertiesObject(object)); - if (attached && !attached->windowObjectName().isEmpty()) { - page->mainFrame()->addToJavaScriptWindowObject(attached->windowObjectName(), object); - } - } -} - -bool QDeclarativeWebView::renderingEnabled() const -{ - Q_D(const QDeclarativeWebView); - return d->rendering; -} - -void QDeclarativeWebView::setRenderingEnabled(bool enabled) -{ - Q_D(QDeclarativeWebView); - if (d->rendering == enabled) - return; - d->rendering = enabled; - emit renderingEnabledChanged(); - - setCacheFrozen(!enabled); - if (enabled) - clearCache(); -} - - -void QDeclarativeWebView::drawContents(QPainter *p, const QRect &r) -{ - Q_D(QDeclarativeWebView); - if (d->rendering) - page()->mainFrame()->render(p,r); -} - -QMouseEvent *QDeclarativeWebView::sceneMouseEventToMouseEvent(QGraphicsSceneMouseEvent *e) -{ - QEvent::Type t; - switch(e->type()) { - default: - case QEvent::GraphicsSceneMousePress: - t = QEvent::MouseButtonPress; - break; - case QEvent::GraphicsSceneMouseRelease: - t = QEvent::MouseButtonRelease; - break; - case QEvent::GraphicsSceneMouseMove: - t = QEvent::MouseMove; - break; - case QGraphicsSceneEvent::GraphicsSceneMouseDoubleClick: - t = QEvent::MouseButtonDblClick; - break; - } - - QMouseEvent *me = new QMouseEvent(t, (e->pos()/contentsScale()).toPoint(), e->button(), e->buttons(), 0); - return me; -} - -QMouseEvent *QDeclarativeWebView::sceneHoverMoveEventToMouseEvent(QGraphicsSceneHoverEvent *e) -{ - QEvent::Type t = QEvent::MouseMove; - - QMouseEvent *me = new QMouseEvent(t, (e->pos()/contentsScale()).toPoint(), Qt::NoButton, Qt::NoButton, 0); - - return me; -} - - -/*! - \qmlsignal WebView::onDoubleClick(clickx,clicky) - - The WebView does not pass double-click events to the web engine, but rather - emits this signals. -*/ - -void QDeclarativeWebView::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) -{ - QMouseEvent *me = sceneMouseEventToMouseEvent(event); - emit doubleClick(me->x(),me->y()); - delete me; -} - -/*! - \qmlmethod bool WebView::heuristicZoom(clickX,clickY,maxzoom) - - Finds a zoom that: - \list - \i shows a whole item - \i includes (\a clickX, \a clickY) - \i fits into the preferredWidth and preferredHeight - \i zooms by no more than \a maxzoom - \i is more than 10% above the current zoom - \endlist - - If such a zoom exists, emits zoomTo(zoom,centerX,centerY) and returns true; otherwise, - no signal is emitted and returns false. -*/ -bool QDeclarativeWebView::heuristicZoom(int clickX, int clickY, qreal maxzoom) -{ - Q_D(QDeclarativeWebView); - if (contentsScale() >= maxzoom/zoomFactor()) - return false; - qreal ozf = contentsScale(); - QRect showarea = elementAreaAt(clickX, clickY, d->preferredwidth/maxzoom, d->preferredheight/maxzoom); - qreal z = qMin(qreal(d->preferredwidth)/showarea.width(),qreal(d->preferredheight)/showarea.height()); - if (z > maxzoom/zoomFactor()) - z = maxzoom/zoomFactor(); - if (z/ozf > 1.2) { - QRectF r(showarea.left()*z, showarea.top()*z, showarea.width()*z, showarea.height()*z); - emit zoomTo(z,r.x()+r.width()/2, r.y()+r.height()/2); - return true; - } else { - return false; - } -} - -/*! - \qmlproperty int WebView::pressGrabTime - - The number of milliseconds the user must press before the WebView - starts passing move events through to the web engine (rather than - letting other QML elements such as a Flickable take them). - - Defaults to 400ms. Set to 0 to always grab and pass move events to - the web engine. -*/ -int QDeclarativeWebView::pressGrabTime() const -{ - Q_D(const QDeclarativeWebView); - return d->pressTime; -} - -void QDeclarativeWebView::setPressGrabTime(int ms) -{ - Q_D(QDeclarativeWebView); - if (d->pressTime == ms) - return; - d->pressTime = ms; - emit pressGrabTimeChanged(); -} - -void QDeclarativeWebView::mousePressEvent(QGraphicsSceneMouseEvent *event) -{ - Q_D(QDeclarativeWebView); - - setFocus (true); - QMouseEvent *me = sceneMouseEventToMouseEvent(event); - - d->pressPoint = me->pos(); - if (d->pressTime) { - d->pressTimer.start(d->pressTime,this); - setKeepMouseGrab(false); - } else { - grabMouse(); - setKeepMouseGrab(true); - } - - page()->event(me); - event->setAccepted( -/* - It is not correct to send the press event upwards, if it is not accepted by WebKit - e.g. push button does not work, if done so as QGraphicsScene will not send the release event at all to WebKit - Might be a bug in WebKit, though - */ -#if 1 //QT_VERSION <= 0x040500 // XXX see bug 230835 - true -#else - me->isAccepted() -#endif - ); - delete me; - if (!event->isAccepted()) { - QDeclarativePaintedItem::mousePressEvent(event); - } -} - -void QDeclarativeWebView::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) -{ - Q_D(QDeclarativeWebView); - - QMouseEvent *me = sceneMouseEventToMouseEvent(event); - page()->event(me); - d->pressTimer.stop(); - event->setAccepted( -/* - It is not correct to send the press event upwards, if it is not accepted by WebKit - e.g. push button does not work, if done so as QGraphicsScene will not send all the events to WebKit - */ -#if 1 //QT_VERSION <= 0x040500 // XXX see bug 230835 - true -#else - me->isAccepted() -#endif - ); - delete me; - if (!event->isAccepted()) { - QDeclarativePaintedItem::mouseReleaseEvent(event); - } - setKeepMouseGrab(false); - ungrabMouse(); -} - -void QDeclarativeWebView::timerEvent(QTimerEvent *event) -{ - Q_D(QDeclarativeWebView); - if (event->timerId() == d->pressTimer.timerId()) { - d->pressTimer.stop(); - grabMouse(); - setKeepMouseGrab(true); - } -} - -void QDeclarativeWebView::mouseMoveEvent(QGraphicsSceneMouseEvent *event) -{ - Q_D(QDeclarativeWebView); - - QMouseEvent *me = sceneMouseEventToMouseEvent(event); - if (d->pressTimer.isActive()) { - if ((me->pos() - d->pressPoint).manhattanLength() > QApplication::startDragDistance()) { - d->pressTimer.stop(); - } - } - if (keepMouseGrab()) { - page()->event(me); - event->setAccepted( -/* - It is not correct to send the press event upwards, if it is not accepted by WebKit - e.g. push button does not work, if done so as QGraphicsScene will not send the release event at all to WebKit - Might be a bug in WebKit, though - */ -#if 1 // QT_VERSION <= 0x040500 // XXX see bug 230835 - true -#else - me->isAccepted() -#endif - ); - } - delete me; - if (!event->isAccepted()) - QDeclarativePaintedItem::mouseMoveEvent(event); - -} -void QDeclarativeWebView::hoverMoveEvent (QGraphicsSceneHoverEvent * event) -{ - QMouseEvent *me = sceneHoverMoveEventToMouseEvent(event); - page()->event(me); - event->setAccepted( -#if QT_VERSION <= 0x040500 // XXX see bug 230835 - true -#else - me->isAccepted() -#endif - ); - delete me; - if (!event->isAccepted()) - QDeclarativePaintedItem::hoverMoveEvent(event); -} - -void QDeclarativeWebView::keyPressEvent(QKeyEvent* event) -{ - page()->event(event); - if (!event->isAccepted()) - QDeclarativePaintedItem::keyPressEvent(event); -} - -void QDeclarativeWebView::keyReleaseEvent(QKeyEvent* event) -{ - page()->event(event); - if (!event->isAccepted()) - QDeclarativePaintedItem::keyReleaseEvent(event); -} - -bool QDeclarativeWebView::sceneEvent(QEvent *event) -{ - if (event->type() == QEvent::KeyPress) { - QKeyEvent *k = static_cast(event); - if (k->key() == Qt::Key_Tab || k->key() == Qt::Key_Backtab) { - if (!(k->modifiers() & (Qt::ControlModifier | Qt::AltModifier))) { //### Add MetaModifier? - page()->event(event); - if (event->isAccepted()) - return true; - } - } - } - return QDeclarativePaintedItem::sceneEvent(event); -} - - -/*! - \qmlproperty action WebView::back - This property holds the action for causing the previous URL in the history to be displayed. -*/ -QAction *QDeclarativeWebView::backAction() const -{ - return page()->action(QWebPage::Back); -} - -/*! - \qmlproperty action WebView::forward - This property holds the action for causing the next URL in the history to be displayed. -*/ -QAction *QDeclarativeWebView::forwardAction() const -{ - return page()->action(QWebPage::Forward); -} - -/*! - \qmlproperty action WebView::reload - This property holds the action for reloading with the current URL -*/ -QAction *QDeclarativeWebView::reloadAction() const -{ - return page()->action(QWebPage::Reload); -} - -/*! - \qmlproperty action WebView::stop - This property holds the action for stopping loading with the current URL -*/ -QAction *QDeclarativeWebView::stopAction() const -{ - return page()->action(QWebPage::Stop); -} - -/*! - \qmlproperty real WebView::title - This property holds the title of the web page currently viewed - - By default, this property contains an empty string. -*/ -QString QDeclarativeWebView::title() const -{ - return page()->mainFrame()->title(); -} - - - -/*! - \qmlproperty pixmap WebView::icon - This property holds the icon associated with the web page currently viewed -*/ -QPixmap QDeclarativeWebView::icon() const -{ - return page()->mainFrame()->icon().pixmap(QSize(256,256)); -} - - -/*! - \qmlproperty real WebView::zoomFactor - This property holds the multiplier used to scale the contents of a Web page. -*/ -void QDeclarativeWebView::setZoomFactor(qreal factor) -{ - Q_D(QDeclarativeWebView); - if (factor == page()->mainFrame()->zoomFactor()) - return; - - page()->mainFrame()->setZoomFactor(factor); - page()->setViewportSize(QSize( - d->preferredwidth>0 ? d->preferredwidth*factor : width()*factor, - d->preferredheight>0 ? d->preferredheight*factor : height()*factor)); - expandToWebPage(); - - emit zoomFactorChanged(); -} - -qreal QDeclarativeWebView::zoomFactor() const -{ - return page()->mainFrame()->zoomFactor(); -} - -/*! - \qmlproperty string WebView::statusText - - This property is the current status suggested by the current web page. In a web browser, - such status is often shown in some kind of status bar. -*/ -void QDeclarativeWebView::setStatusText(const QString& s) -{ - Q_D(QDeclarativeWebView); - d->statusText = s; - emit statusTextChanged(); -} - -void QDeclarativeWebView::windowObjectCleared() -{ - Q_D(QDeclarativeWebView); - d->updateWindowObjects(); -} - -QString QDeclarativeWebView::statusText() const -{ - Q_D(const QDeclarativeWebView); - return d->statusText; -} - -QWebPage *QDeclarativeWebView::page() const -{ - Q_D(const QDeclarativeWebView); - - if (!d->page) { - QDeclarativeWebView *self = const_cast(this); - QWebPage *wp = new QDeclarativeWebPage(self); - - // QML items don't default to having a background, - // even though most we pages will set one anyway. - QPalette pal = QApplication::palette(); - pal.setBrush(QPalette::Base, QColor::fromRgbF(0, 0, 0, 0)); - wp->setPalette(pal); - - wp->setNetworkAccessManager(qmlEngine(this)->networkAccessManager()); - - self->setPage(wp); - - return wp; - } - - return d->page; -} - - -// The QObject interface to settings(). -/*! - \qmlproperty string WebView::settings.standardFontFamily - \qmlproperty string WebView::settings.fixedFontFamily - \qmlproperty string WebView::settings.serifFontFamily - \qmlproperty string WebView::settings.sansSerifFontFamily - \qmlproperty string WebView::settings.cursiveFontFamily - \qmlproperty string WebView::settings.fantasyFontFamily - - \qmlproperty int WebView::settings.minimumFontSize - \qmlproperty int WebView::settings.minimumLogicalFontSize - \qmlproperty int WebView::settings.defaultFontSize - \qmlproperty int WebView::settings.defaultFixedFontSize - - \qmlproperty bool WebView::settings.autoLoadImages - \qmlproperty bool WebView::settings.javascriptEnabled - \qmlproperty bool WebView::settings.javaEnabled - \qmlproperty bool WebView::settings.pluginsEnabled - \qmlproperty bool WebView::settings.privateBrowsingEnabled - \qmlproperty bool WebView::settings.javascriptCanOpenWindows - \qmlproperty bool WebView::settings.javascriptCanAccessClipboard - \qmlproperty bool WebView::settings.developerExtrasEnabled - \qmlproperty bool WebView::settings.linksIncludedInFocusChain - \qmlproperty bool WebView::settings.zoomTextOnly - \qmlproperty bool WebView::settings.printElementBackgrounds - \qmlproperty bool WebView::settings.offlineStorageDatabaseEnabled - \qmlproperty bool WebView::settings.offlineWebApplicationCacheEnabled - \qmlproperty bool WebView::settings.localStorageDatabaseEnabled - \qmlproperty bool WebView::settings.localContentCanAccessRemoteUrls - - These properties give access to the settings controlling the web view. - - See QWebSettings for details of these properties. - - \qml - WebView { - settings.pluginsEnabled: true - settings.standardFontFamily: "Arial" - ... - } - \endqml -*/ -QDeclarativeWebSettings *QDeclarativeWebView::settingsObject() const -{ - Q_D(const QDeclarativeWebView); - d->settings.s = page()->settings(); - return &d->settings; -} - -void QDeclarativeWebView::setPage(QWebPage *page) -{ - Q_D(QDeclarativeWebView); - if (d->page == page) - return; - if (d->page) { - if (d->page->parent() == this) { - delete d->page; - } else { - d->page->disconnect(this); - } - } - d->page = page; - d->page->setViewportSize(QSize( - d->preferredwidth>0 ? d->preferredwidth : width(), - d->preferredheight>0 ? d->preferredheight : height())); - d->page->mainFrame()->setScrollBarPolicy(Qt::Horizontal,Qt::ScrollBarAlwaysOff); - d->page->mainFrame()->setScrollBarPolicy(Qt::Vertical,Qt::ScrollBarAlwaysOff); - connect(d->page,SIGNAL(repaintRequested(QRect)),this,SLOT(paintPage(QRect))); - connect(d->page->mainFrame(),SIGNAL(urlChanged(QUrl)),this,SLOT(pageUrlChanged())); - connect(d->page->mainFrame(), SIGNAL(titleChanged(QString)), this, SIGNAL(titleChanged(QString))); - connect(d->page->mainFrame(), SIGNAL(titleChanged(QString)), this, SIGNAL(iconChanged())); - connect(d->page->mainFrame(), SIGNAL(iconChanged()), this, SIGNAL(iconChanged())); - connect(d->page->mainFrame(), SIGNAL(contentsSizeChanged(QSize)), this, SLOT(noteContentsSizeChanged(QSize))); - connect(d->page->mainFrame(), SIGNAL(initialLayoutCompleted()), this, SLOT(initialLayout())); - - connect(d->page,SIGNAL(loadStarted()),this,SLOT(doLoadStarted())); - connect(d->page,SIGNAL(loadProgress(int)),this,SLOT(doLoadProgress(int))); - connect(d->page,SIGNAL(loadFinished(bool)),this,SLOT(doLoadFinished(bool))); - connect(d->page,SIGNAL(statusBarMessage(QString)),this,SLOT(setStatusText(QString))); - - connect(d->page->mainFrame(),SIGNAL(javaScriptWindowObjectCleared()),this,SLOT(windowObjectCleared())); -} - -/*! - \qmlsignal WebView::onLoadStarted() - - This handler is called when the web engine begins loading - a page. Later, WebView::onLoadFinished() or WebView::onLoadFailed() - will be emitted. -*/ - -/*! - \qmlsignal WebView::onLoadFinished() - - This handler is called when the web engine \e successfully - finishes loading a page, including any component content - (WebView::onLoadFailed() will be emitted otherwise). - - \sa progress -*/ - -/*! - \qmlsignal WebView::onLoadFailed() - - This handler is called when the web engine fails loading - a page or any component content - (WebView::onLoadFinished() will be emitted on success). -*/ - -void QDeclarativeWebView::load(const QNetworkRequest &request, - QNetworkAccessManager::Operation operation, - const QByteArray &body) -{ - page()->mainFrame()->load(request, operation, body); -} - -QString QDeclarativeWebView::html() const -{ - return page()->mainFrame()->toHtml(); -} - -/*! - \qmlproperty string WebView::html - This property holds HTML text set directly - - The html property can be set as a string. - - \qml - WebView { - html: "

This is HTML." - } - \endqml -*/ -void QDeclarativeWebView::setHtml(const QString &html, const QUrl &baseUrl) -{ - Q_D(QDeclarativeWebView); - page()->setViewportSize(QSize( - d->preferredwidth>0 ? d->preferredwidth : width(), - d->preferredheight>0 ? d->preferredheight : height())); - if (isComponentComplete()) - page()->mainFrame()->setHtml(html, baseUrl); - else { - d->pending = d->PendingHtml; - d->pending_url = baseUrl; - d->pending_string = html; - } - emit htmlChanged(); -} - -void QDeclarativeWebView::setContent(const QByteArray &data, const QString &mimeType, const QUrl &baseUrl) -{ - Q_D(QDeclarativeWebView); - page()->setViewportSize(QSize( - d->preferredwidth>0 ? d->preferredwidth : width(), - d->preferredheight>0 ? d->preferredheight : height())); - - if (isComponentComplete()) - page()->mainFrame()->setContent(data,mimeType,qmlContext(this)->resolvedUrl(baseUrl)); - else { - d->pending = d->PendingContent; - d->pending_url = baseUrl; - d->pending_string = mimeType; - d->pending_data = data; - } -} - -QWebHistory *QDeclarativeWebView::history() const -{ - return page()->history(); -} - -QWebSettings *QDeclarativeWebView::settings() const -{ - return page()->settings(); -} - -QDeclarativeWebView *QDeclarativeWebView::createWindow(QWebPage::WebWindowType type) -{ - Q_D(QDeclarativeWebView); - switch (type) { - case QWebPage::WebBrowserWindow: { - if (!d->newWindowComponent && d->newWindowParent) - qWarning("WebView::newWindowComponent not set - WebView::newWindowParent ignored"); - else if (d->newWindowComponent && !d->newWindowParent) - qWarning("WebView::newWindowParent not set - WebView::newWindowComponent ignored"); - else if (d->newWindowComponent && d->newWindowParent) { - QDeclarativeWebView *webview = 0; - QDeclarativeContext *windowContext = new QDeclarativeContext(qmlContext(this)); - - QObject *nobj = d->newWindowComponent->create(windowContext); - if (nobj) { - windowContext->setParent(nobj); - QDeclarativeItem *item = qobject_cast(nobj); - if (!item) { - delete nobj; - } else { - webview = item->findChild(); - if (!webview) { - delete item; - } else { - nobj->setParent(d->newWindowParent); - static_cast(item)->setParentItem(d->newWindowParent); - } - } - } else { - delete windowContext; - } - - return webview; - } - } - break; - case QWebPage::WebModalDialog: { - // Not supported - } - } - return 0; -} - -/*! - \qmlproperty component WebView::newWindowComponent - - This property holds the component to use for new windows. - The component must have a WebView somewhere in its structure. - - When the web engine requests a new window, it will be an instance of - this component. - - The parent of the new window is set by newWindowParent. It must be set. -*/ -QDeclarativeComponent *QDeclarativeWebView::newWindowComponent() const -{ - Q_D(const QDeclarativeWebView); - return d->newWindowComponent; -} - -void QDeclarativeWebView::setNewWindowComponent(QDeclarativeComponent *newWindow) -{ - Q_D(QDeclarativeWebView); - if (newWindow == d->newWindowComponent) - return; - d->newWindowComponent = newWindow; - emit newWindowComponentChanged(); -} - - -/*! - \qmlproperty item WebView::newWindowParent - - The parent item for new windows. - - \sa newWindowComponent -*/ -QDeclarativeItem *QDeclarativeWebView::newWindowParent() const -{ - Q_D(const QDeclarativeWebView); - return d->newWindowParent; -} - -void QDeclarativeWebView::setNewWindowParent(QDeclarativeItem *parent) -{ - Q_D(QDeclarativeWebView); - if (parent == d->newWindowParent) - return; - if (d->newWindowParent && parent) { - QList children = d->newWindowParent->childItems(); - for (int i = 0; i < children.count(); ++i) { - children.at(i)->setParentItem(parent); - } - } - d->newWindowParent = parent; - emit newWindowParentChanged(); -} - -/*! - Returns the area of the largest element at position (\a x,\a y) that is no larger - than \a maxwidth by \a maxheight pixels. - - May return an area larger in the case when no smaller element is at the position. -*/ -QRect QDeclarativeWebView::elementAreaAt(int x, int y, int maxwidth, int maxheight) const -{ - QWebHitTestResult hit = page()->mainFrame()->hitTestContent(QPoint(x,y)); - QRect rv = hit.boundingRect(); - QWebElement element = hit.enclosingBlockElement(); - if (maxwidth<=0) maxwidth = INT_MAX; - if (maxheight<=0) maxheight = INT_MAX; - while (!element.parent().isNull() && element.geometry().width() <= maxwidth && element.geometry().height() <= maxheight) { - rv = element.geometry(); - element = element.parent(); - } - return rv; -} - -/*! - \internal - \class QDeclarativeWebPage - \brief The QDeclarativeWebPage class is a QWebPage that can create QML plugins. - - \sa QDeclarativeWebView -*/ -QDeclarativeWebPage::QDeclarativeWebPage(QDeclarativeWebView *parent) : - QWebPage(parent) -{ -} - -QDeclarativeWebPage::~QDeclarativeWebPage() -{ -} - -void QDeclarativeWebPage::javaScriptConsoleMessage(const QString& message, int lineNumber, const QString& sourceID) -{ - qWarning() << sourceID << ':' << lineNumber << ':' << message; -} - -QString QDeclarativeWebPage::chooseFile(QWebFrame *originatingFrame, const QString& oldFile) -{ - // Not supported (it's modal) - Q_UNUSED(originatingFrame) - Q_UNUSED(oldFile) - return oldFile; -} - -void QDeclarativeWebPage::javaScriptAlert(QWebFrame *originatingFrame, const QString& msg) -{ - Q_UNUSED(originatingFrame) - emit viewItem()->alert(msg); -} - -bool QDeclarativeWebPage::javaScriptConfirm(QWebFrame *originatingFrame, const QString& msg) -{ - // Not supported (it's modal) - Q_UNUSED(originatingFrame) - Q_UNUSED(msg) - return false; -} - -bool QDeclarativeWebPage::javaScriptPrompt(QWebFrame *originatingFrame, const QString& msg, const QString& defaultValue, QString* result) -{ - // Not supported (it's modal) - Q_UNUSED(originatingFrame) - Q_UNUSED(msg) - Q_UNUSED(defaultValue) - Q_UNUSED(result) - return false; -} - - -/* - Qt WebKit does not understand non-QWidget plugins, so dummy widgets - are created, parented to a single dummy tool window. - - The requirements for QML object plugins are input to the Qt WebKit - non-QWidget plugin support, which will obsolete this kludge. -*/ -class QWidget_Dummy_Plugin : public QWidget -{ - Q_OBJECT -public: - static QWidget *dummy_shared_parent() - { - static QWidget *dsp = 0; - if (!dsp) { - dsp = new QWidget(0,Qt::Tool); - dsp->setGeometry(-10000,-10000,0,0); - dsp->show(); - } - return dsp; - } - QWidget_Dummy_Plugin(const QUrl& url, QDeclarativeWebView *view, const QStringList ¶mNames, const QStringList ¶mValues) : - QWidget(dummy_shared_parent()), - propertyNames(paramNames), - propertyValues(paramValues), - webview(view) - { - QDeclarativeEngine *engine = qmlEngine(webview); - component = new QDeclarativeComponent(engine, url, this); - item = 0; - if (component->isLoading()) - connect(component, SIGNAL(statusChanged(QDeclarativeComponent::Status)), this, SLOT(qmlLoaded())); - else - qmlLoaded(); - } - -public Q_SLOTS: - void qmlLoaded() - { - if (component->isError()) { - // ### Could instead give these errors to the WebView to handle. - qWarning() << component->errors(); - return; - } - item = qobject_cast(component->create(qmlContext(webview))); - item->setParent(webview); - QString jsObjName; - for (int i=0; isetProperty(propertyNames[i].toUtf8(),propertyValues[i]); - if (propertyNames[i] == QLatin1String("objectname")) - jsObjName = propertyValues[i]; - } - } - if (!jsObjName.isNull()) { - QWebFrame *f = webview->page()->mainFrame(); - f->addToJavaScriptWindowObject(jsObjName, item); - } - resizeEvent(0); - delete component; - component = 0; - } - void resizeEvent(QResizeEvent*) - { - if (item) { - item->setX(x()); - item->setY(y()); - item->setWidth(width()); - item->setHeight(height()); - } - } - -private: - QDeclarativeComponent *component; - QDeclarativeItem *item; - QStringList propertyNames, propertyValues; - QDeclarativeWebView *webview; -}; - -QDeclarativeWebView *QDeclarativeWebPage::viewItem() -{ - return static_cast(parent()); -} - -QObject *QDeclarativeWebPage::createPlugin(const QString &, const QUrl &url, const QStringList ¶mNames, const QStringList ¶mValues) -{ - QUrl comp = qmlContext(viewItem())->resolvedUrl(url); - return new QWidget_Dummy_Plugin(comp,viewItem(),paramNames,paramValues); -} - -QWebPage *QDeclarativeWebPage::createWindow(WebWindowType type) -{ - QDeclarativeWebView *newView = viewItem()->createWindow(type); - if (newView) - return newView->page(); - return 0; -} - -QT_END_NAMESPACE - -#include diff --git a/src/declarative/graphicsitems/qdeclarativewebview_p.h b/src/declarative/graphicsitems/qdeclarativewebview_p.h deleted file mode 100644 index a65aab3..0000000 --- a/src/declarative/graphicsitems/qdeclarativewebview_p.h +++ /dev/null @@ -1,286 +0,0 @@ -/**************************************************************************** -** -** 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 QDECLARATIVEWEBVIEW_H -#define QDECLARATIVEWEBVIEW_H - -#include "qdeclarativepainteditem_p.h" - -#include -#include -#include -#include - -QT_BEGIN_HEADER - -class QWebHistory; -class QWebSettings; - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) -class QDeclarativeWebViewPrivate; -class QNetworkRequest; -class QDeclarativeWebView; - -class Q_DECLARATIVE_EXPORT QDeclarativeWebPage : public QWebPage -{ - Q_OBJECT -public: - explicit QDeclarativeWebPage(QDeclarativeWebView *parent); - ~QDeclarativeWebPage(); -protected: - QObject *createPlugin(const QString &classid, const QUrl &url, const QStringList ¶mNames, const QStringList ¶mValues); - QWebPage *createWindow(WebWindowType type); - void javaScriptConsoleMessage(const QString& message, int lineNumber, const QString& sourceID); - QString chooseFile(QWebFrame *originatingFrame, const QString& oldFile); - void javaScriptAlert(QWebFrame *originatingFrame, const QString& msg); - bool javaScriptConfirm(QWebFrame *originatingFrame, const QString& msg); - bool javaScriptPrompt(QWebFrame *originatingFrame, const QString& msg, const QString& defaultValue, QString* result); - -private: - QDeclarativeWebView *viewItem(); -}; - - -class QDeclarativeWebViewAttached; -class QDeclarativeWebSettings; - -//### TODO: browser plugins - -class Q_DECLARATIVE_EXPORT QDeclarativeWebView : public QDeclarativePaintedItem -{ - Q_OBJECT - - Q_ENUMS(Status SelectionMode) - - Q_PROPERTY(QString title READ title NOTIFY titleChanged) - Q_PROPERTY(QPixmap icon READ icon NOTIFY iconChanged) - Q_PROPERTY(qreal zoomFactor READ zoomFactor WRITE setZoomFactor NOTIFY zoomFactorChanged) - Q_PROPERTY(QString statusText READ statusText NOTIFY statusTextChanged) - - Q_PROPERTY(QString html READ html WRITE setHtml NOTIFY htmlChanged) - - Q_PROPERTY(int pressGrabTime READ pressGrabTime WRITE setPressGrabTime NOTIFY pressGrabTimeChanged) - - Q_PROPERTY(int preferredWidth READ preferredWidth WRITE setPreferredWidth NOTIFY preferredWidthChanged) - Q_PROPERTY(int preferredHeight READ preferredHeight WRITE setPreferredHeight NOTIFY preferredHeightChanged) - Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY urlChanged) - Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged) - Q_PROPERTY(Status status READ status NOTIFY statusChanged) - - Q_PROPERTY(QAction* reload READ reloadAction CONSTANT) - Q_PROPERTY(QAction* back READ backAction CONSTANT) - Q_PROPERTY(QAction* forward READ forwardAction CONSTANT) - Q_PROPERTY(QAction* stop READ stopAction CONSTANT) - - Q_PROPERTY(QDeclarativeWebSettings* settings READ settingsObject CONSTANT) - - Q_PROPERTY(QDeclarativeListProperty javaScriptWindowObjects READ javaScriptWindowObjects CONSTANT) - - Q_PROPERTY(QDeclarativeComponent* newWindowComponent READ newWindowComponent WRITE setNewWindowComponent NOTIFY newWindowComponentChanged) - Q_PROPERTY(QDeclarativeItem* newWindowParent READ newWindowParent WRITE setNewWindowParent NOTIFY newWindowParentChanged) - - Q_PROPERTY(bool renderingEnabled READ renderingEnabled WRITE setRenderingEnabled NOTIFY renderingEnabledChanged) - -public: - QDeclarativeWebView(QDeclarativeItem *parent=0); - ~QDeclarativeWebView(); - - QUrl url() const; - void setUrl(const QUrl &); - - QString title() const; - - QPixmap icon() const; - - qreal zoomFactor() const; - void setZoomFactor(qreal); - Q_INVOKABLE bool heuristicZoom(int clickX, int clickY, qreal maxzoom); - QRect elementAreaAt(int x, int y, int minwidth, int minheight) const; - - int pressGrabTime() const; - void setPressGrabTime(int); - - int preferredWidth() const; - void setPreferredWidth(int); - int preferredHeight() const; - void setPreferredHeight(int); - - enum Status { Null, Ready, Loading, Error }; - Status status() const; - qreal progress() const; - QString statusText() const; - - QAction *reloadAction() const; - QAction *backAction() const; - QAction *forwardAction() const; - QAction *stopAction() const; - - QWebPage *page() const; - void setPage(QWebPage *page); - - void load(const QNetworkRequest &request, - QNetworkAccessManager::Operation operation = QNetworkAccessManager::GetOperation, - const QByteArray &body = QByteArray()); - - QString html() const; - - void setHtml(const QString &html, const QUrl &baseUrl = QUrl()); - void setContent(const QByteArray &data, const QString &mimeType = QString(), const QUrl &baseUrl = QUrl()); - - QWebHistory *history() const; - QWebSettings *settings() const; - QDeclarativeWebSettings *settingsObject() const; - - bool renderingEnabled() const; - void setRenderingEnabled(bool); - - QDeclarativeListProperty javaScriptWindowObjects(); - - static QDeclarativeWebViewAttached *qmlAttachedProperties(QObject *); - - QDeclarativeComponent *newWindowComponent() const; - void setNewWindowComponent(QDeclarativeComponent *newWindow); - QDeclarativeItem *newWindowParent() const; - void setNewWindowParent(QDeclarativeItem *newWindow); - -Q_SIGNALS: - void preferredWidthChanged(); - void preferredHeightChanged(); - void urlChanged(); - void progressChanged(); - void statusChanged(Status); - void titleChanged(const QString&); - void iconChanged(); - void statusTextChanged(); - void htmlChanged(); - void pressGrabTimeChanged(); - void zoomFactorChanged(); - void newWindowComponentChanged(); - void newWindowParentChanged(); - void renderingEnabledChanged(); - - void loadStarted(); - void loadFinished(); - void loadFailed(); - - void doubleClick(int clickX, int clickY); - - void zoomTo(qreal zoom, int centerX, int centerY); - - void alert(const QString& message); - -public Q_SLOTS: - QVariant evaluateJavaScript(const QString&); - -private Q_SLOTS: - void expandToWebPage(); - void paintPage(const QRect&); - void doLoadStarted(); - void doLoadProgress(int p); - void doLoadFinished(bool ok); - void setStatusText(const QString&); - void windowObjectCleared(); - void pageUrlChanged(); - void noteContentsSizeChanged(const QSize&); - void initialLayout(); - -protected: - void drawContents(QPainter *, const QRect &); - - void mousePressEvent(QGraphicsSceneMouseEvent *event); - void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); - void mouseMoveEvent(QGraphicsSceneMouseEvent *event); - void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); - void timerEvent(QTimerEvent *event); - void hoverMoveEvent (QGraphicsSceneHoverEvent * event); - void keyPressEvent(QKeyEvent* event); - void keyReleaseEvent(QKeyEvent* event); - virtual void geometryChanged(const QRectF &newGeometry, - const QRectF &oldGeometry); - virtual void focusChanged(bool); - virtual bool sceneEvent(QEvent *event); - QDeclarativeWebView *createWindow(QWebPage::WebWindowType type); - -private: - void init(); - virtual void componentComplete(); - Q_DISABLE_COPY(QDeclarativeWebView) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarativeWebView) - QMouseEvent *sceneMouseEventToMouseEvent(QGraphicsSceneMouseEvent *); - QMouseEvent *sceneHoverMoveEventToMouseEvent(QGraphicsSceneHoverEvent *); - friend class QDeclarativeWebPage; -}; - -class QDeclarativeWebViewAttached : public QObject -{ - Q_OBJECT - Q_PROPERTY(QString windowObjectName READ windowObjectName WRITE setWindowObjectName) -public: - QDeclarativeWebViewAttached(QObject *parent) - : QObject(parent) - { - } - - QString windowObjectName() const - { - return m_windowObjectName; - } - - void setWindowObjectName(const QString &n) - { - m_windowObjectName = n; - } - -private: - QString m_windowObjectName; -}; - - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QDeclarativeWebView) -QML_DECLARE_TYPEINFO(QDeclarativeWebView, QML_HAS_ATTACHED_PROPERTIES) - -QT_END_HEADER - -#endif diff --git a/src/declarative/graphicsitems/qdeclarativewebview_p_p.h b/src/declarative/graphicsitems/qdeclarativewebview_p_p.h deleted file mode 100644 index 258b472..0000000 --- a/src/declarative/graphicsitems/qdeclarativewebview_p_p.h +++ /dev/null @@ -1,151 +0,0 @@ -/**************************************************************************** -** -** 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 QDECLARATIVEWEBVIEW_P_H -#define QDECLARATIVEWEBVIEW_P_H - -#include - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QDeclarativeWebSettings : public QObject { - Q_OBJECT - - Q_PROPERTY(QString standardFontFamily READ standardFontFamily WRITE setStandardFontFamily) - Q_PROPERTY(QString fixedFontFamily READ fixedFontFamily WRITE setFixedFontFamily) - Q_PROPERTY(QString serifFontFamily READ serifFontFamily WRITE setSerifFontFamily) - Q_PROPERTY(QString sansSerifFontFamily READ sansSerifFontFamily WRITE setSansSerifFontFamily) - Q_PROPERTY(QString cursiveFontFamily READ cursiveFontFamily WRITE setCursiveFontFamily) - Q_PROPERTY(QString fantasyFontFamily READ fantasyFontFamily WRITE setFantasyFontFamily) - - Q_PROPERTY(int minimumFontSize READ minimumFontSize WRITE setMinimumFontSize) - Q_PROPERTY(int minimumLogicalFontSize READ minimumLogicalFontSize WRITE setMinimumLogicalFontSize) - Q_PROPERTY(int defaultFontSize READ defaultFontSize WRITE setDefaultFontSize) - Q_PROPERTY(int defaultFixedFontSize READ defaultFixedFontSize WRITE setDefaultFixedFontSize) - - Q_PROPERTY(bool autoLoadImages READ autoLoadImages WRITE setAutoLoadImages) - Q_PROPERTY(bool javascriptEnabled READ javascriptEnabled WRITE setJavascriptEnabled) - Q_PROPERTY(bool javaEnabled READ javaEnabled WRITE setJavaEnabled) - Q_PROPERTY(bool pluginsEnabled READ pluginsEnabled WRITE setPluginsEnabled) - Q_PROPERTY(bool privateBrowsingEnabled READ privateBrowsingEnabled WRITE setPrivateBrowsingEnabled) - Q_PROPERTY(bool javascriptCanOpenWindows READ javascriptCanOpenWindows WRITE setJavascriptCanOpenWindows) - Q_PROPERTY(bool javascriptCanAccessClipboard READ javascriptCanAccessClipboard WRITE setJavascriptCanAccessClipboard) - Q_PROPERTY(bool developerExtrasEnabled READ developerExtrasEnabled WRITE setDeveloperExtrasEnabled) - Q_PROPERTY(bool linksIncludedInFocusChain READ linksIncludedInFocusChain WRITE setLinksIncludedInFocusChain) - Q_PROPERTY(bool zoomTextOnly READ zoomTextOnly WRITE setZoomTextOnly) - Q_PROPERTY(bool printElementBackgrounds READ printElementBackgrounds WRITE setPrintElementBackgrounds) - Q_PROPERTY(bool offlineStorageDatabaseEnabled READ offlineStorageDatabaseEnabled WRITE setOfflineStorageDatabaseEnabled) - Q_PROPERTY(bool offlineWebApplicationCacheEnabled READ offlineWebApplicationCacheEnabled WRITE setOfflineWebApplicationCacheEnabled) - Q_PROPERTY(bool localStorageDatabaseEnabled READ localStorageDatabaseEnabled WRITE setLocalStorageDatabaseEnabled) - Q_PROPERTY(bool localContentCanAccessRemoteUrls READ localContentCanAccessRemoteUrls WRITE setLocalContentCanAccessRemoteUrls) - -public: - QDeclarativeWebSettings() {} - - QString standardFontFamily() const { return s->fontFamily(QWebSettings::StandardFont); } - void setStandardFontFamily(const QString& f) { s->setFontFamily(QWebSettings::StandardFont,f); } - QString fixedFontFamily() const { return s->fontFamily(QWebSettings::FixedFont); } - void setFixedFontFamily(const QString& f) { s->setFontFamily(QWebSettings::FixedFont,f); } - QString serifFontFamily() const { return s->fontFamily(QWebSettings::SerifFont); } - void setSerifFontFamily(const QString& f) { s->setFontFamily(QWebSettings::SerifFont,f); } - QString sansSerifFontFamily() const { return s->fontFamily(QWebSettings::SansSerifFont); } - void setSansSerifFontFamily(const QString& f) { s->setFontFamily(QWebSettings::SansSerifFont,f); } - QString cursiveFontFamily() const { return s->fontFamily(QWebSettings::CursiveFont); } - void setCursiveFontFamily(const QString& f) { s->setFontFamily(QWebSettings::CursiveFont,f); } - QString fantasyFontFamily() const { return s->fontFamily(QWebSettings::FantasyFont); } - void setFantasyFontFamily(const QString& f) { s->setFontFamily(QWebSettings::FantasyFont,f); } - - int minimumFontSize() const { return s->fontSize(QWebSettings::MinimumFontSize); } - void setMinimumFontSize(int size) { s->setFontSize(QWebSettings::MinimumFontSize,size); } - int minimumLogicalFontSize() const { return s->fontSize(QWebSettings::MinimumLogicalFontSize); } - void setMinimumLogicalFontSize(int size) { s->setFontSize(QWebSettings::MinimumLogicalFontSize,size); } - int defaultFontSize() const { return s->fontSize(QWebSettings::DefaultFontSize); } - void setDefaultFontSize(int size) { s->setFontSize(QWebSettings::DefaultFontSize,size); } - int defaultFixedFontSize() const { return s->fontSize(QWebSettings::DefaultFixedFontSize); } - void setDefaultFixedFontSize(int size) { s->setFontSize(QWebSettings::DefaultFixedFontSize,size); } - - bool autoLoadImages() const { return s->testAttribute(QWebSettings::AutoLoadImages); } - void setAutoLoadImages(bool on) { s->setAttribute(QWebSettings::AutoLoadImages, on); } - bool javascriptEnabled() const { return s->testAttribute(QWebSettings::JavascriptEnabled); } - void setJavascriptEnabled(bool on) { s->setAttribute(QWebSettings::JavascriptEnabled, on); } - bool javaEnabled() const { return s->testAttribute(QWebSettings::JavaEnabled); } - void setJavaEnabled(bool on) { s->setAttribute(QWebSettings::JavaEnabled, on); } - bool pluginsEnabled() const { return s->testAttribute(QWebSettings::PluginsEnabled); } - void setPluginsEnabled(bool on) { s->setAttribute(QWebSettings::PluginsEnabled, on); } - bool privateBrowsingEnabled() const { return s->testAttribute(QWebSettings::PrivateBrowsingEnabled); } - void setPrivateBrowsingEnabled(bool on) { s->setAttribute(QWebSettings::PrivateBrowsingEnabled, on); } - bool javascriptCanOpenWindows() const { return s->testAttribute(QWebSettings::JavascriptCanOpenWindows); } - void setJavascriptCanOpenWindows(bool on) { s->setAttribute(QWebSettings::JavascriptCanOpenWindows, on); } - bool javascriptCanAccessClipboard() const { return s->testAttribute(QWebSettings::JavascriptCanAccessClipboard); } - void setJavascriptCanAccessClipboard(bool on) { s->setAttribute(QWebSettings::JavascriptCanAccessClipboard, on); } - bool developerExtrasEnabled() const { return s->testAttribute(QWebSettings::DeveloperExtrasEnabled); } - void setDeveloperExtrasEnabled(bool on) { s->setAttribute(QWebSettings::DeveloperExtrasEnabled, on); } - bool linksIncludedInFocusChain() const { return s->testAttribute(QWebSettings::LinksIncludedInFocusChain); } - void setLinksIncludedInFocusChain(bool on) { s->setAttribute(QWebSettings::LinksIncludedInFocusChain, on); } - bool zoomTextOnly() const { return s->testAttribute(QWebSettings::ZoomTextOnly); } - void setZoomTextOnly(bool on) { s->setAttribute(QWebSettings::ZoomTextOnly, on); } - bool printElementBackgrounds() const { return s->testAttribute(QWebSettings::PrintElementBackgrounds); } - void setPrintElementBackgrounds(bool on) { s->setAttribute(QWebSettings::PrintElementBackgrounds, on); } - bool offlineStorageDatabaseEnabled() const { return s->testAttribute(QWebSettings::OfflineStorageDatabaseEnabled); } - void setOfflineStorageDatabaseEnabled(bool on) { s->setAttribute(QWebSettings::OfflineStorageDatabaseEnabled, on); } - bool offlineWebApplicationCacheEnabled() const { return s->testAttribute(QWebSettings::OfflineWebApplicationCacheEnabled); } - void setOfflineWebApplicationCacheEnabled(bool on) { s->setAttribute(QWebSettings::OfflineWebApplicationCacheEnabled, on); } - bool localStorageDatabaseEnabled() const { return s->testAttribute(QWebSettings::LocalStorageDatabaseEnabled); } - void setLocalStorageDatabaseEnabled(bool on) { s->setAttribute(QWebSettings::LocalStorageDatabaseEnabled, on); } - bool localContentCanAccessRemoteUrls() const { return s->testAttribute(QWebSettings::LocalContentCanAccessRemoteUrls); } - void setLocalContentCanAccessRemoteUrls(bool on) { s->setAttribute(QWebSettings::LocalContentCanAccessRemoteUrls, on); } - - QWebSettings *s; -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QDeclarativeWebSettings) - -QT_END_HEADER - -#endif diff --git a/src/plugins/qdeclarativemodules/qdeclarativemodules.pro b/src/plugins/qdeclarativemodules/qdeclarativemodules.pro index 0a6f444..ae53578 100644 --- a/src/plugins/qdeclarativemodules/qdeclarativemodules.pro +++ b/src/plugins/qdeclarativemodules/qdeclarativemodules.pro @@ -3,4 +3,5 @@ TEMPLATE = subdirs SUBDIRS += widgets contains(QT_CONFIG, multimedia): SUBDIRS += multimedia +contains(QT_CONFIG, webkit): SUBDIRS += webkitqmlplugin diff --git a/src/plugins/qdeclarativemodules/webkitqmlplugin/plugin.cpp b/src/plugins/qdeclarativemodules/webkitqmlplugin/plugin.cpp new file mode 100644 index 0000000..2f6205d --- /dev/null +++ b/src/plugins/qdeclarativemodules/webkitqmlplugin/plugin.cpp @@ -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 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 +#include + +#include "qdeclarativewebview_p.h" +#include "qdeclarativewebview_p_p.h" + +QT_BEGIN_NAMESPACE + +class WebKitQmlPlugin : public QDeclarativeExtensionPlugin +{ + Q_OBJECT +public: + virtual void registerTypes(const char *uri) + { + Q_ASSERT(QLatin1String(uri) == QLatin1String("org.webkit")); + qmlRegisterType(uri,1,0,"WebView"); + } +}; + +QT_END_NAMESPACE + +#include "plugin.moc" + +Q_EXPORT_PLUGIN2(webkitqmlplugin, QT_PREPEND_NAMESPACE(WebKitQmlPlugin)); + diff --git a/src/plugins/qdeclarativemodules/webkitqmlplugin/qdeclarativewebview.cpp b/src/plugins/qdeclarativemodules/webkitqmlplugin/qdeclarativewebview.cpp new file mode 100644 index 0000000..733ac86 --- /dev/null +++ b/src/plugins/qdeclarativemodules/webkitqmlplugin/qdeclarativewebview.cpp @@ -0,0 +1,1340 @@ +/**************************************************************************** +** +** 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 "qdeclarativewebview_p.h" +#include "qdeclarativewebview_p_p.h" + +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +static const int MAX_DOUBLECLICK_TIME=500; // XXX need better gesture system + +class QDeclarativeWebViewPrivate : public QDeclarativePaintedItemPrivate +{ + Q_DECLARE_PUBLIC(QDeclarativeWebView) + +public: + QDeclarativeWebViewPrivate() + : QDeclarativePaintedItemPrivate(), page(0), preferredwidth(0), preferredheight(0), + progress(1.0), status(QDeclarativeWebView::Null), pending(PendingNone), + newWindowComponent(0), newWindowParent(0), + pressTime(400), + rendering(true) + { + } + + QUrl url; // page url might be different if it has not loaded yet + QWebPage *page; + + int preferredwidth, preferredheight; + qreal progress; + QDeclarativeWebView::Status status; + QString statusText; + enum { PendingNone, PendingUrl, PendingHtml, PendingContent } pending; + QUrl pending_url; + QString pending_string; + QByteArray pending_data; + mutable QDeclarativeWebSettings settings; + QDeclarativeComponent *newWindowComponent; + QDeclarativeItem *newWindowParent; + + QBasicTimer pressTimer; + QPoint pressPoint; + int pressTime; // milliseconds before it's a "hold" + + + static void windowObjects_append(QDeclarativeListProperty *prop, QObject *o) { + static_cast(prop->data)->windowObjects.append(o); + static_cast(prop->data)->updateWindowObjects(); + } + + void updateWindowObjects(); + QObjectList windowObjects; + + bool rendering; +}; + +/*! + \qmlclass WebView QDeclarativeWebView + \since 4.7 + \brief The WebView item allows you to add web content to a canvas. + \inherits Item + + A WebView renders web content based on a URL. + + If the width and height of the item is not set, they will + dynamically adjust to a size appropriate for the content. + This width may be large for typical online web pages. + + If the preferredWidth is set, the width will be this amount or larger, + usually laying out the web content to fit the preferredWidth. + + \qml + import org.webkit 1.0 + + WebView { + url: "http://www.nokia.com" + width: 490 + height: 400 + scale: 0.5 + smooth: false + smoothCache: true + } + \endqml + + \image webview.png + + The item includes no scrolling, scaling, + toolbars, etc., those must be implemented around WebView. See the WebBrowser example + for a demonstration of this. +*/ + +/*! + \internal + \class QDeclarativeWebView + \brief The QDeclarativeWebView class allows you to add web content to a QDeclarativeView. + + A WebView renders web content base on a URL. + + \image webview.png + + The item includes no scrolling, scaling, + toolbars, etc., those must be implemented around WebView. See the WebBrowser example + for a demonstration of this. + + A QDeclarativeWebView object can be instantiated in Qml using the tag \l WebView. +*/ + +QDeclarativeWebView::QDeclarativeWebView(QDeclarativeItem *parent) + : QDeclarativePaintedItem(*(new QDeclarativeWebViewPrivate), parent) +{ + init(); +} + +QDeclarativeWebView::~QDeclarativeWebView() +{ + Q_D(QDeclarativeWebView); + delete d->page; +} + +void QDeclarativeWebView::init() +{ + Q_D(QDeclarativeWebView); + + QWebSettings::enablePersistentStorage(); + + setAcceptHoverEvents(true); + setAcceptedMouseButtons(Qt::LeftButton); + setFlag(QGraphicsItem::ItemHasNoContents, false); + + d->page = 0; +} + +void QDeclarativeWebView::componentComplete() +{ + QDeclarativePaintedItem::componentComplete(); + Q_D(QDeclarativeWebView); + switch (d->pending) { + case QDeclarativeWebViewPrivate::PendingUrl: + setUrl(d->pending_url); + break; + case QDeclarativeWebViewPrivate::PendingHtml: + setHtml(d->pending_string, d->pending_url); + break; + case QDeclarativeWebViewPrivate::PendingContent: + setContent(d->pending_data, d->pending_string, d->pending_url); + break; + default: + break; + } + d->pending = QDeclarativeWebViewPrivate::PendingNone; + d->updateWindowObjects(); +} + +QDeclarativeWebView::Status QDeclarativeWebView::status() const +{ + Q_D(const QDeclarativeWebView); + return d->status; +} + + +/*! + \qmlproperty real WebView::progress + This property holds the progress of loading the current URL, from 0 to 1. + + If you just want to know when progress gets to 1, use + WebView::onLoadFinished() or WebView::onLoadFailed() instead. +*/ +qreal QDeclarativeWebView::progress() const +{ + Q_D(const QDeclarativeWebView); + return d->progress; +} + +void QDeclarativeWebView::doLoadStarted() +{ + Q_D(QDeclarativeWebView); + + if (!d->url.isEmpty()) { + d->status = Loading; + emit statusChanged(d->status); + } + emit loadStarted(); +} + +void QDeclarativeWebView::doLoadProgress(int p) +{ + Q_D(QDeclarativeWebView); + if (d->progress == p/100.0) + return; + d->progress = p/100.0; + emit progressChanged(); +} + +void QDeclarativeWebView::pageUrlChanged() +{ + Q_D(QDeclarativeWebView); + + page()->setViewportSize(QSize( + d->preferredwidth>0 ? d->preferredwidth : width(), + d->preferredheight>0 ? d->preferredheight : height())); + expandToWebPage(); + + if ((d->url.isEmpty() && page()->mainFrame()->url() != QUrl(QLatin1String("about:blank"))) + || (d->url != page()->mainFrame()->url() && !page()->mainFrame()->url().isEmpty())) + { + d->url = page()->mainFrame()->url(); + if (d->url == QUrl(QLatin1String("about:blank"))) + d->url = QUrl(); + emit urlChanged(); + } +} + +void QDeclarativeWebView::doLoadFinished(bool ok) +{ + Q_D(QDeclarativeWebView); + + if (title().isEmpty()) + pageUrlChanged(); // XXX bug 232556 - pages with no title never get urlChanged() + + if (ok) { + d->status = d->url.isEmpty() ? Null : Ready; + emit loadFinished(); + } else { + d->status = Error; + emit loadFailed(); + } + emit statusChanged(d->status); +} + +/*! + \qmlproperty url WebView::url + This property holds the URL to the page displayed in this item. It can be set, + but also can change spontaneously (eg. because of network redirection). + + If the url is empty, the page is blank. + + The url is always absolute (QML will resolve relative URL strings in the context + of the containing QML document). +*/ +QUrl QDeclarativeWebView::url() const +{ + Q_D(const QDeclarativeWebView); + return d->url; +} + +void QDeclarativeWebView::setUrl(const QUrl &url) +{ + Q_D(QDeclarativeWebView); + if (url == d->url) + return; + + if (isComponentComplete()) { + d->url = url; + page()->setViewportSize(QSize( + d->preferredwidth>0 ? d->preferredwidth : width(), + d->preferredheight>0 ? d->preferredheight : height())); + QUrl seturl = url; + if (seturl.isEmpty()) + seturl = QUrl(QLatin1String("about:blank")); + + Q_ASSERT(!seturl.isRelative()); + + page()->mainFrame()->load(seturl); + + emit urlChanged(); + } else { + d->pending = d->PendingUrl; + d->pending_url = url; + } +} + +/*! + \qmlproperty int WebView::preferredWidth + This property holds the ideal width for displaying the current URL. +*/ +int QDeclarativeWebView::preferredWidth() const +{ + Q_D(const QDeclarativeWebView); + return d->preferredwidth; +} + +void QDeclarativeWebView::setPreferredWidth(int iw) +{ + Q_D(QDeclarativeWebView); + if (d->preferredwidth == iw) return; + d->preferredwidth = iw; + //expandToWebPage(); + emit preferredWidthChanged(); +} + +/*! + \qmlproperty int WebView::preferredHeight + This property holds the ideal height for displaying the current URL. + This only affects the area zoomed by heuristicZoom(). +*/ +int QDeclarativeWebView::preferredHeight() const +{ + Q_D(const QDeclarativeWebView); + return d->preferredheight; +} +void QDeclarativeWebView::setPreferredHeight(int ih) +{ + Q_D(QDeclarativeWebView); + if (d->preferredheight == ih) return; + d->preferredheight = ih; + emit preferredHeightChanged(); +} + +/*! + \qmlmethod bool WebView::evaluateJavaScript(string) + + Evaluates the \a scriptSource JavaScript inside the context of the + main web frame, and returns the result of the last executed statement. + + Note that this JavaScript does \e not have any access to QML objects + except as made available as windowObjects. +*/ +QVariant QDeclarativeWebView::evaluateJavaScript(const QString &scriptSource) +{ + return this->page()->mainFrame()->evaluateJavaScript(scriptSource); +} + +void QDeclarativeWebView::focusChanged(bool hasFocus) +{ + QFocusEvent e(hasFocus ? QEvent::FocusIn : QEvent::FocusOut); + page()->event(&e); + QDeclarativeItem::focusChanged(hasFocus); +} + +void QDeclarativeWebView::initialLayout() +{ + // nothing useful to do at this point +} + +void QDeclarativeWebView::noteContentsSizeChanged(const QSize&) +{ + expandToWebPage(); +} + +void QDeclarativeWebView::expandToWebPage() +{ + Q_D(QDeclarativeWebView); + QSize cs = page()->mainFrame()->contentsSize(); + if (cs.width() < d->preferredwidth) + cs.setWidth(d->preferredwidth); + if (cs.height() < d->preferredheight) + cs.setHeight(d->preferredheight); + if (widthValid()) + cs.setWidth(width()); + if (heightValid()) + cs.setHeight(height()); + if (cs != page()->viewportSize()) { + page()->setViewportSize(cs); + } + if (cs != contentsSize()) + setContentsSize(cs); +} + +void QDeclarativeWebView::geometryChanged(const QRectF &newGeometry, + const QRectF &oldGeometry) +{ + if (newGeometry.size() != oldGeometry.size()) + expandToWebPage(); + QDeclarativePaintedItem::geometryChanged(newGeometry, oldGeometry); +} + +void QDeclarativeWebView::paintPage(const QRect& r) +{ + dirtyCache(r); + update(); +} + +/*! + \qmlproperty list WebView::javaScriptWindowObjects + + This property is a list of object that are available from within + the webview's JavaScript context. + + The \a object will be inserted as a child of the frame's window + object, under the name given by the attached property \c WebView.windowObjectName. + + \qml + WebView { + javaScriptWindowObjects: Object { + WebView.windowObjectName: "coordinates" + } + } + \endqml + + Properties of the object will be exposed as JavaScript properties and slots as + JavaScript methods. + + If Javascript is not enabled for this page, then this property does nothing. +*/ +QDeclarativeListProperty QDeclarativeWebView::javaScriptWindowObjects() +{ + Q_D(QDeclarativeWebView); + return QDeclarativeListProperty(this, d, &QDeclarativeWebViewPrivate::windowObjects_append); +} + +QDeclarativeWebViewAttached *QDeclarativeWebView::qmlAttachedProperties(QObject *o) +{ + return new QDeclarativeWebViewAttached(o); +} + +void QDeclarativeWebViewPrivate::updateWindowObjects() +{ + Q_Q(QDeclarativeWebView); + if (!q->isComponentComplete() || !page) + return; + + for (int ii = 0; ii < windowObjects.count(); ++ii) { + QObject *object = windowObjects.at(ii); + QDeclarativeWebViewAttached *attached = static_cast(qmlAttachedPropertiesObject(object)); + if (attached && !attached->windowObjectName().isEmpty()) { + page->mainFrame()->addToJavaScriptWindowObject(attached->windowObjectName(), object); + } + } +} + +bool QDeclarativeWebView::renderingEnabled() const +{ + Q_D(const QDeclarativeWebView); + return d->rendering; +} + +void QDeclarativeWebView::setRenderingEnabled(bool enabled) +{ + Q_D(QDeclarativeWebView); + if (d->rendering == enabled) + return; + d->rendering = enabled; + emit renderingEnabledChanged(); + + setCacheFrozen(!enabled); + if (enabled) + clearCache(); +} + + +void QDeclarativeWebView::drawContents(QPainter *p, const QRect &r) +{ + Q_D(QDeclarativeWebView); + if (d->rendering) + page()->mainFrame()->render(p,r); +} + +QMouseEvent *QDeclarativeWebView::sceneMouseEventToMouseEvent(QGraphicsSceneMouseEvent *e) +{ + QEvent::Type t; + switch(e->type()) { + default: + case QEvent::GraphicsSceneMousePress: + t = QEvent::MouseButtonPress; + break; + case QEvent::GraphicsSceneMouseRelease: + t = QEvent::MouseButtonRelease; + break; + case QEvent::GraphicsSceneMouseMove: + t = QEvent::MouseMove; + break; + case QGraphicsSceneEvent::GraphicsSceneMouseDoubleClick: + t = QEvent::MouseButtonDblClick; + break; + } + + QMouseEvent *me = new QMouseEvent(t, (e->pos()/contentsScale()).toPoint(), e->button(), e->buttons(), 0); + return me; +} + +QMouseEvent *QDeclarativeWebView::sceneHoverMoveEventToMouseEvent(QGraphicsSceneHoverEvent *e) +{ + QEvent::Type t = QEvent::MouseMove; + + QMouseEvent *me = new QMouseEvent(t, (e->pos()/contentsScale()).toPoint(), Qt::NoButton, Qt::NoButton, 0); + + return me; +} + + +/*! + \qmlsignal WebView::onDoubleClick(clickx,clicky) + + The WebView does not pass double-click events to the web engine, but rather + emits this signals. +*/ + +void QDeclarativeWebView::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) +{ + QMouseEvent *me = sceneMouseEventToMouseEvent(event); + emit doubleClick(me->x(),me->y()); + delete me; +} + +/*! + \qmlmethod bool WebView::heuristicZoom(clickX,clickY,maxzoom) + + Finds a zoom that: + \list + \i shows a whole item + \i includes (\a clickX, \a clickY) + \i fits into the preferredWidth and preferredHeight + \i zooms by no more than \a maxzoom + \i is more than 10% above the current zoom + \endlist + + If such a zoom exists, emits zoomTo(zoom,centerX,centerY) and returns true; otherwise, + no signal is emitted and returns false. +*/ +bool QDeclarativeWebView::heuristicZoom(int clickX, int clickY, qreal maxzoom) +{ + Q_D(QDeclarativeWebView); + if (contentsScale() >= maxzoom/zoomFactor()) + return false; + qreal ozf = contentsScale(); + QRect showarea = elementAreaAt(clickX, clickY, d->preferredwidth/maxzoom, d->preferredheight/maxzoom); + qreal z = qMin(qreal(d->preferredwidth)/showarea.width(),qreal(d->preferredheight)/showarea.height()); + if (z > maxzoom/zoomFactor()) + z = maxzoom/zoomFactor(); + if (z/ozf > 1.2) { + QRectF r(showarea.left()*z, showarea.top()*z, showarea.width()*z, showarea.height()*z); + emit zoomTo(z,r.x()+r.width()/2, r.y()+r.height()/2); + return true; + } else { + return false; + } +} + +/*! + \qmlproperty int WebView::pressGrabTime + + The number of milliseconds the user must press before the WebView + starts passing move events through to the web engine (rather than + letting other QML elements such as a Flickable take them). + + Defaults to 400ms. Set to 0 to always grab and pass move events to + the web engine. +*/ +int QDeclarativeWebView::pressGrabTime() const +{ + Q_D(const QDeclarativeWebView); + return d->pressTime; +} + +void QDeclarativeWebView::setPressGrabTime(int ms) +{ + Q_D(QDeclarativeWebView); + if (d->pressTime == ms) + return; + d->pressTime = ms; + emit pressGrabTimeChanged(); +} + +void QDeclarativeWebView::mousePressEvent(QGraphicsSceneMouseEvent *event) +{ + Q_D(QDeclarativeWebView); + + setFocus (true); + QMouseEvent *me = sceneMouseEventToMouseEvent(event); + + d->pressPoint = me->pos(); + if (d->pressTime) { + d->pressTimer.start(d->pressTime,this); + setKeepMouseGrab(false); + } else { + grabMouse(); + setKeepMouseGrab(true); + } + + page()->event(me); + event->setAccepted( +/* + It is not correct to send the press event upwards, if it is not accepted by WebKit + e.g. push button does not work, if done so as QGraphicsScene will not send the release event at all to WebKit + Might be a bug in WebKit, though + */ +#if 1 //QT_VERSION <= 0x040500 // XXX see bug 230835 + true +#else + me->isAccepted() +#endif + ); + delete me; + if (!event->isAccepted()) { + QDeclarativePaintedItem::mousePressEvent(event); + } +} + +void QDeclarativeWebView::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +{ + Q_D(QDeclarativeWebView); + + QMouseEvent *me = sceneMouseEventToMouseEvent(event); + page()->event(me); + d->pressTimer.stop(); + event->setAccepted( +/* + It is not correct to send the press event upwards, if it is not accepted by WebKit + e.g. push button does not work, if done so as QGraphicsScene will not send all the events to WebKit + */ +#if 1 //QT_VERSION <= 0x040500 // XXX see bug 230835 + true +#else + me->isAccepted() +#endif + ); + delete me; + if (!event->isAccepted()) { + QDeclarativePaintedItem::mouseReleaseEvent(event); + } + setKeepMouseGrab(false); + ungrabMouse(); +} + +void QDeclarativeWebView::timerEvent(QTimerEvent *event) +{ + Q_D(QDeclarativeWebView); + if (event->timerId() == d->pressTimer.timerId()) { + d->pressTimer.stop(); + grabMouse(); + setKeepMouseGrab(true); + } +} + +void QDeclarativeWebView::mouseMoveEvent(QGraphicsSceneMouseEvent *event) +{ + Q_D(QDeclarativeWebView); + + QMouseEvent *me = sceneMouseEventToMouseEvent(event); + if (d->pressTimer.isActive()) { + if ((me->pos() - d->pressPoint).manhattanLength() > QApplication::startDragDistance()) { + d->pressTimer.stop(); + } + } + if (keepMouseGrab()) { + page()->event(me); + event->setAccepted( +/* + It is not correct to send the press event upwards, if it is not accepted by WebKit + e.g. push button does not work, if done so as QGraphicsScene will not send the release event at all to WebKit + Might be a bug in WebKit, though + */ +#if 1 // QT_VERSION <= 0x040500 // XXX see bug 230835 + true +#else + me->isAccepted() +#endif + ); + } + delete me; + if (!event->isAccepted()) + QDeclarativePaintedItem::mouseMoveEvent(event); + +} +void QDeclarativeWebView::hoverMoveEvent (QGraphicsSceneHoverEvent * event) +{ + QMouseEvent *me = sceneHoverMoveEventToMouseEvent(event); + page()->event(me); + event->setAccepted( +#if QT_VERSION <= 0x040500 // XXX see bug 230835 + true +#else + me->isAccepted() +#endif + ); + delete me; + if (!event->isAccepted()) + QDeclarativePaintedItem::hoverMoveEvent(event); +} + +void QDeclarativeWebView::keyPressEvent(QKeyEvent* event) +{ + page()->event(event); + if (!event->isAccepted()) + QDeclarativePaintedItem::keyPressEvent(event); +} + +void QDeclarativeWebView::keyReleaseEvent(QKeyEvent* event) +{ + page()->event(event); + if (!event->isAccepted()) + QDeclarativePaintedItem::keyReleaseEvent(event); +} + +bool QDeclarativeWebView::sceneEvent(QEvent *event) +{ + if (event->type() == QEvent::KeyPress) { + QKeyEvent *k = static_cast(event); + if (k->key() == Qt::Key_Tab || k->key() == Qt::Key_Backtab) { + if (!(k->modifiers() & (Qt::ControlModifier | Qt::AltModifier))) { //### Add MetaModifier? + page()->event(event); + if (event->isAccepted()) + return true; + } + } + } + return QDeclarativePaintedItem::sceneEvent(event); +} + + +/*! + \qmlproperty action WebView::back + This property holds the action for causing the previous URL in the history to be displayed. +*/ +QAction *QDeclarativeWebView::backAction() const +{ + return page()->action(QWebPage::Back); +} + +/*! + \qmlproperty action WebView::forward + This property holds the action for causing the next URL in the history to be displayed. +*/ +QAction *QDeclarativeWebView::forwardAction() const +{ + return page()->action(QWebPage::Forward); +} + +/*! + \qmlproperty action WebView::reload + This property holds the action for reloading with the current URL +*/ +QAction *QDeclarativeWebView::reloadAction() const +{ + return page()->action(QWebPage::Reload); +} + +/*! + \qmlproperty action WebView::stop + This property holds the action for stopping loading with the current URL +*/ +QAction *QDeclarativeWebView::stopAction() const +{ + return page()->action(QWebPage::Stop); +} + +/*! + \qmlproperty real WebView::title + This property holds the title of the web page currently viewed + + By default, this property contains an empty string. +*/ +QString QDeclarativeWebView::title() const +{ + return page()->mainFrame()->title(); +} + + + +/*! + \qmlproperty pixmap WebView::icon + This property holds the icon associated with the web page currently viewed +*/ +QPixmap QDeclarativeWebView::icon() const +{ + return page()->mainFrame()->icon().pixmap(QSize(256,256)); +} + + +/*! + \qmlproperty real WebView::zoomFactor + This property holds the multiplier used to scale the contents of a Web page. +*/ +void QDeclarativeWebView::setZoomFactor(qreal factor) +{ + Q_D(QDeclarativeWebView); + if (factor == page()->mainFrame()->zoomFactor()) + return; + + page()->mainFrame()->setZoomFactor(factor); + page()->setViewportSize(QSize( + d->preferredwidth>0 ? d->preferredwidth*factor : width()*factor, + d->preferredheight>0 ? d->preferredheight*factor : height()*factor)); + expandToWebPage(); + + emit zoomFactorChanged(); +} + +qreal QDeclarativeWebView::zoomFactor() const +{ + return page()->mainFrame()->zoomFactor(); +} + +/*! + \qmlproperty string WebView::statusText + + This property is the current status suggested by the current web page. In a web browser, + such status is often shown in some kind of status bar. +*/ +void QDeclarativeWebView::setStatusText(const QString& s) +{ + Q_D(QDeclarativeWebView); + d->statusText = s; + emit statusTextChanged(); +} + +void QDeclarativeWebView::windowObjectCleared() +{ + Q_D(QDeclarativeWebView); + d->updateWindowObjects(); +} + +QString QDeclarativeWebView::statusText() const +{ + Q_D(const QDeclarativeWebView); + return d->statusText; +} + +QWebPage *QDeclarativeWebView::page() const +{ + Q_D(const QDeclarativeWebView); + + if (!d->page) { + QDeclarativeWebView *self = const_cast(this); + QWebPage *wp = new QDeclarativeWebPage(self); + + // QML items don't default to having a background, + // even though most we pages will set one anyway. + QPalette pal = QApplication::palette(); + pal.setBrush(QPalette::Base, QColor::fromRgbF(0, 0, 0, 0)); + wp->setPalette(pal); + + wp->setNetworkAccessManager(qmlEngine(this)->networkAccessManager()); + + self->setPage(wp); + + return wp; + } + + return d->page; +} + + +// The QObject interface to settings(). +/*! + \qmlproperty string WebView::settings.standardFontFamily + \qmlproperty string WebView::settings.fixedFontFamily + \qmlproperty string WebView::settings.serifFontFamily + \qmlproperty string WebView::settings.sansSerifFontFamily + \qmlproperty string WebView::settings.cursiveFontFamily + \qmlproperty string WebView::settings.fantasyFontFamily + + \qmlproperty int WebView::settings.minimumFontSize + \qmlproperty int WebView::settings.minimumLogicalFontSize + \qmlproperty int WebView::settings.defaultFontSize + \qmlproperty int WebView::settings.defaultFixedFontSize + + \qmlproperty bool WebView::settings.autoLoadImages + \qmlproperty bool WebView::settings.javascriptEnabled + \qmlproperty bool WebView::settings.javaEnabled + \qmlproperty bool WebView::settings.pluginsEnabled + \qmlproperty bool WebView::settings.privateBrowsingEnabled + \qmlproperty bool WebView::settings.javascriptCanOpenWindows + \qmlproperty bool WebView::settings.javascriptCanAccessClipboard + \qmlproperty bool WebView::settings.developerExtrasEnabled + \qmlproperty bool WebView::settings.linksIncludedInFocusChain + \qmlproperty bool WebView::settings.zoomTextOnly + \qmlproperty bool WebView::settings.printElementBackgrounds + \qmlproperty bool WebView::settings.offlineStorageDatabaseEnabled + \qmlproperty bool WebView::settings.offlineWebApplicationCacheEnabled + \qmlproperty bool WebView::settings.localStorageDatabaseEnabled + \qmlproperty bool WebView::settings.localContentCanAccessRemoteUrls + + These properties give access to the settings controlling the web view. + + See QWebSettings for details of these properties. + + \qml + WebView { + settings.pluginsEnabled: true + settings.standardFontFamily: "Arial" + ... + } + \endqml +*/ +QObject *QDeclarativeWebView::settingsObject() const +{ + Q_D(const QDeclarativeWebView); + d->settings.s = page()->settings(); + return &d->settings; +} + +void QDeclarativeWebView::setPage(QWebPage *page) +{ + Q_D(QDeclarativeWebView); + if (d->page == page) + return; + if (d->page) { + if (d->page->parent() == this) { + delete d->page; + } else { + d->page->disconnect(this); + } + } + d->page = page; + d->page->setViewportSize(QSize( + d->preferredwidth>0 ? d->preferredwidth : width(), + d->preferredheight>0 ? d->preferredheight : height())); + d->page->mainFrame()->setScrollBarPolicy(Qt::Horizontal,Qt::ScrollBarAlwaysOff); + d->page->mainFrame()->setScrollBarPolicy(Qt::Vertical,Qt::ScrollBarAlwaysOff); + connect(d->page,SIGNAL(repaintRequested(QRect)),this,SLOT(paintPage(QRect))); + connect(d->page->mainFrame(),SIGNAL(urlChanged(QUrl)),this,SLOT(pageUrlChanged())); + connect(d->page->mainFrame(), SIGNAL(titleChanged(QString)), this, SIGNAL(titleChanged(QString))); + connect(d->page->mainFrame(), SIGNAL(titleChanged(QString)), this, SIGNAL(iconChanged())); + connect(d->page->mainFrame(), SIGNAL(iconChanged()), this, SIGNAL(iconChanged())); + connect(d->page->mainFrame(), SIGNAL(contentsSizeChanged(QSize)), this, SLOT(noteContentsSizeChanged(QSize))); + connect(d->page->mainFrame(), SIGNAL(initialLayoutCompleted()), this, SLOT(initialLayout())); + + connect(d->page,SIGNAL(loadStarted()),this,SLOT(doLoadStarted())); + connect(d->page,SIGNAL(loadProgress(int)),this,SLOT(doLoadProgress(int))); + connect(d->page,SIGNAL(loadFinished(bool)),this,SLOT(doLoadFinished(bool))); + connect(d->page,SIGNAL(statusBarMessage(QString)),this,SLOT(setStatusText(QString))); + + connect(d->page->mainFrame(),SIGNAL(javaScriptWindowObjectCleared()),this,SLOT(windowObjectCleared())); +} + +/*! + \qmlsignal WebView::onLoadStarted() + + This handler is called when the web engine begins loading + a page. Later, WebView::onLoadFinished() or WebView::onLoadFailed() + will be emitted. +*/ + +/*! + \qmlsignal WebView::onLoadFinished() + + This handler is called when the web engine \e successfully + finishes loading a page, including any component content + (WebView::onLoadFailed() will be emitted otherwise). + + \sa progress +*/ + +/*! + \qmlsignal WebView::onLoadFailed() + + This handler is called when the web engine fails loading + a page or any component content + (WebView::onLoadFinished() will be emitted on success). +*/ + +void QDeclarativeWebView::load(const QNetworkRequest &request, + QNetworkAccessManager::Operation operation, + const QByteArray &body) +{ + page()->mainFrame()->load(request, operation, body); +} + +QString QDeclarativeWebView::html() const +{ + return page()->mainFrame()->toHtml(); +} + +/*! + \qmlproperty string WebView::html + This property holds HTML text set directly + + The html property can be set as a string. + + \qml + WebView { + html: "

This is HTML." + } + \endqml +*/ +void QDeclarativeWebView::setHtml(const QString &html, const QUrl &baseUrl) +{ + Q_D(QDeclarativeWebView); + page()->setViewportSize(QSize( + d->preferredwidth>0 ? d->preferredwidth : width(), + d->preferredheight>0 ? d->preferredheight : height())); + if (isComponentComplete()) + page()->mainFrame()->setHtml(html, baseUrl); + else { + d->pending = d->PendingHtml; + d->pending_url = baseUrl; + d->pending_string = html; + } + emit htmlChanged(); +} + +void QDeclarativeWebView::setContent(const QByteArray &data, const QString &mimeType, const QUrl &baseUrl) +{ + Q_D(QDeclarativeWebView); + page()->setViewportSize(QSize( + d->preferredwidth>0 ? d->preferredwidth : width(), + d->preferredheight>0 ? d->preferredheight : height())); + + if (isComponentComplete()) + page()->mainFrame()->setContent(data,mimeType,qmlContext(this)->resolvedUrl(baseUrl)); + else { + d->pending = d->PendingContent; + d->pending_url = baseUrl; + d->pending_string = mimeType; + d->pending_data = data; + } +} + +QWebHistory *QDeclarativeWebView::history() const +{ + return page()->history(); +} + +QWebSettings *QDeclarativeWebView::settings() const +{ + return page()->settings(); +} + +QDeclarativeWebView *QDeclarativeWebView::createWindow(QWebPage::WebWindowType type) +{ + Q_D(QDeclarativeWebView); + switch (type) { + case QWebPage::WebBrowserWindow: { + if (!d->newWindowComponent && d->newWindowParent) + qWarning("WebView::newWindowComponent not set - WebView::newWindowParent ignored"); + else if (d->newWindowComponent && !d->newWindowParent) + qWarning("WebView::newWindowParent not set - WebView::newWindowComponent ignored"); + else if (d->newWindowComponent && d->newWindowParent) { + QDeclarativeWebView *webview = 0; + QDeclarativeContext *windowContext = new QDeclarativeContext(qmlContext(this)); + + QObject *nobj = d->newWindowComponent->create(windowContext); + if (nobj) { + windowContext->setParent(nobj); + QDeclarativeItem *item = qobject_cast(nobj); + if (!item) { + delete nobj; + } else { + webview = item->findChild(); + if (!webview) { + delete item; + } else { + nobj->setParent(d->newWindowParent); + static_cast(item)->setParentItem(d->newWindowParent); + } + } + } else { + delete windowContext; + } + + return webview; + } + } + break; + case QWebPage::WebModalDialog: { + // Not supported + } + } + return 0; +} + +/*! + \qmlproperty component WebView::newWindowComponent + + This property holds the component to use for new windows. + The component must have a WebView somewhere in its structure. + + When the web engine requests a new window, it will be an instance of + this component. + + The parent of the new window is set by newWindowParent. It must be set. +*/ +QDeclarativeComponent *QDeclarativeWebView::newWindowComponent() const +{ + Q_D(const QDeclarativeWebView); + return d->newWindowComponent; +} + +void QDeclarativeWebView::setNewWindowComponent(QDeclarativeComponent *newWindow) +{ + Q_D(QDeclarativeWebView); + if (newWindow == d->newWindowComponent) + return; + d->newWindowComponent = newWindow; + emit newWindowComponentChanged(); +} + + +/*! + \qmlproperty item WebView::newWindowParent + + The parent item for new windows. + + \sa newWindowComponent +*/ +QDeclarativeItem *QDeclarativeWebView::newWindowParent() const +{ + Q_D(const QDeclarativeWebView); + return d->newWindowParent; +} + +void QDeclarativeWebView::setNewWindowParent(QDeclarativeItem *parent) +{ + Q_D(QDeclarativeWebView); + if (parent == d->newWindowParent) + return; + if (d->newWindowParent && parent) { + QList children = d->newWindowParent->childItems(); + for (int i = 0; i < children.count(); ++i) { + children.at(i)->setParentItem(parent); + } + } + d->newWindowParent = parent; + emit newWindowParentChanged(); +} + +/*! + Returns the area of the largest element at position (\a x,\a y) that is no larger + than \a maxwidth by \a maxheight pixels. + + May return an area larger in the case when no smaller element is at the position. +*/ +QRect QDeclarativeWebView::elementAreaAt(int x, int y, int maxwidth, int maxheight) const +{ + QWebHitTestResult hit = page()->mainFrame()->hitTestContent(QPoint(x,y)); + QRect rv = hit.boundingRect(); + QWebElement element = hit.enclosingBlockElement(); + if (maxwidth<=0) maxwidth = INT_MAX; + if (maxheight<=0) maxheight = INT_MAX; + while (!element.parent().isNull() && element.geometry().width() <= maxwidth && element.geometry().height() <= maxheight) { + rv = element.geometry(); + element = element.parent(); + } + return rv; +} + +/*! + \internal + \class QDeclarativeWebPage + \brief The QDeclarativeWebPage class is a QWebPage that can create QML plugins. + + \sa QDeclarativeWebView +*/ +QDeclarativeWebPage::QDeclarativeWebPage(QDeclarativeWebView *parent) : + QWebPage(parent) +{ +} + +QDeclarativeWebPage::~QDeclarativeWebPage() +{ +} + +void QDeclarativeWebPage::javaScriptConsoleMessage(const QString& message, int lineNumber, const QString& sourceID) +{ + qWarning() << sourceID << ':' << lineNumber << ':' << message; +} + +QString QDeclarativeWebPage::chooseFile(QWebFrame *originatingFrame, const QString& oldFile) +{ + // Not supported (it's modal) + Q_UNUSED(originatingFrame) + Q_UNUSED(oldFile) + return oldFile; +} + +void QDeclarativeWebPage::javaScriptAlert(QWebFrame *originatingFrame, const QString& msg) +{ + Q_UNUSED(originatingFrame) + emit viewItem()->alert(msg); +} + +bool QDeclarativeWebPage::javaScriptConfirm(QWebFrame *originatingFrame, const QString& msg) +{ + // Not supported (it's modal) + Q_UNUSED(originatingFrame) + Q_UNUSED(msg) + return false; +} + +bool QDeclarativeWebPage::javaScriptPrompt(QWebFrame *originatingFrame, const QString& msg, const QString& defaultValue, QString* result) +{ + // Not supported (it's modal) + Q_UNUSED(originatingFrame) + Q_UNUSED(msg) + Q_UNUSED(defaultValue) + Q_UNUSED(result) + return false; +} + + +/* + Qt WebKit does not understand non-QWidget plugins, so dummy widgets + are created, parented to a single dummy tool window. + + The requirements for QML object plugins are input to the Qt WebKit + non-QWidget plugin support, which will obsolete this kludge. +*/ +class QWidget_Dummy_Plugin : public QWidget +{ + Q_OBJECT +public: + static QWidget *dummy_shared_parent() + { + static QWidget *dsp = 0; + if (!dsp) { + dsp = new QWidget(0,Qt::Tool); + dsp->setGeometry(-10000,-10000,0,0); + dsp->show(); + } + return dsp; + } + QWidget_Dummy_Plugin(const QUrl& url, QDeclarativeWebView *view, const QStringList ¶mNames, const QStringList ¶mValues) : + QWidget(dummy_shared_parent()), + propertyNames(paramNames), + propertyValues(paramValues), + webview(view) + { + QDeclarativeEngine *engine = qmlEngine(webview); + component = new QDeclarativeComponent(engine, url, this); + item = 0; + if (component->isLoading()) + connect(component, SIGNAL(statusChanged(QDeclarativeComponent::Status)), this, SLOT(qmlLoaded())); + else + qmlLoaded(); + } + +public Q_SLOTS: + void qmlLoaded() + { + if (component->isError()) { + // ### Could instead give these errors to the WebView to handle. + qWarning() << component->errors(); + return; + } + item = qobject_cast(component->create(qmlContext(webview))); + item->setParent(webview); + QString jsObjName; + for (int i=0; isetProperty(propertyNames[i].toUtf8(),propertyValues[i]); + if (propertyNames[i] == QLatin1String("objectname")) + jsObjName = propertyValues[i]; + } + } + if (!jsObjName.isNull()) { + QWebFrame *f = webview->page()->mainFrame(); + f->addToJavaScriptWindowObject(jsObjName, item); + } + resizeEvent(0); + delete component; + component = 0; + } + void resizeEvent(QResizeEvent*) + { + if (item) { + item->setX(x()); + item->setY(y()); + item->setWidth(width()); + item->setHeight(height()); + } + } + +private: + QDeclarativeComponent *component; + QDeclarativeItem *item; + QStringList propertyNames, propertyValues; + QDeclarativeWebView *webview; +}; + +QDeclarativeWebView *QDeclarativeWebPage::viewItem() +{ + return static_cast(parent()); +} + +QObject *QDeclarativeWebPage::createPlugin(const QString &, const QUrl &url, const QStringList ¶mNames, const QStringList ¶mValues) +{ + QUrl comp = qmlContext(viewItem())->resolvedUrl(url); + return new QWidget_Dummy_Plugin(comp,viewItem(),paramNames,paramValues); +} + +QWebPage *QDeclarativeWebPage::createWindow(WebWindowType type) +{ + QDeclarativeWebView *newView = viewItem()->createWindow(type); + if (newView) + return newView->page(); + return 0; +} + +QT_END_NAMESPACE + +#include diff --git a/src/plugins/qdeclarativemodules/webkitqmlplugin/qdeclarativewebview_p.h b/src/plugins/qdeclarativemodules/webkitqmlplugin/qdeclarativewebview_p.h new file mode 100644 index 0000000..0bb5d29 --- /dev/null +++ b/src/plugins/qdeclarativemodules/webkitqmlplugin/qdeclarativewebview_p.h @@ -0,0 +1,285 @@ +/**************************************************************************** +** +** 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 QDECLARATIVEWEBVIEW_H +#define QDECLARATIVEWEBVIEW_H + +#include + +#include +#include +#include +#include + +QT_BEGIN_HEADER + +class QWebHistory; +class QWebSettings; + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) +class QDeclarativeWebViewPrivate; +class QNetworkRequest; +class QDeclarativeWebView; + +class Q_DECLARATIVE_EXPORT QDeclarativeWebPage : public QWebPage +{ + Q_OBJECT +public: + explicit QDeclarativeWebPage(QDeclarativeWebView *parent); + ~QDeclarativeWebPage(); +protected: + QObject *createPlugin(const QString &classid, const QUrl &url, const QStringList ¶mNames, const QStringList ¶mValues); + QWebPage *createWindow(WebWindowType type); + void javaScriptConsoleMessage(const QString& message, int lineNumber, const QString& sourceID); + QString chooseFile(QWebFrame *originatingFrame, const QString& oldFile); + void javaScriptAlert(QWebFrame *originatingFrame, const QString& msg); + bool javaScriptConfirm(QWebFrame *originatingFrame, const QString& msg); + bool javaScriptPrompt(QWebFrame *originatingFrame, const QString& msg, const QString& defaultValue, QString* result); + +private: + QDeclarativeWebView *viewItem(); +}; + + +class QDeclarativeWebViewAttached; + +//### TODO: browser plugins + +class Q_DECLARATIVE_EXPORT QDeclarativeWebView : public QDeclarativePaintedItem +{ + Q_OBJECT + + Q_ENUMS(Status SelectionMode) + + Q_PROPERTY(QString title READ title NOTIFY titleChanged) + Q_PROPERTY(QPixmap icon READ icon NOTIFY iconChanged) + Q_PROPERTY(qreal zoomFactor READ zoomFactor WRITE setZoomFactor NOTIFY zoomFactorChanged) + Q_PROPERTY(QString statusText READ statusText NOTIFY statusTextChanged) + + Q_PROPERTY(QString html READ html WRITE setHtml NOTIFY htmlChanged) + + Q_PROPERTY(int pressGrabTime READ pressGrabTime WRITE setPressGrabTime NOTIFY pressGrabTimeChanged) + + Q_PROPERTY(int preferredWidth READ preferredWidth WRITE setPreferredWidth NOTIFY preferredWidthChanged) + Q_PROPERTY(int preferredHeight READ preferredHeight WRITE setPreferredHeight NOTIFY preferredHeightChanged) + Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY urlChanged) + Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged) + Q_PROPERTY(Status status READ status NOTIFY statusChanged) + + Q_PROPERTY(QAction* reload READ reloadAction CONSTANT) + Q_PROPERTY(QAction* back READ backAction CONSTANT) + Q_PROPERTY(QAction* forward READ forwardAction CONSTANT) + Q_PROPERTY(QAction* stop READ stopAction CONSTANT) + + Q_PROPERTY(QObject* settings READ settingsObject CONSTANT) + + Q_PROPERTY(QDeclarativeListProperty javaScriptWindowObjects READ javaScriptWindowObjects CONSTANT) + + Q_PROPERTY(QDeclarativeComponent* newWindowComponent READ newWindowComponent WRITE setNewWindowComponent NOTIFY newWindowComponentChanged) + Q_PROPERTY(QDeclarativeItem* newWindowParent READ newWindowParent WRITE setNewWindowParent NOTIFY newWindowParentChanged) + + Q_PROPERTY(bool renderingEnabled READ renderingEnabled WRITE setRenderingEnabled NOTIFY renderingEnabledChanged) + +public: + QDeclarativeWebView(QDeclarativeItem *parent=0); + ~QDeclarativeWebView(); + + QUrl url() const; + void setUrl(const QUrl &); + + QString title() const; + + QPixmap icon() const; + + qreal zoomFactor() const; + void setZoomFactor(qreal); + Q_INVOKABLE bool heuristicZoom(int clickX, int clickY, qreal maxzoom); + QRect elementAreaAt(int x, int y, int minwidth, int minheight) const; + + int pressGrabTime() const; + void setPressGrabTime(int); + + int preferredWidth() const; + void setPreferredWidth(int); + int preferredHeight() const; + void setPreferredHeight(int); + + enum Status { Null, Ready, Loading, Error }; + Status status() const; + qreal progress() const; + QString statusText() const; + + QAction *reloadAction() const; + QAction *backAction() const; + QAction *forwardAction() const; + QAction *stopAction() const; + + QWebPage *page() const; + void setPage(QWebPage *page); + + void load(const QNetworkRequest &request, + QNetworkAccessManager::Operation operation = QNetworkAccessManager::GetOperation, + const QByteArray &body = QByteArray()); + + QString html() const; + + void setHtml(const QString &html, const QUrl &baseUrl = QUrl()); + void setContent(const QByteArray &data, const QString &mimeType = QString(), const QUrl &baseUrl = QUrl()); + + QWebHistory *history() const; + QWebSettings *settings() const; + QObject *settingsObject() const; + + bool renderingEnabled() const; + void setRenderingEnabled(bool); + + QDeclarativeListProperty javaScriptWindowObjects(); + + static QDeclarativeWebViewAttached *qmlAttachedProperties(QObject *); + + QDeclarativeComponent *newWindowComponent() const; + void setNewWindowComponent(QDeclarativeComponent *newWindow); + QDeclarativeItem *newWindowParent() const; + void setNewWindowParent(QDeclarativeItem *newWindow); + +Q_SIGNALS: + void preferredWidthChanged(); + void preferredHeightChanged(); + void urlChanged(); + void progressChanged(); + void statusChanged(Status); + void titleChanged(const QString&); + void iconChanged(); + void statusTextChanged(); + void htmlChanged(); + void pressGrabTimeChanged(); + void zoomFactorChanged(); + void newWindowComponentChanged(); + void newWindowParentChanged(); + void renderingEnabledChanged(); + + void loadStarted(); + void loadFinished(); + void loadFailed(); + + void doubleClick(int clickX, int clickY); + + void zoomTo(qreal zoom, int centerX, int centerY); + + void alert(const QString& message); + +public Q_SLOTS: + QVariant evaluateJavaScript(const QString&); + +private Q_SLOTS: + void expandToWebPage(); + void paintPage(const QRect&); + void doLoadStarted(); + void doLoadProgress(int p); + void doLoadFinished(bool ok); + void setStatusText(const QString&); + void windowObjectCleared(); + void pageUrlChanged(); + void noteContentsSizeChanged(const QSize&); + void initialLayout(); + +protected: + void drawContents(QPainter *, const QRect &); + + void mousePressEvent(QGraphicsSceneMouseEvent *event); + void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); + void mouseMoveEvent(QGraphicsSceneMouseEvent *event); + void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); + void timerEvent(QTimerEvent *event); + void hoverMoveEvent (QGraphicsSceneHoverEvent * event); + void keyPressEvent(QKeyEvent* event); + void keyReleaseEvent(QKeyEvent* event); + virtual void geometryChanged(const QRectF &newGeometry, + const QRectF &oldGeometry); + virtual void focusChanged(bool); + virtual bool sceneEvent(QEvent *event); + QDeclarativeWebView *createWindow(QWebPage::WebWindowType type); + +private: + void init(); + virtual void componentComplete(); + Q_DISABLE_COPY(QDeclarativeWebView) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarativeWebView) + QMouseEvent *sceneMouseEventToMouseEvent(QGraphicsSceneMouseEvent *); + QMouseEvent *sceneHoverMoveEventToMouseEvent(QGraphicsSceneHoverEvent *); + friend class QDeclarativeWebPage; +}; + +class QDeclarativeWebViewAttached : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString windowObjectName READ windowObjectName WRITE setWindowObjectName) +public: + QDeclarativeWebViewAttached(QObject *parent) + : QObject(parent) + { + } + + QString windowObjectName() const + { + return m_windowObjectName; + } + + void setWindowObjectName(const QString &n) + { + m_windowObjectName = n; + } + +private: + QString m_windowObjectName; +}; + + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QDeclarativeWebView) +QML_DECLARE_TYPEINFO(QDeclarativeWebView, QML_HAS_ATTACHED_PROPERTIES) + +QT_END_HEADER + +#endif diff --git a/src/plugins/qdeclarativemodules/webkitqmlplugin/qdeclarativewebview_p_p.h b/src/plugins/qdeclarativemodules/webkitqmlplugin/qdeclarativewebview_p_p.h new file mode 100644 index 0000000..258b472 --- /dev/null +++ b/src/plugins/qdeclarativemodules/webkitqmlplugin/qdeclarativewebview_p_p.h @@ -0,0 +1,151 @@ +/**************************************************************************** +** +** 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 QDECLARATIVEWEBVIEW_P_H +#define QDECLARATIVEWEBVIEW_P_H + +#include + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QDeclarativeWebSettings : public QObject { + Q_OBJECT + + Q_PROPERTY(QString standardFontFamily READ standardFontFamily WRITE setStandardFontFamily) + Q_PROPERTY(QString fixedFontFamily READ fixedFontFamily WRITE setFixedFontFamily) + Q_PROPERTY(QString serifFontFamily READ serifFontFamily WRITE setSerifFontFamily) + Q_PROPERTY(QString sansSerifFontFamily READ sansSerifFontFamily WRITE setSansSerifFontFamily) + Q_PROPERTY(QString cursiveFontFamily READ cursiveFontFamily WRITE setCursiveFontFamily) + Q_PROPERTY(QString fantasyFontFamily READ fantasyFontFamily WRITE setFantasyFontFamily) + + Q_PROPERTY(int minimumFontSize READ minimumFontSize WRITE setMinimumFontSize) + Q_PROPERTY(int minimumLogicalFontSize READ minimumLogicalFontSize WRITE setMinimumLogicalFontSize) + Q_PROPERTY(int defaultFontSize READ defaultFontSize WRITE setDefaultFontSize) + Q_PROPERTY(int defaultFixedFontSize READ defaultFixedFontSize WRITE setDefaultFixedFontSize) + + Q_PROPERTY(bool autoLoadImages READ autoLoadImages WRITE setAutoLoadImages) + Q_PROPERTY(bool javascriptEnabled READ javascriptEnabled WRITE setJavascriptEnabled) + Q_PROPERTY(bool javaEnabled READ javaEnabled WRITE setJavaEnabled) + Q_PROPERTY(bool pluginsEnabled READ pluginsEnabled WRITE setPluginsEnabled) + Q_PROPERTY(bool privateBrowsingEnabled READ privateBrowsingEnabled WRITE setPrivateBrowsingEnabled) + Q_PROPERTY(bool javascriptCanOpenWindows READ javascriptCanOpenWindows WRITE setJavascriptCanOpenWindows) + Q_PROPERTY(bool javascriptCanAccessClipboard READ javascriptCanAccessClipboard WRITE setJavascriptCanAccessClipboard) + Q_PROPERTY(bool developerExtrasEnabled READ developerExtrasEnabled WRITE setDeveloperExtrasEnabled) + Q_PROPERTY(bool linksIncludedInFocusChain READ linksIncludedInFocusChain WRITE setLinksIncludedInFocusChain) + Q_PROPERTY(bool zoomTextOnly READ zoomTextOnly WRITE setZoomTextOnly) + Q_PROPERTY(bool printElementBackgrounds READ printElementBackgrounds WRITE setPrintElementBackgrounds) + Q_PROPERTY(bool offlineStorageDatabaseEnabled READ offlineStorageDatabaseEnabled WRITE setOfflineStorageDatabaseEnabled) + Q_PROPERTY(bool offlineWebApplicationCacheEnabled READ offlineWebApplicationCacheEnabled WRITE setOfflineWebApplicationCacheEnabled) + Q_PROPERTY(bool localStorageDatabaseEnabled READ localStorageDatabaseEnabled WRITE setLocalStorageDatabaseEnabled) + Q_PROPERTY(bool localContentCanAccessRemoteUrls READ localContentCanAccessRemoteUrls WRITE setLocalContentCanAccessRemoteUrls) + +public: + QDeclarativeWebSettings() {} + + QString standardFontFamily() const { return s->fontFamily(QWebSettings::StandardFont); } + void setStandardFontFamily(const QString& f) { s->setFontFamily(QWebSettings::StandardFont,f); } + QString fixedFontFamily() const { return s->fontFamily(QWebSettings::FixedFont); } + void setFixedFontFamily(const QString& f) { s->setFontFamily(QWebSettings::FixedFont,f); } + QString serifFontFamily() const { return s->fontFamily(QWebSettings::SerifFont); } + void setSerifFontFamily(const QString& f) { s->setFontFamily(QWebSettings::SerifFont,f); } + QString sansSerifFontFamily() const { return s->fontFamily(QWebSettings::SansSerifFont); } + void setSansSerifFontFamily(const QString& f) { s->setFontFamily(QWebSettings::SansSerifFont,f); } + QString cursiveFontFamily() const { return s->fontFamily(QWebSettings::CursiveFont); } + void setCursiveFontFamily(const QString& f) { s->setFontFamily(QWebSettings::CursiveFont,f); } + QString fantasyFontFamily() const { return s->fontFamily(QWebSettings::FantasyFont); } + void setFantasyFontFamily(const QString& f) { s->setFontFamily(QWebSettings::FantasyFont,f); } + + int minimumFontSize() const { return s->fontSize(QWebSettings::MinimumFontSize); } + void setMinimumFontSize(int size) { s->setFontSize(QWebSettings::MinimumFontSize,size); } + int minimumLogicalFontSize() const { return s->fontSize(QWebSettings::MinimumLogicalFontSize); } + void setMinimumLogicalFontSize(int size) { s->setFontSize(QWebSettings::MinimumLogicalFontSize,size); } + int defaultFontSize() const { return s->fontSize(QWebSettings::DefaultFontSize); } + void setDefaultFontSize(int size) { s->setFontSize(QWebSettings::DefaultFontSize,size); } + int defaultFixedFontSize() const { return s->fontSize(QWebSettings::DefaultFixedFontSize); } + void setDefaultFixedFontSize(int size) { s->setFontSize(QWebSettings::DefaultFixedFontSize,size); } + + bool autoLoadImages() const { return s->testAttribute(QWebSettings::AutoLoadImages); } + void setAutoLoadImages(bool on) { s->setAttribute(QWebSettings::AutoLoadImages, on); } + bool javascriptEnabled() const { return s->testAttribute(QWebSettings::JavascriptEnabled); } + void setJavascriptEnabled(bool on) { s->setAttribute(QWebSettings::JavascriptEnabled, on); } + bool javaEnabled() const { return s->testAttribute(QWebSettings::JavaEnabled); } + void setJavaEnabled(bool on) { s->setAttribute(QWebSettings::JavaEnabled, on); } + bool pluginsEnabled() const { return s->testAttribute(QWebSettings::PluginsEnabled); } + void setPluginsEnabled(bool on) { s->setAttribute(QWebSettings::PluginsEnabled, on); } + bool privateBrowsingEnabled() const { return s->testAttribute(QWebSettings::PrivateBrowsingEnabled); } + void setPrivateBrowsingEnabled(bool on) { s->setAttribute(QWebSettings::PrivateBrowsingEnabled, on); } + bool javascriptCanOpenWindows() const { return s->testAttribute(QWebSettings::JavascriptCanOpenWindows); } + void setJavascriptCanOpenWindows(bool on) { s->setAttribute(QWebSettings::JavascriptCanOpenWindows, on); } + bool javascriptCanAccessClipboard() const { return s->testAttribute(QWebSettings::JavascriptCanAccessClipboard); } + void setJavascriptCanAccessClipboard(bool on) { s->setAttribute(QWebSettings::JavascriptCanAccessClipboard, on); } + bool developerExtrasEnabled() const { return s->testAttribute(QWebSettings::DeveloperExtrasEnabled); } + void setDeveloperExtrasEnabled(bool on) { s->setAttribute(QWebSettings::DeveloperExtrasEnabled, on); } + bool linksIncludedInFocusChain() const { return s->testAttribute(QWebSettings::LinksIncludedInFocusChain); } + void setLinksIncludedInFocusChain(bool on) { s->setAttribute(QWebSettings::LinksIncludedInFocusChain, on); } + bool zoomTextOnly() const { return s->testAttribute(QWebSettings::ZoomTextOnly); } + void setZoomTextOnly(bool on) { s->setAttribute(QWebSettings::ZoomTextOnly, on); } + bool printElementBackgrounds() const { return s->testAttribute(QWebSettings::PrintElementBackgrounds); } + void setPrintElementBackgrounds(bool on) { s->setAttribute(QWebSettings::PrintElementBackgrounds, on); } + bool offlineStorageDatabaseEnabled() const { return s->testAttribute(QWebSettings::OfflineStorageDatabaseEnabled); } + void setOfflineStorageDatabaseEnabled(bool on) { s->setAttribute(QWebSettings::OfflineStorageDatabaseEnabled, on); } + bool offlineWebApplicationCacheEnabled() const { return s->testAttribute(QWebSettings::OfflineWebApplicationCacheEnabled); } + void setOfflineWebApplicationCacheEnabled(bool on) { s->setAttribute(QWebSettings::OfflineWebApplicationCacheEnabled, on); } + bool localStorageDatabaseEnabled() const { return s->testAttribute(QWebSettings::LocalStorageDatabaseEnabled); } + void setLocalStorageDatabaseEnabled(bool on) { s->setAttribute(QWebSettings::LocalStorageDatabaseEnabled, on); } + bool localContentCanAccessRemoteUrls() const { return s->testAttribute(QWebSettings::LocalContentCanAccessRemoteUrls); } + void setLocalContentCanAccessRemoteUrls(bool on) { s->setAttribute(QWebSettings::LocalContentCanAccessRemoteUrls, on); } + + QWebSettings *s; +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QDeclarativeWebSettings) + +QT_END_HEADER + +#endif diff --git a/src/plugins/qdeclarativemodules/webkitqmlplugin/webkitqmlplugin.pro b/src/plugins/qdeclarativemodules/webkitqmlplugin/webkitqmlplugin.pro new file mode 100644 index 0000000..37fe37c --- /dev/null +++ b/src/plugins/qdeclarativemodules/webkitqmlplugin/webkitqmlplugin.pro @@ -0,0 +1,18 @@ +TARGET = webkitqmlplugin +include(../../qpluginbase.pri) + +contains(QT_CONFIG, webkit) { + QT += webkit declarative + + SOURCES += qdeclarativewebview.cpp plugin.cpp + HEADERS += qdeclarativewebview_p.h + HEADERS += qdeclarativewebview_p_p.h + + QTDIR_build:DESTDIR = $$QT_BUILD_TREE/imports/org/webkit + target.path = $$[QT_INSTALL_IMPORTS]/org/webkit + + qmldir.files += $$QT_BUILD_TREE/imports/org/webkit/qmldir + qmldir.path += $$[QT_INSTALL_IMPORTS]/org/webkit + + INSTALLS += target qmldir +} diff --git a/tests/auto/declarative/qdeclarativewebview/data/basic.qml b/tests/auto/declarative/qdeclarativewebview/data/basic.qml index 5394837..f0b41ef 100644 --- a/tests/auto/declarative/qdeclarativewebview/data/basic.qml +++ b/tests/auto/declarative/qdeclarativewebview/data/basic.qml @@ -1,4 +1,5 @@ import Qt 4.6 +import org.webkit 1.0 WebView { url: "basic.html" diff --git a/tests/auto/declarative/qdeclarativewebview/data/elements.qml b/tests/auto/declarative/qdeclarativewebview/data/elements.qml index 7c030e6..16e5788 100644 --- a/tests/auto/declarative/qdeclarativewebview/data/elements.qml +++ b/tests/auto/declarative/qdeclarativewebview/data/elements.qml @@ -1,4 +1,5 @@ import Qt 4.6 +import org.webkit 1.0 WebView { url: "elements.html" diff --git a/tests/auto/declarative/qdeclarativewebview/data/javaScript.qml b/tests/auto/declarative/qdeclarativewebview/data/javaScript.qml index 07eee88..0e92e0e 100644 --- a/tests/auto/declarative/qdeclarativewebview/data/javaScript.qml +++ b/tests/auto/declarative/qdeclarativewebview/data/javaScript.qml @@ -1,4 +1,5 @@ import Qt 4.6 +import org.webkit 1.0 WebView { url: "javaScript.html" diff --git a/tests/auto/declarative/qdeclarativewebview/data/loadError.qml b/tests/auto/declarative/qdeclarativewebview/data/loadError.qml index 1460f30..f827238 100644 --- a/tests/auto/declarative/qdeclarativewebview/data/loadError.qml +++ b/tests/auto/declarative/qdeclarativewebview/data/loadError.qml @@ -1,4 +1,5 @@ import Qt 4.6 +import org.webkit 1.0 WebView { url: "does-not-exist.html" diff --git a/tests/auto/declarative/qdeclarativewebview/data/newwindows.qml b/tests/auto/declarative/qdeclarativewebview/data/newwindows.qml index 0bc8263..4d9df43 100644 --- a/tests/auto/declarative/qdeclarativewebview/data/newwindows.qml +++ b/tests/auto/declarative/qdeclarativewebview/data/newwindows.qml @@ -1,6 +1,7 @@ // Demonstrates opening new WebViews from HTML import Qt 4.6 +import org.webkit 1.0 Grid { columns: 3 diff --git a/tests/auto/declarative/qdeclarativewebview/data/propertychanges.qml b/tests/auto/declarative/qdeclarativewebview/data/propertychanges.qml index 3dd4e51..0770acf 100644 --- a/tests/auto/declarative/qdeclarativewebview/data/propertychanges.qml +++ b/tests/auto/declarative/qdeclarativewebview/data/propertychanges.qml @@ -1,4 +1,5 @@ import Qt 4.6 +import org.webkit 1.0 Item { width: 240 @@ -30,4 +31,4 @@ Item { pressGrabTime: 200 } } -} \ No newline at end of file +} diff --git a/tests/auto/declarative/qdeclarativewebview/data/sethtml.qml b/tests/auto/declarative/qdeclarativewebview/data/sethtml.qml index 063b5a8..9e17597 100644 --- a/tests/auto/declarative/qdeclarativewebview/data/sethtml.qml +++ b/tests/auto/declarative/qdeclarativewebview/data/sethtml.qml @@ -1,4 +1,5 @@ import Qt 4.6 +import org.webkit 1.0 WebView { html: "

This is a string set on the WebView" diff --git a/tests/auto/declarative/qdeclarativewebview/qdeclarativewebview.pro b/tests/auto/declarative/qdeclarativewebview/qdeclarativewebview.pro index 6af0a60..20173c6 100644 --- a/tests/auto/declarative/qdeclarativewebview/qdeclarativewebview.pro +++ b/tests/auto/declarative/qdeclarativewebview/qdeclarativewebview.pro @@ -3,8 +3,7 @@ contains(QT_CONFIG,declarative): QT += declarative contains(QT_CONFIG,webkit): QT += webkit macx:CONFIG -= app_bundle -SOURCES += tst_qdeclarativewebview.cpp testtypes.cpp -HEADERS += testtypes.h +SOURCES += tst_qdeclarativewebview.cpp # Define SRCDIR equal to test's source directory DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/auto/declarative/qdeclarativewebview/testtypes.cpp b/tests/auto/declarative/qdeclarativewebview/testtypes.cpp deleted file mode 100644 index 7efc214..0000000 --- a/tests/auto/declarative/qdeclarativewebview/testtypes.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/**************************************************************************** -** -** 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 test suite 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 "testtypes.h" - -void MyWebView::drawContents(QPainter *p, const QRect &r) -{ - pp += r.width()*r.height(); - QDeclarativeWebView::drawContents(p,r); -} - -void registerTypes() -{ - QML_REGISTER_TYPE(Test,1,0,MyWebView,MyWebView); -} diff --git a/tests/auto/declarative/qdeclarativewebview/testtypes.h b/tests/auto/declarative/qdeclarativewebview/testtypes.h deleted file mode 100644 index 8eb703f..0000000 --- a/tests/auto/declarative/qdeclarativewebview/testtypes.h +++ /dev/null @@ -1,66 +0,0 @@ -/**************************************************************************** -** -** 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 test suite 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 TESTTYPES_H -#define TESTTYPES_H - -#include - -class MyWebView : public QDeclarativeWebView -{ - Q_OBJECT - Q_PROPERTY(int pixelsPainted READ pixelsPainted); - -public: - MyWebView() : pp(0) {} - - int pixelsPainted() const { return pp; } - - void drawContents(QPainter *p, const QRect &r); - -private: - int pp; -}; - -QML_DECLARE_TYPE(MyWebView); - -void registerTypes(); - -#endif // TESTTYPES_H diff --git a/tests/auto/declarative/qdeclarativewebview/tst_qdeclarativewebview.cpp b/tests/auto/declarative/qdeclarativewebview/tst_qdeclarativewebview.cpp index 6d16056..1d6bedc 100644 --- a/tests/auto/declarative/qdeclarativewebview/tst_qdeclarativewebview.cpp +++ b/tests/auto/declarative/qdeclarativewebview/tst_qdeclarativewebview.cpp @@ -43,15 +43,12 @@ #include "../../../shared/util.h" #include #include -#include -#include #include #include #include #include #include #include -#include "testtypes.h" class tst_qdeclarativewebview : public QObject { @@ -70,7 +67,7 @@ private slots: void setHtml(); void javaScript(); void cleanupTestCase(); - void pixelCache(); + //void pixelCache(); void newWindowParent(); void newWindowComponent(); void renderingEnabled(); @@ -89,7 +86,6 @@ private: void tst_qdeclarativewebview::initTestCase() { - registerTypes(); } static QString strippedHtml(QString html) @@ -148,81 +144,81 @@ void tst_qdeclarativewebview::basicProperties() checkNoErrors(component); QWebSettings::enablePersistentStorage(tmpDir()); - QDeclarativeWebView *wv = qobject_cast(component.create()); + QObject *wv = component.create(); QVERIFY(wv != 0); - QTRY_COMPARE(wv->progress(), 1.0); - QCOMPARE(wv->title(),QString("Basic")); - QTRY_COMPARE(wv->icon().width(), 48); - QCOMPARE(wv->icon(),QPixmap(SRCDIR "/data/basic.png")); - QCOMPARE(wv->statusText(),QString("status here")); - QCOMPARE(strippedHtml(fileContents(SRCDIR "/data/basic.html")), strippedHtml(wv->html())); - QCOMPARE(wv->width(), 123.0); - QCOMPARE(wv->preferredWidth(), 0); - QCOMPARE(wv->preferredHeight(), 0); - QCOMPARE(wv->zoomFactor(), 1.0); - QCOMPARE(wv->url(), QUrl::fromLocalFile(SRCDIR "/data/basic.html")); - QCOMPARE(wv->status(), QDeclarativeWebView::Ready); - QVERIFY(wv->reloadAction()); - QVERIFY(wv->reloadAction()->isEnabled()); - QVERIFY(wv->backAction()); - QVERIFY(!wv->backAction()->isEnabled()); - QVERIFY(wv->forwardAction()); - QVERIFY(!wv->forwardAction()->isEnabled()); - QVERIFY(wv->stopAction()); - QVERIFY(!wv->stopAction()->isEnabled()); - - wv->setPixelCacheSize(0); // mainly testing that it doesn't crash or anything! - QCOMPARE(wv->pixelCacheSize(),0); - wv->reloadAction()->trigger(); - QTRY_COMPARE(wv->progress(), 1.0); + QTRY_COMPARE(wv->property("progress").toDouble(), 1.0); + QCOMPARE(wv->property("title").toString(),QString("Basic")); + QTRY_COMPARE(qvariant_cast(wv->property("icon")).width(), 48); + QCOMPARE(qvariant_cast(wv->property("icon")),QPixmap(SRCDIR "/data/basic.png")); + QCOMPARE(wv->property("statusText").toString(),QString("status here")); + QCOMPARE(strippedHtml(fileContents(SRCDIR "/data/basic.html")), strippedHtml(wv->property("html").toString())); + QCOMPARE(wv->property("width").toDouble(), 123.0); + QCOMPARE(wv->property("preferredWidth").toInt(), 0); + QCOMPARE(wv->property("preferredHeight").toInt(), 0); + QCOMPARE(wv->property("zoomFactor").toDouble(), 1.0); + QCOMPARE(wv->property("url").toUrl(), QUrl::fromLocalFile(SRCDIR "/data/basic.html")); + QCOMPARE(wv->property("status").toInt(), 1 /*QDeclarativeWebView::Ready*/); + QVERIFY(qvariant_cast(wv->property("reload"))); + QVERIFY(qvariant_cast(wv->property("reload"))->isEnabled()); + QVERIFY(qvariant_cast(wv->property("back"))); + QVERIFY(!qvariant_cast(wv->property("back"))->isEnabled()); + QVERIFY(qvariant_cast(wv->property("forward"))); + QVERIFY(!qvariant_cast(wv->property("forward"))->isEnabled()); + QVERIFY(qvariant_cast(wv->property("stop"))); + QVERIFY(!qvariant_cast(wv->property("stop"))->isEnabled()); + + wv->setProperty("pixelCacheSize", 0); // mainly testing that it doesn't crash or anything! + QCOMPARE(wv->property("pixelCacheSize").toInt(),0); + qvariant_cast(wv->property("reload"))->trigger(); + QTRY_COMPARE(wv->property("progress").toDouble(), 1.0); } void tst_qdeclarativewebview::settings() { QDeclarativeComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/basic.qml")); checkNoErrors(component); - QDeclarativeWebView *wv = qobject_cast(component.create()); + QObject *wv = component.create(); QVERIFY(wv != 0); - QTRY_COMPARE(wv->progress(), 1.0); + QTRY_COMPARE(wv->property("progress").toDouble(), 1.0); - QDeclarativeWebSettings *s = wv->settingsObject(); + QObject *s = qvariant_cast(wv->property("settings")); // merely tests that setting gets stored (in QWebSettings) // behavioural tests are in WebKit. for (int b=0; b<=1; ++b) { bool on = !!b; - s->setAutoLoadImages(on); - s->setDeveloperExtrasEnabled(on); - s->setJavaEnabled(on); - s->setJavascriptCanAccessClipboard(on); - s->setJavascriptCanOpenWindows(on); - s->setJavascriptEnabled(on); - s->setLinksIncludedInFocusChain(on); - s->setLocalContentCanAccessRemoteUrls(on); - s->setLocalStorageDatabaseEnabled(on); - s->setOfflineStorageDatabaseEnabled(on); - s->setOfflineWebApplicationCacheEnabled(on); - s->setPluginsEnabled(on); - s->setPrintElementBackgrounds(on); - s->setPrivateBrowsingEnabled(on); - s->setZoomTextOnly(on); - - QVERIFY(s->autoLoadImages() == on); - QVERIFY(s->developerExtrasEnabled() == on); - QVERIFY(s->javaEnabled() == on); - QVERIFY(s->javascriptCanAccessClipboard() == on); - QVERIFY(s->javascriptCanOpenWindows() == on); - QVERIFY(s->javascriptEnabled() == on); - QVERIFY(s->linksIncludedInFocusChain() == on); - QVERIFY(s->localContentCanAccessRemoteUrls() == on); - QVERIFY(s->localStorageDatabaseEnabled() == on); - QVERIFY(s->offlineStorageDatabaseEnabled() == on); - QVERIFY(s->offlineWebApplicationCacheEnabled() == on); - QVERIFY(s->pluginsEnabled() == on); - QVERIFY(s->printElementBackgrounds() == on); - QVERIFY(s->privateBrowsingEnabled() == on); - QVERIFY(s->zoomTextOnly() == on); + s->setProperty("autoLoadImages", on); + s->setProperty("developerExtrasEnabled", on); + s->setProperty("javaEnabled", on); + s->setProperty("javascriptCanAccessClipboard", on); + s->setProperty("javascriptCanOpenWindows", on); + s->setProperty("javascriptEnabled", on); + s->setProperty("linksIncludedInFocusChain", on); + s->setProperty("localContentCanAccessRemoteUrls", on); + s->setProperty("localStorageDatabaseEnabled", on); + s->setProperty("offlineStorageDatabaseEnabled", on); + s->setProperty("offlineWebApplicationCacheEnabled", on); + s->setProperty("pluginsEnabled", on); + s->setProperty("printElementBackgrounds", on); + s->setProperty("privateBrowsingEnabled", on); + s->setProperty("zoomTextOnly", on); + + QVERIFY(s->property("autoLoadImages") == on); + QVERIFY(s->property("developerExtrasEnabled") == on); + QVERIFY(s->property("javaEnabled") == on); + QVERIFY(s->property("javascriptCanAccessClipboard") == on); + QVERIFY(s->property("javascriptCanOpenWindows") == on); + QVERIFY(s->property("javascriptEnabled") == on); + QVERIFY(s->property("linksIncludedInFocusChain") == on); + QVERIFY(s->property("localContentCanAccessRemoteUrls") == on); + QVERIFY(s->property("localStorageDatabaseEnabled") == on); + QVERIFY(s->property("offlineStorageDatabaseEnabled") == on); + QVERIFY(s->property("offlineWebApplicationCacheEnabled") == on); + QVERIFY(s->property("pluginsEnabled") == on); + QVERIFY(s->property("printElementBackgrounds") == on); + QVERIFY(s->property("privateBrowsingEnabled") == on); + QVERIFY(s->property("zoomTextOnly") == on); QVERIFY(s->property("autoLoadImages") == on); QVERIFY(s->property("developerExtrasEnabled") == on); @@ -248,65 +244,65 @@ void tst_qdeclarativewebview::historyNav() checkNoErrors(component); QWebSettings::enablePersistentStorage(tmpDir()); - QDeclarativeWebView *wv = qobject_cast(component.create()); + QObject *wv = component.create(); QVERIFY(wv != 0); for (int i=1; i<=2; ++i) { - QTRY_COMPARE(wv->progress(), 1.0); - QCOMPARE(wv->title(),QString("Basic")); - QTRY_COMPARE(wv->icon().width(), 48); - QCOMPARE(wv->icon(),QPixmap(SRCDIR "/data/basic.png")); - QCOMPARE(wv->statusText(),QString("status here")); - QCOMPARE(strippedHtml(fileContents(SRCDIR "/data/basic.html")), strippedHtml(wv->html())); - QCOMPARE(wv->width(), 123.0); - QCOMPARE(wv->preferredWidth(), 0); - QCOMPARE(wv->zoomFactor(), 1.0); - QCOMPARE(wv->url(), QUrl::fromLocalFile(SRCDIR "/data/basic.html")); - QCOMPARE(wv->status(), QDeclarativeWebView::Ready); - QVERIFY(wv->reloadAction()); - QVERIFY(wv->reloadAction()->isEnabled()); - QVERIFY(wv->backAction()); - QVERIFY(!wv->backAction()->isEnabled()); - QVERIFY(wv->forwardAction()); - QVERIFY(!wv->forwardAction()->isEnabled()); - QVERIFY(wv->stopAction()); - QVERIFY(!wv->stopAction()->isEnabled()); - - wv->reloadAction()->trigger(); + QTRY_COMPARE(wv->property("progress").toDouble(), 1.0); + QCOMPARE(wv->property("title").toString(),QString("Basic")); + QTRY_COMPARE(qvariant_cast(wv->property("icon")).width(), 48); + QCOMPARE(qvariant_cast(wv->property("icon")),QPixmap(SRCDIR "/data/basic.png")); + QCOMPARE(wv->property("statusText").toString(),QString("status here")); + QCOMPARE(strippedHtml(fileContents(SRCDIR "/data/basic.html")), strippedHtml(wv->property("html").toString())); + QCOMPARE(wv->property("width").toDouble(), 123.0); + QCOMPARE(wv->property("preferredWidth").toDouble(), 0.0); + QCOMPARE(wv->property("zoomFactor").toDouble(), 1.0); + QCOMPARE(wv->property("url").toUrl(), QUrl::fromLocalFile(SRCDIR "/data/basic.html")); + QCOMPARE(wv->property("status").toInt(), 1 /*QDeclarativeWebView::Ready*/); + QVERIFY(qvariant_cast(wv->property("reload"))); + QVERIFY(qvariant_cast(wv->property("reload"))->isEnabled()); + QVERIFY(qvariant_cast(wv->property("back"))); + QVERIFY(!qvariant_cast(wv->property("back"))->isEnabled()); + QVERIFY(qvariant_cast(wv->property("forward"))); + QVERIFY(!qvariant_cast(wv->property("forward"))->isEnabled()); + QVERIFY(qvariant_cast(wv->property("stop"))); + QVERIFY(!qvariant_cast(wv->property("stop"))->isEnabled()); + + qvariant_cast(wv->property("reload"))->trigger(); } - wv->setUrl(QUrl::fromLocalFile(SRCDIR "/data/forward.html")); - QTRY_COMPARE(wv->progress(), 1.0); - QCOMPARE(wv->title(),QString("Forward")); - QTRY_COMPARE(wv->icon().width(), 32); - QCOMPARE(wv->icon(),QPixmap(SRCDIR "/data/forward.png")); - QCOMPARE(strippedHtml(fileContents(SRCDIR "/data/forward.html")), strippedHtml(wv->html())); - QCOMPARE(wv->url(), QUrl::fromLocalFile(SRCDIR "/data/forward.html")); - QCOMPARE(wv->status(), QDeclarativeWebView::Ready); - QCOMPARE(wv->statusText(),QString("")); - QVERIFY(wv->reloadAction()); - QVERIFY(wv->reloadAction()->isEnabled()); - QVERIFY(wv->backAction()); - QVERIFY(wv->backAction()->isEnabled()); - QVERIFY(wv->forwardAction()); - QVERIFY(!wv->forwardAction()->isEnabled()); - QVERIFY(wv->stopAction()); - QVERIFY(!wv->stopAction()->isEnabled()); - - wv->backAction()->trigger(); - - QTRY_COMPARE(wv->progress(), 1.0); - QCOMPARE(wv->title(),QString("Basic")); - QCOMPARE(strippedHtml(fileContents(SRCDIR "/data/basic.html")), strippedHtml(wv->html())); - QCOMPARE(wv->url(), QUrl::fromLocalFile(SRCDIR "/data/basic.html")); - QCOMPARE(wv->status(), QDeclarativeWebView::Ready); - QVERIFY(wv->reloadAction()); - QVERIFY(wv->reloadAction()->isEnabled()); - QVERIFY(wv->backAction()); - QVERIFY(!wv->backAction()->isEnabled()); - QVERIFY(wv->forwardAction()); - QVERIFY(wv->forwardAction()->isEnabled()); - QVERIFY(wv->stopAction()); - QVERIFY(!wv->stopAction()->isEnabled()); + wv->setProperty("url", QUrl::fromLocalFile(SRCDIR "/data/forward.html")); + QTRY_COMPARE(wv->property("progress").toDouble(), 1.0); + QCOMPARE(wv->property("title").toString(),QString("Forward")); + QTRY_COMPARE(qvariant_cast(wv->property("icon")).width(), 32); + QCOMPARE(qvariant_cast(wv->property("icon")),QPixmap(SRCDIR "/data/forward.png")); + QCOMPARE(strippedHtml(fileContents(SRCDIR "/data/forward.html")), strippedHtml(wv->property("html").toString())); + QCOMPARE(wv->property("url").toUrl(), QUrl::fromLocalFile(SRCDIR "/data/forward.html")); + QCOMPARE(wv->property("status").toInt(), 1 /*QDeclarativeWebView::Ready*/); + QCOMPARE(wv->property("statusText").toString(),QString("")); + QVERIFY(qvariant_cast(wv->property("reload"))); + QVERIFY(qvariant_cast(wv->property("reload"))->isEnabled()); + QVERIFY(qvariant_cast(wv->property("back"))); + QVERIFY(qvariant_cast(wv->property("back"))->isEnabled()); + QVERIFY(qvariant_cast(wv->property("forward"))); + QVERIFY(!qvariant_cast(wv->property("forward"))->isEnabled()); + QVERIFY(qvariant_cast(wv->property("stop"))); + QVERIFY(!qvariant_cast(wv->property("stop"))->isEnabled()); + + qvariant_cast(wv->property("back"))->trigger(); + + QTRY_COMPARE(wv->property("progress").toDouble(), 1.0); + QCOMPARE(wv->property("title").toString(),QString("Basic")); + QCOMPARE(strippedHtml(fileContents(SRCDIR "/data/basic.html")), strippedHtml(wv->property("html").toString())); + QCOMPARE(wv->property("url").toUrl(), QUrl::fromLocalFile(SRCDIR "/data/basic.html")); + QCOMPARE(wv->property("status").toInt(), 1 /*QDeclarativeWebView::Ready*/); + QVERIFY(qvariant_cast(wv->property("reload"))); + QVERIFY(qvariant_cast(wv->property("reload"))->isEnabled()); + QVERIFY(qvariant_cast(wv->property("back"))); + QVERIFY(!qvariant_cast(wv->property("back"))->isEnabled()); + QVERIFY(qvariant_cast(wv->property("forward"))); + QVERIFY(qvariant_cast(wv->property("forward"))->isEnabled()); + QVERIFY(qvariant_cast(wv->property("stop"))); + QVERIFY(!qvariant_cast(wv->property("stop"))->isEnabled()); } void tst_qdeclarativewebview::multipleWindows() @@ -328,16 +324,16 @@ void tst_qdeclarativewebview::loadError() checkNoErrors(component); QWebSettings::enablePersistentStorage(tmpDir()); - QDeclarativeWebView *wv = qobject_cast(component.create()); + QObject *wv = component.create(); QVERIFY(wv != 0); for (int i=1; i<=2; ++i) { - QTRY_COMPARE(wv->progress(), 1.0); - QCOMPARE(wv->title(),QString("")); - QCOMPARE(wv->statusText(),QString("")); // HTML 'status bar' text, not error message - QCOMPARE(wv->url(), QUrl::fromLocalFile(SRCDIR "/data/does-not-exist.html")); // Unlike QWebPage, which loses url - QCOMPARE(wv->status(), QDeclarativeWebView::Error); + QTRY_COMPARE(wv->property("progress").toDouble(), 1.0); + QCOMPARE(wv->property("title").toString(),QString("")); + QCOMPARE(wv->property("statusText").toString(),QString("")); // HTML 'status bar' text, not error message + QCOMPARE(wv->property("url").toUrl(), QUrl::fromLocalFile(SRCDIR "/data/does-not-exist.html")); // Unlike QWebPage, which loses url + QCOMPARE(wv->property("status").toInt(), 3 /*QDeclarativeWebView::Error*/); - wv->reloadAction()->trigger(); + qvariant_cast(wv->property("reload"))->trigger(); } } @@ -345,12 +341,12 @@ void tst_qdeclarativewebview::setHtml() { QDeclarativeComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/sethtml.qml")); checkNoErrors(component); - QDeclarativeWebView *wv = qobject_cast(component.create()); + QObject *wv = component.create(); QVERIFY(wv != 0); - QCOMPARE(wv->html(),QString("

This is a string set on the WebView

")); + QCOMPARE(wv->property("html").toString(),QString("

This is a string set on the WebView

")); QSignalSpy spy(wv, SIGNAL(htmlChanged())); - wv->setHtml(QString("Basic

text

")); + wv->setProperty("html", QString("Basic

text

")); QCOMPARE(spy.count(),1); } @@ -358,81 +354,91 @@ void tst_qdeclarativewebview::elementAreaAt() { QDeclarativeComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/elements.qml")); checkNoErrors(component); - QDeclarativeWebView *wv = qobject_cast(component.create()); + QObject *wv = component.create(); QVERIFY(wv != 0); - QTRY_COMPARE(wv->progress(), 1.0); + QTRY_COMPARE(wv->property("progress").toDouble(), 1.0); + /* not now it's a plugin... QCOMPARE(wv->elementAreaAt(40,30,100,100),QRect(1,1,75,54)); // Area A in data/elements.html QCOMPARE(wv->elementAreaAt(130,30,200,100),QRect(78,3,110,50)); // Area B QCOMPARE(wv->elementAreaAt(40,30,400,400),QRect(0,0,310,100)); // Whole view QCOMPARE(wv->elementAreaAt(130,30,280,280),QRect(76,1,223,54)); // Area BC QCOMPARE(wv->elementAreaAt(130,30,400,400),QRect(0,0,310,100)); // Whole view + */ } void tst_qdeclarativewebview::javaScript() { QDeclarativeComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/javaScript.qml")); checkNoErrors(component); - QDeclarativeWebView *wv = qobject_cast(component.create()); + QObject *wv = component.create(); QVERIFY(wv != 0); - QTRY_COMPARE(wv->progress(), 1.0); + QTRY_COMPARE(wv->property("progress").toDouble(), 1.0); + /* not now it's a plugin... QCOMPARE(wv->evaluateJavaScript("123").toInt(), 123); QCOMPARE(wv->evaluateJavaScript("window.status").toString(), QString("status here")); QCOMPARE(wv->evaluateJavaScript("window.myjsname.qmlprop").toString(), QString("qmlvalue")); + */ } +/* +Cannot be done now that webkit is a plugin + void tst_qdeclarativewebview::pixelCache() { + QDeclarativeComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/pixelCache.qml")); checkNoErrors(component); MyWebView *wv = qobject_cast(component.create()); QVERIFY(wv != 0); - QTRY_COMPARE(wv->progress(), 1.0); + QTRY_COMPARE(wv->property("progress"), 1.0); QPixmap pm(150,150); QPainter p(&pm); wv->paint(&p,0,0); const int expected = 120*(150+128); // 120 = width of HTML page, 150=pixmap height, 128=cache extra area - QCOMPARE(wv->pixelsPainted(), expected); + QCOMPARE(wv->property("pixelsPainted"), expected); wv->paint(&p,0,0); - QCOMPARE(wv->pixelsPainted(), expected); // nothing new needed to be painted - wv->setPixelCacheSize(0); // clears the cache + QCOMPARE(wv->property("pixelsPainted"), expected); // nothing new needed to be painted + wv->setProperty("pixelCacheSize", 0); // clears the cache wv->paint(&p,0,0); - QCOMPARE(wv->pixelsPainted(), expected*2); // everything needed to be painted + QCOMPARE(wv->property("pixelsPainted"), expected*2); // everything needed to be painted // Note that painted things always go into the cache (even if they don't "fit"), // just that they will be removed if anything else needs to be painted. - wv->setPixelCacheSize(expected); // won't clear the cache + wv->setProperty("pixelCacheSize", expected); // won't clear the cache wv->paint(&p,0,0); - QCOMPARE(wv->pixelsPainted(), expected*2); // still there - wv->setPixelCacheSize(expected-1); // too small - will clear the cache + QCOMPARE(wv->property("pixelsPainted"), expected*2); // still there + wv->setProperty("pixelCacheSize", expected-1); // too small - will clear the cache wv->paint(&p,0,0); - QCOMPARE(wv->pixelsPainted(), expected*3); // repainted + QCOMPARE(wv->property("pixelsPainted"), expected*3); // repainted } +*/ void tst_qdeclarativewebview::newWindowParent() { QDeclarativeComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/propertychanges.qml")); checkNoErrors(component); QDeclarativeItem *rootItem = qobject_cast(component.create()); - QDeclarativeWebView *wv = rootItem->findChild("webView"); + QObject *wv = rootItem->findChild("webView"); QVERIFY(rootItem != 0); QVERIFY(wv != 0); - QTRY_COMPARE(wv->progress(), 1.0); + QTRY_COMPARE(wv->property("progress").toDouble(), 1.0); QDeclarativeItem* oldWindowParent = rootItem->findChild("oldWindowParent"); - QCOMPARE(wv->newWindowParent(), oldWindowParent); + QCOMPARE(qvariant_cast(wv->property("newWindowParent")), oldWindowParent); QSignalSpy newWindowParentSpy(wv, SIGNAL(newWindowParentChanged())); QDeclarativeItem* newWindowParent = rootItem->findChild("newWindowParent"); - wv->setNewWindowParent(newWindowParent); + wv->setProperty("newWindowParent", QVariant::fromValue(newWindowParent)); + QVERIFY(newWindowParent); QVERIFY(oldWindowParent); QVERIFY(oldWindowParent->childItems().count() == 0); - QCOMPARE(wv->newWindowParent(), newWindowParent); + QCOMPARE(wv->property("newWindowParent"), QVariant::fromValue(newWindowParent)); QCOMPARE(newWindowParentSpy.count(),1); - wv->setNewWindowParent(newWindowParent); + wv->setProperty("newWindowParent", QVariant::fromValue(newWindowParent)); QCOMPARE(newWindowParentSpy.count(),1); - wv->setNewWindowParent(0); + wv->setProperty("newWindowParent", QVariant::fromValue((QDeclarativeItem*)0)); QCOMPARE(newWindowParentSpy.count(),2); } @@ -441,23 +447,23 @@ void tst_qdeclarativewebview::newWindowComponent() QDeclarativeComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/propertychanges.qml")); checkNoErrors(component); QDeclarativeItem *rootItem = qobject_cast(component.create()); - QDeclarativeWebView *wv = rootItem->findChild("webView"); + QObject *wv = rootItem->findChild("webView"); QVERIFY(rootItem != 0); QVERIFY(wv != 0); - QTRY_COMPARE(wv->progress(), 1.0); + QTRY_COMPARE(wv->property("progress").toDouble(), 1.0); QDeclarativeComponent substituteComponent(&engine); substituteComponent.setData("import Qt 4.6; WebView { objectName: 'newWebView'; url: 'basic.html'; }", QUrl::fromLocalFile("")); QSignalSpy newWindowComponentSpy(wv, SIGNAL(newWindowComponentChanged())); - wv->setNewWindowComponent(&substituteComponent); - QCOMPARE(wv->newWindowComponent(), &substituteComponent); + wv->setProperty("newWindowComponent", QVariant::fromValue(&substituteComponent)); + QCOMPARE(wv->property("newWindowComponent"), QVariant::fromValue(&substituteComponent)); QCOMPARE(newWindowComponentSpy.count(),1); - wv->setNewWindowComponent(&substituteComponent); + wv->setProperty("newWindowComponent", QVariant::fromValue(&substituteComponent)); QCOMPARE(newWindowComponentSpy.count(),1); - wv->setNewWindowComponent(0); + wv->setProperty("newWindowComponent", QVariant::fromValue((QDeclarativeComponent*)0)); QCOMPARE(newWindowComponentSpy.count(),2); } @@ -466,22 +472,22 @@ void tst_qdeclarativewebview::renderingEnabled() QDeclarativeComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/propertychanges.qml")); checkNoErrors(component); QDeclarativeItem *rootItem = qobject_cast(component.create()); - QDeclarativeWebView *wv = rootItem->findChild("webView"); + QObject *wv = rootItem->findChild("webView"); QVERIFY(rootItem != 0); QVERIFY(wv != 0); - QTRY_COMPARE(wv->progress(), 1.0); + QTRY_COMPARE(wv->property("progress").toDouble(), 1.0); - QVERIFY(wv->renderingEnabled()); + QVERIFY(wv->property("renderingEnabled").toBool()); QSignalSpy renderingEnabledSpy(wv, SIGNAL(renderingEnabledChanged())); - wv->setRenderingEnabled(false); - QVERIFY(!wv->renderingEnabled()); + wv->setProperty("renderingEnabled", false); + QVERIFY(!wv->property("renderingEnabled").toBool()); QCOMPARE(renderingEnabledSpy.count(),1); - wv->setRenderingEnabled(false); + wv->setProperty("renderingEnabled", false); QCOMPARE(renderingEnabledSpy.count(),1); - wv->setRenderingEnabled(true); + wv->setProperty("renderingEnabled", true); QCOMPARE(renderingEnabledSpy.count(),2); } @@ -490,21 +496,21 @@ void tst_qdeclarativewebview::pressGrabTime() QDeclarativeComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/propertychanges.qml")); checkNoErrors(component); QDeclarativeItem *rootItem = qobject_cast(component.create()); - QDeclarativeWebView *wv = rootItem->findChild("webView"); + QObject *wv = rootItem->findChild("webView"); QVERIFY(rootItem != 0); QVERIFY(wv != 0); - QTRY_COMPARE(wv->progress(), 1.0); - QCOMPARE(wv->pressGrabTime(), 200); + QTRY_COMPARE(wv->property("progress").toDouble(), 1.0); + QCOMPARE(wv->property("pressGrabTime").toInt(), 200); QSignalSpy pressGrabTimeSpy(wv, SIGNAL(pressGrabTimeChanged())); - wv->setPressGrabTime(100); - QCOMPARE(wv->pressGrabTime(), 100); + wv->setProperty("pressGrabTime", 100); + QCOMPARE(wv->property("pressGrabTime").toInt(), 100); QCOMPARE(pressGrabTimeSpy.count(),1); - wv->setPressGrabTime(100); + wv->setProperty("pressGrabTime", 100); QCOMPARE(pressGrabTimeSpy.count(),1); - wv->setPressGrabTime(0); + wv->setProperty("pressGrabTime", 0); QCOMPARE(pressGrabTimeSpy.count(),2); } diff --git a/tests/auto/declarative/visual/qfxwebview/autosize/autosize.qml b/tests/auto/declarative/visual/qfxwebview/autosize/autosize.qml index 74c6844..3c00ee6 100644 --- a/tests/auto/declarative/visual/qfxwebview/autosize/autosize.qml +++ b/tests/auto/declarative/visual/qfxwebview/autosize/autosize.qml @@ -1,4 +1,5 @@ import Qt 4.6 +import org.webkit 1.0 // The WebView size is determined by the width, height, // preferredWidth, and preferredHeight properties. diff --git a/tests/auto/declarative/visual/webview/embedding/nesting.qml b/tests/auto/declarative/visual/webview/embedding/nesting.qml index 0d76579..5e35306 100644 --- a/tests/auto/declarative/visual/webview/embedding/nesting.qml +++ b/tests/auto/declarative/visual/webview/embedding/nesting.qml @@ -1,4 +1,5 @@ import Qt 4.6 +import org.webkit 1.0 WebView { width: 300 diff --git a/tests/auto/declarative/visual/webview/javascript/evaluateJavaScript.qml b/tests/auto/declarative/visual/webview/javascript/evaluateJavaScript.qml index 78d5cfc..6c01382 100644 --- a/tests/auto/declarative/visual/webview/javascript/evaluateJavaScript.qml +++ b/tests/auto/declarative/visual/webview/javascript/evaluateJavaScript.qml @@ -1,4 +1,5 @@ import Qt 4.6 +import org.webkit 1.0 Column { WebView { diff --git a/tests/auto/declarative/visual/webview/javascript/windowObjects.qml b/tests/auto/declarative/visual/webview/javascript/windowObjects.qml index a41de9a..8c52aff 100644 --- a/tests/auto/declarative/visual/webview/javascript/windowObjects.qml +++ b/tests/auto/declarative/visual/webview/javascript/windowObjects.qml @@ -1,4 +1,5 @@ import Qt 4.6 +import org.webkit 1.0 Column { WebView { diff --git a/tests/auto/declarative/visual/webview/settings/fontFamily.qml b/tests/auto/declarative/visual/webview/settings/fontFamily.qml index 2bb2a53..f547b0e 100644 --- a/tests/auto/declarative/visual/webview/settings/fontFamily.qml +++ b/tests/auto/declarative/visual/webview/settings/fontFamily.qml @@ -1,4 +1,5 @@ import Qt 4.6 +import org.webkit 1.0 WebView { id: web diff --git a/tests/auto/declarative/visual/webview/settings/fontSize.qml b/tests/auto/declarative/visual/webview/settings/fontSize.qml index b970783..7eaa96b 100644 --- a/tests/auto/declarative/visual/webview/settings/fontSize.qml +++ b/tests/auto/declarative/visual/webview/settings/fontSize.qml @@ -1,4 +1,5 @@ import Qt 4.6 +import org.webkit 1.0 Grid { columns: 3 diff --git a/tests/auto/declarative/visual/webview/settings/noAutoLoadImages.qml b/tests/auto/declarative/visual/webview/settings/noAutoLoadImages.qml index 72e672d..67f1633 100644 --- a/tests/auto/declarative/visual/webview/settings/noAutoLoadImages.qml +++ b/tests/auto/declarative/visual/webview/settings/noAutoLoadImages.qml @@ -1,4 +1,5 @@ import Qt 4.6 +import org.webkit 1.0 Grid { columns: 2 diff --git a/tests/auto/declarative/visual/webview/settings/setFontFamily.qml b/tests/auto/declarative/visual/webview/settings/setFontFamily.qml index 26deed8..823469f 100644 --- a/tests/auto/declarative/visual/webview/settings/setFontFamily.qml +++ b/tests/auto/declarative/visual/webview/settings/setFontFamily.qml @@ -1,4 +1,5 @@ import Qt 4.6 +import org.webkit 1.0 WebView { url: "test.html" diff --git a/tests/auto/declarative/visual/webview/zooming/pageWidth.qml b/tests/auto/declarative/visual/webview/zooming/pageWidth.qml index 86dd7d2..4a876dd 100644 --- a/tests/auto/declarative/visual/webview/zooming/pageWidth.qml +++ b/tests/auto/declarative/visual/webview/zooming/pageWidth.qml @@ -1,4 +1,5 @@ import Qt 4.6 +import org.webkit 1.0 WebView { width: 200 diff --git a/tests/auto/declarative/visual/webview/zooming/renderControl.qml b/tests/auto/declarative/visual/webview/zooming/renderControl.qml index 0c8bb3b..49eb91b 100644 --- a/tests/auto/declarative/visual/webview/zooming/renderControl.qml +++ b/tests/auto/declarative/visual/webview/zooming/renderControl.qml @@ -1,4 +1,5 @@ import Qt 4.6 +import org.webkit 1.0 Rectangle { width: 200 diff --git a/tests/auto/declarative/visual/webview/zooming/resolution.qml b/tests/auto/declarative/visual/webview/zooming/resolution.qml index a9d4e3a..8542768 100644 --- a/tests/auto/declarative/visual/webview/zooming/resolution.qml +++ b/tests/auto/declarative/visual/webview/zooming/resolution.qml @@ -1,4 +1,5 @@ import Qt 4.6 +import org.webkit 1.0 WebView { width: 200 * zoomFactor diff --git a/tests/auto/declarative/visual/webview/zooming/zoomTextOnly.qml b/tests/auto/declarative/visual/webview/zooming/zoomTextOnly.qml index 4455b43..c2e9348 100644 --- a/tests/auto/declarative/visual/webview/zooming/zoomTextOnly.qml +++ b/tests/auto/declarative/visual/webview/zooming/zoomTextOnly.qml @@ -1,4 +1,5 @@ import Qt 4.6 +import org.webkit 1.0 WebView { width: 200 diff --git a/tests/auto/declarative/visual/webview/zooming/zooming.qml b/tests/auto/declarative/visual/webview/zooming/zooming.qml index 0ea9131..9f0b865 100644 --- a/tests/auto/declarative/visual/webview/zooming/zooming.qml +++ b/tests/auto/declarative/visual/webview/zooming/zooming.qml @@ -1,4 +1,5 @@ import Qt 4.6 +import org.webkit 1.0 // Note that zooming is better done using zoomFactor and careful // control of rendering to avoid excessive re-rendering during -- cgit v0.12 From fd7d730d04862095898773a781bb9a254d0aeb00 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Tue, 2 Mar 2010 15:56:53 +1000 Subject: doc --- src/declarative/QmlChanges.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/declarative/QmlChanges.txt b/src/declarative/QmlChanges.txt index 34e4834..c312abf 100644 --- a/src/declarative/QmlChanges.txt +++ b/src/declarative/QmlChanges.txt @@ -12,6 +12,7 @@ Connection: syntax and rename: Connection { sender: a; signal: bar(); script: yyy } becomes: Connections { target: a; onFoo: xxx; onBar: yyy } +Using WebView now requires "import org.webkit 1.0" QmlView ------- -- cgit v0.12 From 1e4258c6098a87342b61935f1ad25102ce699af1 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Tue, 2 Mar 2010 16:27:06 +1000 Subject: Fix zooming (broke with transformOrigin default change). Task-number: QTBUG-5845 --- demos/declarative/webbrowser/content/FlickableWebView.qml | 1 + 1 file changed, 1 insertion(+) diff --git a/demos/declarative/webbrowser/content/FlickableWebView.qml b/demos/declarative/webbrowser/content/FlickableWebView.qml index cf4c825..30a5d78 100644 --- a/demos/declarative/webbrowser/content/FlickableWebView.qml +++ b/demos/declarative/webbrowser/content/FlickableWebView.qml @@ -23,6 +23,7 @@ Flickable { WebView { id: webView pixelCacheSize: 4000000 + transformOrigin: Item.TopLeft Script { function fixUrl(url) -- cgit v0.12 From f1412745126db129445a368525f7ec05b20a0885 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 2 Mar 2010 18:45:02 +1000 Subject: Empty URL test --- src/declarative/qml/qdeclarativecomponent.cpp | 7 ++ tests/auto/declarative/declarative.pro | 1 + .../qdeclarativecomponent.pro | 8 +++ .../tst_qdeclarativecomponent.cpp | 75 ++++++++++++++++++++++ 4 files changed, 91 insertions(+) create mode 100644 tests/auto/declarative/qdeclarativecomponent/qdeclarativecomponent.pro create mode 100644 tests/auto/declarative/qdeclarativecomponent/tst_qdeclarativecomponent.cpp diff --git a/src/declarative/qml/qdeclarativecomponent.cpp b/src/declarative/qml/qdeclarativecomponent.cpp index 6a2d2d1..d6bb216 100644 --- a/src/declarative/qml/qdeclarativecomponent.cpp +++ b/src/declarative/qml/qdeclarativecomponent.cpp @@ -437,6 +437,13 @@ void QDeclarativeComponent::loadUrl(const QUrl &url) else d->url = url; + if (url.isEmpty()) { + QDeclarativeError error; + error.setDescription(tr("Invalid empty URL")); + d->state.errors << error; + return; + } + QDeclarativeCompositeTypeData *data = QDeclarativeEnginePrivate::get(d->engine)->typeManager.get(d->url); diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/declarative/declarative.pro index 42ff523..4ee6d8c 100644 --- a/tests/auto/declarative/declarative.pro +++ b/tests/auto/declarative/declarative.pro @@ -7,6 +7,7 @@ SUBDIRS += \ qdeclarativeanimations \ # Cover qdeclarativebehaviors \ # Cover qdeclarativebinding \ # Cover + qdeclarativecomponent \ # Cover qdeclarativeconnection \ # Cover qdeclarativecontext \ # Cover qdeclarativedatetimeformatter \ # Cover diff --git a/tests/auto/declarative/qdeclarativecomponent/qdeclarativecomponent.pro b/tests/auto/declarative/qdeclarativecomponent/qdeclarativecomponent.pro new file mode 100644 index 0000000..c7affb7 --- /dev/null +++ b/tests/auto/declarative/qdeclarativecomponent/qdeclarativecomponent.pro @@ -0,0 +1,8 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += declarative +QT += script network +macx:CONFIG -= app_bundle + +SOURCES += tst_qdeclarativecomponent.cpp + +DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/auto/declarative/qdeclarativecomponent/tst_qdeclarativecomponent.cpp b/tests/auto/declarative/qdeclarativecomponent/tst_qdeclarativecomponent.cpp new file mode 100644 index 0000000..c9e304c --- /dev/null +++ b/tests/auto/declarative/qdeclarativecomponent/tst_qdeclarativecomponent.cpp @@ -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 test suite 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 + +#include +#include + +class tst_qdeclarativecomponent : public QObject +{ + Q_OBJECT +public: + tst_qdeclarativecomponent() { } + +private slots: + void loadEmptyUrl(); + +private: + QDeclarativeEngine engine; +}; + +void tst_qdeclarativecomponent::loadEmptyUrl() +{ + QDeclarativeComponent c(&engine); + c.loadUrl(QUrl()); + + QVERIFY(c.isError()); + QCOMPARE(c.errors().count(), 1); + QDeclarativeError error = c.errors().first(); + QCOMPARE(error.url(), QUrl()); + QCOMPARE(error.line(), -1); + QCOMPARE(error.column(), -1); + QCOMPARE(error.description(), QLatin1String("Invalid empty URL")); +} + +QTEST_MAIN(tst_qdeclarativecomponent) + +#include "tst_qdeclarativecomponent.moc" -- cgit v0.12 From 3b8cad8be96d7791e8ca8305609d1155ec093b80 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 2 Mar 2010 19:35:30 +1000 Subject: Don't return QDeclarativeDeclarativeData for a deleting object This was causing crashes in the qmldesigner. --- src/declarative/qml/qdeclarativedeclarativedata_p.h | 5 ++++- src/declarative/qml/qdeclarativeengine_p.h | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/declarative/qml/qdeclarativedeclarativedata_p.h b/src/declarative/qml/qdeclarativedeclarativedata_p.h index 2c92419..a7a73bc 100644 --- a/src/declarative/qml/qdeclarativedeclarativedata_p.h +++ b/src/declarative/qml/qdeclarativedeclarativedata_p.h @@ -103,7 +103,10 @@ public: static QDeclarativeDeclarativeData *get(const QObject *object, bool create = false) { QObjectPrivate *priv = QObjectPrivate::get(const_cast(object)); - if (priv->declarativeData) { + if (priv->wasDeleted) { + Q_ASSERT(!create); + return 0; + } else if (priv->declarativeData) { return static_cast(priv->declarativeData); } else if (create) { priv->declarativeData = new QDeclarativeDeclarativeData; diff --git a/src/declarative/qml/qdeclarativeengine_p.h b/src/declarative/qml/qdeclarativeengine_p.h index 0359f98..d3eb583 100644 --- a/src/declarative/qml/qdeclarativeengine_p.h +++ b/src/declarative/qml/qdeclarativeengine_p.h @@ -238,7 +238,8 @@ public: QHash propertyCache; QDeclarativePropertyCache *cache(QObject *obj) { Q_Q(QDeclarativeEngine); - if (!obj || QObjectPrivate::get(obj)->metaObject) return 0; + if (!obj || QObjectPrivate::get(obj)->metaObject || + QObjectPrivate::get(obj)->wasDeleted) return 0; const QMetaObject *mo = obj->metaObject(); QDeclarativePropertyCache *rv = propertyCache.value(mo); if (!rv) { -- cgit v0.12 From 6e84a270c94376d24392d797f99bc7e95b217a34 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 2 Mar 2010 19:48:54 +1000 Subject: Add "on" syntax to QmlChanges.txt --- src/declarative/QmlChanges.txt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/declarative/QmlChanges.txt b/src/declarative/QmlChanges.txt index c312abf..4951cb3 100644 --- a/src/declarative/QmlChanges.txt +++ b/src/declarative/QmlChanges.txt @@ -53,6 +53,16 @@ matchProperties and matchTargets have been renamed back to properties and target The semantics are explained in the PropertyAnimation::properties documentation and the animation overview documentation. +Behavior and Animation syntax +----------------------------- + +Previously animations and behaviors could be "assigned" to properties like this: + Item { x: Behavior {}; y: NumberAnimation {} } +To make it more obvious that these are not regular value assignments a new "on" +syntax has been introduced: + Item { Behavior on x {}; NumberAnimation on y {} } +Only the syntax has changed, the behavior is identical. + ============================================================================= The changes below are pre-4.6.0 release. -- cgit v0.12 From 2d99a28a583b099cc0281b39b88b0bda8f5e5f7f Mon Sep 17 00:00:00 2001 From: mae Date: Tue, 2 Mar 2010 11:36:05 +0100 Subject: Moved qdeclarativemodules to imports --- src/declarative/declarative.pro | 28 +- src/declarative/imports/imports.pro | 7 + src/declarative/imports/multimedia/multimedia.cpp | 63 + src/declarative/imports/multimedia/multimedia.pro | 15 + src/declarative/imports/qimportbase.pri | 16 + src/declarative/imports/webkit/plugin.cpp | 66 + .../imports/webkit/qdeclarativewebview.cpp | 1340 ++++++++++++++++++++ .../imports/webkit/qdeclarativewebview_p.h | 285 +++++ .../imports/webkit/qdeclarativewebview_p_p.h | 151 +++ src/declarative/imports/webkit/webkit.pro | 18 + .../imports/widgets/graphicslayouts.cpp | 260 ++++ .../imports/widgets/graphicslayouts_p.h | 226 ++++ .../imports/widgets/graphicswidgets.cpp | 40 + .../imports/widgets/graphicswidgets_p.h | 68 + src/declarative/imports/widgets/widgets.cpp | 138 ++ src/declarative/imports/widgets/widgets.pro | 20 + src/declarative/libdeclarative.pro | 29 + src/plugins/plugins.pro | 1 - .../qdeclarativemodules/multimedia/multimedia.cpp | 63 - .../qdeclarativemodules/multimedia/multimedia.pro | 15 - .../qdeclarativemodules/qdeclarativemodules.pro | 7 - .../qdeclarativemodules/webkitqmlplugin/plugin.cpp | 66 - .../webkitqmlplugin/qdeclarativewebview.cpp | 1340 -------------------- .../webkitqmlplugin/qdeclarativewebview_p.h | 285 ----- .../webkitqmlplugin/qdeclarativewebview_p_p.h | 151 --- .../webkitqmlplugin/webkitqmlplugin.pro | 18 - .../widgets/graphicslayouts.cpp | 260 ---- .../widgets/graphicslayouts_p.h | 226 ---- .../widgets/graphicswidgets.cpp | 40 - .../widgets/graphicswidgets_p.h | 68 - .../qdeclarativemodules/widgets/widgets.cpp | 138 -- .../qdeclarativemodules/widgets/widgets.pro | 20 - 32 files changed, 2744 insertions(+), 2724 deletions(-) create mode 100644 src/declarative/imports/imports.pro create mode 100644 src/declarative/imports/multimedia/multimedia.cpp create mode 100644 src/declarative/imports/multimedia/multimedia.pro create mode 100644 src/declarative/imports/qimportbase.pri create mode 100644 src/declarative/imports/webkit/plugin.cpp create mode 100644 src/declarative/imports/webkit/qdeclarativewebview.cpp create mode 100644 src/declarative/imports/webkit/qdeclarativewebview_p.h create mode 100644 src/declarative/imports/webkit/qdeclarativewebview_p_p.h create mode 100644 src/declarative/imports/webkit/webkit.pro create mode 100644 src/declarative/imports/widgets/graphicslayouts.cpp create mode 100644 src/declarative/imports/widgets/graphicslayouts_p.h create mode 100644 src/declarative/imports/widgets/graphicswidgets.cpp create mode 100644 src/declarative/imports/widgets/graphicswidgets_p.h create mode 100644 src/declarative/imports/widgets/widgets.cpp create mode 100644 src/declarative/imports/widgets/widgets.pro create mode 100644 src/declarative/libdeclarative.pro delete mode 100644 src/plugins/qdeclarativemodules/multimedia/multimedia.cpp delete mode 100644 src/plugins/qdeclarativemodules/multimedia/multimedia.pro delete mode 100644 src/plugins/qdeclarativemodules/qdeclarativemodules.pro delete mode 100644 src/plugins/qdeclarativemodules/webkitqmlplugin/plugin.cpp delete mode 100644 src/plugins/qdeclarativemodules/webkitqmlplugin/qdeclarativewebview.cpp delete mode 100644 src/plugins/qdeclarativemodules/webkitqmlplugin/qdeclarativewebview_p.h delete mode 100644 src/plugins/qdeclarativemodules/webkitqmlplugin/qdeclarativewebview_p_p.h delete mode 100644 src/plugins/qdeclarativemodules/webkitqmlplugin/webkitqmlplugin.pro delete mode 100644 src/plugins/qdeclarativemodules/widgets/graphicslayouts.cpp delete mode 100644 src/plugins/qdeclarativemodules/widgets/graphicslayouts_p.h delete mode 100644 src/plugins/qdeclarativemodules/widgets/graphicswidgets.cpp delete mode 100644 src/plugins/qdeclarativemodules/widgets/graphicswidgets_p.h delete mode 100644 src/plugins/qdeclarativemodules/widgets/widgets.cpp delete mode 100644 src/plugins/qdeclarativemodules/widgets/widgets.pro diff --git a/src/declarative/declarative.pro b/src/declarative/declarative.pro index 4287e25..a7ec18e 100644 --- a/src/declarative/declarative.pro +++ b/src/declarative/declarative.pro @@ -1,29 +1,5 @@ -TARGET = QtDeclarative -QPRO_PWD = $$PWD -QT = core gui xml script network -contains(QT_CONFIG, svg): QT += svg -contains(QT_CONFIG, opengl): QT += opengl -DEFINES += QT_BUILD_DECLARATIVE_LIB QT_NO_URL_CAST_FROM_STRING -win32-msvc*|win32-icc:QMAKE_LFLAGS += /BASE:0x66000000 -solaris-cc*:QMAKE_CXXFLAGS_RELEASE -= -O2 +TEMPLATE = subdirs -unix:QMAKE_PKGCONFIG_REQUIRES = QtCore QtGui QtXml +SUBDIRS = libdeclarative.pro imports -exists("qdeclarative_enable_gcov") { - QMAKE_CXXFLAGS = -fprofile-arcs -ftest-coverage -fno-elide-constructors - LIBS += -lgcov -} -include(../qbase.pri) - -#INCLUDEPATH -= $$QMAKE_INCDIR_QT/$$TARGET -#DESTDIR=. - -#modules -include(3rdparty/3rdparty.pri) -include(util/util.pri) -include(graphicsitems/graphicsitems.pri) -include(qml/qml.pri) -include(debugger/debugger.pri) - -symbian:TARGET.UID3=0x2001E623 diff --git a/src/declarative/imports/imports.pro b/src/declarative/imports/imports.pro new file mode 100644 index 0000000..f874644 --- /dev/null +++ b/src/declarative/imports/imports.pro @@ -0,0 +1,7 @@ +TEMPLATE = subdirs + +SUBDIRS += widgets + +contains(QT_CONFIG, multimedia): SUBDIRS += multimedia +contains(QT_CONFIG, webkit): SUBDIRS += webkit + diff --git a/src/declarative/imports/multimedia/multimedia.cpp b/src/declarative/imports/multimedia/multimedia.cpp new file mode 100644 index 0000000..8becbf3 --- /dev/null +++ b/src/declarative/imports/multimedia/multimedia.cpp @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** 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 +#include +#include + +QT_BEGIN_NAMESPACE + +class QMultimediaQmlModule : public QDeclarativeExtensionPlugin +{ + Q_OBJECT +public: + virtual void registerTypes(const char *uri) + { + QtMultimedia::qRegisterDeclarativeElements(uri); + } +}; + +QT_END_NAMESPACE + +#include "multimedia.moc" + +Q_EXPORT_PLUGIN2(qmultimediaqmlmodule, QT_PREPEND_NAMESPACE(QMultimediaQmlModule)); + diff --git a/src/declarative/imports/multimedia/multimedia.pro b/src/declarative/imports/multimedia/multimedia.pro new file mode 100644 index 0000000..d601d2e --- /dev/null +++ b/src/declarative/imports/multimedia/multimedia.pro @@ -0,0 +1,15 @@ +TARGET = multimedia +include(../qimportbase.pri) + +QT += multimedia declarative + +SOURCES += multimedia.cpp + +QTDIR_build:DESTDIR = $$QT_BUILD_TREE/imports/Qt/multimedia +target.path = $$[QT_INSTALL_IMPORTS]/Qt/multimedia + +qmldir.files += $$QT_BUILD_TREE/imports/Qt/multimedia/qmldir +qmldir.path += $$[QT_INSTALL_IMPORTS]/Qt/multimedia + +INSTALLS += target qmldir + diff --git a/src/declarative/imports/qimportbase.pri b/src/declarative/imports/qimportbase.pri new file mode 100644 index 0000000..5b0a4e2 --- /dev/null +++ b/src/declarative/imports/qimportbase.pri @@ -0,0 +1,16 @@ +TEMPLATE = lib +CONFIG += qt plugin + +win32|mac:!wince*:!win32-msvc:!macx-xcode:CONFIG += debug_and_release +TARGET = $$qtLibraryTarget($$TARGET) +contains(QT_CONFIG, reduce_exports):CONFIG += hide_symbols + +include(../../qt_targets.pri) + +wince*:LIBS += $$QMAKE_LIBS_GUI + +symbian: { + TARGET.EPOCALLOWDLLDATA=1 + TARGET.CAPABILITY = All -Tcb + load(armcc_warnings) +} diff --git a/src/declarative/imports/webkit/plugin.cpp b/src/declarative/imports/webkit/plugin.cpp new file mode 100644 index 0000000..2f6205d --- /dev/null +++ b/src/declarative/imports/webkit/plugin.cpp @@ -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 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 +#include + +#include "qdeclarativewebview_p.h" +#include "qdeclarativewebview_p_p.h" + +QT_BEGIN_NAMESPACE + +class WebKitQmlPlugin : public QDeclarativeExtensionPlugin +{ + Q_OBJECT +public: + virtual void registerTypes(const char *uri) + { + Q_ASSERT(QLatin1String(uri) == QLatin1String("org.webkit")); + qmlRegisterType(uri,1,0,"WebView"); + } +}; + +QT_END_NAMESPACE + +#include "plugin.moc" + +Q_EXPORT_PLUGIN2(webkitqmlplugin, QT_PREPEND_NAMESPACE(WebKitQmlPlugin)); + diff --git a/src/declarative/imports/webkit/qdeclarativewebview.cpp b/src/declarative/imports/webkit/qdeclarativewebview.cpp new file mode 100644 index 0000000..733ac86 --- /dev/null +++ b/src/declarative/imports/webkit/qdeclarativewebview.cpp @@ -0,0 +1,1340 @@ +/**************************************************************************** +** +** 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 "qdeclarativewebview_p.h" +#include "qdeclarativewebview_p_p.h" + +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +static const int MAX_DOUBLECLICK_TIME=500; // XXX need better gesture system + +class QDeclarativeWebViewPrivate : public QDeclarativePaintedItemPrivate +{ + Q_DECLARE_PUBLIC(QDeclarativeWebView) + +public: + QDeclarativeWebViewPrivate() + : QDeclarativePaintedItemPrivate(), page(0), preferredwidth(0), preferredheight(0), + progress(1.0), status(QDeclarativeWebView::Null), pending(PendingNone), + newWindowComponent(0), newWindowParent(0), + pressTime(400), + rendering(true) + { + } + + QUrl url; // page url might be different if it has not loaded yet + QWebPage *page; + + int preferredwidth, preferredheight; + qreal progress; + QDeclarativeWebView::Status status; + QString statusText; + enum { PendingNone, PendingUrl, PendingHtml, PendingContent } pending; + QUrl pending_url; + QString pending_string; + QByteArray pending_data; + mutable QDeclarativeWebSettings settings; + QDeclarativeComponent *newWindowComponent; + QDeclarativeItem *newWindowParent; + + QBasicTimer pressTimer; + QPoint pressPoint; + int pressTime; // milliseconds before it's a "hold" + + + static void windowObjects_append(QDeclarativeListProperty *prop, QObject *o) { + static_cast(prop->data)->windowObjects.append(o); + static_cast(prop->data)->updateWindowObjects(); + } + + void updateWindowObjects(); + QObjectList windowObjects; + + bool rendering; +}; + +/*! + \qmlclass WebView QDeclarativeWebView + \since 4.7 + \brief The WebView item allows you to add web content to a canvas. + \inherits Item + + A WebView renders web content based on a URL. + + If the width and height of the item is not set, they will + dynamically adjust to a size appropriate for the content. + This width may be large for typical online web pages. + + If the preferredWidth is set, the width will be this amount or larger, + usually laying out the web content to fit the preferredWidth. + + \qml + import org.webkit 1.0 + + WebView { + url: "http://www.nokia.com" + width: 490 + height: 400 + scale: 0.5 + smooth: false + smoothCache: true + } + \endqml + + \image webview.png + + The item includes no scrolling, scaling, + toolbars, etc., those must be implemented around WebView. See the WebBrowser example + for a demonstration of this. +*/ + +/*! + \internal + \class QDeclarativeWebView + \brief The QDeclarativeWebView class allows you to add web content to a QDeclarativeView. + + A WebView renders web content base on a URL. + + \image webview.png + + The item includes no scrolling, scaling, + toolbars, etc., those must be implemented around WebView. See the WebBrowser example + for a demonstration of this. + + A QDeclarativeWebView object can be instantiated in Qml using the tag \l WebView. +*/ + +QDeclarativeWebView::QDeclarativeWebView(QDeclarativeItem *parent) + : QDeclarativePaintedItem(*(new QDeclarativeWebViewPrivate), parent) +{ + init(); +} + +QDeclarativeWebView::~QDeclarativeWebView() +{ + Q_D(QDeclarativeWebView); + delete d->page; +} + +void QDeclarativeWebView::init() +{ + Q_D(QDeclarativeWebView); + + QWebSettings::enablePersistentStorage(); + + setAcceptHoverEvents(true); + setAcceptedMouseButtons(Qt::LeftButton); + setFlag(QGraphicsItem::ItemHasNoContents, false); + + d->page = 0; +} + +void QDeclarativeWebView::componentComplete() +{ + QDeclarativePaintedItem::componentComplete(); + Q_D(QDeclarativeWebView); + switch (d->pending) { + case QDeclarativeWebViewPrivate::PendingUrl: + setUrl(d->pending_url); + break; + case QDeclarativeWebViewPrivate::PendingHtml: + setHtml(d->pending_string, d->pending_url); + break; + case QDeclarativeWebViewPrivate::PendingContent: + setContent(d->pending_data, d->pending_string, d->pending_url); + break; + default: + break; + } + d->pending = QDeclarativeWebViewPrivate::PendingNone; + d->updateWindowObjects(); +} + +QDeclarativeWebView::Status QDeclarativeWebView::status() const +{ + Q_D(const QDeclarativeWebView); + return d->status; +} + + +/*! + \qmlproperty real WebView::progress + This property holds the progress of loading the current URL, from 0 to 1. + + If you just want to know when progress gets to 1, use + WebView::onLoadFinished() or WebView::onLoadFailed() instead. +*/ +qreal QDeclarativeWebView::progress() const +{ + Q_D(const QDeclarativeWebView); + return d->progress; +} + +void QDeclarativeWebView::doLoadStarted() +{ + Q_D(QDeclarativeWebView); + + if (!d->url.isEmpty()) { + d->status = Loading; + emit statusChanged(d->status); + } + emit loadStarted(); +} + +void QDeclarativeWebView::doLoadProgress(int p) +{ + Q_D(QDeclarativeWebView); + if (d->progress == p/100.0) + return; + d->progress = p/100.0; + emit progressChanged(); +} + +void QDeclarativeWebView::pageUrlChanged() +{ + Q_D(QDeclarativeWebView); + + page()->setViewportSize(QSize( + d->preferredwidth>0 ? d->preferredwidth : width(), + d->preferredheight>0 ? d->preferredheight : height())); + expandToWebPage(); + + if ((d->url.isEmpty() && page()->mainFrame()->url() != QUrl(QLatin1String("about:blank"))) + || (d->url != page()->mainFrame()->url() && !page()->mainFrame()->url().isEmpty())) + { + d->url = page()->mainFrame()->url(); + if (d->url == QUrl(QLatin1String("about:blank"))) + d->url = QUrl(); + emit urlChanged(); + } +} + +void QDeclarativeWebView::doLoadFinished(bool ok) +{ + Q_D(QDeclarativeWebView); + + if (title().isEmpty()) + pageUrlChanged(); // XXX bug 232556 - pages with no title never get urlChanged() + + if (ok) { + d->status = d->url.isEmpty() ? Null : Ready; + emit loadFinished(); + } else { + d->status = Error; + emit loadFailed(); + } + emit statusChanged(d->status); +} + +/*! + \qmlproperty url WebView::url + This property holds the URL to the page displayed in this item. It can be set, + but also can change spontaneously (eg. because of network redirection). + + If the url is empty, the page is blank. + + The url is always absolute (QML will resolve relative URL strings in the context + of the containing QML document). +*/ +QUrl QDeclarativeWebView::url() const +{ + Q_D(const QDeclarativeWebView); + return d->url; +} + +void QDeclarativeWebView::setUrl(const QUrl &url) +{ + Q_D(QDeclarativeWebView); + if (url == d->url) + return; + + if (isComponentComplete()) { + d->url = url; + page()->setViewportSize(QSize( + d->preferredwidth>0 ? d->preferredwidth : width(), + d->preferredheight>0 ? d->preferredheight : height())); + QUrl seturl = url; + if (seturl.isEmpty()) + seturl = QUrl(QLatin1String("about:blank")); + + Q_ASSERT(!seturl.isRelative()); + + page()->mainFrame()->load(seturl); + + emit urlChanged(); + } else { + d->pending = d->PendingUrl; + d->pending_url = url; + } +} + +/*! + \qmlproperty int WebView::preferredWidth + This property holds the ideal width for displaying the current URL. +*/ +int QDeclarativeWebView::preferredWidth() const +{ + Q_D(const QDeclarativeWebView); + return d->preferredwidth; +} + +void QDeclarativeWebView::setPreferredWidth(int iw) +{ + Q_D(QDeclarativeWebView); + if (d->preferredwidth == iw) return; + d->preferredwidth = iw; + //expandToWebPage(); + emit preferredWidthChanged(); +} + +/*! + \qmlproperty int WebView::preferredHeight + This property holds the ideal height for displaying the current URL. + This only affects the area zoomed by heuristicZoom(). +*/ +int QDeclarativeWebView::preferredHeight() const +{ + Q_D(const QDeclarativeWebView); + return d->preferredheight; +} +void QDeclarativeWebView::setPreferredHeight(int ih) +{ + Q_D(QDeclarativeWebView); + if (d->preferredheight == ih) return; + d->preferredheight = ih; + emit preferredHeightChanged(); +} + +/*! + \qmlmethod bool WebView::evaluateJavaScript(string) + + Evaluates the \a scriptSource JavaScript inside the context of the + main web frame, and returns the result of the last executed statement. + + Note that this JavaScript does \e not have any access to QML objects + except as made available as windowObjects. +*/ +QVariant QDeclarativeWebView::evaluateJavaScript(const QString &scriptSource) +{ + return this->page()->mainFrame()->evaluateJavaScript(scriptSource); +} + +void QDeclarativeWebView::focusChanged(bool hasFocus) +{ + QFocusEvent e(hasFocus ? QEvent::FocusIn : QEvent::FocusOut); + page()->event(&e); + QDeclarativeItem::focusChanged(hasFocus); +} + +void QDeclarativeWebView::initialLayout() +{ + // nothing useful to do at this point +} + +void QDeclarativeWebView::noteContentsSizeChanged(const QSize&) +{ + expandToWebPage(); +} + +void QDeclarativeWebView::expandToWebPage() +{ + Q_D(QDeclarativeWebView); + QSize cs = page()->mainFrame()->contentsSize(); + if (cs.width() < d->preferredwidth) + cs.setWidth(d->preferredwidth); + if (cs.height() < d->preferredheight) + cs.setHeight(d->preferredheight); + if (widthValid()) + cs.setWidth(width()); + if (heightValid()) + cs.setHeight(height()); + if (cs != page()->viewportSize()) { + page()->setViewportSize(cs); + } + if (cs != contentsSize()) + setContentsSize(cs); +} + +void QDeclarativeWebView::geometryChanged(const QRectF &newGeometry, + const QRectF &oldGeometry) +{ + if (newGeometry.size() != oldGeometry.size()) + expandToWebPage(); + QDeclarativePaintedItem::geometryChanged(newGeometry, oldGeometry); +} + +void QDeclarativeWebView::paintPage(const QRect& r) +{ + dirtyCache(r); + update(); +} + +/*! + \qmlproperty list WebView::javaScriptWindowObjects + + This property is a list of object that are available from within + the webview's JavaScript context. + + The \a object will be inserted as a child of the frame's window + object, under the name given by the attached property \c WebView.windowObjectName. + + \qml + WebView { + javaScriptWindowObjects: Object { + WebView.windowObjectName: "coordinates" + } + } + \endqml + + Properties of the object will be exposed as JavaScript properties and slots as + JavaScript methods. + + If Javascript is not enabled for this page, then this property does nothing. +*/ +QDeclarativeListProperty QDeclarativeWebView::javaScriptWindowObjects() +{ + Q_D(QDeclarativeWebView); + return QDeclarativeListProperty(this, d, &QDeclarativeWebViewPrivate::windowObjects_append); +} + +QDeclarativeWebViewAttached *QDeclarativeWebView::qmlAttachedProperties(QObject *o) +{ + return new QDeclarativeWebViewAttached(o); +} + +void QDeclarativeWebViewPrivate::updateWindowObjects() +{ + Q_Q(QDeclarativeWebView); + if (!q->isComponentComplete() || !page) + return; + + for (int ii = 0; ii < windowObjects.count(); ++ii) { + QObject *object = windowObjects.at(ii); + QDeclarativeWebViewAttached *attached = static_cast(qmlAttachedPropertiesObject(object)); + if (attached && !attached->windowObjectName().isEmpty()) { + page->mainFrame()->addToJavaScriptWindowObject(attached->windowObjectName(), object); + } + } +} + +bool QDeclarativeWebView::renderingEnabled() const +{ + Q_D(const QDeclarativeWebView); + return d->rendering; +} + +void QDeclarativeWebView::setRenderingEnabled(bool enabled) +{ + Q_D(QDeclarativeWebView); + if (d->rendering == enabled) + return; + d->rendering = enabled; + emit renderingEnabledChanged(); + + setCacheFrozen(!enabled); + if (enabled) + clearCache(); +} + + +void QDeclarativeWebView::drawContents(QPainter *p, const QRect &r) +{ + Q_D(QDeclarativeWebView); + if (d->rendering) + page()->mainFrame()->render(p,r); +} + +QMouseEvent *QDeclarativeWebView::sceneMouseEventToMouseEvent(QGraphicsSceneMouseEvent *e) +{ + QEvent::Type t; + switch(e->type()) { + default: + case QEvent::GraphicsSceneMousePress: + t = QEvent::MouseButtonPress; + break; + case QEvent::GraphicsSceneMouseRelease: + t = QEvent::MouseButtonRelease; + break; + case QEvent::GraphicsSceneMouseMove: + t = QEvent::MouseMove; + break; + case QGraphicsSceneEvent::GraphicsSceneMouseDoubleClick: + t = QEvent::MouseButtonDblClick; + break; + } + + QMouseEvent *me = new QMouseEvent(t, (e->pos()/contentsScale()).toPoint(), e->button(), e->buttons(), 0); + return me; +} + +QMouseEvent *QDeclarativeWebView::sceneHoverMoveEventToMouseEvent(QGraphicsSceneHoverEvent *e) +{ + QEvent::Type t = QEvent::MouseMove; + + QMouseEvent *me = new QMouseEvent(t, (e->pos()/contentsScale()).toPoint(), Qt::NoButton, Qt::NoButton, 0); + + return me; +} + + +/*! + \qmlsignal WebView::onDoubleClick(clickx,clicky) + + The WebView does not pass double-click events to the web engine, but rather + emits this signals. +*/ + +void QDeclarativeWebView::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) +{ + QMouseEvent *me = sceneMouseEventToMouseEvent(event); + emit doubleClick(me->x(),me->y()); + delete me; +} + +/*! + \qmlmethod bool WebView::heuristicZoom(clickX,clickY,maxzoom) + + Finds a zoom that: + \list + \i shows a whole item + \i includes (\a clickX, \a clickY) + \i fits into the preferredWidth and preferredHeight + \i zooms by no more than \a maxzoom + \i is more than 10% above the current zoom + \endlist + + If such a zoom exists, emits zoomTo(zoom,centerX,centerY) and returns true; otherwise, + no signal is emitted and returns false. +*/ +bool QDeclarativeWebView::heuristicZoom(int clickX, int clickY, qreal maxzoom) +{ + Q_D(QDeclarativeWebView); + if (contentsScale() >= maxzoom/zoomFactor()) + return false; + qreal ozf = contentsScale(); + QRect showarea = elementAreaAt(clickX, clickY, d->preferredwidth/maxzoom, d->preferredheight/maxzoom); + qreal z = qMin(qreal(d->preferredwidth)/showarea.width(),qreal(d->preferredheight)/showarea.height()); + if (z > maxzoom/zoomFactor()) + z = maxzoom/zoomFactor(); + if (z/ozf > 1.2) { + QRectF r(showarea.left()*z, showarea.top()*z, showarea.width()*z, showarea.height()*z); + emit zoomTo(z,r.x()+r.width()/2, r.y()+r.height()/2); + return true; + } else { + return false; + } +} + +/*! + \qmlproperty int WebView::pressGrabTime + + The number of milliseconds the user must press before the WebView + starts passing move events through to the web engine (rather than + letting other QML elements such as a Flickable take them). + + Defaults to 400ms. Set to 0 to always grab and pass move events to + the web engine. +*/ +int QDeclarativeWebView::pressGrabTime() const +{ + Q_D(const QDeclarativeWebView); + return d->pressTime; +} + +void QDeclarativeWebView::setPressGrabTime(int ms) +{ + Q_D(QDeclarativeWebView); + if (d->pressTime == ms) + return; + d->pressTime = ms; + emit pressGrabTimeChanged(); +} + +void QDeclarativeWebView::mousePressEvent(QGraphicsSceneMouseEvent *event) +{ + Q_D(QDeclarativeWebView); + + setFocus (true); + QMouseEvent *me = sceneMouseEventToMouseEvent(event); + + d->pressPoint = me->pos(); + if (d->pressTime) { + d->pressTimer.start(d->pressTime,this); + setKeepMouseGrab(false); + } else { + grabMouse(); + setKeepMouseGrab(true); + } + + page()->event(me); + event->setAccepted( +/* + It is not correct to send the press event upwards, if it is not accepted by WebKit + e.g. push button does not work, if done so as QGraphicsScene will not send the release event at all to WebKit + Might be a bug in WebKit, though + */ +#if 1 //QT_VERSION <= 0x040500 // XXX see bug 230835 + true +#else + me->isAccepted() +#endif + ); + delete me; + if (!event->isAccepted()) { + QDeclarativePaintedItem::mousePressEvent(event); + } +} + +void QDeclarativeWebView::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +{ + Q_D(QDeclarativeWebView); + + QMouseEvent *me = sceneMouseEventToMouseEvent(event); + page()->event(me); + d->pressTimer.stop(); + event->setAccepted( +/* + It is not correct to send the press event upwards, if it is not accepted by WebKit + e.g. push button does not work, if done so as QGraphicsScene will not send all the events to WebKit + */ +#if 1 //QT_VERSION <= 0x040500 // XXX see bug 230835 + true +#else + me->isAccepted() +#endif + ); + delete me; + if (!event->isAccepted()) { + QDeclarativePaintedItem::mouseReleaseEvent(event); + } + setKeepMouseGrab(false); + ungrabMouse(); +} + +void QDeclarativeWebView::timerEvent(QTimerEvent *event) +{ + Q_D(QDeclarativeWebView); + if (event->timerId() == d->pressTimer.timerId()) { + d->pressTimer.stop(); + grabMouse(); + setKeepMouseGrab(true); + } +} + +void QDeclarativeWebView::mouseMoveEvent(QGraphicsSceneMouseEvent *event) +{ + Q_D(QDeclarativeWebView); + + QMouseEvent *me = sceneMouseEventToMouseEvent(event); + if (d->pressTimer.isActive()) { + if ((me->pos() - d->pressPoint).manhattanLength() > QApplication::startDragDistance()) { + d->pressTimer.stop(); + } + } + if (keepMouseGrab()) { + page()->event(me); + event->setAccepted( +/* + It is not correct to send the press event upwards, if it is not accepted by WebKit + e.g. push button does not work, if done so as QGraphicsScene will not send the release event at all to WebKit + Might be a bug in WebKit, though + */ +#if 1 // QT_VERSION <= 0x040500 // XXX see bug 230835 + true +#else + me->isAccepted() +#endif + ); + } + delete me; + if (!event->isAccepted()) + QDeclarativePaintedItem::mouseMoveEvent(event); + +} +void QDeclarativeWebView::hoverMoveEvent (QGraphicsSceneHoverEvent * event) +{ + QMouseEvent *me = sceneHoverMoveEventToMouseEvent(event); + page()->event(me); + event->setAccepted( +#if QT_VERSION <= 0x040500 // XXX see bug 230835 + true +#else + me->isAccepted() +#endif + ); + delete me; + if (!event->isAccepted()) + QDeclarativePaintedItem::hoverMoveEvent(event); +} + +void QDeclarativeWebView::keyPressEvent(QKeyEvent* event) +{ + page()->event(event); + if (!event->isAccepted()) + QDeclarativePaintedItem::keyPressEvent(event); +} + +void QDeclarativeWebView::keyReleaseEvent(QKeyEvent* event) +{ + page()->event(event); + if (!event->isAccepted()) + QDeclarativePaintedItem::keyReleaseEvent(event); +} + +bool QDeclarativeWebView::sceneEvent(QEvent *event) +{ + if (event->type() == QEvent::KeyPress) { + QKeyEvent *k = static_cast(event); + if (k->key() == Qt::Key_Tab || k->key() == Qt::Key_Backtab) { + if (!(k->modifiers() & (Qt::ControlModifier | Qt::AltModifier))) { //### Add MetaModifier? + page()->event(event); + if (event->isAccepted()) + return true; + } + } + } + return QDeclarativePaintedItem::sceneEvent(event); +} + + +/*! + \qmlproperty action WebView::back + This property holds the action for causing the previous URL in the history to be displayed. +*/ +QAction *QDeclarativeWebView::backAction() const +{ + return page()->action(QWebPage::Back); +} + +/*! + \qmlproperty action WebView::forward + This property holds the action for causing the next URL in the history to be displayed. +*/ +QAction *QDeclarativeWebView::forwardAction() const +{ + return page()->action(QWebPage::Forward); +} + +/*! + \qmlproperty action WebView::reload + This property holds the action for reloading with the current URL +*/ +QAction *QDeclarativeWebView::reloadAction() const +{ + return page()->action(QWebPage::Reload); +} + +/*! + \qmlproperty action WebView::stop + This property holds the action for stopping loading with the current URL +*/ +QAction *QDeclarativeWebView::stopAction() const +{ + return page()->action(QWebPage::Stop); +} + +/*! + \qmlproperty real WebView::title + This property holds the title of the web page currently viewed + + By default, this property contains an empty string. +*/ +QString QDeclarativeWebView::title() const +{ + return page()->mainFrame()->title(); +} + + + +/*! + \qmlproperty pixmap WebView::icon + This property holds the icon associated with the web page currently viewed +*/ +QPixmap QDeclarativeWebView::icon() const +{ + return page()->mainFrame()->icon().pixmap(QSize(256,256)); +} + + +/*! + \qmlproperty real WebView::zoomFactor + This property holds the multiplier used to scale the contents of a Web page. +*/ +void QDeclarativeWebView::setZoomFactor(qreal factor) +{ + Q_D(QDeclarativeWebView); + if (factor == page()->mainFrame()->zoomFactor()) + return; + + page()->mainFrame()->setZoomFactor(factor); + page()->setViewportSize(QSize( + d->preferredwidth>0 ? d->preferredwidth*factor : width()*factor, + d->preferredheight>0 ? d->preferredheight*factor : height()*factor)); + expandToWebPage(); + + emit zoomFactorChanged(); +} + +qreal QDeclarativeWebView::zoomFactor() const +{ + return page()->mainFrame()->zoomFactor(); +} + +/*! + \qmlproperty string WebView::statusText + + This property is the current status suggested by the current web page. In a web browser, + such status is often shown in some kind of status bar. +*/ +void QDeclarativeWebView::setStatusText(const QString& s) +{ + Q_D(QDeclarativeWebView); + d->statusText = s; + emit statusTextChanged(); +} + +void QDeclarativeWebView::windowObjectCleared() +{ + Q_D(QDeclarativeWebView); + d->updateWindowObjects(); +} + +QString QDeclarativeWebView::statusText() const +{ + Q_D(const QDeclarativeWebView); + return d->statusText; +} + +QWebPage *QDeclarativeWebView::page() const +{ + Q_D(const QDeclarativeWebView); + + if (!d->page) { + QDeclarativeWebView *self = const_cast(this); + QWebPage *wp = new QDeclarativeWebPage(self); + + // QML items don't default to having a background, + // even though most we pages will set one anyway. + QPalette pal = QApplication::palette(); + pal.setBrush(QPalette::Base, QColor::fromRgbF(0, 0, 0, 0)); + wp->setPalette(pal); + + wp->setNetworkAccessManager(qmlEngine(this)->networkAccessManager()); + + self->setPage(wp); + + return wp; + } + + return d->page; +} + + +// The QObject interface to settings(). +/*! + \qmlproperty string WebView::settings.standardFontFamily + \qmlproperty string WebView::settings.fixedFontFamily + \qmlproperty string WebView::settings.serifFontFamily + \qmlproperty string WebView::settings.sansSerifFontFamily + \qmlproperty string WebView::settings.cursiveFontFamily + \qmlproperty string WebView::settings.fantasyFontFamily + + \qmlproperty int WebView::settings.minimumFontSize + \qmlproperty int WebView::settings.minimumLogicalFontSize + \qmlproperty int WebView::settings.defaultFontSize + \qmlproperty int WebView::settings.defaultFixedFontSize + + \qmlproperty bool WebView::settings.autoLoadImages + \qmlproperty bool WebView::settings.javascriptEnabled + \qmlproperty bool WebView::settings.javaEnabled + \qmlproperty bool WebView::settings.pluginsEnabled + \qmlproperty bool WebView::settings.privateBrowsingEnabled + \qmlproperty bool WebView::settings.javascriptCanOpenWindows + \qmlproperty bool WebView::settings.javascriptCanAccessClipboard + \qmlproperty bool WebView::settings.developerExtrasEnabled + \qmlproperty bool WebView::settings.linksIncludedInFocusChain + \qmlproperty bool WebView::settings.zoomTextOnly + \qmlproperty bool WebView::settings.printElementBackgrounds + \qmlproperty bool WebView::settings.offlineStorageDatabaseEnabled + \qmlproperty bool WebView::settings.offlineWebApplicationCacheEnabled + \qmlproperty bool WebView::settings.localStorageDatabaseEnabled + \qmlproperty bool WebView::settings.localContentCanAccessRemoteUrls + + These properties give access to the settings controlling the web view. + + See QWebSettings for details of these properties. + + \qml + WebView { + settings.pluginsEnabled: true + settings.standardFontFamily: "Arial" + ... + } + \endqml +*/ +QObject *QDeclarativeWebView::settingsObject() const +{ + Q_D(const QDeclarativeWebView); + d->settings.s = page()->settings(); + return &d->settings; +} + +void QDeclarativeWebView::setPage(QWebPage *page) +{ + Q_D(QDeclarativeWebView); + if (d->page == page) + return; + if (d->page) { + if (d->page->parent() == this) { + delete d->page; + } else { + d->page->disconnect(this); + } + } + d->page = page; + d->page->setViewportSize(QSize( + d->preferredwidth>0 ? d->preferredwidth : width(), + d->preferredheight>0 ? d->preferredheight : height())); + d->page->mainFrame()->setScrollBarPolicy(Qt::Horizontal,Qt::ScrollBarAlwaysOff); + d->page->mainFrame()->setScrollBarPolicy(Qt::Vertical,Qt::ScrollBarAlwaysOff); + connect(d->page,SIGNAL(repaintRequested(QRect)),this,SLOT(paintPage(QRect))); + connect(d->page->mainFrame(),SIGNAL(urlChanged(QUrl)),this,SLOT(pageUrlChanged())); + connect(d->page->mainFrame(), SIGNAL(titleChanged(QString)), this, SIGNAL(titleChanged(QString))); + connect(d->page->mainFrame(), SIGNAL(titleChanged(QString)), this, SIGNAL(iconChanged())); + connect(d->page->mainFrame(), SIGNAL(iconChanged()), this, SIGNAL(iconChanged())); + connect(d->page->mainFrame(), SIGNAL(contentsSizeChanged(QSize)), this, SLOT(noteContentsSizeChanged(QSize))); + connect(d->page->mainFrame(), SIGNAL(initialLayoutCompleted()), this, SLOT(initialLayout())); + + connect(d->page,SIGNAL(loadStarted()),this,SLOT(doLoadStarted())); + connect(d->page,SIGNAL(loadProgress(int)),this,SLOT(doLoadProgress(int))); + connect(d->page,SIGNAL(loadFinished(bool)),this,SLOT(doLoadFinished(bool))); + connect(d->page,SIGNAL(statusBarMessage(QString)),this,SLOT(setStatusText(QString))); + + connect(d->page->mainFrame(),SIGNAL(javaScriptWindowObjectCleared()),this,SLOT(windowObjectCleared())); +} + +/*! + \qmlsignal WebView::onLoadStarted() + + This handler is called when the web engine begins loading + a page. Later, WebView::onLoadFinished() or WebView::onLoadFailed() + will be emitted. +*/ + +/*! + \qmlsignal WebView::onLoadFinished() + + This handler is called when the web engine \e successfully + finishes loading a page, including any component content + (WebView::onLoadFailed() will be emitted otherwise). + + \sa progress +*/ + +/*! + \qmlsignal WebView::onLoadFailed() + + This handler is called when the web engine fails loading + a page or any component content + (WebView::onLoadFinished() will be emitted on success). +*/ + +void QDeclarativeWebView::load(const QNetworkRequest &request, + QNetworkAccessManager::Operation operation, + const QByteArray &body) +{ + page()->mainFrame()->load(request, operation, body); +} + +QString QDeclarativeWebView::html() const +{ + return page()->mainFrame()->toHtml(); +} + +/*! + \qmlproperty string WebView::html + This property holds HTML text set directly + + The html property can be set as a string. + + \qml + WebView { + html: "

This is HTML." + } + \endqml +*/ +void QDeclarativeWebView::setHtml(const QString &html, const QUrl &baseUrl) +{ + Q_D(QDeclarativeWebView); + page()->setViewportSize(QSize( + d->preferredwidth>0 ? d->preferredwidth : width(), + d->preferredheight>0 ? d->preferredheight : height())); + if (isComponentComplete()) + page()->mainFrame()->setHtml(html, baseUrl); + else { + d->pending = d->PendingHtml; + d->pending_url = baseUrl; + d->pending_string = html; + } + emit htmlChanged(); +} + +void QDeclarativeWebView::setContent(const QByteArray &data, const QString &mimeType, const QUrl &baseUrl) +{ + Q_D(QDeclarativeWebView); + page()->setViewportSize(QSize( + d->preferredwidth>0 ? d->preferredwidth : width(), + d->preferredheight>0 ? d->preferredheight : height())); + + if (isComponentComplete()) + page()->mainFrame()->setContent(data,mimeType,qmlContext(this)->resolvedUrl(baseUrl)); + else { + d->pending = d->PendingContent; + d->pending_url = baseUrl; + d->pending_string = mimeType; + d->pending_data = data; + } +} + +QWebHistory *QDeclarativeWebView::history() const +{ + return page()->history(); +} + +QWebSettings *QDeclarativeWebView::settings() const +{ + return page()->settings(); +} + +QDeclarativeWebView *QDeclarativeWebView::createWindow(QWebPage::WebWindowType type) +{ + Q_D(QDeclarativeWebView); + switch (type) { + case QWebPage::WebBrowserWindow: { + if (!d->newWindowComponent && d->newWindowParent) + qWarning("WebView::newWindowComponent not set - WebView::newWindowParent ignored"); + else if (d->newWindowComponent && !d->newWindowParent) + qWarning("WebView::newWindowParent not set - WebView::newWindowComponent ignored"); + else if (d->newWindowComponent && d->newWindowParent) { + QDeclarativeWebView *webview = 0; + QDeclarativeContext *windowContext = new QDeclarativeContext(qmlContext(this)); + + QObject *nobj = d->newWindowComponent->create(windowContext); + if (nobj) { + windowContext->setParent(nobj); + QDeclarativeItem *item = qobject_cast(nobj); + if (!item) { + delete nobj; + } else { + webview = item->findChild(); + if (!webview) { + delete item; + } else { + nobj->setParent(d->newWindowParent); + static_cast(item)->setParentItem(d->newWindowParent); + } + } + } else { + delete windowContext; + } + + return webview; + } + } + break; + case QWebPage::WebModalDialog: { + // Not supported + } + } + return 0; +} + +/*! + \qmlproperty component WebView::newWindowComponent + + This property holds the component to use for new windows. + The component must have a WebView somewhere in its structure. + + When the web engine requests a new window, it will be an instance of + this component. + + The parent of the new window is set by newWindowParent. It must be set. +*/ +QDeclarativeComponent *QDeclarativeWebView::newWindowComponent() const +{ + Q_D(const QDeclarativeWebView); + return d->newWindowComponent; +} + +void QDeclarativeWebView::setNewWindowComponent(QDeclarativeComponent *newWindow) +{ + Q_D(QDeclarativeWebView); + if (newWindow == d->newWindowComponent) + return; + d->newWindowComponent = newWindow; + emit newWindowComponentChanged(); +} + + +/*! + \qmlproperty item WebView::newWindowParent + + The parent item for new windows. + + \sa newWindowComponent +*/ +QDeclarativeItem *QDeclarativeWebView::newWindowParent() const +{ + Q_D(const QDeclarativeWebView); + return d->newWindowParent; +} + +void QDeclarativeWebView::setNewWindowParent(QDeclarativeItem *parent) +{ + Q_D(QDeclarativeWebView); + if (parent == d->newWindowParent) + return; + if (d->newWindowParent && parent) { + QList children = d->newWindowParent->childItems(); + for (int i = 0; i < children.count(); ++i) { + children.at(i)->setParentItem(parent); + } + } + d->newWindowParent = parent; + emit newWindowParentChanged(); +} + +/*! + Returns the area of the largest element at position (\a x,\a y) that is no larger + than \a maxwidth by \a maxheight pixels. + + May return an area larger in the case when no smaller element is at the position. +*/ +QRect QDeclarativeWebView::elementAreaAt(int x, int y, int maxwidth, int maxheight) const +{ + QWebHitTestResult hit = page()->mainFrame()->hitTestContent(QPoint(x,y)); + QRect rv = hit.boundingRect(); + QWebElement element = hit.enclosingBlockElement(); + if (maxwidth<=0) maxwidth = INT_MAX; + if (maxheight<=0) maxheight = INT_MAX; + while (!element.parent().isNull() && element.geometry().width() <= maxwidth && element.geometry().height() <= maxheight) { + rv = element.geometry(); + element = element.parent(); + } + return rv; +} + +/*! + \internal + \class QDeclarativeWebPage + \brief The QDeclarativeWebPage class is a QWebPage that can create QML plugins. + + \sa QDeclarativeWebView +*/ +QDeclarativeWebPage::QDeclarativeWebPage(QDeclarativeWebView *parent) : + QWebPage(parent) +{ +} + +QDeclarativeWebPage::~QDeclarativeWebPage() +{ +} + +void QDeclarativeWebPage::javaScriptConsoleMessage(const QString& message, int lineNumber, const QString& sourceID) +{ + qWarning() << sourceID << ':' << lineNumber << ':' << message; +} + +QString QDeclarativeWebPage::chooseFile(QWebFrame *originatingFrame, const QString& oldFile) +{ + // Not supported (it's modal) + Q_UNUSED(originatingFrame) + Q_UNUSED(oldFile) + return oldFile; +} + +void QDeclarativeWebPage::javaScriptAlert(QWebFrame *originatingFrame, const QString& msg) +{ + Q_UNUSED(originatingFrame) + emit viewItem()->alert(msg); +} + +bool QDeclarativeWebPage::javaScriptConfirm(QWebFrame *originatingFrame, const QString& msg) +{ + // Not supported (it's modal) + Q_UNUSED(originatingFrame) + Q_UNUSED(msg) + return false; +} + +bool QDeclarativeWebPage::javaScriptPrompt(QWebFrame *originatingFrame, const QString& msg, const QString& defaultValue, QString* result) +{ + // Not supported (it's modal) + Q_UNUSED(originatingFrame) + Q_UNUSED(msg) + Q_UNUSED(defaultValue) + Q_UNUSED(result) + return false; +} + + +/* + Qt WebKit does not understand non-QWidget plugins, so dummy widgets + are created, parented to a single dummy tool window. + + The requirements for QML object plugins are input to the Qt WebKit + non-QWidget plugin support, which will obsolete this kludge. +*/ +class QWidget_Dummy_Plugin : public QWidget +{ + Q_OBJECT +public: + static QWidget *dummy_shared_parent() + { + static QWidget *dsp = 0; + if (!dsp) { + dsp = new QWidget(0,Qt::Tool); + dsp->setGeometry(-10000,-10000,0,0); + dsp->show(); + } + return dsp; + } + QWidget_Dummy_Plugin(const QUrl& url, QDeclarativeWebView *view, const QStringList ¶mNames, const QStringList ¶mValues) : + QWidget(dummy_shared_parent()), + propertyNames(paramNames), + propertyValues(paramValues), + webview(view) + { + QDeclarativeEngine *engine = qmlEngine(webview); + component = new QDeclarativeComponent(engine, url, this); + item = 0; + if (component->isLoading()) + connect(component, SIGNAL(statusChanged(QDeclarativeComponent::Status)), this, SLOT(qmlLoaded())); + else + qmlLoaded(); + } + +public Q_SLOTS: + void qmlLoaded() + { + if (component->isError()) { + // ### Could instead give these errors to the WebView to handle. + qWarning() << component->errors(); + return; + } + item = qobject_cast(component->create(qmlContext(webview))); + item->setParent(webview); + QString jsObjName; + for (int i=0; isetProperty(propertyNames[i].toUtf8(),propertyValues[i]); + if (propertyNames[i] == QLatin1String("objectname")) + jsObjName = propertyValues[i]; + } + } + if (!jsObjName.isNull()) { + QWebFrame *f = webview->page()->mainFrame(); + f->addToJavaScriptWindowObject(jsObjName, item); + } + resizeEvent(0); + delete component; + component = 0; + } + void resizeEvent(QResizeEvent*) + { + if (item) { + item->setX(x()); + item->setY(y()); + item->setWidth(width()); + item->setHeight(height()); + } + } + +private: + QDeclarativeComponent *component; + QDeclarativeItem *item; + QStringList propertyNames, propertyValues; + QDeclarativeWebView *webview; +}; + +QDeclarativeWebView *QDeclarativeWebPage::viewItem() +{ + return static_cast(parent()); +} + +QObject *QDeclarativeWebPage::createPlugin(const QString &, const QUrl &url, const QStringList ¶mNames, const QStringList ¶mValues) +{ + QUrl comp = qmlContext(viewItem())->resolvedUrl(url); + return new QWidget_Dummy_Plugin(comp,viewItem(),paramNames,paramValues); +} + +QWebPage *QDeclarativeWebPage::createWindow(WebWindowType type) +{ + QDeclarativeWebView *newView = viewItem()->createWindow(type); + if (newView) + return newView->page(); + return 0; +} + +QT_END_NAMESPACE + +#include diff --git a/src/declarative/imports/webkit/qdeclarativewebview_p.h b/src/declarative/imports/webkit/qdeclarativewebview_p.h new file mode 100644 index 0000000..0bb5d29 --- /dev/null +++ b/src/declarative/imports/webkit/qdeclarativewebview_p.h @@ -0,0 +1,285 @@ +/**************************************************************************** +** +** 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 QDECLARATIVEWEBVIEW_H +#define QDECLARATIVEWEBVIEW_H + +#include + +#include +#include +#include +#include + +QT_BEGIN_HEADER + +class QWebHistory; +class QWebSettings; + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) +class QDeclarativeWebViewPrivate; +class QNetworkRequest; +class QDeclarativeWebView; + +class Q_DECLARATIVE_EXPORT QDeclarativeWebPage : public QWebPage +{ + Q_OBJECT +public: + explicit QDeclarativeWebPage(QDeclarativeWebView *parent); + ~QDeclarativeWebPage(); +protected: + QObject *createPlugin(const QString &classid, const QUrl &url, const QStringList ¶mNames, const QStringList ¶mValues); + QWebPage *createWindow(WebWindowType type); + void javaScriptConsoleMessage(const QString& message, int lineNumber, const QString& sourceID); + QString chooseFile(QWebFrame *originatingFrame, const QString& oldFile); + void javaScriptAlert(QWebFrame *originatingFrame, const QString& msg); + bool javaScriptConfirm(QWebFrame *originatingFrame, const QString& msg); + bool javaScriptPrompt(QWebFrame *originatingFrame, const QString& msg, const QString& defaultValue, QString* result); + +private: + QDeclarativeWebView *viewItem(); +}; + + +class QDeclarativeWebViewAttached; + +//### TODO: browser plugins + +class Q_DECLARATIVE_EXPORT QDeclarativeWebView : public QDeclarativePaintedItem +{ + Q_OBJECT + + Q_ENUMS(Status SelectionMode) + + Q_PROPERTY(QString title READ title NOTIFY titleChanged) + Q_PROPERTY(QPixmap icon READ icon NOTIFY iconChanged) + Q_PROPERTY(qreal zoomFactor READ zoomFactor WRITE setZoomFactor NOTIFY zoomFactorChanged) + Q_PROPERTY(QString statusText READ statusText NOTIFY statusTextChanged) + + Q_PROPERTY(QString html READ html WRITE setHtml NOTIFY htmlChanged) + + Q_PROPERTY(int pressGrabTime READ pressGrabTime WRITE setPressGrabTime NOTIFY pressGrabTimeChanged) + + Q_PROPERTY(int preferredWidth READ preferredWidth WRITE setPreferredWidth NOTIFY preferredWidthChanged) + Q_PROPERTY(int preferredHeight READ preferredHeight WRITE setPreferredHeight NOTIFY preferredHeightChanged) + Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY urlChanged) + Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged) + Q_PROPERTY(Status status READ status NOTIFY statusChanged) + + Q_PROPERTY(QAction* reload READ reloadAction CONSTANT) + Q_PROPERTY(QAction* back READ backAction CONSTANT) + Q_PROPERTY(QAction* forward READ forwardAction CONSTANT) + Q_PROPERTY(QAction* stop READ stopAction CONSTANT) + + Q_PROPERTY(QObject* settings READ settingsObject CONSTANT) + + Q_PROPERTY(QDeclarativeListProperty javaScriptWindowObjects READ javaScriptWindowObjects CONSTANT) + + Q_PROPERTY(QDeclarativeComponent* newWindowComponent READ newWindowComponent WRITE setNewWindowComponent NOTIFY newWindowComponentChanged) + Q_PROPERTY(QDeclarativeItem* newWindowParent READ newWindowParent WRITE setNewWindowParent NOTIFY newWindowParentChanged) + + Q_PROPERTY(bool renderingEnabled READ renderingEnabled WRITE setRenderingEnabled NOTIFY renderingEnabledChanged) + +public: + QDeclarativeWebView(QDeclarativeItem *parent=0); + ~QDeclarativeWebView(); + + QUrl url() const; + void setUrl(const QUrl &); + + QString title() const; + + QPixmap icon() const; + + qreal zoomFactor() const; + void setZoomFactor(qreal); + Q_INVOKABLE bool heuristicZoom(int clickX, int clickY, qreal maxzoom); + QRect elementAreaAt(int x, int y, int minwidth, int minheight) const; + + int pressGrabTime() const; + void setPressGrabTime(int); + + int preferredWidth() const; + void setPreferredWidth(int); + int preferredHeight() const; + void setPreferredHeight(int); + + enum Status { Null, Ready, Loading, Error }; + Status status() const; + qreal progress() const; + QString statusText() const; + + QAction *reloadAction() const; + QAction *backAction() const; + QAction *forwardAction() const; + QAction *stopAction() const; + + QWebPage *page() const; + void setPage(QWebPage *page); + + void load(const QNetworkRequest &request, + QNetworkAccessManager::Operation operation = QNetworkAccessManager::GetOperation, + const QByteArray &body = QByteArray()); + + QString html() const; + + void setHtml(const QString &html, const QUrl &baseUrl = QUrl()); + void setContent(const QByteArray &data, const QString &mimeType = QString(), const QUrl &baseUrl = QUrl()); + + QWebHistory *history() const; + QWebSettings *settings() const; + QObject *settingsObject() const; + + bool renderingEnabled() const; + void setRenderingEnabled(bool); + + QDeclarativeListProperty javaScriptWindowObjects(); + + static QDeclarativeWebViewAttached *qmlAttachedProperties(QObject *); + + QDeclarativeComponent *newWindowComponent() const; + void setNewWindowComponent(QDeclarativeComponent *newWindow); + QDeclarativeItem *newWindowParent() const; + void setNewWindowParent(QDeclarativeItem *newWindow); + +Q_SIGNALS: + void preferredWidthChanged(); + void preferredHeightChanged(); + void urlChanged(); + void progressChanged(); + void statusChanged(Status); + void titleChanged(const QString&); + void iconChanged(); + void statusTextChanged(); + void htmlChanged(); + void pressGrabTimeChanged(); + void zoomFactorChanged(); + void newWindowComponentChanged(); + void newWindowParentChanged(); + void renderingEnabledChanged(); + + void loadStarted(); + void loadFinished(); + void loadFailed(); + + void doubleClick(int clickX, int clickY); + + void zoomTo(qreal zoom, int centerX, int centerY); + + void alert(const QString& message); + +public Q_SLOTS: + QVariant evaluateJavaScript(const QString&); + +private Q_SLOTS: + void expandToWebPage(); + void paintPage(const QRect&); + void doLoadStarted(); + void doLoadProgress(int p); + void doLoadFinished(bool ok); + void setStatusText(const QString&); + void windowObjectCleared(); + void pageUrlChanged(); + void noteContentsSizeChanged(const QSize&); + void initialLayout(); + +protected: + void drawContents(QPainter *, const QRect &); + + void mousePressEvent(QGraphicsSceneMouseEvent *event); + void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); + void mouseMoveEvent(QGraphicsSceneMouseEvent *event); + void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); + void timerEvent(QTimerEvent *event); + void hoverMoveEvent (QGraphicsSceneHoverEvent * event); + void keyPressEvent(QKeyEvent* event); + void keyReleaseEvent(QKeyEvent* event); + virtual void geometryChanged(const QRectF &newGeometry, + const QRectF &oldGeometry); + virtual void focusChanged(bool); + virtual bool sceneEvent(QEvent *event); + QDeclarativeWebView *createWindow(QWebPage::WebWindowType type); + +private: + void init(); + virtual void componentComplete(); + Q_DISABLE_COPY(QDeclarativeWebView) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarativeWebView) + QMouseEvent *sceneMouseEventToMouseEvent(QGraphicsSceneMouseEvent *); + QMouseEvent *sceneHoverMoveEventToMouseEvent(QGraphicsSceneHoverEvent *); + friend class QDeclarativeWebPage; +}; + +class QDeclarativeWebViewAttached : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString windowObjectName READ windowObjectName WRITE setWindowObjectName) +public: + QDeclarativeWebViewAttached(QObject *parent) + : QObject(parent) + { + } + + QString windowObjectName() const + { + return m_windowObjectName; + } + + void setWindowObjectName(const QString &n) + { + m_windowObjectName = n; + } + +private: + QString m_windowObjectName; +}; + + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QDeclarativeWebView) +QML_DECLARE_TYPEINFO(QDeclarativeWebView, QML_HAS_ATTACHED_PROPERTIES) + +QT_END_HEADER + +#endif diff --git a/src/declarative/imports/webkit/qdeclarativewebview_p_p.h b/src/declarative/imports/webkit/qdeclarativewebview_p_p.h new file mode 100644 index 0000000..258b472 --- /dev/null +++ b/src/declarative/imports/webkit/qdeclarativewebview_p_p.h @@ -0,0 +1,151 @@ +/**************************************************************************** +** +** 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 QDECLARATIVEWEBVIEW_P_H +#define QDECLARATIVEWEBVIEW_P_H + +#include + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QDeclarativeWebSettings : public QObject { + Q_OBJECT + + Q_PROPERTY(QString standardFontFamily READ standardFontFamily WRITE setStandardFontFamily) + Q_PROPERTY(QString fixedFontFamily READ fixedFontFamily WRITE setFixedFontFamily) + Q_PROPERTY(QString serifFontFamily READ serifFontFamily WRITE setSerifFontFamily) + Q_PROPERTY(QString sansSerifFontFamily READ sansSerifFontFamily WRITE setSansSerifFontFamily) + Q_PROPERTY(QString cursiveFontFamily READ cursiveFontFamily WRITE setCursiveFontFamily) + Q_PROPERTY(QString fantasyFontFamily READ fantasyFontFamily WRITE setFantasyFontFamily) + + Q_PROPERTY(int minimumFontSize READ minimumFontSize WRITE setMinimumFontSize) + Q_PROPERTY(int minimumLogicalFontSize READ minimumLogicalFontSize WRITE setMinimumLogicalFontSize) + Q_PROPERTY(int defaultFontSize READ defaultFontSize WRITE setDefaultFontSize) + Q_PROPERTY(int defaultFixedFontSize READ defaultFixedFontSize WRITE setDefaultFixedFontSize) + + Q_PROPERTY(bool autoLoadImages READ autoLoadImages WRITE setAutoLoadImages) + Q_PROPERTY(bool javascriptEnabled READ javascriptEnabled WRITE setJavascriptEnabled) + Q_PROPERTY(bool javaEnabled READ javaEnabled WRITE setJavaEnabled) + Q_PROPERTY(bool pluginsEnabled READ pluginsEnabled WRITE setPluginsEnabled) + Q_PROPERTY(bool privateBrowsingEnabled READ privateBrowsingEnabled WRITE setPrivateBrowsingEnabled) + Q_PROPERTY(bool javascriptCanOpenWindows READ javascriptCanOpenWindows WRITE setJavascriptCanOpenWindows) + Q_PROPERTY(bool javascriptCanAccessClipboard READ javascriptCanAccessClipboard WRITE setJavascriptCanAccessClipboard) + Q_PROPERTY(bool developerExtrasEnabled READ developerExtrasEnabled WRITE setDeveloperExtrasEnabled) + Q_PROPERTY(bool linksIncludedInFocusChain READ linksIncludedInFocusChain WRITE setLinksIncludedInFocusChain) + Q_PROPERTY(bool zoomTextOnly READ zoomTextOnly WRITE setZoomTextOnly) + Q_PROPERTY(bool printElementBackgrounds READ printElementBackgrounds WRITE setPrintElementBackgrounds) + Q_PROPERTY(bool offlineStorageDatabaseEnabled READ offlineStorageDatabaseEnabled WRITE setOfflineStorageDatabaseEnabled) + Q_PROPERTY(bool offlineWebApplicationCacheEnabled READ offlineWebApplicationCacheEnabled WRITE setOfflineWebApplicationCacheEnabled) + Q_PROPERTY(bool localStorageDatabaseEnabled READ localStorageDatabaseEnabled WRITE setLocalStorageDatabaseEnabled) + Q_PROPERTY(bool localContentCanAccessRemoteUrls READ localContentCanAccessRemoteUrls WRITE setLocalContentCanAccessRemoteUrls) + +public: + QDeclarativeWebSettings() {} + + QString standardFontFamily() const { return s->fontFamily(QWebSettings::StandardFont); } + void setStandardFontFamily(const QString& f) { s->setFontFamily(QWebSettings::StandardFont,f); } + QString fixedFontFamily() const { return s->fontFamily(QWebSettings::FixedFont); } + void setFixedFontFamily(const QString& f) { s->setFontFamily(QWebSettings::FixedFont,f); } + QString serifFontFamily() const { return s->fontFamily(QWebSettings::SerifFont); } + void setSerifFontFamily(const QString& f) { s->setFontFamily(QWebSettings::SerifFont,f); } + QString sansSerifFontFamily() const { return s->fontFamily(QWebSettings::SansSerifFont); } + void setSansSerifFontFamily(const QString& f) { s->setFontFamily(QWebSettings::SansSerifFont,f); } + QString cursiveFontFamily() const { return s->fontFamily(QWebSettings::CursiveFont); } + void setCursiveFontFamily(const QString& f) { s->setFontFamily(QWebSettings::CursiveFont,f); } + QString fantasyFontFamily() const { return s->fontFamily(QWebSettings::FantasyFont); } + void setFantasyFontFamily(const QString& f) { s->setFontFamily(QWebSettings::FantasyFont,f); } + + int minimumFontSize() const { return s->fontSize(QWebSettings::MinimumFontSize); } + void setMinimumFontSize(int size) { s->setFontSize(QWebSettings::MinimumFontSize,size); } + int minimumLogicalFontSize() const { return s->fontSize(QWebSettings::MinimumLogicalFontSize); } + void setMinimumLogicalFontSize(int size) { s->setFontSize(QWebSettings::MinimumLogicalFontSize,size); } + int defaultFontSize() const { return s->fontSize(QWebSettings::DefaultFontSize); } + void setDefaultFontSize(int size) { s->setFontSize(QWebSettings::DefaultFontSize,size); } + int defaultFixedFontSize() const { return s->fontSize(QWebSettings::DefaultFixedFontSize); } + void setDefaultFixedFontSize(int size) { s->setFontSize(QWebSettings::DefaultFixedFontSize,size); } + + bool autoLoadImages() const { return s->testAttribute(QWebSettings::AutoLoadImages); } + void setAutoLoadImages(bool on) { s->setAttribute(QWebSettings::AutoLoadImages, on); } + bool javascriptEnabled() const { return s->testAttribute(QWebSettings::JavascriptEnabled); } + void setJavascriptEnabled(bool on) { s->setAttribute(QWebSettings::JavascriptEnabled, on); } + bool javaEnabled() const { return s->testAttribute(QWebSettings::JavaEnabled); } + void setJavaEnabled(bool on) { s->setAttribute(QWebSettings::JavaEnabled, on); } + bool pluginsEnabled() const { return s->testAttribute(QWebSettings::PluginsEnabled); } + void setPluginsEnabled(bool on) { s->setAttribute(QWebSettings::PluginsEnabled, on); } + bool privateBrowsingEnabled() const { return s->testAttribute(QWebSettings::PrivateBrowsingEnabled); } + void setPrivateBrowsingEnabled(bool on) { s->setAttribute(QWebSettings::PrivateBrowsingEnabled, on); } + bool javascriptCanOpenWindows() const { return s->testAttribute(QWebSettings::JavascriptCanOpenWindows); } + void setJavascriptCanOpenWindows(bool on) { s->setAttribute(QWebSettings::JavascriptCanOpenWindows, on); } + bool javascriptCanAccessClipboard() const { return s->testAttribute(QWebSettings::JavascriptCanAccessClipboard); } + void setJavascriptCanAccessClipboard(bool on) { s->setAttribute(QWebSettings::JavascriptCanAccessClipboard, on); } + bool developerExtrasEnabled() const { return s->testAttribute(QWebSettings::DeveloperExtrasEnabled); } + void setDeveloperExtrasEnabled(bool on) { s->setAttribute(QWebSettings::DeveloperExtrasEnabled, on); } + bool linksIncludedInFocusChain() const { return s->testAttribute(QWebSettings::LinksIncludedInFocusChain); } + void setLinksIncludedInFocusChain(bool on) { s->setAttribute(QWebSettings::LinksIncludedInFocusChain, on); } + bool zoomTextOnly() const { return s->testAttribute(QWebSettings::ZoomTextOnly); } + void setZoomTextOnly(bool on) { s->setAttribute(QWebSettings::ZoomTextOnly, on); } + bool printElementBackgrounds() const { return s->testAttribute(QWebSettings::PrintElementBackgrounds); } + void setPrintElementBackgrounds(bool on) { s->setAttribute(QWebSettings::PrintElementBackgrounds, on); } + bool offlineStorageDatabaseEnabled() const { return s->testAttribute(QWebSettings::OfflineStorageDatabaseEnabled); } + void setOfflineStorageDatabaseEnabled(bool on) { s->setAttribute(QWebSettings::OfflineStorageDatabaseEnabled, on); } + bool offlineWebApplicationCacheEnabled() const { return s->testAttribute(QWebSettings::OfflineWebApplicationCacheEnabled); } + void setOfflineWebApplicationCacheEnabled(bool on) { s->setAttribute(QWebSettings::OfflineWebApplicationCacheEnabled, on); } + bool localStorageDatabaseEnabled() const { return s->testAttribute(QWebSettings::LocalStorageDatabaseEnabled); } + void setLocalStorageDatabaseEnabled(bool on) { s->setAttribute(QWebSettings::LocalStorageDatabaseEnabled, on); } + bool localContentCanAccessRemoteUrls() const { return s->testAttribute(QWebSettings::LocalContentCanAccessRemoteUrls); } + void setLocalContentCanAccessRemoteUrls(bool on) { s->setAttribute(QWebSettings::LocalContentCanAccessRemoteUrls, on); } + + QWebSettings *s; +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QDeclarativeWebSettings) + +QT_END_HEADER + +#endif diff --git a/src/declarative/imports/webkit/webkit.pro b/src/declarative/imports/webkit/webkit.pro new file mode 100644 index 0000000..7ad8564 --- /dev/null +++ b/src/declarative/imports/webkit/webkit.pro @@ -0,0 +1,18 @@ +TARGET = webkitqmlplugin +include(../qimportbase.pri) + +contains(QT_CONFIG, webkit) { + QT += webkit declarative + + SOURCES += qdeclarativewebview.cpp plugin.cpp + HEADERS += qdeclarativewebview_p.h + HEADERS += qdeclarativewebview_p_p.h + + QTDIR_build:DESTDIR = $$QT_BUILD_TREE/imports/org/webkit + target.path = $$[QT_INSTALL_IMPORTS]/org/webkit + + qmldir.files += $$QT_BUILD_TREE/imports/org/webkit/qmldir + qmldir.path += $$[QT_INSTALL_IMPORTS]/org/webkit + + INSTALLS += target qmldir +} diff --git a/src/declarative/imports/widgets/graphicslayouts.cpp b/src/declarative/imports/widgets/graphicslayouts.cpp new file mode 100644 index 0000000..fc15ad2 --- /dev/null +++ b/src/declarative/imports/widgets/graphicslayouts.cpp @@ -0,0 +1,260 @@ +/**************************************************************************** +** +** 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 +#include + +QT_BEGIN_NAMESPACE + +LinearLayoutAttached::LinearLayoutAttached(QObject *parent) +: QObject(parent), _stretch(1), _alignment(Qt::AlignCenter) +{ +} + +void LinearLayoutAttached::setStretchFactor(int f) +{ + if (_stretch == f) + return; + + _stretch = f; + emit stretchChanged(reinterpret_cast(parent()), _stretch); +} + +void LinearLayoutAttached::setAlignment(Qt::Alignment a) +{ + if (_alignment == a) + return; + + _alignment = a; + emit alignmentChanged(reinterpret_cast(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()); + 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))); + //### 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); +} + +void QGraphicsLinearLayoutObject::updateStretch(QGraphicsLayoutItem *item, int stretch) +{ +QGraphicsLinearLayout::setStretchFactor(item, stretch); +} + +void QGraphicsLinearLayoutObject::updateAlignment(QGraphicsLayoutItem *item, Qt::Alignment alignment) +{ +QGraphicsLinearLayout::setAlignment(item, alignment); +} + +QHash QGraphicsLinearLayoutObject::attachedProperties; +LinearLayoutAttached *QGraphicsLinearLayoutObject::qmlAttachedProperties(QObject *obj) +{ +// ### This is not allowed - you must attach to any object +if (!qobject_cast(obj)) + return 0; +LinearLayoutAttached *rv = new LinearLayoutAttached(obj); +attachedProperties.insert(qobject_cast(obj), rv); +return rv; +} + +////////////////////////////////////////////////////////////////////////////////////////////////////// +// QGraphicsGridLayout-related classes +////////////////////////////////////////////////////////////////////////////////////////////////////// +GridLayoutAttached::GridLayoutAttached(QObject *parent) +: QObject(parent), _row(-1), _column(-1), _rowspan(1), _colspan(1), _alignment(-1) +{ +} + +void GridLayoutAttached::setRow(int r) +{ + if (_row == r) + return; + + _row = r; + //emit rowChanged(reinterpret_cast(parent()), _row); +} + +void GridLayoutAttached::setColumn(int c) +{ + if (_column == c) + return; + + _column = c; + //emit columnChanged(reinterpret_cast(parent()), _column); +} + +void GridLayoutAttached::setRowSpan(int rs) +{ + if (_rowspan == rs) + return; + + _rowspan = rs; + //emit rowSpanChanged(reinterpret_cast(parent()), _rowSpan); +} + +void GridLayoutAttached::setColumnSpan(int cs) +{ + if (_colspan == cs) + return; + + _colspan = cs; + //emit columnSpanChanged(reinterpret_cast(parent()), _columnSpan); +} + +void GridLayoutAttached::setAlignment(Qt::Alignment a) +{ + if (_alignment == a) + return; + + _alignment = a; + //emit alignmentChanged(reinterpret_cast(parent()), _alignment); +} + +QGraphicsGridLayoutObject::QGraphicsGridLayoutObject(QObject *parent) +: QObject(parent) +{ +} + +QGraphicsGridLayoutObject::~QGraphicsGridLayoutObject() +{ +} + +void QGraphicsGridLayoutObject::addWidget(QGraphicsWidget *wid) +{ +//use attached properties +if (QObject *obj = attachedProperties.value(qobject_cast(wid))) { + int row = static_cast(obj)->row(); + int column = static_cast(obj)->column(); + int rowSpan = static_cast(obj)->rowSpan(); + int columnSpan = static_cast(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; + } + addItem(item, row, column, rowSpan, columnSpan); + if (alignment != -1) + setAlignment(item,alignment); +} +} + +//### 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; //### +} + +QHash QGraphicsGridLayoutObject::attachedProperties; +GridLayoutAttached *QGraphicsGridLayoutObject::qmlAttachedProperties(QObject *obj) +{ +// ### This is not allowed - you must attach to any object +if (!qobject_cast(obj)) + return 0; +GridLayoutAttached *rv = new GridLayoutAttached(obj); +attachedProperties.insert(qobject_cast(obj), rv); +return rv; +} + +QT_END_NAMESPACE diff --git a/src/declarative/imports/widgets/graphicslayouts_p.h b/src/declarative/imports/widgets/graphicslayouts_p.h new file mode 100644 index 0000000..f9b9ae8 --- /dev/null +++ b/src/declarative/imports/widgets/graphicslayouts_p.h @@ -0,0 +1,226 @@ +/**************************************************************************** +** +** 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 "graphicswidgets_p.h" + +#include +#include + +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 children READ children) + Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation) + Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing) + Q_CLASSINFO("DefaultProperty", "children") +public: + QGraphicsLinearLayoutObject(QObject * = 0); + ~QGraphicsLinearLayoutObject(); + + QDeclarativeListProperty children() { return QDeclarativeListProperty(this, 0, children_append, children_count, children_at, children_clear); } + + static LinearLayoutAttached *qmlAttachedProperties(QObject *); + +private Q_SLOTS: + void updateStretch(QGraphicsLayoutItem*,int); + void updateAlignment(QGraphicsLayoutItem*,Qt::Alignment); + +private: + friend class LinearLayoutAttached; + void clearChildren(); + void insertLayoutItem(int, QGraphicsLayoutItem *); + static QHash attachedProperties; + + static void children_append(QDeclarativeListProperty *prop, QGraphicsLayoutItem *item) { + static_cast(prop->object)->insertLayoutItem(-1, item); + } + + static void children_clear(QDeclarativeListProperty *prop) { + static_cast(prop->object)->clearChildren(); + } + + static int children_count(QDeclarativeListProperty *prop) { + return static_cast(prop->object)->count(); + } + + static QGraphicsLayoutItem *children_at(QDeclarativeListProperty *prop, int index) { + return static_cast(prop->object)->itemAt(index); + } +}; + +class GridLayoutAttached; +class QGraphicsGridLayoutObject : public QObject, public QGraphicsGridLayout +{ + Q_OBJECT + Q_INTERFACES(QGraphicsLayout QGraphicsLayoutItem) + + Q_PROPERTY(QDeclarativeListProperty children READ children) + Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing) + 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 children() { return QDeclarativeListProperty(this, 0, children_append, children_count, children_at, children_clear); } + + qreal spacing() const; + + static GridLayoutAttached *qmlAttachedProperties(QObject *); + +private: + friend class GraphicsLayoutAttached; + void addWidget(QGraphicsWidget *); + void clearChildren(); + void addLayoutItem(QGraphicsLayoutItem *); + static QHash attachedProperties; + + static void children_append(QDeclarativeListProperty *prop, QGraphicsLayoutItem *item) { + static_cast(prop->object)->addLayoutItem(item); + } + + static void children_clear(QDeclarativeListProperty *prop) { + static_cast(prop->object)->clearChildren(); + } + + static int children_count(QDeclarativeListProperty *prop) { + return static_cast(prop->object)->count(); + } + + static QGraphicsLayoutItem *children_at(QDeclarativeListProperty *prop, int index) { + return static_cast(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) +public: + LinearLayoutAttached(QObject *parent); + + int stretchFactor() const { return _stretch; } + void setStretchFactor(int f); + Qt::Alignment alignment() const { return _alignment; } + void setAlignment(Qt::Alignment a); + +Q_SIGNALS: + void stretchChanged(QGraphicsLayoutItem*,int); + void alignmentChanged(QGraphicsLayoutItem*,Qt::Alignment); + +private: + int _stretch; + Qt::Alignment _alignment; +}; + +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) +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); + +private: + int _row; + int _column; + int _rowspan; + int _colspan; + Qt::Alignment _alignment; +}; + +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/src/declarative/imports/widgets/graphicswidgets.cpp b/src/declarative/imports/widgets/graphicswidgets.cpp new file mode 100644 index 0000000..062e516 --- /dev/null +++ b/src/declarative/imports/widgets/graphicswidgets.cpp @@ -0,0 +1,40 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ diff --git a/src/declarative/imports/widgets/graphicswidgets_p.h b/src/declarative/imports/widgets/graphicswidgets_p.h new file mode 100644 index 0000000..2c2b707 --- /dev/null +++ b/src/declarative/imports/widgets/graphicswidgets_p.h @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** 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 GRAPHICSWIDGETS_H +#define GRAPHICSWIDGETS_H + +#include + +#include +#include +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QGraphicsView) +QML_DECLARE_TYPE_HASMETATYPE(QGraphicsScene) +QML_DECLARE_TYPE(QGraphicsWidget) +QML_DECLARE_TYPE(QGraphicsObject) +QML_DECLARE_INTERFACE_HASMETATYPE(QGraphicsItem) + +QT_END_HEADER + +#endif // GRAPHICSWIDGETS_H diff --git a/src/declarative/imports/widgets/widgets.cpp b/src/declarative/imports/widgets/widgets.cpp new file mode 100644 index 0000000..ec21cc4 --- /dev/null +++ b/src/declarative/imports/widgets/widgets.cpp @@ -0,0 +1,138 @@ +/**************************************************************************** +** +** 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 +#include + +#include "graphicslayouts_p.h" +#include "graphicswidgets_p.h" + +QT_BEGIN_NAMESPACE + +class QGraphicsViewDeclarativeUI : public QObject +{ + Q_OBJECT + + Q_PROPERTY(QGraphicsScene *scene READ scene WRITE setScene) + Q_CLASSINFO("DefaultProperty", "scene") +public: + QGraphicsViewDeclarativeUI(QObject *other) : QObject(other) {} + + QGraphicsScene *scene() const { return static_cast(parent())->scene(); } + void setScene(QGraphicsScene *scene) + { + static_cast(parent())->setScene(scene); + } +}; + +class QGraphicsSceneDeclarativeUI : public QObject +{ + Q_OBJECT + + Q_PROPERTY(QDeclarativeListProperty children READ children) + Q_CLASSINFO("DefaultProperty", "children") +public: + QGraphicsSceneDeclarativeUI(QObject *other) : QObject(other) {} + + QDeclarativeListProperty children() { return QDeclarativeListProperty(this->parent(), 0, children_append); } + +private: + static void children_append(QDeclarativeListProperty *prop, QObject *o) { + if (QGraphicsObject *go = qobject_cast(o)) + static_cast(prop->object)->addItem(go); + } +}; + +class QGraphicsWidgetDeclarativeUI : public QObject +{ + Q_OBJECT + + Q_PROPERTY(QDeclarativeListProperty children READ children) + Q_PROPERTY(QGraphicsLayout *layout READ layout WRITE setLayout) + Q_CLASSINFO("DefaultProperty", "children") +public: + QGraphicsWidgetDeclarativeUI(QObject *other) : QObject(other) {} + + QDeclarativeListProperty children() { return QDeclarativeListProperty(this, 0, children_append); } + + QGraphicsLayout *layout() const { return static_cast(parent())->layout(); } + void setLayout(QGraphicsLayout *lo) + { + static_cast(parent())->setLayout(lo); + } + +private: + void setItemParent(QGraphicsItem *wid) + { + wid->setParentItem(static_cast(parent())); + } + + static void children_append(QDeclarativeListProperty *prop, QGraphicsItem *i) { + static_cast(prop->object)->setItemParent(i); + } +}; + +class QWidgetsQmlModule : public QDeclarativeExtensionPlugin +{ + Q_OBJECT +public: + virtual void registerTypes(const char *uri) + { + Q_ASSERT(QLatin1String(uri) == QLatin1String("Qt.widgets")); + + QML_REGISTER_INTERFACE(QGraphicsLayoutItem); + QML_REGISTER_INTERFACE(QGraphicsLayout); + qmlRegisterType(uri,4,6,"QGraphicsLinearLayoutStretchItem"); + qmlRegisterType(uri,4,6,"QGraphicsLinearLayout"); + qmlRegisterType(uri,4,6,"QGraphicsGridLayout"); + qmlRegisterExtendedType(uri,4,6,"QGraphicsView"); + qmlRegisterExtendedType(uri,4,6,"QGraphicsScene"); + qmlRegisterExtendedType(uri,4,6,"QGraphicsWidget"); + QML_REGISTER_INTERFACE(QGraphicsItem); + } +}; + +QT_END_NAMESPACE + +#include "widgets.moc" + +Q_EXPORT_PLUGIN2(qtwidgetsqmlmodule, QT_PREPEND_NAMESPACE(QWidgetsQmlModule)); + diff --git a/src/declarative/imports/widgets/widgets.pro b/src/declarative/imports/widgets/widgets.pro new file mode 100644 index 0000000..230d398 --- /dev/null +++ b/src/declarative/imports/widgets/widgets.pro @@ -0,0 +1,20 @@ +TARGET = widgets +include(../qimportbase.pri) + +QT += declarative + +SOURCES += \ + graphicslayouts.cpp \ + widgets.cpp + +HEADERS += \ + graphicswidgets_p.h \ + graphicslayouts_p.h + +QTDIR_build:DESTDIR = $$QT_BUILD_TREE/imports/Qt/widgets +target.path = $$[QT_INSTALL_IMPORTS]/Qt/widgets + +qmldir.files += $$QT_BUILD_TREE/imports/Qt/widgets/qmldir +qmldir.path += $$[QT_INSTALL_IMPORTS]/Qt/widgets + +INSTALLS += target qmldir diff --git a/src/declarative/libdeclarative.pro b/src/declarative/libdeclarative.pro new file mode 100644 index 0000000..4287e25 --- /dev/null +++ b/src/declarative/libdeclarative.pro @@ -0,0 +1,29 @@ +TARGET = QtDeclarative +QPRO_PWD = $$PWD +QT = core gui xml script network +contains(QT_CONFIG, svg): QT += svg +contains(QT_CONFIG, opengl): QT += opengl +DEFINES += QT_BUILD_DECLARATIVE_LIB QT_NO_URL_CAST_FROM_STRING +win32-msvc*|win32-icc:QMAKE_LFLAGS += /BASE:0x66000000 +solaris-cc*:QMAKE_CXXFLAGS_RELEASE -= -O2 + +unix:QMAKE_PKGCONFIG_REQUIRES = QtCore QtGui QtXml + +exists("qdeclarative_enable_gcov") { + QMAKE_CXXFLAGS = -fprofile-arcs -ftest-coverage -fno-elide-constructors + LIBS += -lgcov +} + +include(../qbase.pri) + +#INCLUDEPATH -= $$QMAKE_INCDIR_QT/$$TARGET +#DESTDIR=. + +#modules +include(3rdparty/3rdparty.pri) +include(util/util.pri) +include(graphicsitems/graphicsitems.pri) +include(qml/qml.pri) +include(debugger/debugger.pri) + +symbian:TARGET.UID3=0x2001E623 diff --git a/src/plugins/plugins.pro b/src/plugins/plugins.pro index 418fd81..730fdc5 100644 --- a/src/plugins/plugins.pro +++ b/src/plugins/plugins.pro @@ -12,6 +12,5 @@ embedded:SUBDIRS *= gfxdrivers decorations mousedrivers kbddrivers symbian:SUBDIRS += s60 contains(QT_CONFIG, phonon): SUBDIRS *= phonon contains(QT_CONFIG, multimedia): SUBDIRS *= audio mediaservices -contains(QT_CONFIG, declarative): SUBDIRS *= qdeclarativemodules diff --git a/src/plugins/qdeclarativemodules/multimedia/multimedia.cpp b/src/plugins/qdeclarativemodules/multimedia/multimedia.cpp deleted file mode 100644 index 8becbf3..0000000 --- a/src/plugins/qdeclarativemodules/multimedia/multimedia.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/**************************************************************************** -** -** 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 -#include -#include - -QT_BEGIN_NAMESPACE - -class QMultimediaQmlModule : public QDeclarativeExtensionPlugin -{ - Q_OBJECT -public: - virtual void registerTypes(const char *uri) - { - QtMultimedia::qRegisterDeclarativeElements(uri); - } -}; - -QT_END_NAMESPACE - -#include "multimedia.moc" - -Q_EXPORT_PLUGIN2(qmultimediaqmlmodule, QT_PREPEND_NAMESPACE(QMultimediaQmlModule)); - diff --git a/src/plugins/qdeclarativemodules/multimedia/multimedia.pro b/src/plugins/qdeclarativemodules/multimedia/multimedia.pro deleted file mode 100644 index d8ad18e..0000000 --- a/src/plugins/qdeclarativemodules/multimedia/multimedia.pro +++ /dev/null @@ -1,15 +0,0 @@ -TARGET = multimedia -include(../../qpluginbase.pri) - -QT += multimedia declarative - -SOURCES += multimedia.cpp - -QTDIR_build:DESTDIR = $$QT_BUILD_TREE/imports/Qt/multimedia -target.path = $$[QT_INSTALL_IMPORTS]/Qt/multimedia - -qmldir.files += $$QT_BUILD_TREE/imports/Qt/multimedia/qmldir -qmldir.path += $$[QT_INSTALL_IMPORTS]/Qt/multimedia - -INSTALLS += target qmldir - diff --git a/src/plugins/qdeclarativemodules/qdeclarativemodules.pro b/src/plugins/qdeclarativemodules/qdeclarativemodules.pro deleted file mode 100644 index ae53578..0000000 --- a/src/plugins/qdeclarativemodules/qdeclarativemodules.pro +++ /dev/null @@ -1,7 +0,0 @@ -TEMPLATE = subdirs - -SUBDIRS += widgets - -contains(QT_CONFIG, multimedia): SUBDIRS += multimedia -contains(QT_CONFIG, webkit): SUBDIRS += webkitqmlplugin - diff --git a/src/plugins/qdeclarativemodules/webkitqmlplugin/plugin.cpp b/src/plugins/qdeclarativemodules/webkitqmlplugin/plugin.cpp deleted file mode 100644 index 2f6205d..0000000 --- a/src/plugins/qdeclarativemodules/webkitqmlplugin/plugin.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/**************************************************************************** -** -** 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 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 -#include - -#include "qdeclarativewebview_p.h" -#include "qdeclarativewebview_p_p.h" - -QT_BEGIN_NAMESPACE - -class WebKitQmlPlugin : public QDeclarativeExtensionPlugin -{ - Q_OBJECT -public: - virtual void registerTypes(const char *uri) - { - Q_ASSERT(QLatin1String(uri) == QLatin1String("org.webkit")); - qmlRegisterType(uri,1,0,"WebView"); - } -}; - -QT_END_NAMESPACE - -#include "plugin.moc" - -Q_EXPORT_PLUGIN2(webkitqmlplugin, QT_PREPEND_NAMESPACE(WebKitQmlPlugin)); - diff --git a/src/plugins/qdeclarativemodules/webkitqmlplugin/qdeclarativewebview.cpp b/src/plugins/qdeclarativemodules/webkitqmlplugin/qdeclarativewebview.cpp deleted file mode 100644 index 733ac86..0000000 --- a/src/plugins/qdeclarativemodules/webkitqmlplugin/qdeclarativewebview.cpp +++ /dev/null @@ -1,1340 +0,0 @@ -/**************************************************************************** -** -** 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 "qdeclarativewebview_p.h" -#include "qdeclarativewebview_p_p.h" - -#include - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -static const int MAX_DOUBLECLICK_TIME=500; // XXX need better gesture system - -class QDeclarativeWebViewPrivate : public QDeclarativePaintedItemPrivate -{ - Q_DECLARE_PUBLIC(QDeclarativeWebView) - -public: - QDeclarativeWebViewPrivate() - : QDeclarativePaintedItemPrivate(), page(0), preferredwidth(0), preferredheight(0), - progress(1.0), status(QDeclarativeWebView::Null), pending(PendingNone), - newWindowComponent(0), newWindowParent(0), - pressTime(400), - rendering(true) - { - } - - QUrl url; // page url might be different if it has not loaded yet - QWebPage *page; - - int preferredwidth, preferredheight; - qreal progress; - QDeclarativeWebView::Status status; - QString statusText; - enum { PendingNone, PendingUrl, PendingHtml, PendingContent } pending; - QUrl pending_url; - QString pending_string; - QByteArray pending_data; - mutable QDeclarativeWebSettings settings; - QDeclarativeComponent *newWindowComponent; - QDeclarativeItem *newWindowParent; - - QBasicTimer pressTimer; - QPoint pressPoint; - int pressTime; // milliseconds before it's a "hold" - - - static void windowObjects_append(QDeclarativeListProperty *prop, QObject *o) { - static_cast(prop->data)->windowObjects.append(o); - static_cast(prop->data)->updateWindowObjects(); - } - - void updateWindowObjects(); - QObjectList windowObjects; - - bool rendering; -}; - -/*! - \qmlclass WebView QDeclarativeWebView - \since 4.7 - \brief The WebView item allows you to add web content to a canvas. - \inherits Item - - A WebView renders web content based on a URL. - - If the width and height of the item is not set, they will - dynamically adjust to a size appropriate for the content. - This width may be large for typical online web pages. - - If the preferredWidth is set, the width will be this amount or larger, - usually laying out the web content to fit the preferredWidth. - - \qml - import org.webkit 1.0 - - WebView { - url: "http://www.nokia.com" - width: 490 - height: 400 - scale: 0.5 - smooth: false - smoothCache: true - } - \endqml - - \image webview.png - - The item includes no scrolling, scaling, - toolbars, etc., those must be implemented around WebView. See the WebBrowser example - for a demonstration of this. -*/ - -/*! - \internal - \class QDeclarativeWebView - \brief The QDeclarativeWebView class allows you to add web content to a QDeclarativeView. - - A WebView renders web content base on a URL. - - \image webview.png - - The item includes no scrolling, scaling, - toolbars, etc., those must be implemented around WebView. See the WebBrowser example - for a demonstration of this. - - A QDeclarativeWebView object can be instantiated in Qml using the tag \l WebView. -*/ - -QDeclarativeWebView::QDeclarativeWebView(QDeclarativeItem *parent) - : QDeclarativePaintedItem(*(new QDeclarativeWebViewPrivate), parent) -{ - init(); -} - -QDeclarativeWebView::~QDeclarativeWebView() -{ - Q_D(QDeclarativeWebView); - delete d->page; -} - -void QDeclarativeWebView::init() -{ - Q_D(QDeclarativeWebView); - - QWebSettings::enablePersistentStorage(); - - setAcceptHoverEvents(true); - setAcceptedMouseButtons(Qt::LeftButton); - setFlag(QGraphicsItem::ItemHasNoContents, false); - - d->page = 0; -} - -void QDeclarativeWebView::componentComplete() -{ - QDeclarativePaintedItem::componentComplete(); - Q_D(QDeclarativeWebView); - switch (d->pending) { - case QDeclarativeWebViewPrivate::PendingUrl: - setUrl(d->pending_url); - break; - case QDeclarativeWebViewPrivate::PendingHtml: - setHtml(d->pending_string, d->pending_url); - break; - case QDeclarativeWebViewPrivate::PendingContent: - setContent(d->pending_data, d->pending_string, d->pending_url); - break; - default: - break; - } - d->pending = QDeclarativeWebViewPrivate::PendingNone; - d->updateWindowObjects(); -} - -QDeclarativeWebView::Status QDeclarativeWebView::status() const -{ - Q_D(const QDeclarativeWebView); - return d->status; -} - - -/*! - \qmlproperty real WebView::progress - This property holds the progress of loading the current URL, from 0 to 1. - - If you just want to know when progress gets to 1, use - WebView::onLoadFinished() or WebView::onLoadFailed() instead. -*/ -qreal QDeclarativeWebView::progress() const -{ - Q_D(const QDeclarativeWebView); - return d->progress; -} - -void QDeclarativeWebView::doLoadStarted() -{ - Q_D(QDeclarativeWebView); - - if (!d->url.isEmpty()) { - d->status = Loading; - emit statusChanged(d->status); - } - emit loadStarted(); -} - -void QDeclarativeWebView::doLoadProgress(int p) -{ - Q_D(QDeclarativeWebView); - if (d->progress == p/100.0) - return; - d->progress = p/100.0; - emit progressChanged(); -} - -void QDeclarativeWebView::pageUrlChanged() -{ - Q_D(QDeclarativeWebView); - - page()->setViewportSize(QSize( - d->preferredwidth>0 ? d->preferredwidth : width(), - d->preferredheight>0 ? d->preferredheight : height())); - expandToWebPage(); - - if ((d->url.isEmpty() && page()->mainFrame()->url() != QUrl(QLatin1String("about:blank"))) - || (d->url != page()->mainFrame()->url() && !page()->mainFrame()->url().isEmpty())) - { - d->url = page()->mainFrame()->url(); - if (d->url == QUrl(QLatin1String("about:blank"))) - d->url = QUrl(); - emit urlChanged(); - } -} - -void QDeclarativeWebView::doLoadFinished(bool ok) -{ - Q_D(QDeclarativeWebView); - - if (title().isEmpty()) - pageUrlChanged(); // XXX bug 232556 - pages with no title never get urlChanged() - - if (ok) { - d->status = d->url.isEmpty() ? Null : Ready; - emit loadFinished(); - } else { - d->status = Error; - emit loadFailed(); - } - emit statusChanged(d->status); -} - -/*! - \qmlproperty url WebView::url - This property holds the URL to the page displayed in this item. It can be set, - but also can change spontaneously (eg. because of network redirection). - - If the url is empty, the page is blank. - - The url is always absolute (QML will resolve relative URL strings in the context - of the containing QML document). -*/ -QUrl QDeclarativeWebView::url() const -{ - Q_D(const QDeclarativeWebView); - return d->url; -} - -void QDeclarativeWebView::setUrl(const QUrl &url) -{ - Q_D(QDeclarativeWebView); - if (url == d->url) - return; - - if (isComponentComplete()) { - d->url = url; - page()->setViewportSize(QSize( - d->preferredwidth>0 ? d->preferredwidth : width(), - d->preferredheight>0 ? d->preferredheight : height())); - QUrl seturl = url; - if (seturl.isEmpty()) - seturl = QUrl(QLatin1String("about:blank")); - - Q_ASSERT(!seturl.isRelative()); - - page()->mainFrame()->load(seturl); - - emit urlChanged(); - } else { - d->pending = d->PendingUrl; - d->pending_url = url; - } -} - -/*! - \qmlproperty int WebView::preferredWidth - This property holds the ideal width for displaying the current URL. -*/ -int QDeclarativeWebView::preferredWidth() const -{ - Q_D(const QDeclarativeWebView); - return d->preferredwidth; -} - -void QDeclarativeWebView::setPreferredWidth(int iw) -{ - Q_D(QDeclarativeWebView); - if (d->preferredwidth == iw) return; - d->preferredwidth = iw; - //expandToWebPage(); - emit preferredWidthChanged(); -} - -/*! - \qmlproperty int WebView::preferredHeight - This property holds the ideal height for displaying the current URL. - This only affects the area zoomed by heuristicZoom(). -*/ -int QDeclarativeWebView::preferredHeight() const -{ - Q_D(const QDeclarativeWebView); - return d->preferredheight; -} -void QDeclarativeWebView::setPreferredHeight(int ih) -{ - Q_D(QDeclarativeWebView); - if (d->preferredheight == ih) return; - d->preferredheight = ih; - emit preferredHeightChanged(); -} - -/*! - \qmlmethod bool WebView::evaluateJavaScript(string) - - Evaluates the \a scriptSource JavaScript inside the context of the - main web frame, and returns the result of the last executed statement. - - Note that this JavaScript does \e not have any access to QML objects - except as made available as windowObjects. -*/ -QVariant QDeclarativeWebView::evaluateJavaScript(const QString &scriptSource) -{ - return this->page()->mainFrame()->evaluateJavaScript(scriptSource); -} - -void QDeclarativeWebView::focusChanged(bool hasFocus) -{ - QFocusEvent e(hasFocus ? QEvent::FocusIn : QEvent::FocusOut); - page()->event(&e); - QDeclarativeItem::focusChanged(hasFocus); -} - -void QDeclarativeWebView::initialLayout() -{ - // nothing useful to do at this point -} - -void QDeclarativeWebView::noteContentsSizeChanged(const QSize&) -{ - expandToWebPage(); -} - -void QDeclarativeWebView::expandToWebPage() -{ - Q_D(QDeclarativeWebView); - QSize cs = page()->mainFrame()->contentsSize(); - if (cs.width() < d->preferredwidth) - cs.setWidth(d->preferredwidth); - if (cs.height() < d->preferredheight) - cs.setHeight(d->preferredheight); - if (widthValid()) - cs.setWidth(width()); - if (heightValid()) - cs.setHeight(height()); - if (cs != page()->viewportSize()) { - page()->setViewportSize(cs); - } - if (cs != contentsSize()) - setContentsSize(cs); -} - -void QDeclarativeWebView::geometryChanged(const QRectF &newGeometry, - const QRectF &oldGeometry) -{ - if (newGeometry.size() != oldGeometry.size()) - expandToWebPage(); - QDeclarativePaintedItem::geometryChanged(newGeometry, oldGeometry); -} - -void QDeclarativeWebView::paintPage(const QRect& r) -{ - dirtyCache(r); - update(); -} - -/*! - \qmlproperty list WebView::javaScriptWindowObjects - - This property is a list of object that are available from within - the webview's JavaScript context. - - The \a object will be inserted as a child of the frame's window - object, under the name given by the attached property \c WebView.windowObjectName. - - \qml - WebView { - javaScriptWindowObjects: Object { - WebView.windowObjectName: "coordinates" - } - } - \endqml - - Properties of the object will be exposed as JavaScript properties and slots as - JavaScript methods. - - If Javascript is not enabled for this page, then this property does nothing. -*/ -QDeclarativeListProperty QDeclarativeWebView::javaScriptWindowObjects() -{ - Q_D(QDeclarativeWebView); - return QDeclarativeListProperty(this, d, &QDeclarativeWebViewPrivate::windowObjects_append); -} - -QDeclarativeWebViewAttached *QDeclarativeWebView::qmlAttachedProperties(QObject *o) -{ - return new QDeclarativeWebViewAttached(o); -} - -void QDeclarativeWebViewPrivate::updateWindowObjects() -{ - Q_Q(QDeclarativeWebView); - if (!q->isComponentComplete() || !page) - return; - - for (int ii = 0; ii < windowObjects.count(); ++ii) { - QObject *object = windowObjects.at(ii); - QDeclarativeWebViewAttached *attached = static_cast(qmlAttachedPropertiesObject(object)); - if (attached && !attached->windowObjectName().isEmpty()) { - page->mainFrame()->addToJavaScriptWindowObject(attached->windowObjectName(), object); - } - } -} - -bool QDeclarativeWebView::renderingEnabled() const -{ - Q_D(const QDeclarativeWebView); - return d->rendering; -} - -void QDeclarativeWebView::setRenderingEnabled(bool enabled) -{ - Q_D(QDeclarativeWebView); - if (d->rendering == enabled) - return; - d->rendering = enabled; - emit renderingEnabledChanged(); - - setCacheFrozen(!enabled); - if (enabled) - clearCache(); -} - - -void QDeclarativeWebView::drawContents(QPainter *p, const QRect &r) -{ - Q_D(QDeclarativeWebView); - if (d->rendering) - page()->mainFrame()->render(p,r); -} - -QMouseEvent *QDeclarativeWebView::sceneMouseEventToMouseEvent(QGraphicsSceneMouseEvent *e) -{ - QEvent::Type t; - switch(e->type()) { - default: - case QEvent::GraphicsSceneMousePress: - t = QEvent::MouseButtonPress; - break; - case QEvent::GraphicsSceneMouseRelease: - t = QEvent::MouseButtonRelease; - break; - case QEvent::GraphicsSceneMouseMove: - t = QEvent::MouseMove; - break; - case QGraphicsSceneEvent::GraphicsSceneMouseDoubleClick: - t = QEvent::MouseButtonDblClick; - break; - } - - QMouseEvent *me = new QMouseEvent(t, (e->pos()/contentsScale()).toPoint(), e->button(), e->buttons(), 0); - return me; -} - -QMouseEvent *QDeclarativeWebView::sceneHoverMoveEventToMouseEvent(QGraphicsSceneHoverEvent *e) -{ - QEvent::Type t = QEvent::MouseMove; - - QMouseEvent *me = new QMouseEvent(t, (e->pos()/contentsScale()).toPoint(), Qt::NoButton, Qt::NoButton, 0); - - return me; -} - - -/*! - \qmlsignal WebView::onDoubleClick(clickx,clicky) - - The WebView does not pass double-click events to the web engine, but rather - emits this signals. -*/ - -void QDeclarativeWebView::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) -{ - QMouseEvent *me = sceneMouseEventToMouseEvent(event); - emit doubleClick(me->x(),me->y()); - delete me; -} - -/*! - \qmlmethod bool WebView::heuristicZoom(clickX,clickY,maxzoom) - - Finds a zoom that: - \list - \i shows a whole item - \i includes (\a clickX, \a clickY) - \i fits into the preferredWidth and preferredHeight - \i zooms by no more than \a maxzoom - \i is more than 10% above the current zoom - \endlist - - If such a zoom exists, emits zoomTo(zoom,centerX,centerY) and returns true; otherwise, - no signal is emitted and returns false. -*/ -bool QDeclarativeWebView::heuristicZoom(int clickX, int clickY, qreal maxzoom) -{ - Q_D(QDeclarativeWebView); - if (contentsScale() >= maxzoom/zoomFactor()) - return false; - qreal ozf = contentsScale(); - QRect showarea = elementAreaAt(clickX, clickY, d->preferredwidth/maxzoom, d->preferredheight/maxzoom); - qreal z = qMin(qreal(d->preferredwidth)/showarea.width(),qreal(d->preferredheight)/showarea.height()); - if (z > maxzoom/zoomFactor()) - z = maxzoom/zoomFactor(); - if (z/ozf > 1.2) { - QRectF r(showarea.left()*z, showarea.top()*z, showarea.width()*z, showarea.height()*z); - emit zoomTo(z,r.x()+r.width()/2, r.y()+r.height()/2); - return true; - } else { - return false; - } -} - -/*! - \qmlproperty int WebView::pressGrabTime - - The number of milliseconds the user must press before the WebView - starts passing move events through to the web engine (rather than - letting other QML elements such as a Flickable take them). - - Defaults to 400ms. Set to 0 to always grab and pass move events to - the web engine. -*/ -int QDeclarativeWebView::pressGrabTime() const -{ - Q_D(const QDeclarativeWebView); - return d->pressTime; -} - -void QDeclarativeWebView::setPressGrabTime(int ms) -{ - Q_D(QDeclarativeWebView); - if (d->pressTime == ms) - return; - d->pressTime = ms; - emit pressGrabTimeChanged(); -} - -void QDeclarativeWebView::mousePressEvent(QGraphicsSceneMouseEvent *event) -{ - Q_D(QDeclarativeWebView); - - setFocus (true); - QMouseEvent *me = sceneMouseEventToMouseEvent(event); - - d->pressPoint = me->pos(); - if (d->pressTime) { - d->pressTimer.start(d->pressTime,this); - setKeepMouseGrab(false); - } else { - grabMouse(); - setKeepMouseGrab(true); - } - - page()->event(me); - event->setAccepted( -/* - It is not correct to send the press event upwards, if it is not accepted by WebKit - e.g. push button does not work, if done so as QGraphicsScene will not send the release event at all to WebKit - Might be a bug in WebKit, though - */ -#if 1 //QT_VERSION <= 0x040500 // XXX see bug 230835 - true -#else - me->isAccepted() -#endif - ); - delete me; - if (!event->isAccepted()) { - QDeclarativePaintedItem::mousePressEvent(event); - } -} - -void QDeclarativeWebView::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) -{ - Q_D(QDeclarativeWebView); - - QMouseEvent *me = sceneMouseEventToMouseEvent(event); - page()->event(me); - d->pressTimer.stop(); - event->setAccepted( -/* - It is not correct to send the press event upwards, if it is not accepted by WebKit - e.g. push button does not work, if done so as QGraphicsScene will not send all the events to WebKit - */ -#if 1 //QT_VERSION <= 0x040500 // XXX see bug 230835 - true -#else - me->isAccepted() -#endif - ); - delete me; - if (!event->isAccepted()) { - QDeclarativePaintedItem::mouseReleaseEvent(event); - } - setKeepMouseGrab(false); - ungrabMouse(); -} - -void QDeclarativeWebView::timerEvent(QTimerEvent *event) -{ - Q_D(QDeclarativeWebView); - if (event->timerId() == d->pressTimer.timerId()) { - d->pressTimer.stop(); - grabMouse(); - setKeepMouseGrab(true); - } -} - -void QDeclarativeWebView::mouseMoveEvent(QGraphicsSceneMouseEvent *event) -{ - Q_D(QDeclarativeWebView); - - QMouseEvent *me = sceneMouseEventToMouseEvent(event); - if (d->pressTimer.isActive()) { - if ((me->pos() - d->pressPoint).manhattanLength() > QApplication::startDragDistance()) { - d->pressTimer.stop(); - } - } - if (keepMouseGrab()) { - page()->event(me); - event->setAccepted( -/* - It is not correct to send the press event upwards, if it is not accepted by WebKit - e.g. push button does not work, if done so as QGraphicsScene will not send the release event at all to WebKit - Might be a bug in WebKit, though - */ -#if 1 // QT_VERSION <= 0x040500 // XXX see bug 230835 - true -#else - me->isAccepted() -#endif - ); - } - delete me; - if (!event->isAccepted()) - QDeclarativePaintedItem::mouseMoveEvent(event); - -} -void QDeclarativeWebView::hoverMoveEvent (QGraphicsSceneHoverEvent * event) -{ - QMouseEvent *me = sceneHoverMoveEventToMouseEvent(event); - page()->event(me); - event->setAccepted( -#if QT_VERSION <= 0x040500 // XXX see bug 230835 - true -#else - me->isAccepted() -#endif - ); - delete me; - if (!event->isAccepted()) - QDeclarativePaintedItem::hoverMoveEvent(event); -} - -void QDeclarativeWebView::keyPressEvent(QKeyEvent* event) -{ - page()->event(event); - if (!event->isAccepted()) - QDeclarativePaintedItem::keyPressEvent(event); -} - -void QDeclarativeWebView::keyReleaseEvent(QKeyEvent* event) -{ - page()->event(event); - if (!event->isAccepted()) - QDeclarativePaintedItem::keyReleaseEvent(event); -} - -bool QDeclarativeWebView::sceneEvent(QEvent *event) -{ - if (event->type() == QEvent::KeyPress) { - QKeyEvent *k = static_cast(event); - if (k->key() == Qt::Key_Tab || k->key() == Qt::Key_Backtab) { - if (!(k->modifiers() & (Qt::ControlModifier | Qt::AltModifier))) { //### Add MetaModifier? - page()->event(event); - if (event->isAccepted()) - return true; - } - } - } - return QDeclarativePaintedItem::sceneEvent(event); -} - - -/*! - \qmlproperty action WebView::back - This property holds the action for causing the previous URL in the history to be displayed. -*/ -QAction *QDeclarativeWebView::backAction() const -{ - return page()->action(QWebPage::Back); -} - -/*! - \qmlproperty action WebView::forward - This property holds the action for causing the next URL in the history to be displayed. -*/ -QAction *QDeclarativeWebView::forwardAction() const -{ - return page()->action(QWebPage::Forward); -} - -/*! - \qmlproperty action WebView::reload - This property holds the action for reloading with the current URL -*/ -QAction *QDeclarativeWebView::reloadAction() const -{ - return page()->action(QWebPage::Reload); -} - -/*! - \qmlproperty action WebView::stop - This property holds the action for stopping loading with the current URL -*/ -QAction *QDeclarativeWebView::stopAction() const -{ - return page()->action(QWebPage::Stop); -} - -/*! - \qmlproperty real WebView::title - This property holds the title of the web page currently viewed - - By default, this property contains an empty string. -*/ -QString QDeclarativeWebView::title() const -{ - return page()->mainFrame()->title(); -} - - - -/*! - \qmlproperty pixmap WebView::icon - This property holds the icon associated with the web page currently viewed -*/ -QPixmap QDeclarativeWebView::icon() const -{ - return page()->mainFrame()->icon().pixmap(QSize(256,256)); -} - - -/*! - \qmlproperty real WebView::zoomFactor - This property holds the multiplier used to scale the contents of a Web page. -*/ -void QDeclarativeWebView::setZoomFactor(qreal factor) -{ - Q_D(QDeclarativeWebView); - if (factor == page()->mainFrame()->zoomFactor()) - return; - - page()->mainFrame()->setZoomFactor(factor); - page()->setViewportSize(QSize( - d->preferredwidth>0 ? d->preferredwidth*factor : width()*factor, - d->preferredheight>0 ? d->preferredheight*factor : height()*factor)); - expandToWebPage(); - - emit zoomFactorChanged(); -} - -qreal QDeclarativeWebView::zoomFactor() const -{ - return page()->mainFrame()->zoomFactor(); -} - -/*! - \qmlproperty string WebView::statusText - - This property is the current status suggested by the current web page. In a web browser, - such status is often shown in some kind of status bar. -*/ -void QDeclarativeWebView::setStatusText(const QString& s) -{ - Q_D(QDeclarativeWebView); - d->statusText = s; - emit statusTextChanged(); -} - -void QDeclarativeWebView::windowObjectCleared() -{ - Q_D(QDeclarativeWebView); - d->updateWindowObjects(); -} - -QString QDeclarativeWebView::statusText() const -{ - Q_D(const QDeclarativeWebView); - return d->statusText; -} - -QWebPage *QDeclarativeWebView::page() const -{ - Q_D(const QDeclarativeWebView); - - if (!d->page) { - QDeclarativeWebView *self = const_cast(this); - QWebPage *wp = new QDeclarativeWebPage(self); - - // QML items don't default to having a background, - // even though most we pages will set one anyway. - QPalette pal = QApplication::palette(); - pal.setBrush(QPalette::Base, QColor::fromRgbF(0, 0, 0, 0)); - wp->setPalette(pal); - - wp->setNetworkAccessManager(qmlEngine(this)->networkAccessManager()); - - self->setPage(wp); - - return wp; - } - - return d->page; -} - - -// The QObject interface to settings(). -/*! - \qmlproperty string WebView::settings.standardFontFamily - \qmlproperty string WebView::settings.fixedFontFamily - \qmlproperty string WebView::settings.serifFontFamily - \qmlproperty string WebView::settings.sansSerifFontFamily - \qmlproperty string WebView::settings.cursiveFontFamily - \qmlproperty string WebView::settings.fantasyFontFamily - - \qmlproperty int WebView::settings.minimumFontSize - \qmlproperty int WebView::settings.minimumLogicalFontSize - \qmlproperty int WebView::settings.defaultFontSize - \qmlproperty int WebView::settings.defaultFixedFontSize - - \qmlproperty bool WebView::settings.autoLoadImages - \qmlproperty bool WebView::settings.javascriptEnabled - \qmlproperty bool WebView::settings.javaEnabled - \qmlproperty bool WebView::settings.pluginsEnabled - \qmlproperty bool WebView::settings.privateBrowsingEnabled - \qmlproperty bool WebView::settings.javascriptCanOpenWindows - \qmlproperty bool WebView::settings.javascriptCanAccessClipboard - \qmlproperty bool WebView::settings.developerExtrasEnabled - \qmlproperty bool WebView::settings.linksIncludedInFocusChain - \qmlproperty bool WebView::settings.zoomTextOnly - \qmlproperty bool WebView::settings.printElementBackgrounds - \qmlproperty bool WebView::settings.offlineStorageDatabaseEnabled - \qmlproperty bool WebView::settings.offlineWebApplicationCacheEnabled - \qmlproperty bool WebView::settings.localStorageDatabaseEnabled - \qmlproperty bool WebView::settings.localContentCanAccessRemoteUrls - - These properties give access to the settings controlling the web view. - - See QWebSettings for details of these properties. - - \qml - WebView { - settings.pluginsEnabled: true - settings.standardFontFamily: "Arial" - ... - } - \endqml -*/ -QObject *QDeclarativeWebView::settingsObject() const -{ - Q_D(const QDeclarativeWebView); - d->settings.s = page()->settings(); - return &d->settings; -} - -void QDeclarativeWebView::setPage(QWebPage *page) -{ - Q_D(QDeclarativeWebView); - if (d->page == page) - return; - if (d->page) { - if (d->page->parent() == this) { - delete d->page; - } else { - d->page->disconnect(this); - } - } - d->page = page; - d->page->setViewportSize(QSize( - d->preferredwidth>0 ? d->preferredwidth : width(), - d->preferredheight>0 ? d->preferredheight : height())); - d->page->mainFrame()->setScrollBarPolicy(Qt::Horizontal,Qt::ScrollBarAlwaysOff); - d->page->mainFrame()->setScrollBarPolicy(Qt::Vertical,Qt::ScrollBarAlwaysOff); - connect(d->page,SIGNAL(repaintRequested(QRect)),this,SLOT(paintPage(QRect))); - connect(d->page->mainFrame(),SIGNAL(urlChanged(QUrl)),this,SLOT(pageUrlChanged())); - connect(d->page->mainFrame(), SIGNAL(titleChanged(QString)), this, SIGNAL(titleChanged(QString))); - connect(d->page->mainFrame(), SIGNAL(titleChanged(QString)), this, SIGNAL(iconChanged())); - connect(d->page->mainFrame(), SIGNAL(iconChanged()), this, SIGNAL(iconChanged())); - connect(d->page->mainFrame(), SIGNAL(contentsSizeChanged(QSize)), this, SLOT(noteContentsSizeChanged(QSize))); - connect(d->page->mainFrame(), SIGNAL(initialLayoutCompleted()), this, SLOT(initialLayout())); - - connect(d->page,SIGNAL(loadStarted()),this,SLOT(doLoadStarted())); - connect(d->page,SIGNAL(loadProgress(int)),this,SLOT(doLoadProgress(int))); - connect(d->page,SIGNAL(loadFinished(bool)),this,SLOT(doLoadFinished(bool))); - connect(d->page,SIGNAL(statusBarMessage(QString)),this,SLOT(setStatusText(QString))); - - connect(d->page->mainFrame(),SIGNAL(javaScriptWindowObjectCleared()),this,SLOT(windowObjectCleared())); -} - -/*! - \qmlsignal WebView::onLoadStarted() - - This handler is called when the web engine begins loading - a page. Later, WebView::onLoadFinished() or WebView::onLoadFailed() - will be emitted. -*/ - -/*! - \qmlsignal WebView::onLoadFinished() - - This handler is called when the web engine \e successfully - finishes loading a page, including any component content - (WebView::onLoadFailed() will be emitted otherwise). - - \sa progress -*/ - -/*! - \qmlsignal WebView::onLoadFailed() - - This handler is called when the web engine fails loading - a page or any component content - (WebView::onLoadFinished() will be emitted on success). -*/ - -void QDeclarativeWebView::load(const QNetworkRequest &request, - QNetworkAccessManager::Operation operation, - const QByteArray &body) -{ - page()->mainFrame()->load(request, operation, body); -} - -QString QDeclarativeWebView::html() const -{ - return page()->mainFrame()->toHtml(); -} - -/*! - \qmlproperty string WebView::html - This property holds HTML text set directly - - The html property can be set as a string. - - \qml - WebView { - html: "

This is HTML." - } - \endqml -*/ -void QDeclarativeWebView::setHtml(const QString &html, const QUrl &baseUrl) -{ - Q_D(QDeclarativeWebView); - page()->setViewportSize(QSize( - d->preferredwidth>0 ? d->preferredwidth : width(), - d->preferredheight>0 ? d->preferredheight : height())); - if (isComponentComplete()) - page()->mainFrame()->setHtml(html, baseUrl); - else { - d->pending = d->PendingHtml; - d->pending_url = baseUrl; - d->pending_string = html; - } - emit htmlChanged(); -} - -void QDeclarativeWebView::setContent(const QByteArray &data, const QString &mimeType, const QUrl &baseUrl) -{ - Q_D(QDeclarativeWebView); - page()->setViewportSize(QSize( - d->preferredwidth>0 ? d->preferredwidth : width(), - d->preferredheight>0 ? d->preferredheight : height())); - - if (isComponentComplete()) - page()->mainFrame()->setContent(data,mimeType,qmlContext(this)->resolvedUrl(baseUrl)); - else { - d->pending = d->PendingContent; - d->pending_url = baseUrl; - d->pending_string = mimeType; - d->pending_data = data; - } -} - -QWebHistory *QDeclarativeWebView::history() const -{ - return page()->history(); -} - -QWebSettings *QDeclarativeWebView::settings() const -{ - return page()->settings(); -} - -QDeclarativeWebView *QDeclarativeWebView::createWindow(QWebPage::WebWindowType type) -{ - Q_D(QDeclarativeWebView); - switch (type) { - case QWebPage::WebBrowserWindow: { - if (!d->newWindowComponent && d->newWindowParent) - qWarning("WebView::newWindowComponent not set - WebView::newWindowParent ignored"); - else if (d->newWindowComponent && !d->newWindowParent) - qWarning("WebView::newWindowParent not set - WebView::newWindowComponent ignored"); - else if (d->newWindowComponent && d->newWindowParent) { - QDeclarativeWebView *webview = 0; - QDeclarativeContext *windowContext = new QDeclarativeContext(qmlContext(this)); - - QObject *nobj = d->newWindowComponent->create(windowContext); - if (nobj) { - windowContext->setParent(nobj); - QDeclarativeItem *item = qobject_cast(nobj); - if (!item) { - delete nobj; - } else { - webview = item->findChild(); - if (!webview) { - delete item; - } else { - nobj->setParent(d->newWindowParent); - static_cast(item)->setParentItem(d->newWindowParent); - } - } - } else { - delete windowContext; - } - - return webview; - } - } - break; - case QWebPage::WebModalDialog: { - // Not supported - } - } - return 0; -} - -/*! - \qmlproperty component WebView::newWindowComponent - - This property holds the component to use for new windows. - The component must have a WebView somewhere in its structure. - - When the web engine requests a new window, it will be an instance of - this component. - - The parent of the new window is set by newWindowParent. It must be set. -*/ -QDeclarativeComponent *QDeclarativeWebView::newWindowComponent() const -{ - Q_D(const QDeclarativeWebView); - return d->newWindowComponent; -} - -void QDeclarativeWebView::setNewWindowComponent(QDeclarativeComponent *newWindow) -{ - Q_D(QDeclarativeWebView); - if (newWindow == d->newWindowComponent) - return; - d->newWindowComponent = newWindow; - emit newWindowComponentChanged(); -} - - -/*! - \qmlproperty item WebView::newWindowParent - - The parent item for new windows. - - \sa newWindowComponent -*/ -QDeclarativeItem *QDeclarativeWebView::newWindowParent() const -{ - Q_D(const QDeclarativeWebView); - return d->newWindowParent; -} - -void QDeclarativeWebView::setNewWindowParent(QDeclarativeItem *parent) -{ - Q_D(QDeclarativeWebView); - if (parent == d->newWindowParent) - return; - if (d->newWindowParent && parent) { - QList children = d->newWindowParent->childItems(); - for (int i = 0; i < children.count(); ++i) { - children.at(i)->setParentItem(parent); - } - } - d->newWindowParent = parent; - emit newWindowParentChanged(); -} - -/*! - Returns the area of the largest element at position (\a x,\a y) that is no larger - than \a maxwidth by \a maxheight pixels. - - May return an area larger in the case when no smaller element is at the position. -*/ -QRect QDeclarativeWebView::elementAreaAt(int x, int y, int maxwidth, int maxheight) const -{ - QWebHitTestResult hit = page()->mainFrame()->hitTestContent(QPoint(x,y)); - QRect rv = hit.boundingRect(); - QWebElement element = hit.enclosingBlockElement(); - if (maxwidth<=0) maxwidth = INT_MAX; - if (maxheight<=0) maxheight = INT_MAX; - while (!element.parent().isNull() && element.geometry().width() <= maxwidth && element.geometry().height() <= maxheight) { - rv = element.geometry(); - element = element.parent(); - } - return rv; -} - -/*! - \internal - \class QDeclarativeWebPage - \brief The QDeclarativeWebPage class is a QWebPage that can create QML plugins. - - \sa QDeclarativeWebView -*/ -QDeclarativeWebPage::QDeclarativeWebPage(QDeclarativeWebView *parent) : - QWebPage(parent) -{ -} - -QDeclarativeWebPage::~QDeclarativeWebPage() -{ -} - -void QDeclarativeWebPage::javaScriptConsoleMessage(const QString& message, int lineNumber, const QString& sourceID) -{ - qWarning() << sourceID << ':' << lineNumber << ':' << message; -} - -QString QDeclarativeWebPage::chooseFile(QWebFrame *originatingFrame, const QString& oldFile) -{ - // Not supported (it's modal) - Q_UNUSED(originatingFrame) - Q_UNUSED(oldFile) - return oldFile; -} - -void QDeclarativeWebPage::javaScriptAlert(QWebFrame *originatingFrame, const QString& msg) -{ - Q_UNUSED(originatingFrame) - emit viewItem()->alert(msg); -} - -bool QDeclarativeWebPage::javaScriptConfirm(QWebFrame *originatingFrame, const QString& msg) -{ - // Not supported (it's modal) - Q_UNUSED(originatingFrame) - Q_UNUSED(msg) - return false; -} - -bool QDeclarativeWebPage::javaScriptPrompt(QWebFrame *originatingFrame, const QString& msg, const QString& defaultValue, QString* result) -{ - // Not supported (it's modal) - Q_UNUSED(originatingFrame) - Q_UNUSED(msg) - Q_UNUSED(defaultValue) - Q_UNUSED(result) - return false; -} - - -/* - Qt WebKit does not understand non-QWidget plugins, so dummy widgets - are created, parented to a single dummy tool window. - - The requirements for QML object plugins are input to the Qt WebKit - non-QWidget plugin support, which will obsolete this kludge. -*/ -class QWidget_Dummy_Plugin : public QWidget -{ - Q_OBJECT -public: - static QWidget *dummy_shared_parent() - { - static QWidget *dsp = 0; - if (!dsp) { - dsp = new QWidget(0,Qt::Tool); - dsp->setGeometry(-10000,-10000,0,0); - dsp->show(); - } - return dsp; - } - QWidget_Dummy_Plugin(const QUrl& url, QDeclarativeWebView *view, const QStringList ¶mNames, const QStringList ¶mValues) : - QWidget(dummy_shared_parent()), - propertyNames(paramNames), - propertyValues(paramValues), - webview(view) - { - QDeclarativeEngine *engine = qmlEngine(webview); - component = new QDeclarativeComponent(engine, url, this); - item = 0; - if (component->isLoading()) - connect(component, SIGNAL(statusChanged(QDeclarativeComponent::Status)), this, SLOT(qmlLoaded())); - else - qmlLoaded(); - } - -public Q_SLOTS: - void qmlLoaded() - { - if (component->isError()) { - // ### Could instead give these errors to the WebView to handle. - qWarning() << component->errors(); - return; - } - item = qobject_cast(component->create(qmlContext(webview))); - item->setParent(webview); - QString jsObjName; - for (int i=0; isetProperty(propertyNames[i].toUtf8(),propertyValues[i]); - if (propertyNames[i] == QLatin1String("objectname")) - jsObjName = propertyValues[i]; - } - } - if (!jsObjName.isNull()) { - QWebFrame *f = webview->page()->mainFrame(); - f->addToJavaScriptWindowObject(jsObjName, item); - } - resizeEvent(0); - delete component; - component = 0; - } - void resizeEvent(QResizeEvent*) - { - if (item) { - item->setX(x()); - item->setY(y()); - item->setWidth(width()); - item->setHeight(height()); - } - } - -private: - QDeclarativeComponent *component; - QDeclarativeItem *item; - QStringList propertyNames, propertyValues; - QDeclarativeWebView *webview; -}; - -QDeclarativeWebView *QDeclarativeWebPage::viewItem() -{ - return static_cast(parent()); -} - -QObject *QDeclarativeWebPage::createPlugin(const QString &, const QUrl &url, const QStringList ¶mNames, const QStringList ¶mValues) -{ - QUrl comp = qmlContext(viewItem())->resolvedUrl(url); - return new QWidget_Dummy_Plugin(comp,viewItem(),paramNames,paramValues); -} - -QWebPage *QDeclarativeWebPage::createWindow(WebWindowType type) -{ - QDeclarativeWebView *newView = viewItem()->createWindow(type); - if (newView) - return newView->page(); - return 0; -} - -QT_END_NAMESPACE - -#include diff --git a/src/plugins/qdeclarativemodules/webkitqmlplugin/qdeclarativewebview_p.h b/src/plugins/qdeclarativemodules/webkitqmlplugin/qdeclarativewebview_p.h deleted file mode 100644 index 0bb5d29..0000000 --- a/src/plugins/qdeclarativemodules/webkitqmlplugin/qdeclarativewebview_p.h +++ /dev/null @@ -1,285 +0,0 @@ -/**************************************************************************** -** -** 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 QDECLARATIVEWEBVIEW_H -#define QDECLARATIVEWEBVIEW_H - -#include - -#include -#include -#include -#include - -QT_BEGIN_HEADER - -class QWebHistory; -class QWebSettings; - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) -class QDeclarativeWebViewPrivate; -class QNetworkRequest; -class QDeclarativeWebView; - -class Q_DECLARATIVE_EXPORT QDeclarativeWebPage : public QWebPage -{ - Q_OBJECT -public: - explicit QDeclarativeWebPage(QDeclarativeWebView *parent); - ~QDeclarativeWebPage(); -protected: - QObject *createPlugin(const QString &classid, const QUrl &url, const QStringList ¶mNames, const QStringList ¶mValues); - QWebPage *createWindow(WebWindowType type); - void javaScriptConsoleMessage(const QString& message, int lineNumber, const QString& sourceID); - QString chooseFile(QWebFrame *originatingFrame, const QString& oldFile); - void javaScriptAlert(QWebFrame *originatingFrame, const QString& msg); - bool javaScriptConfirm(QWebFrame *originatingFrame, const QString& msg); - bool javaScriptPrompt(QWebFrame *originatingFrame, const QString& msg, const QString& defaultValue, QString* result); - -private: - QDeclarativeWebView *viewItem(); -}; - - -class QDeclarativeWebViewAttached; - -//### TODO: browser plugins - -class Q_DECLARATIVE_EXPORT QDeclarativeWebView : public QDeclarativePaintedItem -{ - Q_OBJECT - - Q_ENUMS(Status SelectionMode) - - Q_PROPERTY(QString title READ title NOTIFY titleChanged) - Q_PROPERTY(QPixmap icon READ icon NOTIFY iconChanged) - Q_PROPERTY(qreal zoomFactor READ zoomFactor WRITE setZoomFactor NOTIFY zoomFactorChanged) - Q_PROPERTY(QString statusText READ statusText NOTIFY statusTextChanged) - - Q_PROPERTY(QString html READ html WRITE setHtml NOTIFY htmlChanged) - - Q_PROPERTY(int pressGrabTime READ pressGrabTime WRITE setPressGrabTime NOTIFY pressGrabTimeChanged) - - Q_PROPERTY(int preferredWidth READ preferredWidth WRITE setPreferredWidth NOTIFY preferredWidthChanged) - Q_PROPERTY(int preferredHeight READ preferredHeight WRITE setPreferredHeight NOTIFY preferredHeightChanged) - Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY urlChanged) - Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged) - Q_PROPERTY(Status status READ status NOTIFY statusChanged) - - Q_PROPERTY(QAction* reload READ reloadAction CONSTANT) - Q_PROPERTY(QAction* back READ backAction CONSTANT) - Q_PROPERTY(QAction* forward READ forwardAction CONSTANT) - Q_PROPERTY(QAction* stop READ stopAction CONSTANT) - - Q_PROPERTY(QObject* settings READ settingsObject CONSTANT) - - Q_PROPERTY(QDeclarativeListProperty javaScriptWindowObjects READ javaScriptWindowObjects CONSTANT) - - Q_PROPERTY(QDeclarativeComponent* newWindowComponent READ newWindowComponent WRITE setNewWindowComponent NOTIFY newWindowComponentChanged) - Q_PROPERTY(QDeclarativeItem* newWindowParent READ newWindowParent WRITE setNewWindowParent NOTIFY newWindowParentChanged) - - Q_PROPERTY(bool renderingEnabled READ renderingEnabled WRITE setRenderingEnabled NOTIFY renderingEnabledChanged) - -public: - QDeclarativeWebView(QDeclarativeItem *parent=0); - ~QDeclarativeWebView(); - - QUrl url() const; - void setUrl(const QUrl &); - - QString title() const; - - QPixmap icon() const; - - qreal zoomFactor() const; - void setZoomFactor(qreal); - Q_INVOKABLE bool heuristicZoom(int clickX, int clickY, qreal maxzoom); - QRect elementAreaAt(int x, int y, int minwidth, int minheight) const; - - int pressGrabTime() const; - void setPressGrabTime(int); - - int preferredWidth() const; - void setPreferredWidth(int); - int preferredHeight() const; - void setPreferredHeight(int); - - enum Status { Null, Ready, Loading, Error }; - Status status() const; - qreal progress() const; - QString statusText() const; - - QAction *reloadAction() const; - QAction *backAction() const; - QAction *forwardAction() const; - QAction *stopAction() const; - - QWebPage *page() const; - void setPage(QWebPage *page); - - void load(const QNetworkRequest &request, - QNetworkAccessManager::Operation operation = QNetworkAccessManager::GetOperation, - const QByteArray &body = QByteArray()); - - QString html() const; - - void setHtml(const QString &html, const QUrl &baseUrl = QUrl()); - void setContent(const QByteArray &data, const QString &mimeType = QString(), const QUrl &baseUrl = QUrl()); - - QWebHistory *history() const; - QWebSettings *settings() const; - QObject *settingsObject() const; - - bool renderingEnabled() const; - void setRenderingEnabled(bool); - - QDeclarativeListProperty javaScriptWindowObjects(); - - static QDeclarativeWebViewAttached *qmlAttachedProperties(QObject *); - - QDeclarativeComponent *newWindowComponent() const; - void setNewWindowComponent(QDeclarativeComponent *newWindow); - QDeclarativeItem *newWindowParent() const; - void setNewWindowParent(QDeclarativeItem *newWindow); - -Q_SIGNALS: - void preferredWidthChanged(); - void preferredHeightChanged(); - void urlChanged(); - void progressChanged(); - void statusChanged(Status); - void titleChanged(const QString&); - void iconChanged(); - void statusTextChanged(); - void htmlChanged(); - void pressGrabTimeChanged(); - void zoomFactorChanged(); - void newWindowComponentChanged(); - void newWindowParentChanged(); - void renderingEnabledChanged(); - - void loadStarted(); - void loadFinished(); - void loadFailed(); - - void doubleClick(int clickX, int clickY); - - void zoomTo(qreal zoom, int centerX, int centerY); - - void alert(const QString& message); - -public Q_SLOTS: - QVariant evaluateJavaScript(const QString&); - -private Q_SLOTS: - void expandToWebPage(); - void paintPage(const QRect&); - void doLoadStarted(); - void doLoadProgress(int p); - void doLoadFinished(bool ok); - void setStatusText(const QString&); - void windowObjectCleared(); - void pageUrlChanged(); - void noteContentsSizeChanged(const QSize&); - void initialLayout(); - -protected: - void drawContents(QPainter *, const QRect &); - - void mousePressEvent(QGraphicsSceneMouseEvent *event); - void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); - void mouseMoveEvent(QGraphicsSceneMouseEvent *event); - void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); - void timerEvent(QTimerEvent *event); - void hoverMoveEvent (QGraphicsSceneHoverEvent * event); - void keyPressEvent(QKeyEvent* event); - void keyReleaseEvent(QKeyEvent* event); - virtual void geometryChanged(const QRectF &newGeometry, - const QRectF &oldGeometry); - virtual void focusChanged(bool); - virtual bool sceneEvent(QEvent *event); - QDeclarativeWebView *createWindow(QWebPage::WebWindowType type); - -private: - void init(); - virtual void componentComplete(); - Q_DISABLE_COPY(QDeclarativeWebView) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarativeWebView) - QMouseEvent *sceneMouseEventToMouseEvent(QGraphicsSceneMouseEvent *); - QMouseEvent *sceneHoverMoveEventToMouseEvent(QGraphicsSceneHoverEvent *); - friend class QDeclarativeWebPage; -}; - -class QDeclarativeWebViewAttached : public QObject -{ - Q_OBJECT - Q_PROPERTY(QString windowObjectName READ windowObjectName WRITE setWindowObjectName) -public: - QDeclarativeWebViewAttached(QObject *parent) - : QObject(parent) - { - } - - QString windowObjectName() const - { - return m_windowObjectName; - } - - void setWindowObjectName(const QString &n) - { - m_windowObjectName = n; - } - -private: - QString m_windowObjectName; -}; - - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QDeclarativeWebView) -QML_DECLARE_TYPEINFO(QDeclarativeWebView, QML_HAS_ATTACHED_PROPERTIES) - -QT_END_HEADER - -#endif diff --git a/src/plugins/qdeclarativemodules/webkitqmlplugin/qdeclarativewebview_p_p.h b/src/plugins/qdeclarativemodules/webkitqmlplugin/qdeclarativewebview_p_p.h deleted file mode 100644 index 258b472..0000000 --- a/src/plugins/qdeclarativemodules/webkitqmlplugin/qdeclarativewebview_p_p.h +++ /dev/null @@ -1,151 +0,0 @@ -/**************************************************************************** -** -** 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 QDECLARATIVEWEBVIEW_P_H -#define QDECLARATIVEWEBVIEW_P_H - -#include - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QDeclarativeWebSettings : public QObject { - Q_OBJECT - - Q_PROPERTY(QString standardFontFamily READ standardFontFamily WRITE setStandardFontFamily) - Q_PROPERTY(QString fixedFontFamily READ fixedFontFamily WRITE setFixedFontFamily) - Q_PROPERTY(QString serifFontFamily READ serifFontFamily WRITE setSerifFontFamily) - Q_PROPERTY(QString sansSerifFontFamily READ sansSerifFontFamily WRITE setSansSerifFontFamily) - Q_PROPERTY(QString cursiveFontFamily READ cursiveFontFamily WRITE setCursiveFontFamily) - Q_PROPERTY(QString fantasyFontFamily READ fantasyFontFamily WRITE setFantasyFontFamily) - - Q_PROPERTY(int minimumFontSize READ minimumFontSize WRITE setMinimumFontSize) - Q_PROPERTY(int minimumLogicalFontSize READ minimumLogicalFontSize WRITE setMinimumLogicalFontSize) - Q_PROPERTY(int defaultFontSize READ defaultFontSize WRITE setDefaultFontSize) - Q_PROPERTY(int defaultFixedFontSize READ defaultFixedFontSize WRITE setDefaultFixedFontSize) - - Q_PROPERTY(bool autoLoadImages READ autoLoadImages WRITE setAutoLoadImages) - Q_PROPERTY(bool javascriptEnabled READ javascriptEnabled WRITE setJavascriptEnabled) - Q_PROPERTY(bool javaEnabled READ javaEnabled WRITE setJavaEnabled) - Q_PROPERTY(bool pluginsEnabled READ pluginsEnabled WRITE setPluginsEnabled) - Q_PROPERTY(bool privateBrowsingEnabled READ privateBrowsingEnabled WRITE setPrivateBrowsingEnabled) - Q_PROPERTY(bool javascriptCanOpenWindows READ javascriptCanOpenWindows WRITE setJavascriptCanOpenWindows) - Q_PROPERTY(bool javascriptCanAccessClipboard READ javascriptCanAccessClipboard WRITE setJavascriptCanAccessClipboard) - Q_PROPERTY(bool developerExtrasEnabled READ developerExtrasEnabled WRITE setDeveloperExtrasEnabled) - Q_PROPERTY(bool linksIncludedInFocusChain READ linksIncludedInFocusChain WRITE setLinksIncludedInFocusChain) - Q_PROPERTY(bool zoomTextOnly READ zoomTextOnly WRITE setZoomTextOnly) - Q_PROPERTY(bool printElementBackgrounds READ printElementBackgrounds WRITE setPrintElementBackgrounds) - Q_PROPERTY(bool offlineStorageDatabaseEnabled READ offlineStorageDatabaseEnabled WRITE setOfflineStorageDatabaseEnabled) - Q_PROPERTY(bool offlineWebApplicationCacheEnabled READ offlineWebApplicationCacheEnabled WRITE setOfflineWebApplicationCacheEnabled) - Q_PROPERTY(bool localStorageDatabaseEnabled READ localStorageDatabaseEnabled WRITE setLocalStorageDatabaseEnabled) - Q_PROPERTY(bool localContentCanAccessRemoteUrls READ localContentCanAccessRemoteUrls WRITE setLocalContentCanAccessRemoteUrls) - -public: - QDeclarativeWebSettings() {} - - QString standardFontFamily() const { return s->fontFamily(QWebSettings::StandardFont); } - void setStandardFontFamily(const QString& f) { s->setFontFamily(QWebSettings::StandardFont,f); } - QString fixedFontFamily() const { return s->fontFamily(QWebSettings::FixedFont); } - void setFixedFontFamily(const QString& f) { s->setFontFamily(QWebSettings::FixedFont,f); } - QString serifFontFamily() const { return s->fontFamily(QWebSettings::SerifFont); } - void setSerifFontFamily(const QString& f) { s->setFontFamily(QWebSettings::SerifFont,f); } - QString sansSerifFontFamily() const { return s->fontFamily(QWebSettings::SansSerifFont); } - void setSansSerifFontFamily(const QString& f) { s->setFontFamily(QWebSettings::SansSerifFont,f); } - QString cursiveFontFamily() const { return s->fontFamily(QWebSettings::CursiveFont); } - void setCursiveFontFamily(const QString& f) { s->setFontFamily(QWebSettings::CursiveFont,f); } - QString fantasyFontFamily() const { return s->fontFamily(QWebSettings::FantasyFont); } - void setFantasyFontFamily(const QString& f) { s->setFontFamily(QWebSettings::FantasyFont,f); } - - int minimumFontSize() const { return s->fontSize(QWebSettings::MinimumFontSize); } - void setMinimumFontSize(int size) { s->setFontSize(QWebSettings::MinimumFontSize,size); } - int minimumLogicalFontSize() const { return s->fontSize(QWebSettings::MinimumLogicalFontSize); } - void setMinimumLogicalFontSize(int size) { s->setFontSize(QWebSettings::MinimumLogicalFontSize,size); } - int defaultFontSize() const { return s->fontSize(QWebSettings::DefaultFontSize); } - void setDefaultFontSize(int size) { s->setFontSize(QWebSettings::DefaultFontSize,size); } - int defaultFixedFontSize() const { return s->fontSize(QWebSettings::DefaultFixedFontSize); } - void setDefaultFixedFontSize(int size) { s->setFontSize(QWebSettings::DefaultFixedFontSize,size); } - - bool autoLoadImages() const { return s->testAttribute(QWebSettings::AutoLoadImages); } - void setAutoLoadImages(bool on) { s->setAttribute(QWebSettings::AutoLoadImages, on); } - bool javascriptEnabled() const { return s->testAttribute(QWebSettings::JavascriptEnabled); } - void setJavascriptEnabled(bool on) { s->setAttribute(QWebSettings::JavascriptEnabled, on); } - bool javaEnabled() const { return s->testAttribute(QWebSettings::JavaEnabled); } - void setJavaEnabled(bool on) { s->setAttribute(QWebSettings::JavaEnabled, on); } - bool pluginsEnabled() const { return s->testAttribute(QWebSettings::PluginsEnabled); } - void setPluginsEnabled(bool on) { s->setAttribute(QWebSettings::PluginsEnabled, on); } - bool privateBrowsingEnabled() const { return s->testAttribute(QWebSettings::PrivateBrowsingEnabled); } - void setPrivateBrowsingEnabled(bool on) { s->setAttribute(QWebSettings::PrivateBrowsingEnabled, on); } - bool javascriptCanOpenWindows() const { return s->testAttribute(QWebSettings::JavascriptCanOpenWindows); } - void setJavascriptCanOpenWindows(bool on) { s->setAttribute(QWebSettings::JavascriptCanOpenWindows, on); } - bool javascriptCanAccessClipboard() const { return s->testAttribute(QWebSettings::JavascriptCanAccessClipboard); } - void setJavascriptCanAccessClipboard(bool on) { s->setAttribute(QWebSettings::JavascriptCanAccessClipboard, on); } - bool developerExtrasEnabled() const { return s->testAttribute(QWebSettings::DeveloperExtrasEnabled); } - void setDeveloperExtrasEnabled(bool on) { s->setAttribute(QWebSettings::DeveloperExtrasEnabled, on); } - bool linksIncludedInFocusChain() const { return s->testAttribute(QWebSettings::LinksIncludedInFocusChain); } - void setLinksIncludedInFocusChain(bool on) { s->setAttribute(QWebSettings::LinksIncludedInFocusChain, on); } - bool zoomTextOnly() const { return s->testAttribute(QWebSettings::ZoomTextOnly); } - void setZoomTextOnly(bool on) { s->setAttribute(QWebSettings::ZoomTextOnly, on); } - bool printElementBackgrounds() const { return s->testAttribute(QWebSettings::PrintElementBackgrounds); } - void setPrintElementBackgrounds(bool on) { s->setAttribute(QWebSettings::PrintElementBackgrounds, on); } - bool offlineStorageDatabaseEnabled() const { return s->testAttribute(QWebSettings::OfflineStorageDatabaseEnabled); } - void setOfflineStorageDatabaseEnabled(bool on) { s->setAttribute(QWebSettings::OfflineStorageDatabaseEnabled, on); } - bool offlineWebApplicationCacheEnabled() const { return s->testAttribute(QWebSettings::OfflineWebApplicationCacheEnabled); } - void setOfflineWebApplicationCacheEnabled(bool on) { s->setAttribute(QWebSettings::OfflineWebApplicationCacheEnabled, on); } - bool localStorageDatabaseEnabled() const { return s->testAttribute(QWebSettings::LocalStorageDatabaseEnabled); } - void setLocalStorageDatabaseEnabled(bool on) { s->setAttribute(QWebSettings::LocalStorageDatabaseEnabled, on); } - bool localContentCanAccessRemoteUrls() const { return s->testAttribute(QWebSettings::LocalContentCanAccessRemoteUrls); } - void setLocalContentCanAccessRemoteUrls(bool on) { s->setAttribute(QWebSettings::LocalContentCanAccessRemoteUrls, on); } - - QWebSettings *s; -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QDeclarativeWebSettings) - -QT_END_HEADER - -#endif diff --git a/src/plugins/qdeclarativemodules/webkitqmlplugin/webkitqmlplugin.pro b/src/plugins/qdeclarativemodules/webkitqmlplugin/webkitqmlplugin.pro deleted file mode 100644 index 37fe37c..0000000 --- a/src/plugins/qdeclarativemodules/webkitqmlplugin/webkitqmlplugin.pro +++ /dev/null @@ -1,18 +0,0 @@ -TARGET = webkitqmlplugin -include(../../qpluginbase.pri) - -contains(QT_CONFIG, webkit) { - QT += webkit declarative - - SOURCES += qdeclarativewebview.cpp plugin.cpp - HEADERS += qdeclarativewebview_p.h - HEADERS += qdeclarativewebview_p_p.h - - QTDIR_build:DESTDIR = $$QT_BUILD_TREE/imports/org/webkit - target.path = $$[QT_INSTALL_IMPORTS]/org/webkit - - qmldir.files += $$QT_BUILD_TREE/imports/org/webkit/qmldir - qmldir.path += $$[QT_INSTALL_IMPORTS]/org/webkit - - INSTALLS += target qmldir -} diff --git a/src/plugins/qdeclarativemodules/widgets/graphicslayouts.cpp b/src/plugins/qdeclarativemodules/widgets/graphicslayouts.cpp deleted file mode 100644 index fc15ad2..0000000 --- a/src/plugins/qdeclarativemodules/widgets/graphicslayouts.cpp +++ /dev/null @@ -1,260 +0,0 @@ -/**************************************************************************** -** -** 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 -#include - -QT_BEGIN_NAMESPACE - -LinearLayoutAttached::LinearLayoutAttached(QObject *parent) -: QObject(parent), _stretch(1), _alignment(Qt::AlignCenter) -{ -} - -void LinearLayoutAttached::setStretchFactor(int f) -{ - if (_stretch == f) - return; - - _stretch = f; - emit stretchChanged(reinterpret_cast(parent()), _stretch); -} - -void LinearLayoutAttached::setAlignment(Qt::Alignment a) -{ - if (_alignment == a) - return; - - _alignment = a; - emit alignmentChanged(reinterpret_cast(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()); - 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))); - //### 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); -} - -void QGraphicsLinearLayoutObject::updateStretch(QGraphicsLayoutItem *item, int stretch) -{ -QGraphicsLinearLayout::setStretchFactor(item, stretch); -} - -void QGraphicsLinearLayoutObject::updateAlignment(QGraphicsLayoutItem *item, Qt::Alignment alignment) -{ -QGraphicsLinearLayout::setAlignment(item, alignment); -} - -QHash QGraphicsLinearLayoutObject::attachedProperties; -LinearLayoutAttached *QGraphicsLinearLayoutObject::qmlAttachedProperties(QObject *obj) -{ -// ### This is not allowed - you must attach to any object -if (!qobject_cast(obj)) - return 0; -LinearLayoutAttached *rv = new LinearLayoutAttached(obj); -attachedProperties.insert(qobject_cast(obj), rv); -return rv; -} - -////////////////////////////////////////////////////////////////////////////////////////////////////// -// QGraphicsGridLayout-related classes -////////////////////////////////////////////////////////////////////////////////////////////////////// -GridLayoutAttached::GridLayoutAttached(QObject *parent) -: QObject(parent), _row(-1), _column(-1), _rowspan(1), _colspan(1), _alignment(-1) -{ -} - -void GridLayoutAttached::setRow(int r) -{ - if (_row == r) - return; - - _row = r; - //emit rowChanged(reinterpret_cast(parent()), _row); -} - -void GridLayoutAttached::setColumn(int c) -{ - if (_column == c) - return; - - _column = c; - //emit columnChanged(reinterpret_cast(parent()), _column); -} - -void GridLayoutAttached::setRowSpan(int rs) -{ - if (_rowspan == rs) - return; - - _rowspan = rs; - //emit rowSpanChanged(reinterpret_cast(parent()), _rowSpan); -} - -void GridLayoutAttached::setColumnSpan(int cs) -{ - if (_colspan == cs) - return; - - _colspan = cs; - //emit columnSpanChanged(reinterpret_cast(parent()), _columnSpan); -} - -void GridLayoutAttached::setAlignment(Qt::Alignment a) -{ - if (_alignment == a) - return; - - _alignment = a; - //emit alignmentChanged(reinterpret_cast(parent()), _alignment); -} - -QGraphicsGridLayoutObject::QGraphicsGridLayoutObject(QObject *parent) -: QObject(parent) -{ -} - -QGraphicsGridLayoutObject::~QGraphicsGridLayoutObject() -{ -} - -void QGraphicsGridLayoutObject::addWidget(QGraphicsWidget *wid) -{ -//use attached properties -if (QObject *obj = attachedProperties.value(qobject_cast(wid))) { - int row = static_cast(obj)->row(); - int column = static_cast(obj)->column(); - int rowSpan = static_cast(obj)->rowSpan(); - int columnSpan = static_cast(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; - } - addItem(item, row, column, rowSpan, columnSpan); - if (alignment != -1) - setAlignment(item,alignment); -} -} - -//### 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; //### -} - -QHash QGraphicsGridLayoutObject::attachedProperties; -GridLayoutAttached *QGraphicsGridLayoutObject::qmlAttachedProperties(QObject *obj) -{ -// ### This is not allowed - you must attach to any object -if (!qobject_cast(obj)) - return 0; -GridLayoutAttached *rv = new GridLayoutAttached(obj); -attachedProperties.insert(qobject_cast(obj), rv); -return rv; -} - -QT_END_NAMESPACE diff --git a/src/plugins/qdeclarativemodules/widgets/graphicslayouts_p.h b/src/plugins/qdeclarativemodules/widgets/graphicslayouts_p.h deleted file mode 100644 index f9b9ae8..0000000 --- a/src/plugins/qdeclarativemodules/widgets/graphicslayouts_p.h +++ /dev/null @@ -1,226 +0,0 @@ -/**************************************************************************** -** -** 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 "graphicswidgets_p.h" - -#include -#include - -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 children READ children) - Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation) - Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing) - Q_CLASSINFO("DefaultProperty", "children") -public: - QGraphicsLinearLayoutObject(QObject * = 0); - ~QGraphicsLinearLayoutObject(); - - QDeclarativeListProperty children() { return QDeclarativeListProperty(this, 0, children_append, children_count, children_at, children_clear); } - - static LinearLayoutAttached *qmlAttachedProperties(QObject *); - -private Q_SLOTS: - void updateStretch(QGraphicsLayoutItem*,int); - void updateAlignment(QGraphicsLayoutItem*,Qt::Alignment); - -private: - friend class LinearLayoutAttached; - void clearChildren(); - void insertLayoutItem(int, QGraphicsLayoutItem *); - static QHash attachedProperties; - - static void children_append(QDeclarativeListProperty *prop, QGraphicsLayoutItem *item) { - static_cast(prop->object)->insertLayoutItem(-1, item); - } - - static void children_clear(QDeclarativeListProperty *prop) { - static_cast(prop->object)->clearChildren(); - } - - static int children_count(QDeclarativeListProperty *prop) { - return static_cast(prop->object)->count(); - } - - static QGraphicsLayoutItem *children_at(QDeclarativeListProperty *prop, int index) { - return static_cast(prop->object)->itemAt(index); - } -}; - -class GridLayoutAttached; -class QGraphicsGridLayoutObject : public QObject, public QGraphicsGridLayout -{ - Q_OBJECT - Q_INTERFACES(QGraphicsLayout QGraphicsLayoutItem) - - Q_PROPERTY(QDeclarativeListProperty children READ children) - Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing) - 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 children() { return QDeclarativeListProperty(this, 0, children_append, children_count, children_at, children_clear); } - - qreal spacing() const; - - static GridLayoutAttached *qmlAttachedProperties(QObject *); - -private: - friend class GraphicsLayoutAttached; - void addWidget(QGraphicsWidget *); - void clearChildren(); - void addLayoutItem(QGraphicsLayoutItem *); - static QHash attachedProperties; - - static void children_append(QDeclarativeListProperty *prop, QGraphicsLayoutItem *item) { - static_cast(prop->object)->addLayoutItem(item); - } - - static void children_clear(QDeclarativeListProperty *prop) { - static_cast(prop->object)->clearChildren(); - } - - static int children_count(QDeclarativeListProperty *prop) { - return static_cast(prop->object)->count(); - } - - static QGraphicsLayoutItem *children_at(QDeclarativeListProperty *prop, int index) { - return static_cast(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) -public: - LinearLayoutAttached(QObject *parent); - - int stretchFactor() const { return _stretch; } - void setStretchFactor(int f); - Qt::Alignment alignment() const { return _alignment; } - void setAlignment(Qt::Alignment a); - -Q_SIGNALS: - void stretchChanged(QGraphicsLayoutItem*,int); - void alignmentChanged(QGraphicsLayoutItem*,Qt::Alignment); - -private: - int _stretch; - Qt::Alignment _alignment; -}; - -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) -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); - -private: - int _row; - int _column; - int _rowspan; - int _colspan; - Qt::Alignment _alignment; -}; - -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/src/plugins/qdeclarativemodules/widgets/graphicswidgets.cpp b/src/plugins/qdeclarativemodules/widgets/graphicswidgets.cpp deleted file mode 100644 index 062e516..0000000 --- a/src/plugins/qdeclarativemodules/widgets/graphicswidgets.cpp +++ /dev/null @@ -1,40 +0,0 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ diff --git a/src/plugins/qdeclarativemodules/widgets/graphicswidgets_p.h b/src/plugins/qdeclarativemodules/widgets/graphicswidgets_p.h deleted file mode 100644 index 2c2b707..0000000 --- a/src/plugins/qdeclarativemodules/widgets/graphicswidgets_p.h +++ /dev/null @@ -1,68 +0,0 @@ -/**************************************************************************** -** -** 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 GRAPHICSWIDGETS_H -#define GRAPHICSWIDGETS_H - -#include - -#include -#include -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QGraphicsView) -QML_DECLARE_TYPE_HASMETATYPE(QGraphicsScene) -QML_DECLARE_TYPE(QGraphicsWidget) -QML_DECLARE_TYPE(QGraphicsObject) -QML_DECLARE_INTERFACE_HASMETATYPE(QGraphicsItem) - -QT_END_HEADER - -#endif // GRAPHICSWIDGETS_H diff --git a/src/plugins/qdeclarativemodules/widgets/widgets.cpp b/src/plugins/qdeclarativemodules/widgets/widgets.cpp deleted file mode 100644 index ec21cc4..0000000 --- a/src/plugins/qdeclarativemodules/widgets/widgets.cpp +++ /dev/null @@ -1,138 +0,0 @@ -/**************************************************************************** -** -** 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 -#include - -#include "graphicslayouts_p.h" -#include "graphicswidgets_p.h" - -QT_BEGIN_NAMESPACE - -class QGraphicsViewDeclarativeUI : public QObject -{ - Q_OBJECT - - Q_PROPERTY(QGraphicsScene *scene READ scene WRITE setScene) - Q_CLASSINFO("DefaultProperty", "scene") -public: - QGraphicsViewDeclarativeUI(QObject *other) : QObject(other) {} - - QGraphicsScene *scene() const { return static_cast(parent())->scene(); } - void setScene(QGraphicsScene *scene) - { - static_cast(parent())->setScene(scene); - } -}; - -class QGraphicsSceneDeclarativeUI : public QObject -{ - Q_OBJECT - - Q_PROPERTY(QDeclarativeListProperty children READ children) - Q_CLASSINFO("DefaultProperty", "children") -public: - QGraphicsSceneDeclarativeUI(QObject *other) : QObject(other) {} - - QDeclarativeListProperty children() { return QDeclarativeListProperty(this->parent(), 0, children_append); } - -private: - static void children_append(QDeclarativeListProperty *prop, QObject *o) { - if (QGraphicsObject *go = qobject_cast(o)) - static_cast(prop->object)->addItem(go); - } -}; - -class QGraphicsWidgetDeclarativeUI : public QObject -{ - Q_OBJECT - - Q_PROPERTY(QDeclarativeListProperty children READ children) - Q_PROPERTY(QGraphicsLayout *layout READ layout WRITE setLayout) - Q_CLASSINFO("DefaultProperty", "children") -public: - QGraphicsWidgetDeclarativeUI(QObject *other) : QObject(other) {} - - QDeclarativeListProperty children() { return QDeclarativeListProperty(this, 0, children_append); } - - QGraphicsLayout *layout() const { return static_cast(parent())->layout(); } - void setLayout(QGraphicsLayout *lo) - { - static_cast(parent())->setLayout(lo); - } - -private: - void setItemParent(QGraphicsItem *wid) - { - wid->setParentItem(static_cast(parent())); - } - - static void children_append(QDeclarativeListProperty *prop, QGraphicsItem *i) { - static_cast(prop->object)->setItemParent(i); - } -}; - -class QWidgetsQmlModule : public QDeclarativeExtensionPlugin -{ - Q_OBJECT -public: - virtual void registerTypes(const char *uri) - { - Q_ASSERT(QLatin1String(uri) == QLatin1String("Qt.widgets")); - - QML_REGISTER_INTERFACE(QGraphicsLayoutItem); - QML_REGISTER_INTERFACE(QGraphicsLayout); - qmlRegisterType(uri,4,6,"QGraphicsLinearLayoutStretchItem"); - qmlRegisterType(uri,4,6,"QGraphicsLinearLayout"); - qmlRegisterType(uri,4,6,"QGraphicsGridLayout"); - qmlRegisterExtendedType(uri,4,6,"QGraphicsView"); - qmlRegisterExtendedType(uri,4,6,"QGraphicsScene"); - qmlRegisterExtendedType(uri,4,6,"QGraphicsWidget"); - QML_REGISTER_INTERFACE(QGraphicsItem); - } -}; - -QT_END_NAMESPACE - -#include "widgets.moc" - -Q_EXPORT_PLUGIN2(qtwidgetsqmlmodule, QT_PREPEND_NAMESPACE(QWidgetsQmlModule)); - diff --git a/src/plugins/qdeclarativemodules/widgets/widgets.pro b/src/plugins/qdeclarativemodules/widgets/widgets.pro deleted file mode 100644 index 3ec38da..0000000 --- a/src/plugins/qdeclarativemodules/widgets/widgets.pro +++ /dev/null @@ -1,20 +0,0 @@ -TARGET = widgets -include(../../qpluginbase.pri) - -QT += declarative - -SOURCES += \ - graphicslayouts.cpp \ - widgets.cpp - -HEADERS += \ - graphicswidgets_p.h \ - graphicslayouts_p.h - -QTDIR_build:DESTDIR = $$QT_BUILD_TREE/imports/Qt/widgets -target.path = $$[QT_INSTALL_IMPORTS]/Qt/widgets - -qmldir.files += $$QT_BUILD_TREE/imports/Qt/widgets/qmldir -qmldir.path += $$[QT_INSTALL_IMPORTS]/Qt/widgets - -INSTALLS += target qmldir -- cgit v0.12 From b277a6932c32ce4bae015cce6e1c00c322b4a63b Mon Sep 17 00:00:00 2001 From: mae Date: Tue, 2 Mar 2010 12:13:44 +0100 Subject: Let the 'qml' runtime use its applicationDirPath as importsPath The is analog to the plugin system in Qt. It makes it possible to ship an executable with extra plugins resp. qml import modules without creating a qt.conf. --- tools/qml/main.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/qml/main.cpp b/tools/qml/main.cpp index 6339813..a4de339 100644 --- a/tools/qml/main.cpp +++ b/tools/qml/main.cpp @@ -311,8 +311,11 @@ int main(int argc, char ** argv) usage(); } + viewer.addLibraryPath(QCoreApplication::applicationDirPath()); + foreach (QString lib, libraries) viewer.addLibraryPath(lib); + viewer.setNetworkCacheSize(cache); viewer.setRecordFile(recordfile); if (resizeview) -- cgit v0.12 From e0a9e34b6e776be1df3b3fae68d20f242aa07e6a Mon Sep 17 00:00:00 2001 From: mae Date: Tue, 2 Mar 2010 12:39:38 +0100 Subject: Fix qml import modules loading on Windows On windows, when importing a declarative plugin by name, extend with "d.dll" in the debug case, then with ".dll". This is in sync with qmake's behaviour for libraries. --- src/declarative/qml/qdeclarativeengine.cpp | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index af75e98..277c602 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -1687,6 +1687,7 @@ QString QDeclarativeEngine::offlineStoragePath() const \internal Returns the result of the merge of \a baseName with \a dir, \a suffixes, and \a prefix. + The \a prefix must contain the dot. */ QString QDeclarativeEnginePrivate::resolvePlugin(const QDir &dir, const QString &baseName, const QStringList &suffixes, @@ -1696,7 +1697,6 @@ QString QDeclarativeEnginePrivate::resolvePlugin(const QDir &dir, const QString QString pluginFileName = prefix; pluginFileName += baseName; - pluginFileName += QLatin1Char('.'); pluginFileName += suffix; QFileInfo fileInfo(dir, pluginFileName); @@ -1728,14 +1728,26 @@ QString QDeclarativeEnginePrivate::resolvePlugin(const QDir &dir, const QString QString QDeclarativeEnginePrivate::resolvePlugin(const QDir &dir, const QString &baseName) { #if defined(Q_OS_WIN32) || defined(Q_OS_WINCE) - return resolvePlugin(dir, baseName, QStringList(QLatin1String("dll"))); + return resolvePlugin(dir, baseName, + QStringList() +# ifdef QT_DEBUG + << QLatin1String("d.dll") // try a qmake-style debug build first +# endif + << QLatin1String(".dll"); #elif defined(Q_OS_SYMBIAN) - return resolvePlugin(dir, baseName, QStringList() << QLatin1String("dll") << QLatin1String("qtplugin")); + return resolvePlugin(dir, baseName, + QStringList() + << QLatin1String(".dll") + << QLatin1String(".qtplugin")); #else # if defined(Q_OS_DARWIN) - return resolvePlugin(dir, baseName, QStringList() << QLatin1String("dylib") << QLatin1String("so") << QLatin1String("bundle"), + return resolvePlugin(dir, baseName, + QStringList() + << QLatin1String(".dylib") + << QLatin1String(".so") + << QLatin1String(".bundle"), QLatin1String("lib")); # else // Generic Unix QStringList validSuffixList; @@ -1746,14 +1758,14 @@ QString QDeclarativeEnginePrivate::resolvePlugin(const QDir &dir, const QString "In PA-RISC (PA-32 and PA-64) shared libraries are suffixed with .sl. In IPF (32-bit and 64-bit), the shared libraries are suffixed with .so. For compatibility, the IPF linker also supports the .sl suffix." */ - validSuffixList << QLatin1String("sl"); + validSuffixList << QLatin1String(".sl"); # if defined __ia64 - validSuffixList << QLatin1String("so"); + validSuffixList << QLatin1String(".so"); # endif # elif defined(Q_OS_AIX) - validSuffixList << QLatin1String("a") << QLatin1String("so"); + validSuffixList << QLatin1String(".a") << QLatin1String(".so"); # elif defined(Q_OS_UNIX) - validSuffixList << QLatin1String("so"); + validSuffixList << QLatin1String(".so"); # endif // Examples of valid library names: -- cgit v0.12 From 2afda558815bc29c1f54e7b9bcc0312369dd7d79 Mon Sep 17 00:00:00 2001 From: Tobias Hunger Date: Tue, 2 Mar 2010 13:41:05 +0100 Subject: Build fix on windows --- src/declarative/qml/qdeclarativeengine.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index 277c602..ecaea61 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -1733,7 +1733,7 @@ QString QDeclarativeEnginePrivate::resolvePlugin(const QDir &dir, const QString # ifdef QT_DEBUG << QLatin1String("d.dll") // try a qmake-style debug build first # endif - << QLatin1String(".dll"); + << QLatin1String(".dll")); #elif defined(Q_OS_SYMBIAN) return resolvePlugin(dir, baseName, QStringList() -- cgit v0.12 From 89429d192dc14044f6d27c9dde06811f1f23b954 Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Tue, 2 Mar 2010 14:17:08 +0100 Subject: Compile fix on Windows --- src/declarative/qml/qdeclarativelist.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/declarative/qml/qdeclarativelist.h b/src/declarative/qml/qdeclarativelist.h index 8d59384..eac4967 100644 --- a/src/declarative/qml/qdeclarativelist.h +++ b/src/declarative/qml/qdeclarativelist.h @@ -53,7 +53,7 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) class QObject; -class QMetaObject; +struct QMetaObject; template struct QDeclarativeListProperty { typedef void (*AppendFunction)(QDeclarativeListProperty *, T*); -- cgit v0.12 From 7fd5ade07bd05ff6cb6f4e7cfa7a74081b803809 Mon Sep 17 00:00:00 2001 From: mae Date: Tue, 2 Mar 2010 15:00:23 +0100 Subject: Adapted example to use the import mechanism --- .../imageprovider/ImageProviderCore/qmldir | 2 + .../declarative/imageprovider/imageprovider.cpp | 107 +++++++++++++++++++++ .../declarative/imageprovider/imageprovider.pro | 14 +-- .../declarative/imageprovider/imageprovider.qml | 23 +++++ .../declarative/imageprovider/imageprovider.qrc | 5 - examples/declarative/imageprovider/main.cpp | 98 ------------------- examples/declarative/imageprovider/view.qml | 22 ----- 7 files changed, 140 insertions(+), 131 deletions(-) create mode 100644 examples/declarative/imageprovider/ImageProviderCore/qmldir create mode 100644 examples/declarative/imageprovider/imageprovider.cpp create mode 100644 examples/declarative/imageprovider/imageprovider.qml delete mode 100644 examples/declarative/imageprovider/imageprovider.qrc delete mode 100644 examples/declarative/imageprovider/main.cpp delete mode 100644 examples/declarative/imageprovider/view.qml diff --git a/examples/declarative/imageprovider/ImageProviderCore/qmldir b/examples/declarative/imageprovider/ImageProviderCore/qmldir new file mode 100644 index 0000000..1028590 --- /dev/null +++ b/examples/declarative/imageprovider/ImageProviderCore/qmldir @@ -0,0 +1,2 @@ +plugin imageprovider + diff --git a/examples/declarative/imageprovider/imageprovider.cpp b/examples/declarative/imageprovider/imageprovider.cpp new file mode 100644 index 0000000..253dbf5 --- /dev/null +++ b/examples/declarative/imageprovider/imageprovider.cpp @@ -0,0 +1,107 @@ +/**************************************************************************** +** +** 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 + +#include +#include +#include +#include +#include +#include +#include +#include + +/* + 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) { + QImage image(100, 50, QImage::Format_RGB32); + image.fill(QColor(id).rgba()); + QPainter p(&image); + p.setPen(Qt::black); + 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); + diff --git a/examples/declarative/imageprovider/imageprovider.pro b/examples/declarative/imageprovider/imageprovider.pro index 60423ab..e403bf8 100644 --- a/examples/declarative/imageprovider/imageprovider.pro +++ b/examples/declarative/imageprovider/imageprovider.pro @@ -1,9 +1,11 @@ -TEMPLATE = app -TARGET = imageprovider -DEPENDPATH += . -INCLUDEPATH += . +TEMPLATE = lib +TARGET = imageprovider QT += declarative +CONFIG += qt plugin + +TARGET = $$qtLibraryTarget($$TARGET) +DESTDIR = ImageProviderCore # Input -SOURCES += main.cpp -RESOURCES += imageprovider.qrc +SOURCES += imageprovider.cpp + diff --git a/examples/declarative/imageprovider/imageprovider.qml b/examples/declarative/imageprovider/imageprovider.qml new file mode 100644 index 0000000..a1f2794 --- /dev/null +++ b/examples/declarative/imageprovider/imageprovider.qml @@ -0,0 +1,23 @@ +import Qt 4.6 +import ImageProviderCore 1.0 +//![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 + } + } + } +} +//![0] diff --git a/examples/declarative/imageprovider/imageprovider.qrc b/examples/declarative/imageprovider/imageprovider.qrc deleted file mode 100644 index 17e9301..0000000 --- a/examples/declarative/imageprovider/imageprovider.qrc +++ /dev/null @@ -1,5 +0,0 @@ - - - view.qml - - diff --git a/examples/declarative/imageprovider/main.cpp b/examples/declarative/imageprovider/main.cpp deleted file mode 100644 index d9d4c1a..0000000 --- a/examples/declarative/imageprovider/main.cpp +++ /dev/null @@ -1,98 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include -#include -#include -#include -#include -#include -#include -#include - -/* - 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) { - QImage image(100, 50, QImage::Format_RGB32); - image.fill(QColor(id).rgba()); - QPainter p(&image); - p.setPen(Qt::black); - p.drawText(QRectF(0,0,100,50),Qt::AlignCenter,id); - return image; - } -}; - -int main(int argc, char ** argv) -{ - QApplication app(argc, argv); - - QDeclarativeView view; - - view.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 = view.rootContext(); - ctxt->setContextProperty("myModel", QVariant::fromValue(dataList)); - - view.setSource(QUrl("qrc:view.qml")); - view.show(); - - return app.exec(); -} -//![0] diff --git a/examples/declarative/imageprovider/view.qml b/examples/declarative/imageprovider/view.qml deleted file mode 100644 index 2ab729d..0000000 --- a/examples/declarative/imageprovider/view.qml +++ /dev/null @@ -1,22 +0,0 @@ -import Qt 4.6 -//![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 - } - } - } -} -//![0] -- cgit v0.12 From f56893bbffd5eb26dd77e56707615cbb11a26c9b Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Tue, 2 Mar 2010 15:41:16 +0100 Subject: Rewrite Minehunt demo to use the runtime. --- demos/declarative/minehunt/Description.qml | 34 -- demos/declarative/minehunt/Explosion.qml | 26 -- .../minehunt/MinehuntCore/Explosion.qml | 26 ++ .../MinehuntCore/pics/No-Ones-Laughing-3.jpg | Bin 0 -> 30730 bytes .../minehunt/MinehuntCore/pics/back.png | Bin 0 -> 558 bytes .../minehunt/MinehuntCore/pics/bomb-color.png | Bin 0 -> 284 bytes .../minehunt/MinehuntCore/pics/bomb.png | Bin 0 -> 535 bytes .../minehunt/MinehuntCore/pics/face-sad.png | Bin 0 -> 14844 bytes .../minehunt/MinehuntCore/pics/face-smile-big.png | Bin 0 -> 13810 bytes .../minehunt/MinehuntCore/pics/face-smile.png | Bin 0 -> 15408 bytes .../minehunt/MinehuntCore/pics/flag-color.png | Bin 0 -> 219 bytes .../minehunt/MinehuntCore/pics/flag.png | Bin 0 -> 196 bytes .../minehunt/MinehuntCore/pics/front.png | Bin 0 -> 580 bytes .../minehunt/MinehuntCore/pics/star.png | Bin 0 -> 2677 bytes demos/declarative/minehunt/MinehuntCore/qmldir | 2 + demos/declarative/minehunt/main.cpp | 351 --------------------- demos/declarative/minehunt/minehunt.cpp | 314 ++++++++++++++++++ demos/declarative/minehunt/minehunt.pro | 16 +- demos/declarative/minehunt/minehunt.qml | 24 +- .../minehunt/pics/No-Ones-Laughing-3.jpg | Bin 30730 -> 0 bytes demos/declarative/minehunt/pics/back.png | Bin 558 -> 0 bytes demos/declarative/minehunt/pics/bomb-color.png | Bin 284 -> 0 bytes demos/declarative/minehunt/pics/bomb.png | Bin 535 -> 0 bytes demos/declarative/minehunt/pics/face-sad.png | Bin 14844 -> 0 bytes demos/declarative/minehunt/pics/face-smile-big.png | Bin 13810 -> 0 bytes demos/declarative/minehunt/pics/face-smile.png | Bin 15408 -> 0 bytes demos/declarative/minehunt/pics/flag-color.png | Bin 219 -> 0 bytes demos/declarative/minehunt/pics/flag.png | Bin 196 -> 0 bytes demos/declarative/minehunt/pics/front.png | Bin 580 -> 0 bytes demos/declarative/minehunt/pics/star.png | Bin 2677 -> 0 bytes demos/declarative/minehunt/test.qml | 13 - 31 files changed, 360 insertions(+), 446 deletions(-) delete mode 100644 demos/declarative/minehunt/Description.qml delete mode 100644 demos/declarative/minehunt/Explosion.qml create mode 100644 demos/declarative/minehunt/MinehuntCore/Explosion.qml create mode 100644 demos/declarative/minehunt/MinehuntCore/pics/No-Ones-Laughing-3.jpg create mode 100644 demos/declarative/minehunt/MinehuntCore/pics/back.png create mode 100644 demos/declarative/minehunt/MinehuntCore/pics/bomb-color.png create mode 100644 demos/declarative/minehunt/MinehuntCore/pics/bomb.png create mode 100644 demos/declarative/minehunt/MinehuntCore/pics/face-sad.png create mode 100644 demos/declarative/minehunt/MinehuntCore/pics/face-smile-big.png create mode 100644 demos/declarative/minehunt/MinehuntCore/pics/face-smile.png create mode 100644 demos/declarative/minehunt/MinehuntCore/pics/flag-color.png create mode 100644 demos/declarative/minehunt/MinehuntCore/pics/flag.png create mode 100644 demos/declarative/minehunt/MinehuntCore/pics/front.png create mode 100644 demos/declarative/minehunt/MinehuntCore/pics/star.png create mode 100644 demos/declarative/minehunt/MinehuntCore/qmldir delete mode 100644 demos/declarative/minehunt/main.cpp create mode 100644 demos/declarative/minehunt/minehunt.cpp delete mode 100644 demos/declarative/minehunt/pics/No-Ones-Laughing-3.jpg delete mode 100644 demos/declarative/minehunt/pics/back.png delete mode 100644 demos/declarative/minehunt/pics/bomb-color.png delete mode 100644 demos/declarative/minehunt/pics/bomb.png delete mode 100644 demos/declarative/minehunt/pics/face-sad.png delete mode 100644 demos/declarative/minehunt/pics/face-smile-big.png delete mode 100644 demos/declarative/minehunt/pics/face-smile.png delete mode 100644 demos/declarative/minehunt/pics/flag-color.png delete mode 100644 demos/declarative/minehunt/pics/flag.png delete mode 100644 demos/declarative/minehunt/pics/front.png delete mode 100644 demos/declarative/minehunt/pics/star.png delete mode 100644 demos/declarative/minehunt/test.qml diff --git a/demos/declarative/minehunt/Description.qml b/demos/declarative/minehunt/Description.qml deleted file mode 100644 index cc4d3b2..0000000 --- a/demos/declarative/minehunt/Description.qml +++ /dev/null @@ -1,34 +0,0 @@ -import Qt 4.6 - -Item { - id: page - height: myText.height + 20 - property var text - MouseArea { - anchors.fill: parent - drag.target: page - drag.axis: "XandYAxis" - drag.minimumX: 0 - drag.maximumX: 1000 - drag.minimumY: 0 - drag.maximumY: 1000 - } - Rectangle { - radius: 10 - anchors.fill: parent - color: "lightsteelblue" - } - Item { - x: 10 - y: 10 - width: parent.width - 20 - height: parent.height - 20 - Text { - id: myText - text: page.text - width: parent.width - clip: true - wrap: true - } - } -} diff --git a/demos/declarative/minehunt/Explosion.qml b/demos/declarative/minehunt/Explosion.qml deleted file mode 100644 index e337c46..0000000 --- a/demos/declarative/minehunt/Explosion.qml +++ /dev/null @@ -1,26 +0,0 @@ -import Qt 4.6 - -Item { - property bool explode : false - - Particles { - id: particles - width: 40 - height: 40 - lifeSpan: 1000 - lifeSpanDeviation: 0 - source: "pics/star.png" - count: 0 - angle: 270 - angleDeviation: 360 - velocity: 100 - velocityDeviation: 20 - z: 100 - opacity: 1 - } - states: [ State { name: "exploding"; when: explode == true - StateChangeScript {script: particles.burst(200); } - } - ] - -} diff --git a/demos/declarative/minehunt/MinehuntCore/Explosion.qml b/demos/declarative/minehunt/MinehuntCore/Explosion.qml new file mode 100644 index 0000000..e337c46 --- /dev/null +++ b/demos/declarative/minehunt/MinehuntCore/Explosion.qml @@ -0,0 +1,26 @@ +import Qt 4.6 + +Item { + property bool explode : false + + Particles { + id: particles + width: 40 + height: 40 + lifeSpan: 1000 + lifeSpanDeviation: 0 + source: "pics/star.png" + count: 0 + angle: 270 + angleDeviation: 360 + velocity: 100 + velocityDeviation: 20 + z: 100 + opacity: 1 + } + states: [ State { name: "exploding"; when: explode == true + StateChangeScript {script: particles.burst(200); } + } + ] + +} diff --git a/demos/declarative/minehunt/MinehuntCore/pics/No-Ones-Laughing-3.jpg b/demos/declarative/minehunt/MinehuntCore/pics/No-Ones-Laughing-3.jpg new file mode 100644 index 0000000..445567f Binary files /dev/null and b/demos/declarative/minehunt/MinehuntCore/pics/No-Ones-Laughing-3.jpg differ diff --git a/demos/declarative/minehunt/MinehuntCore/pics/back.png b/demos/declarative/minehunt/MinehuntCore/pics/back.png new file mode 100644 index 0000000..f6b3f0b Binary files /dev/null and b/demos/declarative/minehunt/MinehuntCore/pics/back.png differ diff --git a/demos/declarative/minehunt/MinehuntCore/pics/bomb-color.png b/demos/declarative/minehunt/MinehuntCore/pics/bomb-color.png new file mode 100644 index 0000000..61ad0a9 Binary files /dev/null and b/demos/declarative/minehunt/MinehuntCore/pics/bomb-color.png differ diff --git a/demos/declarative/minehunt/MinehuntCore/pics/bomb.png b/demos/declarative/minehunt/MinehuntCore/pics/bomb.png new file mode 100644 index 0000000..a992575 Binary files /dev/null and b/demos/declarative/minehunt/MinehuntCore/pics/bomb.png differ diff --git a/demos/declarative/minehunt/MinehuntCore/pics/face-sad.png b/demos/declarative/minehunt/MinehuntCore/pics/face-sad.png new file mode 100644 index 0000000..cf00aaf Binary files /dev/null and b/demos/declarative/minehunt/MinehuntCore/pics/face-sad.png differ diff --git a/demos/declarative/minehunt/MinehuntCore/pics/face-smile-big.png b/demos/declarative/minehunt/MinehuntCore/pics/face-smile-big.png new file mode 100644 index 0000000..f9c2335 Binary files /dev/null and b/demos/declarative/minehunt/MinehuntCore/pics/face-smile-big.png differ diff --git a/demos/declarative/minehunt/MinehuntCore/pics/face-smile.png b/demos/declarative/minehunt/MinehuntCore/pics/face-smile.png new file mode 100644 index 0000000..3d66d72 Binary files /dev/null and b/demos/declarative/minehunt/MinehuntCore/pics/face-smile.png differ diff --git a/demos/declarative/minehunt/MinehuntCore/pics/flag-color.png b/demos/declarative/minehunt/MinehuntCore/pics/flag-color.png new file mode 100644 index 0000000..aadad0f Binary files /dev/null and b/demos/declarative/minehunt/MinehuntCore/pics/flag-color.png differ diff --git a/demos/declarative/minehunt/MinehuntCore/pics/flag.png b/demos/declarative/minehunt/MinehuntCore/pics/flag.png new file mode 100644 index 0000000..39cde4d Binary files /dev/null and b/demos/declarative/minehunt/MinehuntCore/pics/flag.png differ diff --git a/demos/declarative/minehunt/MinehuntCore/pics/front.png b/demos/declarative/minehunt/MinehuntCore/pics/front.png new file mode 100644 index 0000000..834331b Binary files /dev/null and b/demos/declarative/minehunt/MinehuntCore/pics/front.png differ diff --git a/demos/declarative/minehunt/MinehuntCore/pics/star.png b/demos/declarative/minehunt/MinehuntCore/pics/star.png new file mode 100644 index 0000000..3772359 Binary files /dev/null and b/demos/declarative/minehunt/MinehuntCore/pics/star.png differ diff --git a/demos/declarative/minehunt/MinehuntCore/qmldir b/demos/declarative/minehunt/MinehuntCore/qmldir new file mode 100644 index 0000000..862c396 --- /dev/null +++ b/demos/declarative/minehunt/MinehuntCore/qmldir @@ -0,0 +1,2 @@ +plugin minehunt +Explosion 1.0 Explosion.qml diff --git a/demos/declarative/minehunt/main.cpp b/demos/declarative/minehunt/main.cpp deleted file mode 100644 index 99856ed..0000000 --- a/demos/declarative/minehunt/main.cpp +++ /dev/null @@ -1,351 +0,0 @@ -/**************************************************************************** -** -** 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 "qdeclarativeengine.h" -#include "qdeclarativecontext.h" -#include "qdeclarative.h" -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -QString fileName = "minehunt.qml"; - -class Tile : public QObject -{ - Q_OBJECT -public: - Tile() : _hasFlag(false), _hasMine(false), _hint(-1), _flipped(false) {} - - Q_PROPERTY(bool hasFlag READ hasFlag WRITE setHasFlag NOTIFY hasFlagChanged); - bool hasFlag() const { return _hasFlag; } - - Q_PROPERTY(bool hasMine READ hasMine NOTIFY hasMineChanged); - bool hasMine() const { return _hasMine; } - - Q_PROPERTY(int hint READ hint NOTIFY hintChanged); - int hint() const { return _hint; } - - Q_PROPERTY(bool flipped READ flipped NOTIFY flippedChanged()); - bool flipped() const { return _flipped; } - - void setHasFlag(bool flag) {if(flag==_hasFlag) return; _hasFlag = flag; emit hasFlagChanged();} - void setHasMine(bool mine) {if(mine==_hasMine) return; _hasMine = mine; emit hasMineChanged();} - void setHint(int hint) { if(hint == _hint) return; _hint = hint; emit hintChanged(); } - void flip() { if (_flipped) return; _flipped = true; emit flippedChanged(); } - void unflip() { if(!_flipped) return; _flipped = false; emit flippedChanged(); } - -signals: - void flippedChanged(); - void hasFlagChanged(); - void hintChanged(); - void hasMineChanged(); - -private: - bool _hasFlag; - bool _hasMine; - int _hint; - bool _flipped; -}; - -QML_DECLARE_TYPE(Tile); - -class MyWidget : public QWidget -{ -Q_OBJECT -public: - MyWidget(int = 370, int = 480, QWidget *parent=0, Qt::WindowFlags flags=0); - ~MyWidget(); - - Q_PROPERTY(QDeclarativeListProperty tiles READ tiles CONSTANT); - QDeclarativeListProperty tiles() { return QDeclarativeListProperty(this, _tiles); } - - Q_PROPERTY(bool isPlaying READ isPlaying NOTIFY isPlayingChanged); - bool isPlaying() {return playing;} - - Q_PROPERTY(bool hasWon READ hasWon NOTIFY hasWonChanged); - bool hasWon() {return won;} - - Q_PROPERTY(int numMines READ numMines NOTIFY numMinesChanged); - int numMines() const{return nMines;} - - Q_PROPERTY(int numFlags READ numFlags NOTIFY numFlagsChanged); - int numFlags() const{return nFlags;} - -public slots: - Q_INVOKABLE bool flip(int row, int col); - Q_INVOKABLE bool flag(int row, int col); - void setBoard(); - void reset(); - -signals: - void isPlayingChanged(); - void hasWonChanged(); - void numMinesChanged(); - void numFlagsChanged(); - -private: - bool onBoard( int r, int c ) const { return r >= 0 && r < numRows && c >= 0 && c < numCols; } - Tile *tile( int row, int col ) { return onBoard(row, col) ? _tiles[col+numRows*row] : 0; } - int getHint(int row, int col); - void setPlaying(bool b){if(b==playing) return; playing=b; emit isPlayingChanged();} - - QDeclarativeView *canvas; - - QList _tiles; - int numCols; - int numRows; - bool playing; - bool won; - int remaining; - int nMines; - int nFlags; -}; - -Q_DECLARE_METATYPE(QList) -MyWidget::MyWidget(int width, int height, QWidget *parent, Qt::WindowFlags flags) -: QWidget(parent, flags), canvas(0), numCols(9), numRows(9), playing(true), won(false) -{ - setObjectName("mainWidget"); - srand(QTime(0,0,0).secsTo(QTime::currentTime())); - - //initialize array - for(int ii = 0; ii < numRows * numCols; ++ii) { - _tiles << new Tile; - } - reset(); - - QVBoxLayout *vbox = new QVBoxLayout; - vbox->setMargin(0); - setLayout(vbox); - - canvas = new QDeclarativeView(this); - canvas->setFixedSize(width, height); - vbox->addWidget(canvas); - - QDeclarativeContext *ctxt = canvas->rootContext(); - ctxt->addDefaultObject(this); - - canvas->setSource(QUrl::fromLocalFile(fileName)); -} - -MyWidget::~MyWidget() -{ -} - -void MyWidget::setBoard() -{ - foreach(Tile* t, _tiles){ - t->setHasMine(false); - t->setHint(-1); - } - //place mines - int mines = nMines; - remaining = numRows*numCols-mines; - while ( mines ) { - int col = int((double(rand()) / double(RAND_MAX)) * numCols); - int row = int((double(rand()) / double(RAND_MAX)) * numRows); - - Tile* t = tile( row, col ); - - if (t && !t->hasMine()) { - t->setHasMine( true ); - mines--; - } - } - - //set hints - for (int r = 0; r < numRows; r++) - for (int c = 0; c < numCols; c++) { - Tile* t = tile(r, c); - if (t && !t->hasMine()) { - int hint = getHint(r,c); - t->setHint(hint); - } - } - - setPlaying(true); -} - -void MyWidget::reset() -{ - foreach(Tile* t, _tiles){ - t->unflip(); - t->setHasFlag(false); - } - nMines = 12; - nFlags = 0; - setPlaying(false); - QTimer::singleShot(600,this, SLOT(setBoard())); -} - -int MyWidget::getHint(int row, int col) -{ - int hint = 0; - for (int c = col-1; c <= col+1; c++) - for (int r = row-1; r <= row+1; r++) { - Tile* t = tile(r, c); - if (t && t->hasMine()) - hint++; - } - return hint; -} - -bool MyWidget::flip(int row, int col) -{ - if(!playing) - return false; - - Tile *t = tile(row, col); - if (!t || t->hasFlag()) - return false; - - if(t->flipped()){ - int flags = 0; - for (int c = col-1; c <= col+1; c++) - for (int r = row-1; r <= row+1; r++) { - Tile *nearT = tile(r, c); - if(!nearT || nearT == t) - continue; - if(nearT->hasFlag()) - flags++; - } - if(!t->hint() || t->hint() != flags) - return false; - for (int c = col-1; c <= col+1; c++) - for (int r = row-1; r <= row+1; r++) { - Tile *nearT = tile(r, c); - if (nearT && !nearT->flipped() && !nearT->hasFlag()) { - flip( r, c ); - } - } - return true; - } - - t->flip(); - - if (t->hint() == 0) { - for (int c = col-1; c <= col+1; c++) - for (int r = row-1; r <= row+1; r++) { - Tile* t = tile(r, c); - if (t && !t->flipped()) { - flip( r, c ); - } - } - } - - if(t->hasMine()){ - for (int r = 0; r < numRows; r++)//Flip all other mines - for (int c = 0; c < numCols; c++) { - Tile* t = tile(r, c); - if (t && t->hasMine()) { - flip(r, c); - } - } - won = false; - hasWonChanged(); - setPlaying(false); - } - - remaining--; - if(!remaining){ - won = true; - hasWonChanged(); - setPlaying(false); - } - return true; -} - -bool MyWidget::flag(int row, int col) -{ - Tile *t = tile(row, col); - if(!t) - return false; - - t->setHasFlag(!t->hasFlag()); - nFlags += (t->hasFlag()?1:-1); - emit numFlagsChanged(); - return true; -} -///////////////////////////////////////////////////////// - -int main(int argc, char ** argv) -{ -#ifdef Q_WS_X11 - // native on X11 is terrible for this demo. - QApplication::setGraphicsSystem("raster"); -#endif - QApplication app(argc, argv); - - bool frameless = false; - - int width = 370; - int height = 480; - - QML_REGISTER_TYPE(0,0,0,Tile,Tile); - - for (int i = 1; i < argc; ++i) { - QString arg = argv[i]; - if (arg == "-frameless") { - frameless = true; - } else if(arg == "-width" && i < (argc - 1)) { - ++i; - width = ::atoi(argv[i]); - } else if(arg == "-height" && i < (argc - 1)) { - ++i; - height = ::atoi(argv[i]); - } else if (arg[0] != '-') { - fileName = arg; - } - } - - MyWidget wid(width, height, 0, frameless ? Qt::FramelessWindowHint : Qt::Widget); - wid.show(); - - return app.exec(); -} - -#include "main.moc" diff --git a/demos/declarative/minehunt/minehunt.cpp b/demos/declarative/minehunt/minehunt.cpp new file mode 100644 index 0000000..89845ef --- /dev/null +++ b/demos/declarative/minehunt/minehunt.cpp @@ -0,0 +1,314 @@ +/**************************************************************************** +** +** 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 +#include +#include +#include +#include + +#include +#include + +class Tile : public QObject +{ + Q_OBJECT +public: + Tile() : _hasFlag(false), _hasMine(false), _hint(-1), _flipped(false) {} + + Q_PROPERTY(bool hasFlag READ hasFlag WRITE setHasFlag NOTIFY hasFlagChanged); + bool hasFlag() const { return _hasFlag; } + + Q_PROPERTY(bool hasMine READ hasMine NOTIFY hasMineChanged); + bool hasMine() const { return _hasMine; } + + Q_PROPERTY(int hint READ hint NOTIFY hintChanged); + int hint() const { return _hint; } + + Q_PROPERTY(bool flipped READ flipped NOTIFY flippedChanged()); + bool flipped() const { return _flipped; } + + void setHasFlag(bool flag) {if(flag==_hasFlag) return; _hasFlag = flag; emit hasFlagChanged();} + void setHasMine(bool mine) {if(mine==_hasMine) return; _hasMine = mine; emit hasMineChanged();} + void setHint(int hint) { if(hint == _hint) return; _hint = hint; emit hintChanged(); } + void flip() { if (_flipped) return; _flipped = true; emit flippedChanged(); } + void unflip() { if(!_flipped) return; _flipped = false; emit flippedChanged(); } + +signals: + void flippedChanged(); + void hasFlagChanged(); + void hintChanged(); + void hasMineChanged(); + +private: + bool _hasFlag; + bool _hasMine; + int _hint; + bool _flipped; +}; + +class MinehuntGame : public QObject +{ + Q_OBJECT +public: + MinehuntGame(); + + Q_PROPERTY(QDeclarativeListProperty tiles READ tiles CONSTANT); + QDeclarativeListProperty tiles() { return QDeclarativeListProperty(this, _tiles); } + + Q_PROPERTY(bool isPlaying READ isPlaying NOTIFY isPlayingChanged); + bool isPlaying() {return playing;} + + Q_PROPERTY(bool hasWon READ hasWon NOTIFY hasWonChanged); + bool hasWon() {return won;} + + Q_PROPERTY(int numMines READ numMines NOTIFY numMinesChanged); + int numMines() const{return nMines;} + + Q_PROPERTY(int numFlags READ numFlags NOTIFY numFlagsChanged); + int numFlags() const{return nFlags;} + +public slots: + Q_INVOKABLE bool flip(int row, int col); + Q_INVOKABLE bool flag(int row, int col); + void setBoard(); + void reset(); + +signals: + void isPlayingChanged(); + void hasWonChanged(); + void numMinesChanged(); + void numFlagsChanged(); + +private: + bool onBoard( int r, int c ) const { return r >= 0 && r < numRows && c >= 0 && c < numCols; } + Tile *tile( int row, int col ) { return onBoard(row, col) ? _tiles[col+numRows*row] : 0; } + int getHint(int row, int col); + void setPlaying(bool b){if(b==playing) return; playing=b; emit isPlayingChanged();} + + QList _tiles; + int numCols; + int numRows; + bool playing; + bool won; + int remaining; + int nMines; + int nFlags; +}; + +MinehuntGame::MinehuntGame() +: numCols(9), numRows(9), playing(true), won(false) +{ + setObjectName("mainObject"); + srand(QTime(0,0,0).secsTo(QTime::currentTime())); + + //initialize array + for(int ii = 0; ii < numRows * numCols; ++ii) { + _tiles << new Tile; + } + reset(); + +} + +void MinehuntGame::setBoard() +{ + foreach(Tile* t, _tiles){ + t->setHasMine(false); + t->setHint(-1); + } + //place mines + int mines = nMines; + remaining = numRows*numCols-mines; + while ( mines ) { + int col = int((double(rand()) / double(RAND_MAX)) * numCols); + int row = int((double(rand()) / double(RAND_MAX)) * numRows); + + Tile* t = tile( row, col ); + + if (t && !t->hasMine()) { + t->setHasMine( true ); + mines--; + } + } + + //set hints + for (int r = 0; r < numRows; r++) + for (int c = 0; c < numCols; c++) { + Tile* t = tile(r, c); + if (t && !t->hasMine()) { + int hint = getHint(r,c); + t->setHint(hint); + } + } + + setPlaying(true); +} + +void MinehuntGame::reset() +{ + foreach(Tile* t, _tiles){ + t->unflip(); + t->setHasFlag(false); + } + nMines = 12; + nFlags = 0; + setPlaying(false); + QTimer::singleShot(600,this, SLOT(setBoard())); +} + +int MinehuntGame::getHint(int row, int col) +{ + int hint = 0; + for (int c = col-1; c <= col+1; c++) + for (int r = row-1; r <= row+1; r++) { + Tile* t = tile(r, c); + if (t && t->hasMine()) + hint++; + } + return hint; +} + +bool MinehuntGame::flip(int row, int col) +{ + if(!playing) + return false; + + Tile *t = tile(row, col); + if (!t || t->hasFlag()) + return false; + + if(t->flipped()){ + int flags = 0; + for (int c = col-1; c <= col+1; c++) + for (int r = row-1; r <= row+1; r++) { + Tile *nearT = tile(r, c); + if(!nearT || nearT == t) + continue; + if(nearT->hasFlag()) + flags++; + } + if(!t->hint() || t->hint() != flags) + return false; + for (int c = col-1; c <= col+1; c++) + for (int r = row-1; r <= row+1; r++) { + Tile *nearT = tile(r, c); + if (nearT && !nearT->flipped() && !nearT->hasFlag()) { + flip( r, c ); + } + } + return true; + } + + t->flip(); + + if (t->hint() == 0) { + for (int c = col-1; c <= col+1; c++) + for (int r = row-1; r <= row+1; r++) { + Tile* t = tile(r, c); + if (t && !t->flipped()) { + flip( r, c ); + } + } + } + + if(t->hasMine()){ + for (int r = 0; r < numRows; r++)//Flip all other mines + for (int c = 0; c < numCols; c++) { + Tile* t = tile(r, c); + if (t && t->hasMine()) { + flip(r, c); + } + } + won = false; + hasWonChanged(); + setPlaying(false); + } + + remaining--; + if(!remaining){ + won = true; + hasWonChanged(); + setPlaying(false); + } + return true; +} + +bool MinehuntGame::flag(int row, int col) +{ + Tile *t = tile(row, col); + if(!t) + return false; + + t->setHasFlag(!t->hasFlag()); + nFlags += (t->hasFlag()?1:-1); + emit numFlagsChanged(); + return true; +} + +QML_DECLARE_TYPE(Tile); +QML_DECLARE_TYPE(MinehuntGame); + +class MinehuntExtensionPlugin : public QDeclarativeExtensionPlugin +{ + Q_OBJECT + + public: + void registerTypes(const char *uri) { + Q_UNUSED(uri); + QML_REGISTER_TYPE(SameGameCore, 0, 1, Tile, Tile); + QML_REGISTER_TYPE(SameGameCore, 0, 1, Game, MinehuntGame); + } + + void initializeEngine(QDeclarativeEngine *engine, const char *uri) { + Q_UNUSED(uri); + + srand(QTime(0,0,0).secsTo(QTime::currentTime())); + + MinehuntGame* game = new MinehuntGame(); + + engine->rootContext()->addDefaultObject(game); + } +}; + +#include "minehunt.moc" + +Q_EXPORT_PLUGIN(MinehuntExtensionPlugin); + diff --git a/demos/declarative/minehunt/minehunt.pro b/demos/declarative/minehunt/minehunt.pro index 01791b1..a497b0f 100644 --- a/demos/declarative/minehunt/minehunt.pro +++ b/demos/declarative/minehunt/minehunt.pro @@ -1,9 +1,11 @@ -SOURCES = main.cpp +TEMPLATE = lib +TARGET = minehunt +QT += declarative +CONFIG += qt plugin -QT += script declarative -contains(QT_CONFIG, opengles2)|contains(QT_CONFIG, opengles1): QT += opengl +TARGET = $$qtLibraryTarget($$TARGET) +DESTDIR = MinehuntCore + +# Input +SOURCES += minehunt.cpp -target.path = $$[QT_INSTALL_EXAMPLES]/declarative/minehunt -sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS minehunt.pro -sources.path = $$[QT_INSTALL_EXAMPLES]/declarative/minehunt -INSTALLS += target sources diff --git a/demos/declarative/minehunt/minehunt.qml b/demos/declarative/minehunt/minehunt.qml index 456f25b..9e99706 100644 --- a/demos/declarative/minehunt/minehunt.qml +++ b/demos/declarative/minehunt/minehunt.qml @@ -1,4 +1,5 @@ import Qt 4.6 +import MinehuntCore 1.0 Item { id: field @@ -24,13 +25,13 @@ Item { angle: flipable.angle; } front: Image { - source: "pics/front.png" + source: "MinehuntCore/pics/front.png" width: 40 height: 40 Image { anchors.horizontalCenter: parent.horizontalCenter anchors.verticalCenter: parent.verticalCenter - source: "pics/flag.png" + source: "MinehuntCore/pics/flag.png" opacity: modelData.hasFlag Behavior on opacity { NumberAnimation { @@ -41,7 +42,7 @@ Item { } } back: Image { - source: "pics/back.png" + source: "MinehuntCore/pics/back.png" width: 40 height: 40 Text { @@ -55,7 +56,7 @@ Item { Image { anchors.horizontalCenter: parent.horizontalCenter anchors.verticalCenter: parent.verticalCenter - source: "pics/bomb.png" + source: "MinehuntCore/pics/bomb.png" opacity: modelData.hasMine } Explosion { @@ -120,16 +121,9 @@ Item { } ] Image { - source: "pics/No-Ones-Laughing-3.jpg" + source: "MinehuntCore/pics/No-Ones-Laughing-3.jpg" fillMode: Image.Tile } - Description { - text: "Use the 'minehunt' executable to run this demo!" - width: 300 - opacity: tiles?0:1 - anchors.horizontalCenter: parent.horizontalCenter - anchors.verticalCenter: parent.verticalCenter - } Repeater { id: repeater model: tiles @@ -156,7 +150,7 @@ Item { Image { // x: 100 // y: 20 - source: "pics/bomb-color.png" + source: "MinehuntCore/pics/bomb-color.png" } Text { // x: 100 @@ -172,7 +166,7 @@ Item { Image { // x: 140 // y: 20 - source: "pics/flag-color.png" + source: "MinehuntCore/pics/flag-color.png" } Text { // x: 140 @@ -187,7 +181,7 @@ Item { y: 390 anchors.right: field.right anchors.rightMargin: 20 - source: isPlaying ? 'pics/face-smile.png' : hasWon ? 'pics/face-smile-big.png': 'pics/face-sad.png' + source: isPlaying ? 'MinehuntCore/pics/face-smile.png' : hasWon ? 'MinehuntCore/pics/face-smile-big.png': 'MinehuntCore/pics/face-sad.png' MouseArea { anchors.fill: parent onPressed: { reset() } diff --git a/demos/declarative/minehunt/pics/No-Ones-Laughing-3.jpg b/demos/declarative/minehunt/pics/No-Ones-Laughing-3.jpg deleted file mode 100644 index 445567f..0000000 Binary files a/demos/declarative/minehunt/pics/No-Ones-Laughing-3.jpg and /dev/null differ diff --git a/demos/declarative/minehunt/pics/back.png b/demos/declarative/minehunt/pics/back.png deleted file mode 100644 index f6b3f0b..0000000 Binary files a/demos/declarative/minehunt/pics/back.png and /dev/null differ diff --git a/demos/declarative/minehunt/pics/bomb-color.png b/demos/declarative/minehunt/pics/bomb-color.png deleted file mode 100644 index 61ad0a9..0000000 Binary files a/demos/declarative/minehunt/pics/bomb-color.png and /dev/null differ diff --git a/demos/declarative/minehunt/pics/bomb.png b/demos/declarative/minehunt/pics/bomb.png deleted file mode 100644 index a992575..0000000 Binary files a/demos/declarative/minehunt/pics/bomb.png and /dev/null differ diff --git a/demos/declarative/minehunt/pics/face-sad.png b/demos/declarative/minehunt/pics/face-sad.png deleted file mode 100644 index cf00aaf..0000000 Binary files a/demos/declarative/minehunt/pics/face-sad.png and /dev/null differ diff --git a/demos/declarative/minehunt/pics/face-smile-big.png b/demos/declarative/minehunt/pics/face-smile-big.png deleted file mode 100644 index f9c2335..0000000 Binary files a/demos/declarative/minehunt/pics/face-smile-big.png and /dev/null differ diff --git a/demos/declarative/minehunt/pics/face-smile.png b/demos/declarative/minehunt/pics/face-smile.png deleted file mode 100644 index 3d66d72..0000000 Binary files a/demos/declarative/minehunt/pics/face-smile.png and /dev/null differ diff --git a/demos/declarative/minehunt/pics/flag-color.png b/demos/declarative/minehunt/pics/flag-color.png deleted file mode 100644 index aadad0f..0000000 Binary files a/demos/declarative/minehunt/pics/flag-color.png and /dev/null differ diff --git a/demos/declarative/minehunt/pics/flag.png b/demos/declarative/minehunt/pics/flag.png deleted file mode 100644 index 39cde4d..0000000 Binary files a/demos/declarative/minehunt/pics/flag.png and /dev/null differ diff --git a/demos/declarative/minehunt/pics/front.png b/demos/declarative/minehunt/pics/front.png deleted file mode 100644 index 834331b..0000000 Binary files a/demos/declarative/minehunt/pics/front.png and /dev/null differ diff --git a/demos/declarative/minehunt/pics/star.png b/demos/declarative/minehunt/pics/star.png deleted file mode 100644 index 3772359..0000000 Binary files a/demos/declarative/minehunt/pics/star.png and /dev/null differ diff --git a/demos/declarative/minehunt/test.qml b/demos/declarative/minehunt/test.qml deleted file mode 100644 index 11ed182..0000000 --- a/demos/declarative/minehunt/test.qml +++ /dev/null @@ -1,13 +0,0 @@ -import Qt 4.6 - - Image { - source: "pics/front.png" - width: 40 - height: 40 - Image { - anchors.horizontalCenter: parent.horizontalCenter - anchors.verticalCenter: parent.verticalCenter - source: "pics/flag.png" - opacity: 1 - } - } -- cgit v0.12 From e16b33eefa365986f8e0d26c710cb7568bf9abff Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Tue, 2 Mar 2010 15:54:38 +0100 Subject: Refactor demos Samegame and Twitter are now trying the new naming convention. --- .../samegame/SamegameCore/BoomBlock.qml | 55 +++++ demos/declarative/samegame/SamegameCore/Button.qml | 25 +++ demos/declarative/samegame/SamegameCore/Dialog.qml | 22 ++ .../samegame/SamegameCore/pics/background.png | Bin 0 -> 313930 bytes .../samegame/SamegameCore/pics/blueStar.png | Bin 0 -> 278 bytes .../samegame/SamegameCore/pics/blueStone.png | Bin 0 -> 3054 bytes .../samegame/SamegameCore/pics/greenStar.png | Bin 0 -> 273 bytes .../samegame/SamegameCore/pics/greenStone.png | Bin 0 -> 2932 bytes .../samegame/SamegameCore/pics/redStar.png | Bin 0 -> 274 bytes .../samegame/SamegameCore/pics/redStone.png | Bin 0 -> 2902 bytes .../samegame/SamegameCore/pics/star.png | Bin 0 -> 262 bytes .../samegame/SamegameCore/pics/yellowStone.png | Bin 0 -> 3056 bytes demos/declarative/samegame/SamegameCore/qmldir | 3 + .../declarative/samegame/SamegameCore/samegame.js | 250 +++++++++++++++++++++ demos/declarative/samegame/content/BoomBlock.qml | 55 ----- demos/declarative/samegame/content/Button.qml | 25 --- demos/declarative/samegame/content/Dialog.qml | 22 -- .../samegame/content/pics/background.png | Bin 313930 -> 0 bytes .../declarative/samegame/content/pics/blueStar.png | Bin 278 -> 0 bytes .../samegame/content/pics/blueStone.png | Bin 3054 -> 0 bytes .../samegame/content/pics/greenStar.png | Bin 273 -> 0 bytes .../samegame/content/pics/greenStone.png | Bin 2932 -> 0 bytes .../declarative/samegame/content/pics/redStar.png | Bin 274 -> 0 bytes .../declarative/samegame/content/pics/redStone.png | Bin 2902 -> 0 bytes demos/declarative/samegame/content/pics/star.png | Bin 262 -> 0 bytes .../samegame/content/pics/yellowStone.png | Bin 3056 -> 0 bytes demos/declarative/samegame/content/qmldir | 3 - demos/declarative/samegame/content/samegame.js | 250 --------------------- demos/declarative/samegame/samegame.qml | 6 +- demos/declarative/twitter/TwitterCore/AuthView.qml | 99 ++++++++ demos/declarative/twitter/TwitterCore/Button.qml | 49 ++++ .../twitter/TwitterCore/FatDelegate.qml | 46 ++++ .../twitter/TwitterCore/HomeTitleBar.qml | 121 ++++++++++ demos/declarative/twitter/TwitterCore/Loading.qml | 8 + .../twitter/TwitterCore/MultiTitleBar.qml | 24 ++ demos/declarative/twitter/TwitterCore/RssModel.qml | 44 ++++ demos/declarative/twitter/TwitterCore/TitleBar.qml | 77 +++++++ demos/declarative/twitter/TwitterCore/ToolBar.qml | 24 ++ .../declarative/twitter/TwitterCore/UserModel.qml | 26 +++ .../twitter/TwitterCore/images/gloss.png | Bin 0 -> 1236 bytes .../twitter/TwitterCore/images/lineedit.png | Bin 0 -> 1415 bytes .../twitter/TwitterCore/images/lineedit.sci | 5 + .../twitter/TwitterCore/images/loading.png | Bin 0 -> 813 bytes .../twitter/TwitterCore/images/stripes.png | Bin 0 -> 257 bytes .../twitter/TwitterCore/images/titlebar.png | Bin 0 -> 1436 bytes .../twitter/TwitterCore/images/titlebar.sci | 5 + .../twitter/TwitterCore/images/toolbutton.png | Bin 0 -> 2550 bytes .../twitter/TwitterCore/images/toolbutton.sci | 5 + demos/declarative/twitter/TwitterCore/qmldir | 10 + demos/declarative/twitter/content/AuthView.qml | 99 -------- demos/declarative/twitter/content/Button.qml | 49 ---- demos/declarative/twitter/content/FatDelegate.qml | 46 ---- demos/declarative/twitter/content/HomeTitleBar.qml | 121 ---------- demos/declarative/twitter/content/Loading.qml | 8 - .../declarative/twitter/content/MultiTitleBar.qml | 24 -- demos/declarative/twitter/content/RssModel.qml | 44 ---- demos/declarative/twitter/content/TitleBar.qml | 77 ------- demos/declarative/twitter/content/ToolBar.qml | 24 -- demos/declarative/twitter/content/UserModel.qml | 26 --- demos/declarative/twitter/content/images/gloss.png | Bin 1236 -> 0 bytes .../twitter/content/images/lineedit.png | Bin 1415 -> 0 bytes .../twitter/content/images/lineedit.sci | 5 - .../declarative/twitter/content/images/loading.png | Bin 813 -> 0 bytes .../declarative/twitter/content/images/stripes.png | Bin 257 -> 0 bytes .../twitter/content/images/titlebar.png | Bin 1436 -> 0 bytes .../twitter/content/images/titlebar.sci | 5 - .../twitter/content/images/toolbutton.png | Bin 2550 -> 0 bytes .../twitter/content/images/toolbutton.sci | 5 - demos/declarative/twitter/twitter.qml | 4 +- 69 files changed, 903 insertions(+), 893 deletions(-) create mode 100644 demos/declarative/samegame/SamegameCore/BoomBlock.qml create mode 100644 demos/declarative/samegame/SamegameCore/Button.qml create mode 100644 demos/declarative/samegame/SamegameCore/Dialog.qml create mode 100644 demos/declarative/samegame/SamegameCore/pics/background.png create mode 100644 demos/declarative/samegame/SamegameCore/pics/blueStar.png create mode 100644 demos/declarative/samegame/SamegameCore/pics/blueStone.png create mode 100644 demos/declarative/samegame/SamegameCore/pics/greenStar.png create mode 100644 demos/declarative/samegame/SamegameCore/pics/greenStone.png create mode 100644 demos/declarative/samegame/SamegameCore/pics/redStar.png create mode 100644 demos/declarative/samegame/SamegameCore/pics/redStone.png create mode 100644 demos/declarative/samegame/SamegameCore/pics/star.png create mode 100644 demos/declarative/samegame/SamegameCore/pics/yellowStone.png create mode 100644 demos/declarative/samegame/SamegameCore/qmldir create mode 100755 demos/declarative/samegame/SamegameCore/samegame.js delete mode 100644 demos/declarative/samegame/content/BoomBlock.qml delete mode 100644 demos/declarative/samegame/content/Button.qml delete mode 100644 demos/declarative/samegame/content/Dialog.qml delete mode 100644 demos/declarative/samegame/content/pics/background.png delete mode 100644 demos/declarative/samegame/content/pics/blueStar.png delete mode 100644 demos/declarative/samegame/content/pics/blueStone.png delete mode 100644 demos/declarative/samegame/content/pics/greenStar.png delete mode 100644 demos/declarative/samegame/content/pics/greenStone.png delete mode 100644 demos/declarative/samegame/content/pics/redStar.png delete mode 100644 demos/declarative/samegame/content/pics/redStone.png delete mode 100644 demos/declarative/samegame/content/pics/star.png delete mode 100644 demos/declarative/samegame/content/pics/yellowStone.png delete mode 100644 demos/declarative/samegame/content/qmldir delete mode 100755 demos/declarative/samegame/content/samegame.js create mode 100644 demos/declarative/twitter/TwitterCore/AuthView.qml create mode 100644 demos/declarative/twitter/TwitterCore/Button.qml create mode 100644 demos/declarative/twitter/TwitterCore/FatDelegate.qml create mode 100644 demos/declarative/twitter/TwitterCore/HomeTitleBar.qml create mode 100644 demos/declarative/twitter/TwitterCore/Loading.qml create mode 100644 demos/declarative/twitter/TwitterCore/MultiTitleBar.qml create mode 100644 demos/declarative/twitter/TwitterCore/RssModel.qml create mode 100644 demos/declarative/twitter/TwitterCore/TitleBar.qml create mode 100644 demos/declarative/twitter/TwitterCore/ToolBar.qml create mode 100644 demos/declarative/twitter/TwitterCore/UserModel.qml create mode 100644 demos/declarative/twitter/TwitterCore/images/gloss.png create mode 100644 demos/declarative/twitter/TwitterCore/images/lineedit.png create mode 100644 demos/declarative/twitter/TwitterCore/images/lineedit.sci create mode 100644 demos/declarative/twitter/TwitterCore/images/loading.png create mode 100644 demos/declarative/twitter/TwitterCore/images/stripes.png create mode 100644 demos/declarative/twitter/TwitterCore/images/titlebar.png create mode 100644 demos/declarative/twitter/TwitterCore/images/titlebar.sci create mode 100644 demos/declarative/twitter/TwitterCore/images/toolbutton.png create mode 100644 demos/declarative/twitter/TwitterCore/images/toolbutton.sci create mode 100644 demos/declarative/twitter/TwitterCore/qmldir delete mode 100644 demos/declarative/twitter/content/AuthView.qml delete mode 100644 demos/declarative/twitter/content/Button.qml delete mode 100644 demos/declarative/twitter/content/FatDelegate.qml delete mode 100644 demos/declarative/twitter/content/HomeTitleBar.qml delete mode 100644 demos/declarative/twitter/content/Loading.qml delete mode 100644 demos/declarative/twitter/content/MultiTitleBar.qml delete mode 100644 demos/declarative/twitter/content/RssModel.qml delete mode 100644 demos/declarative/twitter/content/TitleBar.qml delete mode 100644 demos/declarative/twitter/content/ToolBar.qml delete mode 100644 demos/declarative/twitter/content/UserModel.qml delete mode 100644 demos/declarative/twitter/content/images/gloss.png delete mode 100644 demos/declarative/twitter/content/images/lineedit.png delete mode 100644 demos/declarative/twitter/content/images/lineedit.sci delete mode 100644 demos/declarative/twitter/content/images/loading.png delete mode 100644 demos/declarative/twitter/content/images/stripes.png delete mode 100644 demos/declarative/twitter/content/images/titlebar.png delete mode 100644 demos/declarative/twitter/content/images/titlebar.sci delete mode 100644 demos/declarative/twitter/content/images/toolbutton.png delete mode 100644 demos/declarative/twitter/content/images/toolbutton.sci diff --git a/demos/declarative/samegame/SamegameCore/BoomBlock.qml b/demos/declarative/samegame/SamegameCore/BoomBlock.qml new file mode 100644 index 0000000..e48194a --- /dev/null +++ b/demos/declarative/samegame/SamegameCore/BoomBlock.qml @@ -0,0 +1,55 @@ +import Qt 4.6 + +Item { id:block + property bool dying: false + property bool spawned: false + property int type: 0 + property int targetX: 0 + property int targetY: 0 + + SpringFollow on x { enabled: spawned; source: targetX; spring: 2; damping: 0.2 } + SpringFollow on y { source: targetY; spring: 2; damping: 0.2 } + + Image { id: img + source: { + if(type == 0){ + "pics/redStone.png"; + } else if(type == 1) { + "pics/blueStone.png"; + } else { + "pics/greenStone.png"; + } + } + opacity: 0 + Behavior on opacity { NumberAnimation { duration: 200 } } + anchors.fill: parent + } + + Particles { id: particles + width:1; height:1; anchors.centerIn: parent; + emissionRate: 0; + lifeSpan: 700; lifeSpanDeviation: 600; + angle: 0; angleDeviation: 360; + velocity: 100; velocityDeviation:30; + source: { + if(type == 0){ + "pics/redStar.png"; + } else if (type == 1) { + "pics/blueStar.png"; + } else { + "pics/greenStar.png"; + } + } + } + + states: [ + State{ name: "AliveState"; when: spawned == true && dying == false + PropertyChanges { target: img; opacity: 1 } + }, + State{ name: "DeathState"; when: dying == true + StateChangeScript { script: particles.burst(50); } + PropertyChanges { target: img; opacity: 0 } + StateChangeScript { script: block.destroy(1000); } + } + ] +} diff --git a/demos/declarative/samegame/SamegameCore/Button.qml b/demos/declarative/samegame/SamegameCore/Button.qml new file mode 100644 index 0000000..6629302 --- /dev/null +++ b/demos/declarative/samegame/SamegameCore/Button.qml @@ -0,0 +1,25 @@ +import Qt 4.6 + +Rectangle { + id: container + + signal clicked + property string text: "Button" + + color: activePalette.button; smooth: true + width: txtItem.width + 20; height: txtItem.height + 6 + border.width: 1; border.color: Qt.darker(activePalette.button); radius: 8; + + gradient: Gradient { + GradientStop { + id: topGrad; position: 0.0 + color: if (mr.pressed) { activePalette.dark } else { activePalette.light } } + GradientStop { position: 1.0; color: activePalette.button } + } + + MouseArea { id: mr; anchors.fill: parent; onClicked: container.clicked() } + + Text { + id: txtItem; text: container.text; anchors.centerIn: container; color: activePalette.buttonText + } +} diff --git a/demos/declarative/samegame/SamegameCore/Dialog.qml b/demos/declarative/samegame/SamegameCore/Dialog.qml new file mode 100644 index 0000000..6d5d6b5 --- /dev/null +++ b/demos/declarative/samegame/SamegameCore/Dialog.qml @@ -0,0 +1,22 @@ +import Qt 4.6 + +Rectangle { + id: page + function forceClose() { + page.closed(); + page.opacity = 0; + } + function show(txt) { + myText.text = txt; + page.opacity = 1; + } + signal closed(); + property Item text: myText + color: "white"; border.width: 1; width: myText.width + 20; height: myText.height + 40; + opacity: 0 + Behavior on opacity { + NumberAnimation { duration: 1000 } + } + Text { id: myText; anchors.centerIn: parent; text: "Hello World!" } + MouseArea { id: mr; anchors.fill: parent; onClicked: forceClose(); } +} diff --git a/demos/declarative/samegame/SamegameCore/pics/background.png b/demos/declarative/samegame/SamegameCore/pics/background.png new file mode 100644 index 0000000..3734a27 Binary files /dev/null and b/demos/declarative/samegame/SamegameCore/pics/background.png differ diff --git a/demos/declarative/samegame/SamegameCore/pics/blueStar.png b/demos/declarative/samegame/SamegameCore/pics/blueStar.png new file mode 100644 index 0000000..ff9588f Binary files /dev/null and b/demos/declarative/samegame/SamegameCore/pics/blueStar.png differ diff --git a/demos/declarative/samegame/SamegameCore/pics/blueStone.png b/demos/declarative/samegame/SamegameCore/pics/blueStone.png new file mode 100644 index 0000000..20e43c7 Binary files /dev/null and b/demos/declarative/samegame/SamegameCore/pics/blueStone.png differ diff --git a/demos/declarative/samegame/SamegameCore/pics/greenStar.png b/demos/declarative/samegame/SamegameCore/pics/greenStar.png new file mode 100644 index 0000000..cd06854 Binary files /dev/null and b/demos/declarative/samegame/SamegameCore/pics/greenStar.png differ diff --git a/demos/declarative/samegame/SamegameCore/pics/greenStone.png b/demos/declarative/samegame/SamegameCore/pics/greenStone.png new file mode 100644 index 0000000..b568a19 Binary files /dev/null and b/demos/declarative/samegame/SamegameCore/pics/greenStone.png differ diff --git a/demos/declarative/samegame/SamegameCore/pics/redStar.png b/demos/declarative/samegame/SamegameCore/pics/redStar.png new file mode 100644 index 0000000..0a4dffe Binary files /dev/null and b/demos/declarative/samegame/SamegameCore/pics/redStar.png differ diff --git a/demos/declarative/samegame/SamegameCore/pics/redStone.png b/demos/declarative/samegame/SamegameCore/pics/redStone.png new file mode 100644 index 0000000..36b09a2 Binary files /dev/null and b/demos/declarative/samegame/SamegameCore/pics/redStone.png differ diff --git a/demos/declarative/samegame/SamegameCore/pics/star.png b/demos/declarative/samegame/SamegameCore/pics/star.png new file mode 100644 index 0000000..defbde5 Binary files /dev/null and b/demos/declarative/samegame/SamegameCore/pics/star.png differ diff --git a/demos/declarative/samegame/SamegameCore/pics/yellowStone.png b/demos/declarative/samegame/SamegameCore/pics/yellowStone.png new file mode 100644 index 0000000..b1ce762 Binary files /dev/null and b/demos/declarative/samegame/SamegameCore/pics/yellowStone.png differ diff --git a/demos/declarative/samegame/SamegameCore/qmldir b/demos/declarative/samegame/SamegameCore/qmldir new file mode 100644 index 0000000..a8f8a98 --- /dev/null +++ b/demos/declarative/samegame/SamegameCore/qmldir @@ -0,0 +1,3 @@ +BoomBlock 0.0 BoomBlock.qml +Button 0.0 Button.qml +Dialog 0.0 Dialog.qml diff --git a/demos/declarative/samegame/SamegameCore/samegame.js b/demos/declarative/samegame/SamegameCore/samegame.js new file mode 100755 index 0000000..c0f10bd --- /dev/null +++ b/demos/declarative/samegame/SamegameCore/samegame.js @@ -0,0 +1,250 @@ +/* This script file handles the game logic */ +//Note that X/Y referred to here are in game coordinates +var maxX = 10;//Nums are for gameCanvas.tileSize 40 +var maxY = 15; +var maxIndex = maxX*maxY; +var board = new Array(maxIndex); +var tileSrc = "content/BoomBlock.qml"; +var scoresURL = "http://qtfx-nokia.trolltech.com.au/samegame/scores.php"; +var scoresURL = ""; +var timer; +var component = createComponent(tileSrc); + +//Index function used instead of a 2D array +function index(xIdx,yIdx) { + return xIdx + (yIdx * maxX); +} + +function timeStr(msecs) { + var secs = Math.floor(msecs/1000); + var m = Math.floor(secs/60); + var ret = "" + m + "m " + (secs%60) + "s"; + return ret; +} + +function getTileSize() +{ + return tileSize; +} + +function initBoard() +{ + for(var i = 0; i= maxX || xIdx < 0 || yIdx >= maxY || yIdx < 0) + return; + if(board[index(xIdx, yIdx)] == null) + return; + //If it's a valid tile, remove it and all connected (does nothing if it's not connected) + floodFill(xIdx,yIdx, -1); + if(fillFound <= 0) + return; + gameCanvas.score += (fillFound - 1) * (fillFound - 1); + shuffleDown(); + victoryCheck(); +} + +function floodFill(xIdx,yIdx,type) +{ + if(board[index(xIdx, yIdx)] == null) + return; + var first = false; + if(type == -1){ + first = true; + type = board[index(xIdx,yIdx)].type; + + //Flood fill initialization + fillFound = 0; + floodBoard = new Array(maxIndex); + } + if(xIdx >= maxX || xIdx < 0 || yIdx >= maxY || yIdx < 0) + return; + if(floodBoard[index(xIdx, yIdx)] == 1 || (!first && type != board[index(xIdx,yIdx)].type)) + return; + floodBoard[index(xIdx, yIdx)] = 1; + floodFill(xIdx+1,yIdx,type); + floodFill(xIdx-1,yIdx,type); + floodFill(xIdx,yIdx+1,type); + floodFill(xIdx,yIdx-1,type); + if(first==true && fillFound == 0) + return;//Can't remove single tiles + board[index(xIdx,yIdx)].dying = true; + board[index(xIdx,yIdx)] = null; + fillFound += 1; +} + +function shuffleDown() +{ + //Fall down + for(var xIdx=0; xIdx=0; yIdx--){ + if(board[index(xIdx,yIdx)] == null){ + fallDist += 1; + }else{ + if(fallDist > 0){ + var obj = board[index(xIdx,yIdx)]; + obj.targetY += fallDist * gameCanvas.tileSize; + board[index(xIdx,yIdx+fallDist)] = obj; + board[index(xIdx,yIdx)] = null; + } + } + } + } + //Fall to the left + fallDist = 0; + for(xIdx=0; xIdx 0){ + for(yIdx=0; yIdx=0; xIdx--) + if(board[index(xIdx, maxY - 1)] != null) + deservesBonus = false; + if(deservesBonus) + gameCanvas.score += 500; + //Checks for game over + if(deservesBonus || !(floodMoveCheck(0,maxY-1, -1))){ + timer = new Date() - timer; + //scoreName.show("You won! Please enter your name: "); + scoreName.show("You won! Please enter your name: "); + scoreName.initialWidth = scoreName.text.width + 20; + scoreName.width = scoreName.initialWidth; + scoreName.text.opacity = 0;//Just a spacer + //dialog.show("Game Over. Your score is " + gameCanvas.score); + } +} + +//only floods up and right, to see if it can find adjacent same-typed tiles +function floodMoveCheck(xIdx, yIdx, type) +{ + if(xIdx >= maxX || xIdx < 0 || yIdx >= maxY || yIdx < 0) + return false; + if(board[index(xIdx, yIdx)] == null) + return false; + var myType = board[index(xIdx, yIdx)].type; + if(type == myType) + return true; + return floodMoveCheck(xIdx + 1, yIdx, myType) || + floodMoveCheck(xIdx, yIdx - 1, board[index(xIdx,yIdx)].type); +} + +function createBlock(xIdx,yIdx){ + // Note that we don't wait for the component to become ready. This will + // only work if the block QML is a local file. Otherwise the component will + // not be ready immediately. There is a statusChanged signal on the + // component you could use if you want to wait to load remote files. + if(component.isReady){ + var dynamicObject = component.createObject(); + if(dynamicObject == null){ + print("error creating block"); + print(component.errorsString()); + return false; + } + dynamicObject.type = Math.floor(Math.random() * 3); + dynamicObject.parent = gameCanvas; + dynamicObject.x = xIdx*gameCanvas.tileSize; + dynamicObject.targetX = xIdx*gameCanvas.tileSize; + dynamicObject.targetY = yIdx*gameCanvas.tileSize; + dynamicObject.width = gameCanvas.tileSize; + dynamicObject.height = gameCanvas.tileSize; + dynamicObject.spawned = true; + board[index(xIdx,yIdx)] = dynamicObject; + }else{//isError or isLoading + print("error loading block component"); + print(component.errorsString()); + return false; + } + return true; +} + +function saveHighScore(name) { + if(scoresURL!="") + sendHighScore(name); + //OfflineStorage + var db = openDatabaseSync("SameGameScores", "1.0", "Local SameGame High Scores",100); + var dataStr = "INSERT INTO Scores VALUES(?, ?, ?, ?)"; + var data = [name, gameCanvas.score, maxX+"x"+maxY ,Math.floor(timer/1000)]; + db.transaction( + function(tx) { + tx.executeSql('CREATE TABLE IF NOT EXISTS Scores(name TEXT, score NUMBER, gridSize TEXT, time NUMBER)'); + tx.executeSql(dataStr, data); + + //Only show results for the current grid size + var rs = tx.executeSql('SELECT * FROM Scores WHERE gridSize = "'+maxX+"x"+maxY+'" ORDER BY score desc LIMIT 10'); + var r = "\nHIGH SCORES for this grid size\n\n" + for(var i = 0; i < rs.rows.length; i++){ + r += (i+1)+". " + rs.rows.item(i).name +' got ' + + rs.rows.item(i).score + ' points in ' + + rs.rows.item(i).time + ' seconds.\n'; + } + dialog.show(r); + } + ); +} + +function sendHighScore(name) { + var postman = new XMLHttpRequest() + var postData = "name="+name+"&score="+gameCanvas.score + +"&gridSize="+maxX+"x"+maxY +"&time="+Math.floor(timer/1000); + postman.open("POST", scoresURL, true); + postman.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); + postman.onreadystatechange = function() { + if (postman.readyState == postman.DONE) { + dialog.show("Your score has been uploaded."); + } + } + postman.send(postData); +} diff --git a/demos/declarative/samegame/content/BoomBlock.qml b/demos/declarative/samegame/content/BoomBlock.qml deleted file mode 100644 index e48194a..0000000 --- a/demos/declarative/samegame/content/BoomBlock.qml +++ /dev/null @@ -1,55 +0,0 @@ -import Qt 4.6 - -Item { id:block - property bool dying: false - property bool spawned: false - property int type: 0 - property int targetX: 0 - property int targetY: 0 - - SpringFollow on x { enabled: spawned; source: targetX; spring: 2; damping: 0.2 } - SpringFollow on y { source: targetY; spring: 2; damping: 0.2 } - - Image { id: img - source: { - if(type == 0){ - "pics/redStone.png"; - } else if(type == 1) { - "pics/blueStone.png"; - } else { - "pics/greenStone.png"; - } - } - opacity: 0 - Behavior on opacity { NumberAnimation { duration: 200 } } - anchors.fill: parent - } - - Particles { id: particles - width:1; height:1; anchors.centerIn: parent; - emissionRate: 0; - lifeSpan: 700; lifeSpanDeviation: 600; - angle: 0; angleDeviation: 360; - velocity: 100; velocityDeviation:30; - source: { - if(type == 0){ - "pics/redStar.png"; - } else if (type == 1) { - "pics/blueStar.png"; - } else { - "pics/greenStar.png"; - } - } - } - - states: [ - State{ name: "AliveState"; when: spawned == true && dying == false - PropertyChanges { target: img; opacity: 1 } - }, - State{ name: "DeathState"; when: dying == true - StateChangeScript { script: particles.burst(50); } - PropertyChanges { target: img; opacity: 0 } - StateChangeScript { script: block.destroy(1000); } - } - ] -} diff --git a/demos/declarative/samegame/content/Button.qml b/demos/declarative/samegame/content/Button.qml deleted file mode 100644 index 6629302..0000000 --- a/demos/declarative/samegame/content/Button.qml +++ /dev/null @@ -1,25 +0,0 @@ -import Qt 4.6 - -Rectangle { - id: container - - signal clicked - property string text: "Button" - - color: activePalette.button; smooth: true - width: txtItem.width + 20; height: txtItem.height + 6 - border.width: 1; border.color: Qt.darker(activePalette.button); radius: 8; - - gradient: Gradient { - GradientStop { - id: topGrad; position: 0.0 - color: if (mr.pressed) { activePalette.dark } else { activePalette.light } } - GradientStop { position: 1.0; color: activePalette.button } - } - - MouseArea { id: mr; anchors.fill: parent; onClicked: container.clicked() } - - Text { - id: txtItem; text: container.text; anchors.centerIn: container; color: activePalette.buttonText - } -} diff --git a/demos/declarative/samegame/content/Dialog.qml b/demos/declarative/samegame/content/Dialog.qml deleted file mode 100644 index 6d5d6b5..0000000 --- a/demos/declarative/samegame/content/Dialog.qml +++ /dev/null @@ -1,22 +0,0 @@ -import Qt 4.6 - -Rectangle { - id: page - function forceClose() { - page.closed(); - page.opacity = 0; - } - function show(txt) { - myText.text = txt; - page.opacity = 1; - } - signal closed(); - property Item text: myText - color: "white"; border.width: 1; width: myText.width + 20; height: myText.height + 40; - opacity: 0 - Behavior on opacity { - NumberAnimation { duration: 1000 } - } - Text { id: myText; anchors.centerIn: parent; text: "Hello World!" } - MouseArea { id: mr; anchors.fill: parent; onClicked: forceClose(); } -} diff --git a/demos/declarative/samegame/content/pics/background.png b/demos/declarative/samegame/content/pics/background.png deleted file mode 100644 index 3734a27..0000000 Binary files a/demos/declarative/samegame/content/pics/background.png and /dev/null differ diff --git a/demos/declarative/samegame/content/pics/blueStar.png b/demos/declarative/samegame/content/pics/blueStar.png deleted file mode 100644 index ff9588f..0000000 Binary files a/demos/declarative/samegame/content/pics/blueStar.png and /dev/null differ diff --git a/demos/declarative/samegame/content/pics/blueStone.png b/demos/declarative/samegame/content/pics/blueStone.png deleted file mode 100644 index 20e43c7..0000000 Binary files a/demos/declarative/samegame/content/pics/blueStone.png and /dev/null differ diff --git a/demos/declarative/samegame/content/pics/greenStar.png b/demos/declarative/samegame/content/pics/greenStar.png deleted file mode 100644 index cd06854..0000000 Binary files a/demos/declarative/samegame/content/pics/greenStar.png and /dev/null differ diff --git a/demos/declarative/samegame/content/pics/greenStone.png b/demos/declarative/samegame/content/pics/greenStone.png deleted file mode 100644 index b568a19..0000000 Binary files a/demos/declarative/samegame/content/pics/greenStone.png and /dev/null differ diff --git a/demos/declarative/samegame/content/pics/redStar.png b/demos/declarative/samegame/content/pics/redStar.png deleted file mode 100644 index 0a4dffe..0000000 Binary files a/demos/declarative/samegame/content/pics/redStar.png and /dev/null differ diff --git a/demos/declarative/samegame/content/pics/redStone.png b/demos/declarative/samegame/content/pics/redStone.png deleted file mode 100644 index 36b09a2..0000000 Binary files a/demos/declarative/samegame/content/pics/redStone.png and /dev/null differ diff --git a/demos/declarative/samegame/content/pics/star.png b/demos/declarative/samegame/content/pics/star.png deleted file mode 100644 index defbde5..0000000 Binary files a/demos/declarative/samegame/content/pics/star.png and /dev/null differ diff --git a/demos/declarative/samegame/content/pics/yellowStone.png b/demos/declarative/samegame/content/pics/yellowStone.png deleted file mode 100644 index b1ce762..0000000 Binary files a/demos/declarative/samegame/content/pics/yellowStone.png and /dev/null differ diff --git a/demos/declarative/samegame/content/qmldir b/demos/declarative/samegame/content/qmldir deleted file mode 100644 index a8f8a98..0000000 --- a/demos/declarative/samegame/content/qmldir +++ /dev/null @@ -1,3 +0,0 @@ -BoomBlock 0.0 BoomBlock.qml -Button 0.0 Button.qml -Dialog 0.0 Dialog.qml diff --git a/demos/declarative/samegame/content/samegame.js b/demos/declarative/samegame/content/samegame.js deleted file mode 100755 index c0f10bd..0000000 --- a/demos/declarative/samegame/content/samegame.js +++ /dev/null @@ -1,250 +0,0 @@ -/* This script file handles the game logic */ -//Note that X/Y referred to here are in game coordinates -var maxX = 10;//Nums are for gameCanvas.tileSize 40 -var maxY = 15; -var maxIndex = maxX*maxY; -var board = new Array(maxIndex); -var tileSrc = "content/BoomBlock.qml"; -var scoresURL = "http://qtfx-nokia.trolltech.com.au/samegame/scores.php"; -var scoresURL = ""; -var timer; -var component = createComponent(tileSrc); - -//Index function used instead of a 2D array -function index(xIdx,yIdx) { - return xIdx + (yIdx * maxX); -} - -function timeStr(msecs) { - var secs = Math.floor(msecs/1000); - var m = Math.floor(secs/60); - var ret = "" + m + "m " + (secs%60) + "s"; - return ret; -} - -function getTileSize() -{ - return tileSize; -} - -function initBoard() -{ - for(var i = 0; i= maxX || xIdx < 0 || yIdx >= maxY || yIdx < 0) - return; - if(board[index(xIdx, yIdx)] == null) - return; - //If it's a valid tile, remove it and all connected (does nothing if it's not connected) - floodFill(xIdx,yIdx, -1); - if(fillFound <= 0) - return; - gameCanvas.score += (fillFound - 1) * (fillFound - 1); - shuffleDown(); - victoryCheck(); -} - -function floodFill(xIdx,yIdx,type) -{ - if(board[index(xIdx, yIdx)] == null) - return; - var first = false; - if(type == -1){ - first = true; - type = board[index(xIdx,yIdx)].type; - - //Flood fill initialization - fillFound = 0; - floodBoard = new Array(maxIndex); - } - if(xIdx >= maxX || xIdx < 0 || yIdx >= maxY || yIdx < 0) - return; - if(floodBoard[index(xIdx, yIdx)] == 1 || (!first && type != board[index(xIdx,yIdx)].type)) - return; - floodBoard[index(xIdx, yIdx)] = 1; - floodFill(xIdx+1,yIdx,type); - floodFill(xIdx-1,yIdx,type); - floodFill(xIdx,yIdx+1,type); - floodFill(xIdx,yIdx-1,type); - if(first==true && fillFound == 0) - return;//Can't remove single tiles - board[index(xIdx,yIdx)].dying = true; - board[index(xIdx,yIdx)] = null; - fillFound += 1; -} - -function shuffleDown() -{ - //Fall down - for(var xIdx=0; xIdx=0; yIdx--){ - if(board[index(xIdx,yIdx)] == null){ - fallDist += 1; - }else{ - if(fallDist > 0){ - var obj = board[index(xIdx,yIdx)]; - obj.targetY += fallDist * gameCanvas.tileSize; - board[index(xIdx,yIdx+fallDist)] = obj; - board[index(xIdx,yIdx)] = null; - } - } - } - } - //Fall to the left - fallDist = 0; - for(xIdx=0; xIdx 0){ - for(yIdx=0; yIdx=0; xIdx--) - if(board[index(xIdx, maxY - 1)] != null) - deservesBonus = false; - if(deservesBonus) - gameCanvas.score += 500; - //Checks for game over - if(deservesBonus || !(floodMoveCheck(0,maxY-1, -1))){ - timer = new Date() - timer; - //scoreName.show("You won! Please enter your name: "); - scoreName.show("You won! Please enter your name: "); - scoreName.initialWidth = scoreName.text.width + 20; - scoreName.width = scoreName.initialWidth; - scoreName.text.opacity = 0;//Just a spacer - //dialog.show("Game Over. Your score is " + gameCanvas.score); - } -} - -//only floods up and right, to see if it can find adjacent same-typed tiles -function floodMoveCheck(xIdx, yIdx, type) -{ - if(xIdx >= maxX || xIdx < 0 || yIdx >= maxY || yIdx < 0) - return false; - if(board[index(xIdx, yIdx)] == null) - return false; - var myType = board[index(xIdx, yIdx)].type; - if(type == myType) - return true; - return floodMoveCheck(xIdx + 1, yIdx, myType) || - floodMoveCheck(xIdx, yIdx - 1, board[index(xIdx,yIdx)].type); -} - -function createBlock(xIdx,yIdx){ - // Note that we don't wait for the component to become ready. This will - // only work if the block QML is a local file. Otherwise the component will - // not be ready immediately. There is a statusChanged signal on the - // component you could use if you want to wait to load remote files. - if(component.isReady){ - var dynamicObject = component.createObject(); - if(dynamicObject == null){ - print("error creating block"); - print(component.errorsString()); - return false; - } - dynamicObject.type = Math.floor(Math.random() * 3); - dynamicObject.parent = gameCanvas; - dynamicObject.x = xIdx*gameCanvas.tileSize; - dynamicObject.targetX = xIdx*gameCanvas.tileSize; - dynamicObject.targetY = yIdx*gameCanvas.tileSize; - dynamicObject.width = gameCanvas.tileSize; - dynamicObject.height = gameCanvas.tileSize; - dynamicObject.spawned = true; - board[index(xIdx,yIdx)] = dynamicObject; - }else{//isError or isLoading - print("error loading block component"); - print(component.errorsString()); - return false; - } - return true; -} - -function saveHighScore(name) { - if(scoresURL!="") - sendHighScore(name); - //OfflineStorage - var db = openDatabaseSync("SameGameScores", "1.0", "Local SameGame High Scores",100); - var dataStr = "INSERT INTO Scores VALUES(?, ?, ?, ?)"; - var data = [name, gameCanvas.score, maxX+"x"+maxY ,Math.floor(timer/1000)]; - db.transaction( - function(tx) { - tx.executeSql('CREATE TABLE IF NOT EXISTS Scores(name TEXT, score NUMBER, gridSize TEXT, time NUMBER)'); - tx.executeSql(dataStr, data); - - //Only show results for the current grid size - var rs = tx.executeSql('SELECT * FROM Scores WHERE gridSize = "'+maxX+"x"+maxY+'" ORDER BY score desc LIMIT 10'); - var r = "\nHIGH SCORES for this grid size\n\n" - for(var i = 0; i < rs.rows.length; i++){ - r += (i+1)+". " + rs.rows.item(i).name +' got ' - + rs.rows.item(i).score + ' points in ' - + rs.rows.item(i).time + ' seconds.\n'; - } - dialog.show(r); - } - ); -} - -function sendHighScore(name) { - var postman = new XMLHttpRequest() - var postData = "name="+name+"&score="+gameCanvas.score - +"&gridSize="+maxX+"x"+maxY +"&time="+Math.floor(timer/1000); - postman.open("POST", scoresURL, true); - postman.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); - postman.onreadystatechange = function() { - if (postman.readyState == postman.DONE) { - dialog.show("Your score has been uploaded."); - } - } - postman.send(postData); -} diff --git a/demos/declarative/samegame/samegame.qml b/demos/declarative/samegame/samegame.qml index c81f292..3b19cbe 100644 --- a/demos/declarative/samegame/samegame.qml +++ b/demos/declarative/samegame/samegame.qml @@ -1,5 +1,5 @@ import Qt 4.6 -import "content" +import SamegameCore 1.0 Rectangle { id: screen @@ -12,7 +12,7 @@ Rectangle { Image { id: background - anchors.fill: parent; source: "content/pics/background.png" + anchors.fill: parent; source: "SamegameCore/pics/background.png" fillMode: Image.PreserveAspectCrop smooth: true } @@ -22,7 +22,7 @@ Rectangle { property int score: 0 property int tileSize: 40 - Script { source: "content/samegame.js" } + Script { source: "SamegameCore/samegame.js" } z: 20; anchors.centerIn: parent width: parent.width - (parent.width % getTileSize()); diff --git a/demos/declarative/twitter/TwitterCore/AuthView.qml b/demos/declarative/twitter/TwitterCore/AuthView.qml new file mode 100644 index 0000000..bcf4646 --- /dev/null +++ b/demos/declarative/twitter/TwitterCore/AuthView.qml @@ -0,0 +1,99 @@ +import Qt 4.6 + +Item { + id: wrapper + Column { + anchors.centerIn: parent + spacing: 20 + Column{ + spacing: 4 + Text { + text: "Screen name:" + font.pixelSize: 16; font.bold: true; color: "white"; style: Text.Raised; styleColor: "black" + horizontalAlignment: Qt.AlignRight + } + Item { + width: 220 + height: 28 + BorderImage { source: "images/lineedit.sci"; anchors.fill: parent } + TextInput{ + id: nameIn + width: parent.width - 8 + anchors.centerIn: parent + maximumLength:21 + font.pixelSize: 16; + font.bold: true + color: "#151515"; selectionColor: "green" + KeyNavigation.down: passIn + focus: true + } + } + } + Column{ + spacing: 4 + Text { + text: "Password:" + font.pixelSize: 16; font.bold: true; color: "white"; style: Text.Raised; styleColor: "black" + horizontalAlignment: Qt.AlignRight + } + Item { + width: 220 + height: 28 + BorderImage { source: "images/lineedit.sci"; anchors.fill: parent } + TextInput{ + id: passIn + width: parent.width - 8 + anchors.centerIn: parent + maximumLength:21 + echoMode: TextInput.Password + font.pixelSize: 16; + font.bold: true + color: "#151515"; selectionColor: "green" + KeyNavigation.down: login + KeyNavigation.up: nameIn + } + } + } + Row{ + spacing: 10 + Button { + width: 100 + height: 32 + id: login + keyUsing: true; + function doLogin(){ + rssModel.authName=nameIn.text; + rssModel.authPass=passIn.text; + rssModel.tags='my timeline'; + screen.focus = true; + } + text: "Log in" + KeyNavigation.right: guest + KeyNavigation.up: passIn + Keys.onReturnPressed: login.doLogin(); + Keys.onSelectPressed: login.doLogin(); + Keys.onSpacePressed: login.doLogin(); + onClicked: login.doLogin(); + } + Button { + width: 100 + height: 32 + id: guest + keyUsing: true; + function doGuest() + { + rssModel.authName='-'; + screen.focus = true; + screen.setMode(true); + } + text: "Guest" + KeyNavigation.left: login + KeyNavigation.up: passIn + Keys.onReturnPressed: guest.doGuest(); + Keys.onSelectPressed: guest.doGuest(); + Keys.onSpacePressed: guest.doGuest(); + onClicked: guest.doGuest(); + } + } + } +} diff --git a/demos/declarative/twitter/TwitterCore/Button.qml b/demos/declarative/twitter/TwitterCore/Button.qml new file mode 100644 index 0000000..4cba8c3 --- /dev/null +++ b/demos/declarative/twitter/TwitterCore/Button.qml @@ -0,0 +1,49 @@ +import Qt 4.6 + +Item { + id: container + + signal clicked + + property string text + property bool keyUsing: false + + BorderImage { + id: buttonImage + source: "images/toolbutton.sci" + width: container.width; height: container.height + } + BorderImage { + id: pressed + opacity: 0 + source: "images/toolbutton.sci" + width: container.width; height: container.height + } + MouseArea { + id: mouseRegion + anchors.fill: buttonImage + onClicked: { container.clicked(); } + } + Text { + id: btnText + color: if(container.keyUsing){"#DDDDDD";} else {"#FFFFFF";} + anchors.centerIn: buttonImage; font.bold: true + text: container.text; style: Text.Raised; styleColor: "black" + font.pixelSize: 12 + } + states: [ + State { + name: "Pressed" + when: mouseRegion.pressed == true + PropertyChanges { target: pressed; opacity: 1 } + }, + State { + name: "Focused" + when: container.focus == true + PropertyChanges { target: btnText; color: "#FFFFFF" } + } + ] + transitions: Transition { + ColorAnimation { target: btnText; } + } +} diff --git a/demos/declarative/twitter/TwitterCore/FatDelegate.qml b/demos/declarative/twitter/TwitterCore/FatDelegate.qml new file mode 100644 index 0000000..0f013e6 --- /dev/null +++ b/demos/declarative/twitter/TwitterCore/FatDelegate.qml @@ -0,0 +1,46 @@ +import Qt 4.6 + +Component { + id: listDelegate + Item { + id: wrapper; width: wrapper.ListView.view.width; height: if(txt.height > 58){txt.height+8}else{58}//50+4+4 + Script { + function handleLink(link){ + if(link.slice(0,3) == 'app'){ + setUser(link.slice(7)); + screen.setMode(true); + }else if(link.slice(0,4) == 'http'){ + Qt.openUrlExternally(link); + } + } + function addTags(str){ + var ret = str.replace(/@[a-zA-Z0-9_]+/g, '$&');//click to jump to user? + var ret2 = ret.replace(/http:\/\/[^ \n\t]+/g, '$&');//surrounds http links with html link tags + return ret2; + } + } + Item { + id: moveMe; height: parent.height + Rectangle { + id: blackRect + color: "black"; opacity: wrapper.ListView.index % 2 ? 0.2 : 0.3; height: wrapper.height-2; width: wrapper.width; y: 1 + } + Rectangle { + id: whiteRect; x: 6; width: 50; height: 50; color: "white"; smooth: true + anchors.verticalCenter: parent.verticalCenter + + Loading { x: 1; y: 1; width: 48; height: 48; visible: realImage.status != 1 } + Image { id: realImage; source: userImage; x: 1; y: 1; width:48; height:48 } + } + Text { id:txt; y:4; x: 56 + text: '' + + ''+userScreenName + " from " +source + + "
" + addTags(statusText) + ""; + textFormat: Qt.RichText + color: "#cccccc"; style: Text.Raised; styleColor: "black"; wrap: true + anchors.left: whiteRect.right; anchors.right: blackRect.right; anchors.leftMargin: 6; anchors.rightMargin: 6 + onLinkActivated: handleLink(link) + } + } + } +} diff --git a/demos/declarative/twitter/TwitterCore/HomeTitleBar.qml b/demos/declarative/twitter/TwitterCore/HomeTitleBar.qml new file mode 100644 index 0000000..a206c87 --- /dev/null +++ b/demos/declarative/twitter/TwitterCore/HomeTitleBar.qml @@ -0,0 +1,121 @@ +import Qt 4.6 + +Item { + id: titleBar + + signal update() + onYChanged: state="" //When switching titlebars + + BorderImage { source: "images/titlebar.sci"; width: parent.width; height: parent.height + 14; y: -7 } + Item { + id: container + width: (parent.width * 2) - 55 ; height: parent.height + + Script { + function accept() { + if(rssModel.authName == '' || rssModel.authPass == '') + return false;//Can't login like that + + var postData = "status=" + editor.text; + var postman = new XMLHttpRequest(); + postman.open("POST", "http://twitter.com/statuses/update.xml", true, rssModel.authName, rssModel.authPass); + postman.onreadystatechange = function() { + if (postman.readyState == postman.DONE) { + titleBar.update(); + } + } + postman.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); + postman.send(postData); + + editor.text = "" + titleBar.state = "" + } + } + + Rectangle { + x: 6; width: 50; height: 50; color: "white"; smooth: true + anchors.verticalCenter: parent.verticalCenter + + UserModel { user: rssModel.authName; id: userModel } + Component { id: imgDelegate; + Item { + Loading { width:48; height:48; visible: realImage.status != 1 } + Image { source: image; width:48; height:48; id: realImage } + } + } + ListView { model: userModel.model; x:1; y:1; delegate: imgDelegate } + } + + Text { + id: categoryText + anchors.left: parent.left; anchors.right: tagButton.left + anchors.leftMargin: 58; anchors.rightMargin: 10 + anchors.verticalCenter: parent.verticalCenter + elide: Text.ElideLeft + text: "Timeline for " + rssModel.authName + font.pixelSize: 12; font.bold: true; color: "white"; style: Text.Raised; styleColor: "black" + } + + Button { + id: tagButton; x: titleBar.width - 90; width: 85; height: 32; text: "New Post..." + anchors.verticalCenter: parent.verticalCenter; + onClicked: if (titleBar.state == "Posting") accept(); else titleBar.state = "Posting" + } + + Text { + id: charsLeftText; anchors.horizontalCenter: tagButton.horizontalCenter; + anchors.top: tagButton.bottom; anchors.topMargin: 2 + text: {140 - editor.text.length;} visible: titleBar.state == "Posting" + font.pointSize: 10; font.bold: true; color: "white"; style: Text.Raised; styleColor: "black" + } + Item { + id: txtEdit; + anchors.left: tagButton.right; anchors.leftMargin: 5; y: 4 + anchors.right: parent.right; anchors.rightMargin: 40; height: parent.height - 9 + BorderImage { source: "images/lineedit.sci"; anchors.fill: parent } + + Binding {//TODO: Can this be a function, which also resets the cursor? And flashes? + when: editor.text.length > 140 + target: editor + property: "text" + value: editor.text.slice(0,140) + } + TextEdit { + id: editor + anchors.left: parent.left; + anchors.leftMargin: 8; + anchors.bottom: parent.bottom + anchors.bottomMargin: 4; + cursorVisible: true; font.bold: true + width: parent.width - 12 + height: parent.height - 8 + font.pointSize: 10 + wrap: true + color: "#151515"; selectionColor: "green" + } + Keys.forwardTo: [(returnKey), (editor)] + Item { + id: returnKey + Keys.onReturnPressed: accept() + Keys.onEscapePressed: titleBar.state = "" + } + } + } + states: [ + State { + name: "Posting" + PropertyChanges { target: container; x: -tagButton.x + 5 } + PropertyChanges { target: titleBar; height: 80 } + PropertyChanges { target: tagButton; text: "OK" } + PropertyChanges { target: tagButton; width: 28 } + PropertyChanges { target: tagButton; height: 24 } + PropertyChanges { target: txtEdit; focus: true } + } + ] + transitions: [ + Transition { + from: "*"; to: "*" + NumberAnimation { properties: "x,y,width,height"; easing.type: "InOutQuad" } + } + ] +} diff --git a/demos/declarative/twitter/TwitterCore/Loading.qml b/demos/declarative/twitter/TwitterCore/Loading.qml new file mode 100644 index 0000000..76bf64b --- /dev/null +++ b/demos/declarative/twitter/TwitterCore/Loading.qml @@ -0,0 +1,8 @@ +import Qt 4.6 + +Image { + id: loading; source: "images/loading.png"; transformOrigin: "Center" + NumberAnimation on rotation { + from: 0; to: 360; running: loading.visible == true; repeat: true; duration: 900 + } +} diff --git a/demos/declarative/twitter/TwitterCore/MultiTitleBar.qml b/demos/declarative/twitter/TwitterCore/MultiTitleBar.qml new file mode 100644 index 0000000..e0205b8 --- /dev/null +++ b/demos/declarative/twitter/TwitterCore/MultiTitleBar.qml @@ -0,0 +1,24 @@ +import Qt 4.6 + +Item { + height: homeBar.height + HomeTitleBar { id: homeBar; width: parent.width; height: 60; + onUpdate: rssModel.reload() + } + TitleBar { id: titleBar; width: parent.width; height: 60; + y: -80 + untaggedString: "Latest tweets from everyone" + taggedString: "Latest tweets from " + } + states: [ + State { + name: "search"; when: screen.userView + PropertyChanges { target: titleBar; y: 0 } + PropertyChanges { target: homeBar; y: -80 } + } + ] + transitions: [ + Transition { NumberAnimation { properties: "x,y"; duration: 500; easing.type: "InOutQuad" } } + ] +} + diff --git a/demos/declarative/twitter/TwitterCore/RssModel.qml b/demos/declarative/twitter/TwitterCore/RssModel.qml new file mode 100644 index 0000000..9d88bb7 --- /dev/null +++ b/demos/declarative/twitter/TwitterCore/RssModel.qml @@ -0,0 +1,44 @@ +import Qt 4.6 + +Item { id: wrapper + property var model: xmlModel + property string tags : "" + property string authName : "" + property string authPass : "" + property string mode : "everyone" + property int status: xmlModel.status + function reload() { xmlModel.reload(); } +XmlListModel { + id: xmlModel + + source:{ + if (wrapper.authName == ""){ + ""; //Avoid worthless calls to twitter servers + }else if(wrapper.mode == 'user'){ + "https://"+ ((wrapper.authName!="" && wrapper.authPass!="")? (wrapper.authName+":"+wrapper.authPass+"@") : "" )+"twitter.com/statuses/user_timeline.xml?screen_name="+wrapper.tags; + }else if(wrapper.mode == 'self'){ + "https://"+ ((wrapper.authName!="" && wrapper.authPass!="")? (wrapper.authName+":"+wrapper.authPass+"@") : "" )+"twitter.com/statuses/friends_timeline.xml"; + }else{//everyone/public + "http://twitter.com/statuses/public_timeline.xml"; + } + } + query: "/statuses/status" + + XmlRole { name: "statusText"; query: "text/string()" } + XmlRole { name: "timestamp"; query: "created_at/string()" } + XmlRole { name: "source"; query: "source/string()" } + XmlRole { name: "userName"; query: "user/name/string()" } + XmlRole { name: "userScreenName"; query: "user/screen_name/string()" } + XmlRole { name: "userImage"; query: "user/profile_image_url/string()" } + XmlRole { name: "userLocation"; query: "user/location/string()" } + XmlRole { name: "userDescription"; query: "user/description/string()" } + XmlRole { name: "userFollowers"; query: "user/followers_count/string()" } + XmlRole { name: "userStatuses"; query: "user/statuses_count/string()" } + //TODO: Could also get the user's color scheme, timezone and a few other things +} +Binding { + property: "mode" + target: wrapper + value: {if(wrapper.tags==''){"everyone";}else if(wrapper.tags=='my timeline'){"self";}else{"user";}} +} +} diff --git a/demos/declarative/twitter/TwitterCore/TitleBar.qml b/demos/declarative/twitter/TwitterCore/TitleBar.qml new file mode 100644 index 0000000..149aa82 --- /dev/null +++ b/demos/declarative/twitter/TwitterCore/TitleBar.qml @@ -0,0 +1,77 @@ +import Qt 4.6 + +Item { + id: titleBar + property string untaggedString: "Uploads from everyone" + property string taggedString: "Recent uploads tagged " + + BorderImage { source: "images/titlebar.sci"; width: parent.width; height: parent.height + 14; y: -7 } + + Item { + id: container + width: (parent.width * 2) - 55 ; height: parent.height + + Script { + function accept() { + titleBar.state = "" + background.state = "" + rssModel.tags = editor.text + } + } + + Text { + id: categoryText + anchors { + left: parent.left; right: tagButton.left; leftMargin: 10; rightMargin: 10 + verticalCenter: parent.verticalCenter + } + elide: Text.ElideLeft + text: (rssModel.tags=="" ? untaggedString : taggedString + rssModel.tags) + font.bold: true; color: "White"; style: Text.Raised; styleColor: "Black" + font.pixelSize: 12 + } + + Button { + id: tagButton; x: titleBar.width - 50; width: 45; height: 32; text: "..." + onClicked: if (titleBar.state == "Tags") accept(); else titleBar.state = "Tags" + anchors.verticalCenter: parent.verticalCenter + } + + Item { + id: lineEdit + y: 4; height: parent.height - 9 + anchors { left: tagButton.right; leftMargin: 5; right: parent.right; rightMargin: 5 } + + BorderImage { source: "images/lineedit.sci"; anchors.fill: parent } + + TextInput { + id: editor + anchors { + left: parent.left; right: parent.right; leftMargin: 10; rightMargin: 10 + verticalCenter: parent.verticalCenter + } + cursorVisible: true; font.bold: true + color: "#151515"; selectionColor: "Green" + } + + Keys.forwardTo: [ (returnKey), (editor)] + + Item { + id: returnKey + Keys.onReturnPressed: accept() + Keys.onEscapePressed: titleBar.state = "" + } + } + } + + states: State { + name: "Tags" + PropertyChanges { target: container; x: -tagButton.x + 5 } + PropertyChanges { target: tagButton; text: "OK" } + PropertyChanges { target: lineEdit; focus: true } + } + + transitions: Transition { + NumberAnimation { properties: "x"; easing.type: "InOutQuad" } + } +} diff --git a/demos/declarative/twitter/TwitterCore/ToolBar.qml b/demos/declarative/twitter/TwitterCore/ToolBar.qml new file mode 100644 index 0000000..f96c767 --- /dev/null +++ b/demos/declarative/twitter/TwitterCore/ToolBar.qml @@ -0,0 +1,24 @@ +import Qt 4.6 + +Item { + id: toolbar + + property alias button1Label: button1.text + property alias button2Label: button2.text + signal button1Clicked + signal button2Clicked + + BorderImage { source: "images/titlebar.sci"; width: parent.width; height: parent.height + 14; y: -7 } + + Button { + id: button1 + anchors.left: parent.left; anchors.leftMargin: 5; y: 3; width: 140; height: 32 + onClicked: toolbar.button1Clicked() + } + + Button { + id: button2 + anchors.right: parent.right; anchors.rightMargin: 5; y: 3; width: 140; height: 32 + onClicked: toolbar.button2Clicked() + } +} diff --git a/demos/declarative/twitter/TwitterCore/UserModel.qml b/demos/declarative/twitter/TwitterCore/UserModel.qml new file mode 100644 index 0000000..c146b84 --- /dev/null +++ b/demos/declarative/twitter/TwitterCore/UserModel.qml @@ -0,0 +1,26 @@ +import Qt 4.6 + +//This "model" gets the user information about the searched user. Mainly for the icon. +//Copied from RssModel + +Item { id: wrapper + property var model: xmlModel + property string user : "" + property int status: xmlModel.status + function reload() { xmlModel.reload(); } +XmlListModel { + id: xmlModel + + source: {if(user!="") {"http://twitter.com/users/show.xml?screen_name="+user;}else{"";}} + query: "/user" + + XmlRole { name: "name"; query: "name/string()" } + XmlRole { name: "screenName"; query: "screen_name/string()" } + XmlRole { name: "image"; query: "profile_image_url/string()" } + XmlRole { name: "location"; query: "location/string()" } + XmlRole { name: "description"; query: "description/string()" } + XmlRole { name: "followers"; query: "followers_count/string()" } + //XmlRole { name: "protected"; query: "protected/bool()" } + //TODO: Could also get the user's color scheme, timezone and a few other things +} +} diff --git a/demos/declarative/twitter/TwitterCore/images/gloss.png b/demos/declarative/twitter/TwitterCore/images/gloss.png new file mode 100644 index 0000000..5d370cd Binary files /dev/null and b/demos/declarative/twitter/TwitterCore/images/gloss.png differ diff --git a/demos/declarative/twitter/TwitterCore/images/lineedit.png b/demos/declarative/twitter/TwitterCore/images/lineedit.png new file mode 100644 index 0000000..2cc38dc Binary files /dev/null and b/demos/declarative/twitter/TwitterCore/images/lineedit.png differ diff --git a/demos/declarative/twitter/TwitterCore/images/lineedit.sci b/demos/declarative/twitter/TwitterCore/images/lineedit.sci new file mode 100644 index 0000000..054bff7 --- /dev/null +++ b/demos/declarative/twitter/TwitterCore/images/lineedit.sci @@ -0,0 +1,5 @@ +border.left: 10 +border.top: 10 +border.bottom: 10 +border.right: 10 +source: lineedit.png diff --git a/demos/declarative/twitter/TwitterCore/images/loading.png b/demos/declarative/twitter/TwitterCore/images/loading.png new file mode 100644 index 0000000..47a1589 Binary files /dev/null and b/demos/declarative/twitter/TwitterCore/images/loading.png differ diff --git a/demos/declarative/twitter/TwitterCore/images/stripes.png b/demos/declarative/twitter/TwitterCore/images/stripes.png new file mode 100644 index 0000000..9f36727 Binary files /dev/null and b/demos/declarative/twitter/TwitterCore/images/stripes.png differ diff --git a/demos/declarative/twitter/TwitterCore/images/titlebar.png b/demos/declarative/twitter/TwitterCore/images/titlebar.png new file mode 100644 index 0000000..51c9008 Binary files /dev/null and b/demos/declarative/twitter/TwitterCore/images/titlebar.png differ diff --git a/demos/declarative/twitter/TwitterCore/images/titlebar.sci b/demos/declarative/twitter/TwitterCore/images/titlebar.sci new file mode 100644 index 0000000..0418d94 --- /dev/null +++ b/demos/declarative/twitter/TwitterCore/images/titlebar.sci @@ -0,0 +1,5 @@ +border.left: 10 +border.top: 12 +border.bottom: 12 +border.right: 10 +source: titlebar.png diff --git a/demos/declarative/twitter/TwitterCore/images/toolbutton.png b/demos/declarative/twitter/TwitterCore/images/toolbutton.png new file mode 100644 index 0000000..1131001 Binary files /dev/null and b/demos/declarative/twitter/TwitterCore/images/toolbutton.png differ diff --git a/demos/declarative/twitter/TwitterCore/images/toolbutton.sci b/demos/declarative/twitter/TwitterCore/images/toolbutton.sci new file mode 100644 index 0000000..9e4f965 --- /dev/null +++ b/demos/declarative/twitter/TwitterCore/images/toolbutton.sci @@ -0,0 +1,5 @@ +border.left: 15 +border.top: 4 +border.bottom: 4 +border.right: 15 +source: toolbutton.png diff --git a/demos/declarative/twitter/TwitterCore/qmldir b/demos/declarative/twitter/TwitterCore/qmldir new file mode 100644 index 0000000..8b56c56 --- /dev/null +++ b/demos/declarative/twitter/TwitterCore/qmldir @@ -0,0 +1,10 @@ +AuthView 1.0 AuthView.qml +Button 1.0 Button.qml +FatDelegate 1.0 FatDelegate.qml +HomeTitleBar 1.0 HomeTitleBar.qml +Loading 1.0 Loading.qml +MultiTitleBar 1.0 MultiTitleBar.qml +TitleBar 1.0 TitleBar.qml +RssModel 1.0 RssModel.qml +UserModel 1.0 UserModel.qml +ToolBar 1.0 ToolBar.qml diff --git a/demos/declarative/twitter/content/AuthView.qml b/demos/declarative/twitter/content/AuthView.qml deleted file mode 100644 index bcf4646..0000000 --- a/demos/declarative/twitter/content/AuthView.qml +++ /dev/null @@ -1,99 +0,0 @@ -import Qt 4.6 - -Item { - id: wrapper - Column { - anchors.centerIn: parent - spacing: 20 - Column{ - spacing: 4 - Text { - text: "Screen name:" - font.pixelSize: 16; font.bold: true; color: "white"; style: Text.Raised; styleColor: "black" - horizontalAlignment: Qt.AlignRight - } - Item { - width: 220 - height: 28 - BorderImage { source: "images/lineedit.sci"; anchors.fill: parent } - TextInput{ - id: nameIn - width: parent.width - 8 - anchors.centerIn: parent - maximumLength:21 - font.pixelSize: 16; - font.bold: true - color: "#151515"; selectionColor: "green" - KeyNavigation.down: passIn - focus: true - } - } - } - Column{ - spacing: 4 - Text { - text: "Password:" - font.pixelSize: 16; font.bold: true; color: "white"; style: Text.Raised; styleColor: "black" - horizontalAlignment: Qt.AlignRight - } - Item { - width: 220 - height: 28 - BorderImage { source: "images/lineedit.sci"; anchors.fill: parent } - TextInput{ - id: passIn - width: parent.width - 8 - anchors.centerIn: parent - maximumLength:21 - echoMode: TextInput.Password - font.pixelSize: 16; - font.bold: true - color: "#151515"; selectionColor: "green" - KeyNavigation.down: login - KeyNavigation.up: nameIn - } - } - } - Row{ - spacing: 10 - Button { - width: 100 - height: 32 - id: login - keyUsing: true; - function doLogin(){ - rssModel.authName=nameIn.text; - rssModel.authPass=passIn.text; - rssModel.tags='my timeline'; - screen.focus = true; - } - text: "Log in" - KeyNavigation.right: guest - KeyNavigation.up: passIn - Keys.onReturnPressed: login.doLogin(); - Keys.onSelectPressed: login.doLogin(); - Keys.onSpacePressed: login.doLogin(); - onClicked: login.doLogin(); - } - Button { - width: 100 - height: 32 - id: guest - keyUsing: true; - function doGuest() - { - rssModel.authName='-'; - screen.focus = true; - screen.setMode(true); - } - text: "Guest" - KeyNavigation.left: login - KeyNavigation.up: passIn - Keys.onReturnPressed: guest.doGuest(); - Keys.onSelectPressed: guest.doGuest(); - Keys.onSpacePressed: guest.doGuest(); - onClicked: guest.doGuest(); - } - } - } -} diff --git a/demos/declarative/twitter/content/Button.qml b/demos/declarative/twitter/content/Button.qml deleted file mode 100644 index 4cba8c3..0000000 --- a/demos/declarative/twitter/content/Button.qml +++ /dev/null @@ -1,49 +0,0 @@ -import Qt 4.6 - -Item { - id: container - - signal clicked - - property string text - property bool keyUsing: false - - BorderImage { - id: buttonImage - source: "images/toolbutton.sci" - width: container.width; height: container.height - } - BorderImage { - id: pressed - opacity: 0 - source: "images/toolbutton.sci" - width: container.width; height: container.height - } - MouseArea { - id: mouseRegion - anchors.fill: buttonImage - onClicked: { container.clicked(); } - } - Text { - id: btnText - color: if(container.keyUsing){"#DDDDDD";} else {"#FFFFFF";} - anchors.centerIn: buttonImage; font.bold: true - text: container.text; style: Text.Raised; styleColor: "black" - font.pixelSize: 12 - } - states: [ - State { - name: "Pressed" - when: mouseRegion.pressed == true - PropertyChanges { target: pressed; opacity: 1 } - }, - State { - name: "Focused" - when: container.focus == true - PropertyChanges { target: btnText; color: "#FFFFFF" } - } - ] - transitions: Transition { - ColorAnimation { target: btnText; } - } -} diff --git a/demos/declarative/twitter/content/FatDelegate.qml b/demos/declarative/twitter/content/FatDelegate.qml deleted file mode 100644 index 0f013e6..0000000 --- a/demos/declarative/twitter/content/FatDelegate.qml +++ /dev/null @@ -1,46 +0,0 @@ -import Qt 4.6 - -Component { - id: listDelegate - Item { - id: wrapper; width: wrapper.ListView.view.width; height: if(txt.height > 58){txt.height+8}else{58}//50+4+4 - Script { - function handleLink(link){ - if(link.slice(0,3) == 'app'){ - setUser(link.slice(7)); - screen.setMode(true); - }else if(link.slice(0,4) == 'http'){ - Qt.openUrlExternally(link); - } - } - function addTags(str){ - var ret = str.replace(/@[a-zA-Z0-9_]+/g, '$&');//click to jump to user? - var ret2 = ret.replace(/http:\/\/[^ \n\t]+/g, '$&');//surrounds http links with html link tags - return ret2; - } - } - Item { - id: moveMe; height: parent.height - Rectangle { - id: blackRect - color: "black"; opacity: wrapper.ListView.index % 2 ? 0.2 : 0.3; height: wrapper.height-2; width: wrapper.width; y: 1 - } - Rectangle { - id: whiteRect; x: 6; width: 50; height: 50; color: "white"; smooth: true - anchors.verticalCenter: parent.verticalCenter - - Loading { x: 1; y: 1; width: 48; height: 48; visible: realImage.status != 1 } - Image { id: realImage; source: userImage; x: 1; y: 1; width:48; height:48 } - } - Text { id:txt; y:4; x: 56 - text: '' - + ''+userScreenName + " from " +source - + "
" + addTags(statusText) + ""; - textFormat: Qt.RichText - color: "#cccccc"; style: Text.Raised; styleColor: "black"; wrap: true - anchors.left: whiteRect.right; anchors.right: blackRect.right; anchors.leftMargin: 6; anchors.rightMargin: 6 - onLinkActivated: handleLink(link) - } - } - } -} diff --git a/demos/declarative/twitter/content/HomeTitleBar.qml b/demos/declarative/twitter/content/HomeTitleBar.qml deleted file mode 100644 index a206c87..0000000 --- a/demos/declarative/twitter/content/HomeTitleBar.qml +++ /dev/null @@ -1,121 +0,0 @@ -import Qt 4.6 - -Item { - id: titleBar - - signal update() - onYChanged: state="" //When switching titlebars - - BorderImage { source: "images/titlebar.sci"; width: parent.width; height: parent.height + 14; y: -7 } - Item { - id: container - width: (parent.width * 2) - 55 ; height: parent.height - - Script { - function accept() { - if(rssModel.authName == '' || rssModel.authPass == '') - return false;//Can't login like that - - var postData = "status=" + editor.text; - var postman = new XMLHttpRequest(); - postman.open("POST", "http://twitter.com/statuses/update.xml", true, rssModel.authName, rssModel.authPass); - postman.onreadystatechange = function() { - if (postman.readyState == postman.DONE) { - titleBar.update(); - } - } - postman.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); - postman.send(postData); - - editor.text = "" - titleBar.state = "" - } - } - - Rectangle { - x: 6; width: 50; height: 50; color: "white"; smooth: true - anchors.verticalCenter: parent.verticalCenter - - UserModel { user: rssModel.authName; id: userModel } - Component { id: imgDelegate; - Item { - Loading { width:48; height:48; visible: realImage.status != 1 } - Image { source: image; width:48; height:48; id: realImage } - } - } - ListView { model: userModel.model; x:1; y:1; delegate: imgDelegate } - } - - Text { - id: categoryText - anchors.left: parent.left; anchors.right: tagButton.left - anchors.leftMargin: 58; anchors.rightMargin: 10 - anchors.verticalCenter: parent.verticalCenter - elide: Text.ElideLeft - text: "Timeline for " + rssModel.authName - font.pixelSize: 12; font.bold: true; color: "white"; style: Text.Raised; styleColor: "black" - } - - Button { - id: tagButton; x: titleBar.width - 90; width: 85; height: 32; text: "New Post..." - anchors.verticalCenter: parent.verticalCenter; - onClicked: if (titleBar.state == "Posting") accept(); else titleBar.state = "Posting" - } - - Text { - id: charsLeftText; anchors.horizontalCenter: tagButton.horizontalCenter; - anchors.top: tagButton.bottom; anchors.topMargin: 2 - text: {140 - editor.text.length;} visible: titleBar.state == "Posting" - font.pointSize: 10; font.bold: true; color: "white"; style: Text.Raised; styleColor: "black" - } - Item { - id: txtEdit; - anchors.left: tagButton.right; anchors.leftMargin: 5; y: 4 - anchors.right: parent.right; anchors.rightMargin: 40; height: parent.height - 9 - BorderImage { source: "images/lineedit.sci"; anchors.fill: parent } - - Binding {//TODO: Can this be a function, which also resets the cursor? And flashes? - when: editor.text.length > 140 - target: editor - property: "text" - value: editor.text.slice(0,140) - } - TextEdit { - id: editor - anchors.left: parent.left; - anchors.leftMargin: 8; - anchors.bottom: parent.bottom - anchors.bottomMargin: 4; - cursorVisible: true; font.bold: true - width: parent.width - 12 - height: parent.height - 8 - font.pointSize: 10 - wrap: true - color: "#151515"; selectionColor: "green" - } - Keys.forwardTo: [(returnKey), (editor)] - Item { - id: returnKey - Keys.onReturnPressed: accept() - Keys.onEscapePressed: titleBar.state = "" - } - } - } - states: [ - State { - name: "Posting" - PropertyChanges { target: container; x: -tagButton.x + 5 } - PropertyChanges { target: titleBar; height: 80 } - PropertyChanges { target: tagButton; text: "OK" } - PropertyChanges { target: tagButton; width: 28 } - PropertyChanges { target: tagButton; height: 24 } - PropertyChanges { target: txtEdit; focus: true } - } - ] - transitions: [ - Transition { - from: "*"; to: "*" - NumberAnimation { properties: "x,y,width,height"; easing.type: "InOutQuad" } - } - ] -} diff --git a/demos/declarative/twitter/content/Loading.qml b/demos/declarative/twitter/content/Loading.qml deleted file mode 100644 index 76bf64b..0000000 --- a/demos/declarative/twitter/content/Loading.qml +++ /dev/null @@ -1,8 +0,0 @@ -import Qt 4.6 - -Image { - id: loading; source: "images/loading.png"; transformOrigin: "Center" - NumberAnimation on rotation { - from: 0; to: 360; running: loading.visible == true; repeat: true; duration: 900 - } -} diff --git a/demos/declarative/twitter/content/MultiTitleBar.qml b/demos/declarative/twitter/content/MultiTitleBar.qml deleted file mode 100644 index e0205b8..0000000 --- a/demos/declarative/twitter/content/MultiTitleBar.qml +++ /dev/null @@ -1,24 +0,0 @@ -import Qt 4.6 - -Item { - height: homeBar.height - HomeTitleBar { id: homeBar; width: parent.width; height: 60; - onUpdate: rssModel.reload() - } - TitleBar { id: titleBar; width: parent.width; height: 60; - y: -80 - untaggedString: "Latest tweets from everyone" - taggedString: "Latest tweets from " - } - states: [ - State { - name: "search"; when: screen.userView - PropertyChanges { target: titleBar; y: 0 } - PropertyChanges { target: homeBar; y: -80 } - } - ] - transitions: [ - Transition { NumberAnimation { properties: "x,y"; duration: 500; easing.type: "InOutQuad" } } - ] -} - diff --git a/demos/declarative/twitter/content/RssModel.qml b/demos/declarative/twitter/content/RssModel.qml deleted file mode 100644 index 9d88bb7..0000000 --- a/demos/declarative/twitter/content/RssModel.qml +++ /dev/null @@ -1,44 +0,0 @@ -import Qt 4.6 - -Item { id: wrapper - property var model: xmlModel - property string tags : "" - property string authName : "" - property string authPass : "" - property string mode : "everyone" - property int status: xmlModel.status - function reload() { xmlModel.reload(); } -XmlListModel { - id: xmlModel - - source:{ - if (wrapper.authName == ""){ - ""; //Avoid worthless calls to twitter servers - }else if(wrapper.mode == 'user'){ - "https://"+ ((wrapper.authName!="" && wrapper.authPass!="")? (wrapper.authName+":"+wrapper.authPass+"@") : "" )+"twitter.com/statuses/user_timeline.xml?screen_name="+wrapper.tags; - }else if(wrapper.mode == 'self'){ - "https://"+ ((wrapper.authName!="" && wrapper.authPass!="")? (wrapper.authName+":"+wrapper.authPass+"@") : "" )+"twitter.com/statuses/friends_timeline.xml"; - }else{//everyone/public - "http://twitter.com/statuses/public_timeline.xml"; - } - } - query: "/statuses/status" - - XmlRole { name: "statusText"; query: "text/string()" } - XmlRole { name: "timestamp"; query: "created_at/string()" } - XmlRole { name: "source"; query: "source/string()" } - XmlRole { name: "userName"; query: "user/name/string()" } - XmlRole { name: "userScreenName"; query: "user/screen_name/string()" } - XmlRole { name: "userImage"; query: "user/profile_image_url/string()" } - XmlRole { name: "userLocation"; query: "user/location/string()" } - XmlRole { name: "userDescription"; query: "user/description/string()" } - XmlRole { name: "userFollowers"; query: "user/followers_count/string()" } - XmlRole { name: "userStatuses"; query: "user/statuses_count/string()" } - //TODO: Could also get the user's color scheme, timezone and a few other things -} -Binding { - property: "mode" - target: wrapper - value: {if(wrapper.tags==''){"everyone";}else if(wrapper.tags=='my timeline'){"self";}else{"user";}} -} -} diff --git a/demos/declarative/twitter/content/TitleBar.qml b/demos/declarative/twitter/content/TitleBar.qml deleted file mode 100644 index 149aa82..0000000 --- a/demos/declarative/twitter/content/TitleBar.qml +++ /dev/null @@ -1,77 +0,0 @@ -import Qt 4.6 - -Item { - id: titleBar - property string untaggedString: "Uploads from everyone" - property string taggedString: "Recent uploads tagged " - - BorderImage { source: "images/titlebar.sci"; width: parent.width; height: parent.height + 14; y: -7 } - - Item { - id: container - width: (parent.width * 2) - 55 ; height: parent.height - - Script { - function accept() { - titleBar.state = "" - background.state = "" - rssModel.tags = editor.text - } - } - - Text { - id: categoryText - anchors { - left: parent.left; right: tagButton.left; leftMargin: 10; rightMargin: 10 - verticalCenter: parent.verticalCenter - } - elide: Text.ElideLeft - text: (rssModel.tags=="" ? untaggedString : taggedString + rssModel.tags) - font.bold: true; color: "White"; style: Text.Raised; styleColor: "Black" - font.pixelSize: 12 - } - - Button { - id: tagButton; x: titleBar.width - 50; width: 45; height: 32; text: "..." - onClicked: if (titleBar.state == "Tags") accept(); else titleBar.state = "Tags" - anchors.verticalCenter: parent.verticalCenter - } - - Item { - id: lineEdit - y: 4; height: parent.height - 9 - anchors { left: tagButton.right; leftMargin: 5; right: parent.right; rightMargin: 5 } - - BorderImage { source: "images/lineedit.sci"; anchors.fill: parent } - - TextInput { - id: editor - anchors { - left: parent.left; right: parent.right; leftMargin: 10; rightMargin: 10 - verticalCenter: parent.verticalCenter - } - cursorVisible: true; font.bold: true - color: "#151515"; selectionColor: "Green" - } - - Keys.forwardTo: [ (returnKey), (editor)] - - Item { - id: returnKey - Keys.onReturnPressed: accept() - Keys.onEscapePressed: titleBar.state = "" - } - } - } - - states: State { - name: "Tags" - PropertyChanges { target: container; x: -tagButton.x + 5 } - PropertyChanges { target: tagButton; text: "OK" } - PropertyChanges { target: lineEdit; focus: true } - } - - transitions: Transition { - NumberAnimation { properties: "x"; easing.type: "InOutQuad" } - } -} diff --git a/demos/declarative/twitter/content/ToolBar.qml b/demos/declarative/twitter/content/ToolBar.qml deleted file mode 100644 index f96c767..0000000 --- a/demos/declarative/twitter/content/ToolBar.qml +++ /dev/null @@ -1,24 +0,0 @@ -import Qt 4.6 - -Item { - id: toolbar - - property alias button1Label: button1.text - property alias button2Label: button2.text - signal button1Clicked - signal button2Clicked - - BorderImage { source: "images/titlebar.sci"; width: parent.width; height: parent.height + 14; y: -7 } - - Button { - id: button1 - anchors.left: parent.left; anchors.leftMargin: 5; y: 3; width: 140; height: 32 - onClicked: toolbar.button1Clicked() - } - - Button { - id: button2 - anchors.right: parent.right; anchors.rightMargin: 5; y: 3; width: 140; height: 32 - onClicked: toolbar.button2Clicked() - } -} diff --git a/demos/declarative/twitter/content/UserModel.qml b/demos/declarative/twitter/content/UserModel.qml deleted file mode 100644 index c146b84..0000000 --- a/demos/declarative/twitter/content/UserModel.qml +++ /dev/null @@ -1,26 +0,0 @@ -import Qt 4.6 - -//This "model" gets the user information about the searched user. Mainly for the icon. -//Copied from RssModel - -Item { id: wrapper - property var model: xmlModel - property string user : "" - property int status: xmlModel.status - function reload() { xmlModel.reload(); } -XmlListModel { - id: xmlModel - - source: {if(user!="") {"http://twitter.com/users/show.xml?screen_name="+user;}else{"";}} - query: "/user" - - XmlRole { name: "name"; query: "name/string()" } - XmlRole { name: "screenName"; query: "screen_name/string()" } - XmlRole { name: "image"; query: "profile_image_url/string()" } - XmlRole { name: "location"; query: "location/string()" } - XmlRole { name: "description"; query: "description/string()" } - XmlRole { name: "followers"; query: "followers_count/string()" } - //XmlRole { name: "protected"; query: "protected/bool()" } - //TODO: Could also get the user's color scheme, timezone and a few other things -} -} diff --git a/demos/declarative/twitter/content/images/gloss.png b/demos/declarative/twitter/content/images/gloss.png deleted file mode 100644 index 5d370cd..0000000 Binary files a/demos/declarative/twitter/content/images/gloss.png and /dev/null differ diff --git a/demos/declarative/twitter/content/images/lineedit.png b/demos/declarative/twitter/content/images/lineedit.png deleted file mode 100644 index 2cc38dc..0000000 Binary files a/demos/declarative/twitter/content/images/lineedit.png and /dev/null differ diff --git a/demos/declarative/twitter/content/images/lineedit.sci b/demos/declarative/twitter/content/images/lineedit.sci deleted file mode 100644 index 054bff7..0000000 --- a/demos/declarative/twitter/content/images/lineedit.sci +++ /dev/null @@ -1,5 +0,0 @@ -border.left: 10 -border.top: 10 -border.bottom: 10 -border.right: 10 -source: lineedit.png diff --git a/demos/declarative/twitter/content/images/loading.png b/demos/declarative/twitter/content/images/loading.png deleted file mode 100644 index 47a1589..0000000 Binary files a/demos/declarative/twitter/content/images/loading.png and /dev/null differ diff --git a/demos/declarative/twitter/content/images/stripes.png b/demos/declarative/twitter/content/images/stripes.png deleted file mode 100644 index 9f36727..0000000 Binary files a/demos/declarative/twitter/content/images/stripes.png and /dev/null differ diff --git a/demos/declarative/twitter/content/images/titlebar.png b/demos/declarative/twitter/content/images/titlebar.png deleted file mode 100644 index 51c9008..0000000 Binary files a/demos/declarative/twitter/content/images/titlebar.png and /dev/null differ diff --git a/demos/declarative/twitter/content/images/titlebar.sci b/demos/declarative/twitter/content/images/titlebar.sci deleted file mode 100644 index 0418d94..0000000 --- a/demos/declarative/twitter/content/images/titlebar.sci +++ /dev/null @@ -1,5 +0,0 @@ -border.left: 10 -border.top: 12 -border.bottom: 12 -border.right: 10 -source: titlebar.png diff --git a/demos/declarative/twitter/content/images/toolbutton.png b/demos/declarative/twitter/content/images/toolbutton.png deleted file mode 100644 index 1131001..0000000 Binary files a/demos/declarative/twitter/content/images/toolbutton.png and /dev/null differ diff --git a/demos/declarative/twitter/content/images/toolbutton.sci b/demos/declarative/twitter/content/images/toolbutton.sci deleted file mode 100644 index 9e4f965..0000000 --- a/demos/declarative/twitter/content/images/toolbutton.sci +++ /dev/null @@ -1,5 +0,0 @@ -border.left: 15 -border.top: 4 -border.bottom: 4 -border.right: 15 -source: toolbutton.png diff --git a/demos/declarative/twitter/twitter.qml b/demos/declarative/twitter/twitter.qml index 0ea1309..259f79a 100644 --- a/demos/declarative/twitter/twitter.qml +++ b/demos/declarative/twitter/twitter.qml @@ -1,5 +1,5 @@ import Qt 4.6 -import "content" as Twitter +import TwitterCore 1.0 as Twitter Item { id: screen; width: 320; height: 480 @@ -28,7 +28,7 @@ Item { id: background anchors.fill: parent; color: "#343434"; - Image { source: "content/images/stripes.png"; fillMode: Image.Tile; anchors.fill: parent; opacity: 0.3 } + Image { source: "TwitterCore/images/stripes.png"; fillMode: Image.Tile; anchors.fill: parent; opacity: 0.3 } Twitter.RssModel { id: rssModel } Twitter.Loading { anchors.centerIn: parent; visible: rssModel.status==XmlListModel.Loading && state!='unauthed'} -- cgit v0.12 From 4eaa7599be17d0838f98e2bafb0f0c8a0787530e Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Tue, 2 Mar 2010 15:55:17 +0100 Subject: Add minehunt README --- demos/declarative/minehunt/README | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 demos/declarative/minehunt/README diff --git a/demos/declarative/minehunt/README b/demos/declarative/minehunt/README new file mode 100644 index 0000000..7379dcf --- /dev/null +++ b/demos/declarative/minehunt/README @@ -0,0 +1,3 @@ +To run, simply load the minehunt.qml file with the qml runtime. + +Note that on X11, this demo has problems with the native graphicssystem. If you are using the X11 window system, please pass -graphicssystem raster to the qml binary. -- cgit v0.12 From b0b19d286e10d307db4b9e477d4463eabc2b319d Mon Sep 17 00:00:00 2001 From: Tobias Hunger Date: Tue, 2 Mar 2010 17:56:17 +0100 Subject: Fix build of imports * Fix export macro used in webkit * Fix dependencies on declarative/mutlimedia * Copy qmldir files into the build tree --- imports/Qt/multimedia/qmldir | 1 - imports/Qt/widgets/qmldir | 1 - imports/org/webkit/qmldir | 1 - src/declarative/declarative.pro | 28 +- src/declarative/imports/imports.pro | 7 - src/declarative/imports/multimedia/multimedia.cpp | 63 - src/declarative/imports/multimedia/multimedia.pro | 15 - src/declarative/imports/qimportbase.pri | 16 - src/declarative/imports/webkit/plugin.cpp | 66 - .../imports/webkit/qdeclarativewebview.cpp | 1340 -------------------- .../imports/webkit/qdeclarativewebview_p.h | 285 ----- .../imports/webkit/qdeclarativewebview_p_p.h | 151 --- src/declarative/imports/webkit/webkit.pro | 18 - .../imports/widgets/graphicslayouts.cpp | 260 ---- .../imports/widgets/graphicslayouts_p.h | 226 ---- .../imports/widgets/graphicswidgets.cpp | 40 - .../imports/widgets/graphicswidgets_p.h | 68 - src/declarative/imports/widgets/widgets.cpp | 138 -- src/declarative/imports/widgets/widgets.pro | 20 - src/declarative/libdeclarative.pro | 29 - src/imports/imports.pro | 7 + src/imports/multimedia/multimedia.cpp | 63 + src/imports/multimedia/multimedia.pro | 15 + src/imports/multimedia/qmldir | 1 + src/imports/qimportbase.pri | 33 + src/imports/webkit/plugin.cpp | 66 + src/imports/webkit/qdeclarativewebview.cpp | 1340 ++++++++++++++++++++ src/imports/webkit/qdeclarativewebview_p.h | 287 +++++ src/imports/webkit/qdeclarativewebview_p_p.h | 151 +++ src/imports/webkit/qmldir | 1 + src/imports/webkit/webkit.pro | 19 + src/imports/webkit/webkitqmlplugin_export.h | 53 + src/imports/widgets/graphicslayouts.cpp | 260 ++++ src/imports/widgets/graphicslayouts_p.h | 226 ++++ src/imports/widgets/graphicswidgets.cpp | 40 + src/imports/widgets/graphicswidgets_p.h | 68 + src/imports/widgets/qmldir | 1 + src/imports/widgets/widgets.cpp | 138 ++ src/imports/widgets/widgets.pro | 22 + src/src.pro | 6 + 40 files changed, 2823 insertions(+), 2747 deletions(-) delete mode 100644 imports/Qt/multimedia/qmldir delete mode 100644 imports/Qt/widgets/qmldir delete mode 100644 imports/org/webkit/qmldir delete mode 100644 src/declarative/imports/imports.pro delete mode 100644 src/declarative/imports/multimedia/multimedia.cpp delete mode 100644 src/declarative/imports/multimedia/multimedia.pro delete mode 100644 src/declarative/imports/qimportbase.pri delete mode 100644 src/declarative/imports/webkit/plugin.cpp delete mode 100644 src/declarative/imports/webkit/qdeclarativewebview.cpp delete mode 100644 src/declarative/imports/webkit/qdeclarativewebview_p.h delete mode 100644 src/declarative/imports/webkit/qdeclarativewebview_p_p.h delete mode 100644 src/declarative/imports/webkit/webkit.pro delete mode 100644 src/declarative/imports/widgets/graphicslayouts.cpp delete mode 100644 src/declarative/imports/widgets/graphicslayouts_p.h delete mode 100644 src/declarative/imports/widgets/graphicswidgets.cpp delete mode 100644 src/declarative/imports/widgets/graphicswidgets_p.h delete mode 100644 src/declarative/imports/widgets/widgets.cpp delete mode 100644 src/declarative/imports/widgets/widgets.pro delete mode 100644 src/declarative/libdeclarative.pro create mode 100644 src/imports/imports.pro create mode 100644 src/imports/multimedia/multimedia.cpp create mode 100644 src/imports/multimedia/multimedia.pro create mode 100644 src/imports/multimedia/qmldir create mode 100644 src/imports/qimportbase.pri create mode 100644 src/imports/webkit/plugin.cpp create mode 100644 src/imports/webkit/qdeclarativewebview.cpp create mode 100644 src/imports/webkit/qdeclarativewebview_p.h create mode 100644 src/imports/webkit/qdeclarativewebview_p_p.h create mode 100644 src/imports/webkit/qmldir create mode 100644 src/imports/webkit/webkit.pro create mode 100644 src/imports/webkit/webkitqmlplugin_export.h create mode 100644 src/imports/widgets/graphicslayouts.cpp create mode 100644 src/imports/widgets/graphicslayouts_p.h create mode 100644 src/imports/widgets/graphicswidgets.cpp create mode 100644 src/imports/widgets/graphicswidgets_p.h create mode 100644 src/imports/widgets/qmldir create mode 100644 src/imports/widgets/widgets.cpp create mode 100644 src/imports/widgets/widgets.pro diff --git a/imports/Qt/multimedia/qmldir b/imports/Qt/multimedia/qmldir deleted file mode 100644 index 0e6f656..0000000 --- a/imports/Qt/multimedia/qmldir +++ /dev/null @@ -1 +0,0 @@ -plugin multimedia diff --git a/imports/Qt/widgets/qmldir b/imports/Qt/widgets/qmldir deleted file mode 100644 index 6f19878..0000000 --- a/imports/Qt/widgets/qmldir +++ /dev/null @@ -1 +0,0 @@ -plugin widgets diff --git a/imports/org/webkit/qmldir b/imports/org/webkit/qmldir deleted file mode 100644 index 258aa2c..0000000 --- a/imports/org/webkit/qmldir +++ /dev/null @@ -1 +0,0 @@ -plugin webkitqmlplugin diff --git a/src/declarative/declarative.pro b/src/declarative/declarative.pro index a7ec18e..4287e25 100644 --- a/src/declarative/declarative.pro +++ b/src/declarative/declarative.pro @@ -1,5 +1,29 @@ -TEMPLATE = subdirs +TARGET = QtDeclarative +QPRO_PWD = $$PWD +QT = core gui xml script network +contains(QT_CONFIG, svg): QT += svg +contains(QT_CONFIG, opengl): QT += opengl +DEFINES += QT_BUILD_DECLARATIVE_LIB QT_NO_URL_CAST_FROM_STRING +win32-msvc*|win32-icc:QMAKE_LFLAGS += /BASE:0x66000000 +solaris-cc*:QMAKE_CXXFLAGS_RELEASE -= -O2 -SUBDIRS = libdeclarative.pro imports +unix:QMAKE_PKGCONFIG_REQUIRES = QtCore QtGui QtXml +exists("qdeclarative_enable_gcov") { + QMAKE_CXXFLAGS = -fprofile-arcs -ftest-coverage -fno-elide-constructors + LIBS += -lgcov +} +include(../qbase.pri) + +#INCLUDEPATH -= $$QMAKE_INCDIR_QT/$$TARGET +#DESTDIR=. + +#modules +include(3rdparty/3rdparty.pri) +include(util/util.pri) +include(graphicsitems/graphicsitems.pri) +include(qml/qml.pri) +include(debugger/debugger.pri) + +symbian:TARGET.UID3=0x2001E623 diff --git a/src/declarative/imports/imports.pro b/src/declarative/imports/imports.pro deleted file mode 100644 index f874644..0000000 --- a/src/declarative/imports/imports.pro +++ /dev/null @@ -1,7 +0,0 @@ -TEMPLATE = subdirs - -SUBDIRS += widgets - -contains(QT_CONFIG, multimedia): SUBDIRS += multimedia -contains(QT_CONFIG, webkit): SUBDIRS += webkit - diff --git a/src/declarative/imports/multimedia/multimedia.cpp b/src/declarative/imports/multimedia/multimedia.cpp deleted file mode 100644 index 8becbf3..0000000 --- a/src/declarative/imports/multimedia/multimedia.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/**************************************************************************** -** -** 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 -#include -#include - -QT_BEGIN_NAMESPACE - -class QMultimediaQmlModule : public QDeclarativeExtensionPlugin -{ - Q_OBJECT -public: - virtual void registerTypes(const char *uri) - { - QtMultimedia::qRegisterDeclarativeElements(uri); - } -}; - -QT_END_NAMESPACE - -#include "multimedia.moc" - -Q_EXPORT_PLUGIN2(qmultimediaqmlmodule, QT_PREPEND_NAMESPACE(QMultimediaQmlModule)); - diff --git a/src/declarative/imports/multimedia/multimedia.pro b/src/declarative/imports/multimedia/multimedia.pro deleted file mode 100644 index d601d2e..0000000 --- a/src/declarative/imports/multimedia/multimedia.pro +++ /dev/null @@ -1,15 +0,0 @@ -TARGET = multimedia -include(../qimportbase.pri) - -QT += multimedia declarative - -SOURCES += multimedia.cpp - -QTDIR_build:DESTDIR = $$QT_BUILD_TREE/imports/Qt/multimedia -target.path = $$[QT_INSTALL_IMPORTS]/Qt/multimedia - -qmldir.files += $$QT_BUILD_TREE/imports/Qt/multimedia/qmldir -qmldir.path += $$[QT_INSTALL_IMPORTS]/Qt/multimedia - -INSTALLS += target qmldir - diff --git a/src/declarative/imports/qimportbase.pri b/src/declarative/imports/qimportbase.pri deleted file mode 100644 index 5b0a4e2..0000000 --- a/src/declarative/imports/qimportbase.pri +++ /dev/null @@ -1,16 +0,0 @@ -TEMPLATE = lib -CONFIG += qt plugin - -win32|mac:!wince*:!win32-msvc:!macx-xcode:CONFIG += debug_and_release -TARGET = $$qtLibraryTarget($$TARGET) -contains(QT_CONFIG, reduce_exports):CONFIG += hide_symbols - -include(../../qt_targets.pri) - -wince*:LIBS += $$QMAKE_LIBS_GUI - -symbian: { - TARGET.EPOCALLOWDLLDATA=1 - TARGET.CAPABILITY = All -Tcb - load(armcc_warnings) -} diff --git a/src/declarative/imports/webkit/plugin.cpp b/src/declarative/imports/webkit/plugin.cpp deleted file mode 100644 index 2f6205d..0000000 --- a/src/declarative/imports/webkit/plugin.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/**************************************************************************** -** -** 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 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 -#include - -#include "qdeclarativewebview_p.h" -#include "qdeclarativewebview_p_p.h" - -QT_BEGIN_NAMESPACE - -class WebKitQmlPlugin : public QDeclarativeExtensionPlugin -{ - Q_OBJECT -public: - virtual void registerTypes(const char *uri) - { - Q_ASSERT(QLatin1String(uri) == QLatin1String("org.webkit")); - qmlRegisterType(uri,1,0,"WebView"); - } -}; - -QT_END_NAMESPACE - -#include "plugin.moc" - -Q_EXPORT_PLUGIN2(webkitqmlplugin, QT_PREPEND_NAMESPACE(WebKitQmlPlugin)); - diff --git a/src/declarative/imports/webkit/qdeclarativewebview.cpp b/src/declarative/imports/webkit/qdeclarativewebview.cpp deleted file mode 100644 index 733ac86..0000000 --- a/src/declarative/imports/webkit/qdeclarativewebview.cpp +++ /dev/null @@ -1,1340 +0,0 @@ -/**************************************************************************** -** -** 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 "qdeclarativewebview_p.h" -#include "qdeclarativewebview_p_p.h" - -#include - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -static const int MAX_DOUBLECLICK_TIME=500; // XXX need better gesture system - -class QDeclarativeWebViewPrivate : public QDeclarativePaintedItemPrivate -{ - Q_DECLARE_PUBLIC(QDeclarativeWebView) - -public: - QDeclarativeWebViewPrivate() - : QDeclarativePaintedItemPrivate(), page(0), preferredwidth(0), preferredheight(0), - progress(1.0), status(QDeclarativeWebView::Null), pending(PendingNone), - newWindowComponent(0), newWindowParent(0), - pressTime(400), - rendering(true) - { - } - - QUrl url; // page url might be different if it has not loaded yet - QWebPage *page; - - int preferredwidth, preferredheight; - qreal progress; - QDeclarativeWebView::Status status; - QString statusText; - enum { PendingNone, PendingUrl, PendingHtml, PendingContent } pending; - QUrl pending_url; - QString pending_string; - QByteArray pending_data; - mutable QDeclarativeWebSettings settings; - QDeclarativeComponent *newWindowComponent; - QDeclarativeItem *newWindowParent; - - QBasicTimer pressTimer; - QPoint pressPoint; - int pressTime; // milliseconds before it's a "hold" - - - static void windowObjects_append(QDeclarativeListProperty *prop, QObject *o) { - static_cast(prop->data)->windowObjects.append(o); - static_cast(prop->data)->updateWindowObjects(); - } - - void updateWindowObjects(); - QObjectList windowObjects; - - bool rendering; -}; - -/*! - \qmlclass WebView QDeclarativeWebView - \since 4.7 - \brief The WebView item allows you to add web content to a canvas. - \inherits Item - - A WebView renders web content based on a URL. - - If the width and height of the item is not set, they will - dynamically adjust to a size appropriate for the content. - This width may be large for typical online web pages. - - If the preferredWidth is set, the width will be this amount or larger, - usually laying out the web content to fit the preferredWidth. - - \qml - import org.webkit 1.0 - - WebView { - url: "http://www.nokia.com" - width: 490 - height: 400 - scale: 0.5 - smooth: false - smoothCache: true - } - \endqml - - \image webview.png - - The item includes no scrolling, scaling, - toolbars, etc., those must be implemented around WebView. See the WebBrowser example - for a demonstration of this. -*/ - -/*! - \internal - \class QDeclarativeWebView - \brief The QDeclarativeWebView class allows you to add web content to a QDeclarativeView. - - A WebView renders web content base on a URL. - - \image webview.png - - The item includes no scrolling, scaling, - toolbars, etc., those must be implemented around WebView. See the WebBrowser example - for a demonstration of this. - - A QDeclarativeWebView object can be instantiated in Qml using the tag \l WebView. -*/ - -QDeclarativeWebView::QDeclarativeWebView(QDeclarativeItem *parent) - : QDeclarativePaintedItem(*(new QDeclarativeWebViewPrivate), parent) -{ - init(); -} - -QDeclarativeWebView::~QDeclarativeWebView() -{ - Q_D(QDeclarativeWebView); - delete d->page; -} - -void QDeclarativeWebView::init() -{ - Q_D(QDeclarativeWebView); - - QWebSettings::enablePersistentStorage(); - - setAcceptHoverEvents(true); - setAcceptedMouseButtons(Qt::LeftButton); - setFlag(QGraphicsItem::ItemHasNoContents, false); - - d->page = 0; -} - -void QDeclarativeWebView::componentComplete() -{ - QDeclarativePaintedItem::componentComplete(); - Q_D(QDeclarativeWebView); - switch (d->pending) { - case QDeclarativeWebViewPrivate::PendingUrl: - setUrl(d->pending_url); - break; - case QDeclarativeWebViewPrivate::PendingHtml: - setHtml(d->pending_string, d->pending_url); - break; - case QDeclarativeWebViewPrivate::PendingContent: - setContent(d->pending_data, d->pending_string, d->pending_url); - break; - default: - break; - } - d->pending = QDeclarativeWebViewPrivate::PendingNone; - d->updateWindowObjects(); -} - -QDeclarativeWebView::Status QDeclarativeWebView::status() const -{ - Q_D(const QDeclarativeWebView); - return d->status; -} - - -/*! - \qmlproperty real WebView::progress - This property holds the progress of loading the current URL, from 0 to 1. - - If you just want to know when progress gets to 1, use - WebView::onLoadFinished() or WebView::onLoadFailed() instead. -*/ -qreal QDeclarativeWebView::progress() const -{ - Q_D(const QDeclarativeWebView); - return d->progress; -} - -void QDeclarativeWebView::doLoadStarted() -{ - Q_D(QDeclarativeWebView); - - if (!d->url.isEmpty()) { - d->status = Loading; - emit statusChanged(d->status); - } - emit loadStarted(); -} - -void QDeclarativeWebView::doLoadProgress(int p) -{ - Q_D(QDeclarativeWebView); - if (d->progress == p/100.0) - return; - d->progress = p/100.0; - emit progressChanged(); -} - -void QDeclarativeWebView::pageUrlChanged() -{ - Q_D(QDeclarativeWebView); - - page()->setViewportSize(QSize( - d->preferredwidth>0 ? d->preferredwidth : width(), - d->preferredheight>0 ? d->preferredheight : height())); - expandToWebPage(); - - if ((d->url.isEmpty() && page()->mainFrame()->url() != QUrl(QLatin1String("about:blank"))) - || (d->url != page()->mainFrame()->url() && !page()->mainFrame()->url().isEmpty())) - { - d->url = page()->mainFrame()->url(); - if (d->url == QUrl(QLatin1String("about:blank"))) - d->url = QUrl(); - emit urlChanged(); - } -} - -void QDeclarativeWebView::doLoadFinished(bool ok) -{ - Q_D(QDeclarativeWebView); - - if (title().isEmpty()) - pageUrlChanged(); // XXX bug 232556 - pages with no title never get urlChanged() - - if (ok) { - d->status = d->url.isEmpty() ? Null : Ready; - emit loadFinished(); - } else { - d->status = Error; - emit loadFailed(); - } - emit statusChanged(d->status); -} - -/*! - \qmlproperty url WebView::url - This property holds the URL to the page displayed in this item. It can be set, - but also can change spontaneously (eg. because of network redirection). - - If the url is empty, the page is blank. - - The url is always absolute (QML will resolve relative URL strings in the context - of the containing QML document). -*/ -QUrl QDeclarativeWebView::url() const -{ - Q_D(const QDeclarativeWebView); - return d->url; -} - -void QDeclarativeWebView::setUrl(const QUrl &url) -{ - Q_D(QDeclarativeWebView); - if (url == d->url) - return; - - if (isComponentComplete()) { - d->url = url; - page()->setViewportSize(QSize( - d->preferredwidth>0 ? d->preferredwidth : width(), - d->preferredheight>0 ? d->preferredheight : height())); - QUrl seturl = url; - if (seturl.isEmpty()) - seturl = QUrl(QLatin1String("about:blank")); - - Q_ASSERT(!seturl.isRelative()); - - page()->mainFrame()->load(seturl); - - emit urlChanged(); - } else { - d->pending = d->PendingUrl; - d->pending_url = url; - } -} - -/*! - \qmlproperty int WebView::preferredWidth - This property holds the ideal width for displaying the current URL. -*/ -int QDeclarativeWebView::preferredWidth() const -{ - Q_D(const QDeclarativeWebView); - return d->preferredwidth; -} - -void QDeclarativeWebView::setPreferredWidth(int iw) -{ - Q_D(QDeclarativeWebView); - if (d->preferredwidth == iw) return; - d->preferredwidth = iw; - //expandToWebPage(); - emit preferredWidthChanged(); -} - -/*! - \qmlproperty int WebView::preferredHeight - This property holds the ideal height for displaying the current URL. - This only affects the area zoomed by heuristicZoom(). -*/ -int QDeclarativeWebView::preferredHeight() const -{ - Q_D(const QDeclarativeWebView); - return d->preferredheight; -} -void QDeclarativeWebView::setPreferredHeight(int ih) -{ - Q_D(QDeclarativeWebView); - if (d->preferredheight == ih) return; - d->preferredheight = ih; - emit preferredHeightChanged(); -} - -/*! - \qmlmethod bool WebView::evaluateJavaScript(string) - - Evaluates the \a scriptSource JavaScript inside the context of the - main web frame, and returns the result of the last executed statement. - - Note that this JavaScript does \e not have any access to QML objects - except as made available as windowObjects. -*/ -QVariant QDeclarativeWebView::evaluateJavaScript(const QString &scriptSource) -{ - return this->page()->mainFrame()->evaluateJavaScript(scriptSource); -} - -void QDeclarativeWebView::focusChanged(bool hasFocus) -{ - QFocusEvent e(hasFocus ? QEvent::FocusIn : QEvent::FocusOut); - page()->event(&e); - QDeclarativeItem::focusChanged(hasFocus); -} - -void QDeclarativeWebView::initialLayout() -{ - // nothing useful to do at this point -} - -void QDeclarativeWebView::noteContentsSizeChanged(const QSize&) -{ - expandToWebPage(); -} - -void QDeclarativeWebView::expandToWebPage() -{ - Q_D(QDeclarativeWebView); - QSize cs = page()->mainFrame()->contentsSize(); - if (cs.width() < d->preferredwidth) - cs.setWidth(d->preferredwidth); - if (cs.height() < d->preferredheight) - cs.setHeight(d->preferredheight); - if (widthValid()) - cs.setWidth(width()); - if (heightValid()) - cs.setHeight(height()); - if (cs != page()->viewportSize()) { - page()->setViewportSize(cs); - } - if (cs != contentsSize()) - setContentsSize(cs); -} - -void QDeclarativeWebView::geometryChanged(const QRectF &newGeometry, - const QRectF &oldGeometry) -{ - if (newGeometry.size() != oldGeometry.size()) - expandToWebPage(); - QDeclarativePaintedItem::geometryChanged(newGeometry, oldGeometry); -} - -void QDeclarativeWebView::paintPage(const QRect& r) -{ - dirtyCache(r); - update(); -} - -/*! - \qmlproperty list WebView::javaScriptWindowObjects - - This property is a list of object that are available from within - the webview's JavaScript context. - - The \a object will be inserted as a child of the frame's window - object, under the name given by the attached property \c WebView.windowObjectName. - - \qml - WebView { - javaScriptWindowObjects: Object { - WebView.windowObjectName: "coordinates" - } - } - \endqml - - Properties of the object will be exposed as JavaScript properties and slots as - JavaScript methods. - - If Javascript is not enabled for this page, then this property does nothing. -*/ -QDeclarativeListProperty QDeclarativeWebView::javaScriptWindowObjects() -{ - Q_D(QDeclarativeWebView); - return QDeclarativeListProperty(this, d, &QDeclarativeWebViewPrivate::windowObjects_append); -} - -QDeclarativeWebViewAttached *QDeclarativeWebView::qmlAttachedProperties(QObject *o) -{ - return new QDeclarativeWebViewAttached(o); -} - -void QDeclarativeWebViewPrivate::updateWindowObjects() -{ - Q_Q(QDeclarativeWebView); - if (!q->isComponentComplete() || !page) - return; - - for (int ii = 0; ii < windowObjects.count(); ++ii) { - QObject *object = windowObjects.at(ii); - QDeclarativeWebViewAttached *attached = static_cast(qmlAttachedPropertiesObject(object)); - if (attached && !attached->windowObjectName().isEmpty()) { - page->mainFrame()->addToJavaScriptWindowObject(attached->windowObjectName(), object); - } - } -} - -bool QDeclarativeWebView::renderingEnabled() const -{ - Q_D(const QDeclarativeWebView); - return d->rendering; -} - -void QDeclarativeWebView::setRenderingEnabled(bool enabled) -{ - Q_D(QDeclarativeWebView); - if (d->rendering == enabled) - return; - d->rendering = enabled; - emit renderingEnabledChanged(); - - setCacheFrozen(!enabled); - if (enabled) - clearCache(); -} - - -void QDeclarativeWebView::drawContents(QPainter *p, const QRect &r) -{ - Q_D(QDeclarativeWebView); - if (d->rendering) - page()->mainFrame()->render(p,r); -} - -QMouseEvent *QDeclarativeWebView::sceneMouseEventToMouseEvent(QGraphicsSceneMouseEvent *e) -{ - QEvent::Type t; - switch(e->type()) { - default: - case QEvent::GraphicsSceneMousePress: - t = QEvent::MouseButtonPress; - break; - case QEvent::GraphicsSceneMouseRelease: - t = QEvent::MouseButtonRelease; - break; - case QEvent::GraphicsSceneMouseMove: - t = QEvent::MouseMove; - break; - case QGraphicsSceneEvent::GraphicsSceneMouseDoubleClick: - t = QEvent::MouseButtonDblClick; - break; - } - - QMouseEvent *me = new QMouseEvent(t, (e->pos()/contentsScale()).toPoint(), e->button(), e->buttons(), 0); - return me; -} - -QMouseEvent *QDeclarativeWebView::sceneHoverMoveEventToMouseEvent(QGraphicsSceneHoverEvent *e) -{ - QEvent::Type t = QEvent::MouseMove; - - QMouseEvent *me = new QMouseEvent(t, (e->pos()/contentsScale()).toPoint(), Qt::NoButton, Qt::NoButton, 0); - - return me; -} - - -/*! - \qmlsignal WebView::onDoubleClick(clickx,clicky) - - The WebView does not pass double-click events to the web engine, but rather - emits this signals. -*/ - -void QDeclarativeWebView::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) -{ - QMouseEvent *me = sceneMouseEventToMouseEvent(event); - emit doubleClick(me->x(),me->y()); - delete me; -} - -/*! - \qmlmethod bool WebView::heuristicZoom(clickX,clickY,maxzoom) - - Finds a zoom that: - \list - \i shows a whole item - \i includes (\a clickX, \a clickY) - \i fits into the preferredWidth and preferredHeight - \i zooms by no more than \a maxzoom - \i is more than 10% above the current zoom - \endlist - - If such a zoom exists, emits zoomTo(zoom,centerX,centerY) and returns true; otherwise, - no signal is emitted and returns false. -*/ -bool QDeclarativeWebView::heuristicZoom(int clickX, int clickY, qreal maxzoom) -{ - Q_D(QDeclarativeWebView); - if (contentsScale() >= maxzoom/zoomFactor()) - return false; - qreal ozf = contentsScale(); - QRect showarea = elementAreaAt(clickX, clickY, d->preferredwidth/maxzoom, d->preferredheight/maxzoom); - qreal z = qMin(qreal(d->preferredwidth)/showarea.width(),qreal(d->preferredheight)/showarea.height()); - if (z > maxzoom/zoomFactor()) - z = maxzoom/zoomFactor(); - if (z/ozf > 1.2) { - QRectF r(showarea.left()*z, showarea.top()*z, showarea.width()*z, showarea.height()*z); - emit zoomTo(z,r.x()+r.width()/2, r.y()+r.height()/2); - return true; - } else { - return false; - } -} - -/*! - \qmlproperty int WebView::pressGrabTime - - The number of milliseconds the user must press before the WebView - starts passing move events through to the web engine (rather than - letting other QML elements such as a Flickable take them). - - Defaults to 400ms. Set to 0 to always grab and pass move events to - the web engine. -*/ -int QDeclarativeWebView::pressGrabTime() const -{ - Q_D(const QDeclarativeWebView); - return d->pressTime; -} - -void QDeclarativeWebView::setPressGrabTime(int ms) -{ - Q_D(QDeclarativeWebView); - if (d->pressTime == ms) - return; - d->pressTime = ms; - emit pressGrabTimeChanged(); -} - -void QDeclarativeWebView::mousePressEvent(QGraphicsSceneMouseEvent *event) -{ - Q_D(QDeclarativeWebView); - - setFocus (true); - QMouseEvent *me = sceneMouseEventToMouseEvent(event); - - d->pressPoint = me->pos(); - if (d->pressTime) { - d->pressTimer.start(d->pressTime,this); - setKeepMouseGrab(false); - } else { - grabMouse(); - setKeepMouseGrab(true); - } - - page()->event(me); - event->setAccepted( -/* - It is not correct to send the press event upwards, if it is not accepted by WebKit - e.g. push button does not work, if done so as QGraphicsScene will not send the release event at all to WebKit - Might be a bug in WebKit, though - */ -#if 1 //QT_VERSION <= 0x040500 // XXX see bug 230835 - true -#else - me->isAccepted() -#endif - ); - delete me; - if (!event->isAccepted()) { - QDeclarativePaintedItem::mousePressEvent(event); - } -} - -void QDeclarativeWebView::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) -{ - Q_D(QDeclarativeWebView); - - QMouseEvent *me = sceneMouseEventToMouseEvent(event); - page()->event(me); - d->pressTimer.stop(); - event->setAccepted( -/* - It is not correct to send the press event upwards, if it is not accepted by WebKit - e.g. push button does not work, if done so as QGraphicsScene will not send all the events to WebKit - */ -#if 1 //QT_VERSION <= 0x040500 // XXX see bug 230835 - true -#else - me->isAccepted() -#endif - ); - delete me; - if (!event->isAccepted()) { - QDeclarativePaintedItem::mouseReleaseEvent(event); - } - setKeepMouseGrab(false); - ungrabMouse(); -} - -void QDeclarativeWebView::timerEvent(QTimerEvent *event) -{ - Q_D(QDeclarativeWebView); - if (event->timerId() == d->pressTimer.timerId()) { - d->pressTimer.stop(); - grabMouse(); - setKeepMouseGrab(true); - } -} - -void QDeclarativeWebView::mouseMoveEvent(QGraphicsSceneMouseEvent *event) -{ - Q_D(QDeclarativeWebView); - - QMouseEvent *me = sceneMouseEventToMouseEvent(event); - if (d->pressTimer.isActive()) { - if ((me->pos() - d->pressPoint).manhattanLength() > QApplication::startDragDistance()) { - d->pressTimer.stop(); - } - } - if (keepMouseGrab()) { - page()->event(me); - event->setAccepted( -/* - It is not correct to send the press event upwards, if it is not accepted by WebKit - e.g. push button does not work, if done so as QGraphicsScene will not send the release event at all to WebKit - Might be a bug in WebKit, though - */ -#if 1 // QT_VERSION <= 0x040500 // XXX see bug 230835 - true -#else - me->isAccepted() -#endif - ); - } - delete me; - if (!event->isAccepted()) - QDeclarativePaintedItem::mouseMoveEvent(event); - -} -void QDeclarativeWebView::hoverMoveEvent (QGraphicsSceneHoverEvent * event) -{ - QMouseEvent *me = sceneHoverMoveEventToMouseEvent(event); - page()->event(me); - event->setAccepted( -#if QT_VERSION <= 0x040500 // XXX see bug 230835 - true -#else - me->isAccepted() -#endif - ); - delete me; - if (!event->isAccepted()) - QDeclarativePaintedItem::hoverMoveEvent(event); -} - -void QDeclarativeWebView::keyPressEvent(QKeyEvent* event) -{ - page()->event(event); - if (!event->isAccepted()) - QDeclarativePaintedItem::keyPressEvent(event); -} - -void QDeclarativeWebView::keyReleaseEvent(QKeyEvent* event) -{ - page()->event(event); - if (!event->isAccepted()) - QDeclarativePaintedItem::keyReleaseEvent(event); -} - -bool QDeclarativeWebView::sceneEvent(QEvent *event) -{ - if (event->type() == QEvent::KeyPress) { - QKeyEvent *k = static_cast(event); - if (k->key() == Qt::Key_Tab || k->key() == Qt::Key_Backtab) { - if (!(k->modifiers() & (Qt::ControlModifier | Qt::AltModifier))) { //### Add MetaModifier? - page()->event(event); - if (event->isAccepted()) - return true; - } - } - } - return QDeclarativePaintedItem::sceneEvent(event); -} - - -/*! - \qmlproperty action WebView::back - This property holds the action for causing the previous URL in the history to be displayed. -*/ -QAction *QDeclarativeWebView::backAction() const -{ - return page()->action(QWebPage::Back); -} - -/*! - \qmlproperty action WebView::forward - This property holds the action for causing the next URL in the history to be displayed. -*/ -QAction *QDeclarativeWebView::forwardAction() const -{ - return page()->action(QWebPage::Forward); -} - -/*! - \qmlproperty action WebView::reload - This property holds the action for reloading with the current URL -*/ -QAction *QDeclarativeWebView::reloadAction() const -{ - return page()->action(QWebPage::Reload); -} - -/*! - \qmlproperty action WebView::stop - This property holds the action for stopping loading with the current URL -*/ -QAction *QDeclarativeWebView::stopAction() const -{ - return page()->action(QWebPage::Stop); -} - -/*! - \qmlproperty real WebView::title - This property holds the title of the web page currently viewed - - By default, this property contains an empty string. -*/ -QString QDeclarativeWebView::title() const -{ - return page()->mainFrame()->title(); -} - - - -/*! - \qmlproperty pixmap WebView::icon - This property holds the icon associated with the web page currently viewed -*/ -QPixmap QDeclarativeWebView::icon() const -{ - return page()->mainFrame()->icon().pixmap(QSize(256,256)); -} - - -/*! - \qmlproperty real WebView::zoomFactor - This property holds the multiplier used to scale the contents of a Web page. -*/ -void QDeclarativeWebView::setZoomFactor(qreal factor) -{ - Q_D(QDeclarativeWebView); - if (factor == page()->mainFrame()->zoomFactor()) - return; - - page()->mainFrame()->setZoomFactor(factor); - page()->setViewportSize(QSize( - d->preferredwidth>0 ? d->preferredwidth*factor : width()*factor, - d->preferredheight>0 ? d->preferredheight*factor : height()*factor)); - expandToWebPage(); - - emit zoomFactorChanged(); -} - -qreal QDeclarativeWebView::zoomFactor() const -{ - return page()->mainFrame()->zoomFactor(); -} - -/*! - \qmlproperty string WebView::statusText - - This property is the current status suggested by the current web page. In a web browser, - such status is often shown in some kind of status bar. -*/ -void QDeclarativeWebView::setStatusText(const QString& s) -{ - Q_D(QDeclarativeWebView); - d->statusText = s; - emit statusTextChanged(); -} - -void QDeclarativeWebView::windowObjectCleared() -{ - Q_D(QDeclarativeWebView); - d->updateWindowObjects(); -} - -QString QDeclarativeWebView::statusText() const -{ - Q_D(const QDeclarativeWebView); - return d->statusText; -} - -QWebPage *QDeclarativeWebView::page() const -{ - Q_D(const QDeclarativeWebView); - - if (!d->page) { - QDeclarativeWebView *self = const_cast(this); - QWebPage *wp = new QDeclarativeWebPage(self); - - // QML items don't default to having a background, - // even though most we pages will set one anyway. - QPalette pal = QApplication::palette(); - pal.setBrush(QPalette::Base, QColor::fromRgbF(0, 0, 0, 0)); - wp->setPalette(pal); - - wp->setNetworkAccessManager(qmlEngine(this)->networkAccessManager()); - - self->setPage(wp); - - return wp; - } - - return d->page; -} - - -// The QObject interface to settings(). -/*! - \qmlproperty string WebView::settings.standardFontFamily - \qmlproperty string WebView::settings.fixedFontFamily - \qmlproperty string WebView::settings.serifFontFamily - \qmlproperty string WebView::settings.sansSerifFontFamily - \qmlproperty string WebView::settings.cursiveFontFamily - \qmlproperty string WebView::settings.fantasyFontFamily - - \qmlproperty int WebView::settings.minimumFontSize - \qmlproperty int WebView::settings.minimumLogicalFontSize - \qmlproperty int WebView::settings.defaultFontSize - \qmlproperty int WebView::settings.defaultFixedFontSize - - \qmlproperty bool WebView::settings.autoLoadImages - \qmlproperty bool WebView::settings.javascriptEnabled - \qmlproperty bool WebView::settings.javaEnabled - \qmlproperty bool WebView::settings.pluginsEnabled - \qmlproperty bool WebView::settings.privateBrowsingEnabled - \qmlproperty bool WebView::settings.javascriptCanOpenWindows - \qmlproperty bool WebView::settings.javascriptCanAccessClipboard - \qmlproperty bool WebView::settings.developerExtrasEnabled - \qmlproperty bool WebView::settings.linksIncludedInFocusChain - \qmlproperty bool WebView::settings.zoomTextOnly - \qmlproperty bool WebView::settings.printElementBackgrounds - \qmlproperty bool WebView::settings.offlineStorageDatabaseEnabled - \qmlproperty bool WebView::settings.offlineWebApplicationCacheEnabled - \qmlproperty bool WebView::settings.localStorageDatabaseEnabled - \qmlproperty bool WebView::settings.localContentCanAccessRemoteUrls - - These properties give access to the settings controlling the web view. - - See QWebSettings for details of these properties. - - \qml - WebView { - settings.pluginsEnabled: true - settings.standardFontFamily: "Arial" - ... - } - \endqml -*/ -QObject *QDeclarativeWebView::settingsObject() const -{ - Q_D(const QDeclarativeWebView); - d->settings.s = page()->settings(); - return &d->settings; -} - -void QDeclarativeWebView::setPage(QWebPage *page) -{ - Q_D(QDeclarativeWebView); - if (d->page == page) - return; - if (d->page) { - if (d->page->parent() == this) { - delete d->page; - } else { - d->page->disconnect(this); - } - } - d->page = page; - d->page->setViewportSize(QSize( - d->preferredwidth>0 ? d->preferredwidth : width(), - d->preferredheight>0 ? d->preferredheight : height())); - d->page->mainFrame()->setScrollBarPolicy(Qt::Horizontal,Qt::ScrollBarAlwaysOff); - d->page->mainFrame()->setScrollBarPolicy(Qt::Vertical,Qt::ScrollBarAlwaysOff); - connect(d->page,SIGNAL(repaintRequested(QRect)),this,SLOT(paintPage(QRect))); - connect(d->page->mainFrame(),SIGNAL(urlChanged(QUrl)),this,SLOT(pageUrlChanged())); - connect(d->page->mainFrame(), SIGNAL(titleChanged(QString)), this, SIGNAL(titleChanged(QString))); - connect(d->page->mainFrame(), SIGNAL(titleChanged(QString)), this, SIGNAL(iconChanged())); - connect(d->page->mainFrame(), SIGNAL(iconChanged()), this, SIGNAL(iconChanged())); - connect(d->page->mainFrame(), SIGNAL(contentsSizeChanged(QSize)), this, SLOT(noteContentsSizeChanged(QSize))); - connect(d->page->mainFrame(), SIGNAL(initialLayoutCompleted()), this, SLOT(initialLayout())); - - connect(d->page,SIGNAL(loadStarted()),this,SLOT(doLoadStarted())); - connect(d->page,SIGNAL(loadProgress(int)),this,SLOT(doLoadProgress(int))); - connect(d->page,SIGNAL(loadFinished(bool)),this,SLOT(doLoadFinished(bool))); - connect(d->page,SIGNAL(statusBarMessage(QString)),this,SLOT(setStatusText(QString))); - - connect(d->page->mainFrame(),SIGNAL(javaScriptWindowObjectCleared()),this,SLOT(windowObjectCleared())); -} - -/*! - \qmlsignal WebView::onLoadStarted() - - This handler is called when the web engine begins loading - a page. Later, WebView::onLoadFinished() or WebView::onLoadFailed() - will be emitted. -*/ - -/*! - \qmlsignal WebView::onLoadFinished() - - This handler is called when the web engine \e successfully - finishes loading a page, including any component content - (WebView::onLoadFailed() will be emitted otherwise). - - \sa progress -*/ - -/*! - \qmlsignal WebView::onLoadFailed() - - This handler is called when the web engine fails loading - a page or any component content - (WebView::onLoadFinished() will be emitted on success). -*/ - -void QDeclarativeWebView::load(const QNetworkRequest &request, - QNetworkAccessManager::Operation operation, - const QByteArray &body) -{ - page()->mainFrame()->load(request, operation, body); -} - -QString QDeclarativeWebView::html() const -{ - return page()->mainFrame()->toHtml(); -} - -/*! - \qmlproperty string WebView::html - This property holds HTML text set directly - - The html property can be set as a string. - - \qml - WebView { - html: "

This is HTML." - } - \endqml -*/ -void QDeclarativeWebView::setHtml(const QString &html, const QUrl &baseUrl) -{ - Q_D(QDeclarativeWebView); - page()->setViewportSize(QSize( - d->preferredwidth>0 ? d->preferredwidth : width(), - d->preferredheight>0 ? d->preferredheight : height())); - if (isComponentComplete()) - page()->mainFrame()->setHtml(html, baseUrl); - else { - d->pending = d->PendingHtml; - d->pending_url = baseUrl; - d->pending_string = html; - } - emit htmlChanged(); -} - -void QDeclarativeWebView::setContent(const QByteArray &data, const QString &mimeType, const QUrl &baseUrl) -{ - Q_D(QDeclarativeWebView); - page()->setViewportSize(QSize( - d->preferredwidth>0 ? d->preferredwidth : width(), - d->preferredheight>0 ? d->preferredheight : height())); - - if (isComponentComplete()) - page()->mainFrame()->setContent(data,mimeType,qmlContext(this)->resolvedUrl(baseUrl)); - else { - d->pending = d->PendingContent; - d->pending_url = baseUrl; - d->pending_string = mimeType; - d->pending_data = data; - } -} - -QWebHistory *QDeclarativeWebView::history() const -{ - return page()->history(); -} - -QWebSettings *QDeclarativeWebView::settings() const -{ - return page()->settings(); -} - -QDeclarativeWebView *QDeclarativeWebView::createWindow(QWebPage::WebWindowType type) -{ - Q_D(QDeclarativeWebView); - switch (type) { - case QWebPage::WebBrowserWindow: { - if (!d->newWindowComponent && d->newWindowParent) - qWarning("WebView::newWindowComponent not set - WebView::newWindowParent ignored"); - else if (d->newWindowComponent && !d->newWindowParent) - qWarning("WebView::newWindowParent not set - WebView::newWindowComponent ignored"); - else if (d->newWindowComponent && d->newWindowParent) { - QDeclarativeWebView *webview = 0; - QDeclarativeContext *windowContext = new QDeclarativeContext(qmlContext(this)); - - QObject *nobj = d->newWindowComponent->create(windowContext); - if (nobj) { - windowContext->setParent(nobj); - QDeclarativeItem *item = qobject_cast(nobj); - if (!item) { - delete nobj; - } else { - webview = item->findChild(); - if (!webview) { - delete item; - } else { - nobj->setParent(d->newWindowParent); - static_cast(item)->setParentItem(d->newWindowParent); - } - } - } else { - delete windowContext; - } - - return webview; - } - } - break; - case QWebPage::WebModalDialog: { - // Not supported - } - } - return 0; -} - -/*! - \qmlproperty component WebView::newWindowComponent - - This property holds the component to use for new windows. - The component must have a WebView somewhere in its structure. - - When the web engine requests a new window, it will be an instance of - this component. - - The parent of the new window is set by newWindowParent. It must be set. -*/ -QDeclarativeComponent *QDeclarativeWebView::newWindowComponent() const -{ - Q_D(const QDeclarativeWebView); - return d->newWindowComponent; -} - -void QDeclarativeWebView::setNewWindowComponent(QDeclarativeComponent *newWindow) -{ - Q_D(QDeclarativeWebView); - if (newWindow == d->newWindowComponent) - return; - d->newWindowComponent = newWindow; - emit newWindowComponentChanged(); -} - - -/*! - \qmlproperty item WebView::newWindowParent - - The parent item for new windows. - - \sa newWindowComponent -*/ -QDeclarativeItem *QDeclarativeWebView::newWindowParent() const -{ - Q_D(const QDeclarativeWebView); - return d->newWindowParent; -} - -void QDeclarativeWebView::setNewWindowParent(QDeclarativeItem *parent) -{ - Q_D(QDeclarativeWebView); - if (parent == d->newWindowParent) - return; - if (d->newWindowParent && parent) { - QList children = d->newWindowParent->childItems(); - for (int i = 0; i < children.count(); ++i) { - children.at(i)->setParentItem(parent); - } - } - d->newWindowParent = parent; - emit newWindowParentChanged(); -} - -/*! - Returns the area of the largest element at position (\a x,\a y) that is no larger - than \a maxwidth by \a maxheight pixels. - - May return an area larger in the case when no smaller element is at the position. -*/ -QRect QDeclarativeWebView::elementAreaAt(int x, int y, int maxwidth, int maxheight) const -{ - QWebHitTestResult hit = page()->mainFrame()->hitTestContent(QPoint(x,y)); - QRect rv = hit.boundingRect(); - QWebElement element = hit.enclosingBlockElement(); - if (maxwidth<=0) maxwidth = INT_MAX; - if (maxheight<=0) maxheight = INT_MAX; - while (!element.parent().isNull() && element.geometry().width() <= maxwidth && element.geometry().height() <= maxheight) { - rv = element.geometry(); - element = element.parent(); - } - return rv; -} - -/*! - \internal - \class QDeclarativeWebPage - \brief The QDeclarativeWebPage class is a QWebPage that can create QML plugins. - - \sa QDeclarativeWebView -*/ -QDeclarativeWebPage::QDeclarativeWebPage(QDeclarativeWebView *parent) : - QWebPage(parent) -{ -} - -QDeclarativeWebPage::~QDeclarativeWebPage() -{ -} - -void QDeclarativeWebPage::javaScriptConsoleMessage(const QString& message, int lineNumber, const QString& sourceID) -{ - qWarning() << sourceID << ':' << lineNumber << ':' << message; -} - -QString QDeclarativeWebPage::chooseFile(QWebFrame *originatingFrame, const QString& oldFile) -{ - // Not supported (it's modal) - Q_UNUSED(originatingFrame) - Q_UNUSED(oldFile) - return oldFile; -} - -void QDeclarativeWebPage::javaScriptAlert(QWebFrame *originatingFrame, const QString& msg) -{ - Q_UNUSED(originatingFrame) - emit viewItem()->alert(msg); -} - -bool QDeclarativeWebPage::javaScriptConfirm(QWebFrame *originatingFrame, const QString& msg) -{ - // Not supported (it's modal) - Q_UNUSED(originatingFrame) - Q_UNUSED(msg) - return false; -} - -bool QDeclarativeWebPage::javaScriptPrompt(QWebFrame *originatingFrame, const QString& msg, const QString& defaultValue, QString* result) -{ - // Not supported (it's modal) - Q_UNUSED(originatingFrame) - Q_UNUSED(msg) - Q_UNUSED(defaultValue) - Q_UNUSED(result) - return false; -} - - -/* - Qt WebKit does not understand non-QWidget plugins, so dummy widgets - are created, parented to a single dummy tool window. - - The requirements for QML object plugins are input to the Qt WebKit - non-QWidget plugin support, which will obsolete this kludge. -*/ -class QWidget_Dummy_Plugin : public QWidget -{ - Q_OBJECT -public: - static QWidget *dummy_shared_parent() - { - static QWidget *dsp = 0; - if (!dsp) { - dsp = new QWidget(0,Qt::Tool); - dsp->setGeometry(-10000,-10000,0,0); - dsp->show(); - } - return dsp; - } - QWidget_Dummy_Plugin(const QUrl& url, QDeclarativeWebView *view, const QStringList ¶mNames, const QStringList ¶mValues) : - QWidget(dummy_shared_parent()), - propertyNames(paramNames), - propertyValues(paramValues), - webview(view) - { - QDeclarativeEngine *engine = qmlEngine(webview); - component = new QDeclarativeComponent(engine, url, this); - item = 0; - if (component->isLoading()) - connect(component, SIGNAL(statusChanged(QDeclarativeComponent::Status)), this, SLOT(qmlLoaded())); - else - qmlLoaded(); - } - -public Q_SLOTS: - void qmlLoaded() - { - if (component->isError()) { - // ### Could instead give these errors to the WebView to handle. - qWarning() << component->errors(); - return; - } - item = qobject_cast(component->create(qmlContext(webview))); - item->setParent(webview); - QString jsObjName; - for (int i=0; isetProperty(propertyNames[i].toUtf8(),propertyValues[i]); - if (propertyNames[i] == QLatin1String("objectname")) - jsObjName = propertyValues[i]; - } - } - if (!jsObjName.isNull()) { - QWebFrame *f = webview->page()->mainFrame(); - f->addToJavaScriptWindowObject(jsObjName, item); - } - resizeEvent(0); - delete component; - component = 0; - } - void resizeEvent(QResizeEvent*) - { - if (item) { - item->setX(x()); - item->setY(y()); - item->setWidth(width()); - item->setHeight(height()); - } - } - -private: - QDeclarativeComponent *component; - QDeclarativeItem *item; - QStringList propertyNames, propertyValues; - QDeclarativeWebView *webview; -}; - -QDeclarativeWebView *QDeclarativeWebPage::viewItem() -{ - return static_cast(parent()); -} - -QObject *QDeclarativeWebPage::createPlugin(const QString &, const QUrl &url, const QStringList ¶mNames, const QStringList ¶mValues) -{ - QUrl comp = qmlContext(viewItem())->resolvedUrl(url); - return new QWidget_Dummy_Plugin(comp,viewItem(),paramNames,paramValues); -} - -QWebPage *QDeclarativeWebPage::createWindow(WebWindowType type) -{ - QDeclarativeWebView *newView = viewItem()->createWindow(type); - if (newView) - return newView->page(); - return 0; -} - -QT_END_NAMESPACE - -#include diff --git a/src/declarative/imports/webkit/qdeclarativewebview_p.h b/src/declarative/imports/webkit/qdeclarativewebview_p.h deleted file mode 100644 index 0bb5d29..0000000 --- a/src/declarative/imports/webkit/qdeclarativewebview_p.h +++ /dev/null @@ -1,285 +0,0 @@ -/**************************************************************************** -** -** 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 QDECLARATIVEWEBVIEW_H -#define QDECLARATIVEWEBVIEW_H - -#include - -#include -#include -#include -#include - -QT_BEGIN_HEADER - -class QWebHistory; -class QWebSettings; - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) -class QDeclarativeWebViewPrivate; -class QNetworkRequest; -class QDeclarativeWebView; - -class Q_DECLARATIVE_EXPORT QDeclarativeWebPage : public QWebPage -{ - Q_OBJECT -public: - explicit QDeclarativeWebPage(QDeclarativeWebView *parent); - ~QDeclarativeWebPage(); -protected: - QObject *createPlugin(const QString &classid, const QUrl &url, const QStringList ¶mNames, const QStringList ¶mValues); - QWebPage *createWindow(WebWindowType type); - void javaScriptConsoleMessage(const QString& message, int lineNumber, const QString& sourceID); - QString chooseFile(QWebFrame *originatingFrame, const QString& oldFile); - void javaScriptAlert(QWebFrame *originatingFrame, const QString& msg); - bool javaScriptConfirm(QWebFrame *originatingFrame, const QString& msg); - bool javaScriptPrompt(QWebFrame *originatingFrame, const QString& msg, const QString& defaultValue, QString* result); - -private: - QDeclarativeWebView *viewItem(); -}; - - -class QDeclarativeWebViewAttached; - -//### TODO: browser plugins - -class Q_DECLARATIVE_EXPORT QDeclarativeWebView : public QDeclarativePaintedItem -{ - Q_OBJECT - - Q_ENUMS(Status SelectionMode) - - Q_PROPERTY(QString title READ title NOTIFY titleChanged) - Q_PROPERTY(QPixmap icon READ icon NOTIFY iconChanged) - Q_PROPERTY(qreal zoomFactor READ zoomFactor WRITE setZoomFactor NOTIFY zoomFactorChanged) - Q_PROPERTY(QString statusText READ statusText NOTIFY statusTextChanged) - - Q_PROPERTY(QString html READ html WRITE setHtml NOTIFY htmlChanged) - - Q_PROPERTY(int pressGrabTime READ pressGrabTime WRITE setPressGrabTime NOTIFY pressGrabTimeChanged) - - Q_PROPERTY(int preferredWidth READ preferredWidth WRITE setPreferredWidth NOTIFY preferredWidthChanged) - Q_PROPERTY(int preferredHeight READ preferredHeight WRITE setPreferredHeight NOTIFY preferredHeightChanged) - Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY urlChanged) - Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged) - Q_PROPERTY(Status status READ status NOTIFY statusChanged) - - Q_PROPERTY(QAction* reload READ reloadAction CONSTANT) - Q_PROPERTY(QAction* back READ backAction CONSTANT) - Q_PROPERTY(QAction* forward READ forwardAction CONSTANT) - Q_PROPERTY(QAction* stop READ stopAction CONSTANT) - - Q_PROPERTY(QObject* settings READ settingsObject CONSTANT) - - Q_PROPERTY(QDeclarativeListProperty javaScriptWindowObjects READ javaScriptWindowObjects CONSTANT) - - Q_PROPERTY(QDeclarativeComponent* newWindowComponent READ newWindowComponent WRITE setNewWindowComponent NOTIFY newWindowComponentChanged) - Q_PROPERTY(QDeclarativeItem* newWindowParent READ newWindowParent WRITE setNewWindowParent NOTIFY newWindowParentChanged) - - Q_PROPERTY(bool renderingEnabled READ renderingEnabled WRITE setRenderingEnabled NOTIFY renderingEnabledChanged) - -public: - QDeclarativeWebView(QDeclarativeItem *parent=0); - ~QDeclarativeWebView(); - - QUrl url() const; - void setUrl(const QUrl &); - - QString title() const; - - QPixmap icon() const; - - qreal zoomFactor() const; - void setZoomFactor(qreal); - Q_INVOKABLE bool heuristicZoom(int clickX, int clickY, qreal maxzoom); - QRect elementAreaAt(int x, int y, int minwidth, int minheight) const; - - int pressGrabTime() const; - void setPressGrabTime(int); - - int preferredWidth() const; - void setPreferredWidth(int); - int preferredHeight() const; - void setPreferredHeight(int); - - enum Status { Null, Ready, Loading, Error }; - Status status() const; - qreal progress() const; - QString statusText() const; - - QAction *reloadAction() const; - QAction *backAction() const; - QAction *forwardAction() const; - QAction *stopAction() const; - - QWebPage *page() const; - void setPage(QWebPage *page); - - void load(const QNetworkRequest &request, - QNetworkAccessManager::Operation operation = QNetworkAccessManager::GetOperation, - const QByteArray &body = QByteArray()); - - QString html() const; - - void setHtml(const QString &html, const QUrl &baseUrl = QUrl()); - void setContent(const QByteArray &data, const QString &mimeType = QString(), const QUrl &baseUrl = QUrl()); - - QWebHistory *history() const; - QWebSettings *settings() const; - QObject *settingsObject() const; - - bool renderingEnabled() const; - void setRenderingEnabled(bool); - - QDeclarativeListProperty javaScriptWindowObjects(); - - static QDeclarativeWebViewAttached *qmlAttachedProperties(QObject *); - - QDeclarativeComponent *newWindowComponent() const; - void setNewWindowComponent(QDeclarativeComponent *newWindow); - QDeclarativeItem *newWindowParent() const; - void setNewWindowParent(QDeclarativeItem *newWindow); - -Q_SIGNALS: - void preferredWidthChanged(); - void preferredHeightChanged(); - void urlChanged(); - void progressChanged(); - void statusChanged(Status); - void titleChanged(const QString&); - void iconChanged(); - void statusTextChanged(); - void htmlChanged(); - void pressGrabTimeChanged(); - void zoomFactorChanged(); - void newWindowComponentChanged(); - void newWindowParentChanged(); - void renderingEnabledChanged(); - - void loadStarted(); - void loadFinished(); - void loadFailed(); - - void doubleClick(int clickX, int clickY); - - void zoomTo(qreal zoom, int centerX, int centerY); - - void alert(const QString& message); - -public Q_SLOTS: - QVariant evaluateJavaScript(const QString&); - -private Q_SLOTS: - void expandToWebPage(); - void paintPage(const QRect&); - void doLoadStarted(); - void doLoadProgress(int p); - void doLoadFinished(bool ok); - void setStatusText(const QString&); - void windowObjectCleared(); - void pageUrlChanged(); - void noteContentsSizeChanged(const QSize&); - void initialLayout(); - -protected: - void drawContents(QPainter *, const QRect &); - - void mousePressEvent(QGraphicsSceneMouseEvent *event); - void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); - void mouseMoveEvent(QGraphicsSceneMouseEvent *event); - void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); - void timerEvent(QTimerEvent *event); - void hoverMoveEvent (QGraphicsSceneHoverEvent * event); - void keyPressEvent(QKeyEvent* event); - void keyReleaseEvent(QKeyEvent* event); - virtual void geometryChanged(const QRectF &newGeometry, - const QRectF &oldGeometry); - virtual void focusChanged(bool); - virtual bool sceneEvent(QEvent *event); - QDeclarativeWebView *createWindow(QWebPage::WebWindowType type); - -private: - void init(); - virtual void componentComplete(); - Q_DISABLE_COPY(QDeclarativeWebView) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarativeWebView) - QMouseEvent *sceneMouseEventToMouseEvent(QGraphicsSceneMouseEvent *); - QMouseEvent *sceneHoverMoveEventToMouseEvent(QGraphicsSceneHoverEvent *); - friend class QDeclarativeWebPage; -}; - -class QDeclarativeWebViewAttached : public QObject -{ - Q_OBJECT - Q_PROPERTY(QString windowObjectName READ windowObjectName WRITE setWindowObjectName) -public: - QDeclarativeWebViewAttached(QObject *parent) - : QObject(parent) - { - } - - QString windowObjectName() const - { - return m_windowObjectName; - } - - void setWindowObjectName(const QString &n) - { - m_windowObjectName = n; - } - -private: - QString m_windowObjectName; -}; - - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QDeclarativeWebView) -QML_DECLARE_TYPEINFO(QDeclarativeWebView, QML_HAS_ATTACHED_PROPERTIES) - -QT_END_HEADER - -#endif diff --git a/src/declarative/imports/webkit/qdeclarativewebview_p_p.h b/src/declarative/imports/webkit/qdeclarativewebview_p_p.h deleted file mode 100644 index 258b472..0000000 --- a/src/declarative/imports/webkit/qdeclarativewebview_p_p.h +++ /dev/null @@ -1,151 +0,0 @@ -/**************************************************************************** -** -** 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 QDECLARATIVEWEBVIEW_P_H -#define QDECLARATIVEWEBVIEW_P_H - -#include - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QDeclarativeWebSettings : public QObject { - Q_OBJECT - - Q_PROPERTY(QString standardFontFamily READ standardFontFamily WRITE setStandardFontFamily) - Q_PROPERTY(QString fixedFontFamily READ fixedFontFamily WRITE setFixedFontFamily) - Q_PROPERTY(QString serifFontFamily READ serifFontFamily WRITE setSerifFontFamily) - Q_PROPERTY(QString sansSerifFontFamily READ sansSerifFontFamily WRITE setSansSerifFontFamily) - Q_PROPERTY(QString cursiveFontFamily READ cursiveFontFamily WRITE setCursiveFontFamily) - Q_PROPERTY(QString fantasyFontFamily READ fantasyFontFamily WRITE setFantasyFontFamily) - - Q_PROPERTY(int minimumFontSize READ minimumFontSize WRITE setMinimumFontSize) - Q_PROPERTY(int minimumLogicalFontSize READ minimumLogicalFontSize WRITE setMinimumLogicalFontSize) - Q_PROPERTY(int defaultFontSize READ defaultFontSize WRITE setDefaultFontSize) - Q_PROPERTY(int defaultFixedFontSize READ defaultFixedFontSize WRITE setDefaultFixedFontSize) - - Q_PROPERTY(bool autoLoadImages READ autoLoadImages WRITE setAutoLoadImages) - Q_PROPERTY(bool javascriptEnabled READ javascriptEnabled WRITE setJavascriptEnabled) - Q_PROPERTY(bool javaEnabled READ javaEnabled WRITE setJavaEnabled) - Q_PROPERTY(bool pluginsEnabled READ pluginsEnabled WRITE setPluginsEnabled) - Q_PROPERTY(bool privateBrowsingEnabled READ privateBrowsingEnabled WRITE setPrivateBrowsingEnabled) - Q_PROPERTY(bool javascriptCanOpenWindows READ javascriptCanOpenWindows WRITE setJavascriptCanOpenWindows) - Q_PROPERTY(bool javascriptCanAccessClipboard READ javascriptCanAccessClipboard WRITE setJavascriptCanAccessClipboard) - Q_PROPERTY(bool developerExtrasEnabled READ developerExtrasEnabled WRITE setDeveloperExtrasEnabled) - Q_PROPERTY(bool linksIncludedInFocusChain READ linksIncludedInFocusChain WRITE setLinksIncludedInFocusChain) - Q_PROPERTY(bool zoomTextOnly READ zoomTextOnly WRITE setZoomTextOnly) - Q_PROPERTY(bool printElementBackgrounds READ printElementBackgrounds WRITE setPrintElementBackgrounds) - Q_PROPERTY(bool offlineStorageDatabaseEnabled READ offlineStorageDatabaseEnabled WRITE setOfflineStorageDatabaseEnabled) - Q_PROPERTY(bool offlineWebApplicationCacheEnabled READ offlineWebApplicationCacheEnabled WRITE setOfflineWebApplicationCacheEnabled) - Q_PROPERTY(bool localStorageDatabaseEnabled READ localStorageDatabaseEnabled WRITE setLocalStorageDatabaseEnabled) - Q_PROPERTY(bool localContentCanAccessRemoteUrls READ localContentCanAccessRemoteUrls WRITE setLocalContentCanAccessRemoteUrls) - -public: - QDeclarativeWebSettings() {} - - QString standardFontFamily() const { return s->fontFamily(QWebSettings::StandardFont); } - void setStandardFontFamily(const QString& f) { s->setFontFamily(QWebSettings::StandardFont,f); } - QString fixedFontFamily() const { return s->fontFamily(QWebSettings::FixedFont); } - void setFixedFontFamily(const QString& f) { s->setFontFamily(QWebSettings::FixedFont,f); } - QString serifFontFamily() const { return s->fontFamily(QWebSettings::SerifFont); } - void setSerifFontFamily(const QString& f) { s->setFontFamily(QWebSettings::SerifFont,f); } - QString sansSerifFontFamily() const { return s->fontFamily(QWebSettings::SansSerifFont); } - void setSansSerifFontFamily(const QString& f) { s->setFontFamily(QWebSettings::SansSerifFont,f); } - QString cursiveFontFamily() const { return s->fontFamily(QWebSettings::CursiveFont); } - void setCursiveFontFamily(const QString& f) { s->setFontFamily(QWebSettings::CursiveFont,f); } - QString fantasyFontFamily() const { return s->fontFamily(QWebSettings::FantasyFont); } - void setFantasyFontFamily(const QString& f) { s->setFontFamily(QWebSettings::FantasyFont,f); } - - int minimumFontSize() const { return s->fontSize(QWebSettings::MinimumFontSize); } - void setMinimumFontSize(int size) { s->setFontSize(QWebSettings::MinimumFontSize,size); } - int minimumLogicalFontSize() const { return s->fontSize(QWebSettings::MinimumLogicalFontSize); } - void setMinimumLogicalFontSize(int size) { s->setFontSize(QWebSettings::MinimumLogicalFontSize,size); } - int defaultFontSize() const { return s->fontSize(QWebSettings::DefaultFontSize); } - void setDefaultFontSize(int size) { s->setFontSize(QWebSettings::DefaultFontSize,size); } - int defaultFixedFontSize() const { return s->fontSize(QWebSettings::DefaultFixedFontSize); } - void setDefaultFixedFontSize(int size) { s->setFontSize(QWebSettings::DefaultFixedFontSize,size); } - - bool autoLoadImages() const { return s->testAttribute(QWebSettings::AutoLoadImages); } - void setAutoLoadImages(bool on) { s->setAttribute(QWebSettings::AutoLoadImages, on); } - bool javascriptEnabled() const { return s->testAttribute(QWebSettings::JavascriptEnabled); } - void setJavascriptEnabled(bool on) { s->setAttribute(QWebSettings::JavascriptEnabled, on); } - bool javaEnabled() const { return s->testAttribute(QWebSettings::JavaEnabled); } - void setJavaEnabled(bool on) { s->setAttribute(QWebSettings::JavaEnabled, on); } - bool pluginsEnabled() const { return s->testAttribute(QWebSettings::PluginsEnabled); } - void setPluginsEnabled(bool on) { s->setAttribute(QWebSettings::PluginsEnabled, on); } - bool privateBrowsingEnabled() const { return s->testAttribute(QWebSettings::PrivateBrowsingEnabled); } - void setPrivateBrowsingEnabled(bool on) { s->setAttribute(QWebSettings::PrivateBrowsingEnabled, on); } - bool javascriptCanOpenWindows() const { return s->testAttribute(QWebSettings::JavascriptCanOpenWindows); } - void setJavascriptCanOpenWindows(bool on) { s->setAttribute(QWebSettings::JavascriptCanOpenWindows, on); } - bool javascriptCanAccessClipboard() const { return s->testAttribute(QWebSettings::JavascriptCanAccessClipboard); } - void setJavascriptCanAccessClipboard(bool on) { s->setAttribute(QWebSettings::JavascriptCanAccessClipboard, on); } - bool developerExtrasEnabled() const { return s->testAttribute(QWebSettings::DeveloperExtrasEnabled); } - void setDeveloperExtrasEnabled(bool on) { s->setAttribute(QWebSettings::DeveloperExtrasEnabled, on); } - bool linksIncludedInFocusChain() const { return s->testAttribute(QWebSettings::LinksIncludedInFocusChain); } - void setLinksIncludedInFocusChain(bool on) { s->setAttribute(QWebSettings::LinksIncludedInFocusChain, on); } - bool zoomTextOnly() const { return s->testAttribute(QWebSettings::ZoomTextOnly); } - void setZoomTextOnly(bool on) { s->setAttribute(QWebSettings::ZoomTextOnly, on); } - bool printElementBackgrounds() const { return s->testAttribute(QWebSettings::PrintElementBackgrounds); } - void setPrintElementBackgrounds(bool on) { s->setAttribute(QWebSettings::PrintElementBackgrounds, on); } - bool offlineStorageDatabaseEnabled() const { return s->testAttribute(QWebSettings::OfflineStorageDatabaseEnabled); } - void setOfflineStorageDatabaseEnabled(bool on) { s->setAttribute(QWebSettings::OfflineStorageDatabaseEnabled, on); } - bool offlineWebApplicationCacheEnabled() const { return s->testAttribute(QWebSettings::OfflineWebApplicationCacheEnabled); } - void setOfflineWebApplicationCacheEnabled(bool on) { s->setAttribute(QWebSettings::OfflineWebApplicationCacheEnabled, on); } - bool localStorageDatabaseEnabled() const { return s->testAttribute(QWebSettings::LocalStorageDatabaseEnabled); } - void setLocalStorageDatabaseEnabled(bool on) { s->setAttribute(QWebSettings::LocalStorageDatabaseEnabled, on); } - bool localContentCanAccessRemoteUrls() const { return s->testAttribute(QWebSettings::LocalContentCanAccessRemoteUrls); } - void setLocalContentCanAccessRemoteUrls(bool on) { s->setAttribute(QWebSettings::LocalContentCanAccessRemoteUrls, on); } - - QWebSettings *s; -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QDeclarativeWebSettings) - -QT_END_HEADER - -#endif diff --git a/src/declarative/imports/webkit/webkit.pro b/src/declarative/imports/webkit/webkit.pro deleted file mode 100644 index 7ad8564..0000000 --- a/src/declarative/imports/webkit/webkit.pro +++ /dev/null @@ -1,18 +0,0 @@ -TARGET = webkitqmlplugin -include(../qimportbase.pri) - -contains(QT_CONFIG, webkit) { - QT += webkit declarative - - SOURCES += qdeclarativewebview.cpp plugin.cpp - HEADERS += qdeclarativewebview_p.h - HEADERS += qdeclarativewebview_p_p.h - - QTDIR_build:DESTDIR = $$QT_BUILD_TREE/imports/org/webkit - target.path = $$[QT_INSTALL_IMPORTS]/org/webkit - - qmldir.files += $$QT_BUILD_TREE/imports/org/webkit/qmldir - qmldir.path += $$[QT_INSTALL_IMPORTS]/org/webkit - - INSTALLS += target qmldir -} diff --git a/src/declarative/imports/widgets/graphicslayouts.cpp b/src/declarative/imports/widgets/graphicslayouts.cpp deleted file mode 100644 index fc15ad2..0000000 --- a/src/declarative/imports/widgets/graphicslayouts.cpp +++ /dev/null @@ -1,260 +0,0 @@ -/**************************************************************************** -** -** 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 -#include - -QT_BEGIN_NAMESPACE - -LinearLayoutAttached::LinearLayoutAttached(QObject *parent) -: QObject(parent), _stretch(1), _alignment(Qt::AlignCenter) -{ -} - -void LinearLayoutAttached::setStretchFactor(int f) -{ - if (_stretch == f) - return; - - _stretch = f; - emit stretchChanged(reinterpret_cast(parent()), _stretch); -} - -void LinearLayoutAttached::setAlignment(Qt::Alignment a) -{ - if (_alignment == a) - return; - - _alignment = a; - emit alignmentChanged(reinterpret_cast(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()); - 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))); - //### 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); -} - -void QGraphicsLinearLayoutObject::updateStretch(QGraphicsLayoutItem *item, int stretch) -{ -QGraphicsLinearLayout::setStretchFactor(item, stretch); -} - -void QGraphicsLinearLayoutObject::updateAlignment(QGraphicsLayoutItem *item, Qt::Alignment alignment) -{ -QGraphicsLinearLayout::setAlignment(item, alignment); -} - -QHash QGraphicsLinearLayoutObject::attachedProperties; -LinearLayoutAttached *QGraphicsLinearLayoutObject::qmlAttachedProperties(QObject *obj) -{ -// ### This is not allowed - you must attach to any object -if (!qobject_cast(obj)) - return 0; -LinearLayoutAttached *rv = new LinearLayoutAttached(obj); -attachedProperties.insert(qobject_cast(obj), rv); -return rv; -} - -////////////////////////////////////////////////////////////////////////////////////////////////////// -// QGraphicsGridLayout-related classes -////////////////////////////////////////////////////////////////////////////////////////////////////// -GridLayoutAttached::GridLayoutAttached(QObject *parent) -: QObject(parent), _row(-1), _column(-1), _rowspan(1), _colspan(1), _alignment(-1) -{ -} - -void GridLayoutAttached::setRow(int r) -{ - if (_row == r) - return; - - _row = r; - //emit rowChanged(reinterpret_cast(parent()), _row); -} - -void GridLayoutAttached::setColumn(int c) -{ - if (_column == c) - return; - - _column = c; - //emit columnChanged(reinterpret_cast(parent()), _column); -} - -void GridLayoutAttached::setRowSpan(int rs) -{ - if (_rowspan == rs) - return; - - _rowspan = rs; - //emit rowSpanChanged(reinterpret_cast(parent()), _rowSpan); -} - -void GridLayoutAttached::setColumnSpan(int cs) -{ - if (_colspan == cs) - return; - - _colspan = cs; - //emit columnSpanChanged(reinterpret_cast(parent()), _columnSpan); -} - -void GridLayoutAttached::setAlignment(Qt::Alignment a) -{ - if (_alignment == a) - return; - - _alignment = a; - //emit alignmentChanged(reinterpret_cast(parent()), _alignment); -} - -QGraphicsGridLayoutObject::QGraphicsGridLayoutObject(QObject *parent) -: QObject(parent) -{ -} - -QGraphicsGridLayoutObject::~QGraphicsGridLayoutObject() -{ -} - -void QGraphicsGridLayoutObject::addWidget(QGraphicsWidget *wid) -{ -//use attached properties -if (QObject *obj = attachedProperties.value(qobject_cast(wid))) { - int row = static_cast(obj)->row(); - int column = static_cast(obj)->column(); - int rowSpan = static_cast(obj)->rowSpan(); - int columnSpan = static_cast(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; - } - addItem(item, row, column, rowSpan, columnSpan); - if (alignment != -1) - setAlignment(item,alignment); -} -} - -//### 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; //### -} - -QHash QGraphicsGridLayoutObject::attachedProperties; -GridLayoutAttached *QGraphicsGridLayoutObject::qmlAttachedProperties(QObject *obj) -{ -// ### This is not allowed - you must attach to any object -if (!qobject_cast(obj)) - return 0; -GridLayoutAttached *rv = new GridLayoutAttached(obj); -attachedProperties.insert(qobject_cast(obj), rv); -return rv; -} - -QT_END_NAMESPACE diff --git a/src/declarative/imports/widgets/graphicslayouts_p.h b/src/declarative/imports/widgets/graphicslayouts_p.h deleted file mode 100644 index f9b9ae8..0000000 --- a/src/declarative/imports/widgets/graphicslayouts_p.h +++ /dev/null @@ -1,226 +0,0 @@ -/**************************************************************************** -** -** 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 "graphicswidgets_p.h" - -#include -#include - -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 children READ children) - Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation) - Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing) - Q_CLASSINFO("DefaultProperty", "children") -public: - QGraphicsLinearLayoutObject(QObject * = 0); - ~QGraphicsLinearLayoutObject(); - - QDeclarativeListProperty children() { return QDeclarativeListProperty(this, 0, children_append, children_count, children_at, children_clear); } - - static LinearLayoutAttached *qmlAttachedProperties(QObject *); - -private Q_SLOTS: - void updateStretch(QGraphicsLayoutItem*,int); - void updateAlignment(QGraphicsLayoutItem*,Qt::Alignment); - -private: - friend class LinearLayoutAttached; - void clearChildren(); - void insertLayoutItem(int, QGraphicsLayoutItem *); - static QHash attachedProperties; - - static void children_append(QDeclarativeListProperty *prop, QGraphicsLayoutItem *item) { - static_cast(prop->object)->insertLayoutItem(-1, item); - } - - static void children_clear(QDeclarativeListProperty *prop) { - static_cast(prop->object)->clearChildren(); - } - - static int children_count(QDeclarativeListProperty *prop) { - return static_cast(prop->object)->count(); - } - - static QGraphicsLayoutItem *children_at(QDeclarativeListProperty *prop, int index) { - return static_cast(prop->object)->itemAt(index); - } -}; - -class GridLayoutAttached; -class QGraphicsGridLayoutObject : public QObject, public QGraphicsGridLayout -{ - Q_OBJECT - Q_INTERFACES(QGraphicsLayout QGraphicsLayoutItem) - - Q_PROPERTY(QDeclarativeListProperty children READ children) - Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing) - 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 children() { return QDeclarativeListProperty(this, 0, children_append, children_count, children_at, children_clear); } - - qreal spacing() const; - - static GridLayoutAttached *qmlAttachedProperties(QObject *); - -private: - friend class GraphicsLayoutAttached; - void addWidget(QGraphicsWidget *); - void clearChildren(); - void addLayoutItem(QGraphicsLayoutItem *); - static QHash attachedProperties; - - static void children_append(QDeclarativeListProperty *prop, QGraphicsLayoutItem *item) { - static_cast(prop->object)->addLayoutItem(item); - } - - static void children_clear(QDeclarativeListProperty *prop) { - static_cast(prop->object)->clearChildren(); - } - - static int children_count(QDeclarativeListProperty *prop) { - return static_cast(prop->object)->count(); - } - - static QGraphicsLayoutItem *children_at(QDeclarativeListProperty *prop, int index) { - return static_cast(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) -public: - LinearLayoutAttached(QObject *parent); - - int stretchFactor() const { return _stretch; } - void setStretchFactor(int f); - Qt::Alignment alignment() const { return _alignment; } - void setAlignment(Qt::Alignment a); - -Q_SIGNALS: - void stretchChanged(QGraphicsLayoutItem*,int); - void alignmentChanged(QGraphicsLayoutItem*,Qt::Alignment); - -private: - int _stretch; - Qt::Alignment _alignment; -}; - -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) -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); - -private: - int _row; - int _column; - int _rowspan; - int _colspan; - Qt::Alignment _alignment; -}; - -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/src/declarative/imports/widgets/graphicswidgets.cpp b/src/declarative/imports/widgets/graphicswidgets.cpp deleted file mode 100644 index 062e516..0000000 --- a/src/declarative/imports/widgets/graphicswidgets.cpp +++ /dev/null @@ -1,40 +0,0 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ diff --git a/src/declarative/imports/widgets/graphicswidgets_p.h b/src/declarative/imports/widgets/graphicswidgets_p.h deleted file mode 100644 index 2c2b707..0000000 --- a/src/declarative/imports/widgets/graphicswidgets_p.h +++ /dev/null @@ -1,68 +0,0 @@ -/**************************************************************************** -** -** 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 GRAPHICSWIDGETS_H -#define GRAPHICSWIDGETS_H - -#include - -#include -#include -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QGraphicsView) -QML_DECLARE_TYPE_HASMETATYPE(QGraphicsScene) -QML_DECLARE_TYPE(QGraphicsWidget) -QML_DECLARE_TYPE(QGraphicsObject) -QML_DECLARE_INTERFACE_HASMETATYPE(QGraphicsItem) - -QT_END_HEADER - -#endif // GRAPHICSWIDGETS_H diff --git a/src/declarative/imports/widgets/widgets.cpp b/src/declarative/imports/widgets/widgets.cpp deleted file mode 100644 index ec21cc4..0000000 --- a/src/declarative/imports/widgets/widgets.cpp +++ /dev/null @@ -1,138 +0,0 @@ -/**************************************************************************** -** -** 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 -#include - -#include "graphicslayouts_p.h" -#include "graphicswidgets_p.h" - -QT_BEGIN_NAMESPACE - -class QGraphicsViewDeclarativeUI : public QObject -{ - Q_OBJECT - - Q_PROPERTY(QGraphicsScene *scene READ scene WRITE setScene) - Q_CLASSINFO("DefaultProperty", "scene") -public: - QGraphicsViewDeclarativeUI(QObject *other) : QObject(other) {} - - QGraphicsScene *scene() const { return static_cast(parent())->scene(); } - void setScene(QGraphicsScene *scene) - { - static_cast(parent())->setScene(scene); - } -}; - -class QGraphicsSceneDeclarativeUI : public QObject -{ - Q_OBJECT - - Q_PROPERTY(QDeclarativeListProperty children READ children) - Q_CLASSINFO("DefaultProperty", "children") -public: - QGraphicsSceneDeclarativeUI(QObject *other) : QObject(other) {} - - QDeclarativeListProperty children() { return QDeclarativeListProperty(this->parent(), 0, children_append); } - -private: - static void children_append(QDeclarativeListProperty *prop, QObject *o) { - if (QGraphicsObject *go = qobject_cast(o)) - static_cast(prop->object)->addItem(go); - } -}; - -class QGraphicsWidgetDeclarativeUI : public QObject -{ - Q_OBJECT - - Q_PROPERTY(QDeclarativeListProperty children READ children) - Q_PROPERTY(QGraphicsLayout *layout READ layout WRITE setLayout) - Q_CLASSINFO("DefaultProperty", "children") -public: - QGraphicsWidgetDeclarativeUI(QObject *other) : QObject(other) {} - - QDeclarativeListProperty children() { return QDeclarativeListProperty(this, 0, children_append); } - - QGraphicsLayout *layout() const { return static_cast(parent())->layout(); } - void setLayout(QGraphicsLayout *lo) - { - static_cast(parent())->setLayout(lo); - } - -private: - void setItemParent(QGraphicsItem *wid) - { - wid->setParentItem(static_cast(parent())); - } - - static void children_append(QDeclarativeListProperty *prop, QGraphicsItem *i) { - static_cast(prop->object)->setItemParent(i); - } -}; - -class QWidgetsQmlModule : public QDeclarativeExtensionPlugin -{ - Q_OBJECT -public: - virtual void registerTypes(const char *uri) - { - Q_ASSERT(QLatin1String(uri) == QLatin1String("Qt.widgets")); - - QML_REGISTER_INTERFACE(QGraphicsLayoutItem); - QML_REGISTER_INTERFACE(QGraphicsLayout); - qmlRegisterType(uri,4,6,"QGraphicsLinearLayoutStretchItem"); - qmlRegisterType(uri,4,6,"QGraphicsLinearLayout"); - qmlRegisterType(uri,4,6,"QGraphicsGridLayout"); - qmlRegisterExtendedType(uri,4,6,"QGraphicsView"); - qmlRegisterExtendedType(uri,4,6,"QGraphicsScene"); - qmlRegisterExtendedType(uri,4,6,"QGraphicsWidget"); - QML_REGISTER_INTERFACE(QGraphicsItem); - } -}; - -QT_END_NAMESPACE - -#include "widgets.moc" - -Q_EXPORT_PLUGIN2(qtwidgetsqmlmodule, QT_PREPEND_NAMESPACE(QWidgetsQmlModule)); - diff --git a/src/declarative/imports/widgets/widgets.pro b/src/declarative/imports/widgets/widgets.pro deleted file mode 100644 index 230d398..0000000 --- a/src/declarative/imports/widgets/widgets.pro +++ /dev/null @@ -1,20 +0,0 @@ -TARGET = widgets -include(../qimportbase.pri) - -QT += declarative - -SOURCES += \ - graphicslayouts.cpp \ - widgets.cpp - -HEADERS += \ - graphicswidgets_p.h \ - graphicslayouts_p.h - -QTDIR_build:DESTDIR = $$QT_BUILD_TREE/imports/Qt/widgets -target.path = $$[QT_INSTALL_IMPORTS]/Qt/widgets - -qmldir.files += $$QT_BUILD_TREE/imports/Qt/widgets/qmldir -qmldir.path += $$[QT_INSTALL_IMPORTS]/Qt/widgets - -INSTALLS += target qmldir diff --git a/src/declarative/libdeclarative.pro b/src/declarative/libdeclarative.pro deleted file mode 100644 index 4287e25..0000000 --- a/src/declarative/libdeclarative.pro +++ /dev/null @@ -1,29 +0,0 @@ -TARGET = QtDeclarative -QPRO_PWD = $$PWD -QT = core gui xml script network -contains(QT_CONFIG, svg): QT += svg -contains(QT_CONFIG, opengl): QT += opengl -DEFINES += QT_BUILD_DECLARATIVE_LIB QT_NO_URL_CAST_FROM_STRING -win32-msvc*|win32-icc:QMAKE_LFLAGS += /BASE:0x66000000 -solaris-cc*:QMAKE_CXXFLAGS_RELEASE -= -O2 - -unix:QMAKE_PKGCONFIG_REQUIRES = QtCore QtGui QtXml - -exists("qdeclarative_enable_gcov") { - QMAKE_CXXFLAGS = -fprofile-arcs -ftest-coverage -fno-elide-constructors - LIBS += -lgcov -} - -include(../qbase.pri) - -#INCLUDEPATH -= $$QMAKE_INCDIR_QT/$$TARGET -#DESTDIR=. - -#modules -include(3rdparty/3rdparty.pri) -include(util/util.pri) -include(graphicsitems/graphicsitems.pri) -include(qml/qml.pri) -include(debugger/debugger.pri) - -symbian:TARGET.UID3=0x2001E623 diff --git a/src/imports/imports.pro b/src/imports/imports.pro new file mode 100644 index 0000000..8b47043 --- /dev/null +++ b/src/imports/imports.pro @@ -0,0 +1,7 @@ +TEMPLATE = subdirs + +SUBDIRS += widgets + +contains(QT_CONFIG, webkit): SUBDIRS += webkit +contains(QT_CONFIG, multimedia): SUBDIRS += multimedia + diff --git a/src/imports/multimedia/multimedia.cpp b/src/imports/multimedia/multimedia.cpp new file mode 100644 index 0000000..8becbf3 --- /dev/null +++ b/src/imports/multimedia/multimedia.cpp @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** 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 +#include +#include + +QT_BEGIN_NAMESPACE + +class QMultimediaQmlModule : public QDeclarativeExtensionPlugin +{ + Q_OBJECT +public: + virtual void registerTypes(const char *uri) + { + QtMultimedia::qRegisterDeclarativeElements(uri); + } +}; + +QT_END_NAMESPACE + +#include "multimedia.moc" + +Q_EXPORT_PLUGIN2(qmultimediaqmlmodule, QT_PREPEND_NAMESPACE(QMultimediaQmlModule)); + diff --git a/src/imports/multimedia/multimedia.pro b/src/imports/multimedia/multimedia.pro new file mode 100644 index 0000000..ad2ce1b --- /dev/null +++ b/src/imports/multimedia/multimedia.pro @@ -0,0 +1,15 @@ +TARGET = multimedia +TARGETPATH = $$[QT_INSTALL_IMPORTS]/Qt/multimedia +include(../qimportbase.pri) + +QT += multimedia declarative + +SOURCES += multimedia.cpp + +QTDIR_build:DESTDIR = $$QT_BUILD_TREE/imports/Qt/multimedia +target.path = $$TARGETPATH + +qmldir.files += $$QT_BUILD_TREE/imports/Qt/multimedia/qmldir +qmldir.path += $$TARGETPATH + +INSTALLS += target qmldir diff --git a/src/imports/multimedia/qmldir b/src/imports/multimedia/qmldir new file mode 100644 index 0000000..0e6f656 --- /dev/null +++ b/src/imports/multimedia/qmldir @@ -0,0 +1 @@ +plugin multimedia diff --git a/src/imports/qimportbase.pri b/src/imports/qimportbase.pri new file mode 100644 index 0000000..363dd88 --- /dev/null +++ b/src/imports/qimportbase.pri @@ -0,0 +1,33 @@ +TEMPLATE = lib +CONFIG += qt plugin + +win32|mac:!wince*:!win32-msvc:!macx-xcode:CONFIG += debug_and_release + +isEmpty(TARGETPATH) { + error("qimportbase.pri: You must provide a TARGETPATH!") +} +isEmpty(TARGET) { + error("qimportbase.pri: You must provide a TARGET!") +} + +QMLDIRFILE = $${_PRO_FILE_PWD_}/qmldir +copy2build.input = QMLDIRFILE +copy2build.output = $$TARGETPATH/qmldir +isEmpty(vcproj):copy2build.variable_out = PRE_TARGETDEPS +copy2build.commands = $$QMAKE_COPY ${QMAKE_FILE_IN} ${QMAKE_FILE_OUT} +copy2build.name = COPY ${QMAKE_FILE_IN} +copy2build.CONFIG += no_link +QMAKE_EXTRA_COMPILERS += copy2build + +TARGET = $$qtLibraryTarget($$TARGET) +contains(QT_CONFIG, reduce_exports):CONFIG += hide_symbols + +include(../../qt_targets.pri) + +wince*:LIBS += $$QMAKE_LIBS_GUI + +symbian: { + TARGET.EPOCALLOWDLLDATA=1 + TARGET.CAPABILITY = All -Tcb + load(armcc_warnings) +} diff --git a/src/imports/webkit/plugin.cpp b/src/imports/webkit/plugin.cpp new file mode 100644 index 0000000..2f6205d --- /dev/null +++ b/src/imports/webkit/plugin.cpp @@ -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 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 +#include + +#include "qdeclarativewebview_p.h" +#include "qdeclarativewebview_p_p.h" + +QT_BEGIN_NAMESPACE + +class WebKitQmlPlugin : public QDeclarativeExtensionPlugin +{ + Q_OBJECT +public: + virtual void registerTypes(const char *uri) + { + Q_ASSERT(QLatin1String(uri) == QLatin1String("org.webkit")); + qmlRegisterType(uri,1,0,"WebView"); + } +}; + +QT_END_NAMESPACE + +#include "plugin.moc" + +Q_EXPORT_PLUGIN2(webkitqmlplugin, QT_PREPEND_NAMESPACE(WebKitQmlPlugin)); + diff --git a/src/imports/webkit/qdeclarativewebview.cpp b/src/imports/webkit/qdeclarativewebview.cpp new file mode 100644 index 0000000..733ac86 --- /dev/null +++ b/src/imports/webkit/qdeclarativewebview.cpp @@ -0,0 +1,1340 @@ +/**************************************************************************** +** +** 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 "qdeclarativewebview_p.h" +#include "qdeclarativewebview_p_p.h" + +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +static const int MAX_DOUBLECLICK_TIME=500; // XXX need better gesture system + +class QDeclarativeWebViewPrivate : public QDeclarativePaintedItemPrivate +{ + Q_DECLARE_PUBLIC(QDeclarativeWebView) + +public: + QDeclarativeWebViewPrivate() + : QDeclarativePaintedItemPrivate(), page(0), preferredwidth(0), preferredheight(0), + progress(1.0), status(QDeclarativeWebView::Null), pending(PendingNone), + newWindowComponent(0), newWindowParent(0), + pressTime(400), + rendering(true) + { + } + + QUrl url; // page url might be different if it has not loaded yet + QWebPage *page; + + int preferredwidth, preferredheight; + qreal progress; + QDeclarativeWebView::Status status; + QString statusText; + enum { PendingNone, PendingUrl, PendingHtml, PendingContent } pending; + QUrl pending_url; + QString pending_string; + QByteArray pending_data; + mutable QDeclarativeWebSettings settings; + QDeclarativeComponent *newWindowComponent; + QDeclarativeItem *newWindowParent; + + QBasicTimer pressTimer; + QPoint pressPoint; + int pressTime; // milliseconds before it's a "hold" + + + static void windowObjects_append(QDeclarativeListProperty *prop, QObject *o) { + static_cast(prop->data)->windowObjects.append(o); + static_cast(prop->data)->updateWindowObjects(); + } + + void updateWindowObjects(); + QObjectList windowObjects; + + bool rendering; +}; + +/*! + \qmlclass WebView QDeclarativeWebView + \since 4.7 + \brief The WebView item allows you to add web content to a canvas. + \inherits Item + + A WebView renders web content based on a URL. + + If the width and height of the item is not set, they will + dynamically adjust to a size appropriate for the content. + This width may be large for typical online web pages. + + If the preferredWidth is set, the width will be this amount or larger, + usually laying out the web content to fit the preferredWidth. + + \qml + import org.webkit 1.0 + + WebView { + url: "http://www.nokia.com" + width: 490 + height: 400 + scale: 0.5 + smooth: false + smoothCache: true + } + \endqml + + \image webview.png + + The item includes no scrolling, scaling, + toolbars, etc., those must be implemented around WebView. See the WebBrowser example + for a demonstration of this. +*/ + +/*! + \internal + \class QDeclarativeWebView + \brief The QDeclarativeWebView class allows you to add web content to a QDeclarativeView. + + A WebView renders web content base on a URL. + + \image webview.png + + The item includes no scrolling, scaling, + toolbars, etc., those must be implemented around WebView. See the WebBrowser example + for a demonstration of this. + + A QDeclarativeWebView object can be instantiated in Qml using the tag \l WebView. +*/ + +QDeclarativeWebView::QDeclarativeWebView(QDeclarativeItem *parent) + : QDeclarativePaintedItem(*(new QDeclarativeWebViewPrivate), parent) +{ + init(); +} + +QDeclarativeWebView::~QDeclarativeWebView() +{ + Q_D(QDeclarativeWebView); + delete d->page; +} + +void QDeclarativeWebView::init() +{ + Q_D(QDeclarativeWebView); + + QWebSettings::enablePersistentStorage(); + + setAcceptHoverEvents(true); + setAcceptedMouseButtons(Qt::LeftButton); + setFlag(QGraphicsItem::ItemHasNoContents, false); + + d->page = 0; +} + +void QDeclarativeWebView::componentComplete() +{ + QDeclarativePaintedItem::componentComplete(); + Q_D(QDeclarativeWebView); + switch (d->pending) { + case QDeclarativeWebViewPrivate::PendingUrl: + setUrl(d->pending_url); + break; + case QDeclarativeWebViewPrivate::PendingHtml: + setHtml(d->pending_string, d->pending_url); + break; + case QDeclarativeWebViewPrivate::PendingContent: + setContent(d->pending_data, d->pending_string, d->pending_url); + break; + default: + break; + } + d->pending = QDeclarativeWebViewPrivate::PendingNone; + d->updateWindowObjects(); +} + +QDeclarativeWebView::Status QDeclarativeWebView::status() const +{ + Q_D(const QDeclarativeWebView); + return d->status; +} + + +/*! + \qmlproperty real WebView::progress + This property holds the progress of loading the current URL, from 0 to 1. + + If you just want to know when progress gets to 1, use + WebView::onLoadFinished() or WebView::onLoadFailed() instead. +*/ +qreal QDeclarativeWebView::progress() const +{ + Q_D(const QDeclarativeWebView); + return d->progress; +} + +void QDeclarativeWebView::doLoadStarted() +{ + Q_D(QDeclarativeWebView); + + if (!d->url.isEmpty()) { + d->status = Loading; + emit statusChanged(d->status); + } + emit loadStarted(); +} + +void QDeclarativeWebView::doLoadProgress(int p) +{ + Q_D(QDeclarativeWebView); + if (d->progress == p/100.0) + return; + d->progress = p/100.0; + emit progressChanged(); +} + +void QDeclarativeWebView::pageUrlChanged() +{ + Q_D(QDeclarativeWebView); + + page()->setViewportSize(QSize( + d->preferredwidth>0 ? d->preferredwidth : width(), + d->preferredheight>0 ? d->preferredheight : height())); + expandToWebPage(); + + if ((d->url.isEmpty() && page()->mainFrame()->url() != QUrl(QLatin1String("about:blank"))) + || (d->url != page()->mainFrame()->url() && !page()->mainFrame()->url().isEmpty())) + { + d->url = page()->mainFrame()->url(); + if (d->url == QUrl(QLatin1String("about:blank"))) + d->url = QUrl(); + emit urlChanged(); + } +} + +void QDeclarativeWebView::doLoadFinished(bool ok) +{ + Q_D(QDeclarativeWebView); + + if (title().isEmpty()) + pageUrlChanged(); // XXX bug 232556 - pages with no title never get urlChanged() + + if (ok) { + d->status = d->url.isEmpty() ? Null : Ready; + emit loadFinished(); + } else { + d->status = Error; + emit loadFailed(); + } + emit statusChanged(d->status); +} + +/*! + \qmlproperty url WebView::url + This property holds the URL to the page displayed in this item. It can be set, + but also can change spontaneously (eg. because of network redirection). + + If the url is empty, the page is blank. + + The url is always absolute (QML will resolve relative URL strings in the context + of the containing QML document). +*/ +QUrl QDeclarativeWebView::url() const +{ + Q_D(const QDeclarativeWebView); + return d->url; +} + +void QDeclarativeWebView::setUrl(const QUrl &url) +{ + Q_D(QDeclarativeWebView); + if (url == d->url) + return; + + if (isComponentComplete()) { + d->url = url; + page()->setViewportSize(QSize( + d->preferredwidth>0 ? d->preferredwidth : width(), + d->preferredheight>0 ? d->preferredheight : height())); + QUrl seturl = url; + if (seturl.isEmpty()) + seturl = QUrl(QLatin1String("about:blank")); + + Q_ASSERT(!seturl.isRelative()); + + page()->mainFrame()->load(seturl); + + emit urlChanged(); + } else { + d->pending = d->PendingUrl; + d->pending_url = url; + } +} + +/*! + \qmlproperty int WebView::preferredWidth + This property holds the ideal width for displaying the current URL. +*/ +int QDeclarativeWebView::preferredWidth() const +{ + Q_D(const QDeclarativeWebView); + return d->preferredwidth; +} + +void QDeclarativeWebView::setPreferredWidth(int iw) +{ + Q_D(QDeclarativeWebView); + if (d->preferredwidth == iw) return; + d->preferredwidth = iw; + //expandToWebPage(); + emit preferredWidthChanged(); +} + +/*! + \qmlproperty int WebView::preferredHeight + This property holds the ideal height for displaying the current URL. + This only affects the area zoomed by heuristicZoom(). +*/ +int QDeclarativeWebView::preferredHeight() const +{ + Q_D(const QDeclarativeWebView); + return d->preferredheight; +} +void QDeclarativeWebView::setPreferredHeight(int ih) +{ + Q_D(QDeclarativeWebView); + if (d->preferredheight == ih) return; + d->preferredheight = ih; + emit preferredHeightChanged(); +} + +/*! + \qmlmethod bool WebView::evaluateJavaScript(string) + + Evaluates the \a scriptSource JavaScript inside the context of the + main web frame, and returns the result of the last executed statement. + + Note that this JavaScript does \e not have any access to QML objects + except as made available as windowObjects. +*/ +QVariant QDeclarativeWebView::evaluateJavaScript(const QString &scriptSource) +{ + return this->page()->mainFrame()->evaluateJavaScript(scriptSource); +} + +void QDeclarativeWebView::focusChanged(bool hasFocus) +{ + QFocusEvent e(hasFocus ? QEvent::FocusIn : QEvent::FocusOut); + page()->event(&e); + QDeclarativeItem::focusChanged(hasFocus); +} + +void QDeclarativeWebView::initialLayout() +{ + // nothing useful to do at this point +} + +void QDeclarativeWebView::noteContentsSizeChanged(const QSize&) +{ + expandToWebPage(); +} + +void QDeclarativeWebView::expandToWebPage() +{ + Q_D(QDeclarativeWebView); + QSize cs = page()->mainFrame()->contentsSize(); + if (cs.width() < d->preferredwidth) + cs.setWidth(d->preferredwidth); + if (cs.height() < d->preferredheight) + cs.setHeight(d->preferredheight); + if (widthValid()) + cs.setWidth(width()); + if (heightValid()) + cs.setHeight(height()); + if (cs != page()->viewportSize()) { + page()->setViewportSize(cs); + } + if (cs != contentsSize()) + setContentsSize(cs); +} + +void QDeclarativeWebView::geometryChanged(const QRectF &newGeometry, + const QRectF &oldGeometry) +{ + if (newGeometry.size() != oldGeometry.size()) + expandToWebPage(); + QDeclarativePaintedItem::geometryChanged(newGeometry, oldGeometry); +} + +void QDeclarativeWebView::paintPage(const QRect& r) +{ + dirtyCache(r); + update(); +} + +/*! + \qmlproperty list WebView::javaScriptWindowObjects + + This property is a list of object that are available from within + the webview's JavaScript context. + + The \a object will be inserted as a child of the frame's window + object, under the name given by the attached property \c WebView.windowObjectName. + + \qml + WebView { + javaScriptWindowObjects: Object { + WebView.windowObjectName: "coordinates" + } + } + \endqml + + Properties of the object will be exposed as JavaScript properties and slots as + JavaScript methods. + + If Javascript is not enabled for this page, then this property does nothing. +*/ +QDeclarativeListProperty QDeclarativeWebView::javaScriptWindowObjects() +{ + Q_D(QDeclarativeWebView); + return QDeclarativeListProperty(this, d, &QDeclarativeWebViewPrivate::windowObjects_append); +} + +QDeclarativeWebViewAttached *QDeclarativeWebView::qmlAttachedProperties(QObject *o) +{ + return new QDeclarativeWebViewAttached(o); +} + +void QDeclarativeWebViewPrivate::updateWindowObjects() +{ + Q_Q(QDeclarativeWebView); + if (!q->isComponentComplete() || !page) + return; + + for (int ii = 0; ii < windowObjects.count(); ++ii) { + QObject *object = windowObjects.at(ii); + QDeclarativeWebViewAttached *attached = static_cast(qmlAttachedPropertiesObject(object)); + if (attached && !attached->windowObjectName().isEmpty()) { + page->mainFrame()->addToJavaScriptWindowObject(attached->windowObjectName(), object); + } + } +} + +bool QDeclarativeWebView::renderingEnabled() const +{ + Q_D(const QDeclarativeWebView); + return d->rendering; +} + +void QDeclarativeWebView::setRenderingEnabled(bool enabled) +{ + Q_D(QDeclarativeWebView); + if (d->rendering == enabled) + return; + d->rendering = enabled; + emit renderingEnabledChanged(); + + setCacheFrozen(!enabled); + if (enabled) + clearCache(); +} + + +void QDeclarativeWebView::drawContents(QPainter *p, const QRect &r) +{ + Q_D(QDeclarativeWebView); + if (d->rendering) + page()->mainFrame()->render(p,r); +} + +QMouseEvent *QDeclarativeWebView::sceneMouseEventToMouseEvent(QGraphicsSceneMouseEvent *e) +{ + QEvent::Type t; + switch(e->type()) { + default: + case QEvent::GraphicsSceneMousePress: + t = QEvent::MouseButtonPress; + break; + case QEvent::GraphicsSceneMouseRelease: + t = QEvent::MouseButtonRelease; + break; + case QEvent::GraphicsSceneMouseMove: + t = QEvent::MouseMove; + break; + case QGraphicsSceneEvent::GraphicsSceneMouseDoubleClick: + t = QEvent::MouseButtonDblClick; + break; + } + + QMouseEvent *me = new QMouseEvent(t, (e->pos()/contentsScale()).toPoint(), e->button(), e->buttons(), 0); + return me; +} + +QMouseEvent *QDeclarativeWebView::sceneHoverMoveEventToMouseEvent(QGraphicsSceneHoverEvent *e) +{ + QEvent::Type t = QEvent::MouseMove; + + QMouseEvent *me = new QMouseEvent(t, (e->pos()/contentsScale()).toPoint(), Qt::NoButton, Qt::NoButton, 0); + + return me; +} + + +/*! + \qmlsignal WebView::onDoubleClick(clickx,clicky) + + The WebView does not pass double-click events to the web engine, but rather + emits this signals. +*/ + +void QDeclarativeWebView::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) +{ + QMouseEvent *me = sceneMouseEventToMouseEvent(event); + emit doubleClick(me->x(),me->y()); + delete me; +} + +/*! + \qmlmethod bool WebView::heuristicZoom(clickX,clickY,maxzoom) + + Finds a zoom that: + \list + \i shows a whole item + \i includes (\a clickX, \a clickY) + \i fits into the preferredWidth and preferredHeight + \i zooms by no more than \a maxzoom + \i is more than 10% above the current zoom + \endlist + + If such a zoom exists, emits zoomTo(zoom,centerX,centerY) and returns true; otherwise, + no signal is emitted and returns false. +*/ +bool QDeclarativeWebView::heuristicZoom(int clickX, int clickY, qreal maxzoom) +{ + Q_D(QDeclarativeWebView); + if (contentsScale() >= maxzoom/zoomFactor()) + return false; + qreal ozf = contentsScale(); + QRect showarea = elementAreaAt(clickX, clickY, d->preferredwidth/maxzoom, d->preferredheight/maxzoom); + qreal z = qMin(qreal(d->preferredwidth)/showarea.width(),qreal(d->preferredheight)/showarea.height()); + if (z > maxzoom/zoomFactor()) + z = maxzoom/zoomFactor(); + if (z/ozf > 1.2) { + QRectF r(showarea.left()*z, showarea.top()*z, showarea.width()*z, showarea.height()*z); + emit zoomTo(z,r.x()+r.width()/2, r.y()+r.height()/2); + return true; + } else { + return false; + } +} + +/*! + \qmlproperty int WebView::pressGrabTime + + The number of milliseconds the user must press before the WebView + starts passing move events through to the web engine (rather than + letting other QML elements such as a Flickable take them). + + Defaults to 400ms. Set to 0 to always grab and pass move events to + the web engine. +*/ +int QDeclarativeWebView::pressGrabTime() const +{ + Q_D(const QDeclarativeWebView); + return d->pressTime; +} + +void QDeclarativeWebView::setPressGrabTime(int ms) +{ + Q_D(QDeclarativeWebView); + if (d->pressTime == ms) + return; + d->pressTime = ms; + emit pressGrabTimeChanged(); +} + +void QDeclarativeWebView::mousePressEvent(QGraphicsSceneMouseEvent *event) +{ + Q_D(QDeclarativeWebView); + + setFocus (true); + QMouseEvent *me = sceneMouseEventToMouseEvent(event); + + d->pressPoint = me->pos(); + if (d->pressTime) { + d->pressTimer.start(d->pressTime,this); + setKeepMouseGrab(false); + } else { + grabMouse(); + setKeepMouseGrab(true); + } + + page()->event(me); + event->setAccepted( +/* + It is not correct to send the press event upwards, if it is not accepted by WebKit + e.g. push button does not work, if done so as QGraphicsScene will not send the release event at all to WebKit + Might be a bug in WebKit, though + */ +#if 1 //QT_VERSION <= 0x040500 // XXX see bug 230835 + true +#else + me->isAccepted() +#endif + ); + delete me; + if (!event->isAccepted()) { + QDeclarativePaintedItem::mousePressEvent(event); + } +} + +void QDeclarativeWebView::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +{ + Q_D(QDeclarativeWebView); + + QMouseEvent *me = sceneMouseEventToMouseEvent(event); + page()->event(me); + d->pressTimer.stop(); + event->setAccepted( +/* + It is not correct to send the press event upwards, if it is not accepted by WebKit + e.g. push button does not work, if done so as QGraphicsScene will not send all the events to WebKit + */ +#if 1 //QT_VERSION <= 0x040500 // XXX see bug 230835 + true +#else + me->isAccepted() +#endif + ); + delete me; + if (!event->isAccepted()) { + QDeclarativePaintedItem::mouseReleaseEvent(event); + } + setKeepMouseGrab(false); + ungrabMouse(); +} + +void QDeclarativeWebView::timerEvent(QTimerEvent *event) +{ + Q_D(QDeclarativeWebView); + if (event->timerId() == d->pressTimer.timerId()) { + d->pressTimer.stop(); + grabMouse(); + setKeepMouseGrab(true); + } +} + +void QDeclarativeWebView::mouseMoveEvent(QGraphicsSceneMouseEvent *event) +{ + Q_D(QDeclarativeWebView); + + QMouseEvent *me = sceneMouseEventToMouseEvent(event); + if (d->pressTimer.isActive()) { + if ((me->pos() - d->pressPoint).manhattanLength() > QApplication::startDragDistance()) { + d->pressTimer.stop(); + } + } + if (keepMouseGrab()) { + page()->event(me); + event->setAccepted( +/* + It is not correct to send the press event upwards, if it is not accepted by WebKit + e.g. push button does not work, if done so as QGraphicsScene will not send the release event at all to WebKit + Might be a bug in WebKit, though + */ +#if 1 // QT_VERSION <= 0x040500 // XXX see bug 230835 + true +#else + me->isAccepted() +#endif + ); + } + delete me; + if (!event->isAccepted()) + QDeclarativePaintedItem::mouseMoveEvent(event); + +} +void QDeclarativeWebView::hoverMoveEvent (QGraphicsSceneHoverEvent * event) +{ + QMouseEvent *me = sceneHoverMoveEventToMouseEvent(event); + page()->event(me); + event->setAccepted( +#if QT_VERSION <= 0x040500 // XXX see bug 230835 + true +#else + me->isAccepted() +#endif + ); + delete me; + if (!event->isAccepted()) + QDeclarativePaintedItem::hoverMoveEvent(event); +} + +void QDeclarativeWebView::keyPressEvent(QKeyEvent* event) +{ + page()->event(event); + if (!event->isAccepted()) + QDeclarativePaintedItem::keyPressEvent(event); +} + +void QDeclarativeWebView::keyReleaseEvent(QKeyEvent* event) +{ + page()->event(event); + if (!event->isAccepted()) + QDeclarativePaintedItem::keyReleaseEvent(event); +} + +bool QDeclarativeWebView::sceneEvent(QEvent *event) +{ + if (event->type() == QEvent::KeyPress) { + QKeyEvent *k = static_cast(event); + if (k->key() == Qt::Key_Tab || k->key() == Qt::Key_Backtab) { + if (!(k->modifiers() & (Qt::ControlModifier | Qt::AltModifier))) { //### Add MetaModifier? + page()->event(event); + if (event->isAccepted()) + return true; + } + } + } + return QDeclarativePaintedItem::sceneEvent(event); +} + + +/*! + \qmlproperty action WebView::back + This property holds the action for causing the previous URL in the history to be displayed. +*/ +QAction *QDeclarativeWebView::backAction() const +{ + return page()->action(QWebPage::Back); +} + +/*! + \qmlproperty action WebView::forward + This property holds the action for causing the next URL in the history to be displayed. +*/ +QAction *QDeclarativeWebView::forwardAction() const +{ + return page()->action(QWebPage::Forward); +} + +/*! + \qmlproperty action WebView::reload + This property holds the action for reloading with the current URL +*/ +QAction *QDeclarativeWebView::reloadAction() const +{ + return page()->action(QWebPage::Reload); +} + +/*! + \qmlproperty action WebView::stop + This property holds the action for stopping loading with the current URL +*/ +QAction *QDeclarativeWebView::stopAction() const +{ + return page()->action(QWebPage::Stop); +} + +/*! + \qmlproperty real WebView::title + This property holds the title of the web page currently viewed + + By default, this property contains an empty string. +*/ +QString QDeclarativeWebView::title() const +{ + return page()->mainFrame()->title(); +} + + + +/*! + \qmlproperty pixmap WebView::icon + This property holds the icon associated with the web page currently viewed +*/ +QPixmap QDeclarativeWebView::icon() const +{ + return page()->mainFrame()->icon().pixmap(QSize(256,256)); +} + + +/*! + \qmlproperty real WebView::zoomFactor + This property holds the multiplier used to scale the contents of a Web page. +*/ +void QDeclarativeWebView::setZoomFactor(qreal factor) +{ + Q_D(QDeclarativeWebView); + if (factor == page()->mainFrame()->zoomFactor()) + return; + + page()->mainFrame()->setZoomFactor(factor); + page()->setViewportSize(QSize( + d->preferredwidth>0 ? d->preferredwidth*factor : width()*factor, + d->preferredheight>0 ? d->preferredheight*factor : height()*factor)); + expandToWebPage(); + + emit zoomFactorChanged(); +} + +qreal QDeclarativeWebView::zoomFactor() const +{ + return page()->mainFrame()->zoomFactor(); +} + +/*! + \qmlproperty string WebView::statusText + + This property is the current status suggested by the current web page. In a web browser, + such status is often shown in some kind of status bar. +*/ +void QDeclarativeWebView::setStatusText(const QString& s) +{ + Q_D(QDeclarativeWebView); + d->statusText = s; + emit statusTextChanged(); +} + +void QDeclarativeWebView::windowObjectCleared() +{ + Q_D(QDeclarativeWebView); + d->updateWindowObjects(); +} + +QString QDeclarativeWebView::statusText() const +{ + Q_D(const QDeclarativeWebView); + return d->statusText; +} + +QWebPage *QDeclarativeWebView::page() const +{ + Q_D(const QDeclarativeWebView); + + if (!d->page) { + QDeclarativeWebView *self = const_cast(this); + QWebPage *wp = new QDeclarativeWebPage(self); + + // QML items don't default to having a background, + // even though most we pages will set one anyway. + QPalette pal = QApplication::palette(); + pal.setBrush(QPalette::Base, QColor::fromRgbF(0, 0, 0, 0)); + wp->setPalette(pal); + + wp->setNetworkAccessManager(qmlEngine(this)->networkAccessManager()); + + self->setPage(wp); + + return wp; + } + + return d->page; +} + + +// The QObject interface to settings(). +/*! + \qmlproperty string WebView::settings.standardFontFamily + \qmlproperty string WebView::settings.fixedFontFamily + \qmlproperty string WebView::settings.serifFontFamily + \qmlproperty string WebView::settings.sansSerifFontFamily + \qmlproperty string WebView::settings.cursiveFontFamily + \qmlproperty string WebView::settings.fantasyFontFamily + + \qmlproperty int WebView::settings.minimumFontSize + \qmlproperty int WebView::settings.minimumLogicalFontSize + \qmlproperty int WebView::settings.defaultFontSize + \qmlproperty int WebView::settings.defaultFixedFontSize + + \qmlproperty bool WebView::settings.autoLoadImages + \qmlproperty bool WebView::settings.javascriptEnabled + \qmlproperty bool WebView::settings.javaEnabled + \qmlproperty bool WebView::settings.pluginsEnabled + \qmlproperty bool WebView::settings.privateBrowsingEnabled + \qmlproperty bool WebView::settings.javascriptCanOpenWindows + \qmlproperty bool WebView::settings.javascriptCanAccessClipboard + \qmlproperty bool WebView::settings.developerExtrasEnabled + \qmlproperty bool WebView::settings.linksIncludedInFocusChain + \qmlproperty bool WebView::settings.zoomTextOnly + \qmlproperty bool WebView::settings.printElementBackgrounds + \qmlproperty bool WebView::settings.offlineStorageDatabaseEnabled + \qmlproperty bool WebView::settings.offlineWebApplicationCacheEnabled + \qmlproperty bool WebView::settings.localStorageDatabaseEnabled + \qmlproperty bool WebView::settings.localContentCanAccessRemoteUrls + + These properties give access to the settings controlling the web view. + + See QWebSettings for details of these properties. + + \qml + WebView { + settings.pluginsEnabled: true + settings.standardFontFamily: "Arial" + ... + } + \endqml +*/ +QObject *QDeclarativeWebView::settingsObject() const +{ + Q_D(const QDeclarativeWebView); + d->settings.s = page()->settings(); + return &d->settings; +} + +void QDeclarativeWebView::setPage(QWebPage *page) +{ + Q_D(QDeclarativeWebView); + if (d->page == page) + return; + if (d->page) { + if (d->page->parent() == this) { + delete d->page; + } else { + d->page->disconnect(this); + } + } + d->page = page; + d->page->setViewportSize(QSize( + d->preferredwidth>0 ? d->preferredwidth : width(), + d->preferredheight>0 ? d->preferredheight : height())); + d->page->mainFrame()->setScrollBarPolicy(Qt::Horizontal,Qt::ScrollBarAlwaysOff); + d->page->mainFrame()->setScrollBarPolicy(Qt::Vertical,Qt::ScrollBarAlwaysOff); + connect(d->page,SIGNAL(repaintRequested(QRect)),this,SLOT(paintPage(QRect))); + connect(d->page->mainFrame(),SIGNAL(urlChanged(QUrl)),this,SLOT(pageUrlChanged())); + connect(d->page->mainFrame(), SIGNAL(titleChanged(QString)), this, SIGNAL(titleChanged(QString))); + connect(d->page->mainFrame(), SIGNAL(titleChanged(QString)), this, SIGNAL(iconChanged())); + connect(d->page->mainFrame(), SIGNAL(iconChanged()), this, SIGNAL(iconChanged())); + connect(d->page->mainFrame(), SIGNAL(contentsSizeChanged(QSize)), this, SLOT(noteContentsSizeChanged(QSize))); + connect(d->page->mainFrame(), SIGNAL(initialLayoutCompleted()), this, SLOT(initialLayout())); + + connect(d->page,SIGNAL(loadStarted()),this,SLOT(doLoadStarted())); + connect(d->page,SIGNAL(loadProgress(int)),this,SLOT(doLoadProgress(int))); + connect(d->page,SIGNAL(loadFinished(bool)),this,SLOT(doLoadFinished(bool))); + connect(d->page,SIGNAL(statusBarMessage(QString)),this,SLOT(setStatusText(QString))); + + connect(d->page->mainFrame(),SIGNAL(javaScriptWindowObjectCleared()),this,SLOT(windowObjectCleared())); +} + +/*! + \qmlsignal WebView::onLoadStarted() + + This handler is called when the web engine begins loading + a page. Later, WebView::onLoadFinished() or WebView::onLoadFailed() + will be emitted. +*/ + +/*! + \qmlsignal WebView::onLoadFinished() + + This handler is called when the web engine \e successfully + finishes loading a page, including any component content + (WebView::onLoadFailed() will be emitted otherwise). + + \sa progress +*/ + +/*! + \qmlsignal WebView::onLoadFailed() + + This handler is called when the web engine fails loading + a page or any component content + (WebView::onLoadFinished() will be emitted on success). +*/ + +void QDeclarativeWebView::load(const QNetworkRequest &request, + QNetworkAccessManager::Operation operation, + const QByteArray &body) +{ + page()->mainFrame()->load(request, operation, body); +} + +QString QDeclarativeWebView::html() const +{ + return page()->mainFrame()->toHtml(); +} + +/*! + \qmlproperty string WebView::html + This property holds HTML text set directly + + The html property can be set as a string. + + \qml + WebView { + html: "

This is HTML." + } + \endqml +*/ +void QDeclarativeWebView::setHtml(const QString &html, const QUrl &baseUrl) +{ + Q_D(QDeclarativeWebView); + page()->setViewportSize(QSize( + d->preferredwidth>0 ? d->preferredwidth : width(), + d->preferredheight>0 ? d->preferredheight : height())); + if (isComponentComplete()) + page()->mainFrame()->setHtml(html, baseUrl); + else { + d->pending = d->PendingHtml; + d->pending_url = baseUrl; + d->pending_string = html; + } + emit htmlChanged(); +} + +void QDeclarativeWebView::setContent(const QByteArray &data, const QString &mimeType, const QUrl &baseUrl) +{ + Q_D(QDeclarativeWebView); + page()->setViewportSize(QSize( + d->preferredwidth>0 ? d->preferredwidth : width(), + d->preferredheight>0 ? d->preferredheight : height())); + + if (isComponentComplete()) + page()->mainFrame()->setContent(data,mimeType,qmlContext(this)->resolvedUrl(baseUrl)); + else { + d->pending = d->PendingContent; + d->pending_url = baseUrl; + d->pending_string = mimeType; + d->pending_data = data; + } +} + +QWebHistory *QDeclarativeWebView::history() const +{ + return page()->history(); +} + +QWebSettings *QDeclarativeWebView::settings() const +{ + return page()->settings(); +} + +QDeclarativeWebView *QDeclarativeWebView::createWindow(QWebPage::WebWindowType type) +{ + Q_D(QDeclarativeWebView); + switch (type) { + case QWebPage::WebBrowserWindow: { + if (!d->newWindowComponent && d->newWindowParent) + qWarning("WebView::newWindowComponent not set - WebView::newWindowParent ignored"); + else if (d->newWindowComponent && !d->newWindowParent) + qWarning("WebView::newWindowParent not set - WebView::newWindowComponent ignored"); + else if (d->newWindowComponent && d->newWindowParent) { + QDeclarativeWebView *webview = 0; + QDeclarativeContext *windowContext = new QDeclarativeContext(qmlContext(this)); + + QObject *nobj = d->newWindowComponent->create(windowContext); + if (nobj) { + windowContext->setParent(nobj); + QDeclarativeItem *item = qobject_cast(nobj); + if (!item) { + delete nobj; + } else { + webview = item->findChild(); + if (!webview) { + delete item; + } else { + nobj->setParent(d->newWindowParent); + static_cast(item)->setParentItem(d->newWindowParent); + } + } + } else { + delete windowContext; + } + + return webview; + } + } + break; + case QWebPage::WebModalDialog: { + // Not supported + } + } + return 0; +} + +/*! + \qmlproperty component WebView::newWindowComponent + + This property holds the component to use for new windows. + The component must have a WebView somewhere in its structure. + + When the web engine requests a new window, it will be an instance of + this component. + + The parent of the new window is set by newWindowParent. It must be set. +*/ +QDeclarativeComponent *QDeclarativeWebView::newWindowComponent() const +{ + Q_D(const QDeclarativeWebView); + return d->newWindowComponent; +} + +void QDeclarativeWebView::setNewWindowComponent(QDeclarativeComponent *newWindow) +{ + Q_D(QDeclarativeWebView); + if (newWindow == d->newWindowComponent) + return; + d->newWindowComponent = newWindow; + emit newWindowComponentChanged(); +} + + +/*! + \qmlproperty item WebView::newWindowParent + + The parent item for new windows. + + \sa newWindowComponent +*/ +QDeclarativeItem *QDeclarativeWebView::newWindowParent() const +{ + Q_D(const QDeclarativeWebView); + return d->newWindowParent; +} + +void QDeclarativeWebView::setNewWindowParent(QDeclarativeItem *parent) +{ + Q_D(QDeclarativeWebView); + if (parent == d->newWindowParent) + return; + if (d->newWindowParent && parent) { + QList children = d->newWindowParent->childItems(); + for (int i = 0; i < children.count(); ++i) { + children.at(i)->setParentItem(parent); + } + } + d->newWindowParent = parent; + emit newWindowParentChanged(); +} + +/*! + Returns the area of the largest element at position (\a x,\a y) that is no larger + than \a maxwidth by \a maxheight pixels. + + May return an area larger in the case when no smaller element is at the position. +*/ +QRect QDeclarativeWebView::elementAreaAt(int x, int y, int maxwidth, int maxheight) const +{ + QWebHitTestResult hit = page()->mainFrame()->hitTestContent(QPoint(x,y)); + QRect rv = hit.boundingRect(); + QWebElement element = hit.enclosingBlockElement(); + if (maxwidth<=0) maxwidth = INT_MAX; + if (maxheight<=0) maxheight = INT_MAX; + while (!element.parent().isNull() && element.geometry().width() <= maxwidth && element.geometry().height() <= maxheight) { + rv = element.geometry(); + element = element.parent(); + } + return rv; +} + +/*! + \internal + \class QDeclarativeWebPage + \brief The QDeclarativeWebPage class is a QWebPage that can create QML plugins. + + \sa QDeclarativeWebView +*/ +QDeclarativeWebPage::QDeclarativeWebPage(QDeclarativeWebView *parent) : + QWebPage(parent) +{ +} + +QDeclarativeWebPage::~QDeclarativeWebPage() +{ +} + +void QDeclarativeWebPage::javaScriptConsoleMessage(const QString& message, int lineNumber, const QString& sourceID) +{ + qWarning() << sourceID << ':' << lineNumber << ':' << message; +} + +QString QDeclarativeWebPage::chooseFile(QWebFrame *originatingFrame, const QString& oldFile) +{ + // Not supported (it's modal) + Q_UNUSED(originatingFrame) + Q_UNUSED(oldFile) + return oldFile; +} + +void QDeclarativeWebPage::javaScriptAlert(QWebFrame *originatingFrame, const QString& msg) +{ + Q_UNUSED(originatingFrame) + emit viewItem()->alert(msg); +} + +bool QDeclarativeWebPage::javaScriptConfirm(QWebFrame *originatingFrame, const QString& msg) +{ + // Not supported (it's modal) + Q_UNUSED(originatingFrame) + Q_UNUSED(msg) + return false; +} + +bool QDeclarativeWebPage::javaScriptPrompt(QWebFrame *originatingFrame, const QString& msg, const QString& defaultValue, QString* result) +{ + // Not supported (it's modal) + Q_UNUSED(originatingFrame) + Q_UNUSED(msg) + Q_UNUSED(defaultValue) + Q_UNUSED(result) + return false; +} + + +/* + Qt WebKit does not understand non-QWidget plugins, so dummy widgets + are created, parented to a single dummy tool window. + + The requirements for QML object plugins are input to the Qt WebKit + non-QWidget plugin support, which will obsolete this kludge. +*/ +class QWidget_Dummy_Plugin : public QWidget +{ + Q_OBJECT +public: + static QWidget *dummy_shared_parent() + { + static QWidget *dsp = 0; + if (!dsp) { + dsp = new QWidget(0,Qt::Tool); + dsp->setGeometry(-10000,-10000,0,0); + dsp->show(); + } + return dsp; + } + QWidget_Dummy_Plugin(const QUrl& url, QDeclarativeWebView *view, const QStringList ¶mNames, const QStringList ¶mValues) : + QWidget(dummy_shared_parent()), + propertyNames(paramNames), + propertyValues(paramValues), + webview(view) + { + QDeclarativeEngine *engine = qmlEngine(webview); + component = new QDeclarativeComponent(engine, url, this); + item = 0; + if (component->isLoading()) + connect(component, SIGNAL(statusChanged(QDeclarativeComponent::Status)), this, SLOT(qmlLoaded())); + else + qmlLoaded(); + } + +public Q_SLOTS: + void qmlLoaded() + { + if (component->isError()) { + // ### Could instead give these errors to the WebView to handle. + qWarning() << component->errors(); + return; + } + item = qobject_cast(component->create(qmlContext(webview))); + item->setParent(webview); + QString jsObjName; + for (int i=0; isetProperty(propertyNames[i].toUtf8(),propertyValues[i]); + if (propertyNames[i] == QLatin1String("objectname")) + jsObjName = propertyValues[i]; + } + } + if (!jsObjName.isNull()) { + QWebFrame *f = webview->page()->mainFrame(); + f->addToJavaScriptWindowObject(jsObjName, item); + } + resizeEvent(0); + delete component; + component = 0; + } + void resizeEvent(QResizeEvent*) + { + if (item) { + item->setX(x()); + item->setY(y()); + item->setWidth(width()); + item->setHeight(height()); + } + } + +private: + QDeclarativeComponent *component; + QDeclarativeItem *item; + QStringList propertyNames, propertyValues; + QDeclarativeWebView *webview; +}; + +QDeclarativeWebView *QDeclarativeWebPage::viewItem() +{ + return static_cast(parent()); +} + +QObject *QDeclarativeWebPage::createPlugin(const QString &, const QUrl &url, const QStringList ¶mNames, const QStringList ¶mValues) +{ + QUrl comp = qmlContext(viewItem())->resolvedUrl(url); + return new QWidget_Dummy_Plugin(comp,viewItem(),paramNames,paramValues); +} + +QWebPage *QDeclarativeWebPage::createWindow(WebWindowType type) +{ + QDeclarativeWebView *newView = viewItem()->createWindow(type); + if (newView) + return newView->page(); + return 0; +} + +QT_END_NAMESPACE + +#include diff --git a/src/imports/webkit/qdeclarativewebview_p.h b/src/imports/webkit/qdeclarativewebview_p.h new file mode 100644 index 0000000..5efc3b5 --- /dev/null +++ b/src/imports/webkit/qdeclarativewebview_p.h @@ -0,0 +1,287 @@ +/**************************************************************************** +** +** 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 QDECLARATIVEWEBVIEW_H +#define QDECLARATIVEWEBVIEW_H + +#include "webkitqmlplugin_export.h" + +#include + +#include +#include +#include +#include + +QT_BEGIN_HEADER + +class QWebHistory; +class QWebSettings; + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) +class QDeclarativeWebViewPrivate; +class QNetworkRequest; +class QDeclarativeWebView; + +class WEBKITQMLPLUGIN_EXPORT QDeclarativeWebPage : public QWebPage +{ + Q_OBJECT +public: + explicit QDeclarativeWebPage(QDeclarativeWebView *parent); + ~QDeclarativeWebPage(); +protected: + QObject *createPlugin(const QString &classid, const QUrl &url, const QStringList ¶mNames, const QStringList ¶mValues); + QWebPage *createWindow(WebWindowType type); + void javaScriptConsoleMessage(const QString& message, int lineNumber, const QString& sourceID); + QString chooseFile(QWebFrame *originatingFrame, const QString& oldFile); + void javaScriptAlert(QWebFrame *originatingFrame, const QString& msg); + bool javaScriptConfirm(QWebFrame *originatingFrame, const QString& msg); + bool javaScriptPrompt(QWebFrame *originatingFrame, const QString& msg, const QString& defaultValue, QString* result); + +private: + QDeclarativeWebView *viewItem(); +}; + + +class QDeclarativeWebViewAttached; + +//### TODO: browser plugins + +class WEBKITQMLPLUGIN_EXPORT QDeclarativeWebView : public QDeclarativePaintedItem +{ + Q_OBJECT + + Q_ENUMS(Status SelectionMode) + + Q_PROPERTY(QString title READ title NOTIFY titleChanged) + Q_PROPERTY(QPixmap icon READ icon NOTIFY iconChanged) + Q_PROPERTY(qreal zoomFactor READ zoomFactor WRITE setZoomFactor NOTIFY zoomFactorChanged) + Q_PROPERTY(QString statusText READ statusText NOTIFY statusTextChanged) + + Q_PROPERTY(QString html READ html WRITE setHtml NOTIFY htmlChanged) + + Q_PROPERTY(int pressGrabTime READ pressGrabTime WRITE setPressGrabTime NOTIFY pressGrabTimeChanged) + + Q_PROPERTY(int preferredWidth READ preferredWidth WRITE setPreferredWidth NOTIFY preferredWidthChanged) + Q_PROPERTY(int preferredHeight READ preferredHeight WRITE setPreferredHeight NOTIFY preferredHeightChanged) + Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY urlChanged) + Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged) + Q_PROPERTY(Status status READ status NOTIFY statusChanged) + + Q_PROPERTY(QAction* reload READ reloadAction CONSTANT) + Q_PROPERTY(QAction* back READ backAction CONSTANT) + Q_PROPERTY(QAction* forward READ forwardAction CONSTANT) + Q_PROPERTY(QAction* stop READ stopAction CONSTANT) + + Q_PROPERTY(QObject* settings READ settingsObject CONSTANT) + + Q_PROPERTY(QDeclarativeListProperty javaScriptWindowObjects READ javaScriptWindowObjects CONSTANT) + + Q_PROPERTY(QDeclarativeComponent* newWindowComponent READ newWindowComponent WRITE setNewWindowComponent NOTIFY newWindowComponentChanged) + Q_PROPERTY(QDeclarativeItem* newWindowParent READ newWindowParent WRITE setNewWindowParent NOTIFY newWindowParentChanged) + + Q_PROPERTY(bool renderingEnabled READ renderingEnabled WRITE setRenderingEnabled NOTIFY renderingEnabledChanged) + +public: + QDeclarativeWebView(QDeclarativeItem *parent=0); + ~QDeclarativeWebView(); + + QUrl url() const; + void setUrl(const QUrl &); + + QString title() const; + + QPixmap icon() const; + + qreal zoomFactor() const; + void setZoomFactor(qreal); + Q_INVOKABLE bool heuristicZoom(int clickX, int clickY, qreal maxzoom); + QRect elementAreaAt(int x, int y, int minwidth, int minheight) const; + + int pressGrabTime() const; + void setPressGrabTime(int); + + int preferredWidth() const; + void setPreferredWidth(int); + int preferredHeight() const; + void setPreferredHeight(int); + + enum Status { Null, Ready, Loading, Error }; + Status status() const; + qreal progress() const; + QString statusText() const; + + QAction *reloadAction() const; + QAction *backAction() const; + QAction *forwardAction() const; + QAction *stopAction() const; + + QWebPage *page() const; + void setPage(QWebPage *page); + + void load(const QNetworkRequest &request, + QNetworkAccessManager::Operation operation = QNetworkAccessManager::GetOperation, + const QByteArray &body = QByteArray()); + + QString html() const; + + void setHtml(const QString &html, const QUrl &baseUrl = QUrl()); + void setContent(const QByteArray &data, const QString &mimeType = QString(), const QUrl &baseUrl = QUrl()); + + QWebHistory *history() const; + QWebSettings *settings() const; + QObject *settingsObject() const; + + bool renderingEnabled() const; + void setRenderingEnabled(bool); + + QDeclarativeListProperty javaScriptWindowObjects(); + + static QDeclarativeWebViewAttached *qmlAttachedProperties(QObject *); + + QDeclarativeComponent *newWindowComponent() const; + void setNewWindowComponent(QDeclarativeComponent *newWindow); + QDeclarativeItem *newWindowParent() const; + void setNewWindowParent(QDeclarativeItem *newWindow); + +Q_SIGNALS: + void preferredWidthChanged(); + void preferredHeightChanged(); + void urlChanged(); + void progressChanged(); + void statusChanged(Status); + void titleChanged(const QString&); + void iconChanged(); + void statusTextChanged(); + void htmlChanged(); + void pressGrabTimeChanged(); + void zoomFactorChanged(); + void newWindowComponentChanged(); + void newWindowParentChanged(); + void renderingEnabledChanged(); + + void loadStarted(); + void loadFinished(); + void loadFailed(); + + void doubleClick(int clickX, int clickY); + + void zoomTo(qreal zoom, int centerX, int centerY); + + void alert(const QString& message); + +public Q_SLOTS: + QVariant evaluateJavaScript(const QString&); + +private Q_SLOTS: + void expandToWebPage(); + void paintPage(const QRect&); + void doLoadStarted(); + void doLoadProgress(int p); + void doLoadFinished(bool ok); + void setStatusText(const QString&); + void windowObjectCleared(); + void pageUrlChanged(); + void noteContentsSizeChanged(const QSize&); + void initialLayout(); + +protected: + void drawContents(QPainter *, const QRect &); + + void mousePressEvent(QGraphicsSceneMouseEvent *event); + void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); + void mouseMoveEvent(QGraphicsSceneMouseEvent *event); + void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); + void timerEvent(QTimerEvent *event); + void hoverMoveEvent (QGraphicsSceneHoverEvent * event); + void keyPressEvent(QKeyEvent* event); + void keyReleaseEvent(QKeyEvent* event); + virtual void geometryChanged(const QRectF &newGeometry, + const QRectF &oldGeometry); + virtual void focusChanged(bool); + virtual bool sceneEvent(QEvent *event); + QDeclarativeWebView *createWindow(QWebPage::WebWindowType type); + +private: + void init(); + virtual void componentComplete(); + Q_DISABLE_COPY(QDeclarativeWebView) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarativeWebView) + QMouseEvent *sceneMouseEventToMouseEvent(QGraphicsSceneMouseEvent *); + QMouseEvent *sceneHoverMoveEventToMouseEvent(QGraphicsSceneHoverEvent *); + friend class QDeclarativeWebPage; +}; + +class QDeclarativeWebViewAttached : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString windowObjectName READ windowObjectName WRITE setWindowObjectName) +public: + QDeclarativeWebViewAttached(QObject *parent) + : QObject(parent) + { + } + + QString windowObjectName() const + { + return m_windowObjectName; + } + + void setWindowObjectName(const QString &n) + { + m_windowObjectName = n; + } + +private: + QString m_windowObjectName; +}; + + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QDeclarativeWebView) +QML_DECLARE_TYPEINFO(QDeclarativeWebView, QML_HAS_ATTACHED_PROPERTIES) + +QT_END_HEADER + +#endif diff --git a/src/imports/webkit/qdeclarativewebview_p_p.h b/src/imports/webkit/qdeclarativewebview_p_p.h new file mode 100644 index 0000000..258b472 --- /dev/null +++ b/src/imports/webkit/qdeclarativewebview_p_p.h @@ -0,0 +1,151 @@ +/**************************************************************************** +** +** 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 QDECLARATIVEWEBVIEW_P_H +#define QDECLARATIVEWEBVIEW_P_H + +#include + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QDeclarativeWebSettings : public QObject { + Q_OBJECT + + Q_PROPERTY(QString standardFontFamily READ standardFontFamily WRITE setStandardFontFamily) + Q_PROPERTY(QString fixedFontFamily READ fixedFontFamily WRITE setFixedFontFamily) + Q_PROPERTY(QString serifFontFamily READ serifFontFamily WRITE setSerifFontFamily) + Q_PROPERTY(QString sansSerifFontFamily READ sansSerifFontFamily WRITE setSansSerifFontFamily) + Q_PROPERTY(QString cursiveFontFamily READ cursiveFontFamily WRITE setCursiveFontFamily) + Q_PROPERTY(QString fantasyFontFamily READ fantasyFontFamily WRITE setFantasyFontFamily) + + Q_PROPERTY(int minimumFontSize READ minimumFontSize WRITE setMinimumFontSize) + Q_PROPERTY(int minimumLogicalFontSize READ minimumLogicalFontSize WRITE setMinimumLogicalFontSize) + Q_PROPERTY(int defaultFontSize READ defaultFontSize WRITE setDefaultFontSize) + Q_PROPERTY(int defaultFixedFontSize READ defaultFixedFontSize WRITE setDefaultFixedFontSize) + + Q_PROPERTY(bool autoLoadImages READ autoLoadImages WRITE setAutoLoadImages) + Q_PROPERTY(bool javascriptEnabled READ javascriptEnabled WRITE setJavascriptEnabled) + Q_PROPERTY(bool javaEnabled READ javaEnabled WRITE setJavaEnabled) + Q_PROPERTY(bool pluginsEnabled READ pluginsEnabled WRITE setPluginsEnabled) + Q_PROPERTY(bool privateBrowsingEnabled READ privateBrowsingEnabled WRITE setPrivateBrowsingEnabled) + Q_PROPERTY(bool javascriptCanOpenWindows READ javascriptCanOpenWindows WRITE setJavascriptCanOpenWindows) + Q_PROPERTY(bool javascriptCanAccessClipboard READ javascriptCanAccessClipboard WRITE setJavascriptCanAccessClipboard) + Q_PROPERTY(bool developerExtrasEnabled READ developerExtrasEnabled WRITE setDeveloperExtrasEnabled) + Q_PROPERTY(bool linksIncludedInFocusChain READ linksIncludedInFocusChain WRITE setLinksIncludedInFocusChain) + Q_PROPERTY(bool zoomTextOnly READ zoomTextOnly WRITE setZoomTextOnly) + Q_PROPERTY(bool printElementBackgrounds READ printElementBackgrounds WRITE setPrintElementBackgrounds) + Q_PROPERTY(bool offlineStorageDatabaseEnabled READ offlineStorageDatabaseEnabled WRITE setOfflineStorageDatabaseEnabled) + Q_PROPERTY(bool offlineWebApplicationCacheEnabled READ offlineWebApplicationCacheEnabled WRITE setOfflineWebApplicationCacheEnabled) + Q_PROPERTY(bool localStorageDatabaseEnabled READ localStorageDatabaseEnabled WRITE setLocalStorageDatabaseEnabled) + Q_PROPERTY(bool localContentCanAccessRemoteUrls READ localContentCanAccessRemoteUrls WRITE setLocalContentCanAccessRemoteUrls) + +public: + QDeclarativeWebSettings() {} + + QString standardFontFamily() const { return s->fontFamily(QWebSettings::StandardFont); } + void setStandardFontFamily(const QString& f) { s->setFontFamily(QWebSettings::StandardFont,f); } + QString fixedFontFamily() const { return s->fontFamily(QWebSettings::FixedFont); } + void setFixedFontFamily(const QString& f) { s->setFontFamily(QWebSettings::FixedFont,f); } + QString serifFontFamily() const { return s->fontFamily(QWebSettings::SerifFont); } + void setSerifFontFamily(const QString& f) { s->setFontFamily(QWebSettings::SerifFont,f); } + QString sansSerifFontFamily() const { return s->fontFamily(QWebSettings::SansSerifFont); } + void setSansSerifFontFamily(const QString& f) { s->setFontFamily(QWebSettings::SansSerifFont,f); } + QString cursiveFontFamily() const { return s->fontFamily(QWebSettings::CursiveFont); } + void setCursiveFontFamily(const QString& f) { s->setFontFamily(QWebSettings::CursiveFont,f); } + QString fantasyFontFamily() const { return s->fontFamily(QWebSettings::FantasyFont); } + void setFantasyFontFamily(const QString& f) { s->setFontFamily(QWebSettings::FantasyFont,f); } + + int minimumFontSize() const { return s->fontSize(QWebSettings::MinimumFontSize); } + void setMinimumFontSize(int size) { s->setFontSize(QWebSettings::MinimumFontSize,size); } + int minimumLogicalFontSize() const { return s->fontSize(QWebSettings::MinimumLogicalFontSize); } + void setMinimumLogicalFontSize(int size) { s->setFontSize(QWebSettings::MinimumLogicalFontSize,size); } + int defaultFontSize() const { return s->fontSize(QWebSettings::DefaultFontSize); } + void setDefaultFontSize(int size) { s->setFontSize(QWebSettings::DefaultFontSize,size); } + int defaultFixedFontSize() const { return s->fontSize(QWebSettings::DefaultFixedFontSize); } + void setDefaultFixedFontSize(int size) { s->setFontSize(QWebSettings::DefaultFixedFontSize,size); } + + bool autoLoadImages() const { return s->testAttribute(QWebSettings::AutoLoadImages); } + void setAutoLoadImages(bool on) { s->setAttribute(QWebSettings::AutoLoadImages, on); } + bool javascriptEnabled() const { return s->testAttribute(QWebSettings::JavascriptEnabled); } + void setJavascriptEnabled(bool on) { s->setAttribute(QWebSettings::JavascriptEnabled, on); } + bool javaEnabled() const { return s->testAttribute(QWebSettings::JavaEnabled); } + void setJavaEnabled(bool on) { s->setAttribute(QWebSettings::JavaEnabled, on); } + bool pluginsEnabled() const { return s->testAttribute(QWebSettings::PluginsEnabled); } + void setPluginsEnabled(bool on) { s->setAttribute(QWebSettings::PluginsEnabled, on); } + bool privateBrowsingEnabled() const { return s->testAttribute(QWebSettings::PrivateBrowsingEnabled); } + void setPrivateBrowsingEnabled(bool on) { s->setAttribute(QWebSettings::PrivateBrowsingEnabled, on); } + bool javascriptCanOpenWindows() const { return s->testAttribute(QWebSettings::JavascriptCanOpenWindows); } + void setJavascriptCanOpenWindows(bool on) { s->setAttribute(QWebSettings::JavascriptCanOpenWindows, on); } + bool javascriptCanAccessClipboard() const { return s->testAttribute(QWebSettings::JavascriptCanAccessClipboard); } + void setJavascriptCanAccessClipboard(bool on) { s->setAttribute(QWebSettings::JavascriptCanAccessClipboard, on); } + bool developerExtrasEnabled() const { return s->testAttribute(QWebSettings::DeveloperExtrasEnabled); } + void setDeveloperExtrasEnabled(bool on) { s->setAttribute(QWebSettings::DeveloperExtrasEnabled, on); } + bool linksIncludedInFocusChain() const { return s->testAttribute(QWebSettings::LinksIncludedInFocusChain); } + void setLinksIncludedInFocusChain(bool on) { s->setAttribute(QWebSettings::LinksIncludedInFocusChain, on); } + bool zoomTextOnly() const { return s->testAttribute(QWebSettings::ZoomTextOnly); } + void setZoomTextOnly(bool on) { s->setAttribute(QWebSettings::ZoomTextOnly, on); } + bool printElementBackgrounds() const { return s->testAttribute(QWebSettings::PrintElementBackgrounds); } + void setPrintElementBackgrounds(bool on) { s->setAttribute(QWebSettings::PrintElementBackgrounds, on); } + bool offlineStorageDatabaseEnabled() const { return s->testAttribute(QWebSettings::OfflineStorageDatabaseEnabled); } + void setOfflineStorageDatabaseEnabled(bool on) { s->setAttribute(QWebSettings::OfflineStorageDatabaseEnabled, on); } + bool offlineWebApplicationCacheEnabled() const { return s->testAttribute(QWebSettings::OfflineWebApplicationCacheEnabled); } + void setOfflineWebApplicationCacheEnabled(bool on) { s->setAttribute(QWebSettings::OfflineWebApplicationCacheEnabled, on); } + bool localStorageDatabaseEnabled() const { return s->testAttribute(QWebSettings::LocalStorageDatabaseEnabled); } + void setLocalStorageDatabaseEnabled(bool on) { s->setAttribute(QWebSettings::LocalStorageDatabaseEnabled, on); } + bool localContentCanAccessRemoteUrls() const { return s->testAttribute(QWebSettings::LocalContentCanAccessRemoteUrls); } + void setLocalContentCanAccessRemoteUrls(bool on) { s->setAttribute(QWebSettings::LocalContentCanAccessRemoteUrls, on); } + + QWebSettings *s; +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QDeclarativeWebSettings) + +QT_END_HEADER + +#endif diff --git a/src/imports/webkit/qmldir b/src/imports/webkit/qmldir new file mode 100644 index 0000000..258aa2c --- /dev/null +++ b/src/imports/webkit/qmldir @@ -0,0 +1 @@ +plugin webkitqmlplugin diff --git a/src/imports/webkit/webkit.pro b/src/imports/webkit/webkit.pro new file mode 100644 index 0000000..76b46f1 --- /dev/null +++ b/src/imports/webkit/webkit.pro @@ -0,0 +1,19 @@ +TARGET = webkitqmlplugin +TARGETPATH = $$[QT_INSTALL_IMPORTS]/org/webkit +include(../qimportbase.pri) + +QT += webkit declarative +DEFINES += WEBKITQMLPLUGIN_EXPORTS + +SOURCES += qdeclarativewebview.cpp plugin.cpp +HEADERS += qdeclarativewebview_p.h \ + qdeclarativewebview_p_p.h \ + webkitqmlplugin_export.h + +QTDIR_build:DESTDIR = $$TARGETPATH +target.path = $$TARGETPATH + +qmldir.files += $$QT_BUILD_TREE/imports/org/webkit/qmldir +qmldir.path += $$TARGETPATH + +INSTALLS += target qmldir diff --git a/src/imports/webkit/webkitqmlplugin_export.h b/src/imports/webkit/webkitqmlplugin_export.h new file mode 100644 index 0000000..974fd24 --- /dev/null +++ b/src/imports/webkit/webkitqmlplugin_export.h @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** 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 WEBKITQMLPLUGIN_EXPORT_H +#define WEBKITQMLPLUGIN_EXPORT_H + +#include + +#if defined WEBKITQMLPLUGIN_EXPORTS +# define WEBKITQMLPLUGIN_EXPORT Q_DECL_EXPORT +#else +# define WEBKITQMLPLUGIN_EXPORT Q_DECL_IMPORT +#endif + +#endif // WEBKITQMLPLUGIN_EXPORT_H diff --git a/src/imports/widgets/graphicslayouts.cpp b/src/imports/widgets/graphicslayouts.cpp new file mode 100644 index 0000000..fc15ad2 --- /dev/null +++ b/src/imports/widgets/graphicslayouts.cpp @@ -0,0 +1,260 @@ +/**************************************************************************** +** +** 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 +#include + +QT_BEGIN_NAMESPACE + +LinearLayoutAttached::LinearLayoutAttached(QObject *parent) +: QObject(parent), _stretch(1), _alignment(Qt::AlignCenter) +{ +} + +void LinearLayoutAttached::setStretchFactor(int f) +{ + if (_stretch == f) + return; + + _stretch = f; + emit stretchChanged(reinterpret_cast(parent()), _stretch); +} + +void LinearLayoutAttached::setAlignment(Qt::Alignment a) +{ + if (_alignment == a) + return; + + _alignment = a; + emit alignmentChanged(reinterpret_cast(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()); + 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))); + //### 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); +} + +void QGraphicsLinearLayoutObject::updateStretch(QGraphicsLayoutItem *item, int stretch) +{ +QGraphicsLinearLayout::setStretchFactor(item, stretch); +} + +void QGraphicsLinearLayoutObject::updateAlignment(QGraphicsLayoutItem *item, Qt::Alignment alignment) +{ +QGraphicsLinearLayout::setAlignment(item, alignment); +} + +QHash QGraphicsLinearLayoutObject::attachedProperties; +LinearLayoutAttached *QGraphicsLinearLayoutObject::qmlAttachedProperties(QObject *obj) +{ +// ### This is not allowed - you must attach to any object +if (!qobject_cast(obj)) + return 0; +LinearLayoutAttached *rv = new LinearLayoutAttached(obj); +attachedProperties.insert(qobject_cast(obj), rv); +return rv; +} + +////////////////////////////////////////////////////////////////////////////////////////////////////// +// QGraphicsGridLayout-related classes +////////////////////////////////////////////////////////////////////////////////////////////////////// +GridLayoutAttached::GridLayoutAttached(QObject *parent) +: QObject(parent), _row(-1), _column(-1), _rowspan(1), _colspan(1), _alignment(-1) +{ +} + +void GridLayoutAttached::setRow(int r) +{ + if (_row == r) + return; + + _row = r; + //emit rowChanged(reinterpret_cast(parent()), _row); +} + +void GridLayoutAttached::setColumn(int c) +{ + if (_column == c) + return; + + _column = c; + //emit columnChanged(reinterpret_cast(parent()), _column); +} + +void GridLayoutAttached::setRowSpan(int rs) +{ + if (_rowspan == rs) + return; + + _rowspan = rs; + //emit rowSpanChanged(reinterpret_cast(parent()), _rowSpan); +} + +void GridLayoutAttached::setColumnSpan(int cs) +{ + if (_colspan == cs) + return; + + _colspan = cs; + //emit columnSpanChanged(reinterpret_cast(parent()), _columnSpan); +} + +void GridLayoutAttached::setAlignment(Qt::Alignment a) +{ + if (_alignment == a) + return; + + _alignment = a; + //emit alignmentChanged(reinterpret_cast(parent()), _alignment); +} + +QGraphicsGridLayoutObject::QGraphicsGridLayoutObject(QObject *parent) +: QObject(parent) +{ +} + +QGraphicsGridLayoutObject::~QGraphicsGridLayoutObject() +{ +} + +void QGraphicsGridLayoutObject::addWidget(QGraphicsWidget *wid) +{ +//use attached properties +if (QObject *obj = attachedProperties.value(qobject_cast(wid))) { + int row = static_cast(obj)->row(); + int column = static_cast(obj)->column(); + int rowSpan = static_cast(obj)->rowSpan(); + int columnSpan = static_cast(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; + } + addItem(item, row, column, rowSpan, columnSpan); + if (alignment != -1) + setAlignment(item,alignment); +} +} + +//### 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; //### +} + +QHash QGraphicsGridLayoutObject::attachedProperties; +GridLayoutAttached *QGraphicsGridLayoutObject::qmlAttachedProperties(QObject *obj) +{ +// ### This is not allowed - you must attach to any object +if (!qobject_cast(obj)) + return 0; +GridLayoutAttached *rv = new GridLayoutAttached(obj); +attachedProperties.insert(qobject_cast(obj), rv); +return rv; +} + +QT_END_NAMESPACE diff --git a/src/imports/widgets/graphicslayouts_p.h b/src/imports/widgets/graphicslayouts_p.h new file mode 100644 index 0000000..f9b9ae8 --- /dev/null +++ b/src/imports/widgets/graphicslayouts_p.h @@ -0,0 +1,226 @@ +/**************************************************************************** +** +** 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 "graphicswidgets_p.h" + +#include +#include + +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 children READ children) + Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation) + Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing) + Q_CLASSINFO("DefaultProperty", "children") +public: + QGraphicsLinearLayoutObject(QObject * = 0); + ~QGraphicsLinearLayoutObject(); + + QDeclarativeListProperty children() { return QDeclarativeListProperty(this, 0, children_append, children_count, children_at, children_clear); } + + static LinearLayoutAttached *qmlAttachedProperties(QObject *); + +private Q_SLOTS: + void updateStretch(QGraphicsLayoutItem*,int); + void updateAlignment(QGraphicsLayoutItem*,Qt::Alignment); + +private: + friend class LinearLayoutAttached; + void clearChildren(); + void insertLayoutItem(int, QGraphicsLayoutItem *); + static QHash attachedProperties; + + static void children_append(QDeclarativeListProperty *prop, QGraphicsLayoutItem *item) { + static_cast(prop->object)->insertLayoutItem(-1, item); + } + + static void children_clear(QDeclarativeListProperty *prop) { + static_cast(prop->object)->clearChildren(); + } + + static int children_count(QDeclarativeListProperty *prop) { + return static_cast(prop->object)->count(); + } + + static QGraphicsLayoutItem *children_at(QDeclarativeListProperty *prop, int index) { + return static_cast(prop->object)->itemAt(index); + } +}; + +class GridLayoutAttached; +class QGraphicsGridLayoutObject : public QObject, public QGraphicsGridLayout +{ + Q_OBJECT + Q_INTERFACES(QGraphicsLayout QGraphicsLayoutItem) + + Q_PROPERTY(QDeclarativeListProperty children READ children) + Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing) + 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 children() { return QDeclarativeListProperty(this, 0, children_append, children_count, children_at, children_clear); } + + qreal spacing() const; + + static GridLayoutAttached *qmlAttachedProperties(QObject *); + +private: + friend class GraphicsLayoutAttached; + void addWidget(QGraphicsWidget *); + void clearChildren(); + void addLayoutItem(QGraphicsLayoutItem *); + static QHash attachedProperties; + + static void children_append(QDeclarativeListProperty *prop, QGraphicsLayoutItem *item) { + static_cast(prop->object)->addLayoutItem(item); + } + + static void children_clear(QDeclarativeListProperty *prop) { + static_cast(prop->object)->clearChildren(); + } + + static int children_count(QDeclarativeListProperty *prop) { + return static_cast(prop->object)->count(); + } + + static QGraphicsLayoutItem *children_at(QDeclarativeListProperty *prop, int index) { + return static_cast(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) +public: + LinearLayoutAttached(QObject *parent); + + int stretchFactor() const { return _stretch; } + void setStretchFactor(int f); + Qt::Alignment alignment() const { return _alignment; } + void setAlignment(Qt::Alignment a); + +Q_SIGNALS: + void stretchChanged(QGraphicsLayoutItem*,int); + void alignmentChanged(QGraphicsLayoutItem*,Qt::Alignment); + +private: + int _stretch; + Qt::Alignment _alignment; +}; + +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) +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); + +private: + int _row; + int _column; + int _rowspan; + int _colspan; + Qt::Alignment _alignment; +}; + +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/src/imports/widgets/graphicswidgets.cpp b/src/imports/widgets/graphicswidgets.cpp new file mode 100644 index 0000000..062e516 --- /dev/null +++ b/src/imports/widgets/graphicswidgets.cpp @@ -0,0 +1,40 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ diff --git a/src/imports/widgets/graphicswidgets_p.h b/src/imports/widgets/graphicswidgets_p.h new file mode 100644 index 0000000..2c2b707 --- /dev/null +++ b/src/imports/widgets/graphicswidgets_p.h @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** 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 GRAPHICSWIDGETS_H +#define GRAPHICSWIDGETS_H + +#include + +#include +#include +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QGraphicsView) +QML_DECLARE_TYPE_HASMETATYPE(QGraphicsScene) +QML_DECLARE_TYPE(QGraphicsWidget) +QML_DECLARE_TYPE(QGraphicsObject) +QML_DECLARE_INTERFACE_HASMETATYPE(QGraphicsItem) + +QT_END_HEADER + +#endif // GRAPHICSWIDGETS_H diff --git a/src/imports/widgets/qmldir b/src/imports/widgets/qmldir new file mode 100644 index 0000000..6f19878 --- /dev/null +++ b/src/imports/widgets/qmldir @@ -0,0 +1 @@ +plugin widgets diff --git a/src/imports/widgets/widgets.cpp b/src/imports/widgets/widgets.cpp new file mode 100644 index 0000000..ec21cc4 --- /dev/null +++ b/src/imports/widgets/widgets.cpp @@ -0,0 +1,138 @@ +/**************************************************************************** +** +** 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 +#include + +#include "graphicslayouts_p.h" +#include "graphicswidgets_p.h" + +QT_BEGIN_NAMESPACE + +class QGraphicsViewDeclarativeUI : public QObject +{ + Q_OBJECT + + Q_PROPERTY(QGraphicsScene *scene READ scene WRITE setScene) + Q_CLASSINFO("DefaultProperty", "scene") +public: + QGraphicsViewDeclarativeUI(QObject *other) : QObject(other) {} + + QGraphicsScene *scene() const { return static_cast(parent())->scene(); } + void setScene(QGraphicsScene *scene) + { + static_cast(parent())->setScene(scene); + } +}; + +class QGraphicsSceneDeclarativeUI : public QObject +{ + Q_OBJECT + + Q_PROPERTY(QDeclarativeListProperty children READ children) + Q_CLASSINFO("DefaultProperty", "children") +public: + QGraphicsSceneDeclarativeUI(QObject *other) : QObject(other) {} + + QDeclarativeListProperty children() { return QDeclarativeListProperty(this->parent(), 0, children_append); } + +private: + static void children_append(QDeclarativeListProperty *prop, QObject *o) { + if (QGraphicsObject *go = qobject_cast(o)) + static_cast(prop->object)->addItem(go); + } +}; + +class QGraphicsWidgetDeclarativeUI : public QObject +{ + Q_OBJECT + + Q_PROPERTY(QDeclarativeListProperty children READ children) + Q_PROPERTY(QGraphicsLayout *layout READ layout WRITE setLayout) + Q_CLASSINFO("DefaultProperty", "children") +public: + QGraphicsWidgetDeclarativeUI(QObject *other) : QObject(other) {} + + QDeclarativeListProperty children() { return QDeclarativeListProperty(this, 0, children_append); } + + QGraphicsLayout *layout() const { return static_cast(parent())->layout(); } + void setLayout(QGraphicsLayout *lo) + { + static_cast(parent())->setLayout(lo); + } + +private: + void setItemParent(QGraphicsItem *wid) + { + wid->setParentItem(static_cast(parent())); + } + + static void children_append(QDeclarativeListProperty *prop, QGraphicsItem *i) { + static_cast(prop->object)->setItemParent(i); + } +}; + +class QWidgetsQmlModule : public QDeclarativeExtensionPlugin +{ + Q_OBJECT +public: + virtual void registerTypes(const char *uri) + { + Q_ASSERT(QLatin1String(uri) == QLatin1String("Qt.widgets")); + + QML_REGISTER_INTERFACE(QGraphicsLayoutItem); + QML_REGISTER_INTERFACE(QGraphicsLayout); + qmlRegisterType(uri,4,6,"QGraphicsLinearLayoutStretchItem"); + qmlRegisterType(uri,4,6,"QGraphicsLinearLayout"); + qmlRegisterType(uri,4,6,"QGraphicsGridLayout"); + qmlRegisterExtendedType(uri,4,6,"QGraphicsView"); + qmlRegisterExtendedType(uri,4,6,"QGraphicsScene"); + qmlRegisterExtendedType(uri,4,6,"QGraphicsWidget"); + QML_REGISTER_INTERFACE(QGraphicsItem); + } +}; + +QT_END_NAMESPACE + +#include "widgets.moc" + +Q_EXPORT_PLUGIN2(qtwidgetsqmlmodule, QT_PREPEND_NAMESPACE(QWidgetsQmlModule)); + diff --git a/src/imports/widgets/widgets.pro b/src/imports/widgets/widgets.pro new file mode 100644 index 0000000..b98be59 --- /dev/null +++ b/src/imports/widgets/widgets.pro @@ -0,0 +1,22 @@ +TARGET = widgets +TARGETPATH = $$[QT_INSTALL_IMPORTS]/Qt/widgets +include(../qimportbase.pri) + +QT += declarative + +SOURCES += \ + graphicslayouts.cpp \ + widgets.cpp + +HEADERS += \ + graphicswidgets_p.h \ + graphicslayouts_p.h + +QTDIR_build:DESTDIR = $$QT_BUILD_TREE/imports/Qt/widgets +target.path = $$TARGETPATH + +# install qmldir file +qmldir.files += qmldir +qmldir.path = $$TARGETPATH + +INSTALLS += target qmldir diff --git a/src/src.pro b/src/src.pro index 2b9dc30..7bb731e 100644 --- a/src/src.pro +++ b/src/src.pro @@ -29,6 +29,7 @@ contains(QT_CONFIG, scripttools): SRC_SUBDIRS += src_scripttools contains(QT_CONFIG, declarative): SRC_SUBDIRS += src_declarative contains(QT_CONFIG, multimedia): SRC_SUBDIRS += src_multimedia SRC_SUBDIRS += src_plugins +contains(QT_CONFIG, declarative): SRC_SUBDIRS += src_imports src_s60main.subdir = $$QT_SOURCE_TREE/src/s60main src_s60main.target = sub-s60main @@ -70,6 +71,8 @@ src_activeqt.subdir = $$QT_SOURCE_TREE/src/activeqt src_activeqt.target = sub-activeqt src_plugins.subdir = $$QT_SOURCE_TREE/src/plugins src_plugins.target = sub-plugins +src_imports.subdir = $$QT_SOURCE_TREE/src/imports +src_imports.target = sub-imports src_testlib.subdir = $$QT_SOURCE_TREE/src/testlib src_testlib.target = sub-testlib src_javascriptcore.subdir = $$QT_SOURCE_TREE/src/3rdparty/webkit/JavaScriptCore @@ -103,11 +106,13 @@ src_declarative.target = sub-declarative src_tools_activeqt.depends = src_tools_idc src_gui src_declarative.depends = src_xml src_gui src_script src_network src_svg src_plugins.depends = src_gui src_sql src_svg src_multimedia + src_imports.depends = src_gui src_declarative contains(QT_CONFIG, webkit) { src_webkit.depends = src_gui src_sql src_network src_xml contains(QT_CONFIG, phonon):src_webkit.depends += src_phonon contains(QT_CONFIG, xmlpatterns): src_webkit.depends += src_xmlpatterns contains(QT_CONFIG, declarative):src_declarative.depends += src_webkit + src_imports.depends += webkit #exists($$QT_SOURCE_TREE/src/3rdparty/webkit/JavaScriptCore/JavaScriptCore.pro): src_webkit.depends += src_javascriptcore } contains(QT_CONFIG, qt3support): src_plugins.depends += src_qt3support @@ -117,6 +122,7 @@ src_declarative.target = sub-declarative } contains(QT_CONFIG, opengl)|contains(QT_CONFIG, opengles1)|contains(QT_CONFIG, opengles2): src_plugins.depends += src_opengl contains(QT_CONFIG, declarative): src_multimedia.depends += src_declarative + contains(QT_CONFIG, multimedia): src_imports += src_multimedia } !symbian { -- cgit v0.12 From d88f9fbe1522c48dfef153eef768f9eec123ec9e Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Wed, 3 Mar 2010 09:35:00 +1000 Subject: Make test more reliable. --- .../qdeclarativeanimations/tst_qdeclarativeanimations.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/auto/declarative/qdeclarativeanimations/tst_qdeclarativeanimations.cpp b/tests/auto/declarative/qdeclarativeanimations/tst_qdeclarativeanimations.cpp index 0c166df..f5e15fb 100644 --- a/tests/auto/declarative/qdeclarativeanimations/tst_qdeclarativeanimations.cpp +++ b/tests/auto/declarative/qdeclarativeanimations/tst_qdeclarativeanimations.cpp @@ -217,11 +217,11 @@ void tst_qdeclarativeanimations::resume() animation.setProperty("x"); animation.setFrom(10); animation.setTo(200); - animation.setDuration(500); + animation.setDuration(1000); QVERIFY(animation.from() == 10); animation.start(); - QTest::qWait(200); + QTest::qWait(400); animation.pause(); qreal x = rect.x(); QVERIFY(x != qreal(200) && x != qreal(10)); @@ -231,7 +231,7 @@ void tst_qdeclarativeanimations::resume() animation.resume(); QVERIFY(animation.isRunning()); QVERIFY(!animation.isPaused()); - QTest::qWait(200); + QTest::qWait(400); animation.stop(); QVERIFY(rect.x() > x); } -- cgit v0.12 From eaf436568b2e6870a72e97baf2837d320f5d8ec8 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Wed, 3 Mar 2010 09:35:50 +1000 Subject: Initialize variable before use. --- src/declarative/util/qdeclarativeanimation.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/declarative/util/qdeclarativeanimation.cpp b/src/declarative/util/qdeclarativeanimation.cpp index ebf1a20..7f4f1c0 100644 --- a/src/declarative/util/qdeclarativeanimation.cpp +++ b/src/declarative/util/qdeclarativeanimation.cpp @@ -2225,7 +2225,7 @@ struct PropertyUpdater : public QDeclarativeBulkValueUpdater bool fromSourced; bool fromDefined; bool *wasDeleted; - PropertyUpdater() : wasDeleted(0) {} + PropertyUpdater() : prevInterpolatorType(0), wasDeleted(0) {} ~PropertyUpdater() { if (wasDeleted) *wasDeleted = true; } void setValue(qreal v) { -- cgit v0.12 From 398f97c90f52a8927ac1efe3d7e272da900d6be3 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Wed, 3 Mar 2010 10:08:38 +1000 Subject: /src/imports/ now also contains plugins, so treat the same. --- tests/auto/headers/tst_headers.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/auto/headers/tst_headers.cpp b/tests/auto/headers/tst_headers.cpp index 3745767..12c5843 100644 --- a/tests/auto/headers/tst_headers.cpp +++ b/tests/auto/headers/tst_headers.cpp @@ -271,6 +271,7 @@ void tst_Headers::macros() if (header.endsWith("_p.h") || header.endsWith("_pch.h") || header.contains("global/qconfig-") || header.endsWith("/qconfig.h") || header.contains("/src/tools/") || header.contains("/src/plugins/") + || header.contains("/src/imports/") || header.endsWith("/qiconset.h") || header.endsWith("/qfeatures.h") || header.endsWith("qt_windows.h")) return; -- cgit v0.12 From c131c4d922bd381b44164673085fb83547375fd0 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Wed, 3 Mar 2010 11:04:07 +1000 Subject: Add WorkerScript docs and tests. Task-number: QT-2807 --- src/declarative/qml/qdeclarativeworkerscript.cpp | 83 +++++++++- tests/auto/declarative/declarative.pro | 1 + .../qdeclarativeworkerscript/data/script.js | 5 + .../qdeclarativeworkerscript/data/worker.qml | 27 +++ .../qdeclarativeworkerscript.pro | 9 + .../tst_qdeclarativeworkerscript.cpp | 184 +++++++++++++++++++++ 6 files changed, 308 insertions(+), 1 deletion(-) create mode 100644 tests/auto/declarative/qdeclarativeworkerscript/data/script.js create mode 100644 tests/auto/declarative/qdeclarativeworkerscript/data/worker.qml create mode 100644 tests/auto/declarative/qdeclarativeworkerscript/qdeclarativeworkerscript.pro create mode 100644 tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp diff --git a/src/declarative/qml/qdeclarativeworkerscript.cpp b/src/declarative/qml/qdeclarativeworkerscript.cpp index c1d090e..784353a 100644 --- a/src/declarative/qml/qdeclarativeworkerscript.cpp +++ b/src/declarative/qml/qdeclarativeworkerscript.cpp @@ -365,6 +365,8 @@ void QDeclarativeWorkerScriptEnginePrivate::processLoad(int id, const QUrl &url) workerEngine->evaluate(script); workerEngine->popContext(); + } else { + qWarning().nospace() << "WorkerScript: Cannot find source file " << url.toString(); } } @@ -382,7 +384,7 @@ QVariant QDeclarativeWorkerScriptEnginePrivate::scriptValueToVariant(const QScri quint32 length = (quint32)value.property(QLatin1String("length")).toNumber(); for (quint32 ii = 0; ii < length; ++ii) { - QVariant v = scriptValueToVariant(ii); + QVariant v = scriptValueToVariant(value.property(ii)); list << v; } @@ -561,6 +563,65 @@ void QDeclarativeWorkerScriptEngine::run() delete d->workerEngine; d->workerEngine = 0; } + +/*! + \qmlclass WorkerScript QDeclarativeWorkerScript + \brief The WorkerScript element enables the use of threads in QML. + + Use WorkerScript to run operations in a new thread. + This is useful for running operations in the background so + that the main GUI thread is not blocked. + + Messages can be passed between the new thread and the parent thread + using sendMessage() and the onMessage() handler. + + Here is an example: + + \qml + import Qt 4.6 + + Rectangle { + width: 300 + height: 300 + + Text { + id: myText + text: 'Click anywhere' + } + + WorkerScript { + id: myWorker + source: "script.js" + + onMessage: { + myText.text = messageObject.reply + } + } + + MouseArea { + anchors.fill: parent + onClicked: myWorker.sendMessage( {'x': mouse.x, 'y': mouse.y} ); + } + } + \endqml + + The above worker script specifies a javascript file, "script.js", that handles + the operations to be performed in the new thread: + + \qml + WorkerScript.onMessage = function(message) { + // ... long-running operations and calculations are done here + WorkerScript.sendMessage( {'reply': 'Mouse is at ' + message.x + ',' + message.y} ); + } + \endqml + + When the user clicks anywhere within the rectangle, \c sendMessage() is + called, triggering the \tt WorkerScript.onMessage() handler in + \tt source.js. This in turn sends a reply message that is then received + by the \tt onMessage() handler of \tt myWorker. + + \sa WorkerListModel +*/ QDeclarativeWorkerScript::QDeclarativeWorkerScript(QObject *parent) : QObject(parent), m_engine(0), m_scriptId(-1) { @@ -571,6 +632,12 @@ QDeclarativeWorkerScript::~QDeclarativeWorkerScript() if (m_scriptId != -1) m_engine->removeWorkerScript(m_scriptId); } +/*! + \qmlproperty url WorkerScript::source + + This holds the url of the javascript file that implements the + \tt WorkerScript.onMessage() handler for threaded operations. +*/ QUrl QDeclarativeWorkerScript::source() const { return m_source; @@ -589,6 +656,13 @@ void QDeclarativeWorkerScript::setSource(const QUrl &source) emit sourceChanged(); } +/* + \qmlmethod WorkerScript::sendMessage(jsobject message) + + Sends the given \a message to a worker script handler in another + thread. The other worker script handler can receive this message + through the onMessage() handler. +*/ void QDeclarativeWorkerScript::sendMessage(const QScriptValue &message) { if (!m_engine) { @@ -616,6 +690,13 @@ void QDeclarativeWorkerScript::componentComplete() } } +/*! + \qmlsignal WorkerScript::onMessage(jsobject msg) + + This handler is called when a message \a msg is received from a worker + script in another thread through a call to sendMessage(). +*/ + bool QDeclarativeWorkerScript::event(QEvent *event) { if (event->type() == (QEvent::Type)WorkerDataEvent::WorkerData) { diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/declarative/declarative.pro index 38c75a8..200d831 100644 --- a/tests/auto/declarative/declarative.pro +++ b/tests/auto/declarative/declarative.pro @@ -55,6 +55,7 @@ SUBDIRS += \ qdeclarativexmllistmodel \ # Cover qpacketprotocol \ # Cover qdeclarativerepeater \ # Cover + qdeclarativeworkerscript \ # Cover qdeclarativeworkerlistmodel \ # Cover qdeclarativevaluetypes \ # Cover qdeclarativexmlhttprequest \ # Cover diff --git a/tests/auto/declarative/qdeclarativeworkerscript/data/script.js b/tests/auto/declarative/qdeclarativeworkerscript/data/script.js new file mode 100644 index 0000000..09199de --- /dev/null +++ b/tests/auto/declarative/qdeclarativeworkerscript/data/script.js @@ -0,0 +1,5 @@ +WorkerScript.onMessage = function(msg) { + WorkerScript.sendMessage(msg) +} + + diff --git a/tests/auto/declarative/qdeclarativeworkerscript/data/worker.qml b/tests/auto/declarative/qdeclarativeworkerscript/data/worker.qml new file mode 100644 index 0000000..2982010 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeworkerscript/data/worker.qml @@ -0,0 +1,27 @@ +import Qt 4.6 + +WorkerScript { + id: worker + source: "script.js" + + property bool done : false + property var response + + function testSend(value) { + worker.sendMessage(value) + } + + function testSendLiteral(value) { + eval('worker.sendMessage(' + value +')') + } + + function compareLiteralResponse(expected) { + var e = eval('(' + expected + ')') + return worker.response == e + } + + onMessage: { + worker.done = true + worker.response = messageObject + } +} diff --git a/tests/auto/declarative/qdeclarativeworkerscript/qdeclarativeworkerscript.pro b/tests/auto/declarative/qdeclarativeworkerscript/qdeclarativeworkerscript.pro new file mode 100644 index 0000000..0543ff6 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeworkerscript/qdeclarativeworkerscript.pro @@ -0,0 +1,9 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += declarative +QT += script +macx:CONFIG -= app_bundle + +SOURCES += tst_qdeclarativeworkerscript.cpp + +# Define SRCDIR equal to test's source directory +DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp b/tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp new file mode 100644 index 0000000..841a0ee --- /dev/null +++ b/tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp @@ -0,0 +1,184 @@ +/**************************************************************************** +** +** 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 test suite 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 +#include +#include + +#include +#include +#include + +#include +#include "../../../shared/util.h" + +Q_DECLARE_METATYPE(QList) +Q_DECLARE_METATYPE(QScriptValue) + +class tst_QDeclarativeWorkerScript : public QObject +{ + Q_OBJECT +public: + tst_QDeclarativeWorkerScript() {} +private slots: + void source(); + void source_data(); + void messaging(); + void messaging_data(); + void messaging_sendQObjectList(); + void messaging_sendJsObject(); + +private: + void waitForEchoMessage(QDeclarativeWorkerScript *worker) { + const QMetaObject *mo = worker->metaObject(); + int index = mo->indexOfProperty("done"); + QVERIFY(index >= 0); + QTRY_COMPARE(mo->property(index).read(worker).toBool(), true); + QTRY_COMPARE(mo->property(mo->indexOfProperty("done")).read(worker).toBool(), true); + } + + QDeclarativeEngine m_engine; +}; + +void tst_QDeclarativeWorkerScript::source() +{ + QFETCH(QUrl, source); + QFETCH(bool, valid); + + QDeclarativeComponent component(&m_engine); + component.setData("import Qt 4.6\nWorkerScript { source: '" + source.toString().toUtf8() + "'; }", QUrl()); + + if (!valid) { + QByteArray w = "WorkerScript: Cannot find source file \"" + source.toString().toUtf8() + "\""; + QTest::ignoreMessage(QtWarningMsg, w.constData()); + } + QDeclarativeWorkerScript *item = qobject_cast(component.create()); + QVERIFY(item != 0); + + QCOMPARE(item->source(), source); + + qApp->processEvents(); +} + +void tst_QDeclarativeWorkerScript::source_data() +{ + QTest::addColumn("source"); + QTest::addColumn("valid"); + + QTest::newRow("valid") << QUrl::fromLocalFile(SRCDIR "/data/worker.qml") << true; + QTest::newRow("invalid") << QUrl("file:///asdjfk.js") << false; +} + +void tst_QDeclarativeWorkerScript::messaging() +{ + QFETCH(QVariant, value); + + QDeclarativeComponent component(&m_engine, SRCDIR "/data/worker.qml"); + QDeclarativeWorkerScript *worker = qobject_cast(component.create()); + QVERIFY(worker != 0); + + QVERIFY(QMetaObject::invokeMethod(worker, "testSend", Q_ARG(QVariant, value))); + waitForEchoMessage(worker); + + const QMetaObject *mo = worker->metaObject(); + QCOMPARE(mo->property(mo->indexOfProperty("response")).read(worker).value(), value); + + qApp->processEvents(); +} + +void tst_QDeclarativeWorkerScript::messaging_data() +{ + QTest::addColumn("value"); + + QTest::newRow("invalid") << QVariant(); + QTest::newRow("bool") << qVariantFromValue(true); + QTest::newRow("int") << qVariantFromValue(1001); + QTest::newRow("real") << qVariantFromValue(10334.323); + QTest::newRow("string") << qVariantFromValue(QString("More cheeeese, Gromit!")); + QTest::newRow("variant list") << qVariantFromValue((QVariantList() << "a" << "b" << "c")); +} + +void tst_QDeclarativeWorkerScript::messaging_sendQObjectList() +{ + // Not allowed to send QObjects other than QDeclarativeWorkerListModelAgent + // instances. If objects are sent in a list, they will be sent as 'undefined' + // js values. + + QDeclarativeComponent component(&m_engine, SRCDIR "/data/worker.qml"); + QDeclarativeWorkerScript *worker = qobject_cast(component.create()); + QVERIFY(worker != 0); + + QVariantList objects; + for (int i=0; i<3; i++) + objects << qVariantFromValue(new QObject(this)); + + QVERIFY(QMetaObject::invokeMethod(worker, "testSend", Q_ARG(QVariant, qVariantFromValue(objects)))); + waitForEchoMessage(worker); + + const QMetaObject *mo = worker->metaObject(); + QVariantList result = mo->property(mo->indexOfProperty("response")).read(worker).value(); + QCOMPARE(result, (QVariantList() << QVariant() << QVariant() << QVariant())); + + qApp->processEvents(); +} + +void tst_QDeclarativeWorkerScript::messaging_sendJsObject() +{ + QDeclarativeComponent component(&m_engine, SRCDIR "/data/worker.qml"); + QDeclarativeWorkerScript *worker = qobject_cast(component.create()); + QVERIFY(worker != 0); + + QString jsObject = "{'spell power': 3101, 'haste': 1125}"; + + QVERIFY(QMetaObject::invokeMethod(worker, "testSendLiteral", Q_ARG(QVariant, jsObject))); + waitForEchoMessage(worker); + + QVariant result = qVariantFromValue(false); + QVERIFY(QMetaObject::invokeMethod(worker, "compareLiteralResponse", Qt::DirectConnection, + Q_RETURN_ARG(QVariant, result), Q_ARG(QVariant, jsObject))); + QVERIFY(result.toBool()); + + qApp->processEvents(); +} + +QTEST_MAIN(tst_QDeclarativeWorkerScript) + +#include "tst_qdeclarativeworkerscript.moc" + -- cgit v0.12 From fa23a63af230f0c917cc56e6c652c01e6695ef63 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 3 Mar 2010 12:56:07 +1000 Subject: Fix mouse stealing in nested flickables. Set intent to steal mouse, but don't steal the initiating event. This allows other, higher Flickables to override lower. Task-number: QTBUG-5292 --- .../graphicsitems/qdeclarativeflickable.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativeflickable.cpp b/src/declarative/graphicsitems/qdeclarativeflickable.cpp index c54ddd0..2fdd720 100644 --- a/src/declarative/graphicsitems/qdeclarativeflickable.cpp +++ b/src/declarative/graphicsitems/qdeclarativeflickable.cpp @@ -682,7 +682,7 @@ void QDeclarativeFlickablePrivate::handleMouseMoveEvent(QGraphicsSceneMouseEvent else rejectY = true; } - if (!rejectY) { + if (!rejectY && stealMouse) { _moveY.setValue(newY); moved = true; } @@ -709,7 +709,7 @@ void QDeclarativeFlickablePrivate::handleMouseMoveEvent(QGraphicsSceneMouseEvent else rejectX = true; } - if (!rejectX) { + if (!rejectX && stealMouse) { _moveX.setValue(newX); moved = true; } @@ -752,6 +752,8 @@ void QDeclarativeFlickablePrivate::handleMouseMoveEvent(QGraphicsSceneMouseEvent void QDeclarativeFlickablePrivate::handleMouseReleaseEvent(QGraphicsSceneMouseEvent *event) { Q_Q(QDeclarativeFlickable); + stealMouse = false; + q->setKeepMouseGrab(false); pressed = false; if (lastPosTime.isNull()) return; @@ -781,7 +783,6 @@ void QDeclarativeFlickablePrivate::handleMouseReleaseEvent(QGraphicsSceneMouseEv fixupX(); } - stealMouse = false; lastPosTime = QTime(); if (!timeline.isActive()) @@ -804,6 +805,8 @@ void QDeclarativeFlickable::mouseMoveEvent(QGraphicsSceneMouseEvent *event) Q_D(QDeclarativeFlickable); if (d->interactive) { d->handleMouseMoveEvent(event); + if (d->stealMouse) + setKeepMouseGrab(true); event->accept(); } else { QDeclarativeItem::mouseMoveEvent(event); @@ -1141,7 +1144,8 @@ bool QDeclarativeFlickable::sendMouseEvent(QGraphicsSceneMouseEvent *event) QGraphicsScene *s = scene(); QDeclarativeItem *grabber = s ? qobject_cast(s->mouseGrabberItem()) : 0; - if ((d->stealMouse || myRect.contains(event->scenePos().toPoint())) && (!grabber || !grabber->keepMouseGrab())) { + bool stealThisEvent = d->stealMouse; + if ((stealThisEvent || myRect.contains(event->scenePos().toPoint())) && (!grabber || !grabber->keepMouseGrab())) { mouseEvent.setAccepted(false); for (int i = 0x1; i <= 0x10; i <<= 1) { if (event->buttons() & i) { @@ -1176,17 +1180,19 @@ bool QDeclarativeFlickable::sendMouseEvent(QGraphicsSceneMouseEvent *event) break; } grabber = qobject_cast(s->mouseGrabberItem()); - if (grabber && d->stealMouse && !grabber->keepMouseGrab() && grabber != this) { + if (grabber && stealThisEvent && !grabber->keepMouseGrab() && grabber != this) { d->clearDelayedPress(); grabMouse(); } - return d->stealMouse || d->delayedPressEvent; + return stealThisEvent || d->delayedPressEvent; } else if (!d->lastPosTime.isNull()) { d->lastPosTime = QTime(); } - if (mouseEvent.type() == QEvent::GraphicsSceneMouseRelease) + if (mouseEvent.type() == QEvent::GraphicsSceneMouseRelease) { d->clearDelayedPress(); + d->stealMouse = false; + } return false; } -- cgit v0.12 From a2bddc74ca9d0c09f7c79077e0fbd981f1e9eccb Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Wed, 3 Mar 2010 13:05:28 +1000 Subject: Ensure error is received - the root object is INITIALLY zero. --- .../auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp index b677fec..dea88c4 100644 --- a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp +++ b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp @@ -663,10 +663,12 @@ void tst_qdeclarativetextedit::delegateLoading() QVERIFY(delegate); view->setSource(QUrl("http://localhost:42332/cursorHttpTestFail1.qml")); view->show(); + QTRY_VERIFY(view->status()==QDeclarativeView::Error); view->setFocus(); QTRY_VERIFY(!view->rootObject()); // there is fail item inside this test view->setSource(QUrl("http://localhost:42332/cursorHttpTestFail2.qml")); view->show(); + QTRY_VERIFY(view->status()==QDeclarativeView::Error); view->setFocus(); QTRY_VERIFY(!view->rootObject()); // there is fail item inside this test //ErrorB should get a component which is ready but component.create() returns null -- cgit v0.12 From 2623211c0cd47a08b0acbd17b5ba42c2222a9e25 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Wed, 3 Mar 2010 13:13:09 +1000 Subject: runnable from elsewhere --- .../declarative/qdeclarativepositioners/tst_qdeclarativepositioners.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/auto/declarative/qdeclarativepositioners/tst_qdeclarativepositioners.cpp b/tests/auto/declarative/qdeclarativepositioners/tst_qdeclarativepositioners.cpp index 3a8a892..d23d74c 100644 --- a/tests/auto/declarative/qdeclarativepositioners/tst_qdeclarativepositioners.cpp +++ b/tests/auto/declarative/qdeclarativepositioners/tst_qdeclarativepositioners.cpp @@ -365,7 +365,7 @@ void tst_QDeclarativePositioners::test_grid_animated() } void tst_QDeclarativePositioners::test_propertychanges() { - QDeclarativeView *canvas = createView("data/propertychanges.qml"); + QDeclarativeView *canvas = createView(SRCDIR "/data/propertychanges.qml"); QDeclarativeGrid *grid = qobject_cast(canvas->rootObject()); QDeclarativeTransition *rowTransition = canvas->rootObject()->findChild("rowTransition"); -- cgit v0.12 From e6e7dd15ca71d071ad3be5a0a5b300c44ca3070a Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Wed, 3 Mar 2010 13:14:37 +1000 Subject: remove debugger --- .../qdeclarativemoduleplugin/tst_qdeclarativemoduleplugin.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/auto/declarative/qdeclarativemoduleplugin/tst_qdeclarativemoduleplugin.cpp b/tests/auto/declarative/qdeclarativemoduleplugin/tst_qdeclarativemoduleplugin.cpp index f3caa7f..92f7aef 100644 --- a/tests/auto/declarative/qdeclarativemoduleplugin/tst_qdeclarativemoduleplugin.cpp +++ b/tests/auto/declarative/qdeclarativemoduleplugin/tst_qdeclarativemoduleplugin.cpp @@ -50,7 +50,6 @@ class tst_qdeclarativemoduleplugin : public QObject public: tst_qdeclarativemoduleplugin() { QCoreApplication::addLibraryPath(QLatin1String(SRCDIR) + QDir::separator() + QLatin1String("plugin")); -qDebug() << QLatin1String(SRCDIR) + QDir::separator() + QLatin1String("plugin"); } private slots: -- cgit v0.12 From 991398a5a921e1f01bb8966d3a6bf4f636a1fa62 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Wed, 3 Mar 2010 13:35:44 +1000 Subject: make runnable from elsewhere --- .../qdeclarativexmlhttprequest/tst_qdeclarativexmlhttprequest.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/auto/declarative/qdeclarativexmlhttprequest/tst_qdeclarativexmlhttprequest.cpp b/tests/auto/declarative/qdeclarativexmlhttprequest/tst_qdeclarativexmlhttprequest.cpp index 37d48fa..7dec0ee 100644 --- a/tests/auto/declarative/qdeclarativexmlhttprequest/tst_qdeclarativexmlhttprequest.cpp +++ b/tests/auto/declarative/qdeclarativexmlhttprequest/tst_qdeclarativexmlhttprequest.cpp @@ -1168,7 +1168,7 @@ void tst_qdeclarativexmlhttprequest::redirects() TestHTTPServer server(SERVER_PORT); QVERIFY(server.isValid()); server.addRedirect("redirect.html", "http://127.0.0.1:14445/redirecttarget.html"); - server.serveDirectory("data"); + server.serveDirectory(SRCDIR "/data"); QDeclarativeComponent component(&engine, TEST_FILE("redirects.qml")); QObject *object = component.beginCreate(engine.rootContext()); @@ -1187,7 +1187,7 @@ void tst_qdeclarativexmlhttprequest::redirects() TestHTTPServer server(SERVER_PORT); QVERIFY(server.isValid()); server.addRedirect("redirect.html", "http://127.0.0.1:14445/redirectmissing.html"); - server.serveDirectory("data"); + server.serveDirectory(SRCDIR "/data"); QDeclarativeComponent component(&engine, TEST_FILE("redirectError.qml")); QObject *object = component.beginCreate(engine.rootContext()); @@ -1206,7 +1206,7 @@ void tst_qdeclarativexmlhttprequest::redirects() TestHTTPServer server(SERVER_PORT); QVERIFY(server.isValid()); server.addRedirect("redirect.html", "http://127.0.0.1:14445/redirect.html"); - server.serveDirectory("data"); + server.serveDirectory(SRCDIR "/data"); QDeclarativeComponent component(&engine, TEST_FILE("redirectRecur.qml")); QObject *object = component.beginCreate(engine.rootContext()); -- cgit v0.12 From fdc857a176cf86970981e6d3c814725ca674b307 Mon Sep 17 00:00:00 2001 From: Joona Petrell Date: Wed, 3 Mar 2010 14:06:35 +1000 Subject: Add import Qt.widgets 4.6 to layout.qml example --- examples/declarative/layouts/layouts.qml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/declarative/layouts/layouts.qml b/examples/declarative/layouts/layouts.qml index accd969..4b2a3f8 100644 --- a/examples/declarative/layouts/layouts.qml +++ b/examples/declarative/layouts/layouts.qml @@ -1,5 +1,5 @@ import Qt 4.6 - +import Qt.widgets 4.6 Item { id: resizable width:400 -- cgit v0.12 From 24a695673cc53b224dd3fac44e924a41f8ea20a5 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Wed, 3 Mar 2010 14:22:45 +1000 Subject: Fix settings (was not exported type). --- src/imports/webkit/plugin.cpp | 1 + src/imports/webkit/qdeclarativewebview.cpp | 2 +- src/imports/webkit/qdeclarativewebview_p.h | 5 +++-- src/imports/webkit/qdeclarativewebview_p_p.h | 4 +++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/imports/webkit/plugin.cpp b/src/imports/webkit/plugin.cpp index 2f6205d..799fe9e 100644 --- a/src/imports/webkit/plugin.cpp +++ b/src/imports/webkit/plugin.cpp @@ -54,6 +54,7 @@ public: virtual void registerTypes(const char *uri) { Q_ASSERT(QLatin1String(uri) == QLatin1String("org.webkit")); + QML_REGISTER_NOCREATE_TYPE(QDeclarativeWebSettings); qmlRegisterType(uri,1,0,"WebView"); } }; diff --git a/src/imports/webkit/qdeclarativewebview.cpp b/src/imports/webkit/qdeclarativewebview.cpp index 733ac86..d78ba28 100644 --- a/src/imports/webkit/qdeclarativewebview.cpp +++ b/src/imports/webkit/qdeclarativewebview.cpp @@ -931,7 +931,7 @@ QWebPage *QDeclarativeWebView::page() const } \endqml */ -QObject *QDeclarativeWebView::settingsObject() const +QDeclarativeWebSettings *QDeclarativeWebView::settingsObject() const { Q_D(const QDeclarativeWebView); d->settings.s = page()->settings(); diff --git a/src/imports/webkit/qdeclarativewebview_p.h b/src/imports/webkit/qdeclarativewebview_p.h index 5efc3b5..145e74b 100644 --- a/src/imports/webkit/qdeclarativewebview_p.h +++ b/src/imports/webkit/qdeclarativewebview_p.h @@ -59,6 +59,7 @@ class QWebSettings; QT_BEGIN_NAMESPACE QT_MODULE(Declarative) +class QDeclarativeWebSettings; class QDeclarativeWebViewPrivate; class QNetworkRequest; class QDeclarativeWebView; @@ -113,7 +114,7 @@ class WEBKITQMLPLUGIN_EXPORT QDeclarativeWebView : public QDeclarativePaintedIte Q_PROPERTY(QAction* forward READ forwardAction CONSTANT) Q_PROPERTY(QAction* stop READ stopAction CONSTANT) - Q_PROPERTY(QObject* settings READ settingsObject CONSTANT) + Q_PROPERTY(QDeclarativeWebSettings* settings READ settingsObject CONSTANT) Q_PROPERTY(QDeclarativeListProperty javaScriptWindowObjects READ javaScriptWindowObjects CONSTANT) @@ -170,7 +171,7 @@ public: QWebHistory *history() const; QWebSettings *settings() const; - QObject *settingsObject() const; + QDeclarativeWebSettings *settingsObject() const; bool renderingEnabled() const; void setRenderingEnabled(bool); diff --git a/src/imports/webkit/qdeclarativewebview_p_p.h b/src/imports/webkit/qdeclarativewebview_p_p.h index 258b472..3ad9e9a 100644 --- a/src/imports/webkit/qdeclarativewebview_p_p.h +++ b/src/imports/webkit/qdeclarativewebview_p_p.h @@ -42,6 +42,8 @@ #ifndef QDECLARATIVEWEBVIEW_P_H #define QDECLARATIVEWEBVIEW_P_H +#include "webkitqmlplugin_export.h" + #include #include @@ -52,7 +54,7 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) -class QDeclarativeWebSettings : public QObject { +class WEBKITQMLPLUGIN_EXPORT QDeclarativeWebSettings : public QObject { Q_OBJECT Q_PROPERTY(QString standardFontFamily READ standardFontFamily WRITE setStandardFontFamily) -- cgit v0.12 From 4e5cf3f0936ed921973e451e23414059e1a9fc6b Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Wed, 3 Mar 2010 14:36:48 +1000 Subject: add colorbrowser qml example This example shows how to use qml packages to animate between pathview, gridview and listview. --- examples/declarative/colorbrowser/colorbrowser.qml | 101 ++++++++++++++++++ .../colorbrowser/dummydata/ColorsModel.qml | 96 +++++++++++++++++ .../declarative/colorbrowser/qml/ColorDelegate.qml | 114 +++++++++++++++++++++ .../declarative/colorbrowser/qml/box-shadow.png | Bin 0 -> 871 bytes examples/declarative/colorbrowser/qml/box.png | Bin 0 -> 765 bytes 5 files changed, 311 insertions(+) create mode 100644 examples/declarative/colorbrowser/colorbrowser.qml create mode 100644 examples/declarative/colorbrowser/dummydata/ColorsModel.qml create mode 100644 examples/declarative/colorbrowser/qml/ColorDelegate.qml create mode 100644 examples/declarative/colorbrowser/qml/box-shadow.png create mode 100644 examples/declarative/colorbrowser/qml/box.png diff --git a/examples/declarative/colorbrowser/colorbrowser.qml b/examples/declarative/colorbrowser/colorbrowser.qml new file mode 100644 index 0000000..ebd49c6 --- /dev/null +++ b/examples/declarative/colorbrowser/colorbrowser.qml @@ -0,0 +1,101 @@ +import Qt 4.6 +import 'qml' + +Rectangle { + id: mainWindow + width: 800; height: 480; color: '#454545' + + VisualDataModel { id: colorsVisualModel; delegate: colorsDelegate; model: ColorsModel } + + Component { + id: colorsDelegate + Package { + + Item { + Package.name: 'grid' + GridView { + id: gridView; model: visualModel.parts.grid; width: mainWindow.width; height: mainWindow.height + cellWidth: 160; cellHeight: 160; interactive: false + onCurrentIndexChanged: listView.positionViewAtIndex(currentIndex) + } + } + + Item { + Package.name: 'fullscreen' + ListView { + id: listView; model: visualModel.parts.list; orientation: Qt.Horizontal + width: mainWindow.width; height: mainWindow.height; interactive: false + onCurrentIndexChanged: gridView.positionViewAtIndex(currentIndex) + highlightRangeMode: ListView.StrictlyEnforceRange; snapMode: ListView.SnapOneItem + } + } + + Item { + Package.name: 'stack' + id: wrapper + width: 260; height: 240 + + VisualDataModel { id: visualModel; model: colors; delegate: ColorDelegate {} } + + PathView { + id: pathView; model: visualModel.parts.stack; anchors.centerIn: parent + pathItemCount: 3 + path: Path { + PathAttribute { name: 'z'; value: 9999.0 } + PathLine { x: 1; y: 1 } + PathAttribute { name: 'z'; value: 0.0 } + } + } + + Item { + anchors.horizontalCenter: parent.horizontalCenter; anchors.bottom: parent.bottom; anchors.bottomMargin: 20 + width: albumTitle.width + 20 ; height: albumTitle.height + 4 + Text { id: albumTitle; text: name; color: 'white'; font.bold: true; anchors.centerIn: parent } + } + + MouseRegion { anchors.fill: parent; onClicked: wrapper.state = 'inGrid' } + + states: [ + State { + name: 'inGrid' + PropertyChanges { target: gridView; interactive: true } + PropertyChanges { target: shade; opacity: 1 } + }, + State { + name: 'fullscreen'; extend: 'inGrid' + PropertyChanges { target: gridView; interactive: false } + PropertyChanges { target: listView; interactive: true } + PropertyChanges { target: infobox; opacity: 1 } + } + ] + + transitions: [ + Transition { + from: ''; to: 'inGrid'; reversible: true + NumberAnimation { target: shade; properties: 'opacity'; duration: 300 } + }, + Transition { + from: 'inGrid'; to: 'fullscreen'; reversible: true + SequentialAnimation { + PauseAnimation { duration: 300 } + NumberAnimation { target: infobox; properties: 'opacity'; duration: 300 } + } + } + ] + } + } + } + + GridView { width: parent.width; height: parent.height; cellWidth: 260; cellHeight: 240; model: colorsVisualModel.parts.stack } + Rectangle { id: shade; color: '#454545'; width: parent.width; height: parent.height; opacity: 0 } + ListView { anchors.fill: parent; model: colorsVisualModel.parts.grid; interactive: false } + ListView { anchors.fill: parent; model: colorsVisualModel.parts.fullscreen; interactive: false } + Item { id: foreground; anchors.fill: parent } + + Column { + id: infobox; opacity: 0 + anchors { left: parent.left; leftMargin: 20; bottom: parent.bottom; bottomMargin: 20 } + Text { id: infoColorName; color: '#eeeeee'; style: Text.Outline; styleColor: '#222222'; font.pointSize: 18 } + Text { id: infoColorHex; color: '#eeeeee'; style: Text.Outline; styleColor: '#222222'; font.pointSize: 14 } + } +} diff --git a/examples/declarative/colorbrowser/dummydata/ColorsModel.qml b/examples/declarative/colorbrowser/dummydata/ColorsModel.qml new file mode 100644 index 0000000..eefbcfe --- /dev/null +++ b/examples/declarative/colorbrowser/dummydata/ColorsModel.qml @@ -0,0 +1,96 @@ +import Qt 4.6 + +ListModel { + id: colorsModel + + ListElement { + name: "Reds" + colors: [ + ListElement { name: "Fire Brick"; hex: "#B22222" }, + ListElement { name: "Fire Brick 1"; hex: "#FF3030" }, + ListElement { name: "Fire Brick 2"; hex: "#EE2C2C" }, + ListElement { name: "Fire Brick 3"; hex: "#CD2626" }, + ListElement { name: "Fire Brick 4"; hex: "#8B1A1A" }, + ListElement { name: "Red"; hex: "#FF0000" }, + ListElement { name: "Red 2"; hex: "#EE0000" }, + ListElement { name: "Red 3"; hex: "#CD0000" }, + ListElement { name: "Red 4"; hex: "#8B0000" }, + ListElement { name: "Tomato"; hex: "#FF6347" }, + ListElement { name: "Tomato 2"; hex: "#EE5C42" }, + ListElement { name: "Tomato 3"; hex: "#CD4F39" }, + ListElement { name: "Tomato 4"; hex: "#8B3626" }, + ListElement { name: "Orange Red"; hex: "#FF4500" }, + ListElement { name: "Orange Red 2"; hex: "#EE4000" }, + ListElement { name: "Orange Red 3"; hex: "#CD3700" }, + ListElement { name: "Orange Red 4"; hex: "#8B2500" }, + ListElement { name: "Indian Red 2"; hex: "#EE6363" }, + ListElement { name: "Indian Red 3"; hex: "#CD5555" }, + ListElement { name: "Indian Red 4"; hex: "#8B3A3A" }, + ListElement { name: "Brown"; hex: "#A52A2A" }, + ListElement { name: "Brown 1"; hex: "#FF4040" }, + ListElement { name: "Brown 2"; hex: "#EE3B3B" }, + ListElement { name: "Brown 3"; hex: "#CD3333" }, + ListElement { name: "Brown 4"; hex: "#8B2323" } + ] + } + ListElement { + name: "Greens" + colors: [ + ListElement { name: "Green"; hex: "#008000" }, + ListElement { name: "Green 2"; hex: "#00EE00" }, + ListElement { name: "Green 3"; hex: "#00CD00" }, + ListElement { name: "Green 4"; hex: "#008B00" }, + ListElement { name: "Dark Green"; hex: "#006400" }, + ListElement { name: "Sap Green"; hex: "#308014" }, + ListElement { name: "Medium Spring Green"; hex: "#00FA9A" }, + ListElement { name: "Spring Green"; hex: "#00FF7F" }, + ListElement { name: "Spring Green 1"; hex: "#00EE76" }, + ListElement { name: "Spring Green 2"; hex: "#00CD66" }, + ListElement { name: "Spring Green 3"; hex: "#008B45" }, + ListElement { name: "Medium Sea Green"; hex: "#3CB371" }, + ListElement { name: "Sea Green 1"; hex: "#54FF9F" }, + ListElement { name: "Sea Green 2"; hex: "#4EEE94" }, + ListElement { name: "Sea Green 3"; hex: "#43CD80" }, + ListElement { name: "Sea Green 4"; hex: "#2E8B57" }, + ListElement { name: "Emerald Green"; hex: "#00C957" }, + ListElement { name: "Mint"; hex: "#BDFCC9" }, + ListElement { name: "Cobalt Green"; hex: "#3D9140" }, + ListElement { name: "Dark Sea Green"; hex: "#8FBC8F" }, + ListElement { name: "Dark Sea Green 1"; hex: "#C1FFC1" }, + ListElement { name: "Dark Sea Green 2"; hex: "#B4EEB4" }, + ListElement { name: "Dark Sea Green 3"; hex: "#9BCD9B" }, + ListElement { name: "Dark Sea Green 4"; hex: "#698B69" }, + ListElement { name: "Lime Green"; hex: "#00FF00" } + ] + } + ListElement { + name: "Blues" + colors: [ + ListElement { name: "Dark Slate Blue"; hex: "#483D8B" }, + ListElement { name: "Light Slate Blue"; hex: "#8470FF" }, + ListElement { name: "Medium Slate Blue"; hex: "#7B68EE" }, + ListElement { name: "Slate Blue"; hex: "#6A5ACD" }, + ListElement { name: "Blue"; hex: "#0000FF" }, + ListElement { name: "Midnight Blue"; hex: "#191970" }, + ListElement { name: "Cobalt"; hex: "#3D59AB" }, + ListElement { name: "Royal Blue"; hex: "#4169E1" }, + ListElement { name: "Corn Flower Blue"; hex: "#6495ED" }, + ListElement { name: "Light Steel Blue"; hex: "#B0C4DE" }, + ListElement { name: "Light Steel Blue 1"; hex: "#CAE1FF" }, + ListElement { name: "Light Steel Blue 2"; hex: "#BCD2EE" }, + ListElement { name: "Light Steel Blue 3"; hex: "#A2B5CD" }, + ListElement { name: "Dodger Blue"; hex: "#1E90FF" }, + ListElement { name: "Dodger Blue 2"; hex: "#1C86EE" }, + ListElement { name: "Dodger Blue 3"; hex: "#1874CD" }, + ListElement { name: "Dodger Blue 4"; hex: "#104E8B" }, + ListElement { name: "Steel Blue"; hex: "#4682B4" }, + ListElement { name: "Light Sky Blue"; hex: "#87CEFA" }, + ListElement { name: "Sky Blue"; hex: "#87CEEB" }, + ListElement { name: "Peacock"; hex: "#33A1C9" }, + ListElement { name: "Light Blue"; hex: "#ADD8E6" }, + ListElement { name: "Powder Blue"; hex: "#B0E0E6" }, + ListElement { name: "Cadet Blue"; hex: "#5F9EA0" }, + ListElement { name: "Cyan"; hex: "#00FFFF" } + ] + } +} diff --git a/examples/declarative/colorbrowser/qml/ColorDelegate.qml b/examples/declarative/colorbrowser/qml/ColorDelegate.qml new file mode 100644 index 0000000..605e45b --- /dev/null +++ b/examples/declarative/colorbrowser/qml/ColorDelegate.qml @@ -0,0 +1,114 @@ +import Qt 4.6 + +Package { + Item { id: stack; Package.name: 'stack'; width: 110; height: 110; z: stack.PathView.z } + Item { id: list; Package.name: 'list'; width: mainWindow.width + 4; height: 110 } + Item { id: grid; Package.name: 'grid'; width: 110; height: 110 } + + Item { + id: delegate + + property double randomAngle: Math.random() * (2 * 8 + 1) - 8 + property bool open: false + + width: 110; height: 110; z: stack.PathView.z + + Image { x: -6; y: -5; source: 'box-shadow.png'; smooth: true; } + Rectangle { color: hex; anchors.fill: parent; smooth: true } + Image { id: box; source: 'box.png'; smooth: true; anchors.fill: parent } + + Binding { + target: infoColorName; property: 'text' + value: name; when: delegate.open && list.ListView.isCurrentItem + } + + Binding { + target: infoColorHex; property: 'text' + value: hex; when: delegate.open && list.ListView.isCurrentItem + } + + MouseRegion { + anchors.fill: parent + acceptedButtons: Qt.RightButton | Qt.LeftButton + onClicked: { + if (wrapper.state == 'inGrid' && mouse.button == Qt.RightButton) { + wrapper.state = '' + } else if (wrapper.state == 'inGrid') { + grid.GridView.view.currentIndex = index; + wrapper.state = 'fullscreen' + } else { + grid.GridView.view.currentIndex = index; + wrapper.state = 'inGrid' + } + } + } + + states: [ + State { + name: 'stacked'; when: wrapper.state == '' + ParentChange { target: delegate; parent: stack; x: 0; y: 0; rotation: delegate.randomAngle } + PropertyChanges { target: delegate; visible: stack.PathView.onPath ? 1.0 : 0.0 } + }, + State { + name: 'inGrid'; when: wrapper.state == 'inGrid' + ParentChange { target: delegate; parent: grid; x: 24; y: 24 } + PropertyChanges { target: delegate; open: true } + }, + State { + name: 'fullscreen'; when: wrapper.state == 'fullscreen' + ParentChange { target: delegate; parent: list; x: 0; y: 0; width: mainWindow.width; height: mainWindow.height } + PropertyChanges { target: box; opacity: 0 } + PropertyChanges { target: delegate; open: true } + } + ] + + transitions: [ + Transition { + from: 'stacked'; to: 'inGrid' + SequentialAnimation { + PauseAnimation { duration: 20 * index } + ParentAnimation { + target: delegate; via: foreground + NumberAnimation { targets: delegate; properties: 'x,y,width,height,rotation'; duration: 600; easing.type: 'OutBack' } + } + } + }, + Transition { + from: 'inGrid'; to: 'stacked' + ParentAnimation { + target: delegate; via: foreground + NumberAnimation { properties: 'x,y,width,height,rotation'; duration: 300; easing.type: 'InOutQuad' } + } + }, + Transition { + from: 'inGrid'; to: 'fullscreen' + SequentialAnimation { + PauseAnimation { duration: grid.GridView.isCurrentItem ? 0 : 300 } + ParentAnimation { + target: delegate; via: foreground + NumberAnimation { + properties: 'x,y,width,height,opacity' + duration: grid.GridView.isCurrentItem ? 300 : 1; easing.type: 'InOutQuad' + } + } + } + }, + Transition { + from: 'fullscreen'; to: 'inGrid' + SequentialAnimation { + PauseAnimation { duration: grid.GridView.isCurrentItem ? 3 : 0 } + ParallelAnimation { + ParentAnimation { + target: delegate; via: foreground + NumberAnimation { + properties: 'x,y,width,height' + duration: grid.GridView.isCurrentItem ? 300 : 1; easing.type: 'InOutQuad' + } + } + NumberAnimation { properties: 'opacity'; duration: grid.GridView.isCurrentItem ? 300 : 1; easing.type: 'InOutQuad' } + } + } + } + ] + } +} diff --git a/examples/declarative/colorbrowser/qml/box-shadow.png b/examples/declarative/colorbrowser/qml/box-shadow.png new file mode 100644 index 0000000..3281a37 Binary files /dev/null and b/examples/declarative/colorbrowser/qml/box-shadow.png differ diff --git a/examples/declarative/colorbrowser/qml/box.png b/examples/declarative/colorbrowser/qml/box.png new file mode 100644 index 0000000..86538aa Binary files /dev/null and b/examples/declarative/colorbrowser/qml/box.png differ -- cgit v0.12 From 7d4000b8df8792d286a50a3fac45ce638d943fd7 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Wed, 3 Mar 2010 14:39:17 +1000 Subject: silence debuggery --- .../qdeclarativenumberformatter/tst_qdeclarativenumberformatter.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/auto/declarative/qdeclarativenumberformatter/tst_qdeclarativenumberformatter.cpp b/tests/auto/declarative/qdeclarativenumberformatter/tst_qdeclarativenumberformatter.cpp index 26ff3d5..a9a0077 100644 --- a/tests/auto/declarative/qdeclarativenumberformatter/tst_qdeclarativenumberformatter.cpp +++ b/tests/auto/declarative/qdeclarativenumberformatter/tst_qdeclarativenumberformatter.cpp @@ -172,9 +172,11 @@ tst_qdeclarativenumberformatter::tst_qdeclarativenumberformatter() << "00,000,001.0000" << "00,000,001.0100"; // end + /* qDebug() << "strings.size()" << strings.size() << "\nformats.size()" << formats.size() << "texts.size()" << texts.size(); + */ } void tst_qdeclarativenumberformatter::text_data() -- cgit v0.12 From 6e486bdd5cc8370df7752eda2fa9f75b0a962124 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Wed, 3 Mar 2010 14:43:38 +1000 Subject: Disable until plugin objects problem resolved. --- tests/auto/declarative/qdeclarativewebview/tst_qdeclarativewebview.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/auto/declarative/qdeclarativewebview/tst_qdeclarativewebview.cpp b/tests/auto/declarative/qdeclarativewebview/tst_qdeclarativewebview.cpp index 1d6bedc..f2ea076 100644 --- a/tests/auto/declarative/qdeclarativewebview/tst_qdeclarativewebview.cpp +++ b/tests/auto/declarative/qdeclarativewebview/tst_qdeclarativewebview.cpp @@ -181,6 +181,8 @@ void tst_qdeclarativewebview::settings() QVERIFY(wv != 0); QTRY_COMPARE(wv->property("progress").toDouble(), 1.0); + qWarning("Need to test settings"); + /* QObject *s = qvariant_cast(wv->property("settings")); // merely tests that setting gets stored (in QWebSettings) @@ -236,6 +238,7 @@ void tst_qdeclarativewebview::settings() QVERIFY(s->property("privateBrowsingEnabled") == on); QVERIFY(s->property("zoomTextOnly") == on); } + */ } void tst_qdeclarativewebview::historyNav() -- cgit v0.12 From a2c2a287e6c405200ef990f3dddae9d229aac722 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Wed, 3 Mar 2010 14:36:17 +1000 Subject: Fix incorrect scope resolution for script in a script block. Make sure global variables in a script file are searched before component properties. Task-number: QTBUG-8641 --- src/declarative/qml/qdeclarativecontext.cpp | 1 + .../declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/declarative/qml/qdeclarativecontext.cpp b/src/declarative/qml/qdeclarativecontext.cpp index b244cd8..57ef90c 100644 --- a/src/declarative/qml/qdeclarativecontext.cpp +++ b/src/declarative/qml/qdeclarativecontext.cpp @@ -78,6 +78,7 @@ void QDeclarativeContextPrivate::addScript(const QDeclarativeParser::Object::Scr QScriptValue scope = scriptEngine->newObject(); scriptContext->setActivationObject(scope); + scriptContext->pushScope(scope); for (int ii = 0; ii < script.codes.count(); ++ii) { scriptEngine->evaluate(script.codes.at(ii), script.files.at(ii), script.lineNumbers.at(ii)); diff --git a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp index 8e7944d..85a3ef3 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp +++ b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp @@ -1678,7 +1678,6 @@ void tst_qdeclarativeecmascript::scriptScope() MyQmlObject *object = qobject_cast(component.create()); QVERIFY(object != 0); emit object->basicSignal(); - QEXPECT_FAIL("", "QTBUG-8641", Continue); QCOMPARE(object->property("result").toString(), QLatin1String("world")); delete object; -- cgit v0.12 From a40a5fde406855473ba5f4cfa78208ee5efd9cb1 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Wed, 3 Mar 2010 14:58:55 +1000 Subject: fix crash, re-enable settings test --- .../declarative/qdeclarativewebview/tst_qdeclarativewebview.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/auto/declarative/qdeclarativewebview/tst_qdeclarativewebview.cpp b/tests/auto/declarative/qdeclarativewebview/tst_qdeclarativewebview.cpp index f2ea076..b63e14b 100644 --- a/tests/auto/declarative/qdeclarativewebview/tst_qdeclarativewebview.cpp +++ b/tests/auto/declarative/qdeclarativewebview/tst_qdeclarativewebview.cpp @@ -181,9 +181,8 @@ void tst_qdeclarativewebview::settings() QVERIFY(wv != 0); QTRY_COMPARE(wv->property("progress").toDouble(), 1.0); - qWarning("Need to test settings"); - /* - QObject *s = qvariant_cast(wv->property("settings")); + QObject *s = QDeclarativeProperty(wv,"settings").object(); + QVERIFY(s != 0); // merely tests that setting gets stored (in QWebSettings) // behavioural tests are in WebKit. @@ -238,7 +237,6 @@ void tst_qdeclarativewebview::settings() QVERIFY(s->property("privateBrowsingEnabled") == on); QVERIFY(s->property("zoomTextOnly") == on); } - */ } void tst_qdeclarativewebview::historyNav() -- cgit v0.12 From 004f77f8ab4d07499116d151d6f2b015b57effac Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Wed, 3 Mar 2010 14:59:18 +1000 Subject: OS-friendlier, less noisy. --- tests/auto/declarative/runall.sh | 81 ++++++++++++++++++++++++++-------------- 1 file changed, 52 insertions(+), 29 deletions(-) diff --git a/tests/auto/declarative/runall.sh b/tests/auto/declarative/runall.sh index 39485d3..62e03e3 100755 --- a/tests/auto/declarative/runall.sh +++ b/tests/auto/declarative/runall.sh @@ -41,37 +41,60 @@ ## ############################################################################/ -Xnest :7 2>/dev/null & -sleep 1 -trap "kill $!" EXIT -export DISPLAY=:7 +if [ "$(uname)" = Linux ] +then + Xnest :7 2>/dev/null & + sleep 1 + trap "kill $!" EXIT + export DISPLAY=:7 + export LANG=en_US + kwin 2>/dev/null & + sleep 1 +fi -( make -k -j1 install 2>&1; - for exe in $(make install | sed -n 's/^install .* "\([^"]*qt4\/tst_[^"]*\)".*/\1/p') - do - $exe - done -) | +function filter +{ + exe=$1 + skip=0 while read line do - case "$line" in - make*Error) echo "$line";; - make*Stop) echo "$line";; - make*) ;; - install*) ;; - */qmake*) ;; - */bin/moc*) ;; - *targ.debug*) ;; - g++*) ;; - cd*) ;; - PASS*) ;; - QDEBUG*) ;; - Makefile*) ;; - Config*) ;; - Totals*) ;; - \**) ;; - ./*) ;; - *) echo "$line" - esac + if [ $skip != 0 ] + then + let skip=skip-1 + else + case "$line" in + make*Error) echo "$line";; + make*Stop) echo "$line";; + /*/bin/make*) ;; + make*) ;; + install*) ;; + QDeclarativeDebugServer:*Waiting*) ;; + QDeclarativeDebugServer:*Connection*) ;; + */qmake*) ;; + */bin/moc*) ;; + *targ.debug*) ;; + g++*) ;; + cd*) ;; + XFAIL*) skip=1;; + SKIP*) skip=1;; + PASS*) ;; + QDEBUG*) ;; + Makefile*) ;; + Config*) ;; + Totals*) ;; + \**) ;; + ./*) ;; + *tst_*) echo "$line" ;; + *) echo "$exe: $line" + esac + fi done +} + +make -k -j1 install 2>&1 | filter build +for exe in $(make install | sed -n 's/^install .* "\([^"]*qt4\/tst_[^"]*\)".*/\1/p') +do + echo $exe + $exe 2>&1 | filter $exe +done -- cgit v0.12 From 2ef17050f740b4e0debc43f66f26f419b317b7ab Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Wed, 3 Mar 2010 15:15:47 +1000 Subject: QDeclarativeGuard should handle objects being deleted --- src/declarative/qml/qdeclarativedeclarativedata_p.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/declarative/qml/qdeclarativedeclarativedata_p.h b/src/declarative/qml/qdeclarativedeclarativedata_p.h index a7a73bc..ae40130 100644 --- a/src/declarative/qml/qdeclarativedeclarativedata_p.h +++ b/src/declarative/qml/qdeclarativedeclarativedata_p.h @@ -120,6 +120,11 @@ public: template void QDeclarativeGuard::addGuard() { + if (QObjectPrivate::get(o)->wasDeleted) { + if (prev) remGuard(); + return; + } + QDeclarativeDeclarativeData *data = QDeclarativeDeclarativeData::get(o, true); next = data->guards; if (next) reinterpret_cast *>(next)->prev = &next; -- cgit v0.12 From 0b44693aec2eed33cb54876edb7641e981aa883c Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Wed, 3 Mar 2010 16:16:43 +1000 Subject: 4.6.x compat --- src/declarative/graphicsitems/qdeclarativeparticles.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/declarative/graphicsitems/qdeclarativeparticles.cpp b/src/declarative/graphicsitems/qdeclarativeparticles.cpp index 1a58d3f..deabdd6 100644 --- a/src/declarative/graphicsitems/qdeclarativeparticles.cpp +++ b/src/declarative/graphicsitems/qdeclarativeparticles.cpp @@ -1260,7 +1260,11 @@ void QDeclarativeParticlesPainter::paint(QPainter *p, const QStyleOptionGraphics const int myX = x() + parentItem()->x(); const int myY = y() + parentItem()->y(); +#if (QT_VERSION >= QT_VERSION_CHECK(4,7,0)) QVarLengthArray pixmapData; +#else + QVarLengthArray pixmapData; +#endif pixmapData.resize(d->particles.count()); const QRectF sourceRect = d->image.rect(); @@ -1268,20 +1272,32 @@ void QDeclarativeParticlesPainter::paint(QPainter *p, const QStyleOptionGraphics qreal halfPHeight = sourceRect.height()/2.; for (int i = 0; i < d->particles.count(); ++i) { const QDeclarativeParticle &particle = d->particles.at(i); +#if (QT_VERSION >= QT_VERSION_CHECK(4,7,0)) pixmapData[i].x = particle.x - myX + halfPWidth; pixmapData[i].y = particle.y - myY + halfPHeight; +#else + pixmapData[i].point = QPointF(particle.x - myX + halfPWidth, particle.y - myY + halfPHeight); +#endif pixmapData[i].opacity = particle.opacity; //these never change pixmapData[i].rotation = 0; pixmapData[i].scaleX = 1; pixmapData[i].scaleY = 1; +#if (QT_VERSION >= QT_VERSION_CHECK(4,7,0)) pixmapData[i].sourceLeft = sourceRect.left(); pixmapData[i].sourceTop = sourceRect.top(); pixmapData[i].width = sourceRect.width(); pixmapData[i].height = sourceRect.height(); +#else + pixmapData[i].source = sourceRect; +#endif } +#if (QT_VERSION >= QT_VERSION_CHECK(4,7,0)) p->drawPixmapFragments(pixmapData.data(), d->particles.count(), d->image); +#else + qDrawPixmaps(p, pixmapData.data(), d->particles.count(), d->image); +#endif } void QDeclarativeParticles::componentComplete() -- cgit v0.12 From 7d2471e3beba5745fb5ea4dade3188e643f6b562 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 3 Mar 2010 16:25:21 +1000 Subject: Auto test for QTBUG-8677 --- .../declarative/qdeclarativelanguage/data/attachedProperties.qml | 2 ++ tests/auto/declarative/qdeclarativelanguage/testtypes.h | 7 +++++-- .../declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp | 5 +++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/auto/declarative/qdeclarativelanguage/data/attachedProperties.qml b/tests/auto/declarative/qdeclarativelanguage/data/attachedProperties.qml index b46ec34..aecb3c3 100644 --- a/tests/auto/declarative/qdeclarativelanguage/data/attachedProperties.qml +++ b/tests/auto/declarative/qdeclarativelanguage/data/attachedProperties.qml @@ -3,6 +3,8 @@ import Test 1.0 as Namespace import Qt 4.6 QtObject { + property int value2: 8 MyQmlObject.value: 10 Namespace.MyQmlObject.value2: 13 + MyQmlObject.onValueChanged: value2 = MyQmlObject.value } diff --git a/tests/auto/declarative/qdeclarativelanguage/testtypes.h b/tests/auto/declarative/qdeclarativelanguage/testtypes.h index ec2c5f7..08d6d96 100644 --- a/tests/auto/declarative/qdeclarativelanguage/testtypes.h +++ b/tests/auto/declarative/qdeclarativelanguage/testtypes.h @@ -75,17 +75,20 @@ Q_DECLARE_METATYPE(MyCustomVariantType); class MyAttachedObject : public QObject { Q_OBJECT - Q_PROPERTY(int value READ value WRITE setValue) + Q_PROPERTY(int value READ value WRITE setValue NOTIFY valueChanged) Q_PROPERTY(int value2 READ value2 WRITE setValue2) public: MyAttachedObject(QObject *parent) : QObject(parent), m_value(0), m_value2(0) {} int value() const { return m_value; } - void setValue(int v) { m_value = v; } + void setValue(int v) { if (m_value != v) { m_value = v; emit valueChanged(); } } int value2() const { return m_value2; } void setValue2(int v) { m_value2 = v; } +signals: + void valueChanged(); + private: int m_value; int m_value2; diff --git a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp index 39f5223..870f3fe 100644 --- a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp +++ b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp @@ -713,6 +713,11 @@ void tst_qdeclarativelanguage::attachedProperties() QVERIFY(attached != 0); QCOMPARE(attached->property("value"), QVariant(10)); QCOMPARE(attached->property("value2"), QVariant(13)); + + QEXPECT_FAIL("", "QTBUG-8677", Abort); + attached->setProperty("value", QVariant(12)); + int val = object->property("value2").toInt(); + QCOMPARE(val, 12); } // Tests non-static object properties -- cgit v0.12 From dba7eb104f7788fda36e8a2ecffc8f4c08ec1fae Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Wed, 3 Mar 2010 16:59:04 +1000 Subject: Add documentation for the 'when' property of Binding. --- src/declarative/util/qdeclarativebind.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/declarative/util/qdeclarativebind.cpp b/src/declarative/util/qdeclarativebind.cpp index e95a03e..26baa38 100644 --- a/src/declarative/util/qdeclarativebind.cpp +++ b/src/declarative/util/qdeclarativebind.cpp @@ -72,7 +72,7 @@ public: /*! \qmlclass Binding QDeclarativeBind - \since 4.7 + \since 4.7 \brief The Binding element allows arbitrary property bindings to be created. Sometimes it is necessary to bind to a property of an object that wasn't @@ -114,6 +114,19 @@ QDeclarativeBind::~QDeclarativeBind() { } +/*! + \qmlproperty bool Binding::when + + This property holds when the binding is active. + This should be set to an expression that evaluates to true when you want the binding to be active. + + \code + Binding { + target: contactName; property: 'text' + value: name; when: list.ListView.isCurrentItem + } + \endcode +*/ bool QDeclarativeBind::when() const { Q_D(const QDeclarativeBind); -- cgit v0.12 From 4690084e9f3fbf3635aa3fb6a8025ae046672aea Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Wed, 3 Mar 2010 17:14:07 +1000 Subject: Move JS global scope to top of the QML scope chain QT-2787 --- src/declarative/qml/qdeclarativecompiler.cpp | 62 +++++++++++----------- src/declarative/qml/qdeclarativecompiler_p.h | 2 +- src/declarative/qml/qdeclarativecontext.cpp | 3 ++ src/declarative/qml/qdeclarativeexpression.cpp | 5 ++ .../qml/qdeclarativeglobalscriptclass.cpp | 15 ++++-- .../qml/qdeclarativeglobalscriptclass_p.h | 7 ++- .../qdeclarativeecmascript/data/scope.3.qml | 13 +++++ .../tst_qdeclarativeecmascript.cpp | 10 ++++ .../data/invalidID.2.errors.txt | 2 +- .../data/invalidID.6.errors.txt | 2 +- .../data/invalidID.7.errors.txt | 1 + .../qdeclarativelanguage/data/invalidID.7.qml | 5 ++ .../data/invalidID.8.errors.txt | 1 + .../qdeclarativelanguage/data/invalidID.8.qml | 5 ++ .../data/invalidID.9.errors.txt | 1 + .../qdeclarativelanguage/data/invalidID.9.qml | 5 ++ .../qdeclarativelanguage/data/invalidID.errors.txt | 2 +- .../tst_qdeclarativelanguage.cpp | 6 +-- 18 files changed, 103 insertions(+), 44 deletions(-) create mode 100644 tests/auto/declarative/qdeclarativeecmascript/data/scope.3.qml create mode 100644 tests/auto/declarative/qdeclarativelanguage/data/invalidID.7.errors.txt create mode 100644 tests/auto/declarative/qdeclarativelanguage/data/invalidID.7.qml create mode 100644 tests/auto/declarative/qdeclarativelanguage/data/invalidID.8.errors.txt create mode 100644 tests/auto/declarative/qdeclarativelanguage/data/invalidID.8.qml create mode 100644 tests/auto/declarative/qdeclarativelanguage/data/invalidID.9.errors.txt create mode 100644 tests/auto/declarative/qdeclarativelanguage/data/invalidID.9.qml diff --git a/src/declarative/qml/qdeclarativecompiler.cpp b/src/declarative/qml/qdeclarativecompiler.cpp index a9809c0..1eea012 100644 --- a/src/declarative/qml/qdeclarativecompiler.cpp +++ b/src/declarative/qml/qdeclarativecompiler.cpp @@ -65,6 +65,7 @@ #include "qdeclarativescriptparser_p.h" #include "qdeclarativebinding_p.h" #include "qdeclarativecompiledbindings_p.h" +#include "qdeclarativeglobalscriptclass_p.h" #include @@ -113,32 +114,6 @@ QList QDeclarativeCompiler::errors() const } /*! - Returns true if \a val is a legal object id, false otherwise. - - Legal ids must start with a lower-case letter or underscore, and contain only - letters, numbers and underscores. -*/ -bool QDeclarativeCompiler::isValidId(const QString &val) -{ - if (val.isEmpty()) - return false; - - if (val.at(0).isLetter() && !val.at(0).isLower()) { - qWarning().nospace() << "id " << val << " is invalid: ids cannot start with uppercase letters"; - return false; - } - - QChar u(QLatin1Char('_')); - for (int ii = 0; ii < val.count(); ++ii) - if (val.at(ii) != u && - ((ii == 0 && !val.at(ii).isLetter()) || - (ii != 0 && !val.at(ii).isLetterOrNumber())) ) - return false; - - return true; -} - -/*! Returns true if \a name refers to an attached property, false otherwise. Attached property names are those that start with a capital letter. @@ -1140,10 +1115,11 @@ bool QDeclarativeCompiler::buildComponent(QDeclarativeParser::Object *obj, if (obj->properties.count()) idProp = *obj->properties.begin(); - if (idProp && (idProp->value || idProp->values.count() > 1 || !isValidId(idProp->values.first()->primitive()))) - COMPILE_EXCEPTION(idProp, QCoreApplication::translate("QDeclarativeCompiler","Invalid component id specification")); - if (idProp) { + if (idProp->value || idProp->values.count() > 1 || idProp->values.at(0)->object) + COMPILE_EXCEPTION(idProp, QCoreApplication::translate("QDeclarativeCompiler","Invalid component id specification")); + COMPILE_CHECK(checkValidId(idProp->values.first(), idProp->values.first()->primitive())); + QString idVal = idProp->values.first()->primitive(); if (compileState.ids.contains(idVal)) @@ -1726,8 +1702,7 @@ bool QDeclarativeCompiler::buildIdProperty(QDeclarativeParser::Property *prop, QDeclarativeParser::Value *idValue = prop->values.at(0); QString val = idValue->primitive(); - if (!isValidId(val)) - COMPILE_EXCEPTION(prop, QCoreApplication::translate("QDeclarativeCompiler","\"%1\" is not a valid object id").arg(val)); + COMPILE_CHECK(checkValidId(idValue, val)); // We disallow id's that conflict with import prefixes and types QDeclarativeEnginePrivate::ImportedNamespace *ns = 0; @@ -2476,6 +2451,31 @@ bool QDeclarativeCompiler::buildDynamicMeta(QDeclarativeParser::Object *obj, Dyn return true; } +bool QDeclarativeCompiler::checkValidId(QDeclarativeParser::Value *v, const QString &val) +{ + if (val.isEmpty()) + COMPILE_EXCEPTION(v, QCoreApplication::translate("QDeclarativeCompiler", "Invalid empty ID")); + + if (val.at(0).isLetter() && !val.at(0).isLower()) + COMPILE_EXCEPTION(v, QCoreApplication::translate("QDeclarativeCompiler", "IDs cannot start with an uppercase letter")); + + QChar u(QLatin1Char('_')); + for (int ii = 0; ii < val.count(); ++ii) { + + if (ii == 0 && !val.at(ii).isLetter() && val.at(ii) != u) { + COMPILE_EXCEPTION(v, QCoreApplication::translate("QDeclarativeCompiler", "IDs must start with a letter or underscore")); + } else if (ii != 0 && !val.at(ii).isLetterOrNumber() && val.at(ii) != u) { + COMPILE_EXCEPTION(v, QCoreApplication::translate("QDeclarativeCompiler", "IDs must contain only letters, numbers, and underscores")); + } + + } + + if (QDeclarativeEnginePrivate::get(engine)->globalClass->illegalNames().contains(val)) + COMPILE_EXCEPTION(v, QCoreApplication::translate("QDeclarativeCompiler", "ID illegally masks global JavaScript property")); + + return true; +} + #include static QStringList astNodeToStringList(QDeclarativeJS::AST::Node *node) diff --git a/src/declarative/qml/qdeclarativecompiler_p.h b/src/declarative/qml/qdeclarativecompiler_p.h index 93a3f83..f8ada95 100644 --- a/src/declarative/qml/qdeclarativecompiler_p.h +++ b/src/declarative/qml/qdeclarativecompiler_p.h @@ -155,7 +155,6 @@ public: bool isError() const; QList errors() const; - static bool isValidId(const QString &); static bool isAttachedPropertyName(const QByteArray &); static bool isSignalPropertyName(const QByteArray &); @@ -247,6 +246,7 @@ private: QDeclarativeParser::Object *obj, const QDeclarativeParser::Object::DynamicProperty &); bool completeComponentBuild(); + bool checkValidId(QDeclarativeParser::Value *, const QString &); void genObject(QDeclarativeParser::Object *obj); diff --git a/src/declarative/qml/qdeclarativecontext.cpp b/src/declarative/qml/qdeclarativecontext.cpp index 57ef90c..35e7a77 100644 --- a/src/declarative/qml/qdeclarativecontext.cpp +++ b/src/declarative/qml/qdeclarativecontext.cpp @@ -47,6 +47,7 @@ #include "qdeclarativeengine.h" #include "qdeclarativecompiledbindings_p.h" #include "qdeclarativeinfo.h" +#include "qdeclarativeglobalscriptclass_p.h" #include #include @@ -74,7 +75,9 @@ void QDeclarativeContextPrivate::addScript(const QDeclarativeParser::Object::Scr QScriptEngine *scriptEngine = QDeclarativeEnginePrivate::getScriptEngine(engine); QScriptContext *scriptContext = QScriptDeclarativeClass::pushCleanContext(scriptEngine); + scriptContext->pushScope(enginePriv->contextClass->newContext(q, scopeObject)); + scriptContext->pushScope(enginePriv->globalClass->globalObject()); QScriptValue scope = scriptEngine->newObject(); scriptContext->setActivationObject(scope); diff --git a/src/declarative/qml/qdeclarativeexpression.cpp b/src/declarative/qml/qdeclarativeexpression.cpp index ae1e790..0030615 100644 --- a/src/declarative/qml/qdeclarativeexpression.cpp +++ b/src/declarative/qml/qdeclarativeexpression.cpp @@ -46,6 +46,7 @@ #include "qdeclarativecontext_p.h" #include "qdeclarativerewrite_p.h" #include "qdeclarativecompiler_p.h" +#include "qdeclarativeglobalscriptclass_p.h" #include #include @@ -135,6 +136,7 @@ void QDeclarativeExpressionPrivate::init(QDeclarativeContext *ctxt, void *expr, if (!dd->cachedClosures.at(progIdx)) { QScriptContext *scriptContext = QScriptDeclarativeClass::pushCleanContext(scriptEngine); scriptContext->pushScope(ep->contextClass->newSharedContext()); + scriptContext->pushScope(ep->globalClass->globalObject()); dd->cachedClosures[progIdx] = new QScriptValue(scriptEngine->evaluate(data->expression, data->url, data->line)); scriptEngine->popContext(); } @@ -169,6 +171,7 @@ QScriptValue QDeclarativeExpressionPrivate::evalInObjectScope(QDeclarativeContex QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(context->engine()); QScriptContext *scriptContext = QScriptDeclarativeClass::pushCleanContext(&ep->scriptEngine); scriptContext->pushScope(ep->contextClass->newContext(context, object)); + scriptContext->pushScope(ep->globalClass->globalObject()); QScriptValue rv = ep->scriptEngine.evaluate(program); ep->scriptEngine.popContext(); return rv; @@ -180,6 +183,7 @@ QScriptValue QDeclarativeExpressionPrivate::evalInObjectScope(QDeclarativeContex QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(context->engine()); QScriptContext *scriptContext = QScriptDeclarativeClass::pushCleanContext(&ep->scriptEngine); scriptContext->pushScope(ep->contextClass->newContext(context, object)); + scriptContext->pushScope(ep->globalClass->globalObject()); QScriptValue rv = ep->scriptEngine.evaluate(program); ep->scriptEngine.popContext(); return rv; @@ -335,6 +339,7 @@ QVariant QDeclarativeExpressionPrivate::evalQtScript(QObject *secondaryScope, bo QScriptContext *scriptContext = QScriptDeclarativeClass::pushCleanContext(scriptEngine); scriptContext->pushScope(ep->contextClass->newContext(data->context(), data->me)); + scriptContext->pushScope(ep->globalClass->globalObject()); if (data->expressionRewritten) { data->expressionFunction = scriptEngine->evaluate(data->expression, diff --git a/src/declarative/qml/qdeclarativeglobalscriptclass.cpp b/src/declarative/qml/qdeclarativeglobalscriptclass.cpp index 5b06b42..9ee2fe5 100644 --- a/src/declarative/qml/qdeclarativeglobalscriptclass.cpp +++ b/src/declarative/qml/qdeclarativeglobalscriptclass.cpp @@ -53,15 +53,17 @@ QT_BEGIN_NAMESPACE QDeclarativeGlobalScriptClass::QDeclarativeGlobalScriptClass(QScriptEngine *engine) : QScriptClass(engine) { - QScriptValue v = engine->newObject(); - globalObject = engine->globalObject(); + QScriptValue globalObject = engine->globalObject(); + m_globalObject = engine->newObject(); QScriptValueIterator iter(globalObject); while (iter.hasNext()) { iter.next(); - v.setProperty(iter.scriptName(), iter.value()); + m_globalObject.setProperty(iter.scriptName(), iter.value()); + m_illegalNames.insert(iter.name()); } + QScriptValue v = engine->newObject(); v.setScriptClass(this); engine->setGlobalObject(v); } @@ -101,12 +103,14 @@ void QDeclarativeGlobalScriptClass::setProperty(QScriptValue &object, engine()->currentContext()->throwError(error); } +/* This method is for the use of tst_qdeclarativeecmascript::callQtInvokables() only */ void QDeclarativeGlobalScriptClass::explicitSetProperty(const QString &name, const QScriptValue &value) { + QScriptValue globalObject = engine()->globalObject(); + QScriptValue v = engine()->newObject(); - globalObject = engine()->globalObject(); - QScriptValueIterator iter(globalObject); + QScriptValueIterator iter(v); while (iter.hasNext()) { iter.next(); v.setProperty(iter.scriptName(), iter.value()); @@ -114,6 +118,7 @@ void QDeclarativeGlobalScriptClass::explicitSetProperty(const QString &name, con v.setProperty(name, value); v.setScriptClass(this); + engine()->setGlobalObject(v); } diff --git a/src/declarative/qml/qdeclarativeglobalscriptclass_p.h b/src/declarative/qml/qdeclarativeglobalscriptclass_p.h index a33cf5e..1b34aee 100644 --- a/src/declarative/qml/qdeclarativeglobalscriptclass_p.h +++ b/src/declarative/qml/qdeclarativeglobalscriptclass_p.h @@ -54,6 +54,7 @@ // #include +#include QT_BEGIN_NAMESPACE @@ -74,8 +75,12 @@ public: void explicitSetProperty(const QString &, const QScriptValue &); + const QScriptValue &globalObject() const { return m_globalObject; } + const QSet &illegalNames() const { return m_illegalNames; } + private: - QScriptValue globalObject; + QSet m_illegalNames; + QScriptValue m_globalObject; }; QT_END_NAMESPACE diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/scope.3.qml b/tests/auto/declarative/qdeclarativeecmascript/data/scope.3.qml new file mode 100644 index 0000000..4ad7f34 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeecmascript/data/scope.3.qml @@ -0,0 +1,13 @@ +import Qt 4.6 + +Item { + id: root + + property int foo: 12 + property int console: 11 + + property bool test1: foo == 12 + property bool test2: console != 11 + property bool test3: root.console == 11 +} + diff --git a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp index 85a3ef3..e45f0fa 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp +++ b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp @@ -729,6 +729,16 @@ void tst_qdeclarativeecmascript::scope() QCOMPARE(object->property("test5").toInt(), 24); QCOMPARE(object->property("test6").toInt(), 24); } + + { + QDeclarativeComponent component(&engine, TEST_FILE("scope.3.qml")); + QObject *object = component.create(); + QVERIFY(object != 0); + + QCOMPARE(object->property("test1").toBool(), true); + QCOMPARE(object->property("test2").toBool(), true); + QCOMPARE(object->property("test3").toBool(), true); + } } /* diff --git a/tests/auto/declarative/qdeclarativelanguage/data/invalidID.2.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/invalidID.2.errors.txt index 56e3eeb..2c6b8bf 100644 --- a/tests/auto/declarative/qdeclarativelanguage/data/invalidID.2.errors.txt +++ b/tests/auto/declarative/qdeclarativelanguage/data/invalidID.2.errors.txt @@ -1,2 +1,2 @@ -3:5:"" is not a valid object id +3:9:Invalid empty ID diff --git a/tests/auto/declarative/qdeclarativelanguage/data/invalidID.6.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/invalidID.6.errors.txt index 160e8b5..7251de1 100644 --- a/tests/auto/declarative/qdeclarativelanguage/data/invalidID.6.errors.txt +++ b/tests/auto/declarative/qdeclarativelanguage/data/invalidID.6.errors.txt @@ -1 +1 @@ -3:5:"StartsWithUpperCase" is not a valid object id +3:9:IDs cannot start with an uppercase letter diff --git a/tests/auto/declarative/qdeclarativelanguage/data/invalidID.7.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/invalidID.7.errors.txt new file mode 100644 index 0000000..e4fd1db --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/invalidID.7.errors.txt @@ -0,0 +1 @@ +3:9:ID illegally masks global JavaScript property diff --git a/tests/auto/declarative/qdeclarativelanguage/data/invalidID.7.qml b/tests/auto/declarative/qdeclarativelanguage/data/invalidID.7.qml new file mode 100644 index 0000000..d4bc539 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/invalidID.7.qml @@ -0,0 +1,5 @@ +import Test 1.0 +MyQmlObject { + id: gc +} + diff --git a/tests/auto/declarative/qdeclarativelanguage/data/invalidID.8.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/invalidID.8.errors.txt new file mode 100644 index 0000000..b03ec6c --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/invalidID.8.errors.txt @@ -0,0 +1 @@ +3:9:IDs must contain only letters, numbers, and underscores diff --git a/tests/auto/declarative/qdeclarativelanguage/data/invalidID.8.qml b/tests/auto/declarative/qdeclarativelanguage/data/invalidID.8.qml new file mode 100644 index 0000000..1ea615c --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/invalidID.8.qml @@ -0,0 +1,5 @@ +import Test 1.0 +MyQmlObject { + id: hello.world +} + diff --git a/tests/auto/declarative/qdeclarativelanguage/data/invalidID.9.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/invalidID.9.errors.txt new file mode 100644 index 0000000..c010e79 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/invalidID.9.errors.txt @@ -0,0 +1 @@ +3:9:IDs must start with a letter or underscore diff --git a/tests/auto/declarative/qdeclarativelanguage/data/invalidID.9.qml b/tests/auto/declarative/qdeclarativelanguage/data/invalidID.9.qml new file mode 100644 index 0000000..57474b7 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/invalidID.9.qml @@ -0,0 +1,5 @@ +import Test 1.0 +MyQmlObject { + id: "3hello" +} + diff --git a/tests/auto/declarative/qdeclarativelanguage/data/invalidID.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/invalidID.errors.txt index 1ca678c..c010e79 100644 --- a/tests/auto/declarative/qdeclarativelanguage/data/invalidID.errors.txt +++ b/tests/auto/declarative/qdeclarativelanguage/data/invalidID.errors.txt @@ -1 +1 @@ -3:5:"1" is not a valid object id +3:9:IDs must start with a letter or underscore diff --git a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp index 870f3fe..5d480fa 100644 --- a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp +++ b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp @@ -232,6 +232,9 @@ void tst_qdeclarativelanguage::errors_data() QTest::newRow("invalidID.4") << "invalidID.4.qml" << "invalidID.4.errors.txt" << false; QTest::newRow("invalidID.5") << "invalidID.5.qml" << "invalidID.5.errors.txt" << false; QTest::newRow("invalidID.6") << "invalidID.6.qml" << "invalidID.6.errors.txt" << false; + QTest::newRow("invalidID.7") << "invalidID.7.qml" << "invalidID.7.errors.txt" << false; + QTest::newRow("invalidID.8") << "invalidID.8.qml" << "invalidID.8.errors.txt" << false; + QTest::newRow("invalidID.9") << "invalidID.9.qml" << "invalidID.9.errors.txt" << false; QTest::newRow("unsupportedProperty") << "unsupportedProperty.qml" << "unsupportedProperty.errors.txt" << false; QTest::newRow("nullDotProperty") << "nullDotProperty.qml" << "nullDotProperty.errors.txt" << true; @@ -327,9 +330,6 @@ void tst_qdeclarativelanguage::errors() QFETCH(QString, errorFile); QFETCH(bool, create); - if (file == "invalidID.6.qml") - QTest::ignoreMessage(QtWarningMsg, "id \"StartsWithUpperCase\" is invalid: ids cannot start with uppercase letters"); - QDeclarativeComponent component(&engine, TEST_FILE(file)); if(create) { -- cgit v0.12 From ef785f047adf6f559c282d67e627b78b75a7b9ef Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Wed, 3 Mar 2010 17:53:05 +1000 Subject: QDeclarativeProperty::read() returns a QObjectStar when accessing a QObject property QT-2793 --- src/declarative/qml/qdeclarativeproperty.cpp | 11 +++++-- .../qdeclarativeproperty/data/TestType.qml | 6 ++++ .../data/readSynthesizedObject.qml | 9 ++++++ .../qdeclarativeproperty/qdeclarativeproperty.pro | 2 ++ .../tst_qdeclarativeproperty.cpp | 37 ++++++++++++++++++++++ 5 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 tests/auto/declarative/qdeclarativeproperty/data/TestType.qml create mode 100644 tests/auto/declarative/qdeclarativeproperty/data/readSynthesizedObject.qml diff --git a/src/declarative/qml/qdeclarativeproperty.cpp b/src/declarative/qml/qdeclarativeproperty.cpp index e1ec2cd..521c241 100644 --- a/src/declarative/qml/qdeclarativeproperty.cpp +++ b/src/declarative/qml/qdeclarativeproperty.cpp @@ -793,7 +793,7 @@ QVariant QDeclarativeProperty::read(QObject *object, const QString &name, QDecla QVariant QDeclarativePropertyPrivate::readValueProperty() { - if(isValueType()) { + if (isValueType()) { QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(context); QDeclarativeValueType *valueType = 0; @@ -809,13 +809,20 @@ QVariant QDeclarativePropertyPrivate::readValueProperty() if (!ep) delete valueType; return rv; - } else if(core.flags & QDeclarativePropertyCache::Data::IsQList) { + } else if (core.flags & QDeclarativePropertyCache::Data::IsQList) { QDeclarativeListProperty prop; void *args[] = { &prop, 0 }; QMetaObject::metacall(object, QMetaObject::ReadProperty, core.coreIndex, args); return QVariant::fromValue(QDeclarativeListReferencePrivate::init(prop, core.propType, engine)); + } else if (core.flags & QDeclarativePropertyCache::Data::IsQObjectDerived) { + + QObject *rv = 0; + void *args[] = { &rv, 0 }; + QMetaObject::metacall(object, QMetaObject::ReadProperty, core.coreIndex, args); + return QVariant::fromValue(rv); + } else { return object->metaObject()->property(core.coreIndex).read(object.data()); diff --git a/tests/auto/declarative/qdeclarativeproperty/data/TestType.qml b/tests/auto/declarative/qdeclarativeproperty/data/TestType.qml new file mode 100644 index 0000000..1dfb3e1 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeproperty/data/TestType.qml @@ -0,0 +1,6 @@ +import Qt 4.6 + +QtObject { + property int a: 10 +} + diff --git a/tests/auto/declarative/qdeclarativeproperty/data/readSynthesizedObject.qml b/tests/auto/declarative/qdeclarativeproperty/data/readSynthesizedObject.qml new file mode 100644 index 0000000..8085db2 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeproperty/data/readSynthesizedObject.qml @@ -0,0 +1,9 @@ +import Qt 4.6 + +QtObject { + property TestType test + + test: TestType { + property int b: 19 + } +} diff --git a/tests/auto/declarative/qdeclarativeproperty/qdeclarativeproperty.pro b/tests/auto/declarative/qdeclarativeproperty/qdeclarativeproperty.pro index 22e50cc..af1e1b6 100644 --- a/tests/auto/declarative/qdeclarativeproperty/qdeclarativeproperty.pro +++ b/tests/auto/declarative/qdeclarativeproperty/qdeclarativeproperty.pro @@ -3,3 +3,5 @@ contains(QT_CONFIG,declarative): QT += declarative macx:CONFIG -= app_bundle SOURCES += tst_qdeclarativeproperty.cpp + +DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/auto/declarative/qdeclarativeproperty/tst_qdeclarativeproperty.cpp b/tests/auto/declarative/qdeclarativeproperty/tst_qdeclarativeproperty.cpp index 0333d98..9b8a643 100644 --- a/tests/auto/declarative/qdeclarativeproperty/tst_qdeclarativeproperty.cpp +++ b/tests/auto/declarative/qdeclarativeproperty/tst_qdeclarativeproperty.cpp @@ -46,6 +46,14 @@ #include #include #include +#include +#include + +inline QUrl TEST_FILE(const QString &filename) +{ + QFileInfo fileInfo(__FILE__); + return QUrl::fromLocalFile(fileInfo.absoluteDir().filePath(QLatin1String("data/") + filename)); +} class MyQmlObject : public QObject { @@ -181,6 +189,7 @@ class PropertyObject : public QObject Q_PROPERTY(QUrl url READ url WRITE setUrl); Q_PROPERTY(int resettableProperty READ resettableProperty WRITE setResettableProperty RESET resetProperty); Q_PROPERTY(int propertyWithNotify READ propertyWithNotify WRITE setPropertyWithNotify NOTIFY oddlyNamedNotifySignal) + Q_PROPERTY(MyQmlObject *qmlObject READ qmlObject); Q_CLASSINFO("DefaultProperty", "defaultProperty"); public: @@ -202,6 +211,7 @@ public: int propertyWithNotify() const { return m_propertyWithNotify; } void setPropertyWithNotify(int i) { m_propertyWithNotify = i; emit oddlyNamedNotifySignal(); } + MyQmlObject *qmlObject() { return &m_qmlObject; } signals: void clicked(); void oddlyNamedNotifySignal(); @@ -211,6 +221,7 @@ private: QRect m_rect; QUrl m_url; int m_propertyWithNotify; + MyQmlObject m_qmlObject; }; QML_DECLARE_TYPE(PropertyObject); @@ -953,6 +964,32 @@ void tst_qdeclarativeproperty::read() QCOMPARE(p.read(), QVariant()); } + // Object property + { + PropertyObject o; + QDeclarativeProperty p(&o, "qmlObject"); + QCOMPARE(p.propertyTypeCategory(), QDeclarativeProperty::Object); + QCOMPARE(p.propertyType(), qMetaTypeId()); + QVariant v = p.read(); + QVERIFY(v.userType() == QMetaType::QObjectStar); + QVERIFY(qvariant_cast(v) == o.qmlObject()); + } + { + QDeclarativeComponent component(&engine, TEST_FILE("readSynthesizedObject.qml")); + QObject *object = component.create(); + QVERIFY(object != 0); + + QDeclarativeProperty p(object, "test", &engine); + + QCOMPARE(p.propertyTypeCategory(), QDeclarativeProperty::Object); + QVERIFY(p.propertyType() != QMetaType::QObjectStar); + + QVariant v = p.read(); + QVERIFY(v.userType() == QMetaType::QObjectStar); + QCOMPARE(qvariant_cast(v)->property("a").toInt(), 10); + QCOMPARE(qvariant_cast(v)->property("b").toInt(), 19); + } + // Attached property { QDeclarativeComponent component(&engine); -- cgit v0.12 From 07bd4f61caaa61866fcfa7847eeeb905d4fa2b38 Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Wed, 3 Mar 2010 17:54:43 +1000 Subject: 'on' syntax fixes --- .../graphicsitems/qdeclarativegridview.cpp | 6 ++-- .../graphicsitems/qdeclarativelistview.cpp | 2 +- src/declarative/qml/qdeclarativedom.cpp | 8 ++--- src/declarative/util/qdeclarativeanimation.cpp | 18 ++++++------ src/declarative/util/qdeclarativebehavior.cpp | 6 ++-- src/declarative/util/qdeclarativeeasefollow.cpp | 34 +++++++++++----------- src/declarative/util/qdeclarativespringfollow.cpp | 6 ++-- 7 files changed, 40 insertions(+), 40 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativegridview.cpp b/src/declarative/graphicsitems/qdeclarativegridview.cpp index 090c46d..5b313be 100644 --- a/src/declarative/graphicsitems/qdeclarativegridview.cpp +++ b/src/declarative/graphicsitems/qdeclarativegridview.cpp @@ -744,7 +744,7 @@ QDeclarativeGridView::~QDeclarativeGridView() id: myDelegate Item { id: wrapper - GridView.onRemove: SequentialAnimation { + SequentialAnimation on GridView.onRemove { PropertyAction { target: wrapper.GridView; property: "delayRemove"; value: true } NumberAnimation { target: wrapper; property: "scale"; to: 0; duration: 250; easing: "easeInOutQuad" } PropertyAction { target: wrapper.GridView; property: "delayRemove"; value: false } @@ -989,8 +989,8 @@ void QDeclarativeGridView::setHighlight(QDeclarativeComponent *highlight) id: myHighlight Rectangle { id: wrapper; color: "lightsteelblue"; radius: 4; width: 320; height: 60 - y: SpringFollow { source: Wrapper.GridView.view.currentItem.y; spring: 3; damping: 0.2 } - x: SpringFollow { source: Wrapper.GridView.view.currentItem.x; spring: 3; damping: 0.2 } + SpringFollow on y { source: Wrapper.GridView.view.currentItem.y; spring: 3; damping: 0.2 } + SpringFollow on x { source: Wrapper.GridView.view.currentItem.x; spring: 3; damping: 0.2 } } } \endcode diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp index a05e638..eb5315d 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview.cpp +++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp @@ -1431,7 +1431,7 @@ QDeclarativeListView::~QDeclarativeListView() id: myDelegate Item { id: wrapper - ListView.onRemove: SequentialAnimation { + SequentialAnimation on ListView.onRemove { PropertyAction { target: wrapper.ListView; property: "delayRemove"; value: true } NumberAnimation { target: wrapper; property: "scale"; to: 0; duration: 250; easing: "easeInOutQuad" } PropertyAction { target: wrapper.ListView; property: "delayRemove"; value: false } diff --git a/src/declarative/qml/qdeclarativedom.cpp b/src/declarative/qml/qdeclarativedom.cpp index 5b43109..cb56ead 100644 --- a/src/declarative/qml/qdeclarativedom.cpp +++ b/src/declarative/qml/qdeclarativedom.cpp @@ -374,7 +374,7 @@ QDeclarativeDomValue QDeclarativeDomProperty::value() const QDeclarativeDomValue rv; if (d->property) { rv.d->property = d->property; - if (d->property->values.count()) + if (d->property->values.count()) rv.d->value = d->property->values.at(0); else rv.d->value = d->property->onValues.at(0); @@ -508,7 +508,7 @@ int QDeclarativeDomDynamicProperty::propertyType() const QByteArray QDeclarativeDomDynamicProperty::propertyTypeName() const { - if (isValid()) + if (isValid()) return d->property.customType; return QByteArray(); @@ -1184,7 +1184,7 @@ QDeclarativeDomObject QDeclarativeDomValueValueSource::object() const \qml Rectangle { - x: Behavior { NumberAnimation { duration: 500 } } + Behavior on x { NumberAnimation { duration: 500 } } } \endqml */ @@ -1228,7 +1228,7 @@ QDeclarativeDomValueValueInterceptor &QDeclarativeDomValueValueInterceptor::oper returned. \qml Rectangle { - x: Behavior { NumberAnimation { duration: 500 } } + Behavior on x { NumberAnimation { duration: 500 } } } \endqml */ diff --git a/src/declarative/util/qdeclarativeanimation.cpp b/src/declarative/util/qdeclarativeanimation.cpp index 7f4f1c0..b14de19 100644 --- a/src/declarative/util/qdeclarativeanimation.cpp +++ b/src/declarative/util/qdeclarativeanimation.cpp @@ -110,7 +110,7 @@ QDeclarativeAbstractAnimation::QDeclarativeAbstractAnimation(QDeclarativeAbstrac \code Rectangle { width: 100; height: 100 - x: NumberAnimation { + NumberAnimation on x { running: myMouse.pressed from: 0; to: 100 } @@ -310,7 +310,7 @@ void QDeclarativeAbstractAnimation::setAlwaysRunToEnd(bool f) \code Rectangle { - rotation: NumberAnimation { running: true; repeat: true; from: 0 to: 360 } + NumberAnimation on rotation { running: true; repeat: true; from: 0 to: 360 } } \endcode */ @@ -412,7 +412,7 @@ void QDeclarativeAbstractAnimation::resume() no further influence on property values. In this example animation \code Rectangle { - x: NumberAnimation { from: 0; to: 100; duration: 500 } + NumberAnimation on x { from: 0; to: 100; duration: 500 } } \endcode was stopped at time 250ms, the \c x property will have a value of 50. @@ -450,7 +450,7 @@ void QDeclarativeAbstractAnimation::restart() its end. In the following example, \code Rectangle { - x: NumberAnimation { from: 0; to: 100; duration: 500 } + NumberAnimation on x { from: 0; to: 100; duration: 500 } } \endcode calling \c stop() at time 250ms will result in the \c x property having @@ -1292,7 +1292,7 @@ QDeclarativeVector3dAnimation::QDeclarativeVector3dAnimation(QObject *parent) Q_D(QDeclarativePropertyAnimation); d->interpolatorType = QMetaType::QVector3D; d->interpolator = QVariantAnimationPrivate::getInterpolator(d->interpolatorType); - d->defaultToInterpolatorType = true; + d->defaultToInterpolatorType = true; } QDeclarativeVector3dAnimation::~QDeclarativeVector3dAnimation() @@ -1741,7 +1741,7 @@ void QDeclarativePropertyAnimationPrivate::convertVariant(QVariant &variant, int Animate all changes to a rectangle's x property. \qml Rectangle { - x: Behavior { PropertyAnimation {} } + Behavior on x { PropertyAnimation {} } } \endqml \o As a property value source @@ -1749,7 +1749,7 @@ void QDeclarativePropertyAnimationPrivate::convertVariant(QVariant &variant, int Repeatedly animate the rectangle's x property. \qml Rectangle { - x: SequentialAnimation { + SequentialAnimation on x { repeat: true PropertyAnimation { to: 50 } PropertyAnimation { to: 0 } @@ -2140,8 +2140,8 @@ void QDeclarativePropertyAnimation::setProperties(const QString &prop) id: theRect width: 100; height: 100 color: Qt.rgba(0,0,1) - x: NumberAnimation { to: 500; repeat: true } //animate theRect's x property - y: Behavior { NumberAnimation {} } //animate theRect's y property + NumberAnimation on x { to: 500; repeat: true } //animate theRect's x property + Behavior on y { NumberAnimation {} } //animate theRect's y property } \endqml \row diff --git a/src/declarative/util/qdeclarativebehavior.cpp b/src/declarative/util/qdeclarativebehavior.cpp index 5352341..dea2c02 100644 --- a/src/declarative/util/qdeclarativebehavior.cpp +++ b/src/declarative/util/qdeclarativebehavior.cpp @@ -75,13 +75,13 @@ public: Behaviors provide one way to specify \l{qdeclarativeanimation.html}{animations} in QML. - In the example below, the rect will use a bounce easing curve over 200 millisecond for any changes to its y property: + In the example below, the rectangle will use a bounce easing curve over 200 millisecond for any changes to its y property: \code Rectangle { width: 20; height: 20 color: "#00ff00" - y: 200 //initial value - y: Behavior { + y: 200 // initial value + Behavior on y { NumberAnimation { easing: "easeOutBounce(amplitude:100)" duration: 200 diff --git a/src/declarative/util/qdeclarativeeasefollow.cpp b/src/declarative/util/qdeclarativeeasefollow.cpp index 3fa9866..ee181dd 100644 --- a/src/declarative/util/qdeclarativeeasefollow.cpp +++ b/src/declarative/util/qdeclarativeeasefollow.cpp @@ -59,10 +59,10 @@ class QDeclarativeEaseFollowPrivate : public QObjectPrivate public: QDeclarativeEaseFollowPrivate() : source(0), velocity(200), duration(-1), maximumEasingTime(-1), - reversingMode(QDeclarativeEaseFollow::Eased), initialVelocity(0), + reversingMode(QDeclarativeEaseFollow::Eased), initialVelocity(0), initialValue(0), invert(false), enabled(true), trackVelocity(0), clockOffset(0), lastTick(0), clock(this) - {} + {} qreal source; qreal velocity; @@ -173,7 +173,7 @@ bool QDeclarativeEaseFollowPrivate::recalc() } /* - qWarning() << "a:" << a << "tf:" << tf << "tp:" << tp << "vp:" + qWarning() << "a:" << a << "tf:" << tf << "tp:" << tp << "vp:" << vp << "sp:" << sp << "vi:" << vi << "invert:" << invert; */ return true; @@ -254,19 +254,19 @@ void QDeclarativeEaseFollowPrivate::tick(int t) \since 4.7 \brief The EaseFollow element allows a property to smoothly track a value. - The EaseFollow smoothly animates a property's value to a set target value + The EaseFollow smoothly animates a property's value to a set target value using an ease in/out quad easing curve. If the target value changes while - the animation is in progress, the easing curves used to animate to the old + the animation is in progress, the easing curves used to animate to the old and the new target values are spliced together to avoid any obvious visual glitches. The property animation is configured by setting the velocity at which the - animation should occur, or the duration that the animation should take. + animation should occur, or the duration that the animation should take. If both a velocity and a duration are specified, the one that results in the quickest animation is chosen for each change in the target value. For example, animating from 0 to 800 will take 4 seconds if a velocity - of 200 is set, will take 8 seconds with a duration of 8000 set, and will + of 200 is set, will take 8 seconds with a duration of 8000 set, and will take 4 seconds with both a velocity of 200 and a duration of 8000 set. Animating from 0 to 20000 will take 10 seconds if a velocity of 200 is set, will take 8 seconds with a duration of 8000 set, and will take 8 seconds @@ -283,8 +283,8 @@ Rectangle { color: "green" width: 60; height: 60; x: -5; y: -5; - x: EaseFollow { source: rect1.x - 5; velocity: 200 } - y: EaseFollow { source: rect1.y - 5; velocity: 200 } + EaseFollow on x { source: rect1.x - 5; velocity: 200 } + EaseFollow on y { source: rect1.y - 5; velocity: 200 } } Rectangle { @@ -338,8 +338,8 @@ qreal QDeclarativeEaseFollow::sourceValue() const Sets how the EaseFollow behaves if an animation direction is reversed. If reversing mode is \c Eased, the animation will smoothly decelerate, and - then reverse direction. If the reversing mode is \c Immediate, the - animation will immediately begin accelerating in the reverse direction, + then reverse direction. If the reversing mode is \c Immediate, the + animation will immediately begin accelerating in the reverse direction, begining with a velocity of 0. If the reversing mode is \c Sync, the property is immediately set to the target value. */ @@ -373,7 +373,7 @@ void QDeclarativeEaseFollowPrivate::restart() return; } - bool hasReversed = trackVelocity != 0. && + bool hasReversed = trackVelocity != 0. && ((trackVelocity > 0) == ((initialValue - source) > 0)); if (hasReversed) { @@ -440,7 +440,7 @@ void QDeclarativeEaseFollow::setDuration(qreal v) d->duration = v; d->trackVelocity = 0; - if (d->clock.state() == QAbstractAnimation::Running) + if (d->clock.state() == QAbstractAnimation::Running) d->restart(); emit durationChanged(); @@ -470,7 +470,7 @@ void QDeclarativeEaseFollow::setVelocity(qreal v) d->velocity = v; d->trackVelocity = 0; - if (d->clock.state() == QAbstractAnimation::Running) + if (d->clock.state() == QAbstractAnimation::Running) d->restart(); emit velocityChanged(); @@ -511,8 +511,8 @@ void QDeclarativeEaseFollow::setTarget(const QDeclarativeProperty &t) \qmlproperty qreal EaseFollow::maximumEasingTime This property specifies the maximum time an "eases" during the follow should take. -Setting this property causes the velocity to "level out" after at a time. Setting -a negative value reverts to the normal mode of easing over the entire animation +Setting this property causes the velocity to "level out" after at a time. Setting +a negative value reverts to the normal mode of easing over the entire animation duration. The default value is -1. @@ -528,7 +528,7 @@ void QDeclarativeEaseFollow::setMaximumEasingTime(qreal v) Q_D(QDeclarativeEaseFollow); d->maximumEasingTime = v; - if (d->clock.state() == QAbstractAnimation::Running) + if (d->clock.state() == QAbstractAnimation::Running) d->restart(); emit maximumEasingTimeChanged(); diff --git a/src/declarative/util/qdeclarativespringfollow.cpp b/src/declarative/util/qdeclarativespringfollow.cpp index 6205ab9..1d69dd3 100644 --- a/src/declarative/util/qdeclarativespringfollow.cpp +++ b/src/declarative/util/qdeclarativespringfollow.cpp @@ -222,8 +222,8 @@ void QDeclarativeSpringFollowPrivate::stop() id: rect1 width: 20; height: 20 color: "#00ff00" - y: 200 //initial value - y: SequentialAnimation { + y: 200 // initial value + SequentialAnimation on y { running: true repeat: true NumberAnimation { @@ -239,7 +239,7 @@ void QDeclarativeSpringFollowPrivate::stop() x: rect1.width width: 20; height: 20 color: "#ff0000" - y: SpringFollow { source: rect1.y; velocity: 200 } + SpringFollow on y { source: rect1.y; velocity: 200 } } \endcode -- cgit v0.12 From 64a4b25fac94fc5c9b75ab31690c658e95189797 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Wed, 3 Mar 2010 18:33:44 +1000 Subject: Save secondary scope inside the expression's scope object This prevents the secondary scope from contaminating scopes outside itself when used as a signal expression. QTBUG-8641 --- .../qml/qdeclarativecontextscriptclass.cpp | 30 ++++++++++++++-- .../qml/qdeclarativecontextscriptclass_p.h | 1 + src/declarative/qml/qdeclarativeexpression.cpp | 41 +++++++++++++--------- src/declarative/qml/qdeclarativeexpression_p.h | 5 +-- .../tst_qdeclarativeecmascript.cpp | 3 +- 5 files changed, 58 insertions(+), 22 deletions(-) diff --git a/src/declarative/qml/qdeclarativecontextscriptclass.cpp b/src/declarative/qml/qdeclarativecontextscriptclass.cpp index 7deed0b..d6305d8 100644 --- a/src/declarative/qml/qdeclarativecontextscriptclass.cpp +++ b/src/declarative/qml/qdeclarativecontextscriptclass.cpp @@ -50,10 +50,11 @@ QT_BEGIN_NAMESPACE struct ContextData : public QScriptDeclarativeClass::Object { - ContextData() : isSharedContext(true) {} - ContextData(QDeclarativeContext *c, QObject *o) : context(c), scopeObject(o), isSharedContext(false) {} + ContextData() : overrideObject(0), isSharedContext(true) {} + ContextData(QDeclarativeContext *c, QObject *o) : context(c), scopeObject(o), overrideObject(0), isSharedContext(false) {} QDeclarativeGuard context; QDeclarativeGuard scopeObject; + QObject *overrideObject; bool isSharedContext; QDeclarativeContext *getContext(QDeclarativeEngine *engine) { @@ -110,6 +111,17 @@ QDeclarativeContext *QDeclarativeContextScriptClass::contextFromValue(const QScr return data->getContext(engine); } +QObject *QDeclarativeContextScriptClass::setOverrideObject(QScriptValue &v, QObject *override) +{ + if (scriptClass(v) != this) + return 0; + + ContextData *data = (ContextData *)object(v); + QObject *rv = data->overrideObject; + data->overrideObject = override; + return rv; +} + QScriptClass::QueryFlags QDeclarativeContextScriptClass::queryProperty(Object *object, const Identifier &name, QScriptClass::QueryFlags flags) @@ -127,6 +139,20 @@ QDeclarativeContextScriptClass::queryProperty(Object *object, const Identifier & if (!bindContext) return 0; + QObject *overrideObject = ((ContextData *)object)->overrideObject; + if (overrideObject) { + QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine); + QScriptClass::QueryFlags rv = + ep->objectClass->queryProperty(overrideObject, name, flags, bindContext, + QDeclarativeObjectScriptClass::ImplicitObject | + QDeclarativeObjectScriptClass::SkipAttachedProperties); + if (rv) { + lastScopeObject = overrideObject; + lastContext = bindContext; + return rv; + } + } + bool includeTypes = true; while (bindContext) { QScriptClass::QueryFlags rv = diff --git a/src/declarative/qml/qdeclarativecontextscriptclass_p.h b/src/declarative/qml/qdeclarativecontextscriptclass_p.h index 26086ec..4b0dca0 100644 --- a/src/declarative/qml/qdeclarativecontextscriptclass_p.h +++ b/src/declarative/qml/qdeclarativecontextscriptclass_p.h @@ -70,6 +70,7 @@ public: QScriptValue newSharedContext(); QDeclarativeContext *contextFromValue(const QScriptValue &); + QObject *setOverrideObject(QScriptValue &, QObject *); protected: virtual QScriptClass::QueryFlags queryProperty(Object *, const Identifier &, diff --git a/src/declarative/qml/qdeclarativeexpression.cpp b/src/declarative/qml/qdeclarativeexpression.cpp index 0030615..e528e9e 100644 --- a/src/declarative/qml/qdeclarativeexpression.cpp +++ b/src/declarative/qml/qdeclarativeexpression.cpp @@ -153,9 +153,11 @@ void QDeclarativeExpressionPrivate::init(QDeclarativeContext *ctxt, void *expr, new QScriptProgram(data->expression, data->url, data->line); } - data->expressionFunction = evalInObjectScope(ctxt, me, *dd->cachedPrograms.at(progIdx)); + data->expressionFunction = evalInObjectScope(ctxt, me, *dd->cachedPrograms.at(progIdx), + &data->expressionContext); #else - data->expressionFunction = evalInObjectScope(ctxt, me, data->expression); + data->expressionFunction = evalInObjectScope(ctxt, me, data->expression, + &data->expressionContext); #endif data->expressionFunctionValid = true; @@ -166,11 +168,16 @@ void QDeclarativeExpressionPrivate::init(QDeclarativeContext *ctxt, void *expr, } QScriptValue QDeclarativeExpressionPrivate::evalInObjectScope(QDeclarativeContext *context, QObject *object, - const QString &program) + const QString &program, QScriptValue *contextObject) { QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(context->engine()); QScriptContext *scriptContext = QScriptDeclarativeClass::pushCleanContext(&ep->scriptEngine); - scriptContext->pushScope(ep->contextClass->newContext(context, object)); + if (contextObject) { + *contextObject = ep->contextClass->newContext(context, object); + scriptContext->pushScope(*contextObject); + } else { + scriptContext->pushScope(ep->contextClass->newContext(context, object)); + } scriptContext->pushScope(ep->globalClass->globalObject()); QScriptValue rv = ep->scriptEngine.evaluate(program); ep->scriptEngine.popContext(); @@ -178,11 +185,16 @@ QScriptValue QDeclarativeExpressionPrivate::evalInObjectScope(QDeclarativeContex } QScriptValue QDeclarativeExpressionPrivate::evalInObjectScope(QDeclarativeContext *context, QObject *object, - const QScriptProgram &program) + const QScriptProgram &program, QScriptValue *contextObject) { QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(context->engine()); QScriptContext *scriptContext = QScriptDeclarativeClass::pushCleanContext(&ep->scriptEngine); - scriptContext->pushScope(ep->contextClass->newContext(context, object)); + if (contextObject) { + *contextObject = ep->contextClass->newContext(context, object); + scriptContext->pushScope(*contextObject); + } else { + scriptContext->pushScope(ep->contextClass->newContext(context, object)); + } scriptContext->pushScope(ep->globalClass->globalObject()); QScriptValue rv = ep->scriptEngine.evaluate(program); ep->scriptEngine.popContext(); @@ -330,15 +342,13 @@ QVariant QDeclarativeExpressionPrivate::evalQtScript(QObject *secondaryScope, bo QDeclarativeEngine *engine = data->context()->engine(); QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine); - if (secondaryScope) - ctxtPriv->defaultObjects.append(secondaryScope); - QScriptEngine *scriptEngine = QDeclarativeEnginePrivate::getScriptEngine(engine); if (!data->expressionFunctionValid) { QScriptContext *scriptContext = QScriptDeclarativeClass::pushCleanContext(scriptEngine); - scriptContext->pushScope(ep->contextClass->newContext(data->context(), data->me)); + data->expressionContext = ep->contextClass->newContext(data->context(), data->me); + scriptContext->pushScope(data->expressionContext); scriptContext->pushScope(ep->globalClass->globalObject()); if (data->expressionRewritten) { @@ -362,11 +372,14 @@ QVariant QDeclarativeExpressionPrivate::evalQtScript(QObject *secondaryScope, bo QDeclarativeContext *oldSharedContext = 0; QObject *oldSharedScope = 0; + QObject *oldOverride = 0; if (data->isShared) { oldSharedContext = ep->sharedContext; oldSharedScope = ep->sharedScope; ep->sharedContext = data->context(); ep->sharedScope = data->me; + } else { + oldOverride = ep->contextClass->setOverrideObject(data->expressionContext, secondaryScope); } QScriptValue svalue = data->expressionFunction.call(); @@ -374,6 +387,8 @@ QVariant QDeclarativeExpressionPrivate::evalQtScript(QObject *secondaryScope, bo if (data->isShared) { ep->sharedContext = oldSharedContext; ep->sharedScope = oldSharedScope; + } else { + ep->contextClass->setOverrideObject(data->expressionContext, oldOverride); } if (isUndefined) @@ -388,12 +403,6 @@ QVariant QDeclarativeExpressionPrivate::evalQtScript(QObject *secondaryScope, bo data->error = QDeclarativeError(); } - if (secondaryScope) { - QObject *last = ctxtPriv->defaultObjects.takeLast(); - Q_ASSERT(last == secondaryScope); - Q_UNUSED(last); - } - QVariant rv; if (svalue.isArray()) { diff --git a/src/declarative/qml/qdeclarativeexpression_p.h b/src/declarative/qml/qdeclarativeexpression_p.h index 91ac4c0..cd1729d 100644 --- a/src/declarative/qml/qdeclarativeexpression_p.h +++ b/src/declarative/qml/qdeclarativeexpression_p.h @@ -119,6 +119,7 @@ public: bool expressionFunctionValid:1; bool expressionRewritten:1; QScriptValue expressionFunction; + QScriptValue expressionContext; QObject *me; bool trackChange; @@ -180,8 +181,8 @@ public: virtual void emitValueChanged(); static void exceptionToError(QScriptEngine *, QDeclarativeError &); - static QScriptValue evalInObjectScope(QDeclarativeContext *, QObject *, const QString &); - static QScriptValue evalInObjectScope(QDeclarativeContext *, QObject *, const QScriptProgram &); + static QScriptValue evalInObjectScope(QDeclarativeContext *, QObject *, const QString &, QScriptValue * = 0); + static QScriptValue evalInObjectScope(QDeclarativeContext *, QObject *, const QScriptProgram &, QScriptValue * = 0); }; QT_END_NAMESPACE diff --git a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp index e45f0fa..75ee7ce 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp +++ b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp @@ -1676,8 +1676,7 @@ void tst_qdeclarativeecmascript::scriptScope() MyQmlObject *object = qobject_cast(component.create()); QVERIFY(object != 0); emit object->argumentSignal(19, "Hello world!", 10.3); - QEXPECT_FAIL("", "QTBUG-8641", Continue); - QCOMPARE(object->property("result").toString(), QLatin1String("undefined")); + QCOMPARE(object->property("result").toString(), QString()); delete object; } -- cgit v0.12 From 5c1496d8839010653a9273586c10d99e0eeb66b2 Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Wed, 3 Mar 2010 18:36:44 +1000 Subject: More renaming: MouseRegion -> MouseArea --- doc/src/declarative/tutorial.qdoc | 6 +++--- examples/declarative/colorbrowser/colorbrowser.qml | 2 +- examples/declarative/colorbrowser/qml/ColorDelegate.qml | 2 +- examples/declarative/package/Delegate.qml | 2 +- src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp | 10 +++++----- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/doc/src/declarative/tutorial.qdoc b/doc/src/declarative/tutorial.qdoc index 98efe12..310b776 100644 --- a/doc/src/declarative/tutorial.qdoc +++ b/doc/src/declarative/tutorial.qdoc @@ -173,10 +173,10 @@ In this case the rectangle will have the same size as its parent (see \l{anchor- \snippet examples/declarative/tutorials/helloworld/Cell.qml 3 -In order to change the color of the text when clicking on a cell, we create a \l MouseRegion element with +In order to change the color of the text when clicking on a cell, we create a \l MouseArea element with the same size as its parent. -A \l MouseRegion defines a signal called \e clicked. +A \l MouseArea defines a signal called \e clicked. When this signal is triggered we want to emit our own \e clicked signal with the color as parameter. \section2 The main QML file @@ -214,7 +214,7 @@ Here is the QML code: \snippet examples/declarative/tutorials/helloworld/tutorial3.qml 2 First, we create a new \e down state for our text element. -This state will be activated when the \l MouseRegion is pressed, and deactivated when it is released. +This state will be activated when the \l MouseArea is pressed, and deactivated when it is released. The \e down state includes a set of property changes from our implicit \e {default state} (the items as they were initially defined in the QML). diff --git a/examples/declarative/colorbrowser/colorbrowser.qml b/examples/declarative/colorbrowser/colorbrowser.qml index ebd49c6..421ae07 100644 --- a/examples/declarative/colorbrowser/colorbrowser.qml +++ b/examples/declarative/colorbrowser/colorbrowser.qml @@ -53,7 +53,7 @@ Rectangle { Text { id: albumTitle; text: name; color: 'white'; font.bold: true; anchors.centerIn: parent } } - MouseRegion { anchors.fill: parent; onClicked: wrapper.state = 'inGrid' } + MouseArea { anchors.fill: parent; onClicked: wrapper.state = 'inGrid' } states: [ State { diff --git a/examples/declarative/colorbrowser/qml/ColorDelegate.qml b/examples/declarative/colorbrowser/qml/ColorDelegate.qml index 605e45b..c123d12 100644 --- a/examples/declarative/colorbrowser/qml/ColorDelegate.qml +++ b/examples/declarative/colorbrowser/qml/ColorDelegate.qml @@ -27,7 +27,7 @@ Package { value: hex; when: delegate.open && list.ListView.isCurrentItem } - MouseRegion { + MouseArea { anchors.fill: parent acceptedButtons: Qt.RightButton | Qt.LeftButton onClicked: { diff --git a/examples/declarative/package/Delegate.qml b/examples/declarative/package/Delegate.qml index 62198d0..f35314f 100644 --- a/examples/declarative/package/Delegate.qml +++ b/examples/declarative/package/Delegate.qml @@ -11,7 +11,7 @@ Package { color: 'lightsteelblue' Text { text: display; anchors.centerIn: parent } - MouseRegion { + MouseArea { anchors.fill: parent onClicked: { if (wrapper.state == 'inList') diff --git a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp index a0aed46..55f1c89 100644 --- a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp +++ b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp @@ -144,7 +144,7 @@ QDeclarativeVisualItemModel::QDeclarativeVisualItemModel() QDeclarativeListProperty QDeclarativeVisualItemModel::children() { Q_D(QDeclarativeVisualItemModel); - return QDeclarativeListProperty(this, d, d->children_append, + return QDeclarativeListProperty(this, d, d->children_append, d->children_count, d->children_at); } @@ -483,7 +483,7 @@ QVariant QDeclarativeVisualDataModelDataMetaObject::initialValue(int propId) QDeclarativeVisualDataModelData::QDeclarativeVisualDataModelData(int index, QDeclarativeVisualDataModel *model) -: m_index(index), m_model(model), +: m_index(index), m_model(model), m_meta(new QDeclarativeVisualDataModelDataMetaObject(this, QDeclarativeVisualDataModelPrivate::get(model)->m_delegateDataType)) { QDeclarativeVisualDataModelPrivate *modelPriv = QDeclarativeVisualDataModelPrivate::get(model); @@ -550,7 +550,7 @@ QVariant QDeclarativeVisualDataModelPartsMetaObject::initialValue(int id) } QDeclarativeVisualDataModelParts::QDeclarativeVisualDataModelParts(QDeclarativeVisualDataModel *parent) -: QObject(parent), model(parent) +: QObject(parent), model(parent) { new QDeclarativeVisualDataModelPartsMetaObject(this); } @@ -840,7 +840,7 @@ void QDeclarativeVisualDataModel::setDelegate(QDeclarativeComponent *delegate) Rectangle { height: 25; width: 100 Text { text: path } - MouseRegion { + MouseArea { anchors.fill: parent; onClicked: myModel.setRoot(path) } @@ -969,7 +969,7 @@ QDeclarativeVisualDataModel::ReleaseFlags QDeclarativeVisualDataModel::release(Q QObject *QDeclarativeVisualDataModel::parts() { Q_D(QDeclarativeVisualDataModel); - if (!d->m_parts) + if (!d->m_parts) d->m_parts = new QDeclarativeVisualDataModelParts(this); return d->m_parts; } -- cgit v0.12 From a2af08f9793b3884bdb770f89edd4754c0411654 Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Thu, 4 Mar 2010 00:54:06 +1000 Subject: Clairify a comment in one of the auto tests. --- .../declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp index dea88c4..b1935df 100644 --- a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp +++ b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp @@ -671,9 +671,9 @@ void tst_qdeclarativetextedit::delegateLoading() QTRY_VERIFY(view->status()==QDeclarativeView::Error); view->setFocus(); QTRY_VERIFY(!view->rootObject()); // there is fail item inside this test - //ErrorB should get a component which is ready but component.create() returns null + //A test should be added here with a component which is ready but component.create() returns null //Not sure how to accomplish this with QDeclarativeTextEdits cursor delegate - //###This could be a case of overzealous defensive programming + //###This was only needed for code coverage, and could be a case of overzealous defensive programming //delegate = view->rootObject()->findChild("delegateErrorB"); //QVERIFY(!delegate); } -- cgit v0.12 From 1a7df5ef1fc81fbf2d548c40e3feeb8ef3bb5a8c Mon Sep 17 00:00:00 2001 From: mae Date: Wed, 3 Mar 2010 19:39:45 +0100 Subject: make example work again The code is now a bit on the imperative side, but that was the only working solution to remove the binding loops. --- examples/declarative/dynamic/qml/Sun.qml | 8 ++++---- examples/declarative/imageprovider/imageprovider.qml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/declarative/dynamic/qml/Sun.qml b/examples/declarative/dynamic/qml/Sun.qml index 796a370..81b6e9b 100644 --- a/examples/declarative/dynamic/qml/Sun.qml +++ b/examples/declarative/dynamic/qml/Sun.qml @@ -11,14 +11,14 @@ Image { //x and y get set when instantiated //head offscreen - y: NumberAnimation { - to: parent.height; - duration: 10000; + NumberAnimation on y { + to: window.height / 2; running: created + onRunningChanged: if (running) duration = (window.height - sun.y) * 10; else state = "OffScreen"; } states: State { - name: "OffScreen"; when: created && y > window.height / 2;//Below the ground + name: "OffScreen"; StateChangeScript { script: { sun.created = false; sun.destroy() } } } } diff --git a/examples/declarative/imageprovider/imageprovider.qml b/examples/declarative/imageprovider/imageprovider.qml index a1f2794..f899b1e 100644 --- a/examples/declarative/imageprovider/imageprovider.qml +++ b/examples/declarative/imageprovider/imageprovider.qml @@ -1,5 +1,5 @@ import Qt 4.6 -import ImageProviderCore 1.0 +import "ImageProviderCore" //![0] ListView { width: 100 -- cgit v0.12 From 24c1173aac92e9a4e14da072b5aa62c8289d810d Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 4 Mar 2010 08:54:40 +1000 Subject: Fix painting Rectangle with radius < side/2. Falls back to using standard QPainter. Also avoid painting odd width borders between pixels, i.e. pixel align painting. Task-number: QTBUG-6675, QTBUG-8317, QTBUG-6786 --- .../graphicsitems/qdeclarativerectangle.cpp | 25 ++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativerectangle.cpp b/src/declarative/graphicsitems/qdeclarativerectangle.cpp index d534f21..05fe0f7 100644 --- a/src/declarative/graphicsitems/qdeclarativerectangle.cpp +++ b/src/declarative/graphicsitems/qdeclarativerectangle.cpp @@ -393,9 +393,10 @@ void QDeclarativeRectangle::paint(QPainter *p, const QStyleOptionGraphicsItem *, void QDeclarativeRectangle::drawRect(QPainter &p) { Q_D(QDeclarativeRectangle); - if (d->gradient && d->gradient->gradient()) { + if ((d->gradient && d->gradient->gradient()) + || d->radius > width()/2 || d->radius > height()/2) { // XXX This path is still slower than the image path - // Image path won't work for gradients though + // Image path won't work for gradients or invalid radius though bool oldAA = p.testRenderHint(QPainter::Antialiasing); if (d->smooth) p.setRenderHint(QPainter::Antialiasing); @@ -405,11 +406,23 @@ void QDeclarativeRectangle::drawRect(QPainter &p) } else { p.setPen(Qt::NoPen); } - p.setBrush(*d->gradient->gradient()); - if (d->radius > 0.) - p.drawRoundedRect(0, 0, width(), height(), d->radius, d->radius); + if (d->gradient && d->gradient->gradient()) + p.setBrush(*d->gradient->gradient()); else - p.drawRect(0, 0, width(), height()); + p.setBrush(d->color); + const int pw = d->pen && d->pen->isValid() ? d->pen->width() : 0; + QRectF rect; + if (pw%2) + rect = QRectF(0.5, 0.5, width()-1, height()-1); + else + rect = QRectF(0, 0, width(), height()); + qreal radius = d->radius; + if (radius > width()/2 || radius > height()/2) + radius = qMin(width()/2, height()/2); + if (radius > 0.) + p.drawRoundedRect(rect, radius, radius); + else + p.drawRect(rect); if (d->smooth) p.setRenderHint(QPainter::Antialiasing, oldAA); } else { -- cgit v0.12 From 89e29d1f7a61f5cfa15cbce9b225a9d9ee9b4b7f Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Thu, 4 Mar 2010 08:59:06 +1000 Subject: Fix url in source() test. --- .../qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp b/tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp index 841a0ee..de11fe2 100644 --- a/tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp +++ b/tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp @@ -103,7 +103,7 @@ void tst_QDeclarativeWorkerScript::source_data() QTest::addColumn("valid"); QTest::newRow("valid") << QUrl::fromLocalFile(SRCDIR "/data/worker.qml") << true; - QTest::newRow("invalid") << QUrl("file:///asdjfk.js") << false; + QTest::newRow("invalid") << QUrl::fromLocalFile("asdjfk.js") << false; } void tst_QDeclarativeWorkerScript::messaging() -- cgit v0.12 From f53ac4f7617bfdefcb62e9b27ee6bf1a91a7ed13 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Thu, 4 Mar 2010 09:37:04 +1000 Subject: Fix test to listen for signal instead of try-waiting for property. --- .../declarative/qdeclarativeworkerscript/data/worker.qml | 5 +++-- .../tst_qdeclarativeworkerscript.cpp | 13 ++++++++----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/tests/auto/declarative/qdeclarativeworkerscript/data/worker.qml b/tests/auto/declarative/qdeclarativeworkerscript/data/worker.qml index 2982010..bb4028f 100644 --- a/tests/auto/declarative/qdeclarativeworkerscript/data/worker.qml +++ b/tests/auto/declarative/qdeclarativeworkerscript/data/worker.qml @@ -4,9 +4,10 @@ WorkerScript { id: worker source: "script.js" - property bool done : false property var response + signal done() + function testSend(value) { worker.sendMessage(value) } @@ -21,7 +22,7 @@ WorkerScript { } onMessage: { - worker.done = true worker.response = messageObject + worker.done() } } diff --git a/tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp b/tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp index 841a0ee..b0fc212 100644 --- a/tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp +++ b/tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp @@ -40,6 +40,7 @@ ****************************************************************************/ #include #include +#include #include #include @@ -67,11 +68,13 @@ private slots: private: void waitForEchoMessage(QDeclarativeWorkerScript *worker) { - const QMetaObject *mo = worker->metaObject(); - int index = mo->indexOfProperty("done"); - QVERIFY(index >= 0); - QTRY_COMPARE(mo->property(index).read(worker).toBool(), true); - QTRY_COMPARE(mo->property(mo->indexOfProperty("done")).read(worker).toBool(), true); + QEventLoop loop; + QVERIFY(connect(worker, SIGNAL(done()), &loop, SLOT(quit()))); + QTimer timer; + connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit())); + timer.start(1000); + loop.exec(); + QVERIFY(timer.isActive()); } QDeclarativeEngine m_engine; -- cgit v0.12 From e8916f0b69abad1de5767ac6ca1a555f40e3f675 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Thu, 4 Mar 2010 09:46:25 +1000 Subject: Increase test timer --- .../qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp b/tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp index 15caea6..9957b50 100644 --- a/tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp +++ b/tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp @@ -71,8 +71,9 @@ private: QEventLoop loop; QVERIFY(connect(worker, SIGNAL(done()), &loop, SLOT(quit()))); QTimer timer; + timer.setSingleShot(true); connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit())); - timer.start(1000); + timer.start(10000); loop.exec(); QVERIFY(timer.isActive()); } -- cgit v0.12 From 89a478c8c747b2f572deb88d028715e88c16853e Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 4 Mar 2010 09:53:28 +1000 Subject: Make sure currentIndex is updated when view is flicked. Task-number: QTBUG-8396 --- examples/declarative/parallax/qml/ParallaxView.qml | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/declarative/parallax/qml/ParallaxView.qml b/examples/declarative/parallax/qml/ParallaxView.qml index 5e58100..08193ae 100644 --- a/examples/declarative/parallax/qml/ParallaxView.qml +++ b/examples/declarative/parallax/qml/ParallaxView.qml @@ -25,6 +25,7 @@ Item { anchors.fill: parent model: VisualItemModel { id: visualModel } + highlightRangeMode: ListView.StrictlyEnforceRange snapMode: ListView.SnapOneItem } -- cgit v0.12 From 06e61382f0d6f07798f7db3049f3e185be54efc1 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Thu, 4 Mar 2010 09:54:16 +1000 Subject: system import path not supported with Qt 4.6. --- src/declarative/qml/qdeclarativeengine.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index ecaea61..bd67b0b 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -1383,7 +1383,11 @@ public: paths += QFileInfo(base.toLocalFile()).path(); paths += importPath; paths += QDeclarativeEnginePrivate::get(engine)->environmentImportPath; +#if (QT_VERSION >= QT_VERSION_CHECK(4,7,0)) QString builtinPath = QLibraryInfo::location(QLibraryInfo::ImportsPath); +#else + QString builtinPath; +#endif if (!builtinPath.isEmpty()) paths += builtinPath; -- cgit v0.12 From b67d5d90a306534a1ea2fcb333981c6b1126105c Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Thu, 4 Mar 2010 09:54:42 +1000 Subject: Fix visibility of classes in private headers upon which Bauhaus/Creator relies. Author: Erik Verbruggen --- src/declarative/qml/qdeclarativebinding_p.h | 4 ++-- src/declarative/qml/qdeclarativeproperty_p.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/declarative/qml/qdeclarativebinding_p.h b/src/declarative/qml/qdeclarativebinding_p.h index ec5809d..1a714f0 100644 --- a/src/declarative/qml/qdeclarativebinding_p.h +++ b/src/declarative/qml/qdeclarativebinding_p.h @@ -64,7 +64,7 @@ QT_BEGIN_NAMESPACE -class Q_AUTOTEST_EXPORT QDeclarativeAbstractBinding +class Q_DECLARATIVE_EXPORT QDeclarativeAbstractBinding { public: QDeclarativeAbstractBinding(); @@ -101,7 +101,7 @@ private: class QDeclarativeContext; class QDeclarativeBindingPrivate; -class Q_AUTOTEST_EXPORT QDeclarativeBinding : public QDeclarativeExpression, public QDeclarativeAbstractBinding +class Q_DECLARATIVE_EXPORT QDeclarativeBinding : public QDeclarativeExpression, public QDeclarativeAbstractBinding { Q_OBJECT public: diff --git a/src/declarative/qml/qdeclarativeproperty_p.h b/src/declarative/qml/qdeclarativeproperty_p.h index 1fda7f4..c31e2d3 100644 --- a/src/declarative/qml/qdeclarativeproperty_p.h +++ b/src/declarative/qml/qdeclarativeproperty_p.h @@ -65,7 +65,7 @@ QT_BEGIN_NAMESPACE class QDeclarativeContext; class QDeclarativeEnginePrivate; class QDeclarativeExpression; -class Q_AUTOTEST_EXPORT QDeclarativePropertyPrivate +class Q_DECLARATIVE_EXPORT QDeclarativePropertyPrivate { public: enum WriteFlag { BypassInterceptor = 0x01, DontRemoveBinding = 0x02 }; -- cgit v0.12 From 7ab3b4d96a0cedb50d2c1ce5bfe9eed315548c4f Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Thu, 4 Mar 2010 09:56:03 +1000 Subject: Fix Samegame. --- demos/declarative/samegame/SamegameCore/samegame.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demos/declarative/samegame/SamegameCore/samegame.js b/demos/declarative/samegame/SamegameCore/samegame.js index c0f10bd..1214b79 100755 --- a/demos/declarative/samegame/SamegameCore/samegame.js +++ b/demos/declarative/samegame/SamegameCore/samegame.js @@ -4,7 +4,7 @@ var maxX = 10;//Nums are for gameCanvas.tileSize 40 var maxY = 15; var maxIndex = maxX*maxY; var board = new Array(maxIndex); -var tileSrc = "content/BoomBlock.qml"; +var tileSrc = "SamegameCore/BoomBlock.qml"; var scoresURL = "http://qtfx-nokia.trolltech.com.au/samegame/scores.php"; var scoresURL = ""; var timer; -- cgit v0.12 From 26d28b39504d1c55690985deb52646114b6cf710 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Thu, 4 Mar 2010 10:43:33 +1000 Subject: Fix benchmarks. Get them all running again after renames, etc. --- tests/benchmarks/declarative/binding/binding.pro | 3 +++ tests/benchmarks/declarative/binding/data/idproperty.txt | 2 +- .../declarative/binding/data/objectproperty.txt | 2 +- tests/benchmarks/declarative/binding/testtypes.h | 6 +++--- tests/benchmarks/declarative/binding/tst_binding.cpp | 16 ++++++++-------- tests/benchmarks/declarative/creation/tst_creation.cpp | 5 +++-- .../qdeclarativecomponent/data/samegame/BoomBlock.qml | 6 +++--- .../qdeclarativecomponent/qdeclarativecomponent.pro | 3 +++ .../declarative/qdeclarativecomponent/testtypes.h | 6 +++--- .../qdeclarativecomponent/tst_qdeclarativecomponent.cpp | 14 +++++++------- .../qdeclarativemetaproperty.pro | 2 ++ .../tst_qdeclarativemetaproperty.cpp | 8 ++++---- tests/benchmarks/declarative/script/tst_script.cpp | 11 ++++++----- 13 files changed, 47 insertions(+), 37 deletions(-) diff --git a/tests/benchmarks/declarative/binding/binding.pro b/tests/benchmarks/declarative/binding/binding.pro index aa4cc41..5ceaf34 100644 --- a/tests/benchmarks/declarative/binding/binding.pro +++ b/tests/benchmarks/declarative/binding/binding.pro @@ -7,6 +7,9 @@ macx:CONFIG -= app_bundle SOURCES += tst_binding.cpp testtypes.cpp HEADERS += testtypes.h +# Define SRCDIR equal to test's source directory +DEFINES += SRCDIR=\\\"$$PWD\\\" + symbian* { data.sources = data/* data.path = data diff --git a/tests/benchmarks/declarative/binding/data/idproperty.txt b/tests/benchmarks/declarative/binding/data/idproperty.txt index 71e3c4e..4e474ba 100644 --- a/tests/benchmarks/declarative/binding/data/idproperty.txt +++ b/tests/benchmarks/declarative/binding/data/idproperty.txt @@ -1,7 +1,7 @@ import Test 1.0 MyQmlObject { - id: MyObject + id: myObject MyQmlObject { result: ### diff --git a/tests/benchmarks/declarative/binding/data/objectproperty.txt b/tests/benchmarks/declarative/binding/data/objectproperty.txt index 63fa74d..6133dd6 100644 --- a/tests/benchmarks/declarative/binding/data/objectproperty.txt +++ b/tests/benchmarks/declarative/binding/data/objectproperty.txt @@ -1,7 +1,7 @@ import Test 1.0 MyQmlObject { - id: MyObject + id: myObject result: ### } diff --git a/tests/benchmarks/declarative/binding/testtypes.h b/tests/benchmarks/declarative/binding/testtypes.h index 4b103ce..523f94d 100644 --- a/tests/benchmarks/declarative/binding/testtypes.h +++ b/tests/benchmarks/declarative/binding/testtypes.h @@ -50,7 +50,7 @@ class MyQmlObject : public QObject Q_PROPERTY(int result READ result WRITE setResult); Q_PROPERTY(int value READ value WRITE setValue NOTIFY valueChanged); Q_PROPERTY(MyQmlObject *object READ object WRITE setObject NOTIFY objectChanged); - Q_PROPERTY(QDeclarativeList *data READ data); + Q_PROPERTY(QDeclarativeListProperty data READ data); Q_CLASSINFO("DefaultProperty", "data"); public: MyQmlObject() : m_result(0), m_value(0), m_object(0) {} @@ -61,7 +61,7 @@ public: int value() const { return m_value; } void setValue(int v) { m_value = v; emit valueChanged(); } - QDeclarativeList *data() { return &m_data; } + QDeclarativeListProperty data() { return QDeclarativeListProperty(this, m_data); } MyQmlObject *object() const { return m_object; } void setObject(MyQmlObject *o) { m_object = o; emit objectChanged(); } @@ -71,7 +71,7 @@ signals: void objectChanged(); private: - QDeclarativeConcreteList m_data; + QList m_data; int m_result; int m_value; MyQmlObject *m_object; diff --git a/tests/benchmarks/declarative/binding/tst_binding.cpp b/tests/benchmarks/declarative/binding/tst_binding.cpp index ee529a7..dbddac3 100644 --- a/tests/benchmarks/declarative/binding/tst_binding.cpp +++ b/tests/benchmarks/declarative/binding/tst_binding.cpp @@ -103,8 +103,8 @@ void tst_binding::objectproperty_data() QTest::addColumn("file"); QTest::addColumn("binding"); - QTest::newRow("object.value") << "data/objectproperty.txt" << "object.value"; - QTest::newRow("object.value + 10") << "data/objectproperty.txt" << "object.value + 10"; + QTest::newRow("object.value") << SRCDIR "/data/objectproperty.txt" << "object.value"; + QTest::newRow("object.value + 10") << SRCDIR "/data/objectproperty.txt" << "object.value + 10"; } void tst_binding::objectproperty() @@ -132,13 +132,13 @@ void tst_binding::basicproperty_data() QTest::addColumn("file"); QTest::addColumn("binding"); - QTest::newRow("value") << "data/localproperty.txt" << "value"; - QTest::newRow("value + 10") << "data/localproperty.txt" << "value + 10"; - QTest::newRow("value + value + 10") << "data/localproperty.txt" << "value + value + 10"; + QTest::newRow("value") << SRCDIR "/data/localproperty.txt" << "value"; + QTest::newRow("value + 10") << SRCDIR "/data/localproperty.txt" << "value + 10"; + QTest::newRow("value + value + 10") << SRCDIR "/data/localproperty.txt" << "value + value + 10"; - QTest::newRow("MyObject.value") << "data/idproperty.txt" << "MyObject.value"; - QTest::newRow("MyObject.value + 10") << "data/idproperty.txt" << "MyObject.value + 10"; - QTest::newRow("MyObject.value + MyObject.value + 10") << "data/idproperty.txt" << "MyObject.value + MyObject.value + 10"; + QTest::newRow("myObject.value") << SRCDIR "/data/idproperty.txt" << "myObject.value"; + QTest::newRow("myObject.value + 10") << SRCDIR "/data/idproperty.txt" << "myObject.value + 10"; + QTest::newRow("myObject.value + myObject.value + 10") << SRCDIR "/data/idproperty.txt" << "myObject.value + myObject.value + 10"; } void tst_binding::basicproperty() diff --git a/tests/benchmarks/declarative/creation/tst_creation.cpp b/tests/benchmarks/declarative/creation/tst_creation.cpp index 9c0fd27..4319208 100644 --- a/tests/benchmarks/declarative/creation/tst_creation.cpp +++ b/tests/benchmarks/declarative/creation/tst_creation.cpp @@ -42,7 +42,7 @@ #include #include #include -#include +#include #include #include #include @@ -339,7 +339,8 @@ void tst_creation::itemtree_data_cpp() for (int i = 0; i < 30; ++i) { QDeclarativeItem *child = new QDeclarativeItem; QDeclarativeGraphics_setParent_noEvent(child,item); - item->data()->append(child); + QDeclarativeListReference ref(item, "data"); + ref.append(child); } delete item; } diff --git a/tests/benchmarks/declarative/qdeclarativecomponent/data/samegame/BoomBlock.qml b/tests/benchmarks/declarative/qdeclarativecomponent/data/samegame/BoomBlock.qml index 723e62a..e48194a 100644 --- a/tests/benchmarks/declarative/qdeclarativecomponent/data/samegame/BoomBlock.qml +++ b/tests/benchmarks/declarative/qdeclarativecomponent/data/samegame/BoomBlock.qml @@ -7,8 +7,8 @@ Item { id:block property int targetX: 0 property int targetY: 0 - x: SpringFollow { enabled: spawned; source: targetX; spring: 2; damping: 0.2 } - y: SpringFollow { source: targetY; spring: 2; damping: 0.2 } + SpringFollow on x { enabled: spawned; source: targetX; spring: 2; damping: 0.2 } + SpringFollow on y { source: targetY; spring: 2; damping: 0.2 } Image { id: img source: { @@ -21,7 +21,7 @@ Item { id:block } } opacity: 0 - opacity: Behavior { NumberAnimation { duration: 200 } } + Behavior on opacity { NumberAnimation { duration: 200 } } anchors.fill: parent } diff --git a/tests/benchmarks/declarative/qdeclarativecomponent/qdeclarativecomponent.pro b/tests/benchmarks/declarative/qdeclarativecomponent/qdeclarativecomponent.pro index 12fa9f4..30ef235 100644 --- a/tests/benchmarks/declarative/qdeclarativecomponent/qdeclarativecomponent.pro +++ b/tests/benchmarks/declarative/qdeclarativecomponent/qdeclarativecomponent.pro @@ -7,6 +7,9 @@ macx:CONFIG -= app_bundle SOURCES += tst_qdeclarativecomponent.cpp testtypes.cpp HEADERS += testtypes.h +# Define SRCDIR equal to test's source directory +DEFINES += SRCDIR=\\\"$$PWD\\\" + symbian* { data.sources = data/* data.path = data diff --git a/tests/benchmarks/declarative/qdeclarativecomponent/testtypes.h b/tests/benchmarks/declarative/qdeclarativecomponent/testtypes.h index 4b103ce..523f94d 100644 --- a/tests/benchmarks/declarative/qdeclarativecomponent/testtypes.h +++ b/tests/benchmarks/declarative/qdeclarativecomponent/testtypes.h @@ -50,7 +50,7 @@ class MyQmlObject : public QObject Q_PROPERTY(int result READ result WRITE setResult); Q_PROPERTY(int value READ value WRITE setValue NOTIFY valueChanged); Q_PROPERTY(MyQmlObject *object READ object WRITE setObject NOTIFY objectChanged); - Q_PROPERTY(QDeclarativeList *data READ data); + Q_PROPERTY(QDeclarativeListProperty data READ data); Q_CLASSINFO("DefaultProperty", "data"); public: MyQmlObject() : m_result(0), m_value(0), m_object(0) {} @@ -61,7 +61,7 @@ public: int value() const { return m_value; } void setValue(int v) { m_value = v; emit valueChanged(); } - QDeclarativeList *data() { return &m_data; } + QDeclarativeListProperty data() { return QDeclarativeListProperty(this, m_data); } MyQmlObject *object() const { return m_object; } void setObject(MyQmlObject *o) { m_object = o; emit objectChanged(); } @@ -71,7 +71,7 @@ signals: void objectChanged(); private: - QDeclarativeConcreteList m_data; + QList m_data; int m_result; int m_value; MyQmlObject *m_object; diff --git a/tests/benchmarks/declarative/qdeclarativecomponent/tst_qdeclarativecomponent.cpp b/tests/benchmarks/declarative/qdeclarativecomponent/tst_qdeclarativecomponent.cpp index 7065303..4b1456e 100644 --- a/tests/benchmarks/declarative/qdeclarativecomponent/tst_qdeclarativecomponent.cpp +++ b/tests/benchmarks/declarative/qdeclarativecomponent/tst_qdeclarativecomponent.cpp @@ -90,13 +90,13 @@ void tst_qmlcomponent::creation_data() { QTest::addColumn("file"); - QTest::newRow("Object") << "data/object.qml"; - QTest::newRow("Object - Id") << "data/object_id.qml"; - QTest::newRow("MyQmlObject") << "data/myqmlobject.qml"; - QTest::newRow("MyQmlObject: basic binding") << "data/myqmlobject_binding.qml"; - QTest::newRow("Synthesized properties") << "data/synthesized_properties.qml"; - QTest::newRow("Synthesized properties.2") << "data/synthesized_properties.2.qml"; - QTest::newRow("SameGame - BoomBlock") << "data/samegame/BoomBlock.qml"; + QTest::newRow("Object") << SRCDIR "/data/object.qml"; + QTest::newRow("Object - Id") << SRCDIR "/data/object_id.qml"; + QTest::newRow("MyQmlObject") << SRCDIR "/data/myqmlobject.qml"; + QTest::newRow("MyQmlObject: basic binding") << SRCDIR "/data/myqmlobject_binding.qml"; + QTest::newRow("Synthesized properties") << SRCDIR "/data/synthesized_properties.qml"; + QTest::newRow("Synthesized properties.2") << SRCDIR "/data/synthesized_properties.2.qml"; + QTest::newRow("SameGame - BoomBlock") << SRCDIR "/data/samegame/BoomBlock.qml"; } void tst_qmlcomponent::creation() diff --git a/tests/benchmarks/declarative/qdeclarativemetaproperty/qdeclarativemetaproperty.pro b/tests/benchmarks/declarative/qdeclarativemetaproperty/qdeclarativemetaproperty.pro index 8070768..79fdd26 100644 --- a/tests/benchmarks/declarative/qdeclarativemetaproperty/qdeclarativemetaproperty.pro +++ b/tests/benchmarks/declarative/qdeclarativemetaproperty/qdeclarativemetaproperty.pro @@ -6,3 +6,5 @@ macx:CONFIG -= app_bundle SOURCES += tst_qdeclarativemetaproperty.cpp +# Define SRCDIR equal to test's source directory +DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/benchmarks/declarative/qdeclarativemetaproperty/tst_qdeclarativemetaproperty.cpp b/tests/benchmarks/declarative/qdeclarativemetaproperty/tst_qdeclarativemetaproperty.cpp index dae1751..8a5f4ae 100644 --- a/tests/benchmarks/declarative/qdeclarativemetaproperty/tst_qdeclarativemetaproperty.cpp +++ b/tests/benchmarks/declarative/qdeclarativemetaproperty/tst_qdeclarativemetaproperty.cpp @@ -42,7 +42,7 @@ #include #include #include -#include +#include #include #include @@ -89,8 +89,8 @@ void tst_qmlmetaproperty::lookup_data() { QTest::addColumn("file"); - QTest::newRow("Simple Object") << "data/object.qml"; - QTest::newRow("Synthesized Object") << "data/synthesized_object.qml"; + QTest::newRow("Simple Object") << SRCDIR "/data/object.qml"; + QTest::newRow("Synthesized Object") << SRCDIR "/data/synthesized_object.qml"; } void tst_qmlmetaproperty::lookup() @@ -103,7 +103,7 @@ void tst_qmlmetaproperty::lookup() QObject *obj = c.create(); QBENCHMARK { - QDeclarativeMetaProperty p(obj, "x"); + QDeclarativeProperty p(obj, "x"); } delete obj; diff --git a/tests/benchmarks/declarative/script/tst_script.cpp b/tests/benchmarks/declarative/script/tst_script.cpp index 61f5fc8..9dd4076 100644 --- a/tests/benchmarks/declarative/script/tst_script.cpp +++ b/tests/benchmarks/declarative/script/tst_script.cpp @@ -96,11 +96,6 @@ private slots: private: }; -void tst_script::initTestCase() -{ - QML_REGISTER_TYPE(Qt.test, 1, 0, TestObject, TestObject); -} - inline QUrl TEST_FILE(const QString &filename) { return QUrl::fromLocalFile(QLatin1String(SRCDIR) + QLatin1String("/data/") + filename); @@ -147,6 +142,12 @@ int TestObject::x() return m_x++; } +void tst_script::initTestCase() +{ + QML_REGISTER_TYPE(Qt.test, 1, 0, TestObject, TestObject); +} + + #define PROPERTY_PROGRAM \ "(function(testObject) { return (function() { " \ " var test = 0; " \ -- cgit v0.12 From 1c21463aca94051a5c5e293bd9d5f6da8c491bf9 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 4 Mar 2010 10:45:55 +1000 Subject: Set StrongFocus on QDeclarativeView so that elements can get focus. Task-number: QTBUG-8637 --- src/declarative/util/qdeclarativeview.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/declarative/util/qdeclarativeview.cpp b/src/declarative/util/qdeclarativeview.cpp index f08e634..cd67aeb 100644 --- a/src/declarative/util/qdeclarativeview.cpp +++ b/src/declarative/util/qdeclarativeview.cpp @@ -194,6 +194,7 @@ void QDeclarativeViewPrivate::execute() \o Initializes QGraphicsView for QML key handling: \list \o QGraphicsView::viewport()->setFocusPolicy(Qt::NoFocus); + \o QGraphicsView::setFocusPolicy(Qt::StrongFocus); \o QGraphicsScene::setStickyFocus(true); \endlist \endlist @@ -268,6 +269,7 @@ void QDeclarativeViewPrivate::init() q->setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate); scene.setItemIndexMethod(QGraphicsScene::NoIndex); q->viewport()->setFocusPolicy(Qt::NoFocus); + q->setFocusPolicy(Qt::StrongFocus); scene.setStickyFocus(true); //### needed for correct focus handling } -- cgit v0.12 From 4164a11032b64fe5a557515f283fa0e4c6d0260d Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Thu, 4 Mar 2010 12:18:36 +1000 Subject: Fix test. --- tests/benchmarks/declarative/qdeclarativecomponent/data/object_id.qml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/benchmarks/declarative/qdeclarativecomponent/data/object_id.qml b/tests/benchmarks/declarative/qdeclarativecomponent/data/object_id.qml index 69114af..dc29f15 100644 --- a/tests/benchmarks/declarative/qdeclarativecomponent/data/object_id.qml +++ b/tests/benchmarks/declarative/qdeclarativecomponent/data/object_id.qml @@ -1,6 +1,6 @@ import Qt 4.6 QtObject { - id: Blah + id: blah } -- cgit v0.12 From 1287332bfc1dfb85c59c309d9f2bf37b970013c9 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 4 Mar 2010 12:58:13 +1000 Subject: Document that the views do not set clip: true. Task-number: QT-2942 --- src/declarative/graphicsitems/qdeclarativegridview.cpp | 5 +++++ src/declarative/graphicsitems/qdeclarativelistview.cpp | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/src/declarative/graphicsitems/qdeclarativegridview.cpp b/src/declarative/graphicsitems/qdeclarativegridview.cpp index 5b313be..7b97dcc 100644 --- a/src/declarative/graphicsitems/qdeclarativegridview.cpp +++ b/src/declarative/graphicsitems/qdeclarativegridview.cpp @@ -697,6 +697,11 @@ void QDeclarativeGridViewPrivate::updateCurrent(int modelIndex) In this case ListModel is a handy way for us to test our UI. In practice the model would be implemented in C++, or perhaps via a SQL data source. + + Note that views do not enabel \e clip automatically. If the view + is not clipped by another item or the screen, it will be necessary + to set \e {clip: true} in order to have the out of view items clipped + nicely. */ QDeclarativeGridView::QDeclarativeGridView(QDeclarativeItem *parent) : QDeclarativeFlickable(*(new QDeclarativeGridViewPrivate), parent) diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp index eb5315d..09f8162 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview.cpp +++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp @@ -1359,6 +1359,11 @@ void QDeclarativeListViewPrivate::flickY(qreal velocity) In this case ListModel is a handy way for us to test our UI. In practice the model would be implemented in C++, or perhaps via a SQL data source. + + Note that views do not enabel \e clip automatically. If the view + is not clipped by another item or the screen, it will be necessary + to set \e {clip: true} in order to have the out of view items clipped + nicely. */ QDeclarativeListView::QDeclarativeListView(QDeclarativeItem *parent) -- cgit v0.12 From 08cf6561c4ad2288e385e63d941b60b268cc484e Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 4 Mar 2010 13:05:17 +1000 Subject: Fix spelling. --- src/declarative/graphicsitems/qdeclarativegridview.cpp | 2 +- src/declarative/graphicsitems/qdeclarativelistview.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativegridview.cpp b/src/declarative/graphicsitems/qdeclarativegridview.cpp index 7b97dcc..a6f3d8f 100644 --- a/src/declarative/graphicsitems/qdeclarativegridview.cpp +++ b/src/declarative/graphicsitems/qdeclarativegridview.cpp @@ -698,7 +698,7 @@ void QDeclarativeGridViewPrivate::updateCurrent(int modelIndex) In this case ListModel is a handy way for us to test our UI. In practice the model would be implemented in C++, or perhaps via a SQL data source. - Note that views do not enabel \e clip automatically. If the view + Note that views do not enable \e clip automatically. If the view is not clipped by another item or the screen, it will be necessary to set \e {clip: true} in order to have the out of view items clipped nicely. diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp index 09f8162..a5da424 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview.cpp +++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp @@ -1360,7 +1360,7 @@ void QDeclarativeListViewPrivate::flickY(qreal velocity) In this case ListModel is a handy way for us to test our UI. In practice the model would be implemented in C++, or perhaps via a SQL data source. - Note that views do not enabel \e clip automatically. If the view + Note that views do not enable \e clip automatically. If the view is not clipped by another item or the screen, it will be necessary to set \e {clip: true} in order to have the out of view items clipped nicely. -- cgit v0.12 From afbfc2907b417034a98cf17f5787e0dfe467f737 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 4 Mar 2010 13:29:37 +1000 Subject: Remove unnecessary additional hash of QDeclarativeGridViewAttached --- .../graphicsitems/qdeclarativegridview.cpp | 9 ++++----- .../graphicsitems/qdeclarativegridview_p.h | 19 +++---------------- 2 files changed, 7 insertions(+), 21 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativegridview.cpp b/src/declarative/graphicsitems/qdeclarativegridview.cpp index a6f3d8f..b3c5577 100644 --- a/src/declarative/graphicsitems/qdeclarativegridview.cpp +++ b/src/declarative/graphicsitems/qdeclarativegridview.cpp @@ -52,8 +52,6 @@ QT_BEGIN_NAMESPACE -QHash QDeclarativeGridViewAttached::attachedProperties; - //---------------------------------------------------------------------------- @@ -61,8 +59,9 @@ class FxGridItem { public: FxGridItem(QDeclarativeItem *i, QDeclarativeGridView *v) : item(i), view(v) { - attached = QDeclarativeGridViewAttached::properties(item); - attached->m_view = view; + attached = static_cast(qmlAttachedPropertiesObject(item)); + if (attached) + attached->m_view = view; } ~FxGridItem() {} @@ -1748,7 +1747,7 @@ void QDeclarativeGridView::refill() QDeclarativeGridViewAttached *QDeclarativeGridView::qmlAttachedProperties(QObject *obj) { - return QDeclarativeGridViewAttached::properties(obj); + return new QDeclarativeGridViewAttached(obj); } QT_END_NAMESPACE diff --git a/src/declarative/graphicsitems/qdeclarativegridview_p.h b/src/declarative/graphicsitems/qdeclarativegridview_p.h index d463a46..22fcef6 100644 --- a/src/declarative/graphicsitems/qdeclarativegridview_p.h +++ b/src/declarative/graphicsitems/qdeclarativegridview_p.h @@ -167,9 +167,7 @@ class QDeclarativeGridViewAttached : public QObject public: QDeclarativeGridViewAttached(QObject *parent) : QObject(parent), m_isCurrent(false), m_delayRemove(false) {} - ~QDeclarativeGridViewAttached() { - attachedProperties.remove(parent()); - } + ~QDeclarativeGridViewAttached() {} Q_PROPERTY(QDeclarativeGridView *view READ view CONSTANT) QDeclarativeGridView *view() { return m_view; } @@ -192,15 +190,6 @@ public: } } - static QDeclarativeGridViewAttached *properties(QObject *obj) { - QDeclarativeGridViewAttached *rv = attachedProperties.value(obj); - if (!rv) { - rv = new QDeclarativeGridViewAttached(obj); - attachedProperties.insert(obj, rv); - } - return rv; - } - void emitAdd() { emit add(); } void emitRemove() { emit remove(); } @@ -212,10 +201,8 @@ Q_SIGNALS: public: QDeclarativeGridView *m_view; - bool m_isCurrent; - bool m_delayRemove; - - static QHash attachedProperties; + bool m_isCurrent : 1; + bool m_delayRemove : 1; }; -- cgit v0.12 From c425733907910ad04ed3abdefb5108d682858b12 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Thu, 4 Mar 2010 13:31:33 +1000 Subject: Fix tests failing due to javascript eval errors. --- .../qdeclarativeworkerscript/data/worker.qml | 4 ---- .../tst_qdeclarativeworkerscript.cpp | 20 +++++++++++++------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/tests/auto/declarative/qdeclarativeworkerscript/data/worker.qml b/tests/auto/declarative/qdeclarativeworkerscript/data/worker.qml index bb4028f..1fce155 100644 --- a/tests/auto/declarative/qdeclarativeworkerscript/data/worker.qml +++ b/tests/auto/declarative/qdeclarativeworkerscript/data/worker.qml @@ -12,10 +12,6 @@ WorkerScript { worker.sendMessage(value) } - function testSendLiteral(value) { - eval('worker.sendMessage(' + value +')') - } - function compareLiteralResponse(expected) { var e = eval('(' + expected + ')') return worker.response == e diff --git a/tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp b/tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp index 9957b50..27ecef4 100644 --- a/tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp +++ b/tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp @@ -48,9 +48,9 @@ #include #include +#include #include "../../../shared/util.h" -Q_DECLARE_METATYPE(QList) Q_DECLARE_METATYPE(QScriptValue) class tst_QDeclarativeWorkerScript : public QObject @@ -86,13 +86,14 @@ void tst_QDeclarativeWorkerScript::source() QFETCH(QUrl, source); QFETCH(bool, valid); - QDeclarativeComponent component(&m_engine); - component.setData("import Qt 4.6\nWorkerScript { source: '" + source.toString().toUtf8() + "'; }", QUrl()); - if (!valid) { QByteArray w = "WorkerScript: Cannot find source file \"" + source.toString().toUtf8() + "\""; QTest::ignoreMessage(QtWarningMsg, w.constData()); } + + QDeclarativeComponent component(&m_engine); + component.setData("import Qt 4.6\nWorkerScript { source: '" + source.toString().toUtf8() + "'; }", QUrl()); + QDeclarativeWorkerScript *item = qobject_cast(component.create()); QVERIFY(item != 0); @@ -169,9 +170,15 @@ void tst_QDeclarativeWorkerScript::messaging_sendJsObject() QDeclarativeWorkerScript *worker = qobject_cast(component.create()); QVERIFY(worker != 0); - QString jsObject = "{'spell power': 3101, 'haste': 1125}"; + QString jsObject = "{'name': 'zyz', 'spell power': 3101, 'haste': 1125}"; - QVERIFY(QMetaObject::invokeMethod(worker, "testSendLiteral", Q_ARG(QVariant, jsObject))); + QScriptEngine *engine = QDeclarativeEnginePrivate::getScriptEngine(qmlEngine(worker)); + QScriptValue sv = engine->newObject(); + sv.setProperty("name", "zyz"); + sv.setProperty("spell power", 3101); + sv.setProperty("haste", 1125); + + QVERIFY(QMetaObject::invokeMethod(worker, "testSend", Q_ARG(QVariant, qVariantFromValue(sv)))); waitForEchoMessage(worker); QVariant result = qVariantFromValue(false); @@ -185,4 +192,3 @@ void tst_QDeclarativeWorkerScript::messaging_sendJsObject() QTEST_MAIN(tst_QDeclarativeWorkerScript) #include "tst_qdeclarativeworkerscript.moc" - -- cgit v0.12 From 8047d8f2e63df60b5ea3f6fd02568658c3d19fc6 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 4 Mar 2010 14:39:18 +1000 Subject: Documented view behavior when items are removed from start of view. Task-number: QTBUG-7694 --- src/declarative/graphicsitems/qdeclarativegridview.cpp | 12 ++++++++++++ src/declarative/graphicsitems/qdeclarativelistview.cpp | 6 ++++++ 2 files changed, 18 insertions(+) diff --git a/src/declarative/graphicsitems/qdeclarativegridview.cpp b/src/declarative/graphicsitems/qdeclarativegridview.cpp index b3c5577..463b238 100644 --- a/src/declarative/graphicsitems/qdeclarativegridview.cpp +++ b/src/declarative/graphicsitems/qdeclarativegridview.cpp @@ -1340,6 +1340,18 @@ void QDeclarativeGridView::moveCurrentIndexRight() } } +/*! + \qmlmethod GridView::positionViewAtIndex(int index) + + Positions the view such that the \a index is at the top (or left for horizontal orientation) of the view. + If positioning the view at the index would cause empty space to be displayed at + the end of the view, the view will be positioned at the end. + + It is not recommended to use contentX or contentY to position the view + at a particular index. This is unreliable since removing items from the start + of the list does not cause all other items to be repositioned. + The correct way to bring an item into view is with positionViewAtIndex. +*/ void QDeclarativeGridView::positionViewAtIndex(int index) { Q_D(QDeclarativeGridView); diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp index a5da424..32627da 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview.cpp +++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp @@ -2286,6 +2286,12 @@ void QDeclarativeListView::decrementCurrentIndex() Positions the view such that the \a index is at the top (or left for horizontal orientation) of the view. If positioning the view at the index would cause empty space to be displayed at the end of the view, the view will be positioned at the end. + + It is not recommended to use contentX or contentY to position the view + at a particular index. This is unreliable since removing items from the start + of the list does not cause all other items to be repositioned, and because + the actual start of the view can vary based on the size of the delegates. + The correct way to bring an item into view is with positionViewAtIndex. */ void QDeclarativeListView::positionViewAtIndex(int index) { -- cgit v0.12 From eda079761194a96783cdb8d49c79eb2c9c0b7dac Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Thu, 4 Mar 2010 14:49:20 +1000 Subject: Compile without QVariant::EasingCurve in Qt 4.6.2. --- src/declarative/qml/qdeclarativecompiler.cpp | 2 +- src/declarative/qml/qdeclarativeenginedebug.cpp | 4 +-- .../qml/qdeclarativeobjectscriptclass.cpp | 2 +- src/declarative/qml/qdeclarativeproperty.cpp | 6 ++-- src/declarative/qml/qdeclarativevaluetype.cpp | 41 ++++++++++++++++++++++ src/declarative/qml/qdeclarativevaluetype_p.h | 9 ++++- src/declarative/util/qdeclarativeanimation.cpp | 8 +++-- 7 files changed, 61 insertions(+), 11 deletions(-) diff --git a/src/declarative/qml/qdeclarativecompiler.cpp b/src/declarative/qml/qdeclarativecompiler.cpp index 1eea012..b07a85a 100644 --- a/src/declarative/qml/qdeclarativecompiler.cpp +++ b/src/declarative/qml/qdeclarativecompiler.cpp @@ -1792,7 +1792,7 @@ bool QDeclarativeCompiler::buildGroupedProperty(QDeclarativeParser::Property *pr if (prop->values.count()) COMPILE_EXCEPTION(prop->values.first(), QCoreApplication::translate("QDeclarativeCompiler", "Invalid value in grouped property")); - if (prop->type < (int)QVariant::UserType) { + if (QDeclarativeValueTypeFactory::isValueType(prop->type)) { QDeclarativeEnginePrivate *ep = static_cast(QObjectPrivate::get(engine)); if (prop->type >= 0 /* QVariant == -1 */ && ep->valueTypes[prop->type]) { diff --git a/src/declarative/qml/qdeclarativeenginedebug.cpp b/src/declarative/qml/qdeclarativeenginedebug.cpp index 09882cb..3e4acbe 100644 --- a/src/declarative/qml/qdeclarativeenginedebug.cpp +++ b/src/declarative/qml/qdeclarativeenginedebug.cpp @@ -117,7 +117,7 @@ QDeclarativeEngineDebugServer::propertyData(QObject *obj, int propIdx) QVariant value = prop.read(obj); rv.value = valueContents(value); - if (QVariant::Type(prop.userType()) < QVariant::UserType) { + if (QDeclarativeValueTypeFactory::isValueType(prop.userType())) { rv.type = QDeclarativeObjectProperty::Basic; } else if (QDeclarativeMetaType::isQObject(prop.userType())) { rv.type = QDeclarativeObjectProperty::Object; @@ -131,7 +131,7 @@ QDeclarativeEngineDebugServer::propertyData(QObject *obj, int propIdx) QVariant QDeclarativeEngineDebugServer::valueContents(const QVariant &value) const { int userType = value.userType(); - if (QVariant::Type(userType) < QVariant::UserType) + if (QDeclarativeValueTypeFactory::isValueType(userType)) return value; /* diff --git a/src/declarative/qml/qdeclarativeobjectscriptclass.cpp b/src/declarative/qml/qdeclarativeobjectscriptclass.cpp index 542f417..2e4ffa7 100644 --- a/src/declarative/qml/qdeclarativeobjectscriptclass.cpp +++ b/src/declarative/qml/qdeclarativeobjectscriptclass.cpp @@ -232,7 +232,7 @@ QDeclarativeObjectScriptClass::property(QObject *obj, const Identifier &name) QDeclarativeEnginePrivate::CapturedProperty(obj, lastData->coreIndex, lastData->notifyIndex); } - if ((uint)lastData->propType < QVariant::UserType) { + if (QDeclarativeValueTypeFactory::isValueType((uint)lastData->propType)) { QDeclarativeValueType *valueType = enginePriv->valueTypes[lastData->propType]; if (valueType) return Value(scriptEngine, enginePriv->valueTypeClass->newObject(obj, lastData->coreIndex, valueType)); diff --git a/src/declarative/qml/qdeclarativeproperty.cpp b/src/declarative/qml/qdeclarativeproperty.cpp index 521c241..4f73b89 100644 --- a/src/declarative/qml/qdeclarativeproperty.cpp +++ b/src/declarative/qml/qdeclarativeproperty.cpp @@ -238,10 +238,10 @@ void QDeclarativePropertyPrivate::initProperty(QObject *obj, const QString &name if (property->flags & QDeclarativePropertyCache::Data::IsFunction) return; // Not an object property - if (ii == (path.count() - 2) && property->propType < (int)QVariant::UserType) { + if (ii == (path.count() - 2) && QDeclarativeValueTypeFactory::isValueType(property->propType)) { // We're now at a value type property. We can use a global valuetypes array as we // never actually use the objects, just look up their properties. - QObject *typeObject = qmlValueTypes()->valueTypes[property->propType]; + QObject *typeObject = (*qmlValueTypes())[property->propType]; if (!typeObject) return; // Not a value type int idx = typeObject->metaObject()->indexOfProperty(path.last().toUtf8().constData()); @@ -346,7 +346,7 @@ QDeclarativePropertyPrivate::propertyTypeCategory() const int type = propertyType(); if (type == QVariant::Invalid) return QDeclarativeProperty::InvalidCategory; - else if ((uint)type < QVariant::UserType) + else if (QDeclarativeValueTypeFactory::isValueType((uint)type)) return QDeclarativeProperty::Normal; else if (core.flags & QDeclarativePropertyCache::Data::IsQObjectDerived) return QDeclarativeProperty::Object; diff --git a/src/declarative/qml/qdeclarativevaluetype.cpp b/src/declarative/qml/qdeclarativevaluetype.cpp index 01fa214..34d3795 100644 --- a/src/declarative/qml/qdeclarativevaluetype.cpp +++ b/src/declarative/qml/qdeclarativevaluetype.cpp @@ -45,19 +45,50 @@ QT_BEGIN_NAMESPACE +#if (QT_VERSION < QT_VERSION_CHECK(4,7,0)) +Q_DECLARE_METATYPE(QEasingCurve); +#endif + QDeclarativeValueTypeFactory::QDeclarativeValueTypeFactory() { // ### Optimize for (unsigned int ii = 0; ii < (QVariant::UserType - 1); ++ii) valueTypes[ii] = valueType(ii); +#if (QT_VERSION < QT_VERSION_CHECK(4,7,0)) + easingType = qMetaTypeId(); + easingValueType = valueType(easingType); +#endif } QDeclarativeValueTypeFactory::~QDeclarativeValueTypeFactory() { for (unsigned int ii = 0; ii < (QVariant::UserType - 1); ++ii) delete valueTypes[ii]; +#if (QT_VERSION < QT_VERSION_CHECK(4,7,0)) + delete easingValueType; +#endif +} + +bool QDeclarativeValueTypeFactory::isValueType(int idx) +{ + if ((uint)idx < QVariant::UserType) + return true; +#if (QT_VERSION < QT_VERSION_CHECK(4,7,0)) + if (idx == qMetaTypeId()) + return true; +#endif + return false; } +QDeclarativeValueType *QDeclarativeValueTypeFactory::operator[](int idx) const +{ +#if (QT_VERSION < QT_VERSION_CHECK(4,7,0)) + if (idx == easingType) return easingValueType; +#endif + return valueTypes[idx]; +} + + QDeclarativeValueType *QDeclarativeValueTypeFactory::valueType(int t) { switch (t) { @@ -75,11 +106,17 @@ QDeclarativeValueType *QDeclarativeValueTypeFactory::valueType(int t) return new QDeclarativeRectFValueType; case QVariant::Vector3D: return new QDeclarativeVector3DValueType; +#if (QT_VERSION >= QT_VERSION_CHECK(4,7,0)) case QVariant::EasingCurve: return new QDeclarativeEasingValueType; +#endif case QVariant::Font: return new QDeclarativeFontValueType; default: +#if (QT_VERSION < QT_VERSION_CHECK(4,7,0)) + if (t == qMetaTypeId()) + return new QDeclarativeEasingValueType; +#endif return 0; } } @@ -495,7 +532,11 @@ void QDeclarativeEasingValueType::write(QObject *obj, int idx, QDeclarativePrope QVariant QDeclarativeEasingValueType::value() { +#if (QT_VERSION >= QT_VERSION_CHECK(4,7,0)) return QVariant(easing); +#else + return QVariant::fromValue(easing); +#endif } void QDeclarativeEasingValueType::setValue(QVariant value) diff --git a/src/declarative/qml/qdeclarativevaluetype_p.h b/src/declarative/qml/qdeclarativevaluetype_p.h index cb153be..e69f161 100644 --- a/src/declarative/qml/qdeclarativevaluetype_p.h +++ b/src/declarative/qml/qdeclarativevaluetype_p.h @@ -81,10 +81,17 @@ class Q_DECLARATIVE_EXPORT QDeclarativeValueTypeFactory public: QDeclarativeValueTypeFactory(); ~QDeclarativeValueTypeFactory(); + static bool isValueType(int); static QDeclarativeValueType *valueType(int); + QDeclarativeValueType *operator[](int idx) const; + +private: QDeclarativeValueType *valueTypes[QVariant::UserType - 1]; - QDeclarativeValueType *operator[](int idx) const { return valueTypes[idx]; } +#if (QT_VERSION < QT_VERSION_CHECK(4,7,0)) + int easingType; + QDeclarativeValueType *easingValueType; +#endif }; class Q_AUTOTEST_EXPORT QDeclarativePointFValueType : public QDeclarativeValueType diff --git a/src/declarative/util/qdeclarativeanimation.cpp b/src/declarative/util/qdeclarativeanimation.cpp index b14de19..f33d7c7 100644 --- a/src/declarative/util/qdeclarativeanimation.cpp +++ b/src/declarative/util/qdeclarativeanimation.cpp @@ -52,6 +52,7 @@ #include #include #include +#include #include #include @@ -1710,12 +1711,13 @@ void QDeclarativePropertyAnimationPrivate::convertVariant(QVariant &variant, int break; } default: - if ((uint)type >= QVariant::UserType) { + if (QDeclarativeValueTypeFactory::isValueType((uint)type)) { + variant.convert((QVariant::Type)type); + } else { QDeclarativeMetaType::StringConverter converter = QDeclarativeMetaType::customStringConverter(type); if (converter) variant = converter(variant.toString()); - } else - variant.convert((QVariant::Type)type); + } break; } } -- cgit v0.12 From e86dc3cbc40824353688db52d9933af26a30aaa0 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Thu, 4 Mar 2010 15:19:09 +1000 Subject: QDeclarativeContext::contextProperty() should also access ids QT-2800 --- src/declarative/qml/qdeclarativecontext.cpp | 5 ++++- .../qdeclarativecontext/tst_qdeclarativecontext.cpp | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/declarative/qml/qdeclarativecontext.cpp b/src/declarative/qml/qdeclarativecontext.cpp index 35e7a77..f70e143 100644 --- a/src/declarative/qml/qdeclarativecontext.cpp +++ b/src/declarative/qml/qdeclarativecontext.cpp @@ -484,7 +484,10 @@ QVariant QDeclarativeContext::contextProperty(const QString &name) const if (!value.isValid() && parentContext()) value = parentContext()->contextProperty(name); } else { - value = d->propertyValues[idx]; + if (idx >= d->propertyValues.count()) + value = QVariant::fromValue(d->idValues[idx - d->propertyValues.count()].data()); + else + value = d->propertyValues[idx]; } return value; diff --git a/tests/auto/declarative/qdeclarativecontext/tst_qdeclarativecontext.cpp b/tests/auto/declarative/qdeclarativecontext/tst_qdeclarativecontext.cpp index 5f03989..f0117f5 100644 --- a/tests/auto/declarative/qdeclarativecontext/tst_qdeclarativecontext.cpp +++ b/tests/auto/declarative/qdeclarativecontext/tst_qdeclarativecontext.cpp @@ -60,6 +60,7 @@ private slots: void setContextProperty(); void addDefaultObject(); void destruction(); + void idAsContextProperty(); private: QDeclarativeEngine engine; @@ -429,6 +430,25 @@ void tst_qdeclarativecontext::destruction() QCOMPARE(ctxt, expr.context()); } +void tst_qdeclarativecontext::idAsContextProperty() +{ + QDeclarativeComponent component(&engine); + component.setData("import Qt 4.6; QtObject { property var a; a: QtObject { id: myObject } }", QUrl()); + + QObject *obj = component.create(); + QVERIFY(obj); + + QVariant a = obj->property("a"); + QVERIFY(a.userType() == QMetaType::QObjectStar); + + QVariant ctxt = qmlContext(obj)->contextProperty("myObject"); + QVERIFY(ctxt.userType() == QMetaType::QObjectStar); + + QVERIFY(a == ctxt); + + delete obj; +} + QTEST_MAIN(tst_qdeclarativecontext) #include "tst_qdeclarativecontext.moc" -- cgit v0.12 From 0559b8d2af9f1f9277ff3bedd9a33cca7e255abb Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Thu, 4 Mar 2010 13:54:23 +1000 Subject: Signal handler requires exactly one value. Don't crash on invalid "PropertyAnimation on onClicked" --- src/declarative/qml/qdeclarativecompiler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/declarative/qml/qdeclarativecompiler.cpp b/src/declarative/qml/qdeclarativecompiler.cpp index b07a85a..7a3dde9 100644 --- a/src/declarative/qml/qdeclarativecompiler.cpp +++ b/src/declarative/qml/qdeclarativecompiler.cpp @@ -1342,7 +1342,7 @@ bool QDeclarativeCompiler::buildSignal(QDeclarativeParser::Property *prop, QDecl } else { - if (prop->value || prop->values.count() > 1) + if (prop->value || prop->values.count() != 1) COMPILE_EXCEPTION(prop, QCoreApplication::translate("QDeclarativeCompiler","Incorrectly specified signal")); prop->index = sigIdx; -- cgit v0.12 From 78254634c87f8e1b9c79841d87c530d3af8c9734 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Thu, 4 Mar 2010 14:57:40 +1000 Subject: Add formatting functions to QML's global Qt object. The plan is for these to replace DateTimeFormatter. --- doc/src/declarative/globalobject.qdoc | 76 ++++++++++++++++++++++ src/declarative/qml/qdeclarativeengine.cpp | 65 ++++++++++++++++++ src/declarative/qml/qdeclarativeengine_p.h | 4 ++ .../declarative/qdeclarativeqt/data/formatting.qml | 19 ++++++ .../qdeclarativeqt/tst_qdeclarativeqt.cpp | 29 +++++++++ 5 files changed, 193 insertions(+) create mode 100644 tests/auto/declarative/qdeclarativeqt/data/formatting.qml diff --git a/doc/src/declarative/globalobject.qdoc b/doc/src/declarative/globalobject.qdoc index c718a6d..a8a07d2 100644 --- a/doc/src/declarative/globalobject.qdoc +++ b/doc/src/declarative/globalobject.qdoc @@ -87,6 +87,82 @@ This function returns a Point with the specified \c x and \c y coordinates. This function returns as Size with the specified \c width and \c height. \section3 Qt.vector3d(real x, real y, real z) This function returns a Vector3D with the specified \c x, \c y and \c z. + +\section2 Formatters +The Qt object contains several functions for formatting dates and times. + +\section3 Qt.formatDate(datetime date, variant format) +This function returns the string representation of \c date, formatted according to \c format. +\section3 Qt.formatTime(datetime time, variant format) +This function returns the string representation of \c time, formatted according to \c format. +\section3 Qt.formatDateTime(datetime dateTime, variant format) +This function returns the string representation of \c dateTime, formatted according to \c format. + +\c format for the above formatting functions can be specified as follows. + + These expressions may be used for the date: + + \table + \header \i Expression \i Output + \row \i d \i the day as number without a leading zero (1 to 31) + \row \i dd \i the day as number with a leading zero (01 to 31) + \row \i ddd + \i the abbreviated localized day name (e.g. 'Mon' to 'Sun'). + Uses QDate::shortDayName(). + \row \i dddd + \i the long localized day name (e.g. 'Monday' to 'Qt::Sunday'). + Uses QDate::longDayName(). + \row \i M \i the month as number without a leading zero (1-12) + \row \i MM \i the month as number with a leading zero (01-12) + \row \i MMM + \i the abbreviated localized month name (e.g. 'Jan' to 'Dec'). + Uses QDate::shortMonthName(). + \row \i MMMM + \i the long localized month name (e.g. 'January' to 'December'). + Uses QDate::longMonthName(). + \row \i yy \i the year as two digit number (00-99) + \row \i yyyy \i the year as four digit number + \endtable + + These expressions may be used for the time: + + \table + \header \i Expression \i Output + \row \i h + \i the hour without a leading zero (0 to 23 or 1 to 12 if AM/PM display) + \row \i hh + \i the hour with a leading zero (00 to 23 or 01 to 12 if AM/PM display) + \row \i m \i the minute without a leading zero (0 to 59) + \row \i mm \i the minute with a leading zero (00 to 59) + \row \i s \i the second without a leading zero (0 to 59) + \row \i ss \i the second with a leading zero (00 to 59) + \row \i z \i the milliseconds without leading zeroes (0 to 999) + \row \i zzz \i the milliseconds with leading zeroes (000 to 999) + \row \i AP + \i use AM/PM display. \e AP will be replaced by either "AM" or "PM". + \row \i ap + \i use am/pm display. \e ap will be replaced by either "am" or "pm". + \endtable + + All other input characters will be ignored. Any sequence of characters that + are enclosed in singlequotes will be treated as text and not be used as an + expression. Two consecutive singlequotes ("''") are replaced by a singlequote + in the output. + + Example format strings (assumed that the date and time is 21 May 2001 + 14:13:09): + + \table + \header \i Format \i Result + \row \i dd.MM.yyyy \i 21.05.2001 + \row \i ddd MMMM d yy \i Tue May 21 01 + \row \i hh:mm:ss.zzz \i 14:13:09.042 + \row \i h:m:s ap \i 2:13:9 pm + \endtable + +If no format is specified the locale's short format is used. Alternatively, you can specify +\c Qt.DefaultLocaleLongDate to get the locale's long format. + \section2 Functions The Qt object also contains the following miscellaneous functions which expose Qt functionality for use in QML. diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index bd67b0b..20bbf86 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -236,6 +236,11 @@ QDeclarativeScriptEngine::QDeclarativeScriptEngine(QDeclarativeEnginePrivate *pr qtObject.setProperty(QLatin1String("tint"), newFunction(QDeclarativeEnginePrivate::tint, 2)); } + //date/time formatting + qtObject.setProperty(QLatin1String("formatDate"),newFunction(QDeclarativeEnginePrivate::formatDate, 2)); + qtObject.setProperty(QLatin1String("formatTime"),newFunction(QDeclarativeEnginePrivate::formatTime, 2)); + qtObject.setProperty(QLatin1String("formatDateTime"),newFunction(QDeclarativeEnginePrivate::formatDateTime, 2)); + //misc methods qtObject.setProperty(QLatin1String("closestAngle"), newFunction(QDeclarativeEnginePrivate::closestAngle, 2)); qtObject.setProperty(QLatin1String("playSound"), newFunction(QDeclarativeEnginePrivate::playSound, 1)); @@ -936,6 +941,66 @@ QScriptValue QDeclarativeEnginePrivate::vector(QScriptContext *ctxt, QScriptEngi return engine->newVariant(qVariantFromValue(QVector3D(x, y, z))); } +QScriptValue QDeclarativeEnginePrivate::formatDate(QScriptContext*ctxt, QScriptEngine*engine) +{ + int argCount = ctxt->argumentCount(); + if(argCount == 0 || argCount > 2) + return engine->nullValue(); + + QDate date = ctxt->argument(0).toDateTime().date(); + Qt::DateFormat enumFormat = Qt::DefaultLocaleShortDate; + if (argCount == 2) { + if (ctxt->argument(1).isString()) { + QString format = ctxt->argument(1).toString(); + return engine->newVariant(qVariantFromValue(date.toString(format))); + } else if (ctxt->argument(1).isNumber()) { + enumFormat = Qt::DateFormat(ctxt->argument(1).toInteger()); + } else + return engine->nullValue(); + } + return engine->newVariant(qVariantFromValue(date.toString(enumFormat))); +} + +QScriptValue QDeclarativeEnginePrivate::formatTime(QScriptContext*ctxt, QScriptEngine*engine) +{ + int argCount = ctxt->argumentCount(); + if(argCount == 0 || argCount > 2) + return engine->nullValue(); + + QTime date = ctxt->argument(0).toDateTime().time(); + Qt::DateFormat enumFormat = Qt::DefaultLocaleShortDate; + if (argCount == 2) { + if (ctxt->argument(1).isString()) { + QString format = ctxt->argument(1).toString(); + return engine->newVariant(qVariantFromValue(date.toString(format))); + } else if (ctxt->argument(1).isNumber()) { + enumFormat = Qt::DateFormat(ctxt->argument(1).toInteger()); + } else + return engine->nullValue(); + } + return engine->newVariant(qVariantFromValue(date.toString(enumFormat))); +} + +QScriptValue QDeclarativeEnginePrivate::formatDateTime(QScriptContext*ctxt, QScriptEngine*engine) +{ + int argCount = ctxt->argumentCount(); + if(argCount == 0 || argCount > 2) + return engine->nullValue(); + + QDateTime date = ctxt->argument(0).toDateTime(); + Qt::DateFormat enumFormat = Qt::DefaultLocaleShortDate; + if (argCount == 2) { + if (ctxt->argument(1).isString()) { + QString format = ctxt->argument(1).toString(); + return engine->newVariant(qVariantFromValue(date.toString(format))); + } else if (ctxt->argument(1).isNumber()) { + enumFormat = Qt::DateFormat(ctxt->argument(1).toInteger()); + } else + return engine->nullValue(); + } + return engine->newVariant(qVariantFromValue(date.toString(enumFormat))); +} + QScriptValue QDeclarativeEnginePrivate::rgba(QScriptContext *ctxt, QScriptEngine *engine) { int argCount = ctxt->argumentCount(); diff --git a/src/declarative/qml/qdeclarativeengine_p.h b/src/declarative/qml/qdeclarativeengine_p.h index d3eb583..a9ba73a 100644 --- a/src/declarative/qml/qdeclarativeengine_p.h +++ b/src/declarative/qml/qdeclarativeengine_p.h @@ -327,6 +327,10 @@ public: static QScriptValue consoleLog(QScriptContext*, QScriptEngine*); static QScriptValue quit(QScriptContext*, QScriptEngine*); + static QScriptValue formatDate(QScriptContext*, QScriptEngine*); + static QScriptValue formatTime(QScriptContext*, QScriptEngine*); + static QScriptValue formatDateTime(QScriptContext*, QScriptEngine*); + static QScriptEngine *getScriptEngine(QDeclarativeEngine *e) { return &e->d_func()->scriptEngine; } static QDeclarativeEngine *getEngine(QScriptEngine *e) { return static_cast(e)->p->q_func(); } static QDeclarativeEnginePrivate *get(QDeclarativeEngine *e) { return e->d_func(); } diff --git a/tests/auto/declarative/qdeclarativeqt/data/formatting.qml b/tests/auto/declarative/qdeclarativeqt/data/formatting.qml new file mode 100644 index 0000000..e62749a --- /dev/null +++ b/tests/auto/declarative/qdeclarativeqt/data/formatting.qml @@ -0,0 +1,19 @@ +import Qt 4.6 + +QtObject { + property date date1: "2008-12-24" + property string test1: Qt.formatDate(date1) + property string test2: Qt.formatDate(date1, Qt.DefaultLocaleLongDate) + property string test3: Qt.formatDate(date1, "ddd MMMM d yy") + + property var time1: new Date(0,0,0,14,15,38,200) + property string test4: Qt.formatTime(time1) + property string test5: Qt.formatTime(time1, Qt.DefaultLocaleLongDate) + property string test6: Qt.formatTime(time1, "H:m:s a") + property string test7: Qt.formatTime(time1, "hh:mm:ss.zzz") + + property var dateTime1: new Date(1978,2,4,9,13,54) + property string test8: Qt.formatDateTime(dateTime1) + property string test9: Qt.formatDateTime(dateTime1, Qt.DefaultLocaleLongDate) + property string test10: Qt.formatDateTime(dateTime1, "M/d/yy H:m:s a") +} diff --git a/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp b/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp index 9ec6872..484cbd4 100644 --- a/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp +++ b/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp @@ -73,6 +73,7 @@ private slots: void createComponent(); void createQmlObject(); void consoleLog(); + void formatting(); private: QDeclarativeEngine engine; @@ -364,6 +365,34 @@ void tst_qdeclarativeqt::consoleLog() delete object; } +void tst_qdeclarativeqt::formatting() +{ + QDeclarativeComponent component(&engine, TEST_FILE("formatting.qml")); + QObject *object = component.create(); + QVERIFY(object != 0); + + QDate date1(2008,12,24); + QCOMPARE(object->property("date1").toDate(), date1); + QCOMPARE(object->property("test1").toString(), date1.toString(Qt::DefaultLocaleShortDate)); + QCOMPARE(object->property("test2").toString(), date1.toString(Qt::DefaultLocaleLongDate)); + QCOMPARE(object->property("test3").toString(), date1.toString("ddd MMMM d yy")); + + QTime time1(14,15,38,200); + QCOMPARE(object->property("time1").toTime(), time1); + QCOMPARE(object->property("test4").toString(), time1.toString(Qt::DefaultLocaleShortDate)); + QCOMPARE(object->property("test5").toString(), time1.toString(Qt::DefaultLocaleLongDate)); + QCOMPARE(object->property("test6").toString(), time1.toString("H:m:s a")); + QCOMPARE(object->property("test7").toString(), time1.toString("hh:mm:ss.zzz")); + + QDateTime dateTime1(QDate(1978,03,04),QTime(9,13,54)); + QCOMPARE(object->property("dateTime1").toDateTime(),dateTime1); + QCOMPARE(object->property("test8").toString(), dateTime1.toString(Qt::DefaultLocaleShortDate)); + QCOMPARE(object->property("test9").toString(), dateTime1.toString(Qt::DefaultLocaleLongDate)); + QCOMPARE(object->property("test10").toString(), dateTime1.toString("M/d/yy H:m:s a")); + + delete object; +} + QTEST_MAIN(tst_qdeclarativeqt) #include "tst_qdeclarativeqt.moc" -- cgit v0.12 From ce5b682b481e2da6fe12e2c57c4780edbfb2fb54 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Thu, 4 Mar 2010 15:19:45 +1000 Subject: Remove Qt.playSound() Use SoundEffect instead. --- doc/src/declarative/globalobject.qdoc | 3 --- examples/declarative/tvtennis/tvtennis.qml | 12 +++++++---- src/declarative/QmlChanges.txt | 1 + src/declarative/qml/qdeclarativeengine.cpp | 25 ---------------------- src/declarative/qml/qdeclarativeengine_p.h | 1 - .../qdeclarativeqt/tst_qdeclarativeqt.cpp | 7 ------ 6 files changed, 9 insertions(+), 40 deletions(-) diff --git a/doc/src/declarative/globalobject.qdoc b/doc/src/declarative/globalobject.qdoc index a8a07d2..4b1c7d3 100644 --- a/doc/src/declarative/globalobject.qdoc +++ b/doc/src/declarative/globalobject.qdoc @@ -195,9 +195,6 @@ while the following would rotate myItem clockwise from 350 degrees to 370 degree NumberAnimation { target: myItem; property: "rotation"; from: 350; to: Qt.closetAngle(350, 10) } \endqml -\section3 Qt.playSound(url soundLocation) -This function plays the audio file located at \c soundLocation. Only .wav files are supported. - \section3 Qt.openUrlExternally(url target) This function attempts to open the specified \c target url in an external application, based on the user's desktop preferences. It will return true if it succeeds, and false otherwise. diff --git a/examples/declarative/tvtennis/tvtennis.qml b/examples/declarative/tvtennis/tvtennis.qml index 1585c7b..6022a15 100644 --- a/examples/declarative/tvtennis/tvtennis.qml +++ b/examples/declarative/tvtennis/tvtennis.qml @@ -1,4 +1,5 @@ import Qt 4.6 +import Qt.multimedia 4.7 Rectangle { id: page @@ -15,14 +16,17 @@ Rectangle { color: "Lime" x: 20; width: 20; height: 20; z: 1 + SoundEffect { id: paddle; source: "paddle.wav" } + SoundEffect { id: wall; source: "click.wav" } + // Move the ball to the right and back to the left repeatedly SequentialAnimation on x { repeat: true NumberAnimation { to: page.width - 40; duration: 2000 } - ScriptAction { script: Qt.playSound('paddle.wav') } + ScriptAction { script: paddle.play() } PropertyAction { target: ball; property: "direction"; value: "left" } NumberAnimation { to: 20; duration: 2000 } - ScriptAction { script: Qt.playSound('paddle.wav') } + ScriptAction { script: paddle.play() } PropertyAction { target: ball; property: "direction"; value: "right" } } @@ -32,10 +36,10 @@ Rectangle { // Detect the ball hitting the top or bottom of the view and bounce it onYChanged: { if (y <= 0) { - Qt.playSound('click.wav'); + wall.play(); targetY = page.height - 20; } else if (y >= page.height - 20) { - Qt.playSound('click.wav'); + wall.play(); targetY = 0; } } diff --git a/src/declarative/QmlChanges.txt b/src/declarative/QmlChanges.txt index 4951cb3..6e77abf 100644 --- a/src/declarative/QmlChanges.txt +++ b/src/declarative/QmlChanges.txt @@ -6,6 +6,7 @@ Flickable: renamed viewportHeight -> contentHeight Flickable: renamed viewportX -> contentX Flickable: renamed viewportY -> contentY Removed Flickable.reportedVelocitySmoothing +Removed Qt.playSound (replaced by SoundEffect element) Renamed MouseRegion -> MouseArea Connection: syntax and rename: Connection { sender: a; signal: foo(); script: xxx } diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index 20bbf86..1711cf1 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -243,7 +243,6 @@ QDeclarativeScriptEngine::QDeclarativeScriptEngine(QDeclarativeEnginePrivate *pr //misc methods qtObject.setProperty(QLatin1String("closestAngle"), newFunction(QDeclarativeEnginePrivate::closestAngle, 2)); - qtObject.setProperty(QLatin1String("playSound"), newFunction(QDeclarativeEnginePrivate::playSound, 1)); qtObject.setProperty(QLatin1String("openUrlExternally"),newFunction(QDeclarativeEnginePrivate::desktopOpenUrl, 1)); qtObject.setProperty(QLatin1String("md5"),newFunction(QDeclarativeEnginePrivate::md5, 1)); qtObject.setProperty(QLatin1String("btoa"),newFunction(QDeclarativeEnginePrivate::btoa, 1)); @@ -1105,30 +1104,6 @@ QScriptValue QDeclarativeEnginePrivate::darker(QScriptContext *ctxt, QScriptEngi return qScriptValueFromValue(engine, qVariantFromValue(color)); } -QScriptValue QDeclarativeEnginePrivate::playSound(QScriptContext *ctxt, QScriptEngine *engine) -{ - if (ctxt->argumentCount() != 1) - return engine->undefinedValue(); - - QUrl url(ctxt->argument(0).toString()); - - QDeclarativeEnginePrivate *enginePriv = QDeclarativeEnginePrivate::get(engine); - if (url.isRelative()) { - QDeclarativeContext *context = enginePriv->getContext(ctxt); - if (!context) - return engine->undefinedValue(); - - url = context->resolvedUrl(url); - } - - if (url.scheme() == QLatin1String("file")) { - - QSound::play(url.toLocalFile()); - - } - return engine->undefinedValue(); -} - QScriptValue QDeclarativeEnginePrivate::desktopOpenUrl(QScriptContext *ctxt, QScriptEngine *e) { if(ctxt->argumentCount() < 1) diff --git a/src/declarative/qml/qdeclarativeengine_p.h b/src/declarative/qml/qdeclarativeengine_p.h index a9ba73a..459a325 100644 --- a/src/declarative/qml/qdeclarativeengine_p.h +++ b/src/declarative/qml/qdeclarativeengine_p.h @@ -319,7 +319,6 @@ public: static QScriptValue tint(QScriptContext*, QScriptEngine*); static QScriptValue closestAngle(QScriptContext*, QScriptEngine*); - static QScriptValue playSound(QScriptContext*, QScriptEngine*); static QScriptValue desktopOpenUrl(QScriptContext*, QScriptEngine*); static QScriptValue md5(QScriptContext*, QScriptEngine*); static QScriptValue btoa(QScriptContext*, QScriptEngine*); diff --git a/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp b/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp index 484cbd4..90afd4e 100644 --- a/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp +++ b/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp @@ -67,7 +67,6 @@ private slots: void darker(); void tint(); void closestAngle(); - void playSound(); void openUrlExternally(); void md5(); void createComponent(); @@ -280,12 +279,6 @@ void tst_qdeclarativeqt::closestAngle() delete object; } -void tst_qdeclarativeqt::playSound() -{ - QEXPECT_FAIL("", "How do we test this?", Abort); - QVERIFY(false); -} - void tst_qdeclarativeqt::openUrlExternally() { QEXPECT_FAIL("", "How do we test this?", Abort); -- cgit v0.12 From 84709f178dde24d4926f0222b6ce0ab692eeba67 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 4 Mar 2010 15:29:43 +1000 Subject: Fix ListView contentHeight calculation. Task-number: QT-2630 --- src/declarative/graphicsitems/qdeclarativelistview.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp index 32627da..18d3661 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview.cpp +++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp @@ -223,7 +223,7 @@ public: if (!visibleItems.isEmpty()) { pos = (*visibleItems.constBegin())->position(); if (visibleIndex > 0) - pos -= visibleIndex * (averageSize + spacing) - spacing; + pos -= visibleIndex * (averageSize + spacing); } return pos; } @@ -2414,7 +2414,8 @@ void QDeclarativeListView::itemsInserted(int modelIndex, int count) int i = d->visibleItems.count() - 1; while (i > 0 && d->visibleItems.at(i)->index == -1) --i; - if (d->visibleItems.at(i)->index + 1 == modelIndex) { + if (d->visibleItems.at(i)->index + 1 == modelIndex + && d->visibleItems.at(i)->endPosition() < d->buffer+d->position()+d->size()-1) { // Special case of appending an item to the model. modelIndex = d->visibleIndex + d->visibleItems.count(); } else { -- cgit v0.12 From 5599ddd113fe1385e7a6aff708e12af419b8de87 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 4 Mar 2010 15:41:00 +1000 Subject: Don't mess with highlight size if highlightFollowsCurrentItem is false. Task-number: QT-2630 --- src/declarative/graphicsitems/qdeclarativelistview.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp index 18d3661..cd8d143 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview.cpp +++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp @@ -799,10 +799,13 @@ void QDeclarativeListViewPrivate::createHighlight() if (item) { item->setParent(q->viewport()); highlight = new FxListItem(item, q); - if (orient == QDeclarativeListView::Vertical) - highlight->item->setHeight(currentItem->item->height()); - else - highlight->item->setWidth(currentItem->item->width()); + if (currentItem && autoHighlight) { + if (orient == QDeclarativeListView::Vertical) { + highlight->item->setHeight(currentItem->item->height()); + } else { + highlight->item->setWidth(currentItem->item->width()); + } + } const QLatin1String posProp(orient == QDeclarativeListView::Vertical ? "y" : "x"); highlightPosAnimator = new QDeclarativeEaseFollow(q); highlightPosAnimator->setTarget(QDeclarativeProperty(highlight->item, posProp)); -- cgit v0.12 From 57d68b06c15f8426c25e357f97b9154056969e0f Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Thu, 4 Mar 2010 16:04:15 +1000 Subject: Improve grouped property error messages QT-2579 --- src/declarative/qml/qdeclarativecompiler.cpp | 15 ++++++++++++--- src/declarative/qml/qdeclarativeparser.cpp | 4 ++-- src/declarative/qml/qdeclarativeparser_p.h | 7 ++++++- src/declarative/qml/qdeclarativescriptparser.cpp | 4 ++-- .../qdeclarativelanguage/data/defaultGrouped.errors.txt | 2 +- .../data/invalidGroupedProperty.10.errors.txt | 1 + .../data/invalidGroupedProperty.10.qml | 7 +++++++ .../data/invalidGroupedProperty.8.errors.txt | 1 + .../data/invalidGroupedProperty.8.qml | 6 ++++++ .../data/invalidGroupedProperty.9.errors.txt | 1 + .../data/invalidGroupedProperty.9.qml | 6 ++++++ .../qdeclarativelanguage/tst_qdeclarativelanguage.cpp | 3 +++ 12 files changed, 48 insertions(+), 9 deletions(-) create mode 100644 tests/auto/declarative/qdeclarativelanguage/data/invalidGroupedProperty.10.errors.txt create mode 100644 tests/auto/declarative/qdeclarativelanguage/data/invalidGroupedProperty.10.qml create mode 100644 tests/auto/declarative/qdeclarativelanguage/data/invalidGroupedProperty.8.errors.txt create mode 100644 tests/auto/declarative/qdeclarativelanguage/data/invalidGroupedProperty.8.qml create mode 100644 tests/auto/declarative/qdeclarativelanguage/data/invalidGroupedProperty.9.errors.txt create mode 100644 tests/auto/declarative/qdeclarativelanguage/data/invalidGroupedProperty.9.qml diff --git a/src/declarative/qml/qdeclarativecompiler.cpp b/src/declarative/qml/qdeclarativecompiler.cpp index 7a3dde9..32c746f 100644 --- a/src/declarative/qml/qdeclarativecompiler.cpp +++ b/src/declarative/qml/qdeclarativecompiler.cpp @@ -1789,13 +1789,19 @@ bool QDeclarativeCompiler::buildGroupedProperty(QDeclarativeParser::Property *pr Q_ASSERT(prop->type != 0); Q_ASSERT(prop->index != -1); - if (prop->values.count()) - COMPILE_EXCEPTION(prop->values.first(), QCoreApplication::translate("QDeclarativeCompiler", "Invalid value in grouped property")); - if (QDeclarativeValueTypeFactory::isValueType(prop->type)) { QDeclarativeEnginePrivate *ep = static_cast(QObjectPrivate::get(engine)); if (prop->type >= 0 /* QVariant == -1 */ && ep->valueTypes[prop->type]) { + + if (prop->values.count()) { + if (prop->values.at(0)->location < prop->value->location) { + COMPILE_EXCEPTION(prop->value, QCoreApplication::translate("QDeclarativeCompiler", "Property has already been assigned a value")); + } else { + COMPILE_EXCEPTION(prop->values.at(0), QCoreApplication::translate("QDeclarativeCompiler", "Property has already been assigned a value")); + } + } + COMPILE_CHECK(buildValueTypeProperty(ep->valueTypes[prop->type], prop->value, obj, ctxt.incr())); obj->addValueTypeProperty(prop); @@ -1810,6 +1816,9 @@ bool QDeclarativeCompiler::buildGroupedProperty(QDeclarativeParser::Property *pr if (!prop->value->metatype) COMPILE_EXCEPTION(prop, QCoreApplication::translate("QDeclarativeCompiler","Invalid grouped property access")); + if (prop->values.count()) + COMPILE_EXCEPTION(prop->values.at(0), QCoreApplication::translate("QDeclarativeCompiler", "Cannot assign a value directly to a grouped property")); + obj->addGroupedProperty(prop); COMPILE_CHECK(buildSubObject(prop->value, ctxt.incr())); diff --git a/src/declarative/qml/qdeclarativeparser.cpp b/src/declarative/qml/qdeclarativeparser.cpp index 0e3d856..b0599ad 100644 --- a/src/declarative/qml/qdeclarativeparser.cpp +++ b/src/declarative/qml/qdeclarativeparser.cpp @@ -226,9 +226,9 @@ QDeclarativeParser::Property::~Property() if (value) value->release(); } -Object *QDeclarativeParser::Property::getValue() +Object *QDeclarativeParser::Property::getValue(const LocationSpan &l) { - if (!value) value = new Object; + if (!value) { value = new Object; value->location = l; } return value; } diff --git a/src/declarative/qml/qdeclarativeparser_p.h b/src/declarative/qml/qdeclarativeparser_p.h index d0d7de1..5bf4b68 100644 --- a/src/declarative/qml/qdeclarativeparser_p.h +++ b/src/declarative/qml/qdeclarativeparser_p.h @@ -104,6 +104,11 @@ namespace QDeclarativeParser Location start; Location end; LocationRange range; + + bool operator<(LocationSpan &o) const { + return (start.line < o.start.line) || + (start.line == o.start.line && start.column < o.start.column); + } }; class Property; @@ -318,7 +323,7 @@ namespace QDeclarativeParser // The Object to which this property is attached Object *parent; - Object *getValue(); + Object *getValue(const LocationSpan &); void addValue(Value *v); void addOnValue(Value *v); diff --git a/src/declarative/qml/qdeclarativescriptparser.cpp b/src/declarative/qml/qdeclarativescriptparser.cpp index a4b3668..fe516c5 100644 --- a/src/declarative/qml/qdeclarativescriptparser.cpp +++ b/src/declarative/qml/qdeclarativescriptparser.cpp @@ -85,8 +85,8 @@ class ProcessAST: protected AST::Visitor { const State &state = top(); if (state.property) { - State s(state.property->getValue(), - state.property->getValue()->getProperty(name.toUtf8())); + State s(state.property->getValue(location), + state.property->getValue(location)->getProperty(name.toUtf8())); s.property->location = location; push(s); } else { diff --git a/tests/auto/declarative/qdeclarativelanguage/data/defaultGrouped.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/defaultGrouped.errors.txt index 945d51b..32055f6 100644 --- a/tests/auto/declarative/qdeclarativelanguage/data/defaultGrouped.errors.txt +++ b/tests/auto/declarative/qdeclarativelanguage/data/defaultGrouped.errors.txt @@ -1 +1 @@ -7:9:Invalid value in grouped property +7:9:Cannot assign a value directly to a grouped property diff --git a/tests/auto/declarative/qdeclarativelanguage/data/invalidGroupedProperty.10.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/invalidGroupedProperty.10.errors.txt new file mode 100644 index 0000000..1fcb1b6 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/invalidGroupedProperty.10.errors.txt @@ -0,0 +1 @@ +4:14:Cannot assign a value directly to a grouped property diff --git a/tests/auto/declarative/qdeclarativelanguage/data/invalidGroupedProperty.10.qml b/tests/auto/declarative/qdeclarativelanguage/data/invalidGroupedProperty.10.qml new file mode 100644 index 0000000..41aa3e2 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/invalidGroupedProperty.10.qml @@ -0,0 +1,7 @@ +import Test 1.0 + +MyTypeObject { + grouped: "10x10" + grouped.value: 10 +} + diff --git a/tests/auto/declarative/qdeclarativelanguage/data/invalidGroupedProperty.8.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/invalidGroupedProperty.8.errors.txt new file mode 100644 index 0000000..fa0da21 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/invalidGroupedProperty.8.errors.txt @@ -0,0 +1 @@ +5:19:Property has already been assigned a value diff --git a/tests/auto/declarative/qdeclarativelanguage/data/invalidGroupedProperty.8.qml b/tests/auto/declarative/qdeclarativelanguage/data/invalidGroupedProperty.8.qml new file mode 100644 index 0000000..56fca9b --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/invalidGroupedProperty.8.qml @@ -0,0 +1,6 @@ +import Test 1.0 + +MyTypeObject { + pointProperty: "10x10" + pointProperty.x: 10 +} diff --git a/tests/auto/declarative/qdeclarativelanguage/data/invalidGroupedProperty.9.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/invalidGroupedProperty.9.errors.txt new file mode 100644 index 0000000..6d837a7 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/invalidGroupedProperty.9.errors.txt @@ -0,0 +1 @@ +5:20:Property has already been assigned a value diff --git a/tests/auto/declarative/qdeclarativelanguage/data/invalidGroupedProperty.9.qml b/tests/auto/declarative/qdeclarativelanguage/data/invalidGroupedProperty.9.qml new file mode 100644 index 0000000..982ab26 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/invalidGroupedProperty.9.qml @@ -0,0 +1,6 @@ +import Test 1.0 + +MyTypeObject { + pointProperty.x: 10 + pointProperty: "10x10" +} diff --git a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp index 5d480fa..28daf29 100644 --- a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp +++ b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp @@ -255,6 +255,9 @@ void tst_qdeclarativelanguage::errors_data() QTest::newRow("invalidGroupedProperty.5") << "invalidGroupedProperty.5.qml" << "invalidGroupedProperty.5.errors.txt" << false; QTest::newRow("invalidGroupedProperty.6") << "invalidGroupedProperty.6.qml" << "invalidGroupedProperty.6.errors.txt" << false; QTest::newRow("invalidGroupedProperty.7") << "invalidGroupedProperty.7.qml" << "invalidGroupedProperty.7.errors.txt" << true; + QTest::newRow("invalidGroupedProperty.8") << "invalidGroupedProperty.8.qml" << "invalidGroupedProperty.8.errors.txt" << false; + QTest::newRow("invalidGroupedProperty.9") << "invalidGroupedProperty.9.qml" << "invalidGroupedProperty.9.errors.txt" << false; + QTest::newRow("invalidGroupedProperty.10") << "invalidGroupedProperty.10.qml" << "invalidGroupedProperty.10.errors.txt" << false; QTest::newRow("importNamespaceConflict") << "importNamespaceConflict.qml" << "importNamespaceConflict.errors.txt" << false; QTest::newRow("importVersionMissing (builtin)") << "importVersionMissingBuiltIn.qml" << "importVersionMissingBuiltIn.errors.txt" << false; -- cgit v0.12 From c329db551237906cc659f3276c679d0e573edff2 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Thu, 4 Mar 2010 16:31:06 +1000 Subject: Fix grammar stringifying "on" as "readonly" QTBUG-8676 --- src/declarative/qml/parser/qdeclarativejs.g | 2 +- src/declarative/qml/parser/qdeclarativejsgrammar.cpp | 2 +- src/declarative/qml/parser/qdeclarativejsgrammar_p.h | 4 ++-- src/declarative/qml/parser/qdeclarativejsparser.cpp | 2 +- .../qdeclarativelanguage/data/customOnProperty.qml | 7 +++++++ .../qdeclarativelanguage/tst_qdeclarativelanguage.cpp | 15 +++++++++++++++ 6 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 tests/auto/declarative/qdeclarativelanguage/data/customOnProperty.qml diff --git a/src/declarative/qml/parser/qdeclarativejs.g b/src/declarative/qml/parser/qdeclarativejs.g index 7cf81b2..493ad25 100644 --- a/src/declarative/qml/parser/qdeclarativejs.g +++ b/src/declarative/qml/parser/qdeclarativejs.g @@ -1020,7 +1020,7 @@ case $rule_number: { JsIdentifier: T_ON ; /. case $rule_number: { - QString s = QLatin1String(QDeclarativeJSGrammar::spell[T_READONLY]); + QString s = QLatin1String(QDeclarativeJSGrammar::spell[T_ON]); sym(1).sval = driver->intern(s.constData(), s.length()); break; } diff --git a/src/declarative/qml/parser/qdeclarativejsgrammar.cpp b/src/declarative/qml/parser/qdeclarativejsgrammar.cpp index 0677bc5..89493ff 100644 --- a/src/declarative/qml/parser/qdeclarativejsgrammar.cpp +++ b/src/declarative/qml/parser/qdeclarativejsgrammar.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the QtDeclarative module of the Qt Toolkit. +** This file is part of the QtCore module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/declarative/qml/parser/qdeclarativejsgrammar_p.h b/src/declarative/qml/parser/qdeclarativejsgrammar_p.h index 2b2e3d1..32bb12b 100644 --- a/src/declarative/qml/parser/qdeclarativejsgrammar_p.h +++ b/src/declarative/qml/parser/qdeclarativejsgrammar_p.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the QtDeclarative module of the Qt Toolkit. +** This file is part of the QtCore module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage @@ -61,7 +61,7 @@ QT_BEGIN_NAMESPACE class QDeclarativeJSGrammar { public: - enum { + enum VariousConstants { EOF_SYMBOL = 0, REDUCE_HERE = 100, SHIFT_THERE = 99, diff --git a/src/declarative/qml/parser/qdeclarativejsparser.cpp b/src/declarative/qml/parser/qdeclarativejsparser.cpp index fd9e690..c86e047 100644 --- a/src/declarative/qml/parser/qdeclarativejsparser.cpp +++ b/src/declarative/qml/parser/qdeclarativejsparser.cpp @@ -516,7 +516,7 @@ case 66: { } case 67: { - QString s = QLatin1String(QDeclarativeJSGrammar::spell[T_READONLY]); + QString s = QLatin1String(QDeclarativeJSGrammar::spell[T_ON]); sym(1).sval = driver->intern(s.constData(), s.length()); break; } diff --git a/tests/auto/declarative/qdeclarativelanguage/data/customOnProperty.qml b/tests/auto/declarative/qdeclarativelanguage/data/customOnProperty.qml new file mode 100644 index 0000000..7cd6a83 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/customOnProperty.qml @@ -0,0 +1,7 @@ +import Qt 4.6 + +QtObject { + property int on + + Component.onCompleted: on = 10 +} diff --git a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp index 28daf29..a339a6d 100644 --- a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp +++ b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp @@ -128,6 +128,8 @@ private slots: void qmlAttachedPropertiesObjectMethod(); + void customOnProperty(); + // regression tests for crashes void crash1(); void crash2(); @@ -1397,6 +1399,19 @@ void tst_qdeclarativelanguage::crash2() QDeclarativeComponent component(&engine, TEST_FILE("crash2.qml")); } +// QTBUG-8676 +void tst_qdeclarativelanguage::customOnProperty() +{ + QDeclarativeComponent component(&engine, TEST_FILE("customOnProperty.qml")); + + VERIFY_ERRORS(0); + QObject *object = component.create(); + QVERIFY(object != 0); + + QCOMPARE(object->property("on").toInt(), 10); + + delete object; +} void tst_qdeclarativelanguage::initTestCase() { -- cgit v0.12 From ff40702d547088266a09adb2d1b5d9a270334d21 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 4 Mar 2010 16:54:38 +1000 Subject: Move the multimedia files to the correct place. --- src/imports/multimedia/qdeclarativeaudio.cpp | 327 +++++++ src/imports/multimedia/qdeclarativeaudio_p.h | 173 ++++ src/imports/multimedia/qdeclarativemediabase.cpp | 413 +++++++++ src/imports/multimedia/qdeclarativemediabase_p.h | 168 ++++ src/imports/multimedia/qdeclarativevideo.cpp | 945 +++++++++++++++++++++ src/imports/multimedia/qdeclarativevideo_p.h | 204 +++++ .../multimedia/qmetadatacontrolmetaobject.cpp | 362 ++++++++ .../multimedia/qmetadatacontrolmetaobject_p.h | 92 ++ .../multimedia/qdeclarativeaudio.cpp | 327 ------- .../multimedia/qdeclarativeaudio_p.h | 173 ---- .../multimedia/qdeclarativemediabase.cpp | 413 --------- .../multimedia/qdeclarativemediabase_p.h | 168 ---- .../multimedia/qdeclarativevideo.cpp | 945 --------------------- .../multimedia/qdeclarativevideo_p.h | 204 ----- .../multimedia/qmetadatacontrolmetaobject.cpp | 362 -------- .../multimedia/qmetadatacontrolmetaobject_p.h | 92 -- 16 files changed, 2684 insertions(+), 2684 deletions(-) create mode 100644 src/imports/multimedia/qdeclarativeaudio.cpp create mode 100644 src/imports/multimedia/qdeclarativeaudio_p.h create mode 100644 src/imports/multimedia/qdeclarativemediabase.cpp create mode 100644 src/imports/multimedia/qdeclarativemediabase_p.h create mode 100644 src/imports/multimedia/qdeclarativevideo.cpp create mode 100644 src/imports/multimedia/qdeclarativevideo_p.h create mode 100644 src/imports/multimedia/qmetadatacontrolmetaobject.cpp create mode 100644 src/imports/multimedia/qmetadatacontrolmetaobject_p.h delete mode 100644 src/plugins/qdeclarativemodules/multimedia/qdeclarativeaudio.cpp delete mode 100644 src/plugins/qdeclarativemodules/multimedia/qdeclarativeaudio_p.h delete mode 100644 src/plugins/qdeclarativemodules/multimedia/qdeclarativemediabase.cpp delete mode 100644 src/plugins/qdeclarativemodules/multimedia/qdeclarativemediabase_p.h delete mode 100644 src/plugins/qdeclarativemodules/multimedia/qdeclarativevideo.cpp delete mode 100644 src/plugins/qdeclarativemodules/multimedia/qdeclarativevideo_p.h delete mode 100644 src/plugins/qdeclarativemodules/multimedia/qmetadatacontrolmetaobject.cpp delete mode 100644 src/plugins/qdeclarativemodules/multimedia/qmetadatacontrolmetaobject_p.h diff --git a/src/imports/multimedia/qdeclarativeaudio.cpp b/src/imports/multimedia/qdeclarativeaudio.cpp new file mode 100644 index 0000000..df2888c --- /dev/null +++ b/src/imports/multimedia/qdeclarativeaudio.cpp @@ -0,0 +1,327 @@ +/**************************************************************************** +** +** 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 "qdeclarativeaudio_p.h" + +#include + +QT_BEGIN_NAMESPACE + + +/*! + \qmlclass Audio QDeclarativeAudio + \since 4.7 + \brief The Audio element allows you to add audio playback to a scene. + + \qml + Audio { source: "audio/song.mp3" } + \endqml + + \sa Video +*/ + +/*! + \internal + \class QDeclarativeAudio + \brief The QDeclarativeAudio class provides an audio item that you can add to a QDeclarativeView. +*/ + +void QDeclarativeAudio::_q_error(int errorCode, const QString &errorString) +{ + m_error = QMediaPlayer::Error(errorCode); + m_errorString = errorString; + + emit error(Error(errorCode), errorString); + emit errorChanged(); +} + + +QDeclarativeAudio::QDeclarativeAudio(QObject *parent) + : QObject(parent) +{ + setObject(this); +} + +QDeclarativeAudio::~QDeclarativeAudio() +{ + shutdown(); +} + +/*! + \qmlmethod Audio::play() + + Starts playback of the media. + + Sets the \l playing property to true, and the \l paused property to false. +*/ + +void QDeclarativeAudio::play() +{ + m_playerControl->play(); + + if (m_paused) { + m_paused = false; + emit pausedChanged(); + } +} + +/*! + \qmlmethod Audio::pause() + + Pauses playback of the media. + + Sets the \l playing and \l paused properties to true. +*/ + +void QDeclarativeAudio::pause() +{ + m_playerControl->pause(); + + if (!m_paused && m_state == QMediaPlayer::PausedState) { + m_paused = true; + emit pausedChanged(); + } +} + +/*! + \qmlmethod Audio::stop() + + Stops playback of the media. + + Sets the \l playing and \l paused properties to false. +*/ + +void QDeclarativeAudio::stop() +{ + m_playerControl->stop(); + + if (m_paused) { + m_paused = false; + emit pausedChanged(); + } +} + +/*! + \qmlproperty url Audio::source + + This property holds the source URL of the media. +*/ + +/*! + \qmlproperty bool Audio::playing + + This property holds whether the media is playing. + + Defaults to false, and can be set to true to start playback. +*/ + +/*! + \qmlproperty bool Audio::paused + + This property holds whether the media is paused. + + Defaults to false, and can be set to true to pause playback. +*/ + +/*! + \qmlsignal Audio::onStarted() + + This handler is called when playback is started. +*/ + +/*! + \qmlsignal Audio::onResumed() + + This handler is called when playback is resumed from the paused state. +*/ + +/*! + \qmlsignal Audio::onPaused() + + This handler is called when playback is paused. +*/ + +/*! + \qmlsignal Audio::onStopped() + + This handler is called when playback is stopped. +*/ + +/*! + \qmlproperty enum Audio::status + + This property holds the status of media loading. It can be one of: + + \list + \o NoMedia - no media has been set. + \o Loading - the media is currently being loaded. + \o Loaded - the media has been loaded. + \o Buffering - the media is buffering data. + \o Stalled - playback has been interrupted while the media is buffering data. + \o Buffered - the media has buffered data. + \o EndOfMedia - the media has played to the end. + \o InvalidMedia - the media cannot be played. + \o UnknownStatus - the status of the media is unknown. + \endlist +*/ + +QDeclarativeAudio::Status QDeclarativeAudio::status() const +{ + return Status(m_status); +} + +/*! + \qmlsignal Audio::onLoaded() + + This handler is called when the media source has been loaded. +*/ + +/*! + \qmlsignal Audio::onBuffering() + + This handler is called when the media starts buffering. +*/ + +/*! + \qmlsignal Audio::onStalled() + + This handler is called when playback has stalled while the media buffers. +*/ + +/*! + \qmlsignal Audio::onBuffered() + + This handler is called when the media has finished buffering. +*/ + +/*! + \qmlsignal Audio::onEndOfMedia() + + This handler is called when playback stops because end of the media has been reached. +*/ +/*! + \qmlproperty int Audio::duration + + This property holds the duration of the media in milliseconds. + + If the media doesn't have a fixed duration (a live stream for example) this will be 0. +*/ + +/*! + \qmlproperty int Audio::position + + This property holds the current playback position in milliseconds. + + If the \l seekable property is true, this property can be set to seek to a new position. +*/ + +/*! + \qmlproperty qreal Audio::volume + + This property holds the volume of the audio output, from 0.0 (silent) to 1.0 (maximum volume). +*/ + +/*! + \qmlproperty bool Audio::muted + + This property holds whether the audio output is muted. +*/ + +/*! + \qmlproperty qreal Audio::bufferProgress + + This property holds how much of the data buffer is currently filled, from 0.0 (empty) to 1.0 + (full). +*/ + +/*! + \qmlproperty bool Audio::seekable + + This property holds whether position of the audio can be changed. + + If true; setting a \l position value will cause playback to seek to the new position. +*/ + +/*! + \qmlproperty qreal Audio::playbackRate + + This property holds the rate at which audio is played at as a multiple of the normal rate. +*/ + +/*! + \qmlproperty enum Audio::error + + This property holds the error state of the audio. It can be one of: + + \list + \o NoError - there is no current error. + \o ResourceError - the audio cannot be played due to a problem allocating resources. + \o FormatError - the audio format is not supported. + \o NetworkError - the audio cannot be played due to network issues. + \o AccessDenied - the audio cannot be played due to insufficient permissions. + \o ServiceMissing - the audio cannot be played because the media service could not be + instantiated. + \endlist +*/ + +QDeclarativeAudio::Error QDeclarativeAudio::error() const +{ + return Error(m_error); +} + +/*! + \qmlproperty string Audio::errorString + + This property holds a string describing the current error condition in more detail. +*/ + +/*! + \qmlsignal Audio::onError(error, errorString) + + This handler is called when an \l {Error}{error} has occurred. The errorString parameter + may contain more detailed information about the error. +*/ + +QT_END_NAMESPACE + +#include "moc_qdeclarativeaudio_p.cpp" + + diff --git a/src/imports/multimedia/qdeclarativeaudio_p.h b/src/imports/multimedia/qdeclarativeaudio_p.h new file mode 100644 index 0000000..9881dbc --- /dev/null +++ b/src/imports/multimedia/qdeclarativeaudio_p.h @@ -0,0 +1,173 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#ifndef QDECLARATIVEAUDIO_P_H +#define QDECLARATIVEAUDIO_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of other Qt classes. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qdeclarativemediabase_p.h" + +#include +#include + + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +class QTimerEvent; + +class QDeclarativeAudio : public QObject, public QDeclarativeMediaBase, public QDeclarativeParserStatus +{ + Q_OBJECT + Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) + Q_PROPERTY(bool playing READ isPlaying WRITE setPlaying NOTIFY playingChanged) + Q_PROPERTY(bool paused READ isPaused WRITE setPaused NOTIFY pausedChanged) + Q_PROPERTY(Status status READ status NOTIFY statusChanged) + Q_PROPERTY(int duration READ duration NOTIFY durationChanged) + Q_PROPERTY(int position READ position WRITE setPosition NOTIFY positionChanged) + Q_PROPERTY(qreal volume READ volume WRITE setVolume NOTIFY volumeChanged) + Q_PROPERTY(bool muted READ isMuted WRITE setMuted NOTIFY mutedChanged) + Q_PROPERTY(int bufferProgress READ bufferProgress NOTIFY bufferProgressChanged) + Q_PROPERTY(bool seekable READ isSeekable NOTIFY seekableChanged) + Q_PROPERTY(qreal playbackRate READ playbackRate WRITE setPlaybackRate NOTIFY playbackRateChanged) + Q_PROPERTY(Error error READ error NOTIFY errorChanged) + Q_PROPERTY(QString errorString READ errorString NOTIFY errorChanged) + Q_ENUMS(Status) + Q_ENUMS(Error) + Q_INTERFACES(QDeclarativeParserStatus) +public: + enum Status + { + UnknownStatus = QMediaPlayer::UnknownMediaStatus, + NoMedia = QMediaPlayer::NoMedia, + Loading = QMediaPlayer::LoadingMedia, + Loaded = QMediaPlayer::LoadedMedia, + Stalled = QMediaPlayer::StalledMedia, + Buffering = QMediaPlayer::BufferingMedia, + Buffered = QMediaPlayer::BufferedMedia, + EndOfMedia = QMediaPlayer::EndOfMedia, + InvalidMedia = QMediaPlayer::InvalidMedia + }; + + enum Error + { + NoError = QMediaPlayer::NoError, + ResourceError = QMediaPlayer::ResourceError, + FormatError = QMediaPlayer::FormatError, + NetworkError = QMediaPlayer::NetworkError, + AccessDenied = QMediaPlayer::AccessDeniedError, + ServiceMissing = QMediaPlayer::ServiceMissingError + }; + + QDeclarativeAudio(QObject *parent = 0); + ~QDeclarativeAudio(); + + Status status() const; + Error error() const; + +public Q_SLOTS: + void play(); + void pause(); + void stop(); + +Q_SIGNALS: + void sourceChanged(); + + void playingChanged(); + void pausedChanged(); + + void started(); + void resumed(); + void paused(); + void stopped(); + + void statusChanged(); + + void loaded(); + void buffering(); + void stalled(); + void buffered(); + void endOfMedia(); + + void durationChanged(); + void positionChanged(); + + void volumeChanged(); + void mutedChanged(); + + void bufferProgressChanged(); + + void seekableChanged(); + void playbackRateChanged(); + + void errorChanged(); + void error(QDeclarativeAudio::Error error, const QString &errorString); + +private Q_SLOTS: + void _q_error(int, const QString &); + +private: + Q_DISABLE_COPY(QDeclarativeAudio) + Q_PRIVATE_SLOT(mediaBase(), void _q_stateChanged(QMediaPlayer::State)) + Q_PRIVATE_SLOT(mediaBase(), void _q_mediaStatusChanged(QMediaPlayer::MediaStatus)) + Q_PRIVATE_SLOT(mediaBase(), void _q_metaDataChanged()) + + inline QDeclarativeMediaBase *mediaBase() { return this; } +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QT_PREPEND_NAMESPACE(QDeclarativeAudio)) + +QT_END_HEADER + +#endif diff --git a/src/imports/multimedia/qdeclarativemediabase.cpp b/src/imports/multimedia/qdeclarativemediabase.cpp new file mode 100644 index 0000000..8e87e44 --- /dev/null +++ b/src/imports/multimedia/qdeclarativemediabase.cpp @@ -0,0 +1,413 @@ +/**************************************************************************** +** +** 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 "qdeclarativemediabase_p.h" + +#include +#include + +#include +#include +#include +#include +#include "qmetadatacontrolmetaobject_p.h" + + + +QT_BEGIN_NAMESPACE + + +class QDeclarativeMediaBaseObject : public QMediaObject +{ +public: + QDeclarativeMediaBaseObject(QMediaService *service) + : QMediaObject(0, service) + { + } +}; + +class QDeclarativeMediaBasePlayerControl : public QMediaPlayerControl +{ +public: + QDeclarativeMediaBasePlayerControl(QObject *parent) + : QMediaPlayerControl(parent) + { + } + + QMediaPlayer::State state() const { return QMediaPlayer::StoppedState; } + QMediaPlayer::MediaStatus mediaStatus() const { return QMediaPlayer::NoMedia; } + + qint64 duration() const { return 0; } + qint64 position() const { return 0; } + void setPosition(qint64) {} + int volume() const { return 0; } + void setVolume(int) {} + bool isMuted() const { return false; } + void setMuted(bool) {} + int bufferStatus() const { return 0; } + bool isAudioAvailable() const { return false; } + bool isVideoAvailable() const { return false; } + bool isSeekable() const { return false; } + QMediaTimeRange availablePlaybackRanges() const { return QMediaTimeRange(); } + qreal playbackRate() const { return 1; } + void setPlaybackRate(qreal) {} + QMediaContent media() const { return QMediaContent(); } + const QIODevice *mediaStream() const { return 0; } + void setMedia(const QMediaContent &, QIODevice *) {} + + void play() {} + void pause() {} + void stop() {} +}; + +class QDeclarativeMediaBaseAnimation : public QObject +{ +public: + QDeclarativeMediaBaseAnimation(QDeclarativeMediaBase *media) + : m_media(media) + { + } + + void start() { if (!m_timer.isActive()) m_timer.start(500, this); } + void stop() { m_timer.stop(); } + +protected: + void timerEvent(QTimerEvent *event) + { + if (event->timerId() == m_timer.timerId()) { + event->accept(); + + if (m_media->m_state == QMediaPlayer::PlayingState) + emit m_media->positionChanged(); + if (m_media->m_status == QMediaPlayer::BufferingMedia || QMediaPlayer::StalledMedia) + emit m_media->bufferProgressChanged(); + } else { + QObject::timerEvent(event); + } + } + +private: + QDeclarativeMediaBase *m_media; + QBasicTimer m_timer; +}; + +void QDeclarativeMediaBase::_q_stateChanged(QMediaPlayer::State state) +{ + if (state != m_state) { + QMediaPlayer::State oldState = m_state; + + m_state = state; + + if (state == QMediaPlayer::StoppedState) { + emit stopped(); + emit playingChanged(); + } else if (oldState == QMediaPlayer::StoppedState) { + emit started(); + emit playingChanged(); + } else if (oldState == QMediaPlayer::PausedState) { + m_paused = false; + + emit resumed(); + emit pausedChanged(); + } + + if (state == m_state && state == QMediaPlayer::PausedState) { + bool wasPaused = m_paused; + + m_paused = true; + + emit paused(); + + if (!wasPaused) + emit pausedChanged(); + } + + if (m_state == QMediaPlayer::PlayingState + || m_status == QMediaPlayer::BufferingMedia + || m_status == QMediaPlayer::StalledMedia) { + m_animation->start(); + } else { + m_animation->stop(); + } + } +} + +void QDeclarativeMediaBase::_q_mediaStatusChanged(QMediaPlayer::MediaStatus status) +{ + if (status != m_status) { + m_status = status; + + switch (status) { + case QMediaPlayer::LoadedMedia: + emit loaded(); + break; + case QMediaPlayer::BufferingMedia: + emit buffering(); + break; + case QMediaPlayer::BufferedMedia: + emit buffered(); + break; + case QMediaPlayer::StalledMedia: + emit stalled(); + break; + case QMediaPlayer::EndOfMedia: + emit endOfMedia(); + break; + default: + break; + } + + emit statusChanged(); + + if (m_state == QMediaPlayer::PlayingState + || m_status == QMediaPlayer::BufferingMedia + || m_status == QMediaPlayer::StalledMedia) { + m_animation->start(); + } else { + m_animation->stop(); + } + } +} + +void QDeclarativeMediaBase::_q_metaDataChanged() +{ + m_metaObject->metaDataChanged(); +} + +QDeclarativeMediaBase::QDeclarativeMediaBase() + : m_mediaService(0) + , m_playerControl(0) + , m_mediaObject(0) + , m_mediaProvider(0) + , m_metaDataControl(0) + , m_metaObject(0) + , m_animation(0) + , m_state(QMediaPlayer::StoppedState) + , m_status(QMediaPlayer::NoMedia) + , m_error(QMediaPlayer::NoError) + , m_paused(false) +{ +} + +QDeclarativeMediaBase::~QDeclarativeMediaBase() +{ +} + +void QDeclarativeMediaBase::shutdown() +{ + delete m_metaObject; + delete m_mediaObject; + + if (m_mediaProvider) + m_mediaProvider->releaseService(m_mediaService); + + delete m_animation; + +} + +void QDeclarativeMediaBase::setObject(QObject *object) +{ + if ((m_mediaProvider = QMediaServiceProvider::defaultServiceProvider())) { + if ((m_mediaService = m_mediaProvider->requestService(Q_MEDIASERVICE_MEDIAPLAYER))) { + m_playerControl = qobject_cast( + m_mediaService->control(QMediaPlayerControl_iid)); + m_metaDataControl = qobject_cast( + m_mediaService->control(QMetaDataControl_iid)); + m_mediaObject = new QDeclarativeMediaBaseObject(m_mediaService); + } + } + + if (m_playerControl) { + QObject::connect(m_playerControl, SIGNAL(stateChanged(QMediaPlayer::State)), + object, SLOT(_q_stateChanged(QMediaPlayer::State))); + QObject::connect(m_playerControl, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)), + object, SLOT(_q_mediaStatusChanged(QMediaPlayer::MediaStatus))); + QObject::connect(m_playerControl, SIGNAL(mediaChanged(QMediaContent)), + object, SIGNAL(sourceChanged())); + QObject::connect(m_playerControl, SIGNAL(durationChanged(qint64)), + object, SIGNAL(durationChanged())); + QObject::connect(m_playerControl, SIGNAL(positionChanged(qint64)), + object, SIGNAL(positionChanged())); + QObject::connect(m_playerControl, SIGNAL(volumeChanged(int)), + object, SIGNAL(volumeChanged())); + QObject::connect(m_playerControl, SIGNAL(mutedChanged(bool)), + object, SIGNAL(mutedChanged())); + QObject::connect(m_playerControl, SIGNAL(bufferStatusChanged(int)), + object, SIGNAL(bufferProgressChanged())); + QObject::connect(m_playerControl, SIGNAL(seekableChanged(bool)), + object, SIGNAL(seekableChanged())); + QObject::connect(m_playerControl, SIGNAL(playbackRateChanged(qreal)), + object, SIGNAL(playbackRateChanged())); + QObject::connect(m_playerControl, SIGNAL(error(int,QString)), + object, SLOT(_q_error(int,QString))); + + m_animation = new QDeclarativeMediaBaseAnimation(this); + } else { + m_error = QMediaPlayer::ServiceMissingError; + + m_playerControl = new QDeclarativeMediaBasePlayerControl(object); + } + + if (m_metaDataControl) { + m_metaObject = new QMetaDataControlMetaObject(m_metaDataControl, object); + + QObject::connect(m_metaDataControl, SIGNAL(metaDataChanged()), + object, SLOT(_q_metaDataChanged())); + } +} + +QUrl QDeclarativeMediaBase::source() const +{ + return m_playerControl->media().canonicalUrl(); +} + +void QDeclarativeMediaBase::setSource(const QUrl &url) +{ + if (m_error != QMediaPlayer::ServiceMissingError && m_error != QMediaPlayer::NoError) { + m_error = QMediaPlayer::NoError; + m_errorString = QString(); + + emit errorChanged(); + } + + m_playerControl->setMedia(QMediaContent(url), 0); +} + +bool QDeclarativeMediaBase::isPlaying() const +{ + return m_state != QMediaPlayer::StoppedState; +} + +void QDeclarativeMediaBase::setPlaying(bool playing) +{ + if (playing && m_state == QMediaPlayer::StoppedState) { + if (m_paused) + m_playerControl->pause(); + else + m_playerControl->play(); + } else if (!playing) { + m_playerControl->stop(); + } +} + +bool QDeclarativeMediaBase::isPaused() const +{ + return m_paused; +} + +void QDeclarativeMediaBase::setPaused(bool paused) +{ + if (m_paused != paused) { + if (paused && m_state == QMediaPlayer::PlayingState) { + m_playerControl->pause(); + } else if (!paused && m_state == QMediaPlayer::PausedState) { + m_playerControl->play(); + } else { + m_paused = paused; + + emit pausedChanged(); + } + } +} + +int QDeclarativeMediaBase::duration() const +{ + return m_playerControl->duration(); +} + +int QDeclarativeMediaBase::position() const +{ + return m_playerControl->position(); + +} + +void QDeclarativeMediaBase::setPosition(int position) +{ + m_playerControl->setPosition(position); +} + +qreal QDeclarativeMediaBase::volume() const +{ + return qreal(m_playerControl->volume()) / 100; +} + +void QDeclarativeMediaBase::setVolume(qreal volume) +{ + m_playerControl->setVolume(qRound(volume * 100)); +} + +bool QDeclarativeMediaBase::isMuted() const +{ + return m_playerControl->isMuted(); +} + +void QDeclarativeMediaBase::setMuted(bool muted) +{ + m_playerControl->setMuted(muted); +} + +qreal QDeclarativeMediaBase::bufferProgress() const +{ + return qreal(m_playerControl->bufferStatus()) / 100; +} + +bool QDeclarativeMediaBase::isSeekable() const +{ + return m_playerControl->isSeekable(); +} + +qreal QDeclarativeMediaBase::playbackRate() const +{ + return m_playerControl->playbackRate(); +} + +void QDeclarativeMediaBase::setPlaybackRate(qreal rate) +{ + m_playerControl->setPlaybackRate(rate); +} + +QString QDeclarativeMediaBase::errorString() const +{ + return m_errorString; +} + +QT_END_NAMESPACE + diff --git a/src/imports/multimedia/qdeclarativemediabase_p.h b/src/imports/multimedia/qdeclarativemediabase_p.h new file mode 100644 index 0000000..b40e84e --- /dev/null +++ b/src/imports/multimedia/qdeclarativemediabase_p.h @@ -0,0 +1,168 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#ifndef QDECLARATIVEMEDIABASE_P_H +#define QDECLARATIVEMEDIABASE_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of other Qt classes. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +class QMediaPlayerControl; +class QMediaService; +class QMediaServiceProvider; +class QMetaDataControl; +class QMetaDataControlMetaObject; +class QDeclarativeMediaBaseAnimation; + +class QDeclarativeMediaBase +{ +public: + QDeclarativeMediaBase(); + virtual ~QDeclarativeMediaBase(); + + QUrl source() const; + void setSource(const QUrl &url); + + bool isPlaying() const; + void setPlaying(bool playing); + + bool isPaused() const; + void setPaused(bool paused); + + int duration() const; + + int position() const; + void setPosition(int position); + + qreal volume() const; + void setVolume(qreal volume); + + bool isMuted() const; + void setMuted(bool muted); + + qreal bufferProgress() const; + + bool isSeekable() const; + + qreal playbackRate() const; + void setPlaybackRate(qreal rate); + + QString errorString() const; + + void _q_stateChanged(QMediaPlayer::State state); + void _q_mediaStatusChanged(QMediaPlayer::MediaStatus status); + + void _q_metaDataChanged(); + +protected: + void shutdown(); + + void setObject(QObject *object); + + virtual void sourceChanged() = 0; + + virtual void playingChanged() = 0; + virtual void pausedChanged() = 0; + + virtual void started() = 0; + virtual void resumed() = 0; + virtual void paused() = 0; + virtual void stopped() = 0; + + virtual void statusChanged() = 0; + + virtual void loaded() = 0; + virtual void buffering() = 0; + virtual void stalled() = 0; + virtual void buffered() = 0; + virtual void endOfMedia() = 0; + + virtual void durationChanged() = 0; + virtual void positionChanged() = 0; + + virtual void volumeChanged() = 0; + virtual void mutedChanged() = 0; + + virtual void bufferProgressChanged() = 0; + + virtual void seekableChanged() = 0; + virtual void playbackRateChanged() = 0; + + virtual void errorChanged() = 0; + + QMediaService *m_mediaService; + QMediaPlayerControl *m_playerControl; + + QMediaObject *m_mediaObject; + QMediaServiceProvider *m_mediaProvider; + QMetaDataControl *m_metaDataControl; + QMetaDataControlMetaObject *m_metaObject; + QDeclarativeMediaBaseAnimation *m_animation; + + QMediaPlayer::State m_state; + QMediaPlayer::MediaStatus m_status; + QMediaPlayer::Error m_error; + bool m_paused; + QString m_errorString; + + friend class QDeclarativeMediaBaseAnimation; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif diff --git a/src/imports/multimedia/qdeclarativevideo.cpp b/src/imports/multimedia/qdeclarativevideo.cpp new file mode 100644 index 0000000..064f242 --- /dev/null +++ b/src/imports/multimedia/qdeclarativevideo.cpp @@ -0,0 +1,945 @@ +/**************************************************************************** +** +** 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 "qdeclarativevideo_p.h" + +#include +#include +#include +#include +#include + + +QT_BEGIN_NAMESPACE + + +void QDeclarativeVideo::_q_nativeSizeChanged(const QSizeF &size) +{ + setImplicitWidth(size.width()); + setImplicitHeight(size.height()); +} + +void QDeclarativeVideo::_q_error(int errorCode, const QString &errorString) +{ + m_error = QMediaPlayer::Error(errorCode); + m_errorString = errorString; + + emit error(Error(errorCode), errorString); + emit errorChanged(); +} + + +/*! + \qmlclass Video QDeclarativeVideo + \since 4.7 + \brief The Video element allows you to add videos to a scene. + \inherits Item + + \qml + Video { source: "video/movie.mpg" } + \endqml + + The video item supports untransformed, stretched, and uniformly scaled video presentation. + For a description of stretched uniformly scaled presentation, see the \l fillMode property + description. + + The video item is only visible when the \l hasVideo property is true and the video is playing. + + \sa Audio +*/ + +/*! + \internal + \class QDeclarativeVideo + \brief The QDeclarativeVideo class provides a video item that you can add to a QDeclarativeView. +*/ + +QDeclarativeVideo::QDeclarativeVideo(QDeclarativeItem *parent) + : QDeclarativeItem(parent) + , m_graphicsItem(0) + +{ + m_graphicsItem = new QGraphicsVideoItem(this); + connect(m_graphicsItem, SIGNAL(nativeSizeChanged(QSizeF)), + this, SLOT(_q_nativeSizeChanged(QSizeF))); + + setObject(this); + + if (m_mediaService) { + connect(m_playerControl, SIGNAL(audioAvailableChanged(bool)), + this, SIGNAL(hasAudioChanged())); + connect(m_playerControl, SIGNAL(videoAvailableChanged(bool)), + this, SIGNAL(hasVideoChanged())); + + m_graphicsItem->setMediaObject(m_mediaObject); + } +} + +QDeclarativeVideo::~QDeclarativeVideo() +{ + shutdown(); + + delete m_graphicsItem; +} + +/*! + \qmlproperty url Video::source + + This property holds the source URL of the media. +*/ + +/*! + \qmlproperty bool Video::playing + + This property holds whether the media is playing. + + Defaults to false, and can be set to true to start playback. +*/ + +/*! + \qmlproperty bool Video::paused + + This property holds whether the media is paused. + + Defaults to false, and can be set to true to pause playback. +*/ + +/*! + \qmlsignal Video::onStarted() + + This handler is called when playback is started. +*/ + +/*! + \qmlsignal Video::onResumed() + + This handler is called when playback is resumed from the paused state. +*/ + +/*! + \qmlsignal Video::onPaused() + + This handler is called when playback is paused. +*/ + +/*! + \qmlsignal Video::onStopped() + + This handler is called when playback is stopped. +*/ + +/*! + \qmlproperty enum Video::status + + This property holds the status of media loading. It can be one of: + + \list + \o NoMedia - no media has been set. + \o Loading - the media is currently being loaded. + \o Loaded - the media has been loaded. + \o Buffering - the media is buffering data. + \o Stalled - playback has been interrupted while the media is buffering data. + \o Buffered - the media has buffered data. + \o EndOfMedia - the media has played to the end. + \o InvalidMedia - the media cannot be played. + \o UnknownStatus - the status of the media is cannot be determined. + \endlist +*/ + +QDeclarativeVideo::Status QDeclarativeVideo::status() const +{ + return Status(m_status); +} + +/*! + \qmlsignal Video::onLoaded() + + This handler is called when the media source has been loaded. +*/ + +/*! + \qmlsignal Video::onBuffering() + + This handler is called when the media starts buffering. +*/ + +/*! + \qmlsignal Video::onStalled() + + This handler is called when playback has stalled while the media buffers. +*/ + +/*! + \qmlsignal Video::onBuffered() + + This handler is called when the media has finished buffering. +*/ + +/*! + \qmlsignal Video::onEndOfMedia() + + This handler is called when playback stops because end of the media has been reached. +*/ + +/*! + \qmlproperty int Video::duration + + This property holds the duration of the media in milliseconds. + + If the media doesn't have a fixed duration (a live stream for example) this will be 0. +*/ + +/*! + \qmlproperty int Video::position + + This property holds the current playback position in milliseconds. +*/ + +/*! + \qmlproperty qreal Video::volume + + This property holds the volume of the audio output, from 0.0 (silent) to 1.0 (maximum volume). +*/ + +/*! + \qmlproperty bool Video::muted + + This property holds whether the audio output is muted. +*/ + +/*! + \qmlproperty bool Video::hasAudio + + This property holds whether the media contains audio. +*/ + +bool QDeclarativeVideo::hasAudio() const +{ + return m_playerControl->isAudioAvailable(); +} + +/*! + \qmlproperty bool Video::hasVideo + + This property holds whether the media contains video. +*/ + +bool QDeclarativeVideo::hasVideo() const +{ + return m_playerControl->isVideoAvailable(); +} + +/*! + \qmlproperty qreal Video::bufferProgress + + This property holds how much of the data buffer is currently filled, from 0.0 (empty) to 1.0 + (full). +*/ + +/*! + \qmlproperty bool Video::seekable + + This property holds whether position of the video can be changed. +*/ + +/*! + \qmlproperty qreal Video::playbackRate + + This property holds the rate at which video is played at as a multiple of the normal rate. +*/ + +/*! + \qmlproperty enum Video::error + + This property holds the error state of the video. It can be one of: + + \list + \o NoError - there is no current error. + \o ResourceError - the video cannot be played due to a problem allocating resources. + \o FormatError - the video format is not supported. + \o NetworkError - the video cannot be played due to network issues. + \o AccessDenied - the video cannot be played due to insufficient permissions. + \o ServiceMissing - the video cannot be played because the media service could not be + instantiated. + \endlist +*/ + + +QDeclarativeVideo::Error QDeclarativeVideo::error() const +{ + return Error(m_error); +} + +/*! + \qmlproperty string Video::errorString + + This property holds a string describing the current error condition in more detail. +*/ + +/*! + \qmlsignal Video::onError(error, errorString) + + This handler is called when an \l {Error}{error} has occurred. The errorString parameter + may contain more detailed information about the error. +*/ + +/*! + \qmlproperty enum Video::fillMode + + Set this property to define how the video is scaled to fit the target area. + + \list + \o Stretch - the video is scaled to fit. + \o PreserveAspectFit - the video is scaled uniformly to fit without cropping + \o PreserveAspectCrop - the video is scaled uniformly to fill, cropping if necessary + \endlist + + The default fill mode is PreserveAspectFit. +*/ + +QDeclarativeVideo::FillMode QDeclarativeVideo::fillMode() const +{ + return FillMode(m_graphicsItem->aspectRatioMode()); +} + +void QDeclarativeVideo::setFillMode(FillMode mode) +{ + m_graphicsItem->setAspectRatioMode(Qt::AspectRatioMode(mode)); +} + +/*! + \qmlmethod Video::play() + + Starts playback of the media. + + Sets the \l playing property to true, and the \l paused property to false. +*/ + +void QDeclarativeVideo::play() +{ + m_playerControl->play(); + + if (m_paused) { + m_paused = false; + emit pausedChanged(); + } +} + +/*! + \qmlmethod Video::pause() + + Pauses playback of the media. + + Sets the \l playing and \l paused properties to true. +*/ + +void QDeclarativeVideo::pause() +{ + m_playerControl->pause(); + + if (!m_paused && m_state == QMediaPlayer::PausedState) { + m_paused = true; + emit pausedChanged(); + } +} + +/*! + \qmlmethod Video::stop() + + Stops playback of the media. + + Sets the \l playing and \l paused properties to false. +*/ + +void QDeclarativeVideo::stop() +{ + m_playerControl->stop(); + + if (m_paused) { + m_paused = false; + emit pausedChanged(); + } +} + +void QDeclarativeVideo::paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) +{ +} + +void QDeclarativeVideo::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) +{ + m_graphicsItem->setSize(newGeometry.size()); + + QDeclarativeItem::geometryChanged(newGeometry, oldGeometry); +} + +QT_END_NAMESPACE + +// *************************************** +// Documentation for meta-data properties. +// *************************************** + +/*! + \qmlproperty variant Video::title + + This property holds the tile of the media. + + \sa {QtMultimedia::Title} +*/ + +/*! + \qmlproperty variant Video::subTitle + + This property holds the sub-title of the media. + + \sa {QtMultimedia::SubTitle} +*/ + +/*! + \qmlproperty variant Video::author + + This property holds the author of the media. + + \sa {QtMultimedia::Author} +*/ + +/*! + \qmlproperty variant Video::comment + + This property holds a user comment about the media. + + \sa {QtMultimedia::Comment} +*/ + +/*! + \qmlproperty variant Video::description + + This property holds a description of the media. + + \sa {QtMultimedia::Description} +*/ + +/*! + \qmlproperty variant Video::category + + This property holds the category of the media + + \sa {QtMultimedia::Category} +*/ + +/*! + \qmlproperty variant Video::genre + + This property holds the genre of the media. + + \sa {QtMultimedia::Genre} +*/ + +/*! + \qmlproperty variant Video::year + + This property holds the year of release of the media. + + \sa {QtMultimedia::Year} +*/ + +/*! + \qmlproperty variant Video::date + + This property holds the date of the media. + + \sa {QtMultimedia::Date} +*/ + +/*! + \qmlproperty variant Video::userRating + + This property holds a user rating of the media in the range of 0 to 100. + + \sa {QtMultimedia::UserRating} +*/ + +/*! + \qmlproperty variant Video::keywords + + This property holds a list of keywords describing the media. + + \sa {QtMultimedia::Keywords} +*/ + +/*! + \qmlproperty variant Video::language + + This property holds the language of the media, as an ISO 639-2 code. + + \sa {QtMultimedia::Language} +*/ + +/*! + \qmlproperty variant Video::publisher + + This property holds the publisher of the media. + + \sa {QtMultimedia::Publisher} +*/ + +/*! + \qmlproperty variant Video::copyright + + This property holds the media's copyright notice. + + \sa {QtMultimedia::Copyright} +*/ + +/*! + \qmlproperty variant Video::parentalRating + + This property holds the parental rating of the media. + + \sa {QtMultimedia::ParentalRating} +*/ + +/*! + \qmlproperty variant Video::ratingOrganisation + + This property holds the name of the rating organisation responsible for the + parental rating of the media. + + \sa {QtMultimedia::RatingOrganisation} +*/ + +/*! + \qmlproperty variant Video::size + + This property property holds the size of the media in bytes. + + \sa {QtMultimedia::Size} +*/ + +/*! + \qmlproperty variant Video::mediaType + + This property holds the type of the media. + + \sa {QtMultimedia::MediaType} +*/ + +/*! + \qmlproperty variant Video::audioBitRate + + This property holds the bit rate of the media's audio stream ni bits per + second. + + \sa {QtMultimedia::AudioBitRate} +*/ + +/*! + \qmlproperty variant Video::audioCodec + + This property holds the encoding of the media audio stream. + + \sa {QtMultimedia::AudioCodec} +*/ + +/*! + \qmlproperty variant Video::averageLevel + + This property holds the average volume level of the media. + + \sa {QtMultimedia::AverageLevel} +*/ + +/*! + \qmlproperty variant Video::channelCount + + This property holds the number of channels in the media's audio stream. + + \sa {QtMultimedia::ChannelCount} +*/ + +/*! + \qmlproperty variant Video::peakValue + + This property holds the peak volume of media's audio stream. + + \sa {QtMultimedia::PeakValue} +*/ + +/*! + \qmlproperty variant Video::sampleRate + + This property holds the sample rate of the media's audio stream in hertz. + + \sa {QtMultimedia::SampleRate} +*/ + +/*! + \qmlproperty variant Video::albumTitle + + This property holds the title of the album the media belongs to. + + \sa {QtMultimedia::AlbumTitle} +*/ + +/*! + \qmlproperty variant Video::albumArtist + + This property holds the name of the principal artist of the album the media + belongs to. + + \sa {QtMultimedia::AlbumArtist} +*/ + +/*! + \qmlproperty variant Video::contributingArtist + + This property holds the names of artists contributing to the media. + + \sa {QtMultimedia::ContributingArtist} +*/ + +/*! + \qmlproperty variant Video::composer + + This property holds the composer of the media. + + \sa {QtMultimedia::Composer} +*/ + +/*! + \qmlproperty variant Video::conductor + + This property holds the conductor of the media. + + \sa {QtMultimedia::Conductor} +*/ + +/*! + \qmlproperty variant Video::lyrics + + This property holds the lyrics to the media. + + \sa {QtMultimedia::Lyrics} +*/ + +/*! + \qmlproperty variant Video::mood + + This property holds the mood of the media. + + \sa {QtMultimedia::Mood} +*/ + +/*! + \qmlproperty variant Video::trackNumber + + This property holds the track number of the media. + + \sa {QtMultimedia::TrackNumber} +*/ + +/*! + \qmlproperty variant Video::trackCount + + This property holds the number of track on the album containing the media. + + \sa {QtMultimedia::TrackNumber} +*/ + +/*! + \qmlproperty variant Video::coverArtUrlSmall + + This property holds the URL of a small cover art image. + + \sa {QtMultimedia::CoverArtUrlSmall} +*/ + +/*! + \qmlproperty variant Video::coverArtUrlLarge + + This property holds the URL of a large cover art image. + + \sa {QtMultimedia::CoverArtUrlLarge} +*/ + +/*! + \qmlproperty variant Video::resolution + + This property holds the dimension of an image or video. + + \sa {QtMultimedia::Resolution} +*/ + +/*! + \qmlproperty variant Video::pixelAspectRatio + + This property holds the pixel aspect ratio of an image or video. + + \sa {QtMultimedia::PixelAspectRatio} +*/ + +/*! + \qmlproperty variant Video::videoFrameRate + + This property holds the frame rate of the media's video stream. + + \sa {QtMultimedia::VideoFrameRate} +*/ + +/*! + \qmlproperty variant Video::videoBitRate + + This property holds the bit rate of the media's video stream in bits per + second. + + \sa {QtMultimedia::VideoBitRate} +*/ + +/*! + \qmlproperty variant Video::videoCodec + + This property holds the encoding of the media's video stream. + + \sa {QtMultimedia::VideoCodec} +*/ + +/*! + \qmlproperty variant Video::posterUrl + + This property holds the URL of a poster image. + + \sa {QtMultimedia::PosterUrl} +*/ + +/*! + \qmlproperty variant Video::chapterNumber + + This property holds the chapter number of the media. + + \sa {QtMultimedia::ChapterNumber} +*/ + +/*! + \qmlproperty variant Video::director + + This property holds the director of the media. + + \sa {QtMultimedia::Director} +*/ + +/*! + \qmlproperty variant Video::leadPerformer + + This property holds the lead performer in the media. + + \sa {QtMultimedia::LeadPerformer} +*/ + +/*! + \qmlproperty variant Video::writer + + This property holds the writer of the media. + + \sa {QtMultimedia::Writer} +*/ + +// The remaining properties are related to photos, and are technically +// available but will certainly never have values. +#ifndef Q_QDOC + +/*! + \qmlproperty variant Video::cameraManufacturer + + \sa {QtMultimedia::CameraManufacturer} +*/ + +/*! + \qmlproperty variant Video::cameraModel + + \sa {QtMultimedia::CameraModel} +*/ + +/*! + \qmlproperty variant Video::event + + \sa {QtMultimedia::Event} +*/ + +/*! + \qmlproperty variant Video::subject + + \sa {QtMultimedia::Subject} +*/ + +/*! + \qmlproperty variant Video::orientation + + \sa {QtMultimedia::Orientation} +*/ + +/*! + \qmlproperty variant Video::exposureTime + + \sa {QtMultimedia::ExposureTime} +*/ + +/*! + \qmlproperty variant Video::fNumber + + \sa {QtMultimedia::FNumber} +*/ + +/*! + \qmlproperty variant Video::exposureProgram + + \sa {QtMultimedia::ExposureProgram} +*/ + +/*! + \qmlproperty variant Video::isoSpeedRatings + + \sa {QtMultimedia::ISOSpeedRatings} +*/ + +/*! + \qmlproperty variant Video::exposureBiasValue + + \sa {QtMultimedia::ExposureBiasValue} +*/ + +/*! + \qmlproperty variant Video::dateTimeDigitized + + \sa {QtMultimedia::DateTimeDigitized} +*/ + +/*! + \qmlproperty variant Video::subjectDistance + + \sa {QtMultimedia::SubjectDistance} +*/ + +/*! + \qmlproperty variant Video::meteringMode + + \sa {QtMultimedia::MeteringMode} +*/ + +/*! + \qmlproperty variant Video::lightSource + + \sa {QtMultimedia::LightSource} +*/ + +/*! + \qmlproperty variant Video::flash + + \sa {QtMultimedia::Flash} +*/ + +/*! + \qmlproperty variant Video::focalLength + + \sa {QtMultimedia::FocalLength} +*/ + +/*! + \qmlproperty variant Video::exposureMode + + \sa {QtMultimedia::ExposureMode} +*/ + +/*! + \qmlproperty variant Video::whiteBalance + + \sa {QtMultimedia::WhiteBalance} +*/ + +/*! + \qmlproperty variant Video::DigitalZoomRatio + + \sa {QtMultimedia::DigitalZoomRatio} +*/ + +/*! + \qmlproperty variant Video::focalLengthIn35mmFilm + + \sa {QtMultimedia::FocalLengthIn35mmFile} +*/ + +/*! + \qmlproperty variant Video::sceneCaptureType + + \sa {QtMultimedia::SceneCaptureType} +*/ + +/*! + \qmlproperty variant Video::gainControl + + \sa {QtMultimedia::GainControl} +*/ + +/*! + \qmlproperty variant Video::contrast + + \sa {QtMultimedia::contrast} +*/ + +/*! + \qmlproperty variant Video::saturation + + \sa {QtMultimedia::Saturation} +*/ + +/*! + \qmlproperty variant Video::sharpness + + \sa {QtMultimedia::Sharpness} +*/ + +/*! + \qmlproperty variant Video::deviceSettingDescription + + \sa {QtMultimedia::DeviceSettingDescription} +*/ + +#endif + +#include "moc_qdeclarativevideo_p.cpp" diff --git a/src/imports/multimedia/qdeclarativevideo_p.h b/src/imports/multimedia/qdeclarativevideo_p.h new file mode 100644 index 0000000..fb13519 --- /dev/null +++ b/src/imports/multimedia/qdeclarativevideo_p.h @@ -0,0 +1,204 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#ifndef QDECLARATIVEVIDEO_H +#define QDECLARATIVEVIDEO_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of other Qt classes. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qdeclarativemediabase_p.h" + +#include + +#include +#include + + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +class QTimerEvent; +class QVideoSurfaceFormat; + + +class QDeclarativeVideo : public QDeclarativeItem, public QDeclarativeMediaBase +{ + Q_OBJECT + Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) + Q_PROPERTY(bool playing READ isPlaying WRITE setPlaying NOTIFY playingChanged) + Q_PROPERTY(bool paused READ isPaused WRITE setPaused NOTIFY pausedChanged) + Q_PROPERTY(Status status READ status NOTIFY statusChanged) + Q_PROPERTY(int duration READ duration NOTIFY durationChanged) + Q_PROPERTY(int position READ position WRITE setPosition NOTIFY positionChanged) + Q_PROPERTY(qreal volume READ volume WRITE setVolume NOTIFY volumeChanged) + Q_PROPERTY(bool muted READ isMuted WRITE setMuted NOTIFY mutedChanged) + Q_PROPERTY(bool hasAudio READ hasAudio NOTIFY hasAudioChanged) + Q_PROPERTY(bool hasVideo READ hasVideo NOTIFY hasVideoChanged) + Q_PROPERTY(int bufferProgress READ bufferProgress NOTIFY bufferProgressChanged) + Q_PROPERTY(bool seekable READ isSeekable NOTIFY seekableChanged) + Q_PROPERTY(qreal playbackRate READ playbackRate WRITE setPlaybackRate NOTIFY playbackRateChanged) + Q_PROPERTY(Error error READ error NOTIFY errorChanged) + Q_PROPERTY(QString errorString READ errorString NOTIFY errorChanged) + Q_PROPERTY(FillMode fillMode READ fillMode WRITE setFillMode) + Q_ENUMS(FillMode) + Q_ENUMS(Status) + Q_ENUMS(Error) +public: + enum FillMode + { + Stretch = Qt::IgnoreAspectRatio, + PreserveAspectFit = Qt::KeepAspectRatio, + PreserveAspectCrop = Qt::KeepAspectRatioByExpanding + }; + + enum Status + { + UnknownStatus = QMediaPlayer::UnknownMediaStatus, + NoMedia = QMediaPlayer::NoMedia, + Loading = QMediaPlayer::LoadingMedia, + Loaded = QMediaPlayer::LoadedMedia, + Stalled = QMediaPlayer::StalledMedia, + Buffering = QMediaPlayer::BufferingMedia, + Buffered = QMediaPlayer::BufferedMedia, + EndOfMedia = QMediaPlayer::EndOfMedia, + InvalidMedia = QMediaPlayer::InvalidMedia + }; + + enum Error + { + NoError = QMediaPlayer::NoError, + ResourceError = QMediaPlayer::ResourceError, + FormatError = QMediaPlayer::FormatError, + NetworkError = QMediaPlayer::NetworkError, + AccessDenied = QMediaPlayer::AccessDeniedError, + ServiceMissing = QMediaPlayer::ServiceMissingError + }; + + QDeclarativeVideo(QDeclarativeItem *parent = 0); + ~QDeclarativeVideo(); + + bool hasAudio() const; + bool hasVideo() const; + + FillMode fillMode() const; + void setFillMode(FillMode mode); + + Status status() const; + Error error() const; + + void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); + +public Q_SLOTS: + void play(); + void pause(); + void stop(); + +Q_SIGNALS: + void sourceChanged(); + + void playingChanged(); + void pausedChanged(); + + void started(); + void resumed(); + void paused(); + void stopped(); + + void statusChanged(); + + void loaded(); + void buffering(); + void stalled(); + void buffered(); + void endOfMedia(); + + void durationChanged(); + void positionChanged(); + + void volumeChanged(); + void mutedChanged(); + void hasAudioChanged(); + void hasVideoChanged(); + + void bufferProgressChanged(); + + void seekableChanged(); + void playbackRateChanged(); + + void errorChanged(); + void error(QDeclarativeVideo::Error error, const QString &errorString); + +protected: + void geometryChanged(const QRectF &geometry, const QRectF &); + +private Q_SLOTS: + void _q_nativeSizeChanged(const QSizeF &size); + void _q_error(int, const QString &); + +private: + Q_DISABLE_COPY(QDeclarativeVideo) + + QGraphicsVideoItem *m_graphicsItem; + + Q_PRIVATE_SLOT(mediaBase(), void _q_stateChanged(QMediaPlayer::State)) + Q_PRIVATE_SLOT(mediaBase(), void _q_mediaStatusChanged(QMediaPlayer::MediaStatus)) + Q_PRIVATE_SLOT(mediaBase(), void _q_metaDataChanged()) + + inline QDeclarativeMediaBase *mediaBase() { return this; } +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QT_PREPEND_NAMESPACE(QDeclarativeVideo)) + +QT_END_HEADER + +#endif diff --git a/src/imports/multimedia/qmetadatacontrolmetaobject.cpp b/src/imports/multimedia/qmetadatacontrolmetaobject.cpp new file mode 100644 index 0000000..e90cbd6 --- /dev/null +++ b/src/imports/multimedia/qmetadatacontrolmetaobject.cpp @@ -0,0 +1,362 @@ +/**************************************************************************** +** +** 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 "qmetadatacontrolmetaobject_p.h" +#include + + +QT_BEGIN_NAMESPACE + +// copied from qmetaobject.cpp +// do not touch without touching the moc as well +enum PropertyFlags { + Invalid = 0x00000000, + Readable = 0x00000001, + Writable = 0x00000002, + Resettable = 0x00000004, + EnumOrFlag = 0x00000008, + StdCppSet = 0x00000100, +// Override = 0x00000200, + Designable = 0x00001000, + ResolveDesignable = 0x00002000, + Scriptable = 0x00004000, + ResolveScriptable = 0x00008000, + Stored = 0x00010000, + ResolveStored = 0x00020000, + Editable = 0x00040000, + ResolveEditable = 0x00080000, + User = 0x00100000, + ResolveUser = 0x00200000, + Notify = 0x00400000, + Dynamic = 0x00800000 +}; + +enum MethodFlags { + AccessPrivate = 0x00, + AccessProtected = 0x01, + AccessPublic = 0x02, + AccessMask = 0x03, //mask + + MethodMethod = 0x00, + MethodSignal = 0x04, + MethodSlot = 0x08, + MethodConstructor = 0x0c, + MethodTypeMask = 0x0c, + + MethodCompatibility = 0x10, + MethodCloned = 0x20, + MethodScriptable = 0x40 +}; + +struct QMetaObjectPrivate +{ + int revision; + int className; + int classInfoCount, classInfoData; + int methodCount, methodData; + int propertyCount, propertyData; + int enumeratorCount, enumeratorData; + int constructorCount, constructorData; + int flags; +}; + +static inline const QMetaObjectPrivate *priv(const uint* m_data) +{ return reinterpret_cast(m_data); } +// end of copied lines from qmetaobject.cpp + +namespace +{ + struct MetaDataKey + { + QtMultimedia::MetaData key; + const char *name; + }; + + const MetaDataKey qt_metaDataKeys[] = + { + { QtMultimedia::Title, "title" }, + { QtMultimedia::SubTitle, "subTitle" }, + { QtMultimedia::Author, "author" }, + { QtMultimedia::Comment, "comment" }, + { QtMultimedia::Description, "description" }, + { QtMultimedia::Category, "category" }, + { QtMultimedia::Genre, "genre" }, + { QtMultimedia::Year, "year" }, + { QtMultimedia::Date, "date" }, + { QtMultimedia::UserRating, "userRating" }, + { QtMultimedia::Keywords, "keywords" }, + { QtMultimedia::Language, "language" }, + { QtMultimedia::Publisher, "publisher" }, + { QtMultimedia::Copyright, "copyright" }, + { QtMultimedia::ParentalRating, "parentalRating" }, + { QtMultimedia::RatingOrganisation, "ratingOrganisation" }, + + // Media + { QtMultimedia::Size, "size" }, + { QtMultimedia::MediaType, "mediaType" }, +// { QtMultimedia::Duration, "duration" }, + + // Audio + { QtMultimedia::AudioBitRate, "audioBitRate" }, + { QtMultimedia::AudioCodec, "audioCodec" }, + { QtMultimedia::AverageLevel, "averageLevel" }, + { QtMultimedia::ChannelCount, "channelCount" }, + { QtMultimedia::PeakValue, "peakValue" }, + { QtMultimedia::SampleRate, "sampleRate" }, + + // Music + { QtMultimedia::AlbumTitle, "albumTitle" }, + { QtMultimedia::AlbumArtist, "albumArtist" }, + { QtMultimedia::ContributingArtist, "contributingArtist" }, + { QtMultimedia::Composer, "composer" }, + { QtMultimedia::Conductor, "conductor" }, + { QtMultimedia::Lyrics, "lyrics" }, + { QtMultimedia::Mood, "mood" }, + { QtMultimedia::TrackNumber, "trackNumber" }, + { QtMultimedia::TrackCount, "trackCount" }, + + { QtMultimedia::CoverArtUrlSmall, "coverArtUrlSmall" }, + { QtMultimedia::CoverArtUrlLarge, "coverArtUrlLarge" }, + + // Image/Video + { QtMultimedia::Resolution, "resolution" }, + { QtMultimedia::PixelAspectRatio, "pixelAspectRatio" }, + + // Video + { QtMultimedia::VideoFrameRate, "videoFrameRate" }, + { QtMultimedia::VideoBitRate, "videoBitRate" }, + { QtMultimedia::VideoCodec, "videoCodec" }, + + { QtMultimedia::PosterUrl, "posterUrl" }, + + // Movie + { QtMultimedia::ChapterNumber, "chapterNumber" }, + { QtMultimedia::Director, "director" }, + { QtMultimedia::LeadPerformer, "leadPerformer" }, + { QtMultimedia::Writer, "writer" }, + + // Photos + { QtMultimedia::CameraManufacturer, "cameraManufacturer" }, + { QtMultimedia::CameraModel, "cameraModel" }, + { QtMultimedia::Event, "event" }, + { QtMultimedia::Subject, "subject" }, + { QtMultimedia::Orientation, "orientation" }, + { QtMultimedia::ExposureTime, "exposureTime" }, + { QtMultimedia::FNumber, "fNumber" }, + { QtMultimedia::ExposureProgram, "exposureProgram" }, + { QtMultimedia::ISOSpeedRatings, "isoSpeedRatings" }, + { QtMultimedia::ExposureBiasValue, "exposureBiasValue" }, + { QtMultimedia::DateTimeOriginal, "dateTimeOriginal" }, + { QtMultimedia::DateTimeDigitized, "dateTimeDigitized" }, + { QtMultimedia::SubjectDistance, "subjectDistance" }, + { QtMultimedia::MeteringMode, "meteringMode" }, + { QtMultimedia::LightSource, "lightSource" }, + { QtMultimedia::Flash, "flash" }, + { QtMultimedia::FocalLength, "focalLength" }, + { QtMultimedia::ExposureMode, "exposureMode" }, + { QtMultimedia::WhiteBalance, "whiteBalance" }, + { QtMultimedia::DigitalZoomRatio, "digitalZoomRatio" }, + { QtMultimedia::FocalLengthIn35mmFilm, "focalLengthIn35mmFilm" }, + { QtMultimedia::SceneCaptureType, "sceneCaptureType" }, + { QtMultimedia::GainControl, "gainControl" }, + { QtMultimedia::Contrast, "contrast" }, + { QtMultimedia::Saturation, "saturation" }, + { QtMultimedia::Sharpness, "sharpness" }, + { QtMultimedia::DeviceSettingDescription, "deviceSettingDescription" } + }; + + class QMetaDataControlObject : public QObject + { + public: + inline QObjectData *data() { return d_ptr.data(); } + }; +} + +QMetaDataControlMetaObject::QMetaDataControlMetaObject(QMetaDataControl *control, QObject *object) + : m_control(control) + , m_object(object) + , m_string(0) + , m_data(0) + , m_propertyOffset(0) + , m_signalOffset(0) +{ + const QMetaObject *superClass = m_object->metaObject(); + + const int propertyCount = sizeof(qt_metaDataKeys) / sizeof(MetaDataKey); + const int dataSize = sizeof(uint) + * (13 // QMetaObjectPrivate members. + + 5 // 5 members per signal. + + 4 * propertyCount // 3 members per property + 1 notify signal per property. + + 1); // Terminating value. + + m_data = reinterpret_cast(qMalloc(dataSize)); + + QMetaObjectPrivate *pMeta = reinterpret_cast(m_data); + + pMeta->revision = 3; + pMeta->className = 0; + pMeta->classInfoCount = 0; + pMeta->classInfoData = 0; + pMeta->methodCount = 1; + pMeta->methodData = 13; + pMeta->propertyCount = propertyCount; + pMeta->propertyData = 18; + pMeta->enumeratorCount = 0; + pMeta->enumeratorData = 0; + pMeta->constructorCount = 0; + pMeta->constructorData = 0; + pMeta->flags = 0x01; // Dynamic meta object flag. + + const int classNameSize = qstrlen(superClass->className()) + 1; + + int stringIndex = classNameSize + 1; + + // __metaDataChanged() signal. + static const char *changeSignal = "__metaDataChanged()"; + const int changeSignalSize = qstrlen(changeSignal) + 1; + + m_data[13] = stringIndex; // Signature. + m_data[14] = classNameSize; // Parameters. + m_data[15] = classNameSize; // Type. + m_data[16] = classNameSize; // Tag. + m_data[17] = MethodSignal | AccessProtected; // Flags. + + stringIndex += changeSignalSize; + + const char *qvariantName = "QVariant"; + const int qvariantSize = qstrlen(qvariantName) + 1; + const int qvariantIndex = stringIndex; + + stringIndex += qvariantSize; + + // Properties. + for (int i = 0; i < propertyCount; ++i) { + m_data[18 + 3 * i] = stringIndex; // Name. + m_data[19 + 3 * i] = qvariantIndex; // Type. + m_data[20 + 3 * i] + = Readable | Writable | Notify | Dynamic | (0xffffffff << 24); // Flags. + m_data[18 + propertyCount * 3 + i] = 0; // Notify signal. + + stringIndex += qstrlen(qt_metaDataKeys[i].name) + 1; + } + + // Terminating value. + m_data[18 + propertyCount * 4] = 0; + + // Build string. + m_string = reinterpret_cast(qMalloc(stringIndex + 1)); + + // Class name. + qMemCopy(m_string, superClass->className(), classNameSize); + + stringIndex = classNameSize; + + // Null m_string. + m_string[stringIndex] = '\0'; + stringIndex += 1; + + // __metaDataChanged() signal. + qMemCopy(m_string + stringIndex, changeSignal, changeSignalSize); + stringIndex += changeSignalSize; + + qMemCopy(m_string + stringIndex, qvariantName, qvariantSize); + stringIndex += qvariantSize; + + // Properties. + for (int i = 0; i < propertyCount; ++i) { + const int propertyNameSize = qstrlen(qt_metaDataKeys[i].name) + 1; + + qMemCopy(m_string + stringIndex, qt_metaDataKeys[i].name, propertyNameSize); + stringIndex += propertyNameSize; + } + + // Terminating character. + m_string[stringIndex] = '\0'; + + d.superdata = superClass; + d.stringdata = m_string; + d.data = m_data; + d.extradata = 0; + + static_cast(m_object)->data()->metaObject = this; + + m_propertyOffset = propertyOffset(); + m_signalOffset = methodOffset(); +} + +QMetaDataControlMetaObject::~QMetaDataControlMetaObject() +{ + static_cast(m_object)->data()->metaObject = 0; + + qFree(m_data); + qFree(m_string); +} + +int QMetaDataControlMetaObject::metaCall(QMetaObject::Call c, int id, void **a) +{ + if (c == QMetaObject::ReadProperty && id >= m_propertyOffset) { + int propId = id - m_propertyOffset; + + *reinterpret_cast(a[0]) = m_control->metaData(qt_metaDataKeys[propId].key); + + return -1; + } else if (c == QMetaObject::WriteProperty && id >= m_propertyOffset) { + int propId = id - m_propertyOffset; + + m_control->setMetaData(qt_metaDataKeys[propId].key, *reinterpret_cast(a[0])); + + return -1; + } else { + return m_object->qt_metacall(c, id, a); + } +} + +int QMetaDataControlMetaObject::createProperty(const char *, const char *) +{ + return -1; +} + +void QMetaDataControlMetaObject::metaDataChanged() +{ + activate(m_object, m_signalOffset, 0); +} + +QT_END_NAMESPACE diff --git a/src/imports/multimedia/qmetadatacontrolmetaobject_p.h b/src/imports/multimedia/qmetadatacontrolmetaobject_p.h new file mode 100644 index 0000000..c381f2d --- /dev/null +++ b/src/imports/multimedia/qmetadatacontrolmetaobject_p.h @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#ifndef QMETADATACONTROLMETAOBJECT_P_H +#define QMETADATACONTROLMETAOJBECT_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of other Qt classes. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include +#include + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +class QMetaDataControl; + +class QMetaDataControlMetaObject : public QAbstractDynamicMetaObject +{ +public: + QMetaDataControlMetaObject(QMetaDataControl *control, QObject *object); + ~QMetaDataControlMetaObject(); + + int metaCall(QMetaObject::Call call, int _id, void **arguments); + int createProperty(const char *, const char *); + + void metaDataChanged(); + +private: + QMetaDataControl *m_control; + QObject *m_object; + char *m_string; + uint *m_data; + + int m_propertyOffset; + int m_signalOffset; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif diff --git a/src/plugins/qdeclarativemodules/multimedia/qdeclarativeaudio.cpp b/src/plugins/qdeclarativemodules/multimedia/qdeclarativeaudio.cpp deleted file mode 100644 index df2888c..0000000 --- a/src/plugins/qdeclarativemodules/multimedia/qdeclarativeaudio.cpp +++ /dev/null @@ -1,327 +0,0 @@ -/**************************************************************************** -** -** 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 "qdeclarativeaudio_p.h" - -#include - -QT_BEGIN_NAMESPACE - - -/*! - \qmlclass Audio QDeclarativeAudio - \since 4.7 - \brief The Audio element allows you to add audio playback to a scene. - - \qml - Audio { source: "audio/song.mp3" } - \endqml - - \sa Video -*/ - -/*! - \internal - \class QDeclarativeAudio - \brief The QDeclarativeAudio class provides an audio item that you can add to a QDeclarativeView. -*/ - -void QDeclarativeAudio::_q_error(int errorCode, const QString &errorString) -{ - m_error = QMediaPlayer::Error(errorCode); - m_errorString = errorString; - - emit error(Error(errorCode), errorString); - emit errorChanged(); -} - - -QDeclarativeAudio::QDeclarativeAudio(QObject *parent) - : QObject(parent) -{ - setObject(this); -} - -QDeclarativeAudio::~QDeclarativeAudio() -{ - shutdown(); -} - -/*! - \qmlmethod Audio::play() - - Starts playback of the media. - - Sets the \l playing property to true, and the \l paused property to false. -*/ - -void QDeclarativeAudio::play() -{ - m_playerControl->play(); - - if (m_paused) { - m_paused = false; - emit pausedChanged(); - } -} - -/*! - \qmlmethod Audio::pause() - - Pauses playback of the media. - - Sets the \l playing and \l paused properties to true. -*/ - -void QDeclarativeAudio::pause() -{ - m_playerControl->pause(); - - if (!m_paused && m_state == QMediaPlayer::PausedState) { - m_paused = true; - emit pausedChanged(); - } -} - -/*! - \qmlmethod Audio::stop() - - Stops playback of the media. - - Sets the \l playing and \l paused properties to false. -*/ - -void QDeclarativeAudio::stop() -{ - m_playerControl->stop(); - - if (m_paused) { - m_paused = false; - emit pausedChanged(); - } -} - -/*! - \qmlproperty url Audio::source - - This property holds the source URL of the media. -*/ - -/*! - \qmlproperty bool Audio::playing - - This property holds whether the media is playing. - - Defaults to false, and can be set to true to start playback. -*/ - -/*! - \qmlproperty bool Audio::paused - - This property holds whether the media is paused. - - Defaults to false, and can be set to true to pause playback. -*/ - -/*! - \qmlsignal Audio::onStarted() - - This handler is called when playback is started. -*/ - -/*! - \qmlsignal Audio::onResumed() - - This handler is called when playback is resumed from the paused state. -*/ - -/*! - \qmlsignal Audio::onPaused() - - This handler is called when playback is paused. -*/ - -/*! - \qmlsignal Audio::onStopped() - - This handler is called when playback is stopped. -*/ - -/*! - \qmlproperty enum Audio::status - - This property holds the status of media loading. It can be one of: - - \list - \o NoMedia - no media has been set. - \o Loading - the media is currently being loaded. - \o Loaded - the media has been loaded. - \o Buffering - the media is buffering data. - \o Stalled - playback has been interrupted while the media is buffering data. - \o Buffered - the media has buffered data. - \o EndOfMedia - the media has played to the end. - \o InvalidMedia - the media cannot be played. - \o UnknownStatus - the status of the media is unknown. - \endlist -*/ - -QDeclarativeAudio::Status QDeclarativeAudio::status() const -{ - return Status(m_status); -} - -/*! - \qmlsignal Audio::onLoaded() - - This handler is called when the media source has been loaded. -*/ - -/*! - \qmlsignal Audio::onBuffering() - - This handler is called when the media starts buffering. -*/ - -/*! - \qmlsignal Audio::onStalled() - - This handler is called when playback has stalled while the media buffers. -*/ - -/*! - \qmlsignal Audio::onBuffered() - - This handler is called when the media has finished buffering. -*/ - -/*! - \qmlsignal Audio::onEndOfMedia() - - This handler is called when playback stops because end of the media has been reached. -*/ -/*! - \qmlproperty int Audio::duration - - This property holds the duration of the media in milliseconds. - - If the media doesn't have a fixed duration (a live stream for example) this will be 0. -*/ - -/*! - \qmlproperty int Audio::position - - This property holds the current playback position in milliseconds. - - If the \l seekable property is true, this property can be set to seek to a new position. -*/ - -/*! - \qmlproperty qreal Audio::volume - - This property holds the volume of the audio output, from 0.0 (silent) to 1.0 (maximum volume). -*/ - -/*! - \qmlproperty bool Audio::muted - - This property holds whether the audio output is muted. -*/ - -/*! - \qmlproperty qreal Audio::bufferProgress - - This property holds how much of the data buffer is currently filled, from 0.0 (empty) to 1.0 - (full). -*/ - -/*! - \qmlproperty bool Audio::seekable - - This property holds whether position of the audio can be changed. - - If true; setting a \l position value will cause playback to seek to the new position. -*/ - -/*! - \qmlproperty qreal Audio::playbackRate - - This property holds the rate at which audio is played at as a multiple of the normal rate. -*/ - -/*! - \qmlproperty enum Audio::error - - This property holds the error state of the audio. It can be one of: - - \list - \o NoError - there is no current error. - \o ResourceError - the audio cannot be played due to a problem allocating resources. - \o FormatError - the audio format is not supported. - \o NetworkError - the audio cannot be played due to network issues. - \o AccessDenied - the audio cannot be played due to insufficient permissions. - \o ServiceMissing - the audio cannot be played because the media service could not be - instantiated. - \endlist -*/ - -QDeclarativeAudio::Error QDeclarativeAudio::error() const -{ - return Error(m_error); -} - -/*! - \qmlproperty string Audio::errorString - - This property holds a string describing the current error condition in more detail. -*/ - -/*! - \qmlsignal Audio::onError(error, errorString) - - This handler is called when an \l {Error}{error} has occurred. The errorString parameter - may contain more detailed information about the error. -*/ - -QT_END_NAMESPACE - -#include "moc_qdeclarativeaudio_p.cpp" - - diff --git a/src/plugins/qdeclarativemodules/multimedia/qdeclarativeaudio_p.h b/src/plugins/qdeclarativemodules/multimedia/qdeclarativeaudio_p.h deleted file mode 100644 index 9881dbc..0000000 --- a/src/plugins/qdeclarativemodules/multimedia/qdeclarativeaudio_p.h +++ /dev/null @@ -1,173 +0,0 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ - -#ifndef QDECLARATIVEAUDIO_P_H -#define QDECLARATIVEAUDIO_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists for the convenience -// of other Qt classes. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include "qdeclarativemediabase_p.h" - -#include -#include - - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -class QTimerEvent; - -class QDeclarativeAudio : public QObject, public QDeclarativeMediaBase, public QDeclarativeParserStatus -{ - Q_OBJECT - Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) - Q_PROPERTY(bool playing READ isPlaying WRITE setPlaying NOTIFY playingChanged) - Q_PROPERTY(bool paused READ isPaused WRITE setPaused NOTIFY pausedChanged) - Q_PROPERTY(Status status READ status NOTIFY statusChanged) - Q_PROPERTY(int duration READ duration NOTIFY durationChanged) - Q_PROPERTY(int position READ position WRITE setPosition NOTIFY positionChanged) - Q_PROPERTY(qreal volume READ volume WRITE setVolume NOTIFY volumeChanged) - Q_PROPERTY(bool muted READ isMuted WRITE setMuted NOTIFY mutedChanged) - Q_PROPERTY(int bufferProgress READ bufferProgress NOTIFY bufferProgressChanged) - Q_PROPERTY(bool seekable READ isSeekable NOTIFY seekableChanged) - Q_PROPERTY(qreal playbackRate READ playbackRate WRITE setPlaybackRate NOTIFY playbackRateChanged) - Q_PROPERTY(Error error READ error NOTIFY errorChanged) - Q_PROPERTY(QString errorString READ errorString NOTIFY errorChanged) - Q_ENUMS(Status) - Q_ENUMS(Error) - Q_INTERFACES(QDeclarativeParserStatus) -public: - enum Status - { - UnknownStatus = QMediaPlayer::UnknownMediaStatus, - NoMedia = QMediaPlayer::NoMedia, - Loading = QMediaPlayer::LoadingMedia, - Loaded = QMediaPlayer::LoadedMedia, - Stalled = QMediaPlayer::StalledMedia, - Buffering = QMediaPlayer::BufferingMedia, - Buffered = QMediaPlayer::BufferedMedia, - EndOfMedia = QMediaPlayer::EndOfMedia, - InvalidMedia = QMediaPlayer::InvalidMedia - }; - - enum Error - { - NoError = QMediaPlayer::NoError, - ResourceError = QMediaPlayer::ResourceError, - FormatError = QMediaPlayer::FormatError, - NetworkError = QMediaPlayer::NetworkError, - AccessDenied = QMediaPlayer::AccessDeniedError, - ServiceMissing = QMediaPlayer::ServiceMissingError - }; - - QDeclarativeAudio(QObject *parent = 0); - ~QDeclarativeAudio(); - - Status status() const; - Error error() const; - -public Q_SLOTS: - void play(); - void pause(); - void stop(); - -Q_SIGNALS: - void sourceChanged(); - - void playingChanged(); - void pausedChanged(); - - void started(); - void resumed(); - void paused(); - void stopped(); - - void statusChanged(); - - void loaded(); - void buffering(); - void stalled(); - void buffered(); - void endOfMedia(); - - void durationChanged(); - void positionChanged(); - - void volumeChanged(); - void mutedChanged(); - - void bufferProgressChanged(); - - void seekableChanged(); - void playbackRateChanged(); - - void errorChanged(); - void error(QDeclarativeAudio::Error error, const QString &errorString); - -private Q_SLOTS: - void _q_error(int, const QString &); - -private: - Q_DISABLE_COPY(QDeclarativeAudio) - Q_PRIVATE_SLOT(mediaBase(), void _q_stateChanged(QMediaPlayer::State)) - Q_PRIVATE_SLOT(mediaBase(), void _q_mediaStatusChanged(QMediaPlayer::MediaStatus)) - Q_PRIVATE_SLOT(mediaBase(), void _q_metaDataChanged()) - - inline QDeclarativeMediaBase *mediaBase() { return this; } -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QT_PREPEND_NAMESPACE(QDeclarativeAudio)) - -QT_END_HEADER - -#endif diff --git a/src/plugins/qdeclarativemodules/multimedia/qdeclarativemediabase.cpp b/src/plugins/qdeclarativemodules/multimedia/qdeclarativemediabase.cpp deleted file mode 100644 index 8e87e44..0000000 --- a/src/plugins/qdeclarativemodules/multimedia/qdeclarativemediabase.cpp +++ /dev/null @@ -1,413 +0,0 @@ -/**************************************************************************** -** -** 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 "qdeclarativemediabase_p.h" - -#include -#include - -#include -#include -#include -#include -#include "qmetadatacontrolmetaobject_p.h" - - - -QT_BEGIN_NAMESPACE - - -class QDeclarativeMediaBaseObject : public QMediaObject -{ -public: - QDeclarativeMediaBaseObject(QMediaService *service) - : QMediaObject(0, service) - { - } -}; - -class QDeclarativeMediaBasePlayerControl : public QMediaPlayerControl -{ -public: - QDeclarativeMediaBasePlayerControl(QObject *parent) - : QMediaPlayerControl(parent) - { - } - - QMediaPlayer::State state() const { return QMediaPlayer::StoppedState; } - QMediaPlayer::MediaStatus mediaStatus() const { return QMediaPlayer::NoMedia; } - - qint64 duration() const { return 0; } - qint64 position() const { return 0; } - void setPosition(qint64) {} - int volume() const { return 0; } - void setVolume(int) {} - bool isMuted() const { return false; } - void setMuted(bool) {} - int bufferStatus() const { return 0; } - bool isAudioAvailable() const { return false; } - bool isVideoAvailable() const { return false; } - bool isSeekable() const { return false; } - QMediaTimeRange availablePlaybackRanges() const { return QMediaTimeRange(); } - qreal playbackRate() const { return 1; } - void setPlaybackRate(qreal) {} - QMediaContent media() const { return QMediaContent(); } - const QIODevice *mediaStream() const { return 0; } - void setMedia(const QMediaContent &, QIODevice *) {} - - void play() {} - void pause() {} - void stop() {} -}; - -class QDeclarativeMediaBaseAnimation : public QObject -{ -public: - QDeclarativeMediaBaseAnimation(QDeclarativeMediaBase *media) - : m_media(media) - { - } - - void start() { if (!m_timer.isActive()) m_timer.start(500, this); } - void stop() { m_timer.stop(); } - -protected: - void timerEvent(QTimerEvent *event) - { - if (event->timerId() == m_timer.timerId()) { - event->accept(); - - if (m_media->m_state == QMediaPlayer::PlayingState) - emit m_media->positionChanged(); - if (m_media->m_status == QMediaPlayer::BufferingMedia || QMediaPlayer::StalledMedia) - emit m_media->bufferProgressChanged(); - } else { - QObject::timerEvent(event); - } - } - -private: - QDeclarativeMediaBase *m_media; - QBasicTimer m_timer; -}; - -void QDeclarativeMediaBase::_q_stateChanged(QMediaPlayer::State state) -{ - if (state != m_state) { - QMediaPlayer::State oldState = m_state; - - m_state = state; - - if (state == QMediaPlayer::StoppedState) { - emit stopped(); - emit playingChanged(); - } else if (oldState == QMediaPlayer::StoppedState) { - emit started(); - emit playingChanged(); - } else if (oldState == QMediaPlayer::PausedState) { - m_paused = false; - - emit resumed(); - emit pausedChanged(); - } - - if (state == m_state && state == QMediaPlayer::PausedState) { - bool wasPaused = m_paused; - - m_paused = true; - - emit paused(); - - if (!wasPaused) - emit pausedChanged(); - } - - if (m_state == QMediaPlayer::PlayingState - || m_status == QMediaPlayer::BufferingMedia - || m_status == QMediaPlayer::StalledMedia) { - m_animation->start(); - } else { - m_animation->stop(); - } - } -} - -void QDeclarativeMediaBase::_q_mediaStatusChanged(QMediaPlayer::MediaStatus status) -{ - if (status != m_status) { - m_status = status; - - switch (status) { - case QMediaPlayer::LoadedMedia: - emit loaded(); - break; - case QMediaPlayer::BufferingMedia: - emit buffering(); - break; - case QMediaPlayer::BufferedMedia: - emit buffered(); - break; - case QMediaPlayer::StalledMedia: - emit stalled(); - break; - case QMediaPlayer::EndOfMedia: - emit endOfMedia(); - break; - default: - break; - } - - emit statusChanged(); - - if (m_state == QMediaPlayer::PlayingState - || m_status == QMediaPlayer::BufferingMedia - || m_status == QMediaPlayer::StalledMedia) { - m_animation->start(); - } else { - m_animation->stop(); - } - } -} - -void QDeclarativeMediaBase::_q_metaDataChanged() -{ - m_metaObject->metaDataChanged(); -} - -QDeclarativeMediaBase::QDeclarativeMediaBase() - : m_mediaService(0) - , m_playerControl(0) - , m_mediaObject(0) - , m_mediaProvider(0) - , m_metaDataControl(0) - , m_metaObject(0) - , m_animation(0) - , m_state(QMediaPlayer::StoppedState) - , m_status(QMediaPlayer::NoMedia) - , m_error(QMediaPlayer::NoError) - , m_paused(false) -{ -} - -QDeclarativeMediaBase::~QDeclarativeMediaBase() -{ -} - -void QDeclarativeMediaBase::shutdown() -{ - delete m_metaObject; - delete m_mediaObject; - - if (m_mediaProvider) - m_mediaProvider->releaseService(m_mediaService); - - delete m_animation; - -} - -void QDeclarativeMediaBase::setObject(QObject *object) -{ - if ((m_mediaProvider = QMediaServiceProvider::defaultServiceProvider())) { - if ((m_mediaService = m_mediaProvider->requestService(Q_MEDIASERVICE_MEDIAPLAYER))) { - m_playerControl = qobject_cast( - m_mediaService->control(QMediaPlayerControl_iid)); - m_metaDataControl = qobject_cast( - m_mediaService->control(QMetaDataControl_iid)); - m_mediaObject = new QDeclarativeMediaBaseObject(m_mediaService); - } - } - - if (m_playerControl) { - QObject::connect(m_playerControl, SIGNAL(stateChanged(QMediaPlayer::State)), - object, SLOT(_q_stateChanged(QMediaPlayer::State))); - QObject::connect(m_playerControl, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)), - object, SLOT(_q_mediaStatusChanged(QMediaPlayer::MediaStatus))); - QObject::connect(m_playerControl, SIGNAL(mediaChanged(QMediaContent)), - object, SIGNAL(sourceChanged())); - QObject::connect(m_playerControl, SIGNAL(durationChanged(qint64)), - object, SIGNAL(durationChanged())); - QObject::connect(m_playerControl, SIGNAL(positionChanged(qint64)), - object, SIGNAL(positionChanged())); - QObject::connect(m_playerControl, SIGNAL(volumeChanged(int)), - object, SIGNAL(volumeChanged())); - QObject::connect(m_playerControl, SIGNAL(mutedChanged(bool)), - object, SIGNAL(mutedChanged())); - QObject::connect(m_playerControl, SIGNAL(bufferStatusChanged(int)), - object, SIGNAL(bufferProgressChanged())); - QObject::connect(m_playerControl, SIGNAL(seekableChanged(bool)), - object, SIGNAL(seekableChanged())); - QObject::connect(m_playerControl, SIGNAL(playbackRateChanged(qreal)), - object, SIGNAL(playbackRateChanged())); - QObject::connect(m_playerControl, SIGNAL(error(int,QString)), - object, SLOT(_q_error(int,QString))); - - m_animation = new QDeclarativeMediaBaseAnimation(this); - } else { - m_error = QMediaPlayer::ServiceMissingError; - - m_playerControl = new QDeclarativeMediaBasePlayerControl(object); - } - - if (m_metaDataControl) { - m_metaObject = new QMetaDataControlMetaObject(m_metaDataControl, object); - - QObject::connect(m_metaDataControl, SIGNAL(metaDataChanged()), - object, SLOT(_q_metaDataChanged())); - } -} - -QUrl QDeclarativeMediaBase::source() const -{ - return m_playerControl->media().canonicalUrl(); -} - -void QDeclarativeMediaBase::setSource(const QUrl &url) -{ - if (m_error != QMediaPlayer::ServiceMissingError && m_error != QMediaPlayer::NoError) { - m_error = QMediaPlayer::NoError; - m_errorString = QString(); - - emit errorChanged(); - } - - m_playerControl->setMedia(QMediaContent(url), 0); -} - -bool QDeclarativeMediaBase::isPlaying() const -{ - return m_state != QMediaPlayer::StoppedState; -} - -void QDeclarativeMediaBase::setPlaying(bool playing) -{ - if (playing && m_state == QMediaPlayer::StoppedState) { - if (m_paused) - m_playerControl->pause(); - else - m_playerControl->play(); - } else if (!playing) { - m_playerControl->stop(); - } -} - -bool QDeclarativeMediaBase::isPaused() const -{ - return m_paused; -} - -void QDeclarativeMediaBase::setPaused(bool paused) -{ - if (m_paused != paused) { - if (paused && m_state == QMediaPlayer::PlayingState) { - m_playerControl->pause(); - } else if (!paused && m_state == QMediaPlayer::PausedState) { - m_playerControl->play(); - } else { - m_paused = paused; - - emit pausedChanged(); - } - } -} - -int QDeclarativeMediaBase::duration() const -{ - return m_playerControl->duration(); -} - -int QDeclarativeMediaBase::position() const -{ - return m_playerControl->position(); - -} - -void QDeclarativeMediaBase::setPosition(int position) -{ - m_playerControl->setPosition(position); -} - -qreal QDeclarativeMediaBase::volume() const -{ - return qreal(m_playerControl->volume()) / 100; -} - -void QDeclarativeMediaBase::setVolume(qreal volume) -{ - m_playerControl->setVolume(qRound(volume * 100)); -} - -bool QDeclarativeMediaBase::isMuted() const -{ - return m_playerControl->isMuted(); -} - -void QDeclarativeMediaBase::setMuted(bool muted) -{ - m_playerControl->setMuted(muted); -} - -qreal QDeclarativeMediaBase::bufferProgress() const -{ - return qreal(m_playerControl->bufferStatus()) / 100; -} - -bool QDeclarativeMediaBase::isSeekable() const -{ - return m_playerControl->isSeekable(); -} - -qreal QDeclarativeMediaBase::playbackRate() const -{ - return m_playerControl->playbackRate(); -} - -void QDeclarativeMediaBase::setPlaybackRate(qreal rate) -{ - m_playerControl->setPlaybackRate(rate); -} - -QString QDeclarativeMediaBase::errorString() const -{ - return m_errorString; -} - -QT_END_NAMESPACE - diff --git a/src/plugins/qdeclarativemodules/multimedia/qdeclarativemediabase_p.h b/src/plugins/qdeclarativemodules/multimedia/qdeclarativemediabase_p.h deleted file mode 100644 index b40e84e..0000000 --- a/src/plugins/qdeclarativemodules/multimedia/qdeclarativemediabase_p.h +++ /dev/null @@ -1,168 +0,0 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ - -#ifndef QDECLARATIVEMEDIABASE_P_H -#define QDECLARATIVEMEDIABASE_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists for the convenience -// of other Qt classes. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -class QMediaPlayerControl; -class QMediaService; -class QMediaServiceProvider; -class QMetaDataControl; -class QMetaDataControlMetaObject; -class QDeclarativeMediaBaseAnimation; - -class QDeclarativeMediaBase -{ -public: - QDeclarativeMediaBase(); - virtual ~QDeclarativeMediaBase(); - - QUrl source() const; - void setSource(const QUrl &url); - - bool isPlaying() const; - void setPlaying(bool playing); - - bool isPaused() const; - void setPaused(bool paused); - - int duration() const; - - int position() const; - void setPosition(int position); - - qreal volume() const; - void setVolume(qreal volume); - - bool isMuted() const; - void setMuted(bool muted); - - qreal bufferProgress() const; - - bool isSeekable() const; - - qreal playbackRate() const; - void setPlaybackRate(qreal rate); - - QString errorString() const; - - void _q_stateChanged(QMediaPlayer::State state); - void _q_mediaStatusChanged(QMediaPlayer::MediaStatus status); - - void _q_metaDataChanged(); - -protected: - void shutdown(); - - void setObject(QObject *object); - - virtual void sourceChanged() = 0; - - virtual void playingChanged() = 0; - virtual void pausedChanged() = 0; - - virtual void started() = 0; - virtual void resumed() = 0; - virtual void paused() = 0; - virtual void stopped() = 0; - - virtual void statusChanged() = 0; - - virtual void loaded() = 0; - virtual void buffering() = 0; - virtual void stalled() = 0; - virtual void buffered() = 0; - virtual void endOfMedia() = 0; - - virtual void durationChanged() = 0; - virtual void positionChanged() = 0; - - virtual void volumeChanged() = 0; - virtual void mutedChanged() = 0; - - virtual void bufferProgressChanged() = 0; - - virtual void seekableChanged() = 0; - virtual void playbackRateChanged() = 0; - - virtual void errorChanged() = 0; - - QMediaService *m_mediaService; - QMediaPlayerControl *m_playerControl; - - QMediaObject *m_mediaObject; - QMediaServiceProvider *m_mediaProvider; - QMetaDataControl *m_metaDataControl; - QMetaDataControlMetaObject *m_metaObject; - QDeclarativeMediaBaseAnimation *m_animation; - - QMediaPlayer::State m_state; - QMediaPlayer::MediaStatus m_status; - QMediaPlayer::Error m_error; - bool m_paused; - QString m_errorString; - - friend class QDeclarativeMediaBaseAnimation; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif diff --git a/src/plugins/qdeclarativemodules/multimedia/qdeclarativevideo.cpp b/src/plugins/qdeclarativemodules/multimedia/qdeclarativevideo.cpp deleted file mode 100644 index 064f242..0000000 --- a/src/plugins/qdeclarativemodules/multimedia/qdeclarativevideo.cpp +++ /dev/null @@ -1,945 +0,0 @@ -/**************************************************************************** -** -** 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 "qdeclarativevideo_p.h" - -#include -#include -#include -#include -#include - - -QT_BEGIN_NAMESPACE - - -void QDeclarativeVideo::_q_nativeSizeChanged(const QSizeF &size) -{ - setImplicitWidth(size.width()); - setImplicitHeight(size.height()); -} - -void QDeclarativeVideo::_q_error(int errorCode, const QString &errorString) -{ - m_error = QMediaPlayer::Error(errorCode); - m_errorString = errorString; - - emit error(Error(errorCode), errorString); - emit errorChanged(); -} - - -/*! - \qmlclass Video QDeclarativeVideo - \since 4.7 - \brief The Video element allows you to add videos to a scene. - \inherits Item - - \qml - Video { source: "video/movie.mpg" } - \endqml - - The video item supports untransformed, stretched, and uniformly scaled video presentation. - For a description of stretched uniformly scaled presentation, see the \l fillMode property - description. - - The video item is only visible when the \l hasVideo property is true and the video is playing. - - \sa Audio -*/ - -/*! - \internal - \class QDeclarativeVideo - \brief The QDeclarativeVideo class provides a video item that you can add to a QDeclarativeView. -*/ - -QDeclarativeVideo::QDeclarativeVideo(QDeclarativeItem *parent) - : QDeclarativeItem(parent) - , m_graphicsItem(0) - -{ - m_graphicsItem = new QGraphicsVideoItem(this); - connect(m_graphicsItem, SIGNAL(nativeSizeChanged(QSizeF)), - this, SLOT(_q_nativeSizeChanged(QSizeF))); - - setObject(this); - - if (m_mediaService) { - connect(m_playerControl, SIGNAL(audioAvailableChanged(bool)), - this, SIGNAL(hasAudioChanged())); - connect(m_playerControl, SIGNAL(videoAvailableChanged(bool)), - this, SIGNAL(hasVideoChanged())); - - m_graphicsItem->setMediaObject(m_mediaObject); - } -} - -QDeclarativeVideo::~QDeclarativeVideo() -{ - shutdown(); - - delete m_graphicsItem; -} - -/*! - \qmlproperty url Video::source - - This property holds the source URL of the media. -*/ - -/*! - \qmlproperty bool Video::playing - - This property holds whether the media is playing. - - Defaults to false, and can be set to true to start playback. -*/ - -/*! - \qmlproperty bool Video::paused - - This property holds whether the media is paused. - - Defaults to false, and can be set to true to pause playback. -*/ - -/*! - \qmlsignal Video::onStarted() - - This handler is called when playback is started. -*/ - -/*! - \qmlsignal Video::onResumed() - - This handler is called when playback is resumed from the paused state. -*/ - -/*! - \qmlsignal Video::onPaused() - - This handler is called when playback is paused. -*/ - -/*! - \qmlsignal Video::onStopped() - - This handler is called when playback is stopped. -*/ - -/*! - \qmlproperty enum Video::status - - This property holds the status of media loading. It can be one of: - - \list - \o NoMedia - no media has been set. - \o Loading - the media is currently being loaded. - \o Loaded - the media has been loaded. - \o Buffering - the media is buffering data. - \o Stalled - playback has been interrupted while the media is buffering data. - \o Buffered - the media has buffered data. - \o EndOfMedia - the media has played to the end. - \o InvalidMedia - the media cannot be played. - \o UnknownStatus - the status of the media is cannot be determined. - \endlist -*/ - -QDeclarativeVideo::Status QDeclarativeVideo::status() const -{ - return Status(m_status); -} - -/*! - \qmlsignal Video::onLoaded() - - This handler is called when the media source has been loaded. -*/ - -/*! - \qmlsignal Video::onBuffering() - - This handler is called when the media starts buffering. -*/ - -/*! - \qmlsignal Video::onStalled() - - This handler is called when playback has stalled while the media buffers. -*/ - -/*! - \qmlsignal Video::onBuffered() - - This handler is called when the media has finished buffering. -*/ - -/*! - \qmlsignal Video::onEndOfMedia() - - This handler is called when playback stops because end of the media has been reached. -*/ - -/*! - \qmlproperty int Video::duration - - This property holds the duration of the media in milliseconds. - - If the media doesn't have a fixed duration (a live stream for example) this will be 0. -*/ - -/*! - \qmlproperty int Video::position - - This property holds the current playback position in milliseconds. -*/ - -/*! - \qmlproperty qreal Video::volume - - This property holds the volume of the audio output, from 0.0 (silent) to 1.0 (maximum volume). -*/ - -/*! - \qmlproperty bool Video::muted - - This property holds whether the audio output is muted. -*/ - -/*! - \qmlproperty bool Video::hasAudio - - This property holds whether the media contains audio. -*/ - -bool QDeclarativeVideo::hasAudio() const -{ - return m_playerControl->isAudioAvailable(); -} - -/*! - \qmlproperty bool Video::hasVideo - - This property holds whether the media contains video. -*/ - -bool QDeclarativeVideo::hasVideo() const -{ - return m_playerControl->isVideoAvailable(); -} - -/*! - \qmlproperty qreal Video::bufferProgress - - This property holds how much of the data buffer is currently filled, from 0.0 (empty) to 1.0 - (full). -*/ - -/*! - \qmlproperty bool Video::seekable - - This property holds whether position of the video can be changed. -*/ - -/*! - \qmlproperty qreal Video::playbackRate - - This property holds the rate at which video is played at as a multiple of the normal rate. -*/ - -/*! - \qmlproperty enum Video::error - - This property holds the error state of the video. It can be one of: - - \list - \o NoError - there is no current error. - \o ResourceError - the video cannot be played due to a problem allocating resources. - \o FormatError - the video format is not supported. - \o NetworkError - the video cannot be played due to network issues. - \o AccessDenied - the video cannot be played due to insufficient permissions. - \o ServiceMissing - the video cannot be played because the media service could not be - instantiated. - \endlist -*/ - - -QDeclarativeVideo::Error QDeclarativeVideo::error() const -{ - return Error(m_error); -} - -/*! - \qmlproperty string Video::errorString - - This property holds a string describing the current error condition in more detail. -*/ - -/*! - \qmlsignal Video::onError(error, errorString) - - This handler is called when an \l {Error}{error} has occurred. The errorString parameter - may contain more detailed information about the error. -*/ - -/*! - \qmlproperty enum Video::fillMode - - Set this property to define how the video is scaled to fit the target area. - - \list - \o Stretch - the video is scaled to fit. - \o PreserveAspectFit - the video is scaled uniformly to fit without cropping - \o PreserveAspectCrop - the video is scaled uniformly to fill, cropping if necessary - \endlist - - The default fill mode is PreserveAspectFit. -*/ - -QDeclarativeVideo::FillMode QDeclarativeVideo::fillMode() const -{ - return FillMode(m_graphicsItem->aspectRatioMode()); -} - -void QDeclarativeVideo::setFillMode(FillMode mode) -{ - m_graphicsItem->setAspectRatioMode(Qt::AspectRatioMode(mode)); -} - -/*! - \qmlmethod Video::play() - - Starts playback of the media. - - Sets the \l playing property to true, and the \l paused property to false. -*/ - -void QDeclarativeVideo::play() -{ - m_playerControl->play(); - - if (m_paused) { - m_paused = false; - emit pausedChanged(); - } -} - -/*! - \qmlmethod Video::pause() - - Pauses playback of the media. - - Sets the \l playing and \l paused properties to true. -*/ - -void QDeclarativeVideo::pause() -{ - m_playerControl->pause(); - - if (!m_paused && m_state == QMediaPlayer::PausedState) { - m_paused = true; - emit pausedChanged(); - } -} - -/*! - \qmlmethod Video::stop() - - Stops playback of the media. - - Sets the \l playing and \l paused properties to false. -*/ - -void QDeclarativeVideo::stop() -{ - m_playerControl->stop(); - - if (m_paused) { - m_paused = false; - emit pausedChanged(); - } -} - -void QDeclarativeVideo::paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) -{ -} - -void QDeclarativeVideo::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) -{ - m_graphicsItem->setSize(newGeometry.size()); - - QDeclarativeItem::geometryChanged(newGeometry, oldGeometry); -} - -QT_END_NAMESPACE - -// *************************************** -// Documentation for meta-data properties. -// *************************************** - -/*! - \qmlproperty variant Video::title - - This property holds the tile of the media. - - \sa {QtMultimedia::Title} -*/ - -/*! - \qmlproperty variant Video::subTitle - - This property holds the sub-title of the media. - - \sa {QtMultimedia::SubTitle} -*/ - -/*! - \qmlproperty variant Video::author - - This property holds the author of the media. - - \sa {QtMultimedia::Author} -*/ - -/*! - \qmlproperty variant Video::comment - - This property holds a user comment about the media. - - \sa {QtMultimedia::Comment} -*/ - -/*! - \qmlproperty variant Video::description - - This property holds a description of the media. - - \sa {QtMultimedia::Description} -*/ - -/*! - \qmlproperty variant Video::category - - This property holds the category of the media - - \sa {QtMultimedia::Category} -*/ - -/*! - \qmlproperty variant Video::genre - - This property holds the genre of the media. - - \sa {QtMultimedia::Genre} -*/ - -/*! - \qmlproperty variant Video::year - - This property holds the year of release of the media. - - \sa {QtMultimedia::Year} -*/ - -/*! - \qmlproperty variant Video::date - - This property holds the date of the media. - - \sa {QtMultimedia::Date} -*/ - -/*! - \qmlproperty variant Video::userRating - - This property holds a user rating of the media in the range of 0 to 100. - - \sa {QtMultimedia::UserRating} -*/ - -/*! - \qmlproperty variant Video::keywords - - This property holds a list of keywords describing the media. - - \sa {QtMultimedia::Keywords} -*/ - -/*! - \qmlproperty variant Video::language - - This property holds the language of the media, as an ISO 639-2 code. - - \sa {QtMultimedia::Language} -*/ - -/*! - \qmlproperty variant Video::publisher - - This property holds the publisher of the media. - - \sa {QtMultimedia::Publisher} -*/ - -/*! - \qmlproperty variant Video::copyright - - This property holds the media's copyright notice. - - \sa {QtMultimedia::Copyright} -*/ - -/*! - \qmlproperty variant Video::parentalRating - - This property holds the parental rating of the media. - - \sa {QtMultimedia::ParentalRating} -*/ - -/*! - \qmlproperty variant Video::ratingOrganisation - - This property holds the name of the rating organisation responsible for the - parental rating of the media. - - \sa {QtMultimedia::RatingOrganisation} -*/ - -/*! - \qmlproperty variant Video::size - - This property property holds the size of the media in bytes. - - \sa {QtMultimedia::Size} -*/ - -/*! - \qmlproperty variant Video::mediaType - - This property holds the type of the media. - - \sa {QtMultimedia::MediaType} -*/ - -/*! - \qmlproperty variant Video::audioBitRate - - This property holds the bit rate of the media's audio stream ni bits per - second. - - \sa {QtMultimedia::AudioBitRate} -*/ - -/*! - \qmlproperty variant Video::audioCodec - - This property holds the encoding of the media audio stream. - - \sa {QtMultimedia::AudioCodec} -*/ - -/*! - \qmlproperty variant Video::averageLevel - - This property holds the average volume level of the media. - - \sa {QtMultimedia::AverageLevel} -*/ - -/*! - \qmlproperty variant Video::channelCount - - This property holds the number of channels in the media's audio stream. - - \sa {QtMultimedia::ChannelCount} -*/ - -/*! - \qmlproperty variant Video::peakValue - - This property holds the peak volume of media's audio stream. - - \sa {QtMultimedia::PeakValue} -*/ - -/*! - \qmlproperty variant Video::sampleRate - - This property holds the sample rate of the media's audio stream in hertz. - - \sa {QtMultimedia::SampleRate} -*/ - -/*! - \qmlproperty variant Video::albumTitle - - This property holds the title of the album the media belongs to. - - \sa {QtMultimedia::AlbumTitle} -*/ - -/*! - \qmlproperty variant Video::albumArtist - - This property holds the name of the principal artist of the album the media - belongs to. - - \sa {QtMultimedia::AlbumArtist} -*/ - -/*! - \qmlproperty variant Video::contributingArtist - - This property holds the names of artists contributing to the media. - - \sa {QtMultimedia::ContributingArtist} -*/ - -/*! - \qmlproperty variant Video::composer - - This property holds the composer of the media. - - \sa {QtMultimedia::Composer} -*/ - -/*! - \qmlproperty variant Video::conductor - - This property holds the conductor of the media. - - \sa {QtMultimedia::Conductor} -*/ - -/*! - \qmlproperty variant Video::lyrics - - This property holds the lyrics to the media. - - \sa {QtMultimedia::Lyrics} -*/ - -/*! - \qmlproperty variant Video::mood - - This property holds the mood of the media. - - \sa {QtMultimedia::Mood} -*/ - -/*! - \qmlproperty variant Video::trackNumber - - This property holds the track number of the media. - - \sa {QtMultimedia::TrackNumber} -*/ - -/*! - \qmlproperty variant Video::trackCount - - This property holds the number of track on the album containing the media. - - \sa {QtMultimedia::TrackNumber} -*/ - -/*! - \qmlproperty variant Video::coverArtUrlSmall - - This property holds the URL of a small cover art image. - - \sa {QtMultimedia::CoverArtUrlSmall} -*/ - -/*! - \qmlproperty variant Video::coverArtUrlLarge - - This property holds the URL of a large cover art image. - - \sa {QtMultimedia::CoverArtUrlLarge} -*/ - -/*! - \qmlproperty variant Video::resolution - - This property holds the dimension of an image or video. - - \sa {QtMultimedia::Resolution} -*/ - -/*! - \qmlproperty variant Video::pixelAspectRatio - - This property holds the pixel aspect ratio of an image or video. - - \sa {QtMultimedia::PixelAspectRatio} -*/ - -/*! - \qmlproperty variant Video::videoFrameRate - - This property holds the frame rate of the media's video stream. - - \sa {QtMultimedia::VideoFrameRate} -*/ - -/*! - \qmlproperty variant Video::videoBitRate - - This property holds the bit rate of the media's video stream in bits per - second. - - \sa {QtMultimedia::VideoBitRate} -*/ - -/*! - \qmlproperty variant Video::videoCodec - - This property holds the encoding of the media's video stream. - - \sa {QtMultimedia::VideoCodec} -*/ - -/*! - \qmlproperty variant Video::posterUrl - - This property holds the URL of a poster image. - - \sa {QtMultimedia::PosterUrl} -*/ - -/*! - \qmlproperty variant Video::chapterNumber - - This property holds the chapter number of the media. - - \sa {QtMultimedia::ChapterNumber} -*/ - -/*! - \qmlproperty variant Video::director - - This property holds the director of the media. - - \sa {QtMultimedia::Director} -*/ - -/*! - \qmlproperty variant Video::leadPerformer - - This property holds the lead performer in the media. - - \sa {QtMultimedia::LeadPerformer} -*/ - -/*! - \qmlproperty variant Video::writer - - This property holds the writer of the media. - - \sa {QtMultimedia::Writer} -*/ - -// The remaining properties are related to photos, and are technically -// available but will certainly never have values. -#ifndef Q_QDOC - -/*! - \qmlproperty variant Video::cameraManufacturer - - \sa {QtMultimedia::CameraManufacturer} -*/ - -/*! - \qmlproperty variant Video::cameraModel - - \sa {QtMultimedia::CameraModel} -*/ - -/*! - \qmlproperty variant Video::event - - \sa {QtMultimedia::Event} -*/ - -/*! - \qmlproperty variant Video::subject - - \sa {QtMultimedia::Subject} -*/ - -/*! - \qmlproperty variant Video::orientation - - \sa {QtMultimedia::Orientation} -*/ - -/*! - \qmlproperty variant Video::exposureTime - - \sa {QtMultimedia::ExposureTime} -*/ - -/*! - \qmlproperty variant Video::fNumber - - \sa {QtMultimedia::FNumber} -*/ - -/*! - \qmlproperty variant Video::exposureProgram - - \sa {QtMultimedia::ExposureProgram} -*/ - -/*! - \qmlproperty variant Video::isoSpeedRatings - - \sa {QtMultimedia::ISOSpeedRatings} -*/ - -/*! - \qmlproperty variant Video::exposureBiasValue - - \sa {QtMultimedia::ExposureBiasValue} -*/ - -/*! - \qmlproperty variant Video::dateTimeDigitized - - \sa {QtMultimedia::DateTimeDigitized} -*/ - -/*! - \qmlproperty variant Video::subjectDistance - - \sa {QtMultimedia::SubjectDistance} -*/ - -/*! - \qmlproperty variant Video::meteringMode - - \sa {QtMultimedia::MeteringMode} -*/ - -/*! - \qmlproperty variant Video::lightSource - - \sa {QtMultimedia::LightSource} -*/ - -/*! - \qmlproperty variant Video::flash - - \sa {QtMultimedia::Flash} -*/ - -/*! - \qmlproperty variant Video::focalLength - - \sa {QtMultimedia::FocalLength} -*/ - -/*! - \qmlproperty variant Video::exposureMode - - \sa {QtMultimedia::ExposureMode} -*/ - -/*! - \qmlproperty variant Video::whiteBalance - - \sa {QtMultimedia::WhiteBalance} -*/ - -/*! - \qmlproperty variant Video::DigitalZoomRatio - - \sa {QtMultimedia::DigitalZoomRatio} -*/ - -/*! - \qmlproperty variant Video::focalLengthIn35mmFilm - - \sa {QtMultimedia::FocalLengthIn35mmFile} -*/ - -/*! - \qmlproperty variant Video::sceneCaptureType - - \sa {QtMultimedia::SceneCaptureType} -*/ - -/*! - \qmlproperty variant Video::gainControl - - \sa {QtMultimedia::GainControl} -*/ - -/*! - \qmlproperty variant Video::contrast - - \sa {QtMultimedia::contrast} -*/ - -/*! - \qmlproperty variant Video::saturation - - \sa {QtMultimedia::Saturation} -*/ - -/*! - \qmlproperty variant Video::sharpness - - \sa {QtMultimedia::Sharpness} -*/ - -/*! - \qmlproperty variant Video::deviceSettingDescription - - \sa {QtMultimedia::DeviceSettingDescription} -*/ - -#endif - -#include "moc_qdeclarativevideo_p.cpp" diff --git a/src/plugins/qdeclarativemodules/multimedia/qdeclarativevideo_p.h b/src/plugins/qdeclarativemodules/multimedia/qdeclarativevideo_p.h deleted file mode 100644 index fb13519..0000000 --- a/src/plugins/qdeclarativemodules/multimedia/qdeclarativevideo_p.h +++ /dev/null @@ -1,204 +0,0 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ - -#ifndef QDECLARATIVEVIDEO_H -#define QDECLARATIVEVIDEO_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists for the convenience -// of other Qt classes. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include "qdeclarativemediabase_p.h" - -#include - -#include -#include - - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -class QTimerEvent; -class QVideoSurfaceFormat; - - -class QDeclarativeVideo : public QDeclarativeItem, public QDeclarativeMediaBase -{ - Q_OBJECT - Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) - Q_PROPERTY(bool playing READ isPlaying WRITE setPlaying NOTIFY playingChanged) - Q_PROPERTY(bool paused READ isPaused WRITE setPaused NOTIFY pausedChanged) - Q_PROPERTY(Status status READ status NOTIFY statusChanged) - Q_PROPERTY(int duration READ duration NOTIFY durationChanged) - Q_PROPERTY(int position READ position WRITE setPosition NOTIFY positionChanged) - Q_PROPERTY(qreal volume READ volume WRITE setVolume NOTIFY volumeChanged) - Q_PROPERTY(bool muted READ isMuted WRITE setMuted NOTIFY mutedChanged) - Q_PROPERTY(bool hasAudio READ hasAudio NOTIFY hasAudioChanged) - Q_PROPERTY(bool hasVideo READ hasVideo NOTIFY hasVideoChanged) - Q_PROPERTY(int bufferProgress READ bufferProgress NOTIFY bufferProgressChanged) - Q_PROPERTY(bool seekable READ isSeekable NOTIFY seekableChanged) - Q_PROPERTY(qreal playbackRate READ playbackRate WRITE setPlaybackRate NOTIFY playbackRateChanged) - Q_PROPERTY(Error error READ error NOTIFY errorChanged) - Q_PROPERTY(QString errorString READ errorString NOTIFY errorChanged) - Q_PROPERTY(FillMode fillMode READ fillMode WRITE setFillMode) - Q_ENUMS(FillMode) - Q_ENUMS(Status) - Q_ENUMS(Error) -public: - enum FillMode - { - Stretch = Qt::IgnoreAspectRatio, - PreserveAspectFit = Qt::KeepAspectRatio, - PreserveAspectCrop = Qt::KeepAspectRatioByExpanding - }; - - enum Status - { - UnknownStatus = QMediaPlayer::UnknownMediaStatus, - NoMedia = QMediaPlayer::NoMedia, - Loading = QMediaPlayer::LoadingMedia, - Loaded = QMediaPlayer::LoadedMedia, - Stalled = QMediaPlayer::StalledMedia, - Buffering = QMediaPlayer::BufferingMedia, - Buffered = QMediaPlayer::BufferedMedia, - EndOfMedia = QMediaPlayer::EndOfMedia, - InvalidMedia = QMediaPlayer::InvalidMedia - }; - - enum Error - { - NoError = QMediaPlayer::NoError, - ResourceError = QMediaPlayer::ResourceError, - FormatError = QMediaPlayer::FormatError, - NetworkError = QMediaPlayer::NetworkError, - AccessDenied = QMediaPlayer::AccessDeniedError, - ServiceMissing = QMediaPlayer::ServiceMissingError - }; - - QDeclarativeVideo(QDeclarativeItem *parent = 0); - ~QDeclarativeVideo(); - - bool hasAudio() const; - bool hasVideo() const; - - FillMode fillMode() const; - void setFillMode(FillMode mode); - - Status status() const; - Error error() const; - - void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); - -public Q_SLOTS: - void play(); - void pause(); - void stop(); - -Q_SIGNALS: - void sourceChanged(); - - void playingChanged(); - void pausedChanged(); - - void started(); - void resumed(); - void paused(); - void stopped(); - - void statusChanged(); - - void loaded(); - void buffering(); - void stalled(); - void buffered(); - void endOfMedia(); - - void durationChanged(); - void positionChanged(); - - void volumeChanged(); - void mutedChanged(); - void hasAudioChanged(); - void hasVideoChanged(); - - void bufferProgressChanged(); - - void seekableChanged(); - void playbackRateChanged(); - - void errorChanged(); - void error(QDeclarativeVideo::Error error, const QString &errorString); - -protected: - void geometryChanged(const QRectF &geometry, const QRectF &); - -private Q_SLOTS: - void _q_nativeSizeChanged(const QSizeF &size); - void _q_error(int, const QString &); - -private: - Q_DISABLE_COPY(QDeclarativeVideo) - - QGraphicsVideoItem *m_graphicsItem; - - Q_PRIVATE_SLOT(mediaBase(), void _q_stateChanged(QMediaPlayer::State)) - Q_PRIVATE_SLOT(mediaBase(), void _q_mediaStatusChanged(QMediaPlayer::MediaStatus)) - Q_PRIVATE_SLOT(mediaBase(), void _q_metaDataChanged()) - - inline QDeclarativeMediaBase *mediaBase() { return this; } -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QT_PREPEND_NAMESPACE(QDeclarativeVideo)) - -QT_END_HEADER - -#endif diff --git a/src/plugins/qdeclarativemodules/multimedia/qmetadatacontrolmetaobject.cpp b/src/plugins/qdeclarativemodules/multimedia/qmetadatacontrolmetaobject.cpp deleted file mode 100644 index e90cbd6..0000000 --- a/src/plugins/qdeclarativemodules/multimedia/qmetadatacontrolmetaobject.cpp +++ /dev/null @@ -1,362 +0,0 @@ -/**************************************************************************** -** -** 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 "qmetadatacontrolmetaobject_p.h" -#include - - -QT_BEGIN_NAMESPACE - -// copied from qmetaobject.cpp -// do not touch without touching the moc as well -enum PropertyFlags { - Invalid = 0x00000000, - Readable = 0x00000001, - Writable = 0x00000002, - Resettable = 0x00000004, - EnumOrFlag = 0x00000008, - StdCppSet = 0x00000100, -// Override = 0x00000200, - Designable = 0x00001000, - ResolveDesignable = 0x00002000, - Scriptable = 0x00004000, - ResolveScriptable = 0x00008000, - Stored = 0x00010000, - ResolveStored = 0x00020000, - Editable = 0x00040000, - ResolveEditable = 0x00080000, - User = 0x00100000, - ResolveUser = 0x00200000, - Notify = 0x00400000, - Dynamic = 0x00800000 -}; - -enum MethodFlags { - AccessPrivate = 0x00, - AccessProtected = 0x01, - AccessPublic = 0x02, - AccessMask = 0x03, //mask - - MethodMethod = 0x00, - MethodSignal = 0x04, - MethodSlot = 0x08, - MethodConstructor = 0x0c, - MethodTypeMask = 0x0c, - - MethodCompatibility = 0x10, - MethodCloned = 0x20, - MethodScriptable = 0x40 -}; - -struct QMetaObjectPrivate -{ - int revision; - int className; - int classInfoCount, classInfoData; - int methodCount, methodData; - int propertyCount, propertyData; - int enumeratorCount, enumeratorData; - int constructorCount, constructorData; - int flags; -}; - -static inline const QMetaObjectPrivate *priv(const uint* m_data) -{ return reinterpret_cast(m_data); } -// end of copied lines from qmetaobject.cpp - -namespace -{ - struct MetaDataKey - { - QtMultimedia::MetaData key; - const char *name; - }; - - const MetaDataKey qt_metaDataKeys[] = - { - { QtMultimedia::Title, "title" }, - { QtMultimedia::SubTitle, "subTitle" }, - { QtMultimedia::Author, "author" }, - { QtMultimedia::Comment, "comment" }, - { QtMultimedia::Description, "description" }, - { QtMultimedia::Category, "category" }, - { QtMultimedia::Genre, "genre" }, - { QtMultimedia::Year, "year" }, - { QtMultimedia::Date, "date" }, - { QtMultimedia::UserRating, "userRating" }, - { QtMultimedia::Keywords, "keywords" }, - { QtMultimedia::Language, "language" }, - { QtMultimedia::Publisher, "publisher" }, - { QtMultimedia::Copyright, "copyright" }, - { QtMultimedia::ParentalRating, "parentalRating" }, - { QtMultimedia::RatingOrganisation, "ratingOrganisation" }, - - // Media - { QtMultimedia::Size, "size" }, - { QtMultimedia::MediaType, "mediaType" }, -// { QtMultimedia::Duration, "duration" }, - - // Audio - { QtMultimedia::AudioBitRate, "audioBitRate" }, - { QtMultimedia::AudioCodec, "audioCodec" }, - { QtMultimedia::AverageLevel, "averageLevel" }, - { QtMultimedia::ChannelCount, "channelCount" }, - { QtMultimedia::PeakValue, "peakValue" }, - { QtMultimedia::SampleRate, "sampleRate" }, - - // Music - { QtMultimedia::AlbumTitle, "albumTitle" }, - { QtMultimedia::AlbumArtist, "albumArtist" }, - { QtMultimedia::ContributingArtist, "contributingArtist" }, - { QtMultimedia::Composer, "composer" }, - { QtMultimedia::Conductor, "conductor" }, - { QtMultimedia::Lyrics, "lyrics" }, - { QtMultimedia::Mood, "mood" }, - { QtMultimedia::TrackNumber, "trackNumber" }, - { QtMultimedia::TrackCount, "trackCount" }, - - { QtMultimedia::CoverArtUrlSmall, "coverArtUrlSmall" }, - { QtMultimedia::CoverArtUrlLarge, "coverArtUrlLarge" }, - - // Image/Video - { QtMultimedia::Resolution, "resolution" }, - { QtMultimedia::PixelAspectRatio, "pixelAspectRatio" }, - - // Video - { QtMultimedia::VideoFrameRate, "videoFrameRate" }, - { QtMultimedia::VideoBitRate, "videoBitRate" }, - { QtMultimedia::VideoCodec, "videoCodec" }, - - { QtMultimedia::PosterUrl, "posterUrl" }, - - // Movie - { QtMultimedia::ChapterNumber, "chapterNumber" }, - { QtMultimedia::Director, "director" }, - { QtMultimedia::LeadPerformer, "leadPerformer" }, - { QtMultimedia::Writer, "writer" }, - - // Photos - { QtMultimedia::CameraManufacturer, "cameraManufacturer" }, - { QtMultimedia::CameraModel, "cameraModel" }, - { QtMultimedia::Event, "event" }, - { QtMultimedia::Subject, "subject" }, - { QtMultimedia::Orientation, "orientation" }, - { QtMultimedia::ExposureTime, "exposureTime" }, - { QtMultimedia::FNumber, "fNumber" }, - { QtMultimedia::ExposureProgram, "exposureProgram" }, - { QtMultimedia::ISOSpeedRatings, "isoSpeedRatings" }, - { QtMultimedia::ExposureBiasValue, "exposureBiasValue" }, - { QtMultimedia::DateTimeOriginal, "dateTimeOriginal" }, - { QtMultimedia::DateTimeDigitized, "dateTimeDigitized" }, - { QtMultimedia::SubjectDistance, "subjectDistance" }, - { QtMultimedia::MeteringMode, "meteringMode" }, - { QtMultimedia::LightSource, "lightSource" }, - { QtMultimedia::Flash, "flash" }, - { QtMultimedia::FocalLength, "focalLength" }, - { QtMultimedia::ExposureMode, "exposureMode" }, - { QtMultimedia::WhiteBalance, "whiteBalance" }, - { QtMultimedia::DigitalZoomRatio, "digitalZoomRatio" }, - { QtMultimedia::FocalLengthIn35mmFilm, "focalLengthIn35mmFilm" }, - { QtMultimedia::SceneCaptureType, "sceneCaptureType" }, - { QtMultimedia::GainControl, "gainControl" }, - { QtMultimedia::Contrast, "contrast" }, - { QtMultimedia::Saturation, "saturation" }, - { QtMultimedia::Sharpness, "sharpness" }, - { QtMultimedia::DeviceSettingDescription, "deviceSettingDescription" } - }; - - class QMetaDataControlObject : public QObject - { - public: - inline QObjectData *data() { return d_ptr.data(); } - }; -} - -QMetaDataControlMetaObject::QMetaDataControlMetaObject(QMetaDataControl *control, QObject *object) - : m_control(control) - , m_object(object) - , m_string(0) - , m_data(0) - , m_propertyOffset(0) - , m_signalOffset(0) -{ - const QMetaObject *superClass = m_object->metaObject(); - - const int propertyCount = sizeof(qt_metaDataKeys) / sizeof(MetaDataKey); - const int dataSize = sizeof(uint) - * (13 // QMetaObjectPrivate members. - + 5 // 5 members per signal. - + 4 * propertyCount // 3 members per property + 1 notify signal per property. - + 1); // Terminating value. - - m_data = reinterpret_cast(qMalloc(dataSize)); - - QMetaObjectPrivate *pMeta = reinterpret_cast(m_data); - - pMeta->revision = 3; - pMeta->className = 0; - pMeta->classInfoCount = 0; - pMeta->classInfoData = 0; - pMeta->methodCount = 1; - pMeta->methodData = 13; - pMeta->propertyCount = propertyCount; - pMeta->propertyData = 18; - pMeta->enumeratorCount = 0; - pMeta->enumeratorData = 0; - pMeta->constructorCount = 0; - pMeta->constructorData = 0; - pMeta->flags = 0x01; // Dynamic meta object flag. - - const int classNameSize = qstrlen(superClass->className()) + 1; - - int stringIndex = classNameSize + 1; - - // __metaDataChanged() signal. - static const char *changeSignal = "__metaDataChanged()"; - const int changeSignalSize = qstrlen(changeSignal) + 1; - - m_data[13] = stringIndex; // Signature. - m_data[14] = classNameSize; // Parameters. - m_data[15] = classNameSize; // Type. - m_data[16] = classNameSize; // Tag. - m_data[17] = MethodSignal | AccessProtected; // Flags. - - stringIndex += changeSignalSize; - - const char *qvariantName = "QVariant"; - const int qvariantSize = qstrlen(qvariantName) + 1; - const int qvariantIndex = stringIndex; - - stringIndex += qvariantSize; - - // Properties. - for (int i = 0; i < propertyCount; ++i) { - m_data[18 + 3 * i] = stringIndex; // Name. - m_data[19 + 3 * i] = qvariantIndex; // Type. - m_data[20 + 3 * i] - = Readable | Writable | Notify | Dynamic | (0xffffffff << 24); // Flags. - m_data[18 + propertyCount * 3 + i] = 0; // Notify signal. - - stringIndex += qstrlen(qt_metaDataKeys[i].name) + 1; - } - - // Terminating value. - m_data[18 + propertyCount * 4] = 0; - - // Build string. - m_string = reinterpret_cast(qMalloc(stringIndex + 1)); - - // Class name. - qMemCopy(m_string, superClass->className(), classNameSize); - - stringIndex = classNameSize; - - // Null m_string. - m_string[stringIndex] = '\0'; - stringIndex += 1; - - // __metaDataChanged() signal. - qMemCopy(m_string + stringIndex, changeSignal, changeSignalSize); - stringIndex += changeSignalSize; - - qMemCopy(m_string + stringIndex, qvariantName, qvariantSize); - stringIndex += qvariantSize; - - // Properties. - for (int i = 0; i < propertyCount; ++i) { - const int propertyNameSize = qstrlen(qt_metaDataKeys[i].name) + 1; - - qMemCopy(m_string + stringIndex, qt_metaDataKeys[i].name, propertyNameSize); - stringIndex += propertyNameSize; - } - - // Terminating character. - m_string[stringIndex] = '\0'; - - d.superdata = superClass; - d.stringdata = m_string; - d.data = m_data; - d.extradata = 0; - - static_cast(m_object)->data()->metaObject = this; - - m_propertyOffset = propertyOffset(); - m_signalOffset = methodOffset(); -} - -QMetaDataControlMetaObject::~QMetaDataControlMetaObject() -{ - static_cast(m_object)->data()->metaObject = 0; - - qFree(m_data); - qFree(m_string); -} - -int QMetaDataControlMetaObject::metaCall(QMetaObject::Call c, int id, void **a) -{ - if (c == QMetaObject::ReadProperty && id >= m_propertyOffset) { - int propId = id - m_propertyOffset; - - *reinterpret_cast(a[0]) = m_control->metaData(qt_metaDataKeys[propId].key); - - return -1; - } else if (c == QMetaObject::WriteProperty && id >= m_propertyOffset) { - int propId = id - m_propertyOffset; - - m_control->setMetaData(qt_metaDataKeys[propId].key, *reinterpret_cast(a[0])); - - return -1; - } else { - return m_object->qt_metacall(c, id, a); - } -} - -int QMetaDataControlMetaObject::createProperty(const char *, const char *) -{ - return -1; -} - -void QMetaDataControlMetaObject::metaDataChanged() -{ - activate(m_object, m_signalOffset, 0); -} - -QT_END_NAMESPACE diff --git a/src/plugins/qdeclarativemodules/multimedia/qmetadatacontrolmetaobject_p.h b/src/plugins/qdeclarativemodules/multimedia/qmetadatacontrolmetaobject_p.h deleted file mode 100644 index c381f2d..0000000 --- a/src/plugins/qdeclarativemodules/multimedia/qmetadatacontrolmetaobject_p.h +++ /dev/null @@ -1,92 +0,0 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ - -#ifndef QMETADATACONTROLMETAOBJECT_P_H -#define QMETADATACONTROLMETAOJBECT_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists for the convenience -// of other Qt classes. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include -#include - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -class QMetaDataControl; - -class QMetaDataControlMetaObject : public QAbstractDynamicMetaObject -{ -public: - QMetaDataControlMetaObject(QMetaDataControl *control, QObject *object); - ~QMetaDataControlMetaObject(); - - int metaCall(QMetaObject::Call call, int _id, void **arguments); - int createProperty(const char *, const char *); - - void metaDataChanged(); - -private: - QMetaDataControl *m_control; - QObject *m_object; - char *m_string; - uint *m_data; - - int m_propertyOffset; - int m_signalOffset; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif -- cgit v0.12 From 372f474d97f2169597f994ee80e6c3d5b7f6d7bf Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Thu, 4 Mar 2010 17:16:54 +1000 Subject: Mark QGraphicsItem position properties as FINAL Some of these properties were already final, so this improves the consistency. QTBUG-7948. --- src/gui/graphicsview/qgraphicsitem.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/gui/graphicsview/qgraphicsitem.h b/src/gui/graphicsview/qgraphicsitem.h index d72833b..56f94a2 100644 --- a/src/gui/graphicsview/qgraphicsitem.h +++ b/src/gui/graphicsview/qgraphicsitem.h @@ -540,10 +540,10 @@ class Q_GUI_EXPORT QGraphicsObject : public QObject, public QGraphicsItem Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity NOTIFY opacityChanged FINAL) Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged) Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged FINAL) - Q_PROPERTY(QPointF pos READ pos WRITE setPos) - Q_PROPERTY(qreal x READ x WRITE setX NOTIFY xChanged) - Q_PROPERTY(qreal y READ y WRITE setY NOTIFY yChanged) - Q_PROPERTY(qreal z READ zValue WRITE setZValue NOTIFY zChanged) + Q_PROPERTY(QPointF pos READ pos WRITE setPos FINAL) + Q_PROPERTY(qreal x READ x WRITE setX NOTIFY xChanged FINAL) + Q_PROPERTY(qreal y READ y WRITE setY NOTIFY yChanged FINAL) + Q_PROPERTY(qreal z READ zValue WRITE setZValue NOTIFY zChanged FINAL) Q_PROPERTY(qreal rotation READ rotation WRITE setRotation NOTIFY rotationChanged) Q_PROPERTY(qreal scale READ scale WRITE setScale NOTIFY scaleChanged) Q_PROPERTY(QPointF transformOriginPoint READ transformOriginPoint WRITE setTransformOriginPoint) -- cgit v0.12 From 4802116c73c0b9ee80dddc8ef4720bfdbde4e885 Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Thu, 4 Mar 2010 17:20:52 +1000 Subject: Add support for tab and backtab in KeyNavigation Task-number: QT-3046 --- src/declarative/graphicsitems/qdeclarativeitem.cpp | 88 ++++++++++++++++++---- src/declarative/graphicsitems/qdeclarativeitem_p.h | 13 +++- 2 files changed, 87 insertions(+), 14 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativeitem.cpp b/src/declarative/graphicsitems/qdeclarativeitem.cpp index 5014fd8..3bee5b8 100644 --- a/src/declarative/graphicsitems/qdeclarativeitem.cpp +++ b/src/declarative/graphicsitems/qdeclarativeitem.cpp @@ -498,6 +498,32 @@ void QDeclarativeKeyNavigationAttached::setDown(QDeclarativeItem *i) emit changed(); } +QDeclarativeItem *QDeclarativeKeyNavigationAttached::tab() const +{ + Q_D(const QDeclarativeKeyNavigationAttached); + return d->tab; +} + +void QDeclarativeKeyNavigationAttached::setTab(QDeclarativeItem *i) +{ + Q_D(QDeclarativeKeyNavigationAttached); + d->tab = i; + emit changed(); +} + +QDeclarativeItem *QDeclarativeKeyNavigationAttached::backtab() const +{ + Q_D(const QDeclarativeKeyNavigationAttached); + return d->backtab; +} + +void QDeclarativeKeyNavigationAttached::setBacktab(QDeclarativeItem *i) +{ + Q_D(QDeclarativeKeyNavigationAttached); + d->backtab = i; + emit changed(); +} + void QDeclarativeKeyNavigationAttached::keyPressed(QKeyEvent *event) { Q_D(QDeclarativeKeyNavigationAttached); @@ -529,6 +555,18 @@ void QDeclarativeKeyNavigationAttached::keyPressed(QKeyEvent *event) event->accept(); } break; + case Qt::Key_Tab: + if (d->tab) { + d->tab->setFocus(true); + event->accept(); + } + break; + case Qt::Key_Backtab: + if (d->backtab) { + d->backtab->setFocus(true); + event->accept(); + } + break; default: break; } @@ -563,6 +601,16 @@ void QDeclarativeKeyNavigationAttached::keyReleased(QKeyEvent *event) event->accept(); } break; + case Qt::Key_Tab: + if (d->tab) { + event->accept(); + } + break; + case Qt::Key_Backtab: + if (d->backtab) { + event->accept(); + } + break; default: break; } @@ -902,6 +950,8 @@ const QDeclarativeKeysAttached::SigMap QDeclarativeKeysAttached::sigMap[] = { { Qt::Key_Right, "rightPressed" }, { Qt::Key_Up, "upPressed" }, { Qt::Key_Down, "downPressed" }, + { Qt::Key_Tab, "tabPressed" }, + { Qt::Key_Backtab, "backtabPressed" }, { Qt::Key_Asterisk, "asteriskPressed" }, { Qt::Key_NumberSign, "numberSignPressed" }, { Qt::Key_Escape, "escapePressed" }, @@ -1440,7 +1490,7 @@ QDeclarativeAnchors *QDeclarativeItem::anchors() void QDeclarativeItemPrivate::data_append(QDeclarativeListProperty *prop, QObject *o) { QDeclarativeItem *i = qobject_cast(o); - if (i) + if (i) i->setParentItem(static_cast(prop->object)); else o->setParent(static_cast(prop->object)); @@ -1568,7 +1618,7 @@ void QDeclarativeItemPrivate::transform_clear(QDeclarativeListProperty QDeclarativeItem::data() +QDeclarativeListProperty QDeclarativeItem::data() { return QDeclarativeListProperty(this, 0, QDeclarativeItemPrivate::data_append); } @@ -2179,16 +2229,16 @@ void QDeclarativeItem::focusChanged(bool flag) QDeclarativeListProperty QDeclarativeItem::fxChildren() { return QDeclarativeListProperty(this, 0, QDeclarativeItemPrivate::children_append, - QDeclarativeItemPrivate::children_count, - QDeclarativeItemPrivate::children_at); + QDeclarativeItemPrivate::children_count, + QDeclarativeItemPrivate::children_at); } /*! \internal */ QDeclarativeListProperty QDeclarativeItem::resources() { - return QDeclarativeListProperty(this, 0, QDeclarativeItemPrivate::resources_append, - QDeclarativeItemPrivate::resources_count, - QDeclarativeItemPrivate::resources_at); + return QDeclarativeListProperty(this, 0, QDeclarativeItemPrivate::resources_append, + QDeclarativeItemPrivate::resources_count, + QDeclarativeItemPrivate::resources_at); } /*! @@ -2465,14 +2515,26 @@ QPointF QDeclarativeItemPrivate::computeTransformOrigin() const /*! \internal */ bool QDeclarativeItem::sceneEvent(QEvent *event) { - bool rv = QGraphicsItem::sceneEvent(event); + if (event->type() == QEvent::KeyPress) { + QKeyEvent *k = static_cast(event); - if (event->type() == QEvent::FocusIn || - event->type() == QEvent::FocusOut) { - focusChanged(hasFocus()); - } + if ((k->key() == Qt::Key_Tab || k->key() == Qt::Key_Backtab) && + !(k->modifiers() & (Qt::ControlModifier | Qt::AltModifier))) { + keyPressEvent(static_cast(event)); + if (!event->isAccepted()) + QGraphicsItem::sceneEvent(event); + } else { + QGraphicsItem::sceneEvent(event); + } + } else { + bool rv = QGraphicsItem::sceneEvent(event); - return rv; + if (event->type() == QEvent::FocusIn || + event->type() == QEvent::FocusOut) { + focusChanged(hasFocus()); + } + return rv; + } } /*! \internal */ diff --git a/src/declarative/graphicsitems/qdeclarativeitem_p.h b/src/declarative/graphicsitems/qdeclarativeitem_p.h index 4b4917e..e424970 100644 --- a/src/declarative/graphicsitems/qdeclarativeitem_p.h +++ b/src/declarative/graphicsitems/qdeclarativeitem_p.h @@ -289,12 +289,14 @@ class QDeclarativeKeyNavigationAttachedPrivate : public QObjectPrivate { public: QDeclarativeKeyNavigationAttachedPrivate() - : QObjectPrivate(), left(0), right(0), up(0), down(0) {} + : QObjectPrivate(), left(0), right(0), up(0), down(0), tab(0), backtab(0) {} QDeclarativeItem *left; QDeclarativeItem *right; QDeclarativeItem *up; QDeclarativeItem *down; + QDeclarativeItem *tab; + QDeclarativeItem *backtab; }; class QDeclarativeKeyNavigationAttached : public QObject, public QDeclarativeItemKeyFilter @@ -306,6 +308,9 @@ class QDeclarativeKeyNavigationAttached : public QObject, public QDeclarativeIte Q_PROPERTY(QDeclarativeItem *right READ right WRITE setRight NOTIFY changed) Q_PROPERTY(QDeclarativeItem *up READ up WRITE setUp NOTIFY changed) Q_PROPERTY(QDeclarativeItem *down READ down WRITE setDown NOTIFY changed) + Q_PROPERTY(QDeclarativeItem *tab READ tab WRITE setTab NOTIFY changed) + Q_PROPERTY(QDeclarativeItem *backtab READ backtab WRITE setBacktab NOTIFY changed) + public: QDeclarativeKeyNavigationAttached(QObject * = 0); @@ -317,6 +322,10 @@ public: void setUp(QDeclarativeItem *); QDeclarativeItem *down() const; void setDown(QDeclarativeItem *); + QDeclarativeItem *tab() const; + void setTab(QDeclarativeItem *); + QDeclarativeItem *backtab() const; + void setBacktab(QDeclarativeItem *); static QDeclarativeKeyNavigationAttached *qmlAttachedProperties(QObject *); @@ -407,6 +416,8 @@ Q_SIGNALS: void rightPressed(QDeclarativeKeyEvent *event); void upPressed(QDeclarativeKeyEvent *event); void downPressed(QDeclarativeKeyEvent *event); + void tabPressed(QDeclarativeKeyEvent *event); + void backtabPressed(QDeclarativeKeyEvent *event); void asteriskPressed(QDeclarativeKeyEvent *event); void numberSignPressed(QDeclarativeKeyEvent *event); -- cgit v0.12 From c871d201a65b1524c0590e2d6ad77b8666338b08 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Thu, 4 Mar 2010 17:23:09 +1000 Subject: Fixup test --- tests/auto/declarative/qdeclarativeecmascript/data/methods.5.qml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/methods.5.qml b/tests/auto/declarative/qdeclarativeecmascript/data/methods.5.qml index 3d45b15..5ba324a 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/data/methods.5.qml +++ b/tests/auto/declarative/qdeclarativeecmascript/data/methods.5.qml @@ -1,7 +1,7 @@ import Qt 4.6 Item { - property alias x: item.x + property alias blah: item.x Item { id: item } function testFunction() { return 9; } -- cgit v0.12 From 6633234f5f19899dc54510b2bddb2ae1afd38318 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Thu, 4 Mar 2010 18:12:45 +1000 Subject: Run signal expressions on attached property objects in correct scope QTBUG-8677 --- src/declarative/qml/qdeclarativecompiler.cpp | 13 +++++++++---- src/declarative/qml/qdeclarativecompiler_p.h | 1 + src/declarative/qml/qdeclarativeinstruction_p.h | 1 + src/declarative/qml/qdeclarativevme.cpp | 8 ++++---- .../data/attachedPropertyScope.qml | 9 +++++++++ .../declarative/qdeclarativeecmascript/testtypes.h | 13 ++++++++++++- .../tst_qdeclarativeecmascript.cpp | 21 +++++++++++++++++++++ .../data/attachedProperties.qml | 2 -- .../tst_qdeclarativelanguage.cpp | 5 ----- 9 files changed, 57 insertions(+), 16 deletions(-) create mode 100644 tests/auto/declarative/qdeclarativeecmascript/data/attachedPropertyScope.qml diff --git a/src/declarative/qml/qdeclarativecompiler.cpp b/src/declarative/qml/qdeclarativecompiler.cpp index 32c746f..5a2f3b5 100644 --- a/src/declarative/qml/qdeclarativecompiler.cpp +++ b/src/declarative/qml/qdeclarativecompiler.cpp @@ -983,12 +983,15 @@ void QDeclarativeCompiler::genObjectBody(QDeclarativeParser::Object *obj) } else if (v->type == Value::SignalExpression) { + BindingContext ctxt = compileState.signalExpressions.value(v); + QDeclarativeInstruction store; store.type = QDeclarativeInstruction::StoreSignal; store.line = v->location.start.line; store.storeSignal.signalIndex = prop->index; store.storeSignal.value = output->indexForString(v->value.asScript().trimmed()); + store.storeSignal.context = ctxt.stack; output->bytecode << store; } @@ -1321,7 +1324,7 @@ QMetaMethod QDeclarativeCompiler::findSignalByName(const QMetaObject *mo, const } bool QDeclarativeCompiler::buildSignal(QDeclarativeParser::Property *prop, QDeclarativeParser::Object *obj, - const BindingContext &ctxt) + const BindingContext &ctxt) { Q_ASSERT(obj->metaObject()); Q_ASSERT(!prop->isEmpty()); @@ -1357,6 +1360,8 @@ bool QDeclarativeCompiler::buildSignal(QDeclarativeParser::Property *prop, QDecl QString script = prop->values.at(0)->value.asScript().trimmed(); if (script.isEmpty()) COMPILE_EXCEPTION(prop, QCoreApplication::translate("QDeclarativeCompiler","Empty signal assignment")); + + compileState.signalExpressions.insert(prop->values.at(0), ctxt); } } @@ -2608,9 +2613,9 @@ bool QDeclarativeCompiler::buildBinding(QDeclarativeParser::Value *value, } void QDeclarativeCompiler::genBindingAssignment(QDeclarativeParser::Value *binding, - QDeclarativeParser::Property *prop, - QDeclarativeParser::Object *obj, - QDeclarativeParser::Property *valueTypeProperty) + QDeclarativeParser::Property *prop, + QDeclarativeParser::Object *obj, + QDeclarativeParser::Property *valueTypeProperty) { Q_UNUSED(obj); Q_ASSERT(compileState.bindings.contains(binding)); diff --git a/src/declarative/qml/qdeclarativecompiler_p.h b/src/declarative/qml/qdeclarativecompiler_p.h index f8ada95..cca42e2 100644 --- a/src/declarative/qml/qdeclarativecompiler_p.h +++ b/src/declarative/qml/qdeclarativecompiler_p.h @@ -307,6 +307,7 @@ private: QByteArray compiledBindingData; QHash bindings; + QHash signalExpressions; QList aliasingObjects; QDeclarativeParser::Object *root; }; diff --git a/src/declarative/qml/qdeclarativeinstruction_p.h b/src/declarative/qml/qdeclarativeinstruction_p.h index d8af6a7..c41b14f 100644 --- a/src/declarative/qml/qdeclarativeinstruction_p.h +++ b/src/declarative/qml/qdeclarativeinstruction_p.h @@ -293,6 +293,7 @@ public: struct { int signalIndex; int value; + int context; } storeSignal; struct { int signal; diff --git a/src/declarative/qml/qdeclarativevme.cpp b/src/declarative/qml/qdeclarativevme.cpp index fc3722d..6a08674 100644 --- a/src/declarative/qml/qdeclarativevme.cpp +++ b/src/declarative/qml/qdeclarativevme.cpp @@ -538,13 +538,13 @@ QObject *QDeclarativeVME::run(QDeclarativeVMEStack &stack, QDeclarati case QDeclarativeInstruction::StoreSignal: { QObject *target = stack.top(); - // XXX scope - QMetaMethod signal = - target->metaObject()->method(instr.storeSignal.signalIndex); + QObject *context = stack.at(stack.count() - 1 - instr.assignBinding.context); + + QMetaMethod signal = target->metaObject()->method(instr.storeSignal.signalIndex); QDeclarativeBoundSignal *bs = new QDeclarativeBoundSignal(target, signal, target); QDeclarativeExpression *expr = - new QDeclarativeExpression(ctxt, primitives.at(instr.storeSignal.value), target); + new QDeclarativeExpression(ctxt, primitives.at(instr.storeSignal.value), context); expr->setSourceLocation(comp->name, instr.line); bs->setExpression(expr); } diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/attachedPropertyScope.qml b/tests/auto/declarative/qdeclarativeecmascript/data/attachedPropertyScope.qml new file mode 100644 index 0000000..4b5464d --- /dev/null +++ b/tests/auto/declarative/qdeclarativeecmascript/data/attachedPropertyScope.qml @@ -0,0 +1,9 @@ +import Qt 4.6 +import Qt.test 1.0 + +QtObject { + property int value: 9 + property int value2 + + MyQmlObject.onMySignal: value2 = value +} diff --git a/tests/auto/declarative/qdeclarativeecmascript/testtypes.h b/tests/auto/declarative/qdeclarativeecmascript/testtypes.h index 8fbd071..a283e3f 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/testtypes.h +++ b/tests/auto/declarative/qdeclarativeecmascript/testtypes.h @@ -60,10 +60,21 @@ class MyQmlAttachedObject : public QObject { Q_OBJECT Q_PROPERTY(int value READ value CONSTANT) + Q_PROPERTY(int value2 READ value2 WRITE setValue2) public: - MyQmlAttachedObject(QObject *parent) : QObject(parent) {} + MyQmlAttachedObject(QObject *parent) : QObject(parent), m_value2(0) {} int value() const { return 19; } + int value2() const { return m_value2; } + void setValue2(int v) { m_value2 = v; } + + void emitMySignal() { emit mySignal(); } + +signals: + void mySignal(); + +private: + int m_value2; }; class MyQmlObject : public QObject diff --git a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp index 75ee7ce..2e00e10 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp +++ b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp @@ -123,6 +123,7 @@ private slots: void multiEngineObject(); void deletedObject(); void scriptScope(); + void attachedPropertyScope(); void bug1(); @@ -1693,6 +1694,26 @@ void tst_qdeclarativeecmascript::scriptScope() } } +void tst_qdeclarativeecmascript::attachedPropertyScope() +{ + QDeclarativeComponent component(&engine, TEST_FILE("attachedPropertyScope.qml")); + + QObject *object = component.create(); + QVERIFY(object != 0); + + MyQmlAttachedObject *attached = + qobject_cast(qmlAttachedPropertiesObject(object)); + QVERIFY(attached != 0); + + QCOMPARE(object->property("value2").toInt(), 0); + + attached->emitMySignal(); + + QCOMPARE(object->property("value2").toInt(), 9); + + delete object; +} + QTEST_MAIN(tst_qdeclarativeecmascript) #include "tst_qdeclarativeecmascript.moc" diff --git a/tests/auto/declarative/qdeclarativelanguage/data/attachedProperties.qml b/tests/auto/declarative/qdeclarativelanguage/data/attachedProperties.qml index aecb3c3..b46ec34 100644 --- a/tests/auto/declarative/qdeclarativelanguage/data/attachedProperties.qml +++ b/tests/auto/declarative/qdeclarativelanguage/data/attachedProperties.qml @@ -3,8 +3,6 @@ import Test 1.0 as Namespace import Qt 4.6 QtObject { - property int value2: 8 MyQmlObject.value: 10 Namespace.MyQmlObject.value2: 13 - MyQmlObject.onValueChanged: value2 = MyQmlObject.value } diff --git a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp index a339a6d..3ce15cb 100644 --- a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp +++ b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp @@ -718,11 +718,6 @@ void tst_qdeclarativelanguage::attachedProperties() QVERIFY(attached != 0); QCOMPARE(attached->property("value"), QVariant(10)); QCOMPARE(attached->property("value2"), QVariant(13)); - - QEXPECT_FAIL("", "QTBUG-8677", Abort); - attached->setProperty("value", QVariant(12)); - int val = object->property("value2").toInt(); - QCOMPARE(val, 12); } // Tests non-static object properties -- cgit v0.12 From a65e37f0fd48158403296d5ca9ffa0f0feae2940 Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Thu, 4 Mar 2010 18:17:24 +1000 Subject: Add autotests for tab and backtab in Keys and KeyNavigation. --- .../qdeclarativeitem/data/keynavigation.qml | 8 +++++ .../declarative/qdeclarativeitem/data/keys.qml | 2 ++ .../qdeclarativeitem/tst_qdeclarativeitem.cpp | 38 ++++++++++++++++++++++ 3 files changed, 48 insertions(+) diff --git a/tests/auto/declarative/qdeclarativeitem/data/keynavigation.qml b/tests/auto/declarative/qdeclarativeitem/data/keynavigation.qml index 9281a17..08da901 100644 --- a/tests/auto/declarative/qdeclarativeitem/data/keynavigation.qml +++ b/tests/auto/declarative/qdeclarativeitem/data/keynavigation.qml @@ -11,6 +11,8 @@ Grid { color: focus ? "red" : "lightgray" KeyNavigation.right: item2 KeyNavigation.down: item3 + KeyNavigation.tab: item2 + KeyNavigation.backtab: item4 } Rectangle { id: item2 @@ -19,6 +21,8 @@ Grid { color: focus ? "red" : "lightgray" KeyNavigation.left: item1 KeyNavigation.down: item4 + KeyNavigation.tab: item3 + KeyNavigation.backtab: item1 } Rectangle { id: item3 @@ -27,6 +31,8 @@ Grid { color: focus ? "red" : "lightgray" KeyNavigation.right: item4 KeyNavigation.up: item1 + KeyNavigation.tab: item4 + KeyNavigation.backtab: item2 } Rectangle { id: item4 @@ -35,5 +41,7 @@ Grid { color: focus ? "red" : "lightgray" KeyNavigation.left: item3 KeyNavigation.up: item2 + KeyNavigation.tab: item1 + KeyNavigation.backtab: item3 } } diff --git a/tests/auto/declarative/qdeclarativeitem/data/keys.qml b/tests/auto/declarative/qdeclarativeitem/data/keys.qml index f3c1f7b..7d34fc8 100644 --- a/tests/auto/declarative/qdeclarativeitem/data/keys.qml +++ b/tests/auto/declarative/qdeclarativeitem/data/keys.qml @@ -7,6 +7,8 @@ Item { Keys.onReturnPressed: keysTestObject.keyPress(event.key, "Return", event.modifiers) Keys.onDigit0Pressed: keysTestObject.keyPress(event.key, event.text, event.modifiers) Keys.onDigit9Pressed: { event.accepted = false; keysTestObject.keyPress(event.key, event.text, event.modifiers) } + Keys.onTabPressed: keysTestObject.keyPress(event.key, "Tab", event.modifiers) + Keys.onBacktabPressed: keysTestObject.keyPress(event.key, "Backtab", event.modifiers) Keys.forwardTo: [ item2 ] Keys.enabled: enableKeyHanding diff --git a/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp b/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp index 36dcf1f..dbcba16 100644 --- a/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp +++ b/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp @@ -176,6 +176,26 @@ void tst_QDeclarativeItem::keys() testObject->reset(); + key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier, "", false, 1); + QApplication::sendEvent(canvas, &key); + QCOMPARE(testObject->mKey, int(Qt::Key_Tab)); + QCOMPARE(testObject->mForwardedKey, int(Qt::Key_Tab)); + QCOMPARE(testObject->mText, QLatin1String("Tab")); + QVERIFY(testObject->mModifiers == Qt::NoModifier); + QVERIFY(key.isAccepted()); + + testObject->reset(); + + key = QKeyEvent(QEvent::KeyPress, Qt::Key_Backtab, Qt::NoModifier, "", false, 1); + QApplication::sendEvent(canvas, &key); + QCOMPARE(testObject->mKey, int(Qt::Key_Backtab)); + QCOMPARE(testObject->mForwardedKey, int(Qt::Key_Backtab)); + QCOMPARE(testObject->mText, QLatin1String("Backtab")); + QVERIFY(testObject->mModifiers == Qt::NoModifier); + QVERIFY(key.isAccepted()); + + testObject->reset(); + canvas->rootContext()->setContextProperty("enableKeyHanding", QVariant(false)); key = QKeyEvent(QEvent::KeyPress, Qt::Key_Return, Qt::NoModifier, "", false, 1); @@ -240,6 +260,24 @@ void tst_QDeclarativeItem::keyNavigation() item = findItem(canvas->rootObject(), "item1"); QVERIFY(item); QVERIFY(item->hasFocus()); + + // tab + key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier, "", false, 1); + QApplication::sendEvent(canvas, &key); + QVERIFY(key.isAccepted()); + + item = findItem(canvas->rootObject(), "item2"); + QVERIFY(item); + QVERIFY(item->hasFocus()); + + // backtab + key = QKeyEvent(QEvent::KeyPress, Qt::Key_Backtab, Qt::NoModifier, "", false, 1); + QApplication::sendEvent(canvas, &key); + QVERIFY(key.isAccepted()); + + item = findItem(canvas->rootObject(), "item1"); + QVERIFY(item); + QVERIFY(item->hasFocus()); } void tst_QDeclarativeItem::smooth() -- cgit v0.12 From 83cbbd6c4c9ff2f00651c31af0d52845b2e98390 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Thu, 4 Mar 2010 18:22:49 +1000 Subject: Add testcase for QTBUG-7730 --- .../declarative/qdeclarativeecmascript/data/scope.4.qml | 12 ++++++++++++ .../tst_qdeclarativeecmascript.cpp | 17 +++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 tests/auto/declarative/qdeclarativeecmascript/data/scope.4.qml diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/scope.4.qml b/tests/auto/declarative/qdeclarativeecmascript/data/scope.4.qml new file mode 100644 index 0000000..d65b6e7 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeecmascript/data/scope.4.qml @@ -0,0 +1,12 @@ +import Qt.test 1.0 + +MyQmlObject { + id: a + property int b: 9 + + property int test + property string test2 + + // Should resolve to signal arguments, not to other elements in the file + onArgumentSignal: { test = a; test2 = b; } +} diff --git a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp index 2e00e10..b5649cb 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp +++ b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp @@ -740,6 +740,23 @@ void tst_qdeclarativeecmascript::scope() QCOMPARE(object->property("test2").toBool(), true); QCOMPARE(object->property("test3").toBool(), true); } + + // Signal argument scope + { + QDeclarativeComponent component(&engine, TEST_FILE("scope.4.qml")); + MyQmlObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + + QCOMPARE(object->property("test").toInt(), 0); + QCOMPARE(object->property("test2").toString(), QString()); + + emit object->argumentSignal(13, "Argument Scope", 9); + + QCOMPARE(object->property("test").toInt(), 13); + QCOMPARE(object->property("test2").toString(), QString("Argument Scope")); + + delete object; + } } /* -- cgit v0.12 From 6f09fc3a475eb2e1c843f4aebe7ea0d15182ac1d Mon Sep 17 00:00:00 2001 From: Leonardo Sobral Cunha Date: Thu, 4 Mar 2010 12:49:56 +0100 Subject: Update QML PropertyAnimation::easing docs Task-number: QTBUG-8726 --- src/declarative/util/qdeclarativeanimation.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/declarative/util/qdeclarativeanimation.cpp b/src/declarative/util/qdeclarativeanimation.cpp index f33d7c7..76b6a58 100644 --- a/src/declarative/util/qdeclarativeanimation.cpp +++ b/src/declarative/util/qdeclarativeanimation.cpp @@ -1736,7 +1736,7 @@ void QDeclarativePropertyAnimationPrivate::convertVariant(QVariant &variant, int Animate any objects that have changed their x or y properties in the target state using an InOutQuad easing curve: \qml - Transition { PropertyAnimation { properties: "x,y"; easing: "InOutQuad" } } + Transition { PropertyAnimation { properties: "x,y"; easing.type: "InOutQuad" } } \endqml \o In a Behavior @@ -1877,7 +1877,13 @@ void QDeclarativePropertyAnimation::setTo(const QVariant &t) \qmlproperty QEasingCurve PropertyAnimation::easing \brief the easing curve used for the transition. - Available values are: + For the easing you can specify the following parameters: type, amplitude, period and overshoot. + + \qml + PropertyAnimation { properties: "y"; easing.type: "InOutElastc"; easing.amplitude: 2.0; easing.period: 1.5 } + \endqml + + Available types are: \table \row @@ -2048,6 +2054,15 @@ void QDeclarativePropertyAnimation::setTo(const QVariant &t) \o \inlineimage qeasingcurve-outinbounce.png \endtable + easing.amplitude is not applicable for all curve types. It is only applicable for bounce and elastic curves (curves of type + QEasingCurve::InBounce, QEasingCurve::OutBounce, QEasingCurve::InOutBounce, QEasingCurve::OutInBounce, QEasingCurve::InElastic, + QEasingCurve::OutElastic, QEasingCurve::InOutElastic or QEasingCurve::OutInElastic). + + easing.overshoot is not applicable for all curve types. It is only applicable if type is: QEasingCurve::InBack, QEasingCurve::OutBack, + QEasingCurve::InOutBack or QEasingCurve::OutInBack. + + easing.period is not applicable for all curve types. It is only applicable if type is: QEasingCurve::InElastic, QEasingCurve::OutElastic, + QEasingCurve::InOutElastic or QEasingCurve::OutInElastic. */ QEasingCurve QDeclarativePropertyAnimation::easing() const { -- cgit v0.12