From 2459224c7e68c2eb384aa104982635c98eb6a038 Mon Sep 17 00:00:00 2001 From: momen Date: Wed, 1 Oct 2025 22:18:56 +0800 Subject: [PATCH] =?UTF-8?q?chore:=E6=B7=BB=E5=8A=A0=E5=BF=BD=E7=95=A5?= =?UTF-8?q?=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/appdelegate.cpp | 42 ++++++++++++++++++++++++++++++------------ src/appdelegate.h | 1 + src/mainwindow.cpp | 21 +++++++++++++++++++++ src/mainwindow.h | 3 +++ 4 files changed, 55 insertions(+), 12 deletions(-) diff --git a/src/appdelegate.cpp b/src/appdelegate.cpp index 8a58a46..e29ee8d 100644 --- a/src/appdelegate.cpp +++ b/src/appdelegate.cpp @@ -123,14 +123,14 @@ void AppDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, c progressBarOption.textVisible = true; 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->setBrush(QColor("#ff4444")); - painter->drawRoundedRect(buttonRect, 4, 4); + painter->drawRoundedRect(cancelButtonRect, 4, 4); painter->setPen(Qt::white); painter->setFont(option.font); - painter->drawText(buttonRect, Qt::AlignCenter, "取消"); + painter->drawText(cancelButtonRect, Qt::AlignCenter, "取消"); } else if (isInstalling) { 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->drawText(textRect, Qt::AlignLeft | Qt::AlignVCenter, "正在安装中"); } 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); if (isInstalled) { painter->setBrush(QColor("#10B981")); - painter->drawRoundedRect(buttonRect, 4, 4); + painter->drawRoundedRect(updateButtonRect, 4, 4); painter->setPen(Qt::white); - painter->drawText(buttonRect, Qt::AlignCenter, "已安装"); + painter->drawText(updateButtonRect, Qt::AlignCenter, "已安装"); } else if (m_downloads.contains(packageName) && !m_downloads[packageName].isDownloading) { painter->setBrush(QColor("#10B981")); - painter->drawRoundedRect(buttonRect, 4, 4); + painter->drawRoundedRect(updateButtonRect, 4, 4); painter->setPen(Qt::white); - painter->drawText(buttonRect, Qt::AlignCenter, "下载完成"); + painter->drawText(updateButtonRect, Qt::AlignCenter, "下载完成"); } else { painter->setBrush(QColor("#e9effd")); - painter->drawRoundedRect(buttonRect, 4, 4); + painter->drawRoundedRect(updateButtonRect, 4, 4); 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; } } 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) { return false; } diff --git a/src/appdelegate.h b/src/appdelegate.h index 09d0ea6..15972c1 100644 --- a/src/appdelegate.h +++ b/src/appdelegate.h @@ -38,6 +38,7 @@ public: signals: void updateDisplay(const QString &packageName); void updateFinished(bool success); //传递是否完成更新 + void ignoreApp(const QString &packageName, const QString &version); // 新增:忽略应用信号 private slots: void updateSpinner(); // 新增槽函数 diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index ed12d2b..aa3fa03 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -12,6 +12,7 @@ MainWindow::MainWindow(QWidget *parent) , ui(new Ui::MainWindow) , m_model(new AppListModel(this)) , m_delegate(new AppDelegate(this)) + , m_ignoreConfig(new IgnoreConfig(this)) { QIcon icon(":/resources/128*128/spark-update-tool.png"); setWindowIcon(icon); @@ -53,6 +54,9 @@ MainWindow::MainWindow(QWidget *parent) } }); + // 连接忽略应用信号 + connect(m_delegate, &AppDelegate::ignoreApp, this, &MainWindow::onIgnoreApp); + // 新增:点击“更新全部”按钮批量下载 connect(ui->updatePushButton, &QPushButton::clicked, this, [=](){ qDebug()<<"更新按钮被点击"; @@ -309,4 +313,21 @@ void MainWindow::updateButtonText() { // 新增:处理选择变化 void MainWindow::handleSelectionChanged() { 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); } \ No newline at end of file diff --git a/src/mainwindow.h b/src/mainwindow.h index 7a44f7a..c00714b 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -5,6 +5,7 @@ #include "aptssupdater.h" #include "applistmodel.h" #include "appdelegate.h" +#include "ignoreconfig.h" #include #include // 添加头文件 #include @@ -32,6 +33,7 @@ private: void runAptssUpgrade(); AppListModel *m_model; AppDelegate *m_delegate; + IgnoreConfig *m_ignoreConfig; // 新增:忽略配置管理 QListView *listView; // 声明 QListView 指针 QJsonArray m_allApps; // 新增:保存所有应用数据 void filterAppsByKeyword(const QString &keyword); // 新增:搜索过滤函数声明 @@ -40,5 +42,6 @@ private: private slots: void handleUpdateFinished(bool success); // 新增:处理更新完成的槽函数 void handleSelectionChanged(); // 新增:处理选择变化的槽函数 + void onIgnoreApp(const QString &packageName, const QString &version); // 新增:处理忽略应用的槽函数 }; #endif // MAINWINDOW_H \ No newline at end of file