27 lines
782 B
C++
27 lines
782 B
C++
#include "QGraphicsMovieItem.h"
|
|
|
|
QGraphicsMovieItem::QGraphicsMovieItem(QGraphicsItem *parent) : QGraphicsItem(parent) {}
|
|
|
|
void QGraphicsMovieItem::setMovie(QMovie* movie) {
|
|
prepareGeometryChange();
|
|
QObject::disconnect(mConnection);
|
|
mMovie = movie;
|
|
if (mMovie) {
|
|
mConnection = QObject::connect(mMovie, &QMovie::frameChanged, [=]{ update(); });
|
|
}
|
|
}
|
|
|
|
QRectF QGraphicsMovieItem::boundingRect() const {
|
|
if (mMovie) { return mMovie->frameRect(); }
|
|
else { return QRectF(); }
|
|
}
|
|
|
|
void QGraphicsMovieItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) {
|
|
Q_UNUSED(option)
|
|
Q_UNUSED(widget)
|
|
if (mMovie) {
|
|
painter->drawPixmap(mMovie->frameRect(), mMovie->currentPixmap(), mMovie->frameRect());
|
|
|
|
}
|
|
}
|