MainWnd.cpp 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054
  1. #include "MainWnd.h"
  2. #include "ui_MainWnd.h"
  3. #include "Login.h"
  4. #include <QMouseEvent>
  5. #include <qDebug>
  6. #include "OriginalWnd/OriginalWnd.h"
  7. #include <QDialogButtonBox>
  8. #include "Src/common/JLogAllOutput.h"
  9. #include "Src/SystemInfoPage/SystemInfoPage.h"
  10. MainWnd::MainWnd(QWidget* parent)
  11. : QMainWindow(parent)
  12. , ui(new Ui::MainWnd)
  13. , initialIconSet(false)
  14. {
  15. ui->setupUi(this);
  16. Init();
  17. InitForm();
  18. }
  19. MainWnd::~MainWnd()
  20. {
  21. delete ui;
  22. }
  23. void MainWnd::on_tabProductionBtn_clicked()
  24. {
  25. SwitchToConfig(&OriginalWnd::switchToProductionConfig);
  26. }
  27. void MainWnd::on_tabHomeBtn_clicked()
  28. {
  29. SwitchToConfig(&OriginalWnd::switchToHomeConfig);
  30. }
  31. void MainWnd::on_tabProgramBtn_clicked()
  32. {
  33. SwitchToConfig(&OriginalWnd::switchToProgramConfig);
  34. }
  35. void MainWnd::on_tabModuleBtn_clicked()
  36. {
  37. SwitchToConfig(&OriginalWnd::switchToModuleConfig);
  38. }
  39. void MainWnd::on_tabDispositionBtn_clicked()
  40. {
  41. SwitchToConfig(&OriginalWnd::switchToDispositionConfig);
  42. }
  43. void MainWnd::on_tabDiagnosisBtn_clicked()
  44. {
  45. SwitchToConfig(&OriginalWnd::switchToDiagnosisConfig);
  46. }
  47. void MainWnd::on_tabSystemBtn_clicked()
  48. {
  49. QPointer<SystemInfoPage> sys = new SystemInfoPage;
  50. //connect(sys, &Login::SendSwitchOriginalWndSignals, this, &MainWnd::ShowOriginalWndSlots);
  51. ui->stackedWidget_UI->addWidget(sys);
  52. ui->stackedWidget_UI->setCurrentIndex(ui->stackedWidget_UI->indexOf(sys));
  53. return;
  54. QDialog settingsDialog(this);
  55. settingsDialog.setWindowTitle(tr("Settings"));
  56. QVBoxLayout mainLayout;
  57. settingsDialog.setLayout(&mainLayout);
  58. // Language Group
  59. QLabel languageLabel(tr("Language:"));
  60. QRadioButton englishRadio(tr("English"));
  61. QRadioButton chineseRadio(tr("Chinese"));
  62. QButtonGroup languageGroup;
  63. languageGroup.addButton(&englishRadio);
  64. languageGroup.addButton(&chineseRadio);
  65. QVBoxLayout languageLayout;
  66. languageLayout.addWidget(&languageLabel);
  67. languageLayout.addWidget(&englishRadio);
  68. languageLayout.addWidget(&chineseRadio);
  69. // Theme Group
  70. QLabel themeLabel(tr("Theme:"));
  71. QRadioButton lightThemeRadio(tr("Light"));
  72. QRadioButton darkThemeRadio(tr("Dark"));
  73. QButtonGroup themeGroup;
  74. themeGroup.addButton(&lightThemeRadio);
  75. themeGroup.addButton(&darkThemeRadio);
  76. QVBoxLayout themeLayout;
  77. themeLayout.addWidget(&themeLabel);
  78. themeLayout.addWidget(&lightThemeRadio);
  79. themeLayout.addWidget(&darkThemeRadio);
  80. // Dialog Button Box
  81. QDialogButtonBox buttonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
  82. connect(&buttonBox, &QDialogButtonBox::accepted, &settingsDialog, &QDialog::accept);
  83. connect(&buttonBox, &QDialogButtonBox::rejected, &settingsDialog, &QDialog::reject);
  84. mainLayout.addLayout(&languageLayout);
  85. mainLayout.addLayout(&themeLayout);
  86. mainLayout.addWidget(&buttonBox);
  87. int init_language_data = gen_if.getLanguageValue();
  88. int init_theme_data = gen_if.getThemeValue();
  89. if (init_language_data == 0) {
  90. englishRadio.setChecked(true);
  91. }
  92. else {
  93. chineseRadio.setChecked(true);
  94. languageLabel.setText(tr("sss", "语言"));
  95. englishRadio.setText(tr("英语"));
  96. chineseRadio.setText(tr("中文"));
  97. themeLabel.setText(tr("主题"));
  98. lightThemeRadio.setText(tr("浅色"));
  99. darkThemeRadio.setText(tr("深色"));
  100. settingsDialog.setWindowTitle(tr("设置"));
  101. }
  102. if (init_theme_data == 0) {
  103. lightThemeRadio.setChecked(true);
  104. }
  105. else {
  106. darkThemeRadio.setChecked(true);
  107. }
  108. int current_language_data = init_language_data;
  109. int current_theme_data = init_theme_data;
  110. connect(&languageGroup, QOverload<QAbstractButton*>::of(&QButtonGroup::buttonClicked),
  111. [&current_language_data, &englishRadio, &chineseRadio](QAbstractButton* button) {
  112. if (button == &englishRadio) {
  113. current_language_data = 0;
  114. qDebug() << "Language set to English";
  115. }
  116. else if (button == &chineseRadio) {
  117. current_language_data = 1;
  118. qDebug() << "Language set to Chinese";
  119. }
  120. });
  121. connect(&themeGroup, QOverload<QAbstractButton*>::of(&QButtonGroup::buttonClicked),
  122. [&current_theme_data, &lightThemeRadio, &darkThemeRadio](QAbstractButton* button) {
  123. if (button == &lightThemeRadio) {
  124. current_theme_data = 0;
  125. qDebug() << "Theme set to Light";
  126. }
  127. else if (button == &darkThemeRadio) {
  128. current_theme_data = 1;
  129. qDebug() << "Theme set to Dark";
  130. }
  131. });
  132. int result = settingsDialog.exec();
  133. QSettings settings("YourCompany", "YourApplication_style");
  134. if (result == QDialog::Accepted) {
  135. // 处理“OK”按钮点击事件
  136. if (init_language_data != current_language_data) {
  137. gen_if.setLanguageValue(current_language_data);
  138. if (current_language_data == 0) {
  139. ui->retranslateUi(this);
  140. setLanguageSignal(current_language_data);
  141. }
  142. else {
  143. setChineseMode(this);
  144. setLanguageSignal(current_language_data);
  145. }
  146. }
  147. if (init_theme_data != current_theme_data) {
  148. gen_if.setThemeValue(current_theme_data);
  149. QString qssFileName;
  150. if (current_theme_data == 0) {
  151. qssFileName = ":/light.qss";
  152. settings.setValue("Flag_Style", 0);
  153. }
  154. else {
  155. qssFileName = ":/dark.qss";
  156. settings.setValue("Flag_Style", 1);
  157. }
  158. QFile qssFile(qssFileName);
  159. if (qssFile.open(QFile::ReadOnly)) {
  160. QString qssContent = qssFile.readAll();
  161. qApp->setStyleSheet(qssContent);
  162. qssFile.close();
  163. }
  164. }
  165. // emit styleChanged();
  166. qDebug() << "Dialog accepted";
  167. }
  168. else if (result == QDialog::Rejected) {
  169. // 处理“Cancel”按钮点击事件
  170. // qDebug() << "Dialog rejected";
  171. }
  172. }
  173. void MainWnd::ShowOriginalWndSlots()
  174. {
  175. if (m_pOriginalWnd == nullptr) //防止重复创建
  176. {
  177. m_pOriginalWnd = new OriginalWnd(this, m_pCameraBind.get());
  178. ui->stackedWidget_UI->addWidget(m_pOriginalWnd);
  179. connect(this, &MainWnd::setLanguageSignal, m_pOriginalWnd, &OriginalWnd::onHandleLanguageSignal);
  180. }
  181. ui->stackedWidget_UI->setCurrentWidget(m_pOriginalWnd);
  182. }
  183. void MainWnd::CloseMainWndSlots()
  184. {
  185. m_pCameraBind->JViewExit();
  186. qApp->quit();
  187. }
  188. void MainWnd::applyTheme(int themeValue)
  189. {
  190. QString qssFileName;
  191. if (themeValue == 0) {
  192. qssFileName = ":/light.qss";
  193. }
  194. else {
  195. qssFileName = ":/dark.qss";
  196. }
  197. QFile qssFile(qssFileName);
  198. if (qssFile.open(QFile::ReadOnly)) {
  199. QString qssContent = qssFile.readAll();
  200. qApp->setStyleSheet(qssContent);
  201. qssFile.close();
  202. }
  203. }
  204. void MainWnd::InitForm()
  205. {
  206. setWindowFlags(Qt::FramelessWindowHint | Qt::Dialog);
  207. setAttribute(Qt::WA_TranslucentBackground, true);
  208. LoadLoginPage();
  209. //登录监听
  210. ui->label_logo_m->installEventFilter(this);
  211. ui->stackedWidget_UI->installEventFilter(this);
  212. //安装监听事件,点击左侧按钮图标变化
  213. ui->tabHomeBtn->installEventFilter(this);
  214. ui->tabProductionBtn->installEventFilter(this);
  215. ui->tabProgramBtn->installEventFilter(this);
  216. ui->tabMessageBtn->installEventFilter(this);
  217. ui->tabModuleBtn->installEventFilter(this);
  218. ui->tabDispositionBtn->installEventFilter(this);
  219. ui->tabDiagnosisBtn->installEventFilter(this);
  220. ui->tabSystemBtn->installEventFilter(this);
  221. ui->tabHelpBtn->installEventFilter(this);
  222. QMouseEvent* pressEvent = new QMouseEvent(QEvent::MouseButtonPress,
  223. ui->tabHomeBtn->pos(),
  224. Qt::LeftButton,
  225. Qt::LeftButton,
  226. Qt::NoModifier);
  227. QApplication::sendEvent(ui->tabHomeBtn, pressEvent);
  228. delete pressEvent;
  229. }
  230. void MainWnd::LoadLoginPage()
  231. {
  232. QPointer<Login> login = new Login;
  233. connect(login, &Login::SendSwitchOriginalWndSignals, this, &MainWnd::ShowOriginalWndSlots);
  234. connect(login, &Login::CloseMainWndSig, this, &MainWnd::CloseMainWndSlots);
  235. ui->stackedWidget_UI->addWidget(login);
  236. ui->stackedWidget_UI->setCurrentIndex(ui->stackedWidget_UI->indexOf(login));
  237. }
  238. bool MainWnd::eventFilter(QObject* obj, QEvent* event)
  239. {
  240. if (obj == this->ui->stackedWidget_UI)
  241. {
  242. onCurrentWidgetChanged();
  243. }
  244. if (obj == this->ui->label_logo_m)
  245. {
  246. //判断事件类型是否为鼠标事件
  247. if (event->type() == QEvent::MouseButtonPress)
  248. {
  249. //转换为鼠标事件
  250. QMouseEvent* mouseenevt = static_cast<QMouseEvent*>(event);
  251. //判断鼠标左键点击
  252. if (mouseenevt->button() == Qt::LeftButton)
  253. {
  254. LoadLoginPage();
  255. return true;
  256. }
  257. }
  258. }
  259. QSettings settings("YourCompany", "YourApplication_style");
  260. int flag = settings.value("Flag_Style", 0).toInt();
  261. switch (event->type())
  262. {
  263. case QEvent::MouseButtonPress:
  264. {
  265. if (obj == ui->tabHomeBtn && ui->tabHomeBtn->isEnabled())
  266. {
  267. ui->tabHomeBtn->setIcon(QIcon(":/images/deep/home.png"));
  268. ui->tabHomeBtn->setChecked(true);
  269. if (flag == 0) {
  270. if (ui->tabProductionBtn->isChecked() == false)
  271. {
  272. ui->tabProductionBtn->setIcon(QIcon(":/images/light/Productionn assistance.png"));
  273. }
  274. if (ui->tabProgramBtn->isChecked() == false)
  275. {
  276. ui->tabProgramBtn->setIcon(QIcon(":/images/light/Program.png"));
  277. }
  278. if (ui->tabMessageBtn->isChecked() == false)
  279. {
  280. ui->tabMessageBtn->setIcon(QIcon(":/images/light/Message.png"));
  281. }
  282. if (ui->tabModuleBtn->isChecked() == false)
  283. {
  284. ui->tabModuleBtn->setIcon(QIcon(":/images/light/Module.png"));
  285. }
  286. if (ui->tabDispositionBtn->isChecked() == false)
  287. {
  288. ui->tabDispositionBtn->setIcon(QIcon(":/images/light/Disposition.png"));
  289. }
  290. if (ui->tabDiagnosisBtn->isChecked() == false)
  291. {
  292. ui->tabDiagnosisBtn->setIcon(QIcon(":/images/light/Diagnosis.png"));
  293. }
  294. if (ui->tabSystemBtn->isChecked() == false)
  295. {
  296. ui->tabSystemBtn->setIcon(QIcon(":/images/light/System.png"));
  297. }
  298. if (ui->tabHelpBtn->isChecked() == false)
  299. {
  300. ui->tabHelpBtn->setIcon(QIcon(":/images/light/Help.png"));
  301. }
  302. }
  303. }
  304. if (obj == ui->tabProductionBtn && ui->tabProductionBtn->isEnabled())
  305. {
  306. ui->tabProductionBtn->setIcon(QIcon(":/images/deep/Productionn assistance.png"));
  307. ui->tabProductionBtn->setChecked(true);
  308. if (flag == 0) {
  309. if (ui->tabHomeBtn->isChecked() == false)
  310. {
  311. ui->tabHomeBtn->setIcon(QIcon(":/images/light/home.png"));
  312. }
  313. if (ui->tabProgramBtn->isChecked() == false)
  314. {
  315. ui->tabProgramBtn->setIcon(QIcon(":/images/light/Program.png"));
  316. }
  317. if (ui->tabMessageBtn->isChecked() == false)
  318. {
  319. ui->tabMessageBtn->setIcon(QIcon(":/images/light/Message.png"));
  320. }
  321. if (ui->tabModuleBtn->isChecked() == false)
  322. {
  323. ui->tabModuleBtn->setIcon(QIcon(":/images/light/Module.png"));
  324. }
  325. if (ui->tabDispositionBtn->isChecked() == false)
  326. {
  327. ui->tabDispositionBtn->setIcon(QIcon(":/images/light/Disposition.png"));
  328. }
  329. if (ui->tabDiagnosisBtn->isChecked() == false)
  330. {
  331. ui->tabDiagnosisBtn->setIcon(QIcon(":/images/light/Diagnosis.png"));
  332. }
  333. if (ui->tabSystemBtn->isChecked() == false)
  334. {
  335. ui->tabSystemBtn->setIcon(QIcon(":/images/light/System.png"));
  336. }
  337. if (ui->tabHelpBtn->isChecked() == false)
  338. {
  339. ui->tabHelpBtn->setIcon(QIcon(":/images/light/Help.png"));
  340. }
  341. }
  342. }
  343. if (obj == ui->tabProgramBtn && ui->tabProgramBtn->isEnabled())
  344. {
  345. ui->tabProgramBtn->setIcon(QIcon(":/images/deep/Program.png"));
  346. ui->tabProgramBtn->setChecked(true);
  347. if (flag == 0) {
  348. if (ui->tabHomeBtn->isChecked() == false)
  349. {
  350. ui->tabHomeBtn->setIcon(QIcon(":/images/light/home.png"));
  351. }
  352. if (ui->tabProductionBtn->isChecked() == false)
  353. {
  354. ui->tabProductionBtn->setIcon(QIcon(":/images/light/Productionn assistance.png"));
  355. }
  356. if (ui->tabMessageBtn->isChecked() == false)
  357. {
  358. ui->tabMessageBtn->setIcon(QIcon(":/images/light/Message.png"));
  359. }
  360. if (ui->tabModuleBtn->isChecked() == false)
  361. {
  362. ui->tabModuleBtn->setIcon(QIcon(":/images/light/Module.png"));
  363. }
  364. if (ui->tabDispositionBtn->isChecked() == false)
  365. {
  366. ui->tabDispositionBtn->setIcon(QIcon(":/images/light/Disposition.png"));
  367. }
  368. if (ui->tabDiagnosisBtn->isChecked() == false)
  369. {
  370. ui->tabDiagnosisBtn->setIcon(QIcon(":/images/light/Diagnosis.png"));
  371. }
  372. if (ui->tabSystemBtn->isChecked() == false)
  373. {
  374. ui->tabSystemBtn->setIcon(QIcon(":/images/light/System.png"));
  375. }
  376. if (ui->tabHelpBtn->isChecked() == false)
  377. {
  378. ui->tabHelpBtn->setIcon(QIcon(":/images/light/Help.png"));
  379. }
  380. }
  381. }
  382. if (obj == ui->tabMessageBtn && ui->tabMessageBtn->isEnabled())
  383. {
  384. ui->tabMessageBtn->setIcon(QIcon(":/images/deep/Message.png"));
  385. ui->tabMessageBtn->setChecked(true);
  386. if (flag == 0) {
  387. if (ui->tabHomeBtn->isChecked() == false)
  388. {
  389. ui->tabHomeBtn->setIcon(QIcon(":/images/light/home.png"));
  390. }
  391. if (ui->tabProductionBtn->isChecked() == false)
  392. {
  393. ui->tabProductionBtn->setIcon(QIcon(":/images/light/Productionn assistance.png"));
  394. }
  395. if (ui->tabProgramBtn->isChecked() == false)
  396. {
  397. ui->tabProgramBtn->setIcon(QIcon(":/images/light/Program.png"));
  398. }
  399. if (ui->tabModuleBtn->isChecked() == false)
  400. {
  401. ui->tabModuleBtn->setIcon(QIcon(":/images/light/Module.png"));
  402. }
  403. if (ui->tabDispositionBtn->isChecked() == false)
  404. {
  405. ui->tabDispositionBtn->setIcon(QIcon(":/images/light/Disposition.png"));
  406. }
  407. if (ui->tabDiagnosisBtn->isChecked() == false)
  408. {
  409. ui->tabDiagnosisBtn->setIcon(QIcon(":/images/light/Diagnosis.png"));
  410. }
  411. if (ui->tabSystemBtn->isChecked() == false)
  412. {
  413. ui->tabSystemBtn->setIcon(QIcon(":/images/light/System.png"));
  414. }
  415. if (ui->tabHelpBtn->isChecked() == false)
  416. {
  417. ui->tabHelpBtn->setIcon(QIcon(":/images/light/Help.png"));
  418. }
  419. }
  420. }
  421. if (obj == ui->tabModuleBtn && ui->tabModuleBtn->isEnabled())
  422. {
  423. ui->tabModuleBtn->setIcon(QIcon(":/images/deep/Module.png"));
  424. ui->tabModuleBtn->setChecked(true);
  425. if (flag == 0) {
  426. if (ui->tabHomeBtn->isChecked() == false)
  427. {
  428. ui->tabHomeBtn->setIcon(QIcon(":/images/light/home.png"));
  429. }
  430. if (ui->tabProductionBtn->isChecked() == false)
  431. {
  432. ui->tabProductionBtn->setIcon(QIcon(":/images/light/Productionn assistance.png"));
  433. }
  434. if (ui->tabProgramBtn->isChecked() == false)
  435. {
  436. ui->tabProgramBtn->setIcon(QIcon(":/images/light/Program.png"));
  437. }
  438. if (ui->tabMessageBtn->isChecked() == false)
  439. {
  440. ui->tabMessageBtn->setIcon(QIcon(":/images/light/Message.png"));
  441. }
  442. if (ui->tabDispositionBtn->isChecked() == false)
  443. {
  444. ui->tabDispositionBtn->setIcon(QIcon(":/images/light/Disposition.png"));
  445. }
  446. if (ui->tabDiagnosisBtn->isChecked() == false)
  447. {
  448. ui->tabDiagnosisBtn->setIcon(QIcon(":/images/light/Diagnosis.png"));
  449. }
  450. if (ui->tabSystemBtn->isChecked() == false)
  451. {
  452. ui->tabSystemBtn->setIcon(QIcon(":/images/light/System.png"));
  453. }
  454. if (ui->tabHelpBtn->isChecked() == false)
  455. {
  456. ui->tabHelpBtn->setIcon(QIcon(":/images/light/Help.png"));
  457. }
  458. }
  459. }
  460. if (obj == ui->tabDispositionBtn && ui->tabDispositionBtn->isEnabled())
  461. {
  462. ui->tabDispositionBtn->setIcon(QIcon(":/images/deep/Disposition.png"));
  463. ui->tabDispositionBtn->setChecked(true);
  464. if (flag == 0) {
  465. if (ui->tabHomeBtn->isChecked() == false)
  466. {
  467. ui->tabHomeBtn->setIcon(QIcon(":/images/light/home.png"));
  468. }
  469. if (ui->tabProductionBtn->isChecked() == false)
  470. {
  471. ui->tabProductionBtn->setIcon(QIcon(":/images/light/Productionn assistance.png"));
  472. }
  473. if (ui->tabProgramBtn->isChecked() == false)
  474. {
  475. ui->tabProgramBtn->setIcon(QIcon(":/images/light/Program.png"));
  476. }
  477. if (ui->tabMessageBtn->isChecked() == false)
  478. {
  479. ui->tabMessageBtn->setIcon(QIcon(":/images/light/Message.png"));
  480. }
  481. if (ui->tabModuleBtn->isChecked() == false)
  482. {
  483. ui->tabModuleBtn->setIcon(QIcon(":/images/light/Module.png"));
  484. }
  485. if (ui->tabDiagnosisBtn->isChecked() == false)
  486. {
  487. ui->tabDiagnosisBtn->setIcon(QIcon(":/images/light/Diagnosis.png"));
  488. }
  489. if (ui->tabSystemBtn->isChecked() == false)
  490. {
  491. ui->tabSystemBtn->setIcon(QIcon(":/images/light/System.png"));
  492. }
  493. if (ui->tabHelpBtn->isChecked() == false)
  494. {
  495. ui->tabHelpBtn->setIcon(QIcon(":/images/light/Help.png"));
  496. }
  497. }
  498. }
  499. if (obj == ui->tabDiagnosisBtn && ui->tabDiagnosisBtn->isEnabled())
  500. {
  501. ui->tabDiagnosisBtn->setIcon(QIcon(":/images/deep/Diagnosis.png"));
  502. ui->tabDiagnosisBtn->setChecked(true);
  503. if (flag == 0) {
  504. if (ui->tabHomeBtn->isChecked() == false)
  505. {
  506. ui->tabHomeBtn->setIcon(QIcon(":/images/light/home.png"));
  507. }
  508. if (ui->tabProductionBtn->isChecked() == false)
  509. {
  510. ui->tabProductionBtn->setIcon(QIcon(":/images/light/Productionn assistance.png"));
  511. }
  512. if (ui->tabProgramBtn->isChecked() == false)
  513. {
  514. ui->tabProgramBtn->setIcon(QIcon(":/images/light/Program.png"));
  515. }
  516. if (ui->tabMessageBtn->isChecked() == false)
  517. {
  518. ui->tabMessageBtn->setIcon(QIcon(":/images/light/Message.png"));
  519. }
  520. if (ui->tabModuleBtn->isChecked() == false)
  521. {
  522. ui->tabModuleBtn->setIcon(QIcon(":/images/light/Module.png"));
  523. }
  524. if (ui->tabDispositionBtn->isChecked() == false)
  525. {
  526. ui->tabDispositionBtn->setIcon(QIcon(":/images/light/Disposition.png"));
  527. }
  528. if (ui->tabSystemBtn->isChecked() == false)
  529. {
  530. ui->tabSystemBtn->setIcon(QIcon(":/images/light/System.png"));
  531. }
  532. if (ui->tabHelpBtn->isChecked() == false)
  533. {
  534. ui->tabHelpBtn->setIcon(QIcon(":/images/light/Help.png"));
  535. }
  536. }
  537. }
  538. if (obj == ui->tabSystemBtn && ui->tabSystemBtn->isEnabled())
  539. {
  540. ui->tabSystemBtn->setIcon(QIcon(":/images/deep/System.png"));
  541. ui->tabSystemBtn->setChecked(true);
  542. if (flag == 0) {
  543. if (ui->tabHomeBtn->isChecked() == false)
  544. {
  545. ui->tabHomeBtn->setIcon(QIcon(":/images/light/home.png"));
  546. }
  547. if (ui->tabProductionBtn->isChecked() == false)
  548. {
  549. ui->tabProductionBtn->setIcon(QIcon(":/images/light/Productionn assistance.png"));
  550. }
  551. if (ui->tabProgramBtn->isChecked() == false)
  552. {
  553. ui->tabProgramBtn->setIcon(QIcon(":/images/light/Program.png"));
  554. }
  555. if (ui->tabMessageBtn->isChecked() == false)
  556. {
  557. ui->tabMessageBtn->setIcon(QIcon(":/images/light/Message.png"));
  558. }
  559. if (ui->tabModuleBtn->isChecked() == false)
  560. {
  561. ui->tabModuleBtn->setIcon(QIcon(":/images/light/Module.png"));
  562. }
  563. if (ui->tabDispositionBtn->isChecked() == false)
  564. {
  565. ui->tabDispositionBtn->setIcon(QIcon(":/images/light/Disposition.png"));
  566. }
  567. if (ui->tabDiagnosisBtn->isChecked() == false)
  568. {
  569. ui->tabDiagnosisBtn->setIcon(QIcon(":/images/light/Diagnosis.png"));
  570. }
  571. if (ui->tabHelpBtn->isChecked() == false)
  572. {
  573. ui->tabHelpBtn->setIcon(QIcon(":/images/light/Help.png"));
  574. }
  575. }
  576. }
  577. if (obj == ui->tabHelpBtn && ui->tabHelpBtn->isEnabled())
  578. {
  579. ui->tabHelpBtn->setIcon(QIcon(":/images/deep/Help.png"));
  580. ui->tabHelpBtn->setChecked(true);
  581. if (flag == 0) {
  582. if (ui->tabHomeBtn->isChecked() == false)
  583. {
  584. ui->tabHomeBtn->setIcon(QIcon(":/images/light/home.png"));
  585. }
  586. if (ui->tabProductionBtn->isChecked() == false)
  587. {
  588. ui->tabProductionBtn->setIcon(QIcon(":/images/light/Productionn assistance.png"));
  589. }
  590. if (ui->tabProgramBtn->isChecked() == false)
  591. {
  592. ui->tabProgramBtn->setIcon(QIcon(":/images/light/Program.png"));
  593. }
  594. if (ui->tabMessageBtn->isChecked() == false)
  595. {
  596. ui->tabMessageBtn->setIcon(QIcon(":/images/light/Message.png"));
  597. }
  598. if (ui->tabModuleBtn->isChecked() == false)
  599. {
  600. ui->tabModuleBtn->setIcon(QIcon(":/images/light/Module.png"));
  601. }
  602. if (ui->tabDispositionBtn->isChecked() == false)
  603. {
  604. ui->tabDispositionBtn->setIcon(QIcon(":/images/light/Disposition.png"));
  605. }
  606. if (ui->tabDiagnosisBtn->isChecked() == false)
  607. {
  608. ui->tabDiagnosisBtn->setIcon(QIcon(":/images/light/Diagnosis.png"));
  609. }
  610. if (ui->tabSystemBtn->isChecked() == false)
  611. {
  612. ui->tabSystemBtn->setIcon(QIcon(":/images/light/System.png"));
  613. }
  614. }
  615. }
  616. break;
  617. }
  618. case QEvent::HoverEnter:
  619. {
  620. if (flag == 0) {
  621. if (obj == ui->tabHomeBtn && ui->tabHomeBtn->isEnabled())
  622. {
  623. ui->tabHomeBtn->setIcon(QIcon(":/images/deep/home.png"));
  624. }
  625. if (obj == ui->tabProductionBtn && ui->tabProductionBtn->isEnabled())
  626. {
  627. ui->tabProductionBtn->setIcon(QIcon(":/images/deep/Productionn assistance.png"));
  628. }
  629. if (obj == ui->tabProgramBtn && ui->tabProgramBtn->isEnabled())
  630. {
  631. ui->tabProgramBtn->setIcon(QIcon(":/images/deep/Program.png"));
  632. }
  633. if (obj == ui->tabMessageBtn && ui->tabMessageBtn->isEnabled())
  634. {
  635. ui->tabMessageBtn->setIcon(QIcon(":/images/deep/Message.png"));
  636. }
  637. if (obj == ui->tabModuleBtn && ui->tabModuleBtn->isEnabled())
  638. {
  639. ui->tabModuleBtn->setIcon(QIcon(":/images/deep/Module.png"));
  640. }
  641. if (obj == ui->tabDispositionBtn && ui->tabDispositionBtn->isEnabled())
  642. {
  643. ui->tabDispositionBtn->setIcon(QIcon(":/images/deep/Disposition.png"));
  644. }
  645. if (obj == ui->tabDiagnosisBtn && ui->tabDiagnosisBtn->isEnabled())
  646. {
  647. ui->tabDiagnosisBtn->setIcon(QIcon(":/images/deep/Diagnosis.png"));
  648. }
  649. if (obj == ui->tabSystemBtn && ui->tabSystemBtn->isEnabled())
  650. {
  651. ui->tabSystemBtn->setIcon(QIcon(":/images/deep/System.png"));
  652. }
  653. if (obj == ui->tabHelpBtn && ui->tabHelpBtn->isEnabled())
  654. {
  655. ui->tabHelpBtn->setIcon(QIcon(":/images/deep/Help.png"));
  656. }
  657. }
  658. break;
  659. }
  660. case QEvent::HoverLeave:
  661. {
  662. if (flag == 0) {
  663. if (obj == ui->tabHomeBtn && ui->tabHomeBtn->isChecked() == false)
  664. {
  665. ui->tabHomeBtn->setIcon(QIcon(":/images/light/home.png"));
  666. ui->tabHomeBtn->setChecked(false);
  667. }
  668. if (obj == ui->tabProductionBtn && ui->tabProductionBtn->isChecked() == false)
  669. {
  670. ui->tabProductionBtn->setIcon(QIcon(":/images/light/Productionn assistance.png"));
  671. ui->tabProductionBtn->setChecked(false);
  672. }
  673. if (obj == ui->tabProgramBtn && ui->tabProgramBtn->isChecked() == false)
  674. {
  675. ui->tabProgramBtn->setIcon(QIcon(":/images/light/Program.png"));
  676. ui->tabProgramBtn->setChecked(false);
  677. }
  678. if (obj == ui->tabMessageBtn && ui->tabMessageBtn->isChecked() == false)
  679. {
  680. ui->tabMessageBtn->setIcon(QIcon(":/images/light/Message.png"));
  681. ui->tabMessageBtn->setChecked(false);
  682. }
  683. if (obj == ui->tabModuleBtn && ui->tabModuleBtn->isChecked() == false)
  684. {
  685. ui->tabModuleBtn->setIcon(QIcon(":/images/light/Module.png"));
  686. ui->tabModuleBtn->setChecked(false);
  687. }
  688. if (obj == ui->tabDispositionBtn && ui->tabDispositionBtn->isChecked() == false)
  689. {
  690. ui->tabDispositionBtn->setIcon(QIcon(":/images/light/Disposition.png"));
  691. ui->tabDispositionBtn->setChecked(false);
  692. }
  693. if (obj == ui->tabDiagnosisBtn && ui->tabDiagnosisBtn->isChecked() == false)
  694. {
  695. ui->tabDiagnosisBtn->setIcon(QIcon(":/images/light/Diagnosis.png"));
  696. ui->tabDiagnosisBtn->setChecked(false);
  697. }
  698. if (obj == ui->tabSystemBtn && ui->tabSystemBtn->isChecked() == false)
  699. {
  700. ui->tabSystemBtn->setIcon(QIcon(":/images/light/System.png"));
  701. ui->tabSystemBtn->setChecked(false);
  702. }
  703. if (obj == ui->tabHelpBtn && ui->tabHelpBtn->isChecked() == false)
  704. {
  705. ui->tabHelpBtn->setIcon(QIcon(":/images/light/Help.png"));
  706. ui->tabHelpBtn->setChecked(false);
  707. }
  708. }
  709. }
  710. default:
  711. break;
  712. }
  713. return QWidget::eventFilter(obj, event);
  714. }
  715. void MainWnd::SwitchToConfig(void (OriginalWnd::* switchMethod)())
  716. {
  717. (m_pOriginalWnd->*switchMethod)();
  718. ui->stackedWidget_UI->setCurrentWidget(m_pOriginalWnd);
  719. }
  720. void MainWnd::onCurrentWidgetChanged() {
  721. QWidget* currentWidget = ui->stackedWidget_UI->currentWidget();
  722. if (currentWidget) {
  723. QString currentWidgetName = currentWidget->objectName();
  724. QSettings settings("YourCompany", "YourApplication_style");
  725. int flag = settings.value("Flag_Style", 0).toInt();
  726. if (currentWidgetName == "Login") {
  727. QString styleSheet;
  728. if (flag == 0) {
  729. styleSheet = "QToolButton:disabled { color: #808080; background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #F8FBFF, stop: 1 #E7ECF3); }"; // 设置禁用状态下的文本颜色为灰色
  730. }
  731. else if (flag == 1) {
  732. styleSheet = "QToolButton:disabled { color: #B1B2D8; background: #7276AA;}";
  733. }
  734. ui->tabHomeBtn->setDisabled(true);
  735. ui->tabHomeBtn->setIcon(QIcon(":/images/light/home.png"));
  736. ui->tabHomeBtn->setStyleSheet(styleSheet);
  737. ui->tabProductionBtn->setDisabled(true);
  738. ui->tabProductionBtn->setStyleSheet(styleSheet);
  739. ui->tabProgramBtn->setDisabled(true);
  740. ui->tabProgramBtn->setStyleSheet(styleSheet);
  741. ui->tabMessageBtn->setDisabled(true);
  742. ui->tabMessageBtn->setStyleSheet(styleSheet);
  743. ui->tabModuleBtn->setDisabled(true);
  744. ui->tabModuleBtn->setStyleSheet(styleSheet);
  745. ui->tabDispositionBtn->setDisabled(true);
  746. ui->tabDispositionBtn->setStyleSheet(styleSheet);
  747. ui->tabDiagnosisBtn->setDisabled(true);
  748. ui->tabDiagnosisBtn->setStyleSheet(styleSheet);
  749. ui->tabSystemBtn->setDisabled(true);
  750. ui->tabSystemBtn->setStyleSheet(styleSheet);
  751. ui->tabHelpBtn->setDisabled(true);
  752. ui->tabHelpBtn->setStyleSheet(styleSheet);
  753. }
  754. else {
  755. ui->tabHomeBtn->setDisabled(false);
  756. if (!initialIconSet) {
  757. ui->tabHomeBtn->setIcon(QIcon(":/images/deep/home.png"));
  758. initialIconSet = true;
  759. }
  760. ui->tabProductionBtn->setDisabled(false);
  761. ui->tabProgramBtn->setDisabled(false);
  762. ui->tabMessageBtn->setDisabled(false);
  763. ui->tabModuleBtn->setDisabled(false);
  764. ui->tabDispositionBtn->setDisabled(false);
  765. ui->tabDiagnosisBtn->setDisabled(false);
  766. ui->tabSystemBtn->setDisabled(false);
  767. ui->tabHelpBtn->setDisabled(false);
  768. }
  769. }
  770. }
  771. void MainWnd::Init()
  772. {
  773. m_sqlOper = &SqlOperation::GetInstance();
  774. m_sqlOper->LoadSql();
  775. m_pCameraBind.reset(new CameraBind);
  776. int themeValue = gen_if.getThemeValue();
  777. applyTheme(themeValue);
  778. if (gen_if.getLanguageValue() == 0)
  779. {
  780. }
  781. else
  782. {
  783. setChineseMode(this);
  784. }
  785. ShowOriginalWndSlots();
  786. bool buttonConnected = connect(ui->tabHomeBtn, &QPushButton::clicked,
  787. this, &MainWnd::on_tabHomeBtn_clicked);
  788. qDebug() << "Connected tabHomeBtn clicked to on_tabHomeBtn_clicked:" << buttonConnected;
  789. connect(ui->tabProductionBtn, &QPushButton::clicked,
  790. this, &MainWnd::on_tabProductionBtn_clicked);
  791. connect(ui->tabDiagnosisBtn, &QPushButton::clicked,
  792. this, &MainWnd::on_tabDiagnosisBtn_clicked);
  793. connect(ui->tabDispositionBtn, &QPushButton::clicked,
  794. this, &MainWnd::on_tabDispositionBtn_clicked);
  795. connect(ui->tabModuleBtn, &QPushButton::clicked,
  796. this, &MainWnd::on_tabModuleBtn_clicked);
  797. // connect(ui->tabSystemBtn, &QPushButton::clicked,
  798. // this, &MainWnd::on_tabSystemBtn_clicked);
  799. connect(ui->tabProgramBtn, &QPushButton::clicked,
  800. this, &MainWnd::on_tabProgramBtn_clicked);
  801. JLogAllOutput::cmd_debug("OriginalWnd 已设置为 stackedWidget 的当前页面");
  802. }
  803. void MainWnd::setChineseMode(QMainWindow* MainWnd) {
  804. MainWnd->setWindowTitle(QCoreApplication::translate("MainWnd", "主界面", nullptr));
  805. ui->tabHomeBtn->setText(QCoreApplication::translate("MainWnd", "首页", nullptr));
  806. ui->label_logo_m->setText(QString());
  807. ui->tabProductionBtn->setText(QCoreApplication::translate("MainWnd", "产品助手", nullptr));
  808. ui->tabProgramBtn->setText(QCoreApplication::translate("MainWnd", "进程", nullptr));
  809. ui->tabMessageBtn->setText(QCoreApplication::translate("MainWnd", "信息", nullptr));
  810. ui->tabModuleBtn->setText(QCoreApplication::translate("MainWnd", "校准", nullptr));
  811. ui->tabDispositionBtn->setText(QCoreApplication::translate("MainWnd", "模块配置", nullptr));
  812. ui->tabDiagnosisBtn->setText(QCoreApplication::translate("MainWnd", "诊断", nullptr));
  813. ui->tabSystemBtn->setText(QCoreApplication::translate("MainWnd", "系统信息", nullptr));
  814. ui->tabHelpBtn->setText(QCoreApplication::translate("MainWnd", "帮助", nullptr));
  815. ui->pushButton->setText(QCoreApplication::translate("MainWnd", "关闭", nullptr));
  816. }
  817. void MainWnd::on_pushButton_clicked()
  818. {
  819. //加确认关闭提示确认窗口
  820. // 创建一个消息框
  821. QMessageBox msgBox;
  822. if (gen_if.getLanguageValue() == 0) {
  823. msgBox.setWindowTitle("Confirm Close");
  824. msgBox.setText("Are you sure you want to close the application?");
  825. }
  826. else {
  827. msgBox.setWindowTitle("确认关闭");
  828. msgBox.setText("你确定要关闭程序吗");
  829. }
  830. msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
  831. msgBox.setDefaultButton(QMessageBox::No);
  832. // 显示消息框并获取用户的选择
  833. int ret = msgBox.exec();
  834. switch (ret)
  835. {
  836. case QMessageBox::Yes:
  837. {
  838. CloseMainWndSlots();
  839. }
  840. break;
  841. case QMessageBox::No:
  842. // 用户点击了取消按钮,不执行任何操作
  843. break;
  844. default:
  845. // 其他情况
  846. break;
  847. }
  848. }
  849. // QJsonObject MainWnd::getInfofromDb(){
  850. // QJsonObject data;
  851. // QJsonArray fieldsArray;
  852. // QSqlDatabase db = QSqlDatabase::database();
  853. // if (!db.isOpen()) {
  854. // qWarning() << "数据库未打开";
  855. // return data;
  856. // }
  857. // // 查询 systemConfig 表
  858. // QSqlQuery queryBond(db);
  859. // queryBond.prepare(R"(
  860. // SELECT Function, Description,setValue
  861. // FROM systemConfig
  862. // )");
  863. // if (queryBond.exec()) {
  864. // while (queryBond.next()) {
  865. // QJsonObject field;
  866. // field["Function"] = queryBond.value("Function").toString();
  867. // field["Description"] = queryBond.value("Description").toString();
  868. // field["setValue"] = queryBond.value("setValue").toInt();
  869. // fieldsArray.append(field);
  870. // }
  871. // // qDebug() << "Fetched fields:" << fieldsArray;
  872. // } else {
  873. // qWarning() << "查询 systemConfig 失败:" << queryBond.lastError().text();
  874. // }
  875. // data["systemConfig"]=fieldsArray;
  876. // // qDebug() << "Fetched data:" << data;
  877. // return data;
  878. // }
  879. // int MainWnd::getLanguageValue(){
  880. // int data;
  881. // QJsonArray fieldsArray;
  882. // QSqlDatabase db = QSqlDatabase::database();
  883. // if (!db.isOpen()) {
  884. // qWarning() << "数据库未打开";
  885. // return -1;
  886. // }
  887. // // 查询 systemConfig 表
  888. // QSqlQuery queryBond(db);
  889. // queryBond.prepare(R"(
  890. // SELECT Function, Description,setValue
  891. // FROM systemConfig
  892. // )");
  893. // if (queryBond.exec()) {
  894. // while (queryBond.next()) {
  895. // QJsonObject field;
  896. // field["Function"] = queryBond.value("Function").toString();
  897. // if(field["Function"] == "language"){
  898. // data = queryBond.value("setValue").toInt();
  899. // return data;
  900. // }
  901. // }
  902. // // qDebug() << "Fetched fields:" << fieldsArray;
  903. // } else {
  904. // qWarning() << "查询 systemConfig 失败:" << queryBond.lastError().text();
  905. // }
  906. // return -1;
  907. // }
  908. // int MainWnd::getThemeValue(){
  909. // int data;
  910. // QJsonArray fieldsArray;
  911. // QSqlDatabase db = QSqlDatabase::database();
  912. // if (!db.isOpen()) {
  913. // qWarning() << "数据库未打开";
  914. // return -1;
  915. // }
  916. // // 查询 systemConfig 表
  917. // QSqlQuery queryBond(db);
  918. // queryBond.prepare(R"(
  919. // SELECT Function, Description,setValue
  920. // FROM systemConfig
  921. // )");
  922. // if (queryBond.exec()) {
  923. // while (queryBond.next()) {
  924. // QJsonObject field;
  925. // field["Function"] = queryBond.value("Function").toString();
  926. // if(field["Function"] == "theme"){
  927. // data = queryBond.value("setValue").toInt();
  928. // return data;
  929. // }
  930. // }
  931. // // qDebug() << "Fetched fields:" << fieldsArray;
  932. // } else {
  933. // qWarning() << "查询 systemConfig 失败:" << queryBond.lastError().text();
  934. // }
  935. // return -1;
  936. // }
  937. // void MainWnd::setLanguageValue(int data){
  938. // QSqlDatabase db = QSqlDatabase::database();
  939. // if (!db.isOpen()) {
  940. // qWarning() << "数据库未打开";
  941. // }
  942. // QString sql = QString("UPDATE systemConfig SET setValue = '%1' WHERE Function = 'language'").arg(data);
  943. // QSqlQuery query;
  944. // if (query.exec(sql)) {
  945. // qDebug() << "Update successful";
  946. // } else {
  947. // qDebug() << "Update failed:" << query.lastError().text();
  948. // }
  949. // }
  950. // void MainWnd::setThemeValue(int data){
  951. // QSqlDatabase db = QSqlDatabase::database();
  952. // if (!db.isOpen()) {
  953. // qWarning() << "数据库未打开";
  954. // }
  955. // QString sql = QString("UPDATE systemConfig SET setValue = '%1' WHERE Function = 'theme'").arg(data);
  956. // QSqlQuery query;
  957. // if (query.exec(sql)) {
  958. // qDebug() << "Update successful";
  959. // } else {
  960. // qDebug() << "Update failed:" << query.lastError().text();
  961. // }
  962. // }