PageRenderTime 29ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/qt-everywhere-opensource-src-4.8.2/demos/embedded/lightmaps/mapzoom.cpp

#
C++ | 147 lines | 88 code | 15 blank | 44 comment | 7 complexity | ebc589875ed7a1787569c1466e9f7285 MD5 | raw file
Possible License(s): BSD-3-Clause, Apache-2.0, MPL-2.0-no-copyleft-exception, CC-BY-SA-4.0, LGPL-3.0, GPL-2.0, LGPL-2.0, LGPL-2.1, GPL-3.0
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
  4. ** All rights reserved.
  5. ** Contact: Nokia Corporation (qt-info@nokia.com)
  6. **
  7. ** This file is part of the demonstration applications of the Qt Toolkit.
  8. **
  9. ** $QT_BEGIN_LICENSE:LGPL$
  10. ** GNU Lesser General Public License Usage
  11. ** This file may be used under the terms of the GNU Lesser General Public
  12. ** License version 2.1 as published by the Free Software Foundation and
  13. ** appearing in the file LICENSE.LGPL included in the packaging of this
  14. ** file. Please review the following information to ensure the GNU Lesser
  15. ** General Public License version 2.1 requirements will be met:
  16. ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
  17. **
  18. ** In addition, as a special exception, Nokia gives you certain additional
  19. ** rights. These rights are described in the Nokia Qt LGPL Exception
  20. ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
  21. **
  22. ** GNU General Public License Usage
  23. ** Alternatively, this file may be used under the terms of the GNU General
  24. ** Public License version 3.0 as published by the Free Software Foundation
  25. ** and appearing in the file LICENSE.GPL included in the packaging of this
  26. ** file. Please review the following information to ensure the GNU General
  27. ** Public License version 3.0 requirements will be met:
  28. ** http://www.gnu.org/copyleft/gpl.html.
  29. **
  30. ** Other Usage
  31. ** Alternatively, this file may be used in accordance with the terms and
  32. ** conditions contained in a signed written agreement between you and Nokia.
  33. **
  34. **
  35. **
  36. **
  37. **
  38. ** $QT_END_LICENSE$
  39. **
  40. ****************************************************************************/
  41. #include <QtGui>
  42. #include <QtNetwork>
  43. #include "lightmaps.h"
  44. #include "mapzoom.h"
  45. MapZoom::MapZoom()
  46. : QMainWindow(0)
  47. {
  48. map = new LightMaps(this);
  49. setCentralWidget(map);
  50. map->setFocus();
  51. QAction *osloAction = new QAction(tr("&Oslo"), this);
  52. QAction *berlinAction = new QAction(tr("&Berlin"), this);
  53. QAction *jakartaAction = new QAction(tr("&Jakarta"), this);
  54. QAction *nightModeAction = new QAction(tr("Night Mode"), this);
  55. nightModeAction->setCheckable(true);
  56. nightModeAction->setChecked(false);
  57. QAction *osmAction = new QAction(tr("About OpenStreetMap"), this);
  58. connect(osloAction, SIGNAL(triggered()), SLOT(chooseOslo()));
  59. connect(berlinAction, SIGNAL(triggered()), SLOT(chooseBerlin()));
  60. connect(jakartaAction, SIGNAL(triggered()), SLOT(chooseJakarta()));
  61. connect(nightModeAction, SIGNAL(triggered()), map, SLOT(toggleNightMode()));
  62. connect(osmAction, SIGNAL(triggered()), SLOT(aboutOsm()));
  63. #if defined(Q_OS_SYMBIAN) || defined(Q_OS_WINCE_WM)
  64. menuBar()->addAction(osloAction);
  65. menuBar()->addAction(berlinAction);
  66. menuBar()->addAction(jakartaAction);
  67. menuBar()->addAction(nightModeAction);
  68. menuBar()->addAction(osmAction);
  69. #else
  70. QMenu *menu = menuBar()->addMenu(tr("&Options"));
  71. menu->addAction(osloAction);
  72. menu->addAction(berlinAction);
  73. menu->addAction(jakartaAction);
  74. menu->addSeparator();
  75. menu->addAction(nightModeAction);
  76. menu->addAction(osmAction);
  77. #endif
  78. QNetworkConfigurationManager manager;
  79. if (manager.capabilities() & QNetworkConfigurationManager::NetworkSessionRequired) {
  80. // Get saved network configuration
  81. QSettings settings(QSettings::UserScope, QLatin1String("Trolltech"));
  82. settings.beginGroup(QLatin1String("QtNetwork"));
  83. const QString id =
  84. settings.value(QLatin1String("DefaultNetworkConfiguration")).toString();
  85. settings.endGroup();
  86. // If the saved network configuration is not currently discovered use the system
  87. // default
  88. QNetworkConfiguration config = manager.configurationFromIdentifier(id);
  89. if ((config.state() & QNetworkConfiguration::Discovered) !=
  90. QNetworkConfiguration::Discovered) {
  91. config = manager.defaultConfiguration();
  92. }
  93. networkSession = new QNetworkSession(config, this);
  94. connect(networkSession, SIGNAL(opened()), this, SLOT(sessionOpened()));
  95. networkSession->open();
  96. } else {
  97. networkSession = 0;
  98. }
  99. setWindowTitle(tr("Light Maps"));
  100. }
  101. void MapZoom::sessionOpened()
  102. {
  103. // Save the used configuration
  104. QNetworkConfiguration config = networkSession->configuration();
  105. QString id;
  106. if (config.type() == QNetworkConfiguration::UserChoice) {
  107. id = networkSession->sessionProperty(
  108. QLatin1String("UserChoiceConfiguration")).toString();
  109. } else {
  110. id = config.identifier();
  111. }
  112. QSettings settings(QSettings::UserScope, QLatin1String("Trolltech"));
  113. settings.beginGroup(QLatin1String("QtNetwork"));
  114. settings.setValue(QLatin1String("DefaultNetworkConfiguration"), id);
  115. settings.endGroup();
  116. }
  117. void MapZoom::chooseOslo()
  118. {
  119. map->setCenter(59.9138204, 10.7387413);
  120. }
  121. void MapZoom::chooseBerlin()
  122. {
  123. map->setCenter(52.52958999943302, 13.383053541183472);
  124. }
  125. void MapZoom::chooseJakarta()
  126. {
  127. map->setCenter(-6.211544, 106.845172);
  128. }
  129. void MapZoom::aboutOsm()
  130. {
  131. QDesktopServices::openUrl(QUrl("http://www.openstreetmap.org"));
  132. }