Use the height - 3 lines of text to make also very high pixmaps fit
This commit is contained in:
parent
e787a35330
commit
834bdfd82d
1 changed files with 20 additions and 10 deletions
|
@ -75,6 +75,8 @@ namespace Danbooru {
|
||||||
|
|
||||||
m_downloadButton->resize(m_buttonSize, m_buttonSize);
|
m_downloadButton->resize(m_buttonSize, m_buttonSize);
|
||||||
m_viewButton->resize(m_buttonSize, m_buttonSize);
|
m_viewButton->resize(m_buttonSize, m_buttonSize);
|
||||||
|
m_downloadButton->setToolTip(i18n("Download image"));
|
||||||
|
m_viewButton->setToolTip(i18n("View image"));
|
||||||
|
|
||||||
// Signal-slot connections
|
// Signal-slot connections
|
||||||
|
|
||||||
|
@ -98,11 +100,9 @@ namespace Danbooru {
|
||||||
|
|
||||||
// Pixmap
|
// Pixmap
|
||||||
|
|
||||||
painter->save();
|
|
||||||
|
|
||||||
QStyle *style = QApplication::style();
|
QStyle *style = QApplication::style();
|
||||||
|
|
||||||
style->drawPrimitive(QStyle::PE_PanelItemViewItem, &option, painter, 0);
|
style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, 0);
|
||||||
painter->setRenderHint(QPainter::Antialiasing);
|
painter->setRenderHint(QPainter::Antialiasing);
|
||||||
|
|
||||||
QPixmap pixmap = index.data(Qt::DecorationRole).value<QPixmap>();
|
QPixmap pixmap = index.data(Qt::DecorationRole).value<QPixmap>();
|
||||||
|
@ -111,16 +111,21 @@ namespace Danbooru {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QRect rect = option.rect;
|
QRect rect = opt.rect;
|
||||||
QFontMetrics metrics = option.fontMetrics;
|
QFontMetrics metrics = opt.fontMetrics;
|
||||||
QRect textRect(rect.left() + MARGIN, rect.bottom() - 3 * metrics.height(),
|
QRect textRect(rect.left() + MARGIN, rect.bottom() - 3 * metrics.height(),
|
||||||
rect.width(), 3 * metrics.height());
|
rect.width(), 3 * metrics.height());
|
||||||
|
|
||||||
// Scaling is unavoidable to keep things in the right dimension
|
// Scaling is unavoidable to keep things in the right dimension
|
||||||
|
|
||||||
QPixmap scaled = pixmap.scaled(rect.width() - MARGIN, rect.height() - MARGIN,
|
QPixmap scaled;
|
||||||
Qt::KeepAspectRatio,
|
int maxHeight = rect.height() - 3 * metrics.height() - 2 * MARGIN;
|
||||||
Qt::SmoothTransformation);
|
|
||||||
|
scaled = pixmap.scaled(rect.width() - 2 * MARGIN,
|
||||||
|
maxHeight,
|
||||||
|
Qt::KeepAspectRatio,
|
||||||
|
Qt::SmoothTransformation);
|
||||||
|
|
||||||
|
|
||||||
QRect pixRect = scaled.rect();
|
QRect pixRect = scaled.rect();
|
||||||
pixRect.moveCenter(rect.center());
|
pixRect.moveCenter(rect.center());
|
||||||
|
@ -132,7 +137,6 @@ namespace Danbooru {
|
||||||
pixRect.moveBottom(textRect.top() - MARGIN);
|
pixRect.moveBottom(textRect.top() - MARGIN);
|
||||||
|
|
||||||
painter->drawPixmap(pixRect, scaled);
|
painter->drawPixmap(pixRect, scaled);
|
||||||
painter->restore();
|
|
||||||
|
|
||||||
// Buttons
|
// Buttons
|
||||||
|
|
||||||
|
@ -204,9 +208,15 @@ namespace Danbooru {
|
||||||
QSize DanbooruPostDelegate::sizeHint(const QStyleOptionViewItem& option,
|
QSize DanbooruPostDelegate::sizeHint(const QStyleOptionViewItem& option,
|
||||||
const QModelIndex& index) const
|
const QModelIndex& index) const
|
||||||
{
|
{
|
||||||
|
|
||||||
Q_UNUSED(option)
|
Q_UNUSED(option)
|
||||||
Q_UNUSED(index)
|
|
||||||
|
if (!index.isValid()) {
|
||||||
|
return QSize();
|
||||||
|
}
|
||||||
|
|
||||||
return m_itemView->gridSize();
|
return m_itemView->gridSize();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QModelIndex DanbooruPostDelegate::hoveredIndex() const
|
QModelIndex DanbooruPostDelegate::hoveredIndex() const
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue