AntiClipSettings/Application.h
2024-08-21 09:26:06 +08:00

112 lines
5.1 KiB
C++

#ifndef APPLICATION_H
#define APPLICATION_H
#include "DataCollection.h"
#include "DataStructure.h"
#include "DeviceConnection.h"
#include "DeviceListModel.h"
#include "Singleton.h"
#include <QObject>
#include <QPoint>
#include <QQmlEngine>
class QGuiApplication;
class VideoFrameProvider;
class H264Palyer;
class Application : public QObject {
Q_OBJECT
QML_NAMED_ELEMENT(App)
QML_SINGLETON
Q_PROPERTY(int DeviceWidth MEMBER DeviceWidth CONSTANT FINAL)
Q_PROPERTY(int DeviceHeight MEMBER DeviceHeight CONSTANT FINAL)
Q_PROPERTY(DeviceListModel *devices MEMBER m_devices CONSTANT FINAL);
Q_PROPERTY(DataCollection *collector MEMBER m_collector CONSTANT FINAL);
Q_PROPERTY(DeviceConnection::AreaWay currentOpenDoorAreaWay READ currentOpenDoorAreaWay WRITE
setCurrentOpenDoorAreaWay NOTIFY currentOpenDoorAreaWayChanged)
Q_PROPERTY(QList<QPointF> currentOpenDoorAreaPoints READ currentOpenDoorAreaPoints WRITE
setCurrentOpenDoorAreaPoints NOTIFY currentOpenDoorAreaPointsChanged)
Q_PROPERTY(bool currentShieldedAreaEnabled READ currentShieldedAreaEnabled WRITE setCurrentShieldedAreaEnabled
NOTIFY currentShieldedAreaEnabledChanged)
Q_PROPERTY(QList<QPointF> currentShieldedAreaPoints READ currentShieldedAreaPoints WRITE
setCurrentShieldedAreaPoints NOTIFY currentShieldedAreaPointsChanged)
Q_PROPERTY(bool currentAntiClipAreaEnabled READ currentAntiClipAreaEnabled WRITE setCurrentAntiClipAreaEnabled
NOTIFY currentAntiClipAreaEnabledChanged)
Q_PROPERTY(QList<QPointF> currentAntiClipAreaPoints READ currentAntiClipAreaPoints WRITE
setCurrentAntiClipAreaPoints NOTIFY currentAntiClipAreaPointsChanged)
Q_PROPERTY(
NetworkInfomation currentNetworkInfomation READ currentNetworkInfomation NOTIFY currentNetworkInfomationChanged)
friend class Amass::Singleton<Application>;
public:
constexpr static int DeviceWidth = 640;
constexpr static int DeviceHeight = 360;
inline static const QList<QPointF> FullArea = {QPointF(0, 0), QPointF(DeviceWidth, 0),
QPointF(DeviceWidth, DeviceHeight), QPointF(0, DeviceHeight)};
DeviceConnection::AreaWay currentOpenDoorAreaWay() const;
void setCurrentOpenDoorAreaWay(DeviceConnection::AreaWay way);
QList<QPointF> currentOpenDoorAreaPoints() const;
void setCurrentOpenDoorAreaPoints(const QList<QPointF> &points);
NetworkInfomation currentNetworkInfomation() const;
bool currentShieldedAreaEnabled() const;
void setCurrentShieldedAreaEnabled(bool enabled);
QList<QPointF> currentShieldedAreaPoints() const;
void setCurrentShieldedAreaPoints(const QList<QPointF> &points);
bool currentAntiClipAreaEnabled() const;
void setCurrentAntiClipAreaEnabled(bool enabled);
QList<QPointF> currentAntiClipAreaPoints() const;
void setCurrentAntiClipAreaPoints(const QList<QPointF> &points);
Q_INVOKABLE void updateOpenDoorAreaPoints(const QList<QPointF> &points);
Q_INVOKABLE void updateAntiClipAreaPoints(const QList<QPointF> &points);
Q_INVOKABLE void updateShieldedAreaPoints(const QList<QPointF> &points);
Q_INVOKABLE void updateNetworkInfomation(bool dhcp, const QString &ip, const QString &netmask,
const QString &gateway);
Q_INVOKABLE void connectToDevice(int index);
Q_INVOKABLE void upgradeDevice(const QString &file);
Q_INVOKABLE void startSearchDevice();
int exec();
static Application *create(QQmlEngine *qmlEngine, QJSEngine *jsEngine);
signals:
void newVideoFrame();
void currentOpenDoorAreaPointsChanged();
void currentShieldedAreaPointsChanged();
void currentAntiClipAreaPointsChanged();
void currentOpenDoorAreaWayChanged();
void currentShieldedAreaEnabledChanged();
void currentAntiClipAreaEnabledChanged();
void currentNetworkInfomationChanged();
void currentDeviceOtaProgressChanged(bool status, int progress, const QString &message);
protected:
Application(int &argc, char **argv);
void onDeviceOpenDoorArea(DeviceConnection::AreaWay way, const QList<QPointF> &points);
void onDeviceShieldedArea(bool enabled, const QList<QPointF> &points);
void onDeviceAntiClipArea(bool enabled, const QList<QPointF> &points);
void onDeviceNetworkInfomation(const NetworkInfomation &info);
private:
std::shared_ptr<QGuiApplication> m_app;
VideoFrameProvider *m_videoFrameProvider = nullptr;
std::shared_ptr<H264Palyer> m_player;
std::weak_ptr<DeviceConnection> m_device;
DeviceListModel *m_devices = nullptr;
DataCollection *m_collector = nullptr;
DeviceConnection::AreaWay m_currentOpenDoorAreaWay = DeviceConnection::Diabled;
QList<QPointF> m_currentOpenDoorAreaPoints;
bool m_currentShieldedAreaEnabled = false;
QList<QPointF> m_currentShieldedAreaPoints;
bool m_currentAntiClipAreaEnabled = false;
QList<QPointF> m_currentAntiClipAreaPoints;
NetworkInfomation m_currentNetworkInfomation;
};
#endif // APPLICATION_H