{
d->clearContents();
if (!movie)
return;
d->movie = movie;
connect(movie,
SIGNAL(resized
(QSize)),
this,
SLOT(_q_movieResized
(QSize)));
connect(movie,
SIGNAL(updated
(QRect)),
this,
SLOT(_q_movieUpdated
(QRect)));
// Assume that if the movie is running,
// resize/update signals will come soon enough
if (movie
->state
() != QMovie::Running) d->updateLabel();
}
void QLabelPrivate::_q_movieUpdated(const QRect& rect)
{
if (movie && movie->isValid()) {
if (scaledcontents) {
QRect cr
= q
->contentsRect
();
QRect pixmapRect
(cr.
topLeft(), movie
->currentPixmap
().
size());
if (pixmapRect.isEmpty())
return;
r.setRect(cr.left(), cr.top(),
(rect.width() * cr.width()) / pixmapRect.width(),
(rect.height() * cr.height()) / pixmapRect.height());
} else {
r = q->style()->itemPixmapRect(q->contentsRect(), align, movie->currentPixmap());
r.translate(rect.x(), rect.y());
r.setWidth(qMin(r.width(), rect.width()));
r.setHeight(qMin(r.height(), rect.height()));
}
q->update(r);
}
}
void QLabelPrivate::_q_movieResized(const QSize& size)
{
valid_hints = false;
q->updateGeometry();
}
{
drawFrame(&painter);
QRect cr
= contentsRect
();
cr.adjust(d->margin, d->margin, -d->margin, -d->margin);
int align
= QStyle::visualAlignment(layoutDirection
(),
QFlag(d
->align
));
#ifndef QT_NO_MOVIE
if (d->movie) {
if (d->scaledcontents)
style->drawItemPixmap(&painter, cr, align, d->movie->currentPixmap().scaled(cr.size()));
else
style->drawItemPixmap(&painter, cr, align, d->movie->currentPixmap());
}
... snip...
void QLabel::setMovie(QMovie *movie)
{
Q_D(QLabel);
d->clearContents();
if (!movie)
return;
d->movie = movie;
connect(movie, SIGNAL(resized(QSize)), this, SLOT(_q_movieResized(QSize)));
connect(movie, SIGNAL(updated(QRect)), this, SLOT(_q_movieUpdated(QRect)));
// Assume that if the movie is running,
// resize/update signals will come soon enough
if (movie->state() != QMovie::Running)
d->updateLabel();
}
void QLabelPrivate::_q_movieUpdated(const QRect& rect)
{
Q_Q(QLabel);
if (movie && movie->isValid()) {
QRect r;
if (scaledcontents) {
QRect cr = q->contentsRect();
QRect pixmapRect(cr.topLeft(), movie->currentPixmap().size());
if (pixmapRect.isEmpty())
return;
r.setRect(cr.left(), cr.top(),
(rect.width() * cr.width()) / pixmapRect.width(),
(rect.height() * cr.height()) / pixmapRect.height());
} else {
r = q->style()->itemPixmapRect(q->contentsRect(), align, movie->currentPixmap());
r.translate(rect.x(), rect.y());
r.setWidth(qMin(r.width(), rect.width()));
r.setHeight(qMin(r.height(), rect.height()));
}
q->update(r);
}
}
void QLabelPrivate::_q_movieResized(const QSize& size)
{
Q_Q(QLabel);
valid_hints = false;
_q_movieUpdated(QRect(QPoint(0,0), size));
q->updateGeometry();
}
void QLabel::paintEvent(QPaintEvent *)
{
Q_D(QLabel);
QStyle *style = QWidget::style();
QPainter painter(this);
drawFrame(&painter);
QRect cr = contentsRect();
cr.adjust(d->margin, d->margin, -d->margin, -d->margin);
int align = QStyle::visualAlignment(layoutDirection(), QFlag(d->align));
#ifndef QT_NO_MOVIE
if (d->movie) {
if (d->scaledcontents)
style->drawItemPixmap(&painter, cr, align, d->movie->currentPixmap().scaled(cr.size()));
else
style->drawItemPixmap(&painter, cr, align, d->movie->currentPixmap());
}
... snip...
To copy to clipboard, switch view to plain text mode
Bookmarks