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.

63 lines
1.9 KiB

  1. #ifndef MAINWINDOW_H
  2. #define MAINWINDOW_H
  3. #include <QMainWindow>
  4. #include <QTabWidget>
  5. #include <QToolBar>
  6. #include <QAction>
  7. #include<QTextEdit>
  8. #include "basedocument.h"
  9. #include "serialportmanager.h"
  10. #include<QPushButton>
  11. QT_BEGIN_NAMESPACE
  12. namespace Ui { class MainWindow; }
  13. QT_END_NAMESPACE
  14. class MainWindow : public QMainWindow
  15. {
  16. Q_OBJECT
  17. public:
  18. MainWindow(QWidget *parent = nullptr);
  19. ~MainWindow();
  20. protected:
  21. bool eventFilter(QObject *obj, QEvent *event) override;
  22. private slots:
  23. void onNewHMI(); // 新建HMI文档
  24. void onNewPLC(); // 新建PLC文档
  25. void onTabChanged(int idx); // 标签页切换时更新工具栏
  26. void onSave(); // 保存文档
  27. void onSaveAs(); // 另存为文档
  28. void onOpen(); // 打开文档
  29. void onCloseTab(int index); // 关闭标签页
  30. void onClearLogButtonClicked();
  31. void showLogContextMenu(const QPoint &pos);
  32. void onConnectClicked(); // 连接菜单项槽函数
  33. void handleSerialLog(const QString &message);
  34. private:
  35. SerialPortManager *m_serialDialog=nullptr; // 串口对话框
  36. void createMenus(); // 创建菜单栏
  37. QWidget* m_logPanelContainer;
  38. QDockWidget* m_logDock;
  39. QTextEdit* m_logEdit;
  40. QPushButton* m_clearLogBtn;
  41. void createLogPanel();
  42. void createToolbars(); // 创建工具栏(左侧)
  43. void updateToolBar(BaseDocument *doc); // 根据文档类型更新工具栏
  44. void saveDocument(BaseDocument *doc); // 保存文档
  45. void saveDocumentAs(BaseDocument *doc); // 另存为文档
  46. QTabWidget *m_tabWidget; // 多文档标签页
  47. QToolBar *m_leftToolBar; // 左侧工具栏
  48. int m_hmiCount = 0; // HMI文档计数器
  49. int m_plcCount = 0; // PLC文档计数器
  50. // 菜单动作
  51. QAction *m_saveAction;
  52. QAction *m_saveAsAction;
  53. QAction *m_openAction;
  54. };
  55. #endif // MAINWINDOW_H