summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorWarwick Allison <warwick.allison@nokia.com>2009-08-24 01:17:38 (GMT)
committerWarwick Allison <warwick.allison@nokia.com>2009-08-24 01:17:38 (GMT)
commitdf432c12585e00b682776f5c8a879611a0f07ef7 (patch)
tree9e7e6ed4d2ae790310ddec0a2a8f6eefebe07e5f /src
parent9c6472491c9d5ac23696767388bdeb8337e2e0ee (diff)
downloadQt-df432c12585e00b682776f5c8a879611a0f07ef7.zip
Qt-df432c12585e00b682776f5c8a879611a0f07ef7.tar.gz
Qt-df432c12585e00b682776f5c8a879611a0f07ef7.tar.bz2
Fix WebViewSettings
More QML <-> JavaScript integration, with example. From Tapani Mikola
Diffstat (limited to 'src')
-rw-r--r--src/declarative/fx/qfxwebview.cpp23
-rw-r--r--src/declarative/fx/qfxwebview.h6
2 files changed, 23 insertions, 6 deletions
diff --git a/src/declarative/fx/qfxwebview.cpp b/src/declarative/fx/qfxwebview.cpp
index a7d233f..9fc469a 100644
--- a/src/declarative/fx/qfxwebview.cpp
+++ b/src/declarative/fx/qfxwebview.cpp
@@ -131,6 +131,8 @@ public:
QWebSettings *s;
};
+QML_DECLARE_TYPE(QFxWebSettings)
+QML_DEFINE_NOCREATE_TYPE(QFxWebSettings)
class QFxWebViewPrivate : public QFxPaintedItemPrivate
{
@@ -951,7 +953,7 @@ QWebPage *QFxWebView::page() const
}
\endqml
*/
-QObject *QFxWebView::settingsObject() const
+QFxWebSettings *QFxWebView::settingsObject() const
{
Q_D(const QFxWebView);
d->settings.s = page()->settings();
@@ -1101,22 +1103,35 @@ public:
QmlEngine *engine = qmlEngine(webview);
component = new QmlComponent(engine, url, this);
item = 0;
- if (component->isReady())
- qmlLoaded();
- else
+ if (component->isLoading())
connect(component, SIGNAL(statusChanged(QmlComponent::Status)), this, SLOT(qmlLoaded()));
+ else
+ qmlLoaded();
}
public Q_SLOTS:
void qmlLoaded()
{
+ if (component->isError()) {
+ // XXX Could instead give these errors to the WebView to handle.
+ foreach (QmlError err, component->errors())
+ qWarning(err.toString().toLatin1());
+ return;
+ }
item = qobject_cast<QFxItem*>(component->create(qmlContext(webview)));
item->setParent(webview);
+ QString jsObjName;
for (int i=0; i<propertyNames.count(); ++i) {
if (propertyNames[i] != QLatin1String("type") && propertyNames[i] != QLatin1String("data")) {
item->setProperty(propertyNames[i].toLatin1(),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;
diff --git a/src/declarative/fx/qfxwebview.h b/src/declarative/fx/qfxwebview.h
index d619e94..d84a01c 100644
--- a/src/declarative/fx/qfxwebview.h
+++ b/src/declarative/fx/qfxwebview.h
@@ -75,6 +75,8 @@ private:
class QFxWebViewAttached;
+class QFxWebSettings;
+
class Q_DECLARATIVE_EXPORT QFxWebView : public QFxPaintedItem
{
Q_OBJECT
@@ -103,7 +105,7 @@ class Q_DECLARATIVE_EXPORT QFxWebView : public QFxPaintedItem
Q_PROPERTY(QObject* forward READ forwardAction CONSTANT)
Q_PROPERTY(QObject* stop READ stopAction CONSTANT)
- Q_PROPERTY(QObject* settings READ settingsObject CONSTANT)
+ Q_PROPERTY(QFxWebSettings* settings READ settingsObject CONSTANT)
Q_PROPERTY(QmlList<QObject *>* javaScriptWindowObjects READ javaScriptWindowObjects CONSTANT)
@@ -157,7 +159,7 @@ public:
QWebHistory *history() const;
QWebSettings *settings() const;
- QObject *settingsObject() const;
+ QFxWebSettings *settingsObject() const;
QString status() const;