From 2bb30397e6d327797bb320058fe1a4e949312913 Mon Sep 17 00:00:00 2001
From: Sergey Fedorov <barracuda@macos-powerpc.org>
Date: Fri, 9 May 2025 20:24:22 +0800
Subject: [PATCH 2/3] mainwindow.cpp: compat fixes for Qt4

---
 src/mainwindow.cpp | 55 +++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 50 insertions(+), 5 deletions(-)

diff --git src/mainwindow.cpp src/mainwindow.cpp
index 4efdd90..ff16172 100644
--- src/mainwindow.cpp
+++ src/mainwindow.cpp
@@ -17,11 +17,18 @@
 #include <QImageReader>
 #include <QKeyEvent>
 #include <QMessageBox>
-#include <QMimeDatabase>
 #include <QProcess>
 #include <QScreen>
 #include <QThread>
-#include <QWindow>
+
+#if QT_VERSION >= 0x050000
+    #include <QWindow>
+    #include <QMimeDatabase>
+#else
+    #include <QDesktopWidget>
+    // Fallback using qt4-mimetypes library.
+    #include <QtMimeTypes/QMimeDatabase>
+#endif
 
 #include "preloadthread.h"
 
@@ -37,7 +44,12 @@ MainWindow::MainWindow(QWidget* p_Parent)
     for (auto argIt = args.begin(); argIt != args.end(); ++argIt)
     {
         const QString& arg = *argIt;
+#if QT_VERSION >= 0x050000
         if (QFileInfo::exists(arg))
+#else
+        QFileInfo fileInfo(arg);
+        if (fileInfo.exists())
+#endif
         {
             if (QFileInfo(arg).isFile())
             {
@@ -229,6 +241,7 @@ void MainWindow::PrevImage()
 
 void MainWindow::ToggleFullScreen()
 {
+#if QT_VERSION >= 0x050000
     if (windowHandle()->visibility() & QWindow::FullScreen)
     {
         windowHandle()->showNormal();
@@ -237,7 +250,16 @@ void MainWindow::ToggleFullScreen()
     {
         windowHandle()->showFullScreen();
     }
-
+#else
+    if (isFullScreen())
+    {
+        showNormal();
+    }
+    else
+    {
+        showFullScreen();
+    }
+#endif
     RefreshImage();
 }
 
@@ -249,7 +271,12 @@ void MainWindow::Exit()
 void MainWindow::RotateImage(const QString& p_Angle)
 {
     const QString program = "mogrify";
+#if QT_VERSION >= 0x050000
     const QStringList arguments = { "-rotate", p_Angle, m_Files[m_FileIndex] };
+#else
+    QStringList arguments;
+    arguments << "-rotate" << p_Angle << m_Files[m_FileIndex];
+#endif
     int rv = QProcess::execute(program, arguments);
 
     if (rv != 0)
@@ -364,13 +391,21 @@ void MainWindow::RefreshImage(bool p_ResizeWindow /*= true*/)
     }
 
     QSharedPointer<QPixmap> pixmap = LoadImage();
+#if QT_VERSION >= 0x050000
     const float screenUsage = (windowHandle()->visibility() & QWindow::FullScreen) ? 1.0 : 0.7;
     QSize size = QGuiApplication::primaryScreen()->availableGeometry().size() * screenUsage;
+#else
+    const float screenUsage = isFullScreen() ? 1.0 : 0.7;
+    QDesktopWidget desktop;
+    QSize size = desktop.availableGeometry().size() * screenUsage;
+#endif
 
 #if QT_VERSION >= 0x050600
     qreal dpr = devicePixelRatioF();
-#else
+#elif QT_VERSION >= 0x050000
     qreal dpr = devicePixelRatio();
+#else
+    qreal dpr = 1.0;
 #endif
 
     size.setWidth(size.width() * dpr);
@@ -392,7 +427,11 @@ void MainWindow::RefreshImage(bool p_ResizeWindow /*= true*/)
                    QString::number(pixmap->size().width()) + "x" + QString::number(pixmap->size().height()) + " - " +
                    QString::number(scalePercentage) + "%");
 
+#if QT_VERSION >= 0x050000
     if ((p_ResizeWindow) && !(windowHandle()->visibility() & QWindow::FullScreen))
+#else
+    if ((p_ResizeWindow) && !isFullScreen())
+#endif
     {
         resize(scaledPixmap.size() / dpr);
     }
@@ -406,7 +445,9 @@ QSharedPointer<QImage> MainWindow::LoadQImage(const QString& p_Path)
 {
     QSharedPointer<QImage> image = QSharedPointer<QImage>(new QImage());
     QImageReader imageReader(p_Path);
+#if QT_VERSION >= 0x050000
     imageReader.setAutoTransform(true);
+#endif
     imageReader.read(image.data());
     return image;
 }
@@ -424,11 +465,15 @@ QSharedPointer<QPixmap> MainWindow::LoadImage()
 
 #if QT_VERSION >= 0x050600
     qreal dpr = devicePixelRatioF();
-#else
+#elif QT_VERSION >= 0x050000
     qreal dpr = devicePixelRatio();
+#else
+    qreal dpr = 1.0;
 #endif
 
+#if QT_VERSION >= 0x050000
     pixmap->setDevicePixelRatio(dpr);
+#endif
 
     return pixmap;
 }
