From b94176e69efc3948696c6774d5a228fc753b5b29 Mon Sep 17 00:00:00 2001 From: Andrew den Exter Date: Fri, 25 Mar 2011 15:28:40 +1000 Subject: Fix width of TextInput micro focus rectangle. Remove the padding QLineControl::cursorRect() adds for region updates. QGraphicsView also grew the rectangle by returning the bounding rect of the transformed rectangle which is fixed by using the same transform for QRect as is used for QRectF. Change-Id: I8d8df9dbc6b4250e4e5392871191123a76b304a0 Task-number: QTBUG-18343 Reviewed-by: Martin Jones --- .../graphicsitems/qdeclarativetextinput.cpp | 6 ++-- src/gui/graphicsview/qgraphicsview.cpp | 2 +- .../tst_qdeclarativetextedit.cpp | 20 ++++++++++++ .../tst_qdeclarativetextinput.cpp | 37 +++++++++++++++++++--- 4 files changed, 57 insertions(+), 8 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativetextinput.cpp b/src/declarative/graphicsitems/qdeclarativetextinput.cpp index af18c90..e1c2107 100644 --- a/src/declarative/graphicsitems/qdeclarativetextinput.cpp +++ b/src/declarative/graphicsitems/qdeclarativetextinput.cpp @@ -555,8 +555,10 @@ QRect QDeclarativeTextInput::cursorRectangle() const { Q_D(const QDeclarativeTextInput); QRect r = d->control->cursorRect(); - r.setHeight(r.height()-1); // Make consistent with TextEdit (QLineControl inexplicably adds 1) - r.moveLeft(r.x() - d->hscroll); + // Scroll and make consistent with TextEdit + // QLineControl inexplicably adds 1 to the height and horizontal padding + // for unicode direction markers. + r.adjust(5 - d->hscroll, 0, -4 - d->hscroll, -1); return r; } diff --git a/src/gui/graphicsview/qgraphicsview.cpp b/src/gui/graphicsview/qgraphicsview.cpp index 2b129d7..16268a8 100644 --- a/src/gui/graphicsview/qgraphicsview.cpp +++ b/src/gui/graphicsview/qgraphicsview.cpp @@ -2498,7 +2498,7 @@ QVariant QGraphicsView::inputMethodQuery(Qt::InputMethodQuery query) const else if (value.type() == QVariant::PointF) value = mapFromScene(value.toPointF()); else if (value.type() == QVariant::Rect) - value = mapFromScene(value.toRect()).boundingRect(); + value = d->mapRectFromScene(value.toRect()).toRect(); else if (value.type() == QVariant::Point) value = mapFromScene(value.toPoint()); return value; diff --git a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp index 04ecf91..8f1be6f 100644 --- a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp +++ b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp @@ -148,6 +148,7 @@ private slots: void preeditMicroFocus(); void inputContextMouseHandler(); void inputMethodComposing(); + void cursorRectangleSize(); private: void simulateKey(QDeclarativeView *, int key, Qt::KeyboardModifiers modifiers = 0); @@ -2421,6 +2422,25 @@ void tst_qdeclarativetextedit::inputMethodComposing() QCOMPARE(spy.count(), 2); } +void tst_qdeclarativetextedit::cursorRectangleSize() +{ + QDeclarativeView *canvas = createView(SRCDIR "/data/CursorRect.qml"); + QVERIFY(canvas->rootObject() != 0); + canvas->show(); + canvas->setFocus(); + QApplication::setActiveWindow(canvas); + QTest::qWaitForWindowShown(canvas); + + QDeclarativeTextEdit *textEdit = qobject_cast(canvas->rootObject()); + QVERIFY(textEdit != 0); + textEdit->setFocus(Qt::OtherFocusReason); + QRectF cursorRect = textEdit->positionToRectangle(textEdit->cursorPosition()); + QRectF microFocusFromScene = canvas->scene()->inputMethodQuery(Qt::ImMicroFocus).toRectF(); + QRectF microFocusFromApp= QApplication::focusWidget()->inputMethodQuery(Qt::ImMicroFocus).toRectF(); + + QCOMPARE(microFocusFromScene.size(), cursorRect.size()); + QCOMPARE(microFocusFromApp.size(), cursorRect.size()); +} QTEST_MAIN(tst_qdeclarativetextedit) #include "tst_qdeclarativetextedit.moc" diff --git a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp index a35a2c9..81713e0 100644 --- a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp +++ b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp @@ -135,6 +135,7 @@ private slots: void preeditMicroFocus(); void inputContextMouseHandler(); void inputMethodComposing(); + void cursorRectangleSize(); private: void simulateKey(QDeclarativeView *, int key); @@ -1628,12 +1629,11 @@ void tst_qdeclarativetextinput::cursorDelegate() //Test Delegate gets moved for(int i=0; i<= textInputObject->text().length(); i++){ textInputObject->setCursorPosition(i); - //+5 is because the TextInput cursorRectangle is just a 10xHeight area centered on cursor position - QCOMPARE(textInputObject->cursorRectangle().x() + 5, qRound(delegateObject->x())); + QCOMPARE(textInputObject->cursorRectangle().x(), qRound(delegateObject->x())); QCOMPARE(textInputObject->cursorRectangle().y(), qRound(delegateObject->y())); } textInputObject->setCursorPosition(0); - QCOMPARE(textInputObject->cursorRectangle().x()+5, qRound(delegateObject->x())); + QCOMPARE(textInputObject->cursorRectangle().x(), qRound(delegateObject->x())); QCOMPARE(textInputObject->cursorRectangle().y(), qRound(delegateObject->y())); //Test Delegate gets deleted textInputObject->setCursorDelegate(0); @@ -1722,13 +1722,20 @@ void tst_qdeclarativetextinput::cursorRectangle() QRect r; + // some tolerance for different fonts. +#ifdef Q_OS_LINUX + const int error = 2; +#else + const int error = 5; +#endif + for (int i = 0; i <= 5; ++i) { input.setCursorPosition(i); r = input.cursorRectangle(); int textWidth = fm.width(text.mid(0, i)); - QVERIFY(r.left() < textWidth); - QVERIFY(r.right() > textWidth); + QVERIFY(r.left() < textWidth + error); + QVERIFY(r.right() > textWidth - error); QCOMPARE(input.inputMethodQuery(Qt::ImMicroFocus).toRect(), r); } @@ -2484,6 +2491,26 @@ void tst_qdeclarativetextinput::inputMethodComposing() QCOMPARE(spy.count(), 2); } +void tst_qdeclarativetextinput::cursorRectangleSize() +{ + QDeclarativeView *canvas = createView(SRCDIR "/data/positionAt.qml"); + QVERIFY(canvas->rootObject() != 0); + canvas->show(); + canvas->setFocus(); + QApplication::setActiveWindow(canvas); + QTest::qWaitForWindowShown(canvas); + + QDeclarativeTextInput *textInput = qobject_cast(canvas->rootObject()); + QVERIFY(textInput != 0); + textInput->setFocus(Qt::OtherFocusReason); + QRectF cursorRect = textInput->positionToRectangle(textInput->cursorPosition()); + QRectF microFocusFromScene = canvas->scene()->inputMethodQuery(Qt::ImMicroFocus).toRectF(); + QRectF microFocusFromApp= QApplication::focusWidget()->inputMethodQuery(Qt::ImMicroFocus).toRectF(); + + QCOMPARE(microFocusFromScene.size(), cursorRect.size()); + QCOMPARE(microFocusFromApp.size(), cursorRect.size()); +} + QTEST_MAIN(tst_qdeclarativetextinput) #include "tst_qdeclarativetextinput.moc" -- cgit v0.12 From 462429f5692f810bdd4e04b916db5f9af428d9e4 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 30 Mar 2011 14:09:56 +1000 Subject: Canceling image download while reading causes crash We were deleting a QObject owned by another thread, which is fine if there are no pending events, but very bad if there are, e.g. queued signals due to downloadProgress() updates. Use deleteLater() which is safe to call in any thread. Also call QDeclarativePixmap::clear(QObject *obj) where appropriate to remove connections and ensure we don't handle any unwanted signals after the download is cancelled. Change-Id: Ia8fb41a8cd004d9840e7cec35915f1afdb03ac4d Task-number: QTBUG-18412 Reviewed-by: Aaron Kennedy --- src/declarative/graphicsitems/qdeclarativeborderimage.cpp | 4 +++- src/declarative/graphicsitems/qdeclarativeimagebase.cpp | 3 ++- src/declarative/util/qdeclarativepixmapcache.cpp | 3 ++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativeborderimage.cpp b/src/declarative/graphicsitems/qdeclarativeborderimage.cpp index 8f37e90..45a03a0 100644 --- a/src/declarative/graphicsitems/qdeclarativeborderimage.cpp +++ b/src/declarative/graphicsitems/qdeclarativeborderimage.cpp @@ -300,7 +300,7 @@ void QDeclarativeBorderImage::load() } if (d->url.isEmpty()) { - d->pix.clear(); + d->pix.clear(this); d->status = Null; setImplicitWidth(0); setImplicitHeight(0); @@ -340,6 +340,7 @@ void QDeclarativeBorderImage::load() options |= QDeclarativePixmap::Asynchronous; if (d->cache) options |= QDeclarativePixmap::Cache; + d->pix.clear(this); d->pix.load(qmlEngine(this), d->url, options); if (d->pix.isLoading()) { @@ -472,6 +473,7 @@ void QDeclarativeBorderImage::setGridScaledImage(const QDeclarativeGridScaledIma options |= QDeclarativePixmap::Asynchronous; if (d->cache) options |= QDeclarativePixmap::Cache; + d->pix.clear(this); d->pix.load(qmlEngine(this), d->sciurl, options); if (d->pix.isLoading()) { diff --git a/src/declarative/graphicsitems/qdeclarativeimagebase.cpp b/src/declarative/graphicsitems/qdeclarativeimagebase.cpp index 2de3ba0..8f4416f 100644 --- a/src/declarative/graphicsitems/qdeclarativeimagebase.cpp +++ b/src/declarative/graphicsitems/qdeclarativeimagebase.cpp @@ -176,7 +176,7 @@ void QDeclarativeImageBase::load() Q_D(QDeclarativeImageBase); if (d->url.isEmpty()) { - d->pix.clear(); + d->pix.clear(this); d->status = Null; d->progress = 0.0; setImplicitWidth(0); @@ -191,6 +191,7 @@ void QDeclarativeImageBase::load() options |= QDeclarativePixmap::Asynchronous; if (d->cache) options |= QDeclarativePixmap::Cache; + d->pix.clear(this); d->pix.load(qmlEngine(this), d->url, d->explicitSourceSize ? sourceSize() : QSize(), options); if (d->pix.isLoading()) { diff --git a/src/declarative/util/qdeclarativepixmapcache.cpp b/src/declarative/util/qdeclarativepixmapcache.cpp index 5190eab..9221d78 100644 --- a/src/declarative/util/qdeclarativepixmapcache.cpp +++ b/src/declarative/util/qdeclarativepixmapcache.cpp @@ -426,7 +426,8 @@ void QDeclarativePixmapReader::processJobs() replies.remove(reply); reply->close(); } - delete job; + // deleteLater, since not owned by this thread + job->deleteLater(); } cancelled.clear(); } -- cgit v0.12 From 068652a52f0554b5ceb56798fe5ac4e5049bb9e3 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 31 Mar 2011 09:08:03 +1000 Subject: Rotation transform with NaN angle can cause crash When used in conjunction with Text resulted in massive memory consunmption. Change-Id: I5e19cb54bcd57b1ea32d17641f976f8288611a9e Task-number: QTBUG-18386 Reviewed-by: Charles Yin --- src/gui/graphicsview/qgraphicstransform.cpp | 4 +++- tests/auto/qgraphicstransform/tst_qgraphicstransform.cpp | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/gui/graphicsview/qgraphicstransform.cpp b/src/gui/graphicsview/qgraphicstransform.cpp index 06df788..513c41f 100644 --- a/src/gui/graphicsview/qgraphicstransform.cpp +++ b/src/gui/graphicsview/qgraphicstransform.cpp @@ -92,6 +92,7 @@ #include "qgraphicstransform_p.h" #include #include +#include #ifndef QT_NO_GRAPHICSVIEW QT_BEGIN_NAMESPACE @@ -467,6 +468,7 @@ void QGraphicsRotation::setOrigin(const QVector3D &point) item will be rotated counter-clockwise. Normally the rotation angle will be in the range (-360, 360), but you can also provide numbers outside of this range (e.g., a angle of 370 degrees gives the same result as 10 degrees). + Setting the angle to NaN results in no rotation. \sa origin */ @@ -570,7 +572,7 @@ void QGraphicsRotation::applyTo(QMatrix4x4 *matrix) const { Q_D(const QGraphicsRotation); - if (d->angle == 0. || d->axis.isNull()) + if (d->angle == 0. || d->axis.isNull() || qIsNaN(d->angle)) return; matrix->translate(d->origin); diff --git a/tests/auto/qgraphicstransform/tst_qgraphicstransform.cpp b/tests/auto/qgraphicstransform/tst_qgraphicstransform.cpp index 79f2213..d2b6022 100644 --- a/tests/auto/qgraphicstransform/tst_qgraphicstransform.cpp +++ b/tests/auto/qgraphicstransform/tst_qgraphicstransform.cpp @@ -215,6 +215,10 @@ void tst_QGraphicsTransform::rotation() rotation.setAngle(90); QCOMPARE(transform2D(rotation).map(QPointF(10, 10)), QPointF(10, 10)); QCOMPARE(transform2D(rotation).map(QPointF(20, 10)), QPointF(10, 20)); + + rotation.setOrigin(QVector3D(0, 0, 0)); + rotation.setAngle(qQNaN()); + QCOMPARE(transform2D(rotation).map(QPointF(20, 10)), QPointF(20, 10)); } Q_DECLARE_METATYPE(Qt::Axis); -- cgit v0.12 From af05f64d3edc860c3cf79c7f0bdf2377faae5f40 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 31 Mar 2011 10:32:26 +1000 Subject: Once Image sourceSize is set there is no way to clear it. Image sourceSize lacked a RESET method to allow reverting to the natural size of the image. Change-Id: I4e9089d8e16991375745db553f891bd377143eab Task-number: QTBUG-18442 Reviewed-by: Yann Bodson --- .../graphicsitems/qdeclarativeimage.cpp | 3 +++ .../graphicsitems/qdeclarativeimagebase.cpp | 12 ++++++++++++ .../graphicsitems/qdeclarativeimagebase_p.h | 3 ++- .../qdeclarativeimage/tst_qdeclarativeimage.cpp | 22 ++++++++++++++++++++++ 4 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/declarative/graphicsitems/qdeclarativeimage.cpp b/src/declarative/graphicsitems/qdeclarativeimage.cpp index ed5d5fc..a62d3d2 100644 --- a/src/declarative/graphicsitems/qdeclarativeimage.cpp +++ b/src/declarative/graphicsitems/qdeclarativeimage.cpp @@ -377,6 +377,9 @@ qreal QDeclarativeImage::paintedHeight() const If the source is a non-scalable image (eg. JPEG), the loaded image will be no greater than this property specifies. For some formats (currently only JPEG), the whole image will never actually be loaded into memory. + + Since QtQuick 1.1 the sourceSize can be cleared to the natural size of the image + by setting sourceSize to \c undefined. \note \e {Changing this property dynamically causes the image source to be reloaded, potentially even from the network, if it is not in the disk cache.} diff --git a/src/declarative/graphicsitems/qdeclarativeimagebase.cpp b/src/declarative/graphicsitems/qdeclarativeimagebase.cpp index 8f4416f..daebac4 100644 --- a/src/declarative/graphicsitems/qdeclarativeimagebase.cpp +++ b/src/declarative/graphicsitems/qdeclarativeimagebase.cpp @@ -133,6 +133,18 @@ QSize QDeclarativeImageBase::sourceSize() const return QSize(width != -1 ? width : d->pix.width(), height != -1 ? height : d->pix.height()); } +void QDeclarativeImageBase::resetSourceSize() +{ + Q_D(QDeclarativeImageBase); + if (!d->explicitSourceSize) + return; + d->explicitSourceSize = false; + d->sourcesize = QSize(); + emit sourceSizeChanged(); + if (isComponentComplete()) + load(); +} + bool QDeclarativeImageBase::cache() const { Q_D(const QDeclarativeImageBase); diff --git a/src/declarative/graphicsitems/qdeclarativeimagebase_p.h b/src/declarative/graphicsitems/qdeclarativeimagebase_p.h index abee25d..1763bba 100644 --- a/src/declarative/graphicsitems/qdeclarativeimagebase_p.h +++ b/src/declarative/graphicsitems/qdeclarativeimagebase_p.h @@ -59,7 +59,7 @@ class Q_AUTOTEST_EXPORT QDeclarativeImageBase : public QDeclarativeImplicitSizeI Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged) Q_PROPERTY(bool asynchronous READ asynchronous WRITE setAsynchronous NOTIFY asynchronousChanged) Q_PROPERTY(bool cache READ cache WRITE setCache NOTIFY cacheChanged REVISION 1) - Q_PROPERTY(QSize sourceSize READ sourceSize WRITE setSourceSize NOTIFY sourceSizeChanged) + Q_PROPERTY(QSize sourceSize READ sourceSize WRITE setSourceSize RESET resetSourceSize NOTIFY sourceSizeChanged) Q_PROPERTY(bool mirror READ mirror WRITE setMirror NOTIFY mirrorChanged REVISION 1) public: @@ -80,6 +80,7 @@ public: virtual void setSourceSize(const QSize&); QSize sourceSize() const; + void resetSourceSize(); virtual void setMirror(bool mirror); bool mirror() const; diff --git a/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp b/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp index 9e090d2..c5a3d14 100644 --- a/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp +++ b/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp @@ -91,6 +91,7 @@ private slots: void sourceSize_QTBUG_14303(); void sourceSize_QTBUG_16389(); void nullPixmapPaint(); + void resetSourceSize(); void testQtQuick11Attributes(); void testQtQuick11Attributes_data(); @@ -693,6 +694,27 @@ void tst_qdeclarativeimage::nullPixmapPaint() delete image; } +void tst_qdeclarativeimage::resetSourceSize() +{ + QString src = QUrl::fromLocalFile(SRCDIR "/data/heart200.png").toString(); + QString componentStr = "import QtQuick 1.1\nImage { function reset() { sourceSize = undefined }\nsource: \"" + src + "\"; sourceSize: Qt.size(100,100) }"; + + QDeclarativeComponent component(&engine); + component.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); + QDeclarativeImage *obj = qobject_cast(component.create()); + QVERIFY(obj != 0); + QCOMPARE(obj->pixmap().width(), 100); + QCOMPARE(obj->pixmap().height(), 100); + QCOMPARE(obj->sourceSize().height(), 100); + QCOMPARE(obj->sourceSize().width(), 100); + + QMetaObject::invokeMethod(obj, "reset"); + QCOMPARE(obj->pixmap().width(), 200); + QCOMPARE(obj->pixmap().height(), 200); + QCOMPARE(obj->sourceSize().height(), 200); + QCOMPARE(obj->sourceSize().width(), 200); +} + void tst_qdeclarativeimage::testQtQuick11Attributes() { QFETCH(QString, code); -- cgit v0.12 From 8d9e7bbc1a4efb5b883f66f41c31f9165ef48117 Mon Sep 17 00:00:00 2001 From: Andrew den Exter Date: Thu, 31 Mar 2011 16:22:04 +1000 Subject: Fix auto test failure. Add test file ommited from b94176e69efc3948696c6774d5a228fc753b5b29. Change-Id: Ia5436974a4941f50c8f1636196372e5b8a90be5f --- tests/auto/declarative/qdeclarativetextedit/data/CursorRect.qml | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 tests/auto/declarative/qdeclarativetextedit/data/CursorRect.qml diff --git a/tests/auto/declarative/qdeclarativetextedit/data/CursorRect.qml b/tests/auto/declarative/qdeclarativetextedit/data/CursorRect.qml new file mode 100644 index 0000000..3af0313 --- /dev/null +++ b/tests/auto/declarative/qdeclarativetextedit/data/CursorRect.qml @@ -0,0 +1,8 @@ +import QtQuick 1.0 + +TextEdit { + focus: true + objectName: "myEdit" + width: 50 + text: "This is a long piece of text" +} -- cgit v0.12 From ea304fb207b681ee084c4ce9bc61d1dd847bd7b0 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Fri, 1 Apr 2011 09:29:38 +1000 Subject: PinchArea and Flickable don't work well enough together Allow PinchArea to be more aggressive in grabbing the gesture and keep the gesture until all touches are released. Change-Id: Ic80b7c4c478e1ee3b1c3da0772553756d9d5473f Task-number: QTBUG-17829 Reviewed-by: Bea Lam --- .../graphicsitems/qdeclarativeflickable.cpp | 9 +- .../graphicsitems/qdeclarativepincharea.cpp | 236 +++++++++++---------- .../graphicsitems/qdeclarativepincharea_p.h | 7 +- .../graphicsitems/qdeclarativepincharea_p_p.h | 5 +- .../tst_qdeclarativepincharea.cpp | 73 +++++++ 5 files changed, 219 insertions(+), 111 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativeflickable.cpp b/src/declarative/graphicsitems/qdeclarativeflickable.cpp index f854262..3cc280c 100644 --- a/src/declarative/graphicsitems/qdeclarativeflickable.cpp +++ b/src/declarative/graphicsitems/qdeclarativeflickable.cpp @@ -1339,7 +1339,9 @@ void QDeclarativeFlickable::resizeContent(qreal w, qreal h, QPointF center) Q_D(QDeclarativeFlickable); if (w != d->hData.viewSize) { qreal oldSize = d->hData.viewSize; - setContentWidth(w); + d->hData.viewSize = w; + d->contentItem->setWidth(w); + emit contentWidthChanged(); if (center.x() != 0) { qreal pos = center.x() * w / oldSize; setContentX(contentX() + pos - center.x()); @@ -1347,12 +1349,15 @@ void QDeclarativeFlickable::resizeContent(qreal w, qreal h, QPointF center) } if (h != d->vData.viewSize) { qreal oldSize = d->vData.viewSize; - setContentHeight(h); + d->vData.viewSize = h; + d->contentItem->setHeight(h); + emit contentHeightChanged(); if (center.y() != 0) { qreal pos = center.y() * h / oldSize; setContentY(contentY() + pos - center.y()); } } + d->updateBeginningEnd(); } /*! diff --git a/src/declarative/graphicsitems/qdeclarativepincharea.cpp b/src/declarative/graphicsitems/qdeclarativepincharea.cpp index 9bc3d8d..c30ff8c 100644 --- a/src/declarative/graphicsitems/qdeclarativepincharea.cpp +++ b/src/declarative/graphicsitems/qdeclarativepincharea.cpp @@ -138,6 +138,14 @@ QT_BEGIN_NAMESPACE ignored. */ +/*! + \qmlproperty int PinchEvent::pointCount + + Holds the number of points currently touched. The PinchArea will not react + until two touch points have initited a gesture, but will remain active until + all touch points have been released. +*/ + QDeclarativePinch::QDeclarativePinch() : m_target(0), m_minScale(1.0), m_maxScale(1.0) , m_minRotation(0.0), m_maxRotation(0.0) @@ -295,7 +303,7 @@ bool QDeclarativePinchArea::event(QEvent *event) void QDeclarativePinchArea::updatePinch() { Q_D(QDeclarativePinchArea); - if (d->touchPoints.count() != 2) { + if (d->touchPoints.count() == 0) { if (d->inPinch) { d->stealMouse = false; setKeepMouseGrab(false); @@ -308,127 +316,141 @@ void QDeclarativePinchArea::updatePinch() pe.setPreviousScale(d->pinchLastScale); pe.setStartPoint1(mapFromScene(d->sceneStartPoint1)); pe.setStartPoint2(mapFromScene(d->sceneStartPoint2)); - pe.setPoint1(d->lastPoint1); - pe.setPoint2(d->lastPoint2); + pe.setPoint1(mapFromScene(d->lastPoint1)); + pe.setPoint2(mapFromScene(d->lastPoint2)); emit pinchFinished(&pe); d->pinchStartDist = 0; + d->pinchActivated = false; if (d->pinch && d->pinch->target()) d->pinch->setActive(false); } return; } - if (d->touchPoints.at(0).state() & Qt::TouchPointPressed - || d->touchPoints.at(1).state() & Qt::TouchPointPressed) { - d->sceneStartPoint1 = d->touchPoints.at(0).scenePos(); - d->sceneStartPoint2 = d->touchPoints.at(1).scenePos(); + QTouchEvent::TouchPoint touchPoint1 = d->touchPoints.at(0); + QTouchEvent::TouchPoint touchPoint2 = d->touchPoints.at(d->touchPoints. count() >= 2 ? 1 : 0); + if (d->touchPoints.count() == 2 + && (touchPoint1.state() & Qt::TouchPointPressed || touchPoint2.state() & Qt::TouchPointPressed)) { + d->id1 = touchPoint1.id(); + d->sceneStartPoint1 = touchPoint1.scenePos(); + d->sceneStartPoint2 = touchPoint2.scenePos(); d->inPinch = false; d->pinchRejected = false; - } else if (!d->pinchRejected){ - QDeclarativeItem *grabber = scene() ? qobject_cast(scene()->mouseGrabberItem()) : 0; - if (grabber == this || !grabber || !grabber->keepMouseGrab()) { - const int dragThreshold = QApplication::startDragDistance(); - QPointF p1 = d->touchPoints.at(0).scenePos(); - QPointF p2 = d->touchPoints.at(1).scenePos(); - qreal dx = p1.x() - p2.x(); - qreal dy = p1.y() - p2.y(); - qreal dist = sqrt(dx*dx + dy*dy); - QPointF sceneCenter = (p1 + p2)/2; - qreal angle = QLineF(p1, p2).angle(); - if (angle > 180) - angle -= 360; - if (!d->inPinch) { - if (qAbs(p1.x()-d->sceneStartPoint1.x()) > dragThreshold - || qAbs(p1.y()-d->sceneStartPoint1.y()) > dragThreshold - || qAbs(p2.x()-d->sceneStartPoint2.x()) > dragThreshold - || qAbs(p2.y()-d->sceneStartPoint2.y()) > dragThreshold) { - d->sceneStartCenter = sceneCenter; - d->sceneLastCenter = sceneCenter; - d->pinchStartCenter = mapFromScene(sceneCenter); - d->pinchStartDist = dist; - d->pinchStartAngle = angle; - d->pinchLastScale = 1.0; - d->pinchLastAngle = angle; - d->pinchRotation = 0.0; - d->lastPoint1 = d->touchPoints.at(0).pos(); - d->lastPoint2 = d->touchPoints.at(1).pos(); - QDeclarativePinchEvent pe(d->pinchStartCenter, 1.0, angle, 0.0); - pe.setStartCenter(d->pinchStartCenter); - pe.setPreviousCenter(d->pinchStartCenter); - pe.setPreviousAngle(d->pinchLastAngle); - pe.setPreviousScale(d->pinchLastScale); - pe.setStartPoint1(mapFromScene(d->sceneStartPoint1)); - pe.setStartPoint2(mapFromScene(d->sceneStartPoint2)); - pe.setPoint1(d->lastPoint1); - pe.setPoint2(d->lastPoint2); - emit pinchStarted(&pe); - if (pe.accepted()) { - d->inPinch = true; - d->stealMouse = true; - QGraphicsScene *s = scene(); - if (s && s->mouseGrabberItem() != this) - grabMouse(); - setKeepMouseGrab(true); - if (d->pinch && d->pinch->target()) { - d->pinchStartPos = pinch()->target()->pos(); - d->pinchStartScale = d->pinch->target()->scale(); - d->pinchStartRotation = d->pinch->target()->rotation(); - d->pinch->setActive(true); - } - } else { - d->pinchRejected = true; - } - } - } else if (d->pinchStartDist > 0) { - qreal scale = dist / d->pinchStartDist; - qreal da = d->pinchLastAngle - angle; - if (da > 180) - da -= 360; - else if (da < -180) - da += 360; - d->pinchRotation += da; - QPointF pinchCenter = mapFromScene(sceneCenter); - QDeclarativePinchEvent pe(pinchCenter, scale, angle, d->pinchRotation); + d->pinchActivated = true; + } else if (d->pinchActivated && !d->pinchRejected) { + const int dragThreshold = QApplication::startDragDistance(); + QPointF p1 = touchPoint1.scenePos(); + QPointF p2 = touchPoint2.scenePos(); + qreal dx = p1.x() - p2.x(); + qreal dy = p1.y() - p2.y(); + qreal dist = sqrt(dx*dx + dy*dy); + QPointF sceneCenter = (p1 + p2)/2; + qreal angle = QLineF(p1, p2).angle(); + if (d->touchPoints.count() == 1) { + // If we only have one point then just move the center + if (d->id1 == touchPoint1.id()) + sceneCenter = d->sceneLastCenter + touchPoint1.scenePos() - d->lastPoint1; + else + sceneCenter = d->sceneLastCenter + touchPoint2.scenePos() - d->lastPoint2; + angle = d->pinchLastAngle; + } + d->id1 = touchPoint1.id(); + if (angle > 180) + angle -= 360; + if (!d->inPinch) { + if (d->touchPoints.count() >= 2 + && (qAbs(p1.x()-d->sceneStartPoint1.x()) > dragThreshold + || qAbs(p1.y()-d->sceneStartPoint1.y()) > dragThreshold + || qAbs(p2.x()-d->sceneStartPoint2.x()) > dragThreshold + || qAbs(p2.y()-d->sceneStartPoint2.y()) > dragThreshold)) { + d->sceneStartCenter = sceneCenter; + d->sceneLastCenter = sceneCenter; + d->pinchStartCenter = mapFromScene(sceneCenter); + d->pinchStartDist = dist; + d->pinchStartAngle = angle; + d->pinchLastScale = 1.0; + d->pinchLastAngle = angle; + d->pinchRotation = 0.0; + d->lastPoint1 = p1; + d->lastPoint2 = p2; + QDeclarativePinchEvent pe(d->pinchStartCenter, 1.0, angle, 0.0); pe.setStartCenter(d->pinchStartCenter); - pe.setPreviousCenter(mapFromScene(d->sceneLastCenter)); + pe.setPreviousCenter(d->pinchStartCenter); pe.setPreviousAngle(d->pinchLastAngle); pe.setPreviousScale(d->pinchLastScale); pe.setStartPoint1(mapFromScene(d->sceneStartPoint1)); pe.setStartPoint2(mapFromScene(d->sceneStartPoint2)); - pe.setPoint1(d->touchPoints.at(0).pos()); - pe.setPoint2(d->touchPoints.at(1).pos()); - d->pinchLastScale = scale; - d->sceneLastCenter = sceneCenter; - d->pinchLastAngle = angle; - d->lastPoint1 = d->touchPoints.at(0).pos(); - d->lastPoint2 = d->touchPoints.at(1).pos(); - emit pinchUpdated(&pe); - if (d->pinch && d->pinch->target()) { - qreal s = d->pinchStartScale * scale; - s = qMin(qMax(pinch()->minimumScale(),s), pinch()->maximumScale()); - pinch()->target()->setScale(s); - QPointF pos = sceneCenter - d->sceneStartCenter + d->pinchStartPos; - if (pinch()->axis() & QDeclarativePinch::XAxis) { - qreal x = pos.x(); - if (x < pinch()->xmin()) - x = pinch()->xmin(); - else if (x > pinch()->xmax()) - x = pinch()->xmax(); - pinch()->target()->setX(x); - } - if (pinch()->axis() & QDeclarativePinch::YAxis) { - qreal y = pos.y(); - if (y < pinch()->ymin()) - y = pinch()->ymin(); - else if (y > pinch()->ymax()) - y = pinch()->ymax(); - pinch()->target()->setY(y); - } - if (d->pinchStartRotation >= pinch()->minimumRotation() - && d->pinchStartRotation <= pinch()->maximumRotation()) { - qreal r = d->pinchRotation + d->pinchStartRotation; - r = qMin(qMax(pinch()->minimumRotation(),r), pinch()->maximumRotation()); - pinch()->target()->setRotation(r); + pe.setPoint1(mapFromScene(d->lastPoint1)); + pe.setPoint2(mapFromScene(d->lastPoint2)); + pe.setPointCount(d->touchPoints.count()); + emit pinchStarted(&pe); + if (pe.accepted()) { + d->inPinch = true; + d->stealMouse = true; + QGraphicsScene *s = scene(); + if (s && s->mouseGrabberItem() != this) + grabMouse(); + setKeepMouseGrab(true); + if (d->pinch && d->pinch->target()) { + d->pinchStartPos = pinch()->target()->pos(); + d->pinchStartScale = d->pinch->target()->scale(); + d->pinchStartRotation = d->pinch->target()->rotation(); + d->pinch->setActive(true); } + } else { + d->pinchRejected = true; + } + } + } else if (d->pinchStartDist > 0) { + qreal scale = dist ? dist / d->pinchStartDist : d->pinchLastScale; + qreal da = d->pinchLastAngle - angle; + if (da > 180) + da -= 360; + else if (da < -180) + da += 360; + d->pinchRotation += da; + QPointF pinchCenter = mapFromScene(sceneCenter); + QDeclarativePinchEvent pe(pinchCenter, scale, angle, d->pinchRotation); + pe.setStartCenter(d->pinchStartCenter); + pe.setPreviousCenter(mapFromScene(d->sceneLastCenter)); + pe.setPreviousAngle(d->pinchLastAngle); + pe.setPreviousScale(d->pinchLastScale); + pe.setStartPoint1(mapFromScene(d->sceneStartPoint1)); + pe.setStartPoint2(mapFromScene(d->sceneStartPoint2)); + pe.setPoint1(touchPoint1.pos()); + pe.setPoint2(touchPoint2.pos()); + pe.setPointCount(d->touchPoints.count()); + d->pinchLastScale = scale; + d->sceneLastCenter = sceneCenter; + d->pinchLastAngle = angle; + d->lastPoint1 = touchPoint1.scenePos(); + d->lastPoint2 = touchPoint2.scenePos(); + emit pinchUpdated(&pe); + if (d->pinch && d->pinch->target()) { + qreal s = d->pinchStartScale * scale; + s = qMin(qMax(pinch()->minimumScale(),s), pinch()->maximumScale()); + pinch()->target()->setScale(s); + QPointF pos = sceneCenter - d->sceneStartCenter + d->pinchStartPos; + if (pinch()->axis() & QDeclarativePinch::XAxis) { + qreal x = pos.x(); + if (x < pinch()->xmin()) + x = pinch()->xmin(); + else if (x > pinch()->xmax()) + x = pinch()->xmax(); + pinch()->target()->setX(x); + } + if (pinch()->axis() & QDeclarativePinch::YAxis) { + qreal y = pos.y(); + if (y < pinch()->ymin()) + y = pinch()->ymin(); + else if (y > pinch()->ymax()) + y = pinch()->ymax(); + pinch()->target()->setY(y); + } + if (d->pinchStartRotation >= pinch()->minimumRotation() + && d->pinchStartRotation <= pinch()->maximumRotation()) { + qreal r = d->pinchRotation + d->pinchStartRotation; + r = qMin(qMax(pinch()->minimumRotation(),r), pinch()->maximumRotation()); + pinch()->target()->setRotation(r); } } } diff --git a/src/declarative/graphicsitems/qdeclarativepincharea_p.h b/src/declarative/graphicsitems/qdeclarativepincharea_p.h index 6d04708..b5afea9 100644 --- a/src/declarative/graphicsitems/qdeclarativepincharea_p.h +++ b/src/declarative/graphicsitems/qdeclarativepincharea_p.h @@ -203,11 +203,13 @@ class Q_AUTOTEST_EXPORT QDeclarativePinchEvent : public QObject Q_PROPERTY(QPointF startPoint1 READ startPoint1) Q_PROPERTY(QPointF point2 READ point2) Q_PROPERTY(QPointF startPoint2 READ startPoint2) + Q_PROPERTY(int pointCount READ pointCount) Q_PROPERTY(bool accepted READ accepted WRITE setAccepted) public: QDeclarativePinchEvent(QPointF c, qreal s, qreal a, qreal r) - : QObject(), m_center(c), m_scale(s), m_angle(a), m_rotation(r), m_accepted(true) {} + : QObject(), m_center(c), m_scale(s), m_angle(a), m_rotation(r) + , m_pointCount(0), m_accepted(true) {} QPointF center() const { return m_center; } QPointF startCenter() const { return m_startCenter; } @@ -229,6 +231,8 @@ public: void setPoint2(QPointF p) { m_point2 = p; } QPointF startPoint2() const { return m_startPoint2; } void setStartPoint2(QPointF p) { m_startPoint2 = p; } + int pointCount() const { return m_pointCount; } + void setPointCount(int count) { m_pointCount = count; } bool accepted() const { return m_accepted; } void setAccepted(bool a) { m_accepted = a; } @@ -246,6 +250,7 @@ private: QPointF m_point2; QPointF m_startPoint1; QPointF m_startPoint2; + int m_pointCount; bool m_accepted; }; diff --git a/src/declarative/graphicsitems/qdeclarativepincharea_p_p.h b/src/declarative/graphicsitems/qdeclarativepincharea_p_p.h index cd5cf2a..3264948 100644 --- a/src/declarative/graphicsitems/qdeclarativepincharea_p_p.h +++ b/src/declarative/graphicsitems/qdeclarativepincharea_p_p.h @@ -68,7 +68,8 @@ class QDeclarativePinchAreaPrivate : public QDeclarativeItemPrivate public: QDeclarativePinchAreaPrivate() : absorb(true), stealMouse(false), inPinch(false) - , pinchRejected(false), pinch(0), pinchStartDist(0), pinchStartScale(1.0) + , pinchRejected(false), pinchActivated(false) + , pinch(0), pinchStartDist(0), pinchStartScale(1.0) , pinchLastScale(1.0), pinchStartRotation(0.0), pinchStartAngle(0.0) , pinchLastAngle(0.0), pinchRotation(0.0) { @@ -88,6 +89,7 @@ public: bool stealMouse : 1; bool inPinch : 1; bool pinchRejected : 1; + bool pinchActivated : 1; QDeclarativePinch *pinch; QPointF sceneStartPoint1; QPointF sceneStartPoint2; @@ -105,6 +107,7 @@ public: QPointF sceneLastCenter; QPointF pinchStartPos; QList touchPoints; + int id1; }; QT_END_NAMESPACE diff --git a/tests/auto/declarative/qdeclarativepincharea/tst_qdeclarativepincharea.cpp b/tests/auto/declarative/qdeclarativepincharea/tst_qdeclarativepincharea.cpp index f175033..90506ba 100644 --- a/tests/auto/declarative/qdeclarativepincharea/tst_qdeclarativepincharea.cpp +++ b/tests/auto/declarative/qdeclarativepincharea/tst_qdeclarativepincharea.cpp @@ -43,6 +43,7 @@ #include #include #include +#include #include #include @@ -58,6 +59,7 @@ private slots: void pinchProperties(); void scale(); void pan(); + void flickable(); private: QDeclarativeView *createView(); @@ -301,6 +303,77 @@ void tst_QDeclarativePinchArea::pan() delete canvas; } +void tst_QDeclarativePinchArea::flickable() +{ + QDeclarativeView *canvas = createView(); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/flickresize.qml")); + canvas->show(); + canvas->setFocus(); + QTest::qWaitForWindowShown(canvas); + QVERIFY(canvas->rootObject() != 0); + qApp->processEvents(); + + QDeclarativePinchArea *pinchArea = canvas->rootObject()->findChild("pincharea"); + QDeclarativePinch *pinch = pinchArea->pinch(); + QVERIFY(pinchArea != 0); + QVERIFY(pinch != 0); + + QDeclarativeFlickable *root = qobject_cast(canvas->rootObject()); + QVERIFY(root != 0); + + QWidget *vp = canvas->viewport(); + + QPoint p1(110, 80); + QPoint p2(100, 100); + + // begin by moving one touch point (mouse) + QTest::mousePress(vp, Qt::LeftButton, 0, canvas->mapFromScene(p1)); + QTest::touchEvent(vp).press(0, p1); + { + p1 -= QPoint(10,10); + QMouseEvent mv(QEvent::MouseMove, canvas->mapFromScene(p1), Qt::LeftButton, Qt::LeftButton,Qt::NoModifier); + QApplication::sendEvent(canvas->viewport(), &mv); + QTest::touchEvent(vp).move(0, p1); + } + { + p1 -= QPoint(10,10); + QMouseEvent mv(QEvent::MouseMove, canvas->mapFromScene(p1), Qt::LeftButton, Qt::LeftButton,Qt::NoModifier); + QApplication::sendEvent(vp, &mv); + QTest::touchEvent(vp).move(0, p1); + } + { + p1 -= QPoint(10,10); + QMouseEvent mv(QEvent::MouseMove, canvas->mapFromScene(p1), Qt::LeftButton, Qt::LeftButton,Qt::NoModifier); + QApplication::sendEvent(vp, &mv); + QTest::touchEvent(vp).move(0, p1); + } + + // Flickable has reacted to the gesture + QVERIFY(root->isMoving()); + QVERIFY(root->property("scale").toReal() == 1.0); + + // add another touch point and continue moving + QTest::touchEvent(vp).stationary(0).press(1, p2); + p1 -= QPoint(10,10); + p2 += QPoint(10,10); + QTest::touchEvent(vp).move(0, p1).move(1, p2); + + QCOMPARE(root->property("scale").toReal(), 1.0); + + p1 -= QPoint(10,10); + p2 += QPoint(10,10); + QTest::touchEvent(vp).move(0, p1).move(1, p2); + + // PinchArea has stolen the gesture. + QVERIFY(!root->isMoving()); + QVERIFY(root->property("scale").toReal() > 1.0); + + QTest::mouseRelease(vp, Qt::LeftButton, 0, canvas->mapFromScene(p1)); + QTest::touchEvent(vp).release(0, p1).release(1, p2); + + delete canvas; +} + QDeclarativeView *tst_QDeclarativePinchArea::createView() { QDeclarativeView *canvas = new QDeclarativeView(0); -- cgit v0.12 From 1ff7c423308feeaa73e1eab6e20147f5c3d2ccd3 Mon Sep 17 00:00:00 2001 From: Andrew den Exter Date: Thu, 31 Mar 2011 16:46:02 +1000 Subject: Fix TextInput auto test failure on mac. Allow for some error due to additional padding on mac. Change-Id: Iee9ce8eb9c4cec2f96c22340162f628ffcbd44d1 Reviewed-by: Bea Lam --- .../qdeclarativetextinput/tst_qdeclarativetextinput.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp index 81713e0..ef32ee3 100644 --- a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp +++ b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp @@ -1741,7 +1741,7 @@ void tst_qdeclarativetextinput::cursorRectangle() // Check the cursor rectangle remains within the input bounding rect when auto scrolling. QVERIFY(r.left() < input.boundingRect().width()); - QVERIFY(r.right() >= input.width()); + QVERIFY(r.right() >= input.width() - error); for (int i = 6; i < text.length(); ++i) { input.setCursorPosition(i); @@ -2242,18 +2242,25 @@ void tst_qdeclarativetextinput::preeditAutoScroll() QCOMPARE(input.positionAt(0), 0); QCOMPARE(input.positionAt(input.width()), 5); + // some tolerance for different fonts. +#ifdef Q_OS_LINUX + const int error = 2; +#else + const int error = 5; +#endif + // test if the preedit is larger than the text input that the // character preceding the cursor is still visible. qreal x = input.positionToRectangle(0).x(); for (int i = 0; i < 3; ++i) { ic.sendPreeditText(preeditText, i + 1); - QVERIFY(input.cursorRectangle().right() >= fm.width(preeditText.at(i))); + QVERIFY(input.cursorRectangle().right() >= fm.width(preeditText.at(i)) - error); QVERIFY(input.positionToRectangle(0).x() < x); x = input.positionToRectangle(0).x(); } for (int i = 1; i >= 0; --i) { ic.sendPreeditText(preeditText, i + 1); - QVERIFY(input.cursorRectangle().right() >= fm.width(preeditText.at(i))); + QVERIFY(input.cursorRectangle().right() >= fm.width(preeditText.at(i)) - error); QVERIFY(input.positionToRectangle(0).x() > x); x = input.positionToRectangle(0).x(); } -- cgit v0.12 From 1f38d41854fa2daa51d938a4eb398752b1751e0b Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Fri, 1 Apr 2011 10:36:49 +1000 Subject: Changing width of RTL positioner doesn't relayout If the width of the layout changes then the items must be laid out again. Change-Id: I2b97bd45d07842fd3da2a0637391473ed6d78aa8 Task-number: QTBUG-18501 Reviewed-by: Michael Brasser --- .../graphicsitems/qdeclarativepositioners.cpp | 10 ++++++++++ .../tst_qdeclarativepositioners.cpp | 22 ++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/declarative/graphicsitems/qdeclarativepositioners.cpp b/src/declarative/graphicsitems/qdeclarativepositioners.cpp index 8a9bdb3..e76fc03 100644 --- a/src/declarative/graphicsitems/qdeclarativepositioners.cpp +++ b/src/declarative/graphicsitems/qdeclarativepositioners.cpp @@ -609,6 +609,11 @@ void QDeclarativeRow::setLayoutDirection(Qt::LayoutDirection layoutDirection) QDeclarativeBasePositionerPrivate *d = static_cast(QDeclarativeBasePositionerPrivate::get(this)); if (d->layoutDirection != layoutDirection) { d->layoutDirection = layoutDirection; + // For RTL layout the positioning changes when the width changes. + if (d->layoutDirection == Qt::RightToLeft) + d->addItemChangeListener(d, QDeclarativeItemPrivate::Geometry); + else + d->removeItemChangeListener(d, QDeclarativeItemPrivate::Geometry); prePositioning(); emit layoutDirectionChanged(); emit effectiveLayoutDirectionChanged(); @@ -907,6 +912,11 @@ void QDeclarativeGrid::setLayoutDirection(Qt::LayoutDirection layoutDirection) QDeclarativeBasePositionerPrivate *d = static_cast(QDeclarativeBasePositionerPrivate::get(this)); if (d->layoutDirection != layoutDirection) { d->layoutDirection = layoutDirection; + // For RTL layout the positioning changes when the width changes. + if (d->layoutDirection == Qt::RightToLeft) + d->addItemChangeListener(d, QDeclarativeItemPrivate::Geometry); + else + d->removeItemChangeListener(d, QDeclarativeItemPrivate::Geometry); prePositioning(); emit layoutDirectionChanged(); emit effectiveLayoutDirectionChanged(); diff --git a/tests/auto/declarative/qdeclarativepositioners/tst_qdeclarativepositioners.cpp b/tests/auto/declarative/qdeclarativepositioners/tst_qdeclarativepositioners.cpp index 92ab722..78821cb 100644 --- a/tests/auto/declarative/qdeclarativepositioners/tst_qdeclarativepositioners.cpp +++ b/tests/auto/declarative/qdeclarativepositioners/tst_qdeclarativepositioners.cpp @@ -154,6 +154,15 @@ void tst_QDeclarativePositioners::test_horizontal_rtl() QCOMPARE(row->width(), 110.0); QCOMPARE(row->height(), 50.0); + // Change the width of the row and check that items stay to the right + row->setWidth(200); + QCOMPARE(one->x(), 150.0); + QCOMPARE(one->y(), 0.0); + QCOMPARE(two->x(), 130.0); + QCOMPARE(two->y(), 0.0); + QCOMPARE(three->x(), 90.0); + QCOMPARE(three->y(), 0.0); + delete canvas; } @@ -527,6 +536,19 @@ void tst_QDeclarativePositioners::test_grid_rightToLeft() QCOMPARE(grid->width(), 100.0); QCOMPARE(grid->height(), 100.0); + // Change the width of the grid and check that items stay to the right + grid->setWidth(200); + QCOMPARE(one->x(), 150.0); + QCOMPARE(one->y(), 0.0); + QCOMPARE(two->x(), 130.0); + QCOMPARE(two->y(), 0.0); + QCOMPARE(three->x(), 100.0); + QCOMPARE(three->y(), 0.0); + QCOMPARE(four->x(), 150.0); + QCOMPARE(four->y(), 50.0); + QCOMPARE(five->x(), 140.0); + QCOMPARE(five->y(), 50.0); + delete canvas; } -- cgit v0.12 From 538a415b8296db36355609d6e84137b9354967a7 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Fri, 1 Apr 2011 13:07:31 +1000 Subject: Add missing test file. Missing from ea304fb207b681ee084c4ce9bc61d1dd847bd7b0 Change-Id: If69b16fe71c69c174968868afed5647d6ea414a8 Task-number: QTBUG-17829 --- .../qdeclarativepincharea/data/flickresize.qml | 50 ++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 tests/auto/declarative/qdeclarativepincharea/data/flickresize.qml diff --git a/tests/auto/declarative/qdeclarativepincharea/data/flickresize.qml b/tests/auto/declarative/qdeclarativepincharea/data/flickresize.qml new file mode 100644 index 0000000..2da58fc --- /dev/null +++ b/tests/auto/declarative/qdeclarativepincharea/data/flickresize.qml @@ -0,0 +1,50 @@ +import QtQuick 1.1 + +Flickable { + id: flick + property real scale: 1.0 + width: 640 + height: 360 + contentWidth: 500 + contentHeight: 500 + + PinchArea { + objectName: "pincharea" + width: Math.max(flick.contentWidth, flick.width) + height: Math.max(flick.contentHeight, flick.height) + + property real initialWidth + property real initialHeight + onPinchStarted: { + initialWidth = flick.contentWidth + initialHeight = flick.contentHeight + } + + onPinchUpdated: { + // adjust content pos due to drag + flick.contentX += pinch.previousCenter.x - pinch.center.x + flick.contentY += pinch.previousCenter.y - pinch.center.y + + // resize content + flick.resizeContent(initialWidth * pinch.scale, initialHeight * pinch.scale, pinch.center) + flick.scale = pinch.scale + } + + onPinchFinished: { + // Move its content within bounds. + flick.returnToBounds() + } + + Rectangle { + width: flick.contentWidth + height: flick.contentHeight + color: "white" + Rectangle { + anchors.centerIn: parent + width: parent.width-40 + height: parent.height-40 + color: "blue" + } + } + } +} -- cgit v0.12