6#include "GeoDataIconStyle.h"
10#include "MarbleDebug.h"
11#include "MarbleDirs.h"
12#include "RemoteIconLoader.h"
14#include "GeoDataTypes.h"
16#include <QImageReader>
21class GeoDataIconStylePrivate
24 GeoDataIconStylePrivate()
33 GeoDataIconStylePrivate(
const QString &iconPath,
const QPointF &hotSpot)
37 , m_iconPath(iconPath)
43 RemoteIconLoader *remoteIconLoader()
const
45 static auto remoteIconLoader =
new RemoteIconLoader();
46 return remoteIconLoader;
53 if (iconSize.
width() * m_scale > s_maximumIconSize.width() || iconSize.
height() * m_scale > s_maximumIconSize.height()) {
55 }
else if (iconSize.
width() * m_scale < s_minimumIconSize.width() || iconSize.
height() * m_scale < s_minimumIconSize.width()) {
71 auto const imageSize = imageReader.
size();
72 auto const finalSize = imageSize.
scaled(size, m_aspectRatioMode);
76 mDebug() <<
"GeoDataIconStyle: Failed to read image " <<
path <<
": " << imageReader.
errorString();
89 return remoteIconLoader()->load(
QUrl(m_iconPath));
92 mDebug() <<
"Unable to open style icon at: " <<
path;
103 GeoDataHotSpot m_hotSpot;
107GeoDataIconStyle::GeoDataIconStyle()
108 : d(new GeoDataIconStylePrivate())
112GeoDataIconStyle::GeoDataIconStyle(
const GeoDataIconStyle &other)
113 : GeoDataColorStyle(other)
114 , d(new GeoDataIconStylePrivate(*other.d))
118GeoDataIconStyle::GeoDataIconStyle(
const QString &iconPath,
const QPointF &hotSpot)
119 : d(new GeoDataIconStylePrivate(iconPath, hotSpot))
123GeoDataIconStyle::~GeoDataIconStyle()
128GeoDataIconStyle &GeoDataIconStyle::operator=(
const GeoDataIconStyle &other)
130 GeoDataColorStyle::operator=(other);
135bool GeoDataIconStyle::operator==(
const GeoDataIconStyle &other)
const
137 if (GeoDataColorStyle::operator!=(other)) {
141 return d->m_scale == other.d->m_scale && d->m_icon == other.d->m_icon && d->m_size == other.d->m_size && d->m_iconPath == other.d->m_iconPath
142 && d->m_hotSpot == other.d->m_hotSpot && d->m_heading == other.d->m_heading;
145bool GeoDataIconStyle::operator!=(
const GeoDataIconStyle &other)
const
150const char *GeoDataIconStyle::nodeType()
const
152 return GeoDataTypes::GeoDataIconStyleType;
155void GeoDataIconStyle::setIcon(
const QImage &icon)
158 d->m_scaledIcon =
QImage();
161void GeoDataIconStyle::setIconPath(
const QString &filename)
163 d->m_iconPath = filename;
171 d->m_scaledIcon =
QImage();
174QString GeoDataIconStyle::iconPath()
const
176 return d->m_iconPath;
179QImage GeoDataIconStyle::icon()
const
181 if (!d->m_icon.isNull()) {
183 }
else if (!d->m_iconPath.isEmpty()) {
184 d->m_icon = d->loadIcon(resolvePath(d->m_iconPath), d->m_size);
190void GeoDataIconStyle::setHotSpot(
const QPointF &hotSpot, GeoDataHotSpot::Units xunits, GeoDataHotSpot::Units yunits)
192 d->m_hotSpot.setHotSpot(hotSpot, xunits, yunits);
195QPointF GeoDataIconStyle::hotSpot(GeoDataHotSpot::Units &xunits, GeoDataHotSpot::Units &yunits)
const
197 return d->m_hotSpot.hotSpot(xunits, yunits);
202 if (size == d->m_size && aspectRatioMode == d->m_aspectRatioMode) {
206 d->m_aspectRatioMode = aspectRatioMode;
208 if (!d->m_size.isNull() && !d->m_icon.isNull()) {
210 d->m_icon = d->m_icon.scaled(d->m_size);
211 }
else if (!d->m_iconPath.isEmpty()) {
214 d->m_scaledIcon =
QImage();
218QSize GeoDataIconStyle::size()
const
223void GeoDataIconStyle::setScale(
float scale)
226 d->m_scaledIcon =
QImage();
229float GeoDataIconStyle::scale()
const
234QImage GeoDataIconStyle::scaledIcon()
const
236 if (!d->m_scaledIcon.isNull()) {
237 return d->m_scaledIcon;
241 if (d->m_scale <= 0 || d->m_scale == 1.0) {
246 d->m_scaledIcon = d->loadIcon(resolvePath(d->m_iconPath), d->scaledSize(d->m_size));
248 if (d->m_scaledIcon.isNull()) {
250 QImage const image = icon();
252 QSize iconSize = d->scaledSize(image.
size());
256 return d->m_scaledIcon;
259int GeoDataIconStyle::heading()
const
264void GeoDataIconStyle::setHeading(
int heading)
266 d->m_heading = heading;
269RemoteIconLoader *GeoDataIconStyle::remoteIconLoader()
const
271 return d->remoteIconLoader();
274void GeoDataIconStyle::pack(
QDataStream &stream)
const
276 GeoDataColorStyle::pack(stream);
278 stream << d->m_scale;
280 d->m_hotSpot.pack(stream);
285 GeoDataColorStyle::unpack(stream);
287 stream >> d->m_scale;
289 d->m_hotSpot.unpack(stream);
QString path(const QString &relativePath)
bool isValid(QStringView ifopt)
bool operator==(const StyleDelim &l, const StyleDelim &r)
Binds a QML item to a specific geodetic location in screen coordinates.
bool isNull() const const
QImage scaled(const QSize &size, Qt::AspectRatioMode aspectRatioMode, Qt::TransformationMode transformMode) const const
QString errorString() const const
void setFileName(const QString &fileName)
void setScaledSize(const QSize &size)
bool isNull() const const
void scale(const QSize &size, Qt::AspectRatioMode mode)
QSize scaled(const QSize &s, Qt::AspectRatioMode mode) const const
bool isEmpty() const const