Rewrite album cover loader
This commit is contained in:
@@ -54,16 +54,14 @@ ContextAlbum::ContextAlbum(QWidget *parent)
|
||||
timeline_fade_(new QTimeLine(kFadeTimeLineMs, this)),
|
||||
image_strawberry_(":/pictures/strawberry.png"),
|
||||
image_original_(image_strawberry_),
|
||||
pixmap_current_opacity_(1.0) {
|
||||
pixmap_current_opacity_(1.0),
|
||||
desired_height_(width()) {
|
||||
|
||||
setObjectName("context-widget-album");
|
||||
|
||||
setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||
|
||||
cover_loader_options_.desired_height_ = width();
|
||||
cover_loader_options_.pad_output_image_ = true;
|
||||
cover_loader_options_.scale_output_image_ = true;
|
||||
QImage image = ImageUtils::ScaleAndPad(image_strawberry_, cover_loader_options_.scale_output_image_, cover_loader_options_.pad_output_image_, cover_loader_options_.desired_height_, devicePixelRatioF());
|
||||
QImage image = ImageUtils::ScaleImage(image_strawberry_, QSize(desired_height_, desired_height_), devicePixelRatioF(), true);
|
||||
if (!image.isNull()) {
|
||||
pixmap_current_ = QPixmap::fromImage(image);
|
||||
}
|
||||
@@ -128,8 +126,8 @@ void ContextAlbum::contextMenuEvent(QContextMenuEvent *e) {
|
||||
|
||||
void ContextAlbum::UpdateWidth(const int new_width) {
|
||||
|
||||
if (new_width != cover_loader_options_.desired_height_) {
|
||||
cover_loader_options_.desired_height_ = new_width;
|
||||
if (new_width != desired_height_) {
|
||||
desired_height_ = new_width;
|
||||
ScaleCover();
|
||||
ScalePreviousCovers();
|
||||
updateGeometry();
|
||||
@@ -235,7 +233,7 @@ void ContextAlbum::FadePreviousCoverFinished(std::shared_ptr<PreviousCover> prev
|
||||
|
||||
void ContextAlbum::ScaleCover() {
|
||||
|
||||
QImage image = ImageUtils::ScaleAndPad(image_original_, cover_loader_options_.scale_output_image_, cover_loader_options_.pad_output_image_, cover_loader_options_.desired_height_, devicePixelRatioF());
|
||||
const QImage image = ImageUtils::ScaleImage(image_original_, QSize(desired_height_, desired_height_), devicePixelRatioF(), true);
|
||||
if (image.isNull()) {
|
||||
pixmap_current_ = QPixmap();
|
||||
}
|
||||
@@ -248,7 +246,7 @@ void ContextAlbum::ScaleCover() {
|
||||
void ContextAlbum::ScalePreviousCovers() {
|
||||
|
||||
for (std::shared_ptr<PreviousCover> previous_cover : previous_covers_) {
|
||||
QImage image = ImageUtils::ScaleAndPad(previous_cover->image, cover_loader_options_.scale_output_image_, cover_loader_options_.pad_output_image_, cover_loader_options_.desired_height_, devicePixelRatioF());
|
||||
QImage image = ImageUtils::ScaleImage(previous_cover->image, QSize(desired_height_, desired_height_), devicePixelRatioF(), true);
|
||||
if (image.isNull()) {
|
||||
previous_cover->pixmap = QPixmap();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user