From e0ec4037545d4a5a0b8745cc7c20fa6d7f824726 Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Sun, 30 Apr 2017 02:10:37 +0100 Subject: [PATCH] workaround macOS weirdness where ImageOverlayDialog shows tiny image ImageOverlayDialog::paintEvent was being called three times: width and height is 76 , 30 width and height is 1460 , 1200 width and height is 1460 , 1200 Presumably the first one is before the fullscreen kicks in. However, this meant that the image got squashed and never recovered. Therefore this doesn't destroy the original image but keeps a copy for the resized one. I'm slightly surprised that we actually have to scale the image though - can't Qt do this for you, if you tell it to draw the image into the right sized container? --- include/ImageOverlayDialog.h | 1 + src/ImageOverlayDialog.cc | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/include/ImageOverlayDialog.h b/include/ImageOverlayDialog.h index 21f59d12..87724309 100644 --- a/include/ImageOverlayDialog.h +++ b/include/ImageOverlayDialog.h @@ -35,6 +35,7 @@ protected: private: void scaleImage(int width, int height); + QPixmap originalImage_; QPixmap image_; QRect content_; diff --git a/src/ImageOverlayDialog.cc b/src/ImageOverlayDialog.cc index 0fe1c0e4..2e032562 100644 --- a/src/ImageOverlayDialog.cc +++ b/src/ImageOverlayDialog.cc @@ -21,8 +21,8 @@ #include "ImageOverlayDialog.h" ImageOverlayDialog::ImageOverlayDialog(QPixmap image, QWidget *parent) - : QDialog{parent} - , image_{image} + : QDialog{parent} + , originalImage_{image} { setMouseTracking(true); setModal(false); @@ -41,11 +41,11 @@ ImageOverlayDialog::ImageOverlayDialog(QPixmap image, QWidget *parent) // TODO: Move this into Utils void ImageOverlayDialog::scaleImage(int max_width, int max_height) { - if (image_.isNull()) + if (originalImage_.isNull()) return; - auto width_ratio = (double)max_width / (double)image_.width(); - auto height_ratio = (double)max_height / (double)image_.height(); + auto width_ratio = (double)max_width / (double)originalImage_.width(); + auto height_ratio = (double)max_height / (double)originalImage_.height(); auto min_aspect_ratio = std::min(width_ratio, height_ratio); @@ -53,14 +53,14 @@ void ImageOverlayDialog::scaleImage(int max_width, int max_height) int final_height = 0; if (min_aspect_ratio > 1) { - final_width = image_.width(); - final_height = image_.height(); + final_width = originalImage_.width(); + final_height = originalImage_.height(); } else { - final_width = image_.width() * min_aspect_ratio; - final_height = image_.height() * min_aspect_ratio; + final_width = originalImage_.width() * min_aspect_ratio; + final_height = originalImage_.height() * min_aspect_ratio; } - image_ = image_.scaled(final_width, final_height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); + image_ = originalImage_.scaled(final_width, final_height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); } void ImageOverlayDialog::paintEvent(QPaintEvent *event)