diff options
Diffstat (limited to 'examples/embedded/lightmaps')
-rw-r--r-- | examples/embedded/lightmaps/CMakeLists.txt | 44 | ||||
-rw-r--r-- | examples/embedded/lightmaps/lightmaps.cpp | 285 | ||||
-rw-r--r-- | examples/embedded/lightmaps/lightmaps.h | 97 | ||||
-rw-r--r-- | examples/embedded/lightmaps/lightmaps.pro | 12 | ||||
-rw-r--r-- | examples/embedded/lightmaps/main.cpp | 65 | ||||
-rw-r--r-- | examples/embedded/lightmaps/mapzoom.cpp | 105 | ||||
-rw-r--r-- | examples/embedded/lightmaps/mapzoom.h | 75 | ||||
-rw-r--r-- | examples/embedded/lightmaps/slippymap.cpp | 211 | ||||
-rw-r--r-- | examples/embedded/lightmaps/slippymap.h | 99 |
9 files changed, 0 insertions, 993 deletions
diff --git a/examples/embedded/lightmaps/CMakeLists.txt b/examples/embedded/lightmaps/CMakeLists.txt deleted file mode 100644 index a4546b8a39..0000000000 --- a/examples/embedded/lightmaps/CMakeLists.txt +++ /dev/null @@ -1,44 +0,0 @@ -# Generated from lightmaps.pro. - -cmake_minimum_required(VERSION 3.14) -project(lightmaps LANGUAGES CXX) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(CMAKE_AUTOMOC ON) -set(CMAKE_AUTORCC ON) -set(CMAKE_AUTOUIC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/embedded/lightmaps") - -find_package(Qt6 COMPONENTS Core) -find_package(Qt6 COMPONENTS Gui) -find_package(Qt6 COMPONENTS Network) -find_package(Qt6 COMPONENTS Widgets) - -qt_add_executable(lightmaps - lightmaps.cpp lightmaps.h - main.cpp - mapzoom.cpp mapzoom.h - slippymap.cpp slippymap.h -) -set_target_properties(lightmaps PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) -target_link_libraries(lightmaps PUBLIC - Qt::Core - Qt::Gui - Qt::Network - Qt::Widgets -) - -install(TARGETS lightmaps - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/embedded/lightmaps/lightmaps.cpp b/examples/embedded/lightmaps/lightmaps.cpp deleted file mode 100644 index 8ad3035016..0000000000 --- a/examples/embedded/lightmaps/lightmaps.cpp +++ /dev/null @@ -1,285 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the demonstration applications of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, you may use this file under the terms of the BSD license -** as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtCore> -#include <QtWidgets> -#include <QtNetwork> - -#include "lightmaps.h" -#include "slippymap.h" - -// how long (milliseconds) the user need to hold (after a tap on the screen) -// before triggering the magnifying glass feature -// 701, a prime number, is the sum of 229, 233, 239 -// (all three are also prime numbers, consecutive!) -#define HOLD_TIME 701 - -// maximum size of the magnifier -// Hint: see above to find why I picked this one :) -#define MAX_MAGNIFIER 229 - -LightMaps::LightMaps(QWidget *parent) - : QWidget(parent), pressed(false), snapped(false), zoomed(false), - invert(false) -{ - m_normalMap = new SlippyMap(this); - m_largeMap = new SlippyMap(this); - connect(m_normalMap, SIGNAL(updated(QRect)), SLOT(updateMap(QRect))); - connect(m_largeMap, SIGNAL(updated(QRect)), SLOT(update())); -} - -void LightMaps::setCenter(qreal lat, qreal lng) -{ - m_normalMap->latitude = lat; - m_normalMap->longitude = lng; - m_normalMap->invalidate(); - m_largeMap->latitude = lat; - m_largeMap->longitude = lng; - m_largeMap->invalidate(); -} - -void LightMaps::toggleNightMode() -{ - invert = !invert; - update(); -} - -void LightMaps::updateMap(const QRect &r) -{ - update(r); -} - -void LightMaps::activateZoom() -{ - zoomed = true; - tapTimer.stop(); - m_largeMap->zoom = m_normalMap->zoom + 1; - m_largeMap->width = m_normalMap->width * 2; - m_largeMap->height = m_normalMap->height * 2; - m_largeMap->latitude = m_normalMap->latitude; - m_largeMap->longitude = m_normalMap->longitude; - m_largeMap->invalidate(); - update(); -} - -void LightMaps::resizeEvent(QResizeEvent *) -{ - m_normalMap->width = width(); - m_normalMap->height = height(); - m_normalMap->invalidate(); - m_largeMap->width = m_normalMap->width * 2; - m_largeMap->height = m_normalMap->height * 2; - m_largeMap->invalidate(); -} - -void LightMaps::paintEvent(QPaintEvent *event) -{ - QPainter p; - p.begin(this); - m_normalMap->render(&p, event->rect()); - p.setPen(Qt::black); - p.drawText(rect(), Qt::AlignBottom | Qt::TextWordWrap, - "Map data CCBYSA 2009 OpenStreetMap.org contributors"); - p.end(); - - if (zoomed) { - int dim = qMin(width(), height()); - int magnifierSize = qMin(MAX_MAGNIFIER, dim * 2 / 3); - int radius = magnifierSize / 2; - int ring = radius - 15; - QSize box = QSize(magnifierSize, magnifierSize); - - // reupdate our mask - if (maskPixmap.size() != box) { - maskPixmap = QPixmap(box); - maskPixmap.fill(Qt::transparent); - - QRadialGradient g; - g.setCenter(radius, radius); - g.setFocalPoint(radius, radius); - g.setRadius(radius); - g.setColorAt(1.0, QColor(255, 255, 255, 0)); - g.setColorAt(0.5, QColor(128, 128, 128, 255)); - - QPainter mask(&maskPixmap); - mask.setRenderHint(QPainter::Antialiasing); - mask.setCompositionMode(QPainter::CompositionMode_Source); - mask.setBrush(g); - mask.setPen(Qt::NoPen); - mask.drawRect(maskPixmap.rect()); - mask.setBrush(QColor(Qt::transparent)); - mask.drawEllipse(g.center(), ring, ring); - mask.end(); - } - - QPoint center = dragPos - QPoint(0, radius); - center = center + QPoint(0, radius / 2); - QPoint corner = center - QPoint(radius, radius); - - QPoint xy = center * 2 - QPoint(radius, radius); - - // only set the dimension to the magnified portion - if (zoomPixmap.size() != box) { - zoomPixmap = QPixmap(box); - zoomPixmap.fill(Qt::lightGray); - } - if (true) { - QPainter p(&zoomPixmap); - p.translate(-xy); - m_largeMap->render(&p, QRect(xy, box)); - p.end(); - } - - QPainterPath clipPath; - clipPath.addEllipse(center, ring, ring); - - QPainter p(this); - p.setRenderHint(QPainter::Antialiasing); - p.setClipPath(clipPath); - p.drawPixmap(corner, zoomPixmap); - p.setClipping(false); - p.drawPixmap(corner, maskPixmap); - p.setPen(Qt::gray); - p.drawPath(clipPath); - } - if (invert) { - QPainter p(this); - p.setCompositionMode(QPainter::CompositionMode_Difference); - p.fillRect(event->rect(), Qt::white); - p.end(); - } -} - -void LightMaps::timerEvent(QTimerEvent *) -{ - if (!zoomed) - activateZoom(); - update(); -} - -void LightMaps::mousePressEvent(QMouseEvent *event) -{ - if (event->buttons() != Qt::LeftButton) - return; - pressed = snapped = true; - pressPos = dragPos = event->position().toPoint(); - tapTimer.stop(); - tapTimer.start(HOLD_TIME, this); -} - -void LightMaps::mouseMoveEvent(QMouseEvent *event) -{ - if (!event->buttons()) - return; - if (!zoomed) { - if (!pressed || !snapped) { - QPoint delta = event->position().toPoint() - pressPos; - pressPos = event->position().toPoint(); - m_normalMap->pan(delta); - return; - } else { - const int threshold = 10; - QPoint delta = event->position().toPoint() - pressPos; - if (snapped) { - snapped &= delta.x() < threshold; - snapped &= delta.y() < threshold; - snapped &= delta.x() > -threshold; - snapped &= delta.y() > -threshold; - } - if (!snapped) - tapTimer.stop(); - } - } else { - dragPos = event->position().toPoint(); - update(); - } -} - -void LightMaps::mouseReleaseEvent(QMouseEvent *) -{ - zoomed = false; - update(); -} - -void LightMaps::keyPressEvent(QKeyEvent *event) -{ - if (!zoomed) { - if (event->key() == Qt::Key_Left) - m_normalMap->pan(QPoint(20, 0)); - if (event->key() == Qt::Key_Right) - m_normalMap->pan(QPoint(-20, 0)); - if (event->key() == Qt::Key_Up) - m_normalMap->pan(QPoint(0, 20)); - if (event->key() == Qt::Key_Down) - m_normalMap->pan(QPoint(0, -20)); - if (event->key() == Qt::Key_Z || event->key() == Qt::Key_Select) { - dragPos = QPoint(width() / 2, height() / 2); - activateZoom(); - } - } else { - if (event->key() == Qt::Key_Z || event->key() == Qt::Key_Select) { - zoomed = false; - update(); - } - QPoint delta(0, 0); - if (event->key() == Qt::Key_Left) - delta = QPoint(-15, 0); - if (event->key() == Qt::Key_Right) - delta = QPoint(15, 0); - if (event->key() == Qt::Key_Up) - delta = QPoint(0, -15); - if (event->key() == Qt::Key_Down) - delta = QPoint(0, 15); - if (delta != QPoint(0, 0)) { - dragPos += delta; - update(); - } - } -} diff --git a/examples/embedded/lightmaps/lightmaps.h b/examples/embedded/lightmaps/lightmaps.h deleted file mode 100644 index 25b5785edf..0000000000 --- a/examples/embedded/lightmaps/lightmaps.h +++ /dev/null @@ -1,97 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the demonstration applications of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, you may use this file under the terms of the BSD license -** as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef LIGHTMAPS_H -#define LIGHTMAPS_H - -#include <QBasicTimer> -#include <QWidget> - -class SlippyMap; - -class LightMaps: public QWidget -{ - Q_OBJECT - -public: - LightMaps(QWidget *parent = nullptr); - void setCenter(qreal lat, qreal lng); - -public slots: - void toggleNightMode(); - -protected: - void activateZoom(); - void resizeEvent(QResizeEvent *); - void paintEvent(QPaintEvent *event); - void timerEvent(QTimerEvent *); - void mousePressEvent(QMouseEvent *event); - void mouseMoveEvent(QMouseEvent *event); - void mouseReleaseEvent(QMouseEvent *); - void keyPressEvent(QKeyEvent *event); - -private slots: - void updateMap(const QRect &r); - -private: - SlippyMap *m_normalMap; - SlippyMap *m_largeMap; - bool pressed; - bool snapped; - QPoint pressPos; - QPoint dragPos; - QBasicTimer tapTimer; - bool zoomed; - QPixmap zoomPixmap; - QPixmap maskPixmap; - bool invert; -}; - -#endif diff --git a/examples/embedded/lightmaps/lightmaps.pro b/examples/embedded/lightmaps/lightmaps.pro deleted file mode 100644 index bb75cf0a9c..0000000000 --- a/examples/embedded/lightmaps/lightmaps.pro +++ /dev/null @@ -1,12 +0,0 @@ -TEMPLATE = app -HEADERS = lightmaps.h \ - mapzoom.h \ - slippymap.h -SOURCES = lightmaps.cpp \ - main.cpp \ - mapzoom.cpp \ - slippymap.cpp -QT += network widgets - -target.path = $$[QT_INSTALL_EXAMPLES]/embedded/lightmaps -INSTALLS += target diff --git a/examples/embedded/lightmaps/main.cpp b/examples/embedded/lightmaps/main.cpp deleted file mode 100644 index 663e6a5b5d..0000000000 --- a/examples/embedded/lightmaps/main.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the demonstration applications of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, you may use this file under the terms of the BSD license -** as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QApplication> -#include "mapzoom.h" - -int main(int argc, char **argv) -{ - - QApplication app(argc, argv); - app.setApplicationName("LightMaps"); - - MapZoom w; - w.resize(600, 450); - w.show(); - - return app.exec(); -} diff --git a/examples/embedded/lightmaps/mapzoom.cpp b/examples/embedded/lightmaps/mapzoom.cpp deleted file mode 100644 index 781d4f27e3..0000000000 --- a/examples/embedded/lightmaps/mapzoom.cpp +++ /dev/null @@ -1,105 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the demonstration applications of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, you may use this file under the terms of the BSD license -** as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtWidgets> -#include <QtNetwork> -#include "lightmaps.h" -#include "mapzoom.h" - -MapZoom::MapZoom() - : QMainWindow(0) -{ - map = new LightMaps(this); - setCentralWidget(map); - map->setFocus(); - - QAction *osloAction = new QAction(tr("&Oslo"), this); - QAction *berlinAction = new QAction(tr("&Berlin"), this); - QAction *jakartaAction = new QAction(tr("&Jakarta"), this); - QAction *nightModeAction = new QAction(tr("Night Mode"), this); - nightModeAction->setCheckable(true); - nightModeAction->setChecked(false); - QAction *osmAction = new QAction(tr("About OpenStreetMap"), this); - connect(osloAction, SIGNAL(triggered()), SLOT(chooseOslo())); - connect(berlinAction, SIGNAL(triggered()), SLOT(chooseBerlin())); - connect(jakartaAction, SIGNAL(triggered()), SLOT(chooseJakarta())); - connect(nightModeAction, SIGNAL(triggered()), map, SLOT(toggleNightMode())); - connect(osmAction, SIGNAL(triggered()), SLOT(aboutOsm())); - - QMenu *menu = menuBar()->addMenu(tr("&Options")); - menu->addAction(osloAction); - menu->addAction(berlinAction); - menu->addAction(jakartaAction); - menu->addSeparator(); - menu->addAction(nightModeAction); - menu->addAction(osmAction); - - setWindowTitle(tr("Light Maps")); -} - -void MapZoom::chooseOslo() -{ - map->setCenter(59.9138204, 10.7387413); -} - -void MapZoom::chooseBerlin() -{ - map->setCenter(52.52958999943302, 13.383053541183472); -} - -void MapZoom::chooseJakarta() -{ - map->setCenter(-6.211544, 106.845172); -} - -void MapZoom::aboutOsm() -{ - QDesktopServices::openUrl(QUrl("http://www.openstreetmap.org")); -} diff --git a/examples/embedded/lightmaps/mapzoom.h b/examples/embedded/lightmaps/mapzoom.h deleted file mode 100644 index 3844eca718..0000000000 --- a/examples/embedded/lightmaps/mapzoom.h +++ /dev/null @@ -1,75 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the demonstration applications of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, you may use this file under the terms of the BSD license -** as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef MAPZOOM_H -#define MAPZOOM_H - -#include <QMainWindow> - -class LightMaps; - -class MapZoom : public QMainWindow -{ - Q_OBJECT - -public: - MapZoom(); - -private slots: - void chooseOslo(); - void chooseBerlin(); - void chooseJakarta(); - void aboutOsm(); - -private: - LightMaps *map; -}; - -#endif
\ No newline at end of file diff --git a/examples/embedded/lightmaps/slippymap.cpp b/examples/embedded/lightmaps/slippymap.cpp deleted file mode 100644 index bd97aef7ee..0000000000 --- a/examples/embedded/lightmaps/slippymap.cpp +++ /dev/null @@ -1,211 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the demonstration applications of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, you may use this file under the terms of the BSD license -** as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtWidgets> -#include <QtNetwork> -#include "slippymap.h" -#include "qmath.h" - -// tile size in pixels -const int tdim = 256; - -QPointF tileForCoordinate(qreal lat, qreal lng, int zoom) -{ - qreal radianLat = qDegreesToRadians(lat); - qreal zn = static_cast<qreal>(1 << zoom); - qreal tx = (lng + 180.0) / 360.0; - qreal ty = 0.5 - log(tan(radianLat) + 1.0 / cos(radianLat)) / M_PI / 2.0; - return QPointF(tx * zn, ty * zn); -} - -qreal longitudeFromTile(qreal tx, int zoom) -{ - qreal zn = static_cast<qreal>(1 << zoom); - qreal lat = tx / zn * 360.0 - 180.0; - return lat; -} - -qreal latitudeFromTile(qreal ty, int zoom) -{ - qreal zn = static_cast<qreal>(1 << zoom); - qreal n = M_PI - 2 * M_PI * ty / zn; - return qRadiansToDegrees(atan(sinh(n))); -} - - -SlippyMap::SlippyMap(QObject *parent) - : QObject(parent), width(400), height(300), zoom(15), - latitude(59.9138204), longitude(10.7387413) -{ - m_emptyTile = QPixmap(tdim, tdim); - m_emptyTile.fill(Qt::lightGray); - - QNetworkDiskCache *cache = new QNetworkDiskCache; - cache->setCacheDirectory(QStandardPaths::writableLocation(QStandardPaths::CacheLocation)); - m_manager.setCache(cache); - connect(&m_manager, SIGNAL(finished(QNetworkReply*)), - this, SLOT(handleNetworkData(QNetworkReply*))); -} - -void SlippyMap::invalidate() -{ - if (width <= 0 || height <= 0) - return; - - QPointF ct = tileForCoordinate(latitude, longitude, zoom); - qreal tx = ct.x(); - qreal ty = ct.y(); - - // top-left corner of the center tile - int xp = width / 2 - (tx - floor(tx)) * tdim; - int yp = height / 2 - (ty - floor(ty)) * tdim; - - // first tile vertical and horizontal - int xa = (xp + tdim - 1) / tdim; - int ya = (yp + tdim - 1) / tdim; - int xs = static_cast<int>(tx) - xa; - int ys = static_cast<int>(ty) - ya; - - // offset for top-left tile - m_offset = QPoint(xp - xa * tdim, yp - ya * tdim); - - // last tile vertical and horizontal - int xe = static_cast<int>(tx) + (width - xp - 1) / tdim; - int ye = static_cast<int>(ty) + (height - yp - 1) / tdim; - - // build a rect - m_tilesRect = QRect(xs, ys, xe - xs + 1, ye - ys + 1); - - if (m_url.isEmpty()) - download(); - - emit updated(QRect(0, 0, width, height)); -} - -void SlippyMap::render(QPainter *p, const QRect &rect) -{ - for (int x = 0; x <= m_tilesRect.width(); ++x) - for (int y = 0; y <= m_tilesRect.height(); ++y) { - QPoint tp(x + m_tilesRect.left(), y + m_tilesRect.top()); - QRect box = tileRect(tp); - if (rect.intersects(box)) { - if (m_tilePixmaps.contains(tp)) - p->drawPixmap(box, m_tilePixmaps.value(tp)); - else - p->drawPixmap(box, m_emptyTile); - } - } -} - -void SlippyMap::pan(const QPoint &delta) -{ - QPointF dx = QPointF(delta) / qreal(tdim); - QPointF center = tileForCoordinate(latitude, longitude, zoom) - dx; - latitude = latitudeFromTile(center.y(), zoom); - longitude = longitudeFromTile(center.x(), zoom); - invalidate(); -} - -void SlippyMap::handleNetworkData(QNetworkReply *reply) -{ - QImage img; - QPoint tp = reply->request().attribute(QNetworkRequest::User).toPoint(); - if (!reply->error()) - if (!img.load(reply, 0)) - img = QImage(); - reply->deleteLater(); - m_tilePixmaps[tp] = QPixmap::fromImage(img); - if (img.isNull()) - m_tilePixmaps[tp] = m_emptyTile; - emit updated(tileRect(tp)); - - // purge unused spaces - const QRect bound = m_tilesRect.adjusted(-2, -2, 2, 2); - for (auto it = m_tilePixmaps.keyBegin(); it != m_tilePixmaps.keyEnd(); ++it) { - const QPoint &tp = *it; - if (!bound.contains(tp)) - m_tilePixmaps.remove(tp); - } - - download(); -} - -void SlippyMap::download() -{ - QPoint grab(0, 0); - for (int x = 0; x <= m_tilesRect.width(); ++x) - for (int y = 0; y <= m_tilesRect.height(); ++y) { - QPoint tp = m_tilesRect.topLeft() + QPoint(x, y); - if (!m_tilePixmaps.contains(tp)) { - grab = tp; - break; - } - } - if (grab == QPoint(0, 0)) { - m_url = QUrl(); - return; - } - - QString path = "http://tile.openstreetmap.org/%1/%2/%3.png"; - m_url = QUrl(path.arg(zoom).arg(grab.x()).arg(grab.y())); - QNetworkRequest request; - request.setUrl(m_url); - request.setRawHeader("User-Agent", "The Qt Company (Qt) Graphics Dojo 1.0"); - request.setAttribute(QNetworkRequest::User, QVariant(grab)); - m_manager.get(request); -} - -QRect SlippyMap::tileRect(const QPoint &tp) -{ - QPoint t = tp - m_tilesRect.topLeft(); - int x = t.x() * tdim + m_offset.x(); - int y = t.y() * tdim + m_offset.y(); - return QRect(x, y, tdim, tdim); -} diff --git a/examples/embedded/lightmaps/slippymap.h b/examples/embedded/lightmaps/slippymap.h deleted file mode 100644 index f20945445b..0000000000 --- a/examples/embedded/lightmaps/slippymap.h +++ /dev/null @@ -1,99 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the demonstration applications of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, you may use this file under the terms of the BSD license -** as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef SLIPPYMAP_H -#define SLIPPYMAP_H - -#include <QNetworkAccessManager> -#include <QPixmap> -#include <QUrl> - -QT_BEGIN_NAMESPACE -class QNetworkReply; -class QPainter; -QT_END_NAMESPACE - -class SlippyMap: public QObject -{ - Q_OBJECT - -public: - SlippyMap(QObject *parent = nullptr); - void invalidate(); - void render(QPainter *p, const QRect &rect); - void pan(const QPoint &delta); - - int width; - int height; - int zoom; - qreal latitude; - qreal longitude; - -signals: - void updated(const QRect &rect); - -private slots: - void handleNetworkData(QNetworkReply *reply); - void download(); - -protected: - QRect tileRect(const QPoint &tp); - -private: - QPoint m_offset; - QRect m_tilesRect; - QPixmap m_emptyTile; - QHash<QPoint, QPixmap> m_tilePixmaps; - QNetworkAccessManager m_manager; - QUrl m_url; -}; - -#endif - |