main.cpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. #include "WindowMain.h"
  2. #include <QApplication>
  3. #include <QSplashScreen>
  4. #include "quiwidget.h"
  5. #include "DebugManager.h"
  6. #include "DialogSoftKeyboard.h"
  7. #include "LoggerModule.h"
  8. QString TextColor = "#F0F0F0";
  9. QString PanelColor = "#F0F0F0";
  10. QString BorderColor = "#F0F0F0";
  11. QString NormalColorStart = "#F0F0F0";
  12. QString NormalColorEnd = "#F0F0F0";
  13. QString DarkColorStart = "#F0F0F0";
  14. QString DarkColorEnd = "#F0F0F0";
  15. QString HighColor = "#F0F0F0";
  16. void getQssColor(const QString& qss, QString& textColor, QString& panelColor, QString& borderColor,
  17. QString& normalColorStart, QString& normalColorEnd,
  18. QString& darkColorStart, QString& darkColorEnd, QString& highColor)
  19. {
  20. QString str = qss;
  21. QString flagTextColor = "TextColor:";
  22. int indexTextColor = str.indexOf(flagTextColor);
  23. if (indexTextColor >= 0) {
  24. textColor = str.mid(indexTextColor + flagTextColor.length(), 7);
  25. }
  26. QString flagPanelColor = "PanelColor:";
  27. int indexPanelColor = str.indexOf(flagPanelColor);
  28. if (indexPanelColor >= 0) {
  29. panelColor = str.mid(indexPanelColor + flagPanelColor.length(), 7);
  30. }
  31. QString flagBorderColor = "BorderColor:";
  32. int indexBorderColor = str.indexOf(flagBorderColor);
  33. if (indexBorderColor >= 0) {
  34. borderColor = str.mid(indexBorderColor + flagBorderColor.length(), 7);
  35. }
  36. QString flagNormalColorStart = "NormalColorStart:";
  37. int indexNormalColorStart = str.indexOf(flagNormalColorStart);
  38. if (indexNormalColorStart >= 0) {
  39. normalColorStart = str.mid(indexNormalColorStart + flagNormalColorStart.length(), 7);
  40. }
  41. QString flagNormalColorEnd = "NormalColorEnd:";
  42. int indexNormalColorEnd = str.indexOf(flagNormalColorEnd);
  43. if (indexNormalColorEnd >= 0) {
  44. normalColorEnd = str.mid(indexNormalColorEnd + flagNormalColorEnd.length(), 7);
  45. }
  46. QString flagDarkColorStart = "DarkColorStart:";
  47. int indexDarkColorStart = str.indexOf(flagDarkColorStart);
  48. if (indexDarkColorStart >= 0) {
  49. darkColorStart = str.mid(indexDarkColorStart + flagDarkColorStart.length(), 7);
  50. }
  51. QString flagDarkColorEnd = "DarkColorEnd:";
  52. int indexDarkColorEnd = str.indexOf(flagDarkColorEnd);
  53. if (indexDarkColorEnd >= 0) {
  54. darkColorEnd = str.mid(indexDarkColorEnd + flagDarkColorEnd.length(), 7);
  55. }
  56. QString flagHighColor = "HighColor:";
  57. int indexHighColor = str.indexOf(flagHighColor);
  58. if (indexHighColor >= 0) {
  59. highColor = str.mid(indexHighColor + flagHighColor.length(), 7);
  60. }
  61. }
  62. // 添加本地环境变量
  63. void setDirPath()
  64. {
  65. QString strDirPath = QCoreApplication::applicationDirPath() + "/syslib/";
  66. QDir dir(strDirPath);
  67. QFileInfoList fileInfoList = dir.entryInfoList(QDir::Files | QDir::NoDotAndDotDot | QDir::Dirs);
  68. QString envPath = qgetenv("PATH");
  69. // 首先在 syslib 根目录下设置环境变量
  70. envPath += QDir::toNativeSeparators(strDirPath).prepend(';');
  71. for (int i = 0; i < fileInfoList.size(); i++)
  72. {
  73. // 遍历所有目录,并设置环境变量
  74. QString str = fileInfoList[i].filePath();
  75. envPath += QDir::toNativeSeparators(str).prepend(';');
  76. }
  77. qputenv("PATH", envPath.toStdString().c_str());
  78. }
  79. int main(int argc, char *argv[])
  80. {
  81. // 高分屏缩放支持
  82. QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
  83. // 高分屏缩放策略设置
  84. QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
  85. // 初始化调试信息管理器,用来重定向调试信息
  86. DebugManager::getInstance()->initManager();
  87. QApplication a(argc, argv);
  88. // 设置全局界面风格
  89. // QApplication::setStyle(QStyleFactory::create("fusion"));
  90. // 添加本地环境变量
  91. setDirPath();
  92. // 检查本地halcon库是否可以正常运行
  93. try
  94. {
  95. HTuple ht_Version;
  96. GetSystemInfo("version", &ht_Version);
  97. }
  98. catch (...)
  99. {
  100. qWarning() << "Vision lib Error";
  101. return a.exec();
  102. }
  103. // 显示Splash界面
  104. QString path = ":/image/Splash.png";
  105. QString strPath = QCoreApplication::applicationDirPath() + "/Splash.bmp";
  106. QFileInfo info(strPath);
  107. if (info.exists() != true)
  108. {
  109. strPath = path;
  110. }
  111. QPixmap pix(strPath);
  112. QSplashScreen splash(pix);
  113. splash.show();
  114. a.processEvents();
  115. // 全局变量区域初始化
  116. VPGlobal::init();
  117. QString qssFile = ":/image/qss/black.css";
  118. QFile file(qssFile);
  119. if (file.open(QFile::ReadOnly))
  120. {
  121. QString qss = QLatin1String(file.readAll());
  122. QString paletteColor = qss.mid(20, 7);
  123. getQssColor(qss, TextColor, PanelColor, BorderColor, NormalColorStart, NormalColorEnd, DarkColorStart, DarkColorEnd, HighColor);
  124. qApp->setPalette(QPalette(QColor(paletteColor)));
  125. qApp->setStyleSheet(qss);
  126. file.close();
  127. }
  128. //实例化输入法
  129. //DialogSoftKeyboard::Instance()->hide();
  130. //仅仅当做独立组件使用 默认不启用
  131. //frmInput::Instance()->setOnlyControl(true);
  132. //仅仅触摸屏使用 默认不启用
  133. //frmInput::Instance()->setOnlyTouch(true);
  134. //启用实体键盘(硬键盘)同步 默认不启用
  135. //DialogSoftKeyboard::Instance()->setUseHardKeyBoard(true);
  136. //以下方法设置字体+面板宽高+图标大小+候选字高度
  137. //可以自行改成板子上的字体
  138. //frmInput::Instance()->setFontInfo("HiveOS CN Regular", 18, 16
  139. //frmInput::Instance()->setFontInfo("MicroSoft Yahei", 18, 16);
  140. //DialogSoftKeyboard::Instance()->setFixedSize2(650, 280);
  141. //DialogSoftKeyboard::Instance()->setIconSize(13, 13);
  142. //DialogSoftKeyboard::Instance()->setTopHeight(40);
  143. // WindowMain w;
  144. //w.show();
  145. QUIWidget qui(new WindowMain);
  146. #ifdef QT_NO_DEBUG
  147. //qui.setWindowState(Qt::WindowFullScreen);
  148. qui.setWindowState(Qt::WindowMaximized);
  149. #else
  150. // 设置窗体的初始化大小
  151. qui.resize(QSize(DEFAULT_WIDTH, DEFAULT_HEIGHT));
  152. #endif
  153. qui.show();
  154. splash.finish(&qui);
  155. //WindowMain w;
  156. //w.show();
  157. //splash.finish(&w);
  158. return a.exec();
  159. }