Merge branch 'master' into indicator
authorKatri Kaikkonen <katri.kaikkonen@ixonos.com>
Mon, 2 Aug 2010 13:46:46 +0000 (16:46 +0300)
committerKatri Kaikkonen <katri.kaikkonen@ixonos.com>
Mon, 2 Aug 2010 13:46:46 +0000 (16:46 +0300)
Conflicts:
src/map/mapengine.cpp
src/ui/indicatorbutton.cpp
src/ui/mainwindow.cpp

13 files changed:
1  2 
src/coordinates/geocoordinate.cpp
src/engine/engine.cpp
src/engine/engine.h
src/map/mapcommon.h
src/map/mapengine.cpp
src/map/mapengine.h
src/map/mapscene.cpp
src/map/mapscene.h
src/src.pro
src/ui/indicatorbutton.cpp
src/ui/indicatorbutton.h
src/ui/mainwindow.cpp
src/ui/mainwindow.h

Simple merge
Simple merge
Simple merge
Simple merge
@@@ -177,31 -176,6 +177,20 @@@ QPoint MapEngine::convertSceneCoordinat
      return QPoint(x, y);
  }
  
- SceneCoordinate MapEngine::convertTileNumberToSceneCoordinate(int zoomLevel, QPoint tileNumber)
- {
-     qDebug() << __PRETTY_FUNCTION__;
-     int pow = 1 << (OSM_MAX_ZOOM_LEVEL - zoomLevel);
-     int x = tileNumber.x() * OSM_TILE_SIZE_X * pow;
-     int y = tileNumber.y() * OSM_TILE_SIZE_Y * pow;
-     return SceneCoordinate(x, y);
- }
 +QRectF MapEngine::currentViewSceneRect() const
 +{
 +    qDebug() << __PRETTY_FUNCTION__;
 +
 +    const QPoint ONE_PIXEL = QPoint(1, 1);
 +
 +    QGraphicsView *view = m_mapScene->views().at(0);
 +    QPointF sceneTopLeft = view->mapToScene(0, 0);
 +    QPoint viewBottomRight = QPoint(view->size().width(), view->size().height()) - ONE_PIXEL;
 +    QPointF sceneBottomRight = view->mapToScene(viewBottomRight);
 +
 +    return QRectF(sceneTopLeft, sceneBottomRight);
 +}
 +
  void MapEngine::disableAutoCenteringIfRequired(SceneCoordinate coordinate)
  {
      if (isAutoCenteringEnabled()) {
@@@ -259,36 -233,22 +248,24 @@@ void MapEngine::gpsPositionUpdate(GeoCo
  {
      qDebug() << __PRETTY_FUNCTION__;
  
-     m_gpsLocationItem->updatePosition(SceneCoordinate(position), accuracy);
-     m_gpsPosition = position;
-     m_mapScene->spanItems(currentViewSceneRect());
+     // update GPS location item (but only if accuracy is a valid number)
+     if (!isnan(accuracy)) {
+         qreal resolution = MapScene::horizontalResolutionAtLatitude(position.latitude());
+         m_gpsLocationItem->updateItem(SceneCoordinate(position).toPointF(), accuracy, resolution);
+     }
  
 -    m_mapScene->spanItems(m_zoomLevel, m_sceneCoordinate, m_viewSize);
++m_mapScene->spanItems(currentViewSceneRect());
+     // do automatic centering (if enabled)
      if (m_autoCenteringEnabled) {
          m_lastAutomaticPosition = SceneCoordinate(position);
          m_scrollStartedByGps = true;
          scrollToPosition(m_lastAutomaticPosition);
      }
 +
 +    updateDirectionIndicator();
  }
  
- qreal MapEngine::greatCircleDistance(GeoCoordinate firstLocation, GeoCoordinate secondLocation)
- {
-     qDebug() << __PRETTY_FUNCTION__;
-     const qreal TO_RAD = (M_PI / 180);
-     qreal dLat = (secondLocation.latitude() - firstLocation.latitude()) * TO_RAD;
-     qreal dLon = (secondLocation.longitude() - firstLocation.longitude()) * TO_RAD;
-     qreal a = pow(sin(dLat / 2), 2)
-               + cos(firstLocation.latitude() * TO_RAD)
-                 * cos(secondLocation.latitude() * TO_RAD)
-                 * pow(sin(dLon / 2), 2);
-     qreal c = 2 * atan2(sqrt(a), sqrt(1 - a));
-     return (EARTH_RADIUS * c);
- }
  void MapEngine::init()
  {
      qDebug() << __PRETTY_FUNCTION__;
@@@ -464,10 -413,8 +430,10 @@@ void MapEngine::setCenterPosition(Scene
          m_mapScene->removeOutOfViewTiles(m_viewTilesGrid, m_zoomLevel);
      }
  
 -    m_mapScene->spanItems(m_zoomLevel, m_sceneCoordinate, m_viewSize);
 +    m_mapScene->spanItems(currentViewSceneRect());
-     emit newMapResolution(sceneResolution());
+     emit newMapResolution(viewResolution());
 +
 +    updateDirectionIndicator();
  }
  
  void MapEngine::setGPSEnabled(bool enabled)
@@@ -538,48 -485,6 +504,24 @@@ void MapEngine::setTilesGridSize(const 
      m_tilesGridSize.setWidth(gridWidth);
  }
  
- int MapEngine::tileMaxIndex(int zoomLevel)
- {
-     qDebug() << __PRETTY_FUNCTION__;
-     // subtract one because first tile index is zero
-     return tilesPerSide(zoomLevel) - 1;
- }
- QString MapEngine::tilePath(int zoomLevel, int x, int y)
- {
-     qDebug() << __PRETTY_FUNCTION__;
-     QString tilePathString(QString::number(zoomLevel) + "/");
-     tilePathString.append(QString::number(x) + "/");
-     tilePathString.append(QString::number(y));
-     return tilePathString;
- }
- int MapEngine::tilesPerSide(int zoomLevel)
- {
-     return (1 << zoomLevel);
- }
 +void MapEngine::updateDirectionIndicator()
 +{
 +    qDebug() << __PRETTY_FUNCTION__;
 +
 +    /// @todo implement distance calculation
 +    qreal distance = greatCircleDistance(m_gpsPosition, m_sceneCoordinate);
 +
 +    qreal direction = m_sceneCoordinate.azimuthTo(SceneCoordinate(m_gpsPosition));
 +
 +    // direction indicator triangle should be drawn only if the gps location item is not currently
 +    // visible on the view
 +    bool drawDirectionIndicatorTriangle = true;
 +    if (currentViewSceneRect().contains(m_gpsLocationItem->pos()))
 +        drawDirectionIndicatorTriangle = false;
 +
 +    emit directionIndicatorValuesUpdate(direction, distance, drawDirectionIndicatorTriangle);
 +}
 +
  void MapEngine::updateViewTilesSceneRect()
  {
      qDebug() << __PRETTY_FUNCTION__;
@@@ -639,8 -551,8 +590,8 @@@ void MapEngine::zoomed(
      m_mapScene->setZoomLevel(m_zoomLevel);
      getTiles(m_sceneCoordinate);
      m_mapScene->setSceneVerticalOverlap(m_viewSize.height(), m_zoomLevel);
 -    m_mapScene->spanItems(m_zoomLevel, m_sceneCoordinate, m_viewSize);
 +    m_mapScene->spanItems(currentViewSceneRect());
-     emit newMapResolution(sceneResolution());
+     emit newMapResolution(viewResolution());
  }
  
  void MapEngine::zoomIn()
Simple merge
@@@ -146,9 -163,11 +163,11 @@@ void MapScene::removeOutOfViewTiles(QRe
  
      // if view is near east limit of the map, then there is duplicate tiles also on the opposite
      // side of the world which are removed from allTiles
-     if (tilesGrid.right() > (MapEngine::tileMaxIndex(zoomLevel) - tilesGridWidthHalf + MAP_GRID_PADDING)) {
+     if (tilesGrid.right() > ((MapTile::lastTileIndex(zoomLevel)
+                               - tilesGridWidthHalf
+                               + MAP_GRID_PADDING))) {
          QRect oppositeRect = m_tilesSceneRect;
 -        oppositeRect.translate(-OMS_MAP_PIXELS_X, 0);
 +        oppositeRect.translate(-OSM_MAP_PIXELS_X, 0);
          QList<QGraphicsItem *> oppositeItems = items(oppositeRect, Qt::IntersectsItemBoundingRect);
          foreach (QGraphicsItem *item, oppositeItems)
              allItems.removeOne(item);
Simple merge
diff --cc src/src.pro
Simple merge
@@@ -43,27 -41,23 +43,27 @@@ const qreal M_TO_KM = 1000
  
  IndicatorButton::IndicatorButton(QWidget *parent)
      : QToolButton(parent),
 -      m_isDraggable(false)
 +      m_drawTriangle(false),
 +//      m_isDraggable(false),
 +      m_direction(0),
 +      m_distance(0),
 +      m_distanceText("")
  {
-     m_indicatorLeds[OFF].load(":res/images/led_red.png");
-     m_indicatorLeds[ON].load(":res/images/led_red_s.png");
+     m_indicatorLeds[OFF].load(":res/images/gps_position.png");
+     m_indicatorLeds[ON].load(":res/images/gps_position_s.png");
      setFixedSize(BUTTON_WIDTH, BUTTON_HEIGHT);
  
 -    QSettings settings(DIRECTORY_NAME, FILE_NAME);
 -    QPoint savedLocation = settings.value(DIRECTION_INDICATOR_BUTTON_POSITION,
 -                                          QPoint(DIRECTION_INDICATOR_POSITION_X,
 -                                                 DIRECTION_INDICATOR_POSITION_Y)).toPoint();
 +//    QSettings settings(DIRECTORY_NAME, FILE_NAME);
 +//    QPoint savedLocation = settings.value(DIRECTION_INDICATOR_BUTTON_POSITION,
 +//                                          QPoint(DIRECTION_INDICATOR_POSITION_X,
 +//                                                 DIRECTION_INDICATOR_POSITION_Y)).toPoint();
  
 -    if(savedLocation.x() > DEFAULT_SCREEN_WIDTH || savedLocation.y() > DEFAULT_SCREEN_HEIGHT) {
 -        savedLocation.rx() = DIRECTION_INDICATOR_POSITION_X;
 -        savedLocation.ry() = DIRECTION_INDICATOR_POSITION_Y;
 -    }
 +//    if(savedLocation.x() > DEFAULT_SCREEN_WIDTH || savedLocation.y() > DEFAULT_SCREEN_HEIGHT) {
 +//        savedLocation.rx() = DIRECTION_INDICATOR_POSITION_X;
 +//        savedLocation.ry() = DIRECTION_INDICATOR_POSITION_Y;
 +//    }
  
 -    move(savedLocation);
 +//    move(savedLocation);
  
      // Normal background
      m_normalColor = new QColor(Qt::black);
@@@ -181,17 -168,18 +181,18 @@@ void IndicatorButton::mouseReleaseEvent
  
  void IndicatorButton::setDraggable(bool mode, QPoint eventPosition)
  {
 -    qDebug() << __PRETTY_FUNCTION__;
 -
 -    m_isDraggable = mode;
 -
 -    if(mode) {
 -        emit draggingModeTriggered();
 -        m_forceReleaseTimer->start();
 -        m_dragPosition = eventPosition;
 -    } else {
 -        m_forceReleaseTimer->stop();
 -    }
 -    update();
 +//    qDebug() << __PRETTY_FUNCTION__;
 +
 +//    m_isDraggable = mode;
 +
 +//    if(mode) {
++//        emit draggingModeTriggered();
 +//        m_forceReleaseTimer->start();
 +//        m_dragPosition = eventPosition;
 +//    } else {
 +//        m_forceReleaseTimer->stop();
 +//    }
 +//    update();
  }
  
  void IndicatorButton::screenResized(const QSize &newSize)
Simple merge
@@@ -183,16 -181,16 +183,19 @@@ void MainWindow::buildIndicatorButtonPa
  {
      qDebug() << __PRETTY_FUNCTION__;
  
 -    m_indicatorButton = new IndicatorButton(this);
 +    m_indicatorButtonPanel = new IndicatorButtonPanel(this);
  
 -    connect(m_indicatorButton, SIGNAL(autoCenteringTriggered(bool)),
 -        this, SIGNAL(autoCenteringTriggered(bool)));
 +//    connect(m_indicatorButton, SIGNAL(autoCenteringTriggered(bool)),
 +//        this, SIGNAL(autoCenteringTriggered(bool)));
  
 -    connect(m_mapView, SIGNAL(viewResized(QSize)),
 -            m_indicatorButton, SLOT(screenResized(QSize)));
 +//    connect(m_mapView, SIGNAL(viewResized(QSize)),
 +//            m_indicatorButton, SLOT(screenResized(QSize)));
  
 -    connect(m_indicatorButton, SIGNAL(draggingModeTriggered()),
 -            this, SIGNAL(draggingModeTriggered()));
 +//    connect(this, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)),
 +//            m_indicatorButton, SLOT(updateValues(qreal, qreal, bool)));
++
++//    connect(m_indicatorButton, SIGNAL(draggingModeTriggered()),
++//            this, SIGNAL(draggingModeTriggered()));
  }
  
  void MainWindow::buildInformationBox(const QString &message, bool modal)
Simple merge