综合平台编辑器
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.5 KiB

  1. #include "mainwindow.h"
  2. #include <QToolBar>
  3. #include <QToolButton>
  4. #include <QVBoxLayout>
  5. #include <QButtonGroup>
  6. #include <QFileDialog>
  7. #include <QMessageBox>
  8. MainWindow::MainWindow(QWidget *parent)
  9. : QMainWindow(parent)
  10. , ui_(new Ui::MainWindow)
  11. {
  12. ui_->setupUi(this);
  13. hmi_ = new HMIModule(ui_, this);
  14. hmi_->init();
  15. initMainWindow();
  16. // 连接 HMIModule 的信号到 MainWindow 的槽
  17. connect(hmi_, &HMIModule::logMessageGenerated, this, &MainWindow::appendLog);
  18. connect(ui_->action_3, &QAction::triggered, this, [this]() {
  19. QString fileName = QFileDialog::getSaveFileName(this, "保存HMI设计", "", "JSON文件 (*.json)");
  20. if (!fileName.isEmpty()) {
  21. if (!hmi_->saveToFile(fileName)) {
  22. QMessageBox::warning(this, "保存失败", "文件保存失败!");
  23. }
  24. }
  25. });
  26. connect(ui_->action_2, &QAction::triggered, this, [this]() {
  27. QString fileName = QFileDialog::getOpenFileName(this, "打开HMI设计", "", "JSON文件 (*.json)");
  28. if (!fileName.isEmpty()) {
  29. if (!hmi_->openFromFile(fileName)) {
  30. QMessageBox::warning(this, "打开失败", "文件打开失败或格式不正确!");
  31. }
  32. }
  33. });
  34. }
  35. MainWindow::~MainWindow()
  36. {
  37. delete ui_;
  38. }
  39. void MainWindow::initMainWindow()
  40. {
  41. setWindowTitle("综合平台编辑器");
  42. setWindowIcon(QIcon(":/resource/image/editor.png"));
  43. }
  44. // 实现槽函数
  45. void MainWindow::appendLog(const QString& message)
  46. {
  47. ui_->textEdit->append(message);
  48. }