QGIS API Documentation 3.41.0-Master (cea29feecf2)
Loading...
Searching...
No Matches
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
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#include "moc_qgsanimatedicon.cpp"
19
20QgsAnimatedIcon::QgsAnimatedIcon( const QString &iconPath, QObject *parent )
21 : QObject( parent )
22 , mMovie( new QMovie( this ) )
23{
24 if ( !iconPath.isEmpty() )
25 {
26 mMovie->setFileName( iconPath );
27 }
28 mMovie->setCacheMode( QMovie::CacheAll );
29 connect( mMovie, &QMovie::frameChanged, this, &QgsAnimatedIcon::onFrameChanged );
30}
31
33{
34 return mMovie->fileName();
35}
36
37void QgsAnimatedIcon::setIconPath( const QString &iconPath )
38{
39 mMovie->setFileName( iconPath );
40}
41
43{
44 return mIcon;
45}
46
47bool QgsAnimatedIcon::connectFrameChanged( const QObject *receiver, const char *method )
48{
49 if ( connect( this, SIGNAL( frameChanged() ), receiver, method ) )
50 {
51 mMovie->setPaused( false );
52 return true;
53 }
54 else
55 return false;
56}
57
58bool QgsAnimatedIcon::disconnectFrameChanged( const QObject *receiver, const char *method )
59{
60 return disconnect( this, SIGNAL( frameChanged() ), receiver, method );
61}
62
64{
65 return mMovie->currentPixmap().width();
66}
67
69{
70 return mMovie->currentPixmap().height();
71}
72void QgsAnimatedIcon::onFrameChanged()
73{
74 if ( !isSignalConnected( QMetaMethod::fromSignal( &QgsAnimatedIcon::frameChanged ) ) )
75 mMovie->setPaused( true );
76
77 mIcon = QIcon( mMovie->currentPixmap() );
78 emit frameChanged();
79}
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.