game_list: Update sizeHint in HTMLDelegate to obey icon size
This commit is contained in:
@@ -37,43 +37,44 @@ public:
|
|||||||
QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const override;
|
QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
void HTMLDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option,
|
void HTMLDelegate::paint(QPainter* painter, const QStyleOptionViewItem& _option,
|
||||||
const QModelIndex& index) const {
|
const QModelIndex& index) const {
|
||||||
QStyleOptionViewItemV4 optionV4 = option;
|
auto option = _option;
|
||||||
initStyleOption(&optionV4, index);
|
initStyleOption(&option, index);
|
||||||
|
|
||||||
QStyle* style = optionV4.widget ? optionV4.widget->style() : QApplication::style();
|
QStyle* style = option.widget ? option.widget->style() : QApplication::style();
|
||||||
|
|
||||||
QTextDocument doc;
|
QTextDocument document;
|
||||||
doc.setHtml(optionV4.text);
|
document.setHtml(option.text);
|
||||||
|
|
||||||
/// Painting item without text
|
/// Painting item without text
|
||||||
optionV4.text = QString();
|
option.text = QString();
|
||||||
style->drawControl(QStyle::CE_ItemViewItem, &optionV4, painter);
|
style->drawControl(QStyle::CE_ItemViewItem, &option, painter);
|
||||||
|
|
||||||
QAbstractTextDocumentLayout::PaintContext ctx;
|
QAbstractTextDocumentLayout::PaintContext ctx;
|
||||||
|
|
||||||
// Highlighting text if item is selected
|
// Highlighting text if item is selected
|
||||||
if (optionV4.state & QStyle::State_Selected)
|
if (option.state & QStyle::State_Selected) {
|
||||||
ctx.palette.setColor(QPalette::Text,
|
ctx.palette.setColor(QPalette::Text,
|
||||||
optionV4.palette.color(QPalette::Active, QPalette::HighlightedText));
|
option.palette.color(QPalette::Active, QPalette::HighlightedText));
|
||||||
|
}
|
||||||
|
|
||||||
QRect textRect = style->subElementRect(QStyle::SE_ItemViewItemText, &optionV4);
|
QRect textRect = style->subElementRect(QStyle::SE_ItemViewItemText, &option);
|
||||||
painter->save();
|
painter->save();
|
||||||
painter->translate(textRect.topLeft());
|
painter->translate(textRect.topLeft());
|
||||||
painter->setClipRect(textRect.translated(-textRect.topLeft()));
|
painter->setClipRect(textRect.translated(-textRect.topLeft()));
|
||||||
doc.documentLayout()->draw(painter, ctx);
|
document.documentLayout()->draw(painter, ctx);
|
||||||
painter->restore();
|
painter->restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
QSize HTMLDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const {
|
QSize HTMLDelegate::sizeHint(const QStyleOptionViewItem& _option, const QModelIndex& index) const {
|
||||||
QStyleOptionViewItemV4 optionV4 = option;
|
auto option = _option;
|
||||||
initStyleOption(&optionV4, index);
|
initStyleOption(&option, index);
|
||||||
|
|
||||||
QTextDocument doc;
|
QTextDocument document;
|
||||||
doc.setHtml(optionV4.text);
|
document.setHtml(option.text);
|
||||||
doc.setTextWidth(optionV4.rect.width());
|
document.setTextWidth(option.rect.width());
|
||||||
return QSize(doc.idealWidth(), doc.size().height());
|
return QSize(document.idealWidth(), UISettings::values.icon_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
GameListSearchField::KeyReleaseEater::KeyReleaseEater(GameList* gamelist) : gamelist{gamelist} {}
|
GameListSearchField::KeyReleaseEater::KeyReleaseEater(GameList* gamelist) : gamelist{gamelist} {}
|
||||||
|
|||||||
Reference in New Issue
Block a user