diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-07-03 12:59:23 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-07-05 11:38:23 +0200 |
commit | 8f160af577e4d979954a63ab56f56e4d0c8ad0f8 (patch) | |
tree | 0c6cf366f3309c96e43e532527aff362320b7e94 /examples | |
parent | 601003362c75283e9164e997e3835e7c36c6db00 (diff) | |
parent | fcdde728f0c4b4af5159b993e44eb6089d70aa90 (diff) |
Merge remote-tracking branch 'origin/5.9' into dev
Change-Id: Ida702fd5fa05a32d6cd7fc737aa061da74b675a0
Diffstat (limited to 'examples')
9 files changed, 39 insertions, 79 deletions
diff --git a/examples/webengine/customdialogs/doc/src/customdialogs.qdoc b/examples/webengine/customdialogs/doc/src/customdialogs.qdoc index f5a18b591..2162fe4ca 100644 --- a/examples/webengine/customdialogs/doc/src/customdialogs.qdoc +++ b/examples/webengine/customdialogs/doc/src/customdialogs.qdoc @@ -58,10 +58,11 @@ \section1 Triggering Dialogs - The technical details on how the dialogs are triggered are beyond the scope - of this example. The only thing worth mentioning is that we fire up the - localhost TCP server when the example starts up. The server is needed to - get proxy and HTTP authentication requests. + As mentioned, the \l {webengine/customdialogs/index.html}{index.html} file + is responsible for triggering the dialogs from the side of HTML and + JavaScript. Additionally, the example program starts a localhost TCP server + returning the mocked HTTP responses needed to trigger proxy and HTTP + authentication dialogs. \section1 Custom Dialogs diff --git a/examples/webengine/quicknanobrowser/doc/src/quicknanobrowser.qdoc b/examples/webengine/quicknanobrowser/doc/src/quicknanobrowser.qdoc index 75c2997e8..93b3ed51a 100644 --- a/examples/webengine/quicknanobrowser/doc/src/quicknanobrowser.qdoc +++ b/examples/webengine/quicknanobrowser/doc/src/quicknanobrowser.qdoc @@ -43,7 +43,7 @@ screen mode by using a toolbar button. They can leave fullscreen mode by using a keyboard shortcut. Additional toolbar buttons enable moving backwards and forwards in the browser history, reloading tab content, and opening a settings menu for enabling the following features: - JavaScript, plugins, fullscreen mode, off the record, HTTP disc cache, autoloading images, and + JavaScript, plugins, fullscreen mode, off the record, HTTP disk cache, autoloading images, and ignoring certificate errors. \include examples-run.qdocinc diff --git a/examples/webenginewidgets/contentmanipulation/doc/src/contentmanipulation.qdoc b/examples/webenginewidgets/contentmanipulation/doc/src/contentmanipulation.qdoc index aa94b17da..66a1252dc 100644 --- a/examples/webenginewidgets/contentmanipulation/doc/src/contentmanipulation.qdoc +++ b/examples/webenginewidgets/contentmanipulation/doc/src/contentmanipulation.qdoc @@ -36,7 +36,7 @@ \e{Content Manipulation} shows how to use JQuery with \l {Qt WebEngine Widgets} to create a web browser with special effects and content manipulation. - In the application, we call QWebEnginePage::runJavaScript() to + In the application, we call \l {QWebEnginePage::runJavaScript()} to execute jQuery JavaScript code. We implement a QMainWindow with a QWebEngineView as a central widget to build up the browser itself. @@ -51,7 +51,7 @@ \skipto class MainWindow : \printuntil /^\}/ - We also declare a QString that contains the jQuery, a QWebEngineView + We also declare a QString that contains jQuery, a QWebEngineView that displays the web content, and a QLineEdit that acts as the address bar. @@ -74,9 +74,9 @@ The second part of the constructor creates a QWebEngineView and connects slots to the view's signals: - \printuntil SLOT(finishLoading + \printuntil MainWindow::finishLoading - Furthermore, we create a QLineEdit as the browser's address bar. We then set the horizontal + Furthermore, we create a QLineEdit as the browser's address bar. We then set the vertical QSizePolicy to fill the available area in the browser at all times. We add the QLineEdit to a QToolBar together with a set of navigation actions from QWebEngineView::pageAction(): @@ -136,10 +136,6 @@ \printuntil } \printuntil } - We append \c undefined after the jQuery call to prevent a possible recursion loop - and crash caused by the way the elements returned by the each iterator elements - reference each other, which causes problems upon converting them to QVariant. - The \c rotateImages() function rotates the images on the current web page. This JavaScript code relies on CSS transforms. It looks up all \e {img} elements and rotates the images 180 degrees diff --git a/examples/webenginewidgets/contentmanipulation/mainwindow.cpp b/examples/webenginewidgets/contentmanipulation/mainwindow.cpp index 74d647c69..154a37747 100644 --- a/examples/webenginewidgets/contentmanipulation/mainwindow.cpp +++ b/examples/webenginewidgets/contentmanipulation/mainwindow.cpp @@ -52,22 +52,6 @@ #include <QtWebEngineWidgets> #include "mainwindow.h" -template<typename Arg, typename R, typename C> -struct InvokeWrapper { - R *receiver; - void (C::*memberFun)(Arg); - void operator()(Arg result) { - (receiver->*memberFun)(result); - } -}; - -template<typename Arg, typename R, typename C> -InvokeWrapper<Arg, R, C> invoke(R *receiver, void (C::*memberFun)(Arg)) -{ - InvokeWrapper<Arg, R, C> wrapper = {receiver, memberFun}; - return wrapper; -} - MainWindow::MainWindow(const QUrl& url) { setAttribute(Qt::WA_DeleteOnClose, true); @@ -82,14 +66,14 @@ MainWindow::MainWindow(const QUrl& url) view = new QWebEngineView(this); view->load(url); - connect(view, SIGNAL(loadFinished(bool)), SLOT(adjustLocation())); - connect(view, SIGNAL(titleChanged(QString)), SLOT(adjustTitle())); - connect(view, SIGNAL(loadProgress(int)), SLOT(setProgress(int))); - connect(view, SIGNAL(loadFinished(bool)), SLOT(finishLoading(bool))); + connect(view, &QWebEngineView::loadFinished, this, &MainWindow::adjustLocation); + connect(view, &QWebEngineView::titleChanged, this, &MainWindow::adjustTitle); + connect(view, &QWebEngineView::loadProgress, this, &MainWindow::setProgress); + connect(view, &QWebEngineView::loadFinished, this, &MainWindow::finishLoading); locationEdit = new QLineEdit(this); locationEdit->setSizePolicy(QSizePolicy::Expanding, locationEdit->sizePolicy().verticalPolicy()); - connect(locationEdit, SIGNAL(returnPressed()), SLOT(changeLocation())); + connect(locationEdit, &QLineEdit::returnPressed, this, &MainWindow::changeLocation); QToolBar *toolBar = addToolBar(tr("Navigation")); toolBar->addAction(view->pageAction(QWebEnginePage::Back)); @@ -99,38 +83,40 @@ MainWindow::MainWindow(const QUrl& url) toolBar->addWidget(locationEdit); QMenu *viewMenu = menuBar()->addMenu(tr("&View")); - QAction* viewSourceAction = new QAction("Page Source", this); - connect(viewSourceAction, SIGNAL(triggered()), SLOT(viewSource())); + QAction *viewSourceAction = new QAction(tr("Page Source"), this); + connect(viewSourceAction, &QAction::triggered, this, &MainWindow::viewSource); viewMenu->addAction(viewSourceAction); QMenu *effectMenu = menuBar()->addMenu(tr("&Effect")); - effectMenu->addAction("Highlight all links", this, SLOT(highlightAllLinks())); + effectMenu->addAction(tr("Highlight all links"), this, &MainWindow::highlightAllLinks); rotateAction = new QAction(this); rotateAction->setIcon(style()->standardIcon(QStyle::SP_FileDialogDetailedView)); rotateAction->setCheckable(true); rotateAction->setText(tr("Turn images upside down")); - connect(rotateAction, SIGNAL(toggled(bool)), this, SLOT(rotateImages(bool))); + connect(rotateAction, &QAction::toggled, this, &MainWindow::rotateImages); effectMenu->addAction(rotateAction); QMenu *toolsMenu = menuBar()->addMenu(tr("&Tools")); - toolsMenu->addAction(tr("Remove GIF images"), this, SLOT(removeGifImages())); - toolsMenu->addAction(tr("Remove all inline frames"), this, SLOT(removeInlineFrames())); - toolsMenu->addAction(tr("Remove all object elements"), this, SLOT(removeObjectElements())); - toolsMenu->addAction(tr("Remove all embedded elements"), this, SLOT(removeEmbeddedElements())); + toolsMenu->addAction(tr("Remove GIF images"), this, &MainWindow::removeGifImages); + toolsMenu->addAction(tr("Remove all inline frames"), this, &MainWindow::removeInlineFrames); + toolsMenu->addAction(tr("Remove all object elements"), this, &MainWindow::removeObjectElements); + toolsMenu->addAction(tr("Remove all embedded elements"), this, &MainWindow::removeEmbeddedElements); setCentralWidget(view); } void MainWindow::viewSource() { - QTextEdit* textEdit = new QTextEdit(NULL); + QTextEdit *textEdit = new QTextEdit(nullptr); textEdit->setAttribute(Qt::WA_DeleteOnClose); textEdit->adjustSize(); textEdit->move(this->geometry().center() - textEdit->rect().center()); textEdit->show(); - view->page()->toHtml(invoke(textEdit, &QTextEdit::setPlainText)); + view->page()->toHtml([textEdit](const QString &html){ + textEdit->setPlainText(html); + }); } void MainWindow::adjustLocation() @@ -150,7 +136,7 @@ void MainWindow::adjustTitle() if (progress <= 0 || progress >= 100) setWindowTitle(view->title()); else - setWindowTitle(QString("%1 (%2%)").arg(view->title()).arg(progress)); + setWindowTitle(QStringLiteral("%1 (%2%)").arg(view->title()).arg(progress)); } void MainWindow::setProgress(int p) @@ -170,7 +156,7 @@ void MainWindow::finishLoading(bool) void MainWindow::highlightAllLinks() { - QString code = "qt.jQuery('a').each( function () { qt.jQuery(this).css('background-color', 'yellow') } ); undefined"; + QString code = QStringLiteral("qt.jQuery('a').each( function () { qt.jQuery(this).css('background-color', 'yellow') } )"); view->page()->runJavaScript(code); } @@ -179,32 +165,32 @@ void MainWindow::rotateImages(bool invert) QString code; if (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"; + code = QStringLiteral("qt.jQuery('img').each( function () { qt.jQuery(this).css('transition', 'transform 2s'); qt.jQuery(this).css('transform', 'rotate(180deg)') } )"); 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"; + code = QStringLiteral("qt.jQuery('img').each( function () { qt.jQuery(this).css('transition', 'transform 2s'); qt.jQuery(this).css('transform', 'rotate(0deg)') } )"); view->page()->runJavaScript(code); } void MainWindow::removeGifImages() { - QString code = "qt.jQuery('[src*=gif]').remove()"; + QString code = QStringLiteral("qt.jQuery('[src*=gif]').remove()"); view->page()->runJavaScript(code); } void MainWindow::removeInlineFrames() { - QString code = "qt.jQuery('iframe').remove()"; + QString code = QStringLiteral("qt.jQuery('iframe').remove()"); view->page()->runJavaScript(code); } void MainWindow::removeObjectElements() { - QString code = "qt.jQuery('object').remove()"; + QString code = QStringLiteral("qt.jQuery('object').remove()"); view->page()->runJavaScript(code); } void MainWindow::removeEmbeddedElements() { - QString code = "qt.jQuery('embed').remove()"; + QString code = QStringLiteral("qt.jQuery('embed').remove()"); view->page()->runJavaScript(code); } diff --git a/examples/webenginewidgets/demobrowser/browserapplication.cpp b/examples/webenginewidgets/demobrowser/browserapplication.cpp index 32429a675..c3f3ef9b9 100644 --- a/examples/webenginewidgets/demobrowser/browserapplication.cpp +++ b/examples/webenginewidgets/demobrowser/browserapplication.cpp @@ -314,7 +314,9 @@ void BrowserApplication::loadSettings() settings.endGroup(); settings.beginGroup(QLatin1String("cookies")); - QWebEngineProfile::PersistentCookiesPolicy persistentCookiesPolicy = QWebEngineProfile::PersistentCookiesPolicy(settings.value(QLatin1String("persistentCookiesPolicy")).toInt()); + QWebEngineProfile::PersistentCookiesPolicy persistentCookiesPolicy = + QWebEngineProfile::PersistentCookiesPolicy(settings.value(QLatin1String("persistentCookiesPolicy"), + QWebEngineProfile::AllowPersistentCookies).toInt()); defaultProfile->setPersistentCookiesPolicy(persistentCookiesPolicy); QString pdataPath = settings.value(QLatin1String("persistentDataPath")).toString(); defaultProfile->setPersistentStoragePath(pdataPath); diff --git a/examples/webenginewidgets/demobrowser/browsermainwindow.cpp b/examples/webenginewidgets/demobrowser/browsermainwindow.cpp index 327d7a9d3..14d49f7f3 100644 --- a/examples/webenginewidgets/demobrowser/browsermainwindow.cpp +++ b/examples/webenginewidgets/demobrowser/browsermainwindow.cpp @@ -109,9 +109,7 @@ BrowserMainWindow::BrowserMainWindow(QWidget *parent, Qt::WindowFlags flags) , m_historyForward(0) , m_stop(0) , m_reload(0) -#ifndef QT_NO_PRINTER , m_currentPrinter(nullptr) -#endif { setToolButtonStyle(Qt::ToolButtonFollowStyle); setAttribute(Qt::WA_DeleteOnClose, true); @@ -312,9 +310,7 @@ void BrowserMainWindow::setupMenu() #if defined(QWEBENGINEPAGE_PRINT) fileMenu->addAction(tr("P&rint Preview..."), this, SLOT(slotFilePrintPreview())); #endif -#ifndef QT_NO_PRINTER fileMenu->addAction(tr("&Print..."), this, SLOT(slotFilePrint()), QKeySequence::Print); -#endif fileMenu->addAction(tr("&Print to PDF..."), this, SLOT(slotFilePrintToPDF())); fileMenu->addSeparator(); @@ -702,23 +698,19 @@ void BrowserMainWindow::slotFileOpen() void BrowserMainWindow::slotFilePrintPreview() { -#ifndef QT_NO_PRINTPREVIEWDIALOG if (!currentTab()) return; QPrintPreviewDialog *dialog = new QPrintPreviewDialog(this); connect(dialog, SIGNAL(paintRequested(QPrinter*)), currentTab(), SLOT(print(QPrinter*))); dialog->exec(); -#endif } void BrowserMainWindow::slotFilePrint() { -#ifndef QT_NO_PRINTER if (!currentTab()) return; printRequested(currentTab()->page()); -#endif } void BrowserMainWindow::slotHandlePdfPrinted(const QByteArray& result) @@ -751,7 +743,6 @@ void BrowserMainWindow::slotFilePrintToPDF() currentTab()->page()->printToPdf(invoke(this, &BrowserMainWindow::slotHandlePdfPrinted), dialog->pageLayout()); } -#ifndef QT_NO_PRINTER void BrowserMainWindow::slotHandlePagePrinted(bool result) { Q_UNUSED(result); @@ -763,7 +754,6 @@ void BrowserMainWindow::slotHandlePagePrinted(bool result) void BrowserMainWindow::printRequested(QWebEnginePage *page) { -#ifndef QT_NO_PRINTDIALOG if (m_currentPrinter) return; m_currentPrinter = new QPrinter(); @@ -774,9 +764,7 @@ void BrowserMainWindow::printRequested(QWebEnginePage *page) return; } page->print(m_currentPrinter, invoke(this, &BrowserMainWindow::slotHandlePagePrinted)); -#endif } -#endif void BrowserMainWindow::slotPrivateBrowsing() { diff --git a/examples/webenginewidgets/demobrowser/browsermainwindow.h b/examples/webenginewidgets/demobrowser/browsermainwindow.h index 91e1c1d2f..5bbbb2924 100644 --- a/examples/webenginewidgets/demobrowser/browsermainwindow.h +++ b/examples/webenginewidgets/demobrowser/browsermainwindow.h @@ -56,9 +56,7 @@ #include <QtCore/QUrl> QT_BEGIN_NAMESPACE -#ifndef QT_NO_PRINTER class QPrinter; -#endif class QWebEnginePage; QT_END_NAMESPACE @@ -142,10 +140,8 @@ private slots: void slotSwapFocus(); void slotHandlePdfPrinted(const QByteArray&); -#ifndef QT_NO_PRINTER void slotHandlePagePrinted(bool result); void printRequested(QWebEnginePage *page); -#endif void geometryChangeRequested(const QRect &geometry); void updateToolbarActionText(bool visible); void updateBookmarksToolbarActionText(bool visible); @@ -180,9 +176,7 @@ private: QAction *m_restoreLastSession; QAction *m_addBookmark; -#ifndef QT_NO_PRINTER QPrinter *m_currentPrinter; -#endif QIcon m_reloadIcon; QIcon m_stopIcon; diff --git a/examples/webenginewidgets/demobrowser/printtopdfdialog.cpp b/examples/webenginewidgets/demobrowser/printtopdfdialog.cpp index 0f3b1765e..50a8bb91a 100644 --- a/examples/webenginewidgets/demobrowser/printtopdfdialog.cpp +++ b/examples/webenginewidgets/demobrowser/printtopdfdialog.cpp @@ -52,10 +52,8 @@ #include "ui_printtopdfdialog.h" #include <QtCore/QDir> -#ifndef QT_NO_PRINTER #include <QtPrintSupport/QPageSetupDialog> #include <QtPrintSupport/QPrinter> -#endif // QT_NO_PRINTER #include <QtWidgets/QFileDialog> PrintToPdfDialog::PrintToPdfDialog(const QString &filePath, QWidget *parent) : @@ -66,11 +64,8 @@ PrintToPdfDialog::PrintToPdfDialog(const QString &filePath, QWidget *parent) : ui->setupUi(this); setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); connect(ui->chooseFilePathButton, &QToolButton::clicked, this, &PrintToPdfDialog::onChooseFilePathButtonClicked); -#ifndef QT_NO_PRINTER connect(ui->choosePageLayoutButton, &QToolButton::clicked, this, &PrintToPdfDialog::onChoosePageLayoutButtonClicked); -#else ui->choosePageLayoutButton->hide(); -#endif // QT_NO_PRINTER updatePageLayoutLabel(); setFilePath(filePath); } @@ -82,7 +77,6 @@ PrintToPdfDialog::~PrintToPdfDialog() void PrintToPdfDialog::onChoosePageLayoutButtonClicked() { -#ifndef QT_NO_PRINTER QPrinter printer; printer.setPageLayout(currentPageLayout); @@ -92,7 +86,6 @@ void PrintToPdfDialog::onChoosePageLayoutButtonClicked() currentPageLayout.setPageSize(printer.pageLayout().pageSize()); currentPageLayout.setOrientation(printer.pageLayout().orientation()); updatePageLayoutLabel(); -#endif // QT_NO_PRINTER } void PrintToPdfDialog::onChooseFilePathButtonClicked() diff --git a/examples/webenginewidgets/markdowneditor/doc/src/markdowneditor.qdoc b/examples/webenginewidgets/markdowneditor/doc/src/markdowneditor.qdoc index 0239c1065..a20dc04c5 100644 --- a/examples/webenginewidgets/markdowneditor/doc/src/markdowneditor.qdoc +++ b/examples/webenginewidgets/markdowneditor/doc/src/markdowneditor.qdoc @@ -139,7 +139,7 @@ \printto defaultTextFile - The menu items are connected to the mapping member slots. The + The menu items are connected to the corresponding member slots. The \uicontrol Save item is activated or deactivated depending on whether the user has edited the content. |