8 #include <QAbstractItemView>
9 #include <QAbstractItemModel>
10 #include <QFileDialog>
12 #include <QMessageBox>
13 #include <QProgressBar>
19 #include "satellitedialog.h"
23 WindowMap::WindowMap(QWidget *parent, Settings* settings_p, Log *log)
24 : QMainWindow(parent),satelliteInfo(satelliteInfo), satelliteDialog(0),
25 log(log),pressed(false),snapped(false), settings(settings_p),track(0),trackToSniff(0),network(false),slippyMap(0),
26 waitingForFix(false),validPositions(0),invalidPositions(0),mode(Mode_NewActivityMode),possitionPaint(true),nSession(0),location(0){
29 trackToSniff = new Track();
30 trackToSimulate = QList<GpsPoint*>();
31 settings->setIsConfigured(false);
33 settingsWindow = new SettingsWindow(this,settings,log);
34 settingsWindow->hide();
36 loadTracksWindow = new LoadTracksWindow(this,settings,log);
37 loadTracksWindow->hide();
39 infoWindow = new ActivityInfo(this,settings,log);
42 //log->debug("tracks created");
45 autosaveTimer = new QTimer(this);
46 sPossitioningTimer = new QTimer(this);
47 simulatePossitioningTimer = new QTimer(this);
51 zoomInButton = new QToolButton(this);
52 zoomInButton->setIcon(QIcon(":/images/Zoom-In-icon.png"));
53 zoomInButton->adjustSize();
54 //log->debug(QString("width():%1, zoomInButton.width():%2").arg(width()).arg(zoomInButton->width()));
56 zoomOutButton = new QToolButton(this);
57 zoomOutButton->setIcon(QIcon(":/images/Zoom-Out-icon.png"));
58 zoomOutButton->adjustSize();
61 zoomOutButton->hide();
63 connect(zoomInButton,SIGNAL(clicked()),this,SLOT(onZoomIn()));
64 connect(zoomOutButton,SIGNAL(clicked()),this,SLOT(onZoomOut()));
66 connect(autosaveTimer, SIGNAL(timeout()), this, SLOT(autosave()));
67 connect(sPossitioningTimer, SIGNAL(timeout()), this, SLOT(activatePossitionPaint()));
68 connect(simulatePossitioningTimer, SIGNAL(timeout()), this,SLOT(simulatedPossitionUpdated()));
70 sPossitioningTimer->setInterval(1000*TIME_SECONDS_POSSITIONING_PAN);
74 //log->debug("going to create actions");
76 loadTrackAction = new QAction(tr("Load track"),this);
77 downloadMapsAction = new QAction(tr("Download maps"),this);
78 newActivityAction = new QAction(tr("New activity"),this);
79 simulatedActivityAction = new QAction(tr("Activity simulation"),this);
80 infoAction = new QAction(tr("Activity info"),this);
81 quitAction = new QAction(tr("Quit"), this);
83 lapAction = new QAction(tr("New lap"), this);
84 settingsAction = new QAction(tr("Settings"), this);
85 stopAction = new QAction(tr("Stop"), this);
86 startAction = new QAction(tr("Start"), this);
87 startAction->setEnabled(false);
88 tracksAction = new QAction(tr("Load track"), this);
89 satelliteAction = new QAction(tr("Satellite info."), this);
90 startNetworkAction = new QAction(tr("Start Networking"),this);
91 startNetworkAction->setEnabled(false);
93 //log->debug("done, connecting");
95 connect(loadTrackAction, SIGNAL(triggered()),SLOT(loadTrack()));
96 connect(downloadMapsAction, SIGNAL(triggered()),SLOT(downloadMapTrack()));
97 connect(newActivityAction, SIGNAL(triggered()),SLOT(newActivityTrack()));
98 connect(simulatedActivityAction, SIGNAL(triggered()), SLOT(newSimulation()));
99 connect(stopAction, SIGNAL(triggered()), SLOT(stopActivity()));
100 connect(startAction, SIGNAL(triggered()), SLOT(startActivity()));
101 connect(quitAction, SIGNAL(triggered()), SLOT(quit()));
102 connect(lapAction, SIGNAL(triggered()), SLOT(lapActivity()));
103 connect(settingsAction, SIGNAL(triggered()), SLOT(configureSettings()));
104 connect(tracksAction, SIGNAL(triggered()), SLOT(tracksActivity()));
105 connect(satelliteAction, SIGNAL(triggered()), SLOT(satellite()));
106 connect(startNetworkAction,SIGNAL(triggered()), SLOT(networkStart()));
107 connect(infoAction, SIGNAL(triggered()), SLOT(info()));
110 //log->debug("done!");
112 //log->debug("going to show buttons...");
113 //log->debug("done?");
115 this->setFixedSize(WIDTH_DEFAULT,HEIGHT_DEFAULT);
116 //parent->window()->setFixedSize(WIDTH_DEFAULT,HEIGHT_DEFAULT);
117 downloadingStatus = new DownloadingStatus(this);
118 downloadingStatus->hide();
125 WindowMap::~WindowMap()
127 //log->debug("windowMap destructor");
131 //log->debug("session closed");
133 location->stopUpdates();
135 //log->debug("location closed");
139 void WindowMap::setTrack(QString fileName,QString activity){
141 track = new Track(fileName,activity);
142 //log->debug(QString("track created!!!:%1").arg(track->toString()));
145 void WindowMap::setMenuLoadTracks(){
147 //log->debug("MenuLoadTracks!!!!");
150 #if defined(Q_OS_SYMBIAN) || defined(Q_OS_WINCE_WM) || defined(Q_WS_MAEMO_5) || defined(Q_WS_MAEMO_6)
152 menuBar()->addAction(loadTrackAction);
153 menuBar()->addAction(downloadMapsAction);
154 menuBar()->addAction(newActivityAction);
155 menuBar()->addAction(simulatedActivityAction);
156 menuBar()->addAction(startNetworkAction);
157 menuBar()->addAction(infoAction);
158 menuBar()->addAction(quitAction);
162 QMenu *menu = menuBar()->addMenu("&Options");
164 menu->addAction(loadTrackAction);
165 menu->addAction(downloadMapsAction);
166 menu->addAction(newActivityAction);
167 menu->addAction(simulatedActivityAction);
168 menu->addAction(startNetworkAction);
169 menu->addAction(infoAction);
170 menu->addAction(quitAction);
175 void WindowMap::setMenuActivity(){
178 #if defined(Q_OS_SYMBIAN) || defined(Q_OS_WINCE_WM) || defined(Q_WS_MAEMO_5) || defined(Q_WS_MAEMO_6)
179 menuBar()->addAction(lapAction);
180 menuBar()->addAction(settingsAction);
181 menuBar()->addAction(startAction);
182 menuBar()->addAction(stopAction);
183 menuBar()->addAction(startNetworkAction);
184 menuBar()->addAction(tracksAction);
185 menuBar()->addAction(infoAction);
186 menuBar()->addAction(quitAction);
189 menuBar()->addAction(satelliteAction);
192 QMenu *menu = menuBar()->addMenu("&Options");
194 menu->addAction(lapAction);
195 menu->addAction(settingsAction);
196 menu->addAction(stopAction);
197 menu->addAction(startAction);
198 menu->addAction(tracksAction);
199 menu->addAction(startNetworkAction);
200 menu->addAction(satelliteAction);
201 menu->addAction(infoAction);
202 menu->addAction(quitAction);
208 void WindowMap::activatePossitionPaint(){
209 //log->debug("activating possitionPaint");
211 sPossitioningTimer->stop();
213 void WindowMap::desactivatePossitionPaint(){
214 //log->debug("desactivating possition paint, and starting timer");
215 possitionPaint=false;
216 sPossitioningTimer->start();
219 void WindowMap::clearAllMaps(){
221 slippyMap->clearAllMaps();
226 void WindowMap::startServices(){
229 //log->debug("--- startServices ---");
230 if(settings->getIsOnline()){
231 //log->debug("Is online?" + settings->getIsOnline());
232 //log->debug("going to start networking...");
236 //log->debug("going offline");
237 startNetworkAction->setEnabled(true);
242 void WindowMap::showSatelliteInfo(){
245 satelliteInfo = QGeoSatelliteInfoSource::createDefaultSource(this);
248 SatelliteDialog *dialog = new SatelliteDialog(this,
250 SatelliteDialog::ExitOnCancel,
251 SatelliteDialog::OrderByPrnNumber,
252 SatelliteDialog::ScaleToMaxPossible);
254 dialog->connectSources(location, satelliteInfo);
256 //location->startUpdates();
257 satelliteInfo->startUpdates();
261 //satelliteInfo->stopUpdates();
264 //delete satelliteInfo;
270 void WindowMap::waitForFix() {
274 waitingForFix = true;
276 satelliteInfo = QGeoSatelliteInfoSource::createDefaultSource(this);
279 satelliteDialog = new SatelliteDialog(this,
281 SatelliteDialog::ExitOnCancel,
282 SatelliteDialog::OrderByPrnNumber,
283 SatelliteDialog::ScaleToMaxPossible);
285 connect(satelliteDialog,SIGNAL(rejected()),satelliteDialog,SLOT(hide()));
287 satelliteDialog->connectSources(location, satelliteInfo);
289 satelliteInfo->startUpdates();
291 satelliteDialog->exec();
293 //satelliteInfo->stopUpdates();
296 //delete satelliteInfo;
299 waitingForFix = false;
302 void WindowMap::stopNetworking(){
307 slippyMap->setNetwork(false);
310 void WindowMap::startNetworking(){
312 if(!network && ((mode==Mode_NewActivityMode && settings->getIsOnline()) || (mode==Mode_LoadTracksWindow))){
315 // Set Internet Access Point
316 QNetworkConfigurationManager manager;
317 const bool canStartIAP = (manager.capabilities()
318 & QNetworkConfigurationManager::CanStartAndStopInterfaces);
320 #ifdef BEARER_IN_QTNETWORK
321 QNetworkConfiguration cfg = manager.defaultConfiguration();
322 if (!cfg.isValid() || (!canStartIAP && cfg.state() != QNetworkConfiguration::Active)) {
324 QTM_PREPEND_NAMESPACE(QNetworkConfiguration) cfg = manager.defaultConfiguration();
325 if (!cfg.isValid() || (!canStartIAP && cfg.state() != QTM_PREPEND_NAMESPACE(QNetworkConfiguration)::Active)) {
328 QMessageBox::information(this, tr("Network"), tr(
329 "No Access Point found."));
334 nSession = new QNetworkSession(cfg, this);
336 nSession->waitForOpened(-1);
339 connect(nSession, SIGNAL(opened()), this, SLOT(networkSessionOpened()));
340 connect(nSession,SIGNAL(error(QNetworkSession::SessionError)),this,SLOT(error(QNetworkSession::SessionError)));
345 slippyMap->setNetwork(true);
351 void WindowMap::networkSessionOpened(){
353 //log->debug("--- signal recived of sesson opened ---");
356 //log->debug("invalidating map");
357 slippyMap->setNetwork(true);
358 slippyMap->updateTiles();
364 void WindowMap::error(QNetworkSession::SessionError error)
366 //log->debug("--- Error in Networking!!! ---");
367 //log->debug(QString("settings is configured?%1").arg(settings->getIsConfigured()));
369 if(mode==Mode_NewActivityMode && (!settings->getIsOnline() || !settings->getIsConfigured()))
372 QMessageBox msgBox(this);
374 msgBox.setText(tr("Downloading maps requires network access!."));
375 msgBox.setInformativeText(tr("Try to connect or cancel to disable maps."));
376 msgBox.setIcon(QMessageBox::Information);
377 msgBox.setStandardButtons(QMessageBox::Retry | QMessageBox::Cancel);
378 msgBox.setDefaultButton(QMessageBox::Retry);
380 int ret = msgBox.exec();
381 if (ret == QMessageBox::Retry) {
382 QTimer::singleShot(0, nSession, SLOT(open()));
383 } else if (ret == QMessageBox::Cancel) {
384 if(mode==Mode_NewActivityMode){
386 settings->setIsOnline(false);
387 //log->debug("enabling startNetworking");
388 startNetworkAction->setEnabled(true);
391 QTimer::singleShot(60000, nSession, SLOT(open()));
394 slippyMap->setNetwork(false);
398 void WindowMap::startMaps(){
401 //log->debug(QString("network:%1").arg(network));
402 slippyMap = new TilesMap(nSession, this, log, zoom,settings->getMapType());
403 connect(slippyMap, SIGNAL(updated(QRect)), SLOT(updateMap(QRect)));
404 slippyMap->setWidth(width());
405 slippyMap->setHeight(height());
406 slippyMap->setNetwork(network);
407 //log->debug(QString("START MAPS!!! slippy.network:%1").arg(slippyMap->network));
410 void WindowMap::changeUpdateInterval(int millis){
413 location->setUpdateInterval(millis);
415 simulatePossitioningTimer->setInterval(millis);
418 void WindowMap::changeMapType(MapType map){
419 slippyMap->setMapType(map);
422 bool WindowMap::checkGPS(){
424 #if defined(Q_OS_SYMBIAN) || defined(Q_OS_WINCE_WM) || defined(Q_WS_MAEMO_5) || defined(Q_WS_MAEMO_6)
425 location = QGeoPositionInfoSource::createDefaultSource(this);
428 //With maemo simulator doesn't work, I've to change this.
434 QMessageBox::information(this, tr("No GPS detected"),
435 tr("No GPS support detected, going to simulate mode"));
441 void WindowMap::startGPS(){
444 if(location && !simulateGPS){
445 location->setUpdateInterval(settings->getGpsInterval());
446 connect(location,SIGNAL(positionUpdated(QGeoPositionInfo)),this,SLOT(positionUpdated(QGeoPositionInfo)));
447 if(!settings->getIsOnline())
448 location->setPreferredPositioningMethods(QGeoPositionInfoSource::SatellitePositioningMethods);
450 location->startUpdates();
452 //log->debug("setting signal updateTimeout...");
453 connect(location, SIGNAL(updateTimeout()), this, SLOT(waitForFix()));
454 //log->debug("start positioning...");
459 void WindowMap::setTopLeft(qreal lat, qreal lng){
461 //log->debug("----setTopLeft----");
462 QPointF ct = slippyMap->coordinate2tile(lat, lng, zoom);
464 qreal tx = ct.x()-static_cast<qreal>(width())/(2.0*static_cast<qreal>(tdim));
465 qreal ty = ct.y()-static_cast<qreal>(height())/(2.0*static_cast<qreal>(tdim));
466 topLeft=QPointF(tx,ty);
469 void WindowMap::setCenter(qreal lat, qreal lng) {
471 //log->debug("--- set Center function ---!");
474 log->err("slippyMap not created!");
480 setTopLeft(lat, lng);
481 slippyMap->updateTiles(lat,lng);
484 void WindowMap::updateMap(const QRect &r) {
488 void WindowMap::closeEvent(QCloseEvent *event){
490 //log->debug("---- WindowMap quit, going to show parent and hide this ----");
491 //log->debug(QString("mode:==Mode_NewActivityMode?:%1, mode:%2").arg(mode==Mode_NewActivityMode).arg(mode));
492 if(mode==Mode_NewActivityMode && !simulateGPS){
493 QMessageBox msgBox(this);
495 msgBox.setText(tr("Do you want to close activity?, it will be saved."));
496 msgBox.setInformativeText(tr("Closing Activity"));
497 msgBox.setIcon(QMessageBox::Information);
498 msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
499 msgBox.setDefaultButton(QMessageBox::Cancel);
500 int ret = msgBox.exec();
502 if (ret == QMessageBox::Cancel){
507 settings->setIsConfigured(false);
509 this->parentWidget()->showFullScreen();
515 if(mode==Mode_NewActivityMode && simulateGPS){
516 settings->setIsConfigured(false);
517 //log->debug("exit from simulating GPS");
518 //log->debug("setting isconfigured to false and stopping timer");
519 simulatePossitioningTimer->stop();
523 this->parentWidget()->showFullScreen();
525 //log->debug("done");
529 void WindowMap::showEvent(QShowEvent *){
532 if(mode==Mode_NewActivityMode && !settings->getIsConfigured()){
534 settingsWindow->show();
535 //setWindowTitle(settings->getActivity());
536 }else if(mode==Mode_LoadTracksWindow && !settings->getIsConfigured()){
537 setWindowTitle(QString("Load Tracks ->").append(trackToSniff->getName()));
538 loadTracksWindow->show();
544 void WindowMap::networkStart(){
545 startNetworkAction->setEnabled(false);
546 QTimer::singleShot(0, nSession, SLOT(open()));
549 void WindowMap::configureSettings(){
550 settingsWindow->show();
553 void WindowMap::tracksActivity(){
554 //mode=Mode_LoadTracksWindow;
555 possitionPaint=false;
556 //setMenuLoadTracks();
557 loadTracksWindow->show();
560 void WindowMap::loadTrack(){
561 loadTracksWindow->show();
563 void WindowMap::downloadMapTrack(){
567 qreal lat = slippyMap->getLatitude();
568 qreal lng = slippyMap->getLongitude();
572 //pos.setX((width()-downloadingStatus->width())/2);
573 //pos.setY((height()-downloadingStatus->height())/2);
575 downloadingStatus->show();
577 //downloadingStatus->move(pos);
578 QProgressBar* pb = downloadingStatus->getProgressBar();
579 int numPoints = trackToSniff->getNumPoints();
580 pb->setRange(0,numPoints);
582 downloadingStatus->setText(QString(tr("Making map requests")));
584 connect(slippyMap,SIGNAL(pointsRequested(int)),pb,SLOT(setValue(int)));
585 tilesToDownload = slippyMap->downloadMaps(trackToSniff);
586 disconnect(slippyMap,SIGNAL(pointsRequested(int)),pb,SLOT(setValue(int)));
588 if(tilesToDownload>0){
589 downloadingStatus->setText(QString(tr("Getting map tiles")));
590 pb->setRange(0,tilesToDownload);
592 connect(slippyMap,SIGNAL(tilesDownloaded(int)),this,SLOT(updateProgress(int)));
594 downloadingStatus->hide();
597 slippyMap->updateTiles(lat,lng);
601 void WindowMap::updateProgress(int val){
603 downloadingStatus->getProgressBar()->setValue(val);
604 if(val==tilesToDownload){
605 downloadingStatus->hide();
608 void WindowMap::newActivityTrack(){
609 mode=Mode_NewActivityMode;
610 settings->setIsConfigured(false);
612 settingsWindow->show();
615 void WindowMap::newSimulation(){
616 mode=Mode_NewActivityMode;
618 settings->setIsConfigured(false);
620 settingsWindow->show();
623 void WindowMap::info(){
627 void WindowMap::startActivity(){
629 stopAction->setEnabled(true);
630 startAction->setEnabled(false);
632 //log->debug("stopStart enabled");
634 void WindowMap::stopActivity(){
636 stopAction->setEnabled(false);
637 startAction->setEnabled(true);
644 void WindowMap::settings(){
645 settingsWindow->show();
649 void WindowMap::lapActivity(){
654 void WindowMap::quit(){
655 QCloseEvent *event = new QCloseEvent();
656 emit closeEvent(event);
659 void WindowMap::tracks(){
663 void WindowMap::satellite(){
665 #if defined(Q_OS_SYMBIAN) || defined(Q_OS_WINCE_WM) || defined(Q_WS_MAEMO_5) || defined(Q_WS_MAEMO_6)
670 void WindowMap::stopPositioning() {
672 simulatePossitioningTimer->stop();
675 location->stopUpdates();
679 void WindowMap::startPositioning() {
681 simulatePossitioningTimer->start();
684 location->startUpdates();
688 void WindowMap::onZoomOut(){
691 if(settings->getMapType()==MapTypeICC)
692 minzoom=MIN_ICC_ZOOM;
694 if (zoom > minzoom) {
696 zoomOutButton->setEnabled(zoom > minzoom);
697 zoomInButton->setEnabled(true);
701 slippyMap->setZoom(zoom);
703 setTopLeft(slippyMap->getLatitude(), slippyMap->getLongitude());
704 slippyMap->updateTiles();
709 void WindowMap::onZoomIn(){
710 if (zoom < MAX_ZOOM - 1) {
712 zoomInButton->setEnabled(zoom < MAX_ZOOM - 1);
713 zoomOutButton->setEnabled(true);
717 slippyMap->setZoom(zoom);
718 setTopLeft(slippyMap->getLatitude(), slippyMap->getLongitude());
719 slippyMap->updateTiles();
724 void WindowMap::updateSummary(){
725 emit(infoWindow->updateSummary());
728 void WindowMap::simulatedPossitionUpdated(){
729 log->info("simulated possition!!!");
730 //log->info(QString("num points to simulate:%1").arg(trackToSimulate.size()));
731 GpsPoint* point= new GpsPoint(0,0,0);
734 if(trackToSimulate.size()>0){
736 point = trackToSimulate.first();
738 log->debug(QString("point to simulate:%1").arg(point->toString()));
739 track->addPoint(point);
740 log->debug("going to emit updateSummary!!!");
741 emit(infoWindow->updateSummary());
742 log->debug("point added to track and updated");
743 //log->debug(QString("track num points:%1").arg(track->getNumPoints()));
745 trackToSimulate.removeFirst();
747 //log->info(QString("num points to simulate:%1").arg(trackToSimulate.size()));
749 //log->debug(QString("Possition paint???????????%1").arg(possitionPaint));
751 setCenter(point->getLatitude(),point->getLongitude());
758 void WindowMap::positionUpdated(const QGeoPositionInfo &pos){
760 //log->info("ACTIVITYMAP-POSSITIONUPDATED!!!");
761 //setCenter(pos.coordinate().latitude(), pos.coordinate().longitude());
764 pos.attribute(QGeoPositionInfo::HorizontalAccuracy)<=settings->getHorizontalAccuracy() &&
765 pos.attribute(QGeoPositionInfo::VerticalAccuracy)<=settings->getVerticalAccuracy()){
767 GpsPoint* point = new GpsPoint(pos.coordinate().latitude(),pos.coordinate().longitude(),pos.coordinate().altitude(),pos.timestamp(),
768 pos.attribute(QGeoPositionInfo::GroundSpeed),pos.attribute(QGeoPositionInfo::Direction),
769 pos.attribute(QGeoPositionInfo::MagneticVariation),
770 pos.attribute(QGeoPositionInfo::HorizontalAccuracy),
771 pos.attribute(QGeoPositionInfo::VerticalAccuracy));
774 // log->debug(point->toString());
775 //log->debug("going to add point...");
776 track->addPoint(point);
777 emit(infoWindow->updateSummary());
781 setCenter(point->getLatitude(),point->getLongitude());
784 satelliteDialog->hide();
788 log->debug("position not updated:");
790 log->debug("Horizontal accuracy (meters):" + QString::number(pos.attribute(QGeoPositionInfo::HorizontalAccuracy)));
791 log->debug("Vertical accuracy (meters):" + QString::number(pos.attribute(QGeoPositionInfo::VerticalAccuracy)));
798 void WindowMap::autosave(){
800 if(track!=0 && track->getNumPoints()>0 && !simulateGPS){
801 log->debug("going to save the TCX file...");
805 log->info("done...");
808 void WindowMap::setOrientation(ScreenOrientation orientation)
811 #if defined(Q_OS_SYMBIAN)
812 // If the version of Qt on the device is < 4.7.2, that attribute won't work
813 if (orientation != ScreenOrientationAuto) {
814 const QStringList v = QString::fromAscii(qVersion()).split(QLatin1Char('.'));
815 if (v.count() == 3 && (v.at(0).toInt() << 16 | v.at(1).toInt() << 8 | v.at(2).toInt()) < 0x040702) {
816 qWarning("Screen orientation locking only supported with Qt 4.7.2 and above");
820 #endif // Q_OS_SYMBIAN
822 Qt::WidgetAttribute attribute;
823 switch (orientation) {
824 #if QT_VERSION < 0x040702
825 // Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes
826 case ScreenOrientationLockPortrait:
827 attribute = static_cast<Qt::WidgetAttribute>(128);
829 case ScreenOrientationLockLandscape:
830 attribute = static_cast<Qt::WidgetAttribute>(129);
833 case ScreenOrientationAuto:
834 attribute = static_cast<Qt::WidgetAttribute>(130);
836 #else // QT_VERSION < 0x040702
837 case ScreenOrientationLockPortrait:
838 attribute = Qt::WA_LockPortraitOrientation;
840 case ScreenOrientationLockLandscape:
841 attribute = Qt::WA_LockLandscapeOrientation;
844 case ScreenOrientationAuto:
845 attribute = Qt::WA_AutoOrientation;
847 #endif // QT_VERSION < 0x040702
849 setAttribute(attribute, true);
853 void WindowMap::showExpanded()
857 #elif defined(Q_WS_MAEMO_5)
864 void WindowMap::paintEvent(QPaintEvent *event) {
868 log->debug("---- paint Event ----!");
874 #if defined(Q_OS_SYMBIAN)
875 QFont font = p.font();
876 font.setPixelSize(13);
881 log->debug("slippyMap not created!");
885 slippyMap->render(&p, event->rect());
887 //log->info("going to draw tracking route...");
888 drawTrack(trackToSniff,&p, settings->getTrackToSniffColor());
890 if(mode==Mode_NewActivityMode){
891 //log->info("going to draw actual route...");
892 //log->debug(QString("num points track:%1").arg(track->getNumPoints()));
893 //log->debug("entering to drawTrack");
894 drawTrack(track,&p,settings->getTrackColor(),true);
899 //p.drawText(rect(), Qt::AlignBottom | Qt::TextWordWrap,"OpenStreetMap maps");
900 //log->debug("ending Paint event...");
902 //log->debug("done... and now?");
905 void WindowMap::drawFullTrackMaps(Track* track_p){
907 QList<GpsPoint*> gpsPoints = track_p->getGpsPoints();
908 //log->debug(QString("number of points to draw:%1").arg(gpsPoints.size()));
921 while(zoomToTrack>0 && !found){
924 //log->debug(QString("zoomToTrack:%1").arg(zoomToTrack));
925 for (int i = 0;!changeZoom && i < gpsPoints.size(); ++i) {
926 GpsPoint* point = gpsPoints.at(i);
927 QPointF ct = slippyMap->coordinate2tile(point->getLatitude(), point->getLongitude(), zoomToTrack);
929 //log->debug(QString("point %1: x=%2,y=%3").arg(i).arg(ct.x()).arg(ct.y()));
937 min_x = min(min_x,ct.x());
938 max_x = max(max_x,ct.x());
939 min_y = min(min_y,ct.y());
940 max_y = max(max_y,ct.y());
942 //log->debug(QString("min_x:%1, max_x:%2, min_y:%3, max_y:%4").arg(min_x).arg(max_x).arg(min_y).arg(max_y));
944 // if point is outside screen change zoom
945 qreal d_x=(max_x-min_x)*tdim;
946 qreal d_y=(max_y-min_y)*tdim;
947 //log->debug(QString("x distance:%1, y distance:%2").arg(d_x).arg(d_y));
948 //log->debug(QString("width-border*2=%1, height-border*2=%2").arg(width()-border*2).arg(height()-border*2));
949 if(d_x>(width()-border*2) || d_y>(height()-border*2)){
950 //log->debug("point outside screen, changezoom");
957 //log->debug(QString("all points are inside screen, zoom found: %1").arg(zoomToTrack));
961 qreal med_x=qreal(min_x+static_cast<qreal>(width())/(2.0*static_cast<qreal>(tdim)));
962 qreal med_y=qreal(min_y+static_cast<qreal>(height())/(2.0*static_cast<qreal>(tdim)));
964 qreal lng=slippyMap->tilex2long(med_x,zoomToTrack);
965 qreal lat=slippyMap->tiley2lat(med_y,zoomToTrack);
968 slippyMap->setZoom(zoom);
969 //log->debug(QString("changing zoom to:%1").arg(zoom));
970 //log->debug(QString("centering with x_med:%1,y_med:%2 ").arg(med_x).arg(med_y));
971 //log->debug(QString("centering with lat:%1,lng:%2 ").arg(lat).arg(lng));
974 //log->debug(QString("minx:%1, miny:%2").arg(min_x).arg(min_y));
975 topLeft=QPointF(min_x,min_y);
976 slippyMap->updateTiles(lat,lng);
980 bool WindowMap::drawTrack(Track* track_p, QPainter* p, QString color_s){
981 drawTrack(track_p,p,color_s,false);
984 bool WindowMap::drawTrack(Track* track_p, QPainter* p, QString color_s,bool lastPoint){
986 if (track_p!=NULL && track_p->getNumPoints()<=0){
987 log->debug("no points to draw...");
990 QColor color = QColor(color_s);
991 p->setBrush(QBrush(color));
992 QPen pen(color, 5, Qt::SolidLine);
997 QPointF previous=QPointF(0,0);
999 log->debug("going to get points...");
1000 //log->debug(QString("num:%1").arg(track_p->getNumPoints()));
1001 QList<GpsPoint*> points = track_p->getGpsPoints();
1002 log->debug(QString("drawing with zoom:%1").arg(zoom));
1003 //log->debug(QString("TopLeft x:%1, y:%2").arg(topLeft.x()).arg(topLeft.y()));
1004 for(int i = 0; i < points.size(); ++i){
1006 GpsPoint* point = points.at(i);
1007 QPointF ct = slippyMap->coordinate2tile(point->getLatitude(), point->getLongitude(), zoom);
1009 //log->debug(QString("point %1: x=%2,y=%3").arg(i).arg(ct.x()).arg(ct.y()));
1010 //log->debug(QString("topLeft.x:%1, topLeft.y:%2").arg(topLeft.x()).arg(topLeft.y()));
1011 qreal x_resized = (ct.x() - topLeft.x())*tdim + border;
1012 qreal y_resized = (ct.y() - topLeft.y())*tdim + border;
1013 QPointF resized = QPoint(x_resized,y_resized);
1014 //log->debug(QString("point resized: x=%1,y=%2").arg(resized.x()).arg(resized.y()));
1015 if(!previous.isNull() && previous!=ct &&
1016 (resized.x()>= 0 && resized.x()<=width() && resized.y()>=0 && resized.y() <= height())){
1017 //log->debug(QString("drawing line from: %1,%2 to %3,%4").arg(previous.x()).arg(previous.y()).arg(resized.x()).arg(resized.y()));
1018 p->drawLine(previous,resized);
1024 p->setBrush(QBrush(QColor(color_s)));
1025 p->drawEllipse(previous,10,10);
1026 p->setBrush(QBrush(Qt::black));
1027 p->drawEllipse(previous,7,7);
1033 void WindowMap::mousePressEvent(QMouseEvent *event) {
1037 if (event->buttons() != Qt::LeftButton)
1039 pressed = snapped = true;
1040 pressPos = dragPos = event->pos();
1042 possitionPaint=false;
1045 //tapTimer.start(HOLD_TIME, this);
1048 void WindowMap::mouseMoveEvent(QMouseEvent *event) {
1052 if (!event->buttons())
1055 //possitionPaint=false;
1057 if (!pressed || !snapped) {
1058 QPoint delta = event->pos() - pressPos;
1059 pressPos = event->pos();
1060 QPointF dx = QPointF(delta);
1062 //log->debug(QString("Changing topleft, from %1,%2").arg(topLeft.x()).arg(topLeft.y()));
1063 //log->debug(QString("distance changed: x=%1,y=%2").arg(dx.x()).arg(dx.y()));
1064 topLeft = topLeft -dx/tdim;
1065 //log->debug(QString("to %1,%2").arg(topLeft.x()).arg(topLeft.y()));
1066 //topLeft = QPoint(delta.x()-width()/2,delta.y()-height()/2);
1067 slippyMap->pan(delta);
1071 const int threshold = 10;
1072 QPoint delta = event->pos() - pressPos;
1074 snapped &= delta.x() < threshold;
1075 snapped &= delta.y() < threshold;
1076 snapped &= delta.x() > -threshold;
1077 snapped &= delta.y() > -threshold;
1084 void WindowMap::mouseReleaseEvent(QMouseEvent *) {
1087 desactivatePossitionPaint();
1092 void WindowMap::fixZoomButtons(){
1094 if(settings->getIsConfigured()){
1095 int x_in=(width()-zoomInButton->width());
1096 int y_in=(height()/2-zoomInButton->height()/2);
1097 //log->debug(QString("ZoomIn possition: x=%1,y=%2").arg(x_in).arg(y_in));
1100 int y_out=(height()/2-zoomOutButton->height()/2);
1101 //log->debug(QString("ZoomOut possition: x=%1,y=%2").arg(x_out).arg(y_out));
1103 zoomInButton->move(x_in,y_in);
1104 zoomOutButton->move(x_out,y_out);
1105 zoomInButton->show();
1106 zoomOutButton->show();
1111 void WindowMap::resizeEvent(QResizeEvent * /* event */)
1117 int x = width() - (zoomInButton->width()
1118 + zoomOutButton->width() + 10);
1119 zoomInButton->move(x, 5);
1120 zoomOutButton->move(x + zoomInButton->width() + 5, 5);
1126 /* QString activity;