mirror of
https://github.com/barry-ran/QtScrcpy.git
synced 2025-07-29 20:28:38 +00:00
优化qt自定义事件处理逻辑
This commit is contained in:
parent
bdd5a94bee
commit
6f51c27913
3 changed files with 13 additions and 6 deletions
|
@ -9,8 +9,6 @@ DeviceSocket::DeviceSocket(QObject *parent) : QTcpSocket(parent)
|
||||||
connect(this, &DeviceSocket::readyRead, this, &DeviceSocket::onReadyRead);
|
connect(this, &DeviceSocket::readyRead, this, &DeviceSocket::onReadyRead);
|
||||||
connect(this, &DeviceSocket::aboutToClose, this, &DeviceSocket::quitNotify);
|
connect(this, &DeviceSocket::aboutToClose, this, &DeviceSocket::quitNotify);
|
||||||
connect(this, &DeviceSocket::disconnected, this, &DeviceSocket::quitNotify);
|
connect(this, &DeviceSocket::disconnected, this, &DeviceSocket::quitNotify);
|
||||||
|
|
||||||
installEventFilter(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceSocket::~DeviceSocket()
|
DeviceSocket::~DeviceSocket()
|
||||||
|
@ -39,13 +37,13 @@ qint32 DeviceSocket::recvData(quint8 *buf, qint32 bufSize)
|
||||||
return m_dataSize;
|
return m_dataSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeviceSocket::eventFilter(QObject *watched, QEvent *event)
|
bool DeviceSocket::event(QEvent *event)
|
||||||
{
|
{
|
||||||
if (event->type() == QScrcpyEvent::DeviceSocket) {
|
if (event->type() == QScrcpyEvent::DeviceSocket) {
|
||||||
onReadyRead();
|
onReadyRead();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return QTcpSocket::event(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceSocket::onReadyRead()
|
void DeviceSocket::onReadyRead()
|
||||||
|
|
|
@ -16,7 +16,7 @@ public:
|
||||||
qint32 recvData(quint8* buf, qint32 bufSize);
|
qint32 recvData(quint8* buf, qint32 bufSize);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool eventFilter(QObject *watched, QEvent *event);
|
bool event(QEvent *event);
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void onReadyRead();
|
void onReadyRead();
|
||||||
|
|
|
@ -1,19 +1,28 @@
|
||||||
#ifndef QSCRCPYEVENT_H
|
#ifndef QSCRCPYEVENT_H
|
||||||
#define QSCRCPYEVENT_H
|
#define QSCRCPYEVENT_H
|
||||||
#include <QEvent>
|
#include <QEvent>
|
||||||
#include <QMouseEvent>
|
|
||||||
class QScrcpyEvent : public QEvent
|
class QScrcpyEvent : public QEvent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum Type {
|
enum Type {
|
||||||
DeviceSocket = QEvent::User + 1,
|
DeviceSocket = QEvent::User + 1,
|
||||||
|
Control,
|
||||||
};
|
};
|
||||||
QScrcpyEvent(Type type) : QEvent(QEvent::Type(type)){}
|
QScrcpyEvent(Type type) : QEvent(QEvent::Type(type)){}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// DeviceSocketEvent
|
||||||
class DeviceSocketEvent : public QScrcpyEvent
|
class DeviceSocketEvent : public QScrcpyEvent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DeviceSocketEvent() : QScrcpyEvent(DeviceSocket){}
|
DeviceSocketEvent() : QScrcpyEvent(DeviceSocket){}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// ControlEvent
|
||||||
|
class ControlEvent : public QScrcpyEvent
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ControlEvent() : QScrcpyEvent(Control){}
|
||||||
|
};
|
||||||
#endif // QSCRCPYEVENT_H
|
#endif // QSCRCPYEVENT_H
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue