元数据页面风格调整

This commit is contained in:
taocong
2026-05-28 13:37:53 +08:00
parent 3e05ecd9d2
commit 5f3a8cc8dd
9 changed files with 290 additions and 207 deletions
+63 -36
View File
@@ -2,18 +2,46 @@
#include "src/utils/uf2configreader.h"
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QLabel>
#include <QGroupBox>
#include <QFile>
#include <QCoreApplication>
#include <QTableWidgetItem>
#include <QHeaderView>
#include <QMessageBox>
#include <QInputDialog>
#include <QDialog>
#include <QTextEdit>
#include <QStandardItem>
#include <QStyledItemDelegate>
#include <QPainter>
#include "src/utils/logmanager.h"
#include "ElaPushButton.h"
#include "ElaProgressBar.h"
#include "ElaText.h"
class StatusDelegate : public QStyledItemDelegate
{
public:
explicit StatusDelegate(QObject *parent = nullptr) : QStyledItemDelegate(parent) {}
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
{
QVariant bgColor = index.data(Qt::BackgroundRole);
QVariant fgColor = index.data(Qt::ForegroundRole);
QStyleOptionViewItem opt = option;
initStyleOption(&opt, index);
if (bgColor.canConvert<QBrush>()) {
painter->fillRect(opt.rect, bgColor.value<QBrush>());
}
if (fgColor.canConvert<QBrush>()) {
painter->setPen(fgColor.value<QBrush>().color());
}
painter->drawText(opt.rect, opt.displayAlignment, opt.text);
}
};
BatchConvertPage::BatchConvertPage(QWidget *parent)
: QWidget(parent)
@@ -36,9 +64,12 @@ void BatchConvertPage::initUI()
QVBoxLayout *funcLayout = new QVBoxLayout(funcBox);
funcLayout->setSpacing(10);
m_funcTable = new QTableWidget;
m_funcTable->setColumnCount(3);
m_funcTable->setHorizontalHeaderLabels({"UF20函数名", "是否存在", "操作"});
m_tableModel = new QStandardItemModel(this);
m_tableModel->setColumnCount(3);
m_tableModel->setHorizontalHeaderLabels({"UF20函数名", "是否存在", "操作"});
m_funcTable = new ElaTableView;
m_funcTable->setModel(m_tableModel);
m_funcTable->setMinimumHeight(200);
m_funcTable->setSelectionBehavior(QAbstractItemView::SelectRows);
m_funcTable->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Fixed);
@@ -46,6 +77,7 @@ void BatchConvertPage::initUI()
m_funcTable->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Fixed);
m_funcTable->horizontalHeader()->setStretchLastSection(false);
m_funcTable->setColumnWidth(2, 80);
m_funcTable->setItemDelegateForColumn(1, new StatusDelegate(this));
funcLayout->addWidget(m_funcTable);
QHBoxLayout *tableBtnLayout = new QHBoxLayout;
@@ -68,30 +100,18 @@ void BatchConvertPage::initUI()
QVBoxLayout *progressLayout = new QVBoxLayout(progressBox);
progressLayout->setSpacing(10);
m_progressLabel = new QLabel("等待开始...");
m_progressLabel->setStyleSheet("color: #666;");
m_progressLabel->setFixedHeight(20);
m_progressLabel = new ElaText("等待开始...");
m_progressLabel->setStyleSheet("color: #666; font-size: 12px;");
m_progressLabel->setFixedHeight(40);
m_progressLabel->setWordWrap(false);
m_progressLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
progressLayout->addWidget(m_progressLabel);
m_progressBar = new QProgressBar;
m_progressBar = new ElaProgressBar;
m_progressBar->setRange(0, 100);
m_progressBar->setValue(0);
m_progressBar->setFixedHeight(25);
m_progressBar->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
m_progressBar->setStyleSheet(R"(
QProgressBar {
border: 1px solid #ddd;
border-radius: 4px;
background-color: #f0f0f0;
text-align: center;
}
QProgressBar::chunk {
background-color: #1abc9c;
border-radius: 4px;
}
)");
progressLayout->addWidget(m_progressBar);
layout->addWidget(progressBox);
@@ -122,30 +142,37 @@ bool BatchConvertPage::checkFunctionExists(const QString &funcName)
void BatchConvertPage::updateTable()
{
m_funcTable->setRowCount(m_funcList.size());
m_tableModel->removeRows(0, m_tableModel->rowCount());
for (int i = 0; i < m_funcList.size(); ++i) {
QString funcName = m_funcList[i];
QTableWidgetItem *nameItem = new QTableWidgetItem(funcName);
QStandardItem *nameItem = new QStandardItem(funcName);
nameItem->setFlags(nameItem->flags() & ~Qt::ItemIsEditable);
m_funcTable->setItem(i, 0, nameItem);
bool exists = checkFunctionExists(funcName);
QString statusText = exists ? "是" : "否";
QTableWidgetItem *statusItem = new QTableWidgetItem(statusText);
QStandardItem *statusItem = new QStandardItem(statusText);
statusItem->setFlags(statusItem->flags() & ~Qt::ItemIsEditable);
statusItem->setTextAlignment(Qt::AlignCenter);
if (exists) {
statusItem->setBackground(QColor(144, 238, 144));
statusItem->setForeground(QColor(0, 100, 0));
statusItem->setData(QBrush(QColor(144, 238, 144)), Qt::BackgroundRole);
statusItem->setData(QBrush(QColor(0, 100, 0)), Qt::ForegroundRole);
} else {
statusItem->setBackground(QColor(255, 182, 193));
statusItem->setForeground(QColor(139, 0, 0));
statusItem->setData(QBrush(QColor(255, 182, 193)), Qt::BackgroundRole);
statusItem->setData(QBrush(QColor(139, 0, 0)), Qt::ForegroundRole);
}
m_funcTable->setItem(i, 1, statusItem);
QStandardItem *actionItem = new QStandardItem("");
actionItem->setFlags(actionItem->flags() & ~Qt::ItemIsEditable);
QList<QStandardItem*> rowItems;
rowItems.append(nameItem);
rowItems.append(statusItem);
rowItems.append(actionItem);
m_tableModel->appendRow(rowItems);
QPushButton *editBtn = new QPushButton;
editBtn->setIcon(QIcon(":/resources/images/bianji.png"));
@@ -155,10 +182,10 @@ void BatchConvertPage::updateTable()
connect(editBtn, &QPushButton::clicked, this, [this, i]() {
onEditRow(i);
});
m_funcTable->setCellWidget(i, 2, editBtn);
m_funcTable->setIndexWidget(m_tableModel->index(i, 2), editBtn);
}
int totalWidth = m_funcTable->width();
int totalWidth = m_funcTable->viewport()->width();
m_funcTable->setColumnWidth(0, (totalWidth - 80) * 8 / 10);
m_funcTable->setColumnWidth(1, (totalWidth - 80) * 2 / 10);
m_funcTable->setColumnWidth(2, 80);
@@ -280,15 +307,15 @@ void BatchConvertPage::onAddFunction()
void BatchConvertPage::onRemoveFunction()
{
QList<QTableWidgetItem*> selectedItems = m_funcTable->selectedItems();
if (selectedItems.isEmpty()) {
QModelIndexList selectedIndexes = m_funcTable->selectionModel()->selectedRows();
if (selectedIndexes.isEmpty()) {
QMessageBox::warning(this, "提示", "请先选中要删除的行!");
return;
}
QList<int> rowsToRemove;
for (QTableWidgetItem *item : selectedItems) {
int row = item->row();
for (const QModelIndex &index : selectedIndexes) {
int row = index.row();
if (!rowsToRemove.contains(row)) {
rowsToRemove.append(row);
}