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()) { if (!path.isEmpty()) {
openFolderPath(path); 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() Dialog::~Dialog()
@ -259,6 +270,10 @@ void Dialog::openFolderPath(QString path)
void Dialog::showCursor(QTreeWidgetItem *current, QTreeWidgetItem *previous) void Dialog::showCursor(QTreeWidgetItem *current, QTreeWidgetItem *previous)
{ {
previewCursorTime.stop();
previewCursor.clear();
previewIndex = 0;
if (!current) { if (!current) {
ui->teCursorInfo->clear(); ui->teCursorInfo->clear();
return; return;
@ -306,11 +321,14 @@ void Dialog::showCursor(QTreeWidgetItem *current, QTreeWidgetItem *previous)
QByteArray imgBa; QByteArray imgBa;
QBuffer buffer(&imgBa); QBuffer buffer(&imgBa);
cursor.image.save(&buffer, "PNG"); cursor.image.save(&buffer, "PNG");
previewCursor.append(cursor.image.copy());
imgBa = imgBa.toBase64(); imgBa = imgBa.toBase64();
currentCursorFile.cachedCursors += "<img src=\"data:image/png;base64, " + QSL(imgBa) + "\"/>"; currentCursorFile.cachedCursors += "<img src=\"data:image/png;base64, " + QSL(imgBa) + "\"/>";
} }
// previewCursor = cursorList;
currentCursorFile.cachedCursors += "</p>"; currentCursorFile.cachedCursors += "</p>";
} }
@ -326,6 +344,7 @@ void Dialog::showCursor(QTreeWidgetItem *current, QTreeWidgetItem *previous)
} }
} }
previewCursorTime.start();
ui->teCursorInfo->setHtml(currentCursorFile.cachedCursors); ui->teCursorInfo->setHtml(currentCursorFile.cachedCursors);
} }

View File

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

View File

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