From d46b4208147ec01aba19c703f21954f068b4dc06 Mon Sep 17 00:00:00 2001 From: David Boddie Date: Mon, 9 Nov 2009 19:38:35 +0100 Subject: Doc: Added an example to demonstrate the QWebElement class. Reviewed-by: Trust Me --- doc/src/diagrams/webkit-simpleselector.png | Bin 0 -> 82564 bytes doc/src/images/webkit-simpleselector.png | Bin 0 -> 130292 bytes doc/src/qt4-intro.qdoc | 6 +- examples/webkit/simpleselector/main.cpp | 54 +++++++++++++++ examples/webkit/simpleselector/simpleselector.pro | 11 +++ examples/webkit/simpleselector/window.cpp | 81 ++++++++++++++++++++++ examples/webkit/simpleselector/window.h | 64 +++++++++++++++++ examples/webkit/simpleselector/window.ui | 72 +++++++++++++++++++ examples/webkit/webkit.pro | 3 +- src/gui/kernel/qwidget.cpp | 11 +++ src/gui/kernel/qwidget.h | 4 ++ 11 files changed, 300 insertions(+), 6 deletions(-) create mode 100644 doc/src/diagrams/webkit-simpleselector.png create mode 100644 doc/src/images/webkit-simpleselector.png create mode 100644 examples/webkit/simpleselector/main.cpp create mode 100644 examples/webkit/simpleselector/simpleselector.pro create mode 100644 examples/webkit/simpleselector/window.cpp create mode 100644 examples/webkit/simpleselector/window.h create mode 100644 examples/webkit/simpleselector/window.ui diff --git a/doc/src/diagrams/webkit-simpleselector.png b/doc/src/diagrams/webkit-simpleselector.png new file mode 100644 index 0000000..e442f97 Binary files /dev/null and b/doc/src/diagrams/webkit-simpleselector.png differ diff --git a/doc/src/images/webkit-simpleselector.png b/doc/src/images/webkit-simpleselector.png new file mode 100644 index 0000000..2c888ca Binary files /dev/null and b/doc/src/images/webkit-simpleselector.png differ diff --git a/doc/src/qt4-intro.qdoc b/doc/src/qt4-intro.qdoc index 4911426..0871e51 100644 --- a/doc/src/qt4-intro.qdoc +++ b/doc/src/qt4-intro.qdoc @@ -581,11 +581,7 @@ DOM, helps reuse CSS selector knowledge, and gives little maintenance or footprint overhead. - \code - QWebElement document = frame->documentElement(); - QList allSpans = document.findAll("span"); - QList introSpans = document.findAll("p.intro span"); - \endcode + \snippet webkitsnippets/webelement/main.cpp FindAll intro See the QWebElement class documentation for more information. diff --git a/examples/webkit/simpleselector/main.cpp b/examples/webkit/simpleselector/main.cpp new file mode 100644 index 0000000..74c5469 --- /dev/null +++ b/examples/webkit/simpleselector/main.cpp @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** Copyright (C) 2009 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: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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [main program] +#include +#include "window.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + Window window; + window.setUrl(QUrl("http://www.webkit.org")); + window.show(); + return app.exec(); +} +//! [main program] diff --git a/examples/webkit/simpleselector/simpleselector.pro b/examples/webkit/simpleselector/simpleselector.pro new file mode 100644 index 0000000..3f3037f --- /dev/null +++ b/examples/webkit/simpleselector/simpleselector.pro @@ -0,0 +1,11 @@ +QT += webkit +FORMS = window.ui +HEADERS = window.h +SOURCES = main.cpp \ + window.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/webkit/simpleselector +sources.files = $$SOURCES $$HEADERS $$FORMS $$RESOURCES *.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/webkit/simpleselector +INSTALLS += target sources diff --git a/examples/webkit/simpleselector/window.cpp b/examples/webkit/simpleselector/window.cpp new file mode 100644 index 0000000..295ab7f --- /dev/null +++ b/examples/webkit/simpleselector/window.cpp @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2009 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: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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include "window.h" + +//! [Window class constructor] +Window::Window(QWidget *parent) + : QWidget(parent) +{ + setupUi(this); +} +//! [Window class constructor] + +//! [return pressed] +void Window::on_elementLineEdit_returnPressed() +{ + QWebFrame *frame = webView->page()->mainFrame(); + +//! [select elements] + QWebElement document = frame->documentElement(); + QList elements = document.findAll(elementLineEdit->text()); +//! [select elements] + + foreach (QWebElement element, elements) + element.setAttribute("style", "background-color: #f0f090"); +} +//! [return pressed] + +//! [button clicked] +void Window::on_highlightButton_clicked() +{ + on_elementLineEdit_returnPressed(); +} +//! [button clicked] + +//! [set URL] +void Window::setUrl(const QUrl &url) +{ + webView->setUrl(url); +} +//! [set URL] diff --git a/examples/webkit/simpleselector/window.h b/examples/webkit/simpleselector/window.h new file mode 100644 index 0000000..437d360 --- /dev/null +++ b/examples/webkit/simpleselector/window.h @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2009 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: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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef WINDOW_H +#define WINDOW_H + +#include +#include +#include "ui_window.h" + +//! [Window class definition] +class Window : public QWidget, private Ui::Window +{ + Q_OBJECT + +public: + Window(QWidget *parent = 0); + void setUrl(const QUrl &url); + +public slots: + void on_elementLineEdit_returnPressed(); + void on_highlightButton_clicked(); +}; +//! [Window class definition] + +#endif diff --git a/examples/webkit/simpleselector/window.ui b/examples/webkit/simpleselector/window.ui new file mode 100644 index 0000000..aa824df --- /dev/null +++ b/examples/webkit/simpleselector/window.ui @@ -0,0 +1,72 @@ + + + Window + + + + 0 + 0 + 640 + 480 + + + + Web Element Selector + + + + + + + http://webkit.org/ + + + + + + + + + + QFormLayout::ExpandingFieldsGrow + + + + + &Element: + + + elementLineEdit + + + + + + + li a + + + + + + + + + &Highlight + + + + + + + + + + QWebView + QWidget +
QtWebKit/QWebView
+
+
+ + +
diff --git a/examples/webkit/webkit.pro b/examples/webkit/webkit.pro index 0a1d6bd..47c1443 100644 --- a/examples/webkit/webkit.pro +++ b/examples/webkit/webkit.pro @@ -1,7 +1,8 @@ TEMPLATE = subdirs SUBDIRS += formextractor \ previewer \ - fancybrowser + fancybrowser \ + simpleselector contains(QT_CONFIG, openssl):SUBDIRS += googlechat diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp index f856b13..185fa4e 100644 --- a/src/gui/kernel/qwidget.cpp +++ b/src/gui/kernel/qwidget.cpp @@ -11462,6 +11462,17 @@ void QWidget::languageChange() { } // compat \sa QWidget::setMaximumSize() */ +/*! + \fn QWidget::setupUi(QWidget *widget) + + Sets up the user interface for the specified \a widget. + + \note This function is available with widgets that derive from user + interface descriptions created using \l{uic}. + + \sa {Using a Designer UI File in Your Application} +*/ + QRect QWidgetPrivate::frameStrut() const { Q_Q(const QWidget); diff --git a/src/gui/kernel/qwidget.h b/src/gui/kernel/qwidget.h index b7c55f9..5ba1d23 100644 --- a/src/gui/kernel/qwidget.h +++ b/src/gui/kernel/qwidget.h @@ -288,6 +288,10 @@ public: void setMaximumWidth(int maxw); void setMaximumHeight(int maxh); +#ifdef Q_QDOC + void setupUi(QWidget *widget); +#endif + QSize sizeIncrement() const; void setSizeIncrement(const QSize &); void setSizeIncrement(int w, int h); -- cgit v0.12