From 1c7e3a2a33b890a19bbac57cd068aef04c134527 Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Thu, 30 Apr 2015 15:18:44 +0200 Subject: QShapedPixmapWindow: ensure we set a valid geometry On touch platforms, QCursor::pos() will only be 'valid' when a touch event has (at least once) been translated to a mouse event. Currently this never happens in QtQuick since QtQuick always accepts all touch events and performs its own translations. So rather than setting the geometry of QShapedPixmapWindow from QCursor directly, we instead base it on mouse events. This will ensure that we never try to set the geometry of the window to an 'invalid' value, which can cause a crash on platforms like iOS. Note that we currenly miss an API in Qt to get the current touch points. When that is in place, we can also set a correct start position for the window before the first mouse move event arrives. Task-number: QTBUG-45877 Change-Id: I320598e87d43f6e9e087c204a69b95465128f468 Reviewed-by: Friedemann Kleint --- src/gui/kernel/qshapedpixmapdndwindow.cpp | 8 +++----- src/gui/kernel/qshapedpixmapdndwindow_p.h | 2 +- src/gui/kernel/qsimpledrag.cpp | 15 ++++++++++++--- 3 files changed, 16 insertions(+), 9 deletions(-) (limited to 'src/gui') diff --git a/src/gui/kernel/qshapedpixmapdndwindow.cpp b/src/gui/kernel/qshapedpixmapdndwindow.cpp index 9d0197ef9d..8f80789fb0 100644 --- a/src/gui/kernel/qshapedpixmapdndwindow.cpp +++ b/src/gui/kernel/qshapedpixmapdndwindow.cpp @@ -86,16 +86,14 @@ void QShapedPixmapWindow::setHotspot(const QPoint &hotspot) m_hotSpot = hotspot; } -void QShapedPixmapWindow::updateGeometry() +void QShapedPixmapWindow::updateGeometry(const QPoint &pos) { -#ifndef QT_NO_CURSOR - QRect rect(QCursor::pos() - m_hotSpot, m_pixmap.size()); if (m_pixmap.isNull()) m_backingStore->resize(QSize(1,1)); else if (m_backingStore->size() != m_pixmap.size()) m_backingStore->resize(m_pixmap.size()); - setGeometry(rect); -#endif + + setGeometry(QRect(pos - m_hotSpot, m_backingStore->size())); } void QShapedPixmapWindow::exposeEvent(QExposeEvent *) diff --git a/src/gui/kernel/qshapedpixmapdndwindow_p.h b/src/gui/kernel/qshapedpixmapdndwindow_p.h index ec56573195..fc311cff92 100644 --- a/src/gui/kernel/qshapedpixmapdndwindow_p.h +++ b/src/gui/kernel/qshapedpixmapdndwindow_p.h @@ -63,7 +63,7 @@ public: void setPixmap(const QPixmap &pixmap); void setHotspot(const QPoint &hotspot); - void updateGeometry(); + void updateGeometry(const QPoint &pos); protected: void exposeEvent(QExposeEvent *) Q_DECL_OVERRIDE; diff --git a/src/gui/kernel/qsimpledrag.cpp b/src/gui/kernel/qsimpledrag.cpp index 090e88c118..b850f53014 100644 --- a/src/gui/kernel/qsimpledrag.cpp +++ b/src/gui/kernel/qsimpledrag.cpp @@ -201,7 +201,16 @@ void QBasicDrag::startDrag() m_drag_icon_window->setPixmap(m_drag->pixmap()); m_drag_icon_window->setHotspot(m_drag->hotSpot()); - m_drag_icon_window->updateGeometry(); + +#ifndef QT_NO_CURSOR + QPoint pos = QCursor::pos(); + if (pos.x() == int(qInf())) { + // ### fixme: no mouse pos registered. Get pos from touch... + pos = QPoint(); + } + m_drag_icon_window->updateGeometry(pos); +#endif + m_drag_icon_window->setVisible(true); enableEventFilter(); @@ -218,10 +227,10 @@ void QBasicDrag::cancel() m_drag_icon_window->setVisible(false); } -void QBasicDrag::move(const QMouseEvent *) +void QBasicDrag::move(const QMouseEvent *e) { if (m_drag) - m_drag_icon_window->updateGeometry(); + m_drag_icon_window->updateGeometry(e->globalPos()); } void QBasicDrag::drop(const QMouseEvent *) -- cgit v1.2.3