2 Star 1 Fork 0

ducksoul / SGXExpress

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
main.cpp 6.35 KB
一键复制 编辑 原始数据 按行查看 历史
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QScreen>
#include <QTimer>
#include <qlogging.h>
#include "USB/usbhelper.hpp"
#include "JavaHelper/msgcenter.hpp"
#include "JavaHelper/register.hpp"
#include "Data/CommandHandler.h"
#include "Data/DataHandler.h"
#include "Data/SettingHandler.h"
const char* const applicationName = "SGXExpress";
namespace JavaMSGCenter {
QObject* g_listener;
}
#ifdef ANDROID
#include <android/log.h>
#include "Tools/QtAndroidTools.h"
#include "Tools/APKUpdater.h"
void myMessageHandler(
QtMsgType type,
const QMessageLogContext& context,
const QString& msg
)
{
QString report=msg;
if (context.file && !QString(context.file).isEmpty())
{
report += "[";
report += QString(context.file);
report += ":";
report += QString::number(context.line);
report += "]";
}
if (context.function && !QString(context.function).isEmpty())
{
report += "{";
report += QString(context.function);
report += "}";
}
int prio = ANDROID_LOG_VERBOSE;
const char*const local=report.toLocal8Bit().constData();
switch (type) {
case QtDebugMsg:
prio = ANDROID_LOG_DEBUG;
break;
case QtInfoMsg:
prio = ANDROID_LOG_INFO;
break;
case QtWarningMsg:
prio = ANDROID_LOG_WARN;
break;
case QtCriticalMsg:
prio = ANDROID_LOG_ERROR;
break;
case QtFatalMsg:
default:
__android_log_write(ANDROID_LOG_FATAL, applicationName, local);
abort();
}
__android_log_write(prio, applicationName, local);
}
#endif
int main(int argc, char *argv[])
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
qRegisterMetaType<QVector<QPointF>>();
#ifdef ANDROID
qmlRegisterUncreatableMetaObject(
UpdateState::staticMetaObject, // meta object created by Q_NAMESPACE macro
"UpdateState.Enum", // import statement (can be any string)
1, 0, // major and minor version of the import
"UpdateState", // name in QML (does not have to match C++ name)
"Error: only enums" // error in case someone tries to create a MyNamespace object
);
initContext();
qInstallMessageHandler(myMessageHandler);
QtAndroidTools::initializeQmlTools();
auto msg_center = std::make_shared<MSGCenter>();
JavaMSGCenter::g_listener = msg_center.get();
registerNativeMethods();
#endif
QApplication app(argc, argv);
app.setApplicationName(applicationName);
QScreen *screen = QGuiApplication::screens().at(0);
QPixmap pixmap(screen->size().width(), screen->size().height()); //使用全屏尺寸
pixmap.fill(QColor("#FFFFFF"));
QSplashScreen splash(pixmap); //利用图片创建一个QSplashScreen对象
QMovie movie(":/resources/splash.gif"); //创建启动需要显示的图片
QLabel label(&splash);
label.resize(pixmap.size());
label.setAlignment(Qt::AlignCenter);
label.setGeometry(QStyle::alignedRect(Qt::LeftToRight,Qt::AlignCenter,label.size(),app.screens().at(0)->availableGeometry()));
label.setMovie(&movie);
QDateTime time = QDateTime::currentDateTime();
movie.start(); //启动GIF
splash.show(); //显示图片
auto settingHandler = std::make_shared<SettingHandler>();
auto usbHelper = std::make_shared<USBHelper>();
auto commandHandler = std::make_shared<CommandHandler>(settingHandler.get());
auto dataHandler = std::make_shared<DataHandler>(settingHandler.get());
app.connect(msg_center.get(), &MSGCenter::recvUARTData, dataHandler.get(), &DataHandler::HandleUartData);
app.connect(msg_center.get(), &MSGCenter::recvDeviceInfo, [&](QString data){
Device_ID id = Invalid;
if (data.contains(device_name_map.value(SGX6000))){
id = SGX6000;
}
if (data.contains(device_name_map.value(SX666))){
id = SX666;
}
if (!usbHelper->setConnectDev(id)){
msg_center->makeToast("Device not Match");
return;
}
commandHandler->setDeviceID(id);
dataHandler->setDeviceID(id);
});
app.connect(commandHandler.get(), &CommandHandler::expectRecvNum, dataHandler.get(), &DataHandler::onExpectRecvNum, Qt::DirectConnection);
app.connect(commandHandler.get(), &CommandHandler::chartProperty, dataHandler.get(), &DataHandler::onChartProperty, Qt::DirectConnection);
app.connect(commandHandler.get(), &CommandHandler::monitorClean, dataHandler.get(), &DataHandler::setMonitorClean, Qt::DirectConnection);
app.connect(dataHandler.get(), &DataHandler::recvExpectNum, commandHandler.get(), &CommandHandler::recvExpectedNum);
app.connect(dataHandler.get(), &DataHandler::txOn, commandHandler.get(), &CommandHandler::recvTXOn);
QQmlApplicationEngine engine;
#ifdef ANDROID
auto apkupdater = std::make_shared<APKUpdater>(QApplication::applicationVersion().toInt());
engine.rootContext()->setContextProperty("apkUpdater", apkupdater.get());
//QTimer::singleShot(5000, apkupdater.get(), SLOT(openURL()));
#endif
engine.rootContext()->setContextProperty("msgCenter", msg_center.get());
engine.rootContext()->setContextProperty("dataHandler", dataHandler.get());
engine.rootContext()->setContextProperty("settingHandler", settingHandler.get());
engine.rootContext()->setContextProperty("usbHelper", usbHelper.get());
engine.rootContext()->setContextProperty("commandHandler", commandHandler.get());
const QUrl url(QStringLiteral("qrc:/main.qml"));
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
&app, [url](QObject *obj, const QUrl &objUrl) {
if (!obj && url == objUrl)
QCoreApplication::exit(-1);
}, Qt::QueuedConnection);
engine.load(url);
QDateTime currentTime = QDateTime::currentDateTime(); //记录当前时间
while (time.secsTo(currentTime) <= 2) //继续延时
{
currentTime = QDateTime::currentDateTime();
app.processEvents(); //使程序在显示启动画面的同时仍能响应鼠标其他事件
};
splash.finish(nullptr);
qDebug() << "Width:" << screen->availableGeometry().width()
<< "Height:" << screen->availableGeometry().height();
return app.exec();
}
C++
1
https://gitee.com/ducksoul/sgxexpress.git
git@gitee.com:ducksoul/sgxexpress.git
ducksoul
sgxexpress
SGXExpress
master

搜索帮助