feat: 增加光标动画预览功能

This commit is contained in:
zinface 2023-11-09 11:38:23 +08:00
parent b5324a57af
commit ba1b81d1c9
3 changed files with 31 additions and 0 deletions

View File

@ -49,6 +49,17 @@ Dialog::Dialog(const QString& path, QWidget *parent)
if (!path.isEmpty()) {
openFolderPath(path);
}
previewCursorTime.setInterval(100);
connect(&previewCursorTime, &QTimer::timeout, this, [this](){
if (previewIndex < previewCursor.length()) {
QImage img = previewCursor[previewIndex];
ui->preview->setPixmap(QPixmap::fromImage(img));
previewIndex++;
} else {
previewIndex = 0;
}
});
}
Dialog::~Dialog()
@ -259,6 +270,10 @@ void Dialog::openFolderPath(QString path)
void Dialog::showCursor(QTreeWidgetItem *current, QTreeWidgetItem *previous)
{
previewCursorTime.stop();
previewCursor.clear();
previewIndex = 0;
if (!current) {
ui->teCursorInfo->clear();
return;
@ -306,11 +321,14 @@ void Dialog::showCursor(QTreeWidgetItem *current, QTreeWidgetItem *previous)
QByteArray imgBa;
QBuffer buffer(&imgBa);
cursor.image.save(&buffer, "PNG");
previewCursor.append(cursor.image.copy());
imgBa = imgBa.toBase64();
currentCursorFile.cachedCursors += "<img src=\"data:image/png;base64, " + QSL(imgBa) + "\"/>";
}
// previewCursor = cursorList;
currentCursorFile.cachedCursors += "</p>";
}
@ -326,6 +344,7 @@ void Dialog::showCursor(QTreeWidgetItem *current, QTreeWidgetItem *previous)
}
}
previewCursorTime.start();
ui->teCursorInfo->setHtml(currentCursorFile.cachedCursors);
}

View File

@ -24,6 +24,7 @@
#include <QList>
#include <QMultiMap>
#include <QString>
#include <QTimer>
#include <QTreeWidgetItem>
namespace Ui { class Dialog; }
@ -58,6 +59,10 @@ public:
void openFolderPath(QString path);
void showCursor(QTreeWidgetItem *current, QTreeWidgetItem *previous);
QList<QImage> previewCursor;
QTimer previewCursorTime;
int previewIndex;
private slots:
void on_pbExport_clicked();

View File

@ -59,6 +59,13 @@
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="preview">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
</item>