Commit 0e05ad0a authored by Torsten Rahn's avatar Torsten Rahn
Browse files

Additions to MarbleQuickItem QML element:

- Properties: heading, hoverEnabled
- Signals: lmbMenuRequested, rmbMenuRequested, hoverPositionChanged
- Functions: screenCoordinatesToCoordinate

Additions to Coordinate QML element:
- Properties: defaultNotation
- Functions: toGeoString()

Added moveToScreenCoordinates to GeoItem QML element
parent f0843d32
......@@ -736,7 +736,7 @@ class MARBLE_EXPORT MarbleMap : public QObject
void radiusChanged( int radius );
void mouseMoveGeoPosition( const QString& );
void mouseMoveGeoPosition( const QString& geoPositionString);
void mouseClickGeoPosition( qreal lon, qreal lat, GeoDataCoordinates::Unit );
......
......@@ -6,6 +6,7 @@
// the source code.
//
// Copyright 2011 Dennis Nienhüser <nienhueser@kde.org>
// Copyright 2021 Torsten Rahn
//
#include "Coordinate.h"
......@@ -72,6 +73,11 @@ void Coordinate::setCoordinates( const GeoDataCoordinates &coordinates )
m_coordinate = coordinates;
}
QString Coordinate::toGeoString(Coordinate::Notation notation, int precision) const
{
return m_coordinate.toString(static_cast<GeoDataCoordinates::Notation>(notation), precision);
}
qreal Coordinate::distance( qreal longitude, qreal latitude ) const
{
GeoDataCoordinates::Unit deg = GeoDataCoordinates::Degree;
......@@ -98,4 +104,17 @@ bool Coordinate::operator != ( const Coordinate &other ) const
return !operator == ( other );
}
Coordinate::Notation Coordinate::defaultNotation()
{
return static_cast<Coordinate::Notation>(GeoDataCoordinates::defaultNotation());
}
void Coordinate::setDefaultNotation(Coordinate::Notation defaultNotation)
{
if (GeoDataCoordinates::defaultNotation() == static_cast<GeoDataCoordinates::Notation>(defaultNotation))
return;
GeoDataCoordinates::setDefaultNotation(static_cast<GeoDataCoordinates::Notation>(defaultNotation));
emit defaultNotationChanged(defaultNotation);
}
#include "moc_Coordinate.cpp"
......@@ -28,7 +28,18 @@ class Coordinate : public QObject
Q_PROPERTY( qreal latitude READ latitude WRITE setLatitude NOTIFY latitudeChanged )
Q_PROPERTY( qreal altitude READ altitude WRITE setAltitude NOTIFY altitudeChanged )
Q_PROPERTY( Notation defaultNotation READ defaultNotation WRITE setDefaultNotation NOTIFY defaultNotationChanged )
public:
enum Notation{
Decimal, ///< "Decimal" notation (base-10)
DMS, ///< "Sexagesimal DMS" notation (base-60)
DM, ///< "Sexagesimal DM" notation (base-60)
UTM,
Astro /// < "RA and DEC" notation (used for astronomical sky coordinates)
};
Q_ENUM(Notation)
/** Constructor */
explicit Coordinate( qreal lon = 0.0, qreal lat = 0.0, qreal altitude = 0.0, QObject *parent = nullptr );
explicit Coordinate( const Marble::GeoDataCoordinates & coordinates );
......@@ -57,6 +68,8 @@ public:
/** Change all coordinates at once */
void setCoordinates( const Marble::GeoDataCoordinates &coordinates );
Q_INVOKABLE QString toGeoString( Coordinate::Notation notation = Coordinate::DMS, int precision = -1 ) const;
/** Distance (in meter) to the given coordinate */
Q_INVOKABLE qreal distance( qreal longitude, qreal latitude ) const;
......@@ -67,13 +80,19 @@ public:
bool operator != ( const Coordinate &other ) const;
Notation defaultNotation();
void setDefaultNotation(Notation defaultNotation);
Q_SIGNALS:
void longitudeChanged();
void latitudeChanged();
void altitudeChanged();
void defaultNotationChanged(Notation defaultNotation);
private:
Marble::GeoDataCoordinates m_coordinate;
Notation m_defaultNotation;
};
QML_DECLARE_TYPE( Coordinate )
......
......@@ -31,6 +31,14 @@ namespace Marble
connect(this, &QQuickItem::heightChanged, this, &GeoItem::updateScreenPosition);
}
bool GeoItem::moveToScreenCoordinates(qreal x, qreal y)
{
return m_map->screenCoordinatesToGeoDataCoordinates(QPoint(x,y), m_coordinate);
updateScreenPosition();
emit longitudeChanged();
emit latitudeChanged();
}
qreal GeoItem::longitude() const
{
return m_coordinate.longitude( GeoDataCoordinates::Degree );
......
......@@ -45,6 +45,9 @@ namespace Marble
/** Constructor */
explicit GeoItem( QQuickItem *parent = nullptr );
Q_INVOKABLE bool moveToScreenCoordinates(qreal x, qreal y);
/** Provides access to the longitude (degree) of the coordinate */
qreal longitude() const;
......
......@@ -44,6 +44,8 @@ void MarbleDeclarativePlugin::registerTypes( const char *uri )
//@uri org.kde.marble
qmlRegisterType<Coordinate>( uri, 0, 20, "Coordinate" );
qRegisterMetaType<Coordinate::Notation>();
qmlRegisterType<Marble::Placemark>( uri, 0, 20, "Placemark" );
qmlRegisterType<Marble::PositionSource>( uri, 0, 20, "PositionSource" );
qmlRegisterType<Marble::Bookmarks>( uri, 0, 20, "Bookmarks" );
......@@ -64,8 +66,7 @@ void MarbleDeclarativePlugin::registerTypes( const char *uri )
qRegisterMetaType<Marble::MarblePlacemarkModel*>("MarblePlacemarkModel*");
qmlRegisterType<Marble::MarbleQuickItem>(uri, 0, 20, "MarbleItem");
qmlRegisterType<Marble::GeoItem>(uri, 0, 20, "GeoItem");
qmlRegisterType<Marble::GeoPolyline>(uri, 0, 20, "GeoPolyline");
qmlRegisterType<Marble::GeoPolyline>(uri, 0, 20, "GeoPolyline");
qmlRegisterUncreatableType<Marble::MarblePlacemarkModel>(uri, 1, 0, "MarblePlacemarkModel",
QStringLiteral("MarblePlacemarkModel is not instantiable"));
......
......@@ -88,9 +88,12 @@ namespace Marble
void showLmbMenu(int x, int y) override
{
m_marbleQuick->selectPlacemarkAt(x, y);
emit m_marbleQuick->lmbMenuRequested(QPoint(x,y));
}
void showRmbMenu(int, int) override {}
void showRmbMenu(int x, int y) override {
emit m_marbleQuick->rmbMenuRequested(QPoint(x,y));
}
void openItemToolTip() override {}
void setCursor(const QCursor &cursor) override
{
......@@ -175,7 +178,9 @@ namespace Marble
GeoDataRelation::RouteTrolleyBus |
GeoDataRelation::RouteHiking),
m_showPublicTransport(false),
m_showOutdoorActivities(false)
m_showOutdoorActivities(false),
m_heading(0.0),
m_hoverEnabled(false)
{
m_currentPosition.setName(QObject::tr("Current Location"));
m_relationTypeConverter["road"] = GeoDataRelation::RouteRoad;
......@@ -220,6 +225,8 @@ namespace Marble
GeoDataRelation::RelationTypes m_enabledRelationTypes;
bool m_showPublicTransport;
bool m_showOutdoorActivities;
qreal m_heading;
bool m_hoverEnabled;
};
MarbleQuickItem::MarbleQuickItem(QQuickItem *parent) : QQuickPaintedItem(parent)
......@@ -354,9 +361,16 @@ namespace Marble
{
}
void Marble::MarbleQuickItem::MarbleQuickItem::hoverMoveEvent(QHoverEvent *event) {
if (d->m_hoverEnabled) {
emit hoverPositionChanged(event->pos());
}
QQuickItem::hoverMoveEvent(event);
}
int MarbleQuickItem::mapWidth() const
{
return d->m_map.width();
return d->m_map.width();
}
int MarbleQuickItem::mapHeight() const
......@@ -507,6 +521,10 @@ namespace Marble
d->m_reverseGeocoding.reverseGeocoding(coordinates);
}
bool MarbleQuickItem::hoverEnabled() const
{
return d->m_hoverEnabled;
}
qreal MarbleQuickItem::speed() const
{
......@@ -589,11 +607,62 @@ namespace Marble
return d->m_map.viewport()->screenCoordinates(lineString, polygons);
}
bool MarbleQuickItem::screenCoordinatesToCoordinate(const QPoint & point, Coordinate * coordinate)
{
GeoDataCoordinates geoDataCoordinates;
bool success = screenCoordinatesToGeoDataCoordinates(point, geoDataCoordinates);
if (!qobject_cast<Coordinate*>(coordinate)){
Coordinate * tmp(coordinate);
coordinate = new Coordinate(geoDataCoordinates.longitude(), geoDataCoordinates.latitude(), 0, nullptr);
QQmlEngine::setObjectOwnership(coordinate, QQmlEngine::JavaScriptOwnership);
delete tmp;
}
else {
coordinate->setLongitude(geoDataCoordinates.longitude());
coordinate->setLatitude(geoDataCoordinates.latitude());
}
return success;
}
bool MarbleQuickItem::screenCoordinatesToGeoDataCoordinates(const QPoint & point, GeoDataCoordinates & coordinates)
{
qreal lon = 0.0 , lat = 0.0;
bool const valid = d->m_map.viewport()->geoCoordinates(point.x(), point.y(), lon, lat);
coordinates.setLongitude(lon);
coordinates.setLatitude(lat);
return valid;
}
void MarbleQuickItem::setRadius(int radius)
{
d->m_map.setRadius(radius);
}
void MarbleQuickItem::setHeading(qreal heading)
{
if (qFuzzyCompare(d->m_heading, heading))
return;
d->m_map.setHeading(heading);
d->m_heading = heading;
emit headingChanged(d->m_heading);
}
void MarbleQuickItem::setHoverEnabled(bool hoverEnabled)
{
if (d->m_hoverEnabled == hoverEnabled)
return;
d->m_hoverEnabled = hoverEnabled;
setAcceptHoverEvents(hoverEnabled);
setFlag(ItemAcceptsInputMethod, hoverEnabled);
emit hoverEnabledChanged(d->m_hoverEnabled);
}
void MarbleQuickItem::setZoom(int newZoom, FlyToMode mode)
{
d->m_presenter.setZoom(newZoom, mode);
......@@ -1113,6 +1182,12 @@ namespace Marble
return d->m_map.radius();
}
qreal MarbleQuickItem::heading() const
{
return d->m_map.heading();
}
int MarbleQuickItem::zoom() const
{
return d->m_presenter.logzoom();
......
......@@ -41,6 +41,8 @@ namespace Marble
Q_PROPERTY(int mapHeight READ mapHeight WRITE setMapHeight NOTIFY mapHeightChanged)
Q_PROPERTY(int zoom READ zoom WRITE setZoom NOTIFY zoomChanged)
Q_PROPERTY(int radius READ radius WRITE setRadius NOTIFY radiusChanged)
Q_PROPERTY(qreal heading READ heading WRITE setHeading NOTIFY headingChanged)
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)
......@@ -67,6 +69,7 @@ namespace Marble
Q_PROPERTY(bool animationViewContext READ animationViewContext WRITE setAnimationViewContext NOTIFY animationViewContextChanged)
Q_PROPERTY(bool animationsEnabled READ animationsEnabled WRITE setAnimationsEnabled NOTIFY animationsEnabledChanged)
Q_PROPERTY(QQmlComponent* placemarkDelegate READ placemarkDelegate WRITE setPlacemarkDelegate NOTIFY placemarkDelegateChanged)
Q_PROPERTY(bool hoverEnabled READ hoverEnabled WRITE setHoverEnabled NOTIFY hoverEnabledChanged)
public:
explicit MarbleQuickItem(QQuickItem *parent = nullptr);
......@@ -151,6 +154,9 @@ namespace Marble
Q_INVOKABLE bool isRelationTypeVisible(const QString &relationType) const;
void setHeading(qreal heading);
void setHoverEnabled(bool hoverEnabled);
public:
void paint(QPainter *painter) override;
......@@ -159,11 +165,15 @@ namespace Marble
void classBegin() override;
void componentComplete() override;
void hoverMoveEvent(QHoverEvent* event) override;
public:
virtual bool layersEventFilter(QObject *o, QEvent *e);
int mapWidth() const;
int mapHeight() const;
qreal heading() const;
bool showFrameRate() const;
Projection projection() const;
QString mapThemeId() const;
......@@ -189,6 +199,8 @@ namespace Marble
Q_INVOKABLE QPointF screenCoordinatesFromGeoDataCoordinates(const GeoDataCoordinates & coordinates) const;
Q_INVOKABLE bool screenCoordinatesFromGeoDataLineString(const GeoDataLineString &lineString, QVector<QPolygonF*> &polygons ) const;
Q_INVOKABLE bool screenCoordinatesToGeoDataCoordinates(const QPoint & point, GeoDataCoordinates & coordinates);
Q_INVOKABLE bool screenCoordinatesToCoordinate(const QPoint & point, Coordinate * coordinate);
qreal speed() const;
qreal angle() const;
......@@ -205,6 +217,8 @@ namespace Marble
QQmlComponent* placemarkDelegate() const;
void reverseGeocoding(const QPoint &point);
bool hoverEnabled() const;
Q_SIGNALS:
void mapWidthChanged(int mapWidth);
void mapHeightChanged(int mapHeight);
......@@ -231,6 +245,7 @@ namespace Marble
void currentPositionChanged(Placemark* currentPosition);
void angleChanged();
void speedChanged();
void headingChanged(qreal heading);
void zoomChanged();
void radiusChanged(int radius);
void inertialGlobeRotationChanged(bool inertialGlobeRotation);
......@@ -239,6 +254,12 @@ namespace Marble
void animationsEnabledChanged(bool animationsEnabled);
void hoverEnabledChanged(bool hoverEnabled);
void lmbMenuRequested(const QPoint& point);
void rmbMenuRequested(const QPoint& point);
void hoverPositionChanged(const QPoint& point);
protected:
QObject *getEventFilter() const;
void pinch(const QPointF& center, qreal scale, Qt::GestureState state);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment