34 class KAnimatedButtonPrivate
42 void updateCurrentIcon();
43 void _k_movieFrameChanged(
int number);
44 void _k_movieFinished();
54 QVector<QPixmap*> framesCache;
60 :
QToolButton(parent), d(new KAnimatedButtonPrivate(this))
68 qDeleteAll(d->framesCache);
88 d->movie->jumpToFrame(0);
89 d->_k_movieFrameChanged(0);
93 d->updateCurrentIcon();
99 if ( d->icon_name == icons )
103 d->icon_name =
icons;
118 if (d->current_frame == d->frames)
119 d->current_frame = 0;
121 d->updateCurrentIcon();
124 void KAnimatedButtonPrivate::updateCurrentIcon()
129 QPixmap* frame = framesCache[current_frame];
132 const int icon_size = q->iconDimensions();
133 const int row_size = pixmap.width() / icon_size;
134 const int row = current_frame / row_size;
135 const int column = current_frame % row_size;
136 frame =
new QPixmap(icon_size, icon_size);
137 frame->fill(Qt::transparent);
139 p.drawPixmap(
QPoint(0, 0), pixmap,
QRect(column * icon_size, row * icon_size, icon_size, icon_size));
141 framesCache[current_frame] = frame;
144 q->setIcon(QIcon(*frame));
147 void KAnimatedButtonPrivate::_k_movieFrameChanged(
int number)
150 q->setIcon(QIcon(movie->currentPixmap()));
153 void KAnimatedButtonPrivate::_k_movieFinished()
156 if (movie->state() == QMovie::NotRunning) {
164 d->pixmap = QPixmap();
168 movie->setCacheMode(QMovie::CacheAll);
169 connect(movie, SIGNAL(frameChanged(
int)),
this, SLOT(_k_movieFrameChanged(
int)));
170 connect(movie, SIGNAL(finished()),
this, SLOT(_k_movieFinished()));
177 if ((img.width() % icon_size != 0) || (img.height() % icon_size != 0))
180 d->frames = (img.height() / icon_size) * (img.width() / icon_size);
181 d->pixmap = QPixmap::fromImage(img);
184 d->current_frame = 0;
185 qDeleteAll(d->framesCache);
186 d->framesCache.fill(0);
187 d->framesCache.resize(d->frames);
192 d->movie->jumpToFrame(0);
193 d->_k_movieFrameChanged(0);
195 d->updateCurrentIcon();
201 return qMin(iconSize().width(), iconSize().height());
204 #include "kanimatedbutton.moc"