| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2015 The Qt Company Ltd. |
| 4 | ** Contact: http://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the QtLocation module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:LGPL3$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see http://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at http://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU Lesser General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation and appearing in the file LICENSE.LGPLv3 included in the |
| 21 | ** packaging of this file. Please review the following information to |
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements |
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl.html. |
| 24 | ** |
| 25 | ** GNU General Public License Usage |
| 26 | ** Alternatively, this file may be used under the terms of the GNU |
| 27 | ** General Public License version 2.0 or later as published by the Free |
| 28 | ** Software Foundation and appearing in the file LICENSE.GPL included in |
| 29 | ** the packaging of this file. Please review the following information to |
| 30 | ** ensure the GNU General Public License version 2.0 requirements will be |
| 31 | ** met: http://www.gnu.org/licenses/gpl-2.0.html. |
| 32 | ** |
| 33 | ** $QT_END_LICENSE$ |
| 34 | ** |
| 35 | ****************************************************************************/ |
| 36 | |
| 37 | #include "qgeotiledmap_nokia.h" |
| 38 | #include "qgeotiledmappingmanagerengine_nokia.h" |
| 39 | |
| 40 | #include <QDebug> |
| 41 | #include <QObject> |
| 42 | #include <QColor> |
| 43 | #include <QFont> |
| 44 | #include <QPainter> |
| 45 | #include <QImage> |
| 46 | #include <QRect> |
| 47 | |
| 48 | #include <QStaticText> |
| 49 | |
| 50 | QT_BEGIN_NAMESPACE |
| 51 | |
| 52 | /* |
| 53 | Constructs a new tiled map data object, which stores the map data required by |
| 54 | \a geoMap and makes use of the functionality provided by \a engine. |
| 55 | */ |
| 56 | QGeoTiledMapNokia::QGeoTiledMapNokia(QGeoTiledMappingManagerEngineNokia *engine, QObject *parent /*= 0*/) : |
| 57 | Map(engine, parent), |
| 58 | m_logo(":/nokia/logo.png" ), // HERE logo image |
| 59 | m_engine(engine) |
| 60 | {} |
| 61 | |
| 62 | QGeoTiledMapNokia::~QGeoTiledMapNokia() {} |
| 63 | |
| 64 | void QGeoTiledMapNokia::evaluateCopyrights(const QSet<QGeoTileSpec> &visibleTiles) |
| 65 | { |
| 66 | const int spaceToLogo = 4; |
| 67 | const int blurRate = 1; |
| 68 | const int fontSize = 10; |
| 69 | |
| 70 | if (m_engine.isNull()) |
| 71 | return; |
| 72 | |
| 73 | const QString copyrightsString = m_engine->evaluateCopyrightsText(mapType: activeMapType(), zoomLevel: cameraData().zoomLevel(), tiles: visibleTiles); |
| 74 | |
| 75 | if (viewportWidth() > 0 && viewportHeight() > 0 && ((copyrightsString.isNull() && m_copyrightsSlab.isNull()) || copyrightsString != m_lastCopyrightsString)) { |
| 76 | QFont font("Sans Serif" ); |
| 77 | font.setPixelSize(fontSize); |
| 78 | font.setStyleHint(QFont::SansSerif); |
| 79 | font.setWeight(QFont::Bold); |
| 80 | |
| 81 | QRect textBounds = QFontMetrics(font).boundingRect(x: 0, y: 0, w: viewportWidth(), h: viewportHeight(), flags: Qt::AlignBottom | Qt::AlignLeft | Qt::TextWordWrap, text: copyrightsString); |
| 82 | |
| 83 | m_copyrightsSlab = QImage(m_logo.width() + textBounds.width() + spaceToLogo + blurRate * 2, |
| 84 | qMax(a: m_logo.height(), b: textBounds.height() + blurRate * 2), |
| 85 | QImage::Format_ARGB32_Premultiplied); |
| 86 | m_copyrightsSlab.fill(color: Qt::transparent); |
| 87 | |
| 88 | QPainter painter(&m_copyrightsSlab); |
| 89 | painter.drawImage(p: QPoint(0, m_copyrightsSlab.height() - m_logo.height()), image: m_logo); |
| 90 | painter.setFont(font); |
| 91 | painter.setPen(QColor(0, 0, 0, 64)); |
| 92 | painter.translate(dx: spaceToLogo + m_logo.width(), dy: -blurRate); |
| 93 | for (int x=-blurRate; x<=blurRate; ++x) { |
| 94 | for (int y=-blurRate; y<=blurRate; ++y) { |
| 95 | painter.drawText(x, y, w: textBounds.width(), h: m_copyrightsSlab.height(), |
| 96 | flags: Qt::AlignBottom | Qt::AlignLeft | Qt::TextWordWrap, |
| 97 | str: copyrightsString); |
| 98 | } |
| 99 | } |
| 100 | painter.setPen(Qt::white); |
| 101 | painter.drawText(x: 0, y: 0, w: textBounds.width(), h: m_copyrightsSlab.height(), |
| 102 | flags: Qt::AlignBottom | Qt::AlignLeft | Qt::TextWordWrap, |
| 103 | str: copyrightsString); |
| 104 | painter.end(); |
| 105 | |
| 106 | m_lastCopyrightsString = copyrightsString; |
| 107 | } |
| 108 | |
| 109 | emit copyrightsChanged(copyrightsImage: m_copyrightsSlab); |
| 110 | } |
| 111 | |
| 112 | QT_END_NAMESPACE |
| 113 | |