chore:添加忽略按钮

This commit is contained in:
2025-10-01 22:18:56 +08:00
parent 7b26c6dd9c
commit 2459224c7e
4 changed files with 55 additions and 12 deletions

View File

@@ -123,14 +123,14 @@ void AppDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, c
progressBarOption.textVisible = true; progressBarOption.textVisible = true;
QApplication::style()->drawControl(QStyle::CE_ProgressBar, &progressBarOption, painter); QApplication::style()->drawControl(QStyle::CE_ProgressBar, &progressBarOption, painter);
QRect buttonRect(rect.right() - 80, rect.top() + (rect.height() - 30) / 2, 70, 30); QRect cancelButtonRect(rect.right() - 80, rect.top() + (rect.height() - 30) / 2, 70, 30);
painter->setPen(Qt::NoPen); painter->setPen(Qt::NoPen);
painter->setBrush(QColor("#ff4444")); painter->setBrush(QColor("#ff4444"));
painter->drawRoundedRect(buttonRect, 4, 4); painter->drawRoundedRect(cancelButtonRect, 4, 4);
painter->setPen(Qt::white); painter->setPen(Qt::white);
painter->setFont(option.font); painter->setFont(option.font);
painter->drawText(buttonRect, Qt::AlignCenter, "取消"); painter->drawText(cancelButtonRect, Qt::AlignCenter, "取消");
} else if (isInstalling) { } else if (isInstalling) {
QRect spinnerRect(option.rect.right() - 80, option.rect.top() + (option.rect.height() - 30) / 2, 30, 30); QRect spinnerRect(option.rect.right() - 80, option.rect.top() + (option.rect.height() - 30) / 2, 30, 30);
@@ -146,23 +146,32 @@ void AppDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, c
painter->setFont(option.font); painter->setFont(option.font);
painter->drawText(textRect, Qt::AlignLeft | Qt::AlignVCenter, "正在安装中"); painter->drawText(textRect, Qt::AlignLeft | Qt::AlignVCenter, "正在安装中");
} else { } else {
QRect buttonRect(option.rect.right() - 80, option.rect.top() + (option.rect.height() - 30) / 2, 70, 30); // 绘制忽略按钮
QRect ignoreButtonRect(option.rect.right() - 160, option.rect.top() + (option.rect.height() - 30) / 2, 70, 30);
painter->setPen(Qt::NoPen);
painter->setBrush(QColor("#F3F4F6"));
painter->drawRoundedRect(ignoreButtonRect, 4, 4);
painter->setPen(QColor("#6B7280"));
painter->drawText(ignoreButtonRect, Qt::AlignCenter, "忽略");
// 绘制更新按钮
QRect updateButtonRect(option.rect.right() - 80, option.rect.top() + (option.rect.height() - 30) / 2, 70, 30);
painter->setPen(Qt::NoPen); painter->setPen(Qt::NoPen);
if (isInstalled) { if (isInstalled) {
painter->setBrush(QColor("#10B981")); painter->setBrush(QColor("#10B981"));
painter->drawRoundedRect(buttonRect, 4, 4); painter->drawRoundedRect(updateButtonRect, 4, 4);
painter->setPen(Qt::white); painter->setPen(Qt::white);
painter->drawText(buttonRect, Qt::AlignCenter, "已安装"); painter->drawText(updateButtonRect, Qt::AlignCenter, "已安装");
} else if (m_downloads.contains(packageName) && !m_downloads[packageName].isDownloading) { } else if (m_downloads.contains(packageName) && !m_downloads[packageName].isDownloading) {
painter->setBrush(QColor("#10B981")); painter->setBrush(QColor("#10B981"));
painter->drawRoundedRect(buttonRect, 4, 4); painter->drawRoundedRect(updateButtonRect, 4, 4);
painter->setPen(Qt::white); painter->setPen(Qt::white);
painter->drawText(buttonRect, Qt::AlignCenter, "下载完成"); painter->drawText(updateButtonRect, Qt::AlignCenter, "下载完成");
} else { } else {
painter->setBrush(QColor("#e9effd")); painter->setBrush(QColor("#e9effd"));
painter->drawRoundedRect(buttonRect, 4, 4); painter->drawRoundedRect(updateButtonRect, 4, 4);
painter->setPen(QColor("#2563EB")); painter->setPen(QColor("#2563EB"));
painter->drawText(buttonRect, Qt::AlignCenter, "更新"); painter->drawText(updateButtonRect, Qt::AlignCenter, "更新");
} }
} }
@@ -201,8 +210,17 @@ bool AppDelegate::editorEvent(QEvent *event, QAbstractItemModel *model,
return true; return true;
} }
} else { } else {
QRect buttonRect(rect.right() - 80, rect.top() + (rect.height() - 30) / 2, 70, 30); // 检查是否点击了忽略按钮
if (buttonRect.contains(mouseEvent->pos())) { QRect ignoreButtonRect(rect.right() - 160, rect.top() + (rect.height() - 30) / 2, 70, 30);
if (ignoreButtonRect.contains(mouseEvent->pos())) {
QString currentVersion = index.data(Qt::UserRole + 2).toString();
emit ignoreApp(packageName, currentVersion);
return true;
}
// 检查是否点击了更新按钮
QRect updateButtonRect(rect.right() - 80, rect.top() + (rect.height() - 30) / 2, 70, 30);
if (updateButtonRect.contains(mouseEvent->pos())) {
if (m_downloads.contains(packageName) && !m_downloads[packageName].isDownloading) { if (m_downloads.contains(packageName) && !m_downloads[packageName].isDownloading) {
return false; return false;
} }

View File

@@ -38,6 +38,7 @@ public:
signals: signals:
void updateDisplay(const QString &packageName); void updateDisplay(const QString &packageName);
void updateFinished(bool success); //传递是否完成更新 void updateFinished(bool success); //传递是否完成更新
void ignoreApp(const QString &packageName, const QString &version); // 新增:忽略应用信号
private slots: private slots:
void updateSpinner(); // 新增槽函数 void updateSpinner(); // 新增槽函数

View File

@@ -12,6 +12,7 @@ MainWindow::MainWindow(QWidget *parent)
, ui(new Ui::MainWindow) , ui(new Ui::MainWindow)
, m_model(new AppListModel(this)) , m_model(new AppListModel(this))
, m_delegate(new AppDelegate(this)) , m_delegate(new AppDelegate(this))
, m_ignoreConfig(new IgnoreConfig(this))
{ {
QIcon icon(":/resources/128*128/spark-update-tool.png"); QIcon icon(":/resources/128*128/spark-update-tool.png");
setWindowIcon(icon); setWindowIcon(icon);
@@ -53,6 +54,9 @@ MainWindow::MainWindow(QWidget *parent)
} }
}); });
// 连接忽略应用信号
connect(m_delegate, &AppDelegate::ignoreApp, this, &MainWindow::onIgnoreApp);
// 新增:点击“更新全部”按钮批量下载 // 新增:点击“更新全部”按钮批量下载
connect(ui->updatePushButton, &QPushButton::clicked, this, [=](){ connect(ui->updatePushButton, &QPushButton::clicked, this, [=](){
qDebug()<<"更新按钮被点击"; qDebug()<<"更新按钮被点击";
@@ -309,4 +313,21 @@ void MainWindow::updateButtonText() {
// 新增:处理选择变化 // 新增:处理选择变化
void MainWindow::handleSelectionChanged() { void MainWindow::handleSelectionChanged() {
updateButtonText(); updateButtonText();
}
// 新增:处理忽略应用的槽函数
void MainWindow::onIgnoreApp(const QString &packageName, const QString &version) {
// 将应用添加到忽略配置中
m_ignoreConfig->addIgnoredApp(packageName, version);
// 从模型中移除被忽略的应用
QJsonArray filteredApps;
for (const auto &item : m_allApps) {
QJsonObject obj = item.toObject();
if (obj["package"].toString() != packageName) {
filteredApps.append(item);
}
}
m_allApps = filteredApps;
m_model->setUpdateData(filteredApps);
} }

View File

@@ -5,6 +5,7 @@
#include "aptssupdater.h" #include "aptssupdater.h"
#include "applistmodel.h" #include "applistmodel.h"
#include "appdelegate.h" #include "appdelegate.h"
#include "ignoreconfig.h"
#include <QListView> #include <QListView>
#include <QJsonArray> // 添加头文件 #include <QJsonArray> // 添加头文件
#include <QScreen> #include <QScreen>
@@ -32,6 +33,7 @@ private:
void runAptssUpgrade(); void runAptssUpgrade();
AppListModel *m_model; AppListModel *m_model;
AppDelegate *m_delegate; AppDelegate *m_delegate;
IgnoreConfig *m_ignoreConfig; // 新增:忽略配置管理
QListView *listView; // 声明 QListView 指针 QListView *listView; // 声明 QListView 指针
QJsonArray m_allApps; // 新增:保存所有应用数据 QJsonArray m_allApps; // 新增:保存所有应用数据
void filterAppsByKeyword(const QString &keyword); // 新增:搜索过滤函数声明 void filterAppsByKeyword(const QString &keyword); // 新增:搜索过滤函数声明
@@ -40,5 +42,6 @@ private:
private slots: private slots:
void handleUpdateFinished(bool success); // 新增:处理更新完成的槽函数 void handleUpdateFinished(bool success); // 新增:处理更新完成的槽函数
void handleSelectionChanged(); // 新增:处理选择变化的槽函数 void handleSelectionChanged(); // 新增:处理选择变化的槽函数
void onIgnoreApp(const QString &packageName, const QString &version); // 新增:处理忽略应用的槽函数
}; };
#endif // MAINWINDOW_H #endif // MAINWINDOW_H