diff options
Diffstat (limited to 'demos/mapsdemo')
23 files changed, 2471 insertions, 0 deletions
diff --git a/demos/mapsdemo/icons/endmarker.png b/demos/mapsdemo/icons/endmarker.png Binary files differnew file mode 100644 index 00000000..5701d916 --- /dev/null +++ b/demos/mapsdemo/icons/endmarker.png diff --git a/demos/mapsdemo/icons/mylocation.png b/demos/mapsdemo/icons/mylocation.png Binary files differnew file mode 100644 index 00000000..877adbb1 --- /dev/null +++ b/demos/mapsdemo/icons/mylocation.png diff --git a/demos/mapsdemo/icons/pathmarker.png b/demos/mapsdemo/icons/pathmarker.png Binary files differnew file mode 100644 index 00000000..ae046384 --- /dev/null +++ b/demos/mapsdemo/icons/pathmarker.png diff --git a/demos/mapsdemo/icons/searchmarker.png b/demos/mapsdemo/icons/searchmarker.png Binary files differnew file mode 100644 index 00000000..4c3c4d84 --- /dev/null +++ b/demos/mapsdemo/icons/searchmarker.png diff --git a/demos/mapsdemo/icons/startmarker.png b/demos/mapsdemo/icons/startmarker.png Binary files differnew file mode 100644 index 00000000..d188161e --- /dev/null +++ b/demos/mapsdemo/icons/startmarker.png diff --git a/demos/mapsdemo/icons/waypointmarker.png b/demos/mapsdemo/icons/waypointmarker.png Binary files differnew file mode 100644 index 00000000..6dd1acfa --- /dev/null +++ b/demos/mapsdemo/icons/waypointmarker.png diff --git a/demos/mapsdemo/main.cpp b/demos/mapsdemo/main.cpp new file mode 100644 index 00000000..50fd3043 --- /dev/null +++ b/demos/mapsdemo/main.cpp @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/* Part of the Maps Demo tutorial */ +/* You probably want to read it first, look under Tutorials in + the Mobility documentation */ + +#include "mainwindow.h" + +#include <QApplication> +#include <QList> +#include <QString> +#include <QUrl> +#include <QSettings> +#include <QProcessEnvironment> +#include <QNetworkProxyFactory> + +#include "qgeoserviceprovider.h" + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + + // not in the tutorial text: set up a proxy server from + // a QSettings file if necessary (useful on Linux) + + QApplication::setOrganizationName("Nokia"); + QApplication::setApplicationName("MapsDemo"); + + QSettings settings; + + QVariant value = settings.value("http.proxy"); + if (value.isValid()) { + QUrl url(value.toString(), QUrl::TolerantMode); + QNetworkProxy proxy; + proxy.setType(QNetworkProxy::HttpProxy); + proxy.setHostName(url.host()); + proxy.setPort(url.port(8080)); + QNetworkProxy::setApplicationProxy(proxy); + } + + // launch the main window + MainWindow mw; +#if defined(Q_OS_SYMBIAN) || defined(Q_WS_MAEMO_5) || defined(Q_WS_SIMULATOR) + mw.showMaximized(); +#else + mw.resize(360,640); + mw.show(); +#endif + return a.exec(); +} diff --git a/demos/mapsdemo/mainwindow.cpp b/demos/mapsdemo/mainwindow.cpp new file mode 100644 index 00000000..69f204fd --- /dev/null +++ b/demos/mapsdemo/mainwindow.cpp @@ -0,0 +1,286 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "mainwindow.h" +#include "navigator.h" + +#include <QCoreApplication> +#include <QMenuBar> +#include <QMenu> +#include <QMessageBox> +#include <QAction> +#include <QVBoxLayout> + +MainWindow::MainWindow() : + serviceProvider(0), + markerManager(0), + positionSource(0), + lastNavigator(0), + tracking(true), + firstUpdate(true) +{ + // our actual maps widget is the centre of the mainwindow + mapsWidget = new MapsWidget; + setCentralWidget(mapsWidget); + + // set up the menus + QMenuBar *mbar = new QMenuBar(this); + mbar->addAction("Quit", qApp, SLOT(quit())); + mbar->addAction("My Location", this, SLOT(goToMyLocation())); + + QMenu *searchMenu = new QMenu("Search"); + mbar->addMenu(searchMenu); + + searchMenu->addAction("For address or name", this, SLOT(showSearchDialog())); + + QMenu *navigateMenu = new QMenu("Directions"); + mbar->addMenu(navigateMenu); + + navigateMenu->addAction("From here to address", this, SLOT(showNavigateDialog())); + + setMenuBar(mbar); + setWindowTitle("Maps Demo"); + + // now begin the process of opening the network link + netConfigManager = new QNetworkConfigurationManager; + connect(netConfigManager, SIGNAL(updateCompleted()), + this, SLOT(openNetworkSession())); + netConfigManager->updateConfigurations(); +} + +void MainWindow::openNetworkSession() +{ + // use the default network configuration and make sure that + // the link is open + session = new QNetworkSession(netConfigManager->defaultConfiguration()); + if (session->isOpen()) { + initialize(); + } else { + connect(session, SIGNAL(opened()), + this, SLOT(initialize())); + session->open(); + } +} + +MainWindow::~MainWindow() +{ + delete mapsWidget; + if (serviceProvider) + delete serviceProvider; + if (markerManager) + delete markerManager; +} + +void MainWindow::goToMyLocation() +{ + mapsWidget->animatedPanTo(markerManager->myLocation()); + mapsWidget->map()->setFocus(); + tracking = true; +} + +void MainWindow::initialize() +{ + if (serviceProvider) + delete serviceProvider; + + // check we have a valid default provider + + QList<QString> providers = QGeoServiceProvider::availableServiceProviders(); + if (providers.size() < 1) { + QMessageBox::information(this, tr("Maps Demo"), + tr("No service providers are available")); + QCoreApplication::quit(); + return; + } + + foreach (QString provider, providers) { + serviceProvider = new QGeoServiceProvider(provider); + if (serviceProvider->mappingManager() && + serviceProvider->searchManager() && + serviceProvider->routingManager()) + break; + } + + if (serviceProvider->error() != QGeoServiceProvider::NoError) { + QMessageBox::information(this, tr("Maps Demo"), + tr("Error loading geoservice plugin")); + QCoreApplication::quit(); + return; + } + + if (!serviceProvider->mappingManager() || + !serviceProvider->searchManager() || + !serviceProvider->routingManager()) { + QMessageBox::information(this, tr("Maps Demo"), + tr("No geoservice found with mapping/search/routing")); + QCoreApplication::quit(); + return; + } + + // start initialising things (maps, searching, routing) + + mapsWidget->initialize(serviceProvider->mappingManager()); + + if (markerManager) + delete markerManager; + markerManager = new MarkerManager(serviceProvider->searchManager()); + mapsWidget->setMarkerManager(markerManager); + + connect(markerManager, SIGNAL(searchError(QGeoSearchReply::Error,QString)), + this, SLOT(showErrorMessage(QGeoSearchReply::Error,QString))); + connect(mapsWidget, SIGNAL(markerClicked(Marker*)), + this, SLOT(showMarkerDialog(Marker*))); + connect(mapsWidget, SIGNAL(mapPanned()), + this, SLOT(disableTracking())); + + if (positionSource) + delete positionSource; + + // set up position feeds (eg GPS) + + positionSource = QGeoPositionInfoSource::createDefaultSource(this); + + if (!positionSource) { + mapsWidget->statusBar()->showText("Could not open GPS", 5000); + mapsWidget->setMyLocation(QGeoCoordinate(-27.5796, 153.1)); + //mapsWidget->setMyLocation(QGeoCoordinate(21.1813, -86.8455)); + } else { + positionSource->setUpdateInterval(1000); + connect(positionSource, SIGNAL(positionUpdated(QGeoPositionInfo)), + this, SLOT(updateMyPosition(QGeoPositionInfo))); + positionSource->startUpdates(); + mapsWidget->statusBar()->showText("Opening GPS..."); + } +} + +void MainWindow::disableTracking() +{ + tracking = false; +} + +void MainWindow::updateMyPosition(QGeoPositionInfo info) +{ + if (mapsWidget) { + mapsWidget->setMyLocation(info.coordinate(), false); + if (tracking) + mapsWidget->animatedPanTo(info.coordinate()); + if (firstUpdate) + mapsWidget->statusBar()->showText("Receiving from GPS"); + } + + firstUpdate = false; +} + +void MainWindow::showNavigateDialog() +{ + NavigateDialog nd; + if (nd.exec() == QDialog::Accepted) { + if (markerManager) { + QGeoRouteRequest req; + + req.setTravelModes(nd.travelMode()); + + // tell the old navigator instance to delete itself + // so that its map objects will disappear + if (lastNavigator) + lastNavigator->deleteLater(); + + Navigator *nvg = new Navigator(serviceProvider->routingManager(), + serviceProvider->searchManager(), + mapsWidget, nd.destinationAddress(), + req); + + lastNavigator = nvg; + + connect(nvg, SIGNAL(searchError(QGeoSearchReply::Error,QString)), + this, SLOT(showErrorMessage(QGeoSearchReply::Error,QString))); + connect(nvg, SIGNAL(routingError(QGeoRouteReply::Error,QString)), + this, SLOT(showErrorMessage(QGeoRouteReply::Error,QString))); + + mapsWidget->statusBar()->setText("Routing..."); + mapsWidget->statusBar()->show(); + + nvg->start(); + + connect(nvg, SIGNAL(finished()), + mapsWidget->statusBar(), SLOT(hide())); + + mapsWidget->map()->setFocus(); + } + } +} + +void MainWindow::showSearchDialog() +{ + SearchDialog sd; + if (sd.exec() == QDialog::Accepted) { + if (markerManager) { + markerManager->removeSearchMarkers(); + markerManager->search(sd.searchTerms(), sd.radius()); + mapsWidget->map()->setFocus(); + } + } +} + +void MainWindow::showErrorMessage(QGeoSearchReply::Error err, QString msg) +{ + Q_UNUSED(err) + QMessageBox::critical(this, tr("Error"), msg); + mapsWidget->statusBar()->hide(); + mapsWidget->map()->setFocus(); +} + +void MainWindow::showErrorMessage(QGeoRouteReply::Error err, QString msg) +{ + Q_UNUSED(err) + QMessageBox::critical(this, tr("Error"), msg); + mapsWidget->statusBar()->hide(); + mapsWidget->map()->setFocus(); +} + +void MainWindow::showMarkerDialog(Marker *marker) +{ + MarkerDialog md(marker); + if (md.exec() == QDialog::Accepted) { + md.updateMarker(); + mapsWidget->map()->setFocus(); + } +} diff --git a/demos/mapsdemo/mainwindow.h b/demos/mapsdemo/mainwindow.h new file mode 100644 index 00000000..b47f4aaa --- /dev/null +++ b/demos/mapsdemo/mainwindow.h @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include <QMainWindow> +#include <qnetworksession.h> +#include <qnetworkconfigmanager.h> + +#include "qgeoserviceprovider.h" +#include "qgeopositioninfosource.h" +#include "qgeoroutereply.h" + +#include "mapswidget.h" +#include "marker.h" +#include "searchdialog.h" +#include "markerdialog.h" +#include "navigatedialog.h" +#include "navigator.h" + +class MainWindow : public QMainWindow +{ + Q_OBJECT +public: + MainWindow(); + ~MainWindow(); + +public slots: + void initialize(); + +private slots: + void showSearchDialog(); + void showNavigateDialog(); + void showMarkerDialog(Marker *marker); + void goToMyLocation(); + + void updateMyPosition(QGeoPositionInfo info); + void disableTracking(); + + void showErrorMessage(QGeoSearchReply::Error err, QString msg); + void showErrorMessage(QGeoRouteReply::Error err, QString msg); + + void openNetworkSession(); + +private: + QGeoServiceProvider *serviceProvider; + MapsWidget *mapsWidget; + MarkerManager *markerManager; + QGeoPositionInfoSource *positionSource; + Navigator *lastNavigator; + + QNetworkSession *session; + QNetworkConfigurationManager *netConfigManager; + + bool tracking; + bool firstUpdate; +}; + +#endif // MAINWINDOW_H diff --git a/demos/mapsdemo/mapsdemo.pro b/demos/mapsdemo/mapsdemo.pro new file mode 100644 index 00000000..9c2bb26b --- /dev/null +++ b/demos/mapsdemo/mapsdemo.pro @@ -0,0 +1,41 @@ +TEMPLATE = app +TARGET = mapsdemo + +CONFIG += qt warn_on + +QT += network location + + +RESOURCES += mapsdemo.qrc + +symbian: { + TARGET.CAPABILITY = Location \ + NetworkServices \ + ReadUserData \ + WriteUserData +} + +HEADERS += \ + mapswidget.h \ + marker.h \ + mainwindow.h \ + searchdialog.h \ + markerdialog.h \ + navigatedialog.h \ + navigator.h + +SOURCES += \ + mapswidget.cpp \ + main.cpp \ + marker.cpp \ + mainwindow.cpp \ + searchdialog.cpp \ + markerdialog.cpp \ + navigatedialog.cpp \ + navigator.cpp + +#install +target.path = $$[QT_INSTALL_DEMOS]/qtlocation/mapsdemo +sources.files = $$SOURCES $HEADERS $$RESOURCES $$FORMS *.pro +sources.path = $$[QT_INSTALL_DEMOS]/qtlocation/mapsdemo +INSTALLS += target sources diff --git a/demos/mapsdemo/mapsdemo.qrc b/demos/mapsdemo/mapsdemo.qrc new file mode 100644 index 00000000..a46ea7db --- /dev/null +++ b/demos/mapsdemo/mapsdemo.qrc @@ -0,0 +1,12 @@ +<!DOCTYPE RCC> + <RCC version="1.0"> + + <qresource prefix="/"> + <file>icons/mylocation.png</file> + <file>icons/startmarker.png</file> + <file>icons/endmarker.png</file> + <file>icons/pathmarker.png</file> + <file>icons/searchmarker.png</file> + <file>icons/waypointmarker.png</file> + </qresource> + </RCC> diff --git a/demos/mapsdemo/mapswidget.cpp b/demos/mapsdemo/mapswidget.cpp new file mode 100644 index 00000000..5328a570 --- /dev/null +++ b/demos/mapsdemo/mapswidget.cpp @@ -0,0 +1,531 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "mapswidget.h" +#include "marker.h" + +#include <QGraphicsSceneMouseEvent> +#include <QGraphicsSceneWheelEvent> +#include <QPropertyAnimation> +#include <QParallelAnimationGroup> +#include <QTimer> + +#include "qgeocoordinate.h" + +GeoMap::GeoMap(QGeoMappingManager *manager, MapsWidget *mapsWidget) : + QGraphicsGeoMap(manager), + mapsWidget(mapsWidget), + panActive(false), + markerPressed(false), + pressed(0) +{ + this->setFocus(); +} + +GeoMap::~GeoMap() +{ +} + +double GeoMap::centerLatitude() const +{ + return center().latitude(); +} + +double GeoMap::centerLongitude() const +{ + return center().longitude(); +} + +void GeoMap::setCenterLatitude(double lat) +{ + QGeoCoordinate c = center(); + c.setLatitude(lat); + setCenter(c); +} + +void GeoMap::setCenterLongitude(double lon) +{ + QGeoCoordinate c = center(); + c.setLongitude(lon); + setCenter(c); +} + +void GeoMap::mousePressEvent(QGraphicsSceneMouseEvent *event) +{ + panActive = true; + markerPressed = false; + QList<QGeoMapObject*> objects = mapObjectsAtScreenPosition(event->pos()); + if (objects.size() > 0) { + pressed = objects.first(); + markerPressed = true; + } + + this->setFocus(); + event->accept(); +} + +void GeoMap::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +{ + panActive = false; + + if (markerPressed) { + // check if we're still over the object + QList<QGeoMapObject*> objects = mapObjectsAtScreenPosition(event->pos()); + if (objects.contains(pressed)) { + Marker *m = dynamic_cast<Marker*>(pressed); + if (m) + emit clicked(m); + } + + markerPressed = false; + } + + this->setFocus(); + event->accept(); +} + +void GeoMap::mouseMoveEvent(QGraphicsSceneMouseEvent *event) +{ + if (panActive) { + QPointF delta = event->lastPos() - event->pos(); + pan(delta.x(), delta.y()); + emit panned(); + } + this->setFocus(); + event->accept(); +} + +void GeoMap::wheelEvent(QGraphicsSceneWheelEvent *event) +{ + // pan our current point to the centre, zoom, then pan back + + qreal panx = event->pos().x() - size().width() / 2.0; + qreal pany = event->pos().y() - size().height() / 2.0; + pan(panx, pany); + if (event->delta() > 0) { // zoom in + if (zoomLevel() < maximumZoomLevel()) { + setZoomLevel(zoomLevel() + 1); + } + } else { // zoom out + if (zoomLevel() > minimumZoomLevel()) { + setZoomLevel(zoomLevel() - 1); + } + } + pan(-panx, -pany); + this->setFocus(); + event->accept(); +} + +void GeoMap::keyPressEvent(QKeyEvent *event) +{ + QGeoCoordinate center; + QPropertyAnimation *anim; + const qreal width = size().width(); + const qreal height = size().height(); + + switch (event->key()) { + case Qt::Key_4: + case Qt::Key_Left: + center = screenPositionToCoordinate( + QPointF(width/2 - width/5, height/2)); + anim = new QPropertyAnimation(this, "centerLongitude"); + anim->setEndValue(center.longitude()); + anim->setDuration(200); + anim->start(QAbstractAnimation::DeleteWhenStopped); + break; + case Qt::Key_6: + case Qt::Key_Right: + center = screenPositionToCoordinate( + QPointF(width/2 + width/5, height/2)); + anim = new QPropertyAnimation(this, "centerLongitude"); + anim->setEndValue(center.longitude()); + anim->setDuration(200); + anim->start(QAbstractAnimation::DeleteWhenStopped); + break; + case Qt::Key_2: + case Qt::Key_Up: + center = screenPositionToCoordinate( + QPointF(width/2, height/2 - height/5)); + anim = new QPropertyAnimation(this, "centerLatitude"); + anim->setEndValue(center.latitude()); + anim->setDuration(200); + anim->start(QAbstractAnimation::DeleteWhenStopped); + break; + case Qt::Key_8: + case Qt::Key_Down: + center = screenPositionToCoordinate( + QPointF(width/2, height/2 + height/5)); + anim = new QPropertyAnimation(this, "centerLatitude"); + anim->setEndValue(center.latitude()); + anim->setDuration(200); + anim->start(QAbstractAnimation::DeleteWhenStopped); + break; + case Qt::Key_1: + if (zoomLevel() > minimumZoomLevel()) { + setZoomLevel(zoomLevel() - 1); + } + break; + case Qt::Key_3: + if (zoomLevel() < maximumZoomLevel()) { + setZoomLevel(zoomLevel() + 1); + } + break; + } + this->setFocus(); + event->accept(); +} + + +class ZoomButtonItemPrivate +{ +public: + GeoMap *map; + + QGraphicsSimpleTextItem *plusText; + QGraphicsSimpleTextItem *minusText; + + bool pressedOverTopHalf; + bool pressedOverBottomHalf; +}; + +ZoomButtonItem::ZoomButtonItem(GeoMap *map) : + d(new ZoomButtonItemPrivate) +{ + d->map = map; + d->pressedOverBottomHalf = false; + d->pressedOverTopHalf = false; + + setPen(QPen(QBrush(), 0)); + setBrush(QBrush(QColor(0,0,0,150))); + + d->plusText = new QGraphicsSimpleTextItem(this); + d->plusText->setText("+"); + d->plusText->setBrush(QBrush(Qt::white)); + + d->minusText = new QGraphicsSimpleTextItem(this); + d->minusText->setText("-"); + d->minusText->setBrush(QBrush(Qt::white)); +} + +void ZoomButtonItem::setRect(qreal x, qreal y, qreal w, qreal h) +{ + QGraphicsRectItem::setRect(x, y, w, h); + + QFont f; + f.setFixedPitch(true); + f.setPixelSize(h/5.0); + d->plusText->setFont(f); + d->minusText->setFont(f); + + QRectF plusBound = d->plusText->boundingRect(); + QPointF plusCenter(x+w/2.0, y+h/4.0); + QPointF plusDelta = plusCenter - plusBound.center(); + d->plusText->setPos(plusDelta); + + QRectF minusBound = d->minusText->boundingRect(); + QPointF minusCenter(x+w/2.0, y+3.0*h/4.0); + QPointF minusDelta = minusCenter - minusBound.center(); + d->minusText->setPos(minusDelta); +} + +void ZoomButtonItem::mousePressEvent(QGraphicsSceneMouseEvent *event) +{ + const QPointF pos = event->pos(); + if (!d->pressedOverTopHalf && !d->pressedOverBottomHalf) { + if (isTopHalf(pos)) { + d->pressedOverTopHalf = true; + } else if (isBottomHalf(pos)) { + d->pressedOverBottomHalf = true; + } + } + d->map->setFocus(); + event->accept(); +} + +bool ZoomButtonItem::isTopHalf(const QPointF &point) +{ + return QRectF(rect().x(), rect().y(), + rect().width(), rect().height()/2).contains(point); +} + +bool ZoomButtonItem::isBottomHalf(const QPointF &point) +{ + return QRectF(rect().x(), rect().y() + rect().height()/2, + rect().width(), rect().height()/2).contains(point); +} + +void ZoomButtonItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +{ + const QPointF pos = event->pos(); + if (isTopHalf(pos) && d->pressedOverTopHalf) { + d->map->setZoomLevel(d->map->zoomLevel() + 1.0); + } else if (isBottomHalf(pos) && d->pressedOverBottomHalf) { + d->map->setZoomLevel(d->map->zoomLevel() - 1.0); + } + d->pressedOverBottomHalf = false; + d->pressedOverTopHalf = false; + d->map->setFocus(); + event->accept(); +} + +void ZoomButtonItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) +{ + event->accept(); +} + + +class StatusBarItemPrivate +{ +public: + int offset; + QGraphicsSimpleTextItem *textItem; +}; + +StatusBarItem::StatusBarItem() : + d(new StatusBarItemPrivate) +{ + d->offset = 0; + + setPen(QPen(QBrush(), 0)); + setBrush(QBrush(QColor(0,0,0,120))); + + d->textItem = new QGraphicsSimpleTextItem(this); + d->textItem->setBrush(QBrush(Qt::white)); + + setText(""); +} + +StatusBarItem::~StatusBarItem() +{ +} + +void StatusBarItem::setText(QString text) +{ + d->textItem->setText(text); + QRectF rect = d->textItem->boundingRect(); + QPointF delta = this->rect().center() - rect.center(); + d->textItem->setPos(delta.x(), delta.y()); +} + +int StatusBarItem::offset() const +{ + return d->offset; +} + +void StatusBarItem::setRect(qreal x, qreal y, qreal w, qreal h) +{ + QGraphicsRectItem::setRect(x, y + d->offset, w, h); + setText(d->textItem->text()); +} + +void StatusBarItem::setOffset(int offset) +{ + this->setY(this->y() - d->offset + offset); + d->offset = offset; +} + +void StatusBarItem::showText(QString text, quint32 timeout) +{ + setText(text); + show(); + QTimer::singleShot(timeout, this, SLOT(hide())); +} + +void StatusBarItem::show() +{ + QPropertyAnimation *anim = new QPropertyAnimation(this, "offset"); + anim->setStartValue(0); + anim->setEndValue(-1 * rect().height()); + anim->setDuration(500); + anim->start(QAbstractAnimation::DeleteWhenStopped); +} + +void StatusBarItem::hide() +{ + QPropertyAnimation *anim = new QPropertyAnimation(this, "offset"); + anim->setStartValue(d->offset); + anim->setEndValue(0); + anim->setDuration(500); + anim->start(QAbstractAnimation::DeleteWhenStopped); +} + + +FixedGraphicsView::FixedGraphicsView(QWidget *parent) : + QGraphicsView(parent) +{ +} + +void FixedGraphicsView::scrollContentsBy(int dx, int dy) +{ + Q_UNUSED(dx) + Q_UNUSED(dy) +} + + +class MapsWidgetPrivate +{ +public: + GeoMap *map; + QGraphicsView *view; + MarkerManager *markerManager; + StatusBarItem *statusBarItem; + ZoomButtonItem *zoomButtonItem; +}; + +MapsWidget::MapsWidget(QWidget *parent) : + QWidget(parent), + d(new MapsWidgetPrivate) +{ + d->map = 0; + d->view = 0; + d->markerManager = 0; +} + +MapsWidget::~MapsWidget() +{ +} + +void MapsWidget::initialize(QGeoMappingManager *manager) +{ + d->map = new GeoMap(manager, this); + if (d->markerManager) + d->markerManager->setMap(d->map); + + connect(d->map, SIGNAL(clicked(Marker*)), + this, SIGNAL(markerClicked(Marker*))); + connect(d->map, SIGNAL(panned()), + this, SIGNAL(mapPanned())); + + QGraphicsScene *sc = new QGraphicsScene; + sc->addItem(d->map); + + d->map->setPos(0, 0); + d->map->resize(this->size()); + d->view = new FixedGraphicsView(this); + d->view->setVisible(true); + d->view->setInteractive(true); + d->view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + d->view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + d->view->setScene(sc); + + d->statusBarItem = new StatusBarItem; + sc->addItem(d->statusBarItem); + + d->zoomButtonItem = new ZoomButtonItem(d->map); + sc->addItem(d->zoomButtonItem); + + d->view->resize(this->size()); + d->view->centerOn(d->map); + resizeEvent(0); + d->map->setCenter(QGeoCoordinate(-27.5796, 153.1)); + d->map->setZoomLevel(15); +} + +void MapsWidget::setMyLocation(QGeoCoordinate location, bool center) +{ + if (d->markerManager) + d->markerManager->setMyLocation(location); + if (d->map && center) + d->map->setCenter(location); +} + +QGraphicsGeoMap *MapsWidget::map() const +{ + return d->map; +} + +StatusBarItem *MapsWidget::statusBar() const +{ + return d->statusBarItem; +} + +void MapsWidget::resizeEvent(QResizeEvent *event) +{ + Q_UNUSED(event) + + if (d->view && d->map) { + d->view->resize(size()); + d->map->resize(width()-2, height()-2); + d->view->centerOn(d->map); + d->statusBarItem->setRect(0, height()-2, width()-2, 20); + d->zoomButtonItem->setRect((width()-2)-(width()-2)/10.0, + (height()-2)/2.0 - (height()-2)/6.0, + (width()-2)/10.0, + (height()-2)/3.0); + } +} + +void MapsWidget::animatedPanTo(QGeoCoordinate center) +{ + if (!d->map) + return; + + QPropertyAnimation *latAnim = new QPropertyAnimation(d->map, "centerLatitude"); + latAnim->setEndValue(center.latitude()); + latAnim->setDuration(200); + QPropertyAnimation *lonAnim = new QPropertyAnimation(d->map, "centerLongitude"); + lonAnim->setEndValue(center.longitude()); + lonAnim->setDuration(200); + + QParallelAnimationGroup *group = new QParallelAnimationGroup; + group->addAnimation(latAnim); + group->addAnimation(lonAnim); + group->start(QAbstractAnimation::DeleteWhenStopped); +} + +void MapsWidget::showEvent(QShowEvent *event) +{ + Q_UNUSED(event) + resizeEvent(0); +} + +MarkerManager *MapsWidget::markerManager() const +{ + return d->markerManager; +} + +void MapsWidget::setMarkerManager(MarkerManager *markerManager) +{ + d->markerManager = markerManager; + if (d->map) + d->markerManager->setMap(d->map); + d->markerManager->setStatusBar(d->statusBarItem); +} diff --git a/demos/mapsdemo/mapswidget.h b/demos/mapsdemo/mapswidget.h new file mode 100644 index 00000000..289555db --- /dev/null +++ b/demos/mapsdemo/mapswidget.h @@ -0,0 +1,191 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MAPSWIDGET_H +#define MAPSWIDGET_H + +#include <QGraphicsView> +#include <QGraphicsScene> +#include <QWidget> +#include <QGraphicsRectItem> +#include <QGraphicsSimpleTextItem> + +#include "qgraphicsgeomap.h" +#include "qgeomappingmanager.h" +#include "qgeocoordinate.h" + +class MapsWidget; +class MarkerManager; +class Marker; +class StatusBarItem; +class ZoomButtonItem; + +// The graphics item that actually contains the map +class GeoMap : public QGraphicsGeoMap +{ + Q_OBJECT + + Q_PROPERTY(double centerLatitude READ centerLatitude WRITE setCenterLatitude) + Q_PROPERTY(double centerLongitude READ centerLongitude WRITE setCenterLongitude) + +public: + explicit GeoMap(QGeoMappingManager *manager, MapsWidget *mapsWidget); + ~GeoMap(); + + double centerLatitude() const; + void setCenterLatitude(double lat); + double centerLongitude() const; + void setCenterLongitude(double lon); + +private: + MapsWidget *mapsWidget; + + bool panActive; + bool markerPressed; + QGeoMapObject *pressed; + + void mousePressEvent(QGraphicsSceneMouseEvent *event); + void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); + void mouseMoveEvent(QGraphicsSceneMouseEvent *event); + void wheelEvent(QGraphicsSceneWheelEvent *event); + void keyPressEvent(QKeyEvent *event); + +signals: + void clicked(Marker *marker); + void panned(); +}; + +class FixedGraphicsView : public QGraphicsView +{ + Q_OBJECT + +public: + FixedGraphicsView(QWidget *parent); + +protected: + void scrollContentsBy(int dx, int dy); +}; + +// A widget to hold the view and scene for a GeoMap, as well +// as control widgets +class MapsWidgetPrivate; +class MapsWidget : public QWidget +{ + Q_OBJECT + +public: + explicit MapsWidget(QWidget *parent = 0); + ~MapsWidget(); + + void setMarkerManager(MarkerManager *markerManager); + MarkerManager *markerManager() const; + + QGraphicsGeoMap *map() const; + StatusBarItem *statusBar() const; + + void animatedPanTo(QGeoCoordinate center); + void setMyLocation(QGeoCoordinate location, bool center=true); + +public slots: + void initialize(QGeoMappingManager *manager); + +signals: + void markerClicked(Marker *marker); + void mapPanned(); + +private: + MapsWidgetPrivate *d; + + void resizeEvent(QResizeEvent *event); + void showEvent(QShowEvent *event); +}; + +// An animated status bar item that appears at the bottom +// of the map +class StatusBarItemPrivate; +class StatusBarItem : public QObject, public QGraphicsRectItem +{ + Q_OBJECT + Q_PROPERTY(int offset READ offset WRITE setOffset) + +public: + explicit StatusBarItem(); + ~StatusBarItem(); + + int offset() const; + void setRect(qreal x, qreal y, qreal w, qreal h); + +public slots: + void setText(QString text); + + void showText(QString text, quint32 timeout=3000); + void show(); + void hide(); + + void setOffset(int offset); + +private: + StatusBarItemPrivate *d; +}; + +// Zoom in / zoom out buttons, touch-friendly, appearing on the +// side of the map +class ZoomButtonItemPrivate; +class ZoomButtonItem : public QGraphicsRectItem +{ +public: + explicit ZoomButtonItem(GeoMap *map); + + void setRect(qreal x, qreal y, qreal w, qreal h); + +private: + ZoomButtonItemPrivate *d; + + bool isTopHalf(const QPointF &point); + bool isBottomHalf(const QPointF &point); + +protected: + void mousePressEvent(QGraphicsSceneMouseEvent *event); + void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); + void mouseMoveEvent(QGraphicsSceneMouseEvent *event); +}; + +#endif // MAPSWIDGET_H diff --git a/demos/mapsdemo/marker.cpp b/demos/mapsdemo/marker.cpp new file mode 100644 index 00000000..fee02ada --- /dev/null +++ b/demos/mapsdemo/marker.cpp @@ -0,0 +1,332 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "marker.h" +#include "mapswidget.h" + +#include <QPixmap> + +#include "qlandmark.h" +#include "qgeoboundingcircle.h" + +class MarkerPrivate +{ +public: + Marker::MarkerType type; + QString name; + bool moveable; + QGeoAddress address; +}; + +Marker::Marker(MarkerType type) : + QGeoMapPixmapObject(), + d(new MarkerPrivate) +{ + setMarkerType(type); +} + +void Marker::setMarkerType(MarkerType type) +{ + QString filename; + QPoint offset; + int scale; + + d->type = type; + + switch (d->type) { + case MyLocationMarker: + filename = ":/icons/mylocation.png"; + break; + case SearchMarker: + filename = ":/icons/searchmarker.png"; + break; + case WaypointMarker: + filename = ":/icons/waypointmarker.png"; + break; + case StartMarker: + filename = ":/icons/startmarker.png"; + break; + case EndMarker: + filename = ":/icons/endmarker.png"; + break; + case PathMarker: + filename = ":/icons/pathmarker.png"; + break; + } + + if (d->type == MyLocationMarker) { + offset = QPoint(-13,-13); + scale = 25; + } else { + offset = QPoint(-15, -36); + scale = 30; + } + + setOffset(offset); + setPixmap(QPixmap(filename).scaledToWidth(scale, Qt::SmoothTransformation)); +} + +void Marker::setAddress(QGeoAddress addr) +{ + if (d->address != addr) { + d->address = addr; + emit addressChanged(d->address); + } +} + +Marker::MarkerType Marker::markerType() const +{ + return d->type; +} + +QString Marker::name() const +{ + return d->name; +} + +QGeoAddress Marker::address() const +{ + return d->address; +} + +bool Marker::moveable() const +{ + return d->moveable; +} + +void Marker::setName(QString name) +{ + if (d->name != name) { + d->name = name; + emit nameChanged(d->name); + } +} + +void Marker::setMoveable(bool moveable) +{ + if (d->moveable != moveable) { + d->moveable = moveable; + emit moveableChanged(d->moveable); + } +} + + +class MarkerManagerPrivate +{ +public: + Marker *myLocation; + QList<Marker*> searchMarkers; + + // a reverse geocode request is currently running + bool revGeocodeRunning; + // a request is currently running, and my location has changed + // since it started (ie, the request is stale) + bool myLocHasMoved; + + QGraphicsGeoMap *map; + StatusBarItem *status; + QGeoSearchManager *searchManager; + + QSet<QGeoSearchReply*> forwardReplies; + QSet<QGeoSearchReply*> reverseReplies; +}; + +MarkerManager::MarkerManager(QGeoSearchManager *searchManager, QObject *parent) : + QObject(parent), + d(new MarkerManagerPrivate) +{ + d->searchManager = searchManager; + d->status = 0; + d->revGeocodeRunning = false; + d->myLocHasMoved = false; + + d->myLocation = new Marker(Marker::MyLocationMarker); + d->myLocation->setName("Me"); + + // hook the coordinateChanged() signal for reverse geocoding + connect(d->myLocation, SIGNAL(coordinateChanged(QGeoCoordinate)), + this, SLOT(myLocationChanged(QGeoCoordinate))); + + connect(d->searchManager, SIGNAL(finished(QGeoSearchReply*)), + this, SLOT(replyFinished(QGeoSearchReply*))); + connect(d->searchManager, SIGNAL(finished(QGeoSearchReply*)), + this, SLOT(reverseReplyFinished(QGeoSearchReply*))); +} + +MarkerManager::~MarkerManager() +{ + d->map->removeMapObject(d->myLocation); + delete d->myLocation; + removeSearchMarkers(); +} + +void MarkerManager::setStatusBar(StatusBarItem *bar) +{ + d->status = bar; +} + +void MarkerManager::setMap(QGraphicsGeoMap *map) +{ + d->map = map; + map->addMapObject(d->myLocation); +} + +void MarkerManager::setMyLocation(QGeoCoordinate coord) +{ + d->myLocation->setCoordinate(coord); +} + +void MarkerManager::search(QString query, qreal radius) +{ + QGeoSearchReply *reply; + if (radius > 0) { + QGeoBoundingCircle *boundingCircle = new QGeoBoundingCircle( + d->myLocation->coordinate(), radius); + reply = d->searchManager->search(query, + QGeoSearchManager::SearchAll, + -1, 0, + boundingCircle); + } else { + reply = d->searchManager->search(query); + } + + d->forwardReplies.insert(reply); + + if (d->status) { + d->status->setText("Searching..."); + d->status->show(); + } + + if (reply->isFinished()) { + replyFinished(reply); + } else { + connect(reply, SIGNAL(error(QGeoSearchReply::Error,QString)), + this, SIGNAL(searchError(QGeoSearchReply::Error,QString))); + } +} + +void MarkerManager::removeSearchMarkers() +{ + foreach (Marker *m, d->searchMarkers) { + d->map->removeMapObject(m); + delete m; + } +} + +QGeoCoordinate MarkerManager::myLocation() const +{ + return d->myLocation->coordinate(); +} + +void MarkerManager::myLocationChanged(QGeoCoordinate location) +{ + if (d->revGeocodeRunning) { + d->myLocHasMoved = true; + } else { + QGeoSearchReply *reply = d->searchManager->reverseGeocode(location); + d->reverseReplies.insert(reply); + d->myLocHasMoved = false; + + if (reply->isFinished()) { + d->revGeocodeRunning = false; + reverseReplyFinished(reply); + } else { + d->revGeocodeRunning = true; + } + } +} + +void MarkerManager::reverseReplyFinished(QGeoSearchReply *reply) +{ + if (!d->reverseReplies.contains(reply)) + return; + + if (reply->places().size() > 0) { + QGeoPlace place = reply->places().first(); + d->myLocation->setAddress(place.address()); + } + + d->revGeocodeRunning = false; + if (d->myLocHasMoved) + myLocationChanged(d->myLocation->coordinate()); + + d->reverseReplies.remove(reply); + reply->deleteLater(); +} + +void MarkerManager::replyFinished(QGeoSearchReply *reply) +{ + if (!d->forwardReplies.contains(reply)) + return; + + // generate the markers and add them to the map + foreach (QGeoPlace place, reply->places()) { + Marker *m = new Marker(Marker::SearchMarker); + m->setCoordinate(place.coordinate()); + + if (place.isLandmark()) { + QLandmark lm(place); + m->setName(lm.name()); + } else { + m->setName(QString("%1, %2").arg(place.address().street()) + .arg(place.address().city())); + } + m->setAddress(place.address()); + m->setMoveable(false); + + d->searchMarkers.append(m); + + if (d->map) { + d->map->addMapObject(m); + // also zoom out until marker is visible + while (!d->map->viewport().contains(place.coordinate())) + d->map->setZoomLevel(d->map->zoomLevel()-1); + } + } + + d->forwardReplies.remove(reply); + reply->deleteLater(); + + emit searchFinished(); + + if (d->status) + d->status->hide(); +} diff --git a/demos/mapsdemo/marker.h b/demos/mapsdemo/marker.h new file mode 100644 index 00000000..f90d2fa8 --- /dev/null +++ b/demos/mapsdemo/marker.h @@ -0,0 +1,130 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MARKER_H +#define MARKER_H + +#include <QSignalMapper> + +#include "qgeomappixmapobject.h" +#include "qgeosearchmanager.h" +#include "qgeocoordinate.h" +#include "qgraphicsgeomap.h" +#include "qgeoaddress.h" +#include "qgeosearchreply.h" + + +class StatusBarItem; + +class MarkerPrivate; +class Marker : public QGeoMapPixmapObject +{ + Q_OBJECT + + Q_PROPERTY(MarkerType markerType READ markerType WRITE setMarkerType NOTIFY markerTypeChanged) + Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) + Q_PROPERTY(QGeoAddress address READ address WRITE setAddress NOTIFY addressChanged) + Q_PROPERTY(bool moveable READ moveable WRITE setMoveable NOTIFY moveableChanged) +public: + enum MarkerType { + MyLocationMarker, + SearchMarker, + WaypointMarker, + StartMarker, + EndMarker, + PathMarker + }; + + explicit Marker(MarkerType type); + + MarkerType markerType() const; + void setMarkerType(MarkerType type); + + QString name() const; + QGeoAddress address() const; + bool moveable() const; + +public slots: + void setName(QString name); + void setAddress(QGeoAddress addr); + void setMoveable(bool moveable); + +signals: + void markerTypeChanged(const MarkerType &type); + void nameChanged(const QString &name); + void addressChanged(const QGeoAddress &address); + void moveableChanged(const bool &moveable); + +private: + MarkerPrivate *d; +}; + +class MarkerManagerPrivate; +class MarkerManager : public QObject +{ + Q_OBJECT +public: + explicit MarkerManager(QGeoSearchManager *sm, QObject *parent=0); + ~MarkerManager(); + + QGeoCoordinate myLocation() const; + +public slots: + void setMap(QGraphicsGeoMap *map); + void setStatusBar(StatusBarItem *bar); + void setMyLocation(QGeoCoordinate coord); + void search(QString query, qreal radius=-1); + void removeSearchMarkers(); + +signals: + void searchError(QGeoSearchReply::Error error, QString errorString); + void searchFinished(); + +private: + MarkerManagerPrivate *d; + +private slots: + void replyFinished(QGeoSearchReply *reply); + void myLocationChanged(QGeoCoordinate location); + void reverseReplyFinished(QGeoSearchReply *reply); +}; + +#endif // MARKER_H diff --git a/demos/mapsdemo/markerdialog.cpp b/demos/mapsdemo/markerdialog.cpp new file mode 100644 index 00000000..4a86e373 --- /dev/null +++ b/demos/mapsdemo/markerdialog.cpp @@ -0,0 +1,117 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "markerdialog.h" + +#include <QFormLayout> +#include <QLabel> +#include <QDialogButtonBox> +#include <QVBoxLayout> + +MarkerDialog::MarkerDialog(Marker *marker) : + marker(marker) +{ + QVBoxLayout *vbox = new QVBoxLayout; + + QFormLayout *fm = new QFormLayout; + + nameEdit = new QLineEdit; + nameEdit->setText(marker->name()); + connect(marker, SIGNAL(nameChanged(QString)), + nameEdit, SLOT(setText(QString))); + fm->addRow("Name", nameEdit); + + addressLabel = new QLabel; + setAddressLabel(marker->address()); + connect(marker, SIGNAL(addressChanged(QGeoAddress)), + this, SLOT(setAddressLabel(QGeoAddress))); + fm->addRow("Address", addressLabel); + + lonSpin = new QDoubleSpinBox; + lonSpin->setMinimum(-180.0); + lonSpin->setMaximum(180.0); + lonSpin->setDecimals(7); + lonSpin->setValue(marker->coordinate().longitude()); + fm->addRow("Longitude", lonSpin); + + latSpin = new QDoubleSpinBox; + latSpin->setMinimum(-90.0); + latSpin->setMaximum(90.0); + latSpin->setDecimals(7); + latSpin->setValue(marker->coordinate().latitude()); + fm->addRow("Latitude", latSpin); + + QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Save | + QDialogButtonBox::Close, + Qt::Horizontal); + connect(bb, SIGNAL(accepted()), this, SLOT(accept())); + connect(bb, SIGNAL(rejected()), this, SLOT(reject())); + + vbox->addLayout(fm); + vbox->addWidget(bb); + setLayout(vbox); + setWindowTitle("Edit marker"); +} + +void MarkerDialog::updateMarker() +{ + marker->setName(nameEdit->text()); + QGeoCoordinate c(latSpin->value(), lonSpin->value()); + marker->setCoordinate(c); +} + +void MarkerDialog::setAddressLabel(QGeoAddress address) +{ + QString addressFormat = tr("$street\n$city, $state $postcode\n$country"); + addressFormat.replace("$street", address.street()); + addressFormat.replace("$city", address.city()); + addressFormat.replace("$county", address.county()); + addressFormat.replace("$state", address.state()); + addressFormat.replace("$postcode", address.postcode()); + addressFormat.replace("$district", address.district()); + addressFormat.replace("$country", address.country()); + + addressLabel->setText(addressFormat); +} + +MarkerDialog::~MarkerDialog() +{ +} diff --git a/demos/mapsdemo/markerdialog.h b/demos/mapsdemo/markerdialog.h new file mode 100644 index 00000000..7882c181 --- /dev/null +++ b/demos/mapsdemo/markerdialog.h @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MARKERDIALOG_H +#define MARKERDIALOG_H + +#include <QDialog> +#include <QLineEdit> +#include <QLabel> +#include <QDoubleSpinBox> + +#include "qgeoaddress.h" + +#include "marker.h" + +class MarkerDialog : public QDialog +{ + Q_OBJECT +public: + MarkerDialog(Marker *marker); + ~MarkerDialog(); + +public slots: + void updateMarker(); + +private slots: + void setAddressLabel(QGeoAddress address); + +private: + QLineEdit *nameEdit; + QLabel *addressLabel; + QDoubleSpinBox *lonSpin; + QDoubleSpinBox *latSpin; + + Marker *marker; +}; + +#endif // MARKERDIALOG_H diff --git a/demos/mapsdemo/navigatedialog.cpp b/demos/mapsdemo/navigatedialog.cpp new file mode 100644 index 00000000..2521a091 --- /dev/null +++ b/demos/mapsdemo/navigatedialog.cpp @@ -0,0 +1,95 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "navigatedialog.h" + +#include <QFormLayout> +#include <QDialogButtonBox> +#include <QVBoxLayout> +#include <QMetaObject> + +Q_DECLARE_METATYPE(QGeoRouteRequest::TravelMode) + +NavigateDialog::NavigateDialog(QWidget *parent) : + QDialog(parent) +{ + QFormLayout *formLayout = new QFormLayout; + QVBoxLayout *vbox = new QVBoxLayout; + + addressEdit = new QLineEdit; + formLayout->addRow("Address", addressEdit); + + modeCombo = new QComboBox; + modeCombo->addItem("Car", qVariantFromValue(QGeoRouteRequest::CarTravel)); + modeCombo->addItem("Pedestrian", qVariantFromValue(QGeoRouteRequest::PedestrianTravel)); + modeCombo->addItem("Bicycle", qVariantFromValue(QGeoRouteRequest::BicycleTravel)); + modeCombo->addItem("Public Transit", qVariantFromValue(QGeoRouteRequest::PublicTransitTravel)); + formLayout->addRow("Mode", modeCombo); + + QDialogButtonBox *bb = new QDialogButtonBox; + bb->addButton(QDialogButtonBox::Ok); + bb->addButton(QDialogButtonBox::Cancel); + connect(bb, SIGNAL(accepted()), this, SLOT(accept())); + connect(bb, SIGNAL(rejected()), this, SLOT(reject())); + + vbox->addLayout(formLayout); + vbox->addWidget(bb); + + setLayout(vbox); + setWindowTitle("Directions to address"); +} + +NavigateDialog::~NavigateDialog() +{ +} + +QString NavigateDialog::destinationAddress() const +{ + return addressEdit->text(); +} + +QGeoRouteRequest::TravelModes NavigateDialog::travelMode() const +{ + QVariant v = modeCombo->itemData(modeCombo->currentIndex()); + QGeoRouteRequest::TravelModes mode; + mode |= qVariantValue<QGeoRouteRequest::TravelMode>(v); + return mode; +} diff --git a/demos/mapsdemo/navigatedialog.h b/demos/mapsdemo/navigatedialog.h new file mode 100644 index 00000000..5e6b343a --- /dev/null +++ b/demos/mapsdemo/navigatedialog.h @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef NAVIGATEDIALOG_H +#define NAVIGATEDIALOG_H + +#include <QDialog> +#include <QLineEdit> +#include <QComboBox> + +#include "qgeorouterequest.h" +#include "qgeocoordinate.h" + + +class NavigateDialog : public QDialog +{ + Q_OBJECT +public: + NavigateDialog(QWidget *parent=0); + ~NavigateDialog(); + + QString destinationAddress() const; + QGeoRouteRequest::TravelModes travelMode() const; + +private: + QLineEdit *addressEdit; + QComboBox *modeCombo; +}; + +#endif // NAVIGATEDIALOG_H diff --git a/demos/mapsdemo/navigator.cpp b/demos/mapsdemo/navigator.cpp new file mode 100644 index 00000000..11df70e5 --- /dev/null +++ b/demos/mapsdemo/navigator.cpp @@ -0,0 +1,155 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "navigator.h" +#include "mapswidget.h" +#include "marker.h" + +Navigator::Navigator(QGeoRoutingManager *routingManager, + QGeoSearchManager *searchManager, + MapsWidget *mapsWidget, const QString &address, + const QGeoRouteRequest &requestTemplate) : + address(address), + request(requestTemplate), + routingManager(routingManager), + searchManager(searchManager), + mapsWidget(mapsWidget), + routeObject(0), + endMarker(0), + startMarker(0) +{ +} + +Navigator::~Navigator() +{ + if (routeObject) { + mapsWidget->map()->removeMapObject(routeObject); + delete routeObject; + } + if (endMarker) { + mapsWidget->map()->removeMapObject(endMarker); + delete endMarker; + } + if (startMarker) { + mapsWidget->map()->removeMapObject(startMarker); + delete startMarker; + } +} + +void Navigator::start() +{ + QList<QGeoCoordinate> waypoints = request.waypoints(); + waypoints.append(mapsWidget->markerManager()->myLocation()); + request.setWaypoints(waypoints); + + startMarker = new Marker(Marker::StartMarker); + startMarker->setCoordinate(mapsWidget->markerManager()->myLocation()); + startMarker->setName("Start point"); + mapsWidget->map()->addMapObject(startMarker); + + addressReply = searchManager->search(address); + if (addressReply->isFinished()) { + on_addressSearchFinished(); + } else { + connect(addressReply, SIGNAL(error(QGeoSearchReply::Error,QString)), + this, SIGNAL(searchError(QGeoSearchReply::Error,QString))); + connect(addressReply, SIGNAL(finished()), + this, SLOT(on_addressSearchFinished())); + } +} + +void Navigator::on_addressSearchFinished() +{ + if (addressReply->places().size() <= 0) { + addressReply->deleteLater(); + return; + } + + QGeoPlace place = addressReply->places().at(0); + + QList<QGeoCoordinate> waypoints = request.waypoints(); + waypoints.append(place.coordinate()); + request.setWaypoints(waypoints); + + routeReply = routingManager->calculateRoute(request); + if (routeReply->isFinished()) { + on_routingFinished(); + } else { + connect(routeReply, SIGNAL(error(QGeoRouteReply::Error,QString)), + this, SIGNAL(routingError(QGeoRouteReply::Error,QString))); + connect(routeReply, SIGNAL(finished()), + this, SLOT(on_routingFinished())); + } + + endMarker = new Marker(Marker::EndMarker); + endMarker->setCoordinate(place.coordinate()); + endMarker->setAddress(place.address()); + endMarker->setName("Destination"); + mapsWidget->map()->addMapObject(endMarker); + + addressReply->deleteLater(); +} + +QGeoRoute Navigator::route() const +{ + return firstRoute; +} + +void Navigator::on_routingFinished() +{ + if (routeReply->routes().size() <= 0) { + emit routingError(QGeoRouteReply::NoError, "No valid routes returned"); + routeReply->deleteLater(); + return; + } + + QGeoRoute route = routeReply->routes().at(0); + firstRoute = route; + + routeObject = new QGeoMapRouteObject; + routeObject->setRoute(route); + routeObject->setPen(QPen(Qt::blue, 2.0)); + + mapsWidget->map()->addMapObject(routeObject); + + emit finished(); + routeReply->deleteLater(); +} diff --git a/demos/mapsdemo/navigator.h b/demos/mapsdemo/navigator.h new file mode 100644 index 00000000..47e04d1e --- /dev/null +++ b/demos/mapsdemo/navigator.h @@ -0,0 +1,96 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef NAVIGATOR_H +#define NAVIGATOR_H + +#include <qgeoroutingmanager.h> +#include <qgeosearchmanager.h> + +#include <qgeoroutereply.h> +#include <qgeoroutereply.h> +#include <qgeosearchreply.h> +#include <qgeomaprouteobject.h> + +#include "marker.h" + +class MapsWidget; + +class Navigator : public QObject +{ + Q_OBJECT +public: + Navigator(QGeoRoutingManager *routingManager, QGeoSearchManager *searchManager, + MapsWidget *mapsWidget, const QString &address, + const QGeoRouteRequest &requestTemplate); + ~Navigator(); + + void start(); + QGeoRoute route() const; + +signals: + void finished(); + void searchError(QGeoSearchReply::Error error, QString errorString); + void routingError(QGeoRouteReply::Error error, QString errorString); + +private slots: + void on_addressSearchFinished(); + void on_routingFinished(); + +private: + QString address; + QGeoRouteRequest request; + + QGeoRoutingManager *routingManager; + QGeoSearchManager *searchManager; + MapsWidget *mapsWidget; + + QGeoSearchReply *addressReply; + QGeoRouteReply *routeReply; + + QGeoMapRouteObject *routeObject; + Marker *endMarker; + Marker *startMarker; + + QGeoRoute firstRoute; +}; + +#endif // NAVIGATOR_H diff --git a/demos/mapsdemo/searchdialog.cpp b/demos/mapsdemo/searchdialog.cpp new file mode 100644 index 00000000..2d58d666 --- /dev/null +++ b/demos/mapsdemo/searchdialog.cpp @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "searchdialog.h" + +#include <QFormLayout> +#include <QDialogButtonBox> +#include <QVBoxLayout> + +SearchDialog::SearchDialog(QWidget *parent) : + QDialog(parent) +{ + QFormLayout *formLayout = new QFormLayout; + QVBoxLayout *vbox = new QVBoxLayout; + + searchTermEdit = new QLineEdit; + formLayout->addRow("Search for", searchTermEdit); + + whereCombo = new QComboBox; + whereCombo->addItem(tr("Nearby (<10km)"), 10000); + whereCombo->addItem(tr("Within 30 mins drive of me (<25km)"), 25000); + whereCombo->addItem(tr("Within 100km of me"), 100000); + whereCombo->addItem(tr("Anywhere in the world"), -1); + whereCombo->setCurrentIndex(1); + formLayout->addRow(tr("Where"), whereCombo); + + QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Ok | + QDialogButtonBox::Cancel, + Qt::Horizontal); + connect(bb, SIGNAL(accepted()), this, SLOT(accept())); + connect(bb, SIGNAL(rejected()), this, SLOT(reject())); + + vbox->addLayout(formLayout); + vbox->addWidget(bb); + setLayout(vbox); + setWindowTitle("Search for location"); +} + +qreal SearchDialog::radius() const +{ + const int i = whereCombo->currentIndex(); + return whereCombo->itemData(i).toReal(); +} + +SearchDialog::~SearchDialog() +{ +} + +QString SearchDialog::searchTerms() const +{ + return searchTermEdit->text(); +} diff --git a/demos/mapsdemo/searchdialog.h b/demos/mapsdemo/searchdialog.h new file mode 100644 index 00000000..9d2f214d --- /dev/null +++ b/demos/mapsdemo/searchdialog.h @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef SEARCHDIALOG_H +#define SEARCHDIALOG_H + +#include <QDialog> +#include <QLineEdit> +#include <QComboBox> + +class SearchDialog : public QDialog +{ + Q_OBJECT +public: + SearchDialog(QWidget *parent=0); + ~SearchDialog(); + + QString searchTerms() const; + qreal radius() const; + +private: + QLineEdit *searchTermEdit; + QComboBox *whereCombo; +}; + +#endif // SEARCHDIALOG_H |