FluentUI/example/src/main.cpp

87 lines
3.0 KiB
C++
Raw Normal View History

2023-05-22 16:17:51 +08:00
#include <QGuiApplication>
2023-02-24 18:44:29 +08:00
#include <QQmlApplicationEngine>
2023-03-03 18:19:48 +08:00
#include <QQmlContext>
2023-03-05 23:39:13 +08:00
#include <QDir>
2023-03-09 13:23:39 +08:00
#include <QQuickWindow>
2023-07-21 11:19:30 +08:00
#include <QNetworkProxy>
#include <QSslConfiguration>
2023-03-05 23:39:13 +08:00
#include <QProcess>
2023-09-09 20:09:20 +08:00
#include <QtQml/qqmlextensionplugin.h>
2023-09-27 18:10:20 +08:00
#include <QLoggingCategory>
2024-01-03 16:56:28 +08:00
#include "Version.h"
2023-04-11 23:12:31 +08:00
#include "AppInfo.h"
2023-12-04 21:18:19 +08:00
#include "helper/Log.h"
2023-08-24 15:50:37 +08:00
#include "src/component/CircularReveal.h"
#include "src/component/FileWatcher.h"
2023-08-28 17:14:21 +08:00
#include "src/component/FpsItem.h"
2023-09-17 20:36:33 +08:00
#include "src/helper/SettingsHelper.h"
2023-09-09 20:09:20 +08:00
#ifdef FLUENTUI_BUILD_STATIC_LIB
#if (QT_VERSION > QT_VERSION_CHECK(6, 2, 0))
Q_IMPORT_QML_PLUGIN(FluentUIPlugin)
#endif
#include <FluentUI.h>
#endif
2023-02-26 23:47:07 +08:00
2024-01-04 18:00:44 +08:00
#ifdef WIN32
#include "app_dmp.h"
#endif
2023-09-17 20:36:33 +08:00
int main(int argc, char *argv[])
2023-02-24 18:44:29 +08:00
{
2024-01-04 18:00:44 +08:00
#ifdef WIN32
::SetUnhandledExceptionFilter(MyUnhandledExceptionFilter);
2024-01-04 14:28:51 +08:00
qputenv("QT_QPA_PLATFORM","windows:darkmode=2");
#endif
2024-01-09 21:57:02 +08:00
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
2024-01-04 18:00:44 +08:00
qputenv("QT_QUICK_CONTROLS_STYLE","Basic");
2024-01-09 21:57:02 +08:00
#else
qputenv("QT_QUICK_CONTROLS_STYLE","Default");
#endif
2023-12-14 21:16:09 +08:00
#ifdef Q_OS_LINUX
//fix bug UOSv20 does not print logs
2023-12-14 11:46:51 +08:00
qputenv("QT_LOGGING_RULES","");
2023-12-14 21:16:09 +08:00
//fix bug UOSv20 v-sync does not work
2023-12-14 14:43:49 +08:00
qputenv("QSG_RENDER_LOOP","basic");
2023-12-14 21:16:09 +08:00
#endif
2023-12-06 23:57:30 +08:00
QGuiApplication::setOrganizationName("ZhuZiChu");
QGuiApplication::setOrganizationDomain("https://zhuzichu520.github.io");
QGuiApplication::setApplicationName("FluentUI");
2024-01-04 14:28:51 +08:00
QGuiApplication::setApplicationDisplayName("FluentUI Exmaple");
2024-01-03 16:56:28 +08:00
QGuiApplication::setApplicationVersion(APPLICATION_VERSION);
2023-12-06 23:57:30 +08:00
SettingsHelper::getInstance()->init(argv);
Log::setup("example");
2023-12-31 00:08:18 +08:00
#if (QT_VERSION >= QT_VERSION_CHECK(6, 5, 0))
QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGL);
#endif
2023-08-24 16:02:41 +08:00
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
#endif
#endif
2023-02-24 18:44:29 +08:00
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
2023-09-17 20:36:33 +08:00
engine.rootContext()->setContextProperty("AppInfo",AppInfo::getInstance());
engine.rootContext()->setContextProperty("SettingsHelper",SettingsHelper::getInstance());
#ifdef FLUENTUI_BUILD_STATIC_LIB
2023-09-09 20:09:20 +08:00
FluentUI::getInstance()->registerTypes(&engine);
#endif
2023-08-24 15:50:37 +08:00
qmlRegisterType<CircularReveal>("example", 1, 0, "CircularReveal");
qmlRegisterType<FileWatcher>("example", 1, 0, "FileWatcher");
2023-08-28 17:14:21 +08:00
qmlRegisterType<FpsItem>("example", 1, 0, "FpsItem");
2023-04-27 09:38:57 +08:00
const QUrl url(QStringLiteral("qrc:/example/qml/App.qml"));
2023-02-26 23:47:07 +08:00
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
2023-04-22 00:29:47 +08:00
&app, [url](QObject *obj, const QUrl &objUrl) {
if (!obj && url == objUrl)
QCoreApplication::exit(-1);
}, Qt::QueuedConnection);
2023-02-26 23:47:07 +08:00
engine.load(url);
2023-09-17 20:36:33 +08:00
const int exec = QGuiApplication::exec();
if (exec == 931) {
QProcess::startDetached(qApp->applicationFilePath(), QStringList());
}
return exec;
2023-02-24 18:44:29 +08:00
}