summaryrefslogtreecommitdiffstats
path: root/Source/WebKit/qt/docs/webkitsnippets
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebKit/qt/docs/webkitsnippets')
-rw-r--r--Source/WebKit/qt/docs/webkitsnippets/qtwebkit_bridge_snippets.cpp174
-rw-r--r--Source/WebKit/qt/docs/webkitsnippets/qtwebkit_build_snippet.qdoc8
-rw-r--r--Source/WebKit/qt/docs/webkitsnippets/qtwebkit_qwebinspector_snippet.cpp15
-rw-r--r--Source/WebKit/qt/docs/webkitsnippets/qtwebkit_qwebview_snippet.cpp35
-rw-r--r--Source/WebKit/qt/docs/webkitsnippets/simple/main.cpp34
-rw-r--r--Source/WebKit/qt/docs/webkitsnippets/simple/simple.pro2
-rw-r--r--Source/WebKit/qt/docs/webkitsnippets/webelement/main.cpp125
-rw-r--r--Source/WebKit/qt/docs/webkitsnippets/webelement/webelement.pro8
-rw-r--r--Source/WebKit/qt/docs/webkitsnippets/webpage/main.cpp81
-rw-r--r--Source/WebKit/qt/docs/webkitsnippets/webpage/webpage.pro3
10 files changed, 485 insertions, 0 deletions
diff --git a/Source/WebKit/qt/docs/webkitsnippets/qtwebkit_bridge_snippets.cpp b/Source/WebKit/qt/docs/webkitsnippets/qtwebkit_bridge_snippets.cpp
new file mode 100644
index 0000000..75aa0a9
--- /dev/null
+++ b/Source/WebKit/qt/docs/webkitsnippets/qtwebkit_bridge_snippets.cpp
@@ -0,0 +1,174 @@
+
+void wrapInFunction()
+{
+
+ //! [0]
+ // ...
+ QWebFrame *frame = myWebPage->mainFrame();
+ frame->addToJavaScriptWindowObject("someNameForMyObject", myObject);
+ // ...
+ //! [0]
+#if 0
+ //! [1]
+ {
+ width: ...,
+ height: ...,
+ toDataURL: function() { ... },
+ assignToHTMLImageElement: function(element) { ... }
+ }
+ //! [1]
+#endif
+ //! [2]
+ class MyObject : QObject {
+ Q_OBJECT
+ Q_PROPERTY(QPixmap myPixmap READ getPixmap)
+
+ public:
+ QPixmap getPixmap() const;
+ };
+
+ /* ... */
+
+ MyObject myObject;
+ myWebPage.mainFrame()->addToJavaScriptWindowObject("myObject", &myObject);
+
+ //! [2]
+#if 0
+ //! [3]
+ <html>
+ <head>
+ <script>
+ function loadImage()
+ {
+ myObject.myPixmap.assignToHTMLImageElement(document.getElementById("imageElement"));
+ }
+ </script>
+ </head>
+ <body onload="loadImage()">
+ <img id="imageElement" width="300" height="200" />
+ </body>
+ </html>
+//! [3]
+#endif
+//! [4]
+class MyObject : QObject {
+ Q_OBJECT
+
+ public slots:
+ void doSomethingWithWebElement(const QWebElement&);
+ };
+
+ /* ... */
+
+ MyObject myObject;
+ myWebPage.mainFrame()->addToJavaScriptWindowObject("myObject", &myObject);
+
+ //! [4]
+#if 0
+ //! [5]
+ <html>
+ <head>
+ <script>
+ function runExample() {
+ myObject.doSomethingWithWebElement(document.getElementById("someElement"));
+ }
+ </script>
+ </head>
+ <body onload="runExample()">
+ <span id="someElement">Text</span>
+ </body>
+ </html>
+ //! [5]
+ //! [6]
+ connect(function);
+ //! [6]
+ //! [7]
+ function myInterestingScriptFunction() { ... }
+ ...
+ myQObject.somethingChanged.connect(myInterestingScriptFunction);
+ //! [7]
+ //! [8]
+ myQObject.somethingChanged.connect(myOtherQObject.doSomething);
+ //! [8]
+ //! [9]
+ myQObject.somethingChanged.disconnect(myInterestingFunction);
+ myQObject.somethingChanged.disconnect(myOtherQObject.doSomething);
+ //! [9]
+ //! [10]
+ myQObject.somethingChanged.connect(thisObject, function)
+ //! [10]
+ //! [11]
+ var form = { x: 123 };
+ var onClicked = function() { print(this.x); };
+ myButton.clicked.connect(form, onClicked);
+ //! [11]
+ //! [12]
+ myQObject.somethingChanged.disconnect(thisObject, function);
+ //! [12]
+ //! [13]
+ connect(function);
+ //! [13]
+ //! [14]
+ myQObject.somethingChanged.connect(thisObject, "functionName")
+ //! [14]
+ //! [15]
+ var obj = { x: 123, fun: function() { print(this.x); } };
+ myQObject.somethingChanged.connect(obj, "fun");
+ //! [15]
+ //! [16]
+ connect(function);
+ //! [16]
+ //! [17]
+ myQObject.somethingChanged.disconnect(thisObject, "functionName");
+ //! [17]
+ //! [18]
+ try {
+ myQObject.somethingChanged.connect(myQObject, "slotThatDoesntExist");
+ } catch (e) {
+ print(e);
+ }
+ //! [18]
+ //! [19]
+ myQObject.somethingChanged("hello");
+ //! [19]
+ //! [20]
+ myQObject.myOverloadedSlot(10); // will call the int overload
+ myQObject.myOverloadedSlot("10"); // will call the QString overload
+ //! [20]
+ //! [21]
+ myQObject['myOverloadedSlot(int)']("10"); // call int overload; the argument is converted to an int
+ myQObject['myOverloadedSlot(QString)'](10); // call QString overload; the argument is converted to a string
+ //! [21]
+ //! [22]
+ class MyObject : public QObject
+ {
+ Q_OBJECT
+
+ public:
+ Q_INVOKABLE void thisMethodIsInvokableInJavaScript();
+ void thisMethodIsNotInvokableInJavaScript();
+
+ ...
+ };
+ //! [22]
+ //! [23]
+ Q_PROPERTY(bool enabled READ enabled WRITE setEnabled)
+ //! [23]
+ //! [24]
+ myQObject.enabled = true;
+
+ ...
+
+ myQObject.enabled = !myQObject.enabled;
+ //! [24]
+ //! [25]
+ myDialog.okButton
+ //! [25]
+ //! [26]
+ myDialog.okButton
+ myDialog.okButton.objectName = "cancelButton";
+ // from now on, myDialog.cancelButton references the button
+ //! [26]
+#endif
+}
+
diff --git a/Source/WebKit/qt/docs/webkitsnippets/qtwebkit_build_snippet.qdoc b/Source/WebKit/qt/docs/webkitsnippets/qtwebkit_build_snippet.qdoc
new file mode 100644
index 0000000..d4fc2bd
--- /dev/null
+++ b/Source/WebKit/qt/docs/webkitsnippets/qtwebkit_build_snippet.qdoc
@@ -0,0 +1,8 @@
+//! [0]
+QT += webkit
+//! [0]
+
+
+//! [1]
+#include <QtWebKit>
+//! [1]
diff --git a/Source/WebKit/qt/docs/webkitsnippets/qtwebkit_qwebinspector_snippet.cpp b/Source/WebKit/qt/docs/webkitsnippets/qtwebkit_qwebinspector_snippet.cpp
new file mode 100644
index 0000000..07f1d45
--- /dev/null
+++ b/Source/WebKit/qt/docs/webkitsnippets/qtwebkit_qwebinspector_snippet.cpp
@@ -0,0 +1,15 @@
+
+void wrapInFunction()
+{
+
+//! [0]
+ // ...
+ QWebPage *page = new QWebPage;
+ // ...
+
+ QWebInspector *inspector = new QWebInspector;
+ inspector->setPage(page);
+//! [0]
+
+}
+
diff --git a/Source/WebKit/qt/docs/webkitsnippets/qtwebkit_qwebview_snippet.cpp b/Source/WebKit/qt/docs/webkitsnippets/qtwebkit_qwebview_snippet.cpp
new file mode 100644
index 0000000..f04cd29
--- /dev/null
+++ b/Source/WebKit/qt/docs/webkitsnippets/qtwebkit_qwebview_snippet.cpp
@@ -0,0 +1,35 @@
+
+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/Source/WebKit/qt/docs/webkitsnippets/simple/main.cpp b/Source/WebKit/qt/docs/webkitsnippets/simple/main.cpp
new file mode 100644
index 0000000..408630e
--- /dev/null
+++ b/Source/WebKit/qt/docs/webkitsnippets/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/Source/WebKit/qt/docs/webkitsnippets/simple/simple.pro b/Source/WebKit/qt/docs/webkitsnippets/simple/simple.pro
new file mode 100644
index 0000000..61cd3bf
--- /dev/null
+++ b/Source/WebKit/qt/docs/webkitsnippets/simple/simple.pro
@@ -0,0 +1,2 @@
+QT += webkit
+SOURCES = main.cpp
diff --git a/Source/WebKit/qt/docs/webkitsnippets/webelement/main.cpp b/Source/WebKit/qt/docs/webkitsnippets/webelement/main.cpp
new file mode 100644
index 0000000..b1781a6
--- /dev/null
+++ b/Source/WebKit/qt/docs/webkitsnippets/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/Source/WebKit/qt/docs/webkitsnippets/webelement/webelement.pro b/Source/WebKit/qt/docs/webkitsnippets/webelement/webelement.pro
new file mode 100644
index 0000000..8ca4b59
--- /dev/null
+++ b/Source/WebKit/qt/docs/webkitsnippets/webelement/webelement.pro
@@ -0,0 +1,8 @@
+TEMPLATE = app
+CONFIG -= app_bundle
+CONFIG(QTDIR_build) {
+ QT += webkit
+}
+SOURCES = main.cpp
+include(../../../../../WebKit.pri)
+QMAKE_RPATHDIR = $$OUTPUT_DIR/lib $$QMAKE_RPATHDIR
diff --git a/Source/WebKit/qt/docs/webkitsnippets/webpage/main.cpp b/Source/WebKit/qt/docs/webkitsnippets/webpage/main.cpp
new file mode 100644
index 0000000..393b16a
--- /dev/null
+++ b/Source/WebKit/qt/docs/webkitsnippets/webpage/main.cpp
@@ -0,0 +1,81 @@
+/*
+ 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 <QtGui>
+#include <QWebPage>
+#include <QWebFrame>
+
+//! [0]
+class Thumbnailer : public QObject
+{
+ Q_OBJECT
+
+public:
+ Thumbnailer(const QUrl &url);
+
+signals:
+ void finished();
+
+private 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/Source/WebKit/qt/docs/webkitsnippets/webpage/webpage.pro b/Source/WebKit/qt/docs/webkitsnippets/webpage/webpage.pro
new file mode 100644
index 0000000..fcad03b
--- /dev/null
+++ b/Source/WebKit/qt/docs/webkitsnippets/webpage/webpage.pro
@@ -0,0 +1,3 @@
+CONFIG += console
+QT += webkit
+SOURCES = main.cpp \ No newline at end of file