• 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
  • plugins
  • render
  • navigation
NavigationFloatItem.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 2008 Dennis Nienhüser <earthwings@gentoo.org>
9 // Copyright 2010 Bastian Holst <bastianholst@gmx.de>
10 // Copyright 2013 Mohammed Nafees <nafees.technocool@gmail.com>
11 //
12 
13 #include "NavigationFloatItem.h"
14 
15 #include <qmath.h>
16 #include <QRect>
17 #include <QPixmap>
18 #include <QToolButton>
19 #include <QSlider>
20 #include <QWidget>
21 #include <QPainter>
22 #include <QPixmapCache>
23 
24 #include "ui_navigation.h"
25 #include "ViewportParams.h"
26 #include "MarbleDebug.h"
27 #include "MarbleWidget.h"
28 #include "MarbleModel.h"
29 #include "PositionTracking.h"
30 #include "WidgetGraphicsItem.h"
31 #include "MarbleGraphicsGridLayout.h"
32 
33 using namespace Marble;
34 /* TRANSLATOR Marble::NavigationFloatItem */
35 
36 NavigationFloatItem::NavigationFloatItem()
37  : AbstractFloatItem( 0 )
38 {
39 }
40 
41 NavigationFloatItem::NavigationFloatItem( const MarbleModel *marbleModel )
42  : AbstractFloatItem( marbleModel, QPointF( -10, -30 ) ),
43  m_marbleWidget( 0 ),
44  m_widgetItem( 0 ),
45  m_navigationWidget( 0 ),
46  m_oldViewportRadius( 0 ),
47  m_contextMenu( 0 )
48 {
49  // Plugin is visible by default on desktop systems
50  const bool smallScreen = MarbleGlobal::getInstance()->profiles() & MarbleGlobal::SmallScreen;
51  setEnabled( !smallScreen );
52  setVisible( true );
53 
54  setCacheMode( NoCache );
55  setBackground( QBrush( QColor( Qt::transparent ) ) );
56  setFrame( NoFrame );
57 }
58 
59 NavigationFloatItem::~NavigationFloatItem()
60 {
61  QPixmapCache::remove( "marble/navigation/navigational_backdrop_top" );
62  QPixmapCache::remove( "marble/navigation/navigational_backdrop_center" );
63  QPixmapCache::remove( "marble/navigation/navigational_backdrop_bottom" );
64  QPixmapCache::remove( "marble/navigation/navigational_currentlocation" );
65  QPixmapCache::remove( "marble/navigation/navigational_currentlocation_hover" );
66  QPixmapCache::remove( "marble/navigation/navigational_currentlocation_pressed" );
67 
68  delete m_navigationWidget;
69 }
70 
71 QStringList NavigationFloatItem::backendTypes() const
72 {
73  return QStringList("navigation");
74 }
75 
76 QString NavigationFloatItem::name() const
77 {
78  return tr("Navigation");
79 }
80 
81 QString NavigationFloatItem::guiString() const
82 {
83  return tr("&Navigation");
84 }
85 
86 QString NavigationFloatItem::nameId() const
87 {
88  return QString("navigation");
89 }
90 
91 QString NavigationFloatItem::version() const
92 {
93  return "1.0";
94 }
95 
96 QString NavigationFloatItem::description() const
97 {
98  return tr("A mouse control to zoom and move the map");
99 }
100 
101 QString NavigationFloatItem::copyrightYears() const
102 {
103  return "2008, 2010, 2013";
104 }
105 
106 QList<PluginAuthor> NavigationFloatItem::pluginAuthors() const
107 {
108  return QList<PluginAuthor>()
109  << PluginAuthor( QString::fromUtf8( "Dennis Nienhüser" ), "earthwings@gentoo.org" )
110  << PluginAuthor( "Bastian Holst", "bastianholst@gmx.de" )
111  << PluginAuthor( "Mohammed Nafees", "nafees.technocool@gmail.com" );
112 }
113 
114 QIcon NavigationFloatItem::icon() const
115 {
116  return QIcon(":/icons/navigation.png");
117 }
118 
119 void NavigationFloatItem::initialize()
120 {
121  QWidget *navigationParent = new QWidget( 0 );
122  navigationParent->setAttribute( Qt::WA_NoSystemBackground, true );
123 
124  m_navigationWidget = new Ui::Navigation;
125  m_navigationWidget->setupUi( navigationParent );
126 
127  m_widgetItem = new WidgetGraphicsItem( this );
128  m_widgetItem->setWidget( navigationParent );
129 
130  MarbleGraphicsGridLayout *layout = new MarbleGraphicsGridLayout( 1, 1 );
131  layout->addItem( m_widgetItem, 0, 0 );
132 
133  setLayout( layout );
134 }
135 
136 bool NavigationFloatItem::isInitialized() const
137 {
138  return m_widgetItem;
139 }
140 
141 void NavigationFloatItem::changeViewport( ViewportParams *viewport )
142 {
143  if ( viewport->radius() != m_oldViewportRadius ) {
144  m_oldViewportRadius = viewport->radius();
145  // The slider depends on the map state (zoom factor)
146  update();
147  }
148 }
149 
150 bool NavigationFloatItem::eventFilter( QObject *object, QEvent *e )
151 {
152  if ( !enabled() || !visible() ) {
153  return false;
154  }
155 
156  MarbleWidget *widget = dynamic_cast<MarbleWidget*> (object);
157  if ( !widget ) {
158  return AbstractFloatItem::eventFilter( object, e );
159  }
160 
161  if ( m_marbleWidget != widget ) {
162  // Delayed initialization
163  m_marbleWidget = widget;
164 
165  m_maxZoom = m_marbleWidget->maximumZoom();
166  m_minZoom = m_marbleWidget->minimumZoom();
167 
168  m_navigationWidget->arrowDisc->setMarbleWidget( m_marbleWidget );
169  connect( m_navigationWidget->arrowDisc, SIGNAL(repaintNeeded()), SIGNAL(repaintNeeded()) );
170 
171  connect( m_navigationWidget->homeButton, SIGNAL(repaintNeeded()), SIGNAL(repaintNeeded()) );
172  connect( m_navigationWidget->homeButton, SIGNAL(clicked()),
173  m_marbleWidget, SLOT(goHome()) );
174 
175  connect( m_navigationWidget->zoomInButton, SIGNAL(repaintNeeded()), SIGNAL(repaintNeeded()) );
176  connect( m_navigationWidget->zoomInButton, SIGNAL(clicked()),
177  m_marbleWidget, SLOT(zoomIn()) );
178 
179  m_navigationWidget->zoomSlider->setMaximum( m_maxZoom );
180  m_navigationWidget->zoomSlider->setMinimum( m_minZoom );
181  connect( m_navigationWidget->zoomSlider, SIGNAL(repaintNeeded()), SIGNAL(repaintNeeded()) );
182  connect( m_navigationWidget->zoomSlider, SIGNAL(valueChanged(int)),
183  m_marbleWidget, SLOT(setZoom(int)) );
184 
185  connect( m_navigationWidget->zoomOutButton, SIGNAL(repaintNeeded()), SIGNAL(repaintNeeded()) );
186  connect( m_navigationWidget->zoomOutButton, SIGNAL(clicked()),
187  m_marbleWidget, SLOT(zoomOut()) );
188 
189  connect( m_marbleWidget, SIGNAL(zoomChanged(int)), SLOT(updateButtons(int)) );
190  updateButtons( m_marbleWidget->zoom() );
191  connect( m_marbleWidget, SIGNAL(themeChanged(QString)), this, SLOT(selectTheme(QString)) );
192  }
193 
194  return AbstractFloatItem::eventFilter(object, e);
195 }
196 
197 void NavigationFloatItem::selectTheme( QString )
198 {
199  if ( m_marbleWidget ) {
200  m_maxZoom = m_marbleWidget->maximumZoom();
201  m_minZoom = m_marbleWidget->minimumZoom();
202  m_navigationWidget->zoomSlider->setMaximum( m_maxZoom );
203  m_navigationWidget->zoomSlider->setMinimum( m_minZoom );
204  updateButtons( m_marbleWidget->zoom() );
205  }
206 }
207 
208 void NavigationFloatItem::updateButtons( int zoomValue )
209 {
210  bool const zoomInEnabled = m_navigationWidget->zoomInButton->isEnabled();
211  bool const zoomOutEnabled = m_navigationWidget->zoomOutButton->isEnabled();
212  int const oldZoomValue = m_navigationWidget->zoomSlider->value();
213  m_navigationWidget->zoomInButton->setEnabled( zoomValue < m_maxZoom );
214  m_navigationWidget->zoomOutButton->setEnabled( zoomValue > m_minZoom );
215  m_navigationWidget->zoomSlider->setValue( zoomValue );
216  if ( zoomInEnabled != m_navigationWidget->zoomInButton->isEnabled() ||
217  zoomOutEnabled != m_navigationWidget->zoomOutButton->isEnabled() ||
218  oldZoomValue != zoomValue ) {
219  update();
220  }
221 }
222 
223 QPixmap NavigationFloatItem::pixmap( const QString &id ) const
224 {
225  QPixmap result;
226  if ( !QPixmapCache::find( id, result ) ) {
227  result = QPixmap( QString( ":/%1.png" ).arg( id ) );
228  QPixmapCache::insert( id, result );
229  }
230  return result;
231 }
232 
233 void NavigationFloatItem::paintContent( QPainter *painter )
234 {
235  painter->drawPixmap( 0, 0, pixmap( "marble/navigation/navigational_backdrop_top" ) );
236  painter->drawPixmap( 0, 70, pixmap( "marble/navigation/navigational_backdrop_center" ) );
237  painter->drawPixmap( 0, 311, pixmap( "marble/navigation/navigational_backdrop_bottom" ) );
238 }
239 
240 void NavigationFloatItem::contextMenuEvent( QWidget *w, QContextMenuEvent *e )
241 {
242  if ( !m_contextMenu ) {
243  m_contextMenu = contextMenu();
244 
245  m_activateCurrentPositionButtonAction = new QAction( QIcon(),
246  tr( "Current Location Button" ),
247  m_contextMenu );
248  m_activateHomeButtonAction = new QAction( QIcon( ":/icons/go-home.png" ),
249  tr( "Home Button" ),
250  m_contextMenu );
251  m_activateHomeButtonAction->setVisible( false );
252  m_contextMenu->addSeparator();
253  m_contextMenu->addAction( m_activateCurrentPositionButtonAction );
254  m_contextMenu->addAction( m_activateHomeButtonAction );
255 
256  connect( m_activateCurrentPositionButtonAction, SIGNAL(triggered()), SLOT(toggleToCurrentPositionButton()) );
257  connect( m_activateHomeButtonAction, SIGNAL(triggered()), SLOT(toggleToHomeButton()) );
258  }
259 
260  Q_ASSERT( m_contextMenu );
261  m_contextMenu->exec( w->mapToGlobal( e->pos() ) );
262 }
263 
264 void NavigationFloatItem::writeSettings()
265 {
266  if ( m_activateCurrentPositionButtonAction->isVisible() ) {
267  m_activateCurrentPositionButtonAction->setVisible( false );
268  m_activateHomeButtonAction->setVisible( true );
269  } else {
270  m_activateCurrentPositionButtonAction->setVisible( true );
271  m_activateHomeButtonAction->setVisible( false );
272  }
273 
274  emit settingsChanged( nameId() );
275 }
276 
277 void NavigationFloatItem::toggleToCurrentPositionButton()
278 {
279  writeSettings();
280 
281  QIcon icon;
282  icon.addPixmap( pixmap("marble/navigation/navigational_currentlocation"), QIcon::Normal );
283  icon.addPixmap( pixmap("marble/navigation/navigational_currentlocation_hover"), QIcon::Active );
284  icon.addPixmap( pixmap("marble/navigation/navigational_currentlocation_pressed"), QIcon::Selected );
285  m_navigationWidget->homeButton->setProperty("icon", QVariant(icon));
286  disconnect( m_navigationWidget->homeButton, SIGNAL(clicked()), m_marbleWidget, SLOT(goHome()) );
287  connect( m_navigationWidget->homeButton, SIGNAL(clicked()), SLOT(centerOnCurrentLocation()) );
288 
289  emit repaintNeeded();
290  emit settingsChanged( nameId() );
291 }
292 
293 void NavigationFloatItem::toggleToHomeButton()
294 {
295  writeSettings();
296 
297  QIcon icon;
298  icon.addPixmap( pixmap("marble/navigation/navigational_homebutton"), QIcon::Normal );
299  icon.addPixmap( pixmap("marble/navigation/navigational_homebutton_hover"), QIcon::Active );
300  icon.addPixmap( pixmap("marble/navigation/navigational_homebutton_press"), QIcon::Selected );
301  m_navigationWidget->homeButton->setProperty("icon", QVariant(icon));
302  disconnect( m_navigationWidget->homeButton, SIGNAL(clicked()), this, SLOT(centerOnCurrentLocation()) );
303  connect( m_navigationWidget->homeButton, SIGNAL(clicked()), m_marbleWidget, SLOT(goHome()) );
304 
305  emit repaintNeeded();
306  emit settingsChanged( nameId() );
307 }
308 
309 void NavigationFloatItem::centerOnCurrentLocation()
310 {
311  if ( m_marbleWidget->model()->positionTracking()->currentLocation().isValid() ) {
312  m_marbleWidget->centerOn( m_marbleWidget->model()->positionTracking()->currentLocation(), true );
313  }
314 }
315 
316 Q_EXPORT_PLUGIN2( NavigationFloatItem, Marble::NavigationFloatItem )
317 
318 #include "NavigationFloatItem.moc"
QPainter
Marble::AbstractFloatItem::visible
bool visible() const
Check visibility of the float item.
Definition: AbstractFloatItem.cpp:135
Marble::WidgetGraphicsItem::setWidget
void setWidget(QWidget *widget)
Definition: WidgetGraphicsItem.cpp:48
Marble::NavigationFloatItem::guiString
QString guiString() const
String that should be displayed in GUI.
Definition: NavigationFloatItem.cpp:81
Marble::NavigationFloatItem::backendTypes
QStringList backendTypes() const
Returns the name(s) of the backend that the plugin can render This method should return the name of t...
Definition: NavigationFloatItem.cpp:71
Marble::RenderPlugin::repaintNeeded
void repaintNeeded(QRegion dirtyRegion=QRegion())
This signal is emitted if an update of the view is needed.
Marble::NavigationFloatItem::NavigationFloatItem
NavigationFloatItem()
Definition: NavigationFloatItem.cpp:36
MarbleModel.h
This file contains the headers for MarbleModel.
QWidget
Marble::PluginAuthor
Definition: PluginInterface.h:28
Marble::AbstractFloatItem::eventFilter
virtual bool eventFilter(QObject *object, QEvent *e)
Definition: AbstractFloatItem.cpp:161
Marble::FrameGraphicsItem::setBackground
void setBackground(const QBrush &background)
Changes the background brush of the item.
Definition: FrameGraphicsItem.cpp:165
Marble::NavigationFloatItem::version
QString version() const
Definition: NavigationFloatItem.cpp:91
Marble::NavigationFloatItem::pluginAuthors
QList< PluginAuthor > pluginAuthors() const
Definition: NavigationFloatItem.cpp:106
Marble::NavigationFloatItem::eventFilter
bool eventFilter(QObject *object, QEvent *e)
Definition: NavigationFloatItem.cpp:150
Marble::MarbleGraphicsItem::setLayout
void setLayout(AbstractMarbleGraphicsLayout *layout)
Set the layout of the graphics item.
Definition: MarbleGraphicsItem.cpp:146
Marble::MarbleGraphicsGridLayout::addItem
void addItem(ScreenGraphicsItem *item, int row, int column)
Definition: MarbleGraphicsGridLayout.cpp:74
QObject
MarbleDebug.h
Marble::MarbleWidget
A widget class that displays a view of the earth.
Definition: MarbleWidget.h:102
Marble::NavigationFloatItem::copyrightYears
QString copyrightYears() const
Definition: NavigationFloatItem.cpp:101
Marble::NavigationFloatItem::pixmap
QPixmap pixmap(const QString &Id) const
Definition: NavigationFloatItem.cpp:223
Marble::MarbleWidget::zoom
int zoom
Definition: MarbleWidget.h:109
Marble::NavigationFloatItem::description
QString description() const
Returns a user description of the plugin.
Definition: NavigationFloatItem.cpp:96
Marble::MarbleGraphicsItem::NoCache
Definition: MarbleGraphicsItem.h:40
Marble::NavigationFloatItem::icon
QIcon icon() const
Returns an icon for the plugin.
Definition: NavigationFloatItem.cpp:114
Marble::RenderPlugin::settingsChanged
void settingsChanged(QString nameId)
This signal is emitted if the settings of the RenderPlugin changed.
Marble::FrameGraphicsItem::NoFrame
Definition: FrameGraphicsItem.h:29
Marble::AbstractFloatItem
The abstract class for float item plugins.
Definition: AbstractFloatItem.h:48
Marble::MarbleWidget::maximumZoom
int maximumZoom() const
Return the minimum zoom value for the current map theme.
Definition: MarbleWidget.cpp:382
Marble::NavigationFloatItem
Provides a float item with zoom and move controls.
Definition: NavigationFloatItem.h:37
Marble::MarbleModel::positionTracking
PositionTracking * positionTracking() const
Definition: MarbleModel.cpp:442
Marble::MarbleWidget::model
MarbleModel * model() const
Return the model that this view shows.
Definition: MarbleWidget.cpp:283
Marble::MarbleGraphicsGridLayout
Definition: MarbleGraphicsGridLayout.h:27
Marble::NavigationFloatItem::initialize
void initialize()
Definition: NavigationFloatItem.cpp:119
Marble::WidgetGraphicsItem
Definition: WidgetGraphicsItem.h:28
Marble::MarbleWidget::minimumZoom
int minimumZoom() const
Return the minimum zoom value for the current map theme.
Definition: MarbleWidget.cpp:377
WidgetGraphicsItem.h
Marble::ViewportParams
A public class that controls what is visible in the viewport of a Marble map.
Definition: ViewportParams.h:44
Marble::NavigationFloatItem::contextMenuEvent
void contextMenuEvent(QWidget *w, QContextMenuEvent *e)
Definition: NavigationFloatItem.cpp:240
Q_EXPORT_PLUGIN2
#define Q_EXPORT_PLUGIN2(a, b)
Definition: marble_export.h:34
Marble::NavigationFloatItem::paintContent
void paintContent(QPainter *painter)
Here the items paint their content.
Definition: NavigationFloatItem.cpp:233
Marble::MarbleWidget::centerOn
void centerOn(const qreal lon, const qreal lat, bool animated=false)
Center the view on a geographical point.
Definition: MarbleWidget.cpp:626
MarbleGraphicsGridLayout.h
ViewportParams.h
This file contains the headers for ViewportParams.
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::RenderPlugin::setEnabled
void setEnabled(bool enabled)
settting enabled
Definition: RenderPlugin.cpp:137
Marble::MarbleGraphicsItem::setCacheMode
void setCacheMode(CacheMode mode)
Set the cache mode of the item.
Definition: MarbleGraphicsItem.cpp:159
Marble::ViewportParams::radius
int radius() const
Definition: ViewportParams.cpp:195
NavigationFloatItem.h
Marble::MarbleGlobal::profiles
Profiles profiles() const
Definition: MarbleGlobal.cpp:48
Marble::FrameGraphicsItem::setFrame
void setFrame(FrameType type)
Sets the type of the Frame.
Definition: FrameGraphicsItem.cpp:47
Marble::NavigationFloatItem::nameId
QString nameId() const
Returns the unique name of the plugin.
Definition: NavigationFloatItem.cpp:86
Marble::MarbleGraphicsItem::update
void update()
Marks the item and all parent items as invalid.
Definition: MarbleGraphicsItem.cpp:167
MarbleWidget.h
This file contains the headers for MarbleWidget.
Marble::NavigationFloatItem::name
QString name() const
Returns the user-visible name of the plugin.
Definition: NavigationFloatItem.cpp:76
Marble::MarbleGraphicsItem::layout
AbstractMarbleGraphicsLayout * layout() const
Returns the layout of the MarbleGraphicsItem.
Definition: MarbleGraphicsItem.cpp:141
Marble::NavigationFloatItem::~NavigationFloatItem
~NavigationFloatItem()
Definition: NavigationFloatItem.cpp:59
Marble::RenderPlugin::enabled
bool enabled() const
is enabled
Marble::PositionTracking::currentLocation
GeoDataCoordinates currentLocation() const
Returns the current position, if any.
Definition: PositionTracking.cpp:388
Marble::GeoDataCoordinates::isValid
bool isValid() const
Returns.
Definition: GeoDataCoordinates.cpp:624
PositionTracking.h
Marble::AbstractFloatItem::contextMenu
QMenu * contextMenu()
Definition: AbstractFloatItem.cpp:230
Marble::NavigationFloatItem::changeViewport
void changeViewport(ViewportParams *viewport)
Definition: NavigationFloatItem.cpp:141
Marble::NavigationFloatItem::isInitialized
bool isInitialized() const
Definition: NavigationFloatItem.cpp:136
Marble::AbstractFloatItem::setVisible
void setVisible(bool visible)
Set visibility of the float item.
Definition: AbstractFloatItem.cpp:128
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