mirai/src/main.cpp

47 lines
1.4 KiB
C++
Raw Normal View History

2024-04-13 11:52:42 +02:00
/*
2024-04-10 16:53:18 +02:00
* Mirai. Copyright (C) 2024 Vyn
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
*/
#include <QtCore/QRect>
2024-04-13 11:52:42 +02:00
#include <QtGui/QFont>
#include <QtGui/QGuiApplication>
2024-04-10 16:53:18 +02:00
#include <QtGui/QScreen>
#include <QtQml/QQmlApplicationEngine>
#include <exception>
#include <iostream>
#include <ostream>
int main(int argc, char *argv[])
{
try {
QGuiApplication app(argc, argv);
2024-04-13 11:52:42 +02:00
2024-04-10 16:53:18 +02:00
qreal refDpi = 54.;
qreal refHeight = 1440.;
qreal refWidth = 2560.;
QRect rect = QGuiApplication::primaryScreen()->geometry();
qreal height = qMax(rect.width(), rect.height());
qreal width = qMin(rect.width(), rect.height());
qreal dpi = QGuiApplication::primaryScreen()->logicalDotsPerInch();
2024-04-13 11:52:42 +02:00
// auto m_ratio = qMin(height/refHeight, width/refWidth);
auto m_ratioFont =
qMin(height * refDpi / (dpi * refHeight), width * refDpi / (dpi * refWidth));
2024-04-10 16:53:18 +02:00
QFont font("Helvetica", m_ratioFont);
app.setFont(font);
QQmlApplicationEngine engine;
const QUrl url(u"qrc:/qt/qml/Mirai/src/qml/Main.qml"_qs);
2024-04-13 11:52:42 +02:00
QObject::connect(
&engine, &QQmlApplicationEngine::objectCreationFailed, &app,
[]() { QCoreApplication::exit(-1); }, Qt::QueuedConnection);
2024-04-10 16:53:18 +02:00
engine.load(url);
return app.exec();
2024-04-13 11:52:42 +02:00
} catch (const std::exception &e) {
2024-04-10 16:53:18 +02:00
std::cout << e.what() << std::endl;
}
}