File indexing completed on 2025-01-05 03:59:19

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2012 Mohammed Nafees <nafees.technocool@gmail.com>
0004 // SPDX-FileCopyrightText: 2012 Dennis Nienhüser <nienhueser@kde.org>
0005 // SPDX-FileCopyrightText: 2012 Illya Kovalevskyy <illya.kovalevskyy@gmail.com>
0006 // SPDX-FileCopyrightText: 2015 Imran Tatriev <itatriev@gmail.com>
0007 //
0008 
0009 #include "PopupLayer.h"
0010 
0011 #include "GeoDataCoordinates.h"
0012 #include "GeoPainter.h"
0013 #include "MarbleWidget.h"
0014 #include "ViewportParams.h"
0015 #include "RenderPlugin.h"
0016 #include "RenderState.h"
0017 
0018 #include <QSizeF>
0019 
0020 namespace Marble
0021 {
0022 
0023 class Q_DECL_HIDDEN PopupLayer::Private
0024 {
0025 public:
0026     Private( MarbleWidget *marbleWidget, PopupLayer *q );
0027 
0028     /**
0029      * @brief Sets size of the popup item, based on the requested size and viewport size
0030      * @param viewport required to compute the maximum dimensions
0031      */
0032     void setAppropriateSize( const ViewportParams *viewport );
0033 
0034     static QString filterEmptyShortDescription(const QString &description);
0035     void setupDialogSatellite( const GeoDataPlacemark *index );
0036     void setupDialogCity( const GeoDataPlacemark *index );
0037     void setupDialogNation( const GeoDataPlacemark *index );
0038     void setupDialogGeoPlaces( const GeoDataPlacemark *index );
0039     void setupDialogSkyPlaces( const GeoDataPlacemark *index );
0040 
0041     MarbleWidget *const m_widget;
0042     QSizeF m_requestedSize;
0043     bool m_hasCrosshairsPlugin;
0044     bool m_crosshairsVisible;
0045 };
0046 
0047 PopupLayer::Private::Private( MarbleWidget *marbleWidget, PopupLayer */*q*/ ) :
0048     m_widget( marbleWidget ),
0049     m_hasCrosshairsPlugin( false ),
0050     m_crosshairsVisible( false )
0051 {
0052 }
0053 
0054 PopupLayer::PopupLayer( MarbleWidget *marbleWidget, QObject *parent ) :
0055     QObject( parent ),
0056     d( new Private( marbleWidget, this ) )
0057 {
0058 /*
0059     for (const RenderPlugin *renderPlugin: d->m_widget->renderPlugins()) {
0060         if (renderPlugin->nameId() == QLatin1String("crosshairs")) {
0061             d->m_hasCrosshairsPlugin = true;
0062             break;
0063         }
0064     }
0065 
0066     connect( d->m_popupItem, SIGNAL(repaintNeeded()), this, SIGNAL(repaintNeeded()) );
0067     connect( d->m_popupItem, SIGNAL(hide()), this, SLOT(hidePopupItem()) );
0068 */
0069 }
0070 
0071 PopupLayer::~PopupLayer()
0072 {
0073     delete d;
0074 }
0075 
0076 QStringList PopupLayer::renderPosition() const
0077 {
0078     return QStringList(QStringLiteral("ALWAYS_ON_TOP"));
0079 }
0080 
0081 bool PopupLayer::render( GeoPainter */*painter*/, ViewportParams */*viewport*/,
0082                                 const QString&, GeoSceneLayer* )
0083 {
0084 /*
0085     if ( visible() ) {
0086         d->setAppropriateSize( viewport );
0087         d->m_popupItem->paintEvent( painter, viewport );
0088     }
0089 */
0090     return false;
0091 }
0092 /*
0093 bool PopupLayer::eventFilter( QObject *object, QEvent *e )
0094 {
0095     return visible() && d->m_popupItem->eventFilter( object, e );
0096 }
0097 
0098 qreal PopupLayer::zValue() const
0099 {
0100     return 4711.23;
0101 }
0102 
0103 RenderState PopupLayer::renderState() const
0104 {
0105     return RenderState(QStringLiteral("Popup Window"));
0106 }
0107 */
0108 bool PopupLayer::visible() const
0109 {
0110     return false; //d->m_popupItem->visible();
0111 }
0112 
0113 void PopupLayer::setVisible( bool /*visible*/ )
0114 {
0115 /*
0116     d->m_popupItem->setVisible( visible );
0117     if ( !visible ) {
0118         disconnect( d->m_popupItem, SIGNAL(repaintNeeded()), this, SIGNAL(repaintNeeded()) );
0119         d->m_popupItem->clearHistory();
0120         Q_EMIT repaintNeeded();
0121     }
0122     else {
0123         connect( d->m_popupItem, SIGNAL(repaintNeeded()), this, SIGNAL(repaintNeeded()) );
0124     }
0125 */
0126 }
0127 
0128 void PopupLayer::popup()
0129 {
0130 /*
0131     GeoDataCoordinates coords = d->m_popupItem->coordinate();
0132     ViewportParams viewport( d->m_widget->viewport()->projection(),
0133                              coords.longitude(), coords.latitude(), d->m_widget->viewport()->radius(),
0134                              d->m_widget->viewport()->size() );
0135     qreal sx, sy, lon, lat;
0136     viewport.screenCoordinates( coords, sx, sy );
0137     sx = viewport.radius() < viewport.width() ? 0.5 * (viewport.width() + viewport.radius()) : 0.75 * viewport.width();
0138     viewport.geoCoordinates( sx, sy, lon, lat, GeoDataCoordinates::Radian );
0139     coords.setLatitude( lat );
0140     coords.setLongitude( lon );
0141     d->m_widget->centerOn( coords, true );
0142 
0143     if( d->m_hasCrosshairsPlugin ) {
0144         d->m_crosshairsVisible = d->m_widget->showCrosshairs();
0145 
0146         if( d->m_crosshairsVisible ) {
0147             d->m_widget->setShowCrosshairs( false );
0148         }
0149     }
0150 */
0151     setVisible( false );
0152 }
0153 
0154 void PopupLayer::setCoordinates( const GeoDataCoordinates &/*coordinates*/ , Qt::Alignment /*alignment*/ )
0155 {
0156 /*
0157     d->m_popupItem->setCoordinate( coordinates );
0158     d->m_popupItem->setAlignment( alignment );
0159 */
0160 }
0161 
0162 void PopupLayer::setUrl( const QUrl &/*url*/ )
0163 {
0164 //    d->m_popupItem->setUrl( url );
0165 }
0166 
0167 void PopupLayer::setContent( const QString &/*html*/, const QUrl &/*baseUrl*/ )
0168 {
0169 //    d->m_popupItem->setContent( html, baseUrl );
0170 }
0171 
0172 void PopupLayer::setBackgroundColor(const QColor &/*color*/)
0173 {
0174 /*
0175     if(color.isValid()) {
0176         d->m_popupItem->setBackgroundColor(color);
0177     }
0178 */
0179 }
0180 
0181 void PopupLayer::setTextColor(const QColor &/*color*/)
0182 {
0183 /*
0184     if(color.isValid()) {
0185         d->m_popupItem->setTextColor(color);
0186     }
0187 */
0188 }
0189 
0190 void PopupLayer::setSize( const QSizeF &size )
0191 {
0192     d->m_requestedSize = size;
0193 }
0194 
0195 void PopupLayer::Private::setAppropriateSize( const ViewportParams */*viewport*/ )
0196 {
0197 /*
0198     qreal margin = 15.0;
0199 
0200     QSizeF maximumSize;
0201     maximumSize.setWidth( viewport->width() - margin );
0202     maximumSize.setHeight( viewport->height() - margin );
0203 
0204     QSizeF minimumSize( 100.0, 100.0 );
0205 
0206     m_popupItem->setSize( m_requestedSize.boundedTo( maximumSize ).expandedTo( minimumSize ) );
0207 */
0208 }
0209 
0210 void PopupLayer::hidePopupItem()
0211 {
0212 /*
0213     if( d->m_hasCrosshairsPlugin && d->m_crosshairsVisible ) {
0214         d->m_widget->setShowCrosshairs( d->m_crosshairsVisible );
0215     }
0216 */
0217     setVisible( false );
0218 }
0219 
0220 }
0221 
0222 #include "moc_PopupLayer.cpp"