oopapidocs  2.0
activity.cpp
00001 #include "activity.h"
00002 #include <QtGui>
00003 
00004 static QHash<QString, QIcon> icons;
00005 
00006 QMovie* getMovie() {
00007     static QMovie* movie = 0;
00008     if (movie == 0) {
00009         movie = new QMovie(":/icons/activity.gif", "gif", qApp);
00010         movie->start();
00011     }
00012     return movie;
00013 }
00014 
00015 QIcon getCurrentIcon() {
00016     QMovie* movie = getMovie();
00017     int idx = movie->currentFrameNumber();
00018     QString key = QString("%1").arg(idx);
00019     if (!icons.contains(key)) {
00020         QPixmap pm = movie->currentPixmap();
00021         QIcon retval(pm);
00022         icons[key] = retval;
00023     }
00024     return icons[key];
00025 }
00026 
00027 ActivityButton::ActivityButton(QString text, QWidget* parent)
00028 : QPushButton(text, parent), m_isActive(false) {
00029     setIcon(QIcon(":/icons/inactive.png"));   
00030 }
00031 
00032 void ActivityButton::setActive(bool isActive) {
00033     if (m_isActive == isActive) return;
00034     m_isActive = isActive;
00035     if (isActive) {
00036         connect (getMovie(), SIGNAL(frameChanged(int)),
00037             this, SLOT(updateIcon()), Qt::UniqueConnection);
00038     }
00039     else {
00040         disconnect (getMovie(), 0, this, 0);
00041         setIcon(QIcon(":/icons/inactive.png"));
00042     }
00043 }
00044 
00045 void ActivityButton::updateIcon() {
00046     setIcon(getCurrentIcon());   
00047 }
 All Classes Namespaces Functions Enumerations