MarbleQuickItem.h 9.78 KB
Newer Older
1 2 3 4 5 6 7
//
// This file is part of the Marble Virtual Globe.
//
// This program is free software licensed under the GNU LGPL. You can
// find a copy of this license in LICENSE.txt in the top directory of
// the source code.
//
8
// Copyright 2014      Adam Dabrowski <adabrowski@piap.pl> <adamdbrw@gmail.com>
9 10 11 12 13
//

#ifndef MARBLEQUICKITEM_H
#define MARBLEQUICKITEM_H

14
#include "marble_declarative_export.h"
15 16
#include <QSharedPointer>
#include <QQuickPaintedItem>
17
#include "GeoDataPlacemark.h"
18
#include "MarbleGlobal.h"
19 20
#include "PositionProviderPlugin.h"
#include "MarbleMap.h"
21
#include "Placemark.h"
22 23 24 25

namespace Marble
{
    class MarbleModel;
26
    class MarbleInputHandler;
27 28 29
    class MarbleQuickItemPrivate;

    //Class is still being developed
30
    class MARBLE_DECLARATIVE_EXPORT MarbleQuickItem : public QQuickPaintedItem
31 32 33
    {
    Q_OBJECT

34 35 36 37
        Q_ENUMS(Projection)

        Q_PROPERTY(int mapWidth READ mapWidth WRITE setMapWidth NOTIFY mapWidthChanged)
        Q_PROPERTY(int mapHeight READ mapHeight WRITE setMapHeight NOTIFY mapHeightChanged)
38
        Q_PROPERTY(int zoom READ zoom WRITE setZoom NOTIFY zoomChanged)
39 40 41 42 43 44 45 46 47 48 49 50
        Q_PROPERTY(bool showFrameRate READ showFrameRate WRITE setShowFrameRate NOTIFY showFrameRateChanged)
        Q_PROPERTY(Projection projection READ projection WRITE setProjection NOTIFY projectionChanged)
        Q_PROPERTY(QString mapThemeId READ mapThemeId WRITE setMapThemeId NOTIFY mapThemeIdChanged)
        Q_PROPERTY(bool showAtmosphere READ showAtmosphere WRITE setShowAtmosphere NOTIFY showAtmosphereChanged)
        Q_PROPERTY(bool showCompass READ showCompass WRITE setShowCompass NOTIFY showCompassChanged)
        Q_PROPERTY(bool showClouds READ showClouds WRITE setShowClouds NOTIFY showCloudsChanged)
        Q_PROPERTY(bool showCrosshairs READ showCrosshairs WRITE setShowCrosshairs NOTIFY showCrosshairsChanged)
        Q_PROPERTY(bool showGrid READ showGrid WRITE setShowGrid NOTIFY showGridChanged)
        Q_PROPERTY(bool showOverviewMap READ showOverviewMap WRITE setShowOverviewMap NOTIFY showOverviewMapChanged)
        Q_PROPERTY(bool showOtherPlaces READ showOtherPlaces WRITE setShowOtherPlaces NOTIFY showOtherPlacesChanged)
        Q_PROPERTY(bool showScaleBar READ showScaleBar WRITE setShowScaleBar NOTIFY showScaleBarChanged)
        Q_PROPERTY(bool showBackground READ showBackground WRITE setShowBackground NOTIFY showBackgroundChanged)
51 52
        Q_PROPERTY(bool showPositionMarker READ showPositionMarker WRITE setShowPositionMarker NOTIFY showPositionMarkerChanged)
        Q_PROPERTY(QString positionProvider READ positionProvider WRITE setPositionProvider NOTIFY positionProviderChanged)
53 54
        Q_PROPERTY(bool positionAvailable READ positionAvailable NOTIFY positionAvailableChanged)
        Q_PROPERTY(bool positionVisible READ positionVisible NOTIFY positionVisibleChanged)
55
        Q_PROPERTY(MarbleMap* marbleMap READ map NOTIFY marbleMapChanged)
56
        Q_PROPERTY(Placemark*  currentPosition READ currentPosition NOTIFY currentPositionChanged)
57 58
        Q_PROPERTY(qreal speed READ speed NOTIFY speedChanged)
        Q_PROPERTY(qreal angle READ angle NOTIFY angleChanged)
59
        Q_PROPERTY(bool inertialGlobeRotation READ inertialGlobeRotation WRITE setInertialGlobeRotation NOTIFY inertialGlobeRotationChanged)
60
        Q_PROPERTY(QQmlComponent* placemarkDelegate READ placemarkDelegate WRITE setPlacemarkDelegate NOTIFY placemarkDelegateChanged)
61

62
    public:
63
        explicit MarbleQuickItem(QQuickItem *parent = 0);
64 65 66 67 68 69 70 71 72 73 74 75 76

        enum Projection{
            Spherical = Marble::Spherical,
            Equirectangular = Marble::Equirectangular,
            Mercator = Marble::Mercator,
            Gnomonic = Marble::Gnomonic,
            Stereographic = Marble::Stereographic,
            LambertAzimuthal = Marble::LambertAzimuthal,
            AzimuthalEquidistant = Marble::AzimuthalEquidistant,
            VerticalPerspective = Marble::VerticalPerspective
        };


77 78
        MarbleInputHandler *inputHandler();
        int zoom() const;
79

80
    public Q_SLOTS:
81 82
        void goHome();
        void setZoom(int zoom, FlyToMode mode = Instant);
83
        Q_INVOKABLE void setZoomToMaximumLevel();
84
        void centerOn(const GeoDataPlacemark& placemark, bool animated = false);
85
        void centerOn(const GeoDataLatLonBox& box, bool animated = false);
86
        void centerOn(const GeoDataCoordinates& coordinate);
87
        void centerOn(qreal longitude, qreal latitude);
88
        Q_INVOKABLE void centerOnCoordinates(qreal longitude, qreal latitude);
89
        Q_INVOKABLE void centerOnCurrentPosition();
90
        Q_INVOKABLE void selectPlacemarkAt(int x, int y);
91 92 93 94

        void zoomIn(FlyToMode mode = Automatic);
        void zoomOut(FlyToMode mode = Automatic);

95 96 97 98
        Q_INVOKABLE void handlePinchStarted(const QPointF &point);
        Q_INVOKABLE void handlePinchFinished(const QPointF &point);
        Q_INVOKABLE void handlePinchUpdated(const QPointF &point, qreal scale);

99 100 101 102
        void setMapWidth(int mapWidth);
        void setMapHeight(int mapHeight);
        void setShowFrameRate(bool showFrameRate);
        void setProjection(Projection projection);
103
        void setMapThemeId(const QString& mapThemeId);
104 105 106 107 108 109 110 111 112
        void setShowAtmosphere(bool showAtmosphere);
        void setShowCompass(bool showCompass);
        void setShowClouds(bool showClouds);
        void setShowCrosshairs(bool showCrosshairs);
        void setShowGrid(bool showGrid);
        void setShowOverviewMap(bool showOverviewMap);
        void setShowOtherPlaces(bool showOtherPlaces);
        void setShowScaleBar(bool showScaleBar);
        void setShowBackground(bool showBackground);
113 114
        void setShowPositionMarker(bool showPositionMarker);
        void setPositionProvider(const QString & positionProvider);
115

116 117
        void setInertialGlobeRotation(bool inertialGlobeRotation);

118 119
        void setPluginSetting(const QString &plugin, const QString &key, const QString &value);

120 121 122
        void setPropertyEnabled(const QString &property, bool enabled);
        bool isPropertyEnabled(const QString &property) const;

123
        Q_INVOKABLE void setShowRuntimeTrace(bool showRuntimeTrace);
124
        Q_INVOKABLE void setShowDebugPolygons(bool showDebugPolygons);
125

126 127
        void setPlacemarkDelegate(QQmlComponent* placemarkDelegate);

128 129 130 131 132 133 134
    public:
        void paint(QPainter *painter);

    // QQmlParserStatus interface
    public:
        void classBegin();
        void componentComplete();
135 136

    public:
137
        virtual bool layersEventFilter(QObject *o, QEvent *e);
138

139 140 141 142 143 144 145 146 147 148 149 150 151 152
        int mapWidth() const;
        int mapHeight() const;
        bool showFrameRate() const;
        Projection projection() const;
        QString mapThemeId() const;
        bool showAtmosphere() const;
        bool showCompass() const;
        bool showClouds() const;
        bool showCrosshairs() const;
        bool showGrid() const;
        bool showOverviewMap() const;
        bool showOtherPlaces() const;
        bool showScaleBar() const;
        bool showBackground() const;
153 154
        bool showPositionMarker() const;
        QString positionProvider() const;
155 156 157 158
        bool positionAvailable() const;
        bool positionVisible();
        Q_INVOKABLE qreal distanceFromPointToCurrentLocation(const QPoint & position) const;
        Q_INVOKABLE qreal angleFromPointToCurrentLocation(const QPoint & position) const;
159
        Placemark* currentPosition() const;
160
        Q_INVOKABLE QPointF screenCoordinatesFromCoordinate(Coordinate * coordinate) const;
161 162
        qreal speed() const;
        qreal angle() const;
163

164 165 166 167 168 169
        MarbleModel* model();
        const MarbleModel* model() const;

        MarbleMap* map();
        const MarbleMap* map() const;

170
        bool inertialGlobeRotation() const;
171
        QQmlComponent* placemarkDelegate() const;
172
        void reverseGeocoding(const QPoint &point);
173

174
    Q_SIGNALS:
175 176 177 178
        void mapWidthChanged(int mapWidth);
        void mapHeightChanged(int mapHeight);
        void showFrameRateChanged(bool showFrameRate);
        void projectionChanged(Projection projection);
179
        void mapThemeIdChanged(const QString& mapThemeId);
180 181 182 183 184 185 186 187 188
        void showAtmosphereChanged(bool showAtmosphere);
        void showCompassChanged(bool showCompass);
        void showCloudsChanged(bool showClouds);
        void showCrosshairsChanged(bool showCrosshairs);
        void showGridChanged(bool showGrid);
        void showOverviewMapChanged(bool showOverviewMap);
        void showOtherPlacesChanged(bool showOtherPlaces);
        void showScaleBarChanged(bool showScaleBar);
        void showBackgroundChanged(bool showBackground);
189 190
        void showPositionMarkerChanged(bool showPositionMarker);
        void positionProviderChanged(const QString & positionProvider);
191 192
        void positionAvailableChanged(bool positionAvailable);
        void positionVisibleChanged(bool positionVisible);
193
        void marbleMapChanged();
194
        void visibleLatLonAltBoxChanged();
195
        void currentPositionChanged(Placemark* currentPosition);
196 197
        void angleChanged();
        void speedChanged();
198 199
        void zoomChanged();
        void inertialGlobeRotationChanged(bool inertialGlobeRotation);
200
        void placemarkDelegateChanged(QQmlComponent* placemarkDelegate);
201

202 203
    protected:
        QObject *getEventFilter() const;
204
        void pinch(const QPointF& center, qreal scale, Qt::GestureState state);
205

206
    private Q_SLOTS:
207
        void resizeMap();
208 209 210
        void positionDataStatusChanged(PositionProviderStatus status);
        void positionChanged(const GeoDataCoordinates &, GeoDataAccuracy);
        void updatePositionVisibility();
211
        void updateCurrentPosition(const GeoDataCoordinates & coordinates);
212
        void updatePlacemarks();
213
        void handleReverseGeocoding(const GeoDataCoordinates &coordinates, const GeoDataPlacemark &placemark);
214

215 216 217 218 219 220 221 222
    private:
        typedef QSharedPointer<MarbleQuickItemPrivate> MarbleQuickItemPrivatePtr;
        MarbleQuickItemPrivatePtr d;
        friend class MarbleQuickItemPrivate;
    };
}

#endif // MARBLEQUICKITEM_H