diff --git a/src/model/danboorupostdelegate.cpp b/src/model/danboorupostdelegate.cpp index 0791444..24aac4e 100644 --- a/src/model/danboorupostdelegate.cpp +++ b/src/model/danboorupostdelegate.cpp @@ -35,6 +35,8 @@ // KDE #include +#include +#include namespace Danbooru { @@ -92,6 +94,12 @@ namespace Danbooru { return; } + QStyleOptionViewItemV4 opt(option); + + // Pixmap + + painter->save(); + QStyle *style = QApplication::style(); style->drawPrimitive(QStyle::PE_PanelItemViewItem, &option, painter, 0); @@ -103,40 +111,43 @@ namespace Danbooru { return; } - // Scaling is unavoidable to keep things in the right dimension - //TODO: Replace fixed values by configurable values + QRect rect = option.rect; + QFontMetrics metrics = option.fontMetrics; + QRect textRect(rect.left(), rect.bottom() - 3 * metrics.height(), + rect.width(), 3 * metrics.height()); - QPixmap scaled = pixmap.scaled(256-MARGIN, 256-MARGIN, + // Scaling is unavoidable to keep things in the right dimension + + QPixmap scaled = pixmap.scaled(rect.width() - MARGIN, + rect.height() - MARGIN, Qt::KeepAspectRatio, Qt::SmoothTransformation); + QRect pixRect = scaled.rect(); + pixRect.moveCenter(rect.center()); - QRect rect = option.rect; +// painter->drawRect(option.rect); - // Draw in the center + // move the pixmap up to accomodate some lines of text - QPoint centerCoordinate = rect.center() - QPoint(scaled.width() / 2, - scaled.height() / 2); + pixRect.moveTo(pixRect.left(), + pixRect.top() + textRect.height() / 2); + pixRect.setBottom(textRect.top() - MARGIN); - // Get the bottom coordinate for the buttons, made as center - half - // of the pixmap width (left) then half of the height minus the button - // size and margin (because the move() call later on uses the - // coordinates as TOP coordinates, while we want the bottom of the - // button to align with the bottom of the pixmap) + painter->drawPixmap(pixRect, scaled); + painter->restore(); - QPoint scaleFactor = QPoint( - -(scaled.width() / 2) + (MARGIN / 2), - (scaled.height() / 2) - m_buttonSize + (MARGIN * 1.5) - ); + // Buttons - QPoint bottomCoordinate = rect.center() + scaleFactor; - - painter->drawPixmap(centerCoordinate, scaled); + painter->save(); if (option.state & QStyle::State_MouseOver) { - m_downloadButton->move(centerCoordinate + QPoint(MARGIN / 2, 0)); - m_viewButton->move(bottomCoordinate); + // Get the bottom coordinate for the buttons + + m_downloadButton->move(pixRect.topLeft()); + m_viewButton->move(pixRect.bottomLeft() - QPoint( + 0, m_viewButton->height() - 1.5 * MARGIN)); m_downloadButton->show(); m_viewButton->show(); @@ -146,6 +157,34 @@ namespace Danbooru { m_viewButton->hide(); } + painter->restore(); + + // Text (resolution) + + DanbooruPost* post = index.data().value(); + + painter->save(); + + int imageHeight = post->height(); + int imageWidth = post->width(); + + QString imageText = i18n( + "File size: %1", + KGlobal::locale()->formatByteSize(post->size())); + + KLocalizedString sizestr = ki18np("1 pixel", "%1 pixels"); + + imageText += "\n"; + imageText += i18n("Resolution: %1 x %2", + sizestr.subs(imageWidth).toString(), + sizestr.subs(imageHeight).toString()); + imageText += "\n"; + imageText += i18n("Rating: %1", post->rating()); + + painter->drawText(textRect, imageText); + + painter->restore(); + } QSize DanbooruPostDelegate::sizeHint(const QStyleOptionViewItem& option,