更新图书封面绘制机制

This commit is contained in:
WS 2021-08-14 23:15:16 +08:00
parent 1b9dcf0182
commit 1d59429613
1 changed files with 18 additions and 5 deletions

View File

@ -100,7 +100,7 @@ GroupDisplayDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, c
model->setData(index, static_cast<QLineEdit*>(editor)->text());
}
auto text_rect = [](const QRect& whole_rect, double font_height) -> QRectF {
auto calc_textrect1 = [](const QRect& whole_rect, double font_height) -> QRectF {
return QRectF(whole_rect.left() + 145, whole_rect.top() + 20, whole_rect.width() - 165, font_height);
};
void
@ -109,7 +109,7 @@ GroupDisplayDelegate::updateEditorGeometry(QWidget* editor, const QStyleOptionVi
QStyleOptionViewItem new_ = option;
new_.font.setPointSize(26);
new_.fontMetrics = QFontMetrics(new_.font);
editor->setGeometry(text_rect(option.rect, new_.fontMetrics.height()).toRect());
editor->setGeometry(calc_textrect1(option.rect, new_.fontMetrics.height()).toRect());
}
void
@ -153,7 +153,7 @@ GroupDisplayDelegate::paint(QPainter* painter, const QStyleOptionViewItem& optio
QStyleOptionViewItem new_copy = option;
new_copy.font.setPointSize(26);
new_copy.fontMetrics = QFontMetrics(new_copy.font);
drawDisplay(painter, new_copy, text_rect(option.rect, new_copy.fontMetrics.height()).toRect(), index.data().toString());
drawDisplay(painter, new_copy, calc_textrect1(option.rect, new_copy.fontMetrics.height()).toRect(), index.data().toString());
new_copy.font.setPointSize(18);
new_copy.fontMetrics = QFontMetrics(new_copy.font);
@ -174,17 +174,25 @@ ListIconDelegate::~ListIconDelegate()
{
}
auto
calc_textrect2
= [](const QRect& boundrect, float height) -> QRect {
return QRect(boundrect.left() + 5, boundrect.bottom() - height - 5, boundrect.width() - 10, height);
};
void
ListIconDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
painter->save();
painter->setRenderHint(QPainter::Antialiasing);
drawBackground(painter, option, index);
QPen pen(QColor(0, 0, 200, 150), 3, Qt::SolidLine);
painter->setPen(pen);
QBrush brush(QColor(20, 20, 150, 100));
painter->setBrush(brush);
painter->setRenderHint(QPainter::Antialiasing);
if (option.state & QStyle::State_Selected)
painter->drawRoundedRect(option.rect - QMargins(2, 2, 2, 2), 5, 5);
@ -198,6 +206,11 @@ ListIconDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, c
auto valid_rect = option.rect - QMargins(15, 15, 15, 15);
drawDecoration(painter, option, valid_rect, icon->pixmap(120, 180));
if (option.features & QStyleOptionViewItem::HasCheckIndicator)
drawCheck(painter, option, QRect(option.rect.left() + 5, option.rect.top() + 5, 20, 20), option.checkState);
painter->fillRect(calc_textrect2(option.rect, option.fontMetrics.height() * 1.3), QGradient::Preset::NightFade);
drawDisplay(painter, option, calc_textrect2(option.rect, option.fontMetrics.height() * 1.3), index.data().toString());
painter->restore();
}
@ -228,5 +241,5 @@ ListIconDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const
void
ListIconDelegate::updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
editor->setGeometry(option.rect);
editor->setGeometry(calc_textrect2(option.rect, option.fontMetrics.height() * 1.3));
}