ContextView: Use fixed size to avoid scrollbar issues

This commit is contained in:
Jonas Kvinge 2022-06-06 20:54:15 +02:00
parent be01e28068
commit a2320b99ae
5 changed files with 26 additions and 5 deletions

View File

@ -43,7 +43,6 @@
#include "contextview.h" #include "contextview.h"
#include "contextalbum.h" #include "contextalbum.h"
const int ContextAlbum::kWidgetSpacing = 40;
const int ContextAlbum::kFadeTimeLineMs = 1000; const int ContextAlbum::kFadeTimeLineMs = 1000;
ContextAlbum::ContextAlbum(QWidget *parent) ContextAlbum::ContextAlbum(QWidget *parent)
@ -97,7 +96,7 @@ QSize ContextAlbum::sizeHint() const {
} }
void ContextAlbum::paintEvent(QPaintEvent*) { void ContextAlbum::resizeEvent(QResizeEvent *e) {
if (width() != prev_width_) { if (width() != prev_width_) {
ScaleCover(); ScaleCover();
@ -105,6 +104,12 @@ void ContextAlbum::paintEvent(QPaintEvent*) {
prev_width_ = width(); prev_width_ = width();
} }
QWidget::resizeEvent(e);
}
void ContextAlbum::paintEvent(QPaintEvent*) {
QPainter p(this); QPainter p(this);
p.setRenderHint(QPainter::SmoothPixmapTransform); p.setRenderHint(QPainter::SmoothPixmapTransform);
DrawPreviousCovers(&p); DrawPreviousCovers(&p);

View File

@ -54,6 +54,7 @@ class ContextAlbum : public QWidget {
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;
@ -92,7 +93,6 @@ class ContextAlbum : public QWidget {
void SearchCoverInProgress(); void SearchCoverInProgress();
private: private:
static const int kWidgetSpacing;
static const int kFadeTimeLineMs; static const int kFadeTimeLineMs;
private: private:

View File

@ -69,6 +69,8 @@
#include "contextview.h" #include "contextview.h"
#include "contextalbum.h" #include "contextalbum.h"
const int ContextView::kWidgetSpacing = 40;
ContextView::ContextView(QWidget *parent) ContextView::ContextView(QWidget *parent)
: QWidget(parent), : QWidget(parent),
app_(nullptr), app_(nullptr),
@ -125,7 +127,7 @@ ContextView::ContextView(QWidget *parent)
lyrics_id_(-1), lyrics_id_(-1),
font_size_headline_(0), font_size_headline_(0),
font_size_normal_(0), font_size_normal_(0),
prev_width_(0) { prev_width_(width()) {
setLayout(layout_container_); setLayout(layout_container_);
@ -359,6 +361,17 @@ void ContextView::ReloadSettings() {
} }
void ContextView::resizeEvent(QResizeEvent *e) {
if (prev_width_ != width()) {
widget_album_->setFixedWidth(width() - kWidgetSpacing);
prev_width_ = width();
}
QWidget::resizeEvent(e);
}
void ContextView::Playing() {} void ContextView::Playing() {}
void ContextView::Stopped() { void ContextView::Stopped() {

View File

@ -64,6 +64,7 @@ class ContextView : public QWidget {
Song song_playing() const { return song_playing_; } Song song_playing() const { return song_playing_; }
protected: protected:
void resizeEvent(QResizeEvent *e) override;
void contextMenuEvent(QContextMenuEvent*) override; void contextMenuEvent(QContextMenuEvent*) override;
void dragEnterEvent(QDragEnterEvent*) override; void dragEnterEvent(QDragEnterEvent*) override;
void dropEvent(QDropEvent*) override; void dropEvent(QDropEvent*) override;
@ -101,6 +102,8 @@ class ContextView : public QWidget {
void AlbumCoverLoaded(const Song &song, const QImage &image); void AlbumCoverLoaded(const Song &song, const QImage &image);
private: private:
static const int kWidgetSpacing;
Application *app_; Application *app_;
CollectionView *collectionview_; CollectionView *collectionview_;
AlbumCoverChoiceController *album_cover_choice_controller_; AlbumCoverChoiceController *album_cover_choice_controller_;