Created MapScroller class using Singleton design pattern
authorSami Rämö <sami.ramo@ixonos.com>
Wed, 16 Jun 2010 09:55:01 +0000 (12:55 +0300)
committerSami Rämö <sami.ramo@ixonos.com>
Wed, 16 Jun 2010 09:55:01 +0000 (12:55 +0300)
src/map/mapengine.cpp
src/map/mapengine.h
src/map/mapscroller.cpp [new file with mode: 0644]
src/map/mapscroller.h [new file with mode: 0644]
src/map/mapview.cpp
src/map/mapview.h
src/src.pro

index 43d252f..12c8e3a 100644 (file)
@@ -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<QString>)),
             this, SIGNAL(locationItemClicked(QList<QString>)));
+
+    m_scroller = &MapScroller::getInstance();
 }
 
 MapEngine::~MapEngine()
index 8ec9b90..02a3f6a 100644 (file)
@@ -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 (file)
index 0000000..9d9c626
--- /dev/null
@@ -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 <QDebug>
+#include <QPointF>
+
+#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 (file)
index 0000000..aef5953
--- /dev/null
@@ -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 <QVariantAnimation>
+
+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
index e112bb2..ee797fe 100644 (file)
@@ -26,6 +26,7 @@
 #include <QMouseEvent>
 
 #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)
index e701a5c..e53c433 100644 (file)
@@ -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
index 32d698b..730282a 100644 (file)
@@ -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