288 lines
6.7 KiB
C++
288 lines
6.7 KiB
C++
#include "mainwindow.h"
|
|
#include <QApplication>
|
|
#include <QTextCodec>
|
|
#include <QDesktopWidget>
|
|
#include <QScreen>
|
|
#include <QDir>
|
|
#include <QTranslator>
|
|
#include <QDebug>
|
|
#include <QTextCodec>
|
|
|
|
//#include <QQmlEngine>
|
|
|
|
#include "QScreen"
|
|
#include <QtGlobal>
|
|
|
|
|
|
#include <QStyleFactory>
|
|
//include
|
|
#include "dlink.h"
|
|
|
|
#include "QProcess"
|
|
|
|
|
|
#include "Windows.h"
|
|
|
|
|
|
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
|
|
|
|
QScreen *screen=QGuiApplication::primaryScreen ();
|
|
QRect mm=screen->availableGeometry();
|
|
int screen_width = mm.width();
|
|
int screen_height = mm.height();
|
|
qDebug()<<"availableGeometry:" << screen_width<<screen_height;
|
|
|
|
int max_width = 1920;
|
|
int max_height = 1080;
|
|
|
|
if(screen_width >= max_width)
|
|
{
|
|
screen_width = max_width;
|
|
}
|
|
|
|
if(screen_height >= max_height)
|
|
{
|
|
screen_height = max_height;
|
|
}
|
|
|
|
//return QSize(screen_width, screen_height);//最大1366*768
|
|
return QSize(1080, 720);//最大1366*768
|
|
}
|
|
|
|
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");//如果文件夹不存在就新建
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
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));
|
|
}
|
|
}
|
|
|
|
QStringList getFiles(const QString &filePath,const QString &fileSuffix)
|
|
{
|
|
QStringList list;
|
|
list.clear();
|
|
|
|
QDir Dir(filePath); //查看工作路径是否存在
|
|
if(!Dir.exists()){ return list;} //如果文件夹不存在则返回
|
|
Dir.setFilter(QDir::Files); //设置过滤器只查看文件
|
|
QFileInfoList filelist = Dir.entryInfoList(QDir::Files); //获取所有文件
|
|
|
|
foreach (QFileInfo file, filelist) //遍历只加载.fileSuffix到文件列表
|
|
{
|
|
|
|
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)
|
|
{
|
|
QTranslator * qtTranslator = new QTranslator{};
|
|
QString lang = "qt_" + QLocale::system().name();
|
|
if (qtTranslator->load(lang, QLibraryInfo::location(QLibraryInfo::TranslationsPath))
|
|
&& a->installTranslator(qtTranslator))
|
|
{
|
|
qDebug() << "Success to load translator " <<lang << " from " << QLibraryInfo::location(QLibraryInfo::TranslationsPath);
|
|
}
|
|
else
|
|
{
|
|
qWarning() << "Fail to load translator " <<lang << " from " << QLibraryInfo::location(QLibraryInfo::TranslationsPath);
|
|
}
|
|
|
|
//导入全部的翻译文件
|
|
QStringList filelist = getFiles("./Language","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)
|
|
{
|
|
|
|
}
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
/*
|
|
QString dllpath = "./dll";
|
|
LPCWSTR path = dllpath.toStdWString().c_str();
|
|
SetDllDirectory(path);
|
|
*/
|
|
|
|
|
|
|
|
|
|
makeDir();
|
|
|
|
QApplication a(argc, argv);
|
|
|
|
a.setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);
|
|
QTextCodec::setCodecForLocale(QTextCodec::codecForName("utf8"));
|
|
|
|
|
|
setLibPath();
|
|
LoadLang(&a);
|
|
RegisterType();
|
|
|
|
|
|
|
|
/*
|
|
QProcess *process = new QProcess();
|
|
QString str = QApplication::applicationDirPath();
|
|
str += "/geoserver/httpserver.exe";
|
|
*/
|
|
|
|
|
|
//process->start(str);
|
|
|
|
/*if(process->startDetached(str))
|
|
{
|
|
qInfo() << "start up geo server success";
|
|
}
|
|
else
|
|
{
|
|
qInfo() << "start up geo server failure";
|
|
}
|
|
|
|
|
|
qDebug() << str;
|
|
*/
|
|
|
|
MainWindow w;//这一步已经全部初始化完成
|
|
|
|
w.setWindowTitle(QString("GCS Qt%1 %2").arg(QT_VERSION_STR).arg(APP_VERSION));//with version
|
|
|
|
w.resize(GetDesktopSize());
|
|
|
|
QScreen *screen=QGuiApplication::primaryScreen ();;
|
|
w.move((screen->availableGeometry().width()-w.width())/2,(screen->availableGeometry().height()-w.height())/2);
|
|
|
|
w.show();
|
|
|
|
return a.exec();
|
|
|
|
/*
|
|
if(process)
|
|
process->close();
|
|
delete process;
|
|
process = 0;
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|