ContextView: Update album width from context
This commit is contained in:
parent
dc1f9edfaf
commit
9b743e55d1
@ -54,12 +54,11 @@ ContextAlbum::ContextAlbum(QWidget *parent)
|
|||||||
timeline_fade_(new QTimeLine(kFadeTimeLineMs, this)),
|
timeline_fade_(new QTimeLine(kFadeTimeLineMs, this)),
|
||||||
image_strawberry_(":/pictures/strawberry.png"),
|
image_strawberry_(":/pictures/strawberry.png"),
|
||||||
image_original_(image_strawberry_),
|
image_original_(image_strawberry_),
|
||||||
pixmap_current_opacity_(1.0),
|
pixmap_current_opacity_(1.0) {
|
||||||
prev_width_(width()) {
|
|
||||||
|
|
||||||
setObjectName("context-widget-album");
|
setObjectName("context-widget-album");
|
||||||
|
|
||||||
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
|
setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||||
|
|
||||||
cover_loader_options_.desired_height_ = width();
|
cover_loader_options_.desired_height_ = width();
|
||||||
cover_loader_options_.pad_output_image_ = true;
|
cover_loader_options_.pad_output_image_ = true;
|
||||||
@ -96,18 +95,6 @@ QSize ContextAlbum::sizeHint() const {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContextAlbum::resizeEvent(QResizeEvent *e) {
|
|
||||||
|
|
||||||
if (width() != prev_width_) {
|
|
||||||
ScaleCover();
|
|
||||||
ScalePreviousCovers();
|
|
||||||
prev_width_ = width();
|
|
||||||
}
|
|
||||||
|
|
||||||
QWidget::resizeEvent(e);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void ContextAlbum::paintEvent(QPaintEvent*) {
|
void ContextAlbum::paintEvent(QPaintEvent*) {
|
||||||
|
|
||||||
QPainter p(this);
|
QPainter p(this);
|
||||||
@ -139,6 +126,17 @@ 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;
|
||||||
|
ScaleCover();
|
||||||
|
ScalePreviousCovers();
|
||||||
|
updateGeometry();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void ContextAlbum::SetImage(QImage image) {
|
void ContextAlbum::SetImage(QImage image) {
|
||||||
|
|
||||||
if (image.isNull()) {
|
if (image.isNull()) {
|
||||||
@ -237,8 +235,6 @@ void ContextAlbum::FadePreviousCoverFinished(std::shared_ptr<PreviousCover> prev
|
|||||||
|
|
||||||
void ContextAlbum::ScaleCover() {
|
void ContextAlbum::ScaleCover() {
|
||||||
|
|
||||||
cover_loader_options_.desired_height_ = width();
|
|
||||||
|
|
||||||
QImage image = ImageUtils::ScaleAndPad(image_original_, cover_loader_options_.scale_output_image_, cover_loader_options_.pad_output_image_, cover_loader_options_.desired_height_);
|
QImage image = ImageUtils::ScaleAndPad(image_original_, cover_loader_options_.scale_output_image_, cover_loader_options_.pad_output_image_, cover_loader_options_.desired_height_);
|
||||||
if (image.isNull()) {
|
if (image.isNull()) {
|
||||||
pixmap_current_ = QPixmap();
|
pixmap_current_ = QPixmap();
|
||||||
@ -247,14 +243,11 @@ void ContextAlbum::ScaleCover() {
|
|||||||
pixmap_current_ = QPixmap::fromImage(image);
|
pixmap_current_ = QPixmap::fromImage(image);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateGeometry();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContextAlbum::ScalePreviousCovers() {
|
void ContextAlbum::ScalePreviousCovers() {
|
||||||
|
|
||||||
for (std::shared_ptr<PreviousCover> previous_cover : previous_covers_) {
|
for (std::shared_ptr<PreviousCover> previous_cover : previous_covers_) {
|
||||||
if (previous_cover->pixmap.width() == width()) continue;
|
|
||||||
QImage image = ImageUtils::ScaleAndPad(previous_cover->image, cover_loader_options_.scale_output_image_, cover_loader_options_.pad_output_image_, cover_loader_options_.desired_height_);
|
QImage image = ImageUtils::ScaleAndPad(previous_cover->image, cover_loader_options_.scale_output_image_, cover_loader_options_.pad_output_image_, cover_loader_options_.desired_height_);
|
||||||
if (image.isNull()) {
|
if (image.isNull()) {
|
||||||
previous_cover->pixmap = QPixmap();
|
previous_cover->pixmap = QPixmap();
|
||||||
|
@ -51,10 +51,10 @@ class ContextAlbum : public QWidget {
|
|||||||
|
|
||||||
void Init(ContextView *context_view, AlbumCoverChoiceController *album_cover_choice_controller);
|
void Init(ContextView *context_view, AlbumCoverChoiceController *album_cover_choice_controller);
|
||||||
void SetImage(QImage image = QImage());
|
void SetImage(QImage image = QImage());
|
||||||
|
void UpdateWidth(const int width);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QSize sizeHint() const override;
|
QSize sizeHint() const override;
|
||||||
void resizeEvent(QResizeEvent *e) override;
|
|
||||||
void paintEvent(QPaintEvent*) override;
|
void paintEvent(QPaintEvent*) override;
|
||||||
void mouseDoubleClickEvent(QMouseEvent *e) override;
|
void mouseDoubleClickEvent(QMouseEvent *e) override;
|
||||||
void contextMenuEvent(QContextMenuEvent *e) override;
|
void contextMenuEvent(QContextMenuEvent *e) override;
|
||||||
@ -107,7 +107,6 @@ class ContextAlbum : public QWidget {
|
|||||||
QPixmap pixmap_current_;
|
QPixmap pixmap_current_;
|
||||||
qreal pixmap_current_opacity_;
|
qreal pixmap_current_opacity_;
|
||||||
std::unique_ptr<QMovie> spinner_animation_;
|
std::unique_ptr<QMovie> spinner_animation_;
|
||||||
int prev_width_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CONTEXTALBUM_H
|
#endif // CONTEXTALBUM_H
|
||||||
|
@ -69,7 +69,7 @@
|
|||||||
#include "contextview.h"
|
#include "contextview.h"
|
||||||
#include "contextalbum.h"
|
#include "contextalbum.h"
|
||||||
|
|
||||||
const int ContextView::kWidgetSpacing = 40;
|
const int ContextView::kWidgetSpacing = 50;
|
||||||
|
|
||||||
ContextView::ContextView(QWidget *parent)
|
ContextView::ContextView(QWidget *parent)
|
||||||
: QWidget(parent),
|
: QWidget(parent),
|
||||||
@ -126,8 +126,7 @@ ContextView::ContextView(QWidget *parent)
|
|||||||
lyrics_tried_(false),
|
lyrics_tried_(false),
|
||||||
lyrics_id_(-1),
|
lyrics_id_(-1),
|
||||||
font_size_headline_(0),
|
font_size_headline_(0),
|
||||||
font_size_normal_(0),
|
font_size_normal_(0) {
|
||||||
prev_width_(width()) {
|
|
||||||
|
|
||||||
setLayout(layout_container_);
|
setLayout(layout_container_);
|
||||||
|
|
||||||
@ -140,6 +139,7 @@ ContextView::ContextView(QWidget *parent)
|
|||||||
scrollarea_->setWidget(widget_scrollarea_);
|
scrollarea_->setWidget(widget_scrollarea_);
|
||||||
scrollarea_->setContentsMargins(0, 0, 0, 0);
|
scrollarea_->setContentsMargins(0, 0, 0, 0);
|
||||||
scrollarea_->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
scrollarea_->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||||
|
scrollarea_->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
||||||
|
|
||||||
widget_scrollarea_->setObjectName("context-widget-scrollarea");
|
widget_scrollarea_->setObjectName("context-widget-scrollarea");
|
||||||
widget_scrollarea_->setLayout(layout_scrollarea_);
|
widget_scrollarea_->setLayout(layout_scrollarea_);
|
||||||
@ -363,9 +363,8 @@ void ContextView::ReloadSettings() {
|
|||||||
|
|
||||||
void ContextView::resizeEvent(QResizeEvent *e) {
|
void ContextView::resizeEvent(QResizeEvent *e) {
|
||||||
|
|
||||||
if (prev_width_ != width()) {
|
if (e->size().width() != e->oldSize().width()) {
|
||||||
widget_album_->setFixedWidth(width() - kWidgetSpacing);
|
widget_album_->UpdateWidth(width() - kWidgetSpacing);
|
||||||
prev_width_ = width();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget::resizeEvent(e);
|
QWidget::resizeEvent(e);
|
||||||
|
@ -180,8 +180,6 @@ class ContextView : public QWidget {
|
|||||||
QList<QLabel*> labels_play_data_;
|
QList<QLabel*> labels_play_data_;
|
||||||
QList<QLabel*> labels_play_all_;
|
QList<QLabel*> labels_play_all_;
|
||||||
|
|
||||||
int prev_width_;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CONTEXTVIEW_H
|
#endif // CONTEXTVIEW_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user