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

marble

  • sources
  • kde-4.14
  • kdeedu
  • marble
  • src
  • lib
  • marble
  • layers
PopupLayer.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 2012 Mohammed Nafees <nafees.technocool@gmail.com>
9 // Copyright 2012 Dennis Nienhüser <earthwings@gentoo.org>
10 // Copyright 2012 Illya Kovalevskyy <illya.kovalevskyy@gmail.com>
11 //
12 
13 #include "PopupLayer.h"
14 
15 #include "GeoDataCoordinates.h"
16 #include "GeoPainter.h"
17 #include "MarbleWidget.h"
18 #include "PopupItem.h"
19 #include "ViewportParams.h"
20 
21 #include <QSizeF>
22 
23 namespace Marble
24 {
25 
26 class PopupLayer::Private
27 {
28 public:
29  Private( MarbleWidget *marbleWidget, PopupLayer *q );
30 
35  void setAppropriateSize( const ViewportParams *viewport );
36 
37  static QString filterEmptyShortDescription(const QString &description);
38  void setupDialogSatellite( const GeoDataPlacemark *index );
39  void setupDialogCity( const GeoDataPlacemark *index );
40  void setupDialogNation( const GeoDataPlacemark *index );
41  void setupDialogGeoPlaces( const GeoDataPlacemark *index );
42  void setupDialogSkyPlaces( const GeoDataPlacemark *index );
43 
44  PopupItem *const m_popupItem;
45  MarbleWidget *const m_widget;
46  QSizeF m_requestedSize;
47 };
48 
49 PopupLayer::Private::Private( MarbleWidget *marbleWidget, PopupLayer *q ) :
50  m_popupItem( new PopupItem( q ) ),
51  m_widget( marbleWidget )
52 {
53 }
54 
55 PopupLayer::PopupLayer( MarbleWidget *marbleWidget, QObject *parent ) :
56  QObject( parent ),
57  d( new Private( marbleWidget, this ) )
58 {
59  connect( d->m_popupItem, SIGNAL(repaintNeeded()), this, SIGNAL(repaintNeeded()) );
60  connect( d->m_popupItem, SIGNAL(hide()), this, SLOT(hidePopupItem()) );
61 }
62 
63 PopupLayer::~PopupLayer()
64 {
65  delete d;
66 }
67 
68 QStringList PopupLayer::renderPosition() const
69 {
70  return QStringList( "ALWAYS_ON_TOP" );
71 }
72 
73 bool PopupLayer::render( GeoPainter *painter, ViewportParams *viewport,
74  const QString&, GeoSceneLayer* )
75 {
76  if ( visible() ) {
77  d->setAppropriateSize( viewport );
78  d->m_popupItem->paintEvent( painter, viewport );
79  }
80 
81  return true;
82 }
83 
84 bool PopupLayer::eventFilter( QObject *object, QEvent *e )
85 {
86  return visible() && d->m_popupItem->eventFilter( object, e );
87 }
88 
89 qreal PopupLayer::zValue() const
90 {
91  return 4711.23;
92 }
93 
94 RenderState PopupLayer::renderState() const
95 {
96  return RenderState( "Popup Window" );
97 }
98 
99 bool PopupLayer::visible() const
100 {
101  return d->m_popupItem->visible();
102 }
103 
104 void PopupLayer::setVisible( bool visible )
105 {
106  d->m_popupItem->setVisible( visible );
107  if ( !visible ) {
108  disconnect( d->m_popupItem, SIGNAL(repaintNeeded()), this, SIGNAL(repaintNeeded()) );
109  d->m_popupItem->clearHistory();
110  emit repaintNeeded();
111  }
112  else {
113  connect( d->m_popupItem, SIGNAL(repaintNeeded()), this, SIGNAL(repaintNeeded()) );
114  }
115 }
116 
117 void PopupLayer::popup()
118 {
119  GeoDataCoordinates coords = d->m_popupItem->coordinate();
120  ViewportParams viewport( d->m_widget->viewport()->projection(),
121  coords.longitude(), coords.latitude(), d->m_widget->viewport()->radius(),
122  d->m_widget->viewport()->size() );
123  qreal sx, sy, lon, lat;
124  viewport.screenCoordinates( coords, sx, sy );
125  sx = viewport.radius() < viewport.width() ? 0.5 * (viewport.width() + viewport.radius()) : 0.75 * viewport.width();
126  viewport.geoCoordinates( sx, sy, lon, lat, GeoDataCoordinates::Radian );
127  coords.setLatitude( lat );
128  coords.setLongitude( lon );
129  d->m_widget->centerOn( coords, true );
130  setVisible( true );
131 }
132 
133 void PopupLayer::setCoordinates( const GeoDataCoordinates &coordinates , Qt::Alignment alignment )
134 {
135  d->m_popupItem->setCoordinate( coordinates );
136  d->m_popupItem->setAlignment( alignment );
137 }
138 
139 void PopupLayer::setUrl( const QUrl &url )
140 {
141  d->m_popupItem->setUrl( url );
142 }
143 
144 void PopupLayer::setContent( const QString &html, const QUrl &baseUrl )
145 {
146  d->m_popupItem->setContent( html, baseUrl );
147 }
148 
149 void PopupLayer::setBackgroundColor(const QColor &color)
150 {
151  if(color.isValid()) {
152  d->m_popupItem->setBackgroundColor(color);
153  }
154 }
155 
156 void PopupLayer::setTextColor(const QColor &color)
157 {
158  if(color.isValid()) {
159  d->m_popupItem->setTextColor(color);
160  }
161 }
162 
163 void PopupLayer::setSize( const QSizeF &size )
164 {
165  d->m_requestedSize = size;
166 }
167 
168 void PopupLayer::Private::setAppropriateSize( const ViewportParams *viewport )
169 {
170  qreal margin = 15.0;
171 
172  QSizeF maximumSize;
173  maximumSize.setWidth( viewport->width() - margin );
174  maximumSize.setHeight( viewport->height() - margin );
175 
176  QSizeF minimumSize( 100.0, 100.0 );
177 
178  m_popupItem->setSize( m_requestedSize.boundedTo( maximumSize ).expandedTo( minimumSize ) );
179 }
180 
181 void PopupLayer::hidePopupItem()
182 {
183  setVisible( false );
184 }
185 
186 }
187 
188 #include "PopupLayer.moc"
Marble::PopupLayer::visible
bool visible() const
Is popup item visible.
Definition: PopupLayer.cpp:99
GeoDataCoordinates.h
QEvent
Marble::GeoDataCoordinates
A 3d point representation.
Definition: GeoDataCoordinates.h:52
Marble::PopupLayer::eventFilter
virtual bool eventFilter(QObject *, QEvent *)
Definition: PopupLayer.cpp:84
Marble::GeoDataCoordinates::Radian
Definition: GeoDataCoordinates.h:65
Marble::GeoPainter
A painter that allows to draw geometric primitives on the map.
Definition: GeoPainter.h:98
Marble::PopupLayer::setBackgroundColor
void setBackgroundColor(const QColor &color)
Sets background color of the header.
Definition: PopupLayer.cpp:149
Marble::PopupLayer::popup
void popup()
Make the dialog pop up.
Definition: PopupLayer.cpp:117
PopupItem.h
Marble::PopupLayer::repaintNeeded
void repaintNeeded()
Marble::GeoDataCoordinates::latitude
qreal latitude(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
retrieves the latitude of the GeoDataCoordinates object use the unit parameter to switch between Radi...
Definition: GeoDataCoordinates.cpp:751
Qt::Alignment
typedef Alignment
QObject::disconnect
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
Marble::ViewportParams::height
int height() const
Definition: ViewportParams.cpp:255
Marble::MarbleWidget
A widget class that displays a view of the earth.
Definition: MarbleWidget.h:104
Marble::PopupLayer::setContent
void setContent(const QString &html, const QUrl &baseUrl=QUrl())
Sets content of the browser.
Definition: PopupLayer.cpp:144
Marble::GeoSceneLayer
Layer of a GeoScene document.
Definition: GeoSceneLayer.h:43
Marble::ViewportParams::width
int width() const
Definition: ViewportParams.cpp:250
Marble::PopupLayer::PopupLayer
PopupLayer(MarbleWidget *widget, QObject *parent=0)
Definition: PopupLayer.cpp:55
QObject
QSizeF::setWidth
void setWidth(qreal width)
Marble::PopupLayer::render
bool render(GeoPainter *painter, ViewportParams *viewport, const QString &, GeoSceneLayer *)
Renders the content provided by the layer on the viewport.
Definition: PopupLayer.cpp:73
Marble::ViewportParams::screenCoordinates
bool screenCoordinates(const qreal lon, const qreal lat, qreal &x, qreal &y) const
Get the screen coordinates corresponding to geographical coordinates in the map.
Definition: ViewportParams.cpp:357
Marble::PopupLayer::setTextColor
void setTextColor(const QColor &color)
Sets text color of the header.
Definition: PopupLayer.cpp:156
QString
QColor
GeoPainter.h
Marble::PopupLayer::renderPosition
QStringList renderPosition() const
Preferred level in the layer stack for the rendering.
Definition: PopupLayer.cpp:68
Marble::RenderState
Definition: RenderState.h:22
Marble::PopupLayer::~PopupLayer
~PopupLayer()
Definition: PopupLayer.cpp:63
QStringList
Marble::ViewportParams
A public class that controls what is visible in the viewport of a Marble map.
Definition: ViewportParams.h:44
Marble::GeoDataCoordinates::longitude
qreal longitude(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
retrieves the longitude of the GeoDataCoordinates object use the unit parameter to switch between Rad...
Definition: GeoDataCoordinates.cpp:739
QUrl
Marble::GeoDataCoordinates::setLatitude
void setLatitude(qreal lat, GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian)
set the longitude in a GeoDataCoordinates object
Definition: GeoDataCoordinates.cpp:699
ViewportParams.h
This file contains the headers for ViewportParams.
Marble::PopupLayer::zValue
qreal zValue() const
Returns the z value of the layer (default: 0.0).
Definition: PopupLayer.cpp:89
Marble::GeoDataCoordinates::setLongitude
void setLongitude(qreal lon, GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian)
set the longitude in a GeoDataCoordinates object
Definition: GeoDataCoordinates.cpp:679
Marble::PopupLayer::setVisible
void setVisible(bool visible)
Set visibility of the item.
Definition: PopupLayer.cpp:104
PopupLayer.h
QSizeF
Marble::PopupLayer::setUrl
void setUrl(const QUrl &url)
Sets URL of the browser.
Definition: PopupLayer.cpp:139
MarbleWidget.h
This file contains the headers for MarbleWidget.
Marble::PopupLayer::setCoordinates
void setCoordinates(const GeoDataCoordinates &coordinates, Qt::Alignment alignment)
Sets coordinates.
Definition: PopupLayer.cpp:133
MarbleWidget
Wraps a Marble::MarbleWidget, providing access to important properties and methods.
Definition: MarbleDeclarativeWidget.h:50
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QSizeF::setHeight
void setHeight(qreal height)
Marble::PopupLayer::setSize
void setSize(const QSizeF &size)
Sets size of popup item.
Definition: PopupLayer.cpp:163
Marble::PopupLayer::renderState
RenderState renderState() const
Definition: PopupLayer.cpp:94
QColor::isValid
bool isValid() const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:13:41 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
  • 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