Added signals and slots for view location updates
authorSami Rämö <sami.ramo@ixonos.com>
Fri, 9 Apr 2010 10:35:04 +0000 (13:35 +0300)
committerSami Rämö <sami.ramo@ixonos.com>
Fri, 9 Apr 2010 10:35:04 +0000 (13:35 +0300)
doc/map/map_class_diagram.dia
src/map/mapengine.cpp
src/map/mapengine.h
src/map/mapview.cpp
src/map/mapview.h
src/ui/mapviewscreen.cpp

index 71985e3..cd035d6 100644 (file)
Binary files a/doc/map/map_class_diagram.dia and b/doc/map/map_class_diagram.dia differ
index 0cb6a85..01641be 100644 (file)
@@ -99,3 +99,8 @@ QGraphicsScene* MapEngine::scene()
 {
     return dynamic_cast<QGraphicsScene *>(m_mapScene);
 }
+
+void MapEngine::setLocation(QPointF sceneCoordinate)
+{
+    emit locationChanged(sceneCoordinate);
+}
index b833981..58fd052 100644 (file)
@@ -139,8 +139,23 @@ private slots:
     */
     void mapImageReceived(const QUrl &url, const QPixmap &pixmap);
 
+    /**
+    * @brief Slot for setting current view location
+    *
+    * Emits locationChanged signal.
+    * @param sceneCoordinate Scene coordinates for new position
+    */
+    void setLocation(QPointF sceneCoordinate);
+
 signals:
     /**
+    * @brief Signal for view location change
+    *
+    * @param sceneCoordinate New scene coordinates
+    */
+    void locationChanged(QPointF sceneCoordinate);
+
+    /**
     * @brief Signal for zoom level change
     *
     * @param newZoomLevel New zoom level
index e936417..1b84e23 100644 (file)
@@ -61,9 +61,6 @@ void MapView::mouseMoveEvent(QMouseEvent *event)
 
     emit viewScrolled(m_scenePosition);
 
-    /// @todo REMOVE AFTER UPDATING ENGINE
-    centerToSceneCoordinates(m_scenePosition);
-
     m_mousePosition = mapToScene(event->pos());
 }
 
@@ -78,11 +75,3 @@ void MapView::centerToSceneCoordinates(QPointF sceneCoordinate)
 {
     centerOn(sceneCoordinate);
 }
-
-//bool MapView::event(QEvent *event)
-//{
-//    qDebug() << __PRETTY_FUNCTION__ << "event type:" << event->type();
-//    event->ignore();
-//    QObject::event(event);
-//    return false;
-//}
index c1c79e1..4531231 100644 (file)
@@ -50,9 +50,9 @@ private slots:
     /**
     * @brief Slot for mouse move events
     *
-    * Does calculate mouse movement delta from last event position and save
-    * current event position for next round. Calls centerToSceneCoordinates
-    * to actually make the dragging.
+    * 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 mouseMoveEvent(QMouseEvent *event);
index 82b89dc..7f99866 100644 (file)
 MapViewScreen::MapViewScreen(QWidget *parent)
    : QWidget(parent)
 {
-   QHBoxLayout *mapViewLayout = new QHBoxLayout;
+
    MapView *mapView = new MapView(this);
-   mapViewLayout->addWidget(mapView);
-   setLayout(mapViewLayout);
    MapEngine *mapEngine = new MapEngine(this);
    mapView->setScene(mapEngine->scene());
+
+   connect(mapView, SIGNAL(viewScrolled(QPointF)), mapEngine, SLOT(setLocation(QPointF)));
+   connect(mapEngine, SIGNAL(locationChanged(QPointF)),
+           mapView, SLOT(centerToSceneCoordinates(QPointF)));
    connect(mapEngine, SIGNAL(zoomLevelChanged(int)), mapView, SLOT(setZoomLevel(int)));
+
+   QHBoxLayout *mapViewLayout = new QHBoxLayout;
+   mapViewLayout->addWidget(mapView);
+   setLayout(mapViewLayout);
+
    mapEngine->setViewLocation(QPointF(25.5000, 65.0000));
 }