summaryrefslogtreecommitdiffstats
path: root/examples/webenginewidgets/contentmanipulation/mainwindow.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'examples/webenginewidgets/contentmanipulation/mainwindow.cpp')
-rw-r--r--examples/webenginewidgets/contentmanipulation/mainwindow.cpp64
1 files changed, 25 insertions, 39 deletions
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);
}