Change QWindow/QWidget::map(To/From)(Global/Parent) to operate in float
Change the functions to operate in float and add the QPoint versions as overload calling them. This is more in-line with the event accessors using float and allows for removing some workarounds using a delta when converting touch points. Leave QPlatformWindow::map(To/From)Global() as is for now and add helpers for float. Change-Id: I2d46b8dbda8adff26539e358074b55073dc80b6f Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>bb10
parent
80f7494e8a
commit
37d5aaa4b4
|
|
@ -2191,8 +2191,7 @@ void QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::Mo
|
|||
window = currentMousePressWindow;
|
||||
currentMousePressWindow = nullptr;
|
||||
}
|
||||
QPointF delta = globalPoint - globalPoint.toPoint();
|
||||
localPoint = window->mapFromGlobal(globalPoint.toPoint()) + delta;
|
||||
localPoint = window->mapFromGlobal(globalPoint);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2285,10 +2284,8 @@ void QGuiApplicationPrivate::processWheelEvent(QWindowSystemInterfacePrivate::Wh
|
|||
|
||||
if (e->nullWindow()) {
|
||||
window = QGuiApplication::topLevelAt(globalPoint.toPoint());
|
||||
if (window) {
|
||||
QPointF delta = globalPoint - globalPoint.toPoint();
|
||||
localPoint = window->mapFromGlobal(globalPoint.toPoint()) + delta;
|
||||
}
|
||||
if (window)
|
||||
localPoint = window->mapFromGlobal(globalPoint);
|
||||
}
|
||||
|
||||
if (!window)
|
||||
|
|
@ -2962,12 +2959,7 @@ void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::To
|
|||
|
||||
for (QEventPoint &pt : touchEvent.touchPoints()) {
|
||||
auto &touchPoint = QMutableEventPoint::from(pt);
|
||||
|
||||
// preserve the sub-pixel resolution
|
||||
const QPointF screenPos = touchPoint.globalPosition();
|
||||
const QPointF delta = screenPos - screenPos.toPoint();
|
||||
|
||||
touchPoint.setPosition(w->mapFromGlobal(screenPos.toPoint()) + delta);
|
||||
touchPoint.setPosition(w->mapFromGlobal(touchPoint.globalPosition()));
|
||||
}
|
||||
|
||||
QGuiApplication::sendSpontaneousEvent(w, &touchEvent);
|
||||
|
|
|
|||
|
|
@ -599,9 +599,9 @@ QPoint QHighDpiScaling::mapPositionFromNative(const QPoint &pos, const QPlatform
|
|||
return (pos - topLeft) / scaleFactor + topLeft;
|
||||
}
|
||||
|
||||
QPoint QHighDpiScaling::mapPositionToGlobal(const QPoint &pos, const QPoint &windowGlobalPosition, const QWindow *window)
|
||||
QPointF QHighDpiScaling::mapPositionToGlobal(const QPointF &pos, const QPoint &windowGlobalPosition, const QWindow *window)
|
||||
{
|
||||
QPoint globalPosCandidate = pos + windowGlobalPosition;
|
||||
QPointF globalPosCandidate = pos + QPointF(windowGlobalPosition);
|
||||
if (QGuiApplicationPrivate::screen_list.size() <= 1)
|
||||
return globalPosCandidate;
|
||||
|
||||
|
|
@ -609,18 +609,18 @@ QPoint QHighDpiScaling::mapPositionToGlobal(const QPoint &pos, const QPoint &win
|
|||
// in cases where a window spans screens. Detect this case and map via
|
||||
// native coordinates to the correct screen.
|
||||
auto currentScreen = window->screen();
|
||||
if (currentScreen && !currentScreen->geometry().contains(globalPosCandidate)) {
|
||||
auto nativeGlobalPos = QHighDpi::toNativePixels(globalPosCandidate, currentScreen);
|
||||
if (auto actualPlatformScreen = currentScreen->handle()->screenForPosition(nativeGlobalPos))
|
||||
if (currentScreen && !currentScreen->geometry().contains(globalPosCandidate.toPoint())) {
|
||||
QPointF nativeGlobalPos = QHighDpi::toNativePixels(globalPosCandidate, currentScreen);
|
||||
if (auto actualPlatformScreen = currentScreen->handle()->screenForPosition(nativeGlobalPos.toPoint()))
|
||||
return QHighDpi::fromNativePixels(nativeGlobalPos, actualPlatformScreen->screen());
|
||||
}
|
||||
|
||||
return globalPosCandidate;
|
||||
}
|
||||
|
||||
QPoint QHighDpiScaling::mapPositionFromGlobal(const QPoint &pos, const QPoint &windowGlobalPosition, const QWindow *window)
|
||||
QPointF QHighDpiScaling::mapPositionFromGlobal(const QPointF &pos, const QPoint &windowGlobalPosition, const QWindow *window)
|
||||
{
|
||||
QPoint windowPosCandidate = pos - windowGlobalPosition;
|
||||
QPointF windowPosCandidate = pos - QPointF(windowGlobalPosition);
|
||||
if (QGuiApplicationPrivate::screen_list.size() <= 1 || window->handle() == nullptr)
|
||||
return windowPosCandidate;
|
||||
|
||||
|
|
@ -629,10 +629,10 @@ QPoint QHighDpiScaling::mapPositionFromGlobal(const QPoint &pos, const QPoint &w
|
|||
// position-to-be-mapped may not work in cases where a window spans multiple screens.
|
||||
// Map both positions to native global space (using the correct screens), subtract there,
|
||||
// and then map the difference back using the scale factor for the window.
|
||||
QScreen *posScreen = QGuiApplication::screenAt(pos);
|
||||
QScreen *posScreen = QGuiApplication::screenAt(pos.toPoint());
|
||||
if (posScreen && posScreen != window->screen()) {
|
||||
QPoint nativePos = QHighDpi::toNativePixels(pos, posScreen);
|
||||
QPoint windowNativePos = window->handle()->geometry().topLeft();
|
||||
QPointF nativePos = QHighDpi::toNativePixels(pos, posScreen);
|
||||
QPointF windowNativePos = window->handle()->geometry().topLeft();
|
||||
return QHighDpi::fromNativeLocalPosition(nativePos - windowNativePos, window);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -112,8 +112,8 @@ public:
|
|||
|
||||
static QPoint mapPositionFromNative(const QPoint &pos, const QPlatformScreen *platformScreen);
|
||||
static QPoint mapPositionToNative(const QPoint &pos, const QPlatformScreen *platformScreen);
|
||||
static QPoint mapPositionToGlobal(const QPoint &pos, const QPoint &windowGlobalPosition, const QWindow *window);
|
||||
static QPoint mapPositionFromGlobal(const QPoint &pos, const QPoint &windowGlobalPosition, const QWindow *window);
|
||||
static QPointF mapPositionToGlobal(const QPointF &pos, const QPoint &windowGlobalPosition, const QWindow *window);
|
||||
static QPointF mapPositionFromGlobal(const QPointF &pos, const QPoint &windowGlobalPosition, const QWindow *window);
|
||||
static QDpi logicalDpi(const QScreen *screen);
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -266,6 +266,20 @@ QPoint QPlatformWindow::mapToGlobal(const QPoint &pos) const
|
|||
return result;
|
||||
}
|
||||
|
||||
QPointF QPlatformWindow::mapToGlobalF(const QPointF &pos) const
|
||||
{
|
||||
const QPoint posPt = pos.toPoint();
|
||||
const QPointF delta = pos - posPt;
|
||||
return mapToGlobal(posPt) + delta;
|
||||
}
|
||||
|
||||
QPointF QPlatformWindow::mapFromGlobalF(const QPointF &pos) const
|
||||
{
|
||||
const QPoint posPt = pos.toPoint();
|
||||
const QPointF delta = pos - posPt;
|
||||
return mapFromGlobal(posPt) + delta;
|
||||
}
|
||||
|
||||
/*!
|
||||
Translates the global screen coordinate \a pos to window
|
||||
coordinates using native methods. This is required for embedded windows,
|
||||
|
|
|
|||
|
|
@ -113,7 +113,9 @@ public:
|
|||
virtual bool isEmbedded() const;
|
||||
virtual bool isForeignWindow() const { return false; }
|
||||
virtual QPoint mapToGlobal(const QPoint &pos) const;
|
||||
QPointF mapToGlobalF(const QPointF &pos) const;
|
||||
virtual QPoint mapFromGlobal(const QPoint &pos) const;
|
||||
QPointF mapFromGlobalF(const QPointF &pos) const;
|
||||
|
||||
virtual void propagateSizeHints();
|
||||
|
||||
|
|
|
|||
|
|
@ -180,7 +180,7 @@ bool QBasicDrag::eventFilter(QObject *o, QEvent *e)
|
|||
qCDebug(lcDnd) << "mouse released over" << releaseWindow << "after drag from" << m_sourceWindow << "globalPos" << release->globalPosition().toPoint();
|
||||
if (!releaseWindow)
|
||||
releaseWindow = m_sourceWindow;
|
||||
QPoint releaseWindowPos = (releaseWindow ? releaseWindow->mapFromGlobal(release->globalPosition().toPoint()) : release->globalPosition().toPoint());
|
||||
QPointF releaseWindowPos = (releaseWindow ? releaseWindow->mapFromGlobal(release->globalPosition()) : release->globalPosition());
|
||||
QMouseEvent *newRelease = new QMouseEvent(release->type(),
|
||||
releaseWindowPos, releaseWindowPos, release->globalPosition(),
|
||||
release->button(), release->buttons(),
|
||||
|
|
|
|||
|
|
@ -2631,51 +2631,68 @@ bool QWindow::nativeEvent(const QByteArray &eventType, void *message, long *resu
|
|||
}
|
||||
|
||||
/*!
|
||||
\fn QPoint QWindow::mapToGlobal(const QPoint &pos) const
|
||||
\fn QPointF QWindow::mapToGlobal(const QPointF &pos) const
|
||||
|
||||
Translates the window coordinate \a pos to global screen
|
||||
coordinates. For example, \c{mapToGlobal(QPoint(0,0))} would give
|
||||
coordinates. For example, \c{mapToGlobal(QPointF(0,0))} would give
|
||||
the global coordinates of the top-left pixel of the window.
|
||||
|
||||
\sa mapFromGlobal()
|
||||
\since 6.0
|
||||
*/
|
||||
QPoint QWindow::mapToGlobal(const QPoint &pos) const
|
||||
QPointF QWindow::mapToGlobal(const QPointF &pos) const
|
||||
{
|
||||
Q_D(const QWindow);
|
||||
// QTBUG-43252, prefer platform implementation for foreign windows.
|
||||
if (d->platformWindow
|
||||
&& (d->platformWindow->isForeignWindow() || d->platformWindow->isEmbedded())) {
|
||||
return QHighDpi::fromNativeLocalPosition(d->platformWindow->mapToGlobal(QHighDpi::toNativeLocalPosition(pos, this)), this);
|
||||
return QHighDpi::fromNativeLocalPosition(d->platformWindow->mapToGlobalF(QHighDpi::toNativeLocalPosition(pos, this)), this);
|
||||
}
|
||||
|
||||
if (QHighDpiScaling::isActive())
|
||||
return QHighDpiScaling::mapPositionToGlobal(pos, d->globalPosition(), this);
|
||||
|
||||
return pos + d->globalPosition();
|
||||
return pos + QPointF(d->globalPosition());
|
||||
}
|
||||
|
||||
/*!
|
||||
\overload
|
||||
*/
|
||||
QPoint QWindow::mapToGlobal(const QPoint &pos) const
|
||||
{
|
||||
return mapToGlobal(QPointF(pos)).toPoint();
|
||||
}
|
||||
|
||||
/*!
|
||||
\fn QPoint QWindow::mapFromGlobal(const QPoint &pos) const
|
||||
\fn QPointF QWindow::mapFromGlobal(const QPointF &pos) const
|
||||
|
||||
Translates the global screen coordinate \a pos to window
|
||||
coordinates.
|
||||
|
||||
\sa mapToGlobal()
|
||||
\since 6.0
|
||||
*/
|
||||
QPoint QWindow::mapFromGlobal(const QPoint &pos) const
|
||||
QPointF QWindow::mapFromGlobal(const QPointF &pos) const
|
||||
{
|
||||
Q_D(const QWindow);
|
||||
// QTBUG-43252, prefer platform implementation for foreign windows.
|
||||
if (d->platformWindow
|
||||
&& (d->platformWindow->isForeignWindow() || d->platformWindow->isEmbedded())) {
|
||||
return QHighDpi::fromNativeLocalPosition(d->platformWindow->mapFromGlobal(QHighDpi::toNativeLocalPosition(pos, this)), this);
|
||||
return QHighDpi::fromNativeLocalPosition(d->platformWindow->mapFromGlobalF(QHighDpi::toNativeLocalPosition(pos, this)), this);
|
||||
}
|
||||
|
||||
if (QHighDpiScaling::isActive())
|
||||
return QHighDpiScaling::mapPositionFromGlobal(pos, d->globalPosition(), this);
|
||||
|
||||
return pos - d->globalPosition();
|
||||
return pos - QPointF(d->globalPosition());
|
||||
}
|
||||
|
||||
/*!
|
||||
\overload
|
||||
*/
|
||||
QPoint QWindow::mapFromGlobal(const QPoint &pos) const
|
||||
{
|
||||
return QWindow::mapFromGlobal(QPointF(pos)).toPoint();
|
||||
}
|
||||
|
||||
QPoint QWindowPrivate::globalPosition() const
|
||||
|
|
|
|||
|
|
@ -260,6 +260,8 @@ public:
|
|||
virtual QAccessibleInterface *accessibleRoot() const;
|
||||
virtual QObject *focusObject() const;
|
||||
|
||||
QPointF mapToGlobal(const QPointF &pos) const;
|
||||
QPointF mapFromGlobal(const QPointF &pos) const;
|
||||
QPoint mapToGlobal(const QPoint &pos) const;
|
||||
QPoint mapFromGlobal(const QPoint &pos) const;
|
||||
|
||||
|
|
|
|||
|
|
@ -3207,7 +3207,7 @@ bool QApplication::notify(QObject *receiver, QEvent *e)
|
|||
}
|
||||
if (w->isWindow())
|
||||
break;
|
||||
dragEvent->p = w->mapToParent(dragEvent->p.toPoint());
|
||||
dragEvent->p = w->mapToParent(dragEvent->p);
|
||||
w = w->parentWidget();
|
||||
}
|
||||
}
|
||||
|
|
@ -3232,7 +3232,7 @@ bool QApplication::notify(QObject *receiver, QEvent *e)
|
|||
QDropEvent *dragEvent = static_cast<QDropEvent *>(e);
|
||||
QWidget *origReciver = static_cast<QWidget *>(receiver);
|
||||
while (origReciver && w != origReciver) {
|
||||
dragEvent->p = origReciver->mapToParent(dragEvent->p.toPoint());
|
||||
dragEvent->p = origReciver->mapToParent(dragEvent->p);
|
||||
origReciver = origReciver->parentWidget();
|
||||
}
|
||||
}
|
||||
|
|
@ -3942,11 +3942,8 @@ bool QApplicationPrivate::updateTouchPointsForWidget(QWidget *widget, QTouchEven
|
|||
bool containsPress = false;
|
||||
|
||||
for (QEventPoint &pt : QMutableTouchEvent::from(touchEvent)->touchPoints()) {
|
||||
// preserve the sub-pixel resolution
|
||||
const QPointF screenPos = pt.globalPosition();
|
||||
const QPointF delta = screenPos - screenPos.toPoint();
|
||||
|
||||
QMutableEventPoint::from(pt).setPosition(widget->mapFromGlobal(screenPos.toPoint()) + delta);
|
||||
QMutableEventPoint::from(pt).setPosition(widget->mapFromGlobal(screenPos));
|
||||
|
||||
if (pt.state() == QEventPoint::State::Pressed)
|
||||
containsPress = true;
|
||||
|
|
|
|||
|
|
@ -4029,15 +4029,16 @@ void QWidget::setFixedHeight(int h)
|
|||
of the calling widget.
|
||||
|
||||
\sa mapFrom(), mapToParent(), mapToGlobal(), underMouse()
|
||||
\since 6.0
|
||||
*/
|
||||
|
||||
QPoint QWidget::mapTo(const QWidget * parent, const QPoint & pos) const
|
||||
QPointF QWidget::mapTo(const QWidget *parent, const QPointF &pos) const
|
||||
{
|
||||
QPoint p = pos;
|
||||
QPointF p = pos;
|
||||
if (parent) {
|
||||
const QWidget * w = this;
|
||||
while (w != parent) {
|
||||
Q_ASSERT_X(w, "QWidget::mapTo(const QWidget *parent, const QPoint &pos)",
|
||||
Q_ASSERT_X(w, "QWidget::mapTo(const QWidget *parent, const QPointF &pos)",
|
||||
"parent must be in parent hierarchy");
|
||||
p = w->mapToParent(p);
|
||||
w = w->parentWidget();
|
||||
|
|
@ -4046,6 +4047,13 @@ QPoint QWidget::mapTo(const QWidget * parent, const QPoint & pos) const
|
|||
return p;
|
||||
}
|
||||
|
||||
/*!
|
||||
\overload
|
||||
*/
|
||||
QPoint QWidget::mapTo(const QWidget *parent, const QPoint &pos) const
|
||||
{
|
||||
return mapTo(parent, QPointF(pos)).toPoint();
|
||||
}
|
||||
|
||||
/*!
|
||||
Translates the widget coordinate \a pos from the coordinate system
|
||||
|
|
@ -4053,11 +4061,12 @@ QPoint QWidget::mapTo(const QWidget * parent, const QPoint & pos) const
|
|||
must not be \nullptr and must be a parent of the calling widget.
|
||||
|
||||
\sa mapTo(), mapFromParent(), mapFromGlobal(), underMouse()
|
||||
\since 6.0
|
||||
*/
|
||||
|
||||
QPoint QWidget::mapFrom(const QWidget * parent, const QPoint & pos) const
|
||||
QPointF QWidget::mapFrom(const QWidget *parent, const QPointF &pos) const
|
||||
{
|
||||
QPoint p(pos);
|
||||
QPointF p(pos);
|
||||
if (parent) {
|
||||
const QWidget * w = this;
|
||||
while (w != parent) {
|
||||
|
|
@ -4071,6 +4080,13 @@ QPoint QWidget::mapFrom(const QWidget * parent, const QPoint & pos) const
|
|||
return p;
|
||||
}
|
||||
|
||||
/*!
|
||||
\overload
|
||||
*/
|
||||
QPoint QWidget::mapFrom(const QWidget *parent, const QPoint &pos) const
|
||||
{
|
||||
return mapFrom(parent, QPointF(pos)).toPoint();
|
||||
}
|
||||
|
||||
/*!
|
||||
Translates the widget coordinate \a pos to a coordinate in the
|
||||
|
|
@ -4079,8 +4095,17 @@ QPoint QWidget::mapFrom(const QWidget * parent, const QPoint & pos) const
|
|||
Same as mapToGlobal() if the widget has no parent.
|
||||
|
||||
\sa mapFromParent(), mapTo(), mapToGlobal(), underMouse()
|
||||
\since 6.0
|
||||
*/
|
||||
|
||||
QPointF QWidget::mapToParent(const QPointF &pos) const
|
||||
{
|
||||
return pos + QPointF(data->crect.topLeft());
|
||||
}
|
||||
|
||||
/*!
|
||||
\overload
|
||||
*/
|
||||
QPoint QWidget::mapToParent(const QPoint &pos) const
|
||||
{
|
||||
return pos + data->crect.topLeft();
|
||||
|
|
@ -4093,8 +4118,17 @@ QPoint QWidget::mapToParent(const QPoint &pos) const
|
|||
Same as mapFromGlobal() if the widget has no parent.
|
||||
|
||||
\sa mapToParent(), mapFrom(), mapFromGlobal(), underMouse()
|
||||
\since 6.0
|
||||
*/
|
||||
|
||||
QPointF QWidget::mapFromParent(const QPointF &pos) const
|
||||
{
|
||||
return pos - QPointF(data->crect.topLeft());
|
||||
}
|
||||
|
||||
/*!
|
||||
\overload
|
||||
*/
|
||||
QPoint QWidget::mapFromParent(const QPoint &pos) const
|
||||
{
|
||||
return pos - data->crect.topLeft();
|
||||
|
|
@ -12177,34 +12211,52 @@ static MapToGlobalTransformResult mapToGlobalTransform(const QWidget *w)
|
|||
}
|
||||
|
||||
/*!
|
||||
\fn QPoint QWidget::mapToGlobal(const QPoint &pos) const
|
||||
\fn QPointF QWidget::mapToGlobal(const QPointF &pos) const
|
||||
|
||||
Translates the widget coordinate \a pos to global screen
|
||||
coordinates. For example, \c{mapToGlobal(QPoint(0,0))} would give
|
||||
coordinates. For example, \c{mapToGlobal(QPointF(0,0))} would give
|
||||
the global coordinates of the top-left pixel of the widget.
|
||||
|
||||
\sa mapFromGlobal(), mapTo(), mapToParent()
|
||||
\since 6.0
|
||||
*/
|
||||
QPoint QWidget::mapToGlobal(const QPoint &pos) const
|
||||
QPointF QWidget::mapToGlobal(const QPointF &pos) const
|
||||
{
|
||||
const MapToGlobalTransformResult t = mapToGlobalTransform(this);
|
||||
const QPoint g = t.transform.map(pos);
|
||||
const QPointF g = t.transform.map(pos);
|
||||
return t.window ? t.window->mapToGlobal(g) : g;
|
||||
}
|
||||
|
||||
/*!
|
||||
\fn QPoint QWidget::mapFromGlobal(const QPoint &pos) const
|
||||
\overload
|
||||
*/
|
||||
QPoint QWidget::mapToGlobal(const QPoint &pos) const
|
||||
{
|
||||
return mapToGlobal(QPointF(pos)).toPoint();
|
||||
}
|
||||
|
||||
/*!
|
||||
\fn QPointF QWidget::mapFromGlobal(const QPointF &pos) const
|
||||
|
||||
Translates the global screen coordinate \a pos to widget
|
||||
coordinates.
|
||||
|
||||
\sa mapToGlobal(), mapFrom(), mapFromParent()
|
||||
\since 6.0
|
||||
*/
|
||||
QPointF QWidget::mapFromGlobal(const QPointF &pos) const
|
||||
{
|
||||
const MapToGlobalTransformResult t = mapToGlobalTransform(this);
|
||||
const QPointF windowLocal = t.window ? t.window->mapFromGlobal(pos) : pos;
|
||||
return t.transform.inverted().map(windowLocal);
|
||||
}
|
||||
|
||||
/*!
|
||||
\overload
|
||||
*/
|
||||
QPoint QWidget::mapFromGlobal(const QPoint &pos) const
|
||||
{
|
||||
const MapToGlobalTransformResult t = mapToGlobalTransform(this);
|
||||
const QPoint windowLocal = t.window ? t.window->mapFromGlobal(pos) : pos;
|
||||
return t.transform.inverted().map(windowLocal);
|
||||
return mapFromGlobal(QPointF(pos)).toPoint();
|
||||
}
|
||||
|
||||
QWidget *qt_pressGrab = nullptr;
|
||||
|
|
|
|||
|
|
@ -295,11 +295,17 @@ public:
|
|||
|
||||
// Widget coordinate mapping
|
||||
|
||||
QPointF mapToGlobal(const QPointF &) const;
|
||||
QPoint mapToGlobal(const QPoint &) const;
|
||||
QPointF mapFromGlobal(const QPointF &) const;
|
||||
QPoint mapFromGlobal(const QPoint &) const;
|
||||
QPointF mapToParent(const QPointF &) const;
|
||||
QPoint mapToParent(const QPoint &) const;
|
||||
QPointF mapFromParent(const QPointF &) const;
|
||||
QPoint mapFromParent(const QPoint &) const;
|
||||
QPointF mapTo(const QWidget *, const QPointF &) const;
|
||||
QPoint mapTo(const QWidget *, const QPoint &) const;
|
||||
QPointF mapFrom(const QWidget *, const QPointF &) const;
|
||||
QPoint mapFrom(const QWidget *, const QPoint &) const;
|
||||
|
||||
QWidget *window() const;
|
||||
|
|
|
|||
|
|
@ -845,25 +845,25 @@ void QWidgetWindow::handleWheelEvent(QWheelEvent *event)
|
|||
return;
|
||||
|
||||
QWidget *rootWidget = m_widget;
|
||||
QPoint pos = event->position().toPoint();
|
||||
QPointF pos = event->position();
|
||||
|
||||
// Use proper popup window for wheel event. Some QPA sends the wheel
|
||||
// event to the root menu, so redirect it to the proper popup window.
|
||||
QWidget *activePopupWidget = QApplication::activePopupWidget();
|
||||
if (activePopupWidget && activePopupWidget != m_widget) {
|
||||
rootWidget = activePopupWidget;
|
||||
pos = rootWidget->mapFromGlobal(event->globalPosition().toPoint());
|
||||
pos = rootWidget->mapFromGlobal(event->globalPosition());
|
||||
}
|
||||
|
||||
// which child should have it?
|
||||
QWidget *widget = rootWidget->childAt(pos);
|
||||
QWidget *widget = rootWidget->childAt(pos.toPoint());
|
||||
|
||||
if (!widget)
|
||||
widget = rootWidget;
|
||||
|
||||
QPoint mapped = widget->mapFrom(rootWidget, pos);
|
||||
QPointF mapped = widget->mapFrom(rootWidget, pos);
|
||||
|
||||
QWheelEvent translated(QPointF(mapped), event->globalPosition(), event->pixelDelta(), event->angleDelta(),
|
||||
QWheelEvent translated(mapped, event->globalPosition(), event->pixelDelta(), event->angleDelta(),
|
||||
event->buttons(), event->modifiers(), event->phase(), event->inverted(),
|
||||
event->source(), event->pointingDevice());
|
||||
translated.setTimestamp(event->timestamp());
|
||||
|
|
|
|||
|
|
@ -297,8 +297,8 @@ protected:
|
|||
#endif // QT_CONFIG(graphicsview)
|
||||
|
||||
if (me) {
|
||||
QMouseEvent copy(me->type(), mouseTarget->mapFromGlobal(me->globalPosition().toPoint()),
|
||||
mouseTarget->topLevelWidget()->mapFromGlobal(me->globalPosition().toPoint()), me->globalPosition(),
|
||||
QMouseEvent copy(me->type(), mouseTarget->mapFromGlobal(me->globalPosition()),
|
||||
mouseTarget->topLevelWidget()->mapFromGlobal(me->globalPosition()), me->globalPosition(),
|
||||
me->button(), me->buttons(), me->modifiers(), me->source());
|
||||
qt_sendSpontaneousEvent(mouseTarget, ©);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1356,14 +1356,14 @@ bool QMenuPrivate::mouseEventTaken(QMouseEvent *e)
|
|||
for(QWidget *caused = causedPopup.widget; caused;) {
|
||||
bool passOnEvent = false;
|
||||
QWidget *next_widget = nullptr;
|
||||
QPoint cpos = caused->mapFromGlobal(e->globalPosition().toPoint());
|
||||
QPointF cpos = caused->mapFromGlobal(e->globalPosition());
|
||||
#if QT_CONFIG(menubar)
|
||||
if (QMenuBar *mb = qobject_cast<QMenuBar*>(caused)) {
|
||||
passOnEvent = mb->rect().contains(cpos);
|
||||
passOnEvent = mb->rect().contains(cpos.toPoint());
|
||||
} else
|
||||
#endif
|
||||
if (QMenu *m = qobject_cast<QMenu*>(caused)) {
|
||||
passOnEvent = m->rect().contains(cpos);
|
||||
passOnEvent = m->rect().contains(cpos.toPoint());
|
||||
next_widget = m->d_func()->causedPopup.widget;
|
||||
}
|
||||
if (passOnEvent) {
|
||||
|
|
|
|||
|
|
@ -260,10 +260,16 @@ void tst_QWindow::mapGlobal()
|
|||
c.setGeometry(40, 40, 100, 100);
|
||||
|
||||
QCOMPARE(a.mapToGlobal(QPoint(100, 100)), QPoint(110, 110));
|
||||
auto delta = a.mapToGlobal(QPointF(100.5, 100.5)) - QPointF(110.5, 110.5);
|
||||
QVERIFY(qFuzzyIsNull(delta.manhattanLength()));
|
||||
|
||||
QCOMPARE(b.mapToGlobal(QPoint(100, 100)), QPoint(130, 130));
|
||||
QCOMPARE(c.mapToGlobal(QPoint(100, 100)), QPoint(170, 170));
|
||||
|
||||
QCOMPARE(a.mapFromGlobal(QPoint(100, 100)), QPoint(90, 90));
|
||||
delta = a.mapFromGlobal(QPointF(100.5, 100.5)) - QPointF(90.5, 90.5);
|
||||
QVERIFY(qFuzzyIsNull(delta.manhattanLength()));
|
||||
|
||||
QCOMPARE(b.mapFromGlobal(QPoint(100, 100)), QPoint(70, 70));
|
||||
QCOMPARE(c.mapFromGlobal(QPoint(100, 100)), QPoint(30, 30));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1608,6 +1608,8 @@ void tst_QWidget::mapFromAndTo()
|
|||
QCOMPARE(window.mapToGlobal(QPoint(-10, 0)), QPoint(90, 100));
|
||||
QCOMPARE(window.mapToGlobal(QPoint(0, -10)), QPoint(100, 90));
|
||||
QCOMPARE(window.mapToGlobal(QPoint(100, 100)), QPoint(200, 200));
|
||||
auto delta = window.mapToGlobal(QPointF(100.5, 100.5)) - QPointF(200.5, 200.5);
|
||||
QVERIFY(qFuzzyIsNull(delta.manhattanLength()));
|
||||
QCOMPARE(window.mapToGlobal(QPoint(110, 100)), QPoint(210, 200));
|
||||
QCOMPARE(window.mapToGlobal(QPoint(100, 110)), QPoint(200, 210));
|
||||
QCOMPARE(window.mapFromGlobal(QPoint(100, 100)), QPoint(0, 0));
|
||||
|
|
@ -1616,6 +1618,8 @@ void tst_QWidget::mapFromAndTo()
|
|||
QCOMPARE(window.mapFromGlobal(QPoint(90, 100)), QPoint(-10, 0));
|
||||
QCOMPARE(window.mapFromGlobal(QPoint(100, 90)), QPoint(0, -10));
|
||||
QCOMPARE(window.mapFromGlobal(QPoint(200, 200)), QPoint(100, 100));
|
||||
delta = window.mapFromGlobal(QPointF(200.5, 200.5)) - QPointF(100.5, 100.5);
|
||||
QVERIFY(qFuzzyIsNull(delta.manhattanLength()));
|
||||
QCOMPARE(window.mapFromGlobal(QPoint(210, 200)), QPoint(110, 100));
|
||||
QCOMPARE(window.mapFromGlobal(QPoint(200, 210)), QPoint(100, 110));
|
||||
QCOMPARE(window.mapToParent(QPoint(0, 0)), QPoint(100, 100));
|
||||
|
|
|
|||
Loading…
Reference in New Issue