LCOV - code coverage report
Current view: top level - core - qgsanimatedicon.h (source / functions) Hit Total Coverage
Test: coverage.info.cleaned Lines: 0 8 0.0 %
Date: 2021-03-26 12:19:53 Functions: 0 0 -
Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /***************************************************************************
       2                 :            :   qgsanimatedicon.h - QgsAnimatedIcon
       3                 :            : 
       4                 :            :  ---------------------
       5                 :            :  begin                : 13.3.2017
       6                 :            :  copyright            : (C) 2017 by Matthias Kuhn
       7                 :            :  email                : matthias@opengis.ch
       8                 :            :  ***************************************************************************
       9                 :            :  *                                                                         *
      10                 :            :  *   This program is free software; you can redistribute it and/or modify  *
      11                 :            :  *   it under the terms of the GNU General Public License as published by  *
      12                 :            :  *   the Free Software Foundation; either version 2 of the License, or     *
      13                 :            :  *   (at your option) any later version.                                   *
      14                 :            :  *                                                                         *
      15                 :            :  ***************************************************************************/
      16                 :            : #ifndef QGSANIMATEDICON_H
      17                 :            : #define QGSANIMATEDICON_H
      18                 :            : 
      19                 :            : #include <QObject>
      20                 :            : #include <QMovie>
      21                 :            : #include <QIcon>
      22                 :            : #include <QMetaMethod>
      23                 :            : 
      24                 :            : #include "qgis_core.h"
      25                 :            : 
      26                 :            : /**
      27                 :            :  * \ingroup core
      28                 :            :  * \brief Animated icon is keeping an animation running if there are listeners connected to frameChanged
      29                 :            : */
      30                 :            : class CORE_EXPORT QgsAnimatedIcon : public QObject
      31                 :            : {
      32                 :            :     Q_OBJECT
      33                 :            :   public:
      34                 :            : 
      35                 :            :     /**
      36                 :            :      * Create a new animated icon. Optionally, the \a iconPath can already be specified.
      37                 :            :      */
      38                 :            :     QgsAnimatedIcon( const QString &iconPath = QString(), QObject *parent = nullptr );
      39                 :            : 
      40                 :            :     /**
      41                 :            :      * Path to a movie, e.g. animated GIF
      42                 :            :      */
      43                 :            :     QString iconPath() const;
      44                 :            : 
      45                 :            :     /**
      46                 :            :      * Path to a movie, e.g. animated GIF
      47                 :            :      */
      48                 :            :     void setIconPath( const QString &iconPath );
      49                 :            : 
      50                 :            :     /**
      51                 :            :      * Gets the icons representation in the current frame.
      52                 :            :      * This will need to be called repeatedly, whenever a frameChanged()
      53                 :            :      * signal is emitted.
      54                 :            :      */
      55                 :            :     QIcon icon() const;
      56                 :            : 
      57                 :            : #ifndef SIP_RUN
      58                 :            : 
      59                 :            :     /**
      60                 :            :      * Connect a slot that will be notified repeatedly whenever a frame changes and which should
      61                 :            :      * request the current icon and trigger UI updates.
      62                 :            :      *
      63                 :            :      * Connect to the frame changed signal with this method and not directly. This method
      64                 :            :      * makes sure the annimation is started.
      65                 :            :      *
      66                 :            :      * \note Available in Python bindings as
      67                 :            :      *       bool connectFrameChanged( const QObject *receiver, const char *method );.
      68                 :            :      * \since QGIS 3.0
      69                 :            :      */
      70                 :            :     template <typename Func1>
      71                 :          0 :     bool connectFrameChanged( const typename QtPrivate::FunctionPointer<Func1>::Object *receiver, Func1 slot )
      72                 :            :     {
      73                 :          0 :       if ( connect( this, &QgsAnimatedIcon::frameChanged, receiver, slot ) )
      74                 :            :       {
      75                 :          0 :         mMovie->setPaused( false );
      76                 :          0 :         return true;
      77                 :            :       }
      78                 :            :       else
      79                 :          0 :         return false;
      80                 :          0 :     }
      81                 :            : 
      82                 :            :     /**
      83                 :            :      * Convenience function to disconnect the same style that the frame change connection was established.
      84                 :            :      *
      85                 :            :      * \note Available in Python bindings as
      86                 :            :      *       bool disconnectFrameChanged( const QObject *receiver, const char *method );.
      87                 :            :      * \since QGIS 3.0
      88                 :            :      */
      89                 :            :     template <typename Func1>
      90                 :          0 :     bool disconnectFrameChanged( const typename QtPrivate::FunctionPointer<Func1>::Object *receiver, Func1 slot )
      91                 :            :     {
      92                 :          0 :       return disconnect( this, &QgsAnimatedIcon::frameChanged, receiver, slot );
      93                 :            :     }
      94                 :            : 
      95                 :            : #endif
      96                 :            : 
      97                 :            :     /**
      98                 :            :      * Connect a slot that will be notified repeatedly whenever a frame changes and which should
      99                 :            :      * request the current icon and trigger UI updates.
     100                 :            :      *
     101                 :            :      * Connect to the frame changed signal with this method and not directly. This method
     102                 :            :      * makes sure the annimation is started.
     103                 :            :      *
     104                 :            :      * \since QGIS 3.0
     105                 :            :      */
     106                 :            :     bool connectFrameChanged( const QObject *receiver, const char *method );
     107                 :            : 
     108                 :            :     /**
     109                 :            :      * Convenience function to disconnect the same style that the frame change connection was established.
     110                 :            :      *
     111                 :            :      * \since QGIS 3.0
     112                 :            :      */
     113                 :            :     bool disconnectFrameChanged( const QObject *receiver, const char *method );
     114                 :            : 
     115                 :            : 
     116                 :            :     /**
     117                 :            :      * The native width of the icon.
     118                 :            :      *
     119                 :            :      * \since QGIS 3.0
     120                 :            :      */
     121                 :            :     int width() const;
     122                 :            : 
     123                 :            :     /**
     124                 :            :      * The native height of the icon.
     125                 :            :      *
     126                 :            :      * \since QGIS 3.0
     127                 :            :      */
     128                 :            :     int height() const;
     129                 :            : 
     130                 :            :   signals:
     131                 :            : 
     132                 :            :     /**
     133                 :            :      * Emitted when the icon changed. You should use connectFrameChanged instead of connecting
     134                 :            :      * to this signal directly.
     135                 :            :      * Connecting to this signal directly will cause the animation not to be started.
     136                 :            :      *
     137                 :            :      * \see connectFrameChanged
     138                 :            :      */
     139                 :            :     void frameChanged();
     140                 :            : 
     141                 :            :   private slots:
     142                 :            :     void onFrameChanged();
     143                 :            : 
     144                 :            :   private:
     145                 :            :     QMovie *mMovie = nullptr;
     146                 :            :     QIcon mIcon;
     147                 :            : };
     148                 :            : 
     149                 :            : #endif // QGSANIMATEDICON_H

Generated by: LCOV version 1.14