summaryrefslogtreecommitdiffstats
path: root/examples/webkit
diff options
context:
space:
mode:
Diffstat (limited to 'examples/webkit')
-rw-r--r--examples/webkit/imageanalyzer/README20
-rw-r--r--examples/webkit/imageanalyzer/imageanalyzer.cpp222
-rw-r--r--examples/webkit/imageanalyzer/imageanalyzer.h101
-rw-r--r--examples/webkit/imageanalyzer/imageanalyzer.pro14
-rw-r--r--examples/webkit/imageanalyzer/main.cpp53
-rw-r--r--examples/webkit/imageanalyzer/mainwindow.cpp80
-rw-r--r--examples/webkit/imageanalyzer/mainwindow.h66
-rw-r--r--examples/webkit/imageanalyzer/resources/imageanalyzer.qrc10
-rw-r--r--examples/webkit/imageanalyzer/resources/images/README2
-rw-r--r--examples/webkit/imageanalyzer/resources/images/bellaCoola.jpgbin0 -> 129886 bytes
-rw-r--r--examples/webkit/imageanalyzer/resources/images/flower.jpgbin0 -> 67126 bytes
-rw-r--r--examples/webkit/imageanalyzer/resources/images/mtRainier.jpgbin0 -> 104090 bytes
-rw-r--r--examples/webkit/imageanalyzer/resources/images/seaShell.jpgbin0 -> 82690 bytes
-rw-r--r--examples/webkit/imageanalyzer/resources/images/trees.jpgbin0 -> 98630 bytes
-rw-r--r--examples/webkit/imageanalyzer/resources/index.html133
-rw-r--r--examples/webkit/webkit.pro1
16 files changed, 702 insertions, 0 deletions
diff --git a/examples/webkit/imageanalyzer/README b/examples/webkit/imageanalyzer/README
new file mode 100644
index 0000000..9415b57
--- /dev/null
+++ b/examples/webkit/imageanalyzer/README
@@ -0,0 +1,20 @@
+This example demonstrates the use of Qt WebKit to make a hybrid application.
+
+Build instructions:
+
+ On Mac OS X:
+ In this directory:
+ qmake -spec macx-g++
+ make clean all
+ open imageanalyzer.app
+ On Linux/Unix:
+ In this directory:
+ qmake
+ make clean all
+ ./imageanalyzer
+
+ On Windows:
+ In this directory:
+ qmake
+ nmake clean all
+ debug\imageanalyzer.exe
diff --git a/examples/webkit/imageanalyzer/imageanalyzer.cpp b/examples/webkit/imageanalyzer/imageanalyzer.cpp
new file mode 100644
index 0000000..1d0ee45
--- /dev/null
+++ b/examples/webkit/imageanalyzer/imageanalyzer.cpp
@@ -0,0 +1,222 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
+#include <QNetworkReply>
+#include <QNetworkRequest>
+#include <QNetworkAccessManager>
+#include <QNetworkDiskCache>
+#include "imageanalyzer.h"
+
+/*!
+ * This class operates as follows:
+ * Parent calls the slot startAnalysis which shoves a list of QStrings into URLQueue and then calls fetchURLs.
+ * FetchURLs sends out HTTP GETs for each image it can't get out of the cache.
+ * As the responses come in, handleReply trys to create an image out of each and pushes those images into imageQueue.
+ * On the last (detected by no outstandingFetches and URLQueue.isEmpty()) call to queueImage (from handleReply)
+ * a thread is forked to process all the images. When it finishes, it emits a finished signal that is received
+ * by our JavaScript code.
+ */
+
+//! [ ImageAnalyzer - Constructor ]
+ImageAnalyzer::ImageAnalyzer(QNetworkDiskCache* netcache, QObject* parent)
+ : QObject(parent), m_cache(netcache), m_outstandingFetches(0)
+{
+ /* ImageAnalyzer only wants to receive http responses
+ for requests that it makes, so that's why it has its own
+ QNetworkAccessManager. */
+ m_network = new QNetworkAccessManager(this);
+ m_watcher = new QFutureWatcher<QRgb>(this);
+ /* We want to share a cache with the web browser,
+ in case it has some images we want: */
+ m_network->setCache(m_cache);
+
+ QObject::connect(m_network, SIGNAL(finished(QNetworkReply*)),
+ this, SLOT(handleReply(QNetworkReply*)));
+ QObject::connect(m_watcher, SIGNAL(finished()),
+ this, SLOT(doneProcessing()));
+ QObject::connect(m_watcher, SIGNAL(progressValueChanged(int)),
+ this, SLOT(progressStatus(int)));
+}
+//! [ ImageAnalyzer - Constructor ]
+ImageAnalyzer::~ImageAnalyzer()
+{
+ delete(m_watcher);
+}
+
+
+QRgb ImageAnalyzer::lastResults()
+{
+ int rTot = 0;
+ int bTot = 0;
+ int gTot = 0;
+ int count = m_watcher->future().results().size();
+ foreach(const QRgb & triplet, m_watcher->future().results())
+ {
+ rTot += qRed(triplet);
+ bTot += qBlue(triplet);
+ gTot += qGreen(triplet);
+ }
+ return qRgb(rTot/count, bTot/count, gTot/count);
+}
+
+float ImageAnalyzer::lastRed() { return qRed(lastResults())/2.55; }
+float ImageAnalyzer::lastGreen() { return qGreen(lastResults())/2.55; }
+float ImageAnalyzer::lastBlue() { return qBlue(lastResults())/2.55; }
+
+void ImageAnalyzer::progressStatus(int newstat)
+{
+ emit updateProgress(newstat, m_watcher->progressMaximum());
+}
+
+
+bool ImageAnalyzer::isBusy()
+{
+ return m_watcher->isRunning();
+}
+
+
+//! [ ImageAnalyzer - startAnalysis ]
+void ImageAnalyzer::startAnalysis(const QStringList & urls)
+{
+ m_URLQueue = urls;
+ fetchURLs();
+}
+//! [ ImageAnalyzer - startAnalysis ]
+
+/*!
+ * Analyzes the entire queue - just starts all our http GETs.
+ */
+//! [ ImageAnalyzer - fetchURLs ]
+void ImageAnalyzer::fetchURLs()
+{
+ while (!m_URLQueue.isEmpty())
+ {
+ QString url = m_URLQueue.takeFirst();
+ QUrl URL = QUrl(url);
+ QIODevice * pData = m_cache->data(URL);
+ // Is image already loaded in cache?
+ if (pData == 0) {
+ // HTTP Get image over network.
+ m_outstandingFetches++;
+ QNetworkRequest request = QNetworkRequest(URL);
+ request.setRawHeader("User-Agent", "Nokia - Custom QT app");
+ m_network->get(request);
+ } else {
+ // Get image from cache
+ QImage image;
+ image.load(pData, 0);
+ if (!image.isNull())
+ queueImage(image);
+ delete(pData);
+ }
+ }
+}
+//! [ ImageAnalyzer - fetchURLs ]
+/*
+ * Slot to handle the incoming responses from our http GETs
+ */
+//! [ ImageAnalyzer - handleReply ]
+void ImageAnalyzer::handleReply(QNetworkReply * pReply)
+{
+ m_outstandingFetches--;
+ if (pReply->error()) {
+ qDebug() << "Error code" << pReply->error();
+ qDebug() << "Http code" << pReply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
+ return;
+ }
+ QImage image;
+ image.load(pReply, 0);
+ pReply->deleteLater();
+ if (image.isNull()) {
+ qDebug() << "bad image";
+ qDebug() << pReply->rawHeaderList();
+ foreach(QByteArray element, pReply->rawHeaderList()) {
+ qDebug() << element << " = " << pReply->rawHeader(element);
+ }
+ return;
+ }
+ queueImage(image);
+}
+//! [ ImageAnalyzer - handleReply ]
+
+void ImageAnalyzer::doneProcessing()
+{
+ m_imageQueue = QList<QImage>();
+ emit finishedAnalysis();
+}
+//! [ ImageAnalyzer - queueImage ]
+void ImageAnalyzer::queueImage(QImage img)
+{
+ if (!img.isNull())
+ m_imageQueue << img;
+
+ if (m_outstandingFetches == 0 && m_URLQueue.isEmpty()) {
+ m_watcher->setFuture(QtConcurrent::mapped(m_imageQueue, averageRGB));
+ }
+}
+//! [ ImageAnalyzer - queueImage ]
+
+//! [ ImageAnalyzer - averageRGB ]
+QRgb averageRGB(const QImage &img)
+{
+ int pixelCount = img.width() * img.height();
+ int rAvg, gAvg, bAvg;
+
+ // We waste some time here:
+ for (int timeWaster=0; timeWaster < 100; timeWaster++) {
+ quint64 rTot = 0;
+ quint64 gTot = 0;
+ quint64 bTot = 0;
+ for (int i=0; i < img.width(); i++) {
+ for (int j=0; j < img.height(); j++) {
+ QRgb pixel = img.pixel(i,j);
+ rTot += qRed(pixel);
+ gTot += qGreen(pixel);
+ bTot += qBlue(pixel);
+ }
+ }
+ rAvg = (rTot)/(pixelCount);
+ gAvg = (gTot)/(pixelCount);
+ bAvg = (bTot)/(pixelCount);
+ }
+ return qRgb(rAvg, gAvg, bAvg);
+}
+//! [ ImageAnalyzer - averageRGB ]
diff --git a/examples/webkit/imageanalyzer/imageanalyzer.h b/examples/webkit/imageanalyzer/imageanalyzer.h
new file mode 100644
index 0000000..1bb25dc
--- /dev/null
+++ b/examples/webkit/imageanalyzer/imageanalyzer.h
@@ -0,0 +1,101 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
+#ifndef IMAGEANALYZER_H
+#define IMAGEANALYZER_H
+#include <QFutureWatcher>
+#include <QtGui>
+
+class QNetworkAccessManager;
+class QNetworkReply;
+class QNetworkDiskCache;
+
+//! [ ImageAnalyzer - public interface ]
+class ImageAnalyzer : public QObject
+{
+ Q_OBJECT
+public:
+ ImageAnalyzer(QNetworkDiskCache * netcache, QObject * parent=0);
+
+ QRgb lastResults();
+ float lastRed();
+ float lastGreen();
+ float lastBlue();
+ bool isBusy();
+ Q_PROPERTY(bool busy READ isBusy);
+ Q_PROPERTY(float red READ lastRed);
+ Q_PROPERTY(float green READ lastGreen);
+ Q_PROPERTY(float blue READ lastBlue);
+ ~ImageAnalyzer();
+
+public slots:
+ /*! initiates analysis of all the urls in the list */
+ void startAnalysis(const QStringList & urls);
+
+signals:
+ void finishedAnalysis();
+ void updateProgress(int completed, int total);
+ //! [ ImageAnalyzer - public interface ]
+
+private slots:
+ void handleReply(QNetworkReply*);
+ void doneProcessing();
+ void progressStatus(int);
+
+private:
+ QRgb processImages();
+ void fetchURLs();
+ void queueImage(QImage img);
+
+ //! [ ImageAnalyzer - private members ]
+private:
+ QNetworkAccessManager* m_network;
+ QNetworkDiskCache* m_cache;
+ QStringList m_URLQueue;
+ QList<QImage> m_imageQueue;
+ int m_outstandingFetches;
+ QFutureWatcher<QRgb> * m_watcher;
+ //! [ ImageAnalyzer - private members ]
+};
+
+QRgb averageRGB(const QImage &img);
+
+#endif
diff --git a/examples/webkit/imageanalyzer/imageanalyzer.pro b/examples/webkit/imageanalyzer/imageanalyzer.pro
new file mode 100644
index 0000000..c9a0ed1
--- /dev/null
+++ b/examples/webkit/imageanalyzer/imageanalyzer.pro
@@ -0,0 +1,14 @@
+TEMPLATE = app
+HEADERS = imageanalyzer.h \
+ mainwindow.h
+SOURCES = imageanalyzer.cpp \
+ main.cpp \
+ mainwindow.cpp
+
+QT += network webkit
+
+RESOURCES = resources/imageanalyzer.qrc
+
+OTHER_FILES += html/index.html README ../webkit-bridge-tutorial.qdoc outline.txt
+
+
diff --git a/examples/webkit/imageanalyzer/main.cpp b/examples/webkit/imageanalyzer/main.cpp
new file mode 100644
index 0000000..c3f04de
--- /dev/null
+++ b/examples/webkit/imageanalyzer/main.cpp
@@ -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 examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
+#include "imageanalyzer.h"
+#include "mainwindow.h"
+
+int main(int argc, char* argv[])
+{
+ QApplication app(argc, argv);
+
+ MainWin win;
+ win.show();
+ return app.exec();
+}
+
diff --git a/examples/webkit/imageanalyzer/mainwindow.cpp b/examples/webkit/imageanalyzer/mainwindow.cpp
new file mode 100644
index 0000000..d89098e
--- /dev/null
+++ b/examples/webkit/imageanalyzer/mainwindow.cpp
@@ -0,0 +1,80 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include "mainwindow.h"
+#include "imageanalyzer.h"
+
+#include <QWebFrame>
+#include <QWebElementCollection>
+#include <QNetworkDiskCache>
+
+/*
+ * Default Constructor
+ */
+//! [MainWindow - constructor]
+MainWin::MainWin(QWidget * parent) : QWebView(parent)
+{
+ m_network = new QNetworkAccessManager(this);
+ m_cache = new QNetworkDiskCache(this);
+ m_cache->setCacheDirectory(QDesktopServices::storageLocation(QDesktopServices::CacheLocation) + "/imageanalyzer");
+ m_cache->setMaximumCacheSize(1000000); //set the cache to 10megs
+ m_network->setCache(m_cache);
+ page()->setNetworkAccessManager(m_network);
+
+ //! The object we will expose to JavaScript engine:
+ m_analyzer = new ImageAnalyzer(m_cache, this);
+
+ // Signal is emitted before frame loads any web content:
+ QObject::connect(page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()),
+ this, SLOT(addJSObject()));
+
+ // qrc:// URLs refer to resources. See imagenalayzer.qrc
+ QUrl startURL = QUrl("qrc:/index.html");
+
+ // Load web content now!
+ setUrl(startURL);
+}
+//! [MainWindow - constructor]
+
+//! [MainWindow - addJSObject]
+void MainWin::addJSObject() {
+ // Add pAnalyzer to JavaScript Frame as member "imageAnalyzer".
+ page()->mainFrame()->addToJavaScriptWindowObject(QString("imageAnalyzer"), m_analyzer);
+}
+//! [MainWindow - addJSObject]
diff --git a/examples/webkit/imageanalyzer/mainwindow.h b/examples/webkit/imageanalyzer/mainwindow.h
new file mode 100644
index 0000000..076e586
--- /dev/null
+++ b/examples/webkit/imageanalyzer/mainwindow.h
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QWebView>
+
+class ImageAnalyzer;
+class QNetworkDiskCache;
+
+class MainWin : public QWebView
+{
+ Q_OBJECT
+
+public:
+ explicit MainWin(QWidget * parent = 0);
+
+private:
+ ImageAnalyzer * m_analyzer;
+ QNetworkAccessManager * m_network;
+ QNetworkDiskCache * m_cache;
+
+private slots:
+ void addJSObject();
+
+};
+#endif
diff --git a/examples/webkit/imageanalyzer/resources/imageanalyzer.qrc b/examples/webkit/imageanalyzer/resources/imageanalyzer.qrc
new file mode 100644
index 0000000..fe9a5df
--- /dev/null
+++ b/examples/webkit/imageanalyzer/resources/imageanalyzer.qrc
@@ -0,0 +1,10 @@
+<!DOCTYPE RCC><RCC version="1.0">
+ <qresource>
+ <file>index.html</file>
+ <file>images/mtRainier.jpg</file>
+ <file>images/bellaCoola.jpg</file>
+ <file>images/trees.jpg</file>
+ <file>images/flower.jpg</file>
+ <file>images/seaShell.jpg</file>
+</qresource>
+</RCC>
diff --git a/examples/webkit/imageanalyzer/resources/images/README b/examples/webkit/imageanalyzer/resources/images/README
new file mode 100644
index 0000000..176a1da
--- /dev/null
+++ b/examples/webkit/imageanalyzer/resources/images/README
@@ -0,0 +1,2 @@
+The images are under public domain and were obtained from
+http://publicdomainpictures.net
diff --git a/examples/webkit/imageanalyzer/resources/images/bellaCoola.jpg b/examples/webkit/imageanalyzer/resources/images/bellaCoola.jpg
new file mode 100644
index 0000000..f90ed54
--- /dev/null
+++ b/examples/webkit/imageanalyzer/resources/images/bellaCoola.jpg
Binary files differ
diff --git a/examples/webkit/imageanalyzer/resources/images/flower.jpg b/examples/webkit/imageanalyzer/resources/images/flower.jpg
new file mode 100644
index 0000000..6b7f6be
--- /dev/null
+++ b/examples/webkit/imageanalyzer/resources/images/flower.jpg
Binary files differ
diff --git a/examples/webkit/imageanalyzer/resources/images/mtRainier.jpg b/examples/webkit/imageanalyzer/resources/images/mtRainier.jpg
new file mode 100644
index 0000000..d09a3f2
--- /dev/null
+++ b/examples/webkit/imageanalyzer/resources/images/mtRainier.jpg
Binary files differ
diff --git a/examples/webkit/imageanalyzer/resources/images/seaShell.jpg b/examples/webkit/imageanalyzer/resources/images/seaShell.jpg
new file mode 100644
index 0000000..c5005a9
--- /dev/null
+++ b/examples/webkit/imageanalyzer/resources/images/seaShell.jpg
Binary files differ
diff --git a/examples/webkit/imageanalyzer/resources/images/trees.jpg b/examples/webkit/imageanalyzer/resources/images/trees.jpg
new file mode 100644
index 0000000..083b26d
--- /dev/null
+++ b/examples/webkit/imageanalyzer/resources/images/trees.jpg
Binary files differ
diff --git a/examples/webkit/imageanalyzer/resources/index.html b/examples/webkit/imageanalyzer/resources/index.html
new file mode 100644
index 0000000..6532951
--- /dev/null
+++ b/examples/webkit/imageanalyzer/resources/index.html
@@ -0,0 +1,133 @@
+
+<html>
+ <body>
+ <!-- [ images list ] -->
+ <div style="float:right; width:50%; border-left: solid 1px black">
+ <div id="listdiv" align="center">
+ <h5>Images to be analyzed:</h5>
+ <select multiple size=10 id=imglist style="width:80%"></select>
+ <br />
+ <input type="button" id="evalbutton" value="Analyze" onclick="analyzeImages()" />
+ </div>
+ </div>
+ <!-- [ images list ] -->
+ <div style="width:50%">
+ <div id="titleblock" align="center">
+ <h2>Image Analyzer</h2>
+ </div>
+ <div id=outputdiv align=center>
+ <h4>Status: <span id=status>Idle</span></h4>
+ <h5>
+ Latest Results:<br />
+ Red: <span id=redval style="color:red">n/a</span><br />
+ Green: <span id=greenval style="color:green">n/a</span><br />
+ Blue: <span id=blueval style="color:blue">n/a</span><br />
+ </h5>
+ <h3>Click on images below to select for analysis</h3>
+ </div>
+ </div>
+ <!-- [ sample images ] -->
+ <div id=imagediv style="clear:both; text-align:center">
+ <hr/>
+ <img src="images/mtRainier.jpg" height=150px onclick='return addImage(this);' />
+ <img src="images/bellaCoola.jpg" height=150px onclick='return addImage(this);'/>
+ <img src="images/seaShell.jpg" height=150px onclick='return addImage(this);'/>
+ <!-- [ sample images ] -->
+ <img src="images/flower.jpg" height=150px onclick='return addImage(this);'/>
+ <img src="images/trees.jpg" height=150px onclick='return addImage(this);'/>
+ </div>
+
+ </body>
+</html>
+
+<script type="text/javascript">
+ var remaining = 0;
+ var connected = false;
+ //We use this function because connect statements resolve their target once, imediately
+ //not at signal emission so they must be connected once the imageAnalyzer object has been added to the frame
+ //! <!-- [ connect slots ] -->
+ function connectSlots()
+ {
+ if ( !connected ) {
+ connected = true;
+ imageAnalyzer.finishedAnalysis.connect(this, finished);
+ imageAnalyzer.updateProgress.connect(this, updateProg);
+ }
+ }
+ //! <!-- [ connect slots ] -->
+
+ function finished() {
+ setStatus('Idle');
+ setResults(imageAnalyzer.red.toFixed(2), imageAnalyzer.green.toFixed(2), imageAnalyzer.blue.toFixed(2));
+ }
+ //This will function as the recieving "slot" for the progress signal
+ function updateProg(complete, max)
+ {
+ var oldRemaining = remaining;
+ remaining = max - complete;
+ pullList(oldRemaining - remaining);
+ //Prevent results getting messed up if we don't get signals in order
+ if( imageAnalyzer.busy ) {
+ setStatus('Processing (' + complete + ' of ' + max + ' completed)');
+ setResults('Calculating','Calculating','Calculating');
+ }
+ }
+
+//! <!-- [ analyzeImages ] -->
+function analyzeImages() {
+ connectSlots();
+ var imglist = document.getElementsByTagName('option');
+ if (imglist.length > 0) {
+ stringlist = [];
+ for(var i=0; i<imglist.length; i++) {
+ stringlist[i]=imglist[i].value;
+ }
+ if (!imageAnalyzer.busy) {
+ remaining = stringlist.length;
+ imageAnalyzer.startAnalysis(stringlist);
+ } else {
+ alert("Processing, please wait until finished.");
+ }
+//! <!-- [ analyzeImages ] -->
+ } else {
+ alert('No images selected. Click on one or more images to select them for analysis.');
+ }
+}
+function clearList() {
+ var imglist = document.getElementById('imglist');
+ while(imglist.length > 0) {
+ imglist.removeChild(imglist.childNodes[0]);
+ }
+}
+function pullList(count) {
+ var imglist = document.getElementById('imglist');
+ while(imglist.length > 0 && count > 0) {
+ imglist.removeChild(imglist.childNodes[0]);
+ count--;
+ }
+}
+function setStatus(statusString) {
+ document.getElementById('status').innerHTML = statusString;
+}
+
+function setResults(red, green, blue) {
+ if (! isNaN(red) ) { red += " %"; }
+ if (! isNaN(green) ) { green += " %"; }
+ if (! isNaN(blue) ) { blue += " %"; }
+ document.getElementById('redval').innerHTML = red;
+ document.getElementById('greenval').innerHTML = green;
+ document.getElementById('blueval').innerHTML = blue;
+}
+//! <!-- [ addImage ] -->
+function addImage(newimg) {
+ var imglist = document.getElementById('imglist');
+ var curChildren = imglist.childNodes;
+ var newline = document.createElement('option');
+ newline.innerHTML = newimg.src.substring(newimg.src.lastIndexOf('/')+1);
+ newline.value = newimg.src;
+ imglist.appendChild(newline);
+}
+//! <!-- [ addImage ] -->
+</script>
+
+
diff --git a/examples/webkit/webkit.pro b/examples/webkit/webkit.pro
index 76c8801..6a1d8f8 100644
--- a/examples/webkit/webkit.pro
+++ b/examples/webkit/webkit.pro
@@ -4,6 +4,7 @@ SUBDIRS += domtraversal \
previewer \
fancybrowser \
simpleselector \
+ imageanalyzer \
framecapture
contains(QT_CONFIG, openssl):SUBDIRS += googlechat