diff options
author | Johan Klokkhammer Helsing <johan.helsing@qt.io> | 2018-09-21 10:03:06 +0200 |
---|---|---|
committer | Johan Helsing <johan.helsing@qt.io> | 2018-09-24 06:48:38 +0000 |
commit | d32e59c1274d5a6806d6e82fd230ce1419d64440 (patch) | |
tree | 76abf375e7a4272b5a236d0d60aa97bf6d51d49e /src/compositor/compositor_api/qwaylandquickitem.cpp | |
parent | 08695981de465eb75f00947c59c237d149253464 (diff) |
Compositor: Add QWaylandQuickItem::mapFromSurface
[ChangeLog][Compositor] Added QWaylandQuickItem::mapFromSurface which converts
points in Wayland surface coordinates to points in QQuickItem coordinates.
i.e. the inverse of the existing QWaylandQuickItem::mapToSurface.
Task-number: QTBUG-70662
Change-Id: I11123c2c5394d7d9b7b8fdfcfd325592597a6b50
Reviewed-by: Paul Olav Tvete <paul.tvete@qt.io>
Diffstat (limited to 'src/compositor/compositor_api/qwaylandquickitem.cpp')
-rw-r--r-- | src/compositor/compositor_api/qwaylandquickitem.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/compositor/compositor_api/qwaylandquickitem.cpp b/src/compositor/compositor_api/qwaylandquickitem.cpp index fd9b1b800..e913a5a8b 100644 --- a/src/compositor/compositor_api/qwaylandquickitem.cpp +++ b/src/compositor/compositor_api/qwaylandquickitem.cpp @@ -1061,6 +1061,22 @@ QPointF QWaylandQuickItem::mapToSurface(const QPointF &point) const } /*! + * Maps the given \a point in the Wayland surfaces's coordinate system to the equivalent + * point within this item's coordinate system, and returns the mapped coordinate. + */ +QPointF QWaylandQuickItem::mapFromSurface(const QPointF &point) const +{ + Q_D(const QWaylandQuickItem); + if (!surface() || surface()->size().isEmpty()) + return point * d->scaleFactor(); + + qreal xScale = width() / surface()->size().width() * surface()->bufferScale(); + qreal yScale = height() / surface()->size().height() * surface()->bufferScale(); + + return QPointF(point.x() * xScale, point.y() * yScale); +} + +/*! * \qmlproperty bool QtWaylandCompositor::WaylandQuickItem::sizeFollowsSurface * * This property specifies whether the size of the item should always match |