- 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
This commit is contained in:
@@ -41,3 +41,9 @@ void ImageSwitcher::start()
|
|||||||
connect(&timerNoContent, SIGNAL(timeout()), this, SLOT(updateImage()));
|
connect(&timerNoContent, SIGNAL(timeout()), this, SLOT(updateImage()));
|
||||||
timer.start(timeout);
|
timer.start(timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ImageSwitcher::scheduleImageUpdate()
|
||||||
|
{
|
||||||
|
// update our image in 100msec, to let the system settle
|
||||||
|
QTimer::singleShot(100, this, SLOT(updateImage()));
|
||||||
|
}
|
||||||
@@ -14,6 +14,7 @@ class ImageSwitcher : public QObject
|
|||||||
public:
|
public:
|
||||||
ImageSwitcher(MainWindow& w, unsigned int timeout, std::unique_ptr<ImageSelector>& selector);
|
ImageSwitcher(MainWindow& w, unsigned int timeout, std::unique_ptr<ImageSelector>& selector);
|
||||||
void start();
|
void start();
|
||||||
|
void scheduleImageUpdate();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void updateImage();
|
void updateImage();
|
||||||
|
|||||||
@@ -118,31 +118,7 @@ bool MainWindow::event(QEvent* event)
|
|||||||
void MainWindow::resizeEvent(QResizeEvent* event)
|
void MainWindow::resizeEvent(QResizeEvent* event)
|
||||||
{
|
{
|
||||||
QMainWindow::resizeEvent(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);
|
updateImage(true);
|
||||||
if(lastScreenSize != screenSize && switcher != nullptr)
|
|
||||||
{
|
|
||||||
lastScreenSize = screenSize;
|
|
||||||
if(debugMode)
|
|
||||||
{
|
|
||||||
std::cout << "Updating image due to resize" << std::endl;
|
|
||||||
}
|
|
||||||
switcher->updateImage();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::checkWindowSize()
|
void MainWindow::checkWindowSize()
|
||||||
@@ -158,6 +134,29 @@ void MainWindow::checkWindowSize()
|
|||||||
std::cout << "Resizing Window" << screenSize.width() << "," << screenSize.height() << std::endl;
|
std::cout << "Resizing Window" << screenSize.width() << "," << screenSize.height() << std::endl;
|
||||||
}
|
}
|
||||||
setFixedSize(screenSize);
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user