SVN commit 793334 by cgilles:
digiKam from trunk : Marble widget integration into right sidebar as new Geolocation of picture! A screenshot of digiKam using Marble can be seen here: http://digikam3rdparty.free.fr/Screenshots/marbleintegrationforphotogeolocation.png CCMAIL: [hidden email] BUG: 138290 M +5 -5 imagepropertiesgpstab.cpp M +2 -2 imagepropertiesgpstab.h M +1 -1 imagepropertiessidebarcamgui.cpp M +2 -1 imagepropertiessidebardb.cpp M +79 -95 worldmapwidget.cpp M +13 -16 worldmapwidget.h --- trunk/extragear/graphics/digikam/libs/imageproperties/imagepropertiesgpstab.cpp #793333:793334 @@ -238,15 +238,15 @@ } DMetadata meta(url.path()); - setMetadata(meta); + setMetadata(meta, url); } -void ImagePropertiesGPSTab::setMetadata(const DMetadata& meta) +void ImagePropertiesGPSTab::setMetadata(const DMetadata& meta, const KUrl& url) { double alt, lat, lon; QDateTime dt = meta.getImageDateTime(); if (meta.getGPSInfo(alt, lat, lon)) - setGPSInfo(lat, lon, alt, dt); + setGPSInfo(lat, lon, alt, dt, url); else setGPSInfo(); } @@ -260,14 +260,14 @@ setEnabled(false); } -void ImagePropertiesGPSTab::setGPSInfo(double lat, double lon, long alt, const QDateTime& dt) +void ImagePropertiesGPSTab::setGPSInfo(double lat, double lon, long alt, const QDateTime& dt, const KUrl& url) { d->altitude->setText(QString("%1 m").arg(QString::number(alt))); d->latitude->setText(QString::number(lat)); d->longitude->setText(QString::number(lon)); d->date->setText(KGlobal::locale()->formatDateTime(dt, KLocale::ShortDate, true)); setEnabled(true); - d->map->setGPSPosition(lat, lon); + d->map->setGPSPosition(lat, lon, alt, dt, url); } } // namespace Digikam --- trunk/extragear/graphics/digikam/libs/imageproperties/imagepropertiesgpstab.h #793333:793334 @@ -64,10 +64,10 @@ ~ImagePropertiesGPSTab(); void setGPSInfo(); - void setGPSInfo(double lat, double lon, long alt, const QDateTime& dt); + void setGPSInfo(double lat, double lon, long alt, const QDateTime& dt, const KUrl& url); void setCurrentURL(const KUrl& url=KUrl()); - void setMetadata(const DMetadata& meta); + void setMetadata(const DMetadata& meta, const KUrl& url); int getWebGPSLocator(); void setWebGPSLocator(int locator); --- trunk/extragear/graphics/digikam/libs/imageproperties/imagepropertiessidebarcamgui.cpp #793333:793334 @@ -179,7 +179,7 @@ } else if (tab == d->gpsTab && !d->dirtyGpsTab) { - d->gpsTab->setMetadata(d->metaData); + d->gpsTab->setMetadata(d->metaData, d->currentURL); d->dirtyGpsTab = true; } --- trunk/extragear/graphics/digikam/libs/imageproperties/imagepropertiessidebardb.cpp #793333:793334 @@ -281,7 +281,8 @@ m_gpsTab->setGPSInfo(pos.latitudeNumber(), pos.longitudeNumber(), pos.altitude(), - d->currentInfos.first().dateTime()); + d->currentInfos.first().dateTime(), + d->currentInfos.first().fileUrl()); m_dirtyGpsTab = true; } } --- trunk/extragear/graphics/digikam/libs/imageproperties/worldmapwidget.cpp #793333:793334 @@ -23,17 +23,16 @@ // Qt includes. -#include <QPainter> -#include <QString> -#include <QPixmap> -#include <QLabel> -#include <QFrame> +#include <QVBoxLayout> +#include <QStyle> +#include <QDomDocument> +#include <QTextStream> +#include <QFile> // KDE includes. -#include <kstandarddirs.h> -#include <kcursor.h> -#include <klocale.h> +#include <ktemporaryfile.h> +#include <marble/MarbleWidget.h> // Local includes. @@ -51,33 +50,39 @@ WorldMapWidgetPriv() { - latitude = 0; - longitude = 0; + latitude = 0; + longitude = 0; + altitude = 0; + marbleWidget = 0; } - int xPos; - int yPos; - int xMousePos; - int yMousePos; + double latitude; + double longitude; + double altitude; - double latitude; - double longitude; -}; + QDateTime dt; -K_GLOBAL_STATIC(QPixmap, worldMap) + KUrl url; + MarbleWidget *marbleWidget; +}; + WorldMapWidget::WorldMapWidget(int w, int h, QWidget *parent) - : Q3ScrollView(parent) + : QFrame(parent) { - d = new WorldMapWidgetPriv; - setAttribute(Qt::WA_DeleteOnClose); - setVScrollBarMode(Q3ScrollView::AlwaysOff); - setHScrollBarMode(Q3ScrollView::AlwaysOff); - viewport()->setMouseTracking(true); setMinimumWidth(w); setMinimumHeight(h); - resizeContents(worldMapPixmap().width(), worldMapPixmap().height()); + setFrameStyle(QFrame::StyledPanel | QFrame::Sunken); + setLineWidth(style()->pixelMetric(QStyle::PM_DefaultFrameWidth)); + + d = new WorldMapWidgetPriv; + d->marbleWidget = new MarbleWidget(this); + + QVBoxLayout *vlay = new QVBoxLayout(this); + vlay->addWidget(d->marbleWidget); + vlay->setMargin(0); + vlay->setSpacing(0); } WorldMapWidget::~WorldMapWidget() @@ -85,100 +90,79 @@ delete d; } -QPixmap &WorldMapWidget::worldMapPixmap() +double WorldMapWidget::getLatitude() { - if (worldMap->isNull()) - { - QString mapPath = KStandardDirs::locate("data", "digikam/data/worldmap.jpg"); - *worldMap = QPixmap(mapPath); - } - return *worldMap; -} - -double WorldMapWidget::getLatitude(void) -{ return d->latitude; } -double WorldMapWidget::getLongitude(void) +double WorldMapWidget::getLongitude() { return d->longitude; } -void WorldMapWidget::setGPSPosition(double lat, double lng) +void WorldMapWidget::setGPSPosition(double lat, double lng, double alt, const QDateTime& dt, const KUrl& url) { d->latitude = lat; d->longitude = lng; + d->altitude = alt; + d->dt = dt; + d->url = url; - double latMid = contentsHeight() / 2.0; - double longMid = contentsWidth() / 2.0; + d->marbleWidget->setHome(lng, lat); + d->marbleWidget->centerOn(lng, lat); - double latOffset = ( d->latitude * latMid ) / 90.0; - double longOffset = ( d->longitude * longMid ) / 180.0; + // NOTE: There is no method currently to place a mark over the map in Marble 0.5.1. + // The only way is to use a temporary KML file with all informations that + // we need. - d->xPos = (int)(longMid + longOffset); - d->yPos = (int)(latMid - latOffset); + QDomDocument kmlDocument; + QDomImplementation impl; + QDomProcessingInstruction instr = kmlDocument.createProcessingInstruction("xml","version=\"1.0\" encoding=\"UTF-8\""); + kmlDocument.appendChild(instr); + QDomElement kmlRoot = kmlDocument.createElementNS( "http://earth.google.com/kml/2.1","kml"); + kmlDocument.appendChild(kmlRoot); - viewport()->repaint(); - center(d->xPos, d->yPos); -} + QDomElement kmlAlbum = addKmlElement(kmlDocument, kmlRoot, "Document"); + QDomElement kmlName = addKmlTextElement(kmlDocument, kmlAlbum, "name", "Geolocation"); + QDomElement kmlPlacemark = addKmlElement(kmlDocument, kmlAlbum, "Placemark"); + addKmlTextElement(kmlDocument, kmlPlacemark, "name", d->url.fileName()); -void WorldMapWidget::drawContents(QPainter *p, int x, int y, int w, int h) -{ - if (isEnabled()) - { - p->drawPixmap(x, y, worldMapPixmap(), x, y, w, h); - p->setPen(QPen(Qt::white, 0, Qt::SolidLine)); - p->drawLine(d->xPos, 0, d->xPos, contentsHeight()); - p->drawLine(0, d->yPos, contentsWidth(), d->yPos); - p->setPen(QPen(Qt::red, 0, Qt::DotLine)); - p->drawLine(d->xPos, 0, d->xPos, contentsHeight()); - p->drawLine(0, d->yPos, contentsWidth(), d->yPos); - p->setPen( Qt::red ); - p->setBrush( Qt::red ); - p->drawEllipse( d->xPos-2, d->yPos-2, 4, 4 ); - } - else - { - p->fillRect(x, y, w, h, palette().color(QPalette::Disabled, QPalette::Background)); - } -} + QDomElement kmlGeometry = addKmlElement(kmlDocument, kmlPlacemark, "Point"); + addKmlTextElement(kmlDocument, kmlGeometry, "coordinates", QString("%1,%2").arg(lng).arg(lat)); + addKmlTextElement(kmlDocument, kmlGeometry, "altitudeMode", "clampToGround"); + addKmlTextElement(kmlDocument, kmlGeometry, "extrude", "1"); -void WorldMapWidget::contentsMousePressEvent(QMouseEvent *e) -{ - if (!e) return; + QDomElement kmlTimeStamp = addKmlElement(kmlDocument, kmlPlacemark, "TimeStamp"); + addKmlTextElement(kmlDocument, kmlTimeStamp, "when", d->dt.toString("yyyy-MM-ddThh:mm:ssZ")); - if (e->button() == Qt::LeftButton) - { - d->xMousePos = e->x(); - d->yMousePos = e->y(); - setCursor( Qt::SizeAllCursor ); - } + KTemporaryFile KMLFile; + KMLFile.setSuffix(".kml"); + KMLFile.setAutoRemove(true); + KMLFile.open(); + QFile file(KMLFile.fileName()); + file.open(QIODevice::WriteOnly); + QTextStream stream(&file); + stream << kmlDocument.toString(); + file.close(); + + DDebug() << KMLFile.fileName() << endl; + d->marbleWidget->addPlaceMarkFile(KMLFile.fileName()); } -void WorldMapWidget::contentsMouseMoveEvent(QMouseEvent *e) +QDomElement WorldMapWidget::addKmlElement(QDomDocument &kmlDocument, QDomElement &target, const QString& tag) { - if (!e) return; - - if (e->buttons() & Qt::LeftButton) - { - uint newxpos = e->x(); - uint newypos = e->y(); - - scrollBy (-(newxpos - d->xMousePos), -(newypos - d->yMousePos)); - viewport()->repaint(); - - d->xMousePos = newxpos - (newxpos-d->xMousePos); - d->yMousePos = newypos - (newypos-d->yMousePos); - return; - } - - setCursor( Qt::PointingHandCursor ); + QDomElement kmlElement = kmlDocument.createElement(tag); + target.appendChild(kmlElement); + return kmlElement; } -void WorldMapWidget::contentsMouseReleaseEvent(QMouseEvent*) +QDomElement WorldMapWidget::addKmlTextElement(QDomDocument &kmlDocument, QDomElement &target, const QString& tag, const QString& text) { - unsetCursor(); + QDomElement kmlElement = kmlDocument.createElement(tag); + target.appendChild(kmlElement); + QDomText kmlTextElement = kmlDocument.createTextNode(text); + kmlElement.appendChild(kmlTextElement); + return kmlElement; } } // namespace Digikam --- trunk/extragear/graphics/digikam/libs/imageproperties/worldmapwidget.h #793333:793334 @@ -26,10 +26,14 @@ // Qt includes. -#include <Q3ScrollView> -#include <QPixmap> -#include <QMouseEvent> +#include <QFrame> +#include <QDateTime> +#include <QDomDocument> +// KDE includes. + +#include <kurl.h> + // Local includes #include "digikam_export.h" @@ -39,7 +43,7 @@ class WorldMapWidgetPriv; -class DIGIKAM_EXPORT WorldMapWidget : public Q3ScrollView +class DIGIKAM_EXPORT WorldMapWidget : public QFrame { Q_OBJECT @@ -48,23 +52,16 @@ WorldMapWidget(int w, int h, QWidget *parent); ~WorldMapWidget(); - void setGPSPosition(double lat, double lng); + void setGPSPosition(double lat, double lng, double alt, const QDateTime& dt, const KUrl& url); - double getLatitude(void); - double getLongitude(void); + double getLatitude(); + double getLongitude(); -protected: - - void drawContents(QPainter *p, int x, int y, int w, int h); - private: - void contentsMousePressEvent ( QMouseEvent * e ); - void contentsMouseReleaseEvent ( QMouseEvent * e ); - void contentsMouseMoveEvent( QMouseEvent * e ); + QDomElement addKmlElement(QDomDocument &kmlDocument, QDomElement &target, const QString& tag); + QDomElement addKmlTextElement(QDomDocument &kmlDocument, QDomElement &target, const QString& tag, const QString& text); - QPixmap &worldMapPixmap(); - private: WorldMapWidgetPriv *d; _______________________________________________ Digikam-devel mailing list [hidden email] https://mail.kde.org/mailman/listinfo/digikam-devel |
Free forum by Nabble | Edit this page |