123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- #include "WindowMain.h"
- #include <QApplication>
- #include <QSplashScreen>
- #include "quiwidget.h"
- #include "DebugManager.h"
- #include "DialogSoftKeyboard.h"
- #include "LoggerModule.h"
- QString TextColor = "#F0F0F0";
- QString PanelColor = "#F0F0F0";
- QString BorderColor = "#F0F0F0";
- QString NormalColorStart = "#F0F0F0";
- QString NormalColorEnd = "#F0F0F0";
- QString DarkColorStart = "#F0F0F0";
- QString DarkColorEnd = "#F0F0F0";
- QString HighColor = "#F0F0F0";
- void getQssColor(const QString& qss, QString& textColor, QString& panelColor, QString& borderColor,
- QString& normalColorStart, QString& normalColorEnd,
- QString& darkColorStart, QString& darkColorEnd, QString& highColor)
- {
- QString str = qss;
- QString flagTextColor = "TextColor:";
- int indexTextColor = str.indexOf(flagTextColor);
- if (indexTextColor >= 0) {
- textColor = str.mid(indexTextColor + flagTextColor.length(), 7);
- }
- QString flagPanelColor = "PanelColor:";
- int indexPanelColor = str.indexOf(flagPanelColor);
- if (indexPanelColor >= 0) {
- panelColor = str.mid(indexPanelColor + flagPanelColor.length(), 7);
- }
- QString flagBorderColor = "BorderColor:";
- int indexBorderColor = str.indexOf(flagBorderColor);
- if (indexBorderColor >= 0) {
- borderColor = str.mid(indexBorderColor + flagBorderColor.length(), 7);
- }
- QString flagNormalColorStart = "NormalColorStart:";
- int indexNormalColorStart = str.indexOf(flagNormalColorStart);
- if (indexNormalColorStart >= 0) {
- normalColorStart = str.mid(indexNormalColorStart + flagNormalColorStart.length(), 7);
- }
- QString flagNormalColorEnd = "NormalColorEnd:";
- int indexNormalColorEnd = str.indexOf(flagNormalColorEnd);
- if (indexNormalColorEnd >= 0) {
- normalColorEnd = str.mid(indexNormalColorEnd + flagNormalColorEnd.length(), 7);
- }
- QString flagDarkColorStart = "DarkColorStart:";
- int indexDarkColorStart = str.indexOf(flagDarkColorStart);
- if (indexDarkColorStart >= 0) {
- darkColorStart = str.mid(indexDarkColorStart + flagDarkColorStart.length(), 7);
- }
- QString flagDarkColorEnd = "DarkColorEnd:";
- int indexDarkColorEnd = str.indexOf(flagDarkColorEnd);
- if (indexDarkColorEnd >= 0) {
- darkColorEnd = str.mid(indexDarkColorEnd + flagDarkColorEnd.length(), 7);
- }
- QString flagHighColor = "HighColor:";
- int indexHighColor = str.indexOf(flagHighColor);
- if (indexHighColor >= 0) {
- highColor = str.mid(indexHighColor + flagHighColor.length(), 7);
- }
- }
- // 添加本地环境变量
- void setDirPath()
- {
- QString strDirPath = QCoreApplication::applicationDirPath() + "/syslib/";
- QDir dir(strDirPath);
- QFileInfoList fileInfoList = dir.entryInfoList(QDir::Files | QDir::NoDotAndDotDot | QDir::Dirs);
- QString envPath = qgetenv("PATH");
- // 首先在 syslib 根目录下设置环境变量
- envPath += QDir::toNativeSeparators(strDirPath).prepend(';');
- for (int i = 0; i < fileInfoList.size(); i++)
- {
- // 遍历所有目录,并设置环境变量
- QString str = fileInfoList[i].filePath();
- envPath += QDir::toNativeSeparators(str).prepend(';');
- }
- qputenv("PATH", envPath.toStdString().c_str());
- }
- int main(int argc, char *argv[])
- {
- // 高分屏缩放支持
- QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
- // 高分屏缩放策略设置
- QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
- // 初始化调试信息管理器,用来重定向调试信息
- DebugManager::getInstance()->initManager();
- QApplication a(argc, argv);
- // 设置全局界面风格
- // QApplication::setStyle(QStyleFactory::create("fusion"));
- // 添加本地环境变量
- setDirPath();
- // 检查本地halcon库是否可以正常运行
- try
- {
- HTuple ht_Version;
- GetSystemInfo("version", &ht_Version);
- }
- catch (...)
- {
- qWarning() << "Vision lib Error";
- return a.exec();
- }
- // 显示Splash界面
- QString path = ":/image/Splash.png";
- QString strPath = QCoreApplication::applicationDirPath() + "/Splash.bmp";
- QFileInfo info(strPath);
- if (info.exists() != true)
- {
- strPath = path;
- }
- QPixmap pix(strPath);
- QSplashScreen splash(pix);
- splash.show();
- a.processEvents();
- // 全局变量区域初始化
- VPGlobal::init();
-
- QString qssFile = ":/image/qss/black.css";
- QFile file(qssFile);
- if (file.open(QFile::ReadOnly))
- {
- QString qss = QLatin1String(file.readAll());
- QString paletteColor = qss.mid(20, 7);
- getQssColor(qss, TextColor, PanelColor, BorderColor, NormalColorStart, NormalColorEnd, DarkColorStart, DarkColorEnd, HighColor);
- qApp->setPalette(QPalette(QColor(paletteColor)));
- qApp->setStyleSheet(qss);
- file.close();
- }
- //实例化输入法
- //DialogSoftKeyboard::Instance()->hide();
- //仅仅当做独立组件使用 默认不启用
- //frmInput::Instance()->setOnlyControl(true);
- //仅仅触摸屏使用 默认不启用
- //frmInput::Instance()->setOnlyTouch(true);
- //启用实体键盘(硬键盘)同步 默认不启用
- //DialogSoftKeyboard::Instance()->setUseHardKeyBoard(true);
- //以下方法设置字体+面板宽高+图标大小+候选字高度
- //可以自行改成板子上的字体
- //frmInput::Instance()->setFontInfo("HiveOS CN Regular", 18, 16
- //frmInput::Instance()->setFontInfo("MicroSoft Yahei", 18, 16);
- //DialogSoftKeyboard::Instance()->setFixedSize2(650, 280);
- //DialogSoftKeyboard::Instance()->setIconSize(13, 13);
- //DialogSoftKeyboard::Instance()->setTopHeight(40);
- // WindowMain w;
- //w.show();
- QUIWidget qui(new WindowMain);
- #ifdef QT_NO_DEBUG
- //qui.setWindowState(Qt::WindowFullScreen);
- qui.setWindowState(Qt::WindowMaximized);
- #else
- // 设置窗体的初始化大小
- qui.resize(QSize(DEFAULT_WIDTH, DEFAULT_HEIGHT));
- #endif
-
- qui.show();
- splash.finish(&qui);
- //WindowMain w;
- //w.show();
- //splash.finish(&w);
- return a.exec();
- }
|