diff --git a/src/bindings/python/sip/MarbleWidget.sip b/src/bindings/python/sip/MarbleWidget.sip index ede7fbb13..0c65125df 100644 --- a/src/bindings/python/sip/MarbleWidget.sip +++ b/src/bindings/python/sip/MarbleWidget.sip @@ -1,203 +1,203 @@ // // Copyright 2008 Simon Edwards // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library. If not, see . // namespace Marble { class MarbleWidget : QWidget { %TypeHeaderCode #include %End public: explicit MarbleWidget (QWidget* parent /TransferThis/ = 0); Marble::MarbleModel* model () const; int radius () const; void setRadius (int radius); int zoom () const; qreal distance () const; void setDistance (qreal distance); QString distanceString () const; int minimumZoom () const; int maximumZoom () const; qreal centerLongitude () const; qreal centerLatitude () const; QPixmap mapScreenShot (); bool showOverviewMap () const; bool showScaleBar () const; bool showCompass () const; bool showClouds () const; bool showAtmosphere () const; bool showCrosshairs () const; bool showGrid () const; bool showPlaces () const; bool showCities () const; bool showTerrain () const; bool showOtherPlaces () const; bool showRelief () const; bool showIceLayer () const; bool showBorders () const; bool showRivers () const; bool showLakes () const; bool showFrameRate () const; quint64 volatileTileCacheLimit () const; QList renderPlugins () const; QList floatItems () const; Marble::Projection projection () const; QString mapThemeId () const; Marble::ViewContext viewContext () const; bool animationsEnabled () const; Marble::AngleUnit defaultAngleUnit () const; void setDefaultAngleUnit (Marble::AngleUnit angleUnit); QFont defaultFont () const; void setDefaultFont (const QFont& font); void zoomView (int zoom, Marble::FlyToMode mode = Marble::Instant); void zoomViewBy (int zoomStep, Marble::FlyToMode mode = Marble::Instant); void zoomIn (Marble::FlyToMode mode = Marble::Automatic); void zoomOut (Marble::FlyToMode mode = Marble::Automatic); void centerOn (const Marble::GeoDataCoordinates& point, bool animated = 0); void setCenterLatitude (qreal lat, Marble::FlyToMode mode = Marble::Instant); void setCenterLongitude (qreal lon, Marble::FlyToMode mode = Marble::Instant); void setProjection (int projection); void setProjection (Marble::Projection projection /Constrained/); void moveLeft (Marble::FlyToMode mode = Marble::Automatic); void moveRight (Marble::FlyToMode mode = Marble::Automatic); void moveUp (Marble::FlyToMode mode = Marble::Automatic); void moveDown (Marble::FlyToMode mode = Marble::Automatic); void goHome (Marble::FlyToMode mode = Marble::Automatic); void setMapThemeId (const QString& maptheme); void setPropertyValue (const QString& name, bool value); void setShowOverviewMap (bool visible); void setShowScaleBar (bool visible); void setShowCompass (bool visible); void setShowClouds (bool visible); void setShowAtmosphere (bool visible); void setShowCrosshairs (bool visible); void setShowGrid (bool visible); void setShowPlaces (bool visible); void setShowCities (bool visible); void setShowTerrain (bool visible); void setShowOtherPlaces (bool visible); void setShowRelief (bool visible); void setShowIceLayer (bool visible); void setShowBorders (bool visible); void setShowRivers (bool visible); void setShowLakes (bool visible); void setShowFrameRate (bool visible); void setShowTileId (bool visible); void notifyMouseClick (int x, int y); void clearVolatileTileCache (); void setVolatileTileCacheLimit (quint64 kiloBytes); void creatingTilesStart (Marble::TileCreator* creator, const QString& name, const QString& description); void setViewContext (Marble::ViewContext viewContext); void setAnimationsEnabled (bool enabled); void setSelection (const QRect& region); signals: void zoomChanged (int zoom); void distanceChanged (const QString& distanceString); void projectionChanged (Marble::Projection); void mouseClickGeoPosition (qreal lon, qreal lat, Marble::GeoDataCoordinates::Unit); void framesPerSecond (qreal fps); protected: void leaveEvent (QEvent* event); void paintEvent (QPaintEvent* event); virtual void customPaint (Marble::GeoPainter* painter); void resizeEvent (QResizeEvent* event); void connectNotify (const char* signal); void disconnectNotify (const char* signal); public: virtual ~MarbleWidget (); //ig MarbleWidgetInputHandler* inputHandler () const; //ig void setInputHandler (MarbleWidgetInputHandler* handler); void readPluginSettings (QSettings& settings); void writePluginSettings (QSettings& settings) const; //ig Marble::GeoSceneDocument* mapTheme () const; void setInputEnabled (bool); void centerOn (const Marble::GeoDataLatLonBox& box, bool animated = 0); signals: -//ig void regionSelected (const QList&); +//ig void regionSelected (const Marble::GeoDataLatLonBox &); void pluginSettingsChanged (); void renderPluginInitialized (Marble::RenderPlugin* renderPlugin); protected: void changeEvent (QEvent* event); public: //ig Marble::ViewportParams* viewport (); const Marble::ViewportParams* viewport () const; Marble::GeoDataLookAt lookAt () const; Marble::AbstractFloatItem* floatItem (const QString& nameId) const; //ig RoutingLayer* routingLayer (); void rotateBy (const qreal deltaLon, const qreal deltaLat, Marble::FlyToMode mode = Marble::Instant); void centerOn (const qreal lon, const qreal lat, bool animated = 0); void flyTo (const Marble::GeoDataLookAt& lookAt, Marble::FlyToMode mode = Marble::Automatic); void reloadMap (); signals: void themeChanged (const QString& theme); void mouseMoveGeoPosition (const QString&); void visibleLatLonAltBoxChanged (const Marble::GeoDataLatLonAltBox& visibleLatLonAltBox); public: int tileZoomLevel () const; QList whichItemAt (const QPoint& curpos) const; signals: void tileLevelChanged (int level); public: void addLayer (Marble::LayerInterface* layer /Transfer/); void removeLayer (Marble::LayerInterface* layer /TransferBack/); qreal radiusFromDistance (qreal distance) const; qreal distanceFromRadius (qreal radius) const; qreal zoomFromDistance (qreal distance) const; qreal distanceFromZoom (qreal zoom) const; bool showBackground () const; void setShowBackground (bool visible); void setMapQualityForViewContext (Marble::MapQuality quality, Marble::ViewContext viewContext); //FIXME //ig QVector whichFeatureAt (const QPoint&) const; //ig MarbleWidgetPopupMenu* popupMenu (); bool showSunShading () const; bool showCityLights () const; void centerOn (const Marble::GeoDataPlacemark& placemark, bool animated = 0); void setShowSunShading (bool visible); void setShowCityLights (bool visible); QRegion mapRegion () const; bool screenCoordinates (qreal lon, qreal lat, qreal& x, qreal& y) const; bool geoCoordinates (int x, int y, qreal& lon, qreal& lat, Marble::GeoDataCoordinates::Unit = Marble::GeoDataCoordinates::Degree) const; qreal moveStep () const; Marble::GeoDataCoordinates focusPoint () const; void setFocusPoint (const Marble::GeoDataCoordinates& focusPoint); void resetFocusPoint (); Marble::MapQuality mapQuality (Marble::ViewContext = Marble::Still) const; //ig const TextureLayer* textureLayer () const; void setShowRuntimeTrace (bool visible); void downloadRegion (const QVector&); // FIXME //ig PopupLayer* popupLayer (); bool isLockedToSubSolarPoint () const; bool isSubSolarPointIconVisible () const; void setZoom (int zoom, Marble::FlyToMode mode = Marble::Instant); void setLockToSubSolarPoint (bool visible); void setSubSolarPointIconVisible (bool visible); }; // MarbleWidget }; // Marble diff --git a/src/lib/marble/MarbleAbstractPresenter.cpp b/src/lib/marble/MarbleAbstractPresenter.cpp index 8613d89e4..19d2bcad9 100644 --- a/src/lib/marble/MarbleAbstractPresenter.cpp +++ b/src/lib/marble/MarbleAbstractPresenter.cpp @@ -1,603 +1,594 @@ // // 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. // // Copyright 2006-2007 Torsten Rahn // Copyright 2007 Inge Wallin // Copyright 2010-2012 Bernhard Beschow // Copyright 2012 Mohammed Nafees // Copyright 2014 Adam Dabrowski // #include #include #include #include #include #include "MarbleMap.h" #include "MarbleModel.h" #include #include "GeoDataGeometry.h" #include "GeoDataLatLonAltBox.h" #include #include #include #include namespace Marble { MarbleAbstractPresenter::MarbleAbstractPresenter(MarbleMap *map, QObject *parent) : QObject(parent) ,m_map(map) ,m_physics(this) ,m_animationsEnabled(false) ,m_logzoom(0) ,m_zoomStep(MarbleGlobal::getInstance()->profiles() & MarbleGlobal::SmallScreen ? 60 : 40) ,m_viewAngle(110) { } MarbleAbstractPresenter::~MarbleAbstractPresenter() { } qreal MarbleAbstractPresenter::zoom(qreal radius) const { return (200.0 * log(radius)); } qreal MarbleAbstractPresenter::radius(qreal zoom) const { return pow(M_E, (zoom / 200.0)); } void MarbleAbstractPresenter::rotateBy(const qreal deltaLon, const qreal deltaLat, FlyToMode mode) { Quaternion rotPhi(1.0, deltaLat / 180.0, 0.0, 0.0); Quaternion rotTheta(1.0, 0.0, deltaLon / 180.0, 0.0); Quaternion axis = map()->viewport()->planetAxis(); axis = rotTheta * axis; axis *= rotPhi; axis.normalize(); const qreal lat = -axis.pitch(); const qreal lon = axis.yaw(); GeoDataLookAt target = lookAt(); target.setLongitude(lon); target.setLatitude(lat); flyTo(target, mode); } void MarbleAbstractPresenter::flyTo(const GeoDataLookAt &newLookAt, FlyToMode mode) { if (!m_animationsEnabled || mode == Instant) { const int radius = qRound(radiusFromDistance(newLookAt.range() * METER2KM)); qreal const zoomVal = zoom(radius); // Prevent exceeding zoom range. Note: Bounding to range is not useful here if (qRound(zoomVal) >= minimumZoom() && qRound(zoomVal) <= maximumZoom()) { map()->setRadius(radius); m_logzoom = qRound(zoom(radius)); GeoDataCoordinates::Unit deg = GeoDataCoordinates::Degree; map()->centerOn(newLookAt.longitude(deg), newLookAt.latitude(deg)); emit zoomChanged(m_logzoom); emit distanceChanged(distanceString()); } } else { m_physics.flyTo(newLookAt, mode); } } QString MarbleAbstractPresenter::distanceString() const { // distance() returns data in km, so translating to meters qreal dist = distance() * KM2METER, convertedDistance; MarbleLocale::MeasureUnit unit; MarbleLocale *locale = MarbleGlobal::getInstance()->locale(); locale->meterToTargetUnit(dist, locale->measurementSystem(), convertedDistance, unit); QString unitString = locale->unitAbbreviation(unit); return QString("%L1 %2").arg(convertedDistance, 8, 'f', 1, QLatin1Char(' ')) .arg(unitString); } GeoDataLookAt MarbleAbstractPresenter::lookAt() const { GeoDataLookAt result; result.setLongitude(map()->viewport()->centerLongitude()); result.setLatitude(map()->viewport()->centerLatitude()); result.setAltitude(0.0); result.setRange(distance() * KM2METER); return result; } qreal MarbleAbstractPresenter::distance() const { return distanceFromRadius(radius()); } qreal MarbleAbstractPresenter::distanceFromRadius(qreal radius) const { // Due to Marble's orthographic projection ("we have no focus") // it's actually not possible to calculate a "real" distance. // Additionally the viewing angle of the earth doesn't adjust to // the window's size. // // So the only possible workaround is to come up with a distance // definition which gives a reasonable approximation of // reality. Therefore we assume that the average window width // (about 800 pixels) equals the viewing angle of a human being. return (model()->planet()->radius() * 0.4 / radius / tan(0.5 * m_viewAngle * DEG2RAD)); } qreal MarbleAbstractPresenter::radiusFromDistance(qreal distance) const { return model()->planet()->radius() / (distance * tan(0.5 * m_viewAngle * DEG2RAD) / 0.4 ); } int MarbleAbstractPresenter::polarity() const { return map()->viewport()->polarity(); } int MarbleAbstractPresenter::zoom() const { return m_logzoom; } int MarbleAbstractPresenter::minimumZoom() const { return map()->minimumZoom(); } int MarbleAbstractPresenter::maximumZoom() const { return map()->maximumZoom(); } void MarbleAbstractPresenter::setZoom(int newZoom, FlyToMode mode) { // It won't fly anyway. So we should do everything to keep the zoom value. if (!m_animationsEnabled || mode == Instant) { // Check for under and overflow. if (newZoom < minimumZoom()) newZoom = minimumZoom(); else if (newZoom > maximumZoom()) newZoom = maximumZoom(); // Prevent infinite loops. if (newZoom == m_logzoom) return; map()->setRadius(radius(newZoom)); m_logzoom = newZoom; emit zoomChanged(m_logzoom); emit distanceChanged(distanceString()); } else { GeoDataLookAt target = lookAt(); target.setRange(KM2METER * distanceFromZoom(newZoom)); flyTo(target, mode); } } void MarbleAbstractPresenter::zoomView(int zoom, FlyToMode mode) { setZoom(zoom, mode); } void MarbleAbstractPresenter::zoomViewBy(int zoomStep, FlyToMode mode) { setZoom(zoom() + zoomStep, mode); } void MarbleAbstractPresenter::zoomIn(FlyToMode mode) { if (map()->tileZoomLevel() < 0) { zoomViewBy(m_zoomStep, mode); } else { qreal radiusVal = map()->preferredRadiusCeil(map()->radius() / 0.95); radiusVal = qBound( radius(minimumZoom()), radiusVal, radius(maximumZoom()) ); GeoDataLookAt target = lookAt(); target.setRange(KM2METER * distanceFromRadius(radiusVal)); flyTo(target, mode); } } void MarbleAbstractPresenter::zoomOut(FlyToMode mode) { if (map()->tileZoomLevel() <= 0) { zoomViewBy(-m_zoomStep, mode); } else { qreal radiusVal = map()->preferredRadiusFloor(map()->radius() * 0.95); radiusVal = qBound( radius(minimumZoom()), radiusVal, radius(maximumZoom()) ); GeoDataLookAt target = lookAt(); target.setRange(KM2METER * distanceFromRadius(radiusVal)); flyTo(target, mode); } } void MarbleAbstractPresenter::zoomAtBy(const QPoint &pos, int zoomStep) { qreal radiusVal; if (map()->tileZoomLevel() <= 0) { radiusVal = radius(zoom() + zoomStep); } else { radiusVal = zoomStep > 0 ? map()->preferredRadiusCeil(map()->radius() / 0.95) : map()->preferredRadiusFloor(map()->radius() * 0.95); radiusVal = qBound( radius(minimumZoom()), radiusVal, radius(maximumZoom()) ); } zoomAt(pos, distanceFromRadius(radiusVal)); } qreal MarbleAbstractPresenter::distanceFromZoom(qreal zoom) const { return distanceFromRadius(radius(zoom)); } qreal MarbleAbstractPresenter::zoomFromDistance(qreal distance) const { return zoom(radiusFromDistance(distance)); } void MarbleAbstractPresenter::goHome(FlyToMode mode) { qreal homeLon = 0; qreal homeLat = 0; int homeZoom = 0; model()->home(homeLon, homeLat, homeZoom); GeoDataLookAt target; target.setLongitude(homeLon, GeoDataCoordinates::Degree); target.setLatitude(homeLat, GeoDataCoordinates::Degree); target.setRange(1000 * distanceFromZoom(homeZoom)); flyTo(target, mode); } void MarbleAbstractPresenter::moveByStep(int stepsRight, int stepsDown, FlyToMode mode) { int polarity = map()->viewport()->polarity(); qreal left = polarity * stepsRight * moveStep(); qreal down = stepsDown * moveStep(); rotateBy(left, down, mode); } qreal MarbleAbstractPresenter::moveStep() const { int width = map()->width(); int height = map()->height(); if (radius() < qSqrt((qreal)(width * width + height * height))) return 180.0 * 0.1; else return 180.0 * qAtan((qreal)width / (qreal)(2 * radius())) * 0.2; } int MarbleAbstractPresenter::radius() const { return map()->radius(); } void MarbleAbstractPresenter::setRadius(int radiusVal) { Q_ASSERT(radiusVal >= 0); bool adjustRadius = radiusVal != map()->radius(); qreal const zoomVal = zoom(radiusVal); // Prevent exceeding zoom range if (zoomVal < minimumZoom()) { radiusVal = radius(minimumZoom()); adjustRadius = true; } else if (zoomVal > maximumZoom()) { radiusVal = radius(maximumZoom()); adjustRadius = true; } if (adjustRadius) { map()->setRadius(radiusVal); m_logzoom = qRound(zoomVal); emit zoomChanged(m_logzoom); emit distanceChanged(distanceString()); } } //Moved from MarbleWidgetInputHandlerPrivate - fits more here now void MarbleAbstractPresenter::zoomAt(const QPoint &pos, qreal newDistance) { Q_ASSERT(newDistance > 0.0); qreal destLat; qreal destLon; if (!map()->geoCoordinates(pos.x(), pos.y(), destLon, destLat, GeoDataCoordinates::Degree)) { return; } ViewportParams* now = map()->viewport(); qreal x(0), y(0); if (!now->screenCoordinates(destLon * DEG2RAD, destLat * DEG2RAD, x, y)) { return; } ViewportParams soon; soon.setProjection(now->projection()); soon.centerOn(now->centerLongitude(), now->centerLatitude()); soon.setSize(now->size()); qreal newRadius = radiusFromDistance(newDistance); soon.setRadius(newRadius); qreal mouseLon, mouseLat; if (!soon.geoCoordinates(int(x), int(y), mouseLon, mouseLat, GeoDataCoordinates::Degree )) { return; } const qreal lon = destLon - (mouseLon - map()->centerLongitude()); const qreal lat = destLat - (mouseLat - map()->centerLatitude()); GeoDataLookAt lookAt; lookAt.setLongitude(lon, GeoDataCoordinates::Degree); lookAt.setLatitude(lat, GeoDataCoordinates::Degree); lookAt.setAltitude(0.0); lookAt.setRange(newDistance * KM2METER); map()->viewport()->setFocusPoint(GeoDataCoordinates(destLon, destLat, 0, GeoDataCoordinates::Degree)); flyTo(lookAt, Linear); } void MarbleAbstractPresenter::moveTo(const QPoint &pos, qreal factor) { Q_ASSERT(factor > 0.0); qreal destLat; qreal destLon; map()->geoCoordinates(pos.x(), pos.y(), destLon, destLat, GeoDataCoordinates::Radian); GeoDataLookAt lookAt; lookAt.setLongitude(destLon); lookAt.setLatitude(destLat); lookAt.setAltitude(0.0); lookAt.setRange(distance() * factor * KM2METER); flyTo(lookAt); } void MarbleAbstractPresenter::centerOn(const qreal lon, const qreal lat, bool animated) { GeoDataCoordinates target(lon, lat, 0.0, GeoDataCoordinates::Degree); centerOn(target, animated); } void MarbleAbstractPresenter::centerOn(const GeoDataCoordinates &position, bool animated) { GeoDataLookAt target = lookAt(); target.setCoordinates(position); flyTo(target, animated ? Automatic : Instant); } void MarbleAbstractPresenter::centerOn(const GeoDataLatLonBox &box, bool animated) { if (box.isEmpty()) { return; } int newRadius = radius(); ViewportParams* viewparams = map()->viewport(); //prevent divide by zero if(box.height() && box.width()) { //work out the needed zoom level int const horizontalRadius = ( 0.25 * M_PI ) * (viewparams->height() / box.height()); int const verticalRadius = ( 0.25 * M_PI ) * (viewparams->width() / box.width()); newRadius = qMin(horizontalRadius, verticalRadius ); newRadius = qMax(radius(minimumZoom()), qMin(newRadius, radius(maximumZoom()))); } //move the map GeoDataLookAt target; target.setCoordinates(box.center()); target.setAltitude(box.center().altitude()); target.setRange(KM2METER * distanceFromRadius(newRadius)); flyTo(target, animated ? Automatic : Instant); } void MarbleAbstractPresenter::centerOn(const GeoDataPlacemark& placemark, bool animated) { const GeoDataLookAt *lookAt(placemark.lookAt()); if (lookAt) { flyTo(*lookAt, animated ? Automatic : Instant); } else { bool icon; GeoDataCoordinates coords = placemark.coordinate(model()->clock()->dateTime(), &icon); if (icon) { centerOn(coords, animated); } else { centerOn(placemark.geometry()->latLonAltBox(), animated); } } } void MarbleAbstractPresenter::headingOn(qreal heading) { map()->setHeading(heading); } void MarbleAbstractPresenter::setCenterLatitude(qreal lat, FlyToMode mode) { centerOn(centerLongitude(), lat, mode); } void MarbleAbstractPresenter::setCenterLongitude(qreal lon, FlyToMode mode) { centerOn(lon, centerLatitude(), mode); } qreal MarbleAbstractPresenter::centerLatitude() const { return map()->centerLatitude(); } qreal MarbleAbstractPresenter::centerLongitude() const { return map()->centerLongitude(); } ViewContext MarbleAbstractPresenter::viewContext() const { return map()->viewContext(); } void MarbleAbstractPresenter::setViewContext(ViewContext viewContext) { map()->setViewContext(viewContext); } bool MarbleAbstractPresenter::animationsEnabled() const { return m_animationsEnabled; } void MarbleAbstractPresenter::setAnimationsEnabled(bool enabled) { m_animationsEnabled = enabled; } int MarbleAbstractPresenter::logzoom() const { return m_logzoom; } void MarbleAbstractPresenter::setLogzoom(int value) { m_logzoom = value; } int MarbleAbstractPresenter::zoomStep() const { return m_zoomStep; } qreal MarbleAbstractPresenter::viewAngle() const { return m_viewAngle; } MarbleMap* MarbleAbstractPresenter::map() { return m_map; } const MarbleMap* MarbleAbstractPresenter::map() const { return m_map; } MarbleModel* MarbleAbstractPresenter::model() { return m_map->model(); } const MarbleModel* MarbleAbstractPresenter::model() const { return m_map->model(); } ViewportParams* MarbleAbstractPresenter::viewport() { return map()->viewport(); } const ViewportParams* MarbleAbstractPresenter::viewport() const { return map()->viewport(); } void MarbleAbstractPresenter::setDistance(qreal newDistance) { qreal minDistance = 0.001; if (newDistance <= minDistance) { mDebug() << "Invalid distance: 0 m"; newDistance = minDistance; } int newRadius = radiusFromDistance(newDistance); setRadius(newRadius); } void MarbleAbstractPresenter::setSelection(const QRect& region) { QPoint tl = region.topLeft(); QPoint br = region.bottomRight(); mDebug() << "Selection region: (" << tl.x() << ", " << tl.y() << ") (" << br.x() << ", " << br.y() << ")" << endl; - GeoDataLatLonAltBox box = viewport()->latLonAltBox(region); + const GeoDataLatLonAltBox box = viewport()->latLonAltBox(region); - // NOTE: coordinates as lon1, lat1, lon2, lat2 (or West, North, East, South) - // as left/top, right/bottom rectangle. - QList coordinates; - coordinates << box.west(GeoDataCoordinates::Degree) << box.north(GeoDataCoordinates::Degree) - << box.east(GeoDataCoordinates::Degree) << box.south(GeoDataCoordinates::Degree); - - mDebug() << "West: " << coordinates[0] << " North: " << coordinates[1] - << " East: " << coordinates[2] << " South: " << coordinates[3] << endl; - - emit regionSelected(coordinates); + emit regionSelected(box); } } #include "moc_MarbleAbstractPresenter.cpp" diff --git a/src/lib/marble/MarbleAbstractPresenter.h b/src/lib/marble/MarbleAbstractPresenter.h index 8ec1f2c2a..de85fca98 100644 --- a/src/lib/marble/MarbleAbstractPresenter.h +++ b/src/lib/marble/MarbleAbstractPresenter.h @@ -1,155 +1,156 @@ // // 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. // // Copyright 2006-2008 Torsten Rahn // Copyright 2007 Inge Wallin // Copyright 2014 Adam Dabrowski // #ifndef MARBLEABSTRACTPRESENTER_H #define MARBLEABSTRACTPRESENTER_H #include #include "GeoDataLatLonBox.h" #include "MarblePhysics.h" #include namespace Marble { class GeoDataPlacemark; class GeoDataLookAt; class MarbleMap; class MarbleModel; class ViewportParams; class MARBLE_EXPORT MarbleAbstractPresenter : public QObject { Q_OBJECT Q_SIGNALS: void zoomChanged(int zoom); void distanceChanged(const QString& distanceString); - /** This signal is emitted when a new rectangle region is selected over the map - * The list of double values includes coordinates in degrees using the following: - * lon1, lat1, lon2, lat2 (or West, North, East, South) as left/top, right/bottom rectangle. - */ - void regionSelected(const QList&); + /** + * This signal is emit when a new rectangle region is selected over the map. + * + * @param boundingBox The geographical coordinates of the selected region + */ + void regionSelected(const GeoDataLatLonBox &boundingBox); public: explicit MarbleAbstractPresenter(MarbleMap *map, QObject *parent = 0); ~MarbleAbstractPresenter() override; qreal moveStep() const; int radius() const; GeoDataLookAt lookAt() const; QString distanceString() const; /** * @brief Approximated altitude of the camera in km */ qreal distance() const; /** * @brief An approximate distance from @p radius * @param radius radius of planet disc in screen pixels */ qreal distanceFromRadius(qreal radius) const; /** * @brief The radius of the rendered planet disc derived from the approximate apparent @p distance */ qreal radiusFromDistance(qreal distance) const; /** * @brief Rotate the globe in the given direction in discrete steps * @param stepsRight Number of steps to go right. Negative values go left. * @param stepsDown Number of steps to go down. Negative values go up. * @param mode Interpolation mode to use when traveling to the target */ void moveByStep(int stepsRight, int stepsDown, FlyToMode mode = Automatic); int polarity() const; int zoom() const; int minimumZoom() const; int maximumZoom() const; qreal distanceFromZoom(qreal zoom) const; qreal zoomFromDistance(qreal distance) const; void zoomAt(const QPoint &pos, qreal newDistance); void moveTo(const QPoint &pos, qreal factor); qreal centerLongitude() const; qreal centerLatitude() const; ViewContext viewContext() const; qreal zoom(qreal radius) const; qreal radius(qreal zoom) const; MarbleMap* map(); MarbleModel* model(); const MarbleMap* map() const; const MarbleModel* model() const; int logzoom() const; void setLogzoom(int value); int zoomStep() const; qreal viewAngle() const; bool animationsEnabled() const; ViewportParams *viewport(); const ViewportParams* viewport() const; public Q_SLOTS: void rotateBy(const qreal deltaLon, const qreal deltaLat, FlyToMode mode = Instant); void flyTo(const GeoDataLookAt &newLookAt, FlyToMode mode = Automatic); void goHome(FlyToMode mode = Automatic); void setZoom(int newZoom, FlyToMode mode = Instant); void zoomView(int zoom, FlyToMode mode = Instant); void zoomViewBy(int zoomStep, FlyToMode mode = Instant); void zoomIn(FlyToMode mode = Automatic); void zoomOut(FlyToMode mode = Automatic); void zoomAtBy(const QPoint &pos, int zoomStep); void setViewContext(ViewContext viewContext); void centerOn(const qreal lon, const qreal lat, bool animated = false); void centerOn(const GeoDataCoordinates &point, bool animated = false); void centerOn(const GeoDataLatLonBox& box, bool animated = false); void centerOn(const GeoDataPlacemark& placemark, bool animated = false); void headingOn(qreal heading); void setCenterLatitude(qreal lat, FlyToMode mode); void setCenterLongitude(qreal lon, FlyToMode mode); void setAnimationsEnabled(bool enabled); void setRadius(int radius); void setDistance(qreal newDistance); void setSelection(const QRect& region); private: MarbleMap *const m_map; MarblePhysics m_physics; bool m_animationsEnabled; int m_logzoom; int m_zoomStep; const qreal m_viewAngle; }; } #endif // MARBLEABSTRACTPRESENTER_H diff --git a/src/lib/marble/MarbleWidget.cpp b/src/lib/marble/MarbleWidget.cpp index 3a656f77a..2e79f7d64 100644 --- a/src/lib/marble/MarbleWidget.cpp +++ b/src/lib/marble/MarbleWidget.cpp @@ -1,1252 +1,1252 @@ // // 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. // // Copyright 2006-2007 Torsten Rahn // Copyright 2007 Inge Wallin // Copyright 2010-2012 Bernhard Beschow // Copyright 2012 Mohammed Nafees // #include "MarbleWidget.h" #include #include #include #include #include #include #include #include #include #include "DataMigration.h" #include "FpsLayer.h" #include "FileManager.h" #include "GeoDataLatLonAltBox.h" #include "GeoDataPlacemark.h" #include "GeoDataLookAt.h" #include "GeoPainter.h" #include "MarbleClock.h" #include "MarbleDebug.h" #include "MarbleDirs.h" #include "MarbleLocale.h" #include "MarbleMap.h" #include "MarbleModel.h" #include "MarbleWidgetInputHandler.h" #include "MarbleWidgetPopupMenu.h" #include "Planet.h" #include "PopupLayer.h" #include "RenderState.h" #include "RenderPlugin.h" #include "SunLocator.h" #include "TileCreatorDialog.h" #include "ViewportParams.h" #include "routing/RoutingLayer.h" #include "MarbleAbstractPresenter.h" #include "StyleBuilder.h" namespace Marble { class MarbleWidget::CustomPaintLayer : public LayerInterface { public: explicit CustomPaintLayer( MarbleWidget *widget ) : m_widget( widget ) { } QStringList renderPosition() const override { return QStringList() << "USER_TOOLS"; } bool render( GeoPainter *painter, ViewportParams *viewport, const QString &renderPos, GeoSceneLayer *layer ) override { Q_UNUSED( viewport ); Q_UNUSED( renderPos ); Q_UNUSED( layer ); painter->setPen( Qt::black ); m_widget->customPaint( painter ); return true; } qreal zValue() const override { return 1.0e7; } RenderState renderState() const override { return RenderState(QStringLiteral("Custom Widget Paint")); } QString runtimeTrace() const override { return QStringLiteral("MarbleWidget::CustomPaintLayer"); } private: MarbleWidget *const m_widget; }; class MarbleWidgetPrivate { public: explicit MarbleWidgetPrivate( MarbleWidget *parent ) : m_widget( parent ), m_model(), m_map( &m_model ), m_presenter( &m_map ), m_inputhandler( 0 ), m_routingLayer( 0 ), m_mapInfoDialog( 0 ), m_customPaintLayer( parent ), m_popupmenu( 0 ), m_showFrameRate( false ) { } ~MarbleWidgetPrivate() { m_map.removeLayer( &m_customPaintLayer ); m_map.removeLayer( m_mapInfoDialog ); delete m_mapInfoDialog; delete m_popupmenu; } void construct(); void updateMapTheme(); void setInputHandler(); void setInputHandler( MarbleWidgetInputHandler *handler ); /** * @brief Update widget flags and cause a full repaint * * The background of the widget only needs to be redrawn in certain cases. This * method sets the widget flags accordingly and triggers a repaint. */ void updateSystemBackgroundAttribute(); MarbleWidget *const m_widget; MarbleModel m_model; MarbleMap m_map; MarbleAbstractPresenter m_presenter; MarbleWidgetInputHandler *m_inputhandler; RoutingLayer *m_routingLayer; PopupLayer *m_mapInfoDialog; MarbleWidget::CustomPaintLayer m_customPaintLayer; MarbleWidgetPopupMenu *m_popupmenu; bool m_showFrameRate; }; MarbleWidget::MarbleWidget(QWidget *parent) : QWidget( parent ), d( new MarbleWidgetPrivate( this ) ) { // setAttribute( Qt::WA_PaintOnScreen, true ); d->construct(); } MarbleWidget::~MarbleWidget() { // Remove and delete an existing InputHandler // initialized in d->construct() setInputHandler( 0 ); delete d; } void MarbleWidgetPrivate::construct() { QPointer dataMigration = new DataMigration( m_widget ); dataMigration->exec(); delete dataMigration; // Widget settings m_widget->setMinimumSize( 200, 300 ); m_widget->setFocusPolicy( Qt::WheelFocus ); m_widget->setFocus( Qt::OtherFocusReason ); // Set background: black. m_widget->setPalette( QPalette ( Qt::black ) ); // Set whether the black space gets displayed or the earth gets simply // displayed on the widget background. m_widget->setAutoFillBackground( true ); // Initialize the map and forward some signals. m_map.setSize( m_widget->width(), m_widget->height() ); m_map.setShowFrameRate( false ); // never let the map draw the frame rate, // we do this differently here in the widget - m_widget->connect( &m_presenter, SIGNAL(regionSelected(QList)), m_widget, SIGNAL(regionSelected(QList)) ); + m_widget->connect( &m_presenter, SIGNAL(regionSelected(GeoDataLatLonBox)), m_widget, SIGNAL(regionSelected(GeoDataLatLonBox)) ); m_widget->connect( &m_presenter, SIGNAL(zoomChanged(int)), m_widget, SIGNAL(zoomChanged(int)) ); m_widget->connect( &m_presenter, SIGNAL(distanceChanged(QString)), m_widget, SIGNAL(distanceChanged(QString)) ); // forward some signals of m_map m_widget->connect( &m_map, SIGNAL(visibleLatLonAltBoxChanged(GeoDataLatLonAltBox)), m_widget, SIGNAL(visibleLatLonAltBoxChanged(GeoDataLatLonAltBox)) ); m_widget->connect( &m_map, SIGNAL(projectionChanged(Projection)), m_widget, SIGNAL(projectionChanged(Projection)) ); m_widget->connect( &m_map, SIGNAL(tileLevelChanged(int)), m_widget, SIGNAL(tileLevelChanged(int)) ); m_widget->connect( &m_map, SIGNAL(framesPerSecond(qreal)), m_widget, SIGNAL(framesPerSecond(qreal)) ); m_widget->connect( &m_map, SIGNAL(viewContextChanged(ViewContext)), m_widget, SLOT(setViewContext(ViewContext)) ); m_widget->connect( &m_map, SIGNAL(pluginSettingsChanged()), m_widget, SIGNAL(pluginSettingsChanged()) ); m_widget->connect( &m_map, SIGNAL(renderPluginInitialized(RenderPlugin*)), m_widget, SIGNAL(renderPluginInitialized(RenderPlugin*)) ); // react to some signals of m_map m_widget->connect( &m_map, SIGNAL(themeChanged(QString)), m_widget, SLOT(updateMapTheme()) ); m_widget->connect( &m_map, SIGNAL(viewContextChanged(ViewContext)), m_widget, SIGNAL(viewContextChanged(ViewContext)) ); m_widget->connect( &m_map, SIGNAL(repaintNeeded(QRegion)), m_widget, SLOT(update()) ); m_widget->connect( &m_map, SIGNAL(visibleLatLonAltBoxChanged(GeoDataLatLonAltBox)), m_widget, SLOT(updateSystemBackgroundAttribute()) ); m_widget->connect( &m_map, SIGNAL(renderStatusChanged(RenderStatus)), m_widget, SIGNAL(renderStatusChanged(RenderStatus)) ); m_widget->connect( &m_map, SIGNAL(renderStateChanged(RenderState)), m_widget, SIGNAL(renderStateChanged(RenderState)) ); m_widget->connect( m_model.fileManager(), SIGNAL(centeredDocument(GeoDataLatLonBox)), m_widget, SLOT(centerOn(GeoDataLatLonBox)) ); // Show a progress dialog when the model calculates new map tiles. m_widget->connect( &m_model, SIGNAL( creatingTilesStart( TileCreator*, const QString&, const QString& ) ), m_widget, SLOT( creatingTilesStart( TileCreator*, const QString&, const QString& ) ) ); m_popupmenu = new MarbleWidgetPopupMenu( m_widget, &m_model ); m_routingLayer = new RoutingLayer( m_widget, m_widget ); m_routingLayer->setPlacemarkModel( 0 ); QObject::connect( m_routingLayer, SIGNAL(repaintNeeded(QRect)), m_widget, SLOT(update()) ); m_mapInfoDialog = new PopupLayer( m_widget, m_widget ); m_mapInfoDialog->setVisible( false ); m_widget->connect( m_mapInfoDialog, SIGNAL(repaintNeeded()), m_widget, SLOT(update()) ); m_map.addLayer( m_mapInfoDialog ); setInputHandler(); m_widget->setMouseTracking( true ); m_map.addLayer( &m_customPaintLayer ); m_widget->connect( m_inputhandler, SIGNAL(mouseClickGeoPosition(qreal,qreal,GeoDataCoordinates::Unit)), m_widget, SIGNAL(highlightedPlacemarksChanged(qreal,qreal,GeoDataCoordinates::Unit)) ); m_widget->setHighlightEnabled( true ); } void MarbleWidgetPrivate::setInputHandler() { setInputHandler( new MarbleWidgetInputHandler( &m_presenter, m_widget ) ); } void MarbleWidgetPrivate::setInputHandler( MarbleWidgetInputHandler *handler ) { delete m_inputhandler; m_inputhandler = handler; if ( m_inputhandler ) { m_widget->installEventFilter( m_inputhandler ); QObject::connect( m_inputhandler, SIGNAL(mouseClickScreenPosition(int,int)), m_widget, SLOT(notifyMouseClick(int,int)) ); QObject::connect( m_inputhandler, SIGNAL(mouseMoveGeoPosition(QString)), m_widget, SIGNAL(mouseMoveGeoPosition(QString)) ); } } void MarbleWidgetPrivate::updateSystemBackgroundAttribute() { // We only have to repaint the background every time if the earth // doesn't cover the whole image. const bool isOn = m_map.viewport()->mapCoversViewport() && !m_model.mapThemeId().isEmpty(); m_widget->setAttribute( Qt::WA_NoSystemBackground, isOn ); } // ---------------------------------------------------------------- MarbleModel *MarbleWidget::model() { return &d->m_model; } const MarbleModel *MarbleWidget::model() const { return &d->m_model; } ViewportParams* MarbleWidget::viewport() { return d->m_map.viewport(); } const ViewportParams* MarbleWidget::viewport() const { return d->m_map.viewport(); } MarbleWidgetPopupMenu *MarbleWidget::popupMenu() { return d->m_popupmenu; } void MarbleWidget::setInputHandler( MarbleWidgetInputHandler *handler ) { d->setInputHandler(handler); } MarbleWidgetInputHandler *MarbleWidget::inputHandler() const { return d->m_inputhandler; } int MarbleWidget::radius() const { return d->m_map.radius(); } void MarbleWidget::setRadius( int radius ) { d->m_map.setRadius( radius ); } qreal MarbleWidget::moveStep() const { return d->m_presenter.moveStep(); } int MarbleWidget::zoom() const { return d->m_presenter.logzoom(); } int MarbleWidget::tileZoomLevel() const { return d->m_map.tileZoomLevel(); } int MarbleWidget::minimumZoom() const { return d->m_map.minimumZoom(); } int MarbleWidget::maximumZoom() const { return d->m_map.maximumZoom(); } QVector MarbleWidget::whichFeatureAt( const QPoint &curpos ) const { return d->m_map.whichFeatureAt( curpos ); } QList MarbleWidget::whichItemAt( const QPoint &curpos ) const { return d->m_map.whichItemAt( curpos ); } void MarbleWidget::addLayer( LayerInterface *layer ) { d->m_map.addLayer( layer ); } void MarbleWidget::removeLayer( LayerInterface *layer ) { d->m_map.removeLayer( layer ); } Marble::TextureLayer* MarbleWidget::textureLayer() const { return d->m_map.textureLayer(); } QPixmap MarbleWidget::mapScreenShot() { return QPixmap::grabWidget( this ); } RenderStatus MarbleWidget::renderStatus() const { return d->m_map.renderStatus(); } RenderState MarbleWidget::renderState() const { return d->m_map.renderState(); } void MarbleWidget::setHighlightEnabled(bool enabled) { if ( enabled ) { connect( this, SIGNAL(highlightedPlacemarksChanged(qreal,qreal,GeoDataCoordinates::Unit)), &d->m_map, SIGNAL(highlightedPlacemarksChanged(qreal,qreal,GeoDataCoordinates::Unit)), Qt::UniqueConnection ); } else { disconnect( this, SIGNAL(highlightedPlacemarksChanged(qreal,qreal,GeoDataCoordinates::Unit)), &d->m_map, SIGNAL(highlightedPlacemarksChanged(qreal,qreal,GeoDataCoordinates::Unit)) ); } } bool MarbleWidget::showOverviewMap() const { return d->m_map.showOverviewMap(); } bool MarbleWidget::showScaleBar() const { return d->m_map.showScaleBar(); } bool MarbleWidget::showCompass() const { return d->m_map.showCompass(); } bool MarbleWidget::showClouds() const { return d->m_map.showClouds(); } bool MarbleWidget::showSunShading() const { return d->m_map.showSunShading(); } bool MarbleWidget::showCityLights() const { return d->m_map.showCityLights(); } bool MarbleWidget::isLockedToSubSolarPoint() const { return d->m_map.isLockedToSubSolarPoint(); } bool MarbleWidget::isSubSolarPointIconVisible() const { return d->m_map.isSubSolarPointIconVisible(); } bool MarbleWidget::showAtmosphere() const { return d->m_map.showAtmosphere(); } bool MarbleWidget::showCrosshairs() const { return d->m_map.showCrosshairs(); } bool MarbleWidget::showGrid() const { return d->m_map.showGrid(); } bool MarbleWidget::showPlaces() const { return d->m_map.showPlaces(); } bool MarbleWidget::showCities() const { return d->m_map.showCities(); } bool MarbleWidget::showTerrain() const { return d->m_map.showTerrain(); } bool MarbleWidget::showOtherPlaces() const { return d->m_map.showOtherPlaces(); } bool MarbleWidget::showRelief() const { return d->m_map.showRelief(); } bool MarbleWidget::showIceLayer() const { return d->m_map.showIceLayer(); } bool MarbleWidget::showBorders() const { return d->m_map.showBorders(); } bool MarbleWidget::showRivers() const { return d->m_map.showRivers(); } bool MarbleWidget::showLakes() const { return d->m_map.showLakes(); } bool MarbleWidget::showFrameRate() const { return d->m_showFrameRate; } bool MarbleWidget::showBackground() const { return d->m_map.showBackground(); } quint64 MarbleWidget::volatileTileCacheLimit() const { return d->m_map.volatileTileCacheLimit(); } void MarbleWidget::setZoom( int newZoom, FlyToMode mode ) { d->m_presenter.setZoom( newZoom, mode ); } void MarbleWidget::zoomView( int zoom, FlyToMode mode ) { d->m_presenter.zoomView( zoom, mode ); } void MarbleWidget::zoomViewBy( int zoomStep, FlyToMode mode ) { d->m_presenter.zoomViewBy( zoomStep, mode ); } void MarbleWidget::zoomIn( FlyToMode mode ) { d->m_presenter.zoomIn( mode ); } void MarbleWidget::zoomOut( FlyToMode mode ) { d->m_presenter.zoomOut( mode ); } void MarbleWidget::rotateBy( const qreal deltaLon, const qreal deltaLat, FlyToMode mode ) { d->m_presenter.rotateBy( deltaLon, deltaLat, mode ); } void MarbleWidget::centerOn( const qreal lon, const qreal lat, bool animated ) { d->m_presenter.centerOn( lon, lat, animated ); } void MarbleWidget::centerOn( const GeoDataCoordinates &position, bool animated ) { d->m_presenter.centerOn( position, animated ); } void MarbleWidget::centerOn( const GeoDataLatLonBox &box, bool animated ) { d->m_presenter.centerOn( box, animated ); } void MarbleWidget::centerOn( const GeoDataPlacemark& placemark, bool animated ) { d->m_presenter.centerOn( placemark, animated ); } void MarbleWidget::setCenterLatitude( qreal lat, FlyToMode mode ) { d->m_presenter.setCenterLatitude( lat, mode ); } void MarbleWidget::setCenterLongitude( qreal lon, FlyToMode mode ) { d->m_presenter.setCenterLongitude( lon, mode ); } Projection MarbleWidget::projection() const { return d->m_map.projection(); } void MarbleWidget::setProjection( Projection projection ) { d->m_map.setProjection( projection ); } void MarbleWidget::setProjection( int projection ) { setProjection( Projection( qAbs( projection ) % (Mercator+1) ) ); } void MarbleWidget::moveLeft( FlyToMode mode ) { d->m_presenter.moveByStep( -1, 0, mode ); } void MarbleWidget::moveRight( FlyToMode mode ) { d->m_presenter.moveByStep( 1, 0, mode ); } void MarbleWidget::moveUp( FlyToMode mode ) { d->m_presenter.moveByStep( 0, -1, mode ); } void MarbleWidget::moveDown( FlyToMode mode ) { d->m_presenter.moveByStep( 0, 1, mode ); } void MarbleWidget::leaveEvent( QEvent* ) { emit mouseMoveGeoPosition( QCoreApplication::translate( "Marble", NOT_AVAILABLE ) ); } void MarbleWidget::resizeEvent( QResizeEvent *event ) { setUpdatesEnabled( false ); d->m_map.setSize( event->size() ); setUpdatesEnabled( true ); QWidget::resizeEvent( event ); } void MarbleWidget::connectNotify( const QMetaMethod &signal ) { if ( d->m_inputhandler && signal == QMetaMethod::fromSignal( &MarbleWidget::mouseMoveGeoPosition ) ) { d->m_inputhandler->setPositionSignalConnected( true ); } } void MarbleWidget::disconnectNotify( const QMetaMethod &signal ) { if ( d->m_inputhandler && signal == QMetaMethod::fromSignal( &MarbleWidget::mouseMoveGeoPosition ) ) { d->m_inputhandler->setPositionSignalConnected( false ); } } bool MarbleWidget::screenCoordinates( qreal lon, qreal lat, qreal& x, qreal& y ) const { return d->m_map.screenCoordinates( lon, lat, x, y ); } bool MarbleWidget::geoCoordinates( int x, int y, qreal& lon, qreal& lat, GeoDataCoordinates::Unit unit ) const { return d->m_map.geoCoordinates( x, y, lon, lat, unit ); } qreal MarbleWidget::centerLatitude() const { return d->m_map.centerLatitude(); } qreal MarbleWidget::centerLongitude() const { return d->m_map.centerLongitude(); } QRegion MarbleWidget::mapRegion() const { return viewport()->mapRegion(); } void MarbleWidget::paintEvent( QPaintEvent *evt ) { QTime t; t.start(); QPaintDevice *paintDevice = this; QImage image; if (!isEnabled()) { // If the globe covers fully the screen then we can use the faster // RGB32 as there are no translucent areas involved. QImage::Format imageFormat = ( d->m_map.viewport()->mapCoversViewport() ) ? QImage::Format_RGB32 : QImage::Format_ARGB32_Premultiplied; // Paint to an intermediate image image = QImage( rect().size(), imageFormat ); image.fill( Qt::transparent ); paintDevice = ℑ } { // FIXME: Better way to get the GeoPainter // Create a painter that will do the painting. GeoPainter geoPainter( paintDevice, d->m_map.viewport(), d->m_map.mapQuality() ); d->m_map.paint( geoPainter, evt->rect() ); } if ( !isEnabled() ) { // Draw a grayscale version of the intermediate image QRgb* pixel = reinterpret_cast( image.scanLine( 0 )); for (int i=0; im_showFrameRate ) { QPainter painter( this ); FpsLayer fpsPainter( &t ); fpsPainter.paint( &painter ); const qreal fps = 1000.0 / (qreal)( t.elapsed() + 1 ); emit framesPerSecond( fps ); } } void MarbleWidget::customPaint( GeoPainter *painter ) { Q_UNUSED( painter ); /* This is a NOOP in the base class*/ } void MarbleWidget::goHome( FlyToMode mode ) { d->m_presenter.goHome( mode ); } QString MarbleWidget::mapThemeId() const { return d->m_model.mapThemeId(); } void MarbleWidget::setMapThemeId( const QString& mapThemeId ) { d->m_map.setMapThemeId( mapThemeId ); } void MarbleWidgetPrivate::updateMapTheme() { m_map.removeLayer( m_routingLayer ); m_widget->setRadius( m_widget->radius() ); // Corrects zoom range, if needed if (m_model.planetId() == QLatin1String("earth")) { m_map.addLayer( m_routingLayer ); } emit m_widget->themeChanged( m_map.mapThemeId() ); // Now we want a full repaint as the atmosphere might differ m_widget->setAttribute( Qt::WA_NoSystemBackground, false ); m_widget->update(); } GeoSceneDocument *MarbleWidget::mapTheme() const { return d->m_model.mapTheme(); } void MarbleWidget::setPropertyValue( const QString& name, bool value ) { mDebug() << "In MarbleWidget the property " << name << "was set to " << value; d->m_map.setPropertyValue( name, value ); } void MarbleWidget::setShowOverviewMap( bool visible ) { d->m_map.setShowOverviewMap( visible ); } void MarbleWidget::setShowScaleBar( bool visible ) { d->m_map.setShowScaleBar( visible ); } void MarbleWidget::setShowCompass( bool visible ) { d->m_map.setShowCompass( visible ); } void MarbleWidget::setShowClouds( bool visible ) { d->m_map.setShowClouds( visible ); } void MarbleWidget::setShowSunShading( bool visible ) { d->m_map.setShowSunShading( visible ); } void MarbleWidget::setShowCityLights( bool visible ) { d->m_map.setShowCityLights( visible ); } void MarbleWidget::setLockToSubSolarPoint( bool visible ) { if ( d->m_map.isLockedToSubSolarPoint() != visible ) { // Toggling input modifies event filters, so avoid that if not needed d->m_map.setLockToSubSolarPoint( visible ); setInputEnabled( !d->m_map.isLockedToSubSolarPoint() ); } } void MarbleWidget::setSubSolarPointIconVisible( bool visible ) { if ( d->m_map.isSubSolarPointIconVisible() != visible ) { d->m_map.setSubSolarPointIconVisible( visible ); } QList pluginList = renderPlugins(); QList::const_iterator i = pluginList.constBegin(); QList::const_iterator const end = pluginList.constEnd(); for (; i != end; ++i ) { if ((*i)->nameId() == QLatin1String("sun")) { (*i)->setVisible( visible ); } } } void MarbleWidget::setShowAtmosphere( bool visible ) { d->m_map.setShowAtmosphere( visible ); } void MarbleWidget::setShowCrosshairs( bool visible ) { d->m_map.setShowCrosshairs( visible ); } void MarbleWidget::setShowGrid( bool visible ) { d->m_map.setShowGrid( visible ); } void MarbleWidget::setShowPlaces( bool visible ) { d->m_map.setShowPlaces( visible ); } void MarbleWidget::setShowCities( bool visible ) { d->m_map.setShowCities( visible ); } void MarbleWidget::setShowTerrain( bool visible ) { d->m_map.setShowTerrain( visible ); } void MarbleWidget::setShowOtherPlaces( bool visible ) { d->m_map.setShowOtherPlaces( visible ); } void MarbleWidget::setShowRelief( bool visible ) { d->m_map.setShowRelief( visible ); } void MarbleWidget::setShowIceLayer( bool visible ) { d->m_map.setShowIceLayer( visible ); } void MarbleWidget::setShowBorders( bool visible ) { d->m_map.setShowBorders( visible ); } void MarbleWidget::setShowRivers( bool visible ) { d->m_map.setShowRivers( visible ); } void MarbleWidget::setShowLakes( bool visible ) { d->m_map.setShowLakes( visible ); } void MarbleWidget::setShowFrameRate( bool visible ) { d->m_showFrameRate = visible; update(); } void MarbleWidget::setShowBackground( bool visible ) { d->m_map.setShowBackground( visible ); } void MarbleWidget::setShowRuntimeTrace( bool visible ) { d->m_map.setShowRuntimeTrace( visible ); } bool MarbleWidget::showRuntimeTrace() const { return d->m_map.showRuntimeTrace(); } void MarbleWidget::setShowDebugPolygons( bool visible) { d->m_map.setShowDebugPolygons( visible ); } bool MarbleWidget::showDebugPolygons() const { return d->m_map.showDebugPolygons(); } void MarbleWidget::setShowDebugBatchRender( bool visible) { d->m_map.setShowDebugBatchRender( visible ); } bool MarbleWidget::showDebugBatchRender() const { return d->m_map.showDebugBatchRender(); } void MarbleWidget::setShowDebugPlacemarks( bool visible) { d->m_map.setShowDebugPlacemarks( visible ); } bool MarbleWidget::showDebugPlacemarks() const { return d->m_map.showDebugPlacemarks(); } void MarbleWidget::setDebugLevelTags(bool visible) { d->m_map.setLevelTagDebugModeEnabled(visible); } bool MarbleWidget::debugLevelTags() const { return d->m_map.levelTagDebugModeEnabled(); } void MarbleWidget::setShowTileId( bool visible ) { d->m_map.setShowTileId( visible ); } void MarbleWidget::notifyMouseClick( int x, int y) { qreal lon = 0; qreal lat = 0; bool const valid = geoCoordinates( x, y, lon, lat, GeoDataCoordinates::Radian ); if ( valid ) { emit mouseClickGeoPosition( lon, lat, GeoDataCoordinates::Radian ); } } void MarbleWidget::clearVolatileTileCache() { mDebug() << "About to clear VolatileTileCache"; d->m_map.clearVolatileTileCache(); } void MarbleWidget::setVolatileTileCacheLimit( quint64 kiloBytes ) { d->m_map.setVolatileTileCacheLimit( kiloBytes ); } // This slot will called when the Globe starts to create the tiles. void MarbleWidget::creatingTilesStart( TileCreator *creator, const QString &name, const QString &description ) { QPointer dialog = new TileCreatorDialog( creator, this ); dialog->setSummary( name, description ); dialog->exec(); delete dialog; } MapQuality MarbleWidget::mapQuality( ViewContext viewContext ) const { return d->m_map.mapQuality( viewContext ); } void MarbleWidget::setMapQualityForViewContext( MapQuality quality, ViewContext viewContext ) { d->m_map.setMapQualityForViewContext( quality, viewContext ); } ViewContext MarbleWidget::viewContext() const { return d->m_map.viewContext(); } void MarbleWidget::setViewContext( ViewContext viewContext ) { // Inform routing layer about view context change. If not done, // the routing layer causes severe performance problems when dragging the // map. So either do not remove this line, or keep a similar call in place // when you refactor it and test your changes wrt drag performance at // high zoom level with long routes! d->m_routingLayer->setViewContext( viewContext ); d->m_map.setViewContext( viewContext ); } bool MarbleWidget::animationsEnabled() const { return d->m_presenter.animationsEnabled(); } void MarbleWidget::setAnimationsEnabled( bool enabled ) { d->m_presenter.setAnimationsEnabled( enabled ); } AngleUnit MarbleWidget::defaultAngleUnit() const { return d->m_map.defaultAngleUnit(); } void MarbleWidget::setDefaultAngleUnit( AngleUnit angleUnit ) { d->m_map.setDefaultAngleUnit( angleUnit ); } QFont MarbleWidget::defaultFont() const { return d->m_map.defaultFont(); } void MarbleWidget::setDefaultFont( const QFont& font ) { d->m_map.setDefaultFont( font ); } void MarbleWidget::setSelection( const QRect& region ) { d->m_presenter.setSelection( region ); } qreal MarbleWidget::distance() const { return d->m_presenter.distance(); } void MarbleWidget::setDistance( qreal newDistance ) { d->m_presenter.setDistance( newDistance ); } QString MarbleWidget::distanceString() const { return d->m_presenter.distanceString(); } void MarbleWidget::setInputEnabled( bool enabled ) { //if input is set as enabled if ( enabled ) { if ( !d->m_inputhandler ) { d->setInputHandler(); } else { installEventFilter( d->m_inputhandler ); } } else // input is disabled { mDebug() << "MarbleWidget::disableInput"; removeEventFilter( d->m_inputhandler ); setCursor( Qt::ArrowCursor ); } } QList MarbleWidget::renderPlugins() const { return d->m_map.renderPlugins(); } void MarbleWidget::readPluginSettings( QSettings& settings ) { for( RenderPlugin *plugin: renderPlugins() ) { settings.beginGroup(QLatin1String("plugin_") + plugin->nameId()); QHash hash; for ( const QString& key: settings.childKeys() ) { hash.insert( key, settings.value( key ) ); } plugin->setSettings( hash ); settings.endGroup(); } } void MarbleWidget::writePluginSettings( QSettings& settings ) const { for( RenderPlugin *plugin: renderPlugins() ) { settings.beginGroup(QLatin1String("plugin_") + plugin->nameId()); QHash hash = plugin->settings(); QHash::iterator it = hash.begin(); while( it != hash.end() ) { settings.setValue( it.key(), it.value() ); ++it; } settings.endGroup(); } } QList MarbleWidget::floatItems() const { return d->m_map.floatItems(); } AbstractFloatItem * MarbleWidget::floatItem( const QString &nameId ) const { return d->m_map.floatItem( nameId ); } void MarbleWidget::changeEvent( QEvent * event ) { if ( event->type() == QEvent::EnabledChange ) { setInputEnabled(isEnabled()); } QWidget::changeEvent(event); } void MarbleWidget::flyTo( const GeoDataLookAt &newLookAt, FlyToMode mode ) { d->m_presenter.flyTo( newLookAt, mode ); } void MarbleWidget::reloadMap() { d->m_map.reload(); } void MarbleWidget::downloadRegion( QVector const & pyramid ) { d->m_map.downloadRegion( pyramid ); } GeoDataLookAt MarbleWidget::lookAt() const { return d->m_presenter.lookAt(); } GeoDataCoordinates MarbleWidget::focusPoint() const { return d->m_map.viewport()->focusPoint(); } void MarbleWidget::setFocusPoint( const GeoDataCoordinates &focusPoint ) { d->m_map.viewport()->setFocusPoint( focusPoint ); } void MarbleWidget::resetFocusPoint() { d->m_map.viewport()->resetFocusPoint(); } qreal MarbleWidget::radiusFromDistance( qreal distance ) const { return d->m_presenter.radiusFromDistance( distance ); } qreal MarbleWidget::distanceFromRadius( qreal radius ) const { return d->m_presenter.distanceFromRadius( radius ); } qreal MarbleWidget::zoomFromDistance( qreal distance ) const { return d->m_presenter.zoomFromDistance( distance ); } qreal MarbleWidget::distanceFromZoom( qreal zoom ) const { return d->m_presenter.distanceFromZoom( zoom ); } RoutingLayer* MarbleWidget::routingLayer() { return d->m_routingLayer; } PopupLayer *MarbleWidget::popupLayer() { return d->m_mapInfoDialog; } const StyleBuilder* MarbleWidget::styleBuilder() const { return d->m_map.styleBuilder(); } void MarbleWidget::setHeading( qreal heading ) { d->m_map.setHeading( heading ); } qreal MarbleWidget::heading() const { return d->m_map.heading(); } void MarbleWidget::setLevelToDebug(int level) { d->m_map.setDebugLevelTag(level); } int MarbleWidget::levelToDebug() const { return d->m_map.debugLevelTag(); } } #include "moc_MarbleWidget.cpp" diff --git a/src/lib/marble/MarbleWidget.h b/src/lib/marble/MarbleWidget.h index 2044ddcce..91ca60bfe 100644 --- a/src/lib/marble/MarbleWidget.h +++ b/src/lib/marble/MarbleWidget.h @@ -1,1173 +1,1174 @@ // // 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. // // Copyright 2006-2008 Torsten Rahn // Copyright 2007 Inge Wallin // #ifndef MARBLE_MARBLEWIDGET_H #define MARBLE_MARBLEWIDGET_H /** @file * This file contains the headers for MarbleWidget. * * @author Torsten Rahn * @author Inge Wallin */ #include #include "GeoDataCoordinates.h" #include "MarbleGlobal.h" // types needed in all of marble. #include "marble_export.h" // Qt class QSettings; class QPixmap; namespace Marble { class AbstractDataPluginItem; class AbstractFloatItem; class GeoDataLatLonAltBox; class GeoDataLatLonBox; class GeoDataFeature; class GeoDataPlacemark; class GeoDataLookAt; class GeoPainter; class GeoSceneDocument; class LayerInterface; class MarbleModel; class MarbleWidgetPopupMenu; class MarbleWidgetInputHandler; class MarbleWidgetPrivate; class RenderPlugin; class RenderState; class RoutingLayer; class TextureLayer; class TileCoordsPyramid; class TileCreator; class ViewportParams; class PopupLayer; class StyleBuilder; /** * @short A widget class that displays a view of the earth. * * This widget displays a view of the earth or any other globe, * depending on which dataset is used. The user can navigate the * globe using either a control widget, e.g. the MarbleNavigator, or * the mouse. The mouse and keyboard control is done through a * MarbleWidgetInputHandler. Only some aspects of the widget can be * controlled by the mouse and/or keyboard. * * By clicking on the globe and moving the mouse, the position can be * changed. The user can also zoom by using the scroll wheel of the * mouse in the widget. The zoom value is not tied to any units, but * is an abstract value without any physical meaning. A value around * 1000 shows the full globe in a normal-sized window. Higher zoom * values give a more zoomed-in view. * * The MarbleWidget owns a data model to work. This model is contained * in the MarbleModel class, and it is painted by using a MarbleMap. * The widget takes care of creating the map and model. A MarbleModel * contains several datatypes, among them tiles which provide the * background, vectors which provide things like country * borders and coastlines and placemarks which can show points * of interest, such as cities, mountain tops or the poles. * * In addition to navigating with the mouse, you can also use it to * get information about items on the map. You can either click on a * placemark with the left mouse button or with the right mouse button * anywhere on the map. * * The left mouse button opens up a menu with all the placemarks * within a certain distance from the mouse pointer. When you choose * one item from the menu, Marble will open up a dialog window with * some information about the placemark and also try to connect to * Wikipedia to retrieve an article about it. If there is such an * article, you will get a mini-browser window with the article in a tab. * * @see MarbleNavigator * @see MarbleMap * @see MarbleModel */ class MARBLE_EXPORT MarbleWidget : public QWidget { Q_OBJECT #ifdef MARBLE_DBUS Q_CLASSINFO("D-Bus Interface", "org.kde.MarbleWidget") #endif Q_PROPERTY(int zoom READ zoom WRITE setZoom) Q_PROPERTY(QString mapThemeId READ mapThemeId WRITE setMapThemeId) Q_PROPERTY(int projection READ projection WRITE setProjection) Q_PROPERTY(qreal longitude READ centerLongitude WRITE setCenterLongitude) Q_PROPERTY(qreal latitude READ centerLatitude WRITE setCenterLatitude) Q_PROPERTY(bool showOverviewMap READ showOverviewMap WRITE setShowOverviewMap) Q_PROPERTY(bool showScaleBar READ showScaleBar WRITE setShowScaleBar) Q_PROPERTY(bool showCompass READ showCompass WRITE setShowCompass) Q_PROPERTY(bool showGrid READ showGrid WRITE setShowGrid) Q_PROPERTY(bool showClouds READ showClouds WRITE setShowClouds) Q_PROPERTY(bool showSunShading READ showSunShading WRITE setShowSunShading) Q_PROPERTY(bool showCityLights READ showCityLights WRITE setShowCityLights) Q_PROPERTY(bool isLockedToSubSolarPoint READ isLockedToSubSolarPoint WRITE setLockToSubSolarPoint) Q_PROPERTY(bool isSubSolarPointIconVisible READ isSubSolarPointIconVisible WRITE setSubSolarPointIconVisible) Q_PROPERTY(bool showAtmosphere READ showAtmosphere WRITE setShowAtmosphere) Q_PROPERTY(bool showCrosshairs READ showCrosshairs WRITE setShowCrosshairs) Q_PROPERTY(bool showPlaces READ showPlaces WRITE setShowPlaces) Q_PROPERTY(bool showCities READ showCities WRITE setShowCities) Q_PROPERTY(bool showTerrain READ showTerrain WRITE setShowTerrain) Q_PROPERTY(bool showOtherPlaces READ showOtherPlaces WRITE setShowOtherPlaces) Q_PROPERTY(bool showRelief READ showRelief WRITE setShowRelief) Q_PROPERTY(bool showIceLayer READ showIceLayer WRITE setShowIceLayer) Q_PROPERTY(bool showBorders READ showBorders WRITE setShowBorders) Q_PROPERTY(bool showRivers READ showRivers WRITE setShowRivers) Q_PROPERTY(bool showLakes READ showLakes WRITE setShowLakes) Q_PROPERTY(ViewContext viewContext READ viewContext WRITE setViewContext NOTIFY viewContextChanged) Q_PROPERTY( RenderStatus renderStatus READ renderStatus NOTIFY renderStatusChanged ) Q_PROPERTY(quint64 volatileTileCacheLimit READ volatileTileCacheLimit WRITE setVolatileTileCacheLimit) public: /** * @brief Construct a new MarbleWidget. * @param parent the parent widget * * This constructor should be used when you will only use one * MarbleWidget. The widget will create its own MarbleModel when * created. */ explicit MarbleWidget( QWidget *parent = 0 ); ~MarbleWidget() override; /// @name Access to helper objects //@{ /** * @brief Return the model that this view shows. */ MarbleModel *model(); const MarbleModel *model() const; ViewportParams *viewport(); const ViewportParams *viewport() const; MarbleWidgetPopupMenu *popupMenu(); /** * Returns the current input handler */ MarbleWidgetInputHandler *inputHandler() const; /** * @brief Set the input handler */ void setInputHandler( MarbleWidgetInputHandler *handler ); /** * @brief Returns a list of all RenderPlugins on the widget, this includes float items * @return the list of RenderPlugins */ QList renderPlugins() const; /** * @brief Returns a list of all FloatItems on the widget * @return the list of the floatItems */ QList floatItems() const; /** * @brief Returns the FloatItem with the given id * @return The pointer to the requested floatItem, * * If no item is found the null pointer is returned. */ AbstractFloatItem * floatItem( const QString &nameId ) const; /** * Reads the plugin settings from the passed QSettings. * You shouldn't use this in a KDE application as these use KConfig. Here you could * use MarblePart which is handling this automatically. * @param settings The QSettings object to be used. */ void readPluginSettings( QSettings& settings ); /** * Writes the plugin settings in the passed QSettings. * You shouldn't use this in a KDE application as these use KConfig. Here you could * use MarblePart which is handling this automatically. * @param settings The QSettings object to be used. */ void writePluginSettings( QSettings& settings ) const; /** * @brief Retrieve the view context (i.e. still or animated map) */ ViewContext viewContext() const; /** * @brief Get the GeoSceneDocument object of the current map theme */ GeoSceneDocument * mapTheme() const; /** * @brief Returns all widgets of dataPlugins on the position curpos */ QList whichItemAt( const QPoint& curpos ) const; /** * @brief Add a layer to be included in rendering. */ void addLayer( LayerInterface *layer ); /** * @brief Remove a layer from being included in rendering. */ void removeLayer( LayerInterface *layer ); RoutingLayer* routingLayer(); PopupLayer* popupLayer(); /** * @since 0.26.0 */ const StyleBuilder* styleBuilder() const; /** * @brief Get the Projection used for the map * @return @c Spherical a Globe * @return @c Equirectangular a flat map * @return @c Mercator another flat map */ Projection projection() const; // int projection() const; //@} /// @name Visible map area //@{ /** * @brief Get the ID of the current map theme * To ensure that a unique identifier is being used the theme does NOT * get represented by its name but the by relative location of the file * that specifies the theme: * * Example: * mapThemeId = "earth/bluemarble/bluemarble.dgml" */ QString mapThemeId() const; /** * @brief Return the projected region which describes the (shape of the) projected surface. */ QRegion mapRegion() const; /** * @brief Return the radius of the globe in pixels. */ int radius() const; /** * @brief Return the current zoom amount. */ int zoom() const; int tileZoomLevel() const; /** * @brief Return the current distance. */ qreal distance() const; /** * @brief Return the current distance string. */ QString distanceString() const; /** * @brief Return the minimum zoom value for the current map theme. */ int minimumZoom() const; /** * @brief Return the minimum zoom value for the current map theme. */ int maximumZoom() const; //@} /// @name Position management //@{ /** * @brief Get the screen coordinates corresponding to geographical coordinates in the widget. * @param lon the lon coordinate of the requested pixel position * @param lat the lat coordinate of the requested pixel position * @param x the x coordinate of the pixel is returned through this parameter * @param y the y coordinate of the pixel is returned through this parameter * @return @c true if the geographical coordinates are visible on the screen * @c false if the geographical coordinates are not visible on the screen */ bool screenCoordinates( qreal lon, qreal lat, qreal& x, qreal& y ) const; /** * @brief Get the earth coordinates corresponding to a pixel in the widget. * @param x the x coordinate of the pixel * @param y the y coordinate of the pixel * @param lon the longitude angle is returned through this parameter * @param lat the latitude angle is returned through this parameter * @return @c true if the pixel (x, y) is within the globe * @c false if the pixel (x, y) is outside the globe, i.e. in space. */ bool geoCoordinates( int x, int y, qreal& lon, qreal& lat, GeoDataCoordinates::Unit = GeoDataCoordinates::Degree ) const; /** * @brief Return the longitude of the center point. * @return The longitude of the center point in degree. */ qreal centerLongitude() const; /** * @brief Return the latitude of the center point. * @return The latitude of the center point in degree. */ qreal centerLatitude() const; qreal heading() const; /** * @brief Return how much the map will move if one of the move slots are called. * @return The move step. */ qreal moveStep() const; /** * @brief Return the lookAt */ GeoDataLookAt lookAt() const; /** * @return The current point of focus, e.g. the point that is not moved * when changing the zoom level. If not set, it defaults to the * center point. * @see centerLongitude centerLatitude setFocusPoint resetFocusPoint */ GeoDataCoordinates focusPoint() const; /** * @brief Change the point of focus, overridding any previously set focus point. * @param focusPoint New focus point * @see focusPoint resetFocusPoint */ void setFocusPoint( const GeoDataCoordinates &focusPoint ); /** * @brief Invalidate any focus point set with @ref setFocusPoint. * @see focusPoint setFocusPoint */ void resetFocusPoint(); /** * @brief Return the globe radius (pixel) for the given distance (km) */ qreal radiusFromDistance( qreal distance ) const; /** * @brief Return the distance (km) at the given globe radius (pixel) */ qreal distanceFromRadius( qreal radius ) const; /** * Returns the zoom value (no unit) corresponding to the given camera distance (km) */ qreal zoomFromDistance( qreal distance ) const; /** * Returns the distance (km) corresponding to the given zoom value */ qreal distanceFromZoom( qreal zoom ) const; //@} /// @name Placemark management //@{ QVector whichFeatureAt( const QPoint& ) const; //@} /// @name Float items and map appearance //@{ /** * @brief Return whether the overview map is visible. * @return The overview map visibility. */ bool showOverviewMap() const; /** * @brief Return whether the scale bar is visible. * @return The scale bar visibility. */ bool showScaleBar() const; /** * @brief Return whether the compass bar is visible. * @return The compass visibility. */ bool showCompass() const; /** * @brief Return whether the cloud cover is visible. * @return The cloud cover visibility. */ bool showClouds() const; /** * @brief Return whether the night shadow is visible. * @return visibility of night shadow */ bool showSunShading() const; /** * @brief Return whether the city lights are shown instead of the night shadow. * @return visibility of city lights */ bool showCityLights() const; /** * @brief Return whether the globe is locked to the sub solar point * @return if globe is locked to sub solar point */ bool isLockedToSubSolarPoint() const; /** * @brief Return whether the sun icon is shown in the sub solar point. * @return visibility of the sun icon in the sub solar point */ bool isSubSolarPointIconVisible() const; /** * @brief Return whether the atmospheric glow is visible. * @return The cloud cover visibility. */ bool showAtmosphere() const; /** * @brief Return whether the crosshairs are visible. * @return The crosshairs' visibility. */ bool showCrosshairs() const; /** * @brief Return whether the coordinate grid is visible. * @return The coordinate grid visibility. */ bool showGrid() const; /** * @brief Return whether the place marks are visible. * @return The place mark visibility. */ bool showPlaces() const; /** * @brief Return whether the city place marks are visible. * @return The city place mark visibility. */ bool showCities() const; /** * @brief Return whether the terrain place marks are visible. * @return The terrain place mark visibility. */ bool showTerrain() const; /** * @brief Return whether other places are visible. * @return The visibility of other places. */ bool showOtherPlaces() const; /** * @brief Return whether the relief is visible. * @return The relief visibility. */ bool showRelief() const; /** * @brief Return whether the ice layer is visible. * @return The ice layer visibility. */ bool showIceLayer() const; /** * @brief Return whether the borders are visible. * @return The border visibility. */ bool showBorders() const; /** * @brief Return whether the rivers are visible. * @return The rivers' visibility. */ bool showRivers() const; /** * @brief Return whether the lakes are visible. * @return The lakes' visibility. */ bool showLakes() const; /** * @brief Return whether the frame rate gets displayed. * @return the frame rates visibility */ bool showFrameRate() const; bool showBackground() const; /** * @brief Retrieve the map quality depending on the view context */ MapQuality mapQuality( ViewContext = Still ) const; /** * @brief Retrieve whether travels to a point should get animated */ bool animationsEnabled() const; AngleUnit defaultAngleUnit() const; void setDefaultAngleUnit( AngleUnit angleUnit ); QFont defaultFont() const; void setDefaultFont( const QFont& font ); //@} /// @name Tile management //@{ /** * @brief Returns the limit in kilobytes of the volatile (in RAM) tile cache. * @return the limit of volatile tile cache */ quint64 volatileTileCacheLimit() const; //@} /// @name Miscellaneous //@{ /** * @brief Return a QPixmap with the current contents of the widget. */ QPixmap mapScreenShot(); //@} /// @todo Enable this instead of the zoomView slot below for proper deprecation warnings /// around Marble 1.8 // @deprecated Please use setZoom //MARBLE_DEPRECATED( void zoomView( int zoom, FlyToMode mode = Instant ) ); /** * Summarized render status of the current map view * @see renderState */ RenderStatus renderStatus() const; /** * Detailed render status of the current map view */ RenderState renderState() const; /** * Toggle whether regions are highlighted when user selects them */ void setHighlightEnabled( bool enabled ); public Q_SLOTS: /// @name Position management slots //@{ /** * @brief Set the radius of the globe in pixels. * @param radius The new globe radius value in pixels. */ void setRadius( int radius ); /** * @brief Zoom the view to a certain zoomlevel * @param zoom the new zoom level. * * The zoom level is an abstract value without physical * interpretation. A zoom value around 1000 lets the viewer see * all of the earth in the default window. */ void setZoom( int zoom, FlyToMode mode = Instant ); /** * @deprecated To be removed soon. Please use setZoom instead. Same parameters. */ void zoomView( int zoom, FlyToMode mode = Instant ); /** * @brief Zoom the view by a certain step * @param zoomStep the difference between the old zoom and the new */ void zoomViewBy( int zoomStep, FlyToMode mode = Instant ); /** * @brief Zoom in by the amount zoomStep. */ void zoomIn( FlyToMode mode = Automatic ); /** * @brief Zoom out by the amount zoomStep. */ void zoomOut( FlyToMode mode = Automatic ); /** * @brief Set the distance of the observer to the globe in km. * @param distance The new distance in km. */ void setDistance( qreal distance ); /** * @brief Rotate the view by the two angles phi and theta. * @param deltaLon an angle that specifies the change in terms of longitude * @param deltaLat an angle that specifies the change in terms of latitude * * This function rotates the view by two angles, * deltaLon ("theta") and deltaLat ("phi"). * If we start at (0, 0), the result will be the exact equivalent * of (lon, lat), otherwise the resulting angle will be the sum of * the previous position and the two offsets. */ void rotateBy( const qreal deltaLon, const qreal deltaLat, FlyToMode mode = Instant ); /** * @brief Center the view on a geographical point * @param lat an angle in degrees parallel to the latitude lines * +90(N) - -90(S) * @param lon an angle in degrees parallel to the longitude lines * +180(W) - -180(E) */ void centerOn( const qreal lon, const qreal lat, bool animated = false ); /** * @brief Center the view on a point * This method centers the Marble map on the point described by the latitude * and longitude in the GeoDataCoordinate parameter @c point. It also zooms * the map to be at the elevation described by the altitude. If this is * not the desired functionality or you do not have an accurate altitude * then use @see centerOn(qreal, qreal, bool) * @param point the point in 3 dimensions above the globe to move the view * to. It will always be looking vertically down. */ void centerOn( const GeoDataCoordinates &point, bool animated = false ); /** * @brief Center the view on a bounding box so that it completely fills the viewport * This method not only centers on the center of the GeoDataLatLon box but it also * adjusts the zoom of the marble widget so that the LatLon box provided fills * the viewport. * @param box The GeoDataLatLonBox to zoom and move the MarbleWidget to. */ void centerOn( const GeoDataLatLonBox& box, bool animated = false ); /** * @brief Center the view on a placemark according to the following logic: * - if the placemark has a lookAt, zoom and center on that lookAt * - otherwise use the placemark geometry's latLonAltBox * @param box The GeoDataPlacemark to zoom and move the MarbleWidget to. */ void centerOn( const GeoDataPlacemark& placemark, bool animated = false ); /** * @brief Set the latitude for the center point * @param lat the new value for the latitude in degree. * @param mode the FlyToMode that will be used. */ void setCenterLatitude( qreal lat, FlyToMode mode = Instant ); /** * @brief Set the longitude for the center point * @param lon the new value for the longitude in degree. * @param mode the FlyToMode that will be used. */ void setCenterLongitude( qreal lon, FlyToMode mode = Instant ); void setHeading( qreal heading ); /** * @brief Move left by the moveStep. */ void moveLeft( FlyToMode mode = Automatic ); /** * @brief Move right by the moveStep. */ void moveRight( FlyToMode mode = Automatic ); /** * @brief Move up by the moveStep. */ void moveUp( FlyToMode mode = Automatic ); /** * @brief Move down by the moveStep. */ void moveDown( FlyToMode mode = Automatic ); /** * @brief Center the view on the default start point with the default zoom. */ void goHome( FlyToMode mode = Automatic ); /** * @brief Change the camera position to the given position. * @param lookAt New camera position. Changing the camera position means * that both the current center position as well as the zoom value may change * @param mode Interpolation type for intermediate camera positions. Automatic * (default) chooses a suitable interpolation among Instant, Lenar and Jump. * Instant will directly set the new zoom and position values, while * Linear results in a linear interpolation of intermediate center coordinates * along the sphere and a linear interpolation of changes in the camera distance * to the ground. Finally, Jump will behave the same as Linear with regard to * the center position interpolation, but use a parabolic height increase * towards the middle point of the intermediate positions. This appears * like a jump of the camera. */ void flyTo( const GeoDataLookAt &lookAt, FlyToMode mode = Automatic ); //@} /// @name Float items and map appearance slots //@{ /** * @brief Set the Projection used for the map * @param projection projection type (e.g. Spherical, Equirectangular, Mercator) */ void setProjection( int projection ); void setProjection( Projection projection ); /** * @brief Set a new map theme * @param maptheme The ID of the new maptheme. To ensure that a unique * identifier is being used the theme does NOT get represented by its * name but the by relative location of the file that specifies the theme: * * Example: * maptheme = "earth/bluemarble/bluemarble.dgml" */ void setMapThemeId( const QString& maptheme ); /** * @brief Sets the value of a map theme property * @param value value of the property (usually: visibility) * * Later on we might add a "setPropertyType and a QVariant * if needed. */ void setPropertyValue( const QString& name, bool value ); /** * @brief Set whether the overview map overlay is visible * @param visible visibility of the overview map */ void setShowOverviewMap( bool visible ); /** * @brief Set whether the scale bar overlay is visible * @param visible visibility of the scale bar */ void setShowScaleBar( bool visible ); /** * @brief Set whether the compass overlay is visible * @param visible visibility of the compass */ void setShowCompass( bool visible ); /** * @brief Set whether the cloud cover is visible * @param visible visibility of the cloud cover */ void setShowClouds( bool visible ); /** * @brief Set whether the night shadow is visible. * @param visibile visibility of shadow */ void setShowSunShading( bool visible ); /** * @brief Set whether city lights instead of night shadow are visible. * @param visible visibility of city lights */ void setShowCityLights( bool visible ); /** * @brief Set the globe locked to the sub solar point * @param vsible if globe is locked to the sub solar point */ void setLockToSubSolarPoint( bool visible ); /** * @brief Set whether the sun icon is shown in the sub solar point * @param visible if the sun icon is shown in the sub solar point */ void setSubSolarPointIconVisible( bool visible ); /** * @brief Set whether the atmospheric glow is visible * @param visible visibility of the atmospheric glow */ void setShowAtmosphere( bool visible ); /** * @brief Set whether the crosshairs are visible * @param visible visibility of the crosshairs */ void setShowCrosshairs( bool visible ); /** * @brief Set whether the coordinate grid overlay is visible * @param visible visibility of the coordinate grid */ void setShowGrid( bool visible ); /** * @brief Set whether the place mark overlay is visible * @param visible visibility of the place marks */ void setShowPlaces( bool visible ); /** * @brief Set whether the city place mark overlay is visible * @param visible visibility of the city place marks */ void setShowCities( bool visible ); /** * @brief Set whether the terrain place mark overlay is visible * @param visible visibility of the terrain place marks */ void setShowTerrain( bool visible ); /** * @brief Set whether the other places overlay is visible * @param visible visibility of other places */ void setShowOtherPlaces( bool visible ); /** * @brief Set whether the relief is visible * @param visible visibility of the relief */ void setShowRelief( bool visible ); /** * @brief Set whether the ice layer is visible * @param visible visibility of the ice layer */ void setShowIceLayer( bool visible ); /** * @brief Set whether the borders visible * @param visible visibility of the borders */ void setShowBorders( bool visible ); /** * @brief Set whether the rivers are visible * @param visible visibility of the rivers */ void setShowRivers( bool visible ); /** * @brief Set whether the lakes are visible * @param visible visibility of the lakes */ void setShowLakes( bool visible ); /** * @brief Set whether the frame rate gets shown * @param visible visibility of the frame rate */ void setShowFrameRate( bool visible ); void setShowBackground( bool visible ); /** * @brief Set whether the is tile is visible * NOTE: This is part of the transitional debug API * and might be subject to changes until Marble 0.8 * @param visible visibility of the tile */ void setShowTileId( bool visible ); /** * @brief Set whether the runtime tracing for layers gets shown * @param visible visibility of the runtime tracing */ void setShowRuntimeTrace( bool visible ); bool showRuntimeTrace() const; /** * @brief Set whether to enter the debug mode for * polygon node drawing * @param visible visibility of the node debug mode */ void setShowDebugPolygons( bool visible); bool showDebugPolygons() const; /** * @brief Set whether to enter the debug mode for * batch rendering * @param visible visibility of the batch rendering */ void setShowDebugBatchRender( bool visible); bool showDebugBatchRender() const; /** * @brief Set whether to enter the debug mode for * placemark drawing * @param visible visibility of the node debug mode */ void setShowDebugPlacemarks(bool visible); bool showDebugPlacemarks() const; /** * @brief Set whether to render according to OSM indoor level tags * @param visible visibility of entities (placemarks, buildings etc.) level-wise */ void setDebugLevelTags(bool visible); bool debugLevelTags() const; /** * @brief Set the level to debug * @param level the level to debug */ void setLevelToDebug(int level); int levelToDebug() const; /** * @brief Set the map quality for the specified view context. * * @param quality map quality for the specified view context * @param viewContext view context whose map quality should be set */ void setMapQualityForViewContext( MapQuality quality, ViewContext viewContext ); /** * @brief Set the view context (i.e. still or animated map) */ void setViewContext( ViewContext viewContext ); /** * @brief Set whether travels to a point should get animated */ void setAnimationsEnabled( bool enabled ); //@} /// @name Tile management slots //@{ void clearVolatileTileCache(); /** * @brief Set the limit of the volatile (in RAM) tile cache. * @param kilobytes The limit in kilobytes. */ void setVolatileTileCacheLimit( quint64 kiloBytes ); /** * @brief A slot that is called when the model starts to create new tiles. * @param creator the tile creator object. * @param name the name of the created theme. * @param description a descriptive text that can be shown in a dialog. * @see creatingTilesProgress * * This function is connected to the models signal with the same * name. When the model needs to create a cache of tiles in * several different resolutions, it will emit creatingTilesStart * once with a name of the theme and a descriptive text. The * widget can then pop up a dialog to explain why there is a * delay. The model will then call creatingTilesProgress several * times until the parameter reaches 100 (100%), after which the * creation process is finished. After this there will be no more * calls to creatingTilesProgress, and the poup dialog can then be * closed. */ void creatingTilesStart( TileCreator *creator, const QString& name, const QString& description ); /** * @brief Re-download all visible tiles. */ void reloadMap(); void downloadRegion( QVector const & ); //@} /// @name Miscellaneous slots //@{ /** * @brief Used to notify about the position of the mouse click */ void notifyMouseClick( int x, int y ); void setSelection( const QRect& region ); void setInputEnabled( bool ); TextureLayer *textureLayer() const; //@} Q_SIGNALS: /** * @brief Signal that the zoom has changed, and to what. * @param zoom The new zoom value. * @see setZoom() */ void zoomChanged( int zoom ); void distanceChanged( const QString& distanceString ); void tileLevelChanged( int level ); void viewContextChanged(ViewContext newViewContext); /** * @brief Signal that the theme has changed * @param theme Name of the new theme. */ void themeChanged( const QString& theme ); void projectionChanged( Projection ); void mouseMoveGeoPosition( const QString& ); void mouseClickGeoPosition( qreal lon, qreal lat, GeoDataCoordinates::Unit ); void framesPerSecond( qreal fps ); - /** This signal is emit when a new rectangle region is selected over the map - * The list of double values include coordinates in degrees using this order: - * lon1, lat1, lon2, lat2 (or West, North, East, South) as left/top, right/bottom rectangle. + /** + * This signal is emit when a new rectangle region is selected over the map. + * + * @param boundingBox The geographical coordinates of the selected region */ - void regionSelected( const QList& ); + void regionSelected(const GeoDataLatLonBox &boundingBox); /** * This signal is emit when the settings of a plugin changed. */ void pluginSettingsChanged(); /** * @brief Signal that a render item has been initialized */ void renderPluginInitialized( RenderPlugin *renderPlugin ); /** * This signal is emitted when the visible region of the map changes. This typically happens * when the user moves the map around or zooms. */ void visibleLatLonAltBoxChanged( const GeoDataLatLonAltBox& visibleLatLonAltBox ); /** * @brief Emitted when the layer rendering status has changed * @param status New render status */ void renderStatusChanged( RenderStatus status ); void renderStateChanged( const RenderState &state ); void highlightedPlacemarksChanged( qreal lon, qreal lat, GeoDataCoordinates::Unit unit ); protected: /** * @brief Reimplementation of the leaveEvent() function in QWidget. */ void leaveEvent( QEvent *event ) override; /** * @brief Reimplementation of the paintEvent() function in QWidget. */ void paintEvent( QPaintEvent *event ) override; /** * @brief Reimplementation of the resizeEvent() function in QWidget. */ void resizeEvent( QResizeEvent *event ) override; void connectNotify(const QMetaMethod &signal) override; void disconnectNotify(const QMetaMethod &signal) override; /** * @brief Reimplementation of the changeEvent() function in QWidget to * react to changes of the enabled state */ void changeEvent( QEvent * event ) override; /** * @brief Enables custom drawing onto the MarbleWidget straight after * @brief the globe and before all other layers has been rendered. * @param painter * * @deprecated implement LayerInterface and add it using @p addLayer() */ virtual void customPaint( GeoPainter *painter ); private: Q_PRIVATE_SLOT( d, void updateMapTheme() ) Q_PRIVATE_SLOT( d, void updateSystemBackgroundAttribute() ) private: Q_DISABLE_COPY( MarbleWidget ) MarbleWidgetPrivate * const d; friend class MarbleWidgetPrivate; class CustomPaintLayer; friend class CustomPaintLayer; friend class MarbleWidgetDefaultInputHandler; }; } #endif