@@ -28,6 +28,14 @@ MainWindow::MainWindow(QWidget *parent)
2828 : QMainWindow(parent), ui(new Ui::MainWindow)
2929{
3030 ui->setupUi (this );
31+
32+ QScreen *screen = QGuiApplication::primaryScreen ();
33+ if (screen != nullptr )
34+ {
35+ this ->move (
36+ (screen->geometry ().width () - this ->width ())/2 ,
37+ (screen->geometry ().height () - this ->height ())/2 );
38+ }
3139 init ();
3240}
3341
@@ -57,15 +65,15 @@ void MainWindow::recreate()
5765void MainWindow::refresh ()
5866{
5967 ui->cpuContent ->setText (QString (" <span style='color:blue'>%1%</span>" )
60- .arg (m_cpu->getUsage (), 5 , ' f' , 1 , ' ' ));
68+ .arg (m_cpu->getUsage (), 5 , ' f' , 1 , ' ' ));
6169
6270 double memUsage = m_mem->getUsage ();
6371 double memTotal = m_mem->getTotal ();
6472 ui->memContent ->setText (
6573 QString (" <span style='color:blue'>(%1G / %2G) %3%</span>" )
66- .arg (memUsage, 0 , ' f' , 1 )
67- .arg (memTotal, 0 , ' f' , 1 )
68- .arg (memUsage / memTotal * 100 , 4 , ' f' , 1 ));
74+ .arg (memUsage, 0 , ' f' , 1 )
75+ .arg (memTotal, 0 , ' f' , 1 )
76+ .arg (memUsage / memTotal * 100 , 4 , ' f' , 1 ));
6977}
7078
7179void MainWindow::on_sliderCtrl_valueChanged (int value)
@@ -159,10 +167,10 @@ void MainWindow::createTray()
159167 // 连接信号和槽
160168 connect (showAction, &QAction::triggered, this ,
161169 [&]
162- {
163- showNormal ();
164- activateWindow ();
165- });
170+ {
171+ showNormal ();
172+ activateWindow ();
173+ });
166174 connect (hideAction, &QAction::triggered, this , &MainWindow::hide);
167175 connect (quitAction, &QAction::triggered, qApp, &QApplication::quit);
168176
@@ -297,30 +305,30 @@ void MainWindow::init()
297305 /* 首选项菜单 */
298306 connect (ui->menuPreference , &QMenu::aboutToShow,
299307 [this ]
300- {
301- ui->menuPreference ->hide ();
302- QTimer::singleShot (50 ,
303- [this ]()
304- {
305- m_preferenceDlg->show ();
306- m_preferenceDlg->activateWindow ();
307- m_preferenceDlg->raise ();
308- });
309- });
308+ {
309+ ui->menuPreference ->hide ();
310+ QTimer::singleShot (50 ,
311+ [this ]()
312+ {
313+ m_preferenceDlg->show ();
314+ m_preferenceDlg->activateWindow ();
315+ m_preferenceDlg->raise ();
316+ });
317+ });
310318
311319 /* 关于菜单 */
312320 connect (ui->menuAbout , &QMenu::aboutToShow,
313321 [this ]
314- {
315- ui->menuAbout ->hide ();
316- QTimer::singleShot (50 ,
317- [this ]()
318- {
319- m_aboutDlg->show ();
320- m_aboutDlg->activateWindow ();
321- m_aboutDlg->raise ();
322- });
323- });
322+ {
323+ ui->menuAbout ->hide ();
324+ QTimer::singleShot (50 ,
325+ [this ]()
326+ {
327+ m_aboutDlg->show ();
328+ m_aboutDlg->activateWindow ();
329+ m_aboutDlg->raise ();
330+ });
331+ });
324332
325333 m_languageGroup = new QActionGroup (this );
326334 m_languageGroup->setExclusive (true );
@@ -329,7 +337,7 @@ void MainWindow::init()
329337 m_languageGroup->addAction (ui->actionEN );
330338 QString language =
331339 m_settings->value (CONFIG_LANGUAGE, QLocale ().system ().name ())
332- .toString ();
340+ .toString ();
333341 if (language == " zh_CN" )
334342 {
335343 ui->actionCN ->setChecked (true );
@@ -345,42 +353,42 @@ void MainWindow::init()
345353
346354 connect (ui->actionCN , &QAction::triggered,
347355 [this ]
348- {
349- m_settings->setValue (CONFIG_LANGUAGE, " zh_CN" );
350- QMessageBox msgBox (this );
351- msgBox.setWindowFlags (Qt::Dialog | Qt::WindowTitleHint |
352- Qt::CustomizeWindowHint);
353- msgBox.setIcon (QMessageBox::Information);
354- msgBox.setWindowTitle (tr (" 提示" ));
355- msgBox.setText (tr (" 直到重启应用后,界面的语言才会生效" ));
356- msgBox.exec ();
357- });
356+ {
357+ m_settings->setValue (CONFIG_LANGUAGE, " zh_CN" );
358+ QMessageBox msgBox (this );
359+ msgBox.setWindowFlags (Qt::Dialog | Qt::WindowTitleHint |
360+ Qt::CustomizeWindowHint);
361+ msgBox.setIcon (QMessageBox::Information);
362+ msgBox.setWindowTitle (tr (" 提示" ));
363+ msgBox.setText (tr (" 直到重启应用后,界面的语言才会生效" ));
364+ msgBox.exec ();
365+ });
358366
359367 connect (ui->actionTW , &QAction::triggered,
360368 [this ]
361- {
362- m_settings->setValue (CONFIG_LANGUAGE, " zh_TW" );
363- QMessageBox msgBox (this );
364- msgBox.setWindowFlags (Qt::Dialog | Qt::WindowTitleHint |
365- Qt::CustomizeWindowHint);
366- msgBox.setIcon (QMessageBox::Information);
367- msgBox.setWindowTitle (tr (" 提示" ));
368- msgBox.setText (tr (" 直到重启应用后,界面的语言才会生效" ));
369- msgBox.exec ();
370- });
369+ {
370+ m_settings->setValue (CONFIG_LANGUAGE, " zh_TW" );
371+ QMessageBox msgBox (this );
372+ msgBox.setWindowFlags (Qt::Dialog | Qt::WindowTitleHint |
373+ Qt::CustomizeWindowHint);
374+ msgBox.setIcon (QMessageBox::Information);
375+ msgBox.setWindowTitle (tr (" 提示" ));
376+ msgBox.setText (tr (" 直到重启应用后,界面的语言才会生效" ));
377+ msgBox.exec ();
378+ });
371379
372380 connect (ui->actionEN , &QAction::triggered,
373381 [this ]
374- {
375- m_settings->setValue (CONFIG_LANGUAGE, " en_US" );
376- QMessageBox msgBox (this );
377- msgBox.setWindowFlags (Qt::Dialog | Qt::WindowTitleHint |
378- Qt::CustomizeWindowHint);
379- msgBox.setIcon (QMessageBox::Information);
380- msgBox.setWindowTitle (tr (" 提示" ));
381- msgBox.setText (tr (" 直到重启应用后,界面的语言才会生效" ));
382- msgBox.exec ();
383- });
382+ {
383+ m_settings->setValue (CONFIG_LANGUAGE, " en_US" );
384+ QMessageBox msgBox (this );
385+ msgBox.setWindowFlags (Qt::Dialog | Qt::WindowTitleHint |
386+ Qt::CustomizeWindowHint);
387+ msgBox.setIcon (QMessageBox::Information);
388+ msgBox.setWindowTitle (tr (" 提示" ));
389+ msgBox.setText (tr (" 直到重启应用后,界面的语言才会生效" ));
390+ msgBox.exec ();
391+ });
384392}
385393
386394void MainWindow::closeEvent (QCloseEvent *event)
@@ -434,7 +442,7 @@ bool MainWindow::nativeEventFilter(const QByteArray &eventType,
434442 currentValue + m_preferenceDlg->getIncreaseStep ());
435443 qDebug () << " 全局快捷键: 增加速度到"
436444 << speedFactor (currentValue +
437- m_preferenceDlg->getIncreaseStep ());
445+ m_preferenceDlg->getIncreaseStep ());
438446 }
439447 }
440448 break ;
@@ -453,7 +461,7 @@ bool MainWindow::nativeEventFilter(const QByteArray &eventType,
453461 currentValue - m_preferenceDlg->getDecreaseStep ());
454462 qDebug () << " 全局快捷键: 降低速度到"
455463 << speedFactor (currentValue -
456- m_preferenceDlg->getDecreaseStep ());
464+ m_preferenceDlg->getDecreaseStep ());
457465 }
458466 }
459467 break ;
0 commit comments