From 2e96ea48147e3ad14b07dc85b7eeb79ab4b9a369 Mon Sep 17 00:00:00 2001 From: Alfred Reynolds Date: Fri, 6 Aug 2021 17:29:28 +1200 Subject: [PATCH] - improve support for on the fly rotation of our window. Schedule the image update for a future frame so we don't block right away and clear the current image. This also fixes loading multiple images during a rotation as it takes time for geometry changes to apply to QT --- src/imageswitcher.cpp | 6 ++++++ src/imageswitcher.h | 1 + src/mainwindow.cpp | 49 +++++++++++++++++++++---------------------- 3 files changed, 31 insertions(+), 25 deletions(-) diff --git a/src/imageswitcher.cpp b/src/imageswitcher.cpp index 892bedc..109c98e 100644 --- a/src/imageswitcher.cpp +++ b/src/imageswitcher.cpp @@ -41,3 +41,9 @@ void ImageSwitcher::start() connect(&timerNoContent, SIGNAL(timeout()), this, SLOT(updateImage())); timer.start(timeout); } + +void ImageSwitcher::scheduleImageUpdate() +{ + // update our image in 100msec, to let the system settle + QTimer::singleShot(100, this, SLOT(updateImage())); +} \ No newline at end of file diff --git a/src/imageswitcher.h b/src/imageswitcher.h index f0f665c..46a79bc 100644 --- a/src/imageswitcher.h +++ b/src/imageswitcher.h @@ -14,6 +14,7 @@ class ImageSwitcher : public QObject public: ImageSwitcher(MainWindow& w, unsigned int timeout, std::unique_ptr& selector); void start(); + void scheduleImageUpdate(); public slots: void updateImage(); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 3f0ca19..3516333 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -118,31 +118,7 @@ bool MainWindow::event(QEvent* event) void MainWindow::resizeEvent(QResizeEvent* event) { QMainWindow::resizeEvent(event); - // the window size in this event may not match the monitor size, so use QGuiApplication to find the true monitor size - QScreen *screen = QGuiApplication::primaryScreen(); - if (screen != nullptr) - { - QSize screenSize = screen->geometry().size(); - bool isLandscape = screenSize.width() > screenSize.height(); - if (imageAspectMatchesMonitor) - { - baseImageOptions.onlyAspect = isLandscape ? ImageAspect_Landscape : ImageAspect_Portrait; - } - if(debugMode) - { - std::cout << "Got resize:" << this << " " << screenSize.width() << "," << screenSize.height() << " , is landscape? " << (isLandscape ? "y" : "n") << std::endl; - } - updateImage(true); - if(lastScreenSize != screenSize && switcher != nullptr) - { - lastScreenSize = screenSize; - if(debugMode) - { - std::cout << "Updating image due to resize" << std::endl; - } - switcher->updateImage(); - } - } + updateImage(true); } void MainWindow::checkWindowSize() @@ -158,6 +134,29 @@ void MainWindow::checkWindowSize() std::cout << "Resizing Window" << screenSize.width() << "," << screenSize.height() << std::endl; } setFixedSize(screenSize); + updateImage(true); + } + + if (imageAspectMatchesMonitor) + { + bool isLandscape = screenSize.width() > screenSize.height(); + ImageAspect newAspect = isLandscape ? ImageAspect_Landscape : ImageAspect_Portrait; + if (newAspect != baseImageOptions.onlyAspect) + { + if(debugMode) + { + std::cout << "Changing image orientation to " << newAspect << std::endl; + } + baseImageOptions.onlyAspect = newAspect; + currentImage.filename = ""; + warn("Monitor aspect changed, updating image..."); + repaint(); // force an immediate redraw as we might block for a while loading the next image + if (switcher != nullptr) + { + // pick a new image as our aspect changed, we can't just resize the image + switcher->scheduleImageUpdate(); + } + } } } }