From 1fcd7970e07a0ecab206224824d1c71488fc19e9 Mon Sep 17 00:00:00 2001 From: Jocelyn Turcotte Date: Wed, 15 Jan 2014 19:10:22 +0100 Subject: Implement QWebEnginePage::toHtml and toPlainText Those methods are now made asynchronous and need to be given a callback to handle the result. Update the code in the browser and fancybrowser examples using std::bind when using C++11 or tr1::bind with C++03 (which should be available with compilers on platforms that we support). Add a (currently failing) earlyToHtml test to make sure that an empty page doesn't crash because of a possibly incomplete attachment of the QtRenderViewObserver. Change-Id: I3ab7cb6f25b91b584dd80df5e4e9ad1e3214348e Reviewed-by: Pierre Rossi --- examples/widgets/browser/browsermainwindow.cpp | 19 +++++++++++++------ examples/widgets/fancybrowser/mainwindow.cpp | 19 ++++++++++++------- 2 files changed, 25 insertions(+), 13 deletions(-) (limited to 'examples') diff --git a/examples/widgets/browser/browsermainwindow.cpp b/examples/widgets/browser/browsermainwindow.cpp index 9a2262314..ac8426d9a 100644 --- a/examples/widgets/browser/browsermainwindow.cpp +++ b/examples/widgets/browser/browsermainwindow.cpp @@ -71,6 +71,16 @@ #include +#if __cplusplus >= 201103L +#include +using std::bind; +namespace placeholders = std::placeholders; +#else +#include +using std::tr1::bind; +namespace placeholders = std::tr1::placeholders; +#endif + BrowserMainWindow::BrowserMainWindow(QWidget *parent, Qt::WindowFlags flags) : QMainWindow(parent, flags) , m_tabWidget(new TabWidget(this)) @@ -372,9 +382,7 @@ void BrowserMainWindow::setupMenu() #endif viewMenu->addSeparator(); -#if defined(QWEBENGINEPAGE_TOHTML) viewMenu->addAction(tr("Page S&ource"), this, SLOT(slotViewPageSource()), tr("Ctrl+Alt+U")); -#endif QAction *a = viewMenu->addAction(tr("&Full Screen"), this, SLOT(slotViewFullScreen(bool)), Qt::Key_F11); a->setCheckable(true); @@ -810,17 +818,16 @@ void BrowserMainWindow::slotViewFullScreen(bool makeFullScreen) void BrowserMainWindow::slotViewPageSource() { -#if defined(QWEBENGINEPAGE_TOHTML) if (!currentTab()) return; - QString markup = currentTab()->page()->toHtml(); - QPlainTextEdit *view = new QPlainTextEdit(markup); + QPlainTextEdit *view = new QPlainTextEdit; view->setWindowTitle(tr("Page Source of %1").arg(currentTab()->title())); view->setMinimumWidth(640); view->setAttribute(Qt::WA_DeleteOnClose); view->show(); -#endif + + currentTab()->page()->toHtml(bind(&QPlainTextEdit::setPlainText, view, placeholders::_1)); } void BrowserMainWindow::slotHome() diff --git a/examples/widgets/fancybrowser/mainwindow.cpp b/examples/widgets/fancybrowser/mainwindow.cpp index 53b2a545d..b9d5a8364 100644 --- a/examples/widgets/fancybrowser/mainwindow.cpp +++ b/examples/widgets/fancybrowser/mainwindow.cpp @@ -42,6 +42,16 @@ #include #include "mainwindow.h" +#if __cplusplus >= 201103L +#include +using std::bind; +namespace placeholders = std::placeholders; +#else +#include +using std::tr1::bind; +namespace placeholders = std::tr1::placeholders; +#endif + //! [1] MainWindow::MainWindow(const QUrl& url) @@ -75,12 +85,10 @@ MainWindow::MainWindow(const QUrl& url) toolBar->addWidget(locationEdit); //! [1] -#ifdef QWEBENGINEPAGE_TOHTML QMenu *viewMenu = menuBar()->addMenu(tr("&View")); QAction* viewSourceAction = new QAction("Page Source", this); connect(viewSourceAction, SIGNAL(triggered()), SLOT(viewSource())); viewMenu->addAction(viewSourceAction); -#endif //! [3] QMenu *effectMenu = menuBar()->addMenu(tr("&Effect")); @@ -106,16 +114,13 @@ MainWindow::MainWindow(const QUrl& url) void MainWindow::viewSource() { -#ifdef QWEBENGINEPAGE_TOHTML - QWebEnginePage *mainFrame = view->page(); QTextEdit* textEdit = new QTextEdit(NULL); textEdit->setAttribute(Qt::WA_DeleteOnClose); textEdit->adjustSize(); textEdit->move(this->geometry().center() - textEdit->rect().center()); - - textEdit->setPlainText(mainFrame->toHtml()); textEdit->show(); -#endif + + view->page()->toHtml(bind(&QTextEdit::setPlainText, textEdit, placeholders::_1)); } //! [4] -- cgit v1.2.1