12 #include "MapViewWidget.h"
15 #include "MarbleDebug.h"
16 #include "MarbleDirs.h"
19 #include "MapThemeManager.h"
20 #include "MapThemeSortFilterProxyModel.h"
21 #include "GeoSceneDocument.h"
22 #include "GeoSceneHead.h"
23 #include "MapViewItemDelegate.h"
24 #include "CelestialSortFilterProxyModel.h"
27 #include <QResizeEvent>
31 #include <QMessageBox>
32 #include <QStandardItemModel>
33 #include <QGridLayout>
36 #include <QToolButton>
41 #include "ui_MapViewWidget.h"
46 class Q_DECL_HIDDEN MapViewWidget::Private {
48 Private( MapViewWidget *parent )
50 m_marbleModel( nullptr ),
52 m_celestialListProxy(),
54 m_globeViewButton( nullptr ),
55 m_mercatorViewButton( nullptr ),
56 m_popupMenuFlat( nullptr ),
57 m_flatViewAction( nullptr ),
58 m_mercatorViewAction( nullptr ),
59 m_celestialBodyAction( nullptr ),
60 m_gnomonicViewAction( nullptr ),
61 m_stereographicViewAction( nullptr ),
62 m_lambertAzimuthalViewAction( nullptr ),
63 m_azimuthalEquidistantViewAction( nullptr ),
64 m_verticalPerspectiveViewAction( nullptr ),
65 m_globeViewAction( nullptr ),
66 m_mapViewDelegate(nullptr)
68 m_mapSortProxy.setDynamicSortFilter(
true );
69 m_celestialListProxy.setDynamicSortFilter(
true );
74 delete m_mapViewDelegate;
77 void applyExtendedLayout()
79 m_mapViewUi.projectionLabel_2->setVisible(
true);
80 m_mapViewUi.celestialBodyLabel->setVisible(
true);
81 m_mapViewUi.projectionComboBox->setVisible(
true);
82 m_mapViewUi.mapThemeLabel->setVisible(
true);
83 m_mapViewUi.line->setVisible(
true);
85 m_toolBar->setVisible(
false);
86 const int labelId = m_mapViewUi.verticalLayout->indexOf(m_mapViewUi.celestialBodyLabel);
87 m_mapViewUi.verticalLayout->insertWidget(labelId+1, m_mapViewUi.celestialBodyComboBox);
88 m_toolBar->removeAction(m_celestialBodyAction);
89 m_mapViewUi.celestialBodyComboBox->show();
92 void applyReducedLayout()
94 m_mapViewUi.projectionLabel_2->setVisible(
false);
95 m_mapViewUi.celestialBodyLabel->setVisible(
false);
96 m_mapViewUi.projectionComboBox->setVisible(
false);
97 m_mapViewUi.mapThemeLabel->setVisible(
false);
98 m_mapViewUi.line->setVisible(
false);
100 m_toolBar->setVisible(
true);
101 m_celestialBodyAction = m_toolBar->addWidget(m_mapViewUi.celestialBodyComboBox);
102 m_mapViewUi.verticalLayout->removeWidget(m_mapViewUi.celestialBodyComboBox);
103 m_mapViewUi.celestialBodyComboBox->show();
111 m_globeViewButton->
setIcon(
QIcon(QStringLiteral(
":/icons/map-globe.png")));
112 m_globeViewButton->setToolTip( tr(
"Globe View") );
113 m_globeViewButton->setCheckable(
true);
114 m_globeViewButton->setChecked(
false);
116 m_globeViewAction =
new QAction(
QIcon(QStringLiteral(
":/icons/map-globe.png")),
117 tr(
"Spherical view" ),
119 m_globeViewAction->setCheckable(
true );
120 m_globeViewAction->setChecked(
false );
123 m_mercatorViewButton->
setIcon(
QIcon(QStringLiteral(
":/icons/map-mercator.png")));
124 m_mercatorViewButton->setToolTip( tr(
"Mercator View") );
125 m_mercatorViewButton->setCheckable(
true);
126 m_mercatorViewButton->setChecked(
false);
129 m_popupMenuFlat =
new QMenu(q);
131 m_mercatorViewAction =
new QAction(
QIcon(QStringLiteral(
":/icons/map-mercator.png")),
134 m_mercatorViewAction->setCheckable(
true);
135 m_mercatorViewAction->setChecked(
false);
137 m_flatViewAction =
new QAction(
QIcon(QStringLiteral(
":/icons/map-flat.png")),
140 m_flatViewAction->setCheckable(
true);
141 m_flatViewAction->setChecked(
false);
143 m_gnomonicViewAction =
new QAction(
QIcon(QStringLiteral(
":/icons/map-gnomonic.png")),
144 tr(
"Gnomonic view" ),
146 m_gnomonicViewAction->setCheckable(
true );
147 m_gnomonicViewAction->setChecked(
false );
149 m_stereographicViewAction =
new QAction(
QIcon(QStringLiteral(
":/icons/map-globe.png")),
150 tr(
"Stereographic view" ),
152 m_stereographicViewAction->setCheckable(
true );
153 m_stereographicViewAction->setChecked(
false );
155 m_lambertAzimuthalViewAction =
new QAction(
QIcon(QStringLiteral(
":/icons/map-globe.png")),
156 tr(
"Lambert Azimuthal Equal-Area view" ),
158 m_lambertAzimuthalViewAction->setCheckable(
true );
159 m_lambertAzimuthalViewAction->setChecked(
false );
161 m_azimuthalEquidistantViewAction =
new QAction(
QIcon(QStringLiteral(
":/icons/map-globe.png")),
162 tr(
"Azimuthal Equidistant view" ),
164 m_azimuthalEquidistantViewAction->setCheckable(
true );
165 m_azimuthalEquidistantViewAction->setChecked(
false );
167 m_verticalPerspectiveViewAction =
new QAction(
QIcon(QStringLiteral(
":/icons/map-globe.png")),
168 tr(
"Perspective Globe view" ),
170 m_verticalPerspectiveViewAction->setCheckable(
true );
171 m_verticalPerspectiveViewAction->setChecked(
false );
174 m_popupMenuFlat->addAction(m_mercatorViewAction);
175 m_popupMenuFlat->addAction(m_flatViewAction);
176 m_popupMenuFlat->addAction(m_gnomonicViewAction);
177 m_popupMenuFlat->addAction(m_stereographicViewAction);
178 m_popupMenuFlat->addAction(m_lambertAzimuthalViewAction);
179 m_popupMenuFlat->addAction(m_azimuthalEquidistantViewAction);
180 m_popupMenuFlat->addAction(m_verticalPerspectiveViewAction);
181 m_mercatorViewButton->setMenu(m_popupMenuFlat);
183 m_toolBar->addWidget(m_globeViewButton);
184 m_toolBar->addWidget(m_mercatorViewButton);
185 m_toolBar->addSeparator();
186 m_toolBar->setContentsMargins(0,0,0,0);
187 m_toolBar->setIconSize(
QSize(16, 16));
188 m_mapViewUi.toolBarLayout->insertWidget(0, m_toolBar);
191 q, SLOT(globeViewRequested()));
193 q, SLOT(mercatorViewRequested()));
195 q, SLOT(mercatorViewRequested()));
197 q, SLOT(flatViewRequested()));
199 q, SLOT(gnomonicViewRequested()));
201 q, SLOT(stereographicViewRequested()));
203 q, SLOT(lambertAzimuthalViewRequested()));
205 q, SLOT(azimuthalEquidistantViewRequested()));
207 q, SLOT(verticalPerspectiveViewRequested()));
209 q, SLOT(globeViewRequested()));
211 applyReducedLayout();
214 void updateMapFilter()
216 int currentIndex = m_mapViewUi.celestialBodyComboBox->currentIndex();
217 const QString selectedId = m_celestialListProxy.
data( m_celestialListProxy.index( currentIndex, 1 ) ).toString();
224 void celestialBodySelected(
int comboIndex );
226 void projectionSelected(
int projectionIndex );
229 void mapThemeSelected(
int index );
231 void showContextMenu(
const QPoint& pos );
233 void toggleFavorite();
234 void toggleIconSize();
236 bool isCurrentFavorite()
const;
237 QString currentThemeName()
const;
238 QString currentThemePath()
const;
241 MapViewWidget *
const q;
243 Ui::MapViewWidget m_mapViewUi;
246 MapThemeSortFilterProxyModel m_mapSortProxy;
253 QMenu *m_popupMenuFlat;
256 QAction *m_celestialBodyAction;
258 QAction *m_stereographicViewAction;
259 QAction *m_lambertAzimuthalViewAction;
260 QAction *m_azimuthalEquidistantViewAction;
261 QAction *m_verticalPerspectiveViewAction;
268 d( new Private( this ) )
270 d->m_mapViewUi.
setupUi(
this );
271 layout()->setMargin( 0 );
273 if ( MarbleGlobal::getInstance()->profiles() & MarbleGlobal::SmallScreen ) {
275 layout->
addItem( d->m_mapViewUi.verticalLayout->takeAt( 1 ), 0, 0 );
276 layout->
addItem( d->m_mapViewUi.verticalLayout->takeAt( 1 ), 0, 1 );
277 d->m_mapViewUi.line->setVisible(
false );
278 layout->
addItem( d->m_mapViewUi.verticalLayout->takeAt( 2 ), 1, 0 );
279 layout->
addItem( d->m_mapViewUi.verticalLayout->takeAt( 2 ), 1, 1 );
280 layout->
addItem( d->m_mapViewUi.verticalLayout->takeAt( 3 ), 2, 0 );
281 layout->
addItem( d->m_mapViewUi.verticalLayout->takeAt( 4 ), 2, 1 );
282 d->m_mapViewUi.verticalLayout->insertLayout( 0, layout );
283 d->m_mapViewUi.mapThemeComboBox->setModel( &d->m_mapSortProxy );
284 d->m_mapViewUi.mapThemeComboBox->setIconSize(
QSize( 48, 48 ) );
285 connect( d->m_mapViewUi.mapThemeComboBox, SIGNAL(activated(
int)),
286 this, SLOT(mapThemeSelected(
int)) );
287 d->m_mapViewUi.marbleThemeSelectView->setVisible(
false );
291 QSize const iconSize = d->m_settings.value(QStringLiteral(
"MapView/iconSize"),
QSize(90, 90)).toSize();
292 d->m_mapViewUi.marbleThemeSelectView->setIconSize( iconSize );
293 delete d->m_mapViewDelegate;
295 d->m_mapViewUi.marbleThemeSelectView->setItemDelegate(d->m_mapViewDelegate);
296 d->m_mapViewUi.marbleThemeSelectView->setAlternatingRowColors(
true );
298 d->m_mapViewUi.marbleThemeSelectView->setWrapping(
true );
300 d->m_mapViewUi.marbleThemeSelectView->setUniformItemSizes(
true );
305 d->m_mapViewUi.marbleThemeSelectView->setModel( &d->m_mapSortProxy );
308 connect( d->m_mapViewUi.marbleThemeSelectView, SIGNAL(customContextMenuRequested(
QPoint)),
309 this, SLOT(showContextMenu(
QPoint)) );
311 d->m_mapViewUi.mapThemeComboBox->setVisible(
false );
315 connect( d->m_mapViewUi.projectionComboBox, SIGNAL(activated(
int)),
316 this, SLOT(projectionSelected(
int)) );
318 d->m_mapViewUi.projectionComboBox->setEnabled(
true );
319 d->m_mapViewUi.celestialBodyComboBox->setModel( &d->m_celestialListProxy );
321 connect( d->m_mapViewUi.celestialBodyComboBox, SIGNAL(activated(
int)),
322 this, SLOT(celestialBodySelected(
int)) );
324 d->m_settings.beginGroup(QStringLiteral(
"Favorites"));
325 if (!d->m_settings.contains(QStringLiteral(
"initialized"))) {
326 d->m_settings.setValue(QStringLiteral(
"initialized"),
true);
328 d->m_settings.setValue(QStringLiteral(
"Atlas"), currentDateTime);
329 d->m_settings.setValue(QStringLiteral(
"OpenStreetMap"), currentDateTime);
330 d->m_settings.setValue(QStringLiteral(
"Satellite View"), currentDateTime);
332 d->m_settings.endGroup();
335 MapViewWidget::~MapViewWidget()
342 d->m_marbleModel = widget->
model();
343 d->m_mapSortProxy.setSourceModel( mapThemeManager->
mapThemeModel() );
344 d->m_mapSortProxy.sort( 0 );
346 d->m_celestialListProxy.sort( 0 );
348 connect(
this, SIGNAL(projectionChanged(
Projection)),
351 connect( widget, SIGNAL(themeChanged(
QString)),
352 this, SLOT(setMapThemeId(
QString)) );
354 connect( widget, SIGNAL(projectionChanged(
Projection)),
357 connect(
this, SIGNAL(mapThemeIdChanged(
QString)),
358 widget, SLOT(setMapThemeId(
QString)) );
361 setMapThemeId(widget->mapThemeId());
369 if (d->m_toolBar->isVisible() &&
event->size().height() > 400) {
370 d->applyExtendedLayout();
371 }
else if (!d->m_toolBar->isVisible() &&
event->size().height() <= 400) {
372 d->applyReducedLayout();
376 void MapViewWidget::setMapThemeId(
const QString &themeId )
378 const bool smallscreen = MarbleGlobal::getInstance()->profiles() & MarbleGlobal::SmallScreen;
380 const int currentRow = smallscreen ? d->m_mapViewUi.mapThemeComboBox->currentIndex() :
381 d->m_mapViewUi.marbleThemeSelectView->currentIndex().row();
382 const QString oldThemeId = d->m_mapSortProxy.
data( d->m_mapSortProxy.index( currentRow, 0 ),
Qt::UserRole + 1 ).toString();
385 if ( themeId == oldThemeId )
392 if ( celestialBodyId != oldCelestialBodyId ) {
393 for (
int row = 0; row < d->m_celestialListProxy.rowCount(); ++row ) {
394 if ( d->m_celestialListProxy.data( d->m_celestialListProxy.index( row, 1 ) ).toString() == celestialBodyId ) {
395 d->m_mapViewUi.celestialBodyComboBox->setCurrentIndex( row );
400 d->updateMapFilter();
404 for (
int row = 0; row < d->m_mapSortProxy.rowCount(); ++row ) {
405 if( d->m_mapSortProxy.data( d->m_mapSortProxy.index( row, 0 ),
Qt::UserRole + 1 ).toString() == themeId ) {
407 d->m_mapViewUi.mapThemeComboBox->setCurrentIndex( row );
410 const QModelIndex index = d->m_mapSortProxy.index( row, 0 );
411 d->m_mapViewUi.marbleThemeSelectView->setCurrentIndex( index );
412 d->m_mapViewUi.marbleThemeSelectView->scrollTo( index );
422 if ( (
int)projection != d->m_mapViewUi.projectionComboBox->currentIndex() )
423 d->m_mapViewUi.projectionComboBox->setCurrentIndex( (
int) projection );
426 switch (projection) {
428 d->m_globeViewButton->setChecked(
true);
429 d->m_globeViewAction->setChecked(
true);
430 d->m_mercatorViewButton->setChecked(
false);
431 d->m_mercatorViewAction->setChecked(
false);
432 d->m_flatViewAction->setChecked(
false);
433 d->m_gnomonicViewAction->setChecked(
false);
434 d->m_stereographicViewAction->setChecked(
false);
435 d->m_lambertAzimuthalViewAction->setChecked(
false);
436 d->m_azimuthalEquidistantViewAction->setChecked(
false);
437 d->m_verticalPerspectiveViewAction->setChecked(
false);
440 d->m_mercatorViewButton->setChecked(
true);
441 d->m_mercatorViewAction->setChecked(
true);
442 d->m_globeViewButton->setChecked(
false);
443 d->m_flatViewAction->setChecked(
false);
444 d->m_gnomonicViewAction->setChecked(
false);
445 d->m_globeViewAction->setChecked(
false);
446 d->m_stereographicViewAction->setChecked(
false);
447 d->m_lambertAzimuthalViewAction->setChecked(
false);
448 d->m_azimuthalEquidistantViewAction->setChecked(
false);
449 d->m_verticalPerspectiveViewAction->setChecked(
false);
452 d->m_flatViewAction->setChecked(
true);
453 d->m_mercatorViewButton->setChecked(
true);
454 d->m_globeViewButton->setChecked(
false);
455 d->m_mercatorViewAction->setChecked(
false);
456 d->m_gnomonicViewAction->setChecked(
false);
457 d->m_globeViewAction->setChecked(
false);
458 d->m_stereographicViewAction->setChecked(
false);
459 d->m_lambertAzimuthalViewAction->setChecked(
false);
460 d->m_azimuthalEquidistantViewAction->setChecked(
false);
461 d->m_verticalPerspectiveViewAction->setChecked(
false);
464 d->m_flatViewAction->setChecked(
false);
465 d->m_mercatorViewButton->setChecked(
true);
466 d->m_globeViewButton->setChecked(
false);
467 d->m_mercatorViewAction->setChecked(
false);
468 d->m_gnomonicViewAction->setChecked(
true);
469 d->m_globeViewAction->setChecked(
false);
470 d->m_stereographicViewAction->setChecked(
false);
471 d->m_lambertAzimuthalViewAction->setChecked(
false);
472 d->m_azimuthalEquidistantViewAction->setChecked(
false);
473 d->m_verticalPerspectiveViewAction->setChecked(
false);
476 d->m_flatViewAction->setChecked(
false);
477 d->m_mercatorViewButton->setChecked(
true);
478 d->m_globeViewButton->setChecked(
false);
479 d->m_mercatorViewAction->setChecked(
false);
480 d->m_gnomonicViewAction->setChecked(
false);
481 d->m_globeViewAction->setChecked(
false);
482 d->m_stereographicViewAction->setChecked(
true);
483 d->m_lambertAzimuthalViewAction->setChecked(
false);
484 d->m_azimuthalEquidistantViewAction->setChecked(
false);
485 d->m_verticalPerspectiveViewAction->setChecked(
false);
488 d->m_flatViewAction->setChecked(
false);
489 d->m_mercatorViewButton->setChecked(
true);
490 d->m_globeViewButton->setChecked(
false);
491 d->m_mercatorViewAction->setChecked(
false);
492 d->m_gnomonicViewAction->setChecked(
false);
493 d->m_globeViewAction->setChecked(
false);
494 d->m_stereographicViewAction->setChecked(
false);
495 d->m_lambertAzimuthalViewAction->setChecked(
true);
496 d->m_azimuthalEquidistantViewAction->setChecked(
false);
497 d->m_verticalPerspectiveViewAction->setChecked(
false);
500 d->m_flatViewAction->setChecked(
false);
501 d->m_mercatorViewButton->setChecked(
true);
502 d->m_globeViewButton->setChecked(
false);
503 d->m_mercatorViewAction->setChecked(
false);
504 d->m_gnomonicViewAction->setChecked(
false);
505 d->m_globeViewAction->setChecked(
false);
506 d->m_stereographicViewAction->setChecked(
false);
507 d->m_lambertAzimuthalViewAction->setChecked(
false);
508 d->m_azimuthalEquidistantViewAction->setChecked(
true);
509 d->m_verticalPerspectiveViewAction->setChecked(
false);
512 d->m_flatViewAction->setChecked(
false);
513 d->m_mercatorViewButton->setChecked(
true);
514 d->m_globeViewButton->setChecked(
false);
515 d->m_mercatorViewAction->setChecked(
false);
516 d->m_gnomonicViewAction->setChecked(
false);
517 d->m_globeViewAction->setChecked(
false);
518 d->m_stereographicViewAction->setChecked(
false);
519 d->m_lambertAzimuthalViewAction->setChecked(
false);
520 d->m_azimuthalEquidistantViewAction->setChecked(
false);
521 d->m_verticalPerspectiveViewAction->setChecked(
true);
527 void MapViewWidget::globeViewRequested()
532 void MapViewWidget::flatViewRequested()
537 void MapViewWidget::mercatorViewRequested()
542 void MapViewWidget::gnomonicViewRequested()
547 void MapViewWidget::stereographicViewRequested()
552 void MapViewWidget::lambertAzimuthalViewRequested()
557 void MapViewWidget::azimuthalEquidistantViewRequested()
562 void MapViewWidget::verticalPerspectiveViewRequested()
567 void MapViewWidget::Private::celestialBodySelected(
int comboIndex )
569 Q_UNUSED( comboIndex )
573 bool foundMapTheme =
false;
575 QString currentMapThemeId = m_marbleModel->mapThemeId();
576 QString oldPlanetId = m_marbleModel->planetId();
578 int row = m_mapSortProxy.rowCount();
580 for (
int i = 0; i < row; ++i )
584 if ( currentMapThemeId == itMapThemeId )
586 foundMapTheme =
true;
590 if ( !foundMapTheme ) {
592 emit q->mapThemeIdChanged( m_mapSortProxy.data( index,
Qt::UserRole + 1 ).toString() );
595 if( oldPlanetId != m_marbleModel->planetId() ) {
596 emit q->celestialBodyChanged( m_marbleModel->planetId() );
601 void MapViewWidget::Private::projectionSelected(
int projectionIndex )
603 emit q->projectionChanged( (
Projection) projectionIndex );
606 void MapViewWidget::Private::mapThemeSelected(
QModelIndex index )
608 mapThemeSelected( index.
row() );
611 void MapViewWidget::Private::mapThemeSelected(
int index )
613 const QModelIndex columnIndex = m_mapSortProxy.index( index, 0 );
616 mDebug() << Q_FUNC_INFO << currentmaptheme;
618 emit q->mapThemeIdChanged( currentmaptheme );
621 QString MapViewWidget::Private::currentThemeName()
const
623 const QModelIndex index = m_mapViewUi.marbleThemeSelectView->currentIndex();
629 QString MapViewWidget::Private::currentThemePath()
const
631 const QModelIndex index = m_mapViewUi.marbleThemeSelectView->currentIndex();
632 const QModelIndex columnIndex = m_mapSortProxy.index( index.
row(), 0 );
642 void MapViewWidget::Private::showContextMenu(
const QPoint& pos )
646 QAction* iconSizeAction = menu.
addAction( tr(
"&Show Large Icons" ), q, SLOT(toggleIconSize()) );
648 iconSizeAction->
setChecked( m_mapViewUi.marbleThemeSelectView->iconSize() ==
QSize( 96, 96 ) );
649 QAction *favAction = menu.
addAction(
QIcon(QStringLiteral(
":/icons/bookmarks.png")), tr(
"&Favorite"), q, SLOT(toggleFavorite()));
654 menu.
addAction(
QIcon(QStringLiteral(
":/icons/create-new-map.png")), tr(
"&Create a New Map..."), q, SIGNAL(showMapWizard()));
656 menu.
addAction( tr(
"&Delete Map Theme" ), q, SLOT(deleteMap()) );
660 void MapViewWidget::Private::deleteMap()
664 tr(
"Are you sure that you want to delete \"%1\"?" ).arg( currentThemeName() ),
668 emit q->mapThemeDeleted();
672 void MapViewWidget::Private::toggleFavorite()
674 QModelIndex index = m_mapViewUi.marbleThemeSelectView->currentIndex();
675 if( isCurrentFavorite() ) {
676 m_settings.remove(favoriteKey(index));
680 QStandardItemModel* sourceModel = qobject_cast<QStandardItemModel*>(m_mapSortProxy.sourceModel());
681 const QModelIndex sourceIndex = m_mapSortProxy.mapToSource(index);
682 emit sourceModel->
dataChanged( sourceIndex, sourceIndex );
683 index = m_mapViewUi.marbleThemeSelectView->currentIndex();
684 m_mapViewUi.marbleThemeSelectView->scrollTo(index);
687 void MapViewWidget::Private::toggleIconSize()
689 bool const isLarge = m_mapViewUi.marbleThemeSelectView->iconSize() ==
QSize( 96, 96 );
690 int const size = isLarge ? 52 : 96;
691 m_mapViewUi.marbleThemeSelectView->setIconSize(
QSize( size, size ) );
692 m_settings.setValue(QStringLiteral(
"MapView/iconSize"), m_mapViewUi.marbleThemeSelectView->iconSize() );
695 bool MapViewWidget::Private::isCurrentFavorite()
const
697 const QModelIndex index = m_mapViewUi.marbleThemeSelectView->currentIndex();
698 return m_settings.contains(favoriteKey(index));
703 #include "moc_MapViewWidget.cpp"