1 /****************************************************************************
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
6 ** This file is part of the demonstration applications of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
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.
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 2.1 or version 3 as published by the Free
20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22 ** following information to ensure the GNU Lesser General Public License
23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
26 ** As a special exception, The Qt Company gives you certain additional
27 ** rights. These rights are described in The Qt Company LGPL Exception
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
30 ** GNU General Public License Usage
31 ** Alternatively, this file may be used under the terms of the GNU
32 ** General Public License version 3.0 as published by the Free Software
33 ** Foundation and appearing in the file LICENSE.GPL included in the
34 ** packaging of this file. Please review the following information to
35 ** ensure the GNU General Public License version 3.0 requirements will be
36 ** met: http://www.gnu.org/copyleft/gpl.html.
40 ****************************************************************************/
44 #include "lightmaps.h"
50 map = new LightMaps(this);
51 setCentralWidget(map);
54 QAction *osloAction = new QAction(tr("&Oslo"), this);
55 QAction *berlinAction = new QAction(tr("&Berlin"), this);
56 QAction *jakartaAction = new QAction(tr("&Jakarta"), this);
57 QAction *nightModeAction = new QAction(tr("Night Mode"), this);
58 nightModeAction->setCheckable(true);
59 nightModeAction->setChecked(false);
60 QAction *osmAction = new QAction(tr("About OpenStreetMap"), this);
61 connect(osloAction, SIGNAL(triggered()), SLOT(chooseOslo()));
62 connect(berlinAction, SIGNAL(triggered()), SLOT(chooseBerlin()));
63 connect(jakartaAction, SIGNAL(triggered()), SLOT(chooseJakarta()));
64 connect(nightModeAction, SIGNAL(triggered()), map, SLOT(toggleNightMode()));
65 connect(osmAction, SIGNAL(triggered()), SLOT(aboutOsm()));
67 #if defined(Q_OS_SYMBIAN) || defined(Q_OS_WINCE_WM)
68 menuBar()->addAction(osloAction);
69 menuBar()->addAction(berlinAction);
70 menuBar()->addAction(jakartaAction);
71 menuBar()->addAction(nightModeAction);
72 menuBar()->addAction(osmAction);
74 QMenu *menu = menuBar()->addMenu(tr("&Options"));
75 menu->addAction(osloAction);
76 menu->addAction(berlinAction);
77 menu->addAction(jakartaAction);
79 menu->addAction(nightModeAction);
80 menu->addAction(osmAction);
83 QNetworkConfigurationManager manager;
84 if (manager.capabilities() & QNetworkConfigurationManager::NetworkSessionRequired) {
85 // Get saved network configuration
86 QSettings settings(QSettings::UserScope, QLatin1String("Trolltech"));
87 settings.beginGroup(QLatin1String("QtNetwork"));
89 settings.value(QLatin1String("DefaultNetworkConfiguration")).toString();
92 // If the saved network configuration is not currently discovered use the system
94 QNetworkConfiguration config = manager.configurationFromIdentifier(id);
95 if ((config.state() & QNetworkConfiguration::Discovered) !=
96 QNetworkConfiguration::Discovered) {
97 config = manager.defaultConfiguration();
100 networkSession = new QNetworkSession(config, this);
101 connect(networkSession, SIGNAL(opened()), this, SLOT(sessionOpened()));
103 networkSession->open();
108 setWindowTitle(tr("Light Maps"));
111 void MapZoom::sessionOpened()
113 // Save the used configuration
114 QNetworkConfiguration config = networkSession->configuration();
116 if (config.type() == QNetworkConfiguration::UserChoice) {
117 id = networkSession->sessionProperty(
118 QLatin1String("UserChoiceConfiguration")).toString();
120 id = config.identifier();
123 QSettings settings(QSettings::UserScope, QLatin1String("Trolltech"));
124 settings.beginGroup(QLatin1String("QtNetwork"));
125 settings.setValue(QLatin1String("DefaultNetworkConfiguration"), id);
129 void MapZoom::chooseOslo()
131 map->setCenter(59.9138204, 10.7387413);
134 void MapZoom::chooseBerlin()
136 map->setCenter(52.52958999943302, 13.383053541183472);
139 void MapZoom::chooseJakarta()
141 map->setCenter(-6.211544, 106.845172);
144 void MapZoom::aboutOsm()
146 QDesktopServices::openUrl(QUrl("http://www.openstreetmap.org"));