From a40fd4b4f9cd750c6a5d8459317b0d9d544b5efe Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sami=20R=C3=A4m=C3=B6?= Date: Wed, 16 Jun 2010 12:55:01 +0300 Subject: [PATCH] Created MapScroller class using Singleton design pattern --- src/map/mapengine.cpp | 3 +++ src/map/mapengine.h | 2 ++ src/map/mapscroller.cpp | 41 +++++++++++++++++++++++++++++++++++++ src/map/mapscroller.h | 51 +++++++++++++++++++++++++++++++++++++++++++++++ src/map/mapview.cpp | 8 ++++++++ src/map/mapview.h | 4 ++++ src/src.pro | 6 ++++-- 7 files changed, 113 insertions(+), 2 deletions(-) create mode 100644 src/map/mapscroller.cpp create mode 100644 src/map/mapscroller.h diff --git a/src/map/mapengine.cpp b/src/map/mapengine.cpp index 43d252f..12c8e3a 100644 --- a/src/map/mapengine.cpp +++ b/src/map/mapengine.cpp @@ -37,6 +37,7 @@ #include "mapcommon.h" #include "mapfetcher.h" #include "mapscene.h" +#include "mapscroller.h" #include "maptile.h" #include "network/networkaccessmanager.h" #include "ownlocationitem.h" @@ -85,6 +86,8 @@ MapEngine::MapEngine(QObject *parent) connect(m_friendItemsHandler, SIGNAL(locationItemClicked(QList)), this, SIGNAL(locationItemClicked(QList))); + + m_scroller = &MapScroller::getInstance(); } MapEngine::~MapEngine() diff --git a/src/map/mapengine.h b/src/map/mapengine.h index 8ec9b90..02a3f6a 100644 --- a/src/map/mapengine.h +++ b/src/map/mapengine.h @@ -33,6 +33,7 @@ class FriendItemsHandler; class GPSLocationItem; class MapFetcher; class MapScene; +class MapScroller; class MapTile; class OwnLocationItem; class User; @@ -445,6 +446,7 @@ private: GPSLocationItem *m_gpsLocationItem; ///< Item pointing current location from GPS MapFetcher *m_mapFetcher; ///< Fetcher for map tiles MapScene *m_mapScene; ///< Scene for map tiles + MapScroller *m_scroller; OwnLocationItem *m_ownLocation; ///< Item to show own location }; diff --git a/src/map/mapscroller.cpp b/src/map/mapscroller.cpp new file mode 100644 index 0000000..9d9c626 --- /dev/null +++ b/src/map/mapscroller.cpp @@ -0,0 +1,41 @@ +/* + Situare - A location system for Facebook + Copyright (C) 2010 Ixonos Plc. Authors: + + Sami Rämö - sami.ramo@ixonos.com + + Situare is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + version 2 as published by the Free Software Foundation. + + Situare is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Situare; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#include +#include + +#include "mapscroller.h" + +MapScroller::MapScroller() +{ + setEasingCurve(QEasingCurve::OutCubic); +} + +MapScroller& MapScroller::getInstance() +{ + static MapScroller instance; + return instance; +} + +void MapScroller::updateCurrentValue(const QVariant &value) +{ + qWarning() << __PRETTY_FUNCTION__ << value.toPointF().x() << value.toPointF().y(); +} diff --git a/src/map/mapscroller.h b/src/map/mapscroller.h new file mode 100644 index 0000000..aef5953 --- /dev/null +++ b/src/map/mapscroller.h @@ -0,0 +1,51 @@ +/* + Situare - A location system for Facebook + Copyright (C) 2010 Ixonos Plc. Authors: + + Sami Rämö - sami.ramo@ixonos.com + + Situare is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + version 2 as published by the Free Software Foundation. + + Situare is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Situare; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + + +#ifndef MAPSCROLLER_H +#define MAPSCROLLER_H + +#include + +class MapScroller : public QVariantAnimation +{ + Q_OBJECT + +private: + /// @todo remove default constructor after caller does set easing curve + MapScroller(); // {} + ~MapScroller() {} + MapScroller(const MapScroller &); // intentionally undefined + MapScroller & operator=(const MapScroller &); // intentionally undefined + +private: + void updateCurrentValue(const QVariant &value); + +public: + static MapScroller &getInstance(); + +signals: + +public slots: + +}; + +#endif // MAPSCROLLER_H diff --git a/src/map/mapview.cpp b/src/map/mapview.cpp index e112bb2..ee797fe 100644 --- a/src/map/mapview.cpp +++ b/src/map/mapview.cpp @@ -26,6 +26,7 @@ #include #include "mapcommon.h" +#include "mapscroller.h" #include "mapview.h" MapView::MapView(QWidget *parent) @@ -41,6 +42,8 @@ MapView::MapView(QWidget *parent) this, SIGNAL(viewZoomFinished())); setOptimizationFlag(QGraphicsView::DontAdjustForAntialiasing); + + m_scroller = &MapScroller::getInstance(); } void MapView::centerToSceneCoordinates(QPoint sceneCoordinate) @@ -74,6 +77,11 @@ void MapView::mousePressEvent(QMouseEvent *event) void MapView::mouseReleaseEvent(QMouseEvent *event) { QGraphicsView::mouseReleaseEvent(event); + + m_scroller->setStartValue(m_scenePosition); + m_scroller->setEndValue(m_scenePosition + m_scenePosition); + m_scroller->setDuration(1000); + m_scroller->start(); } void MapView::resizeEvent(QResizeEvent *event) diff --git a/src/map/mapview.h b/src/map/mapview.h index e701a5c..e53c433 100644 --- a/src/map/mapview.h +++ b/src/map/mapview.h @@ -27,6 +27,8 @@ class QPropertyAnimation; +class MapScroller; + /** * @brief Map view widget * @@ -149,6 +151,8 @@ private: QPointF m_mousePosition; ///< Previous mouse event position QPointF m_scenePosition; ///< New center position QPropertyAnimation *m_zoomAnimation; ///< Zoom animation + + MapScroller *m_scroller; }; #endif // MAPVIEW_H diff --git a/src/src.pro b/src/src.pro index 32d698b..730282a 100644 --- a/src/src.pro +++ b/src/src.pro @@ -50,7 +50,8 @@ SOURCES += main.cpp \ ui/userinfopanel.cpp \ ui/zoombutton.cpp \ ui/zoombuttonpanel.cpp \ - user/user.cpp + user/user.cpp \ + map/mapscroller.cpp HEADERS += common.h \ engine/engine.h \ facebookservice/facebookauthentication.h \ @@ -98,7 +99,8 @@ HEADERS += common.h \ ui/sidepanelbase.h \ ui/zoombutton.h \ ui/zoombuttonpanel.h \ - user/user.h + user/user.h \ + map/mapscroller.h QT += network \ webkit DEFINES += QT_NO_DEBUG_OUTPUT -- 1.7.9.5