diff options
author | Benjamin Poulain <benjamin.poulain@nokia.com> | 2010-01-18 15:10:24 (GMT) |
---|---|---|
committer | Benjamin Poulain <benjamin.poulain@nokia.com> | 2010-01-18 15:10:24 (GMT) |
commit | ee889d2404f6a55a8fae812dc5809dc805905d2b (patch) | |
tree | 1a21a11c5efef138b1244cecfadd00e9e3875e5d | |
parent | 4974742bb85b5f22ade3e1a59c2b5fe7ac84e684 (diff) | |
download | Qt-ee889d2404f6a55a8fae812dc5809dc805905d2b.zip Qt-ee889d2404f6a55a8fae812dc5809dc805905d2b.tar.gz Qt-ee889d2404f6a55a8fae812dc5809dc805905d2b.tar.bz2 |
Avoid painting while loading in the anomaly demo browser
At load time, loading, layouting and painting are fighting for
the CPU. By skipping painting and layouting, we achieve a better
loading time, and the experience is better.
-rw-r--r-- | demos/embedded/anomaly/anomaly.pro | 6 | ||||
-rw-r--r-- | demos/embedded/anomaly/src/BrowserView.cpp | 5 | ||||
-rw-r--r-- | demos/embedded/anomaly/src/BrowserView.h | 4 | ||||
-rw-r--r-- | demos/embedded/anomaly/src/webview.cpp | 37 | ||||
-rw-r--r-- | demos/embedded/anomaly/src/webview.h | 25 |
5 files changed, 72 insertions, 5 deletions
diff --git a/demos/embedded/anomaly/anomaly.pro b/demos/embedded/anomaly/anomaly.pro index 2871ba7..165ce89 100644 --- a/demos/embedded/anomaly/anomaly.pro +++ b/demos/embedded/anomaly/anomaly.pro @@ -8,7 +8,8 @@ HEADERS += src/BrowserWindow.h \ src/BookmarksView.h \ src/flickcharm.h \ src/ZoomStrip.h \ - src/ControlStrip.h + src/ControlStrip.h \ + src/webview.h SOURCES += src/Main.cpp \ src/BrowserWindow.cpp \ src/BrowserView.cpp \ @@ -18,7 +19,8 @@ SOURCES += src/Main.cpp \ src/BookmarksView.cpp \ src/flickcharm.cpp \ src/ZoomStrip.cpp \ - src/ControlStrip.cpp + src/ControlStrip.cpp \ + src/webview.cpp RESOURCES += src/anomaly.qrc symbian { diff --git a/demos/embedded/anomaly/src/BrowserView.cpp b/demos/embedded/anomaly/src/BrowserView.cpp index ab52e81..0945b89 100644 --- a/demos/embedded/anomaly/src/BrowserView.cpp +++ b/demos/embedded/anomaly/src/BrowserView.cpp @@ -48,6 +48,7 @@ #include "ControlStrip.h" #include "TitleBar.h" #include "flickcharm.h" +#include "webview.h" #include "ZoomStrip.h" #if defined (Q_OS_SYMBIAN) @@ -62,7 +63,7 @@ BrowserView::BrowserView(QWidget *parent) , m_currentZoom(100) { m_titleBar = new TitleBar(this); - m_webView = new QWebView(this); + m_webView = new WebView(this); m_zoomStrip = new ZoomStrip(this); m_controlStrip = new ControlStrip(this); @@ -95,7 +96,7 @@ void BrowserView::initialize() connect(m_webView, SIGNAL(loadFinished(bool)), SLOT(finish(bool))); connect(m_webView, SIGNAL(urlChanged(QUrl)), SLOT(updateTitleBar())); - m_webView->setHtml("Will try to load page soon!"); + m_webView->setHtml("about:blank"); m_webView->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); m_webView->setFocus(); #ifdef Q_OS_SYMBIAN diff --git a/demos/embedded/anomaly/src/BrowserView.h b/demos/embedded/anomaly/src/BrowserView.h index fdc126d..5ab1dd7 100644 --- a/demos/embedded/anomaly/src/BrowserView.h +++ b/demos/embedded/anomaly/src/BrowserView.h @@ -49,6 +49,7 @@ class QUrl; class QWebView; class TitleBar; class ControlStrip; +class WebView; class ZoomStrip; class BrowserView : public QWidget @@ -81,7 +82,7 @@ protected: private: TitleBar *m_titleBar; - QWebView *m_webView; + WebView *m_webView; ZoomStrip *m_zoomStrip; ControlStrip *m_controlStrip; int m_progress; @@ -90,3 +91,4 @@ private: }; #endif // BROWSERVIEW_H + diff --git a/demos/embedded/anomaly/src/webview.cpp b/demos/embedded/anomaly/src/webview.cpp new file mode 100644 index 0000000..d55c68e --- /dev/null +++ b/demos/embedded/anomaly/src/webview.cpp @@ -0,0 +1,37 @@ +#include "webview.h" + +#include <QPaintEvent> + +WebView::WebView(QWidget *parent) + : QWebView(parent) + , inLoading(false) +{ + connect(this, SIGNAL(loadStarted()), this, SLOT(newPageLoading())); + connect(this, SIGNAL(loadFinished(bool)), this, SLOT(pageLoaded(bool))); +} + +void WebView::paintEvent(QPaintEvent *event) +{ + if (inLoading && loadingTime.elapsed() < 750) { + QPainter painter(this); + painter.setBrush(Qt::white); + painter.setPen(Qt::NoPen); + foreach (const QRect &rect, event->region().rects()) { + painter.drawRect(rect); + } + } else { + QWebView::paintEvent(event); + } +} + +void WebView::newPageLoading() +{ + inLoading = true; + loadingTime.start(); +} + +void WebView::pageLoaded(bool) +{ + inLoading = false; + update(); +} diff --git a/demos/embedded/anomaly/src/webview.h b/demos/embedded/anomaly/src/webview.h new file mode 100644 index 0000000..a7426c6 --- /dev/null +++ b/demos/embedded/anomaly/src/webview.h @@ -0,0 +1,25 @@ +#ifndef WEBVIEW_H +#define WEBVIEW_H + +#include <QWebView> +#include <QTime> + +class WebView : public QWebView +{ + Q_OBJECT +public: + WebView(QWidget *parent = 0); + +protected: + void paintEvent(QPaintEvent *event); + +private slots: + void newPageLoading(); + void pageLoaded(bool ok); + +private: + QTime loadingTime; + bool inLoading; +}; + +#endif // WEBVIEW_H |