#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QScreen>


double MainWindow::ScreenScalingDPI()
{
    const qreal refDpi = 96.0 , refHeight = 943.0, refWidth = 1676.0;
//    QSizeF size = qApp->primaryScreen()->physicalSize();
    QRect rect2 = qApp->primaryScreen()->availableGeometry();
    QRect rect = qApp->primaryScreen()->geometry();
    qreal height = qMax(rect.width(), rect.height());
    qreal width = qMin(rect.width(), rect.height());
    qreal dpi = qApp->primaryScreen()->logicalDotsPerInch();
    double m_ratio = qMin(height/refHeight, width/refWidth);
    double m_ratioFont = qMin(height*refDpi/(dpi*refHeight), width*refDpi/(dpi*refWidth));

    //Incorrect screen size reported on Android: Qt 6.5.0, 6.4.3, 6.3.2
    //CORRECT screen size reported on:  Qt 5.12.3
    ui->listWidget->insertItem(0, QString("rect1: %1,%2").arg(rect.width()).arg(rect.height()));
    ui->listWidget->insertItem(0, QString("rect2: %1,%2").arg(rect2.width()).arg(rect2.height()));
    ui->listWidget->insertItem(0, QString("DPI: %1, ratio: %2").arg(dpi).arg(m_ratioFont));


    return m_ratioFont;
}

MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}
