Merge branch 'map' of https://vcs.maemo.org/git/situare into map
authorJussi Laitinen <jupe@l3l7588.ixonos.local>
Fri, 9 Apr 2010 10:56:14 +0000 (13:56 +0300)
committerJussi Laitinen <jupe@l3l7588.ixonos.local>
Fri, 9 Apr 2010 10:56:14 +0000 (13:56 +0300)
Conflicts:
src/map/mapengine.cpp
src/ui/mapviewscreen.cpp

1  2 
src/map/mapengine.cpp
src/map/mapengine.h
src/ui/mapviewscreen.cpp

@@@ -114,58 -100,7 +114,61 @@@ QGraphicsScene* MapEngine::scene(
      return dynamic_cast<QGraphicsScene *>(m_mapScene);
  }
  
 -void MapEngine::setLocation(QPointF sceneCoordinate)
 +int MapEngine::tileMaxValue(int zoomLevel)
 +{
 +    return (1 << zoomLevel) - 1;
 +}
 +
 +QRect MapEngine::calculateGrid(QPointF sceneCenterCoordinate)
  {
 -    emit locationChanged(sceneCoordinate);
 +
 +    QPoint tileCenterCoordinate = convertSceneCoordinateToTileNumber(m_zoomLevel, sceneCenterCoordinate);
 +
 +    qDebug() << tileCenterCoordinate.x() - (GRID_WIDTH/2);
 +    int topLeftX = tileCenterCoordinate.x() - (GRID_WIDTH/2);
 +    int topLeftY = tileCenterCoordinate.y() - (GRID_HEIGHT/2);
 +
 +   return QRect(topLeftX, topLeftY, GRID_WIDTH, GRID_HEIGHT);
  }
 +
 +void MapEngine::setLocation(QPointF sceneCenterCoordinate)
 +{
++      emit locationChanged(sceneCoordinate);
++
 +    QRect grid = calculateGrid(sceneCenterCoordinate);
 +    int topLeftX = grid.topLeft().x();
 +    int topLeftY = grid.topLeft().y();
 +    int bottomRightX = grid.bottomRight().x();
 +    int bottomRightY = grid.bottomRight().y();
 +
 +    qDebug() << topLeftX << "," << topLeftY;
 +    qDebug() << bottomRightY << "," << bottomRightX;
 +
 +    int tileMaxVal = tileMaxValue(m_zoomLevel);
 +
 +    for (int x = topLeftX; x <= bottomRightX; ++x) {
 +        for (int y = topLeftY; y <= bottomRightY; ++y) {
 +
 +            int tileX = x;
 +            int tileY = y;
 +
 +            if (tileX < 0)
 +                tileX += tileMaxVal;
 +            else if (tileX > tileMaxVal)
 +                tileX -= tileMaxVal;
 +
 +            if (tileY < 0)
 +                tileY += tileMaxVal;
 +            else if (tileY > tileMaxVal)
 +                tileY -= tileMaxVal;
 +
 +            QUrl url = buildURL(m_zoomLevel, QPoint(tileX, tileY));
 +
 +            qDebug() << url.toString();
 +
 +            if (!mapTilesInScene.contains(url.toString()))
 +                emit fetchImage(buildURL(m_zoomLevel, QPoint(tileX, tileY)));
 +        }
 +    }
 +}
++
Simple merge
  MapViewScreen::MapViewScreen(QWidget *parent)
     : QWidget(parent)
  {
-    QHBoxLayout *mapViewLayout = new QHBoxLayout;
-    MapView *mapView = new MapView(this);
--
-    //DEBUG
-    QVBoxLayout *topAreaLayout = new QVBoxLayout;
-    search = new QPushButton("Show", this);
-    lonLine.setText(QString("25.5400"));
-    latLine.setText(QString("65.0000"));
-    topAreaLayout->addWidget(&lonLine);
-    topAreaLayout->addWidget(&latLine);
-    topAreaLayout->addWidget(search);
-    QWidget *topArea = new QWidget(this);
-    topArea->setLayout(topAreaLayout);
-    mapViewLayout->addWidget(topArea);
-    connect(search, SIGNAL(clicked()), this, SLOT(show()));
-    //DEBUG
-    mapViewLayout->addWidget(mapView);
-    setLayout(mapViewLayout);
-    mapEngine = new MapEngine(this);
 -   MapView *mapView = new MapView(this);
++      MapView *mapView = new MapView(this);
+    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)));
-    show();
- }
  
- void MapViewScreen::show()
- {
-     qreal lon = lonLine.text().toFloat();
-     qreal lat = latLine.text().toFloat();
+    QHBoxLayout *mapViewLayout = new QHBoxLayout;
+    mapViewLayout->addWidget(mapView);
+    setLayout(mapViewLayout);
  
-     mapEngine->setViewLocation(QPointF(lon, lat));
+    mapEngine->setViewLocation(QPointF(25.5000, 65.0000));
  }