summaryrefslogtreecommitdiffstats
path: root/src/widgets
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2020-06-11 09:24:12 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2020-07-14 10:25:47 +0200
commit37d5aaa4b42f9c837f0d27edb9da2185971d02be (patch)
tree867c23bfbff55f3d27dfee553ab20b015a938aa0 /src/widgets
parent80f7494e8a9f9a70e3b53833a098d74d8c2331d9 (diff)
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>
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/kernel/qapplication.cpp9
-rw-r--r--src/widgets/kernel/qwidget.cpp76
-rw-r--r--src/widgets/kernel/qwidget.h6
-rw-r--r--src/widgets/kernel/qwidgetwindow.cpp10
-rw-r--r--src/widgets/util/qflickgesture.cpp4
-rw-r--r--src/widgets/widgets/qmenu.cpp6
6 files changed, 83 insertions, 28 deletions
diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp
index f19801f511..951fc9cd67 100644
--- a/src/widgets/kernel/qapplication.cpp
+++ b/src/widgets/kernel/qapplication.cpp
@@ -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;
diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp
index dcebc5e5df..01755e01c7 100644
--- a/src/widgets/kernel/qwidget.cpp
+++ b/src/widgets/kernel/qwidget.cpp
@@ -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,36 +12211,54 @@ 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
*/
-QPoint QWidget::mapFromGlobal(const QPoint &pos) const
+QPointF QWidget::mapFromGlobal(const QPointF &pos) const
{
const MapToGlobalTransformResult t = mapToGlobalTransform(this);
- const QPoint windowLocal = t.window ? t.window->mapFromGlobal(pos) : pos;
+ const QPointF windowLocal = t.window ? t.window->mapFromGlobal(pos) : pos;
return t.transform.inverted().map(windowLocal);
}
+/*!
+ \overload
+*/
+QPoint QWidget::mapFromGlobal(const QPoint &pos) const
+{
+ return mapFromGlobal(QPointF(pos)).toPoint();
+}
+
QWidget *qt_pressGrab = nullptr;
QWidget *qt_mouseGrb = nullptr;
static bool mouseGrabWithCursor = false;
diff --git a/src/widgets/kernel/qwidget.h b/src/widgets/kernel/qwidget.h
index 0d2c2913f9..2bfff96252 100644
--- a/src/widgets/kernel/qwidget.h
+++ b/src/widgets/kernel/qwidget.h
@@ -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;
diff --git a/src/widgets/kernel/qwidgetwindow.cpp b/src/widgets/kernel/qwidgetwindow.cpp
index 05bf43d669..32d89dbb44 100644
--- a/src/widgets/kernel/qwidgetwindow.cpp
+++ b/src/widgets/kernel/qwidgetwindow.cpp
@@ -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());
diff --git a/src/widgets/util/qflickgesture.cpp b/src/widgets/util/qflickgesture.cpp
index 7d12350c9a..3b4af0fe8f 100644
--- a/src/widgets/util/qflickgesture.cpp
+++ b/src/widgets/util/qflickgesture.cpp
@@ -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, &copy);
}
diff --git a/src/widgets/widgets/qmenu.cpp b/src/widgets/widgets/qmenu.cpp
index 5edc480949..74420ecb2c 100644
--- a/src/widgets/widgets/qmenu.cpp
+++ b/src/widgets/widgets/qmenu.cpp
@@ -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) {