SVN checkout 11/12/2010
[monav:monav.git] / client / mapview.cpp
1 /*
2 Copyright 2010  Christian Vetter veaac.fdirct@gmail.com
3
4 This file is part of MoNav.
5
6 MoNav is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 MoNav is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with MoNav.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "mapview.h"
21 #include "ui_mapview.h"
22 #include "addressdialog.h"
23 #include "bookmarksdialog.h"
24 #include "mapdatawidget.h"
25 #include "mapdata.h"
26 #include "routinglogic.h"
27 #include "routedescriptiondialog.h"
28 #include "gpsdialog.h"
29
30 #include <QtDebug>
31 #include <QInputDialog>
32 #include <QSettings>
33 #include <QGridLayout>
34 #include <QResizeEvent>
35 #include <QMessageBox>
36 #include <QStyle>
37 #include <QScrollArea>
38
39 #ifdef Q_WS_MAEMO_5
40 #include "fullscreenexitbutton.h"
41 #include <QtGui/QX11Info>
42 #include <X11/Xlib.h>
43 #include <X11/Xatom.h>
44 #endif
45
46 MapView::MapView( QWidget *parent ) :
47                 QDialog(parent, Qt::Window ),
48                 m_ui(new Ui::MapView)
49 {
50         m_ui->setupUi(this);
51
52         this->setWindowIcon( QIcon( ":/images/source.png" ) );
53
54         m_ui->zoomBar->hide();
55
56         // ensure that we're painting our background
57         setAutoFillBackground(true);
58
59         m_mode = NoSelection;
60         m_fixed = false;
61
62         setupMenu();
63         m_ui->headerWidget->hide();
64         m_ui->infoWidget->hide();
65
66         QSettings settings( "MoNavClient" );
67         settings.beginGroup( "MapView" );
68         m_virtualZoom = settings.value( "virtualZoom", 1 ).toInt();
69         if ( settings.contains( "geometry") )
70                 setGeometry( settings.value( "geometry" ).toRect() );
71         m_menuMode = settings.value( "useMenus", false ).toBool() ? GeneralSettingsDialog::MenuPopup : GeneralSettingsDialog::MenuOverlay;
72
73         connectSlots();
74
75         if ( MapData::instance()->loaded() )
76                 dataLoaded();
77         else
78                 settingsDataDirectory();
79
80         m_customIconSize = settings.value( "customIconSize", false ).toBool();
81         m_defaultIconSize = QApplication::style()->pixelMetric( QStyle::PM_ToolBarIconSize );
82         m_iconSize = settings.value( "iconSize", m_defaultIconSize ).toInt();
83
84         resizeIcons();
85
86 #ifdef Q_WS_MAEMO_5
87         setAttribute( Qt::WA_Maemo5StackedWindow );
88         grabZoomKeys( true );
89         new FullScreenExitButton(this);
90         showFullScreen();
91 #endif
92
93 }
94
95 MapView::~MapView()
96 {
97         QSettings settings( "MoNavClient" );
98         settings.beginGroup( "MapView" );
99         settings.setValue( "virtualZoom", m_virtualZoom );
100         settings.setValue( "geometry", geometry() );
101         settings.setValue( "iconSize", m_iconSize );
102         settings.setValue( "customIconSize", m_customIconSize );
103         settings.setValue( "useMenus", m_menuMode == GeneralSettingsDialog::MenuPopup );
104
105         delete m_ui;
106 }
107
108 void MapView::connectSlots()
109 {
110         connect( m_ui->zoomBar, SIGNAL(valueChanged(int)), m_ui->paintArea, SLOT(setZoom(int)) );
111         connect( m_ui->paintArea, SIGNAL(zoomChanged(int)), m_ui->zoomBar, SLOT(setValue(int)) );
112         connect( m_ui->paintArea, SIGNAL(mouseClicked(ProjectedCoordinate)), this, SLOT(mouseClicked(ProjectedCoordinate)) );
113         connect( m_ui->previousButton, SIGNAL(clicked()), this, SLOT(previousPlace()) );
114         connect( m_ui->nextButton, SIGNAL(clicked()), this, SLOT(nextPlace()) );
115         connect( m_ui->paintArea, SIGNAL(contextMenu(QPoint)), this, SLOT(showContextMenu(QPoint)) );
116         connect( m_ui->zoomIn, SIGNAL(clicked()), this, SLOT(addZoom()) );
117         connect( m_ui->zoomOut, SIGNAL(clicked()), this, SLOT(substractZoom()) );
118
119         connect( m_ui->infoIcon1, SIGNAL(clicked()), this, SLOT(showInstructions()) );
120         connect( m_ui->infoIcon2, SIGNAL(clicked()), this, SLOT(showInstructions()) );
121
122         connect( MapData::instance(), SIGNAL(dataLoaded()), this, SLOT(dataLoaded()) );
123         connect( RoutingLogic::instance(), SIGNAL(instructionsChanged()), this, SLOT(instructionsChanged()) );
124         connect( m_ui->lockButton, SIGNAL(clicked()), this, SLOT(toogleLocked()) );
125
126         connect( m_ui->show, SIGNAL(clicked()), this, SLOT(gotoMenu()) );
127         connect( m_ui->tools, SIGNAL(clicked()), this, SLOT(toolsMenu()) );
128         connect( m_ui->settings, SIGNAL(clicked()), this, SLOT(settingsMenu()) );
129         connect( m_ui->source, SIGNAL(clicked()), this, SLOT(sourceMenu()) );
130         connect( m_ui->target, SIGNAL(clicked()), this, SLOT(targetMenu()) );
131 }
132
133 void MapView::setupMenu()
134 {
135         m_gotoMenu = new QMenu( tr( "Show" ), this );
136         m_gotoGPSAction = m_gotoMenu->addAction( QIcon( ":/images/oxygen/network-wireless.png" ), tr( "GPS-Location" ), this, SLOT(gotoGPS()) );
137         m_gotoSourceAction = m_gotoMenu->addAction( QIcon( ":/images/source.png" ), tr( "Departure" ), this, SLOT(gotoSource()) );
138         m_gotoTargetAction = m_gotoMenu->addAction( QIcon( ":/images/target.png" ), tr( "Destination" ), this, SLOT(gotoTarget()) );
139         m_gotoBookmarkAction = m_gotoMenu->addAction( QIcon( ":/images/oxygen/bookmarks.png" ), tr( "Bookmark" ), this, SLOT(gotoBookmark()) );
140         m_gotoAddressAction = m_gotoMenu->addAction( QIcon( ":/images/address.png" ), tr( "Address" ), this, SLOT(gotoAddress()) );
141
142         m_gotoOverlay = new OverlayWidget( this, tr( "Show" ) );
143         m_gotoOverlay->addActions( m_gotoMenu->actions() );
144
145         m_sourceMenu = new QMenu( tr( "Departure" ), this );
146         m_sourceByTapAction = m_sourceMenu->addAction( QIcon( ":/images/map.png" ), tr( "Tap on Map" ), this, SLOT(setModeSourceSelection()) );
147         m_sourceByBookmarkAction = m_sourceMenu->addAction( QIcon( ":/images/oxygen/bookmarks.png" ), tr( "Bookmark" ), this, SLOT(sourceByBookmark()) );
148         m_sourceByAddressAction = m_sourceMenu->addAction( QIcon( ":/images/address.png" ), tr( "Address" ), this, SLOT(sourceByAddress()) );
149         m_sourceByAddressAction = m_sourceMenu->addAction( QIcon( ":/images/oxygen/network-wireless.png" ), tr( "GPS Reciever" ), this, SLOT(sourceByGPS()) );
150
151         m_sourceOverlay = new OverlayWidget( this, tr( "Departure" ) );
152         m_sourceOverlay->addActions( m_sourceMenu->actions() );
153
154         m_targetMenu = new QMenu( tr( "Destination" ), this );
155         m_targetByTapAction = m_targetMenu->addAction( QIcon( ":/images/map.png" ), tr( "Tap on Map" ), this, SLOT(setModeTargetSelection()) );
156         m_targetByBookmarkAction = m_targetMenu->addAction( QIcon( ":/images/oxygen/bookmarks.png" ), tr( "Bookmark" ), this, SLOT(targetByBookmark()) );
157         m_targetByAddressAction = m_targetMenu->addAction( QIcon( ":/images/address.png" ), tr( "Address" ), this, SLOT(targetByAddress()) );
158
159         m_targetOverlay = new OverlayWidget( this, tr( "Destination" ) );
160         m_targetOverlay->addActions( m_targetMenu->actions() );
161
162         m_toolsMenu = new QMenu( tr( "Tools" ), this );
163         m_bookmarkAction = m_toolsMenu->addAction( QIcon( ":/images/oxygen/bookmarks.png" ), tr( "Bookmarks" ), this, SLOT(bookmarks()) );
164         m_magnifyAction = m_toolsMenu->addAction( QIcon( ":/images/oxygen/zoom-in.png" ), tr( "Magnify" ), this, SLOT(magnify()) );
165
166         m_toolsOverlay = new OverlayWidget( this, tr( "Tools" ) );
167         m_toolsOverlay->addActions( m_toolsMenu->actions() );
168
169         m_settingsMenu = new QMenu( tr( "Settings" ), this );
170         m_settingsDataDirectory = m_settingsMenu->addAction( QIcon( ":/images/oxygen/folder-tar.png" ), tr( "Map Data" ), this, SLOT(settingsDataDirectory()) );
171         m_settingsGeneral = m_settingsMenu->addAction( QIcon( ":/images/oxygen/preferences-system.png" ), tr( "General" ), this, SLOT(settingsGeneral()) );
172         m_settingsGPSLookup = m_settingsMenu->addAction( QIcon( ":/images/oxygen/network-wireless.png" ), tr( "GPS Lookup" ), this, SLOT(settingsGPSLookup()) );
173         m_settingsRenderer = m_settingsMenu->addAction( QIcon( ":/images/map.png" ), tr( "Renderer" ), this, SLOT(settingsRenderer()) );
174         m_settingsRouter = m_settingsMenu->addAction( QIcon( ":/images/route.png" ), tr( "Router" ), this, SLOT(settingsRouter()) );
175         m_settingsAddressLookup = m_settingsMenu->addAction( QIcon( ":/images/address.png" ), tr( "Address Lookup" ), this, SLOT(settingsAddressLookup()) );
176         m_settingsGPS = m_settingsMenu->addAction( QIcon( ":/images/oxygen/hwinfo.png" ), tr( "GPS Reciever" ), this, SLOT(settingsGPS()) );
177
178         m_settingsOverlay = new OverlayWidget( this, tr( "Settings" ) );
179         m_settingsOverlay->addActions( m_settingsMenu->actions() );
180 }
181
182 void MapView::resizeIcons()
183 {
184         if ( !m_customIconSize )
185                 m_iconSize = m_defaultIconSize;
186         foreach ( QToolButton* button, this->findChildren< QToolButton* >() )
187                 button->setIconSize( QSize( m_iconSize, m_iconSize ) );
188         foreach ( QToolBar* button, this->findChildren< QToolBar* >() )
189                 button->setIconSize( QSize( m_iconSize, m_iconSize ) );
190         foreach ( QScrollArea* scrollArea, this->findChildren< QScrollArea* >() )
191                 scrollArea->resize( scrollArea->widget()->sizeHint() );
192 }
193
194 void MapView::showInstructions()
195 {
196         RouteDescriptionDialog* window = new RouteDescriptionDialog( this );
197         window->exec();
198         delete window;
199 }
200
201 void MapView::settingsGeneral()
202 {
203         GeneralSettingsDialog* window = new GeneralSettingsDialog;
204         window->setIconSize( m_iconSize );
205         window->setCustomIconSize( m_customIconSize );
206         window->setMenuMode( m_menuMode );
207         window->exec();
208         m_iconSize = window->iconSize();
209         m_customIconSize = window->customIconSize();
210         m_menuMode = window->menuMode();
211         delete window;
212         resizeIcons();
213 }
214
215 void MapView::settingsRenderer()
216 {
217         IRenderer* renderer = MapData::instance()->renderer();
218         if ( renderer != NULL )
219                 renderer->ShowSettings();
220 }
221
222 void MapView::settingsRouter()
223 {
224         IRouter* router = MapData::instance()->router();
225         if ( router != NULL )
226                 router->ShowSettings();
227 }
228
229 void MapView::settingsGPSLookup()
230 {
231         IGPSLookup* gpsLookup = MapData::instance()->gpsLookup();
232         if( gpsLookup != NULL )
233                 gpsLookup->ShowSettings();
234 }
235
236 void MapView::settingsAddressLookup()
237 {
238         IAddressLookup* addressLookup = MapData::instance()->addressLookup();
239         if ( addressLookup != NULL )
240                 addressLookup->ShowSettings();
241 }
242
243 void MapView::settingsGPS()
244 {
245         GPSDialog* window = new GPSDialog( this );
246         window->exec();
247         delete window;
248 }
249
250 void MapView::settingsDataDirectory()
251 {
252         MapDataWidget* window = new MapDataWidget( this );
253         window->exec( true );
254         if ( !MapData::instance()->loaded() ) {
255                 QMessageBox::information( this, "Map Data", "No Data Directory Specified" );
256                 QApplication::closeAllWindows();
257         }
258         delete window;
259 }
260
261 void MapView::gotoMenu()
262 {
263         if ( m_menuMode == GeneralSettingsDialog::MenuPopup ) {
264                 QPoint position = m_ui->show->mapToGlobal( QPoint( m_ui->show->width() / 2, m_ui->show->height() / 2 ) );
265                 m_gotoMenu->exec( position );
266         } else {
267                 m_gotoOverlay->show();
268         }
269 }
270
271 void MapView::toolsMenu()
272 {
273         if ( m_menuMode == GeneralSettingsDialog::MenuPopup ) {
274                 QPoint position = m_ui->tools->mapToGlobal( QPoint( m_ui->tools->width() / 2, m_ui->tools->height() / 2 ) );
275                 m_toolsMenu->exec( position );
276         } else {
277                 m_toolsOverlay->show();
278         }
279 }
280
281 void MapView::settingsMenu()
282 {
283         if ( m_menuMode == GeneralSettingsDialog::MenuPopup ) {
284                 QPoint position = m_ui->settings->mapToGlobal( QPoint( m_ui->settings->width() / 2, m_ui->settings->height() / 2 ) );
285                 m_settingsMenu->exec( position );
286         } else {
287                 m_settingsOverlay->show();
288         }
289 }
290
291 void MapView::sourceMenu()
292 {
293         if ( m_menuMode == GeneralSettingsDialog::MenuPopup ) {
294                 QPoint position = m_ui->source->mapToGlobal( QPoint( m_ui->source->width() / 2, m_ui->source->height() / 2 ) );
295                 m_sourceMenu->exec( position );
296         } else {
297                 m_sourceOverlay->show();
298         }
299 }
300 void MapView::targetMenu()
301 {
302         if ( m_menuMode == GeneralSettingsDialog::MenuPopup ) {
303                 QPoint position = m_ui->target->mapToGlobal( QPoint( m_ui->target->width() / 2, m_ui->target->height() / 2 ) );
304                 m_targetMenu->exec( position );
305         } else {
306                 m_targetOverlay->show();
307         }
308 }
309
310 void MapView::resizeEvent( QResizeEvent* event )
311 {
312         QBoxLayout* box = qobject_cast< QBoxLayout* >( m_ui->infoWidget->layout() );
313         assert ( box != NULL );
314         if ( event->size().width() > event->size().height() )
315                 box->setDirection( QBoxLayout::LeftToRight );
316         else
317                 box->setDirection( QBoxLayout::TopToBottom );
318 }
319
320 #ifdef Q_WS_MAEMO_5
321 void MapView::grabZoomKeys(bool grab)
322 {
323         if ( !winId() ) {
324                 qWarning() << "Can't grab keys unless we have a window id";
325                 return;
326         }
327
328         unsigned long val = ( grab ) ? 1 : 0;
329         Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
330         if ( !atom ) {
331                 qWarning() << "Unable to obtain _HILDON_ZOOM_KEY_ATOM. This will only work on a Maemo 5 device!";
332                 return;
333         }
334
335         XChangeProperty ( QX11Info::display(),
336                                                         winId(),
337                                                         atom,
338                                                         XA_INTEGER,
339                                                         32,
340                                                         PropModeReplace,
341                                                         reinterpret_cast< unsigned char* >( &val ),
342                                                         1 );
343 }
344
345 void MapView::keyPressEvent( QKeyEvent* event )
346 {
347         switch (event->key()) {
348         case Qt::Key_F7:
349                 addZoom();
350                 event->accept();
351                 break;
352
353         case Qt::Key_F8:
354                 this->substractZoom();
355                 event->accept();
356                 break;
357         }
358         QWidget::keyPressEvent(event);
359 }
360
361 #endif
362
363 void MapView::dataLoaded()
364 {
365         IRenderer* renderer = MapData::instance()->renderer();
366         if ( renderer == NULL )
367                 return;
368
369         m_maxZoom = renderer->GetMaxZoom();
370         m_ui->zoomBar->setMaximum( m_maxZoom );
371         m_ui->zoomBar->setValue( m_maxZoom );
372         m_ui->paintArea->setMaxZoom( m_maxZoom );
373         m_ui->paintArea->setZoom( m_maxZoom );
374         m_ui->paintArea->setVirtualZoom( m_virtualZoom );
375         m_ui->paintArea->setCenter( RoutingLogic::instance()->source().ToProjectedCoordinate() );
376 }
377
378 void MapView::setModeSourceSelection()
379 {
380         m_mode = Source;
381 }
382
383 void MapView::setModeTargetSelection()
384 {
385         m_mode = Target;
386 }
387
388 void MapView::setModePOISelection()
389 {
390         m_mode = POI;
391 }
392
393 void MapView::setModeNoSelection()
394 {
395         m_mode = NoSelection;
396 }
397
398 void MapView::instructionsChanged()
399 {
400         if ( !m_fixed )
401                 return;
402
403         QStringList label;
404         QStringList icon;
405
406         RoutingLogic::instance()->instructions( &label, &icon, 60 );
407
408         m_ui->infoWidget->setHidden( label.empty() );
409
410         if ( label.isEmpty() )
411                 return;
412
413         m_ui->infoLabel1->setText( label[0] );
414         m_ui->infoIcon1->setIcon( QIcon( icon[0] ) );
415
416         m_ui->infoIcon2->setHidden( label.size() == 1 );
417         m_ui->infoLabel2->setHidden( label.size() == 1 );
418
419         if ( label.size() == 1 )
420                 return;
421
422         m_ui->infoLabel2->setText( label[1] );
423         m_ui->infoIcon2->setIcon( QIcon( icon[1] ) );
424 }
425
426 void MapView::mouseClicked( ProjectedCoordinate clickPos )
427 {
428         UnsignedCoordinate coordinate( clickPos );
429         if ( m_mode == Source ) {
430                 RoutingLogic::instance()->setSource( coordinate );
431         } else if ( m_mode == Target ) {
432                 RoutingLogic::instance()->setTarget( coordinate );
433         } else if ( m_mode == POI ){
434                 m_selected = coordinate;
435                 m_ui->paintArea->setPOI( coordinate );
436                 return;
437         }
438
439         //m_mode = None; // might be contra-productiv for some use cases. E.g., many new users just want to click around the map and wonder about the blazingly fast routing *g*
440 }
441
442 void MapView::nextPlace()
443 {
444         m_place = ( m_place + 1 ) % m_places.size();
445         m_ui->headerLabel->setText( QString( tr( "Choose City (%1/%2)" ) ).arg( m_place + 1 ).arg( m_places.size() ) );
446         m_ui->paintArea->setCenter( m_places[m_place].ToProjectedCoordinate() );
447 }
448
449 void MapView::previousPlace()
450 {
451         m_place = ( m_place + m_places.size() - 1 ) % m_places.size();
452         m_ui->headerLabel->setText( QString( tr( "Choose City (%1/%2)" ) ).arg( m_place + 1 ).arg( m_places.size() ) );
453         m_ui->paintArea->setCenter( m_places[m_place].ToProjectedCoordinate() );
454 }
455
456 int MapView::selectPlaces( QVector< UnsignedCoordinate > places, QWidget* p )
457 {
458         if ( places.size() == 0 )
459                 return -1;
460
461         MapView* window = new MapView( p );
462         window->setPlaces( places );
463
464         int value = window->exec();
465         int id = -1;
466         if ( value == Accepted )
467                 id = window->m_place;
468         delete window;
469
470         return id;
471 }
472
473 void MapView::setPlaces( QVector< UnsignedCoordinate > p )
474 {
475         m_places = p;
476         m_place = 0;
477
478         m_ui->headerLabel->setText( QString( tr( "Choose City (%1/%2)" ) ).arg( 1 ).arg( p.size() ) );
479         m_ui->headerWidget->show();
480         m_ui->lockWidget->hide();
481         m_ui->waypointsWidget->hide();
482         m_ui->menuWidget->hide();
483
484         m_ui->paintArea->setCenter( m_places.first().ToProjectedCoordinate() );
485         m_ui->paintArea->setPOIs( p );
486 }
487
488 bool MapView::selectStreet( UnsignedCoordinate* result, QVector< int >segmentLength, QVector< UnsignedCoordinate > coordinates, QWidget* p )
489 {
490         if ( result == NULL )
491                 return false;
492         if ( segmentLength.size() == 0 )
493                 return false;
494         if ( coordinates.size() == 0 )
495                 return false;
496
497         MapView* window = new MapView( p );
498         window->setEdges( segmentLength, coordinates );
499         window->setModePOISelection();
500
501         int value = window->exec();
502
503         if ( value == Accepted )
504                 *result = window->m_selected;
505         delete window;
506
507         return value == Accepted;
508 }
509
510 void MapView::setEdges( QVector< int > segmentLength, QVector< UnsignedCoordinate > coordinates )
511 {
512         m_ui->headerLabel->setText( tr( "Choose Coordinate" ) );
513         m_ui->headerWidget->show();
514         m_ui->nextButton->hide();
515         m_ui->previousButton->hide();
516         m_ui->lockWidget->hide();
517         m_ui->waypointsWidget->hide();
518         m_ui->menuWidget->hide();
519
520         ProjectedCoordinate center = coordinates[coordinates.size()/2].ToProjectedCoordinate();
521
522         m_ui->paintArea->setCenter( center );
523         m_ui->paintArea->setEdges( segmentLength, coordinates );
524
525         UnsignedCoordinate centerPos( center );
526         m_selected = centerPos;
527         m_ui->paintArea->setPOI( centerPos );
528 }
529
530 void MapView::showContextMenu( QPoint /*globalPos*/ )
531 {
532 }
533
534 void MapView::gotoSource()
535 {
536         UnsignedCoordinate coordinate = RoutingLogic::instance()->source();
537         if ( !coordinate.IsValid() )
538                 return;
539         m_ui->paintArea->setCenter( coordinate.ToProjectedCoordinate() );
540         m_ui->paintArea->setZoom( m_maxZoom );
541 }
542
543 void MapView::gotoGPS()
544 {
545         bool ok = false;
546         double latitude = QInputDialog::getDouble( this, "Enter Coordinate", "Enter Latitude", 0, -90, 90, 5, &ok );
547         if ( !ok )
548                 return;
549         double longitude = QInputDialog::getDouble( this, "Enter Coordinate", "Enter Latitude", 0, -180, 180, 5, &ok );
550         if ( !ok )
551                 return;
552         GPSCoordinate gps( latitude, longitude );
553         m_ui->paintArea->setCenter( ProjectedCoordinate( gps ) );
554         m_ui->paintArea->setZoom( m_maxZoom );
555 }
556
557 void MapView::gotoTarget()
558 {
559         UnsignedCoordinate coordinate = RoutingLogic::instance()->target();
560         if ( !coordinate.IsValid() )
561                 return;
562         m_ui->paintArea->setCenter( coordinate.ToProjectedCoordinate() );
563         m_ui->paintArea->setZoom( m_maxZoom );
564 }
565
566 void MapView::gotoBookmark()
567 {
568         UnsignedCoordinate result;
569         if ( !BookmarksDialog::showBookmarks( &result, this ) )
570                 return;
571         m_ui->paintArea->setCenter( result.ToProjectedCoordinate() );
572 }
573
574 void MapView::gotoAddress()
575 {
576         if ( MapData::instance()->addressLookup() == NULL )
577                 return;
578         UnsignedCoordinate result;
579         if ( !AddressDialog::getAddress( &result, this, true ) )
580                 return;
581         m_ui->paintArea->setCenter( result.ToProjectedCoordinate() );
582 }
583
584 void MapView::sourceByBookmark()
585 {
586         UnsignedCoordinate result;
587         if ( !BookmarksDialog::showBookmarks( &result, this ) )
588                 return;
589         RoutingLogic::instance()->setSource( result );
590         m_ui->paintArea->setCenter( result.ToProjectedCoordinate() );
591 }
592
593 void MapView::sourceByAddress()
594 {
595         if ( MapData::instance()->addressLookup() == NULL )
596                 return;
597         UnsignedCoordinate result;
598         if ( !AddressDialog::getAddress( &result, this ) )
599                 return;
600         RoutingLogic::instance()->setSource( result );
601         m_ui->paintArea->setCenter( result.ToProjectedCoordinate() );
602 }
603
604 void MapView::sourceByGPS()
605 {
606         RoutingLogic::instance()->setGPSLink( true );
607 }
608
609 void MapView::targetByBookmark()
610 {
611         UnsignedCoordinate result;
612         if ( !BookmarksDialog::showBookmarks( &result, this ) )
613                 return;
614         RoutingLogic::instance()->setTarget( result );
615         m_ui->paintArea->setCenter( result.ToProjectedCoordinate() );
616 }
617
618 void MapView::targetByAddress()
619 {
620         if ( MapData::instance()->addressLookup() == NULL )
621                 return;
622         UnsignedCoordinate result;
623         if ( !AddressDialog::getAddress( &result, this ) )
624                 return;
625         RoutingLogic::instance()->setTarget( result );
626         m_ui->paintArea->setCenter( result.ToProjectedCoordinate() );
627 }
628
629 void MapView::bookmarks()
630 {
631         UnsignedCoordinate result;
632         if ( !BookmarksDialog::showBookmarks( &result, this ) )
633                 return;
634
635         m_ui->paintArea->setCenter( result.ToProjectedCoordinate() );
636 }
637
638 void MapView::addZoom()
639 {
640         m_ui->zoomBar->triggerAction( QAbstractSlider::SliderSingleStepAdd );
641 }
642
643 void MapView::substractZoom()
644 {
645         m_ui->zoomBar->triggerAction( QAbstractSlider::SliderSingleStepSub );
646 }
647
648 void MapView::magnify()
649 {
650         bool ok = false;
651         int result = QInputDialog::getInt( this, "Magnification", "Enter Factor", m_virtualZoom, 1, 10, 1, &ok );
652         if ( !ok )
653                 return;
654         m_virtualZoom = result;
655         m_ui->paintArea->setVirtualZoom( m_virtualZoom );
656 }
657
658 void MapView::toogleLocked()
659 {
660         m_fixed = !m_fixed;
661         m_ui->paintArea->setFixed( m_fixed );
662         if ( m_fixed ) {
663                 m_ui->lockButton->setIcon( QIcon( ":images/oxygen/emblem-locked.png") );
664                 instructionsChanged();
665         } else {
666                 m_ui->lockButton->setIcon( QIcon( ":images/oxygen/emblem-unlocked.png") );
667                 m_ui->infoWidget->hide();
668         }
669 }
670