Almost working delegate version with text. Needs a little more polishing though
This commit is contained in:
parent
1886dbf53c
commit
04f1c4a76f
1 changed files with 60 additions and 21 deletions
|
@ -35,6 +35,8 @@
|
|||
// KDE
|
||||
|
||||
#include <KPushButton>
|
||||
#include <KLocale>
|
||||
#include <KLocalizedString>
|
||||
|
||||
|
||||
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<Danbooru::DanbooruPost*>();
|
||||
|
||||
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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue