2026-07-11 15:28:36 +08:00

104 lines
3.8 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef DRONESCREWCTRL_MAINWINDOW_H
#define DRONESCREWCTRL_MAINWINDOW_H
#include <QMainWindow>
#include <QImage>
#include <QLabel>
#include <QGraphicsScene>
#include <QGraphicsPixmapItem>
#include <QDateTime>
#include <QSize>
#include <QStringListModel>
#include <QVBoxLayout>
#include "IYDroneScrewCtrlStatus.h"
#include "DeviceStatusWidget.h"
#include "DetectLogHelper.h"
#include "AboutDialog.h"
#include "WDRemoteDataTypes.h"
namespace Ui { class MainWindow; }
class DroneScrewCtrlPresenter;
class MainWindow : public QMainWindow, public IYDroneScrewCtrlStatus
{
Q_OBJECT
public:
explicit MainWindow(QWidget* parent = nullptr);
~MainWindow() override;
// IYDroneScrewCtrlStatus
void OnRtspFrame(const QImage& frame) override;
void OnDetectionResult(const CtrlDetectionFrame& result) override;
void OnWorkStatusChanged(CtrlWorkStatus status) override;
void OnServerConnectionChanged(bool connected) override;
void OnStatusMessage(const QString& msg) override;
private slots:
// 顶部工具栏:两个按钮的状态机
// btn_start —— 主开关:空闲(start_image) ⟷ 运行(stop_all)
// btn_detect_start —— 开始检测(start_detect),仅实时显示状态下可用
void on_btn_start_clicked(); // 开始实时显示 / 停止(按当前状态切换)
void on_btn_detect_start_clicked(); // 开始检测(从实时显示切到检测)
void on_btn_close_clicked();
void on_btn_hide_clicked();
void on_btn_camera_clicked(); // 连接配置
void on_btn_algo_config_clicked(); // 算法参数
void on_btn_test_clicked(); // 历史数据
void onServerInfoReceived(const WDRemoteServerInfo& info); // 服务器参数接收
protected:
void resizeEvent(QResizeEvent* event) override;
bool eventFilter(QObject* obj, QEvent* event) override;
private:
void initUi();
void renderDisplay();
void appendLog(const QString& msg);
void clampResultList();
void clearResultList();
bool refreshServerInfoFromServer();
QString historyRootDir() const;
QString finalResultHistoryKey(const CtrlDetectionFrame& result) const;
QString makeFinalResultHistoryText(const CtrlDetectionFrame& result,
const QDateTime& savedAt) const;
bool saveFinalResultHistory(const CtrlDetectionFrame& result);
// 顶部按钮状态机
enum class UiState { Idle, Live, Detect };
enum class ResultDisplayMode { Distance, Precision };
void applyUiState(UiState s);
UiState m_uiState{UiState::Idle};
ResultDisplayMode m_resultDisplayMode{ResultDisplayMode::Distance};
// 页面布局
void adjustLayoutForCameraCount(int cameraCount);
void setupSingleCameraLayout();
void setupMultiCameraLayout();
int getAvailableHeight();
void updateVersionLabelAlignment();
private:
Ui::MainWindow* ui{nullptr};
DroneScrewCtrlPresenter* m_pPresenter{nullptr};
// 显示画面QGraphicsView + Scene + PixmapItem
QGraphicsScene* m_pScene{nullptr};
QGraphicsPixmapItem* m_pPixmapItem{nullptr};
QImage m_currentImage;
QSize m_lastRenderImageSize;
QSize m_lastRenderViewSize;
// 公用组件
DeviceStatusWidget* m_deviceStatusWidget{nullptr};
DetectLogHelper* m_logHelper{nullptr};
QLabel* m_versionLabel{nullptr};
int m_maxResultItems{200};
WDRemoteServerInfo m_cachedServerInfo; // 从 Server 读取的参数缓存
QString m_lastStoredFinalResultKey;
};
#endif // DRONESCREWCTRL_MAINWINDOW_H