458 lines
13 KiB
C++
458 lines
13 KiB
C++
#include "mainwindow.h"
|
|
#include "widgets/overlaydialogswidget.h"
|
|
#include <QVBoxLayout>
|
|
#include <QHBoxLayout>
|
|
#include <QMouseEvent>
|
|
#include <QDebug>
|
|
#include <QProcess>
|
|
#include <QCoreApplication>
|
|
|
|
MainWindow::MainWindow(QWidget *parent)
|
|
: QMainWindow(parent), m_currentPage(0), m_totalPages(1), m_isSwiping(false), m_swipeThreshold(100)
|
|
{
|
|
// 设置窗口属性
|
|
setWindowTitle("智能校验仪");
|
|
setMinimumSize(1024, 600);
|
|
resize(1024, 600);
|
|
|
|
// 初始化配置管理器
|
|
m_configManager = new ConfigManager(this);
|
|
|
|
// 初始化规程管理器
|
|
m_procedureManager = new ProcedureManager(this);
|
|
|
|
// 加载配置
|
|
loadConfig();
|
|
|
|
// 设置UI
|
|
setupUI();
|
|
|
|
// 设置页面
|
|
setupPages();
|
|
|
|
// 设置规程播放器
|
|
setupProcedurePlayer();
|
|
|
|
// 设置信号测量功能
|
|
setupSignalMeasurement();
|
|
}
|
|
|
|
MainWindow::~MainWindow()
|
|
{
|
|
}
|
|
|
|
void MainWindow::setupUI()
|
|
{
|
|
// 创建中心部件
|
|
m_centralWidget = new QWidget(this);
|
|
m_centralWidget->setObjectName("centralWidget");
|
|
setCentralWidget(m_centralWidget);
|
|
|
|
// 主布局
|
|
QVBoxLayout *mainLayout = new QVBoxLayout(m_centralWidget);
|
|
mainLayout->setContentsMargins(0, 0, 0, 0);
|
|
mainLayout->setSpacing(0);
|
|
|
|
// 主视图切换器 - 用于在启动器和规程播放器之间切换
|
|
m_mainStackedWidget = new QStackedWidget(this);
|
|
mainLayout->addWidget(m_mainStackedWidget, 1);
|
|
|
|
// 启动器容器
|
|
m_launcherContainer = new QWidget(this);
|
|
m_launcherContainer->setObjectName("launcherContainer");
|
|
|
|
QVBoxLayout *launcherLayout = new QVBoxLayout(m_launcherContainer);
|
|
launcherLayout->setContentsMargins(0, 0, 0, 0);
|
|
launcherLayout->setSpacing(0);
|
|
|
|
// 状态栏 - 透明风格
|
|
m_statusBar = new StatusBar(this);
|
|
launcherLayout->addWidget(m_statusBar);
|
|
|
|
// 页面容器 - 放置启动器页面
|
|
m_pageContainer = new QWidget(this);
|
|
m_pageContainer->setObjectName("pageContainer");
|
|
m_pageContainer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
|
launcherLayout->addWidget(m_pageContainer, 1);
|
|
|
|
// 页面指示器 - Android风格点状指示器
|
|
m_pageIndicator = new PageIndicator(1, this);
|
|
m_pageIndicator->setFixedHeight(40);
|
|
m_pageIndicator->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
|
launcherLayout->addWidget(m_pageIndicator);
|
|
connect(m_pageIndicator, &PageIndicator::pageClicked, this, &MainWindow::goToPage);
|
|
|
|
// 添加启动器到主视图
|
|
m_mainStackedWidget->addWidget(m_launcherContainer);
|
|
|
|
// Android风格渐变壁纸背景
|
|
m_launcherContainer->setStyleSheet(R"(
|
|
#launcherContainer {
|
|
background: qlineargradient(x1:0, y1:0, x2:1, y2:1,
|
|
stop:0 #667eea, stop:0.5 #764ba2, stop:1 #f093fb);
|
|
}
|
|
#pageContainer {
|
|
background: transparent;
|
|
}
|
|
)");
|
|
}
|
|
|
|
void MainWindow::setupPages()
|
|
{
|
|
// 获取页面配置
|
|
auto pagesConfig = m_configManager->getPages();
|
|
m_totalPages = pagesConfig.size();
|
|
m_pageIndicator->setPageCount(m_totalPages);
|
|
|
|
qDebug() << "=== setupPages Debug ===";
|
|
qDebug() << "Total pages:" << m_totalPages;
|
|
for (int i = 0; i < pagesConfig.size(); ++i)
|
|
{
|
|
qDebug() << "Page" << i << ":" << pagesConfig[i].title;
|
|
qDebug() << " Apps count:" << pagesConfig[i].apps.size();
|
|
for (const auto &app : pagesConfig[i].apps)
|
|
{
|
|
qDebug() << " - " << app.name << "(" << app.id << ")";
|
|
}
|
|
}
|
|
|
|
// 为页面容器创建布局
|
|
QVBoxLayout *containerLayout = new QVBoxLayout(m_pageContainer);
|
|
containerLayout->setContentsMargins(0, 0, 0, 0);
|
|
containerLayout->setSpacing(0);
|
|
|
|
// 使用 QStackedWidget 来管理多个页面
|
|
m_stackedWidget = new QStackedWidget(m_pageContainer);
|
|
containerLayout->addWidget(m_stackedWidget);
|
|
|
|
// 创建各个页面
|
|
for (int i = 0; i < pagesConfig.size(); ++i)
|
|
{
|
|
LauncherPage *page = new LauncherPage(pagesConfig[i], m_stackedWidget);
|
|
connect(page, &LauncherPage::appClicked, this, &MainWindow::onAppClicked);
|
|
m_pages.append(page);
|
|
m_stackedWidget->addWidget(page);
|
|
}
|
|
|
|
// 显示当前页面
|
|
m_stackedWidget->setCurrentIndex(m_currentPage);
|
|
|
|
// 不再需要Dock栏
|
|
// m_dockBar->setApps(m_configManager->getDockApps());
|
|
}
|
|
|
|
void MainWindow::loadConfig()
|
|
{
|
|
// 从配置文件加载
|
|
QString configPath = QCoreApplication::applicationDirPath() + "/config/launcher_config.json";
|
|
if (!m_configManager->loadFromFile(configPath))
|
|
{
|
|
// 使用默认配置
|
|
m_configManager->loadDefaultConfig();
|
|
}
|
|
}
|
|
|
|
void MainWindow::setupProcedurePlayer()
|
|
{
|
|
// 规程列表页
|
|
m_procedureListWidget = new ProcedureListWidget(m_procedureManager, this);
|
|
connect(m_procedureListWidget, &ProcedureListWidget::procedureSelected,
|
|
this, &MainWindow::onProcedureSelected);
|
|
connect(m_procedureListWidget, &ProcedureListWidget::backRequested,
|
|
this, &MainWindow::onBackToLauncher);
|
|
m_mainStackedWidget->addWidget(m_procedureListWidget);
|
|
|
|
// 规程执行页
|
|
m_procedurePlayerWidget = new ProcedurePlayerWidget(m_procedureManager, this);
|
|
connect(m_procedurePlayerWidget, &ProcedurePlayerWidget::backToListRequested,
|
|
this, [this]()
|
|
{ showProcedureList(); });
|
|
m_mainStackedWidget->addWidget(m_procedurePlayerWidget);
|
|
}
|
|
|
|
void MainWindow::setupSignalMeasurement()
|
|
{
|
|
m_signalMeasurementWidget = new SignalMeasurementWidget(this);
|
|
connect(m_signalMeasurementWidget, &SignalMeasurementWidget::backRequested,
|
|
this, &MainWindow::onBackToLauncherFromSignal);
|
|
m_mainStackedWidget->addWidget(m_signalMeasurementWidget);
|
|
|
|
// 设置系统设置页面
|
|
m_settingsWidget = new SettingsWidget(this);
|
|
connect(m_settingsWidget, &SettingsWidget::backRequested,
|
|
this, &MainWindow::showLauncher);
|
|
m_mainStackedWidget->addWidget(m_settingsWidget);
|
|
|
|
// 设置数据管理页面
|
|
m_dataManagementWidget = new DataManagementWidget(this);
|
|
connect(m_dataManagementWidget, &DataManagementWidget::backRequested,
|
|
this, &MainWindow::showLauncher);
|
|
m_mainStackedWidget->addWidget(m_dataManagementWidget);
|
|
|
|
// 设置无线通讯页面
|
|
m_wirelessWidget = new WirelessWidget(this);
|
|
connect(m_wirelessWidget, &WirelessWidget::backRequested,
|
|
this, &MainWindow::showLauncher);
|
|
m_mainStackedWidget->addWidget(m_wirelessWidget);
|
|
|
|
// 设置网络测试页面
|
|
m_networkTestWidget = new NetworkTestWidget(this);
|
|
connect(m_networkTestWidget, &NetworkTestWidget::backRequested,
|
|
this, &MainWindow::showLauncher);
|
|
m_mainStackedWidget->addWidget(m_networkTestWidget);
|
|
|
|
// 设置波形采集页面
|
|
m_waveformWidget = new WaveformWidget(this);
|
|
connect(m_waveformWidget, &WaveformWidget::backRequested,
|
|
this, &MainWindow::showLauncher);
|
|
m_mainStackedWidget->addWidget(m_waveformWidget);
|
|
|
|
// 设置双通道页面
|
|
m_dualChannelWidget = new DualChannelWidget(this);
|
|
connect(m_dualChannelWidget, &DualChannelWidget::backRequested,
|
|
this, &MainWindow::showLauncher);
|
|
m_mainStackedWidget->addWidget(m_dualChannelWidget);
|
|
|
|
// 设置信号微调页面
|
|
m_signalTrimWidget = new SignalTrimWidget(this);
|
|
connect(m_signalTrimWidget, &SignalTrimWidget::backRequested,
|
|
this, &MainWindow::showLauncher);
|
|
m_mainStackedWidget->addWidget(m_signalTrimWidget);
|
|
}
|
|
|
|
void MainWindow::showLauncher()
|
|
{
|
|
m_mainStackedWidget->setCurrentWidget(m_launcherContainer);
|
|
}
|
|
|
|
void MainWindow::showProcedureList()
|
|
{
|
|
m_procedureListWidget->refreshList();
|
|
m_mainStackedWidget->setCurrentWidget(m_procedureListWidget);
|
|
}
|
|
|
|
void MainWindow::showProcedurePlayer(const QString &procedureId)
|
|
{
|
|
m_procedurePlayerWidget->loadProcedure(procedureId);
|
|
m_mainStackedWidget->setCurrentWidget(m_procedurePlayerWidget);
|
|
}
|
|
|
|
void MainWindow::showSignalMeasurement(const QString &appId)
|
|
{
|
|
// 根据appId设置对应的模块
|
|
if (appId == "rtd_measure")
|
|
m_signalMeasurementWidget->setModule(0); // 热电阻测量
|
|
else if (appId == "rtd_output")
|
|
m_signalMeasurementWidget->setModule(11); // 热电阻输出(新增)
|
|
else if (appId == "rtd")
|
|
m_signalMeasurementWidget->setModule(0); // 兼容旧的rtd
|
|
else if (appId == "thermocouple")
|
|
m_signalMeasurementWidget->setModule(1);
|
|
else if (appId == "insulation")
|
|
m_signalMeasurementWidget->setModule(2);
|
|
else if (appId == "dc_current")
|
|
m_signalMeasurementWidget->setModule(3);
|
|
else if (appId == "dc_voltage")
|
|
m_signalMeasurementWidget->setModule(4);
|
|
else if (appId == "frequency")
|
|
m_signalMeasurementWidget->setModule(5);
|
|
else if (appId == "ac_voltage")
|
|
m_signalMeasurementWidget->setModule(6);
|
|
else if (appId == "switch_detect")
|
|
m_signalMeasurementWidget->setModule(7);
|
|
else if (appId == "waveform")
|
|
m_signalMeasurementWidget->setModule(8);
|
|
else if (appId == "ramp")
|
|
m_signalMeasurementWidget->setModule(9);
|
|
else if (appId == "ripple")
|
|
m_signalMeasurementWidget->setModule(10);
|
|
else
|
|
m_signalMeasurementWidget->setModule(0); // 默认热电阻
|
|
|
|
m_mainStackedWidget->setCurrentWidget(m_signalMeasurementWidget);
|
|
}
|
|
|
|
void MainWindow::onProcedureSelected(const QString &procedureId)
|
|
{
|
|
showProcedurePlayer(procedureId);
|
|
}
|
|
|
|
void MainWindow::onBackToLauncher()
|
|
{
|
|
showLauncher();
|
|
}
|
|
|
|
void MainWindow::onBackToLauncherFromSignal()
|
|
{
|
|
showLauncher();
|
|
}
|
|
|
|
void MainWindow::resizeEvent(QResizeEvent *event)
|
|
{
|
|
QMainWindow::resizeEvent(event);
|
|
|
|
// 调整页面大小
|
|
for (auto page : m_pages)
|
|
{
|
|
page->setGeometry(m_pageContainer->rect());
|
|
}
|
|
}
|
|
|
|
void MainWindow::mousePressEvent(QMouseEvent *event)
|
|
{
|
|
// 检查是否在页面容器区域
|
|
if (m_pageContainer->geometry().contains(event->pos()))
|
|
{
|
|
m_swipeStartPos = event->pos();
|
|
m_isSwiping = true;
|
|
}
|
|
QMainWindow::mousePressEvent(event);
|
|
}
|
|
|
|
void MainWindow::mouseMoveEvent(QMouseEvent *event)
|
|
{
|
|
if (m_isSwiping)
|
|
{
|
|
// 可以添加实时跟随效果
|
|
}
|
|
QMainWindow::mouseMoveEvent(event);
|
|
}
|
|
|
|
void MainWindow::mouseReleaseEvent(QMouseEvent *event)
|
|
{
|
|
if (m_isSwiping)
|
|
{
|
|
int deltaX = event->pos().x() - m_swipeStartPos.x();
|
|
handleSwipe(deltaX);
|
|
m_isSwiping = false;
|
|
}
|
|
QMainWindow::mouseReleaseEvent(event);
|
|
}
|
|
|
|
void MainWindow::handleSwipe(int deltaX)
|
|
{
|
|
if (qAbs(deltaX) < m_swipeThreshold)
|
|
{
|
|
return; // 滑动距离不够
|
|
}
|
|
|
|
int newPage = m_currentPage;
|
|
if (deltaX > 0 && m_currentPage > 0)
|
|
{
|
|
// 向右滑动,前一页
|
|
newPage = m_currentPage - 1;
|
|
}
|
|
else if (deltaX < 0 && m_currentPage < m_totalPages - 1)
|
|
{
|
|
// 向左滑动,后一页
|
|
newPage = m_currentPage + 1;
|
|
}
|
|
|
|
if (newPage != m_currentPage)
|
|
{
|
|
goToPage(newPage);
|
|
}
|
|
}
|
|
|
|
void MainWindow::goToPage(int pageIndex)
|
|
{
|
|
if (pageIndex < 0 || pageIndex >= m_totalPages || pageIndex == m_currentPage)
|
|
{
|
|
return;
|
|
}
|
|
|
|
m_currentPage = pageIndex;
|
|
m_stackedWidget->setCurrentIndex(pageIndex);
|
|
if (m_pageIndicator)
|
|
{
|
|
m_pageIndicator->setCurrentPage(pageIndex);
|
|
}
|
|
}
|
|
|
|
void MainWindow::animatePageTransition(int fromPage, int toPage)
|
|
{
|
|
Q_UNUSED(fromPage)
|
|
Q_UNUSED(toPage)
|
|
// 使用 QStackedWidget 后不需要手动动画
|
|
}
|
|
|
|
void MainWindow::onAppClicked(const QString &appId)
|
|
{
|
|
openApplication(appId);
|
|
}
|
|
|
|
void MainWindow::onDockAppClicked(const QString &appId)
|
|
{
|
|
openApplication(appId);
|
|
}
|
|
|
|
void MainWindow::openApplication(const QString &appId)
|
|
{
|
|
qDebug() << "Opening application:" << appId;
|
|
|
|
// 根据appId打开对应功能窗口
|
|
if (appId == "procedures" || appId == "procedure")
|
|
{
|
|
// 打开规程播放器
|
|
showProcedureList();
|
|
}
|
|
else if (appId == "signal_measurement" || appId == "rtd" || appId == "rtd_measure" ||
|
|
appId == "rtd_output" || appId == "thermocouple" ||
|
|
appId == "insulation" || appId == "dc_current" || appId == "dc_voltage" ||
|
|
appId == "frequency" || appId == "ac_voltage" || appId == "switch_detect" ||
|
|
appId == "ripple" || appId == "ramp")
|
|
{
|
|
// 打开信号测量功能页面
|
|
showSignalMeasurement(appId);
|
|
}
|
|
else if (appId == "waveform")
|
|
{
|
|
// 打开波形采集页面
|
|
m_mainStackedWidget->setCurrentWidget(m_waveformWidget);
|
|
}
|
|
else if (appId == "dual_channel")
|
|
{
|
|
// 打开双通道页面
|
|
m_mainStackedWidget->setCurrentWidget(m_dualChannelWidget);
|
|
}
|
|
else if (appId == "trim")
|
|
{
|
|
// 打开信号微调页面
|
|
m_mainStackedWidget->setCurrentWidget(m_signalTrimWidget);
|
|
}
|
|
else if (appId == "data_management")
|
|
{
|
|
// 打开数据管理页面
|
|
m_mainStackedWidget->setCurrentWidget(m_dataManagementWidget);
|
|
}
|
|
else if (appId == "wireless")
|
|
{
|
|
// 打开无线通讯页面
|
|
m_mainStackedWidget->setCurrentWidget(m_wirelessWidget);
|
|
}
|
|
else if (appId == "sop" || appId == "dock_sop")
|
|
{
|
|
// 打开规程播放器
|
|
showProcedureList();
|
|
}
|
|
else if (appId == "rcp63" || appId == "dock_rcp63")
|
|
{
|
|
// 直接打开RCP63规程
|
|
showProcedurePlayer("KMCIXRCP503");
|
|
}
|
|
else if (appId == "settings" || appId == "dock_settings")
|
|
{
|
|
// 打开系统设置页面
|
|
m_mainStackedWidget->setCurrentWidget(m_settingsWidget);
|
|
}
|
|
else if (appId == "dock_network")
|
|
{
|
|
// 打开网络测试页面
|
|
m_mainStackedWidget->setCurrentWidget(m_networkTestWidget);
|
|
}
|
|
else
|
|
{
|
|
OverlayDialog::information(this, "功能", QString("功能 ID: %1").arg(appId));
|
|
}
|
|
}
|