summaryrefslogtreecommitdiffstats
path: root/examples/webkit/fancybrowser/mainwindow.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'examples/webkit/fancybrowser/mainwindow.cpp')
-rw-r--r--examples/webkit/fancybrowser/mainwindow.cpp28
1 files changed, 26 insertions, 2 deletions
diff --git a/examples/webkit/fancybrowser/mainwindow.cpp b/examples/webkit/fancybrowser/mainwindow.cpp
index a3293b8..06af62e 100644
--- a/examples/webkit/fancybrowser/mainwindow.cpp
+++ b/examples/webkit/fancybrowser/mainwindow.cpp
@@ -45,7 +45,7 @@
//! [1]
-MainWindow::MainWindow()
+MainWindow::MainWindow(const QUrl& url)
{
progress = 0;
@@ -60,7 +60,7 @@ MainWindow::MainWindow()
//! [2]
view = new QWebView(this);
- view->load(QUrl("http://www.google.com/ncr"));
+ view->load(url);
connect(view, SIGNAL(loadFinished(bool)), SLOT(adjustLocation()));
connect(view, SIGNAL(titleChanged(const QString&)), SLOT(adjustTitle()));
connect(view, SIGNAL(loadProgress(int)), SLOT(setProgress(int)));
@@ -78,6 +78,11 @@ MainWindow::MainWindow()
toolBar->addWidget(locationEdit);
//! [2]
+ QMenu *viewMenu = menuBar()->addMenu(tr("&View"));
+ QAction* viewSourceAction = new QAction("Page Source", this);
+ connect(viewSourceAction, SIGNAL(triggered()), SLOT(viewSource()));
+ viewMenu->addAction(viewSourceAction);
+
//! [3]
QMenu *effectMenu = menuBar()->addMenu(tr("&Effect"));
effectMenu->addAction("Highlight all links", this, SLOT(highlightAllLinks()));
@@ -100,6 +105,23 @@ MainWindow::MainWindow()
}
//! [3]
+void MainWindow::viewSource()
+{
+ QNetworkAccessManager* accessManager = view->page()->networkAccessManager();
+ QNetworkRequest request(view->url());
+ QNetworkReply* reply = accessManager->get(request);
+ connect(reply, SIGNAL(finished()), this, SLOT(slotSourceDownloaded()));
+}
+
+void MainWindow::slotSourceDownloaded()
+{
+ QNetworkReply* reply = qobject_cast<QNetworkReply*>(const_cast<QObject*>(sender()));
+ QTextEdit* textEdit = new QTextEdit(NULL);
+ textEdit->setAttribute(Qt::WA_DeleteOnClose);
+ textEdit->show();
+ textEdit->setPlainText(reply->readAll());
+}
+
//! [4]
void MainWindow::adjustLocation()
{
@@ -136,6 +158,8 @@ void MainWindow::finishLoading(bool)
progress = 100;
adjustTitle();
view->page()->mainFrame()->evaluateJavaScript(jQuery);
+ // Enable this to see the dump of the internal render tree
+ //qDebug() << view->page()->mainFrame()->renderTreeDump();
}
//! [6]