Files
spark-store/spark-update-tool/src/appdelegate.h
momen bc97519124 Add 'spark-update-tool/' from commit 'e5217b3829f4732887140066e6c3d33a120dc9da'
git-subtree-dir: spark-update-tool
git-subtree-mainline: 286f34f3f8
git-subtree-split: e5217b3829
2025-08-29 23:09:01 +08:00

47 lines
1.4 KiB
C++

#pragma once
#include <QStyledItemDelegate>
#include <QHash>
#include <QQueue>
#include <QProcess>
#include <QElapsedTimer>
#include "downloadmanager.h"
struct DownloadInfo {
int progress = 0;
bool isDownloading = false;
bool isInstalled = false;
bool isInstalling = false; // 新增:标记是否正在安装
};
class AppDelegate : public QStyledItemDelegate {
Q_OBJECT
public:
explicit AppDelegate(QObject *parent = nullptr);
void setModel(QAbstractItemModel *model);
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override;
bool editorEvent(QEvent *event, QAbstractItemModel *model,
const QStyleOptionViewItem &option, const QModelIndex &index) override;
void startDownloadForAll();
signals:
void updateDisplay(const QString &packageName);
private:
DownloadManager *m_downloadManager;
QHash<QString, DownloadInfo> m_downloads;
QAbstractItemModel *m_model = nullptr;
QQueue<QString> m_installQueue;
bool m_isInstalling = false;
QProcess *m_installProcess = nullptr;
QString m_installingPackage; // 当前正在安装的包名
QElapsedTimer m_spinnerTimer; // 用于转圈动画
void enqueueInstall(const QString &packageName);
void startNextInstall();
};