From 6f51c279137fa7d9e4729056908b9836749c552e Mon Sep 17 00:00:00 2001 From: rankun Date: Tue, 6 Nov 2018 12:15:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96qt=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E4=BA=8B=E4=BB=B6=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/devicesocket.cpp | 6 ++---- src/devicesocket.h | 2 +- src/qscrcpyevent.h | 11 ++++++++++- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/devicesocket.cpp b/src/devicesocket.cpp index ea11c7b..debe994 100644 --- a/src/devicesocket.cpp +++ b/src/devicesocket.cpp @@ -9,8 +9,6 @@ DeviceSocket::DeviceSocket(QObject *parent) : QTcpSocket(parent) connect(this, &DeviceSocket::readyRead, this, &DeviceSocket::onReadyRead); connect(this, &DeviceSocket::aboutToClose, this, &DeviceSocket::quitNotify); connect(this, &DeviceSocket::disconnected, this, &DeviceSocket::quitNotify); - - installEventFilter(this); } DeviceSocket::~DeviceSocket() @@ -39,13 +37,13 @@ qint32 DeviceSocket::recvData(quint8 *buf, qint32 bufSize) return m_dataSize; } -bool DeviceSocket::eventFilter(QObject *watched, QEvent *event) +bool DeviceSocket::event(QEvent *event) { if (event->type() == QScrcpyEvent::DeviceSocket) { onReadyRead(); return true; } - return false; + return QTcpSocket::event(event); } void DeviceSocket::onReadyRead() diff --git a/src/devicesocket.h b/src/devicesocket.h index 9101302..bb83d36 100644 --- a/src/devicesocket.h +++ b/src/devicesocket.h @@ -16,7 +16,7 @@ public: qint32 recvData(quint8* buf, qint32 bufSize); protected: - bool eventFilter(QObject *watched, QEvent *event); + bool event(QEvent *event); protected slots: void onReadyRead(); diff --git a/src/qscrcpyevent.h b/src/qscrcpyevent.h index bd32aa6..0f2cb65 100644 --- a/src/qscrcpyevent.h +++ b/src/qscrcpyevent.h @@ -1,19 +1,28 @@ #ifndef QSCRCPYEVENT_H #define QSCRCPYEVENT_H #include -#include + class QScrcpyEvent : public QEvent { public: enum Type { DeviceSocket = QEvent::User + 1, + Control, }; QScrcpyEvent(Type type) : QEvent(QEvent::Type(type)){} }; +// DeviceSocketEvent class DeviceSocketEvent : public QScrcpyEvent { public: DeviceSocketEvent() : QScrcpyEvent(DeviceSocket){} }; + +// ControlEvent +class ControlEvent : public QScrcpyEvent +{ +public: + ControlEvent() : QScrcpyEvent(Control){} +}; #endif // QSCRCPYEVENT_H