00001 /* 00002 Situare - A location system for Facebook 00003 Copyright (C) 2010 Ixonos Plc. Authors: 00004 00005 Sami Rämö - sami.ramo@ixonos.com 00006 Pekka Nissinen - pekka.nissinen@ixonos.com 00007 00008 Situare is free software; you can redistribute it and/or 00009 modify it under the terms of the GNU General Public License 00010 version 2 as published by the Free Software Foundation. 00011 00012 Situare is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with Situare; if not, write to the Free Software 00019 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 00020 USA. 00021 */ 00022 00023 #ifndef MAPVIEW_H 00024 #define MAPVIEW_H 00025 00026 #include <QGraphicsView> 00027 #include <QTime> 00028 00029 #include "coordinates/scenecoordinate.h" 00030 00031 class QParallelAnimationGroup; 00032 class QPropertyAnimation; 00033 00034 class MapScroller; 00035 00036 #define VALUES 4 00037 00044 class MapView : public QGraphicsView 00045 { 00046 Q_OBJECT 00047 00053 Q_PROPERTY(qreal viewScale READ viewScale WRITE setViewScale) 00054 00055 00060 Q_PROPERTY(qreal viewShift READ viewShift WRITE setViewShift) 00061 00062 public: 00068 MapView(QWidget *parent = 0); 00069 00076 ~MapView(); 00077 00078 /******************************************************************************* 00079 * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS 00080 ******************************************************************************/ 00081 protected: 00087 void resizeEvent(QResizeEvent *event); 00088 00089 private: 00096 void mouseDoubleClickEvent(QMouseEvent *event); 00097 00110 void mouseMoveEvent(QMouseEvent *event); 00111 00120 void mousePressEvent(QMouseEvent *event); 00121 00133 void mouseReleaseEvent(QMouseEvent *event); 00134 00135 /******************************************************************************* 00136 * MEMBER FUNCTIONS AND SLOTS 00137 ******************************************************************************/ 00138 public slots: 00146 void centerToSceneCoordinates(const SceneCoordinate &coordinate); 00147 00153 void setZoomLevel(int zoomLevel); 00154 00155 private slots: 00159 void disableCenterShift(); 00160 00166 void doubleTapZoomFinished(); 00167 00171 void enableCenterShift(); 00172 00173 private: 00181 QPointF center() const; 00182 00188 void setViewScale(qreal viewScale); 00189 00195 void setViewShift(qreal viewShift); 00196 00200 void updateCenterShift(); 00201 00207 qreal viewScale() const; 00208 00214 qreal viewShift() const; 00215 00216 /******************************************************************************* 00217 * SIGNALS 00218 ******************************************************************************/ 00219 signals: 00225 void horizontalShiftingChanged(int shifting); 00226 00233 void viewResized(const QSize &size); 00234 00241 void viewScrolled(const SceneCoordinate &coordinate); 00242 00246 void viewZoomFinished(); 00247 00251 void zoomIn(); 00252 00253 /******************************************************************************* 00254 * DATA MEMBERS 00255 ******************************************************************************/ 00256 private: 00257 bool m_doubleTapZoomRunning; 00258 00259 int m_dragTime[VALUES]; 00260 int m_index; 00261 int m_zoomLevel; 00262 00263 qreal m_centerHorizontalShiftViewPixels; 00264 qreal m_kineticMaxViewDistance; 00265 00266 QParallelAnimationGroup *m_scrollAndZoomAnimation; 00267 00268 QPoint m_dragMovement[VALUES]; 00269 QPoint m_internalScenePosition; 00270 QPoint m_lastMouseEventScenePosition; 00271 QPoint m_lastMouseEventViewPosition; 00272 QPoint m_viewCenterPoint; 00273 00274 QPointF m_centerHorizontalShiftPoint; 00275 00276 QPropertyAnimation *m_zoomAnimation; 00277 00278 QTime m_time; 00279 00280 QPropertyAnimation *m_centerShiftAnimation; 00281 00282 MapScroller *m_scroller; 00283 SceneCoordinate m_lastSetScenePosition; 00284 }; 00285 00286 #endif // MAPVIEW_H