summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron McCarthy <mccarthy.aaron@gmail.com>2014-12-12 00:43:44 +1000
committerAlex Blasche <alexander.blasche@theqtcompany.com>2015-01-27 14:50:13 +0000
commitbbb1839392f24fe133ab182ffe36b2e2b0304edf (patch)
treeb969e8b0370312b408a2714087546178bcb43845
parentab890b333b30eda0593e7d748018ef3f4c683ddf (diff)
downloadqtlocation-bbb1839392f24fe133ab182ffe36b2e2b0304edf.tar.gz
Allow HTML based copyright notices.
In addition to the image based map copyright/attribution notice allow a geo service provider to provide a HTML string which is rendered and displayed. Add copyrightLinkActivated signal to the map to enable the application to launch the url in an external browser. The geo service providers are no longer in control of the position of the copyright notice. For the time being it will be placed at the bottom left of the map. Change-Id: I49bfc58a70e9254220903d5103c714c08f327e8b Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
-rw-r--r--examples/location/mapviewer/content/map/MapComponent.qml2
-rw-r--r--examples/location/places/places.qml9
-rw-r--r--src/imports/location/qdeclarativegeomap.cpp27
-rw-r--r--src/imports/location/qdeclarativegeomap_p.h1
-rw-r--r--src/imports/location/qdeclarativegeomapcopyrightsnotice.cpp87
-rw-r--r--src/imports/location/qdeclarativegeomapcopyrightsnotice_p.h22
-rw-r--r--src/location/maps/qgeomap.cpp3
-rw-r--r--src/location/maps/qgeomap_p.h3
-rw-r--r--src/location/maps/qgeomapdata_p.h3
-rw-r--r--src/plugins/geoservices/nokia/qgeotiledmapdata_nokia.cpp11
-rw-r--r--src/plugins/geoservices/nokia/qgeotiledmapdata_nokia.h1
11 files changed, 129 insertions, 40 deletions
diff --git a/examples/location/mapviewer/content/map/MapComponent.qml b/examples/location/mapviewer/content/map/MapComponent.qml
index 211e245f..dfa8ec23 100644
--- a/examples/location/mapviewer/content/map/MapComponent.qml
+++ b/examples/location/mapviewer/content/map/MapComponent.qml
@@ -83,6 +83,8 @@ Map {
when: followme
}*/
+ onCopyrightLinkActivated: Qt.openUrlExternally(link)
+
PositionSource{
id: positionSource
active: followme
diff --git a/examples/location/places/places.qml b/examples/location/places/places.qml
index 3ed7a7cc..23330591 100644
--- a/examples/location/places/places.qml
+++ b/examples/location/places/places.qml
@@ -497,8 +497,13 @@ Item {
MapComponent {
z: backgroundRect.z + 1
- width: page.width
- height: page.height - mainMenu.height
+
+ anchors {
+ top: searchBox.bottom
+ bottom: mainMenu.top
+ left: page.left
+ right: page.right
+ }
MapItemView {
model: placeSearchModel
diff --git a/src/imports/location/qdeclarativegeomap.cpp b/src/imports/location/qdeclarativegeomap.cpp
index 80e39d0c..4c4b8888 100644
--- a/src/imports/location/qdeclarativegeomap.cpp
+++ b/src/imports/location/qdeclarativegeomap.cpp
@@ -173,6 +173,13 @@ QT_BEGIN_NAMESPACE
\image api-map.png
*/
+/*!
+ \qmlsignal QtLocation::Map::copyrightLinkActivated(string link)
+
+ This signal is emitted when the user clicks on a \a link in the copyright notice. The
+ application should open the link in a browser or display its contents to the user.
+*/
+
QDeclarativeGeoMap::QDeclarativeGeoMap(QQuickItem *parent)
: QQuickItem(parent),
plugin_(0),
@@ -247,10 +254,12 @@ void QDeclarativeGeoMap::onMapChildrenChanged()
// create a new one and set its parent, re-assign it to the weak pointer, then connect the copyrights-change signal
copyrightsWPtr_ = new QDeclarativeGeoMapCopyrightNotice(this);
copyrights = copyrightsWPtr_.data();
- connect(map_,
- SIGNAL(copyrightsChanged(QImage,QPoint)),
- copyrights,
- SLOT(copyrightsChanged(QImage,QPoint)));
+ connect(map_, SIGNAL(copyrightsChanged(QImage)),
+ copyrights, SLOT(copyrightsChanged(QImage)));
+ connect(map_, SIGNAL(copyrightsChanged(QString)),
+ copyrights, SLOT(copyrightsChanged(QString)));
+ connect(copyrights, SIGNAL(linkActivated(QString)),
+ this, SIGNAL(copyrightLinkActivated(QString)));
} else {
// just re-set its parent.
copyrights->setParent(this);
@@ -478,10 +487,12 @@ void QDeclarativeGeoMap::mappingManagerInitialized()
map_->setActiveMapType(QGeoMapType());
copyrightsWPtr_ = new QDeclarativeGeoMapCopyrightNotice(this);
- connect(map_,
- SIGNAL(copyrightsChanged(QImage,QPoint)),
- copyrightsWPtr_.data(),
- SLOT(copyrightsChanged(QImage,QPoint)));
+ connect(map_, SIGNAL(copyrightsChanged(QImage)),
+ copyrightsWPtr_.data(), SLOT(copyrightsChanged(QImage)));
+ connect(map_, SIGNAL(copyrightsChanged(QString)),
+ copyrightsWPtr_.data(), SLOT(copyrightsChanged(QString)));
+ connect(copyrightsWPtr_.data(), SIGNAL(linkActivated(QString)),
+ this, SIGNAL(copyrightLinkActivated(QString)));
connect(map_,
SIGNAL(updateRequired()),
diff --git a/src/imports/location/qdeclarativegeomap_p.h b/src/imports/location/qdeclarativegeomap_p.h
index 9ba23e53..256ddcfb 100644
--- a/src/imports/location/qdeclarativegeomap_p.h
+++ b/src/imports/location/qdeclarativegeomap_p.h
@@ -180,6 +180,7 @@ Q_SIGNALS:
void maximumZoomLevelChanged();
void mapItemsChanged();
void errorChanged();
+ void copyrightLinkActivated(const QString &link);
private Q_SLOTS:
void updateMapDisplay(const QRectF &target);
diff --git a/src/imports/location/qdeclarativegeomapcopyrightsnotice.cpp b/src/imports/location/qdeclarativegeomapcopyrightsnotice.cpp
index 6dd01f99..845164c4 100644
--- a/src/imports/location/qdeclarativegeomapcopyrightsnotice.cpp
+++ b/src/imports/location/qdeclarativegeomapcopyrightsnotice.cpp
@@ -1,5 +1,6 @@
/****************************************************************************
**
+** Copyright (C) 2014 Aaron McCarthy <mccarthy.aaron@gmail.com>
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
@@ -31,15 +32,25 @@
**
****************************************************************************/
-#include <QPainter>
-#include <QPoint>
-
#include "qdeclarativegeomapcopyrightsnotice_p.h"
+#include <QtGui/QTextDocument>
+#include <QtGui/QAbstractTextDocumentLayout>
+#include <QtGui/QPainter>
+#include <QtQuick/private/qquickanchors_p.h>
+#include <QtQuick/private/qquickanchors_p_p.h>
+
QT_BEGIN_NAMESPACE
QDeclarativeGeoMapCopyrightNotice::QDeclarativeGeoMapCopyrightNotice(QQuickItem *parent)
- : QQuickPaintedItem(parent) {}
+: QQuickPaintedItem(parent), m_copyrightsHtml(0)
+{
+ QQuickAnchors *anchors = property("anchors").value<QQuickAnchors *>();
+ if (anchors) {
+ anchors->setLeft(QQuickAnchorLine(parent, QQuickAnchorLine::Left));
+ anchors->setBottom(QQuickAnchorLine(parent, QQuickAnchorLine::Bottom));
+ }
+}
QDeclarativeGeoMapCopyrightNotice::~QDeclarativeGeoMapCopyrightNotice()
{
@@ -50,7 +61,29 @@ QDeclarativeGeoMapCopyrightNotice::~QDeclarativeGeoMapCopyrightNotice()
*/
void QDeclarativeGeoMapCopyrightNotice::paint(QPainter *painter)
{
- painter->drawImage(0, 0, copyrightsImage_);
+ painter->drawImage(0, 0, m_copyrightsImage);
+}
+
+void QDeclarativeGeoMapCopyrightNotice::mousePressEvent(QMouseEvent *event)
+{
+ if (m_copyrightsHtml) {
+ m_activeAnchor = m_copyrightsHtml->documentLayout()->anchorAt(event->pos());
+ if (!m_activeAnchor.isEmpty())
+ return;
+ }
+
+ QQuickPaintedItem::mousePressEvent(event);
+}
+
+void QDeclarativeGeoMapCopyrightNotice::mouseReleaseEvent(QMouseEvent *event)
+{
+ if (m_copyrightsHtml) {
+ QString anchor = m_copyrightsHtml->documentLayout()->anchorAt(event->pos());
+ if (anchor == m_activeAnchor && !anchor.isEmpty()) {
+ emit linkActivated(anchor);
+ m_activeAnchor.clear();
+ }
+ }
}
/*!
@@ -65,13 +98,45 @@ void QDeclarativeGeoMapCopyrightNotice::setCopyrightsZ(int copyrightsZ)
/*!
\internal
*/
-void QDeclarativeGeoMapCopyrightNotice::copyrightsChanged(const QImage &copyrightsImage, const QPoint &copyrightsPos)
+void QDeclarativeGeoMapCopyrightNotice::copyrightsChanged(const QImage &copyrightsImage)
{
- setX(copyrightsPos.x());
- setY(copyrightsPos.y());
- setWidth(copyrightsImage.width());
- setHeight(copyrightsImage.height());
- copyrightsImage_ = copyrightsImage;
+ delete m_copyrightsHtml;
+ m_copyrightsHtml = 0;
+
+ m_copyrightsImage = copyrightsImage;
+
+ setWidth(m_copyrightsImage.width());
+ setHeight(m_copyrightsImage.height());
+
+ setKeepMouseGrab(false);
+ setAcceptedMouseButtons(Qt::NoButton);
+
+ update();
+}
+
+void QDeclarativeGeoMapCopyrightNotice::copyrightsChanged(const QString &copyrightsHtml)
+{
+ if (!m_copyrightsHtml)
+ m_copyrightsHtml = new QTextDocument(this);
+
+ m_copyrightsHtml->setHtml(copyrightsHtml);
+
+ m_copyrightsImage = QImage(m_copyrightsHtml->size().toSize(),
+ QImage::Format_ARGB32_Premultiplied);
+ m_copyrightsImage.fill(qPremultiply(qRgba(255, 255, 255, 128)));
+
+ QPainter painter(&m_copyrightsImage);
+ m_copyrightsHtml->drawContents(&painter);
+
+ setWidth(m_copyrightsImage.width());
+ setHeight(m_copyrightsImage.height());
+
+ setContentsSize(m_copyrightsImage.size());
+
+ setKeepMouseGrab(true);
+ setAcceptedMouseButtons(Qt::LeftButton);
+
+ update();
}
QT_END_NAMESPACE
diff --git a/src/imports/location/qdeclarativegeomapcopyrightsnotice_p.h b/src/imports/location/qdeclarativegeomapcopyrightsnotice_p.h
index 3a5dbd55..873ec444 100644
--- a/src/imports/location/qdeclarativegeomapcopyrightsnotice_p.h
+++ b/src/imports/location/qdeclarativegeomapcopyrightsnotice_p.h
@@ -1,5 +1,6 @@
/****************************************************************************
**
+** Copyright (C) 2014 Aaron McCarthy <mccarthy.aaron@gmail.com>
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
@@ -34,14 +35,17 @@
#ifndef QDECLARATIVEGEOMAPCOPYRIGHTSNOTICE_H
#define QDECLARATIVEGEOMAPCOPYRIGHTSNOTICE_H
-#include <QQuickPaintedItem>
-#include <QImage>
+#include <QtGui/QImage>
+#include <QtQuick/QQuickPaintedItem>
QT_BEGIN_NAMESPACE
+class QTextDocument;
+
class QDeclarativeGeoMapCopyrightNotice : public QQuickPaintedItem
{
Q_OBJECT
+
public:
explicit QDeclarativeGeoMapCopyrightNotice(QQuickItem *parent);
~QDeclarativeGeoMapCopyrightNotice();
@@ -49,13 +53,21 @@ public:
void setCopyrightsZ(int copyrightsZ);
public Q_SLOTS:
- void copyrightsChanged(const QImage &copyrightsImage, const QPoint &copyrightsPos);
+ void copyrightsChanged(const QImage &copyrightsImage);
+ void copyrightsChanged(const QString &copyrightsHtml);
+
+signals:
+ void linkActivated(const QString &link);
protected:
- void paint(QPainter *painter);
+ void paint(QPainter *painter) Q_DECL_OVERRIDE;
+ void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
+ void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
private:
- QImage copyrightsImage_;
+ QTextDocument *m_copyrightsHtml;
+ QImage m_copyrightsImage;
+ QString m_activeAnchor;
};
QT_END_NAMESPACE
diff --git a/src/location/maps/qgeomap.cpp b/src/location/maps/qgeomap.cpp
index 31fe29d2..c7def6da 100644
--- a/src/location/maps/qgeomap.cpp
+++ b/src/location/maps/qgeomap.cpp
@@ -67,7 +67,8 @@ QGeoMap::QGeoMap(QGeoMapData *mapData, QObject *parent)
connect(mapData_, SIGNAL(cameraDataChanged(QGeoCameraData)), this, SIGNAL(cameraDataChanged(QGeoCameraData)));
connect(mapData_, SIGNAL(updateRequired()), this, SIGNAL(updateRequired()));
connect(mapData_, SIGNAL(activeMapTypeChanged()), this, SIGNAL(activeMapTypeChanged()));
- connect(mapData_, SIGNAL(copyrightsChanged(QImage,QPoint)), this, SIGNAL(copyrightsChanged(QImage,QPoint)));
+ connect(mapData_, SIGNAL(copyrightsChanged(QImage)), this, SIGNAL(copyrightsChanged(QImage)));
+ connect(mapData_, SIGNAL(copyrightsChanged(QString)), this, SIGNAL(copyrightsChanged(QString)));
}
QGeoMap::~QGeoMap()
diff --git a/src/location/maps/qgeomap_p.h b/src/location/maps/qgeomap_p.h
index 7d62358b..e52c6e5f 100644
--- a/src/location/maps/qgeomap_p.h
+++ b/src/location/maps/qgeomap_p.h
@@ -105,7 +105,8 @@ Q_SIGNALS:
void cameraDataChanged(const QGeoCameraData &cameraData);
void updateRequired();
void activeMapTypeChanged();
- void copyrightsChanged(const QImage &copyrightsImage, const QPoint &copyrightsPos);
+ void copyrightsChanged(const QImage &copyrightsImage);
+ void copyrightsChanged(const QString &copyrights);
private:
QGeoMapData *mapData_;
diff --git a/src/location/maps/qgeomapdata_p.h b/src/location/maps/qgeomapdata_p.h
index bc4b5dfc..359b8db2 100644
--- a/src/location/maps/qgeomapdata_p.h
+++ b/src/location/maps/qgeomapdata_p.h
@@ -108,7 +108,8 @@ Q_SIGNALS:
void cameraDataChanged(const QGeoCameraData &cameraData);
void updateRequired();
void activeMapTypeChanged();
- void copyrightsChanged(const QImage &copyrightsImage, const QPoint &copyrightsPos);
+ void copyrightsChanged(const QImage &copyrightsImage);
+ void copyrightsChanged(const QString &copyrightsHtml);
private:
QGeoMapDataPrivate *d_ptr;
diff --git a/src/plugins/geoservices/nokia/qgeotiledmapdata_nokia.cpp b/src/plugins/geoservices/nokia/qgeotiledmapdata_nokia.cpp
index f3e60deb..3486008d 100644
--- a/src/plugins/geoservices/nokia/qgeotiledmapdata_nokia.cpp
+++ b/src/plugins/geoservices/nokia/qgeotiledmapdata_nokia.cpp
@@ -67,7 +67,6 @@ QGeoTiledMapDataNokia::~QGeoTiledMapDataNokia() {}
void QGeoTiledMapDataNokia::evaluateCopyrights(const QSet<QGeoTileSpec> &visibleTiles)
{
- const int copyrightsMargin = 10;
const int spaceToLogo = 4;
const int blurRate = 1;
const int fontSize = 10;
@@ -106,18 +105,10 @@ void QGeoTiledMapDataNokia::evaluateCopyrights(const QSet<QGeoTileSpec> &visible
copyrightsString);
painter.end();
- QPoint copyrightsPos(copyrightsMargin, height() - (copyrightsSlab.height() + copyrightsMargin));
- lastCopyrightsPos = copyrightsPos;
- emit copyrightsChanged(copyrightsSlab, copyrightsPos);
-
lastCopyrightsString = copyrightsString;
}
- QPoint copyrightsPos(copyrightsMargin, height() - (copyrightsSlab.height() + copyrightsMargin));
- if (copyrightsPos != lastCopyrightsPos) {
- lastCopyrightsPos = copyrightsPos;
- emit copyrightsChanged(copyrightsSlab, copyrightsPos);
- }
+ emit copyrightsChanged(copyrightsSlab);
}
int QGeoTiledMapDataNokia::mapVersion()
diff --git a/src/plugins/geoservices/nokia/qgeotiledmapdata_nokia.h b/src/plugins/geoservices/nokia/qgeotiledmapdata_nokia.h
index ac9c6530..7c24acfe 100644
--- a/src/plugins/geoservices/nokia/qgeotiledmapdata_nokia.h
+++ b/src/plugins/geoservices/nokia/qgeotiledmapdata_nokia.h
@@ -67,7 +67,6 @@ private:
QImage logo;
QImage copyrightsSlab;
QString lastCopyrightsString;
- QPoint lastCopyrightsPos;
};
QT_END_NAMESPACE