setHovered(false);
}
-void QSGMouseArea::mouseUngrabEvent()
+void QSGMouseArea::ungrabMouse()
{
Q_D(QSGMouseArea);
if (d->pressed) {
}
}
+void QSGMouseArea::mouseUngrabEvent()
+{
+ ungrabMouse();
+}
+
bool QSGMouseArea::sendMouseEvent(QGraphicsSceneMouseEvent *event)
{
Q_D(QSGMouseArea);
}
}
+void QSGMouseArea::windowDeactivateEvent()
+{
+ ungrabMouse();
+ QSGItem::windowDeactivateEvent();
+}
+
void QSGMouseArea::geometryChanged(const QRectF &newGeometry,
const QRectF &oldGeometry)
{
virtual void hoverLeaveEvent(QHoverEvent *event);
virtual bool childMouseEventFilter(QSGItem *i, QEvent *e);
virtual void timerEvent(QTimerEvent *event);
+ virtual void windowDeactivateEvent();
virtual void geometryChanged(const QRectF &newGeometry,
const QRectF &oldGeometry);
private:
void handlePress();
void handleRelease();
+ void ungrabMouse();
private:
Q_DISABLE_COPY(QSGMouseArea)
--- /dev/null
+import QtQuick 2.0
+
+Rectangle {
+ id: root
+ color: "#ffffff"
+ width: 320; height: 240
+ property bool pressed:mouse.pressed
+ property bool canceled: false
+ property bool released: false
+
+ MouseArea {
+ id: mouse
+ anchors.fill: parent
+ onPressed: { root.canceled = false }
+ onCanceled: {root.canceled = true}
+ onReleased: {root.released = true; root.canceled = false}
+ }
+}
\ No newline at end of file
void updateMouseAreaPosOnResize();
void noOnClickedWithPressAndHold();
void onMousePressRejected();
+ void pressedCanceledOnWindowDeactivate();
void doubleClick();
void clickTwice();
void pressedOrdering();
delete canvas;
}
+void tst_QSGMouseArea::pressedCanceledOnWindowDeactivate()
+{
+ QSGView *canvas = createView();
+ canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/pressedCanceled.qml"));
+ canvas->show();
+ canvas->setFocus();
+ QVERIFY(canvas->rootObject() != 0);
+ QVERIFY(!canvas->rootObject()->property("pressed").toBool());
+ QVERIFY(!canvas->rootObject()->property("canceled").toBool());
+ QVERIFY(!canvas->rootObject()->property("released").toBool());
+
+ QMouseEvent pressEvent(QEvent::MouseButtonPress, QPoint(100, 100), Qt::LeftButton, Qt::LeftButton, 0);
+ QApplication::sendEvent(canvas, &pressEvent);
+
+ QVERIFY(canvas->rootObject()->property("pressed").toBool());
+ QVERIFY(!canvas->rootObject()->property("canceled").toBool());
+ QVERIFY(!canvas->rootObject()->property("released").toBool());
+
+ QTest::qWait(200);
+
+ QEvent windowDeactivateEvent(QEvent::WindowDeactivate);
+ QApplication::sendEvent(canvas, &windowDeactivateEvent);
+ QVERIFY(!canvas->rootObject()->property("pressed").toBool());
+ QVERIFY(canvas->rootObject()->property("canceled").toBool());
+ QVERIFY(!canvas->rootObject()->property("released").toBool());
+ QTest::qWait(200);
+
+ //press again
+ QApplication::sendEvent(canvas, &pressEvent);
+ QVERIFY(canvas->rootObject()->property("pressed").toBool());
+ QVERIFY(!canvas->rootObject()->property("canceled").toBool());
+ QVERIFY(!canvas->rootObject()->property("released").toBool());
+
+ QTest::qWait(200);
+
+ //release
+ QMouseEvent releaseEvent(QEvent::MouseButtonRelease, QPoint(100, 100), Qt::LeftButton, Qt::LeftButton, 0);
+ QApplication::sendEvent(canvas, &releaseEvent);
+ QVERIFY(!canvas->rootObject()->property("pressed").toBool());
+ QVERIFY(!canvas->rootObject()->property("canceled").toBool());
+ QVERIFY(canvas->rootObject()->property("released").toBool());
+
+ delete canvas;
+}
void tst_QSGMouseArea::doubleClick()
{
QSGView *canvas = createView();