summaryrefslogtreecommitdiff
path: root/src/imports/positioning
diff options
context:
space:
mode:
authorAlbin Olsson <albin.olsson@cybercom.com>2013-09-19 16:17:20 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-10-11 12:18:46 +0200
commit42541b2406f6b35e109ee6bee64283582dfd2adc (patch)
tree96c873be5b39ef46022b72d88c04233578f4457b /src/imports/positioning
parent7ec8919a055e35232b5127e312a525f61b0bc483 (diff)
downloadqtlocation-42541b2406f6b35e109ee6bee64283582dfd2adc.tar.gz
Make geo coordinates animatable in QML.
Interpolation logic in AnimatableCoordinate has been moved around so that QGeoCoordinates can be animated directly by QPropertyAnimation. A new QML type has been added, 'CoordinateAnimation', for animating coordinates in QML. This type follows the pattern of 'ColorAnimation' and other specializations of 'PropertyAnimation'. QDoubleVector2D, QDoubleVector3D and QGeoProjection has been moved to QtPositioning Testcase for CoordinateAnimation has been added to declarative_ui. AnimatableCoordinate and QGeoCoordinateInterpolator are redundant and have been removed. Change-Id: I0809da566e1800274384f9c5337df65623d1e61a Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
Diffstat (limited to 'src/imports/positioning')
-rw-r--r--src/imports/positioning/positioning.cpp4
-rw-r--r--src/imports/positioning/positioning.pro6
-rw-r--r--src/imports/positioning/qdeclarativegeocoordinateanimation.cpp122
-rw-r--r--src/imports/positioning/qdeclarativegeocoordinateanimation_p.h75
4 files changed, 205 insertions, 2 deletions
diff --git a/src/imports/positioning/positioning.cpp b/src/imports/positioning/positioning.cpp
index 031b06b2..b4bda5fd 100644
--- a/src/imports/positioning/positioning.cpp
+++ b/src/imports/positioning/positioning.cpp
@@ -51,6 +51,7 @@
#include "qdeclarativegeorectangle.h"
#include "qdeclarativegeocircle.h"
#include "qdeclarativecoordinate_p.h"
+#include "qdeclarativegeocoordinateanimation_p.h"
#include "locationsingleton.h"
@@ -112,6 +113,9 @@ public:
qRegisterMetaType<QGeoRectangle>("QGeoRectangle");
qRegisterMetaType<QGeoCircle>("QGeoCircle");
qRegisterMetaType<QGeoLocation>("QGeoLocation");
+
+ qRegisterAnimationInterpolator<QGeoCoordinate>(geoCoordinateInterpolator);
+ qmlRegisterType<QDeclarativeGeoCoordinateAnimation>(uri, 5, 3, "CoordinateAnimation");
} else {
qDebug() << "Unsupported URI given to load positioning QML plugin: " << QLatin1String(uri);
}
diff --git a/src/imports/positioning/positioning.pro b/src/imports/positioning/positioning.pro
index 1f71f03c..6af459d8 100644
--- a/src/imports/positioning/positioning.pro
+++ b/src/imports/positioning/positioning.pro
@@ -11,7 +11,8 @@ HEADERS += qdeclarativeposition_p.h \
qdeclarativegeocircle.h \
locationvaluetypeprovider.h \
locationsingleton.h \
- error_messages.h
+ error_messages.h \
+ qdeclarativegeocoordinateanimation_p.h
SOURCES += qdeclarativeposition.cpp \
positioning.cpp \
@@ -22,7 +23,8 @@ SOURCES += qdeclarativeposition.cpp \
qdeclarativegeocircle.cpp \
locationvaluetypeprovider.cpp \
locationsingleton.cpp \
- error_messages.cpp
+ error_messages.cpp \
+ qdeclarativegeocoordinateanimation.cpp
load(qml_plugin)
diff --git a/src/imports/positioning/qdeclarativegeocoordinateanimation.cpp b/src/imports/positioning/qdeclarativegeocoordinateanimation.cpp
new file mode 100644
index 00000000..df4fee1b
--- /dev/null
+++ b/src/imports/positioning/qdeclarativegeocoordinateanimation.cpp
@@ -0,0 +1,122 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtPositioning module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/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 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qdeclarativegeocoordinateanimation_p.h"
+#include <QtQuick/private/qquickanimation_p_p.h>
+#include <QtPositioning/private/qgeoprojection_p.h>
+#include <QtPositioning/private/qdoublevector2d_p.h>
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \qmltype CoordinateAnimation
+ \instantiates QDeclarativeGeoCoordinateAnimation
+
+ \brief A PropertyAnimation for geo coordinate properties.
+
+ \inqmlmodule QtLocation 5.0
+ \ingroup qml-QtLocation5-maps
+
+ 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 bool QtLocation5::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 bool QtLocation5::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));
+}
+
+QVariant geoCoordinateInterpolator(const QGeoCoordinate &from, const QGeoCoordinate &to, qreal progress)
+{
+ if (from == to) {
+ if (progress < 0.5) {
+ return QVariant::fromValue(from);
+ } else {
+ return QVariant::fromValue(to);
+ }
+ }
+
+ QGeoCoordinate result = QGeoProjection::coordinateInterpolation(from, to, progress);
+
+ return QVariant::fromValue(result);
+}
+
+QT_END_NAMESPACE
diff --git a/src/imports/positioning/qdeclarativegeocoordinateanimation_p.h b/src/imports/positioning/qdeclarativegeocoordinateanimation_p.h
new file mode 100644
index 00000000..86a0459a
--- /dev/null
+++ b/src/imports/positioning/qdeclarativegeocoordinateanimation_p.h
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtPositioning module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/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 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QDECLARATIVEGEOCOORDINATEANIMATION_P_H
+#define QDECLARATIVEGEOCOORDINATEANIMATION_P_H
+
+#include <QtQuick/private/qquickanimation_p.h>
+#include "qdeclarativecoordinate_p.h"
+
+QT_BEGIN_NAMESPACE
+
+
+QVariant geoCoordinateInterpolator(const QGeoCoordinate &from, const QGeoCoordinate &to, qreal progress);
+
+class QDeclarativeGeoCoordinateAnimation : public QQuickPropertyAnimation
+{
+ Q_OBJECT
+ Q_DECLARE_PRIVATE(QQuickPropertyAnimation)
+ Q_PROPERTY(QGeoCoordinate from READ from WRITE setFrom)
+ Q_PROPERTY(QGeoCoordinate to READ to WRITE setTo)
+
+public:
+ QDeclarativeGeoCoordinateAnimation(QObject *parent=0);
+ ~QDeclarativeGeoCoordinateAnimation();
+
+ QGeoCoordinate from() const;
+ void setFrom(const QGeoCoordinate &);
+
+ QGeoCoordinate to() const;
+ void setTo(const QGeoCoordinate &);
+};
+
+QT_END_NAMESPACE
+
+QML_DECLARE_TYPE(QDeclarativeGeoCoordinateAnimation)
+
+#endif // QDECLARATIVEGEOCOORDINATEANIMATION_P_H