80void QDeclarativeGeoMapCopyrightNotice::anchorToBottomLeft()
84 QQuickAnchors *anchors = property(
"anchors").value<QQuickAnchors *>();
86 anchors->setLeft(QQuickAnchorLine(qobject_cast<QQuickItem *>(parent()), QQuickAnchors::LeftAnchor));
87 anchors->setBottom(QQuickAnchorLine(qobject_cast<QQuickItem *>(parent()), QQuickAnchors::BottomAnchor));
91void QDeclarativeGeoMapCopyrightNotice::setMapSource(QDeclarativeGeoMap *map)
93 if (m_mapSource == map)
98 m_mapSource->detachCopyrightNotice(copyrightsVisible());
99 m_mapSource->disconnect(
this);
100 m_mapSource->m_map->disconnect(
this);
101 if (m_copyrightsHtml)
102 m_copyrightsHtml->clear();
103 m_copyrightsImage = QImage();
104 m_mapSource =
nullptr;
109 m_mapSource->attachCopyrightNotice(copyrightsVisible());
110 connect(
this, &QDeclarativeGeoMapCopyrightNotice::copyrightsVisibleChanged,
111 mapSource(), &QDeclarativeGeoMap::onAttachedCopyrightNoticeVisibilityChanged);
114 if (m_mapSource->m_copyrights && !m_mapSource->m_copyrights->m_copyrightsImage.isNull())
115 m_copyrightsImage = m_mapSource->m_copyrights->m_copyrightsImage;
117 connect(mapSource(), &QDeclarativeGeoMap::copyrightsImageChanged,
118 this, &QDeclarativeGeoMapCopyrightNotice::copyrightsImageChanged);
119 connect(mapSource(), &QDeclarativeGeoMap::copyrightsChanged,
120 this, &QDeclarativeGeoMapCopyrightNotice::copyrightsChanged);
122 if (m_mapSource->m_map)
125 connect(mapSource(), &QDeclarativeGeoMap::mapReadyChanged,
this, &QDeclarativeGeoMapCopyrightNotice::connectMap);
129void QDeclarativeGeoMapCopyrightNotice::connectMap()
131 connect(m_mapSource->m_map.data(), &QGeoMap::copyrightsStyleSheetChanged,
132 this, &QDeclarativeGeoMapCopyrightNotice::onCopyrightsStyleSheetChanged);
133 connect(
this, &QDeclarativeGeoMapCopyrightNotice::linkActivated,
134 mapSource(), &QDeclarativeGeoMap::copyrightLinkActivated);
136 onCopyrightsStyleSheetChanged(m_mapSource->m_map->copyrightsStyleSheet());
139 emit mapSourceChanged();
152void QDeclarativeGeoMapCopyrightNotice::setStyleSheet(
const QString &styleSheet)
154 m_userDefinedStyleSheet =
true;
156 if (styleSheet == m_styleSheet)
159 m_styleSheet = styleSheet;
160 if (!m_html.isEmpty() && m_copyrightsHtml) {
161 delete m_copyrightsHtml;
163#if QT_CONFIG(texthtmlparser)
164 m_copyrightsHtml->setHtml(m_html);
166 m_copyrightsHtml->setPlainText(m_html);
169 rasterizeHtmlAndUpdate();
170 emit styleSheetChanged(m_styleSheet);
192void QDeclarativeGeoMapCopyrightNotice::mouseReleaseEvent(QMouseEvent *event)
194 if (m_copyrightsHtml) {
195 QString anchor = m_copyrightsHtml->documentLayout()->anchorAt(event->pos());
196 if (anchor == m_activeAnchor && !anchor.isEmpty()) {
197 emit linkActivated(anchor);
198 m_activeAnchor.clear();
203void QDeclarativeGeoMapCopyrightNotice::rasterizeHtmlAndUpdate()
205 if (!m_copyrightsHtml || m_copyrightsHtml->isEmpty())
208 m_copyrightsImage = QImage(m_copyrightsHtml->size().toSize(),
209 QImage::Format_ARGB32_Premultiplied);
211 m_copyrightsImage.fill(qPremultiply(QColor(Qt::transparent).rgba()));
212 QPainter painter(&m_copyrightsImage);
213 QAbstractTextDocumentLayout::PaintContext ctx;
214 ctx.palette.setColor(QPalette::Text, QColor::fromString(
"black"));
215 m_copyrightsHtml->documentLayout()->draw(&painter, ctx);
217 setImplicitSize(m_copyrightsImage.width(), m_copyrightsImage.height());
218 setContentsSize(m_copyrightsImage.size());
220 setKeepMouseGrab(
true);
221 setAcceptedMouseButtons(Qt::LeftButton);
248void QDeclarativeGeoMapCopyrightNotice::setCopyrightsVisible(
bool visible)
250 Q_D(QDeclarativeGeoMapCopyrightNotice);
251 if (visible == m_copyrightsVisible)
254 m_copyrightsVisible = visible;
255 d->QQuickItemPrivate::setVisible(!m_copyrightsImage.isNull() && visible);
256 emit copyrightsVisibleChanged();
276void QDeclarativeGeoMapCopyrightNotice::copyrightsImageChanged(
const QImage ©rightsImage)
278 Q_D(QDeclarativeGeoMapCopyrightNotice);
279 delete m_copyrightsHtml;
280 m_copyrightsHtml =
nullptr;
282 m_copyrightsImage = copyrightsImage;
284 setImplicitSize(m_copyrightsImage.width(), m_copyrightsImage.height());
286 setKeepMouseGrab(
false);
287 setAcceptedMouseButtons(Qt::NoButton);
288 d->QQuickItemPrivate::setVisible(m_copyrightsVisible && !m_copyrightsImage.isNull());
293void QDeclarativeGeoMapCopyrightNotice::copyrightsChanged(
const QString ©rightsHtml)
295 Q_D(QDeclarativeGeoMapCopyrightNotice);
296 if (copyrightsHtml.isEmpty()) {
297 d->QQuickItemPrivate::setVisible(
false);
300 d->QQuickItemPrivate::setVisible(m_copyrightsVisible);
305#if QT_CONFIG(texthtmlparser)
306 m_html = QStringLiteral(
"<div id='copyright-root'><span>") + copyrightsHtml + QStringLiteral(
"</span></div>");
308 m_html = copyrightsHtml;
311 if (!m_copyrightsHtml)
314#if QT_CONFIG(texthtmlparser)
315 m_copyrightsHtml->setHtml(m_html);
317 m_copyrightsHtml->setPlainText(m_html);
319 rasterizeHtmlAndUpdate();
322void QDeclarativeGeoMapCopyrightNotice::onCopyrightsStyleSheetChanged(
const QString &styleSheet)
324 if (m_userDefinedStyleSheet || styleSheet == m_styleSheet)
327 m_styleSheet = styleSheet;
328 if (!m_html.isEmpty() && m_copyrightsHtml) {
329 delete m_copyrightsHtml;
331#if QT_CONFIG(texthtmlparser)
332 m_copyrightsHtml->setHtml(m_html);
334 m_copyrightsHtml->setPlainText(m_html);
337 rasterizeHtmlAndUpdate();
338 emit styleSheetChanged(m_styleSheet);