380 lines
15 KiB
C++
380 lines
15 KiB
C++
#include "LaunchPage.h"
|
||
#include "ui_LaunchPage.h"
|
||
#include <PublicFunctions/Basic.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);
|
||
|
||
#if CONFIG_EN_SUB_THREAD //是否开启子进程
|
||
LP_ST.start();
|
||
#endif
|
||
|
||
QTimer::singleShot(10, this, &LaunchPage::createPages);
|
||
|
||
|
||
|
||
|
||
}
|
||
|
||
LaunchPage::~LaunchPage()
|
||
{
|
||
#if CONFIG_EN_SUB_THREAD //是否开启子进程
|
||
LP_ST.KillThread();
|
||
#endif
|
||
delete ui;
|
||
|
||
// 清理TTS
|
||
if (tts) {
|
||
tts->stop();
|
||
delete tts;
|
||
}
|
||
}
|
||
void LaunchPage::AddLogInfo(QString Str){
|
||
Sleep_ms(1);
|
||
ui->LoaderList->addItem(Str);
|
||
ui->LoaderList->setCurrentRow(ui->LoaderList->count() - 1);
|
||
//qDebug()<<Str;
|
||
}
|
||
// 加载下一个窗口的函数
|
||
void LaunchPage::loadNextWindow(QWidget *container,QHBoxLayout *hLayout) {
|
||
|
||
}
|
||
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::createPages(){
|
||
WinInit();
|
||
/* ============= 1. 只把主窗口 show 出来 ============= */
|
||
AddLogInfo("窗口创建->正在创建公共窗口...");
|
||
P00_PublicPage *pubWin = new P00_PublicPage(this);
|
||
pubWin->setObjectName("pubWin");
|
||
pubWin->setStyleSheet("background-color: transparent;");
|
||
|
||
AddLogInfo("窗口布局->正在共享窗口布局...");
|
||
// 获取PublicWin中的scrollArea
|
||
QScrollArea *scrollArea = pubWin->findChild<QScrollArea*>("scrollArea");
|
||
bool isNewScrollArea = false;
|
||
|
||
if (!scrollArea) {
|
||
// 如果找不到scrollArea,创建新的并添加到PublicWin布局
|
||
scrollArea = new QScrollArea(pubWin);
|
||
scrollArea->setObjectName("scrollArea");
|
||
isNewScrollArea = true;
|
||
qDebug() << "创建新的scrollArea";
|
||
}
|
||
AddLogInfo("窗口属性->正在设置窗口属性...");
|
||
scrollArea->setStyleSheet("background-color: transparent; border: none;");
|
||
// 配置滚动区域属性
|
||
scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
||
scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||
scrollArea->setWidgetResizable(false); // 关键:保持内容原始尺寸以实现横向滚动
|
||
scrollArea->setStyleSheet("border: none;");
|
||
|
||
// 创建容器部件 - 用于承载水平排列的窗口
|
||
QWidget *container = new QWidget();
|
||
container->setObjectName("scrollContainer");
|
||
container->setStyleSheet("background-color: transparent;");
|
||
// 使用水平布局
|
||
QHBoxLayout *hLayout = new QHBoxLayout(container);
|
||
hLayout->setSpacing(10); // 窗口之间的间距
|
||
hLayout->setContentsMargins(0, 0, 0, 0); // 容器内边距
|
||
for (uint8_t PgaeIndex = 0; PgaeIndex < 17; PgaeIndex ++) {
|
||
|
||
switch (PgaeIndex) {
|
||
case 0: {
|
||
P01_MianPage *p01 = new P01_MianPage(container);
|
||
AddLogInfo("窗口创建->P01_MianPage窗口...");
|
||
p01->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
||
hLayout->addWidget(p01);
|
||
AddLogInfo("窗口载入布局->P01_MianPage 窗口...");
|
||
break;
|
||
}
|
||
case 1: {
|
||
P02_ShieldPage *p02 = new P02_ShieldPage(container);
|
||
AddLogInfo("窗口创建->P02_ShieldPage窗口...");
|
||
p02->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
||
hLayout->addWidget(p02);
|
||
AddLogInfo("窗口载入布局->P02_ShieldPage 窗口...");
|
||
break;
|
||
}
|
||
case 2: {
|
||
P301_PumpPage *p301 = new P301_PumpPage(container);
|
||
AddLogInfo("窗口创建->P301_PumpPage窗口...");
|
||
p301->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
||
hLayout->addWidget(p301);
|
||
AddLogInfo("窗口载入布局->P301_PumpPage 窗口...");
|
||
break;
|
||
}
|
||
case 3: {
|
||
P401_CuttingPage *p401 = new P401_CuttingPage(container);
|
||
AddLogInfo("窗口创建->P401_CuttingPage窗口...");
|
||
p401->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
||
hLayout->addWidget(p401);
|
||
AddLogInfo("窗口载入布局->P401_CuttingPage 窗口...");
|
||
break;
|
||
}
|
||
case 4: {
|
||
P501_LoaderPage *p501 = new P501_LoaderPage(container);
|
||
AddLogInfo("窗口创建->P501_LoaderPage窗口...");
|
||
p501->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
||
hLayout->addWidget(p501);
|
||
AddLogInfo("窗口载入布局->P501_LoaderPage 窗口...");
|
||
break;
|
||
}
|
||
case 5: {
|
||
P601_TransportPage *p601 = new P601_TransportPage(container);
|
||
AddLogInfo("窗口创建->P601_TransportPage窗口...");
|
||
p601->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
||
hLayout->addWidget(p601);
|
||
AddLogInfo("窗口载入布局->P601_TransportPage 窗口...");
|
||
break;
|
||
}
|
||
case 6: {
|
||
P07_CylinderPage *p07 = new P07_CylinderPage(container);
|
||
AddLogInfo("窗口创建->P07_CylinderPage窗口...");
|
||
p07->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
||
hLayout->addWidget(p07);
|
||
AddLogInfo("窗口载入布局->P07_CylinderPage 窗口...");
|
||
break;
|
||
}
|
||
case 7: {
|
||
P08_AlarmPage *p08 = new P08_AlarmPage(container);
|
||
AddLogInfo("窗口创建->P08_AlarmPage窗口...");
|
||
p08->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
||
hLayout->addWidget(p08);
|
||
AddLogInfo("窗口载入布局->P08_AlarmPage 窗口...");
|
||
break;
|
||
}
|
||
case 8: {
|
||
P09_RemotePage *p09 = new P09_RemotePage(container);
|
||
AddLogInfo("窗口创建->P09_RemotePage窗口...");
|
||
p09->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
||
hLayout->addWidget(p09);
|
||
AddLogInfo("窗口载入布局->P09_RemotePage 窗口...");
|
||
break;
|
||
}
|
||
case 9: {
|
||
P10_IntelligentPage *p10 = new P10_IntelligentPage(container);
|
||
AddLogInfo("窗口创建->P10_IntelligentPage窗口...");
|
||
p10->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
||
hLayout->addWidget(p10);
|
||
AddLogInfo("窗口载入布局->P10_IntelligentPage 窗口...");
|
||
break;
|
||
}
|
||
case 10: {
|
||
P11_IsolationPage *p11 = new P11_IsolationPage(container);
|
||
AddLogInfo("窗口创建->P11_IsolationPage窗口...");
|
||
p11->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
||
hLayout->addWidget(p11);
|
||
AddLogInfo("窗口载入布局->P11_IsolationPage 窗口...");
|
||
break;
|
||
}
|
||
case 11: {
|
||
P12_NetworkPage *p12 = new P12_NetworkPage(container);
|
||
AddLogInfo("窗口创建->P12_NetworkPage窗口...");
|
||
p12->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
||
hLayout->addWidget(p12);
|
||
AddLogInfo("窗口载入布局->P12_NetworkPage 窗口...");
|
||
break;
|
||
}
|
||
case 12: {
|
||
P13_InsPage *p13 = new P13_InsPage(container);
|
||
AddLogInfo("窗口创建->P13_InsPage窗口...");
|
||
p13->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
||
hLayout->addWidget(p13);
|
||
AddLogInfo("窗口载入布局->P13_InsPage 窗口...");
|
||
break;
|
||
}
|
||
case 13: {
|
||
P14_AtlasPage *p14 = new P14_AtlasPage(container);
|
||
AddLogInfo("窗口创建->P14_AtlasPage窗口...");
|
||
p14->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
||
hLayout->addWidget(p14);
|
||
AddLogInfo("窗口载入布局->P14_AtlasPage 窗口...");
|
||
break;
|
||
}
|
||
case 14: {
|
||
P15_ParameterPage *p15 = new P15_ParameterPage(container);
|
||
AddLogInfo("窗口创建->P15_ParameterPage窗口...");
|
||
p15->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
||
hLayout->addWidget(p15);
|
||
AddLogInfo("窗口载入布局->P15_ParameterPage 窗口...");
|
||
break;
|
||
}
|
||
case 15: {
|
||
P16_SettingPage *p16 = new P16_SettingPage(container);
|
||
AddLogInfo("窗口创建->P16_SettingPage窗口...");
|
||
p16->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
||
hLayout->addWidget(p16);
|
||
AddLogInfo("窗口载入布局->P16_SettingPage 窗口...");
|
||
break;
|
||
}
|
||
default:
|
||
// 所有窗口加载完成,可以添加完成提示
|
||
AddLogInfo("所有窗口加载完成");
|
||
}
|
||
}
|
||
|
||
|
||
|
||
// 隐藏滚动条(如果需要)
|
||
scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); // 水平滚动条按需显示
|
||
scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); // 隐藏垂直滚动条
|
||
// 设置滚动区域的内容部件
|
||
scrollArea->setWidget(container);
|
||
// 确保scrollArea被正确添加到PublicWin中
|
||
if (isNewScrollArea) {
|
||
// 为PublicWin设置布局(如果没有)
|
||
if (!pubWin->layout()) {
|
||
QVBoxLayout *mainLayout = new QVBoxLayout(pubWin);
|
||
mainLayout->setContentsMargins(0, 0, 0, 0);
|
||
pubWin->setLayout(mainLayout);
|
||
}
|
||
// 将滚动区域添加到布局
|
||
pubWin->layout()->addWidget(scrollArea);
|
||
}
|
||
// 显示主窗口
|
||
ui->LoaderList->clear();
|
||
ui->LoaderList->setStyleSheet("border-image: url(:/Frames/null.png);");
|
||
pubWin->show();
|
||
|
||
}
|
||
void LaunchPage::WinInit(){
|
||
ui->LoaderList->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||
ui->LoaderList->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||
|
||
TrayIconInit();
|
||
AddLogInfo("读取配置->UI_油泵界面启停条件_配置...");
|
||
PumpConditionConfigFile = ConfigFiles().ReadFile_Csv("./ProgramConfig/UI_油泵界面启停条件_配置.csv");
|
||
|
||
AddLogInfo("读取配置->UI_截割界面启停条件_配置...");
|
||
CutConditionConfigFile = ConfigFiles().ReadFile_Csv("./ProgramConfig/UI_截割界面启停条件_配置.csv");
|
||
|
||
AddLogInfo("读取配置->UI_装载界面启停条件_配置...");
|
||
LoaderConditionConfigFile = ConfigFiles().ReadFile_Csv("./ProgramConfig/UI_装载界面启停条件_配置.csv");
|
||
|
||
AddLogInfo("读取配置->UI_运输界面启停条件_配置...");
|
||
TransportConditionConfigFile = ConfigFiles().ReadFile_Csv("./ProgramConfig/UI_运输界面启停条件_配置.csv");
|
||
|
||
AddLogInfo("读取配置->UI_备用界面启停条件_配置...");
|
||
StandbyConditionConfigFile = ConfigFiles().ReadFile_Csv("./ProgramConfig/UI_备用界面启停条件_配置.csv");
|
||
|
||
|
||
|
||
AddLogInfo("解析配置->UI_报警内容文本_配置...");
|
||
QTimer::singleShot(1000, this, [=]() {
|
||
AddLogInfo("读取配置->UI_报警内容文本_配置...");
|
||
QList<QStringList> FileData = ConfigFiles().ReadFile_Csv("./ProgramConfig/UI_报警内容文本_配置.csv");
|
||
for (int row = 1; row < FileData.size()-1; ++row)
|
||
{
|
||
bool ok1,ok2;
|
||
uint8_t Dev = FileData.at(row)[0].toUInt(&ok1, 16);
|
||
uint8_t Index = FileData.at(row)[1].toUInt(&ok2, 16);
|
||
AlarmText[Dev][Index].TextColor = FileData.at(row)[2];
|
||
AlarmText[Dev][Index].AlarmText = FileData.at(row)[3] + "->" + FileData.at(row)[4];
|
||
AlarmText[Dev][Index].Troubleshoot = FileData.at(row)[5];
|
||
}
|
||
});
|
||
|
||
|
||
|
||
AddLogInfo("界面解析->正在解析所有界面名称...");
|
||
gPageName["P01"] = "主预览";
|
||
gPageName["P02"] = "屏蔽条件";
|
||
gPageName["P301"] = "油泵设备";
|
||
gPageName["P401"] = "截割设备";
|
||
gPageName["P501"] = "装载设备";
|
||
gPageName["P601"] = "运输设备";
|
||
gPageName["P07"] = "备用设备";
|
||
gPageName["P08"] = "故障记录";
|
||
gPageName["P09"] = "遥控测试";
|
||
gPageName["P10"] = "自动智能";
|
||
gPageName["P11"] = "绝缘检测";
|
||
gPageName["P12.00"] = "网络拓扑";
|
||
gPageName["P12.01"] = "硬件IO 1";
|
||
gPageName["P12.02"] = "硬件IO 2";
|
||
gPageName["P12.03"] = "硬件IO 3";
|
||
gPageName["P12.04"] = "硬件IO 4";
|
||
gPageName["P12.05"] = "硬件IO 3";
|
||
gPageName["P12.06"] = "操作箱 1";
|
||
gPageName["P12.07"] = "操作箱 2";
|
||
gPageName["P12.08"] = "操作箱 3";
|
||
gPageName["P12.09"] = "操作箱 4";
|
||
gPageName["P13"] = "本地控制";
|
||
gPageName["P14"] = "随机图册";
|
||
gPageName["P15"] = "参数设置";
|
||
gPageName["P16"] = "系统设置";
|
||
|
||
gPageIndexStr = "P01";
|
||
|
||
// 创建实例(建议全局唯一)
|
||
ttsManager = new TTSManager(this);
|
||
|
||
AddLogInfo("读取配置->正在判断是否具有语音播报能力...");
|
||
// 初始化TTS
|
||
tts = new QTextToSpeech(this);
|
||
tts->setLocale(QLocale("zh_CN"));
|
||
tts->setRate(0.0);
|
||
tts->setPitch(1.0);
|
||
tts->setVolume(1.0);
|
||
|
||
qDebug() << "可用语音列表:";
|
||
for (const QVoice &v : tts->availableVoices()) {
|
||
qDebug() << v.name();
|
||
}
|
||
|
||
connect(tts, &QTextToSpeech::stateChanged,
|
||
[](QTextToSpeech::State s){
|
||
if (s == QTextToSpeech::Ready)
|
||
qDebug() << "TTS ready";
|
||
});
|
||
}
|