summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoopesh Chander <roop@forwardbias.in>2009-11-11 18:50:57 +0530
committerRoopesh Chander <roop@forwardbias.in>2009-11-11 19:00:25 +0530
commit8084be771d14e4262335c2eba906bea58fe04abd (patch)
treeab9dbd0e1058a36262771adaedf12bd19680b581
parente50e75b133901051da4c41d5ddcf597c0e463866 (diff)
use another way to know whether it's loading or not, now that there's no progress()
-rw-r--r--webscrap.cpp19
-rw-r--r--webscrap.h4
2 files changed, 16 insertions, 7 deletions
diff --git a/webscrap.cpp b/webscrap.cpp
index c4e5eb1..be15a2f 100644
--- a/webscrap.cpp
+++ b/webscrap.cpp
@@ -16,14 +16,16 @@ const int WebScrapContainer::s_padding = 2; // padding on the other three sides
WebScrap::WebScrap(QUrl url, QRect scrapRect, QGraphicsItem * parent)
: QGraphicsWebView(parent)
+ , m_isLoading(false)
{
setScrapRect(scrapRect);
- setUrl(url);
setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
page()->mainFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff);
page()->mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff);
page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
- connect(this, SIGNAL(loadFinished(bool)), SLOT(onLoad()));
+ connect(this, SIGNAL(loadStarted()), SLOT(onLoadStarted()));
+ connect(this, SIGNAL(loadFinished(bool)), SLOT(onLoadFinished()));
+ setUrl(url);
setDimensionsFixed(true);
connect(page(), SIGNAL(linkClicked(QUrl)), this, SLOT(openUrlInExternalBrowser(QUrl)));
@@ -51,7 +53,7 @@ WebScrap::WebScrap(QUrl url, QRect scrapRect, QGraphicsItem * parent)
void WebScrap::setScrapRect(QRect r) {
m_scrapRect = r;
setGeometry(QRectF(pos(), r.size()));
- // if (progress() == 1)
+ if (! m_isLoading)
page()->mainFrame()->setScrollPosition(scrapRect().topLeft());
}
@@ -99,9 +101,14 @@ QSize WebScrap::pageSize() const {
return m_pageSize;
}
-void WebScrap::onLoad() {
+void WebScrap::onLoadStarted() {
+ m_isLoading = true;
+}
+
+void WebScrap::onLoadFinished() {
page()->mainFrame()->setScrollPosition(scrapRect().topLeft());
page()->setViewportSize(pageSize());
+ m_isLoading = false;
update();
}
@@ -113,7 +120,7 @@ void WebScrap::onRefresh() {
m_webshot.fill(Qt::transparent);
QPainter painter(&m_webshot);
page()->mainFrame()->render(&painter);
- // if (progress() == 1)
+ if (! m_isLoading)
reload();
}
@@ -140,7 +147,7 @@ void WebScrap::paint(QPainter* painter, const QStyleOptionGraphicsItem* options,
painter->setPen(Qt::NoPen);
painter->drawPath(clipPath);
painter->setClipPath(clipPath);
- if (1) { // if (progress() >= 1) {
+ if (! m_isLoading) {
painter->fillRect(options->rect, Qt::white);
QGraphicsWebView::paint(painter, options, widget);
painter->save();
diff --git a/webscrap.h b/webscrap.h
index 7dd78e4..0612198 100644
--- a/webscrap.h
+++ b/webscrap.h
@@ -36,7 +36,8 @@ public:
QSize pageSize() const;
public slots:
- void onLoad();
+ void onLoadFinished();
+ void onLoadStarted();
void onRefresh();
void setScrapRect(QRect rect);
void openUrlInExternalBrowser(QUrl url);
@@ -55,6 +56,7 @@ private:
bool m_isDimensionsFixed;
QPixmap m_loadingPix, m_adjustablePix, m_arrowPix, m_scalePix;
QSize m_pageSize;
+ bool m_isLoading;
};
class WebScrapContainer : public QGraphicsWidget {