diff --git a/examples/widgets/fancybrowser/doc/src/fancybrowser.qdoc b/examples/widgets/fancybrowser/doc/src/fancybrowser.qdoc index 937b00d30483924971e7d38bfd550f376780e6db..c1de06332bd05f29d4c9882ce7a6dcc8a76e9e4f 100644 --- a/examples/widgets/fancybrowser/doc/src/fancybrowser.qdoc +++ b/examples/widgets/fancybrowser/doc/src/fancybrowser.qdoc @@ -26,19 +26,19 @@ ****************************************************************************/ /*! - \example webkitwidgets/fancybrowser + \example webengine/fancybrowser \title Fancy Browser Example \brief Demonstrates how to use browse web and manipulate content - \ingroup webkit-widgetexamples + \ingroup webengine-widgetexamples - \brief The Fancy Browser example shows how to use JQuery with QtWebKit to + \brief The Fancy Browser example shows how to use JQuery with QtWebEngine to create a web browser with special effects and content manipulation. \image fancybrowser-example.png - The application makes use of QWebFrame::evaluateJavaScript to - evaluate the jQuery JavaScript code. A QMainWindow with a QWebView + The application makes use of QWebEnginePage::evaluateJavaScript to + evaluate the jQuery JavaScript code. A QMainWindow with a QWebEngineView as central widget builds up the browser itself. \section1 MainWindow Class Definition @@ -46,7 +46,7 @@ The \c MainWindow class inherits QMainWindow. It implements a number of slots to perform actions on both the application and on the web content. - \snippet webkitwidgets/fancybrowser/mainwindow.h 1 + \snippet webenginewidgets/fancybrowser/mainwindow.h 1 We also declare a QString that contains the jQuery, a QWebView that displays the web content, and a QLineEdit that acts as the @@ -56,7 +56,7 @@ We start by implementing the constructor. - \snippet webkitwidgets/fancybrowser/mainwindow.cpp 1 + \snippet webenginewidgets/fancybrowser/mainwindow.cpp 1 The first part of the constructor sets the value of \c progress to 0. This value will be used later in the code to visualize the @@ -66,7 +66,7 @@ content. The jQuery library is a JavaScript library that provides different functions for manipulating HTML. - \snippet webkitwidgets/fancybrowser/mainwindow.cpp 2 + \snippet webenginewidgets/fancybrowser/mainwindow.cpp 2 The second part of the constructor creates a QWebView and connects slots to the views signals. Furthermore, we create a QLineEdit as @@ -75,13 +75,13 @@ QLineEdit to a QToolbar together with a set of navigation actions from QWebView::pageAction. - \snippet webkitwidgets/fancybrowser/mainwindow.cpp 3 + \snippet webenginewidgets/fancybrowser/mainwindow.cpp 3 The third and last part of the constructor implements two QMenus and assigns a set of actions to them. The last line sets the QWebView as the central widget in the QMainWindow. - \snippet webkitwidgets/fancybrowser/mainwindow.cpp 4 + \snippet webenginewidgets/fancybrowser/mainwindow.cpp 4 When the page is loaded, \c adjustLocation() updates the address bar; \c adjustLocation() is triggered by the \c loadFinished() @@ -90,28 +90,28 @@ the new web page has finished loading, \c adjustLocation() will be run once more to update the address bar. - \snippet webkitwidgets/fancybrowser/mainwindow.cpp 5 + \snippet webenginewidgets/fancybrowser/mainwindow.cpp 5 \c adjustTitle() sets the window title and displays the loading progress. This slot is triggered by the \c titleChanged() signal in QWebView. - \snippet webkitwidgets/fancybrowser/mainwindow.cpp 6 + \snippet webenginewidgets/fancybrowser/mainwindow.cpp 6 When a web page has loaded, \c finishLoading() is triggered by the \c loadFinished() signal in QWebView. \c finishLoading() then updates the - progress in the title bar and calls \c evaluateJavaScript() to evaluate the - jQuery library. This evaluates the JavaScript against the current web page. - What that means is that the JavaScript can be viewed as part of the content - loaded into the QWebView, and therefore needs to be loaded every time a new - page is loaded. Once the jQuery library is loaded, we can start executing - the different jQuery functions in the browser. + progress in the title bar and calls \c evaluateJavaScript() + to evaluate the jQuery library. This evaluates the JavaScript against the + current web page. What that means is that the JavaScript can be viewed as + part of the content loaded into the QWebView, and therefore needs to be + loaded every time a new page is loaded. Once the jQuery library is loaded, + we can start executing the different jQuery functions in the browser. The rotateImages() function is then called explicitely to make sure that the images of the newly loaded page respect the state of the toggle action. - \snippet webkitwidgets/fancybrowser/mainwindow.cpp 7 + \snippet webenginewidgets/fancybrowser/mainwindow.cpp 7 The first jQuery-based function, \c highlightAllLinks(), is designed to highlight all links in the current webpage. The JavaScript code looks @@ -119,14 +119,14 @@ For each such element, the background color is set to be yellow by using CSS. - \snippet webkitwidgets/fancybrowser/mainwindow.cpp 8 + \snippet webenginewidgets/fancybrowser/mainwindow.cpp 8 The \c rotateImages() function rotates the images on the current - web page. Webkit supports CSS transforms and this JavaScript code + web page. This JavaScript code relies on CSS transforms and looks up all \e {img} elements and rotates the images 180 degrees and then back again. - \snippet webkitwidgets/fancybrowser/mainwindow.cpp 9 + \snippet webenginewidgets/fancybrowser/mainwindow.cpp 9 The remaining four methods remove different elements from the current web page. \c removeGifImages() removes all GIF images on the page by looking up diff --git a/examples/widgets/fancybrowser/fancybrowser.pro b/examples/widgets/fancybrowser/fancybrowser.pro index f066be476439d8b61c0a308f510f63ef962174b7..01f7c535a2b743bc6f33162202264793cfc8006d 100644 --- a/examples/widgets/fancybrowser/fancybrowser.pro +++ b/examples/widgets/fancybrowser/fancybrowser.pro @@ -1,4 +1,7 @@ QT += webenginewidgets + +include($$QTWEBENGINE_ROOT/common.pri) + HEADERS = mainwindow.h SOURCES = main.cpp \ mainwindow.cpp diff --git a/examples/widgets/fancybrowser/mainwindow.cpp b/examples/widgets/fancybrowser/mainwindow.cpp index fa9ec796812baadc2805f19f99985ef48e14e78e..1f2785697e399b7825f51c49643b6406c6a39eb8 100644 --- a/examples/widgets/fancybrowser/mainwindow.cpp +++ b/examples/widgets/fancybrowser/mainwindow.cpp @@ -39,8 +39,7 @@ ****************************************************************************/ #include <QtWidgets> -#include <QtNetwork> -#include <QtWebKitWidgets> +#include <QtWebEngineWidgets> #include "mainwindow.h" //! [1] @@ -55,12 +54,9 @@ MainWindow::MainWindow(const QUrl& url) jQuery = file.readAll(); jQuery.append("\nvar qt = { 'jQuery': jQuery.noConflict(true) };"); file.close(); -//! [1] - - QNetworkProxyFactory::setUseSystemConfiguration(true); -//! [2] - view = new QWebView(this); +//! [1] + view = new QWebEngineView(this); view->load(url); connect(view, SIGNAL(loadFinished(bool)), SLOT(adjustLocation())); connect(view, SIGNAL(titleChanged(QString)), SLOT(adjustTitle())); @@ -72,12 +68,12 @@ MainWindow::MainWindow(const QUrl& url) connect(locationEdit, SIGNAL(returnPressed()), SLOT(changeLocation())); QToolBar *toolBar = addToolBar(tr("Navigation")); - toolBar->addAction(view->pageAction(QWebPage::Back)); - toolBar->addAction(view->pageAction(QWebPage::Forward)); - toolBar->addAction(view->pageAction(QWebPage::Reload)); - toolBar->addAction(view->pageAction(QWebPage::Stop)); + toolBar->addAction(view->pageAction(QWebEnginePage::Back)); + toolBar->addAction(view->pageAction(QWebEnginePage::Forward)); + toolBar->addAction(view->pageAction(QWebEnginePage::Reload)); + toolBar->addAction(view->pageAction(QWebEnginePage::Stop)); toolBar->addWidget(locationEdit); -//! [2] +//! [1] QMenu *viewMenu = menuBar()->addMenu(tr("&View")); QAction* viewSourceAction = new QAction("Page Source", this); @@ -108,7 +104,8 @@ MainWindow::MainWindow(const QUrl& url) void MainWindow::viewSource() { - QWebFrame *mainFrame = view->page()->mainFrame(); +#ifdef QWEBENGINEPAGE_TOHTML + QWebEnginePage *mainFrame = view->page(); QTextEdit* textEdit = new QTextEdit(NULL); textEdit->setAttribute(Qt::WA_DeleteOnClose); textEdit->adjustSize(); @@ -116,6 +113,7 @@ void MainWindow::viewSource() textEdit->setPlainText(mainFrame->toHtml()); textEdit->show(); +#endif } //! [4] @@ -153,7 +151,7 @@ void MainWindow::finishLoading(bool) { progress = 100; adjustTitle(); - view->page()->mainFrame()->evaluateJavaScript(jQuery); + view->page()->runJavaScript(jQuery); rotateImages(rotateAction->isChecked()); } @@ -166,7 +164,7 @@ void MainWindow::highlightAllLinks() // the way the elements returned by the each iterator elements reference each other, which causes problems upon // converting them to QVariants. QString code = "qt.jQuery('a').each( function () { qt.jQuery(this).css('background-color', 'yellow') } ); undefined"; - view->page()->mainFrame()->evaluateJavaScript(code); + view->page()->runJavaScript(code); } //! [7] @@ -182,7 +180,7 @@ void MainWindow::rotateImages(bool invert) code = "qt.jQuery('img').each( function () { qt.jQuery(this).css('-webkit-transition', '-webkit-transform 2s'); qt.jQuery(this).css('-webkit-transform', 'rotate(180deg)') } ); undefined"; else code = "qt.jQuery('img').each( function () { qt.jQuery(this).css('-webkit-transition', '-webkit-transform 2s'); qt.jQuery(this).css('-webkit-transform', 'rotate(0deg)') } ); undefined"; - view->page()->mainFrame()->evaluateJavaScript(code); + view->page()->runJavaScript(code); } //! [8] @@ -190,25 +188,25 @@ void MainWindow::rotateImages(bool invert) void MainWindow::removeGifImages() { QString code = "qt.jQuery('[src*=gif]').remove()"; - view->page()->mainFrame()->evaluateJavaScript(code); + view->page()->runJavaScript(code); } void MainWindow::removeInlineFrames() { QString code = "qt.jQuery('iframe').remove()"; - view->page()->mainFrame()->evaluateJavaScript(code); + view->page()->runJavaScript(code); } void MainWindow::removeObjectElements() { QString code = "qt.jQuery('object').remove()"; - view->page()->mainFrame()->evaluateJavaScript(code); + view->page()->runJavaScript(code); } void MainWindow::removeEmbeddedElements() { QString code = "qt.jQuery('embed').remove()"; - view->page()->mainFrame()->evaluateJavaScript(code); + view->page()->runJavaScript(code); } //! [9] diff --git a/examples/widgets/fancybrowser/mainwindow.h b/examples/widgets/fancybrowser/mainwindow.h index 4ce0fac50f249c954043f4cd1eb644adc8afcbd8..5f33bdf963530264b334bfce49a3750b395d9d28 100644 --- a/examples/widgets/fancybrowser/mainwindow.h +++ b/examples/widgets/fancybrowser/mainwindow.h @@ -40,8 +40,8 @@ #include <QtWidgets> -class QWebView; QT_BEGIN_NAMESPACE +class QWebEngineView; class QLineEdit; QT_END_NAMESPACE @@ -72,7 +72,7 @@ protected slots: private: QString jQuery; - QWebView *view; + QWebEngineView *view; QLineEdit *locationEdit; QAction *rotateAction; int progress;