MarbleDBusInterface.cpp 3.12 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
#include "MarbleDBusInterface.h"

#include "MarbleWidget.h"
#include "MarbleModel.h"
#include "MapThemeManager.h"
#include <GeoSceneDocument.h>
#include <GeoSceneSettings.h>
#include <GeoSceneProperty.h>

namespace Marble
{

class MarbleDBusInterface::Private
{
public:
    Private( MarbleWidget* widget );

    MarbleWidget* m_marbleWidget;
    QPointF m_currentCenter;
};

MarbleDBusInterface::Private::Private( MarbleWidget *widget ) :
    m_marbleWidget( widget )
{
    // nothing to do
}

MarbleDBusInterface::MarbleDBusInterface( MarbleWidget* widget ) :
    QDBusAbstractAdaptor( widget ),
    d( new Private( widget ) )
{
    connect( widget, SIGNAL(themeChanged(QString)), this, SIGNAL(mapThemeChanged(QString)) );
    connect( widget, SIGNAL(tileLevelChanged(int)), this, SIGNAL(tileLevelChanged(int)) );
    connect( widget, SIGNAL(zoomChanged(int)), this, SIGNAL(zoomChanged(int)) );
    connect( widget, SIGNAL(visibleLatLonAltBoxChanged(GeoDataLatLonAltBox)),
             this, SLOT(handleVisibleLatLonAltBoxChange()) );
}

MarbleDBusInterface::~MarbleDBusInterface()
{
    // nothing to do
    // (an explicit destructor is required by QScopePointer)
}

QString MarbleDBusInterface::mapTheme() const
{
    return d->m_marbleWidget->mapThemeId();
}

QStringList MarbleDBusInterface::mapThemes() const
{
    MapThemeManager mapThemeManager;
    return mapThemeManager.mapThemeIds();
}

int MarbleDBusInterface::tileLevel() const
{
    return d->m_marbleWidget->tileZoomLevel();
}

int MarbleDBusInterface::zoom() const
{
    return d->m_marbleWidget->zoom();
}

QPointF MarbleDBusInterface::center() const
{
    return d->m_currentCenter;
}

void MarbleDBusInterface::setMapTheme( const QString &mapTheme )
{
    d->m_marbleWidget->setMapThemeId( mapTheme );
}

void MarbleDBusInterface::setZoom(int zoom)
{
    d->m_marbleWidget->setZoom(zoom);
}

void MarbleDBusInterface::setPropertyEnabled(const QString &key, bool enabled )
{
    d->m_marbleWidget->setPropertyValue( key, enabled );
}

bool MarbleDBusInterface::isPropertyEnabled( const QString &key ) const
{
    bool value = false;
    GeoSceneDocument const * const mapTheme = d->m_marbleWidget->model()->mapTheme();
    if ( mapTheme ) {
        mapTheme->settings()->propertyValue( key, value );
    }

    return value;
}

QStringList MarbleDBusInterface::properties() const
{
    QStringList properties;
    GeoSceneDocument const * const mapTheme = d->m_marbleWidget->model()->mapTheme();
    if ( mapTheme ) {
        foreach( const GeoSceneProperty* property, mapTheme->settings()->allProperties() ) {
            properties << property->name();
        }
    }
    return properties;
}

void MarbleDBusInterface::setCenter( const QPointF &center ) const
{
    d->m_marbleWidget->centerOn( center.x(), center.y() );
}

void MarbleDBusInterface::handleVisibleLatLonAltBoxChange()
{
    QPointF const newCenter = QPointF( d->m_marbleWidget->centerLongitude(),
                                       d->m_marbleWidget->centerLatitude() );
    if ( newCenter != d->m_currentCenter ) {
        d->m_currentCenter = newCenter;
        emit centerChanged( d->m_currentCenter );
    }
}

}
125 126

#include "MarbleDBusInterface.moc"