MainWnd.cpp 37 KB

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