blob: ffcb6bc3474d13ac27234aaa81c639a1c208fdc0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
#include "webview.h"
#include <QPaintEvent>
#include <QWebFrame>
WebView::WebView(QWidget *parent)
: QWebView(parent)
, inLoading(false)
{
connect(this, SIGNAL(loadStarted()), this, SLOT(newPageLoading()));
connect(this, SIGNAL(loadFinished(bool)), this, SLOT(pageLoaded(bool)));
page()->setPreferredContentsSize(QSize(1024, 768));
}
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();
}
|