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?
This commit is contained in:
Matthew Hodgson 2017-04-30 02:10:37 +01:00
parent 57070f12be
commit e0ec403754
2 changed files with 11 additions and 10 deletions

View File

@ -35,6 +35,7 @@ protected:
private:
void scaleImage(int width, int height);
QPixmap originalImage_;
QPixmap image_;
QRect content_;

View File

@ -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)