mirror of
https://gitee.com/spark-store-project/spark-store
synced 2025-12-20 03:01:36 +08:00
feat:显示包信息
This commit is contained in:
@@ -6,30 +6,78 @@ AppDelegate::AppDelegate(QObject *parent) : QStyledItemDelegate(parent) {}
|
|||||||
|
|
||||||
void AppDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
void AppDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
QStyledItemDelegate::paint(painter, option, index);
|
painter->save();
|
||||||
|
|
||||||
// 获取数据
|
// 绘制背景
|
||||||
|
if (option.state & QStyle::State_Selected) {
|
||||||
|
painter->fillRect(option.rect, option.palette.highlight());
|
||||||
|
} else {
|
||||||
|
painter->fillRect(option.rect, QColor("#F3F4F6"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置字体
|
||||||
|
QFont boldFont = option.font;
|
||||||
|
boldFont.setBold(true);
|
||||||
|
|
||||||
|
QFont normalFont = option.font;
|
||||||
|
|
||||||
|
// 数据
|
||||||
QString name = index.data(Qt::DisplayRole).toString();
|
QString name = index.data(Qt::DisplayRole).toString();
|
||||||
QString currentVersion = index.data(Qt::UserRole + 2).toString();
|
QString currentVersion = index.data(Qt::UserRole + 2).toString();
|
||||||
QString newVersion = index.data(Qt::UserRole + 3).toString();
|
QString newVersion = index.data(Qt::UserRole + 3).toString();
|
||||||
QString iconPath = index.data(Qt::UserRole + 4).toString();
|
QString iconPath = index.data(Qt::UserRole + 4).toString();
|
||||||
// 获取包大小数据
|
QString size = index.data(Qt::UserRole + 5).toString();
|
||||||
QVariant sizeVariant = index.data(Qt::UserRole + 5);
|
QString description = index.data(Qt::UserRole + 6).toString(); // 假设额外说明文本
|
||||||
QString size = sizeVariant.isValid() ? sizeVariant.toString() : "未知";
|
|
||||||
|
|
||||||
// 绘制图标
|
// 区域定义
|
||||||
QIcon icon(iconPath);
|
QRect rect = option.rect;
|
||||||
QRect iconRect(option.rect.x() + 10, option.rect.y() + 10, 32, 32);
|
int margin = 10;
|
||||||
icon.paint(painter, iconRect);
|
int spacing = 6;
|
||||||
|
int iconSize = 40;
|
||||||
|
|
||||||
// 绘制文本,添加包大小信息
|
// 图标
|
||||||
QRect textRect(iconRect.right() + 10, option.rect.y() + 10, option.rect.width() - iconRect.width() - 20, option.rect.height() - 20);
|
QRect iconRect(rect.left() + margin, rect.top() + (rect.height() - iconSize) / 2, iconSize, iconSize);
|
||||||
painter->drawText(textRect, Qt::TextWordWrap, QString("%1\n当前版本: %2 → 新版本: %3\n包大小: %4").arg(name, currentVersion, newVersion, size));
|
QIcon(iconPath).paint(painter, iconRect);
|
||||||
|
|
||||||
|
// 文本起点
|
||||||
|
int textX = iconRect.right() + margin;
|
||||||
|
int textWidth = rect.width() - textX - 100; // 留出按钮区域
|
||||||
|
|
||||||
|
// 绘制应用名称
|
||||||
|
QRect nameRect(textX, rect.top() + margin, textWidth, 20);
|
||||||
|
painter->setFont(boldFont);
|
||||||
|
painter->setPen(QColor("#333333")); // 改为深色,确保清晰
|
||||||
|
painter->drawText(nameRect, Qt::AlignLeft | Qt::AlignVCenter, name); // 绘制应用名称
|
||||||
|
|
||||||
|
// 绘制版本信息
|
||||||
|
QRect versionRect(textX, nameRect.bottom() + spacing, textWidth, 20);
|
||||||
|
painter->setFont(normalFont);
|
||||||
|
painter->setPen(QColor("#888888")); // 使用浅灰色,保持对比
|
||||||
|
painter->drawText(versionRect, Qt::AlignLeft | Qt::AlignVCenter,
|
||||||
|
QString("当前版本: %1 → 新版本: %2").arg(currentVersion, newVersion));
|
||||||
|
|
||||||
|
// 描述行
|
||||||
|
QRect descRect(textX, versionRect.bottom() + spacing, textWidth, 40);
|
||||||
|
painter->setFont(normalFont);
|
||||||
|
painter->setPen(QColor("#AAAAAA"));
|
||||||
|
painter->drawText(descRect, Qt::TextWordWrap,
|
||||||
|
QString("更新说明:%1\n包大小:%2").arg(description, size));
|
||||||
|
|
||||||
|
// 更新按钮(样式占位)
|
||||||
|
QRect buttonRect(rect.right() - 80, rect.top() + (rect.height() - 30) / 2, 70, 30);
|
||||||
|
painter->setPen(Qt::NoPen);
|
||||||
|
painter->setBrush(QColor("#267AFF"));
|
||||||
|
painter->drawRoundedRect(buttonRect, 6, 6);
|
||||||
|
painter->setPen(Qt::white);
|
||||||
|
painter->drawText(buttonRect, Qt::AlignCenter, "更新");
|
||||||
|
|
||||||
|
painter->restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QSize AppDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
|
QSize AppDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
return QSize(option.rect.width(), 60); // 每行高度 60
|
return QSize(option.rect.width(), 110); // 每行高度 110
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AppDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index)
|
bool AppDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index)
|
||||||
|
|||||||
Reference in New Issue
Block a user