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 <Friedemann.Kleint@theqtcompany.com>bb10
parent
cb07059525
commit
1c7e3a2a33
|
|
@ -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 *)
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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 *)
|
||||
|
|
|
|||
Loading…
Reference in New Issue