summaryrefslogtreecommitdiffstats
path: root/src/declarative
diff options
context:
space:
mode:
Diffstat (limited to 'src/declarative')
-rw-r--r--src/declarative/debugger/qmldebug.cpp26
-rw-r--r--src/declarative/debugger/qmldebugclient.cpp2
-rw-r--r--src/declarative/graphicsitems/qmlgraphicsgridview.cpp26
-rw-r--r--src/declarative/graphicsitems/qmlgraphicsgridview_p.h5
-rw-r--r--src/declarative/graphicsitems/qmlgraphicslistview.cpp30
-rw-r--r--src/declarative/graphicsitems/qmlgraphicslistview_p.h3
-rw-r--r--src/declarative/graphicsitems/qmlgraphicspainteditem.cpp38
-rw-r--r--src/declarative/graphicsitems/qmlgraphicspainteditem_p.h4
-rw-r--r--src/declarative/graphicsitems/qmlgraphicspainteditem_p_p.h3
-rw-r--r--src/declarative/graphicsitems/qmlgraphicspositioners.cpp6
-rw-r--r--src/declarative/graphicsitems/qmlgraphicswebview.cpp95
-rw-r--r--src/declarative/graphicsitems/qmlgraphicswebview_p.h10
-rw-r--r--src/declarative/qml/qmlenginedebug.cpp1
-rw-r--r--src/declarative/util/qmltimer.cpp2
14 files changed, 171 insertions, 80 deletions
diff --git a/src/declarative/debugger/qmldebug.cpp b/src/declarative/debugger/qmldebug.cpp
index 1403ffa..f24b456 100644
--- a/src/declarative/debugger/qmldebug.cpp
+++ b/src/declarative/debugger/qmldebug.cpp
@@ -107,31 +107,35 @@ int QmlEngineDebugPrivate::getId()
void QmlEngineDebugPrivate::remove(QmlEngineDebug *c, QmlDebugEnginesQuery *q)
{
- QmlEngineDebugPrivate *p = (QmlEngineDebugPrivate *)QObjectPrivate::get(c);
- if (p && q)
+ if (c && q) {
+ QmlEngineDebugPrivate *p = (QmlEngineDebugPrivate *)QObjectPrivate::get(c);
p->enginesQuery.remove(q->m_queryId);
+ }
}
void QmlEngineDebugPrivate::remove(QmlEngineDebug *c,
QmlDebugRootContextQuery *q)
{
- QmlEngineDebugPrivate *p = (QmlEngineDebugPrivate *)QObjectPrivate::get(c);
- if (p && q)
+ if (c && q) {
+ QmlEngineDebugPrivate *p = (QmlEngineDebugPrivate *)QObjectPrivate::get(c);
p->rootContextQuery.remove(q->m_queryId);
+ }
}
void QmlEngineDebugPrivate::remove(QmlEngineDebug *c, QmlDebugObjectQuery *q)
{
- QmlEngineDebugPrivate *p = (QmlEngineDebugPrivate *)QObjectPrivate::get(c);
- if (p && q)
+ if (c && q) {
+ QmlEngineDebugPrivate *p = (QmlEngineDebugPrivate *)QObjectPrivate::get(c);
p->objectQuery.remove(q->m_queryId);
+ }
}
void QmlEngineDebugPrivate::remove(QmlEngineDebug *c, QmlDebugExpressionQuery *q)
{
- QmlEngineDebugPrivate *p = (QmlEngineDebugPrivate *)QObjectPrivate::get(c);
- if (p && q)
+ if (c && q) {
+ QmlEngineDebugPrivate *p = (QmlEngineDebugPrivate *)QObjectPrivate::get(c);
p->expressionQuery.remove(q->m_queryId);
+ }
}
@@ -424,6 +428,9 @@ void QmlEngineDebug::removeWatch(QmlDebugWatch *watch)
{
Q_D(QmlEngineDebug);
+ if (!watch || watch->state() == QmlDebugWatch::Inactive || watch->state() == QmlDebugWatch::Dead)
+ return;
+
watch->setState(QmlDebugWatch::Inactive);
d->watched.remove(watch->queryId());
@@ -555,7 +562,8 @@ QmlDebugWatch::QmlDebugWatch(QObject *parent)
QmlDebugWatch::~QmlDebugWatch()
{
- m_client->removeWatch(this);
+ if (m_client)
+ m_client->removeWatch(this);
}
int QmlDebugWatch::queryId() const
diff --git a/src/declarative/debugger/qmldebugclient.cpp b/src/declarative/debugger/qmldebugclient.cpp
index 4888758..2cd1301 100644
--- a/src/declarative/debugger/qmldebugclient.cpp
+++ b/src/declarative/debugger/qmldebugclient.cpp
@@ -178,6 +178,8 @@ bool QmlDebugClient::isConnected() const
{
Q_D(const QmlDebugClient);
+ if (!d->client)
+ return false;
return d->client->isConnected();
}
diff --git a/src/declarative/graphicsitems/qmlgraphicsgridview.cpp b/src/declarative/graphicsitems/qmlgraphicsgridview.cpp
index 10050f2..1b94426 100644
--- a/src/declarative/graphicsitems/qmlgraphicsgridview.cpp
+++ b/src/declarative/graphicsitems/qmlgraphicsgridview.cpp
@@ -565,6 +565,7 @@ void QmlGraphicsGridViewPrivate::updateTrackedItem()
void QmlGraphicsGridViewPrivate::createHighlight()
{
Q_Q(QmlGraphicsGridView);
+ bool changed = false;
if (highlight) {
if (trackedItem == highlight)
trackedItem = 0;
@@ -575,6 +576,7 @@ void QmlGraphicsGridViewPrivate::createHighlight()
delete highlightYAnimator;
highlightXAnimator = 0;
highlightYAnimator = 0;
+ changed = true;
}
if (currentItem) {
@@ -606,8 +608,11 @@ void QmlGraphicsGridViewPrivate::createHighlight()
highlightYAnimator->setTarget(QmlMetaProperty(highlight->item, QLatin1String("y")));
highlightYAnimator->setDuration(150);
highlightYAnimator->setEnabled(autoHighlight);
+ changed = true;
}
}
+ if (changed)
+ emit q->highlightChanged();
}
void QmlGraphicsGridViewPrivate::updateHighlight()
@@ -887,6 +892,25 @@ QmlGraphicsItem *QmlGraphicsGridView::currentItem()
}
/*!
+ \qmlproperty Item GridView::highlightItem
+
+ \c highlightItem holds the highlight item, which was created
+ from the \l highlight component.
+
+ The highlightItem is managed by the view unless
+ \l highlightFollowsCurrentItem is set to false.
+
+ \sa highlight, highlightFollowsCurrentItem
+*/
+QmlGraphicsItem *QmlGraphicsGridView::highlightItem()
+{
+ Q_D(QmlGraphicsGridView);
+ if (!d->highlight)
+ return 0;
+ return d->highlight->item;
+}
+
+/*!
\qmlproperty int GridView::count
This property holds the number of items in the view.
*/
@@ -909,7 +933,7 @@ int QmlGraphicsGridView::count() const
The below example demonstrates how to make a simple highlight:
\snippet doc/src/snippets/declarative/gridview/gridview.qml 1
- \sa highlightFollowsCurrentItem
+ \sa highlightItem, highlightFollowsCurrentItem
*/
QmlComponent *QmlGraphicsGridView::highlight() const
{
diff --git a/src/declarative/graphicsitems/qmlgraphicsgridview_p.h b/src/declarative/graphicsitems/qmlgraphicsgridview_p.h
index 3fd36bd..3e09cf3 100644
--- a/src/declarative/graphicsitems/qmlgraphicsgridview_p.h
+++ b/src/declarative/graphicsitems/qmlgraphicsgridview_p.h
@@ -62,8 +62,11 @@ class Q_DECLARATIVE_EXPORT QmlGraphicsGridView : public QmlGraphicsFlickable
Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged)
Q_PROPERTY(QmlGraphicsItem *currentItem READ currentItem NOTIFY currentIndexChanged)
Q_PROPERTY(int count READ count NOTIFY countChanged)
+
Q_PROPERTY(QmlComponent *highlight READ highlight WRITE setHighlight)
+ Q_PROPERTY(QmlGraphicsItem *highlightItem READ highlightItem NOTIFY highlightChanged)
Q_PROPERTY(bool highlightFollowsCurrentItem READ highlightFollowsCurrentItem WRITE setHighlightFollowsCurrentItem)
+
Q_PROPERTY(Flow flow READ flow WRITE setFlow)
Q_PROPERTY(bool keyNavigationWraps READ isWrapEnabled WRITE setWrapEnabled)
Q_PROPERTY(int cacheBuffer READ cacheBuffer WRITE setCacheBuffer)
@@ -85,6 +88,7 @@ public:
void setCurrentIndex(int idx);
QmlGraphicsItem *currentItem();
+ QmlGraphicsItem *highlightItem();
int count() const;
QmlComponent *highlight() const;
@@ -123,6 +127,7 @@ Q_SIGNALS:
void currentIndexChanged();
void cellWidthChanged();
void cellHeightChanged();
+ void highlightChanged();
protected:
virtual void viewportMoved();
diff --git a/src/declarative/graphicsitems/qmlgraphicslistview.cpp b/src/declarative/graphicsitems/qmlgraphicslistview.cpp
index 53287a6..12bf0d8 100644
--- a/src/declarative/graphicsitems/qmlgraphicslistview.cpp
+++ b/src/declarative/graphicsitems/qmlgraphicslistview.cpp
@@ -641,6 +641,7 @@ void QmlGraphicsListViewPrivate::updateTrackedItem()
void QmlGraphicsListViewPrivate::createHighlight()
{
Q_Q(QmlGraphicsListView);
+ bool changed = false;
if (highlight) {
if (trackedItem == highlight)
trackedItem = 0;
@@ -651,6 +652,7 @@ void QmlGraphicsListViewPrivate::createHighlight()
delete highlightSizeAnimator;
highlightPosAnimator = 0;
highlightSizeAnimator = 0;
+ changed = true;
}
if (currentItem) {
@@ -687,8 +689,11 @@ void QmlGraphicsListViewPrivate::createHighlight()
highlightSizeAnimator->setVelocity(highlightResizeSpeed);
highlightSizeAnimator->setTarget(QmlMetaProperty(highlight->item, sizeProp));
highlightSizeAnimator->setEnabled(autoHighlight);
+ changed = true;
}
}
+ if (changed)
+ emit q->highlightChanged();
}
void QmlGraphicsListViewPrivate::updateHighlight()
@@ -871,7 +876,7 @@ void QmlGraphicsListViewPrivate::flickX(qreal velocity)
if (v > 0)
dist = -dist;
dist = -_moveX.value() - snapPosAt(-(_moveX.value() - highlightRangeStart) + dist) + highlightRangeStart;
- if (v < 0 && dist >= 0 || v > 0 && dist <= 0) {
+ if ((v < 0 && dist >= 0) || (v > 0 && dist <= 0)) {
timeline.reset(_moveX);
fixupX();
return;
@@ -929,7 +934,7 @@ void QmlGraphicsListViewPrivate::flickY(qreal velocity)
if (v > 0)
dist = -dist;
dist = -_moveY.value() - snapPosAt(-(_moveY.value() - highlightRangeStart) + dist) + highlightRangeStart;
- if (v < 0 && dist >= 0 || v > 0 && dist <= 0) {
+ if ((v < 0 && dist >= 0) || (v > 0 && dist <= 0)) {
timeline.reset(_moveY);
fixupY();
return;
@@ -1202,6 +1207,25 @@ QmlGraphicsItem *QmlGraphicsListView::currentItem()
}
/*!
+ \qmlproperty Item ListView::highlightItem
+
+ \c highlightItem holds the highlight item, which was created
+ from the \l highlight component.
+
+ The highlightItem is managed by the view unless
+ \l highlightFollowsCurrentItem is set to false.
+
+ \sa highlight, highlightFollowsCurrentItem
+*/
+QmlGraphicsItem *QmlGraphicsListView::highlightItem()
+{
+ Q_D(QmlGraphicsListView);
+ if (!d->highlight)
+ return 0;
+ return d->highlight->item;
+}
+
+/*!
\qmlproperty int ListView::count
This property holds the number of items in the view.
*/
@@ -1228,7 +1252,7 @@ int QmlGraphicsListView::count() const
\snippet doc/src/snippets/declarative/listview/listview.qml 1
\image trivialListView.png
- \sa highlightFollowsCurrentItem
+ \sa highlightItem, highlightFollowsCurrentItem
*/
QmlComponent *QmlGraphicsListView::highlight() const
{
diff --git a/src/declarative/graphicsitems/qmlgraphicslistview_p.h b/src/declarative/graphicsitems/qmlgraphicslistview_p.h
index 3f46434..b8a6e1f 100644
--- a/src/declarative/graphicsitems/qmlgraphicslistview_p.h
+++ b/src/declarative/graphicsitems/qmlgraphicslistview_p.h
@@ -66,6 +66,7 @@ class Q_DECLARATIVE_EXPORT QmlGraphicsListView : public QmlGraphicsFlickable
Q_PROPERTY(int count READ count NOTIFY countChanged)
Q_PROPERTY(QmlComponent *highlight READ highlight WRITE setHighlight)
+ Q_PROPERTY(QmlGraphicsItem *highlightItem READ highlightItem NOTIFY highlightChanged)
Q_PROPERTY(bool highlightFollowsCurrentItem READ highlightFollowsCurrentItem WRITE setHighlightFollowsCurrentItem)
Q_PROPERTY(qreal highlightMoveSpeed READ highlightMoveSpeed WRITE setHighlightMoveSpeed NOTIFY highlightMoveSpeedChanged)
Q_PROPERTY(qreal highlightResizeSpeed READ highlightResizeSpeed WRITE setHighlightResizeSpeed NOTIFY highlightResizeSpeedChanged)
@@ -99,6 +100,7 @@ public:
void setCurrentIndex(int idx);
QmlGraphicsItem *currentItem();
+ QmlGraphicsItem *highlightItem();
int count() const;
QmlComponent *highlight() const;
@@ -155,6 +157,7 @@ Q_SIGNALS:
void sectionExpressionChanged();
void highlightMoveSpeedChanged();
void highlightResizeSpeedChanged();
+ void highlightChanged();
protected:
virtual void viewportMoved();
diff --git a/src/declarative/graphicsitems/qmlgraphicspainteditem.cpp b/src/declarative/graphicsitems/qmlgraphicspainteditem.cpp
index a0d9b09..2c849c8 100644
--- a/src/declarative/graphicsitems/qmlgraphicspainteditem.cpp
+++ b/src/declarative/graphicsitems/qmlgraphicspainteditem.cpp
@@ -209,17 +209,12 @@ void QmlGraphicsPaintedItem::paint(QPainter *p, const QStyleOptionGraphicsItem *
++inpaint;
- QRectF clipf = p->clipRegion().boundingRect();
- if (clipf.isEmpty())
- clipf = mapToScene(content).boundingRect(); // ### Inefficient: Maps toScene and then fromScene
- else
- clipf = mapToScene(clipf).boundingRect();
-
- const QRect clip = mapFromScene(clipf).boundingRect().toRect();
+ const QRect clip = p->clipRegion().boundingRect();
QRegion topaint(clip);
topaint &= content;
QRegion uncached(content);
+ p->setRenderHints(QPainter::SmoothPixmapTransform, d->smooth);
int cachesize=0;
for (int i=0; i<d->imagecache.count(); ++i) {
@@ -229,7 +224,7 @@ void QmlGraphicsPaintedItem::paint(QPainter *p, const QStyleOptionGraphicsItem *
if (!d->cachefrozen) {
if (!d->imagecache[i]->dirty.isNull() && topaint.contains(d->imagecache[i]->dirty)) {
QPainter qp(&d->imagecache[i]->image);
- qp.setRenderHints(QPainter::HighQualityAntialiasing | QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform, d->smooth);
+ qp.setRenderHints(QPainter::HighQualityAntialiasing | QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform, d->smoothCache);
qp.translate(-area.x(), -area.y());
if (d->fillColor.isValid()){
if(d->fillColor.alpha() < 255){
@@ -285,7 +280,7 @@ void QmlGraphicsPaintedItem::paint(QPainter *p, const QStyleOptionGraphicsItem *
img.fill(d->fillColor);
{
QPainter qp(&img);
- qp.setRenderHints(QPainter::HighQualityAntialiasing | QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform, d->smooth);
+ qp.setRenderHints(QPainter::HighQualityAntialiasing | QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform, d->smoothCache);
qp.translate(-r.x(),-r.y());
drawContents(&qp, r);
@@ -383,5 +378,30 @@ QColor QmlGraphicsPaintedItem::fillColor() const
return d->fillColor;
}
+/*!
+ \qmlproperty bool PaintedItem::smoothCache
+
+ Controls whether the cached tiles of which the item is composed are
+ rendered smoothly when they are generated.
+
+ This is in addition toe Item::smooth, which controls the smooth painting of
+ the already-painted cached tiles under transformation.
+*/
+bool QmlGraphicsPaintedItem::smoothCache() const
+{
+ Q_D(const QmlGraphicsPaintedItem);
+ return d->smoothCache;
+}
+
+void QmlGraphicsPaintedItem::setSmoothCache(bool on)
+{
+ Q_D(QmlGraphicsPaintedItem);
+ if (d->smoothCache != on) {
+ d->smoothCache = on;
+ clearCache();
+ }
+}
+
+
QT_END_NAMESPACE
diff --git a/src/declarative/graphicsitems/qmlgraphicspainteditem_p.h b/src/declarative/graphicsitems/qmlgraphicspainteditem_p.h
index 99873a7..8d629b3 100644
--- a/src/declarative/graphicsitems/qmlgraphicspainteditem_p.h
+++ b/src/declarative/graphicsitems/qmlgraphicspainteditem_p.h
@@ -59,6 +59,7 @@ class Q_DECLARATIVE_EXPORT QmlGraphicsPaintedItem : public QmlGraphicsItem
Q_PROPERTY(QSize contentsSize READ contentsSize WRITE setContentsSize)
Q_PROPERTY(QColor fillColor READ fillColor WRITE setFillColor NOTIFY fillColorChanged)
Q_PROPERTY(int cacheSize READ cacheSize WRITE setCacheSize)
+ Q_PROPERTY(bool smoothCache READ smoothCache WRITE setSmoothCache)
public:
QmlGraphicsPaintedItem(QmlGraphicsItem *parent=0);
@@ -70,6 +71,9 @@ public:
int cacheSize() const;
void setCacheSize(int pixels);
+ bool smoothCache() const;
+ void setSmoothCache(bool on);
+
QColor fillColor() const;
void setFillColor(const QColor&);
diff --git a/src/declarative/graphicsitems/qmlgraphicspainteditem_p_p.h b/src/declarative/graphicsitems/qmlgraphicspainteditem_p_p.h
index a744557..a938ecf 100644
--- a/src/declarative/graphicsitems/qmlgraphicspainteditem_p_p.h
+++ b/src/declarative/graphicsitems/qmlgraphicspainteditem_p_p.h
@@ -63,7 +63,7 @@ class QmlGraphicsPaintedItemPrivate : public QmlGraphicsItemPrivate
public:
QmlGraphicsPaintedItemPrivate()
- : max_imagecache_size(100000), fillColor(Qt::transparent), cachefrozen(false)
+ : max_imagecache_size(100000), fillColor(Qt::transparent), cachefrozen(false), smoothCache(true)
{
}
@@ -82,6 +82,7 @@ public:
QSize contentsSize;
QColor fillColor;
bool cachefrozen;
+ bool smoothCache;
};
QT_END_NAMESPACE
diff --git a/src/declarative/graphicsitems/qmlgraphicspositioners.cpp b/src/declarative/graphicsitems/qmlgraphicspositioners.cpp
index cbb4b13..ced9d55 100644
--- a/src/declarative/graphicsitems/qmlgraphicspositioners.cpp
+++ b/src/declarative/graphicsitems/qmlgraphicspositioners.cpp
@@ -443,7 +443,7 @@ Column {
Column {
move: Transition {
NumberAnimation {
- properties: "y"
+ matchProperties: "y"
ease: "easeOutBounce"
}
}
@@ -584,7 +584,7 @@ Row {
id: positioner
move: Transition {
NumberAnimation {
- properties: "x"
+ matchProperties: "x"
ease: "easeOutBounce"
}
}
@@ -738,7 +738,7 @@ Grid {
Grid {
move: Transition {
NumberAnimation {
- properties: "x,y"
+ matchProperties: "x,y"
ease: "easeOutBounce"
}
}
diff --git a/src/declarative/graphicsitems/qmlgraphicswebview.cpp b/src/declarative/graphicsitems/qmlgraphicswebview.cpp
index 827144d..14c4352 100644
--- a/src/declarative/graphicsitems/qmlgraphicswebview.cpp
+++ b/src/declarative/graphicsitems/qmlgraphicswebview.cpp
@@ -166,7 +166,7 @@ class QmlGraphicsWebViewPrivate : public QmlGraphicsPaintedItemPrivate
public:
QmlGraphicsWebViewPrivate()
- : QmlGraphicsPaintedItemPrivate(), page(0), preferredwidth(0), pagewidth(0),
+ : QmlGraphicsPaintedItemPrivate(), page(0), preferredwidth(0), preferredheight(0),
progress(1.0), status(QmlGraphicsWebView::Null), pending(PendingNone),
newWindowComponent(0), newWindowParent(0),
windowObjects(this),
@@ -177,8 +177,7 @@ public:
QUrl url; // page url might be different if it has not loaded yet
QWebPage *page;
- int preferredwidth;
- int pagewidth;
+ int preferredwidth, preferredheight;
qreal progress;
QmlGraphicsWebView::Status status;
QString statusText;
@@ -227,7 +226,8 @@ public:
width: 490
height: 400
scale: 0.5
- smooth: true
+ smooth: false
+ smoothCache: true
}
\endqml
@@ -341,22 +341,15 @@ void QmlGraphicsWebView::pageUrlChanged()
{
Q_D(QmlGraphicsWebView);
- // Reset zooming to full
- qreal zf = 1.0;
if (d->preferredwidth) {
- if (d->pagewidth)
- zf = qreal(d->preferredwidth)/d->pagewidth;
- page()->mainFrame()->setZoomFactor(zf);
page()->setViewportSize(QSize(d->preferredwidth,-1));
} else {
- page()->mainFrame()->setZoomFactor(zf);
page()->setViewportSize(QSize(-1,-1));
}
- emit zooming(zf,0,0);
expandToWebPage();
if ((d->url.isEmpty() && page()->mainFrame()->url() != QUrl(QLatin1String("about:blank")))
- || d->url != page()->mainFrame()->url() && !page()->mainFrame()->url().isEmpty())
+ || (d->url != page()->mainFrame()->url() && !page()->mainFrame()->url().isEmpty()))
{
d->url = page()->mainFrame()->url();
if (d->url == QUrl(QLatin1String("about:blank")))
@@ -406,15 +399,11 @@ void QmlGraphicsWebView::setUrl(const QUrl &url)
if (isComponentComplete()) {
d->url = url;
- qreal zf = 1.0;
if (d->preferredwidth) {
- if (d->pagewidth)
- zf = qreal(d->preferredwidth)/d->pagewidth;
page()->setViewportSize(QSize(d->preferredwidth,-1));
} else {
page()->setViewportSize(QSize(-1,-1));
}
- page()->mainFrame()->setZoomFactor(zf);
QUrl seturl = url;
if (seturl.isEmpty())
seturl = QUrl(QLatin1String("about:blank"));
@@ -444,35 +433,27 @@ void QmlGraphicsWebView::setPreferredWidth(int iw)
{
Q_D(QmlGraphicsWebView);
if (d->preferredwidth == iw) return;
- if (d->pagewidth) {
- if (d->preferredwidth) {
- setZoomFactor(zoomFactor()*iw/d->preferredwidth);
- } else {
- setZoomFactor(qreal(iw)/d->pagewidth);
- }
- }
d->preferredwidth = iw;
expandToWebPage();
emit preferredWidthChanged();
}
/*!
- \qmlproperty int WebView::webPageWidth
- This property holds the page width suggested to the web engine. The zoomFactor
- will be changed to fit this with in preferredWidth.
+ \qmlproperty int WebView::preferredHeight
+ This property holds the ideal height for displaying the current URL.
+ This only affects the area zoomed by heuristicZoom().
*/
-int QmlGraphicsWebView::webPageWidth() const
+int QmlGraphicsWebView::preferredHeight() const
{
Q_D(const QmlGraphicsWebView);
- return d->pagewidth;
+ return d->preferredheight;
}
-
-void QmlGraphicsWebView::setWebPageWidth(int pw)
+void QmlGraphicsWebView::setPreferredHeight(int ih)
{
Q_D(QmlGraphicsWebView);
- if (d->pagewidth == pw) return;
- d->pagewidth = pw;
- expandToWebPage();
+ if (d->preferredheight == ih) return;
+ d->preferredheight = ih;
+ emit preferredHeightChanged();
}
/*!
@@ -715,18 +696,38 @@ void QmlGraphicsWebView::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
delete me;
}
-void QmlGraphicsWebView::heuristicZoom(int clickX, int clickY)
+/*!
+ \qmlmethod bool WebView::heuristicZoom(clickX,clickY,maxzoom)
+
+ Finds a zoom that:
+ \list
+ \i shows a whole item
+ \i includes (\a clickX, \a clickY)
+ \i fits into the preferredWidth and preferredHeight
+ \i zooms by no more than \a maxzoom
+ \i is more than 20% above the current zoom
+ \endlist
+
+ If such a zoom exists, emits zoomTo(zoom,centerX,centerY) and returns true; otherwise,
+ no signal is emitted and returns false.
+*/
+bool QmlGraphicsWebView::heuristicZoom(int clickX, int clickY, qreal maxzoom)
{
Q_D(QmlGraphicsWebView);
qreal ozf = zoomFactor();
- QRect showarea = elementAreaAt(clickX, clickY, 1, 1);
- qreal z = qreal(preferredWidth())*ozf/showarea.width()*.95;
- if ((z/ozf > 0.99 && z/ozf <1.01) || z < qreal(d->preferredwidth)/d->pagewidth) {
- // zoom out
- z = qreal(d->preferredwidth)/d->pagewidth;
+ if (ozf >= maxzoom)
+ return false;
+ 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.2) {
+ QRectF r(showarea.left()/ozf*z, showarea.top()/ozf*z, showarea.width()/ozf*z, showarea.height()/ozf*z);
+ emit zoomTo(z,r.x()+r.width()/2, r.y()+r.height()/2);
+ return true;
+ } else {
+ return false;
}
- QRectF r(showarea.left()/ozf*z, showarea.top()/ozf*z, showarea.width()/ozf*z, showarea.height()/ozf*z);
- emit zooming(z,r.x()+r.width()/2, r.y()+r.height()/2);
}
void QmlGraphicsWebView::mousePressEvent(QGraphicsSceneMouseEvent *event)
@@ -911,7 +912,7 @@ void QmlGraphicsWebView::setZoomFactor(qreal factor)
return;
page()->mainFrame()->setZoomFactor(factor);
- page()->setViewportSize(QSize(d->pagewidth*factor,-1));
+ page()->setViewportSize(QSize(d->preferredwidth ? d->preferredwidth : -1,-1));
expandToWebPage();
emit zoomFactorChanged();
@@ -1239,15 +1240,15 @@ void QmlGraphicsWebView::setNewWindowParent(QmlGraphicsItem *parent)
QRect QmlGraphicsWebView::elementAreaAt(int x, int y, int maxwidth, int maxheight) const
{
QWebHitTestResult hit = page()->mainFrame()->hitTestContent(QPoint(x,y));
+ QRect rv = hit.boundingRect();
QWebElement element = hit.enclosingBlockElement();
- QWebElement parent = element.parent();
if (maxwidth<=0) maxwidth = INT_MAX;
if (maxheight<=0) maxheight = INT_MAX;
- while (!parent.isNull() && parent.geometry().width() <= maxwidth && parent.geometry().height() <= maxheight) {
- element = parent;
- parent = element.parent();
+ while (!element.parent().isNull() && element.geometry().width() <= maxwidth && element.geometry().height() <= maxheight) {
+ rv = element.geometry();
+ element = element.parent();
}
- return element.geometry();
+ return rv;
}
/*!
diff --git a/src/declarative/graphicsitems/qmlgraphicswebview_p.h b/src/declarative/graphicsitems/qmlgraphicswebview_p.h
index 6373246..7c9faf4 100644
--- a/src/declarative/graphicsitems/qmlgraphicswebview_p.h
+++ b/src/declarative/graphicsitems/qmlgraphicswebview_p.h
@@ -94,7 +94,7 @@ class Q_DECLARATIVE_EXPORT QmlGraphicsWebView : public QmlGraphicsPaintedItem
Q_PROPERTY(QString html READ html WRITE setHtml)
Q_PROPERTY(int preferredWidth READ preferredWidth WRITE setPreferredWidth NOTIFY preferredWidthChanged)
- Q_PROPERTY(int webPageWidth READ webPageWidth WRITE setWebPageWidth)
+ Q_PROPERTY(int preferredHeight READ preferredHeight WRITE setPreferredHeight NOTIFY preferredHeightChanged)
Q_PROPERTY(int pixelCacheSize READ pixelCacheSize WRITE setPixelCacheSize)
Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY urlChanged)
Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged)
@@ -127,11 +127,12 @@ public:
qreal zoomFactor() const;
void setZoomFactor(qreal);
+ Q_INVOKABLE bool heuristicZoom(int clickX, int clickY, qreal maxzoom);
int preferredWidth() const;
void setPreferredWidth(int);
- int webPageWidth() const;
- void setWebPageWidth(int);
+ int preferredHeight() const;
+ void setPreferredHeight(int);
enum Status { Null, Ready, Loading, Error };
Status status() const;
@@ -191,11 +192,10 @@ Q_SIGNALS:
void doubleClick(int clickX, int clickY);
- void zooming(qreal zoom, int centerX, int centerY);
+ void zoomTo(qreal zoom, int centerX, int centerY);
public Q_SLOTS:
QVariant evaluateJavaScript(const QString&);
- void heuristicZoom(int clickX, int clickY);
private Q_SLOTS:
void expandToWebPage();
diff --git a/src/declarative/qml/qmlenginedebug.cpp b/src/declarative/qml/qmlenginedebug.cpp
index 20d6fc1..3813d20 100644
--- a/src/declarative/qml/qmlenginedebug.cpp
+++ b/src/declarative/qml/qmlenginedebug.cpp
@@ -99,7 +99,6 @@ QmlEngineDebugServer::QmlObjectProperty
QmlEngineDebugServer::propertyData(QObject *obj, int propIdx)
{
QmlObjectProperty rv;
-;
QMetaProperty prop = obj->metaObject()->property(propIdx);
diff --git a/src/declarative/util/qmltimer.cpp b/src/declarative/util/qmltimer.cpp
index 8ee9059..c1b3504 100644
--- a/src/declarative/util/qmltimer.cpp
+++ b/src/declarative/util/qmltimer.cpp
@@ -271,7 +271,7 @@ void QmlTimer::ticked()
emit triggered();
}
-void QmlTimer::stateChanged(QAbstractAnimation::State, QAbstractAnimation::State state)
+void QmlTimer::stateChanged(QAbstractAnimation::State state, QAbstractAnimation::State)
{
Q_D(QmlTimer);
if (d->running && state != QAbstractAnimation::Running) {