This commit is contained in:
hm
2022-08-16 20:35:36 +08:00
parent 49eb2c7215
commit c96e464220
14 changed files with 643 additions and 498 deletions
+43 -43
View File
@@ -87,6 +87,35 @@ void CheckDirs(const QString &path, const QStringList &dirs) {
}
}
QStringList getFiles(const QString &filePath,const QString &fileSuffix)
{
QStringList list;
list.clear();
QDir Dir(filePath); //查看工作路径是否存在
if(!Dir.exists()){ return list;} //如果文件夹不存在则返回
Dir.setFilter(QDir::Files); //设置过滤器只查看文件
QStringList filelist = Dir.entryList(QDir::Files); //获取所有文件
foreach (QFileInfo file, filelist) //遍历只加载.txt到文件列表
{
if(file.fileName().split(".").back() == fileSuffix) //判断进行再次确认是.fileSuffix
{
list.push_back(file.absoluteFilePath());
}
}
return list;
}
void setLibPath(void)
{
QString strLibPath(QDir::toNativeSeparators(QApplication::applicationDirPath()) + QDir::separator() + "plugins");
QApplication::addLibraryPath(strLibPath);
qDebug() << strLibPath;
}
void LoadLang(QApplication *a)
{
@@ -102,30 +131,25 @@ void LoadLang(QApplication *a)
qWarning() << "Fail to load translator " <<lang << " from " << QLibraryInfo::location(QLibraryInfo::TranslationsPath);
}
QTranslator * myappTranslator = new QTranslator{};
lang = "GCS_" + QLocale::system().name();
if (myappTranslator->load(lang, QCoreApplication::applicationDirPath())
&& a->installTranslator(myappTranslator))
{
qDebug() << "Success to load translator " <<lang << " from " << QCoreApplication::applicationDirPath();
}
else
{
qWarning() << "Fail to load translator " <<lang << " from " << QCoreApplication::applicationDirPath();
//导入全部的翻译文件
QStringList filelist = getFiles("./","qm");
foreach (QString lang, filelist) {
QTranslator * Translator = new QTranslator{};
if (Translator->load(lang, QCoreApplication::applicationDirPath())
&& a->installTranslator(Translator))
{
qDebug() << "load translator " <<lang << " from " << QCoreApplication::applicationDirPath();
}
}
}
void RegisterType(void)
{
//qmlRegisterModule("Drivers.LinkUI",1,0);
//qmlRegisterType<LinkUI>("Drivers.LinkUI",1,0,"LinkUI");
qDebug() << "register qml type";
}
@@ -133,47 +157,23 @@ int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QTranslator translator;
translator.load(":/qm/GCS_zh_CN.qm");
a.installTranslator(&translator);
QString strLibPath(QDir::toNativeSeparators(QApplication::applicationDirPath()) + QDir::separator() + "plugins");
QApplication::addLibraryPath(strLibPath);
qDebug() << strLibPath;
a.setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);
QTextCodec::setCodecForLocale(QTextCodec::codecForName("utf8"));
setLibPath();
LoadLang(&a);
RegisterType();
QStringList l = QStyleFactory::keys();
foreach (QString s, l) {
qDebug() << s;
}
//QApplication::setStyle(QStyleFactory::create("fusion"));
MainWindow w;//这一步已经全部初始化完成
w.setWindowTitle(QString("GCS Qt%1 %2").arg(QT_VERSION_STR).arg(APP_VERSION));//with version
//w.setWindowTitle(QString("KB3A-V1.00 %1").arg(APP_VERSION));//with version
// 主要是控制HDMI输出,如果是LCD显示,此行无关紧要
w.resize(GetDesktopSize());
QScreen *screen=QGuiApplication::primaryScreen ();;
w.move((screen->availableGeometry().width()-w.width())/2,(screen->availableGeometry().height()-w.height())/2);
//qDebug() << screen;
//w.setWindowState(Qt::WindowMaximized);
w.show();
return a.exec();