diff options
Diffstat (limited to 'examples/webkit')
-rw-r--r-- | examples/webkit/fancybrowser/fancybrowser.pro | 4 | ||||
-rw-r--r-- | examples/webkit/fancybrowser/mainwindow.cpp | 1 | ||||
-rw-r--r-- | examples/webkit/fancybrowser/mainwindow.h | 2 | ||||
-rwxr-xr-x | examples/webkit/formextractor/form.html | 24 | ||||
-rw-r--r-- | examples/webkit/formextractor/formextractor.cpp | 29 | ||||
-rw-r--r-- | examples/webkit/formextractor/formextractor.h | 4 | ||||
-rw-r--r-- | examples/webkit/formextractor/formextractor.pro | 7 | ||||
-rw-r--r-- | examples/webkit/formextractor/mainwindow.cpp | 3 | ||||
-rw-r--r-- | examples/webkit/framecapture/framecapture.cpp | 121 | ||||
-rw-r--r-- | examples/webkit/framecapture/framecapture.h | 70 | ||||
-rw-r--r-- | examples/webkit/framecapture/framecapture.pro | 11 | ||||
-rw-r--r-- | examples/webkit/framecapture/main.cpp | 76 | ||||
-rw-r--r-- | examples/webkit/googlechat/googlechat.pro | 4 | ||||
-rw-r--r-- | examples/webkit/previewer/mainwindow.cpp | 6 | ||||
-rw-r--r-- | examples/webkit/previewer/previewer.pro | 7 | ||||
-rw-r--r-- | examples/webkit/webkit.pro | 2 |
16 files changed, 330 insertions, 41 deletions
diff --git a/examples/webkit/fancybrowser/fancybrowser.pro b/examples/webkit/fancybrowser/fancybrowser.pro index 3de3036284..e496241cde 100644 --- a/examples/webkit/fancybrowser/fancybrowser.pro +++ b/examples/webkit/fancybrowser/fancybrowser.pro @@ -1,4 +1,4 @@ -QT += webkit +QT += webkit network HEADERS = mainwindow.h SOURCES = main.cpp \ mainwindow.cpp @@ -9,3 +9,5 @@ target.path = $$[QT_INSTALL_EXAMPLES]/webkit/fancybrowser sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro sources.path = $$[QT_INSTALL_EXAMPLES]/webkit/fancybrowser INSTALLS += target sources + +symbian:TARGET.UID3 = 0xA000CF6C diff --git a/examples/webkit/fancybrowser/mainwindow.cpp b/examples/webkit/fancybrowser/mainwindow.cpp index a5d989cbb4..ecca36b814 100644 --- a/examples/webkit/fancybrowser/mainwindow.cpp +++ b/examples/webkit/fancybrowser/mainwindow.cpp @@ -94,6 +94,7 @@ MainWindow::MainWindow() toolsMenu->addAction(tr("Remove all embedded elements"), this, SLOT(removeEmbeddedElements())); setCentralWidget(view); + setUnifiedTitleAndToolBarOnMac(true); } //! [3] diff --git a/examples/webkit/fancybrowser/mainwindow.h b/examples/webkit/fancybrowser/mainwindow.h index c2d0368697..6b0c72d6cb 100644 --- a/examples/webkit/fancybrowser/mainwindow.h +++ b/examples/webkit/fancybrowser/mainwindow.h @@ -41,8 +41,8 @@ #include <QtGui> -QT_BEGIN_NAMESPACE class QWebView; +QT_BEGIN_NAMESPACE class QLineEdit; QT_END_NAMESPACE diff --git a/examples/webkit/formextractor/form.html b/examples/webkit/formextractor/form.html index 18ddff1e87..6b0bbde976 100755 --- a/examples/webkit/formextractor/form.html +++ b/examples/webkit/formextractor/form.html @@ -1,22 +1,4 @@ -<html><script> -function extractFormValues() -{ - var firstName = document.getElementById("firstname").value; - var lastName = document.getElementById("lastname").value; - var maleGender = document.getElementById("genderMale"); - var femaleGender = document.getElementById("genderFemale"); - - var gender = ""; - if (maleGender.checked) - gender = maleGender.value; - else if (femaleGender.checked) - gender = femaleGender.value; - - var updates = document.getElementById("updates").checked; - - formExtractor.setValues(firstName, lastName, gender, updates); -} -</script><body> +<html><body> <h1> The Green People Book Club </h1> @@ -24,7 +6,7 @@ The Green People Book Club <p> Welcome to The Green People Book Club. Please register to obtain a membership with us. </p> - <form onsubmit="extractFormValues()"> + <form onsubmit="formExtractor.submit()"> <table> <tbody><tr> <td> @@ -61,4 +43,4 @@ Welcome to The Green People Book Club. Please register to obtain a membership wi <input type="submit" value="Submit"> </form> -</body></html>
\ No newline at end of file +</body></html> diff --git a/examples/webkit/formextractor/formextractor.cpp b/examples/webkit/formextractor/formextractor.cpp index e1d31e8a0c..c0d4063d1c 100644 --- a/examples/webkit/formextractor/formextractor.cpp +++ b/examples/webkit/formextractor/formextractor.cpp @@ -41,6 +41,8 @@ #include "formextractor.h" +#include <QWebElement> + FormExtractor::FormExtractor(QWidget *parent, Qt::WFlags flags) : QWidget(parent, flags) { @@ -55,17 +57,28 @@ FormExtractor::~FormExtractor() { } -void FormExtractor::setValues(const QString &firstName, const QString &lastName, - const QString &gender, bool updates) +void FormExtractor::submit() { - ui.firstNameEdit->setText(firstName); - ui.lastNameEdit->setText(lastName); - ui.genderEdit->setText(gender); + QWebFrame *frame = ui.webView->page()->mainFrame(); - if (updates == false) - ui.updatesEdit->setText("No"); - else + QWebElement firstName = frame->findFirstElement("#firstname"); + QWebElement lastName = frame->findFirstElement("#lastname"); + QWebElement maleGender = frame->findFirstElement("#genderMale"); + QWebElement femaleGender = frame->findFirstElement("#genderFemale"); + QWebElement updates = frame->findFirstElement("#updates"); + + ui.firstNameEdit->setText(firstName.scriptableProperty("value").toString()); + ui.lastNameEdit->setText(lastName.scriptableProperty("value").toString()); + + if (maleGender.scriptableProperty("checked").toBool()) + ui.genderEdit->setText(maleGender.scriptableProperty("value").toString()); + else if (femaleGender.scriptableProperty("checked").toBool()) + ui.genderEdit->setText(femaleGender.scriptableProperty("value").toString()); + + if (updates.scriptableProperty("checked").toBool()) ui.updatesEdit->setText("Yes"); + else + ui.updatesEdit->setText("No"); } void FormExtractor::populateJavaScriptWindowObject() diff --git a/examples/webkit/formextractor/formextractor.h b/examples/webkit/formextractor/formextractor.h index 9aba404c48..a3d67acc6d 100644 --- a/examples/webkit/formextractor/formextractor.h +++ b/examples/webkit/formextractor/formextractor.h @@ -55,9 +55,7 @@ public: ~FormExtractor(); public slots: - void setValues(const QString &firstName, const QString &lastName, - const QString &gender, bool updates); - + void submit(); void populateJavaScriptWindowObject(); private: diff --git a/examples/webkit/formextractor/formextractor.pro b/examples/webkit/formextractor/formextractor.pro index d2cb240d59..ba9c72fce1 100644 --- a/examples/webkit/formextractor/formextractor.pro +++ b/examples/webkit/formextractor/formextractor.pro @@ -1,4 +1,4 @@ -QT += webkit +QT += webkit network TARGET = formExtractor TEMPLATE = app SOURCES += main.cpp \ @@ -14,3 +14,8 @@ target.path = $$[QT_INSTALL_EXAMPLES]/webkit/formextractor sources.files = $$SOURCES $$HEADERS $$FORMS $$RESOURCES *.pro form.html images sources.path = $$[QT_INSTALL_EXAMPLES]/webkit/formextractor INSTALLS += target sources + +symbian { + include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) + TARGET.UID3 = 0xA000CF6D +} diff --git a/examples/webkit/formextractor/mainwindow.cpp b/examples/webkit/formextractor/mainwindow.cpp index dde9e39c7f..7bf8b6b88c 100644 --- a/examples/webkit/formextractor/mainwindow.cpp +++ b/examples/webkit/formextractor/mainwindow.cpp @@ -48,13 +48,14 @@ MainWindow::MainWindow() createMenus(); centralWidget = new FormExtractor(this); setCentralWidget(centralWidget); + setUnifiedTitleAndToolBarOnMac(true); } void MainWindow::createActions() { exitAct = new QAction(tr("E&xit"), this); exitAct->setStatusTip(tr("Exit the application")); - exitAct->setShortcut(tr("Ctrl+Q")); + exitAct->setShortcuts(QKeySequence::Quit); connect(exitAct, SIGNAL(triggered()), this, SLOT(close())); aboutAct = new QAction(tr("&About"), this); diff --git a/examples/webkit/framecapture/framecapture.cpp b/examples/webkit/framecapture/framecapture.cpp new file mode 100644 index 0000000000..a241142ed7 --- /dev/null +++ b/examples/webkit/framecapture/framecapture.cpp @@ -0,0 +1,121 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "framecapture.h" + +#include <iostream> +#include <QtWebKit> + +FrameCapture::FrameCapture(): QObject(), m_percent(0) +{ + connect(&m_page, SIGNAL(loadProgress(int)), this, SLOT(printProgress(int))); + connect(&m_page, SIGNAL(loadFinished(bool)), this, SLOT(saveResult(bool))); +} + +void FrameCapture::load(const QUrl &url, const QString &outputFileName) +{ + std::cout << "Loading " << qPrintable(url.toString()) << std::endl; + m_percent = 0; + int index = outputFileName.lastIndexOf('.'); + m_fileName = (index == -1) ? outputFileName + ".png" : outputFileName; + m_page.mainFrame()->load(url); + m_page.mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff); + m_page.mainFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff); +} + +void FrameCapture::printProgress(int percent) +{ + if (m_percent >= percent) + return; + + while (m_percent++ < percent) + std::cout << "#" << std::flush; +} + +void FrameCapture::saveResult(bool ok) +{ + std::cout << std::endl; + + // crude error-checking + if (!ok) { + std::cerr << "Failed loading " << qPrintable(m_page.mainFrame()->url().toString()) << std::endl; + emit finished(); + return; + } + + // save each internal frame in different image files + int frameCounter = 0; + foreach(QWebFrame *frame, m_page.mainFrame()->childFrames()) { + QString fileName(m_fileName); + int index = m_fileName.lastIndexOf('.'); + fileName = fileName.insert(index, "_frame" + QString::number(++frameCounter)); + + frame->setClipRenderToViewport(false); + + QImage image(frame->contentsSize(), QImage::Format_ARGB32_Premultiplied); + image.fill(Qt::transparent); + + saveFrame(frame, image, fileName); + } + + // save the main frame + m_page.setViewportSize(m_page.mainFrame()->contentsSize()); + QImage image(m_page.mainFrame()->contentsSize(), QImage::Format_ARGB32_Premultiplied); + image.fill(Qt::transparent); + saveFrame(m_page.mainFrame(), image, m_fileName); + + emit finished(); +} + +void FrameCapture::saveFrame(QWebFrame *frame, QImage image, QString fileName) +{ + QPainter painter(&image); + painter.setRenderHint(QPainter::Antialiasing, true); + painter.setRenderHint(QPainter::TextAntialiasing, true); + painter.setRenderHint(QPainter::SmoothPixmapTransform, true); + + frame->render(&painter); + + painter.end(); + + image.save(fileName); +} + diff --git a/examples/webkit/framecapture/framecapture.h b/examples/webkit/framecapture/framecapture.h new file mode 100644 index 0000000000..5b887de78d --- /dev/null +++ b/examples/webkit/framecapture/framecapture.h @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef FRAMECAPTURE_H +#define FRAMECAPTURE_H + +#include <QtWebKit> + +class FrameCapture : public QObject +{ + Q_OBJECT + +public: + FrameCapture(); + void load(const QUrl &url, const QString &outputFileName); + +signals: + void finished(); + +private slots: + void printProgress(int percent); + void saveResult(bool ok); + +private: + QWebPage m_page; + QString m_fileName; + int m_percent; + + void saveFrame(QWebFrame *frame, QImage image, QString fileName); +}; + +#endif diff --git a/examples/webkit/framecapture/framecapture.pro b/examples/webkit/framecapture/framecapture.pro new file mode 100644 index 0000000000..6f2f0934a5 --- /dev/null +++ b/examples/webkit/framecapture/framecapture.pro @@ -0,0 +1,11 @@ +QT += webkit + +HEADERS = framecapture.h +SOURCES = main.cpp \ + framecapture.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/webkit/framecapture +sources.files = $$SOURCES $$HEADERS +sources.path = $$[QT_INSTALL_EXAMPLES]/webkit/framecapture +INSTALLS += target sources diff --git a/examples/webkit/framecapture/main.cpp b/examples/webkit/framecapture/main.cpp new file mode 100644 index 0000000000..0de5e14564 --- /dev/null +++ b/examples/webkit/framecapture/main.cpp @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "framecapture.h" + +#include <iostream> +#include <QtGui> + +int main(int argc, char * argv[]) +{ + if (argc != 3) { + std::cout << "Capture a web page and save its internal frames in different images" << std::endl << std::endl; + std::cout << " framecapture <url> <outputfile>" << std::endl; + std::cout << std::endl; + std::cout << "Notes:" << std::endl; + std::cout << " 'url' is the URL of the web page to be captured" << std::endl; + std::cout << " 'outputfile' is the prefix of the image files to be generated" << std::endl; + std::cout << std::endl; + std::cout << "Example: " << std::endl; + std::cout << " framecapture qt.nokia.com trolltech.png" << std::endl; + std::cout << std::endl; + std::cout << "Result:" << std::endl; + std::cout << " trolltech.png (full page)" << std::endl; + std::cout << " trolltech_frame1.png (...) trolltech_frameN.png ('N' number of internal frames)" << std::endl; + return 0; + } + + QUrl url = QWebView::guessUrlFromString(QString::fromLatin1(argv[1])); + QString fileName = QString::fromLatin1(argv[2]); + + QApplication a(argc, argv); + FrameCapture capture; + QObject::connect(&capture, SIGNAL(finished()), QApplication::instance(), SLOT(quit())); + capture.load(url, fileName); + + return a.exec(); +} + diff --git a/examples/webkit/googlechat/googlechat.pro b/examples/webkit/googlechat/googlechat.pro index 14b7085a82..8e4f9a6fc8 100644 --- a/examples/webkit/googlechat/googlechat.pro +++ b/examples/webkit/googlechat/googlechat.pro @@ -1,4 +1,4 @@ -QT += webkit +QT += webkit network HEADERS = googlechat.h SOURCES = main.cpp \ googlechat.cpp @@ -9,3 +9,5 @@ target.path = $$[QT_INSTALL_EXAMPLES]/webkit/googlechat sources.files = $$SOURCES $$HEADERS $$FORMS *.pro sources.path = $$[QT_INSTALL_EXAMPLES]/webkit/googlechat INSTALLS += target sources + +symbian:TARGET.UID3 = 0xA000CF6E diff --git a/examples/webkit/previewer/mainwindow.cpp b/examples/webkit/previewer/mainwindow.cpp index 150d7de18c..88fe167d6d 100644 --- a/examples/webkit/previewer/mainwindow.cpp +++ b/examples/webkit/previewer/mainwindow.cpp @@ -61,7 +61,7 @@ MainWindow::MainWindow() void MainWindow::createActions() { openAct = new QAction(tr("&Open..."), this); - openAct->setShortcut(tr("Ctrl+O")); + openAct->setShortcuts(QKeySequence::Open); openAct->setStatusTip(tr("Open an existing HTML file")); connect(openAct, SIGNAL(triggered()), this, SLOT(open())); @@ -72,13 +72,13 @@ void MainWindow::createActions() //! [1] saveAct = new QAction(tr("&Save"), this); - saveAct->setShortcut(tr("Ctrl+S")); + saveAct->setShortcuts(QKeySequence::Save); saveAct->setStatusTip(tr("Save the HTML file to disk")); connect(saveAct, SIGNAL(triggered()), this, SLOT(save())); exitAct = new QAction(tr("E&xit"), this); exitAct->setStatusTip(tr("Exit the application")); - exitAct->setShortcut(tr("Ctrl+Q")); + exitAct->setShortcuts(QKeySequence::Quit); connect(exitAct, SIGNAL(triggered()), this, SLOT(close())); aboutAct = new QAction(tr("&About"), this); diff --git a/examples/webkit/previewer/previewer.pro b/examples/webkit/previewer/previewer.pro index 75ab6fbaaa..c3088a2ea2 100644 --- a/examples/webkit/previewer/previewer.pro +++ b/examples/webkit/previewer/previewer.pro @@ -1,4 +1,4 @@ -QT += webkit +QT += webkit network HEADERS = previewer.h \ mainwindow.h SOURCES = main.cpp \ @@ -11,3 +11,8 @@ target.path = $$[QT_INSTALL_EXAMPLES]/webkit/previewer sources.files = $$SOURCES $$HEADERS $$FORMS $$RESOURCES *.pro images sources.path = $$[QT_INSTALL_EXAMPLES]/webkit/previewer INSTALLS += target sources + +symbian { + include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) + TARGET.UID3 = 0xA000CF6F +} diff --git a/examples/webkit/webkit.pro b/examples/webkit/webkit.pro index 225816adac..9ad6789b98 100644 --- a/examples/webkit/webkit.pro +++ b/examples/webkit/webkit.pro @@ -9,3 +9,5 @@ target.path = $$[QT_INSTALL_EXAMPLES]/webkit sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS webkit.pro README sources.path = $$[QT_INSTALL_EXAMPLES]/webkit INSTALLS += target sources + +symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) |