summaryrefslogtreecommitdiffstats
path: root/examples/webkit
diff options
context:
space:
mode:
authorDavid Faure <faure@kde.org>2009-11-06 10:48:44 (GMT)
committerMarkus Goetz <Markus.Goetz@nokia.com>2009-11-09 15:51:36 (GMT)
commit9c0196d1b6fa98d9463dd9e8a0cb571a232bf685 (patch)
tree0190a96269b2a52042d57b7e125a688c8db3e542 /examples/webkit
parent6982e18e1523ac6c5001cc07f2b8042a712b0954 (diff)
downloadQt-9c0196d1b6fa98d9463dd9e8a0cb571a232bf685.zip
Qt-9c0196d1b6fa98d9463dd9e8a0cb571a232bf685.tar.gz
Qt-9c0196d1b6fa98d9463dd9e8a0cb571a232bf685.tar.bz2
Add "View Page Source" and support for URL on the command line
This example app is useful for debugging QtWebKit problems, it was just missing a way to load the url from the command-line (to avoid loading google first), and a "view page source" action. Reviewed-By: Markus Goetz Merge-Request: 2021
Diffstat (limited to 'examples/webkit')
-rw-r--r--examples/webkit/fancybrowser/main.cpp7
-rw-r--r--examples/webkit/fancybrowser/mainwindow.cpp28
-rw-r--r--examples/webkit/fancybrowser/mainwindow.h5
3 files changed, 36 insertions, 4 deletions
diff --git a/examples/webkit/fancybrowser/main.cpp b/examples/webkit/fancybrowser/main.cpp
index 7f3c983..2245788 100644
--- a/examples/webkit/fancybrowser/main.cpp
+++ b/examples/webkit/fancybrowser/main.cpp
@@ -45,7 +45,12 @@
int main(int argc, char * argv[])
{
QApplication app(argc, argv);
- MainWindow *browser = new MainWindow;
+ QUrl url;
+ if (argc > 1)
+ url = QUrl(argv[1]);
+ else
+ url = QUrl("http://www.google.com/ncr");
+ MainWindow *browser = new MainWindow(url);
browser->show();
return app.exec();
}
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]
diff --git a/examples/webkit/fancybrowser/mainwindow.h b/examples/webkit/fancybrowser/mainwindow.h
index 33fd8f5..be95614 100644
--- a/examples/webkit/fancybrowser/mainwindow.h
+++ b/examples/webkit/fancybrowser/mainwindow.h
@@ -52,7 +52,7 @@ class MainWindow : public QMainWindow
Q_OBJECT
public:
- MainWindow();
+ MainWindow(const QUrl& url);
protected slots:
@@ -62,6 +62,9 @@ protected slots:
void setProgress(int p);
void finishLoading(bool);
+ void viewSource();
+ void slotSourceDownloaded();
+
void highlightAllLinks();
void rotateImages(bool toggle);
void removeGifImages();