AntiClipSettings/Application.h

146 lines
6.8 KiB
C
Raw Permalink Normal View History

2024-08-26 16:46:41 +08:00
#ifndef APPLICATION_H
2024-08-13 20:06:10 +08:00
#define APPLICATION_H
2024-08-21 09:26:06 +08:00
#include "DataCollection.h"
2024-08-16 16:24:15 +08:00
#include "DataStructure.h"
#include "DeviceConnection.h"
#include "DeviceListModel.h"
2024-08-13 20:06:10 +08:00
#include "Singleton.h"
#include <QObject>
#include <QPoint>
#include <QQmlEngine>
class QGuiApplication;
class VideoFrameProvider;
2024-09-11 14:18:56 +08:00
class Settings;
2024-08-13 20:06:10 +08:00
class H264Palyer;
class Application : public QObject {
Q_OBJECT
QML_NAMED_ELEMENT(App)
QML_SINGLETON
2024-08-14 20:01:38 +08:00
Q_PROPERTY(int DeviceWidth MEMBER DeviceWidth CONSTANT FINAL)
2024-08-16 16:24:15 +08:00
Q_PROPERTY(int DeviceHeight MEMBER DeviceHeight CONSTANT FINAL)
Q_PROPERTY(DeviceListModel *devices MEMBER m_devices CONSTANT FINAL);
2024-08-21 09:26:06 +08:00
Q_PROPERTY(DataCollection *collector MEMBER m_collector CONSTANT FINAL);
2024-08-16 16:24:15 +08:00
Q_PROPERTY(DeviceConnection::AreaWay currentOpenDoorAreaWay READ currentOpenDoorAreaWay WRITE
setCurrentOpenDoorAreaWay NOTIFY currentOpenDoorAreaWayChanged)
2024-08-13 20:06:10 +08:00
Q_PROPERTY(QList<QPointF> currentOpenDoorAreaPoints READ currentOpenDoorAreaPoints WRITE
setCurrentOpenDoorAreaPoints NOTIFY currentOpenDoorAreaPointsChanged)
2024-08-14 20:01:38 +08:00
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(int currentAntiClipSensitivity READ currentAntiClipSensitivity WRITE setCurrentAntiClipSensitivity NOTIFY currentAntiClipSensitivityChanged)
2024-08-14 20:01:38 +08:00
Q_PROPERTY(QList<QPointF> currentAntiClipAreaPoints READ currentAntiClipAreaPoints WRITE
setCurrentAntiClipAreaPoints NOTIFY currentAntiClipAreaPointsChanged)
2024-08-16 16:24:15 +08:00
Q_PROPERTY(
NetworkInfomation currentNetworkInfomation READ currentNetworkInfomation NOTIFY currentNetworkInfomationChanged)
2024-08-21 16:03:49 +08:00
Q_PROPERTY(QString currentFirmware MEMBER m_currentFirmware NOTIFY currentFirmwareChanged)
2024-08-22 10:48:28 +08:00
Q_PROPERTY(bool currentDeviceConnected MEMBER m_currentDeviceConnected NOTIFY currentDeviceConnectedChanged)
Q_PROPERTY(bool currentDeviceFlip READ currentDeviceFlip WRITE setCurrentDeviceFlip NOTIFY currentDeviceFlipChanged)
Q_PROPERTY(int currentDeviceRotation READ currentDeviceRotation WRITE setCurrentDeviceRotation NOTIFY
currentDeviceRotationChanged)
2024-08-13 20:06:10 +08:00
friend class Amass::Singleton<Application>;
public:
2024-08-14 20:01:38 +08:00
constexpr static int DeviceWidth = 640;
2024-08-16 16:24:15 +08:00
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);
2024-08-13 20:06:10 +08:00
QList<QPointF> currentOpenDoorAreaPoints() const;
void setCurrentOpenDoorAreaPoints(const QList<QPointF> &points);
2024-08-14 20:01:38 +08:00
2024-08-16 16:24:15 +08:00
NetworkInfomation currentNetworkInfomation() const;
2024-08-14 20:01:38 +08:00
bool currentShieldedAreaEnabled() const;
void setCurrentShieldedAreaEnabled(bool enabled);
QList<QPointF> currentShieldedAreaPoints() const;
void setCurrentShieldedAreaPoints(const QList<QPointF> &points);
bool currentAntiClipAreaEnabled() const;
void setCurrentAntiClipAreaEnabled(bool enabled);
int currentAntiClipSensitivity() const;
void setCurrentAntiClipSensitivity(int sensitivity);
2024-08-14 20:01:38 +08:00
QList<QPointF> currentAntiClipAreaPoints() const;
void setCurrentAntiClipAreaPoints(const QList<QPointF> &points);
bool currentDeviceFlip() const;
void setCurrentDeviceFlip(bool flip);
int currentDeviceRotation() const;
void setCurrentDeviceRotation(int rotation);
2024-08-14 20:01:38 +08:00
Q_INVOKABLE void updateOpenDoorAreaPoints(const QList<QPointF> &points);
Q_INVOKABLE void updateAntiClipAreaPoints(const QList<QPointF> &points);
Q_INVOKABLE void updateShieldedAreaPoints(const QList<QPointF> &points);
2024-08-16 16:24:15 +08:00
Q_INVOKABLE void updateNetworkInfomation(bool dhcp, const QString &ip, const QString &netmask,
2024-08-22 10:48:28 +08:00
const QString &gateway, const QString &dns);
2024-08-20 09:29:49 +08:00
Q_INVOKABLE void connectToDevice(int index);
2024-08-19 09:33:04 +08:00
Q_INVOKABLE void upgradeDevice(const QString &file);
Q_INVOKABLE void resetDevice();
2024-08-21 09:26:06 +08:00
Q_INVOKABLE void startSearchDevice();
2024-08-14 20:01:38 +08:00
2024-08-13 20:06:10 +08:00
int exec();
static Application *create(QQmlEngine *qmlEngine, QJSEngine *jsEngine);
signals:
void newVideoFrame();
void currentOpenDoorAreaPointsChanged();
2024-08-14 20:01:38 +08:00
void currentShieldedAreaPointsChanged();
void currentAntiClipAreaPointsChanged();
2024-08-16 16:24:15 +08:00
void currentOpenDoorAreaWayChanged();
2024-08-14 20:01:38 +08:00
void currentShieldedAreaEnabledChanged();
void currentAntiClipAreaEnabledChanged();
void currentAntiClipSensitivityChanged();
2024-08-16 16:24:15 +08:00
void currentNetworkInfomationChanged();
2024-08-21 16:03:49 +08:00
void currentFirmwareChanged();
2024-08-22 10:48:28 +08:00
void currentDeviceConnectedChanged();
2024-08-21 09:26:06 +08:00
void currentDeviceOtaProgressChanged(bool status, int progress, const QString &message);
void currentDeviceFlipChanged();
void currentDeviceRotationChanged();
2024-08-22 10:48:28 +08:00
void newMessage(int type, const QString &title, const QString &message);
2024-08-13 20:06:10 +08:00
protected:
Application(int &argc, char **argv);
void onDeviceRotationChanged(int rotation);
void onDeviceFlipChanged(bool flip);
2024-08-16 16:24:15 +08:00
void onDeviceOpenDoorArea(DeviceConnection::AreaWay way, const QList<QPointF> &points);
2024-08-14 20:01:38 +08:00
void onDeviceShieldedArea(bool enabled, const QList<QPointF> &points);
void onDeviceAntiClipArea(bool enabled, const QList<QPointF> &points, int sensitivity);
2024-08-16 16:24:15 +08:00
void onDeviceNetworkInfomation(const NetworkInfomation &info);
2024-08-21 16:03:49 +08:00
void onDeviceFirmware(const QString &firmware);
2024-08-22 10:48:28 +08:00
void onDeviceConnected();
void onDeviceDisconnected();
2024-08-13 20:06:10 +08:00
private:
std::shared_ptr<QGuiApplication> m_app;
VideoFrameProvider *m_videoFrameProvider = nullptr;
2024-09-11 14:18:56 +08:00
std::shared_ptr<Settings> m_settings;
2024-08-13 20:06:10 +08:00
std::shared_ptr<H264Palyer> m_player;
2024-08-20 09:29:49 +08:00
std::weak_ptr<DeviceConnection> m_device;
2024-08-16 16:24:15 +08:00
DeviceListModel *m_devices = nullptr;
2024-08-21 09:26:06 +08:00
DataCollection *m_collector = nullptr;
2024-08-13 20:06:10 +08:00
2024-08-16 16:24:15 +08:00
DeviceConnection::AreaWay m_currentOpenDoorAreaWay = DeviceConnection::Diabled;
2024-08-13 20:06:10 +08:00
QList<QPointF> m_currentOpenDoorAreaPoints;
2024-08-14 20:01:38 +08:00
bool m_currentShieldedAreaEnabled = false;
QList<QPointF> m_currentShieldedAreaPoints;
bool m_currentAntiClipAreaEnabled = false;
int m_currentAntiClipSensitivity = 1;
2024-08-14 20:01:38 +08:00
QList<QPointF> m_currentAntiClipAreaPoints;
2024-08-16 16:24:15 +08:00
NetworkInfomation m_currentNetworkInfomation;
2024-08-21 16:03:49 +08:00
QString m_currentFirmware;
2024-08-22 10:48:28 +08:00
bool m_currentDeviceConnected = false;
bool m_currentDeviceFlip = false;
int m_currentDeviceRotation = 0;
2024-08-13 20:06:10 +08:00
};
#endif // APPLICATION_H