• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

marble

  • sources
  • kde-4.12
  • kdeedu
  • marble
  • src
  • lib
  • marble
MapViewWidget.cpp
Go to the documentation of this file.
1 //
2 // This file is part of the Marble Virtual Globe.
3 //
4 // This program is free software licensed under the GNU LGPL. You can
5 // find a copy of this license in LICENSE.txt in the top directory of
6 // the source code.
7 //
8 // Copyright 2004-2007 Torsten Rahn <tackat@kde.org>
9 // Copyright 2007 Inge Wallin <ingwa@kde.org>
10 // Copyright 2007 Thomas Zander <zander@kde.org>
11 // Copyright 2010 Bastian Holst <bastianholst@gmx.de>
12 // Coprright 2011-2013 Bernhard Beschow <bbeschow@cs.tu-berlin.de>
13 // Copyright 2012 Illya Kovalevskyy <illya.kovalevskyy@gmail.com>
14 //
15 
16 // Self
17 #include "MapViewWidget.h"
18 
19 // Marble
20 #include "MarbleDebug.h"
21 #include "MarbleDirs.h"
22 #include "MarbleWidget.h"
23 #include "MarbleModel.h"
24 #include "MapThemeManager.h"
25 #include "MapThemeSortFilterProxyModel.h"
26 #include "GeoSceneDocument.h"
27 #include "GeoSceneHead.h"
28 
29 // Qt
30 #include <QResizeEvent>
31 #include <QFileInfo>
32 #include <QSettings>
33 #include <QMenu>
34 #include <QMessageBox>
35 #include <QStandardItemModel>
36 #include <QGridLayout>
37 #include <QPainter>
38 #include <QToolBar>
39 #include <QToolButton>
40 #include <QTextDocument>
41 #include <QAbstractTextDocumentLayout>
42 
43 using namespace Marble;
44 // Ui
45 #include "ui_MapViewWidget.h"
46 
47 namespace Marble
48 {
49 
50 class MapViewItemDelegate : public QAbstractItemDelegate
51 {
52 public:
53  MapViewItemDelegate( QListView* view );
54  void paint( QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const;
55  QSize sizeHint( const QStyleOptionViewItem &option, const QModelIndex &index ) const;
56 
57 private:
58  QString text( const QModelIndex &index ) const;
59  QListView* m_view;
60  QIcon m_bookmarkIcon;
61 };
62 
63 class CelestialSortFilterProxyModel : public QSortFilterProxyModel
64 {
65 public:
66  CelestialSortFilterProxyModel()
67  {
68  setupPriorities();
69  setupMoonsList();
70  setupDwarfsList();
71  }
72  ~CelestialSortFilterProxyModel() {}
73 
74  // A small trick to change names for dwarfs and moons
75  QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const
76  {
77  QVariant var = QSortFilterProxyModel::data(index, role);
78  if (role == Qt::DisplayRole && index.column() == 0) {
79  QString newOne = var.toString();
80  if (newOne == tr("Moon")) {
81  return QString(" " + tr("Moon"));
82  } else if (m_moons.contains(newOne.toLower())) {
83  return QString(" "+newOne+" (" + tr("moon") + ")");
84  } else if (m_dwarfs.contains(newOne.toLower())) {
85  return QString(newOne+ " (" + tr("dwarf planet") + ")");
86  }
87  return newOne;
88  } else {
89  return var;
90  }
91  }
92 
93 private:
94  // TODO: create priority on the model side (Planet Class) by taking the distance to the "home planet/home star" into account
95  void setupPriorities()
96  {
97  // here we will set m_priority for default order
98  int prefix = 100;
99 
100  m_priority["sun"] = prefix;
101  m_priority["mercury"] = prefix--;
102  m_priority["venus"] = prefix--;
103  m_priority["earth"] = prefix--;
104  m_priority["moon"] = prefix--;
105  m_priority["mars"] = prefix--;
106 
107  m_priority["jupiter"] = prefix--;
108  // Moons of Jupiter
109  m_priority["io"] = prefix--;
110  m_priority["europa"] = prefix--;
111  m_priority["ganymede"] = prefix--;
112  m_priority["callisto"] = prefix--;
113 
114  m_priority["saturn"] = prefix--;
115  // Moons of Saturn
116  m_priority["mimas"] = prefix--;
117  m_priority["enceladus"] = prefix--;
118  m_priority["thetys"] = prefix--;
119  m_priority["dione"] = prefix--;
120  m_priority["rhea"] = prefix--;
121  m_priority["titan"] = prefix--;
122  m_priority["iapetus"] = prefix--;
123 
124  m_priority["uranus"] = prefix--;
125  m_priority["neptune"] = prefix--;
126  m_priority["pluto"] = prefix--;
127  m_priority["ceres"] = prefix--;
128  }
129 
130  void setupMoonsList()
131  {
132  m_moons.push_back("moon");
133  m_moons.push_back("europa");
134  m_moons.push_back("ganymede");
135  m_moons.push_back("callisto");
136  m_moons.push_back("mimas");
137  m_moons.push_back("enceladus");
138  m_moons.push_back("thetys");
139  m_moons.push_back("dione");
140  m_moons.push_back("rhea");
141  m_moons.push_back("titan");
142  m_moons.push_back("iapetus");
143  }
144 
145  void setupDwarfsList()
146  {
147  m_dwarfs.push_back("pluto");
148  m_dwarfs.push_back("ceres");
149  }
150 
151 protected:
152  bool lessThan(const QModelIndex &left, const QModelIndex &right) const {
153  const QString nameLeft = sourceModel()->index(left.row(), 1).data().toString();
154  const QString nameRight = sourceModel()->index(right.row(), 1).data().toString();
155  const QString first = nameLeft.toLower();
156  const QString second = nameRight.toLower();
157 
158  // both are in the list
159  if (m_priority.contains(first) && m_priority.contains(second)) {
160  return m_priority[first] > m_priority[second];
161  }
162 
163  // only left in the list
164  if (m_priority.contains(first) && !m_priority.contains(second)) {
165  return true;
166  }
167 
168  // only right in the list
169  if (!m_priority.contains(first) && m_priority.contains(second)) {
170  return false;
171  }
172 
173  return QSortFilterProxyModel::lessThan(left, right);
174  }
175 
176 private:
177  QMap<QString, int> m_priority;
178  QList<QString> m_moons;
179  QList<QString> m_dwarfs;
180 };
181 
182 class MapViewWidget::Private {
183  public:
184  Private( MapViewWidget *parent )
185  : q( parent ),
186  m_marbleModel( 0 ),
187  m_mapSortProxy(),
188  m_celestialListProxy(),
189  m_toolBar( 0 )
190  {
191  m_mapSortProxy.setDynamicSortFilter( true );
192  m_celestialListProxy.setDynamicSortFilter( true );
193  }
194 
195  void applyExtendedLayout()
196  {
197  m_mapViewUi.projectionLabel_2->setVisible(true);
198  m_mapViewUi.celestialBodyLabel->setVisible(true);
199  m_mapViewUi.projectionComboBox->setVisible(true);
200  m_mapViewUi.mapThemeLabel->setVisible(true);
201  m_mapViewUi.line->setVisible(true);
202 
203  m_toolBar->setVisible(false);
204  const int labelId = m_mapViewUi.verticalLayout->indexOf(m_mapViewUi.celestialBodyLabel);
205  m_mapViewUi.verticalLayout->insertWidget(labelId+1, m_mapViewUi.celestialBodyComboBox);
206  m_toolBar->removeAction(m_celestialBodyAction);
207  m_mapViewUi.celestialBodyComboBox->show();
208  }
209 
210  void applyReducedLayout()
211  {
212  m_mapViewUi.projectionLabel_2->setVisible(false);
213  m_mapViewUi.celestialBodyLabel->setVisible(false);
214  m_mapViewUi.projectionComboBox->setVisible(false);
215  m_mapViewUi.mapThemeLabel->setVisible(false);
216  m_mapViewUi.line->setVisible(false);
217 
218  m_toolBar->setVisible(true);
219  m_celestialBodyAction = m_toolBar->addWidget(m_mapViewUi.celestialBodyComboBox);
220  m_mapViewUi.verticalLayout->removeWidget(m_mapViewUi.celestialBodyComboBox);
221  m_mapViewUi.celestialBodyComboBox->show();
222  }
223 
224  void setupToolBar()
225  {
226  m_toolBar = new QToolBar;
227 
228  m_globeViewButton = new QToolButton;
229  m_globeViewButton->setIcon( QIcon(":/icons/map-globe.png") );
230  m_globeViewButton->setToolTip( tr("Globe View") );
231  m_globeViewButton->setCheckable(true);
232  m_globeViewButton->setChecked(false);
233 
234  m_mercatorViewButton = new QToolButton;
235  m_mercatorViewButton->setIcon( QIcon(":/icons/map-mercator.png") );
236  m_mercatorViewButton->setToolTip( tr("Mercator View") );
237  m_mercatorViewButton->setCheckable(true);
238  m_mercatorViewButton->setChecked(false);
239  m_mercatorViewButton->setPopupMode(QToolButton::MenuButtonPopup);
240 
241  m_popupMenu = new QMenu;
242 
243  m_mercatorViewAction = new QAction( QIcon(":/icons/map-mercator.png"),
244  tr("Mercator View"),
245  m_popupMenu );
246  m_mercatorViewAction->setCheckable(true);
247  m_mercatorViewAction->setChecked(false);
248 
249  m_flatViewAction = new QAction( QIcon(":/icons/map-flat.png"),
250  tr("Flat View"),
251  m_popupMenu );
252  m_flatViewAction->setCheckable(true);
253  m_flatViewAction->setChecked(false);
254 
255  m_popupMenu->addAction(m_mercatorViewAction);
256  m_popupMenu->addAction(m_flatViewAction);
257  m_mercatorViewButton->setMenu(m_popupMenu);
258 
259  m_toolBar->addWidget(m_globeViewButton);
260  m_toolBar->addWidget(m_mercatorViewButton);
261  m_toolBar->addSeparator();
262  m_toolBar->setContentsMargins(0,0,0,0);
263  m_toolBar->setIconSize(QSize(16, 16));
264  m_mapViewUi.toolBarLayout->insertWidget(0, m_toolBar);
265 
266  QObject::connect(m_globeViewButton, SIGNAL(clicked()),
267  q, SLOT(globeViewRequested()));
268  QObject::connect(m_mercatorViewButton, SIGNAL(clicked()),
269  q, SLOT(mercatorViewRequested()));
270  QObject::connect(m_mercatorViewAction, SIGNAL(triggered()),
271  q, SLOT(mercatorViewRequested()));
272  QObject::connect(m_flatViewAction, SIGNAL(triggered()),
273  q, SLOT(flatViewRequested()));
274 
275  applyReducedLayout();
276  }
277 
278  void updateMapFilter()
279  {
280  int currentIndex = m_mapViewUi.celestialBodyComboBox->currentIndex();
281  const QString selectedId = m_celestialListProxy.data( m_celestialListProxy.index( currentIndex, 1 ) ).toString();
282 
283  if ( !selectedId.isEmpty() ) {
284  m_mapSortProxy.setFilterRegExp( QRegExp( selectedId, Qt::CaseInsensitive,QRegExp::FixedString ) );
285  }
286  }
287 
288  void celestialBodySelected( int comboIndex );
289 
290  void projectionSelected( int projectionIndex );
291 
292  void mapThemeSelected( QModelIndex index );
293  void mapThemeSelected( int index );
294 
295  void showContextMenu( const QPoint& pos );
296  void deleteMap();
297  void toggleFavorite();
298  void toggleIconSize();
299 
300  bool isCurrentFavorite();
301  QString currentThemeName() const;
302  QString currentThemePath() const;
303 
304  MapViewWidget *const q;
305 
306  Ui::MapViewWidget m_mapViewUi;
307  MarbleModel *m_marbleModel;
308 
309  MapThemeSortFilterProxyModel m_mapSortProxy;
310 
311  CelestialSortFilterProxyModel m_celestialListProxy;
312  QSettings m_settings;
313  QToolBar *m_toolBar;
314  QToolButton *m_globeViewButton;
315  QToolButton *m_mercatorViewButton;
316  QMenu *m_popupMenu;
317  QAction *m_flatViewAction;
318  QAction *m_mercatorViewAction;
319  QAction *m_celestialBodyAction;
320 };
321 
322 MapViewWidget::MapViewWidget( QWidget *parent, Qt::WindowFlags f )
323  : QWidget( parent, f ),
324  d( new Private( this ) )
325 {
326  d->m_mapViewUi.setupUi( this );
327  layout()->setMargin( 0 );
328 
329  if ( MarbleGlobal::getInstance()->profiles() & MarbleGlobal::SmallScreen ) {
330  QGridLayout* layout = new QGridLayout;
331  layout->addItem( d->m_mapViewUi.verticalLayout->takeAt( 1 ), 0, 0 );
332  layout->addItem( d->m_mapViewUi.verticalLayout->takeAt( 1 ), 0, 1 );
333  d->m_mapViewUi.line->setVisible( false );
334  layout->addItem( d->m_mapViewUi.verticalLayout->takeAt( 2 ), 1, 0 );
335  layout->addItem( d->m_mapViewUi.verticalLayout->takeAt( 2 ), 1, 1 );
336  layout->addItem( d->m_mapViewUi.verticalLayout->takeAt( 3 ), 2, 0 );
337  layout->addItem( d->m_mapViewUi.verticalLayout->takeAt( 4 ), 2, 1 );
338  d->m_mapViewUi.verticalLayout->insertLayout( 0, layout );
339  d->m_mapViewUi.mapThemeComboBox->setModel( &d->m_mapSortProxy );
340  d->m_mapViewUi.mapThemeComboBox->setIconSize( QSize( 48, 48 ) );
341  connect( d->m_mapViewUi.mapThemeComboBox, SIGNAL(activated(int)),
342  this, SLOT(mapThemeSelected(int)) );
343  d->m_mapViewUi.marbleThemeSelectView->setVisible( false );
344  }
345  else {
346  d->m_mapViewUi.marbleThemeSelectView->setViewMode( QListView::IconMode );
347  QSize const iconSize = d->m_settings.value( "MapView/iconSize", QSize( 90, 90 ) ).toSize();
348  d->m_mapViewUi.marbleThemeSelectView->setIconSize( iconSize );
349  d->m_mapViewUi.marbleThemeSelectView->setItemDelegate( new MapViewItemDelegate( d->m_mapViewUi.marbleThemeSelectView ) );
350  d->m_mapViewUi.marbleThemeSelectView->setAlternatingRowColors( true );
351  d->m_mapViewUi.marbleThemeSelectView->setFlow( QListView::LeftToRight );
352  d->m_mapViewUi.marbleThemeSelectView->setWrapping( true );
353  d->m_mapViewUi.marbleThemeSelectView->setResizeMode( QListView::Adjust );
354  d->m_mapViewUi.marbleThemeSelectView->setUniformItemSizes( true );
355  d->m_mapViewUi.marbleThemeSelectView->setMovement( QListView::Static );
356  d->m_mapViewUi.marbleThemeSelectView->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
357  d->m_mapViewUi.marbleThemeSelectView->setEditTriggers( QListView::NoEditTriggers );
358  d->m_mapViewUi.marbleThemeSelectView->setSelectionMode( QListView::SingleSelection );
359  d->m_mapViewUi.marbleThemeSelectView->setModel( &d->m_mapSortProxy );
360  connect( d->m_mapViewUi.marbleThemeSelectView, SIGNAL(pressed(QModelIndex)),
361  this, SLOT(mapThemeSelected(QModelIndex)) );
362  connect( d->m_mapViewUi.marbleThemeSelectView, SIGNAL(customContextMenuRequested(QPoint)),
363  this, SLOT(showContextMenu(QPoint)) );
364 
365  d->m_mapViewUi.mapThemeComboBox->setVisible( false );
366  d->setupToolBar();
367  }
368 
369  connect( d->m_mapViewUi.projectionComboBox, SIGNAL(activated(int)),
370  this, SLOT(projectionSelected(int)) );
371 
372  d->m_mapViewUi.projectionComboBox->setEnabled( true );
373  d->m_mapViewUi.celestialBodyComboBox->setModel( &d->m_celestialListProxy );
374 
375  connect( d->m_mapViewUi.celestialBodyComboBox, SIGNAL(activated(int)),
376  this, SLOT(celestialBodySelected(int)) );
377 
378  d->m_settings.beginGroup( "Favorites" );
379  if( !d->m_settings.contains( "initialized" ) ) {
380  d->m_settings.setValue( "initialized", true );
381  QDateTime currentDateTime = QDateTime::currentDateTime();
382  d->m_settings.setValue( "Atlas", currentDateTime );
383  d->m_settings.setValue( "OpenStreetMap", currentDateTime );
384  d->m_settings.setValue( "Satellite View", currentDateTime );
385  }
386  d->m_settings.endGroup();
387 }
388 
389 MapViewWidget::~MapViewWidget()
390 {
391  delete d;
392 }
393 
394 void MapViewWidget::setMarbleWidget( MarbleWidget *widget, MapThemeManager *mapThemeManager )
395 {
396  d->m_marbleModel = widget->model();
397  d->m_mapSortProxy.setSourceModel( mapThemeManager->mapThemeModel() );
398  d->m_mapSortProxy.sort( 0 );
399  d->m_celestialListProxy.setSourceModel( mapThemeManager->celestialBodiesModel() );
400  d->m_celestialListProxy.sort( 0 );
401 
402  connect( this, SIGNAL(projectionChanged(Projection)),
403  widget, SLOT(setProjection(Projection)) );
404 
405  connect( widget, SIGNAL(themeChanged(QString)),
406  this, SLOT(setMapThemeId(QString)) );
407 
408  connect( widget, SIGNAL(projectionChanged(Projection)),
409  this, SLOT(setProjection(Projection)) );
410 
411  connect( this, SIGNAL(mapThemeIdChanged(QString)),
412  widget, SLOT(setMapThemeId(QString)) );
413 
414  setProjection(widget->projection());
415  setMapThemeId(widget->mapThemeId());
416 }
417 
418 void MapViewWidget::resizeEvent(QResizeEvent *event)
419 {
420  if (!d->m_toolBar)
421  return;
422 
423  if (d->m_toolBar->isVisible() && event->size().height() > 400) {
424  d->applyExtendedLayout();
425  } else if (!d->m_toolBar->isVisible() && event->size().height() <= 400) {
426  d->applyReducedLayout();
427  }
428 }
429 
430 void MapViewWidget::setMapThemeId( const QString &themeId )
431 {
432  const bool smallscreen = MarbleGlobal::getInstance()->profiles() & MarbleGlobal::SmallScreen;
433 
434  const int currentRow = smallscreen ? d->m_mapViewUi.mapThemeComboBox->currentIndex() :
435  d->m_mapViewUi.marbleThemeSelectView->currentIndex().row();
436  const QString oldThemeId = d->m_mapSortProxy.data( d->m_mapSortProxy.index( currentRow, 0 ), Qt::UserRole + 1 ).toString();
437 
438  // Check if the new selected theme is different from the current one
439  if ( themeId == oldThemeId )
440  return;
441 
442  const QString oldCelestialBodyId = oldThemeId.section( '/', 0, 0 );
443  const QString celestialBodyId = themeId.section( '/', 0, 0 );
444 
445  // select celestialBodyId in GUI
446  if ( celestialBodyId != oldCelestialBodyId ) {
447  for ( int row = 0; row < d->m_celestialListProxy.rowCount(); ++row ) {
448  if ( d->m_celestialListProxy.data( d->m_celestialListProxy.index( row, 1 ) ).toString() == celestialBodyId ) {
449  d->m_mapViewUi.celestialBodyComboBox->setCurrentIndex( row );
450  break;
451  }
452  }
453 
454  d->updateMapFilter();
455  }
456 
457  // select themeId in GUI
458  for ( int row = 0; row < d->m_mapSortProxy.rowCount(); ++row ) {
459  if( d->m_mapSortProxy.data( d->m_mapSortProxy.index( row, 0 ), Qt::UserRole + 1 ).toString() == themeId ) {
460  if ( smallscreen ) {
461  d->m_mapViewUi.mapThemeComboBox->setCurrentIndex( row );
462  }
463  else {
464  const QModelIndex index = d->m_mapSortProxy.index( row, 0 );
465  d->m_mapViewUi.marbleThemeSelectView->setCurrentIndex( index );
466  d->m_mapViewUi.marbleThemeSelectView->scrollTo( index );
467  }
468 
469  break;
470  }
471  }
472 }
473 
474 void MapViewWidget::setProjection( Projection projection )
475 {
476  if ( (int)projection != d->m_mapViewUi.projectionComboBox->currentIndex() )
477  d->m_mapViewUi.projectionComboBox->setCurrentIndex( (int) projection );
478 
479  if (d->m_toolBar) {
480  switch (projection) {
481  case Marble::Spherical:
482  d->m_globeViewButton->setChecked(true);
483  d->m_mercatorViewButton->setChecked(false);
484  d->m_mercatorViewAction->setChecked(false);
485  d->m_flatViewAction->setChecked(false);
486  break;
487  case Marble::Mercator:
488  d->m_mercatorViewButton->setChecked(true);
489  d->m_mercatorViewAction->setChecked(true);
490  d->m_globeViewButton->setChecked(false);
491  d->m_flatViewAction->setChecked(false);
492  break;
493  case Marble::Equirectangular:
494  d->m_flatViewAction->setChecked(true);
495  d->m_mercatorViewButton->setChecked(true);
496  d->m_globeViewButton->setChecked(false);
497  d->m_mercatorViewAction->setChecked(false);
498  break;
499  }
500  }
501 }
502 
503 void MapViewWidget::globeViewRequested()
504 {
505  emit projectionChanged(Marble::Spherical);
506 }
507 
508 void MapViewWidget::flatViewRequested()
509 {
510  emit projectionChanged(Marble::Equirectangular);
511 }
512 
513 void MapViewWidget::mercatorViewRequested()
514 {
515  emit projectionChanged(Marble::Mercator);
516 }
517 
518 void MapViewWidget::Private::celestialBodySelected( int comboIndex )
519 {
520  Q_UNUSED( comboIndex )
521 
522  updateMapFilter();
523 
524  bool foundMapTheme = false;
525 
526  QString currentMapThemeId = m_marbleModel->mapThemeId();
527  QString oldPlanetId = m_marbleModel->planetId();
528 
529  int row = m_mapSortProxy.rowCount();
530 
531  for ( int i = 0; i < row; ++i )
532  {
533  QModelIndex index = m_mapSortProxy.index(i,0);
534  QString itMapThemeId = m_mapSortProxy.data(index, Qt::UserRole + 1).toString();
535  if ( currentMapThemeId == itMapThemeId )
536  {
537  foundMapTheme = true;
538  break;
539  }
540  }
541  if ( !foundMapTheme ) {
542  QModelIndex index = m_mapSortProxy.index(0,0);
543  emit q->mapThemeIdChanged( m_mapSortProxy.data( index, Qt::UserRole + 1 ).toString() );
544  }
545 
546  if( oldPlanetId != m_marbleModel->planetId() ) {
547  emit q->celestialBodyChanged( m_marbleModel->planetId() );
548  }
549 }
550 
551 // Relay a signal and convert the parameter from an int to a Projection.
552 void MapViewWidget::Private::projectionSelected( int projectionIndex )
553 {
554  emit q->projectionChanged( (Projection) projectionIndex );
555 }
556 
557 void MapViewWidget::Private::mapThemeSelected( QModelIndex index )
558 {
559  mapThemeSelected( index.row() );
560 }
561 
562 void MapViewWidget::Private::mapThemeSelected( int index )
563 {
564  const QModelIndex columnIndex = m_mapSortProxy.index( index, 0 );
565  const QString currentmaptheme = m_mapSortProxy.data( columnIndex, Qt::UserRole + 1 ).toString();
566 
567  mDebug() << Q_FUNC_INFO << currentmaptheme;
568 
569  emit q->mapThemeIdChanged( currentmaptheme );
570 }
571 
572 QString MapViewWidget::Private::currentThemeName() const
573 {
574  const QModelIndex index = m_mapViewUi.marbleThemeSelectView->currentIndex();
575  const QModelIndex columnIndex = m_mapSortProxy.index( index.row(), 0, QModelIndex() );
576 
577  return m_mapSortProxy.data( columnIndex ).toString();
578 }
579 
580 QString MapViewWidget::Private::currentThemePath() const
581 {
582  const QModelIndex index = m_mapViewUi.marbleThemeSelectView->currentIndex();
583  const QModelIndex columnIndex = m_mapSortProxy.index( index.row(), 0 );
584 
585  return m_mapSortProxy.data( columnIndex, Qt::UserRole + 1 ).toString();
586 }
587 
588 void MapViewWidget::Private::showContextMenu( const QPoint& pos )
589 {
590  QMenu menu;
591 
592  QAction* iconSizeAction = menu.addAction( tr( "&Show Large Icons" ), q, SLOT(toggleIconSize()) );
593  iconSizeAction->setCheckable( true );
594  iconSizeAction->setChecked( m_mapViewUi.marbleThemeSelectView->iconSize() == QSize( 96, 96 ) );
595  QAction *favAction = menu.addAction( QIcon( ":/icons/bookmarks.png" ), tr( "&Favorite" ), q, SLOT(toggleFavorite()) );
596  favAction->setCheckable( true );
597  favAction->setChecked( isCurrentFavorite() );
598  menu.addSeparator();
599 
600  menu.addAction( QIcon( ":/icons/create-new-map.png" ), tr("&Create a New Map..."), q, SIGNAL(showMapWizard()) );
601  if( QFileInfo( MarbleDirs::localPath() + "/maps/" + currentThemePath() ).exists() )
602  menu.addAction( tr( "&Delete Map Theme" ), q, SLOT(deleteMap()) );
603  menu.addAction( tr( "&Upload Map..." ), q, SIGNAL(showUploadDialog()) );
604  menu.exec( m_mapViewUi.marbleThemeSelectView->mapToGlobal( pos ) );
605 }
606 
607 void MapViewWidget::Private::deleteMap()
608 {
609  if(QMessageBox::warning( q,
610  tr( "Marble" ),
611  tr( "Are you sure that you want to delete \"%1\"?" ).arg( currentThemeName() ),
612  QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes )
613  {
614  MapThemeManager::deleteMapTheme( currentThemePath() );
615  emit q->mapThemeDeleted();
616  }
617 }
618 
619 void MapViewWidget::Private::toggleFavorite()
620 {
621  const QModelIndex index = m_mapViewUi.marbleThemeSelectView->currentIndex();
622  const QModelIndex columnIndex = m_mapSortProxy.index( index.row(), 0 );
623 
624  if( isCurrentFavorite() ) {
625  m_settings.beginGroup( "Favorites" );
626  m_settings.remove( m_mapSortProxy.data( columnIndex ).toString() );
627  }
628  else {
629  m_settings.beginGroup( "Favorites" );
630  m_settings.setValue( m_mapSortProxy.data( columnIndex ).toString(), QDateTime::currentDateTime() );
631  }
632  m_settings.endGroup();
633 }
634 
635 void MapViewWidget::Private::toggleIconSize()
636 {
637  bool const isLarge = m_mapViewUi.marbleThemeSelectView->iconSize() == QSize( 96, 96 );
638  int const size = isLarge ? 52 : 96;
639  m_mapViewUi.marbleThemeSelectView->setIconSize( QSize( size, size ) );
640  m_settings.setValue("MapView/iconSize", m_mapViewUi.marbleThemeSelectView->iconSize() );
641 }
642 
643 bool MapViewWidget::Private::isCurrentFavorite()
644 {
645  const QModelIndex index = m_mapViewUi.marbleThemeSelectView->currentIndex();
646  const QModelIndex nameIndex = m_mapSortProxy.index( index.row(), 0 );
647 
648  m_settings.beginGroup( "Favorites" );
649  const bool isFavorite = m_settings.contains( m_mapSortProxy.data( nameIndex ).toString() );
650  m_settings.endGroup();
651 
652  return isFavorite;
653 }
654 
655 MapViewItemDelegate::MapViewItemDelegate( QListView *view ) :
656  m_view( view ), m_bookmarkIcon( ":/icons/bookmarks.png" )
657 {
658  // nothing to do
659 }
660 
661 void MapViewItemDelegate::paint( QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const
662 {
663  QStyleOptionViewItemV4 styleOption = option;
664  styleOption.text = QString();
665  QApplication::style()->drawControl(QStyle::CE_ItemViewItem, &styleOption, painter);
666 
667  QAbstractTextDocumentLayout::PaintContext paintContext;
668  if (styleOption.state & QStyle::State_Selected) {
669  paintContext.palette.setColor(QPalette::Text,
670  styleOption.palette.color(QPalette::Active, QPalette::HighlightedText));
671  }
672 
673  QRect const rect = option.rect;
674  QSize const iconSize = option.decorationSize;
675  QRect const iconRect( rect.topLeft(), iconSize );
676  QIcon const icon = index.data( Qt::DecorationRole ).value<QIcon>();
677  painter->drawPixmap( iconRect, icon.pixmap( iconSize ) );
678 
679  int const padding = 5;
680  QString const name = index.data().toString();
681  const bool isFavorite = QSettings().contains( "Favorites/" + name );
682  QSize const bookmarkSize( 16, 16 );
683  QRect bookmarkRect( iconRect.bottomRight(), bookmarkSize );
684  bookmarkRect.translate( QPoint( -bookmarkSize.width() - padding, -bookmarkSize.height() - padding ) );
685  QIcon::Mode mode = isFavorite ? QIcon::Normal : QIcon::Disabled;
686  painter->drawPixmap( bookmarkRect, m_bookmarkIcon.pixmap( bookmarkSize, mode ) );
687 
688  QTextDocument document;
689  document.setTextWidth( rect.width() - iconSize.width() - padding );
690  document.setDefaultFont( option.font );
691  document.setHtml( text( index ) );
692 
693  QRect textRect = QRect( iconRect.topRight(), QSize( document.textWidth() - padding, rect.height() - padding ) );
694  painter->save();
695  painter->translate( textRect.topLeft() );
696  painter->setClipRect( textRect.translated( -textRect.topLeft() ) );
697  document.documentLayout()->draw( painter, paintContext );
698  painter->restore();
699 }
700 
701 QSize MapViewItemDelegate::sizeHint( const QStyleOptionViewItem &option, const QModelIndex &index ) const
702 {
703  if ( index.column() == 0 ) {
704  QSize const iconSize = option.decorationSize;
705  QTextDocument doc;
706  doc.setDefaultFont( option.font );
707  doc.setTextWidth( m_view->width() - iconSize.width() - 10 );
708  doc.setHtml( text( index ) );
709  return QSize( iconSize.width() + doc.size().width(), iconSize.height() );
710  }
711 
712  return QSize();
713 }
714 
715 QString MapViewItemDelegate::text( const QModelIndex &index ) const
716 {
717  QString const title = index.data().toString();
718  QString const description = index.data( Qt::UserRole+2 ).toString();
719  return QString("<p><b>%1</b></p>%2").arg( title ).arg( description );
720 }
721 
722 }
723 
724 #include "MapViewWidget.moc"
GeoSceneHead.h
Marble::MapThemeManager::mapThemeModel
QStandardItemModel * mapThemeModel()
Provides a model of the locally existing themes.
Definition: MapThemeManager.cpp:319
QPainter
Marble::MarbleWidget::projection
int projection
Definition: MarbleWidget.h:112
MarbleModel.h
This file contains the headers for MarbleModel.
QWidget
Marble::MapViewWidget::setMapThemeId
void setMapThemeId(const QString &)
Definition: MapViewWidget.cpp:430
Marble::MapViewWidget::setProjection
void setProjection(Projection projection)
Definition: MapViewWidget.cpp:474
Marble::MapViewWidget
Definition: MapViewWidget.h:32
GeoSceneDocument.h
Marble::MarbleDirs::localPath
static QString localPath()
Definition: MarbleDirs.cpp:217
Marble::MapViewWidget::Private
friend class Private
Definition: MapViewWidget.h:81
Marble::MapViewWidget::mapThemeIdChanged
void mapThemeIdChanged(const QString &)
MarbleDebug.h
Marble::MarbleWidget
A widget class that displays a view of the earth.
Definition: MarbleWidget.h:102
Marble::Equirectangular
Flat projection ("plate carree")
Definition: MarbleGlobal.h:46
Marble::Mercator
Mercator projection.
Definition: MarbleGlobal.h:47
MarbleDirs.h
Marble::MarbleWidget::model
MarbleModel * model() const
Return the model that this view shows.
Definition: MarbleWidget.cpp:283
Marble::MapThemeManager::deleteMapTheme
static void deleteMapTheme(const QString &mapThemeId)
Deletes the map theme with the specified map theme ID.
Definition: MapThemeManager.cpp:163
Marble::MapViewWidget::projectionChanged
void projectionChanged(Projection)
MapThemeSortFilterProxyModel.h
Marble::MarbleGlobal::SmallScreen
Definition: MarbleGlobal.h:268
Marble::MarbleGlobal::getInstance
static MarbleGlobal * getInstance()
Definition: MarbleGlobal.cpp:37
Marble::MarbleModel
The data model (not based on QAbstractModel) for a MarbleWidget.
Definition: MarbleModel.h:96
Marble::MapThemeManager
The class that handles map themes that are locally available .
Definition: MapThemeManager.h:48
Marble::MapViewWidget::setMarbleWidget
void setMarbleWidget(MarbleWidget *widget, MapThemeManager *mapThemeManager)
Set a MarbleWidget associated to this widget.
Definition: MapViewWidget.cpp:394
Marble::MarbleGlobal::profiles
Profiles profiles() const
Definition: MarbleGlobal.cpp:48
Marble::Projection
Projection
This enum is used to choose the projection shown in the view.
Definition: MarbleGlobal.h:44
Marble::MarbleWidget::mapThemeId
QString mapThemeId
Definition: MarbleWidget.h:111
MarbleWidget.h
This file contains the headers for MarbleWidget.
iconSize
const QSize iconSize(16, 16)
Marble::Spherical
Spherical projection.
Definition: MarbleGlobal.h:45
MapViewWidget.h
Marble::MapViewWidget::resizeEvent
void resizeEvent(QResizeEvent *event)
Definition: MapViewWidget.cpp:418
Marble::MapViewWidget::MapViewWidget
MapViewWidget(QWidget *parent=0, Qt::WindowFlags f=0)
Definition: MapViewWidget.cpp:322
Marble::mDebug
QDebug mDebug()
a function to replace qDebug() in Marble library code
Definition: MarbleDebug.cpp:31
Marble::MapThemeManager::celestialBodiesModel
QStandardItemModel * celestialBodiesModel()
Provides a model of all installed planets.
Definition: MapThemeManager.cpp:328
Marble::MapThemeSortFilterProxyModel
Definition: MapThemeSortFilterProxyModel.h:21
MapThemeManager.h
Marble::MapViewWidget::~MapViewWidget
~MapViewWidget()
Definition: MapViewWidget.cpp:389
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:38:51 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

marble

Skip menu "marble"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal