summaryrefslogtreecommitdiff
path: root/src/imports/positioning
diff options
context:
space:
mode:
authorMichal Klocek <michal.klocek@theqtcompany.com>2015-06-09 14:37:52 +0200
committerMichal Klocek <michal.klocek@theqtcompany.com>2015-06-23 12:42:51 +0000
commitf5c6e2690a749cd1e33b49a1cb57ebfa94996da3 (patch)
treebaa7e5969a6caf7e7dea77c61144a534cfdae9fb /src/imports/positioning
parent526fd8bd3d9ef112399d1cae6c0dfa094525d33e (diff)
downloadqtlocation-f5c6e2690a749cd1e33b49a1cb57ebfa94996da3.tar.gz
Add new types of interpolation to CoordinateAnimation
A longitude animation can go in two directions West and East. Current implementation is always using the shortest animation path between two coordinates. Provide setting to overload this behavior. Add 'direction' setting to CoordianteAnimation. Implement two new interpolators and provide new private implementation derived form qquickpropertyanimation. Change-Id: Ida70780c8aef60ebea7a8b8d59f115c583430374 Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'src/imports/positioning')
-rw-r--r--src/imports/positioning/positioning.cpp4
-rw-r--r--src/imports/positioning/positioning.pro5
-rw-r--r--src/imports/positioning/qdeclarativegeocoordinateanimation.cpp96
-rw-r--r--src/imports/positioning/qquickgeocoordinateanimation.cpp212
-rw-r--r--src/imports/positioning/qquickgeocoordinateanimation_p.h (renamed from src/imports/positioning/qdeclarativegeocoordinateanimation_p.h)32
-rw-r--r--src/imports/positioning/qquickgeocoordinateanimation_p_p.h63
6 files changed, 304 insertions, 108 deletions
diff --git a/src/imports/positioning/positioning.cpp b/src/imports/positioning/positioning.cpp
index d8380750..ef8eb776 100644
--- a/src/imports/positioning/positioning.cpp
+++ b/src/imports/positioning/positioning.cpp
@@ -39,7 +39,7 @@
#include "qdeclarativepositionsource_p.h"
#include "qdeclarativeposition_p.h"
-#include "qdeclarativegeocoordinateanimation_p.h"
+#include "qquickgeocoordinateanimation_p.h"
#include "locationsingleton.h"
#include <QtCore/QVariantAnimation>
@@ -531,7 +531,7 @@ public:
// Register the 5.3 types
// Introduction of 5.3 version; existing 5.0 exports become automatically available under 5.3
minor = 3;
- qmlRegisterType<QDeclarativeGeoCoordinateAnimation >(uri, major, minor, "CoordinateAnimation");
+ qmlRegisterType<QQuickGeoCoordinateAnimation >(uri, major, minor, "CoordinateAnimation");
qmlRegisterType<QDeclarativePosition, 1 >(uri, major, minor, "Position");
// Register the 5.4 types
diff --git a/src/imports/positioning/positioning.pro b/src/imports/positioning/positioning.pro
index 7e49ec8e..119c3dea 100644
--- a/src/imports/positioning/positioning.pro
+++ b/src/imports/positioning/positioning.pro
@@ -5,13 +5,14 @@ INCLUDEPATH *= $$PWD
HEADERS += qdeclarativeposition_p.h \
qdeclarativepositionsource_p.h \
locationsingleton.h \
- qdeclarativegeocoordinateanimation_p.h
+ qquickgeocoordinateanimation_p.h \
+ qquickgeocoordinateanimation_p_p.h
SOURCES += qdeclarativeposition.cpp \
positioning.cpp \
qdeclarativepositionsource.cpp \
locationsingleton.cpp \
- qdeclarativegeocoordinateanimation.cpp
+ qquickgeocoordinateanimation.cpp
load(qml_plugin)
diff --git a/src/imports/positioning/qdeclarativegeocoordinateanimation.cpp b/src/imports/positioning/qdeclarativegeocoordinateanimation.cpp
deleted file mode 100644
index 8bb677ad..00000000
--- a/src/imports/positioning/qdeclarativegeocoordinateanimation.cpp
+++ /dev/null
@@ -1,96 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the QtPositioning module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL21$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** As a special exception, The Qt Company gives you certain additional
-** rights. These rights are described in The Qt Company LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qdeclarativegeocoordinateanimation_p.h"
-#include <QtQuick/private/qquickanimation_p_p.h>
-#include <QtPositioning/private/qdoublevector2d_p.h>
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \qmltype CoordinateAnimation
- \instantiates QDeclarativeGeoCoordinateAnimation
- \inherits PropertyAnimation
- \inqmlmodule QtPositioning
- \since 5.3
-
- \brief A PropertyAnimation for geo coordinate properties.
-
- A specialized \l{PropertyAnimation} that defines an animation
- between two geo coordinates.
-*/
-
-QDeclarativeGeoCoordinateAnimation::QDeclarativeGeoCoordinateAnimation(QObject *parent)
- : QQuickPropertyAnimation(parent)
-{
- Q_D(QQuickPropertyAnimation);
- d->interpolatorType = qMetaTypeId<QGeoCoordinate>();
- d->defaultToInterpolatorType = true;
- d->interpolator = QVariantAnimationPrivate::getInterpolator(d->interpolatorType);
-}
-
-QDeclarativeGeoCoordinateAnimation::~QDeclarativeGeoCoordinateAnimation()
-{
-}
-
-/*!
- \qmlproperty coordinate CoordinateAnimation::from
- This property holds the coordinate where the animation should begin.
-*/
-QGeoCoordinate QDeclarativeGeoCoordinateAnimation::from() const
-{
- Q_D(const QQuickPropertyAnimation);
- return d->from.value<QGeoCoordinate>();
-}
-
-void QDeclarativeGeoCoordinateAnimation::setFrom(const QGeoCoordinate &f)
-{
- QQuickPropertyAnimation::setFrom(QVariant::fromValue(f));
-}
-
-/*!
- \qmlproperty coordinate CoordinateAnimation::to
- This property holds the coordinate where the animation should end.
-*/
-QGeoCoordinate QDeclarativeGeoCoordinateAnimation::to() const
-{
- Q_D(const QQuickPropertyAnimation);
- return d->to.value<QGeoCoordinate>();
-}
-
-void QDeclarativeGeoCoordinateAnimation::setTo(const QGeoCoordinate &t)
-{
- QQuickPropertyAnimation::setTo(QVariant::fromValue(t));
-}
-
-QT_END_NAMESPACE
diff --git a/src/imports/positioning/qquickgeocoordinateanimation.cpp b/src/imports/positioning/qquickgeocoordinateanimation.cpp
new file mode 100644
index 00000000..ed66b794
--- /dev/null
+++ b/src/imports/positioning/qquickgeocoordinateanimation.cpp
@@ -0,0 +1,212 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the QtPositioning module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL21$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** As a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qquickgeocoordinateanimation_p.h"
+#include "qquickgeocoordinateanimation_p_p.h"
+#include <QtQuick/private/qquickanimation_p_p.h>
+#include <QtPositioning/private/qdoublevector2d_p.h>
+#include <QtPositioning/private/qgeoprojection_p.h>
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \qmltype CoordinateAnimation
+ \instantiates QQuickGeoCoordinateAnimation
+ \inherits PropertyAnimation
+ \inqmlmodule QtPositioning
+ \since 5.3
+
+ \brief A PropertyAnimation for geo coordinate properties.
+
+ A specialized \l{PropertyAnimation} that defines an animation
+ between two \l{coordinate}{coordinates}.
+
+ By default, a \l{latitude} of the \l{coordinate} is animated in the direction of shortest
+ (geodesic) distance between those coordinates. Since CoordinateAnimation uses Mercator
+ map projection, the \l{latitude} animation is always between -90 and 90 degrees.
+ The \l{longitude} animation path is not limited and can go over 180 degrees
+ in both west and east directions.
+
+ The \l{direction} property can be set to specify the direction in which the \l{longitude}
+ animation should occur.
+
+ \sa {Animation and Transitions in Qt Quick}
+*/
+
+QVariant q_coordinateWestInterpolator(const QGeoCoordinate &from, const QGeoCoordinate &to, qreal progress)
+{
+ QDoubleVector2D fromVector = QGeoProjection::coordToMercator(from);
+ QDoubleVector2D toVector = QGeoProjection::coordToMercator(to);
+
+ double toX = toVector.x();
+ double diff = toVector.x() - fromVector.x();
+
+ while (diff < 0.0) {
+ toX += 1.0;
+ diff += 1.0;
+ }
+
+ double x = fromVector.x() + (toX - fromVector.x()) * progress;
+ double y = fromVector.y() + (toVector.y() - fromVector.y()) * progress;
+
+ while (x > 1.0)
+ x -= 1.0;
+
+ QGeoCoordinate result = QGeoProjection::mercatorToCoord(QDoubleVector2D(x, y));
+ result.setAltitude(from.altitude() + (to.altitude() - from.altitude()) * progress);
+
+ return QVariant::fromValue(result);
+}
+
+QVariant q_coordinateEastInterpolator(const QGeoCoordinate &from, const QGeoCoordinate &to, qreal progress)
+{
+ QDoubleVector2D fromVector = QGeoProjection::coordToMercator(from);
+ QDoubleVector2D toVector = QGeoProjection::coordToMercator(to);
+
+ double toX = toVector.x();
+ double diff = toVector.x() - fromVector.x();
+
+ while (diff > 0.0) {
+ toX -= 1.0;
+ diff -= 1.0;
+ }
+
+ double x = fromVector.x() + (toX - fromVector.x()) * progress;
+ double y = fromVector.y() + (toVector.y() - fromVector.y()) * progress;
+
+ while (x < 0.0)
+ x += 1.0;
+
+ QGeoCoordinate result = QGeoProjection::mercatorToCoord(QDoubleVector2D(x, y));
+ result.setAltitude(from.altitude() + (to.altitude() - from.altitude()) * progress);
+
+ return QVariant::fromValue(result);
+}
+
+QQuickGeoCoordinateAnimation::QQuickGeoCoordinateAnimation(QObject *parent)
+ : QQuickPropertyAnimation(*(new QQuickGeoCoordinateAnimationPrivate), parent)
+
+{
+ Q_D(QQuickGeoCoordinateAnimation);
+ d->interpolatorType = qMetaTypeId<QGeoCoordinate>();
+ d->defaultToInterpolatorType = true;
+ d->interpolator = QVariantAnimationPrivate::getInterpolator(d->interpolatorType);
+}
+
+QQuickGeoCoordinateAnimation::~QQuickGeoCoordinateAnimation()
+{
+}
+
+/*!
+ \qmlproperty coordinate CoordinateAnimation::from
+ This property holds the coordinate where the animation should begin.
+*/
+QGeoCoordinate QQuickGeoCoordinateAnimation::from() const
+{
+ Q_D(const QQuickPropertyAnimation);
+ return d->from.value<QGeoCoordinate>();
+}
+
+void QQuickGeoCoordinateAnimation::setFrom(const QGeoCoordinate &f)
+{
+ QQuickPropertyAnimation::setFrom(QVariant::fromValue(f));
+}
+
+/*!
+ \qmlproperty coordinate CoordinateAnimation::to
+ This property holds the coordinate where the animation should end.
+*/
+QGeoCoordinate QQuickGeoCoordinateAnimation::to() const
+{
+ Q_D(const QQuickGeoCoordinateAnimation);
+ return d->to.value<QGeoCoordinate>();
+}
+
+void QQuickGeoCoordinateAnimation::setTo(const QGeoCoordinate &t)
+{
+ QQuickPropertyAnimation::setTo(QVariant::fromValue(t));
+}
+
+/*!
+ \qmlproperty enumeration CoordinateAnimation::direction
+ This property holds the direction of the \l{longitude} animation of the \l{coordinate}.
+
+ Possible values are:
+
+ \list
+ \li CoordinateAnimation.Shortest (default) - the longitude animation goes in the direction
+ that produces the shortest animation path.
+ \li CoordinateAnimation.West - the longitude animation always goes into western direction
+ and may cross the date line.
+ \li CoordinateAnimation.East - the longitude animation always goes into eastern direction
+ and may cross the date line.
+ \endlist
+ \since 5.5
+*/
+
+
+QQuickGeoCoordinateAnimation::Direction QQuickGeoCoordinateAnimation::direction() const
+{
+ Q_D(const QQuickGeoCoordinateAnimation);
+ return d->m_direction;
+}
+
+void QQuickGeoCoordinateAnimation::setDirection(QQuickGeoCoordinateAnimation::Direction direction)
+{
+ Q_D( QQuickGeoCoordinateAnimation);
+ if (d->m_direction == direction)
+ return;
+
+ d->m_direction = direction;
+ switch (direction) {
+ case West:
+ d->interpolator = reinterpret_cast<QVariantAnimation::Interpolator>(&q_coordinateWestInterpolator);
+ break;
+ case East:
+ d->interpolator = reinterpret_cast<QVariantAnimation::Interpolator>(&q_coordinateEastInterpolator);
+ break;
+ case Shortest:
+ default:
+ d->interpolator = QVariantAnimationPrivate::getInterpolator(d->interpolatorType);
+ break;
+ }
+ emit directionChanged();
+
+}
+
+QQuickGeoCoordinateAnimationPrivate::QQuickGeoCoordinateAnimationPrivate():
+ m_direction(QQuickGeoCoordinateAnimation::Shortest)
+{
+}
+
+QT_END_NAMESPACE
diff --git a/src/imports/positioning/qdeclarativegeocoordinateanimation_p.h b/src/imports/positioning/qquickgeocoordinateanimation_p.h
index 2aafc8f6..8c93a0b0 100644
--- a/src/imports/positioning/qdeclarativegeocoordinateanimation_p.h
+++ b/src/imports/positioning/qquickgeocoordinateanimation_p.h
@@ -31,34 +31,50 @@
**
****************************************************************************/
-#ifndef QDECLARATIVEGEOCOORDINATEANIMATION_P_H
-#define QDECLARATIVEGEOCOORDINATEANIMATION_P_H
+#ifndef QQUICKGEOCOORDINATEANIMATION_P_H
+#define QQUICKGEOCOORDINATEANIMATION_P_H
#include <QtQuick/private/qquickanimation_p.h>
#include <QtPositioning/qgeocoordinate.h>
QT_BEGIN_NAMESPACE
-class QDeclarativeGeoCoordinateAnimation : public QQuickPropertyAnimation
+class QQuickGeoCoordinateAnimationPrivate;
+
+class QQuickGeoCoordinateAnimation : public QQuickPropertyAnimation
{
Q_OBJECT
- Q_DECLARE_PRIVATE(QQuickPropertyAnimation)
+ Q_DECLARE_PRIVATE(QQuickGeoCoordinateAnimation)
Q_PROPERTY(QGeoCoordinate from READ from WRITE setFrom)
Q_PROPERTY(QGeoCoordinate to READ to WRITE setTo)
+ Q_PROPERTY(Direction direction READ direction WRITE setDirection NOTIFY directionChanged)
public:
- QDeclarativeGeoCoordinateAnimation(QObject *parent=0);
- ~QDeclarativeGeoCoordinateAnimation();
+ enum Direction {
+ Shortest,
+ West,
+ East
+ };
+ Q_ENUM(Direction)
+
+ QQuickGeoCoordinateAnimation(QObject *parent=0);
+ ~QQuickGeoCoordinateAnimation();
QGeoCoordinate from() const;
void setFrom(const QGeoCoordinate &);
QGeoCoordinate to() const;
void setTo(const QGeoCoordinate &);
+
+ Direction direction() const;
+ void setDirection(Direction direction);
+
+Q_SIGNALS:
+ void directionChanged();
};
QT_END_NAMESPACE
-QML_DECLARE_TYPE(QDeclarativeGeoCoordinateAnimation)
+QML_DECLARE_TYPE(QQuickGeoCoordinateAnimation)
-#endif // QDECLARATIVEGEOCOORDINATEANIMATION_P_H
+#endif // QQUICKCOORDINATEANIMATION_P_H
diff --git a/src/imports/positioning/qquickgeocoordinateanimation_p_p.h b/src/imports/positioning/qquickgeocoordinateanimation_p_p.h
new file mode 100644
index 00000000..daa59b73
--- /dev/null
+++ b/src/imports/positioning/qquickgeocoordinateanimation_p_p.h
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the QtPositioning module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL21$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** As a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QQUICKGEOCOORDINATEANIMATION_P_P_H
+#define QQUICKGEOCOORDINATEANIMATION_P_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qquickgeocoordinateanimation_p.h"
+#include <QtQuick/private/qquickanimation_p_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QQuickGeoCoordinateAnimationPrivate : public QQuickPropertyAnimationPrivate
+{
+ Q_DECLARE_PUBLIC(QQuickGeoCoordinateAnimation)
+public:
+ QQuickGeoCoordinateAnimationPrivate();
+ QQuickGeoCoordinateAnimation::Direction m_direction;
+};
+
+QT_END_NAMESPACE
+
+#endif // QQUICKGEOCOORDINATEANIMATION_P_P_H