From 834bdfd82df408fdac974151d41c19dccab8447f Mon Sep 17 00:00:00 2001 From: Luca Beltrame Date: Tue, 23 Jul 2013 07:31:14 +0200 Subject: [PATCH] Use the height - 3 lines of text to make also very high pixmaps fit --- src/model/danboorupostdelegate.cpp | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/model/danboorupostdelegate.cpp b/src/model/danboorupostdelegate.cpp index 3f74e3f..6a9ee28 100644 --- a/src/model/danboorupostdelegate.cpp +++ b/src/model/danboorupostdelegate.cpp @@ -75,6 +75,8 @@ namespace Danbooru { m_downloadButton->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 @@ -98,11 +100,9 @@ namespace Danbooru { // Pixmap - painter->save(); - QStyle *style = QApplication::style(); - style->drawPrimitive(QStyle::PE_PanelItemViewItem, &option, painter, 0); + style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, 0); painter->setRenderHint(QPainter::Antialiasing); QPixmap pixmap = index.data(Qt::DecorationRole).value(); @@ -111,16 +111,21 @@ namespace Danbooru { return; } - QRect rect = option.rect; - QFontMetrics metrics = option.fontMetrics; + QRect rect = opt.rect; + QFontMetrics metrics = opt.fontMetrics; QRect textRect(rect.left() + MARGIN, rect.bottom() - 3 * metrics.height(), rect.width(), 3 * metrics.height()); // Scaling is unavoidable to keep things in the right dimension - QPixmap scaled = pixmap.scaled(rect.width() - MARGIN, rect.height() - MARGIN, - Qt::KeepAspectRatio, - Qt::SmoothTransformation); + QPixmap scaled; + int maxHeight = rect.height() - 3 * metrics.height() - 2 * MARGIN; + + scaled = pixmap.scaled(rect.width() - 2 * MARGIN, + maxHeight, + Qt::KeepAspectRatio, + Qt::SmoothTransformation); + QRect pixRect = scaled.rect(); pixRect.moveCenter(rect.center()); @@ -132,7 +137,6 @@ namespace Danbooru { pixRect.moveBottom(textRect.top() - MARGIN); painter->drawPixmap(pixRect, scaled); - painter->restore(); // Buttons @@ -204,9 +208,15 @@ namespace Danbooru { QSize DanbooruPostDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const { + Q_UNUSED(option) - Q_UNUSED(index) + + if (!index.isValid()) { + return QSize(); + } + return m_itemView->gridSize(); + } QModelIndex DanbooruPostDelegate::hoveredIndex() const