QGIS API Documentation  3.20.0-Odense (decaadbb31)
qgsanimatedicon.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsanimatedicon.cpp - QgsAnimatedIcon
3 
4  ---------------------
5  begin : 13.3.2017
6  copyright : (C) 2017 by Matthias Kuhn
7  email : [email protected]
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 
17 #include "qgsanimatedicon.h"
18 
19 QgsAnimatedIcon::QgsAnimatedIcon( const QString &iconPath, QObject *parent )
20  : QObject( parent )
21  , mMovie( new QMovie( this ) )
22 {
23  if ( !iconPath.isEmpty() )
24  {
25  mMovie->setFileName( iconPath );
26  }
27  mMovie->setCacheMode( QMovie::CacheAll );
28  connect( mMovie, &QMovie::frameChanged, this, &QgsAnimatedIcon::onFrameChanged );
29 }
30 
32 {
33  return mMovie->fileName();
34 }
35 
36 void QgsAnimatedIcon::setIconPath( const QString &iconPath )
37 {
38  mMovie->setFileName( iconPath );
39 }
40 
41 QIcon QgsAnimatedIcon::icon() const
42 {
43  return mIcon;
44 }
45 
46 bool QgsAnimatedIcon::connectFrameChanged( const QObject *receiver, const char *method )
47 {
48  if ( connect( this, SIGNAL( frameChanged() ), receiver, method ) )
49  {
50  mMovie->setPaused( false );
51  return true;
52  }
53  else
54  return false;
55 }
56 
57 bool QgsAnimatedIcon::disconnectFrameChanged( const QObject *receiver, const char *method )
58 {
59  return disconnect( this, SIGNAL( frameChanged() ), receiver, method );
60 }
61 
63 {
64  return mMovie->currentPixmap().width();
65 }
66 
68 {
69  return mMovie->currentPixmap().height();
70 }
71 void QgsAnimatedIcon::onFrameChanged()
72 {
73  if ( !isSignalConnected( QMetaMethod::fromSignal( &QgsAnimatedIcon::frameChanged ) ) )
74  mMovie->setPaused( true );
75 
76  mIcon = QIcon( mMovie->currentPixmap() );
77  emit frameChanged();
78 }
bool disconnectFrameChanged(const typename QtPrivate::FunctionPointer< Func1 >::Object *receiver, Func1 slot)
Convenience function to disconnect the same style that the frame change connection was established.
void frameChanged()
Emitted when the icon changed.
QgsAnimatedIcon(const QString &iconPath=QString(), QObject *parent=nullptr)
Create a new animated icon.
int height() const
The native height of the icon.
int width() const
The native width of the icon.
bool connectFrameChanged(const typename QtPrivate::FunctionPointer< Func1 >::Object *receiver, Func1 slot)
Connect a slot that will be notified repeatedly whenever a frame changes and which should request the...
void setIconPath(const QString &iconPath)
Path to a movie, e.g.
QIcon icon() const
Gets the icons representation in the current frame.
QString iconPath() const
Path to a movie, e.g.