Copyright (C) 2010 Ixonos Plc. Authors:
Sami Rämö - sami.ramo@ixonos.com
+ Pekka Nissinen - pekka.nissinen@ixonos.com
Situare is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
#define MAPVIEW_H
#include <QGraphicsView>
+#include <QPropertyAnimation>
/**
* @brief Map view widget
*
* @author Sami Rämö - sami.ramo (at) ixonos.com
+* @author Pekka Nissinen - pekka.nissinen (at) ixonos.com
*/
class MapView : public QGraphicsView
{
Q_OBJECT
+
+ /**
+ * @brief View scaling
+ *
+ * @property viewScale
+ */
+ Q_PROPERTY(qreal viewScale READ viewScale WRITE setViewScale)
+
public:
/**
* @brief Constructor
*/
MapView(QWidget *parent = 0);
-private:
- //
+/*******************************************************************************
+ * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
+ ******************************************************************************/
+protected:
/**
- * @brief get current horizontal scale (vertical should be same)
+ * @brief Called when view is resized.
*
- * @return qreal Current horizontal scale value
+ * @param event resize event
*/
- qreal currentScale();
+ void resizeEvent(QResizeEvent *event);
-signals:
+private:
/**
- * @brief Signal for view scroll events
+ * @brief Event handler for mouse move events
*
- * Signal is emitted when view scroll is requested with mouse (or finger).
- * @param sceneCoordinate Scene coordinates of the new requested center point of the view
+ * Does calculate mouse movement delta from last event position and new view center
+ * based on that delta. Saves current event position for next round. Emits viewScrolled
+ * signal and doesn't actually scroll the view.
+ * @param event Mouse event
*/
- void viewScrolled(QPointF sceneCoordinate);
+ void mouseMoveEvent(QMouseEvent *event);
- void viewResized(const QSize &size);
+ /**
+ * @brief Event handler for mouse press events
+ *
+ * Saves inial values for mouse and scene location for dragging view.
+ * @param event Mouse event
+ */
+ void mousePressEvent(QMouseEvent *event);
+/*******************************************************************************
+ * MEMBER FUNCTIONS AND SLOTS
+ ******************************************************************************/
public slots:
/**
* @brief Slot for centering view to new location
*
* @param sceneCoordinate Scene coordinates of the new center point
*/
- void centerToSceneCoordinates(QPointF sceneCoordinate);
+ void centerToSceneCoordinates(QPoint sceneCoordinate);
/**
* @brief Set zoom level of the view
*/
void setZoomLevel(int zoomLevel);
-protected:
- void resizeEvent(QResizeEvent *event);
+ /**
+ * @brief updates view ports content
+ */
+ void updateViewPortContent();
-private slots:
/**
- * @brief Slot for mouse move events
+ * @brief Slot for catching request to get view port contents.
+ * implementation of this slot sends signal that includes visble area of view port.
+ */
+ QRect viewportContent();
+
+private:
+ /**
+ * @brief Set new view scale
*
- * Does calculate mouse movement delta from last event position and new view center
- * based on that delta. Saves current event position for next round. Emits viewScrolled
- * signal and doesn't actually scroll the view.
- * @param event Mouse event
+ * @param viewScale New scaling factor
*/
- void mouseMoveEvent(QMouseEvent *event);
+ void setViewScale(qreal viewScale);
/**
- * @brief Slot for mouse press events
+ * @brief Get current view scale
*
- * Saves inial values for mouse and scene location for dragging view.
- * @param event Mouse event
+ * @return Current view scaling factor
*/
- void mousePressEvent(QMouseEvent *event);
+ qreal viewScale();
+
+/*******************************************************************************
+ * SIGNALS
+ ******************************************************************************/
+signals:
+ /**
+ * @brief Signal for view resize events.
+ *
+ * Signal is emitted when view has been resized.
+ * @param size view size
+ */
+ void viewResized(const QSize &size);
+
+ /**
+ * @brief Signal for view scroll events
+ *
+ * Signal is emitted when view is scrolled.
+ * @param sceneCoordinate Scene coordinates of the new center point of the view
+ */
+ void viewScrolled(QPoint sceneCoordinate);
+
+ /**
+ * @brief Signal for informing that zooming animation is finished
+ */
+ void viewZoomFinished();
+
+ /**
+ * @brief Signal for updating view content
+ *
+ * Signal is emitted when view content needs an update.
+ * @param viewTopLeft Scene coordinate of the viewport top left corner
+ */
+ void viewContentChanged(QPoint viewTopLeft);
+
+ /**
+ * @brief Signal that sends visible area of map scene
+ *
+ * @param viewArea visible area of map scene
+ */
+ void updateViewContent(QRect viewArea);
/**
- * @brief Timer events for smooth zoom effect
+ * @brief Signal for drawing OSM license
*
- * @param event
+ * Signal is emitted when view is resized.
+ * @param width Viewport width
+ * @param height Viewport height
*/
- void timerEvent(QTimerEvent *event);
+ void viewResizedNewSize(int width, int height);
+/*******************************************************************************
+ * DATA MEMBERS
+ ******************************************************************************/
private:
- QPointF m_mousePosition; ///< Previous mouse event position
- QPointF m_scenePosition; ///< New center position
- qreal m_zoomTargetScale; ///< Scaling factor of the target zoom level
- qreal m_zoomScaleDelta; ///< Scaling factor delta for smooth zoom transition effect
+ QPoint m_mousePosition; ///< Previous mouse event position
+ QPoint m_scenePosition; ///< New center position
+ QPropertyAnimation *m_zoomAnimation; ///< Zoom animation
};
#endif // MAPVIEW_H