summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/declarative/graphicsitems/qdeclarativeflickable.cpp38
-rw-r--r--src/declarative/graphicsitems/qdeclarativeitem.cpp24
-rw-r--r--src/declarative/graphicsitems/qdeclarativeitem_p.h23
-rw-r--r--src/declarative/graphicsitems/qdeclarativemousearea.cpp40
-rw-r--r--src/declarative/util/qdeclarativesmoothedanimation.cpp4
-rw-r--r--sync.profile16
-rw-r--r--tests/auto/declarative/qdeclarativedebugjs/tst_qdeclarativedebugjs.cpp4
-rw-r--r--tests/auto/declarative/qdeclarativedebugobservermode/tst_qdeclarativedebugobservermode.cpp4
-rw-r--r--tests/auto/declarative/qdeclarativeengine/tst_qdeclarativeengine.cpp7
-rw-r--r--tests/auto/declarative/qdeclarativeflickable/data/nestedStopAtBounds.qml38
-rw-r--r--tests/auto/declarative/qdeclarativeflickable/tst_qdeclarativeflickable.cpp82
-rw-r--r--tests/auto/declarative/qdeclarativefocusscope/data/notifications.qml81
-rw-r--r--tests/auto/declarative/qdeclarativefocusscope/tst_qdeclarativefocusscope.cpp293
-rw-r--r--tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp179
-rw-r--r--tests/auto/declarative/qdeclarativemousearea/data/nestedStopAtBounds.qml44
-rw-r--r--tests/auto/declarative/qdeclarativemousearea/tst_qdeclarativemousearea.cpp96
-rw-r--r--tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp36
-rw-r--r--tests/auto/declarative/qdeclarativesmoothedanimation/data/smoothedanimationZeroDuration.qml12
-rw-r--r--tests/auto/declarative/qdeclarativesmoothedanimation/tst_qdeclarativesmoothedanimation.cpp21
-rw-r--r--tests/auto/declarative/qdeclarativevisualdatamodel/tst_qdeclarativevisualdatamodel.cpp2
20 files changed, 920 insertions, 124 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativeflickable.cpp b/src/declarative/graphicsitems/qdeclarativeflickable.cpp
index edbd9782..64ae2094 100644
--- a/src/declarative/graphicsitems/qdeclarativeflickable.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeflickable.cpp
@@ -799,22 +799,19 @@ void QDeclarativeFlickablePrivate::handleMouseMoveEvent(QGraphicsSceneMouseEvent
newY = minY + (newY - minY) / 2;
if (newY < maxY && maxY - minY <= 0)
newY = maxY + (newY - maxY) / 2;
- if (boundsBehavior == QDeclarativeFlickable::StopAtBounds && (newY > minY || newY < maxY)) {
- rejectY = true;
- if (newY < maxY) {
- newY = maxY;
- rejectY = false;
- }
- if (newY > minY) {
- newY = minY;
- rejectY = false;
- }
+ if (boundsBehavior == QDeclarativeFlickable::StopAtBounds && newY <= maxY) {
+ newY = maxY;
+ rejectY = vData.pressPos == maxY && dy < 0;
+ }
+ if (boundsBehavior == QDeclarativeFlickable::StopAtBounds && newY >= minY) {
+ newY = minY;
+ rejectY = vData.pressPos == minY && dy > 0;
}
if (!rejectY && stealMouse && dy != 0) {
vData.move.setValue(qRound(newY));
vMoved = true;
}
- if (qAbs(dy) > QApplication::startDragDistance())
+ if (!rejectY && qAbs(dy) > QApplication::startDragDistance())
stealY = true;
}
}
@@ -831,23 +828,20 @@ void QDeclarativeFlickablePrivate::handleMouseMoveEvent(QGraphicsSceneMouseEvent
newX = minX + (newX - minX) / 2;
if (newX < maxX && maxX - minX <= 0)
newX = maxX + (newX - maxX) / 2;
- if (boundsBehavior == QDeclarativeFlickable::StopAtBounds && (newX > minX || newX < maxX)) {
- rejectX = true;
- if (newX < maxX) {
- newX = maxX;
- rejectX = false;
- }
- if (newX > minX) {
- newX = minX;
- rejectX = false;
- }
+ if (boundsBehavior == QDeclarativeFlickable::StopAtBounds && newX <= maxX) {
+ newX = maxX;
+ rejectX = hData.pressPos == maxX && dx < 0;
+ }
+ if (boundsBehavior == QDeclarativeFlickable::StopAtBounds && newX >= minX) {
+ newX = minX;
+ rejectX = hData.pressPos == minX && dx > 0;
}
if (!rejectX && stealMouse && dx != 0) {
hData.move.setValue(qRound(newX));
hMoved = true;
}
- if (qAbs(dx) > QApplication::startDragDistance())
+ if (!rejectX && qAbs(dx) > QApplication::startDragDistance())
stealX = true;
}
}
diff --git a/src/declarative/graphicsitems/qdeclarativeitem.cpp b/src/declarative/graphicsitems/qdeclarativeitem.cpp
index 99b3857d..c3bb5d9f 100644
--- a/src/declarative/graphicsitems/qdeclarativeitem.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeitem.cpp
@@ -2744,9 +2744,27 @@ QDeclarativeItem *QDeclarativeItem::childAt(qreal x, qreal y) const
void QDeclarativeItemPrivate::focusChanged(bool flag)
{
Q_Q(QDeclarativeItem);
- if (!(flags & QGraphicsItem::ItemIsFocusScope) && parent)
- emit q->activeFocusChanged(flag); //see also QDeclarativeItemPrivate::subFocusItemChange()
- emit q->focusChanged(flag);
+
+ if (hadActiveFocus != flag) {
+ hadActiveFocus = flag;
+ emit q->activeFocusChanged(flag);
+ }
+
+ QDeclarativeItem *focusItem = q;
+ for (QDeclarativeItem *p = q->parentItem(); p; p = p->parentItem()) {
+ if (p->flags() & QGraphicsItem::ItemIsFocusScope) {
+ if (!flag && QGraphicsItemPrivate::get(p)->focusScopeItem != focusItem)
+ break;
+ if (p->d_func()->hadActiveFocus != flag) {
+ p->d_func()->hadActiveFocus = flag;
+ emit p->activeFocusChanged(flag);
+ }
+ focusItem = p;
+ }
+ }
+
+ // For all but the top most focus scope/item this will be called for us by QGraphicsItem.
+ focusItem->d_func()->focusScopeItemChange(flag);
}
QDeclarativeListProperty<QObject> QDeclarativeItemPrivate::resources()
diff --git a/src/declarative/graphicsitems/qdeclarativeitem_p.h b/src/declarative/graphicsitems/qdeclarativeitem_p.h
index 8ef91887..20262307 100644
--- a/src/declarative/graphicsitems/qdeclarativeitem_p.h
+++ b/src/declarative/graphicsitems/qdeclarativeitem_p.h
@@ -128,8 +128,8 @@ public:
componentComplete(true), keepMouse(false),
smooth(false), transformOriginDirty(true), doneEventPreHandler(false),
inheritedLayoutMirror(false), effectiveLayoutMirror(false), isMirrorImplicit(true),
- inheritMirrorFromParent(false), inheritMirrorFromItem(false), keyHandler(0),
- mWidth(0), mHeight(0), mImplicitWidth(0), mImplicitHeight(0), attachedLayoutDirection(0), hadSubFocusItem(false)
+ inheritMirrorFromParent(false), inheritMirrorFromItem(false), hadFocus(false), hadActiveFocus(false), keyHandler(0),
+ mWidth(0), mHeight(0), mImplicitWidth(0), mImplicitHeight(0), attachedLayoutDirection(0)
{
QGraphicsItemPrivate::acceptedMouseButtons = 0;
isDeclarativeItem = 1;
@@ -289,6 +289,8 @@ public:
bool isMirrorImplicit:1;
bool inheritMirrorFromParent:1;
bool inheritMirrorFromItem:1;
+ bool hadFocus:1;
+ bool hadActiveFocus:1;
QDeclarativeItemKeyFilter *keyHandler;
@@ -299,7 +301,6 @@ public:
QDeclarativeLayoutMirroringAttached* attachedLayoutDirection;
- bool hadSubFocusItem;
QPointF computeTransformOrigin() const;
@@ -312,22 +313,14 @@ public:
}
// Reimplemented from QGraphicsItemPrivate
- virtual void subFocusItemChange()
- {
- bool hasSubFocusItem = subFocusItem != 0;
- if (((flags & QGraphicsItem::ItemIsFocusScope) || !parent) && hasSubFocusItem != hadSubFocusItem)
- emit q_func()->activeFocusChanged(hasSubFocusItem);
- //see also QDeclarativeItemPrivate::focusChanged
- hadSubFocusItem = hasSubFocusItem;
- }
-
- // Reimplemented from QGraphicsItemPrivate
virtual void focusScopeItemChange(bool isSubFocusItem)
{
- emit q_func()->focusChanged(isSubFocusItem);
+ if (hadFocus != isSubFocusItem) {
+ hadFocus = isSubFocusItem;
+ emit q_func()->focusChanged(isSubFocusItem);
+ }
}
-
// Reimplemented from QGraphicsItemPrivate
virtual void siblingOrderChange()
{
diff --git a/src/declarative/graphicsitems/qdeclarativemousearea.cpp b/src/declarative/graphicsitems/qdeclarativemousearea.cpp
index a7c38ea8..4752ec32 100644
--- a/src/declarative/graphicsitems/qdeclarativemousearea.cpp
+++ b/src/declarative/graphicsitems/qdeclarativemousearea.cpp
@@ -530,39 +530,35 @@ void QDeclarativeMouseArea::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
curLocalPos = event->scenePos();
}
- const int dragThreshold = QApplication::startDragDistance();
- qreal dx = qAbs(curLocalPos.x() - startLocalPos.x());
- qreal dy = qAbs(curLocalPos.y() - startLocalPos.y());
-
if (keepMouseGrab() && d->stealMouse)
d->drag->setActive(true);
bool dragX = drag()->axis() & QDeclarativeDrag::XAxis;
bool dragY = drag()->axis() & QDeclarativeDrag::YAxis;
- if (dragX && d->drag->active()) {
- qreal x = (curLocalPos.x() - startLocalPos.x()) + d->startX;
- if (x < drag()->xmin())
- x = drag()->xmin();
- else if (x > drag()->xmax())
- x = drag()->xmax();
- drag()->target()->setX(x);
- }
- if (dragY && d->drag->active()) {
- qreal y = (curLocalPos.y() - startLocalPos.y()) + d->startY;
- if (y < drag()->ymin())
- y = drag()->ymin();
- else if (y > drag()->ymax())
- y = drag()->ymax();
- drag()->target()->setY(y);
+ const qreal x = dragX
+ ? qBound(d->drag->xmin(), d->startX + curLocalPos.x() - startLocalPos.x(), d->drag->xmax())
+ : d->startX;
+ const qreal y = dragY
+ ? qBound(d->drag->ymin(), d->startY + curLocalPos.y() - startLocalPos.y(), d->drag->ymax())
+ : d->startY;
+
+ if (d->drag->active()) {
+ if (dragX && dragY)
+ d->drag->target()->setPos(x, y);
+ else if (dragX)
+ d->drag->target()->setX(x);
+ else if (dragY)
+ d->drag->target()->setY(y);
}
if (!keepMouseGrab()) {
- if ((!dragY && dy < dragThreshold && dragX && dx > dragThreshold)
- || (!dragX && dx < dragThreshold && dragY && dy > dragThreshold)
- || (dragX && dragY && (dx > dragThreshold || dy > dragThreshold))) {
+ const int dragThreshold = QApplication::startDragDistance();
+
+ if (qAbs(x - d->startX) > dragThreshold || qAbs(y - d->startY) > dragThreshold) {
setKeepMouseGrab(true);
d->stealMouse = true;
+ d->startScene = event->scenePos();
}
}
diff --git a/src/declarative/util/qdeclarativesmoothedanimation.cpp b/src/declarative/util/qdeclarativesmoothedanimation.cpp
index 1e68a7a1..240bc5d6 100644
--- a/src/declarative/util/qdeclarativesmoothedanimation.cpp
+++ b/src/declarative/util/qdeclarativesmoothedanimation.cpp
@@ -100,10 +100,10 @@ bool QSmoothedAnimation::recalc()
s = (invert? qreal(-1.0): qreal(1.0)) * s;
- if (userDuration > 0 && velocity > 0) {
+ if (userDuration >= 0 && velocity > 0) {
tf = s / velocity;
if (tf > (userDuration / qreal(1000.))) tf = (userDuration / qreal(1000.));
- } else if (userDuration > 0) {
+ } else if (userDuration >= 0) {
tf = userDuration / qreal(1000.);
} else if (velocity > 0) {
tf = s / velocity;
diff --git a/sync.profile b/sync.profile
index 78673d95..af38a344 100644
--- a/sync.profile
+++ b/sync.profile
@@ -8,12 +8,12 @@
# - any git symbolic ref resolvable from the module's repository (e.g. "refs/heads/master" to track master branch)
#
%dependencies = (
- "qtbase" => "refs/heads/release",
- "qtscript" => "refs/heads/release",
- "qtxmlpatterns" => "refs/heads/release",
- "qtdeclarative" => "refs/heads/release",
- "qtjsbackend" => "refs/heads/release",
- "qtactiveqt" => "refs/heads/release",
- "qttools" => "refs/heads/release",
- "qtwebkit" => "refs/heads/release",
+ "qtbase" => "refs/heads/old/5.0",
+ "qtscript" => "refs/heads/old/5.0",
+ "qtxmlpatterns" => "refs/heads/old/5.0",
+ "qtdeclarative" => "refs/heads/old/5.0",
+ "qtjsbackend" => "refs/heads/old/5.0",
+ "qtactiveqt" => "refs/heads/old/5.0",
+ "qttools" => "refs/heads/old/5.0",
+ "qtwebkit" => "refs/heads/old/5.0",
);
diff --git a/tests/auto/declarative/qdeclarativedebugjs/tst_qdeclarativedebugjs.cpp b/tests/auto/declarative/qdeclarativedebugjs/tst_qdeclarativedebugjs.cpp
index 903b3739..995c375a 100644
--- a/tests/auto/declarative/qdeclarativedebugjs/tst_qdeclarativedebugjs.cpp
+++ b/tests/auto/declarative/qdeclarativedebugjs/tst_qdeclarativedebugjs.cpp
@@ -133,10 +133,6 @@ private:
class tst_QDeclarativeDebugJS : public QDeclarativeDataTest
{
Q_OBJECT
-private:
- QDeclarativeDebugConnection *m_conn;
- QDeclarativeEngine *m_engine;
- QJSDebugClient *m_client;
private slots:
void initTestCase();
diff --git a/tests/auto/declarative/qdeclarativedebugobservermode/tst_qdeclarativedebugobservermode.cpp b/tests/auto/declarative/qdeclarativedebugobservermode/tst_qdeclarativedebugobservermode.cpp
index 83c2f21a..d97ae70d 100644
--- a/tests/auto/declarative/qdeclarativedebugobservermode/tst_qdeclarativedebugobservermode.cpp
+++ b/tests/auto/declarative/qdeclarativedebugobservermode/tst_qdeclarativedebugobservermode.cpp
@@ -117,10 +117,6 @@ private:
class tst_QDeclarativeDebugObserverMode : public QDeclarativeDataTest
{
Q_OBJECT
-private:
- QDeclarativeDebugConnection *m_conn;
- QDeclarativeEngine *m_engine;
- QDeclarativeObserverModeClient *m_client;
private slots:
void initTestCase();
diff --git a/tests/auto/declarative/qdeclarativeengine/tst_qdeclarativeengine.cpp b/tests/auto/declarative/qdeclarativeengine/tst_qdeclarativeengine.cpp
index 7795e026..f67cecdc 100644
--- a/tests/auto/declarative/qdeclarativeengine/tst_qdeclarativeengine.cpp
+++ b/tests/auto/declarative/qdeclarativeengine/tst_qdeclarativeengine.cpp
@@ -334,6 +334,8 @@ public:
setFinished(true);
}
virtual qint64 readData(char* buffer, qint64 number) {
+ Q_UNUSED(buffer)
+ Q_UNUSED(number)
return 0;
}
virtual void abort() { }
@@ -348,6 +350,9 @@ public:
}
QNetworkReply *createRequest(Operation op, const QNetworkRequest & req, QIODevice * outgoingData = 0) {
+ Q_UNUSED(op)
+ Q_UNUSED(req)
+ Q_UNUSED(outgoingData)
return new MyReply;
}
};
@@ -356,7 +361,7 @@ class MyFactory : public QDeclarativeNetworkAccessManagerFactory {
public:
QNetworkAccessManager *create(QObject *parent) {
- return new MyManager;
+ return new MyManager(parent);
}
};
diff --git a/tests/auto/declarative/qdeclarativeflickable/data/nestedStopAtBounds.qml b/tests/auto/declarative/qdeclarativeflickable/data/nestedStopAtBounds.qml
new file mode 100644
index 00000000..6b28edf5
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeflickable/data/nestedStopAtBounds.qml
@@ -0,0 +1,38 @@
+import QtQuick 1.1
+
+Flickable {
+ id: outer
+ objectName: "outerFlickable"
+ width: 400
+ height: 400
+ contentX: 50
+ contentY: 50
+ contentWidth: 500
+ contentHeight: 500
+ flickableDirection: inner.flickableDirection
+
+ Rectangle {
+ x: 100
+ y: 100
+ width: 300
+ height: 300
+
+ color: "yellow"
+ Flickable {
+ id: inner
+ objectName: "innerFlickable"
+ anchors.fill: parent
+ contentX: 100
+ contentY: 100
+ contentWidth: 400
+ contentHeight: 400
+ boundsBehavior: Flickable.StopAtBounds
+
+ Rectangle {
+ anchors.fill: parent
+ anchors.margins: 100
+ color: "blue"
+ }
+ }
+ }
+}
diff --git a/tests/auto/declarative/qdeclarativeflickable/tst_qdeclarativeflickable.cpp b/tests/auto/declarative/qdeclarativeflickable/tst_qdeclarativeflickable.cpp
index d36e96f9..c8a98d33 100644
--- a/tests/auto/declarative/qdeclarativeflickable/tst_qdeclarativeflickable.cpp
+++ b/tests/auto/declarative/qdeclarativeflickable/tst_qdeclarativeflickable.cpp
@@ -75,6 +75,8 @@ private slots:
void testQtQuick11Attributes_data();
void wheel();
void flickVelocity();
+ void nestedStopAtBounds();
+ void nestedStopAtBounds_data();
private:
QDeclarativeEngine engine;
@@ -524,6 +526,86 @@ void tst_qdeclarativeflickable::flick(QGraphicsView *canvas, const QPoint &from,
QTest::mouseRelease(canvas->viewport(), Qt::LeftButton, 0, canvas->mapFromScene(to));
}
+void tst_qdeclarativeflickable::nestedStopAtBounds_data()
+{
+ QTest::addColumn<bool>("transpose");
+ QTest::addColumn<bool>("invert");
+
+ QTest::newRow("left") << false << false;
+ QTest::newRow("right") << false << true;
+ QTest::newRow("top") << true << false;
+ QTest::newRow("bottom") << true << true;
+}
+
+void tst_qdeclarativeflickable::nestedStopAtBounds()
+{
+ QFETCH(bool, transpose);
+ QFETCH(bool, invert);
+
+ QDeclarativeView view;
+ view.setSource(QUrl::fromLocalFile(SRCDIR "/data/nestedStopAtBounds.qml"));
+ view.show();
+ view.activateWindow();
+ QVERIFY(QTest::qWaitForWindowExposed(&view));
+ QVERIFY(view.rootObject());
+
+ QDeclarativeFlickable *outer = qobject_cast<QDeclarativeFlickable*>(view.rootObject());
+ QVERIFY(outer);
+
+ QDeclarativeFlickable *inner = outer->findChild<QDeclarativeFlickable*>("innerFlickable");
+ QVERIFY(inner);
+ inner->setFlickableDirection(transpose ? QDeclarativeFlickable::VerticalFlick : QDeclarativeFlickable::HorizontalFlick);
+ inner->setContentX(invert ? 0 : 100);
+ inner->setContentY(invert ? 0 : 100);
+
+ const int threshold = QApplication::startDragDistance();
+
+ QPoint position(200, 200);
+ int &axis = transpose ? position.ry() : position.rx();
+
+ QGraphicsSceneMouseEvent moveEvent(QEvent::GraphicsSceneMouseMove);
+ moveEvent.setButton(Qt::LeftButton);
+ moveEvent.setButtons(Qt::LeftButton);
+
+ // drag toward the aligned boundary. Outer mouse area dragged.
+ QTest::mousePress(view.viewport(), Qt::LeftButton, 0, position);
+ QTest::qWait(10);
+ axis += invert ? threshold * 2 : -threshold * 2;
+ moveEvent.setScenePos(position);
+ QApplication::sendEvent(view.scene(), &moveEvent);
+ axis += invert ? threshold : -threshold;
+ moveEvent.setScenePos(position);
+ QApplication::sendEvent(view.scene(), &moveEvent);
+ axis += invert ? threshold : -threshold;
+ moveEvent.setScenePos(position);
+ QApplication::sendEvent(view.scene(), &moveEvent);
+ QVERIFY(outer->contentX() != 50 || outer->contentY() != 50);
+ QVERIFY((inner->contentX() == 0 || inner->contentX() == 100)
+ && (inner->contentY() == 0 || inner->contentY() == 100));
+ QTest::mouseRelease(view.viewport(), Qt::LeftButton, 0, position);
+
+ axis = 200;
+ outer->setContentX(50);
+ outer->setContentY(50);
+
+ // drag away from the aligned boundary. Inner mouse area dragged.
+ QTest::mousePress(view.viewport(), Qt::LeftButton, 0, position);
+ QTest::qWait(10);
+ axis += invert ? -threshold * 2 : threshold * 2;
+ moveEvent.setScenePos(position);
+ QApplication::sendEvent(view.scene(), &moveEvent);
+ axis += invert ? -threshold : threshold;
+ moveEvent.setScenePos(position);
+ QApplication::sendEvent(view.scene(), &moveEvent);
+ axis += invert ? -threshold : threshold;
+ moveEvent.setScenePos(position);
+ QApplication::sendEvent(view.scene(), &moveEvent);
+ QVERIFY(outer->contentX() == 50 && outer->contentY() == 50);
+ QVERIFY((inner->contentX() != 0 && inner->contentX() != 100)
+ || (inner->contentY() != 0 && inner->contentY() != 100));
+ QTest::mouseRelease(view.viewport(), Qt::LeftButton, 0, position);
+}
+
template<typename T>
T *tst_qdeclarativeflickable::findItem(QGraphicsObject *parent, const QString &objectName)
{
diff --git a/tests/auto/declarative/qdeclarativefocusscope/data/notifications.qml b/tests/auto/declarative/qdeclarativefocusscope/data/notifications.qml
new file mode 100644
index 00000000..8345972a
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativefocusscope/data/notifications.qml
@@ -0,0 +1,81 @@
+import QtQuick 1.1
+
+Item {
+ objectName: "rootItem"
+
+ property bool handlerFocus
+ property bool handlerActiveFocus
+
+ onFocusChanged: handlerFocus = focus
+ onActiveFocusChanged: handlerActiveFocus = activeFocus
+
+ Item {
+ objectName: "item1"
+
+ property bool handlerFocus
+ property bool handlerActiveFocus
+
+ onFocusChanged: handlerFocus = focus
+ onActiveFocusChanged: handlerActiveFocus = activeFocus
+ }
+
+ Item {
+ objectName: "item2"
+
+ property bool handlerFocus
+ property bool handlerActiveFocus
+
+ onFocusChanged: handlerFocus = focus
+ onActiveFocusChanged: handlerActiveFocus = activeFocus
+
+ Item {
+ objectName: "item3"
+
+ property bool handlerFocus
+ property bool handlerActiveFocus
+
+ onFocusChanged: handlerFocus = focus
+ onActiveFocusChanged: handlerActiveFocus = activeFocus
+ }
+ }
+
+ FocusScope {
+ objectName: "scope1"
+
+ property bool handlerFocus
+ property bool handlerActiveFocus
+
+ onFocusChanged: handlerFocus = focus
+ onActiveFocusChanged: handlerActiveFocus = activeFocus
+
+ Item {
+ objectName: "item4"
+
+ property bool handlerFocus
+ property bool handlerActiveFocus
+
+ onFocusChanged: handlerFocus = focus
+ onActiveFocusChanged: handlerActiveFocus = activeFocus
+ }
+
+ FocusScope {
+ objectName: "scope2"
+
+ property bool handlerFocus
+ property bool handlerActiveFocus
+
+ onFocusChanged: handlerFocus = focus
+ onActiveFocusChanged: handlerActiveFocus = activeFocus
+
+ Item {
+ objectName: "item5"
+
+ property bool handlerFocus
+ property bool handlerActiveFocus
+
+ onFocusChanged: handlerFocus = focus
+ onActiveFocusChanged: handlerActiveFocus = activeFocus
+ }
+ }
+ }
+}
diff --git a/tests/auto/declarative/qdeclarativefocusscope/tst_qdeclarativefocusscope.cpp b/tests/auto/declarative/qdeclarativefocusscope/tst_qdeclarativefocusscope.cpp
index 64c8d210..f7099ba2 100644
--- a/tests/auto/declarative/qdeclarativefocusscope/tst_qdeclarativefocusscope.cpp
+++ b/tests/auto/declarative/qdeclarativefocusscope/tst_qdeclarativefocusscope.cpp
@@ -68,6 +68,10 @@ private slots:
void signalEmission();
void qtBug13380();
void forceActiveFocus();
+ void notifications();
+ void notifications_data();
+ void notificationsInScope();
+ void notificationsInScope_data();
};
/*
@@ -396,8 +400,11 @@ void tst_qdeclarativefocusscope::forceActiveFocus()
{
QDeclarativeView *view = new QDeclarativeView;
view->setSource(QUrl::fromLocalFile(SRCDIR "/data/forceActiveFocus.qml"));
+ view->show();
+ view->activateWindow();
+ QVERIFY(QTest::qWaitForWindowActive(view));
- QGraphicsObject *rootObject = view->rootObject();
+ QDeclarativeItem *rootObject = qobject_cast<QDeclarativeItem *>(view->rootObject());
QVERIFY(rootObject);
QDeclarativeItem *scope = findItem<QDeclarativeItem>(rootObject, QLatin1String("scope"));
@@ -416,6 +423,11 @@ void tst_qdeclarativefocusscope::forceActiveFocus()
QVERIFY(scopeB);
QVERIFY(itemB2);
+ QCOMPARE(rootObject->hasActiveFocus(), false);
+ QCOMPARE(scope->hasActiveFocus(), false);
+ QCOMPARE(scopeA->hasActiveFocus(), false);
+ QCOMPARE(scopeB->hasActiveFocus(), false);
+
QSignalSpy rootSpy(rootObject, SIGNAL(activeFocusChanged(bool)));
QSignalSpy scopeSpy(scope, SIGNAL(activeFocusChanged(bool)));
QSignalSpy scopeASpy(scopeA, SIGNAL(activeFocusChanged(bool)));
@@ -424,22 +436,34 @@ void tst_qdeclarativefocusscope::forceActiveFocus()
// First, walk the focus from item-a1 down to item-a2 and back again
itemA1->forceActiveFocus();
QVERIFY(itemA1->hasActiveFocus());
- QCOMPARE(rootSpy.count(), 1);
+ QCOMPARE(rootSpy.count(), 0);
QCOMPARE(scopeSpy.count(), 1);
scopeA->forceActiveFocus();
QVERIFY(!itemA1->hasActiveFocus());
QVERIFY(scopeA->hasActiveFocus());
QCOMPARE(scopeASpy.count(), 1);
- QCOMPARE(rootSpy.count(), 1);
+ QCOMPARE(rootSpy.count(), 0);
QCOMPARE(scopeSpy.count(), 1);
itemA2->forceActiveFocus();
QVERIFY(!itemA1->hasActiveFocus());
QVERIFY(itemA2->hasActiveFocus());
QVERIFY(scopeA->hasActiveFocus());
+ if (scopeASpy.count() == 3) {
+ qWarning() << "ignoring spurious changed signals";
+ QCOMPARE(scopeASpy.takeFirst().first().toBool(), true);
+ QCOMPARE(scopeASpy.takeFirst().first().toBool(), false);
+ QCOMPARE(scopeASpy.first().first().toBool(), true);
+ }
QCOMPARE(scopeASpy.count(), 1);
- QCOMPARE(rootSpy.count(), 1);
+ QCOMPARE(rootSpy.count(), 0);
+ if (scopeSpy.count() == 3) {
+ qWarning() << "ignoring spurious changed signals";
+ QCOMPARE(scopeSpy.takeFirst().first().toBool(), true);
+ QCOMPARE(scopeSpy.takeFirst().first().toBool(), false);
+ QCOMPARE(scopeSpy.first().first().toBool(), true);
+ }
QCOMPARE(scopeSpy.count(), 1);
scopeA->forceActiveFocus();
@@ -447,7 +471,7 @@ void tst_qdeclarativefocusscope::forceActiveFocus()
QVERIFY(itemA2->hasActiveFocus());
QVERIFY(scopeA->hasActiveFocus());
QCOMPARE(scopeASpy.count(), 1);
- QCOMPARE(rootSpy.count(), 1);
+ QCOMPARE(rootSpy.count(), 0);
QCOMPARE(scopeSpy.count(), 1);
itemA1->forceActiveFocus();
@@ -455,13 +479,13 @@ void tst_qdeclarativefocusscope::forceActiveFocus()
QVERIFY(!scopeA->hasActiveFocus());
QVERIFY(!itemA2->hasActiveFocus());
QCOMPARE(scopeASpy.count(), 2);
- QCOMPARE(rootSpy.count(), 1);
+ QCOMPARE(rootSpy.count(), 0);
QCOMPARE(scopeSpy.count(), 1);
// Then jump back and forth between branch 'a' and 'b'
itemB1->forceActiveFocus();
QVERIFY(itemB1->hasActiveFocus());
- QCOMPARE(rootSpy.count(), 1);
+ QCOMPARE(rootSpy.count(), 0);
QCOMPARE(scopeSpy.count(), 1);
scopeA->forceActiveFocus();
@@ -469,7 +493,7 @@ void tst_qdeclarativefocusscope::forceActiveFocus()
QVERIFY(!itemB1->hasActiveFocus());
QVERIFY(scopeA->hasActiveFocus());
QCOMPARE(scopeASpy.count(), 3);
- QCOMPARE(rootSpy.count(), 1);
+ QCOMPARE(rootSpy.count(), 0);
QCOMPARE(scopeSpy.count(), 1);
scopeB->forceActiveFocus();
@@ -478,7 +502,7 @@ void tst_qdeclarativefocusscope::forceActiveFocus()
QVERIFY(scopeB->hasActiveFocus());
QCOMPARE(scopeASpy.count(), 4);
QCOMPARE(scopeBSpy.count(), 1);
- QCOMPARE(rootSpy.count(), 1);
+ QCOMPARE(rootSpy.count(), 0);
QCOMPARE(scopeSpy.count(), 1);
itemA2->forceActiveFocus();
@@ -486,7 +510,7 @@ void tst_qdeclarativefocusscope::forceActiveFocus()
QVERIFY(itemA2->hasActiveFocus());
QCOMPARE(scopeASpy.count(), 5);
QCOMPARE(scopeBSpy.count(), 2);
- QCOMPARE(rootSpy.count(), 1);
+ QCOMPARE(rootSpy.count(), 0);
QCOMPARE(scopeSpy.count(), 1);
itemB2->forceActiveFocus();
@@ -494,12 +518,259 @@ void tst_qdeclarativefocusscope::forceActiveFocus()
QVERIFY(itemB2->hasActiveFocus());
QCOMPARE(scopeASpy.count(), 6);
QCOMPARE(scopeBSpy.count(), 3);
- QCOMPARE(rootSpy.count(), 1);
+ QCOMPARE(rootSpy.count(), 0);
QCOMPARE(scopeSpy.count(), 1);
delete view;
}
+
+void tst_qdeclarativefocusscope::notifications_data()
+{
+ QTest::addColumn<QString>("objectName");
+
+ QTest::newRow("rootItem") << "";
+ QTest::newRow("item1") << "item1";
+ QTest::newRow("item3") << "item3";
+ QTest::newRow("focusScope") << "scope1";
+}
+
+void tst_qdeclarativefocusscope::notifications()
+{
+ QFETCH(QString, objectName);
+ QDeclarativeView canvas;
+ canvas.setSource(QUrl::fromLocalFile(SRCDIR "/data/notifications.qml"));
+ canvas.show();
+ canvas.activateWindow();
+ QVERIFY(QTest::qWaitForWindowActive(&canvas));
+
+ QGraphicsScene *scene = canvas.scene();
+
+ QDeclarativeItem *item = qobject_cast<QDeclarativeItem*>(canvas.rootObject());
+ QVERIFY(item);
+
+ item = objectName.isEmpty() ? item : item->findChild<QDeclarativeItem *>(objectName);
+ QVERIFY(item);
+
+ QSignalSpy focusSpy(item, SIGNAL(focusChanged(bool)));
+ QSignalSpy activeFocusSpy(item, SIGNAL(activeFocusChanged(bool)));
+
+ QCOMPARE(item->hasFocus(), false);
+ QCOMPARE(item->hasActiveFocus(), false);
+
+ item->setFocus(true);
+
+ QCOMPARE(item->hasFocus(), true);
+ QCOMPARE(item->hasActiveFocus(), true);
+ QCOMPARE(focusSpy.count(), 1);
+ QCOMPARE(activeFocusSpy.count(), 1);
+ QCOMPARE(focusSpy.takeFirst().first().toBool(), true);
+ QCOMPARE(activeFocusSpy.takeFirst().first().toBool(), true);
+ QCOMPARE(item->property("handlerFocus").value<bool>(), true);
+ QCOMPARE(item->property("handlerActiveFocus").value<bool>(), true);
+
+ item->setFocus(false);
+
+ QCOMPARE(item->hasFocus(), false);
+ QCOMPARE(item->hasActiveFocus(), false);
+ QCOMPARE(focusSpy.count(), 1);
+ QCOMPARE(activeFocusSpy.count(), 1);
+ QCOMPARE(focusSpy.takeFirst().first().toBool(), false);
+ QCOMPARE(activeFocusSpy.takeFirst().first().toBool(), false);
+ QCOMPARE(item->property("handlerFocus").value<bool>(), false);
+ QCOMPARE(item->property("handlerActiveFocus").value<bool>(), false);
+
+ item->QGraphicsItem::setFocus();
+
+ QCOMPARE(item->hasFocus(), true);
+ QCOMPARE(item->hasActiveFocus(), true);
+ QCOMPARE(focusSpy.count(), 1);
+ QCOMPARE(activeFocusSpy.count(), 1);
+ QCOMPARE(focusSpy.takeFirst().first().toBool(), true);
+ QCOMPARE(activeFocusSpy.takeFirst().first().toBool(), true);
+ QCOMPARE(item->property("handlerFocus").value<bool>(), true);
+ QCOMPARE(item->property("handlerActiveFocus").value<bool>(), true);
+
+ item->clearFocus();
+
+ QCOMPARE(item->hasFocus(), false);
+ QCOMPARE(item->hasActiveFocus(), false);
+ QCOMPARE(focusSpy.count(), 1);
+ QCOMPARE(activeFocusSpy.count(), 1);
+ QCOMPARE(focusSpy.takeFirst().first().toBool(), false);
+ QCOMPARE(activeFocusSpy.takeFirst().first().toBool(), false);
+ QCOMPARE(item->property("handlerFocus").value<bool>(), false);
+ QCOMPARE(item->property("handlerActiveFocus").value<bool>(), false);
+
+ scene->setFocusItem(item);
+
+ QCOMPARE(item->hasFocus(), true);
+ QCOMPARE(item->hasActiveFocus(), true);
+ QCOMPARE(focusSpy.count(), 1);
+ QCOMPARE(activeFocusSpy.count(), 1);
+ QCOMPARE(focusSpy.takeFirst().first().toBool(), true);
+ QCOMPARE(activeFocusSpy.takeFirst().first().toBool(), true);
+ QCOMPARE(item->property("handlerFocus").value<bool>(), true);
+ QCOMPARE(item->property("handlerActiveFocus").value<bool>(), true);
+
+ scene->setFocusItem(0);
+
+ QCOMPARE(item->hasFocus(), false);
+ QCOMPARE(item->hasActiveFocus(), false);
+ QCOMPARE(focusSpy.count(), 1);
+ QCOMPARE(activeFocusSpy.count(), 1);
+ QCOMPARE(focusSpy.takeFirst().first().toBool(), false);
+ QCOMPARE(activeFocusSpy.takeFirst().first().toBool(), false);
+ QCOMPARE(item->property("handlerFocus").value<bool>(), false);
+ QCOMPARE(item->property("handlerActiveFocus").value<bool>(), false);
+}
+
+void tst_qdeclarativefocusscope::notificationsInScope_data()
+{
+ QTest::addColumn<QString>("itemName");
+ QTest::addColumn<QString>("scopeName");
+
+ QTest::newRow("item4") << "item4" << "scope1";
+ QTest::newRow("item5") << "item5" << "scope2";
+}
+
+void tst_qdeclarativefocusscope::notificationsInScope()
+{
+ QFETCH(QString, itemName);
+ QFETCH(QString, scopeName);
+ QDeclarativeView canvas;
+ canvas.setSource(QUrl::fromLocalFile(SRCDIR "/data/notifications.qml"));
+ canvas.show();
+ canvas.activateWindow();
+ QVERIFY(QTest::qWaitForWindowActive(&canvas));
+
+ QVERIFY(canvas.rootObject());
+
+ QDeclarativeItem *scope = canvas.rootObject()->findChild<QDeclarativeItem *>(scopeName);
+ QVERIFY(scope);
+
+ QDeclarativeItem *item = scope->findChild<QDeclarativeItem *>(itemName);
+ QVERIFY(item);
+
+ QSignalSpy itemFocusSpy(item, SIGNAL(focusChanged(bool)));
+ QSignalSpy itemActiveFocusSpy(item, SIGNAL(activeFocusChanged(bool)));
+
+ QSignalSpy scopeFocusSpy(scope, SIGNAL(focusChanged(bool)));
+ QSignalSpy scopeActiveFocusSpy(scope, SIGNAL(activeFocusChanged(bool)));
+
+ QCOMPARE(item->hasFocus(), false);
+ QCOMPARE(item->hasActiveFocus(), false);
+ QCOMPARE(scope->hasFocus(), false);
+ QCOMPARE(scope->hasActiveFocus(), false);
+ QCOMPARE(item->property("handlerFocus").value<bool>(), false);
+ QCOMPARE(item->property("handlerActiveFocus").value<bool>(), false);
+ QCOMPARE(scope->property("handlerFocus").value<bool>(), false);
+ QCOMPARE(scope->property("handlerActiveFocus").value<bool>(), false);
+
+ item->setFocus(true);
+ QCOMPARE(item->hasFocus(), true);
+ QCOMPARE(item->hasActiveFocus(), false);
+ QCOMPARE(scope->hasFocus(), false);
+ QCOMPARE(scope->hasActiveFocus(), false);
+ QCOMPARE(itemFocusSpy.count(), 1);
+ QCOMPARE(itemFocusSpy.takeFirst().first().toBool(), true);
+ QCOMPARE(itemActiveFocusSpy.count(), 0);
+ QCOMPARE(scopeFocusSpy.count(), 0);
+ QCOMPARE(scopeActiveFocusSpy.count(), 0);
+ QCOMPARE(item->property("handlerFocus").value<bool>(), true);
+ QCOMPARE(item->property("handlerActiveFocus").value<bool>(), false);
+ QCOMPARE(scope->property("handlerFocus").value<bool>(), false);
+ QCOMPARE(scope->property("handlerActiveFocus").value<bool>(), false);
+
+ item->setFocus(false);
+ QCOMPARE(item->hasFocus(), false);
+ QCOMPARE(item->hasActiveFocus(), false);
+ QCOMPARE(scope->hasFocus(), false);
+ QCOMPARE(scope->hasActiveFocus(), false);
+ QCOMPARE(itemFocusSpy.count(), 1);
+ QCOMPARE(itemFocusSpy.takeFirst().first().toBool(), false);
+ QCOMPARE(itemActiveFocusSpy.count(), 0);
+ QCOMPARE(scopeFocusSpy.count(), 0);
+ QCOMPARE(scopeActiveFocusSpy.count(), 0);
+ QCOMPARE(item->property("handlerFocus").value<bool>(), false);
+ QCOMPARE(item->property("handlerActiveFocus").value<bool>(), false);
+ QCOMPARE(scope->property("handlerFocus").value<bool>(), false);
+ QCOMPARE(scope->property("handlerActiveFocus").value<bool>(), false);
+
+ item->forceActiveFocus();
+ QCOMPARE(item->hasFocus(), true);
+ QCOMPARE(item->hasActiveFocus(), true);
+ QCOMPARE(scope->hasFocus(), true);
+ QCOMPARE(scope->hasActiveFocus(), true);
+ QCOMPARE(itemFocusSpy.count(), 1);
+ QCOMPARE(itemFocusSpy.takeFirst().first().toBool(), true);
+ QCOMPARE(itemActiveFocusSpy.count(), 1);
+ QCOMPARE(itemActiveFocusSpy.takeFirst().first().toBool(), true);
+ QCOMPARE(scopeFocusSpy.count(), 1);
+ QCOMPARE(scopeFocusSpy.takeFirst().first().toBool(), true);
+ QCOMPARE(scopeActiveFocusSpy.count(), 1);
+ QCOMPARE(scopeActiveFocusSpy.takeFirst().first().toBool(), true);
+ QCOMPARE(item->property("handlerFocus").value<bool>(), true);
+ QCOMPARE(item->property("handlerActiveFocus").value<bool>(), true);
+ QCOMPARE(scope->property("handlerFocus").value<bool>(), true);
+ QCOMPARE(scope->property("handlerActiveFocus").value<bool>(), true);
+
+ scope->setFocus(false);
+ QCOMPARE(item->hasFocus(), true);
+ QCOMPARE(item->hasActiveFocus(), false);
+ QCOMPARE(scope->hasFocus(), false);
+ QCOMPARE(scope->hasActiveFocus(), false);
+ QCOMPARE(itemFocusSpy.count(), 0);
+ QCOMPARE(itemActiveFocusSpy.count(), 1);
+ QCOMPARE(itemActiveFocusSpy.takeFirst().first().toBool(), false);
+ QCOMPARE(scopeFocusSpy.count(), 1);
+ QCOMPARE(scopeFocusSpy.takeFirst().first().toBool(), false);
+ QCOMPARE(scopeActiveFocusSpy.count(), 1);
+ QCOMPARE(scopeActiveFocusSpy.takeFirst().first().toBool(), false);
+ QCOMPARE(item->property("handlerFocus").value<bool>(), true);
+ QCOMPARE(item->property("handlerActiveFocus").value<bool>(), false);
+ QCOMPARE(scope->property("handlerFocus").value<bool>(), false);
+ QCOMPARE(scope->property("handlerActiveFocus").value<bool>(), false);
+
+ scope->setFocus(true);
+ QCOMPARE(item->hasFocus(), true);
+ QCOMPARE(item->hasActiveFocus(), true);
+ QCOMPARE(scope->hasFocus(), true);
+ QCOMPARE(scope->hasActiveFocus(), true);
+ QCOMPARE(itemFocusSpy.count(), 0);
+ QCOMPARE(itemActiveFocusSpy.count(), 1);
+ QCOMPARE(itemActiveFocusSpy.takeFirst().first().toBool(), true);
+ QCOMPARE(scopeFocusSpy.count(), 1);
+ QCOMPARE(scopeFocusSpy.takeFirst().first().toBool(), true);
+ QCOMPARE(scopeActiveFocusSpy.count(), 1);
+ QCOMPARE(scopeActiveFocusSpy.takeFirst().first().toBool(), true);
+ QCOMPARE(item->property("handlerFocus").value<bool>(), true);
+ QCOMPARE(item->property("handlerActiveFocus").value<bool>(), true);
+ QCOMPARE(scope->property("handlerFocus").value<bool>(), true);
+ QCOMPARE(scope->property("handlerActiveFocus").value<bool>(), true);
+
+ item->setFocus(false);
+ QCOMPARE(item->hasFocus(), false);
+ QCOMPARE(item->hasActiveFocus(), false);
+ QCOMPARE(scope->hasFocus(), true);
+ QCOMPARE(scope->hasActiveFocus(), true);
+ QCOMPARE(itemFocusSpy.count(), 1);
+ QCOMPARE(itemFocusSpy.takeFirst().first().toBool(), false);
+ QCOMPARE(itemActiveFocusSpy.count(), 1);
+ QCOMPARE(itemActiveFocusSpy.takeFirst().first().toBool(), false);
+ if (scopeFocusSpy.count() == 2) {
+ qWarning() << "ignoring spurious changed signals";
+ QCOMPARE(scopeFocusSpy.takeFirst().first().toBool(), false);
+ QCOMPARE(scopeFocusSpy.takeFirst().first().toBool(), true);
+ }
+ QCOMPARE(scopeFocusSpy.count(), 0);
+ QCOMPARE(scopeActiveFocusSpy.count(), 0);
+ QCOMPARE(item->property("handlerFocus").value<bool>(), false);
+ QCOMPARE(item->property("handlerActiveFocus").value<bool>(), false);
+ QCOMPARE(scope->property("handlerFocus").value<bool>(), true);
+ QCOMPARE(scope->property("handlerActiveFocus").value<bool>(), true);
+}
+
QTEST_MAIN(tst_qdeclarativefocusscope)
#include "tst_qdeclarativefocusscope.moc"
diff --git a/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp b/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp
index 0f61bb7e..0251d74d 100644
--- a/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp
+++ b/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp
@@ -86,6 +86,11 @@ private slots:
void qtbug_16871();
void qtbug_21045();
void hasActiveFocusAfterClear();
+ void setAndClearFocusOfItem();
+ void setAndClearFocusScopeFocus();
+ void setFocusThenSetFocusItem0();
+ void setFocusFocusItem0ThenHasActiveFocus();
+
private:
QDeclarativeEngine engine;
};
@@ -1043,6 +1048,7 @@ void tst_QDeclarativeItem::propertyChanges()
QCOMPARE(parentItem->childrenRect(), childrenRectArguments.at(0).toRectF());
QCOMPARE(item->hasActiveFocus(), true);
+ QCOMPARE(item->hasFocus(), true);
QCOMPARE(focusSpy.count(),1);
QList<QVariant> focusArguments = focusSpy.first();
QVERIFY(focusArguments.count() == 1);
@@ -1249,8 +1255,9 @@ void tst_QDeclarativeItem::qtbug_21045()
void tst_QDeclarativeItem::hasActiveFocusAfterClear()
{
QGraphicsScene scene;
- QGraphicsView view(&scene);
- view.show();
+ scene.setFocus();
+ QEvent event(QEvent::WindowActivate);
+ qApp->sendEvent(&scene, &event);
QDeclarativeEngine engine;
QDeclarativeComponent qmlComponent(&engine);
@@ -1273,6 +1280,174 @@ void tst_QDeclarativeItem::hasActiveFocusAfterClear()
QVERIFY(!createdItem->hasActiveFocus());
}
+void tst_QDeclarativeItem::setAndClearFocusOfItem()
+{
+ QGraphicsScene scene;
+ scene.setFocus();
+ QEvent event(QEvent::WindowActivate);
+ qApp->sendEvent(&scene, &event);
+
+ QDeclarativeEngine engine(&scene);
+ QDeclarativeComponent qmlComponent(&engine);
+ qmlComponent.setData(
+ "import QtQuick 1.1;"
+ "Item { id: root; "
+ "signal focusChangedTo(bool value);"
+ "signal activeFocusChangedTo(bool value);"
+ "onFocusChanged: root.focusChangedTo(focus);"
+ "onActiveFocusChanged: root.activeFocusChangedTo(activeFocus);"
+ "}", QUrl("test"));
+
+ QGraphicsItem *createdItem = qobject_cast<QGraphicsItem*>(qmlComponent.create(engine.rootContext()));
+ QVERIFY(createdItem);
+ scene.addItem(createdItem);
+
+ QSignalSpy focusChangedSpy(createdItem->toGraphicsObject(), SIGNAL(focusChangedTo(bool)));
+ QSignalSpy activeFocusChangedSpy(createdItem->toGraphicsObject(), SIGNAL(activeFocusChangedTo(bool)));
+
+ QVERIFY(!createdItem->hasFocus());
+ createdItem->toGraphicsObject()->setFocus();
+ QCOMPARE(focusChangedSpy.count(), 1);
+ QCOMPARE(activeFocusChangedSpy.count(), 1);
+ QCOMPARE(focusChangedSpy.takeFirst().first().toBool(), true);
+ QCOMPARE(activeFocusChangedSpy.takeFirst().first().toBool(), true);
+
+ createdItem->toGraphicsObject()->clearFocus();
+ QCOMPARE(focusChangedSpy.count(), 1);
+ QCOMPARE(activeFocusChangedSpy.count(), 1);
+ QCOMPARE(focusChangedSpy.takeFirst().first().toBool(), false);
+ QCOMPARE(activeFocusChangedSpy.takeFirst().first().toBool(), false);
+}
+
+void tst_QDeclarativeItem::setAndClearFocusScopeFocus()
+{
+ //graphicsview init
+ QGraphicsScene scene;
+ scene.setFocus();
+ QEvent event(QEvent::WindowActivate);
+ qApp->sendEvent(&scene, &event);
+
+ //declarative init
+ QDeclarativeEngine engine(&scene);
+ QDeclarativeComponent qmlComponent(&engine);
+
+ qmlComponent.setData(
+ "\nimport QtQuick 1.1"
+ "\nFocusScope {"
+ "\n id: root"
+ "\n signal listActiveFocusChangedTo(bool value)"
+ "\n signal topRectActiveFocusChangedTo(bool value)"
+ "\n Rectangle {"
+ "\n id: topRect"
+ "\n focus: true"
+ "\n onActiveFocusChanged: root.topRectActiveFocusChangedTo(topRect.activeFocus)"
+ "\n }"
+ "\n FocusScope {"
+ "\n objectName: \"focusScope\""
+ "\n onActiveFocusChanged: root.listActiveFocusChangedTo(activeFocus)"
+ "\n }"
+ "\n Rectangle { objectName: \"bottom\" }"
+ "}", QUrl(""));
+
+ QGraphicsItem *createdItem = qobject_cast<QGraphicsItem*>(qmlComponent.create(engine.rootContext()));
+ QVERIFY(createdItem);
+ scene.addItem(createdItem);
+
+ QDeclarativeItem *focusScope = createdItem->toGraphicsObject()->findChild<QDeclarativeItem*>("focusScope");
+ QDeclarativeItem *bottomRect = createdItem->toGraphicsObject()->findChild<QDeclarativeItem*>("bottom");
+
+ QSignalSpy focusScopeSpy(createdItem->toGraphicsObject(), SIGNAL(listActiveFocusChangedTo(bool)));
+ QSignalSpy topRectFocusSpy(createdItem->toGraphicsObject(), SIGNAL(topRectActiveFocusChangedTo(bool)));
+
+ //#1: root gets activefocus, and in turn the top rectangle
+ createdItem->setFocus();
+
+ //#2
+ focusScope->setFocus(true);
+
+ //#3
+ bottomRect->setFocus(true);
+
+ QCOMPARE(topRectFocusSpy.count(), 2);
+ QCOMPARE(focusScopeSpy.count(), 2);
+
+ QCOMPARE(topRectFocusSpy.takeFirst().first().toBool(), true); //from #1
+ QCOMPARE(topRectFocusSpy.takeFirst().first().toBool(), false); //from #2
+
+ QCOMPARE(focusScopeSpy.takeFirst().first().toBool(), true); //from #2
+ QCOMPARE(focusScopeSpy.takeFirst().first().toBool(), false); //from #3
+}
+
+void tst_QDeclarativeItem::setFocusThenSetFocusItem0()
+{
+ //graphicsview init
+ QGraphicsScene scene;
+ scene.setFocus();
+ QEvent event(QEvent::WindowActivate);
+ qApp->sendEvent(&scene, &event);
+
+ //declarative init
+ QDeclarativeEngine engine(&scene);
+ QDeclarativeComponent qmlComponent(&engine);
+ qmlComponent.setData(
+ "import QtQuick 1.1;"
+ "Item {"
+ "signal focusChangedTo(bool value);"
+ "signal activeFocusChangedTo(bool value);"
+ "onFocusChanged: focusChangedTo(focus);"
+ "onActiveFocusChanged: activeFocusChangedTo(activeFocus);"
+ "}", QUrl(""));
+
+ QGraphicsItem *createdItem = qobject_cast<QGraphicsItem*>(qmlComponent.create(engine.rootContext()));
+ QVERIFY(createdItem);
+
+ scene.addItem(createdItem);
+
+ QSignalSpy focusChangedSpy(createdItem->toGraphicsObject(), SIGNAL(focusChangedTo(bool)));
+ QSignalSpy activeFocusChangedSpy(createdItem->toGraphicsObject(), SIGNAL(activeFocusChangedTo(bool)));
+
+ createdItem->toGraphicsObject()->setFocus();
+ QVERIFY(!focusChangedSpy.isEmpty());
+ QVERIFY(!activeFocusChangedSpy.isEmpty());
+ QCOMPARE(focusChangedSpy.takeFirst().first().toBool(), true);
+ QCOMPARE(activeFocusChangedSpy.takeFirst().first().toBool(), true);
+
+ scene.setFocusItem(0);
+ QVERIFY(!focusChangedSpy.isEmpty());
+ QVERIFY(!activeFocusChangedSpy.isEmpty());
+ QCOMPARE(focusChangedSpy.takeFirst().first().toBool(), false);
+ QCOMPARE(activeFocusChangedSpy.takeFirst().first().toBool(), false);
+ QVERIFY(activeFocusChangedSpy.isEmpty());
+}
+
+void tst_QDeclarativeItem::setFocusFocusItem0ThenHasActiveFocus()
+{
+ QGraphicsScene scene;
+ scene.setFocus();
+ QEvent event(QEvent::WindowActivate);
+ qApp->sendEvent(&scene, &event);
+
+ QDeclarativeEngine engine(&scene);
+ QDeclarativeComponent qmlComponent(&engine);
+ qmlComponent.setData(
+ "import QtQuick 1.1;"
+ "TextInput {"
+ "width: 100; height: 100;"
+ "Rectangle { anchors.fill: parent; color: \"yellow\"; z: parent.z - 1 }"
+ "}", QUrl(""));
+ QDeclarativeItem *createdItem = qobject_cast<QDeclarativeItem*>(qmlComponent.create(engine.rootContext()));
+ QVERIFY(createdItem != 0);
+
+ scene.addItem(createdItem);
+
+ createdItem->QGraphicsItem::setFocus();
+ QCoreApplication::processEvents();
+ scene.setFocusItem(0);
+ QCoreApplication::processEvents();
+
+ QVERIFY(!createdItem->hasActiveFocus());
+}
+
QTEST_MAIN(tst_QDeclarativeItem)
#include "tst_qdeclarativeitem.moc"
diff --git a/tests/auto/declarative/qdeclarativemousearea/data/nestedStopAtBounds.qml b/tests/auto/declarative/qdeclarativemousearea/data/nestedStopAtBounds.qml
new file mode 100644
index 00000000..0379964d
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativemousearea/data/nestedStopAtBounds.qml
@@ -0,0 +1,44 @@
+import QtQuick 1.1
+
+Rectangle {
+ width: 400
+ height: 400
+
+ MouseArea {
+ id: outer
+ objectName: "outer"
+ x: 50
+ y: 50
+ width: 300
+ height: 300
+
+ drag.target: outer
+ drag.filterChildren: true
+
+ Rectangle {
+ anchors.fill: parent
+ color: "yellow"
+ }
+
+ MouseArea {
+ id: inner
+ objectName: "inner"
+
+ x: 0
+ y: 0
+ width: 200
+ height: 200
+
+ drag.target: inner
+ drag.minimumX: 0
+ drag.maximumX: 100
+ drag.minimumY: 0
+ drag.maximumY: 100
+
+ Rectangle {
+ anchors.fill: parent
+ color: "blue"
+ }
+ }
+ }
+}
diff --git a/tests/auto/declarative/qdeclarativemousearea/tst_qdeclarativemousearea.cpp b/tests/auto/declarative/qdeclarativemousearea/tst_qdeclarativemousearea.cpp
index b28381ef..0415c5c9 100644
--- a/tests/auto/declarative/qdeclarativemousearea/tst_qdeclarativemousearea.cpp
+++ b/tests/auto/declarative/qdeclarativemousearea/tst_qdeclarativemousearea.cpp
@@ -71,6 +71,8 @@ private slots:
void preventContextMenu();
#endif // QT_NO_CONTEXTMENU
void changeAxis();
+ void nestedStopAtBounds();
+ void nestedStopAtBounds_data();
private:
QDeclarativeView *createView();
@@ -237,18 +239,18 @@ void tst_QDeclarativeMouseArea::dragging()
QApplication::sendEvent(scene, &moveEvent);
QVERIFY(drag->active());
- QCOMPARE(blackRect->x(), 72.0);
- QCOMPARE(blackRect->y(), 72.0);
+ QCOMPARE(blackRect->x(), 61.0);
+ QCOMPARE(blackRect->y(), 61.0);
QGraphicsSceneMouseEvent releaseEvent(QEvent::GraphicsSceneMouseRelease);
- releaseEvent.setScenePos(QPointF(110, 110));
+ releaseEvent.setScenePos(QPointF(122, 122));
releaseEvent.setButton(Qt::LeftButton);
releaseEvent.setButtons(Qt::LeftButton);
QApplication::sendEvent(scene, &releaseEvent);
QVERIFY(!drag->active());
- QCOMPARE(blackRect->x(), 72.0);
- QCOMPARE(blackRect->y(), 72.0);
+ QCOMPARE(blackRect->x(), 61.0);
+ QCOMPARE(blackRect->y(), 61.0);
delete canvas;
}
@@ -739,14 +741,14 @@ void tst_QDeclarativeMouseArea::changeAxis()
QApplication::sendEvent(scene, &moveEvent);
QVERIFY(drag->active());
- QCOMPARE(blackRect->x(), 72.0);
- QCOMPARE(blackRect->y(), 72.0);
+ QCOMPARE(blackRect->x(), 61.0);
+ QCOMPARE(blackRect->y(), 61.0);
QCOMPARE(drag->axis(), QDeclarativeDrag::XandYAxis);
/* When blackRect.x becomes bigger than 75, the drag axis is change to
* Drag.YAxis by the QML code. Verify that this happens, and that the drag
* movement is effectively constrained to the Y axis. */
- moveEvent.setScenePos(QPointF(133, 133));
+ moveEvent.setScenePos(QPointF(144, 144));
moveEvent.setButton(Qt::LeftButton);
moveEvent.setButtons(Qt::LeftButton);
QApplication::sendEvent(scene, &moveEvent);
@@ -755,7 +757,7 @@ void tst_QDeclarativeMouseArea::changeAxis()
QCOMPARE(blackRect->y(), 83.0);
QCOMPARE(drag->axis(), QDeclarativeDrag::YAxis);
- moveEvent.setScenePos(QPointF(144, 144));
+ moveEvent.setScenePos(QPointF(155, 155));
moveEvent.setButton(Qt::LeftButton);
moveEvent.setButtons(Qt::LeftButton);
QApplication::sendEvent(scene, &moveEvent);
@@ -764,7 +766,7 @@ void tst_QDeclarativeMouseArea::changeAxis()
QCOMPARE(blackRect->y(), 94.0);
QGraphicsSceneMouseEvent releaseEvent(QEvent::GraphicsSceneMouseRelease);
- releaseEvent.setScenePos(QPointF(144, 144));
+ releaseEvent.setScenePos(QPointF(155, 155));
releaseEvent.setButton(Qt::LeftButton);
releaseEvent.setButtons(Qt::LeftButton);
QApplication::sendEvent(scene, &releaseEvent);
@@ -776,6 +778,80 @@ void tst_QDeclarativeMouseArea::changeAxis()
delete canvas;
}
+void tst_QDeclarativeMouseArea::nestedStopAtBounds_data()
+{
+ QTest::addColumn<bool>("transpose");
+ QTest::addColumn<bool>("invert");
+
+ QTest::newRow("left") << false << false;
+ QTest::newRow("right") << false << true;
+ QTest::newRow("top") << true << false;
+ QTest::newRow("bottom") << true << true;
+}
+
+void tst_QDeclarativeMouseArea::nestedStopAtBounds()
+{
+ QFETCH(bool, transpose);
+ QFETCH(bool, invert);
+
+ QDeclarativeView view;
+ view.setSource(QUrl::fromLocalFile(SRCDIR "/data/nestedStopAtBounds.qml"));
+ view.show();
+ view.activateWindow();
+ QVERIFY(QTest::qWaitForWindowExposed(&view));
+ QVERIFY(view.rootObject());
+
+ QDeclarativeMouseArea *outer = view.rootObject()->findChild<QDeclarativeMouseArea*>("outer");
+ QVERIFY(outer);
+
+ QDeclarativeMouseArea *inner = outer->findChild<QDeclarativeMouseArea*>("inner");
+ QVERIFY(inner);
+ inner->drag()->setAxis(transpose ? QDeclarativeDrag::YAxis : QDeclarativeDrag::XAxis);
+ inner->setX(invert ? 100 : 0);
+ inner->setY(invert ? 100 : 0);
+
+ const int threshold = QApplication::startDragDistance();
+
+ QPoint position(200, 200);
+ int &axis = transpose ? position.ry() : position.rx();
+
+ QGraphicsSceneMouseEvent moveEvent(QEvent::GraphicsSceneMouseMove);
+ moveEvent.setButton(Qt::LeftButton);
+ moveEvent.setButtons(Qt::LeftButton);
+
+ // drag toward the aligned boundary. Outer mouse area dragged.
+ QTest::mousePress(view.viewport(), Qt::LeftButton, 0, position);
+ QTest::qWait(10);
+ axis += invert ? threshold * 2 : -threshold * 2;
+ moveEvent.setScenePos(position);
+ QApplication::sendEvent(view.scene(), &moveEvent);
+ axis += invert ? threshold : -threshold;
+ moveEvent.setScenePos(position);
+ QApplication::sendEvent(view.scene(), &moveEvent);
+ QCOMPARE(outer->drag()->active(), true);
+ QCOMPARE(inner->drag()->active(), false);
+ QTest::mouseRelease(view.viewport(), Qt::LeftButton, 0, position);
+
+ QVERIFY(!outer->drag()->active());
+
+ axis = 200;
+ outer->setX(50);
+ outer->setY(50);
+
+ // drag away from the aligned boundary. Inner mouse area dragged.
+ QTest::mousePress(view.viewport(), Qt::LeftButton, 0, position);
+ QTest::qWait(10);
+ axis += invert ? -threshold * 2 : threshold * 2;
+ moveEvent.setScenePos(position);
+ QApplication::sendEvent(view.scene(), &moveEvent);
+ axis += invert ? -threshold : threshold;
+ moveEvent.setScenePos(position);
+ QApplication::sendEvent(view.scene(), &moveEvent);
+ QCOMPARE(outer->drag()->active(), false);
+ QCOMPARE(inner->drag()->active(), true);
+ QTest::mouseRelease(view.viewport(), Qt::LeftButton, 0, position);
+}
+
QTEST_MAIN(tst_QDeclarativeMouseArea)
#include "tst_qdeclarativemousearea.moc"
diff --git a/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp b/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp
index cd8c5aed..8815dbfb 100644
--- a/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp
+++ b/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp
@@ -615,45 +615,44 @@ void tst_QDeclarativePathView::moveModel_data()
QTest::addColumn<int>("from");
QTest::addColumn<int>("to");
QTest::addColumn<int>("count");
- QTest::addColumn<qreal>("offset");
QTest::addColumn<int>("currentIndex");
// We have 8 items, with currentIndex == 4
QTest::newRow("move after current")
- << int(QDeclarativePathView::StrictlyEnforceRange) << 5 << 6 << 1 << 4. << 4;
+ << int(QDeclarativePathView::StrictlyEnforceRange) << 5 << 6 << 1 << 4;
QTest::newRow("move before current")
- << int(QDeclarativePathView::StrictlyEnforceRange) << 2 << 3 << 1 << 4. << 4;
+ << int(QDeclarativePathView::StrictlyEnforceRange) << 2 << 3 << 1 << 4;
QTest::newRow("move before current to after")
- << int(QDeclarativePathView::StrictlyEnforceRange) << 2 << 6 << 1 << 5. << 3;
+ << int(QDeclarativePathView::StrictlyEnforceRange) << 2 << 6 << 1 << 3;
QTest::newRow("move multiple after current")
- << int(QDeclarativePathView::StrictlyEnforceRange) << 5 << 6 << 2 << 4. << 4;
+ << int(QDeclarativePathView::StrictlyEnforceRange) << 5 << 6 << 2 << 4;
QTest::newRow("move multiple before current")
- << int(QDeclarativePathView::StrictlyEnforceRange) << 0 << 1 << 2 << 4. << 4;
+ << int(QDeclarativePathView::StrictlyEnforceRange) << 0 << 1 << 2 << 4;
QTest::newRow("move before current to end")
- << int(QDeclarativePathView::StrictlyEnforceRange) << 2 << 7 << 1 << 5. << 3;
+ << int(QDeclarativePathView::StrictlyEnforceRange) << 2 << 7 << 1 << 3;
QTest::newRow("move last to beginning")
- << int(QDeclarativePathView::StrictlyEnforceRange) << 7 << 0 << 1 << 3. << 5;
+ << int(QDeclarativePathView::StrictlyEnforceRange) << 7 << 0 << 1 << 5;
QTest::newRow("move current")
- << int(QDeclarativePathView::StrictlyEnforceRange) << 4 << 6 << 1 << 2. << 6;
+ << int(QDeclarativePathView::StrictlyEnforceRange) << 4 << 6 << 1 << 6;
QTest::newRow("no range - move after current")
- << int(QDeclarativePathView::NoHighlightRange) << 5 << 6 << 1 << 4. << 4;
+ << int(QDeclarativePathView::NoHighlightRange) << 5 << 6 << 1 << 4;
QTest::newRow("no range - move before current")
- << int(QDeclarativePathView::NoHighlightRange) << 2 << 3 << 1 << 4. << 4;
+ << int(QDeclarativePathView::NoHighlightRange) << 2 << 3 << 1 << 4;
QTest::newRow("no range - move before current to after")
- << int(QDeclarativePathView::NoHighlightRange) << 2 << 6 << 1 << 5. << 3;
+ << int(QDeclarativePathView::NoHighlightRange) << 2 << 6 << 1 << 3;
QTest::newRow("no range - move multiple after current")
- << int(QDeclarativePathView::NoHighlightRange) << 5 << 6 << 2 << 4. << 4;
+ << int(QDeclarativePathView::NoHighlightRange) << 5 << 6 << 2 << 4;
QTest::newRow("no range - move multiple before current")
- << int(QDeclarativePathView::NoHighlightRange) << 0 << 1 << 2 << 4. << 4;
+ << int(QDeclarativePathView::NoHighlightRange) << 0 << 1 << 2 << 4;
QTest::newRow("no range - move before current to end")
- << int(QDeclarativePathView::NoHighlightRange) << 2 << 7 << 1 << 5. << 3;
+ << int(QDeclarativePathView::NoHighlightRange) << 2 << 7 << 1 << 3;
QTest::newRow("no range - move last to beginning")
- << int(QDeclarativePathView::NoHighlightRange) << 7 << 0 << 1 << 3. << 5;
+ << int(QDeclarativePathView::NoHighlightRange) << 7 << 0 << 1 << 5;
QTest::newRow("no range - move current")
- << int(QDeclarativePathView::NoHighlightRange) << 4 << 6 << 1 << 4. << 6;
+ << int(QDeclarativePathView::NoHighlightRange) << 4 << 6 << 1 << 6;
QTest::newRow("no range - move multiple incl. current")
- << int(QDeclarativePathView::NoHighlightRange) << 0 << 1 << 5 << 4. << 5;
+ << int(QDeclarativePathView::NoHighlightRange) << 0 << 1 << 5 << 5;
}
void tst_QDeclarativePathView::moveModel()
@@ -662,7 +661,6 @@ void tst_QDeclarativePathView::moveModel()
QFETCH(int, from);
QFETCH(int, to);
QFETCH(int, count);
- QFETCH(qreal, offset);
QFETCH(int, currentIndex);
QDeclarativeView *window = createView();
diff --git a/tests/auto/declarative/qdeclarativesmoothedanimation/data/smoothedanimationZeroDuration.qml b/tests/auto/declarative/qdeclarativesmoothedanimation/data/smoothedanimationZeroDuration.qml
new file mode 100644
index 00000000..cba1ffe5
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativesmoothedanimation/data/smoothedanimationZeroDuration.qml
@@ -0,0 +1,12 @@
+import QtQuick 1.0
+
+Rectangle {
+ width: 300; height: 300;
+ Rectangle {
+ objectName: "theRect"
+ color: "red"
+ width: 60; height: 60;
+ x: 100; y: 100;
+ SmoothedAnimation on x { objectName: "easeX"; to: 200; duration: 0 }
+ }
+}
diff --git a/tests/auto/declarative/qdeclarativesmoothedanimation/tst_qdeclarativesmoothedanimation.cpp b/tests/auto/declarative/qdeclarativesmoothedanimation/tst_qdeclarativesmoothedanimation.cpp
index 452168a6..1d511779 100644
--- a/tests/auto/declarative/qdeclarativesmoothedanimation/tst_qdeclarativesmoothedanimation.cpp
+++ b/tests/auto/declarative/qdeclarativesmoothedanimation/tst_qdeclarativesmoothedanimation.cpp
@@ -58,6 +58,7 @@ private slots:
void simpleAnimation();
void valueSource();
void behavior();
+ void zeroDuration();
private:
QDeclarativeEngine engine;
@@ -201,6 +202,26 @@ void tst_qdeclarativesmoothedanimation::behavior()
QTRY_COMPARE(theRect->y(), qreal(200));
}
+void tst_qdeclarativesmoothedanimation::zeroDuration()
+{
+ QDeclarativeEngine engine;
+
+ QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/smoothedanimationZeroDuration.qml"));
+
+ QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(c.create());
+ QVERIFY(rect);
+
+ QDeclarativeRectangle *theRect = rect->findChild<QDeclarativeRectangle*>("theRect");
+ QVERIFY(theRect);
+
+ QDeclarativeSmoothedAnimation *easeX = rect->findChild<QDeclarativeSmoothedAnimation*>("easeX");
+ QVERIFY(easeX);
+ QVERIFY(easeX->isRunning());
+
+ QTRY_VERIFY(!easeX->isRunning());
+ QTRY_COMPARE(theRect->x(), qreal(200));
+}
+
QTEST_MAIN(tst_qdeclarativesmoothedanimation)
#include "tst_qdeclarativesmoothedanimation.moc"
diff --git a/tests/auto/declarative/qdeclarativevisualdatamodel/tst_qdeclarativevisualdatamodel.cpp b/tests/auto/declarative/qdeclarativevisualdatamodel/tst_qdeclarativevisualdatamodel.cpp
index 1b2fdc4e..6e7c7f6b 100644
--- a/tests/auto/declarative/qdeclarativevisualdatamodel/tst_qdeclarativevisualdatamodel.cpp
+++ b/tests/auto/declarative/qdeclarativevisualdatamodel/tst_qdeclarativevisualdatamodel.cpp
@@ -520,7 +520,7 @@ void tst_qdeclarativevisualdatamodel::qaimRowsMoved()
SingleRoleModel model;
model.list.clear();
for (int i=0; i<30; i++)
- model.list << ("item " + i);
+ model.list << (QStringLiteral("item ") + QString::number(i));
engine.rootContext()->setContextProperty("myModel", &model);
QDeclarativeVisualDataModel *obj = qobject_cast<QDeclarativeVisualDataModel*>(c.create());