1 Star 1 Fork 0

zinface/learning_deepin-deb-installer

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
packageslistdelegate.cpp 2.27 KB
一键复制 编辑 原始数据 按行查看 历史
#include "deblistmodel.h"
#include "packageslistdelegate.h"
#include <QItemDelegate>
#include <QPainter>
PackagesListDelegate::PackagesListDelegate(QObject *parent)
: QAbstractItemDelegate(parent)
{
const QIcon icon = QIcon::fromTheme("application.vnc.debian.binary-package", QIcon::fromTheme("debian-swirl"));
m_packageIcon = icon.pixmap(48, 48);
}
void PackagesListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
const int content_x = 65;
if(index.row()){
const QPoint start(content_x, option.rect.top());
const QPoint end(option.rect.right() -10, option.rect.top());
painter->setPen(QColor(220,220,220));
painter->setRenderHint(QPainter::Antialiasing, false);
painter->drawLine(start, end);
}
painter->setRenderHint(QPainter::Antialiasing);
const int x = 10;
const int y = option.rect.top() + (option.rect.height() - m_packageIcon.height()) / 2;
painter->drawPixmap(x, y, m_packageIcon);
QRect name_rect = option.rect;
name_rect.setLeft(content_x);
name_rect.setHeight(name_rect.height() / 2);
const QString name = index.data(DebListModel::PackageNameRole).toString();
const QFont old_font = painter->font();
QFont f = old_font;
f.setWeight(500);
painter->setFont(f);
const QRectF name_bounding_rect = painter->boundingRect(name_rect, name, Qt::AlignLeft | Qt::AlignBottom);
painter->setPen(Qt::black);
painter->drawText(name_rect, name, Qt::AlignLeft | Qt::AlignBottom);
painter->setFont(old_font);
const int version_x = name_bounding_rect.right() + 8;
QRect version_rect = name_rect;
version_rect.setLeft(version_x);
painter->drawText(version_rect, index.data(DebListModel::PackageVersionRole).toString(), Qt::AlignLeft | Qt::AlignBottom);
QRect info_rect = option.rect;
info_rect.setLeft(content_x);
info_rect.setTop(name_rect.bottom() + 1 + 3);
painter->setPen(QColor(80,80,80));
painter->drawText(info_rect, index.data(DebListModel::PackageDescriptionRole).toString(), Qt::AlignLeft | Qt::AlignTop);
}
QSize PackagesListDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
{
Q_UNUSED(option);
return index.data(Qt::SizeHintRole).toSize();
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zinface/learning_deepin-deb-installer.git
git@gitee.com:zinface/learning_deepin-deb-installer.git
zinface
learning_deepin-deb-installer
learning_deepin-deb-installer
master

搜索帮助