Animated icon in memcard editor (#3526)

pull/3527/head
Ariel Nogueira Kovaljski 2 months ago committed by GitHub
parent 19f17007ec
commit 645344b8ff
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -32,6 +32,7 @@ static constexpr std::array<std::pair<ConsoleRegion, const char*>, 3> MEMORY_CAR
{ConsoleRegion::NTSC_J, "BI"},
{ConsoleRegion::PAL, "BE"},
}};
static constexpr int MEMORY_CARD_ICON_FRAME_DURATION_MS = 200;
MemoryCardEditorWindow::MemoryCardEditorWindow() : QWidget()
{
@ -282,13 +283,35 @@ void MemoryCardEditorWindow::updateCardTable(Card* card)
if (!fi.icon_frames.empty())
{
const QImage image(reinterpret_cast<const u8*>(fi.icon_frames[0].pixels), MemoryCardImage::ICON_WIDTH,
MemoryCardImage::ICON_HEIGHT, QImage::Format_RGBA8888);
std::shared_ptr<QVector<QPixmap>> pixmaps = std::make_shared<QVector<QPixmap>>();
QTableWidgetItem* icon = new QTableWidgetItem();
setCardTableItemProperties(icon, fi);
icon->setIcon(QIcon(QPixmap::fromImage(image)));
card->table->setItem(row, 0, icon);
for (const auto& icon_frame : fi.icon_frames) {
const QImage image(reinterpret_cast<const u8*>(icon_frame.pixels), MemoryCardImage::ICON_WIDTH,
MemoryCardImage::ICON_HEIGHT, QImage::Format_RGBA8888);
QPixmap pixmap = QPixmap::fromImage(image.copy()).scaledToHeight(
MemoryCardImage::ICON_HEIGHT * 2,
Qt::FastTransformation
);
pixmaps->append(pixmap);
}
QLabel* icon = new QLabel;
icon->setPixmap((*pixmaps).first());
card->table->setCellWidget(row, 0, icon);
card->table->resizeRowToContents(row);
card->table->resizeColumnToContents(0);
QTimer* timer = new QTimer(icon);
std::shared_ptr<int> frame = std::make_shared<int>(0);
connect(timer, &QTimer::timeout, icon, [=]() {
icon->setPixmap((*pixmaps)[*frame]);
*frame = (*frame + 1) % pixmaps->size();
});
timer->start(MEMORY_CARD_ICON_FRAME_DURATION_MS);
}
QString title_str(QString::fromStdString(fi.title));

@ -31,8 +31,8 @@
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
<width>32</width>
<height>32</height>
</size>
</property>
<attribute name="horizontalHeaderShowSortIndicator" stdset="0">
@ -188,8 +188,8 @@
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
<width>32</width>
<height>32</height>
</size>
</property>
<attribute name="horizontalHeaderShowSortIndicator" stdset="0">

Loading…
Cancel
Save