Marble

PopupLayer.cpp
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 <[email protected]>
9 // Copyright 2012 Dennis Nienhüser <[email protected]>
10 // Copyright 2012 Illya Kovalevskyy <[email protected]>
11 // Copyright 2015 Imran Tatriev <[email protected]>
12 //
13 
14 #include "PopupLayer.h"
15 
16 #include "GeoDataCoordinates.h"
17 #include "GeoPainter.h"
18 #include "MarbleWidget.h"
19 #include "PopupItem.h"
20 #include "ViewportParams.h"
21 #include "RenderPlugin.h"
22 #include "RenderState.h"
23 
24 #include <QSizeF>
25 
26 namespace Marble
27 {
28 
29 class Q_DECL_HIDDEN PopupLayer::Private
30 {
31 public:
32  Private( MarbleWidget *marbleWidget, PopupLayer *q );
33 
38  void setAppropriateSize( const ViewportParams *viewport );
39 
40  static QString filterEmptyShortDescription(const QString &description);
41  void setupDialogSatellite( const GeoDataPlacemark *index );
42  void setupDialogCity( const GeoDataPlacemark *index );
43  void setupDialogNation( const GeoDataPlacemark *index );
44  void setupDialogGeoPlaces( const GeoDataPlacemark *index );
45  void setupDialogSkyPlaces( const GeoDataPlacemark *index );
46 
47  PopupItem *const m_popupItem;
48  MarbleWidget *const m_widget;
49  QSizeF m_requestedSize;
50  bool m_hasCrosshairsPlugin;
51  bool m_crosshairsVisible;
52 };
53 
54 PopupLayer::Private::Private( MarbleWidget *marbleWidget, PopupLayer *q ) :
55  m_popupItem( new PopupItem( q ) ),
56  m_widget( marbleWidget ),
57  m_hasCrosshairsPlugin( false ),
58  m_crosshairsVisible( true )
59 {
60 }
61 
62 PopupLayer::PopupLayer( MarbleWidget *marbleWidget, QObject *parent ) :
63  QObject( parent ),
64  d( new Private( marbleWidget, this ) )
65 {
66  for (const RenderPlugin *renderPlugin: d->m_widget->renderPlugins()) {
67  if (renderPlugin->nameId() == QLatin1String("crosshairs")) {
68  d->m_hasCrosshairsPlugin = true;
69  break;
70  }
71  }
72 
73  connect( d->m_popupItem, SIGNAL(repaintNeeded()), this, SIGNAL(repaintNeeded()) );
74  connect( d->m_popupItem, SIGNAL(hide()), this, SLOT(hidePopupItem()) );
75 }
76 
77 PopupLayer::~PopupLayer()
78 {
79  delete d;
80 }
81 
82 QStringList PopupLayer::renderPosition() const
83 {
84  return QStringList(QStringLiteral("ALWAYS_ON_TOP"));
85 }
86 
87 bool PopupLayer::render( GeoPainter *painter, ViewportParams *viewport,
88  const QString&, GeoSceneLayer* )
89 {
90  if ( visible() ) {
91  d->setAppropriateSize( viewport );
92  d->m_popupItem->paintEvent( painter, viewport );
93  }
94 
95  return true;
96 }
97 
98 bool PopupLayer::eventFilter( QObject *object, QEvent *e )
99 {
100  return visible() && d->m_popupItem->eventFilter( object, e );
101 }
102 
103 qreal PopupLayer::zValue() const
104 {
105  return 4711.23;
106 }
107 
108 RenderState PopupLayer::renderState() const
109 {
110  return RenderState(QStringLiteral("Popup Window"));
111 }
112 
114 {
115  return d->m_popupItem->visible();
116 }
117 
118 void PopupLayer::setVisible( bool visible )
119 {
120  d->m_popupItem->setVisible( visible );
121  if ( !visible ) {
122  disconnect( d->m_popupItem, SIGNAL(repaintNeeded()), this, SIGNAL(repaintNeeded()) );
123  d->m_popupItem->clearHistory();
124  emit repaintNeeded();
125  }
126  else {
127  connect( d->m_popupItem, SIGNAL(repaintNeeded()), this, SIGNAL(repaintNeeded()) );
128  }
129 }
130 
132 {
133  GeoDataCoordinates coords = d->m_popupItem->coordinate();
134  ViewportParams viewport( d->m_widget->viewport()->projection(),
135  coords.longitude(), coords.latitude(), d->m_widget->viewport()->radius(),
136  d->m_widget->viewport()->size() );
137  qreal sx, sy, lon, lat;
138  viewport.screenCoordinates( coords, sx, sy );
139  sx = viewport.radius() < viewport.width() ? 0.5 * (viewport.width() + viewport.radius()) : 0.75 * viewport.width();
140  viewport.geoCoordinates( sx, sy, lon, lat, GeoDataCoordinates::Radian );
141  coords.setLatitude( lat );
142  coords.setLongitude( lon );
143  d->m_widget->centerOn( coords, true );
144 
145  if( d->m_hasCrosshairsPlugin ) {
146  d->m_crosshairsVisible = d->m_widget->showCrosshairs();
147 
148  if( d->m_crosshairsVisible ) {
149  d->m_widget->setShowCrosshairs( false );
150  }
151  }
152 
153  setVisible( true );
154 }
155 
156 void PopupLayer::setCoordinates( const GeoDataCoordinates &coordinates , Qt::Alignment alignment )
157 {
158  d->m_popupItem->setCoordinate( coordinates );
159  d->m_popupItem->setAlignment( alignment );
160 }
161 
162 void PopupLayer::setUrl( const QUrl &url )
163 {
164  d->m_popupItem->setUrl( url );
165 }
166 
167 void PopupLayer::setContent( const QString &html, const QUrl &baseUrl )
168 {
169  d->m_popupItem->setContent( html, baseUrl );
170 }
171 
173 {
174  if(color.isValid()) {
175  d->m_popupItem->setBackgroundColor(color);
176  }
177 }
178 
180 {
181  if(color.isValid()) {
182  d->m_popupItem->setTextColor(color);
183  }
184 }
185 
186 void PopupLayer::setSize( const QSizeF &size )
187 {
188  d->m_requestedSize = size;
189 }
190 
191 void PopupLayer::Private::setAppropriateSize( const ViewportParams *viewport )
192 {
193  qreal margin = 15.0;
194 
195  QSizeF maximumSize;
196  maximumSize.setWidth( viewport->width() - margin );
197  maximumSize.setHeight( viewport->height() - margin );
198 
199  QSizeF minimumSize( 100.0, 100.0 );
200 
201  m_popupItem->setSize( m_requestedSize.boundedTo( maximumSize ).expandedTo( minimumSize ) );
202 }
203 
204 void PopupLayer::hidePopupItem()
205 {
206  if( d->m_hasCrosshairsPlugin && d->m_crosshairsVisible ) {
207  d->m_widget->setShowCrosshairs( d->m_crosshairsVisible );
208  }
209 
210  setVisible( false );
211 }
212 
213 }
214 
215 #include "moc_PopupLayer.cpp"
bool visible() const
Is popup item visible.
Definition: PopupLayer.cpp:113
A 3d point representation.
Binds a QML item to a specific geodetic location in screen coordinates.
void setBackgroundColor(const QColor &color)
Sets background color of the header.
Definition: PopupLayer.cpp:172
void popup()
Make the dialog pop up.
Definition: PopupLayer.cpp:131
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
typedef Alignment
void setContent(const QString &html, const QUrl &baseUrl=QUrl())
Sets content of the browser.
Definition: PopupLayer.cpp:167
void setWidth(qreal width)
bool screenCoordinates(const qreal lon, const qreal lat, qreal &x, qreal &y) const
Get the screen coordinates corresponding to geographical coordinates in the map.
void setTextColor(const QColor &color)
Sets text color of the header.
Definition: PopupLayer.cpp:179
A public class that controls what is visible in the viewport of a Marble map.
void setLatitude(qreal lat, GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian)
set the longitude in a GeoDataCoordinates object
This file contains the headers for ViewportParams.
void setLongitude(qreal lon, GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian)
set the longitude in a GeoDataCoordinates object
void setVisible(bool visible)
Set visibility of the item.
Definition: PopupLayer.cpp:118
void setUrl(const QUrl &url)
Sets URL of the browser.
Definition: PopupLayer.cpp:162
This file contains the headers for MarbleWidget.
void setCoordinates(const GeoDataCoordinates &coordinates, Qt::Alignment alignment)
Sets coordinates.
Definition: PopupLayer.cpp:156
qreal longitude(GeoDataCoordinates::Unit unit) const
retrieves the longitude of the GeoDataCoordinates object use the unit parameter to switch between Rad...
qreal latitude(GeoDataCoordinates::Unit unit) const
retrieves the latitude of the GeoDataCoordinates object use the unit parameter to switch between Radi...
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QObject * parent() const const
void setHeight(qreal height)
void setSize(const QSizeF &size)
Sets size of popup item.
Definition: PopupLayer.cpp:186
bool isValid() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat Jul 11 2020 23:19:35 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.