diff options
author | axis <qt-info@nokia.com> | 2009-04-24 11:34:15 (GMT) |
---|---|---|
committer | axis <qt-info@nokia.com> | 2009-04-24 11:34:15 (GMT) |
commit | 8f427b2b914d5b575a4a7c0ed65d2fb8f45acc76 (patch) | |
tree | a17e1a767a89542ab59907462206d7dcf2e504b2 /examples/webkit/formextractor | |
download | Qt-8f427b2b914d5b575a4a7c0ed65d2fb8f45acc76.zip Qt-8f427b2b914d5b575a4a7c0ed65d2fb8f45acc76.tar.gz Qt-8f427b2b914d5b575a4a7c0ed65d2fb8f45acc76.tar.bz2 |
Long live Qt for S60!
Diffstat (limited to 'examples/webkit/formextractor')
-rwxr-xr-x | examples/webkit/formextractor/form.html | 64 | ||||
-rw-r--r-- | examples/webkit/formextractor/formextractor.cpp | 74 | ||||
-rw-r--r-- | examples/webkit/formextractor/formextractor.h | 67 | ||||
-rw-r--r-- | examples/webkit/formextractor/formextractor.pro | 18 | ||||
-rw-r--r-- | examples/webkit/formextractor/formextractor.qrc | 5 | ||||
-rw-r--r-- | examples/webkit/formextractor/formextractor.ui | 159 | ||||
-rw-r--r-- | examples/webkit/formextractor/main.cpp | 53 | ||||
-rw-r--r-- | examples/webkit/formextractor/mainwindow.cpp | 87 | ||||
-rw-r--r-- | examples/webkit/formextractor/mainwindow.h | 75 |
9 files changed, 602 insertions, 0 deletions
diff --git a/examples/webkit/formextractor/form.html b/examples/webkit/formextractor/form.html new file mode 100755 index 0000000..18ddff1 --- /dev/null +++ b/examples/webkit/formextractor/form.html @@ -0,0 +1,64 @@ +<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> +<h1> +The Green People Book Club +</h1> + +<p> +Welcome to The Green People Book Club. Please register to obtain a membership with us. +</p> + <form onsubmit="extractFormValues()"> + <table> + <tbody><tr> + <td> + First name: + </td> + <td> + <input type="text" id="firstname"> + </td> + </tr> + <tr> + <td> + Last name: + </td> + <td> + <input type="text" id="lastname"> + </td> + </tr> + <tr> + <td> + Gender: + </td> + <td> + <input type="radio" name="gender" id="genderMale" value="Male"> Male + <input type="radio" name="gender" id="genderFemale" value="Female"> Female + </td> + </tr> + <tr> + <td colspan="2"> + <input type="checkbox" id="updates" value="receive"> + Check here if you would like to receive regular updates from us: + </td> + </tr> + </tbody></table> + <input type="submit" value="Submit"> + </form> + +</body></html>
\ No newline at end of file diff --git a/examples/webkit/formextractor/formextractor.cpp b/examples/webkit/formextractor/formextractor.cpp new file mode 100644 index 0000000..d5ecc29 --- /dev/null +++ b/examples/webkit/formextractor/formextractor.cpp @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "formextractor.h" + +FormExtractor::FormExtractor(QWidget *parent, Qt::WFlags flags) + : QWidget(parent, flags) +{ + ui.setupUi(this); + ui.webView->setUrl(QUrl("qrc:/form.html")); + connect(ui.webView->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), + this, SLOT(populateJavaScriptWindowObject())); + resize(300, 300); +} + +FormExtractor::~FormExtractor() +{ +} + +void FormExtractor::setValues(const QString &firstName, const QString &lastName, + const QString &gender, bool updates) +{ + ui.firstNameEdit->setText(firstName); + ui.lastNameEdit->setText(lastName); + ui.genderEdit->setText(gender); + + if (updates == false) + ui.updatesEdit->setText("No"); + else + ui.updatesEdit->setText("Yes"); +} + +void FormExtractor::populateJavaScriptWindowObject() +{ + ui.webView->page()->mainFrame()->addToJavaScriptWindowObject("formExtractor", this); +} diff --git a/examples/webkit/formextractor/formextractor.h b/examples/webkit/formextractor/formextractor.h new file mode 100644 index 0000000..5b11565 --- /dev/null +++ b/examples/webkit/formextractor/formextractor.h @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef FORMEXTRACTOR_H +#define FORMEXTRACTOR_H + +#include <QtGui/QWidget> +#include <QWebFrame> +#include "ui_formextractor.h" + +class FormExtractor : public QWidget +{ + Q_OBJECT + +public: + FormExtractor(QWidget *parent = 0, Qt::WFlags flags = 0); + ~FormExtractor(); + +public slots: + void setValues(const QString &firstName, const QString &lastName, + const QString &gender, bool updates); + + void populateJavaScriptWindowObject(); + +private: + Ui::Form ui; +}; + +#endif // FORMEXTRACTOR_H diff --git a/examples/webkit/formextractor/formextractor.pro b/examples/webkit/formextractor/formextractor.pro new file mode 100644 index 0000000..ddd39b4 --- /dev/null +++ b/examples/webkit/formextractor/formextractor.pro @@ -0,0 +1,18 @@ +QT += webkit +TARGET = formExtractor +TEMPLATE = app +SOURCES += main.cpp \ + formextractor.cpp \ + mainwindow.cpp +HEADERS += formextractor.h \ + mainwindow.h +FORMS += formextractor.ui +RESOURCES += formextractor.qrc + +# install +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 + +include($$QT_SOURCE_TREE/examples/examplebase.pri) diff --git a/examples/webkit/formextractor/formextractor.qrc b/examples/webkit/formextractor/formextractor.qrc new file mode 100644 index 0000000..e35f4b2 --- /dev/null +++ b/examples/webkit/formextractor/formextractor.qrc @@ -0,0 +1,5 @@ +<!DOCTYPE RCC><RCC version="1.0"> + <qresource> + <file>form.html</file> + </qresource> + </RCC>
\ No newline at end of file diff --git a/examples/webkit/formextractor/formextractor.ui b/examples/webkit/formextractor/formextractor.ui new file mode 100644 index 0000000..5c4afec --- /dev/null +++ b/examples/webkit/formextractor/formextractor.ui @@ -0,0 +1,159 @@ +<ui version="4.0" > + <class>Form</class> + <widget class="QWidget" name="Form" > + <property name="geometry" > + <rect> + <x>0</x> + <y>0</y> + <width>680</width> + <height>218</height> + </rect> + </property> + <property name="windowTitle" > + <string>Form</string> + </property> + <layout class="QHBoxLayout" name="horizontalLayout" > + <item> + <widget class="QGroupBox" name="webFormGroupBox" > + <property name="title" > + <string>Web Form</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout_2" > + <item> + <layout class="QVBoxLayout" name="verticalLayout" > + <item> + <widget class="QWebView" name="webView" > + <property name="minimumSize" > + <size> + <width>200</width> + <height>150</height> + </size> + </property> + <property name="maximumSize" > + <size> + <width>400</width> + <height>16777215</height> + </size> + </property> + <property name="url" > + <url> + <string>about:blank</string> + </url> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </widget> + </item> + <item> + <spacer name="horizontalSpacer" > + <property name="orientation" > + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0" > + <size> + <width>28</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QGroupBox" name="dataGroupBox" > + <property name="title" > + <string>Extracted Data</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout_3" > + <item> + <layout class="QFormLayout" name="formLayout" > + <property name="fieldGrowthPolicy" > + <enum>QFormLayout::FieldsStayAtSizeHint</enum> + </property> + <item row="0" column="0" > + <widget class="QLabel" name="firstNameLabel" > + <property name="text" > + <string>First Name</string> + </property> + </widget> + </item> + <item row="0" column="1" > + <widget class="QLineEdit" name="firstNameEdit" > + <property name="readOnly" > + <bool>true</bool> + </property> + </widget> + </item> + <item row="1" column="0" > + <widget class="QLabel" name="lastNameLabel" > + <property name="text" > + <string>Last Name</string> + </property> + </widget> + </item> + <item row="1" column="1" > + <widget class="QLineEdit" name="lastNameEdit" > + <property name="readOnly" > + <bool>true</bool> + </property> + </widget> + </item> + <item row="2" column="0" > + <widget class="QLabel" name="genderLabel" > + <property name="text" > + <string>Gender</string> + </property> + </widget> + </item> + <item row="2" column="1" > + <widget class="QLineEdit" name="genderEdit" > + <property name="readOnly" > + <bool>true</bool> + </property> + </widget> + </item> + <item row="3" column="0" > + <widget class="QLabel" name="updatesLabel" > + <property name="text" > + <string>Receive Updates</string> + </property> + </widget> + </item> + <item row="3" column="1" > + <widget class="QLineEdit" name="updatesEdit" > + <property name="readOnly" > + <bool>true</bool> + </property> + </widget> + </item> + </layout> + </item> + <item> + <spacer name="verticalSpacer" > + <property name="orientation" > + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0" > + <size> + <width>20</width> + <height>24</height> + </size> + </property> + </spacer> + </item> + </layout> + </widget> + </item> + </layout> + </widget> + <customwidgets> + <customwidget> + <class>QWebView</class> + <extends>QWidget</extends> + <header>QtWebKit/QWebView</header> + </customwidget> + </customwidgets> + <resources/> + <connections/> +</ui> diff --git a/examples/webkit/formextractor/main.cpp b/examples/webkit/formextractor/main.cpp new file mode 100644 index 0000000..aa7847d --- /dev/null +++ b/examples/webkit/formextractor/main.cpp @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui/QApplication> +#include "mainwindow.h" + +int main(int argc, char *argv[]) +{ + Q_INIT_RESOURCE(formextractor); + QApplication app(argc, argv); + MainWindow mainWindow; + mainWindow.setWindowTitle("Form Extractor"); + mainWindow.show(); + return app.exec(); +} diff --git a/examples/webkit/formextractor/mainwindow.cpp b/examples/webkit/formextractor/mainwindow.cpp new file mode 100644 index 0000000..222d9b2 --- /dev/null +++ b/examples/webkit/formextractor/mainwindow.cpp @@ -0,0 +1,87 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> +#include "mainwindow.h" + +MainWindow::MainWindow() +{ + createActions(); + createMenus(); + centralWidget = new FormExtractor(this); + setCentralWidget(centralWidget); +} + +void MainWindow::createActions() +{ + exitAct = new QAction(tr("E&xit"), this); + exitAct->setStatusTip(tr("Exit the application")); + exitAct->setShortcut(tr("Ctrl+Q")); + connect(exitAct, SIGNAL(triggered()), this, SLOT(close())); + + aboutAct = new QAction(tr("&About"), this); + aboutAct->setStatusTip(tr("Show the application's About box")); + connect(aboutAct, SIGNAL(triggered()), this, SLOT(about())); + + aboutQtAct = new QAction(tr("About &Qt"), this); + aboutQtAct->setStatusTip(tr("Show the Qt library's About box")); + connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt())); +} + +void MainWindow::createMenus() +{ + fileMenu = menuBar()->addMenu(tr("&File")); + fileMenu->addAction(exitAct); + + menuBar()->addSeparator(); + + helpMenu = menuBar()->addMenu(tr("&Help")); + helpMenu->addAction(aboutAct); + helpMenu->addAction(aboutQtAct); +} + +void MainWindow::about() +{ + QMessageBox::about(this, tr("About Form Extractor"), + tr("The <b>Form Extractor</b> example demonstrates how to " + "extract data from a web form using QtWebKit.")); + +} diff --git a/examples/webkit/formextractor/mainwindow.h b/examples/webkit/formextractor/mainwindow.h new file mode 100644 index 0000000..7918870 --- /dev/null +++ b/examples/webkit/formextractor/mainwindow.h @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include <QMainWindow> +#include "formextractor.h" + +QT_BEGIN_NAMESPACE +class QAction; +class QMenu; +QT_END_NAMESPACE + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(); + +private slots: + void about(); + +private: + FormExtractor *centralWidget; + QMenu *fileMenu; + QMenu *helpMenu; + QAction *exitAct; + QAction *aboutAct; + QAction *aboutQtAct; + + void createActions(); + void createMenus(); +}; + +#endif // MAINWINDOW_H |