|
- #pragma once
- #include "editorwidget.h"
- #include <QLabel>
- #include <QPushButton>
- #include <QListWidgetItem>
- #include <QKeyEvent>
- #include <QEvent>
- #include <QGraphicsScene>
-
- class HmiControlItem;
-
- /**
- * @brief HMI (Human Machine Interface) 图形编辑器控件
- *
- * 继承自 EditorWidget,扩展了多页面管理、点击放置与“旁边粘贴”
- */
- class HmiEditorWidget : public EditorWidget {
- Q_OBJECT
-
- public:
- explicit HmiEditorWidget(QWidget* parent = nullptr);
- ~HmiEditorWidget();
-
- // 页面管理接口
- QGraphicsScene* getCurrentScene() const override;
- QList<QGraphicsScene*> getPages() const override { return m_pages; }
- int getCurrentPageIndex() const override { return m_currentPageIndex; }
- void clearPages() override;
- void createNewPage();
- void switchToPage(int index);
- void refreshView();
-
- protected:
- // 覆盖 EditorWidget 接口
- void initToolbar() override;
- void onToolbarItemClicked(QListWidgetItem* item) override;
- void keyPressEvent(QKeyEvent* event) override;
- bool eventFilter(QObject* obj, QEvent* event) override;
- void resizeEvent(QResizeEvent* event) override;
- void showEvent(QShowEvent* event) override;
-
- private slots:
- void onNewPageClicked();
- void onDeletePageClicked();
- void onPreviousPageClicked();
- void onNextPageClicked();
-
- private:
- // —— 辅助 —— //
- void initViewScale();
- void updatePageLabel();
-
- // 根据类型名创建控件并放到 scenePos 上;成功返回新控件指针
- HmiControlItem* createItemByType(const QString& type, const QPointF& scenePos);
-
- // 设置/清除“放置模式”的鼠标提示
- void setPlacingCursor(bool on);
-
- // 计算“在原控件旁边”的粘贴位置(第 n 次粘贴做轻微错行)
- QPointF calcPasteBesidePos(HmiControlItem* src, int pasteIndex = 0) const;
-
- private:
- // 页面
- QList<QGraphicsScene*> m_pages;
- int m_currentPageIndex = -1;
-
- // UI
- QLabel* m_pageLabel = nullptr;
- QPushButton* m_newPageButton = nullptr;
- QPushButton* m_deletePageButton = nullptr;
- QPushButton* m_prevPageButton = nullptr;
- QPushButton* m_nextPageButton = nullptr;
-
- // 交互状态:待放置的控件类型(与工具栏 item 的 UserRole 文本一致:如 “按钮”“指示灯”)
- QString m_pendingType;
- };
|