1
0
mirror of https://github.com/jaredtao/TaoQuick.git synced 2025-01-31 21:22:58 +08:00
2020-11-07 22:56:31 +08:00

87 lines
2.8 KiB
C++

#include "AppInfo.h"
#include "Trans/Trans.h"
#include "Frameless/TaoFrameLessView.h"
#include "Logger/Logger.h"
#include "QuickTool/QuickTool.h"
#include "DeviceAddTable/DeviceAddModel.h"
#include <QDir>
#include <QGuiApplication>
#include <QQmlContext>
#include <QQmlEngine>
#include <QUrl>
#include <QQuickItem>
static void prepareApp()
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
QCoreApplication::setOrganizationName("JaredTao");
QCoreApplication::setOrganizationDomain("https://JaredTao.gitee.io");
QCoreApplication::setApplicationName("TaoQuickShow");
}
int main(int argc, char **argv)
{
prepareApp();
QGuiApplication app(argc, argv);
#ifdef TAODEBUG
// qSetMessagePattern("[%{time h:mm:ss.zzz} %{function}] %{message}");
qSetMessagePattern("[%{time h:mm:ss.zzz} %{file} row(%{line}) %{function}] %{message}");
#else
Logger::initLog();
#endif
const auto appPath = QDir::cleanPath(app.applicationDirPath());
qWarning() << "appPath" << appPath;
TaoFrameLessView view;
view.setMinimumSize({ 800, 600 });
view.resize(1440, 960);
view.moveToScreenCenter();
Trans trans;
AppInfo appInfo;
QuickTool quickTool;
trans.beforeUiReady(view.rootContext());
appInfo.beforeUiReady(view.rootContext());
view.engine()->addImportPath(qmlPath);
#ifdef TaoQuickImportPath
view.engine()->addImportPath(TaoQuickImportPath);
qWarning() << "TaoQuickImportPath " << TaoQuickImportPath;
#endif
#ifdef TaoQuickImagePath
view.rootContext()->setContextProperty("taoQuickImagePath", TaoQuickImagePath);
#endif
#ifdef TAODEBUG
view.rootContext()->setContextProperty("isDebug", true);
#else
view.rootContext()->setContextProperty("isDebug", QVariant(false));
#endif
view.rootContext()->setContextProperty("qmlPath", qmlPath);
view.rootContext()->setContextProperty("imgPath", imgPath);
view.rootContext()->setContextProperty("contentsPath", contentsPath);
view.rootContext()->setContextProperty("appPath", appPath);
view.rootContext()->setContextProperty("view", &view);
view.rootContext()->setContextProperty("quickTool", &quickTool);
DeviceAddModel model;
view.rootContext()->setContextProperty("deviceAddModel", &model);
const QUrl url(qmlPath + QStringLiteral("main.qml"));
QObject::connect(&view, &QQuickView::statusChanged, [&](QQuickView::Status status) {
if (status == QQuickView::Status::Ready) {
trans.afterUiReady();
appInfo.afterUiReady();
quickTool.setRootObjet(view.rootObject());
}
});
QObject::connect(view.engine(), &QQmlEngine::quit, qApp, &QCoreApplication::quit);
view.setSource(url);
view.moveToScreenCenter();
view.show();
return app.exec();
}