summaryrefslogtreecommitdiffstats
path: root/src/webenginewidgets/doc/snippets
diff options
context:
space:
mode:
Diffstat (limited to 'src/webenginewidgets/doc/snippets')
-rw-r--r--src/webenginewidgets/doc/snippets/qtwebengine_build_snippet.qdoc8
-rw-r--r--src/webenginewidgets/doc/snippets/qtwebengine_qwebengineinspector_snippet.cpp38
-rw-r--r--src/webenginewidgets/doc/snippets/qtwebengine_qwebengineview_snippet.cpp58
-rw-r--r--src/webenginewidgets/doc/snippets/simple/main.cpp34
-rw-r--r--src/webenginewidgets/doc/snippets/simple/simple.pro2
-rw-r--r--src/webenginewidgets/doc/snippets/webelement/main.cpp125
-rw-r--r--src/webenginewidgets/doc/snippets/webelement/webelement.pro2
-rw-r--r--src/webenginewidgets/doc/snippets/webpage/main.cpp82
-rw-r--r--src/webenginewidgets/doc/snippets/webpage/webpage.pro3
9 files changed, 352 insertions, 0 deletions
diff --git a/src/webenginewidgets/doc/snippets/qtwebengine_build_snippet.qdoc b/src/webenginewidgets/doc/snippets/qtwebengine_build_snippet.qdoc
new file mode 100644
index 000000000..d4fc2bd85
--- /dev/null
+++ b/src/webenginewidgets/doc/snippets/qtwebengine_build_snippet.qdoc
@@ -0,0 +1,8 @@
+//! [0]
+QT += webkit
+//! [0]
+
+
+//! [1]
+#include <QtWebKit>
+//! [1]
diff --git a/src/webenginewidgets/doc/snippets/qtwebengine_qwebengineinspector_snippet.cpp b/src/webenginewidgets/doc/snippets/qtwebengine_qwebengineinspector_snippet.cpp
new file mode 100644
index 000000000..5e57de027
--- /dev/null
+++ b/src/webenginewidgets/doc/snippets/qtwebengine_qwebengineinspector_snippet.cpp
@@ -0,0 +1,38 @@
+/*
+ Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. 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.
+
+ THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS 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 APPLE INC. OR ITS 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.
+*/
+
+void wrapInFunction()
+{
+
+//! [0]
+ // ...
+ QWebPage *page = new QWebPage;
+ // ...
+
+ QWebInspector *inspector = new QWebInspector;
+ inspector->setPage(page);
+//! [0]
+
+}
+
diff --git a/src/webenginewidgets/doc/snippets/qtwebengine_qwebengineview_snippet.cpp b/src/webenginewidgets/doc/snippets/qtwebengine_qwebengineview_snippet.cpp
new file mode 100644
index 000000000..2bf43b848
--- /dev/null
+++ b/src/webenginewidgets/doc/snippets/qtwebengine_qwebengineview_snippet.cpp
@@ -0,0 +1,58 @@
+/*
+ Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. 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.
+
+ THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS 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 APPLE INC. OR ITS 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.
+*/
+
+void wrapInFunction()
+{
+
+//! [0]
+ view->page()->history();
+//! [0]
+
+
+//! [1]
+ view->page()->settings();
+//! [1]
+
+
+//! [2]
+ view->triggerAction(QWebPage::Copy);
+//! [2]
+
+
+//! [3]
+ view->page()->triggerPageAction(QWebPage::Stop);
+//! [3]
+
+
+//! [4]
+ view->page()->triggerPageAction(QWebPage::GoBack);
+//! [4]
+
+
+//! [5]
+ view->page()->triggerPageAction(QWebPage::GoForward);
+//! [5]
+
+}
+
diff --git a/src/webenginewidgets/doc/snippets/simple/main.cpp b/src/webenginewidgets/doc/snippets/simple/main.cpp
new file mode 100644
index 000000000..408630eb1
--- /dev/null
+++ b/src/webenginewidgets/doc/snippets/simple/main.cpp
@@ -0,0 +1,34 @@
+/*
+ Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies)
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include <QApplication>
+#include <QUrl>
+#include <QWebView>
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ QWidget *parent = 0;
+//! [Using QWebView]
+ QWebView *view = new QWebView(parent);
+ view->load(QUrl("http://qt.nokia.com/"));
+ view->show();
+//! [Using QWebView]
+ return app.exec();
+}
diff --git a/src/webenginewidgets/doc/snippets/simple/simple.pro b/src/webenginewidgets/doc/snippets/simple/simple.pro
new file mode 100644
index 000000000..7fe095809
--- /dev/null
+++ b/src/webenginewidgets/doc/snippets/simple/simple.pro
@@ -0,0 +1,2 @@
+QT += webkitwidgets
+SOURCES = main.cpp
diff --git a/src/webenginewidgets/doc/snippets/webelement/main.cpp b/src/webenginewidgets/doc/snippets/webelement/main.cpp
new file mode 100644
index 000000000..b1781a6f4
--- /dev/null
+++ b/src/webenginewidgets/doc/snippets/webelement/main.cpp
@@ -0,0 +1,125 @@
+/*
+ Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies)
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include <QApplication>
+#include <QUrl>
+#include <qwebview.h>
+#include <qwebframe.h>
+#include <qwebelement.h>
+
+static QWebFrame *frame;
+
+static void traverse()
+{
+//! [Traversing with QWebElement]
+ frame->setHtml("<html><body><p>First Paragraph</p><p>Second Paragraph</p></body></html>");
+ QWebElement doc = frame->documentElement();
+ QWebElement body = doc.firstChild();
+ QWebElement firstParagraph = body.firstChild();
+ QWebElement secondParagraph = firstParagraph.nextSibling();
+//! [Traversing with QWebElement]
+}
+
+static void findButtonAndClick()
+{
+
+ frame->setHtml("<form name=\"myform\" action=\"submit_form.asp\" method=\"get\">"
+ "<input type=\"text\" name=\"myfield\">"
+ "<input type=\"submit\" value=\"Submit\">"
+ "</form>");
+
+//! [Calling a DOM element method]
+
+ QWebElement document = frame->documentElement();
+ /* Assume that the document has the following structure:
+
+ <form name="myform" action="submit_form.asp" method="get">
+ <input type="text" name="myfield">
+ <input type="submit" value="Submit">
+ </form>
+
+ */
+
+ QWebElement button = document.findFirst("input[type=submit]");
+ button.evaluateJavaScript("click()");
+
+//! [Calling a DOM element method]
+
+ }
+
+static void autocomplete1()
+{
+ QWebElement document = frame->documentElement();
+
+//! [autocomplete1]
+ QWebElement firstTextInput = document.findFirst("input[type=text]");
+ QString storedText = firstTextInput.attribute("value");
+//! [autocomplete1]
+
+}
+
+
+static void autocomplete2()
+{
+
+ QWebElement document = frame->documentElement();
+ QString storedText = "text";
+
+//! [autocomplete2]
+ QWebElement firstTextInput = document.findFirst("input[type=text]");
+ textInput.setAttribute("value", storedText);
+//! [autocomplete2]
+
+}
+
+
+static void findAll()
+{
+//! [FindAll]
+ QWebElement document = frame->documentElement();
+ /* Assume the document has the following structure:
+
+ <p class=intro>
+ <span>Intro</span>
+ <span>Snippets</span>
+ </p>
+ <p>
+ <span>Content</span>
+ <span>Here</span>
+ </p>
+ */
+
+//! [FindAll intro]
+ QWebElementCollection allSpans = document.findAll("span");
+ QWebElementCollection introSpans = document.findAll("p.intro span");
+//! [FindAll intro] //! [FindAll]
+}
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ QWebView *view = new QWebView(0);
+ frame = view->page()->mainFrame();
+ traverse();
+ findAll();
+ findButtonAndClick();
+ autocomplete1();
+ autocomplete2();
+ return 0;
+}
diff --git a/src/webenginewidgets/doc/snippets/webelement/webelement.pro b/src/webenginewidgets/doc/snippets/webelement/webelement.pro
new file mode 100644
index 000000000..fbe701314
--- /dev/null
+++ b/src/webenginewidgets/doc/snippets/webelement/webelement.pro
@@ -0,0 +1,2 @@
+TEMPLATE = app
+SOURCES = main.cpp
diff --git a/src/webenginewidgets/doc/snippets/webpage/main.cpp b/src/webenginewidgets/doc/snippets/webpage/main.cpp
new file mode 100644
index 000000000..daeed2bc6
--- /dev/null
+++ b/src/webenginewidgets/doc/snippets/webpage/main.cpp
@@ -0,0 +1,82 @@
+/*
+ Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies)
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include <QApplication>
+#include <QPainter>
+#include <QWebFrame>
+#include <QWebPage>
+
+//! [0]
+class Thumbnailer : public QObject
+{
+ Q_OBJECT
+
+public:
+ Thumbnailer(const QUrl &url);
+
+Q_SIGNALS:
+ void finished();
+
+private Q_SLOTS:
+ void render();
+
+private:
+ QWebPage page;
+
+};
+//! [0]
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ Thumbnailer thumbnail(QUrl("http://qt.nokia.com"));
+
+ QObject::connect(&thumbnail, SIGNAL(finished()),
+ &app, SLOT(quit()));
+
+ return app.exec();
+}
+
+//! [1]
+Thumbnailer::Thumbnailer(const QUrl &url)
+{
+ page.mainFrame()->load(url);
+ connect(&page, SIGNAL(loadFinished(bool)),
+ this, SLOT(render()));
+}
+//! [1]
+
+//! [2]
+void Thumbnailer::render()
+{
+ page.setViewportSize(page.mainFrame()->contentsSize());
+ QImage image(page.viewportSize(), QImage::Format_ARGB32);
+ QPainter painter(&image);
+
+ page.mainFrame()->render(&painter);
+ painter.end();
+
+ QImage thumbnail = image.scaled(400, 400);
+ thumbnail.save("thumbnail.png");
+
+ emit finished();
+}
+//! [2]
+#include "main.moc"
diff --git a/src/webenginewidgets/doc/snippets/webpage/webpage.pro b/src/webenginewidgets/doc/snippets/webpage/webpage.pro
new file mode 100644
index 000000000..8d9c6938e
--- /dev/null
+++ b/src/webenginewidgets/doc/snippets/webpage/webpage.pro
@@ -0,0 +1,3 @@
+CONFIG += console
+QT += webkitwidgets
+SOURCES = main.cpp