PageRenderTime 43ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

/examples/embedded/lightmaps/mapzoom.cpp

https://bitbucket.org/cvp2ri/qt5-tlsauth
C++ | 139 lines | 80 code | 15 blank | 44 comment | 6 complexity | 2f505a00c2f6086efc46e94d58f8331a MD5 | raw file
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
  4. ** Contact: http://www.qt-project.org/legal
  5. **
  6. ** This file is part of the demonstration applications of the Qt Toolkit.
  7. **
  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 Digia. For licensing terms and
  14. ** conditions see http://qt.digia.com/licensing. For further information
  15. ** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
  20. ** Foundation and appearing in the file LICENSE.LGPL included in the
  21. ** packaging of this file. Please review the following information to
  22. ** ensure the GNU Lesser General Public License version 2.1 requirements
  23. ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
  24. **
  25. ** In addition, as a special exception, Digia gives you certain additional
  26. ** rights. These rights are described in the Digia Qt LGPL Exception
  27. ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
  28. **
  29. ** GNU General Public License Usage
  30. ** Alternatively, this file may be used under the terms of the GNU
  31. ** General Public License version 3.0 as published by the Free Software
  32. ** Foundation and appearing in the file LICENSE.GPL included in the
  33. ** packaging of this file. Please review the following information to
  34. ** ensure the GNU General Public License version 3.0 requirements will be
  35. ** met: http://www.gnu.org/copyleft/gpl.html.
  36. **
  37. **
  38. ** $QT_END_LICENSE$
  39. **
  40. ****************************************************************************/
  41. #include <QtWidgets>
  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. QMenu *menu = menuBar()->addMenu(tr("&Options"));
  64. menu->addAction(osloAction);
  65. menu->addAction(berlinAction);
  66. menu->addAction(jakartaAction);
  67. menu->addSeparator();
  68. menu->addAction(nightModeAction);
  69. menu->addAction(osmAction);
  70. QNetworkConfigurationManager manager;
  71. if (manager.capabilities() & QNetworkConfigurationManager::NetworkSessionRequired) {
  72. // Get saved network configuration
  73. QSettings settings(QSettings::UserScope, QLatin1String("QtProject"));
  74. settings.beginGroup(QLatin1String("QtNetwork"));
  75. const QString id =
  76. settings.value(QLatin1String("DefaultNetworkConfiguration")).toString();
  77. settings.endGroup();
  78. // If the saved network configuration is not currently discovered use the system
  79. // default
  80. QNetworkConfiguration config = manager.configurationFromIdentifier(id);
  81. if ((config.state() & QNetworkConfiguration::Discovered) !=
  82. QNetworkConfiguration::Discovered) {
  83. config = manager.defaultConfiguration();
  84. }
  85. networkSession = new QNetworkSession(config, this);
  86. connect(networkSession, SIGNAL(opened()), this, SLOT(sessionOpened()));
  87. networkSession->open();
  88. } else {
  89. networkSession = 0;
  90. }
  91. setWindowTitle(tr("Light Maps"));
  92. }
  93. void MapZoom::sessionOpened()
  94. {
  95. // Save the used configuration
  96. QNetworkConfiguration config = networkSession->configuration();
  97. QString id;
  98. if (config.type() == QNetworkConfiguration::UserChoice) {
  99. id = networkSession->sessionProperty(
  100. QLatin1String("UserChoiceConfiguration")).toString();
  101. } else {
  102. id = config.identifier();
  103. }
  104. QSettings settings(QSettings::UserScope, QLatin1String("QtProject"));
  105. settings.beginGroup(QLatin1String("QtNetwork"));
  106. settings.setValue(QLatin1String("DefaultNetworkConfiguration"), id);
  107. settings.endGroup();
  108. }
  109. void MapZoom::chooseOslo()
  110. {
  111. map->setCenter(59.9138204, 10.7387413);
  112. }
  113. void MapZoom::chooseBerlin()
  114. {
  115. map->setCenter(52.52958999943302, 13.383053541183472);
  116. }
  117. void MapZoom::chooseJakarta()
  118. {
  119. map->setCenter(-6.211544, 106.845172);
  120. }
  121. void MapZoom::aboutOsm()
  122. {
  123. QDesktopServices::openUrl(QUrl("http://www.openstreetmap.org"));
  124. }