|
- #include "mainwindow.h"
- #include <QToolBar>
- #include <QToolButton>
- #include <QVBoxLayout>
- #include <QButtonGroup>
- #include <QFileDialog>
- #include <QMessageBox>
-
- MainWindow::MainWindow(QWidget *parent)
- : QMainWindow(parent)
- , ui_(new Ui::MainWindow)
- {
- ui_->setupUi(this);
- hmi_ = new HMIModule(ui_, this);
- hmi_->init();
-
- initMainWindow();
- // 连接 HMIModule 的信号到 MainWindow 的槽
- connect(hmi_, &HMIModule::logMessageGenerated, this, &MainWindow::appendLog);
-
- connect(ui_->action_3, &QAction::triggered, this, [this]() {
- QString fileName = QFileDialog::getSaveFileName(this, "保存HMI设计", "", "JSON文件 (*.json)");
- if (!fileName.isEmpty()) {
- if (!hmi_->saveToFile(fileName)) {
- QMessageBox::warning(this, "保存失败", "文件保存失败!");
- }
- }
- });
-
- connect(ui_->action_2, &QAction::triggered, this, [this]() {
- QString fileName = QFileDialog::getOpenFileName(this, "打开HMI设计", "", "JSON文件 (*.json)");
- if (!fileName.isEmpty()) {
- if (!hmi_->openFromFile(fileName)) {
- QMessageBox::warning(this, "打开失败", "文件打开失败或格式不正确!");
- }
- }
- });
- }
-
- MainWindow::~MainWindow()
- {
- delete ui_;
- }
-
- void MainWindow::initMainWindow()
- {
- setWindowTitle("综合平台编辑器");
- setWindowIcon(QIcon(":/resource/image/editor.png"));
- }
-
- // 实现槽函数
- void MainWindow::appendLog(const QString& message)
- {
- ui_->textEdit->append(message);
- }
|