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