void QGeoTiledMapDataNokia::evaluateCopyrights(const QSet<QGeoTileSpec> &visibleTiles)
{
    const int copyrightsMargin = 10;
    const int spaceToLogo = 4;
    const int blurRate = 1;
    const int fontSize = 10;

    QGeoTiledMappingManagerEngineNokia *engineNokia = static_cast<QGeoTiledMappingManagerEngineNokia *>(engine());
    const QString copyrightsString = engineNokia->evaluateCopyrightsText(activeMapType(), mapController()->zoom(), visibleTiles);

    if (width() > 0 && height() > 0 && ((copyrightsString.isNull() && copyrightsSlab.isNull()) || copyrightsString != lastCopyrightsString)) {
        QFont font("Sans Serif");
        font.setPixelSize(fontSize);
        font.setStyleHint(QFont::SansSerif);
        font.setWeight(QFont::Bold);

        QRect textBounds = QFontMetrics(font).boundingRect(0, 0, width(), height(), Qt::AlignBottom | Qt::AlignLeft | Qt::TextWordWrap, copyrightsString);

        copyrightsSlab = QImage(logo.width() + textBounds.width() + spaceToLogo + blurRate * 2,
                                qMax(logo.height(), textBounds.height() + blurRate * 2),
                                QImage::Format_ARGB32_Premultiplied);
        copyrightsSlab.fill(Qt::transparent);

        QPainter painter(&copyrightsSlab);
        painter.drawImage(QPoint(0, copyrightsSlab.height() - logo.height()), logo);
        painter.setFont(font);
        painter.setPen(QColor(0, 0, 0, 64));
        painter.translate(spaceToLogo + logo.width(), -blurRate);
        for (int x=-blurRate; x<=blurRate; ++x) {
            for (int y=-blurRate; y<=blurRate; ++y) {
                painter.drawText(x, y, textBounds.width(), copyrightsSlab.height(),
                                 Qt::AlignBottom | Qt::AlignLeft | Qt::TextWordWrap,
                                 copyrightsString);
            }
        }
        painter.setPen(Qt::white);
        painter.drawText(0, 0, textBounds.width(), copyrightsSlab.height(),
                         Qt::AlignBottom | Qt::AlignLeft | Qt::TextWordWrap,
                         copyrightsString);
        painter.end();

        QPoint copyrightsPos(copyrightsMargin, height() - (copyrightsSlab.height() + copyrightsMargin));
        lastCopyrightsPos = copyrightsPos;
        emit copyrightsChanged(copyrightsSlab, copyrightsPos);

        lastCopyrightsString = copyrightsString;
    }

    QPoint copyrightsPos(copyrightsMargin, height() - (copyrightsSlab.height() + copyrightsMargin));
    if (copyrightsPos != lastCopyrightsPos) {
        lastCopyrightsPos = copyrightsPos;
        emit copyrightsChanged(copyrightsSlab, copyrightsPos);
    }
}
Example #2
0
void QGeoTiledMapOsm::onProviderDataUpdated(const QGeoTileProviderOsm *provider)
{
    if (!provider->isResolved() || provider->mapType().mapId() != m_mapId)
        return;
    QString copyRights;
    const QString mapCopy = provider->mapCopyRight();
    const QString dataCopy = provider->dataCopyRight();
    const QString styleCopy = provider->styleCopyRight();
    if (!mapCopy.isEmpty()) {
        copyRights += QStringLiteral("Map &copy; ");
        copyRights += mapCopy;
    }
    if (!dataCopy.isEmpty()) {
        if (!copyRights.isEmpty())
            copyRights += QStringLiteral("<br/>");
        copyRights += QStringLiteral("Data &copy; ");
        copyRights += dataCopy;
    }
    if (!styleCopy.isEmpty()) {
        if (!copyRights.isEmpty())
            copyRights += QStringLiteral("<br/>");
        copyRights += QStringLiteral("Style &copy; ");
        copyRights += styleCopy;
    }

    if (copyRights.isEmpty() && provider->mapType().style() == QGeoMapType::CustomMap)
        copyRights = m_engine->customCopyright();

    emit copyrightsChanged(copyRights);
}
/*!
    \internal
*/
void QDeclarativeGeoMap::onMapChildrenChanged()
{
    if (!m_componentCompleted || !m_mappingManagerInitialized)
        return;

    int maxChildZ = 0;
    QObjectList kids = children();
    bool foundCopyrights = false;

    for (int i = 0; i < kids.size(); ++i) {
        QDeclarativeGeoMapCopyrightNotice *copyrights = qobject_cast<QDeclarativeGeoMapCopyrightNotice *>(kids.at(i));
        if (copyrights) {
            foundCopyrights = true;
        } else {
            QDeclarativeGeoMapItemBase *mapItem = qobject_cast<QDeclarativeGeoMapItemBase *>(kids.at(i));
            if (mapItem) {
                if (mapItem->z() > maxChildZ)
                    maxChildZ = mapItem->z();
            }
        }
    }

    QDeclarativeGeoMapCopyrightNotice *copyrights = m_copyrights.data();
    // if copyrights object not found within the map's children
    if (!foundCopyrights) {
        // if copyrights object was deleted!
        if (!copyrights) {
            // create a new one and set its parent, re-assign it to the weak pointer, then connect the copyrights-change signal
            m_copyrights = new QDeclarativeGeoMapCopyrightNotice(this);
            copyrights = m_copyrights.data();
            connect(m_map, SIGNAL(copyrightsChanged(QImage)),
                    copyrights, SLOT(copyrightsChanged(QImage)));
            connect(m_map, SIGNAL(copyrightsChanged(QString)),
                    copyrights, SLOT(copyrightsChanged(QString)));
            connect(copyrights, SIGNAL(linkActivated(QString)),
                    this, SIGNAL(copyrightLinkActivated(QString)));
        } else {
            // just re-set its parent.
            copyrights->setParent(this);
        }
    }

    // put the copyrights notice object at the highest z order
    copyrights->setCopyrightsZ(maxChildZ + 1);
}
void QGeoTiledMapKokudo::evaluateCopyrights(const QSet<QGeoTileSpec> &visibleTiles)
{
    if (visibleTiles.isEmpty())
        return;

    QGeoTileSpec tile = *visibleTiles.constBegin();
    if (tile.mapId() == m_mapId)
        return;

    m_mapId = tile.mapId();

    QString copyrights = tr("<a href='http://www.gsi.go.jp/kikakuchousei/kikakuchousei40182.html'>国土地理院</a>");

    emit copyrightsChanged(copyrights);
}
/*!
    \internal
    this function will only be ever called once
*/
void QDeclarativeGeoMap::mappingManagerInitialized()
{
    m_mappingManagerInitialized = true;

    m_map = m_mappingManager->createMap(this);
    m_gestureArea->setMap(m_map);

    // once mappingManagerInitilized_ is set zoomLevel() returns the default initialised
    // zoom level of the map controller. Overwrite it here to whatever the user chose.
    m_map->mapController()->setZoom(m_zoomLevel);

    //The zoom level limits are only restricted by the plugins values, if the user has set a more
    //strict zoom level limit before initialization nothing is done here.
    if (m_mappingManager->cameraCapabilities().minimumZoomLevel() > m_gestureArea->minimumZoomLevel())
        setMinimumZoomLevel(m_mappingManager->cameraCapabilities().minimumZoomLevel());

    if (m_gestureArea->maximumZoomLevel() < 0
            || m_mappingManager->cameraCapabilities().maximumZoomLevel() < m_gestureArea->maximumZoomLevel())
        setMaximumZoomLevel(m_mappingManager->cameraCapabilities().maximumZoomLevel());

    m_map->setActiveMapType(QGeoMapType());

    m_copyrights = new QDeclarativeGeoMapCopyrightNotice(this);
    connect(m_map, SIGNAL(copyrightsChanged(QImage)),
            m_copyrights.data(), SLOT(copyrightsChanged(QImage)));
    connect(m_map, SIGNAL(copyrightsChanged(QString)),
            m_copyrights.data(), SLOT(copyrightsChanged(QString)));
    connect(m_copyrights.data(), SIGNAL(linkActivated(QString)),
            this, SIGNAL(copyrightLinkActivated(QString)));

    connect(m_map,
            SIGNAL(updateRequired()),
            this,
            SLOT(update()));
    connect(m_map->mapController(),
            SIGNAL(centerChanged(QGeoCoordinate)),
            this,
            SLOT(mapCenterChanged(QGeoCoordinate)));
    connect(m_map->mapController(),
            SIGNAL(zoomChanged(qreal)),
            this,
            SLOT(mapZoomLevelChanged(qreal)));

    m_map->mapController()->setCenter(m_center);

    QList<QGeoMapType> types = m_mappingManager->supportedMapTypes();
    for (int i = 0; i < types.size(); ++i) {
        QDeclarativeGeoMapType *type = new QDeclarativeGeoMapType(types[i], this);
        m_supportedMapTypes.append(type);
    }

    if (!m_supportedMapTypes.isEmpty()) {
        QDeclarativeGeoMapType *type = m_supportedMapTypes.at(0);
        m_activeMapType = type;
        m_map->setActiveMapType(type->mapType());
    }

    // Map tiles are built in this call
    m_map->resize(width(), height());
    // This prefetches a buffer around the map
    m_map->prefetchData();
    m_map->update();

    connect(m_mappingManager, SIGNAL(supportedMapTypesChanged()), this, SLOT(onSupportedMapTypesChanged()));
    emit minimumZoomLevelChanged();
    emit maximumZoomLevelChanged();
    emit supportedMapTypesChanged();
    emit activeMapTypeChanged();

    // Any map items that were added before the plugin was ready
    // need to have setMap called again
    foreach (const QPointer<QDeclarativeGeoMapItemBase> &item, m_mapItems) {
        if (item)
            item.data()->setMap(this, m_map);
    }
}
/*!
    \internal
    this function will only be ever called once
*/
void QDeclarativeGeoMap::mappingManagerInitialized()
{
    mappingManagerInitialized_ = true;

    map_ = mappingManager_->createMap(this);
    gestureArea_->setMap(map_);

    //The zoom level limits are only restricted by the plugins values, if the user has set a more
    //strict zoom level limit before initialization nothing is done here.
    if (mappingManager_->cameraCapabilities().minimumZoomLevel() > gestureArea_->minimumZoomLevel())
        setMinimumZoomLevel(mappingManager_->cameraCapabilities().minimumZoomLevel());

    if (gestureArea_->maximumZoomLevel() < 0
            || mappingManager_->cameraCapabilities().maximumZoomLevel() < gestureArea_->maximumZoomLevel())
        setMaximumZoomLevel(mappingManager_->cameraCapabilities().maximumZoomLevel());

    map_->setActiveMapType(QGeoMapType());

    copyrightsWPtr_ = new QDeclarativeGeoMapCopyrightNotice(this);
    connect(map_,
            SIGNAL(copyrightsChanged(QImage,QPoint)),
            copyrightsWPtr_.data(),
            SLOT(copyrightsChanged(QImage,QPoint)));

    connect(map_,
            SIGNAL(updateRequired()),
            this,
            SLOT(update()));
    connect(map_->mapController(),
            SIGNAL(centerChanged(QGeoCoordinate)),
            this,
            SIGNAL(centerChanged(QGeoCoordinate)));
    connect(map_->mapController(),
            SIGNAL(zoomChanged(qreal)),
            this,
            SLOT(mapZoomLevelChanged(qreal)));

    map_->mapController()->setCenter(center_);
    map_->mapController()->setZoom(zoomLevel_);

    QList<QGeoMapType> types = mappingManager_->supportedMapTypes();
    for (int i = 0; i < types.size(); ++i) {
        QDeclarativeGeoMapType *type = new QDeclarativeGeoMapType(types[i], this);
        supportedMapTypes_.append(type);
    }

    if (!supportedMapTypes_.isEmpty()) {
        QDeclarativeGeoMapType *type = supportedMapTypes_.at(0);
        activeMapType_ = type;
        map_->setActiveMapType(type->mapType());
    }

    // Map tiles are built in this call
    map_->resize(width(), height());
    // This prefetches a buffer around the map
    map_->cameraStopped();
    map_->update();

    emit minimumZoomLevelChanged();
    emit maximumZoomLevelChanged();
    emit supportedMapTypesChanged();
    emit activeMapTypeChanged();

    // Any map items that were added before the plugin was ready
    // need to have setMap called again
    foreach (const QPointer<QDeclarativeGeoMapItemBase> &item, mapItems_) {
        if (item)
            item.data()->setMap(this, map_);
    }
}