47 lines
1.1 KiB
C++
47 lines
1.1 KiB
C++
#include "SequenceFrame.h"
|
|
|
|
#include <QPainter>
|
|
|
|
SequenceFrame::SequenceFrame(const QStringList& paths, QWidget* parent)
|
|
: QWidget(parent) {
|
|
InitImageList(paths);
|
|
|
|
connect(&timer_, &QTimer::timeout, this, &SequenceFrame::OnTimeout);
|
|
timer_.start(80);
|
|
}
|
|
|
|
void SequenceFrame::Start() {
|
|
currentIndex_ = 0;
|
|
}
|
|
|
|
void SequenceFrame::paintEvent(QPaintEvent* event) {
|
|
if (imageList_.isEmpty()) {
|
|
return;
|
|
}
|
|
|
|
QPainter painter(this);
|
|
|
|
const QPixmap& image = imageList_.at(currentIndex_);
|
|
const QRect& r = rect();
|
|
painter.drawPixmap(r, image, image.rect());
|
|
|
|
//QString text = QString("x:%1, y:%2").arg(r.x()).arg(r.y());
|
|
//painter.drawText(r.bottomRight(), text);
|
|
}
|
|
|
|
void SequenceFrame::InitImageList(const QStringList& paths) {
|
|
for (const QString& path : paths) {
|
|
QPixmap pixmap(path);
|
|
if (!pixmap.isNull()) {
|
|
imageList_.append(pixmap);
|
|
}
|
|
}
|
|
}
|
|
|
|
void SequenceFrame::OnTimeout() {
|
|
currentIndex_ = (currentIndex_ + 1) % imageList_.size();
|
|
//const QPixmap& image = imageList_.at(currentIndex_);
|
|
// setMask(image.mask());
|
|
update();
|
|
}
|