File indexing completed on 2024-04-21 03:49:39

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2004-2007 Torsten Rahn <tackat@kde.org>
0004 // SPDX-FileCopyrightText: 2007 Inge Wallin <ingwa@kde.org>
0005 // SPDX-FileCopyrightText: 2007 Thomas Zander <zander@kde.org>
0006 // SPDX-FileCopyrightText: 2010 Bastian Holst <bastianholst@gmx.de>
0007 // SPDX-FileCopyrightText: 2011-2013 Bernhard Beschow <bbeschow@cs.tu-berlin.de>
0008 // SPDX-FileCopyrightText: 2012 Illya Kovalevskyy <illya.kovalevskyy@gmail.com>
0009 //
0010 
0011 // Self
0012 #include "MapViewWidget.h"
0013 
0014 // Marble
0015 #include "MarbleDebug.h"
0016 #include "MarbleDirs.h"
0017 #include "MarbleWidget.h"
0018 #include "MarbleModel.h"
0019 #include "MapThemeManager.h"
0020 #include "MapThemeSortFilterProxyModel.h"
0021 #include "GeoSceneDocument.h"
0022 #include "GeoSceneHead.h"
0023 #include "MapViewItemDelegate.h"
0024 #include "CelestialSortFilterProxyModel.h"
0025 
0026 // Qt
0027 #include <QResizeEvent>
0028 #include <QFileInfo>
0029 #include <QSettings>
0030 #include <QMenu>
0031 #include <QMessageBox>
0032 #include <QStandardItemModel>
0033 #include <QGridLayout>
0034 #include <QPainter>
0035 #include <QToolBar>
0036 #include <QToolButton>
0037 #include <QDateTime>
0038 
0039 using namespace Marble;
0040 // Ui
0041 #include "ui_MapViewWidget.h"
0042 
0043 namespace Marble
0044 {
0045 
0046 class Q_DECL_HIDDEN MapViewWidget::Private {
0047  public:
0048     Private( MapViewWidget *parent )
0049         : q( parent ),
0050           m_marbleModel( nullptr ),
0051           m_mapSortProxy(),
0052           m_celestialListProxy(),
0053           m_toolBar( nullptr ),
0054           m_globeViewButton( nullptr ),
0055           m_mercatorViewButton( nullptr ),
0056           m_popupMenuFlat( nullptr ),
0057           m_flatViewAction( nullptr ),
0058           m_mercatorViewAction( nullptr ),
0059           m_celestialBodyAction( nullptr ),
0060           m_gnomonicViewAction( nullptr ),
0061           m_stereographicViewAction( nullptr ),
0062           m_lambertAzimuthalViewAction( nullptr ),
0063           m_azimuthalEquidistantViewAction( nullptr ),
0064           m_verticalPerspectiveViewAction( nullptr ),
0065           m_globeViewAction( nullptr ),
0066           m_mapViewDelegate(nullptr)
0067     {
0068         m_mapSortProxy.setDynamicSortFilter( true );
0069         m_celestialListProxy.setDynamicSortFilter( true );
0070     }
0071 
0072     ~Private()
0073     {
0074         delete m_mapViewDelegate;
0075     }
0076 
0077     void applyExtendedLayout()
0078     {
0079         m_mapViewUi.projectionLabel_2->setVisible(true);
0080         m_mapViewUi.celestialBodyLabel->setVisible(true);
0081         m_mapViewUi.projectionComboBox->setVisible(true);
0082         m_mapViewUi.mapThemeLabel->setVisible(true);
0083         m_mapViewUi.line->setVisible(true);
0084 
0085         m_toolBar->setVisible(false);
0086         const int labelId = m_mapViewUi.verticalLayout->indexOf(m_mapViewUi.celestialBodyLabel);
0087         m_mapViewUi.verticalLayout->insertWidget(labelId+1, m_mapViewUi.celestialBodyComboBox);
0088         m_toolBar->removeAction(m_celestialBodyAction);
0089         m_mapViewUi.celestialBodyComboBox->show();
0090     }
0091 
0092     void applyReducedLayout()
0093     {
0094         m_mapViewUi.projectionLabel_2->setVisible(false);
0095         m_mapViewUi.celestialBodyLabel->setVisible(false);
0096         m_mapViewUi.projectionComboBox->setVisible(false);
0097         m_mapViewUi.mapThemeLabel->setVisible(false);
0098         m_mapViewUi.line->setVisible(false);
0099 
0100         m_toolBar->setVisible(true);
0101         m_celestialBodyAction = m_toolBar->addWidget(m_mapViewUi.celestialBodyComboBox);
0102         m_mapViewUi.verticalLayout->removeWidget(m_mapViewUi.celestialBodyComboBox);
0103         m_mapViewUi.celestialBodyComboBox->show();
0104     }
0105 
0106     void setupToolBar()
0107     {
0108         m_toolBar = new QToolBar;
0109 
0110         m_globeViewButton = new QToolButton;
0111         m_globeViewButton->setIcon(QIcon(QStringLiteral(":/icons/map-globe.png")));
0112         m_globeViewButton->setToolTip( tr("Globe View") );
0113         m_globeViewButton->setCheckable(true);
0114         m_globeViewButton->setChecked(false);
0115 
0116         m_globeViewAction = new QAction(QIcon(QStringLiteral(":/icons/map-globe.png")),
0117                                              tr( "Spherical view" ),
0118                                              m_globeViewButton );
0119         m_globeViewAction->setCheckable( true );
0120         m_globeViewAction->setChecked( false );
0121 
0122         m_mercatorViewButton = new QToolButton;
0123         m_mercatorViewButton->setIcon(QIcon(QStringLiteral(":/icons/map-mercator.png")));
0124         m_mercatorViewButton->setToolTip( tr("Mercator View") );
0125         m_mercatorViewButton->setCheckable(true);
0126         m_mercatorViewButton->setChecked(false);
0127         m_mercatorViewButton->setPopupMode(QToolButton::MenuButtonPopup);
0128 
0129         m_popupMenuFlat = new QMenu(q);
0130 
0131         m_mercatorViewAction = new QAction(QIcon(QStringLiteral(":/icons/map-mercator.png")),
0132                                               tr("Mercator View"),
0133                                               m_popupMenuFlat );
0134         m_mercatorViewAction->setCheckable(true);
0135         m_mercatorViewAction->setChecked(false);
0136 
0137         m_flatViewAction = new QAction( QIcon(QStringLiteral(":/icons/map-flat.png")),
0138                                         tr("Flat View"),
0139                                         m_popupMenuFlat );
0140         m_flatViewAction->setCheckable(true);
0141         m_flatViewAction->setChecked(false);
0142 
0143         m_gnomonicViewAction = new QAction( QIcon(QStringLiteral(":/icons/map-gnomonic.png")),
0144                                             tr( "Gnomonic view" ),
0145                                             m_popupMenuFlat);
0146         m_gnomonicViewAction->setCheckable( true );
0147         m_gnomonicViewAction->setChecked( false );
0148 
0149         m_stereographicViewAction = new QAction(QIcon(QStringLiteral(":/icons/map-globe.png")),
0150                                             tr( "Stereographic view" ),
0151                                             m_popupMenuFlat);
0152         m_stereographicViewAction->setCheckable( true );
0153         m_stereographicViewAction->setChecked( false );
0154 
0155         m_lambertAzimuthalViewAction = new QAction(QIcon(QStringLiteral(":/icons/map-globe.png")),
0156                                             tr( "Lambert Azimuthal Equal-Area view" ),
0157                                             m_popupMenuFlat);
0158         m_lambertAzimuthalViewAction->setCheckable( true );
0159         m_lambertAzimuthalViewAction->setChecked( false );
0160 
0161         m_azimuthalEquidistantViewAction = new QAction(QIcon(QStringLiteral(":/icons/map-globe.png")),
0162                                             tr( "Azimuthal Equidistant view" ),
0163                                             m_popupMenuFlat);
0164         m_azimuthalEquidistantViewAction->setCheckable( true );
0165         m_azimuthalEquidistantViewAction->setChecked( false );
0166 
0167         m_verticalPerspectiveViewAction = new QAction(QIcon(QStringLiteral(":/icons/map-globe.png")),
0168                                             tr( "Perspective Globe view" ),
0169                                             m_popupMenuFlat);
0170         m_verticalPerspectiveViewAction->setCheckable( true );
0171         m_verticalPerspectiveViewAction->setChecked( false );
0172 
0173 
0174         m_popupMenuFlat->addAction(m_mercatorViewAction);
0175         m_popupMenuFlat->addAction(m_flatViewAction);
0176         m_popupMenuFlat->addAction(m_gnomonicViewAction);
0177         m_popupMenuFlat->addAction(m_stereographicViewAction);
0178         m_popupMenuFlat->addAction(m_lambertAzimuthalViewAction);
0179         m_popupMenuFlat->addAction(m_azimuthalEquidistantViewAction);
0180         m_popupMenuFlat->addAction(m_verticalPerspectiveViewAction);
0181         m_mercatorViewButton->setMenu(m_popupMenuFlat);
0182 
0183         m_toolBar->addWidget(m_globeViewButton);
0184         m_toolBar->addWidget(m_mercatorViewButton);
0185         m_toolBar->addSeparator();
0186         m_toolBar->setContentsMargins(0,0,0,0);
0187         m_toolBar->setIconSize(QSize(16, 16));
0188         m_mapViewUi.toolBarLayout->insertWidget(0, m_toolBar);
0189 
0190         QObject::connect(m_globeViewButton, SIGNAL(clicked()),
0191                          q, SLOT(globeViewRequested()));
0192         QObject::connect(m_mercatorViewButton, SIGNAL(clicked()),
0193                          q, SLOT(mercatorViewRequested()));
0194         QObject::connect(m_mercatorViewAction, SIGNAL(triggered()),
0195                          q, SLOT(mercatorViewRequested()));
0196         QObject::connect(m_flatViewAction, SIGNAL(triggered()),
0197                          q, SLOT(flatViewRequested()));
0198         QObject::connect(m_gnomonicViewAction, SIGNAL(triggered()),
0199                          q, SLOT(gnomonicViewRequested()));
0200         QObject::connect(m_stereographicViewAction, SIGNAL(triggered()),
0201                          q, SLOT(stereographicViewRequested()));
0202         QObject::connect(m_lambertAzimuthalViewAction, SIGNAL(triggered()),
0203                          q, SLOT(lambertAzimuthalViewRequested()));
0204         QObject::connect(m_azimuthalEquidistantViewAction, SIGNAL(triggered()),
0205                          q, SLOT(azimuthalEquidistantViewRequested()));
0206         QObject::connect(m_verticalPerspectiveViewAction, SIGNAL(triggered()),
0207                          q, SLOT(verticalPerspectiveViewRequested()));
0208         QObject::connect(m_globeViewAction, SIGNAL(triggered()),
0209                          q, SLOT(globeViewRequested()));
0210 
0211         applyReducedLayout();
0212     }
0213 
0214     void updateMapFilter()
0215     {
0216         int currentIndex = m_mapViewUi.celestialBodyComboBox->currentIndex();
0217         const QString selectedId = m_celestialListProxy.data( m_celestialListProxy.index( currentIndex, 1 ) ).toString();
0218 
0219         if ( !selectedId.isEmpty() ) {
0220             m_mapSortProxy.setFilterRegExp( QRegExp( selectedId, Qt::CaseInsensitive,QRegExp::FixedString ) );
0221         }
0222     }
0223 
0224     void celestialBodySelected( int comboIndex );
0225 
0226     void projectionSelected( int projectionIndex );
0227 
0228     void mapThemeSelected( QModelIndex index );
0229     void mapThemeSelected( int index );
0230 
0231     void showContextMenu( const QPoint& pos );
0232     void deleteMap();
0233     void toggleFavorite();
0234     void toggleIconSize();
0235 
0236     bool isCurrentFavorite() const;
0237     QString currentThemeName() const;
0238     QString currentThemePath() const;
0239     QString favoriteKey(const QModelIndex &index) const;
0240 
0241     MapViewWidget *const q;
0242 
0243     Ui::MapViewWidget  m_mapViewUi;
0244     MarbleModel      *m_marbleModel;
0245 
0246     MapThemeSortFilterProxyModel m_mapSortProxy;
0247 
0248     CelestialSortFilterProxyModel m_celestialListProxy;
0249     QSettings m_settings;
0250     QToolBar *m_toolBar;
0251     QToolButton *m_globeViewButton;
0252     QToolButton *m_mercatorViewButton;
0253     QMenu *m_popupMenuFlat;
0254     QAction *m_flatViewAction;
0255     QAction *m_mercatorViewAction;
0256     QAction *m_celestialBodyAction;
0257     QAction *m_gnomonicViewAction;
0258     QAction *m_stereographicViewAction;
0259     QAction *m_lambertAzimuthalViewAction;
0260     QAction *m_azimuthalEquidistantViewAction;
0261     QAction *m_verticalPerspectiveViewAction;
0262     QAction *m_globeViewAction;
0263     MapViewItemDelegate* m_mapViewDelegate;
0264 };
0265 
0266 MapViewWidget::MapViewWidget( QWidget *parent, Qt::WindowFlags f )
0267     : QWidget( parent, f ),
0268       d( new Private( this ) )
0269 {
0270     d->m_mapViewUi.setupUi( this );
0271     layout()->setMargin( 0 );
0272 
0273     if ( MarbleGlobal::getInstance()->profiles() & MarbleGlobal::SmallScreen ) {
0274         QGridLayout* layout = new QGridLayout;
0275         layout->addItem( d->m_mapViewUi.verticalLayout->takeAt( 1 ), 0, 0 );
0276         layout->addItem( d->m_mapViewUi.verticalLayout->takeAt( 1 ), 0, 1 );
0277         d->m_mapViewUi.line->setVisible( false );
0278         layout->addItem( d->m_mapViewUi.verticalLayout->takeAt( 2 ), 1, 0 );
0279         layout->addItem( d->m_mapViewUi.verticalLayout->takeAt( 2 ), 1, 1 );
0280         layout->addItem( d->m_mapViewUi.verticalLayout->takeAt( 3 ), 2, 0 );
0281         layout->addItem( d->m_mapViewUi.verticalLayout->takeAt( 4 ), 2, 1 );
0282         d->m_mapViewUi.verticalLayout->insertLayout( 0, layout );
0283         d->m_mapViewUi.mapThemeComboBox->setModel( &d->m_mapSortProxy );
0284         d->m_mapViewUi.mapThemeComboBox->setIconSize( QSize( 48, 48 ) );
0285         connect( d->m_mapViewUi.mapThemeComboBox, SIGNAL(activated(int)),
0286                  this,                            SLOT(mapThemeSelected(int)) );
0287         d->m_mapViewUi.marbleThemeSelectView->setVisible( false );
0288     }
0289     else {
0290         d->m_mapViewUi.marbleThemeSelectView->setViewMode( QListView::IconMode );
0291         QSize const iconSize = d->m_settings.value(QStringLiteral("MapView/iconSize"), QSize(90, 90)).toSize();
0292         d->m_mapViewUi.marbleThemeSelectView->setIconSize( iconSize );
0293         delete d->m_mapViewDelegate;
0294         d->m_mapViewDelegate = new MapViewItemDelegate(d->m_mapViewUi.marbleThemeSelectView);
0295         d->m_mapViewUi.marbleThemeSelectView->setItemDelegate(d->m_mapViewDelegate);
0296         d->m_mapViewUi.marbleThemeSelectView->setAlternatingRowColors( true );
0297         d->m_mapViewUi.marbleThemeSelectView->setFlow( QListView::LeftToRight );
0298         d->m_mapViewUi.marbleThemeSelectView->setWrapping( true );
0299         d->m_mapViewUi.marbleThemeSelectView->setResizeMode( QListView::Adjust );
0300         d->m_mapViewUi.marbleThemeSelectView->setUniformItemSizes( true );
0301         d->m_mapViewUi.marbleThemeSelectView->setMovement( QListView::Static );
0302         d->m_mapViewUi.marbleThemeSelectView->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
0303         d->m_mapViewUi.marbleThemeSelectView->setEditTriggers( QListView::NoEditTriggers );
0304         d->m_mapViewUi.marbleThemeSelectView->setSelectionMode( QListView::SingleSelection );
0305         d->m_mapViewUi.marbleThemeSelectView->setModel( &d->m_mapSortProxy );
0306         connect( d->m_mapViewUi.marbleThemeSelectView, SIGNAL(pressed(QModelIndex)),
0307                  this,                                 SLOT(mapThemeSelected(QModelIndex)) );
0308         connect( d->m_mapViewUi.marbleThemeSelectView, SIGNAL(activated(QModelIndex)),
0309                  this,                                 SLOT(mapThemeSelected(QModelIndex)) );
0310         connect( d->m_mapViewUi.marbleThemeSelectView, SIGNAL(customContextMenuRequested(QPoint)),
0311                  this,                                 SLOT(showContextMenu(QPoint)) );
0312 
0313         d->m_mapViewUi.mapThemeComboBox->setVisible( false );
0314         d->setupToolBar();
0315     }
0316 
0317     connect( d->m_mapViewUi.projectionComboBox,    SIGNAL(activated(int)),
0318              this,                                 SLOT(projectionSelected(int)) );
0319 
0320     d->m_mapViewUi.projectionComboBox->setEnabled( true );
0321     d->m_mapViewUi.celestialBodyComboBox->setModel( &d->m_celestialListProxy );
0322 
0323     connect( d->m_mapViewUi.celestialBodyComboBox, SIGNAL(activated(int)),
0324              this,                                 SLOT(celestialBodySelected(int)) );
0325 
0326     d->m_settings.beginGroup(QStringLiteral("Favorites"));
0327     if (!d->m_settings.contains(QStringLiteral("initialized"))) {
0328         d->m_settings.setValue(QStringLiteral("initialized"), true);
0329         QDateTime currentDateTime = QDateTime::currentDateTime();
0330         d->m_settings.setValue(QStringLiteral("Atlas"), currentDateTime);
0331         d->m_settings.setValue(QStringLiteral("OpenStreetMap"), currentDateTime);
0332         d->m_settings.setValue(QStringLiteral("Satellite View"), currentDateTime);
0333     }
0334     d->m_settings.endGroup();
0335 }
0336 
0337 MapViewWidget::~MapViewWidget()
0338 {
0339     delete d;
0340 }
0341 
0342 void MapViewWidget::setMarbleWidget( MarbleWidget *widget, MapThemeManager *mapThemeManager )
0343 {
0344     d->m_marbleModel = widget->model();
0345     d->m_mapSortProxy.setSourceModel( mapThemeManager->mapThemeModel() );
0346     d->m_mapSortProxy.sort( 0 );
0347     d->m_celestialListProxy.setSourceModel( mapThemeManager->celestialBodiesModel() );
0348     d->m_celestialListProxy.sort( 0 );
0349 
0350     connect( this, SIGNAL(projectionChanged(Projection)),
0351              widget, SLOT(setProjection(Projection)) );
0352 
0353     connect( widget, SIGNAL(themeChanged(QString)),
0354              this, SLOT(setMapThemeId(QString)) );
0355 
0356     connect( widget, SIGNAL(projectionChanged(Projection)),
0357              this, SLOT(setProjection(Projection)) );
0358 
0359     connect( this, SIGNAL(mapThemeIdChanged(QString)),
0360              widget, SLOT(setMapThemeId(QString)) );
0361 
0362     setProjection(widget->projection());
0363     setMapThemeId(widget->mapThemeId());
0364 }
0365 
0366 void MapViewWidget::resizeEvent(QResizeEvent *event)
0367 {
0368     if (!d->m_toolBar)
0369         return;
0370 
0371     if (d->m_toolBar->isVisible() && event->size().height() > 400) {
0372         d->applyExtendedLayout();
0373     } else if (!d->m_toolBar->isVisible() && event->size().height() <= 400) {
0374         d->applyReducedLayout();
0375     }
0376 }
0377 
0378 void MapViewWidget::setMapThemeId( const QString &themeId )
0379 {
0380     const bool smallscreen = MarbleGlobal::getInstance()->profiles() & MarbleGlobal::SmallScreen;
0381 
0382     const int currentRow = smallscreen ? d->m_mapViewUi.mapThemeComboBox->currentIndex() :
0383                                          d->m_mapViewUi.marbleThemeSelectView->currentIndex().row();
0384     const QString oldThemeId = d->m_mapSortProxy.data( d->m_mapSortProxy.index( currentRow, 0 ), Qt::UserRole + 1 ).toString();
0385 
0386     // Check if the new selected theme is different from the current one
0387     if ( themeId == oldThemeId )
0388         return;
0389 
0390     const QString oldCelestialBodyId = oldThemeId.section(QLatin1Char('/'), 0, 0);
0391     const QString celestialBodyId = themeId.section(QLatin1Char('/'), 0, 0);
0392 
0393     // select celestialBodyId in GUI
0394     if ( celestialBodyId != oldCelestialBodyId ) {
0395         for ( int row = 0; row < d->m_celestialListProxy.rowCount(); ++row ) {
0396             if ( d->m_celestialListProxy.data( d->m_celestialListProxy.index( row, 1 ) ).toString() == celestialBodyId ) {
0397                 d->m_mapViewUi.celestialBodyComboBox->setCurrentIndex( row );
0398                 break;
0399             }
0400         }
0401 
0402         d->updateMapFilter();
0403     }
0404 
0405     // select themeId in GUI
0406     for ( int row = 0; row < d->m_mapSortProxy.rowCount(); ++row ) {
0407         if( d->m_mapSortProxy.data( d->m_mapSortProxy.index( row, 0 ), Qt::UserRole + 1 ).toString() == themeId ) {
0408             if ( smallscreen ) {
0409                 d->m_mapViewUi.mapThemeComboBox->setCurrentIndex( row );
0410             }
0411             else {
0412                 const QModelIndex index = d->m_mapSortProxy.index( row, 0 );
0413                 d->m_mapViewUi.marbleThemeSelectView->setCurrentIndex( index );
0414                 d->m_mapViewUi.marbleThemeSelectView->scrollTo( index );
0415             }
0416 
0417             break;
0418         }
0419     }
0420 }
0421 
0422 void MapViewWidget::setProjection( Projection projection )
0423 {
0424     if ( (int)projection != d->m_mapViewUi.projectionComboBox->currentIndex() )
0425         d->m_mapViewUi.projectionComboBox->setCurrentIndex( (int) projection );
0426 
0427     if (d->m_toolBar) {
0428         switch (projection) {
0429         case Marble::Spherical:
0430             d->m_globeViewButton->setChecked(true);
0431             d->m_globeViewAction->setChecked(true);
0432             d->m_mercatorViewButton->setChecked(false);
0433             d->m_mercatorViewAction->setChecked(false);
0434             d->m_flatViewAction->setChecked(false);
0435             d->m_gnomonicViewAction->setChecked(false);
0436             d->m_stereographicViewAction->setChecked(false);
0437             d->m_lambertAzimuthalViewAction->setChecked(false);
0438             d->m_azimuthalEquidistantViewAction->setChecked(false);
0439             d->m_verticalPerspectiveViewAction->setChecked(false);
0440             break;
0441         case Marble::Mercator:
0442             d->m_mercatorViewButton->setChecked(true);
0443             d->m_mercatorViewAction->setChecked(true);
0444             d->m_globeViewButton->setChecked(false);
0445             d->m_flatViewAction->setChecked(false);
0446             d->m_gnomonicViewAction->setChecked(false);
0447             d->m_globeViewAction->setChecked(false);
0448             d->m_stereographicViewAction->setChecked(false);
0449             d->m_lambertAzimuthalViewAction->setChecked(false);
0450             d->m_azimuthalEquidistantViewAction->setChecked(false);
0451             d->m_verticalPerspectiveViewAction->setChecked(false);
0452             break;
0453         case Marble::Equirectangular:
0454             d->m_flatViewAction->setChecked(true);
0455             d->m_mercatorViewButton->setChecked(true);
0456             d->m_globeViewButton->setChecked(false);
0457             d->m_mercatorViewAction->setChecked(false);
0458             d->m_gnomonicViewAction->setChecked(false);
0459             d->m_globeViewAction->setChecked(false);
0460             d->m_stereographicViewAction->setChecked(false);
0461             d->m_lambertAzimuthalViewAction->setChecked(false);
0462             d->m_azimuthalEquidistantViewAction->setChecked(false);
0463             d->m_verticalPerspectiveViewAction->setChecked(false);
0464             break;
0465         case Marble::Gnomonic:
0466             d->m_flatViewAction->setChecked(false);
0467             d->m_mercatorViewButton->setChecked(true);
0468             d->m_globeViewButton->setChecked(false);
0469             d->m_mercatorViewAction->setChecked(false);
0470             d->m_gnomonicViewAction->setChecked(true);
0471             d->m_globeViewAction->setChecked(false);
0472             d->m_stereographicViewAction->setChecked(false);
0473             d->m_lambertAzimuthalViewAction->setChecked(false);
0474             d->m_azimuthalEquidistantViewAction->setChecked(false);
0475             d->m_verticalPerspectiveViewAction->setChecked(false);
0476             break;
0477         case Marble::Stereographic:
0478             d->m_flatViewAction->setChecked(false);
0479             d->m_mercatorViewButton->setChecked(true);
0480             d->m_globeViewButton->setChecked(false);
0481             d->m_mercatorViewAction->setChecked(false);
0482             d->m_gnomonicViewAction->setChecked(false);
0483             d->m_globeViewAction->setChecked(false);
0484             d->m_stereographicViewAction->setChecked(true);
0485             d->m_lambertAzimuthalViewAction->setChecked(false);
0486             d->m_azimuthalEquidistantViewAction->setChecked(false);
0487             d->m_verticalPerspectiveViewAction->setChecked(false);
0488             break;
0489         case Marble::LambertAzimuthal:
0490             d->m_flatViewAction->setChecked(false);
0491             d->m_mercatorViewButton->setChecked(true);
0492             d->m_globeViewButton->setChecked(false);
0493             d->m_mercatorViewAction->setChecked(false);
0494             d->m_gnomonicViewAction->setChecked(false);
0495             d->m_globeViewAction->setChecked(false);
0496             d->m_stereographicViewAction->setChecked(false);
0497             d->m_lambertAzimuthalViewAction->setChecked(true);
0498             d->m_azimuthalEquidistantViewAction->setChecked(false);
0499             d->m_verticalPerspectiveViewAction->setChecked(false);
0500             break;
0501         case Marble::AzimuthalEquidistant:
0502             d->m_flatViewAction->setChecked(false);
0503             d->m_mercatorViewButton->setChecked(true);
0504             d->m_globeViewButton->setChecked(false);
0505             d->m_mercatorViewAction->setChecked(false);
0506             d->m_gnomonicViewAction->setChecked(false);
0507             d->m_globeViewAction->setChecked(false);
0508             d->m_stereographicViewAction->setChecked(false);
0509             d->m_lambertAzimuthalViewAction->setChecked(false);
0510             d->m_azimuthalEquidistantViewAction->setChecked(true);
0511             d->m_verticalPerspectiveViewAction->setChecked(false);
0512             break;
0513         case Marble::VerticalPerspective:
0514             d->m_flatViewAction->setChecked(false);
0515             d->m_mercatorViewButton->setChecked(true);
0516             d->m_globeViewButton->setChecked(false);
0517             d->m_mercatorViewAction->setChecked(false);
0518             d->m_gnomonicViewAction->setChecked(false);
0519             d->m_globeViewAction->setChecked(false);
0520             d->m_stereographicViewAction->setChecked(false);
0521             d->m_lambertAzimuthalViewAction->setChecked(false);
0522             d->m_azimuthalEquidistantViewAction->setChecked(false);
0523             d->m_verticalPerspectiveViewAction->setChecked(true);
0524             break;
0525         }
0526     }
0527 }
0528 
0529 void MapViewWidget::globeViewRequested()
0530 {
0531     emit projectionChanged(Marble::Spherical);
0532 }
0533 
0534 void MapViewWidget::flatViewRequested()
0535 {
0536     emit projectionChanged(Marble::Equirectangular);
0537 }
0538 
0539 void MapViewWidget::mercatorViewRequested()
0540 {
0541     emit projectionChanged(Marble::Mercator);
0542 }
0543 
0544 void MapViewWidget::gnomonicViewRequested()
0545 {
0546     emit projectionChanged(Marble::Gnomonic);
0547 }
0548 
0549 void MapViewWidget::stereographicViewRequested()
0550 {
0551     emit projectionChanged(Marble::Stereographic);
0552 }
0553 
0554 void MapViewWidget::lambertAzimuthalViewRequested()
0555 {
0556     emit projectionChanged(Marble::LambertAzimuthal);
0557 }
0558 
0559 void MapViewWidget::azimuthalEquidistantViewRequested()
0560 {
0561     emit projectionChanged(Marble::AzimuthalEquidistant);
0562 }
0563 
0564 void MapViewWidget::verticalPerspectiveViewRequested()
0565 {
0566     emit projectionChanged(Marble::VerticalPerspective);
0567 }
0568 
0569 void MapViewWidget::Private::celestialBodySelected( int comboIndex )
0570 {
0571     Q_UNUSED( comboIndex )
0572 
0573     updateMapFilter();
0574 
0575     bool foundMapTheme = false;
0576 
0577     QString currentMapThemeId = m_marbleModel->mapThemeId();
0578     QString oldPlanetId = m_marbleModel->planetId();
0579 
0580     int row = m_mapSortProxy.rowCount();
0581 
0582     for ( int i = 0; i < row; ++i )
0583     {
0584         QModelIndex index = m_mapSortProxy.index(i,0);
0585         QString itMapThemeId = m_mapSortProxy.data(index, Qt::UserRole + 1).toString();
0586         if ( currentMapThemeId == itMapThemeId )
0587         {
0588             foundMapTheme = true;
0589             break;
0590         }
0591     }
0592     if ( !foundMapTheme ) {
0593         QModelIndex index = m_mapSortProxy.index(0,0);
0594         emit q->mapThemeIdChanged( m_mapSortProxy.data( index, Qt::UserRole + 1 ).toString() );
0595     }
0596 
0597     if( oldPlanetId != m_marbleModel->planetId() ) {
0598         emit q->celestialBodyChanged( m_marbleModel->planetId() );
0599     }
0600 }
0601 
0602 // Relay a signal and convert the parameter from an int to a Projection.
0603 void MapViewWidget::Private::projectionSelected( int projectionIndex )
0604 {
0605     emit q->projectionChanged( (Projection) projectionIndex );
0606 }
0607 
0608 void MapViewWidget::Private::mapThemeSelected( QModelIndex index )
0609 {
0610     mapThemeSelected( index.row() );
0611 }
0612 
0613 void MapViewWidget::Private::mapThemeSelected( int index )
0614 {
0615     const QModelIndex columnIndex = m_mapSortProxy.index( index, 0 );
0616     const QString currentmaptheme = m_mapSortProxy.data( columnIndex, Qt::UserRole + 1 ).toString();
0617 
0618     mDebug() << currentmaptheme;
0619 
0620     emit q->mapThemeIdChanged( currentmaptheme );
0621 }
0622 
0623 QString MapViewWidget::Private::currentThemeName() const
0624 {
0625     const QModelIndex index = m_mapViewUi.marbleThemeSelectView->currentIndex();
0626     const QModelIndex columnIndex = m_mapSortProxy.index( index.row(), 0, QModelIndex() );
0627 
0628     return m_mapSortProxy.data( columnIndex ).toString();
0629 }
0630 
0631 QString MapViewWidget::Private::currentThemePath() const
0632 {
0633     const QModelIndex index = m_mapViewUi.marbleThemeSelectView->currentIndex();
0634     const QModelIndex columnIndex = m_mapSortProxy.index( index.row(), 0 );
0635 
0636     return m_mapSortProxy.data( columnIndex, Qt::UserRole + 1 ).toString();
0637 }
0638 
0639 QString MapViewWidget::Private::favoriteKey(const QModelIndex &index) const
0640 {
0641     return QLatin1String("Favorites/") + m_mapSortProxy.data(index).toString();
0642 }
0643 
0644 void MapViewWidget::Private::showContextMenu( const QPoint& pos )
0645 {
0646     qDebug();
0647     Q_UNUSED(pos)
0648     QMenu menu;
0649 
0650     QAction* iconSizeAction = menu.addAction( tr( "&Show Large Icons" ), q, SLOT(toggleIconSize()) );
0651     iconSizeAction->setCheckable( true );
0652     iconSizeAction->setChecked( m_mapViewUi.marbleThemeSelectView->iconSize() == QSize( 96, 96 ) );
0653     QAction *favAction = menu.addAction(QIcon(QStringLiteral(":/icons/bookmarks.png")), tr("&Favorite"), q, SLOT(toggleFavorite()));
0654     favAction->setCheckable( true );
0655     favAction->setChecked( isCurrentFavorite() );
0656     menu.addSeparator();
0657 
0658     menu.addAction(QIcon(QStringLiteral(":/icons/create-new-map.png")), tr("&Create a New Map..."), q, SIGNAL(showMapWizard()));
0659     if (QFileInfo(MarbleDirs::localPath() + QLatin1String("/maps/") + currentThemePath()).exists()) {
0660         menu.addAction( tr( "&Delete Map Theme" ), q, SLOT(deleteMap()) );
0661     }
0662     menu.exec( m_mapViewUi.marbleThemeSelectView->mapToGlobal( pos ) );
0663 }
0664 
0665 void MapViewWidget::Private::deleteMap()
0666 {
0667     if(QMessageBox::warning( q,
0668                              tr( "Marble" ),
0669                              tr( "Are you sure that you want to delete \"%1\"?" ).arg( currentThemeName() ),
0670                              QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes )
0671     {
0672         MapThemeManager::deleteMapTheme( currentThemePath() );
0673         emit q->mapThemeDeleted();
0674     }
0675 }
0676 
0677 void MapViewWidget::Private::toggleFavorite()
0678 {
0679     QModelIndex index = m_mapViewUi.marbleThemeSelectView->currentIndex();
0680     if( isCurrentFavorite() ) {
0681         m_settings.remove(favoriteKey(index));
0682     } else {
0683         m_settings.setValue(favoriteKey(index), QDateTime::currentDateTime() );
0684     }
0685     QStandardItemModel* sourceModel = qobject_cast<QStandardItemModel*>(m_mapSortProxy.sourceModel());
0686     const QModelIndex sourceIndex = m_mapSortProxy.mapToSource(index);
0687     emit sourceModel->dataChanged( sourceIndex, sourceIndex );
0688     index = m_mapViewUi.marbleThemeSelectView->currentIndex();
0689     m_mapViewUi.marbleThemeSelectView->scrollTo(index);
0690 }
0691 
0692 void MapViewWidget::Private::toggleIconSize()
0693 {
0694     bool const isLarge = m_mapViewUi.marbleThemeSelectView->iconSize() == QSize( 96, 96 );
0695     int const size = isLarge ? 52 : 96;
0696     m_mapViewUi.marbleThemeSelectView->setIconSize( QSize( size, size ) );
0697     m_settings.setValue(QStringLiteral("MapView/iconSize"), m_mapViewUi.marbleThemeSelectView->iconSize() );
0698 }
0699 
0700 bool MapViewWidget::Private::isCurrentFavorite() const
0701 {
0702     const QModelIndex index = m_mapViewUi.marbleThemeSelectView->currentIndex();
0703     return m_settings.contains(favoriteKey(index));
0704 }
0705 
0706 }
0707 
0708 #include "moc_MapViewWidget.cpp"