79void QDeclarativeGeoMapCopyrightNotice::anchorToBottomLeft()
83 QQuickAnchors *anchors = property(
"anchors").value<QQuickAnchors *>();
85 anchors->setLeft(QQuickAnchorLine(qobject_cast<QQuickItem *>(parent()), QQuickAnchors::LeftAnchor));
86 anchors->setBottom(QQuickAnchorLine(qobject_cast<QQuickItem *>(parent()), QQuickAnchors::BottomAnchor));
90void QDeclarativeGeoMapCopyrightNotice::setMapSource(QDeclarativeGeoMap *map)
92 if (m_mapSource == map)
97 m_mapSource->detachCopyrightNotice(copyrightsVisible());
98 m_mapSource->disconnect(
this);
99 m_mapSource->m_map->disconnect(
this);
100 if (m_copyrightsHtml)
101 m_copyrightsHtml->clear();
102 m_copyrightsImage = QImage();
103 m_mapSource =
nullptr;
108 m_mapSource->attachCopyrightNotice(copyrightsVisible());
109 connect(
this, &QDeclarativeGeoMapCopyrightNotice::copyrightsVisibleChanged,
110 mapSource(), &QDeclarativeGeoMap::onAttachedCopyrightNoticeVisibilityChanged);
113 if (m_mapSource->m_copyrights && !m_mapSource->m_copyrights->m_copyrightsImage.isNull())
114 m_copyrightsImage = m_mapSource->m_copyrights->m_copyrightsImage;
116 connect(mapSource(), &QDeclarativeGeoMap::copyrightsImageChanged,
117 this, &QDeclarativeGeoMapCopyrightNotice::copyrightsImageChanged);
118 connect(mapSource(), &QDeclarativeGeoMap::copyrightsChanged,
119 this, &QDeclarativeGeoMapCopyrightNotice::copyrightsChanged);
121 if (m_mapSource->m_map)
124 connect(mapSource(), &QDeclarativeGeoMap::mapReadyChanged,
this, &QDeclarativeGeoMapCopyrightNotice::connectMap);
128void QDeclarativeGeoMapCopyrightNotice::connectMap()
130 connect(m_mapSource->m_map.data(), &QGeoMap::copyrightsStyleSheetChanged,
131 this, &QDeclarativeGeoMapCopyrightNotice::onCopyrightsStyleSheetChanged);
132 connect(
this, &QDeclarativeGeoMapCopyrightNotice::linkActivated,
133 mapSource(), &QDeclarativeGeoMap::copyrightLinkActivated);
135 onCopyrightsStyleSheetChanged(m_mapSource->m_map->copyrightsStyleSheet());
138 emit mapSourceChanged();
151void QDeclarativeGeoMapCopyrightNotice::setStyleSheet(
const QString &styleSheet)
153 m_userDefinedStyleSheet =
true;
155 if (styleSheet == m_styleSheet)
158 m_styleSheet = styleSheet;
159 if (!m_html.isEmpty() && m_copyrightsHtml) {
160 delete m_copyrightsHtml;
162#if QT_CONFIG(texthtmlparser)
163 m_copyrightsHtml->setHtml(m_html);
165 m_copyrightsHtml->setPlainText(m_html);
168 rasterizeHtmlAndUpdate();
169 emit styleSheetChanged(m_styleSheet);
191void QDeclarativeGeoMapCopyrightNotice::mouseReleaseEvent(QMouseEvent *event)
193 if (m_copyrightsHtml) {
194 QString anchor = m_copyrightsHtml->documentLayout()->anchorAt(event->pos());
195 if (anchor == m_activeAnchor && !anchor.isEmpty()) {
196 emit linkActivated(anchor);
197 m_activeAnchor.clear();
202void QDeclarativeGeoMapCopyrightNotice::rasterizeHtmlAndUpdate()
204 if (!m_copyrightsHtml || m_copyrightsHtml->isEmpty())
207 m_copyrightsImage = QImage(m_copyrightsHtml->size().toSize(),
208 QImage::Format_ARGB32_Premultiplied);
210 m_copyrightsImage.fill(qPremultiply(QColor(Qt::transparent).rgba()));
211 QPainter painter(&m_copyrightsImage);
212 QAbstractTextDocumentLayout::PaintContext ctx;
213 ctx.palette.setColor(QPalette::Text, QColor::fromString(
"black"));
214 m_copyrightsHtml->documentLayout()->draw(&painter, ctx);
216 setImplicitSize(m_copyrightsImage.width(), m_copyrightsImage.height());
217 setContentsSize(m_copyrightsImage.size());
219 setKeepMouseGrab(
true);
220 setAcceptedMouseButtons(Qt::LeftButton);
247void QDeclarativeGeoMapCopyrightNotice::setCopyrightsVisible(
bool visible)
249 Q_D(QDeclarativeGeoMapCopyrightNotice);
250 if (visible == m_copyrightsVisible)
253 m_copyrightsVisible = visible;
254 d->QQuickItemPrivate::setVisible(!m_copyrightsImage.isNull() && visible);
255 emit copyrightsVisibleChanged();
275void QDeclarativeGeoMapCopyrightNotice::copyrightsImageChanged(
const QImage ©rightsImage)
277 Q_D(QDeclarativeGeoMapCopyrightNotice);
278 delete m_copyrightsHtml;
279 m_copyrightsHtml =
nullptr;
281 m_copyrightsImage = copyrightsImage;
283 setImplicitSize(m_copyrightsImage.width(), m_copyrightsImage.height());
285 setKeepMouseGrab(
false);
286 setAcceptedMouseButtons(Qt::NoButton);
287 d->QQuickItemPrivate::setVisible(m_copyrightsVisible && !m_copyrightsImage.isNull());
292void QDeclarativeGeoMapCopyrightNotice::copyrightsChanged(
const QString ©rightsHtml)
294 Q_D(QDeclarativeGeoMapCopyrightNotice);
295 if (copyrightsHtml.isEmpty()) {
296 d->QQuickItemPrivate::setVisible(
false);
299 d->QQuickItemPrivate::setVisible(m_copyrightsVisible);
304#if QT_CONFIG(texthtmlparser)
305 m_html = QStringLiteral(
"<div id='copyright-root'><span>") + copyrightsHtml + QStringLiteral(
"</span></div>");
307 m_html = copyrightsHtml;
310 if (!m_copyrightsHtml)
313#if QT_CONFIG(texthtmlparser)
314 m_copyrightsHtml->setHtml(m_html);
316 m_copyrightsHtml->setPlainText(m_html);
318 rasterizeHtmlAndUpdate();
321void QDeclarativeGeoMapCopyrightNotice::onCopyrightsStyleSheetChanged(
const QString &styleSheet)
323 if (m_userDefinedStyleSheet || styleSheet == m_styleSheet)
326 m_styleSheet = styleSheet;
327 if (!m_html.isEmpty() && m_copyrightsHtml) {
328 delete m_copyrightsHtml;
330#if QT_CONFIG(texthtmlparser)
331 m_copyrightsHtml->setHtml(m_html);
333 m_copyrightsHtml->setPlainText(m_html);
336 rasterizeHtmlAndUpdate();
337 emit styleSheetChanged(m_styleSheet);