From 7c400a77dfbc3f45cb7626962b6e055d582f4cba Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Tue, 17 Nov 2009 15:18:38 +1000 Subject: Partial fix for QTBUGT-5845 --- demos/declarative/webbrowser/webbrowser.qml | 15 ++++---- .../graphicsitems/qmlgraphicswebview.cpp | 44 +++++++++++++--------- .../graphicsitems/qmlgraphicswebview_p.h | 1 + 3 files changed, 36 insertions(+), 24 deletions(-) diff --git a/demos/declarative/webbrowser/webbrowser.qml b/demos/declarative/webbrowser/webbrowser.qml index 8a01af5..23e0a20 100644 --- a/demos/declarative/webbrowser/webbrowser.qml +++ b/demos/declarative/webbrowser/webbrowser.qml @@ -202,11 +202,11 @@ Item { var sc = zoom/zoomFactor; scaleAnim.to = sc; flickVX.from = flickable.viewportX - flickVX.to = Math.min(Math.max(0,centerX-flickable.width/2),webView.width*sc-flickable.width) - finalX.value = Math.min(Math.max(0,centerX-flickable.width/2),webView.width*sc-flickable.width) + flickVX.to = Math.max(0,Math.min(centerX-flickable.width/2,webView.width*sc-flickable.width)) + finalX.value = flickVX.to flickVY.from = flickable.viewportY - flickVY.to = Math.min(Math.max(0,centerY-flickable.height/2),webView.height*sc-flickable.height) - finalY.value = Math.min(Math.max(0,centerY-flickable.height/2),webView.height*sc-flickable.height) + flickVY.to = Math.max(0,Math.min(centerY-flickable.height/2,webView.height*sc-flickable.height)) + finalY.value = flickVY.to finalZoom.value = zoom quickZoom.start() } @@ -214,11 +214,12 @@ Item { preferredWidth: flickable.width preferredHeight: flickable.height - zoomFactor: flickable.width > 980 ? flickable.width : flickable.width/980 + zoomFactor: flickable.width > 980 ? 1 : flickable.width/980 onUrlChanged: { if (url != null) { webBrowser.urlString = url.toString(); } } - onDoubleClick: { if (!heuristicZoom(clickX,clickY,2.5)) { - var zf = flickable.width > 980 ? flickable.width : flickable.width/980; + onDoubleClick: { + if (!heuristicZoom(clickX,clickY,2.5)) { + var zf = flickable.width > 980 ? 1 : flickable.width/980; doZoom(zf,clickX/zoomFactor*zf,clickY/zoomFactor*zf) } } diff --git a/src/declarative/graphicsitems/qmlgraphicswebview.cpp b/src/declarative/graphicsitems/qmlgraphicswebview.cpp index c8bb504..da6c00d 100644 --- a/src/declarative/graphicsitems/qmlgraphicswebview.cpp +++ b/src/declarative/graphicsitems/qmlgraphicswebview.cpp @@ -252,11 +252,9 @@ void QmlGraphicsWebView::pageUrlChanged() { Q_D(QmlGraphicsWebView); - if (d->preferredwidth) { - page()->setViewportSize(QSize(d->preferredwidth,-1)); - } else { - page()->setViewportSize(QSize(-1,-1)); - } + page()->setViewportSize(QSize( + d->preferredwidth>0 ? d->preferredwidth : width(), + d->preferredheight>0 ? d->preferredheight : height())); expandToWebPage(); if ((d->url.isEmpty() && page()->mainFrame()->url() != QUrl(QLatin1String("about:blank"))) @@ -310,11 +308,11 @@ void QmlGraphicsWebView::setUrl(const QUrl &url) if (isComponentComplete()) { d->url = url; - if (d->preferredwidth) { - page()->setViewportSize(QSize(d->preferredwidth,-1)); - } else { - page()->setViewportSize(QSize(-1,-1)); - } + page()->setViewportSize(QSize( + d->preferredwidth>0 ? d->preferredwidth : width(), + d->preferredheight>0 ? d->preferredheight : height())); + if (d->preferredwidth > 0 && d->preferredheight > 0) + page()->setPreferredContentsSize(QSize(d->preferredwidth,d->preferredheight)); QUrl seturl = url; if (seturl.isEmpty()) seturl = QUrl(QLatin1String("about:blank")); @@ -388,6 +386,11 @@ void QmlGraphicsWebView::focusChanged(bool hasFocus) QmlGraphicsItem::focusChanged(hasFocus); } +void QmlGraphicsWebView::initialLayout() +{ + // nothing useful to do at this point +} + void QmlGraphicsWebView::contentsSizeChanged(const QSize&) { expandToWebPage(); @@ -397,9 +400,10 @@ void QmlGraphicsWebView::expandToWebPage() { Q_D(QmlGraphicsWebView); QSize cs = page()->mainFrame()->contentsSize(); - qreal zoom = zoomFactor(); - if (cs.width() < d->preferredwidth*zoom) - cs.setWidth(d->preferredwidth*zoom); + if (cs.width() < d->preferredwidth) + cs.setWidth(d->preferredwidth); + if (cs.height() < d->preferredheight) + cs.setHeight(d->preferredheight); if (widthValid()) cs.setWidth(width()); if (heightValid()) @@ -828,7 +832,9 @@ void QmlGraphicsWebView::setZoomFactor(qreal factor) return; page()->mainFrame()->setZoomFactor(factor); - page()->setViewportSize(QSize(d->preferredwidth ? d->preferredwidth : -1,-1)); + page()->setViewportSize(QSize( + d->preferredwidth>0 ? d->preferredwidth*factor : width()*factor, + d->preferredheight>0 ? d->preferredheight*factor : height()*factor)); expandToWebPage(); emit zoomFactorChanged(); @@ -952,7 +958,8 @@ void QmlGraphicsWebView::setPage(QWebPage *page) } d->page = page; d->page->setViewportSize(QSize( - d->preferredwidth>0 ? d->preferredwidth : -1, -1)); + d->preferredwidth>0 ? d->preferredwidth : width(), + d->preferredheight>0 ? d->preferredheight : height())); d->page->mainFrame()->setScrollBarPolicy(Qt::Horizontal,Qt::ScrollBarAlwaysOff); d->page->mainFrame()->setScrollBarPolicy(Qt::Vertical,Qt::ScrollBarAlwaysOff); connect(d->page,SIGNAL(repaintRequested(QRect)),this,SLOT(paintPage(QRect))); @@ -960,6 +967,7 @@ void QmlGraphicsWebView::setPage(QWebPage *page) connect(d->page->mainFrame(), SIGNAL(titleChanged(QString)), this, SIGNAL(titleChanged(QString))); connect(d->page->mainFrame(), SIGNAL(iconChanged()), this, SIGNAL(iconChanged())); connect(d->page->mainFrame(), SIGNAL(contentsSizeChanged(QSize)), this, SLOT(contentsSizeChanged(QSize))); + connect(d->page->mainFrame(), SIGNAL(initialLayoutCompleted()), this, SLOT(initialLayout())); connect(d->page,SIGNAL(loadStarted()),this,SLOT(doLoadStarted())); connect(d->page,SIGNAL(loadProgress(int)),this,SLOT(doLoadProgress(int))); @@ -1023,7 +1031,8 @@ void QmlGraphicsWebView::setHtml(const QString &html, const QUrl &baseUrl) { Q_D(QmlGraphicsWebView); page()->setViewportSize(QSize( - d->preferredwidth>0 ? d->preferredwidth : width(), height())); + d->preferredwidth>0 ? d->preferredwidth : width(), + d->preferredheight>0 ? d->preferredheight : height())); if (isComponentComplete()) page()->mainFrame()->setHtml(html, baseUrl); else { @@ -1037,7 +1046,8 @@ void QmlGraphicsWebView::setContent(const QByteArray &data, const QString &mimeT { Q_D(QmlGraphicsWebView); page()->setViewportSize(QSize( - d->preferredwidth>0 ? d->preferredwidth : width(), height())); + d->preferredwidth>0 ? d->preferredwidth : width(), + d->preferredheight>0 ? d->preferredheight : height())); if (isComponentComplete()) page()->mainFrame()->setContent(data,mimeType,qmlContext(this)->resolvedUrl(baseUrl)); diff --git a/src/declarative/graphicsitems/qmlgraphicswebview_p.h b/src/declarative/graphicsitems/qmlgraphicswebview_p.h index 1d55830..e2e4888 100644 --- a/src/declarative/graphicsitems/qmlgraphicswebview_p.h +++ b/src/declarative/graphicsitems/qmlgraphicswebview_p.h @@ -208,6 +208,7 @@ private Q_SLOTS: void windowObjectCleared(); void pageUrlChanged(); void contentsSizeChanged(const QSize&); + void initialLayout(); protected: void drawContents(QPainter *, const QRect &); -- cgit v0.12