From 94162fe4e00f3f00e3a1dee8a7523865e7347984 Mon Sep 17 00:00:00 2001 From: Barry <870709864@qq.com> Date: Thu, 20 Jun 2019 09:18:00 +0800 Subject: [PATCH] =?UTF-8?q?update:=E9=87=8D=E6=9E=84controller=20controlle?= =?UTF-8?q?r=E7=AE=A1=E7=90=86inputconvert=E5=92=8Creceiver=20receiver?= =?UTF-8?q?=E8=B4=9F=E8=B4=A3=E6=8E=A5=E6=94=B6=E7=BB=88=E7=AB=AF=E7=9A=84?= =?UTF-8?q?=E6=B6=88=E6=81=AF=20inputconvert=E8=B4=9F=E8=B4=A3=E8=BD=AC?= =?UTF-8?q?=E5=8C=96=E9=BC=A0=E6=A0=87=E9=94=AE=E7=9B=98=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + QtScrcpy/QtScrcpy.pro | 4 +- .../controller.cpp | 33 +++++++++++++--- .../{inputcontrol => controller}/controller.h | 13 ++++++- QtScrcpy/controller/controller.pri | 14 +++++++ .../inputconvert}/controlmsg.cpp | 0 .../inputconvert}/controlmsg.h | 0 .../inputconvert/inputconvert.pri} | 10 +---- .../inputconvert/inputconvertbase.cpp | 22 +++++++++++ .../inputconvert}/inputconvertbase.h | 15 ++++--- .../inputconvert}/inputconvertgame.cpp | 3 +- .../inputconvert}/inputconvertgame.h | 7 +--- .../inputconvert}/inputconvertnormal.cpp | 3 +- .../inputconvert}/inputconvertnormal.h | 3 +- .../receiver}/devicemsg.cpp | 0 .../receiver}/devicemsg.h | 0 .../receiver}/receiver.cpp | 27 +++++++------ .../receiver}/receiver.h | 8 ++-- QtScrcpy/controller/receiver/receiver.pri | 7 ++++ QtScrcpy/inputcontrol/inputconvertbase.cpp | 24 ------------ QtScrcpy/videoform.cpp | 39 ++++++++++--------- QtScrcpy/videoform.h | 30 +++++++------- TODO.txt | 1 - 23 files changed, 163 insertions(+), 101 deletions(-) rename QtScrcpy/{inputcontrol => controller}/controller.cpp (63%) rename QtScrcpy/{inputcontrol => controller}/controller.h (58%) create mode 100644 QtScrcpy/controller/controller.pri rename QtScrcpy/{inputcontrol => controller/inputconvert}/controlmsg.cpp (100%) rename QtScrcpy/{inputcontrol => controller/inputconvert}/controlmsg.h (100%) rename QtScrcpy/{inputcontrol/inputcontrol.pri => controller/inputconvert/inputconvert.pri} (53%) create mode 100644 QtScrcpy/controller/inputconvert/inputconvertbase.cpp rename QtScrcpy/{inputcontrol => controller/inputconvert}/inputconvertbase.h (76%) rename QtScrcpy/{inputcontrol => controller/inputconvert}/inputconvertgame.cpp (99%) rename QtScrcpy/{inputcontrol => controller/inputconvert}/inputconvertgame.h (94%) rename QtScrcpy/{inputcontrol => controller/inputconvert}/inputconvertnormal.cpp (98%) rename QtScrcpy/{inputcontrol => controller/inputconvert}/inputconvertnormal.h (92%) rename QtScrcpy/{inputcontrol => controller/receiver}/devicemsg.cpp (100%) rename QtScrcpy/{inputcontrol => controller/receiver}/devicemsg.h (100%) rename QtScrcpy/{inputcontrol => controller/receiver}/receiver.cpp (58%) rename QtScrcpy/{inputcontrol => controller/receiver}/receiver.h (63%) create mode 100644 QtScrcpy/controller/receiver/receiver.pri delete mode 100644 QtScrcpy/inputcontrol/inputconvertbase.cpp diff --git a/.gitignore b/.gitignore index e8d49bb..c91f58f 100644 --- a/.gitignore +++ b/.gitignore @@ -132,3 +132,4 @@ /output/win/debug/QtScrcpy.pdb /output/win/debug/QtScrcpy.exe /output/win/release/QtScrcpy.exe +build diff --git a/QtScrcpy/QtScrcpy.pro b/QtScrcpy/QtScrcpy.pro index fd42dfc..0661aee 100644 --- a/QtScrcpy/QtScrcpy.pro +++ b/QtScrcpy/QtScrcpy.pro @@ -55,7 +55,7 @@ include ($$PWD/decoder/decoder.pri) include ($$PWD/render/render.pri) include ($$PWD/stream/stream.pri) include ($$PWD/android/android.pri) -include ($$PWD/inputcontrol/inputcontrol.pri) +include ($$PWD/controller/controller.pri) include ($$PWD/uibase/uibase.pri) include ($$PWD/fontawesome/fontawesome.pri) include ($$PWD/filehandler/filehandler.pri) @@ -72,7 +72,7 @@ INCLUDEPATH += \ $$PWD/render \ $$PWD/stream \ $$PWD/android \ - $$PWD/inputcontrol \ + $$PWD/controller \ $$PWD/uibase \ $$PWD/filehandler \ $$PWD/recorder \ diff --git a/QtScrcpy/inputcontrol/controller.cpp b/QtScrcpy/controller/controller.cpp similarity index 63% rename from QtScrcpy/inputcontrol/controller.cpp rename to QtScrcpy/controller/controller.cpp index 5929730..4314170 100644 --- a/QtScrcpy/inputcontrol/controller.cpp +++ b/QtScrcpy/controller/controller.cpp @@ -8,6 +8,11 @@ Controller::Controller(QObject* parent) : QObject(parent) { m_receiver = new Receiver(this); + Q_ASSERT(m_receiver); + + m_inputConvert = new InputConvertGame(this); + Q_ASSERT(m_inputConvert); + connect(m_inputConvert, &InputConvertGame::grabCursor, this, &Controller::grabCursor); } Controller::~Controller() @@ -21,12 +26,7 @@ void Controller::setControlSocket(QTcpSocket* controlSocket) return; } m_controlSocket = controlSocket; - connect(controlSocket, &QTcpSocket::readyRead, m_receiver, &Receiver::onReadyRead); -} - -QTcpSocket *Controller::getControlSocket() -{ - return m_controlSocket; + m_receiver->setControlSocket(controlSocket); } void Controller::postControlMsg(ControlMsg *controlMsg) @@ -43,6 +43,27 @@ void Controller::test(QRect rc) postControlMsg(controlMsg); } +void Controller::mouseEvent(const QMouseEvent *from, const QSize &frameSize, const QSize &showSize) +{ + if (m_inputConvert) { + m_inputConvert->mouseEvent(from, frameSize, showSize); + } +} + +void Controller::wheelEvent(const QWheelEvent *from, const QSize &frameSize, const QSize &showSize) +{ + if (m_inputConvert) { + m_inputConvert->wheelEvent(from, frameSize, showSize); + } +} + +void Controller::keyEvent(const QKeyEvent *from, const QSize &frameSize, const QSize &showSize) +{ + if (m_inputConvert) { + m_inputConvert->keyEvent(from, frameSize, showSize); + } +} + bool Controller::event(QEvent *event) { if (event && event->type() == ControlMsg::Control) { diff --git a/QtScrcpy/inputcontrol/controller.h b/QtScrcpy/controller/controller.h similarity index 58% rename from QtScrcpy/inputcontrol/controller.h rename to QtScrcpy/controller/controller.h index a046284..da537b6 100644 --- a/QtScrcpy/inputcontrol/controller.h +++ b/QtScrcpy/controller/controller.h @@ -4,8 +4,9 @@ #include #include +#include "inputconvertgame.h" + class QTcpSocket; -class ControlMsg; class Receiver; class Controller : public QObject { @@ -15,10 +16,17 @@ public: virtual ~Controller(); void setControlSocket(QTcpSocket* controlSocket); - QTcpSocket* getControlSocket(); void postControlMsg(ControlMsg* controlMsg); void test(QRect rc); + // for input convert + void mouseEvent(const QMouseEvent* from, const QSize& frameSize, const QSize& showSize); + void wheelEvent(const QWheelEvent* from, const QSize& frameSize, const QSize& showSize); + void keyEvent(const QKeyEvent* from, const QSize& frameSize, const QSize& showSize); + +signals: + void grabCursor(bool grab); + protected: bool event(QEvent *event); @@ -28,6 +36,7 @@ private: private: QPointer m_controlSocket; QPointer m_receiver; + QPointer m_inputConvert; }; #endif // CONTROLLER_H diff --git a/QtScrcpy/controller/controller.pri b/QtScrcpy/controller/controller.pri new file mode 100644 index 0000000..5088569 --- /dev/null +++ b/QtScrcpy/controller/controller.pri @@ -0,0 +1,14 @@ +HEADERS += \ + $$PWD/controller.h + +SOURCES += \ + $$PWD/controller.cpp + +include ($$PWD/receiver/receiver.pri) +include ($$PWD/inputconvert/inputconvert.pri) + +INCLUDEPATH += \ + $$PWD/receiver \ + $$PWD/inputconvert + + diff --git a/QtScrcpy/inputcontrol/controlmsg.cpp b/QtScrcpy/controller/inputconvert/controlmsg.cpp similarity index 100% rename from QtScrcpy/inputcontrol/controlmsg.cpp rename to QtScrcpy/controller/inputconvert/controlmsg.cpp diff --git a/QtScrcpy/inputcontrol/controlmsg.h b/QtScrcpy/controller/inputconvert/controlmsg.h similarity index 100% rename from QtScrcpy/inputcontrol/controlmsg.h rename to QtScrcpy/controller/inputconvert/controlmsg.h diff --git a/QtScrcpy/inputcontrol/inputcontrol.pri b/QtScrcpy/controller/inputconvert/inputconvert.pri similarity index 53% rename from QtScrcpy/inputcontrol/inputcontrol.pri rename to QtScrcpy/controller/inputconvert/inputconvert.pri index 0c3d8bb..57568a5 100644 --- a/QtScrcpy/inputcontrol/inputcontrol.pri +++ b/QtScrcpy/controller/inputconvert/inputconvert.pri @@ -1,18 +1,12 @@ HEADERS += \ - $$PWD/controller.h \ $$PWD/inputconvertbase.h \ $$PWD/inputconvertgame.h \ $$PWD/inputconvertnormal.h \ - $$PWD/receiver.h \ - $$PWD/controlmsg.h \ - $$PWD/devicemsg.h + $$PWD/controlmsg.h SOURCES += \ - $$PWD/controller.cpp \ $$PWD/inputconvertbase.cpp \ $$PWD/inputconvertgame.cpp \ $$PWD/inputconvertnormal.cpp \ - $$PWD/receiver.cpp \ - $$PWD/controlmsg.cpp \ - $$PWD/devicemsg.cpp + $$PWD/controlmsg.cpp diff --git a/QtScrcpy/controller/inputconvert/inputconvertbase.cpp b/QtScrcpy/controller/inputconvert/inputconvertbase.cpp new file mode 100644 index 0000000..c95456d --- /dev/null +++ b/QtScrcpy/controller/inputconvert/inputconvertbase.cpp @@ -0,0 +1,22 @@ +#include "inputconvertbase.h" +#include "controller.h" + +InputConvertBase::InputConvertBase(Controller* controller) + : QObject(controller) + , m_controller(controller) +{ + Q_ASSERT(controller); +} + +InputConvertBase::~InputConvertBase() +{ + +} + +void InputConvertBase::sendControlMsg(ControlMsg *msg) +{ + if (msg && m_controller) { + m_controller->postControlMsg(msg); + } +} + diff --git a/QtScrcpy/inputcontrol/inputconvertbase.h b/QtScrcpy/controller/inputconvert/inputconvertbase.h similarity index 76% rename from QtScrcpy/inputcontrol/inputconvertbase.h rename to QtScrcpy/controller/inputconvert/inputconvertbase.h index 55fb229..53f8d1a 100644 --- a/QtScrcpy/inputcontrol/inputconvertbase.h +++ b/QtScrcpy/controller/inputconvert/inputconvertbase.h @@ -4,14 +4,16 @@ #include #include #include +#include #include "controlmsg.h" -#include "controller.h" -class InputConvertBase +class Controller; +class InputConvertBase : public QObject { + Q_OBJECT public: - InputConvertBase(); + InputConvertBase(Controller* controller); virtual ~InputConvertBase(); // the frame size may be different from the real device size, so we need the size @@ -20,11 +22,14 @@ public: virtual void wheelEvent(const QWheelEvent* from, const QSize& frameSize, const QSize& showSize) = 0; virtual void keyEvent(const QKeyEvent* from, const QSize& frameSize, const QSize& showSize) = 0; - void setControlSocket(QTcpSocket* controlSocket); +signals: + void grabCursor(bool grab); + +protected: void sendControlMsg(ControlMsg* msg); private: - Controller m_controller; + QPointer m_controller; }; #endif // INPUTCONVERTBASE_H diff --git a/QtScrcpy/inputcontrol/inputconvertgame.cpp b/QtScrcpy/controller/inputconvert/inputconvertgame.cpp similarity index 99% rename from QtScrcpy/inputcontrol/inputconvertgame.cpp rename to QtScrcpy/controller/inputconvert/inputconvertgame.cpp index c243993..e02e126 100644 --- a/QtScrcpy/inputcontrol/inputconvertgame.cpp +++ b/QtScrcpy/controller/inputconvert/inputconvertgame.cpp @@ -6,7 +6,8 @@ #define CURSOR_POS_CHECK 50 -InputConvertGame::InputConvertGame(QObject* parent) : QObject(parent) +InputConvertGame::InputConvertGame(Controller* controller) + : InputConvertNormal(controller) { } diff --git a/QtScrcpy/inputcontrol/inputconvertgame.h b/QtScrcpy/controller/inputconvert/inputconvertgame.h similarity index 94% rename from QtScrcpy/inputcontrol/inputconvertgame.h rename to QtScrcpy/controller/inputconvert/inputconvertgame.h index 8a6ba98..ecf29c9 100644 --- a/QtScrcpy/inputcontrol/inputconvertgame.h +++ b/QtScrcpy/controller/inputconvert/inputconvertgame.h @@ -5,20 +5,17 @@ #include "inputconvertnormal.h" #define MULTI_TOUCH_MAX_NUM 10 -class InputConvertGame : public QObject, public InputConvertNormal +class InputConvertGame : public InputConvertNormal { Q_OBJECT public: - InputConvertGame(QObject* parent = Q_NULLPTR); + InputConvertGame(Controller* controller); virtual ~InputConvertGame(); virtual void mouseEvent(const QMouseEvent* from, const QSize& frameSize, const QSize& showSize); virtual void wheelEvent(const QWheelEvent* from, const QSize& frameSize, const QSize& showSize); virtual void keyEvent(const QKeyEvent* from, const QSize& frameSize, const QSize& showSize); -signals: - void grabCursor(bool grab); - protected: void updateSize(const QSize& frameSize, const QSize& showSize); void sendTouchDownEvent(int id, QPointF pos); diff --git a/QtScrcpy/inputcontrol/inputconvertnormal.cpp b/QtScrcpy/controller/inputconvert/inputconvertnormal.cpp similarity index 98% rename from QtScrcpy/inputcontrol/inputconvertnormal.cpp rename to QtScrcpy/controller/inputconvert/inputconvertnormal.cpp index 5cb46df..906774c 100644 --- a/QtScrcpy/inputcontrol/inputconvertnormal.cpp +++ b/QtScrcpy/controller/inputconvert/inputconvertnormal.cpp @@ -1,6 +1,7 @@ #include "inputconvertnormal.h" -InputConvertNormal::InputConvertNormal() +InputConvertNormal::InputConvertNormal(Controller* controller) + : InputConvertBase(controller) { } diff --git a/QtScrcpy/inputcontrol/inputconvertnormal.h b/QtScrcpy/controller/inputconvert/inputconvertnormal.h similarity index 92% rename from QtScrcpy/inputcontrol/inputconvertnormal.h rename to QtScrcpy/controller/inputconvert/inputconvertnormal.h index fb7da2c..e8ebe2d 100644 --- a/QtScrcpy/inputcontrol/inputconvertnormal.h +++ b/QtScrcpy/controller/inputconvert/inputconvertnormal.h @@ -5,8 +5,9 @@ class InputConvertNormal : public InputConvertBase { + Q_OBJECT public: - InputConvertNormal(); + InputConvertNormal(Controller* controller); virtual ~InputConvertNormal(); virtual void mouseEvent(const QMouseEvent* from, const QSize& frameSize, const QSize& showSize); diff --git a/QtScrcpy/inputcontrol/devicemsg.cpp b/QtScrcpy/controller/receiver/devicemsg.cpp similarity index 100% rename from QtScrcpy/inputcontrol/devicemsg.cpp rename to QtScrcpy/controller/receiver/devicemsg.cpp diff --git a/QtScrcpy/inputcontrol/devicemsg.h b/QtScrcpy/controller/receiver/devicemsg.h similarity index 100% rename from QtScrcpy/inputcontrol/devicemsg.h rename to QtScrcpy/controller/receiver/devicemsg.h diff --git a/QtScrcpy/inputcontrol/receiver.cpp b/QtScrcpy/controller/receiver/receiver.cpp similarity index 58% rename from QtScrcpy/inputcontrol/receiver.cpp rename to QtScrcpy/controller/receiver/receiver.cpp index af5dead..6b496e9 100644 --- a/QtScrcpy/inputcontrol/receiver.cpp +++ b/QtScrcpy/controller/receiver/receiver.cpp @@ -1,37 +1,42 @@ #include #include #include +#include #include "receiver.h" -#include "controller.h" #include "devicemsg.h" -Receiver::Receiver(Controller* controller) : QObject(controller) -{ - m_controller = controller; - Q_ASSERT(controller); +Receiver::Receiver(QObject *parent) : QObject(parent) +{ } Receiver::~Receiver() { +} +void Receiver::setControlSocket(QTcpSocket *controlSocket) +{ + if (m_controlSocket || !controlSocket) { + return; + } + m_controlSocket = controlSocket; + connect(controlSocket, &QTcpSocket::readyRead, this, &Receiver::onReadyRead); } void Receiver::onReadyRead() -{ - QTcpSocket* controlSocket = m_controller->getControlSocket(); - if (!controlSocket) { +{ + if (!m_controlSocket) { return; } - while (controlSocket->bytesAvailable()) { - QByteArray byteArray = controlSocket->peek(controlSocket->bytesAvailable()); + while (m_controlSocket->bytesAvailable()) { + QByteArray byteArray = m_controlSocket->peek(m_controlSocket->bytesAvailable()); DeviceMsg deviceMsg; qint32 consume = deviceMsg.deserialize(byteArray); if (0 >= consume) { break; } - controlSocket->read(consume); + m_controlSocket->read(consume); processMsg(&deviceMsg); } } diff --git a/QtScrcpy/inputcontrol/receiver.h b/QtScrcpy/controller/receiver/receiver.h similarity index 63% rename from QtScrcpy/inputcontrol/receiver.h rename to QtScrcpy/controller/receiver/receiver.h index 917ff25..13266ed 100644 --- a/QtScrcpy/inputcontrol/receiver.h +++ b/QtScrcpy/controller/receiver/receiver.h @@ -3,15 +3,17 @@ #include -class Controller; +class QTcpSocket; class DeviceMsg; class Receiver : public QObject { Q_OBJECT public: - explicit Receiver(Controller *controller); + explicit Receiver(QObject *parent = Q_NULLPTR); virtual ~Receiver(); + void setControlSocket(QTcpSocket *controlSocket); + public slots: void onReadyRead(); @@ -19,7 +21,7 @@ protected: void processMsg(DeviceMsg *deviceMsg); private: - QPointer m_controller; + QPointer m_controlSocket; }; #endif // RECEIVER_H diff --git a/QtScrcpy/controller/receiver/receiver.pri b/QtScrcpy/controller/receiver/receiver.pri new file mode 100644 index 0000000..324cad4 --- /dev/null +++ b/QtScrcpy/controller/receiver/receiver.pri @@ -0,0 +1,7 @@ +HEADERS += \ + $$PWD/devicemsg.h \ + $$PWD/receiver.h + +SOURCES += \ + $$PWD/devicemsg.cpp \ + $$PWD/receiver.cpp diff --git a/QtScrcpy/inputcontrol/inputconvertbase.cpp b/QtScrcpy/inputcontrol/inputconvertbase.cpp deleted file mode 100644 index 59282d4..0000000 --- a/QtScrcpy/inputcontrol/inputconvertbase.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include "inputconvertbase.h" - -InputConvertBase::InputConvertBase() -{ - -} - -InputConvertBase::~InputConvertBase() -{ - -} - -void InputConvertBase::setControlSocket(QTcpSocket *controlSocket) -{ - m_controller.setControlSocket(controlSocket); -} - -void InputConvertBase::sendControlMsg(ControlMsg *msg) -{ - if (msg) { - m_controller.postControlMsg(msg); - } -} - diff --git a/QtScrcpy/videoform.cpp b/QtScrcpy/videoform.cpp index f3f7775..6df50df 100644 --- a/QtScrcpy/videoform.cpp +++ b/QtScrcpy/videoform.cpp @@ -20,7 +20,7 @@ #include "ui_videoform.h" #include "iconhelper.h" #include "toolform.h" -#include "controlmsg.h" +//#include "controlmsg.h" #include "mousetap/mousetap.h" VideoForm::VideoForm(const QString& serial, quint16 maxSize, quint32 bitRate, const QString& fileName, bool closeScreen, QWidget *parent) : @@ -39,6 +39,8 @@ VideoForm::VideoForm(const QString& serial, quint16 maxSize, quint32 bitRate, co m_vb->init(); m_decoder = new Decoder(m_vb); m_stream.setDecoder(m_decoder); + m_controller = new Controller(this); + if (!fileName.trimmed().isEmpty()) { m_recorder = new Recorder(fileName.trimmed()); m_stream.setRecoder(m_recorder); @@ -149,7 +151,8 @@ void VideoForm::initSignals() QMessageBox::information(this, "QtScrcpy", tr("file transfer failed"), QMessageBox::Ok); } }); - connect(&m_inputConvert, &InputConvertGame::grabCursor, this, [this](bool grab){ + + connect(m_controller, &Controller::grabCursor, this, [this](bool grab){ #ifdef Q_OS_WIN32 MouseTap::getInstance()->enableMouseEventTap(ui->videoWidget, grab); @@ -185,7 +188,7 @@ void VideoForm::initSignals() m_stream.startDecode(); // init controller - m_inputConvert.setControlSocket(m_server->getControlSocket()); + m_controller->setControlSocket(m_server->getControlSocket()); if (m_closeScreen) { setScreenPowerMode(ControlMsg::SPM_OFF); @@ -358,7 +361,7 @@ void VideoForm::postTurnOn() if (!controlMsg) { return; } - m_inputConvert.sendControlMsg(controlMsg); + m_controller->postControlMsg(controlMsg); } void VideoForm::expandNotificationPanel() @@ -367,7 +370,7 @@ void VideoForm::expandNotificationPanel() if (!controlMsg) { return; } - m_inputConvert.sendControlMsg(controlMsg); + m_controller->postControlMsg(controlMsg); } void VideoForm::collapseNotificationPanel() @@ -376,7 +379,7 @@ void VideoForm::collapseNotificationPanel() if (!controlMsg) { return; } - m_inputConvert.sendControlMsg(controlMsg); + m_controller->postControlMsg(controlMsg); } void VideoForm::requestDeviceClipboard() @@ -385,7 +388,7 @@ void VideoForm::requestDeviceClipboard() if (!controlMsg) { return; } - m_inputConvert.sendControlMsg(controlMsg); + m_controller->postControlMsg(controlMsg); } void VideoForm::setDeviceClipboard() @@ -397,7 +400,7 @@ void VideoForm::setDeviceClipboard() return; } controlMsg->setSetClipboardMsgData(text); - m_inputConvert.sendControlMsg(controlMsg); + m_controller->postControlMsg(controlMsg); } void VideoForm::clipboardPaste() @@ -414,7 +417,7 @@ void VideoForm::postTextInput(QString& text) return; } controlMsg->setInjectTextMsgData(text); - m_inputConvert.sendControlMsg(controlMsg); + m_controller->postControlMsg(controlMsg); } void VideoForm::setScreenPowerMode(ControlMsg::ScreenPowerMode mode) @@ -424,7 +427,7 @@ void VideoForm::setScreenPowerMode(ControlMsg::ScreenPowerMode mode) return; } controlMsg->setSetScreenPowerModeData(mode); - m_inputConvert.sendControlMsg(controlMsg); + m_controller->postControlMsg(controlMsg); } void VideoForm::staysOnTop(bool top) @@ -454,21 +457,21 @@ void VideoForm::postKeyCodeClick(AndroidKeycode keycode) return; } controlEventDown->setInjectKeycodeMsgData(AKEY_EVENT_ACTION_DOWN, keycode, AMETA_NONE); - m_inputConvert.sendControlMsg(controlEventDown); + m_controller->postControlMsg(controlEventDown); ControlMsg* controlEventUp = new ControlMsg(ControlMsg::CMT_INJECT_KEYCODE); if (!controlEventUp) { return; } controlEventUp->setInjectKeycodeMsgData(AKEY_EVENT_ACTION_UP, keycode, AMETA_NONE); - m_inputConvert.sendControlMsg(controlEventUp); + m_controller->postControlMsg(controlEventUp); } void VideoForm::mousePressEvent(QMouseEvent *event) { if (ui->videoWidget->geometry().contains(event->pos())) { event->setLocalPos(ui->videoWidget->mapFrom(this, event->localPos().toPoint())); - m_inputConvert.mouseEvent(event, ui->videoWidget->frameSize(), ui->videoWidget->size()); + m_controller->mouseEvent(event, ui->videoWidget->frameSize(), ui->videoWidget->size()); } else { if (event->button() == Qt::LeftButton) { m_dragPosition = event->globalPos() - frameGeometry().topLeft(); @@ -481,7 +484,7 @@ void VideoForm::mouseReleaseEvent(QMouseEvent *event) { if (ui->videoWidget->geometry().contains(event->pos())) { event->setLocalPos(ui->videoWidget->mapFrom(this, event->localPos().toPoint())); - m_inputConvert.mouseEvent(event, ui->videoWidget->frameSize(), ui->videoWidget->size()); + m_controller->mouseEvent(event, ui->videoWidget->frameSize(), ui->videoWidget->size()); } } @@ -489,7 +492,7 @@ void VideoForm::mouseMoveEvent(QMouseEvent *event) { if (ui->videoWidget->geometry().contains(event->pos())) { event->setLocalPos(ui->videoWidget->mapFrom(this, event->localPos().toPoint())); - m_inputConvert.mouseEvent(event, ui->videoWidget->frameSize(), ui->videoWidget->size()); + m_controller->mouseEvent(event, ui->videoWidget->frameSize(), ui->videoWidget->size()); } else { if (event->buttons() & Qt::LeftButton) { move(event->globalPos() - m_dragPosition); @@ -509,7 +512,7 @@ void VideoForm::wheelEvent(QWheelEvent *event) */ QWheelEvent wheelEvent(pos, event->globalPosF(), event->delta(), event->buttons(), event->modifiers(), event->orientation()); - m_inputConvert.wheelEvent(&wheelEvent, ui->videoWidget->frameSize(), ui->videoWidget->size()); + m_controller->wheelEvent(&wheelEvent, ui->videoWidget->frameSize(), ui->videoWidget->size()); } } @@ -533,13 +536,13 @@ void VideoForm::keyPressEvent(QKeyEvent *event) } //qDebug() << "keyPressEvent" << event->isAutoRepeat(); - m_inputConvert.keyEvent(event, ui->videoWidget->frameSize(), ui->videoWidget->size()); + m_controller->keyEvent(event, ui->videoWidget->frameSize(), ui->videoWidget->size()); } void VideoForm::keyReleaseEvent(QKeyEvent *event) { //qDebug() << "keyReleaseEvent" << event->isAutoRepeat(); - m_inputConvert.keyEvent(event, ui->videoWidget->frameSize(), ui->videoWidget->size()); + m_controller->keyEvent(event, ui->videoWidget->frameSize(), ui->videoWidget->size()); } void VideoForm::paintEvent(QPaintEvent *paint) diff --git a/QtScrcpy/videoform.h b/QtScrcpy/videoform.h index edb8deb..9f4f992 100644 --- a/QtScrcpy/videoform.h +++ b/QtScrcpy/videoform.h @@ -7,9 +7,8 @@ #include "server.h" #include "stream.h" -#include "inputconvertnormal.h" -#include "inputconvertgame.h" #include "filehandler.h" +#include "controller.h" namespace Ui { class videoForm; @@ -22,7 +21,6 @@ class Decoder; class VideoForm : public QWidget { Q_OBJECT - public: explicit VideoForm(const QString& serial, quint16 maxSize = 720, quint32 bitRate = 8000000, const QString& fileName = "", bool closeScreen = false, QWidget *parent = 0); ~VideoForm(); @@ -72,25 +70,31 @@ protected: void dropEvent(QDropEvent *event); private: - Ui::videoForm *ui; - QSize frameSize; - Server* m_server = Q_NULLPTR; - Stream m_stream; + // ui + Ui::videoForm *ui; + QPointer m_toolForm; + QPointer m_loadingWidget; + + // server relevant + Server* m_server = Q_NULLPTR; VideoBuffer* m_vb = Q_NULLPTR; Decoder* m_decoder = Q_NULLPTR; - //InputConvertNormal m_inputConvert; - InputConvertGame m_inputConvert; + Recorder* m_recorder = Q_NULLPTR; + QPointer m_controller; + Stream m_stream; FileHandler m_fileHandler; + + // server params QString m_serial = ""; quint16 m_maxSize = 720; quint32 m_bitRate = 8000000; + + // assist member + QSize frameSize; QPoint m_dragPosition; float m_widthHeightRatio = 0.5f; - QPointer m_toolForm; - Recorder* m_recorder = Q_NULLPTR; - QTime m_startTimeCount; - QPointer m_loadingWidget; bool m_closeScreen = false; + QTime m_startTimeCount; }; #endif // VIDEOFORM_H diff --git a/TODO.txt b/TODO.txt index ea9fbb6..ddb389f 100644 --- a/TODO.txt +++ b/TODO.txt @@ -12,7 +12,6 @@ b35733edb6df2a00b6af9b1c98627d344c377963 只录制不启动窗口(先重构,目前启动流程在videoform里) 跳过帧改为动态配置,而不是静态编译 https://github.com/Genymobile/scrcpy/commit/ebccb9f6cc111e8acfbe10d656cac5c1f1b744a0 单独线程打印帧率 https://github.com/Genymobile/scrcpy/commit/e2a272bf99ecf48fcb050177113f903b3fb323c4 -重构input 重构videoform 重构整个目录 群控