MainWnd.cpp 38 KB

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