Files
EJM_Display/LaunchPage.cpp

76 lines
2.1 KiB
C++
Raw Normal View History

2025-08-20 23:06:28 +08:00
#include "LaunchPage.h"
#include "ui_LaunchPage.h"
#include <Pages/P00_PublicPage.h>
#if CONFIG_EN_SUB_THREAD //是否开启子进程
#include <Threads/SubThread.h>
SubThread LP_ST;
#endif
LaunchPage::LaunchPage(QWidget *parent)
: QWidget(parent)
, ui(new Ui::LaunchPage)
{
ui->setupUi(this);
setWindowFlag(Qt::FramelessWindowHint); // 设置窗口无边框,设置后窗口无法移动
setAttribute(Qt::WA_TranslucentBackground, true);
TrayIconInit();
WinInit();
#if CONFIG_EN_SUB_THREAD //是否开启子进程
LP_ST.start();
#endif
}
LaunchPage::~LaunchPage()
{
#if CONFIG_EN_SUB_THREAD //是否开启子进程
LP_ST.KillThread();
#endif
delete ui;
}
void LaunchPage::TrayIconInit()
{
//托盘初始化
QIcon icon = QIcon("logo.png");
trayIcon = new QSystemTrayIcon(this);
trayIcon->setIcon(icon);
trayIcon->setToolTip("郑煤机-掘锚一体机");
trayIcon->show(); //必须调用,否则托盘图标不显示
//创建菜单项动作(以下动作只对windows有效)
minimizeAction = new QAction("隐藏", this);
connect(minimizeAction, SIGNAL(triggered()), this, SLOT(
hide()
)); //绑定信号槽
restoreAction = new QAction("还原", this);
connect(restoreAction, SIGNAL(triggered()), this, SLOT(
showNormal()
));
quitAction = new QAction("退出", this);
connect(quitAction, &QAction::triggered, this, [this]() {
// 退出应用程序
qApp->quit();
});
//创建托盘菜单(必须先创建动作,后添加菜单项,还可以加入菜单项图标美化)
trayIconMenu = new QMenu(this);
trayIconMenu->addAction(minimizeAction);
trayIconMenu->addAction(restoreAction);
trayIconMenu->addSeparator();
trayIconMenu->addAction(quitAction);
trayIcon->setContextMenu(trayIconMenu);
connect(trayIcon,SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
this,SLOT(iconActivated(QSystemTrayIcon::ActivationReason)));
}
void LaunchPage::WinInit(){
P00_PublicPage* PubPage = new P00_PublicPage();
this->hide();
PubPage->show();
}