diff options
4 files changed, 117 insertions, 29 deletions
diff --git a/src/location/declarativemaps/qdeclarativegeomapcopyrightsnotice.cpp b/src/location/declarativemaps/qdeclarativegeomapcopyrightsnotice.cpp index 2cabebde..9da6a92c 100644 --- a/src/location/declarativemaps/qdeclarativegeomapcopyrightsnotice.cpp +++ b/src/location/declarativemaps/qdeclarativegeomapcopyrightsnotice.cpp @@ -74,8 +74,29 @@ QT_BEGIN_NAMESPACE be set, as it is the only data source for this element. */ +/*! + \qmlproperty color QtLocation::MapCopyrightNotice::backgroundColor + + This property holds the current background color of the copyright notice. +*/ + +/*! + \qmlproperty string QtLocation::MapCopyrightNotice::styleSheet + + This property holds the current css2.1 style sheet used to style the copyright notice, if in HTML form. + + Example: + \code + MapCopyrightNotice { + mapSource: myMap + styleSheet: "body { color : green; font-family: \"Lucida\"; font-size: 8px} a{ font-size: 8px; color:#A62900}" + } + \endcode +*/ + QDeclarativeGeoMapCopyrightNotice::QDeclarativeGeoMapCopyrightNotice(QQuickItem *parent) -: QQuickPaintedItem(parent), m_copyrightsHtml(0), m_copyrightsVisible(true), m_mapSource(0) +: QQuickPaintedItem(parent), m_copyrightsHtml(0), m_copyrightsVisible(true), m_mapSource(0), + m_backgroundColor(255, 255, 255, 128) { // If this item is constructed inside the map, automatically anchor it where it always used to be. if (qobject_cast<QDeclarativeGeoMap *>(parent)) @@ -133,6 +154,38 @@ QDeclarativeGeoMap *QDeclarativeGeoMapCopyrightNotice::mapSource() return m_mapSource; } +QColor QDeclarativeGeoMapCopyrightNotice::backgroundColor() const +{ + return m_backgroundColor; +} + +QString QDeclarativeGeoMapCopyrightNotice::styleSheet() const +{ + return m_styleSheet; +} + +void QDeclarativeGeoMapCopyrightNotice::setBackgroundColor(const QColor &color) +{ + m_backgroundColor = color; + rasterizeHtmlAndUpdate(); + emit backgroundColorChanged(m_backgroundColor); +} + +void QDeclarativeGeoMapCopyrightNotice::setStyleSheet(const QString &styleSheet) +{ + if (styleSheet == m_styleSheet) + return; + + m_styleSheet = styleSheet; + if (!m_html.isEmpty() && m_copyrightsHtml) { + delete m_copyrightsHtml; + createCopyright(); + m_copyrightsHtml->setHtml(m_html); + } + rasterizeHtmlAndUpdate(); + emit styleSheetChanged(m_styleSheet); +} + /*! \internal */ @@ -163,6 +216,36 @@ void QDeclarativeGeoMapCopyrightNotice::mouseReleaseEvent(QMouseEvent *event) } } +void QDeclarativeGeoMapCopyrightNotice::rasterizeHtmlAndUpdate() +{ + if (!m_copyrightsHtml || m_copyrightsHtml->isEmpty()) + return; + + m_copyrightsImage = QImage(m_copyrightsHtml->size().toSize(), + QImage::Format_ARGB32_Premultiplied); + + m_copyrightsImage.fill(qPremultiply(m_backgroundColor.rgba())); + QPainter painter(&m_copyrightsImage); + QAbstractTextDocumentLayout::PaintContext ctx; + ctx.palette.setColor(QPalette::Text, QStringLiteral("black")); + m_copyrightsHtml->documentLayout()->draw(&painter, ctx); + + setImplicitSize(m_copyrightsImage.width(), m_copyrightsImage.height()); + setContentsSize(m_copyrightsImage.size()); + + setKeepMouseGrab(true); + setAcceptedMouseButtons(Qt::LeftButton); + + update(); +} + +void QDeclarativeGeoMapCopyrightNotice::createCopyright() +{ + m_copyrightsHtml = new QTextDocument(this); + if (!m_styleSheet.isEmpty()) + m_copyrightsHtml->setDefaultStyleSheet(m_styleSheet); +} + /*! \internal */ @@ -192,8 +275,7 @@ void QDeclarativeGeoMapCopyrightNotice::copyrightsChanged(const QImage ©righ m_copyrightsImage = copyrightsImage; - setWidth(m_copyrightsImage.width()); - setHeight(m_copyrightsImage.height()); + setImplicitSize(m_copyrightsImage.width(), m_copyrightsImage.height()); setKeepMouseGrab(false); setAcceptedMouseButtons(Qt::NoButton); @@ -213,31 +295,12 @@ void QDeclarativeGeoMapCopyrightNotice::copyrightsChanged(const QString ©rig setVisible(true); } + m_html = copyrightsHtml; if (!m_copyrightsHtml) - m_copyrightsHtml = new QTextDocument(this); + createCopyright(); 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); // <- this uses the default application palette, that might have, f.ex., white text - QAbstractTextDocumentLayout::PaintContext ctx; - ctx.palette.setColor(QPalette::Text, QColor(QStringLiteral("black"))); - ctx.palette.setColor(QPalette::Link, QColor(QStringLiteral("blue"))); - m_copyrightsHtml->documentLayout()->draw(&painter, ctx); - - setWidth(m_copyrightsImage.width()); - setHeight(m_copyrightsImage.height()); - - setContentsSize(m_copyrightsImage.size()); - - setKeepMouseGrab(true); - setAcceptedMouseButtons(Qt::LeftButton); - - update(); + rasterizeHtmlAndUpdate(); } QT_END_NAMESPACE diff --git a/src/location/declarativemaps/qdeclarativegeomapcopyrightsnotice_p.h b/src/location/declarativemaps/qdeclarativegeomapcopyrightsnotice_p.h index 551bf411..4501fdf7 100644 --- a/src/location/declarativemaps/qdeclarativegeomapcopyrightsnotice_p.h +++ b/src/location/declarativemaps/qdeclarativegeomapcopyrightsnotice_p.h @@ -63,6 +63,8 @@ class Q_LOCATION_PRIVATE_EXPORT QDeclarativeGeoMapCopyrightNotice : public QQuic { Q_OBJECT Q_PROPERTY(QDeclarativeGeoMap *mapSource READ mapSource WRITE setMapSource NOTIFY mapSourceChanged) + Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged) + Q_PROPERTY(QString styleSheet READ styleSheet WRITE setStyleSheet NOTIFY styleSheetChanged) public: QDeclarativeGeoMapCopyrightNotice(QQuickItem *parent = Q_NULLPTR); @@ -76,6 +78,11 @@ public: void setMapSource(QDeclarativeGeoMap *mapSource); QDeclarativeGeoMap *mapSource(); + QColor backgroundColor() const; + QString styleSheet() const; + void setBackgroundColor(const QColor &color); + void setStyleSheet(const QString &styleSheet); + public Q_SLOTS: void copyrightsChanged(const QImage ©rightsImage); void copyrightsChanged(const QString ©rightsHtml); @@ -83,18 +90,26 @@ public Q_SLOTS: signals: void linkActivated(const QString &link); void mapSourceChanged(); + void backgroundColorChanged(const QColor &color); + void styleSheetChanged(const QString &styleSheet); protected: void paint(QPainter *painter) Q_DECL_OVERRIDE; void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE; void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE; + void rasterizeHtmlAndUpdate(); private: + void createCopyright(); + QTextDocument *m_copyrightsHtml; + QString m_html; QImage m_copyrightsImage; QString m_activeAnchor; bool m_copyrightsVisible; QDeclarativeGeoMap *m_mapSource; + QColor m_backgroundColor; + QString m_styleSheet; }; QT_END_NAMESPACE diff --git a/src/plugins/geoservices/esri/geotiledmap_esri.cpp b/src/plugins/geoservices/esri/geotiledmap_esri.cpp index 9171fc2b..8caf055d 100644 --- a/src/plugins/geoservices/esri/geotiledmap_esri.cpp +++ b/src/plugins/geoservices/esri/geotiledmap_esri.cpp @@ -44,6 +44,11 @@ QT_BEGIN_NAMESPACE +static QString bodify(const QString &html) +{ + return QStringLiteral("<body>") + html + QStringLiteral("</body>"); +} + GeoTiledMapEsri::GeoTiledMapEsri(GeoTiledMappingManagerEngineEsri *engine, QObject *parent) : QGeoTiledMap(engine, parent), m_engine(engine), m_mapId(-1) { @@ -67,7 +72,7 @@ void GeoTiledMapEsri::evaluateCopyrights(const QSet<QGeoTileSpec> &visibleTiles) GeoMapSource *mapSource = engine()->mapSource(m_mapId); if (mapSource) - emit copyrightsChanged(mapSource->copyright()); + emit copyrightsChanged(bodify(mapSource->copyright())); } QT_END_NAMESPACE diff --git a/src/plugins/geoservices/osm/qgeotiledmaposm.cpp b/src/plugins/geoservices/osm/qgeotiledmaposm.cpp index d94a40a6..e1383afb 100644 --- a/src/plugins/geoservices/osm/qgeotiledmaposm.cpp +++ b/src/plugins/geoservices/osm/qgeotiledmaposm.cpp @@ -45,6 +45,11 @@ QT_BEGIN_NAMESPACE +static QString bodify(const QString &html) +{ + return QStringLiteral("<body>") + html + QStringLiteral("</body>"); +} + QGeoTiledMapOsm::QGeoTiledMapOsm(QGeoTiledMappingManagerEngineOsm *engine, QObject *parent) : QGeoTiledMap(engine, parent), m_mapId(-1), m_engine(engine) { @@ -95,13 +100,13 @@ void QGeoTiledMapOsm::onProviderDataUpdated(const QGeoTileProviderOsm *provider) } if (!dataCopy.isEmpty()) { if (!copyRights.isEmpty()) - copyRights += QStringLiteral("<br/>"); + copyRights += QStringLiteral(" | "); copyRights += QStringLiteral("Data © "); copyRights += dataCopy; } if (!styleCopy.isEmpty()) { if (!copyRights.isEmpty()) - copyRights += QStringLiteral("<br/>"); + copyRights += QStringLiteral(" | "); copyRights += QStringLiteral("Style © "); copyRights += styleCopy; } @@ -109,7 +114,7 @@ void QGeoTiledMapOsm::onProviderDataUpdated(const QGeoTileProviderOsm *provider) if (copyRights.isEmpty() && provider->mapType().style() == QGeoMapType::CustomMap) copyRights = m_engine->customCopyright(); - emit copyrightsChanged(copyRights); + emit copyrightsChanged(bodify(copyRights)); } QT_END_NAMESPACE |