File indexing completed on 2024-05-05 03:49:18

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2014 Adam Dabrowski <adabrowski@piap.pl, adamdbrw@gmail.com>
0004 //
0005 
0006 #ifndef MARBLEQUICKITEM_H
0007 #define MARBLEQUICKITEM_H
0008 
0009 #include "marble_declarative_export.h"
0010 #include <QSharedPointer>
0011 #include <QQuickPaintedItem>
0012 #include "GeoDataAccuracy.h"
0013 #include "GeoDataLineString.h"
0014 #include "MarbleGlobal.h"
0015 #include "PositionProviderPluginInterface.h"
0016 #include "MarbleMap.h"
0017 #include "Placemark.h"
0018 #include "Coordinate.h"
0019 #include "MapTheme.h"
0020 
0021 namespace Marble
0022 {
0023     class GeoDataLatLonBox;
0024     class GeoDataPlacemark;
0025     class MarbleModel;
0026     class MarbleInputHandler;
0027     class MarbleQuickItemPrivate;
0028 
0029     //Class is still being developed
0030     class MARBLE_DECLARATIVE_EXPORT MarbleQuickItem : public QQuickPaintedItem
0031     {
0032     Q_OBJECT
0033 
0034         Q_ENUMS(Projection)
0035 
0036         Q_PROPERTY(int mapWidth READ mapWidth WRITE setMapWidth NOTIFY mapWidthChanged)
0037         Q_PROPERTY(int mapHeight READ mapHeight WRITE setMapHeight NOTIFY mapHeightChanged)
0038         Q_PROPERTY(int zoom READ zoom WRITE setZoom NOTIFY zoomChanged)
0039         Q_PROPERTY(int minimumZoom READ minimumZoom NOTIFY minimumZoomChanged)
0040         Q_PROPERTY(int maximumZoom READ maximumZoom NOTIFY maximumZoomChanged)
0041         Q_PROPERTY(int radius READ radius WRITE setRadius NOTIFY radiusChanged)
0042         Q_PROPERTY(qreal heading READ heading WRITE setHeading NOTIFY headingChanged)
0043 
0044         Q_PROPERTY(bool showFrameRate READ showFrameRate WRITE setShowFrameRate NOTIFY showFrameRateChanged)
0045         Q_PROPERTY(Projection projection READ projection WRITE setProjection NOTIFY projectionChanged)
0046 
0047         Q_PROPERTY(Marble::MapTheme* mapTheme READ mapTheme NOTIFY mapThemeChanged)
0048         Q_PROPERTY(QString mapThemeId READ mapThemeId WRITE setMapThemeId NOTIFY mapThemeIdChanged)
0049         Q_PROPERTY(bool showAtmosphere READ showAtmosphere WRITE setShowAtmosphere NOTIFY showAtmosphereChanged)
0050         Q_PROPERTY(bool showCompass READ showCompass WRITE setShowCompass NOTIFY showCompassChanged)
0051         Q_PROPERTY(bool showClouds READ showClouds WRITE setShowClouds NOTIFY showCloudsChanged)
0052         Q_PROPERTY(bool showCrosshairs READ showCrosshairs WRITE setShowCrosshairs NOTIFY showCrosshairsChanged)
0053         Q_PROPERTY(bool showGrid READ showGrid WRITE setShowGrid NOTIFY showGridChanged)
0054         Q_PROPERTY(bool showOverviewMap READ showOverviewMap WRITE setShowOverviewMap NOTIFY showOverviewMapChanged)
0055         Q_PROPERTY(bool showOtherPlaces READ showOtherPlaces WRITE setShowOtherPlaces NOTIFY showOtherPlacesChanged)
0056         Q_PROPERTY(bool showScaleBar READ showScaleBar WRITE setShowScaleBar NOTIFY showScaleBarChanged)
0057         Q_PROPERTY(bool showBackground READ showBackground WRITE setShowBackground NOTIFY showBackgroundChanged)
0058         Q_PROPERTY(bool showPositionMarker READ showPositionMarker WRITE setShowPositionMarker NOTIFY showPositionMarkerChanged)
0059         Q_PROPERTY(bool showPublicTransport READ showPublicTransport WRITE setShowPublicTransport NOTIFY showPublicTransportChanged)
0060         Q_PROPERTY(bool showOutdoorActivities READ showOutdoorActivities WRITE setShowOutdoorActivities NOTIFY showOutdoorActivitiesChanged)
0061         Q_PROPERTY(QString positionProvider READ positionProvider WRITE setPositionProvider NOTIFY positionProviderChanged)
0062         Q_PROPERTY(bool positionAvailable READ positionAvailable NOTIFY positionAvailableChanged)
0063         Q_PROPERTY(bool positionVisible READ positionVisible NOTIFY positionVisibleChanged)
0064         Q_PROPERTY(MarbleMap* marbleMap READ map NOTIFY marbleMapChanged)
0065         Q_PROPERTY(Placemark*  currentPosition READ currentPosition NOTIFY currentPositionChanged)
0066         Q_PROPERTY(qreal speed READ speed NOTIFY speedChanged)
0067         Q_PROPERTY(qreal angle READ angle NOTIFY angleChanged)
0068         Q_PROPERTY(bool inertialGlobeRotation READ inertialGlobeRotation WRITE setInertialGlobeRotation NOTIFY inertialGlobeRotationChanged)
0069         Q_PROPERTY(bool animationViewContext READ animationViewContext WRITE setAnimationViewContext NOTIFY animationViewContextChanged)
0070         Q_PROPERTY(bool animationsEnabled READ animationsEnabled WRITE setAnimationsEnabled NOTIFY animationsEnabledChanged)
0071         Q_PROPERTY(QQmlComponent* placemarkDelegate READ placemarkDelegate WRITE setPlacemarkDelegate NOTIFY placemarkDelegateChanged)
0072         Q_PROPERTY(bool hoverEnabled READ hoverEnabled WRITE setHoverEnabled NOTIFY hoverEnabledChanged)
0073         Q_PROPERTY(bool invertColorEnabled READ invertColorEnabled WRITE setInvertColorEnabled NOTIFY invertColorEnabledChanged)
0074         Q_PROPERTY(bool workOffline READ workOffline WRITE setWorkOffline NOTIFY workOfflineChanged)
0075 
0076     public:
0077         explicit MarbleQuickItem(QQuickItem *parent = nullptr);
0078 
0079         enum Projection{
0080             Spherical = Marble::Spherical,
0081             Equirectangular = Marble::Equirectangular,
0082             Mercator = Marble::Mercator,
0083             Gnomonic = Marble::Gnomonic,
0084             Stereographic = Marble::Stereographic,
0085             LambertAzimuthal = Marble::LambertAzimuthal,
0086             AzimuthalEquidistant = Marble::AzimuthalEquidistant,
0087             VerticalPerspective = Marble::VerticalPerspective
0088         };
0089 
0090 
0091         MarbleInputHandler *inputHandler();
0092         int zoom() const;
0093         int radius() const;
0094 
0095     public Q_SLOTS:
0096         void goHome();
0097         void setZoom(int zoom, FlyToMode mode = Instant);
0098         Q_INVOKABLE void setZoomToMaximumLevel();
0099         void setRadius(int radius);
0100         void centerOn(const GeoDataPlacemark& placemark, bool animated = false);
0101         void centerOn(const GeoDataLatLonBox& box, bool animated = false);
0102         void centerOn(const GeoDataCoordinates& coordinate);
0103         void centerOn(qreal longitude, qreal latitude);
0104         Q_INVOKABLE void centerOnCoordinates(qreal longitude, qreal latitude);
0105         Q_INVOKABLE void centerOnCurrentPosition();
0106         Q_INVOKABLE void selectPlacemarkAt(int x, int y);
0107 
0108         void zoomIn(FlyToMode mode = Automatic);
0109         void zoomOut(FlyToMode mode = Automatic);
0110 
0111         Q_INVOKABLE void handlePinchStarted(const QPointF &point);
0112         Q_INVOKABLE void handlePinchFinished(const QPointF &point);
0113         Q_INVOKABLE void handlePinchUpdated(const QPointF &point, qreal scale);
0114 
0115         void setMapWidth(int mapWidth);
0116         void setMapHeight(int mapHeight);
0117         void setShowFrameRate(bool showFrameRate);
0118         void setProjection(Projection projection);
0119         void setMapThemeId(const QString& mapThemeId);
0120         void setShowAtmosphere(bool showAtmosphere);
0121         void setShowCompass(bool showCompass);
0122         void setShowClouds(bool showClouds);
0123         void setShowCrosshairs(bool showCrosshairs);
0124         void setShowGrid(bool showGrid);
0125         void setShowOverviewMap(bool showOverviewMap);
0126         void setShowOtherPlaces(bool showOtherPlaces);
0127         void setShowScaleBar(bool showScaleBar);
0128         void setShowBackground(bool showBackground);
0129         void setShowPositionMarker(bool showPositionMarker);
0130         void setShowPublicTransport(bool showPublicTransport);
0131         void setShowOutdoorActivities(bool showOutdoorActivities);
0132         void setPositionProvider(const QString & positionProvider);
0133 
0134         void setInertialGlobeRotation(bool inertialGlobeRotation);
0135         void setAnimationViewContext(bool animationViewContext);
0136         void setAnimationsEnabled(bool animationsEnabled);
0137 
0138         void setPluginSetting(const QString &plugin, const QString &key, const QString &value);
0139 
0140         void setPropertyEnabled(const QString &property, bool enabled);
0141         bool isPropertyEnabled(const QString &property) const;
0142 
0143         void setWorkOffline(bool enabled);
0144 
0145         Q_INVOKABLE void setInvertColorEnabled(bool enabled, const QString &blending = QString("InvertColorBlending"));
0146 
0147         Q_INVOKABLE void setShowRuntimeTrace(bool showRuntimeTrace);
0148         Q_INVOKABLE void setShowDebugPolygons(bool showDebugPolygons);
0149         Q_INVOKABLE void setShowDebugPlacemarks(bool showDebugPlacemarks);
0150         Q_INVOKABLE void setShowDebugBatches(bool showDebugBatches);
0151 
0152         void setPlacemarkDelegate(QQmlComponent* placemarkDelegate);
0153 
0154         Q_INVOKABLE void loadSettings();
0155         Q_INVOKABLE void writeSettings();
0156 
0157         Q_INVOKABLE void reloadTiles();
0158         Q_INVOKABLE void highlightRouteRelation(qint64 osmId, bool enabled);
0159         Q_INVOKABLE void setRelationTypeVisible(const QString &relationType, bool visible);
0160         Q_INVOKABLE bool isRelationTypeVisible(const QString &relationType) const;
0161 
0162         void setHeading(qreal heading);
0163         void setHoverEnabled(bool hoverEnabled);
0164 
0165     public:
0166         void paint(QPainter *painter) override;
0167 
0168     // QQmlParserStatus interface
0169     public:
0170         void classBegin() override;
0171         void componentComplete() override;
0172 
0173         void hoverMoveEvent(QHoverEvent* event) override;
0174 
0175     public:
0176         virtual bool layersEventFilter(QObject *o, QEvent *e);
0177 
0178         int mapWidth() const;
0179         int mapHeight() const;
0180         qreal heading() const;
0181 
0182         bool showFrameRate() const;
0183         Projection projection() const;
0184         QString mapThemeId() const;
0185         Marble::MapTheme * mapTheme() const;
0186         bool showAtmosphere() const;
0187         bool showCompass() const;
0188         bool showClouds() const;
0189         bool showCrosshairs() const;
0190         bool showGrid() const;
0191         bool showOverviewMap() const;
0192         bool showOtherPlaces() const;
0193         bool showScaleBar() const;
0194         bool showBackground() const;
0195         bool showPositionMarker() const;
0196         bool showPublicTransport() const;
0197         bool showOutdoorActivities() const;
0198         QString positionProvider() const;
0199         bool positionAvailable() const;
0200         bool positionVisible() const;
0201         Q_INVOKABLE qreal distanceFromPointToCurrentLocation(const QPoint & position) const;
0202         Q_INVOKABLE qreal angleFromPointToCurrentLocation(const QPoint & position) const;
0203         Placemark* currentPosition() const;
0204         Q_INVOKABLE QPointF screenCoordinatesFromCoordinate(Coordinate * coordinate) const;
0205         Q_INVOKABLE QPointF screenCoordinatesFromGeoDataCoordinates(const GeoDataCoordinates & coordinates) const;
0206         Q_INVOKABLE bool screenCoordinatesFromGeoDataLineString(const GeoDataLineString &lineString, QVector<QPolygonF*> &polygons ) const;
0207 
0208         Q_INVOKABLE bool screenCoordinatesToGeoDataCoordinates(const QPoint & point, GeoDataCoordinates & coordinates);
0209         Q_INVOKABLE bool screenCoordinatesToCoordinate(const QPoint & point, Coordinate * coordinate);
0210         qreal speed() const;
0211         qreal angle() const;
0212 
0213         MarbleModel* model();
0214         const MarbleModel* model() const;
0215 
0216         MarbleMap* map();
0217         const MarbleMap* map() const;
0218 
0219         bool inertialGlobeRotation() const;
0220         bool animationViewContext() const;
0221         bool animationsEnabled() const;
0222 
0223         QQmlComponent* placemarkDelegate() const;
0224         void reverseGeocoding(const QPoint &point);
0225 
0226         bool hoverEnabled() const;
0227         Q_INVOKABLE bool invertColorEnabled();
0228         bool workOffline();
0229 
0230 
0231         Q_INVOKABLE void moveUp();
0232         Q_INVOKABLE void moveDown();
0233         Q_INVOKABLE void moveLeft();
0234         Q_INVOKABLE void moveRight();
0235 
0236 
0237         int minimumZoom() const;
0238 
0239         int maximumZoom() const;
0240 
0241     Q_SIGNALS:
0242         void mapWidthChanged(int mapWidth);
0243         void mapHeightChanged(int mapHeight);
0244         void showFrameRateChanged(bool showFrameRate);
0245         void projectionChanged(Projection projection);
0246         void mapThemeIdChanged(const QString& mapThemeId);
0247         void mapThemeChanged();
0248         void showAtmosphereChanged(bool showAtmosphere);
0249         void showCompassChanged(bool showCompass);
0250         void showCloudsChanged(bool showClouds);
0251         void showCrosshairsChanged(bool showCrosshairs);
0252         void showGridChanged(bool showGrid);
0253         void showOverviewMapChanged(bool showOverviewMap);
0254         void showOtherPlacesChanged(bool showOtherPlaces);
0255         void showScaleBarChanged(bool showScaleBar);
0256         void showBackgroundChanged(bool showBackground);
0257         void showPositionMarkerChanged(bool showPositionMarker);
0258         void showPublicTransportChanged(bool showPublicTransport);
0259         void showOutdoorActivitiesChanged(bool showOutdoorActivities);
0260         void positionProviderChanged(const QString & positionProvider);
0261         void positionAvailableChanged(bool positionAvailable);
0262         void positionVisibleChanged(bool positionVisible);
0263         void marbleMapChanged();
0264         void visibleLatLonAltBoxChanged();
0265         void currentPositionChanged(Placemark* currentPosition);
0266         void angleChanged();
0267         void speedChanged();
0268         void headingChanged(qreal heading);
0269         void zoomChanged();
0270         void radiusChanged(int radius);
0271         void inertialGlobeRotationChanged(bool inertialGlobeRotation);
0272         void animationViewContextChanged(bool animationViewContext);
0273         void placemarkDelegateChanged(QQmlComponent* placemarkDelegate);
0274 
0275         void animationsEnabledChanged(bool animationsEnabled);
0276 
0277         void hoverEnabledChanged(bool hoverEnabled);
0278 
0279         void lmbMenuRequested(const QPoint& point);
0280         void rmbMenuRequested(const QPoint& point);
0281         void hoverPositionChanged(const QPoint& point);
0282 
0283         void minimumZoomChanged(int minimumZoom);
0284         void maximumZoomChanged(int maximumZoom);
0285 
0286         void invertColorEnabledChanged(bool enabled);
0287         void workOfflineChanged();
0288 
0289         void geoItemUpdateRequested();
0290 
0291     protected:
0292         QObject *getEventFilter() const;
0293         void pinch(const QPointF& center, qreal scale, Qt::GestureState state);
0294 
0295     private Q_SLOTS:
0296         void resizeMap();
0297         void positionDataStatusChanged(PositionProviderStatus status);
0298         void positionChanged(const GeoDataCoordinates &, GeoDataAccuracy);
0299         void updatePositionVisibility();
0300         void updateCurrentPosition(const GeoDataCoordinates & coordinates);
0301         void updatePlacemarks();
0302         void handleReverseGeocoding(const GeoDataCoordinates &coordinates, const GeoDataPlacemark &placemark);
0303         void handleVisibleLatLonAltBoxChanged(const GeoDataLatLonAltBox& latLonAltBox);
0304 
0305     private:
0306         using MarbleQuickItemPrivatePtr = QSharedPointer<MarbleQuickItemPrivate>;
0307         MarbleQuickItemPrivatePtr d;
0308         friend class MarbleQuickItemPrivate;
0309     };
0310 }
0311 
0312 #endif // MARBLEQUICKITEM_H