File indexing completed on 2024-05-12 03:50:12

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2007 Murad Tagirov <tmurad@gmail.com>
0004 // SPDX-FileCopyrightText: 2007 Inge Wallin <ingwa@kde.org>
0005 //
0006 
0007 
0008 #ifndef MARBLE_GEODATAICONSTYLE_H
0009 #define MARBLE_GEODATAICONSTYLE_H
0010 
0011 
0012 #include "GeoDataColorStyle.h"
0013 #include "GeoDataHotSpot.h"
0014 
0015 #include "geodata_export.h"
0016 
0017 #include <QSize>
0018 
0019 namespace Marble
0020 {
0021 
0022 class GeoDataIconStylePrivate;
0023 class RemoteIconLoader;
0024 
0025 // Limits for the user in case of scaling the icon too much
0026 static const QSize s_maximumIconSize = QSize( 100, 100 );
0027 static const QSize s_minimumIconSize = QSize( 10, 10 );
0028 
0029 /**
0030  */
0031 class GEODATA_EXPORT GeoDataIconStyle : public GeoDataColorStyle
0032 {
0033   public:
0034     GeoDataIconStyle();
0035     GeoDataIconStyle( const GeoDataIconStyle& other );
0036     explicit GeoDataIconStyle( const QString& iconPath,
0037                                const QPointF &hotSpot = QPointF( 0.5, 0.5 ) );
0038     ~GeoDataIconStyle() override;
0039 
0040     GeoDataIconStyle& operator=( const GeoDataIconStyle& other );
0041 
0042     bool operator==( const GeoDataIconStyle &other ) const;
0043     bool operator!=( const GeoDataIconStyle &other ) const;
0044 
0045     /// Provides type information for downcasting a GeoData
0046     const char* nodeType() const override;
0047 
0048     void setIcon( const QImage& icon );
0049     QImage icon() const;
0050 
0051     /**
0052      * @brief Returns a scaled version of label icon
0053      * @return  the scaled icon
0054      */
0055     QImage scaledIcon() const;
0056 
0057     /**
0058      * @brief setIconPath Set the path to load the icon from. Any existing icon is invalidated.
0059      * @param filename Path to the icon to load. Can also be a virtual file system like qrc:/
0060      */
0061     void setIconPath( const QString& filename );
0062     QString iconPath() const;
0063 
0064     void setHotSpot( const QPointF& hotSpot, GeoDataHotSpot::Units xunits, GeoDataHotSpot::Units yunits );
0065     QPointF hotSpot( GeoDataHotSpot::Units& xunits, GeoDataHotSpot::Units& yunits ) const;
0066 
0067     /**
0068      * @brief setSize Change the size of @see icon(). A null size (0, 0) is treated as a request to keep
0069      * the original icon size. Otherwise the icon will be scaled to the given size. This is especially useful
0070      * for vector graphics like .svg or to keep the memory footprint low when loading large images.
0071      * @param size Size in pixel that @see icon() should have. When the icon was previously set by #setIcon,
0072      * it is resized unless a null size is passed. Otherwise icon() will be scaled to the given size.
0073      * @param aspectRatioMode Aspect ratio mode.
0074      */
0075     void setSize(const QSize &size, Qt::AspectRatioMode aspectRatioMode=Qt::KeepAspectRatio);
0076 
0077     /**
0078      * @brief size Returns the size @see icon() will have if it can be loaded from @see iconPath.
0079      * A null size (default) is returned to indicate that the original size of the icon is used.
0080      * @return size specified by @see setSize
0081      */
0082     QSize size() const;
0083 
0084     void setScale(float scale);
0085     float scale() const;
0086 
0087     int heading() const;
0088     void setHeading( int heading );
0089     
0090     RemoteIconLoader *remoteIconLoader() const;
0091 
0092     /*
0093      * Serializable methods
0094      */
0095     void pack( QDataStream& stream ) const override;
0096     void unpack( QDataStream& stream ) override;
0097 
0098   private:
0099     GeoDataIconStylePrivate * const d;
0100 };
0101 
0102 }
0103 
0104 #endif