176 lines
4.2 KiB
C++
176 lines
4.2 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"
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
if(screen_width >= 1366)
|
|
{
|
|
screen_width = 1366;
|
|
}
|
|
|
|
if(screen_height >= 768)
|
|
{
|
|
screen_height = 768;
|
|
}
|
|
|
|
//return QSize(screen_width, screen_height);//最大1366*768
|
|
return QSize(1000, 650);//最大1366*768
|
|
}
|
|
|
|
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));
|
|
}
|
|
}
|
|
|
|
|
|
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);
|
|
}
|
|
|
|
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();
|
|
}
|
|
}
|
|
|
|
|
|
void RegisterType(void)
|
|
{
|
|
|
|
//qmlRegisterModule("Drivers.LinkUI",1,0);
|
|
|
|
//qmlRegisterType<LinkUI>("Drivers.LinkUI",1,0,"LinkUI");
|
|
|
|
|
|
qDebug() << "register qml type";
|
|
|
|
}
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
QApplication a(argc, argv);
|
|
|
|
QString strLibPath(QDir::toNativeSeparators(QApplication::applicationDirPath()) + QDir::separator() + "plugins");
|
|
|
|
QApplication::addLibraryPath(strLibPath);
|
|
|
|
qDebug() << strLibPath;
|
|
|
|
a.setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);
|
|
|
|
QTextCodec::setCodecForLocale(QTextCodec::codecForName("utf8"));
|
|
|
|
LoadLang(&a);
|
|
|
|
RegisterType();
|
|
|
|
|
|
QStringList l = QStyleFactory::keys();
|
|
|
|
foreach (QString s, l) {
|
|
qDebug() << s;
|
|
}
|
|
//QApplication::setStyle(QStyleFactory::create("fusion"));
|
|
|
|
|
|
MainWindow w;//这一步已经全部初始化完成
|
|
|
|
w.setWindowTitle(QString("GCS New Frame Qt%1 %2").arg(QT_VERSION_STR).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();
|
|
}
|
|
|
|
|
|
|