Show the album cover dimensions on top of the images in the album cover search dialog.
Fixes issue 1704
This commit is contained in:
parent
5c90404915
commit
c366f722fb
|
@ -329,6 +329,11 @@ QByteArray Sha256(const QByteArray& data) {
|
|||
return ret;
|
||||
}
|
||||
|
||||
QString PrettySize(const QSize& size) {
|
||||
return QString::number(size.width()) + "x" +
|
||||
QString::number(size.height());
|
||||
}
|
||||
|
||||
} // namespace Utilities
|
||||
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
#include <QColor>
|
||||
#include <QLocale>
|
||||
#include <QSize>
|
||||
#include <QString>
|
||||
|
||||
#include <boost/scoped_array.hpp>
|
||||
|
@ -31,6 +32,7 @@ namespace Utilities {
|
|||
QString PrettyTimeDelta(int seconds);
|
||||
QString PrettyTimeNanosec(qint64 nanoseconds);
|
||||
QString PrettySize(quint64 bytes);
|
||||
QString PrettySize(const QSize& size);
|
||||
QString WordyTime(quint64 seconds);
|
||||
QString WordyTimeNanosec(qint64 nanoseconds);
|
||||
QString Ago(int seconds_since_epoch, const QLocale& locale);
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include "albumcoversearcher.h"
|
||||
#include "ui_albumcoversearcher.h"
|
||||
#include "core/logging.h"
|
||||
#include "core/utilities.h"
|
||||
#include "covers/albumcoverfetcher.h"
|
||||
#include "covers/albumcoverloader.h"
|
||||
#include "widgets/forcescrollperpixel.h"
|
||||
|
@ -28,6 +29,64 @@
|
|||
#include <QPainter>
|
||||
#include <QStandardItemModel>
|
||||
|
||||
const int SizeOverlayDelegate::kMargin = 4;
|
||||
const int SizeOverlayDelegate::kPaddingX = 3;
|
||||
const int SizeOverlayDelegate::kPaddingY = 1;
|
||||
const qreal SizeOverlayDelegate::kBorder = 5.0;
|
||||
const qreal SizeOverlayDelegate::kFontPointSize = 7.5;
|
||||
const int SizeOverlayDelegate::kBorderAlpha = 200;
|
||||
const int SizeOverlayDelegate::kBackgroundAlpha = 175;
|
||||
|
||||
|
||||
SizeOverlayDelegate::SizeOverlayDelegate(QObject* parent)
|
||||
: QStyledItemDelegate(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void SizeOverlayDelegate::paint(QPainter* painter,
|
||||
const QStyleOptionViewItem& option,
|
||||
const QModelIndex& index) const {
|
||||
QStyledItemDelegate::paint(painter, option, index);
|
||||
|
||||
if (!index.data(AlbumCoverSearcher::Role_ImageFetchFinished).toBool()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const QSize size = index.data(AlbumCoverSearcher::Role_ImageSize).toSize();
|
||||
const QString text = Utilities::PrettySize(size);
|
||||
|
||||
QFont font(option.font);
|
||||
font.setPointSizeF(kFontPointSize);
|
||||
font.setBold(true);
|
||||
|
||||
const QFontMetrics metrics(font);
|
||||
|
||||
const int text_width = metrics.width(text);
|
||||
|
||||
const QRect icon_rect(
|
||||
option.rect.left(), option.rect.top(),
|
||||
option.rect.width(), option.rect.width());
|
||||
|
||||
const QRect background_rect(
|
||||
icon_rect.right() - kMargin - text_width - kPaddingX*2,
|
||||
icon_rect.bottom() - kMargin - metrics.height() - kPaddingY*2,
|
||||
text_width + kPaddingX*2, metrics.height() + kPaddingY*2);
|
||||
const QRect text_rect(
|
||||
background_rect.left() + kPaddingX, background_rect.top() + kPaddingY,
|
||||
text_width, metrics.height());
|
||||
|
||||
painter->save();
|
||||
painter->setRenderHint(QPainter::Antialiasing);
|
||||
painter->setPen(QColor(0, 0, 0, kBorderAlpha));
|
||||
painter->setBrush(QColor(0, 0, 0, kBackgroundAlpha));
|
||||
painter->drawRoundedRect(background_rect, kBorder, kBorder);
|
||||
|
||||
painter->setPen(Qt::white);
|
||||
painter->setFont(font);
|
||||
painter->drawText(text_rect, text);
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
|
||||
AlbumCoverSearcher::AlbumCoverSearcher(const QIcon& no_cover_icon, QWidget* parent)
|
||||
: QDialog(parent),
|
||||
|
@ -43,10 +102,10 @@ AlbumCoverSearcher::AlbumCoverSearcher(const QIcon& no_cover_icon, QWidget* pare
|
|||
|
||||
ui_->covers->set_header_text(tr("Covers from %1"));
|
||||
ui_->covers->AddSortSpec(Role_ImageDimensions, Qt::DescendingOrder);
|
||||
ui_->covers->setItemDelegate(new SizeOverlayDelegate(this));
|
||||
ui_->covers->setModel(model_);
|
||||
|
||||
loader_->Start(true);
|
||||
loader_->Worker()->SetDefaultOutputImage(QImage(":nocover.png"));
|
||||
loader_->Worker()->SetScaleOutputImage(false);
|
||||
loader_->Worker()->SetPadOutputImage(false);
|
||||
connect(loader_->Worker().get(), SIGNAL(ImageLoaded(quint64,QImage)),
|
||||
|
@ -142,6 +201,15 @@ void AlbumCoverSearcher::SearchFinished(quint64 id, const CoverSearchResults& re
|
|||
void AlbumCoverSearcher::ImageLoaded(quint64 id, const QImage& image) {
|
||||
if (!cover_loading_tasks_.contains(id))
|
||||
return;
|
||||
QStandardItem* item = cover_loading_tasks_.take(id);
|
||||
|
||||
if (cover_loading_tasks_.isEmpty())
|
||||
ui_->busy->hide();
|
||||
|
||||
if (image.isNull()) {
|
||||
model_->removeRow(item->row());
|
||||
return;
|
||||
}
|
||||
|
||||
QIcon icon(QPixmap::fromImage(image));
|
||||
|
||||
|
@ -161,15 +229,10 @@ void AlbumCoverSearcher::ImageLoaded(quint64 id, const QImage& image) {
|
|||
|
||||
icon.addPixmap(QPixmap::fromImage(padded_image));
|
||||
|
||||
QStandardItem* item = cover_loading_tasks_.take(id);
|
||||
item->setData(true, Role_ImageFetchFinished);
|
||||
item->setData(image.width() * image.height(), Role_ImageDimensions);
|
||||
item->setData(image.size(), Role_ImageSize);
|
||||
item->setIcon(icon);
|
||||
item->setToolTip(item->text() + " (" + QString::number(image.width()) + "x" +
|
||||
QString::number(image.height()) + ")");
|
||||
|
||||
if (cover_loading_tasks_.isEmpty())
|
||||
ui_->busy->hide();
|
||||
}
|
||||
|
||||
void AlbumCoverSearcher::keyPressEvent(QKeyEvent* e) {
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
|
||||
#include <QDialog>
|
||||
#include <QIcon>
|
||||
#include <QStyledItemDelegate>
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
|
@ -34,6 +35,23 @@ class QStandardItem;
|
|||
class QStandardItemModel;
|
||||
|
||||
|
||||
class SizeOverlayDelegate : public QStyledItemDelegate {
|
||||
public:
|
||||
static const int kMargin;
|
||||
static const int kPaddingX;
|
||||
static const int kPaddingY;
|
||||
static const qreal kBorder;
|
||||
static const qreal kFontPointSize;
|
||||
static const int kBorderAlpha;
|
||||
static const int kBackgroundAlpha;
|
||||
|
||||
SizeOverlayDelegate(QObject* parent = NULL);
|
||||
|
||||
void paint(QPainter* painter, const QStyleOptionViewItem& option,
|
||||
const QModelIndex& index) const;
|
||||
};
|
||||
|
||||
|
||||
// This is a dialog that lets the user search for album covers
|
||||
class AlbumCoverSearcher : public QDialog {
|
||||
Q_OBJECT
|
||||
|
@ -46,7 +64,8 @@ public:
|
|||
Role_ImageURL = Qt::UserRole + 1,
|
||||
Role_ImageRequestId,
|
||||
Role_ImageFetchFinished,
|
||||
Role_ImageDimensions,
|
||||
Role_ImageDimensions, // width * height
|
||||
Role_ImageSize,
|
||||
};
|
||||
|
||||
void Init(AlbumCoverFetcher* fetcher);
|
||||
|
|
Loading…
Reference in New Issue