Files

286 lines
6.7 KiB
C++
Raw Permalink Normal View History

2022-08-11 08:59:12 +08:00
#include "mainwindow.h"
2020-03-18 23:31:54 +08:00
#include <QApplication>
#include <QTextCodec>
#include <QDesktopWidget>
#include <QScreen>
#include <QDir>
#include <QTranslator>
#include <QDebug>
#include <QTextCodec>
2021-06-27 18:25:22 +08:00
//#include <QQmlEngine>
2020-04-30 17:29:57 +08:00
#include "QScreen"
2020-05-08 17:03:58 +08:00
#include <QtGlobal>
2020-03-18 23:31:54 +08:00
2020-04-09 20:19:56 +08:00
2020-10-10 12:12:30 +08:00
#include <QStyleFactory>
2020-04-09 20:19:56 +08:00
//include
#include "dlink.h"
2022-09-07 09:52:12 +08:00
#include "QProcess"
2020-04-09 20:19:56 +08:00
2022-09-23 00:36:28 +08:00
#include "Windows.h"
2020-04-09 20:19:56 +08:00
2020-03-18 23:31:54 +08:00
QSize GetDesktopSize() {
#ifdef __arm__
int fb_fd = open("/dev/fb0", O_RDWR);
int lcd_width, lcd_height;
static struct fb_var_screeninfo var;
if(-1 == fb_fd)
{
printf("cat't open /dev/fb0 \n");
return QSize(0, 0);
}
//获取屏幕参数
if(-1 == ioctl(fb_fd, FBIOGET_VSCREENINFO, &var))
{
close(fb_fd);
printf("cat't ioctl /dev/fb0 \n");
return QSize(0, 0);
}
// 计算参数
lcd_width = var.xres;
lcd_height = var.yres;
printf("fb width:%d height:%d \n", lcd_width, lcd_height);
close(fb_fd);
return QSize(lcd_width, lcd_height);
#endif
2020-04-30 17:29:57 +08:00
QScreen *screen=QGuiApplication::primaryScreen ();
QRect mm=screen->availableGeometry();
2020-04-30 17:29:57 +08:00
int screen_width = mm.width();
int screen_height = mm.height();
qDebug()<<"availableGeometry:" << screen_width<<screen_height;
2021-04-28 15:39:44 +08:00
int max_width = 1920;
int max_height = 1080;
if(screen_width >= max_width)
2020-04-30 17:29:57 +08:00
{
2021-04-28 15:39:44 +08:00
screen_width = max_width;
2020-04-30 17:29:57 +08:00
}
2021-04-28 15:39:44 +08:00
if(screen_height >= max_height)
2020-04-30 17:29:57 +08:00
{
2021-04-28 15:39:44 +08:00
screen_height = max_height;
2020-04-30 17:29:57 +08:00
}
//return QSize(screen_width, screen_height);//最大1366*768
2022-06-15 18:52:14 +08:00
return QSize(1080, 720);//最大1366*768
2020-03-18 23:31:54 +08:00
}
2022-09-15 18:16:34 +08:00
void makeDir(void)
{
//构建语言文件夹
QDir *Languagedir = new QDir;
if(!Languagedir->exists("./Language"))
{
qDebug() << "make dir Language";
Languagedir->mkdir("./Language");//如果文件夹不存在就新建
}
//构建日志目录
QDir *logdir = new QDir;
if(!logdir->exists("./log"))
{
qDebug() << "make dir log";
logdir->mkdir("./log");//如果文件夹不存在就新建
}
//构建Tlog目录
QDir *Tlogdir = new QDir;
if(!Tlogdir->exists("./log/tlog"))
{
qDebug() << "make dir tlog";
Tlogdir->mkdir("./log/tlog");//如果文件夹不存在就新建
}
//构建CSV目录
QDir *csvlog = new QDir;
if(!csvlog->exists("./log/csv"))
{
qDebug() << "make dir csv";
csvlog->mkdir("./log/csv");//如果文件夹不存在就新建
}
//构建文本日志目录
QDir *textlog = new QDir;
if(!textlog->exists("./log/textlog"))
{
qDebug() << "make dir textlog";
textlog->mkdir("./log/textlog");//如果文件夹不存在就新建
}
//构建Other目录
QDir *Otherdir = new QDir;
if(!Otherdir->exists("./log/other"))
{
qDebug() << "make dir other";
Otherdir->mkdir("./log/other");//如果文件夹不存在就新建
}
}
2020-03-18 23:31:54 +08:00
void CheckDir(const QString &path) {
QDir dir(path);
if (!dir.exists()) {
dir.mkpath(path);
}
}
void CheckDirs(const QString &path, const QStringList &dirs) {
for (int i = 0; i < dirs.size(); i++) {
CheckDir(path + dirs.at(i));
}
}
2022-08-16 20:35:36 +08:00
QStringList getFiles(const QString &filePath,const QString &fileSuffix)
{
QStringList list;
list.clear();
QDir Dir(filePath); //查看工作路径是否存在
if(!Dir.exists()){ return list;} //如果文件夹不存在则返回
Dir.setFilter(QDir::Files); //设置过滤器只查看文件
2022-09-23 00:36:28 +08:00
QFileInfoList filelist = Dir.entryInfoList(QDir::Files); //获取所有文件
2022-09-15 18:16:34 +08:00
2022-09-23 00:36:28 +08:00
foreach (QFileInfo file, filelist) //遍历只加载.fileSuffix到文件列表
2022-08-16 20:35:36 +08:00
{
2022-09-15 18:16:34 +08:00
2022-08-16 20:35:36 +08:00
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);
2022-09-15 18:16:34 +08:00
//qDebug() << strLibPath;
2022-08-16 20:35:36 +08:00
}
2020-03-18 23:31:54 +08:00
2020-04-09 20:19:56 +08:00
void LoadLang(QApplication *a)
2020-03-18 23:31:54 +08:00
{
QTranslator * qtTranslator = new QTranslator{};
QString lang = "qt_" + QLocale::system().name();
if (qtTranslator->load(lang, QLibraryInfo::location(QLibraryInfo::TranslationsPath))
2020-04-09 20:19:56 +08:00
&& a->installTranslator(qtTranslator))
2020-03-18 23:31:54 +08:00
{
qDebug() << "Success to load translator " <<lang << " from " << QLibraryInfo::location(QLibraryInfo::TranslationsPath);
}
else
{
qWarning() << "Fail to load translator " <<lang << " from " << QLibraryInfo::location(QLibraryInfo::TranslationsPath);
}
2022-08-16 20:35:36 +08:00
//导入全部的翻译文件
2022-09-15 18:16:34 +08:00
QStringList filelist = getFiles("./Language","qm");
2022-08-16 20:35:36 +08:00
foreach (QString lang, filelist) {
QTranslator * Translator = new QTranslator{};
if (Translator->load(lang, QCoreApplication::applicationDirPath())
&& a->installTranslator(Translator))
{
qDebug() << "load translator " <<lang << " from " << QCoreApplication::applicationDirPath();
}
2020-03-18 23:31:54 +08:00
}
2022-08-16 20:35:36 +08:00
2020-04-09 20:19:56 +08:00
}
2020-03-18 23:31:54 +08:00
2022-08-16 20:35:36 +08:00
2020-04-09 20:19:56 +08:00
void RegisterType(void)
{
2020-03-18 23:31:54 +08:00
2020-04-09 20:19:56 +08:00
}
2020-04-09 20:19:56 +08:00
int main(int argc, char *argv[])
{
2022-09-23 00:36:28 +08:00
/*
2022-09-15 18:16:34 +08:00
QString dllpath = "./dll";
LPCWSTR path = dllpath.toStdWString().c_str();
SetDllDirectory(path);
2022-09-23 00:36:28 +08:00
*/
2022-09-15 18:16:34 +08:00
makeDir();
2020-04-09 20:19:56 +08:00
QApplication a(argc, argv);
2020-05-08 18:50:17 +08:00
a.setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);
2020-10-11 19:10:57 +08:00
QTextCodec::setCodecForLocale(QTextCodec::codecForName("utf8"));
2022-09-15 18:16:34 +08:00
2022-08-16 20:35:36 +08:00
setLibPath();
2020-04-09 20:19:56 +08:00
LoadLang(&a);
RegisterType();
2020-10-10 20:22:04 +08:00
2022-09-15 18:16:34 +08:00
/*
2022-09-07 09:52:12 +08:00
QProcess *process = new QProcess();
QString str = QApplication::applicationDirPath();
str += "/geoserver/httpserver.exe";
2022-09-15 18:16:34 +08:00
*/
2022-09-07 09:52:12 +08:00
//process->start(str);
/*if(process->startDetached(str))
{
qInfo() << "start up geo server success";
}
else
{
qInfo() << "start up geo server failure";
}
2022-09-15 18:16:34 +08:00
2022-09-07 09:52:12 +08:00
qDebug() << str;
2022-09-15 18:16:34 +08:00
*/
2022-09-07 09:52:12 +08:00
2020-05-08 17:03:58 +08:00
MainWindow w;//这一步已经全部初始化完成
2020-12-30 00:12:15 +08:00
w.setWindowTitle(QString("GCS Qt%1 %2").arg(QT_VERSION_STR).arg(APP_VERSION));//with version
2022-08-16 20:35:36 +08:00
w.resize(GetDesktopSize());
QScreen *screen=QGuiApplication::primaryScreen ();;
w.move((screen->availableGeometry().width()-w.width())/2,(screen->availableGeometry().height()-w.height())/2);
2020-03-18 23:31:54 +08:00
w.show();
return a.exec();
2022-09-07 09:52:12 +08:00
2022-09-15 18:16:34 +08:00
/*
2022-09-07 09:52:12 +08:00
if(process)
process->close();
delete process;
process = 0;
2022-09-15 18:16:34 +08:00
*/
2022-09-07 09:52:12 +08:00
2020-03-18 23:31:54 +08:00
}