From b062febea0038c8e05b070bff5b9afd6e3c6d9f6 Mon Sep 17 00:00:00 2001 From: Felipe Bugno Date: Mon, 9 Nov 2020 21:49:22 -0300 Subject: [PATCH] Fix HiDPI scaling for glow animation and drag over playlist This set the proper scaling and pixel ratio of QPixmap widgets used as cached objects. Most of cached objects uses a custom QPaint instead of the default painter object from the parent widget. The problem is that, unlike the painter from the parent object, set by the main application, and that has DPI and scaling settings from the device, these custom QPainters don't know about the underlying device, thus uses a scale of 1 to render artifacts. When a cached object "edited" by a custom QPaint along his pipeline where used on a paint or drawrow routine, his stored image is distorted and burred in a effort to resize it to the display configuration. --- src/playlist/playlistview.cpp | 9 +++++++-- src/playlist/playlistview.h | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/playlist/playlistview.cpp b/src/playlist/playlistview.cpp index 443cc5272..84fd2d5e6 100644 --- a/src/playlist/playlistview.cpp +++ b/src/playlist/playlistview.cpp @@ -214,6 +214,9 @@ PlaylistView::PlaylistView(QWidget *parent) dynamic_controls_->hide(); + // To proper scale all pixmaps + device_pixel_ratio = this->devicePixelRatioF(); + // For fading connect(fade_animation_, SIGNAL(valueChanged(qreal)), SLOT(FadePreviousBackgroundImage(qreal))); fade_animation_->setDirection(QTimeLine::Backward); // 1.0 -> 0.0 @@ -557,7 +560,8 @@ void PlaylistView::UpdateCachedCurrentRowPixmap(QStyleOptionViewItem option, con cached_current_row_row_ = idx.row(); option.rect.moveTo(0, 0); - cached_current_row_ = QPixmap(option.rect.size()); + cached_current_row_ = QPixmap(option.rect.width() * device_pixel_ratio, option.rect.height() * device_pixel_ratio); + cached_current_row_.setDevicePixelRatio(device_pixel_ratio); cached_current_row_.fill(Qt::transparent); QPainter p(&cached_current_row_); @@ -1023,7 +1027,8 @@ void PlaylistView::paintEvent(QPaintEvent *event) { if (drop_indicator_row_ != -1) { if (cached_tree_.isNull()) { - cached_tree_ = QPixmap(size()); + cached_tree_ = QPixmap(size().width() * device_pixel_ratio, size().height() * device_pixel_ratio); + cached_tree_.setDevicePixelRatio(device_pixel_ratio); cached_tree_.fill(Qt::transparent); QPainter cache_painter(&cached_tree_); diff --git a/src/playlist/playlistview.h b/src/playlist/playlistview.h index c685ad02a..ac6df1d36 100644 --- a/src/playlist/playlistview.h +++ b/src/playlist/playlistview.h @@ -220,6 +220,7 @@ class PlaylistView : public QTreeView { Playlist *playlist_; PlaylistHeader *header_; + qreal device_pixel_ratio; AppearanceSettingsPage::BackgroundImageType background_image_type_; QString background_image_filename_; AppearanceSettingsPage::BackgroundImagePosition background_image_position_;