diff options
Diffstat (limited to 'src/declarative/graphicsitems/qmlgraphicswebview.cpp')
-rw-r--r-- | src/declarative/graphicsitems/qmlgraphicswebview.cpp | 49 |
1 files changed, 24 insertions, 25 deletions
diff --git a/src/declarative/graphicsitems/qmlgraphicswebview.cpp b/src/declarative/graphicsitems/qmlgraphicswebview.cpp index e21bda3..35dd1f0 100644 --- a/src/declarative/graphicsitems/qmlgraphicswebview.cpp +++ b/src/declarative/graphicsitems/qmlgraphicswebview.cpp @@ -55,12 +55,12 @@ #include "qml.h" #include "qmlengine.h" -#include <private/qmlstate_p.h> -#include <private/qlistmodelinterface_p.h> +#include "qmlstate_p.h" +#include "qlistmodelinterface_p.h" #include "qmlgraphicswebview_p.h" #include "qmlgraphicswebview_p_p.h" -#include <private/qmlgraphicspainteditem_p_p.h> +#include "qmlgraphicspainteditem_p_p.h" QT_BEGIN_NAMESPACE QML_DEFINE_TYPE(Qt,4,6,WebView,QmlGraphicsWebView) @@ -317,8 +317,6 @@ void QmlGraphicsWebView::setUrl(const QUrl &url) 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")); @@ -349,7 +347,7 @@ void QmlGraphicsWebView::setPreferredWidth(int iw) Q_D(QmlGraphicsWebView); if (d->preferredwidth == iw) return; d->preferredwidth = iw; - expandToWebPage(); + //expandToWebPage(); emit preferredWidthChanged(); } @@ -397,7 +395,7 @@ void QmlGraphicsWebView::initialLayout() // nothing useful to do at this point } -void QmlGraphicsWebView::contentsSizeChanged(const QSize&) +void QmlGraphicsWebView::noteContentsSizeChanged(const QSize&) { expandToWebPage(); } @@ -416,10 +414,9 @@ void QmlGraphicsWebView::expandToWebPage() cs.setHeight(height()); if (cs != page()->viewportSize()) { page()->setViewportSize(cs); - clearCache(); - setImplicitWidth(cs.width()); - setImplicitHeight(cs.height()); } + if (cs != contentsSize()) + setContentsSize(cs); } void QmlGraphicsWebView::geometryChanged(const QRectF &newGeometry, @@ -432,9 +429,6 @@ void QmlGraphicsWebView::geometryChanged(const QRectF &newGeometry, void QmlGraphicsWebView::paintPage(const QRect& r) { - Q_D(QmlGraphicsWebView); - if (d->page->mainFrame()->contentsSize() != contentsSize()) - setContentsSize(d->page->mainFrame()->contentsSize()); dirtyCache(r); update(); } @@ -536,7 +530,7 @@ void QmlGraphicsWebView::drawContents(QPainter *p, const QRect &r) page()->mainFrame()->render(p,r); } -static QMouseEvent *sceneMouseEventToMouseEvent(QGraphicsSceneMouseEvent *e) +QMouseEvent *QmlGraphicsWebView::sceneMouseEventToMouseEvent(QGraphicsSceneMouseEvent *e) { QEvent::Type t; switch(e->type()) { @@ -555,15 +549,15 @@ static QMouseEvent *sceneMouseEventToMouseEvent(QGraphicsSceneMouseEvent *e) break; } - QMouseEvent *me = new QMouseEvent(t, e->pos().toPoint(), e->button(), e->buttons(), 0); + QMouseEvent *me = new QMouseEvent(t, (e->pos()/contentsScale()).toPoint(), e->button(), e->buttons(), 0); return me; } -static QMouseEvent *sceneHoverMoveEventToMouseEvent(QGraphicsSceneHoverEvent *e) +QMouseEvent *QmlGraphicsWebView::sceneHoverMoveEventToMouseEvent(QGraphicsSceneHoverEvent *e) { QEvent::Type t = QEvent::MouseMove; - QMouseEvent *me = new QMouseEvent(t, e->pos().toPoint(), Qt::NoButton, Qt::NoButton, 0); + QMouseEvent *me = new QMouseEvent(t, (e->pos()/contentsScale()).toPoint(), Qt::NoButton, Qt::NoButton, 0); return me; } @@ -601,15 +595,15 @@ void QmlGraphicsWebView::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) bool QmlGraphicsWebView::heuristicZoom(int clickX, int clickY, qreal maxzoom) { Q_D(QmlGraphicsWebView); - qreal ozf = zoomFactor(); - if (ozf >= maxzoom) + if (contentsScale() >= maxzoom/zoomFactor()) return false; + qreal ozf = contentsScale(); QRect showarea = elementAreaAt(clickX, clickY, d->preferredwidth/maxzoom, d->preferredheight/maxzoom); - qreal z = qMin(qreal(d->preferredwidth)*ozf/showarea.width(),qreal(d->preferredheight)*ozf/showarea.height()); - if (z > maxzoom) - z = maxzoom; - if (z/ozf > 1.1) { - QRectF r(showarea.left()/ozf*z, showarea.top()/ozf*z, showarea.width()/ozf*z, showarea.height()/ozf*z); + qreal z = qMin(qreal(d->preferredwidth)/showarea.width(),qreal(d->preferredheight)/showarea.height()); + if (z > maxzoom/zoomFactor()) + z = maxzoom/zoomFactor(); + if (z/ozf > 1.2) { + QRectF r(showarea.left()*z, showarea.top()*z, showarea.width()*z, showarea.height()*z); emit zoomTo(z,r.x()+r.width()/2, r.y()+r.height()/2); return true; } else { @@ -963,7 +957,7 @@ void QmlGraphicsWebView::setPage(QWebPage *page) connect(d->page->mainFrame(),SIGNAL(urlChanged(QUrl)),this,SLOT(pageUrlChanged())); 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(contentsSizeChanged(QSize)), this, SLOT(noteContentsSizeChanged(QSize))); connect(d->page->mainFrame(), SIGNAL(initialLayoutCompleted()), this, SLOT(initialLayout())); connect(d->page,SIGNAL(loadStarted()),this,SLOT(doLoadStarted())); @@ -1204,6 +1198,7 @@ QString QmlGraphicsWebPage::chooseFile(QWebFrame *originatingFrame, const QStrin void QmlGraphicsWebPage::javaScriptAlert(QWebFrame *originatingFrame, const QString& msg) { + Q_UNUSED(originatingFrame) emit viewItem()->alert(msg); } @@ -1218,6 +1213,10 @@ bool QmlGraphicsWebPage::javaScriptConfirm(QWebFrame *originatingFrame, const QS bool QmlGraphicsWebPage::javaScriptPrompt(QWebFrame *originatingFrame, const QString& msg, const QString& defaultValue, QString* result) { // Not supported (it's modal) + Q_UNUSED(originatingFrame) + Q_UNUSED(msg) + Q_UNUSED(defaultValue) + Q_UNUSED(result) return false; } |