diff --git a/QtScrcpy/device/controller/controller.cpp b/QtScrcpy/device/controller/controller.cpp index 0ec988e..65fd60a 100644 --- a/QtScrcpy/device/controller/controller.cpp +++ b/QtScrcpy/device/controller/controller.cpp @@ -62,7 +62,7 @@ void Controller::updateScript(QString gameScript) connect(m_inputConvert, &InputConvertBase::grabCursor, this, &Controller::grabCursor); } -void Controller::postTurnOn() +void Controller::onPostTurnOn() { ControlMsg* controlMsg = new ControlMsg(ControlMsg::CMT_BACK_OR_SCREEN_ON); if (!controlMsg) { @@ -71,42 +71,42 @@ void Controller::postTurnOn() postControlMsg(controlMsg); } -void Controller::postGoHome() +void Controller::onPostGoHome() { postKeyCodeClick(AKEYCODE_HOME); } -void Controller::postGoMenu() +void Controller::onPostGoMenu() { postKeyCodeClick(AKEYCODE_MENU); } -void Controller::postGoBack() +void Controller::onPostGoBack() { postKeyCodeClick(AKEYCODE_BACK); } -void Controller::postAppSwitch() +void Controller::onPostAppSwitch() { postKeyCodeClick(AKEYCODE_APP_SWITCH); } -void Controller::postPower() +void Controller::onPostPower() { postKeyCodeClick(AKEYCODE_POWER); } -void Controller::postVolumeUp() +void Controller::onPostVolumeUp() { postKeyCodeClick(AKEYCODE_VOLUME_UP); } -void Controller::postVolumeDown() +void Controller::onPostVolumeDown() { postKeyCodeClick(AKEYCODE_VOLUME_DOWN); } -void Controller::expandNotificationPanel() +void Controller::onExpandNotificationPanel() { ControlMsg* controlMsg = new ControlMsg(ControlMsg::CMT_EXPAND_NOTIFICATION_PANEL); if (!controlMsg) { @@ -115,7 +115,7 @@ void Controller::expandNotificationPanel() postControlMsg(controlMsg); } -void Controller::collapseNotificationPanel() +void Controller::onCollapseNotificationPanel() { ControlMsg* controlMsg = new ControlMsg(ControlMsg::CMT_COLLAPSE_NOTIFICATION_PANEL); if (!controlMsg) { @@ -124,7 +124,7 @@ void Controller::collapseNotificationPanel() postControlMsg(controlMsg); } -void Controller::requestDeviceClipboard() +void Controller::onRequestDeviceClipboard() { ControlMsg* controlMsg = new ControlMsg(ControlMsg::CMT_GET_CLIPBOARD); if (!controlMsg) { @@ -133,7 +133,7 @@ void Controller::requestDeviceClipboard() postControlMsg(controlMsg); } -void Controller::setDeviceClipboard() +void Controller::onSetDeviceClipboard() { QClipboard *board = QApplication::clipboard(); QString text = board->text(); @@ -145,14 +145,14 @@ void Controller::setDeviceClipboard() postControlMsg(controlMsg); } -void Controller::clipboardPaste() +void Controller::onClipboardPaste() { QClipboard *board = QApplication::clipboard(); QString text = board->text(); - postTextInput(text); + onPostTextInput(text); } -void Controller::postTextInput(QString& text) +void Controller::onPostTextInput(QString& text) { ControlMsg* controlMsg = new ControlMsg(ControlMsg::CMT_INJECT_TEXT); if (!controlMsg) { @@ -162,7 +162,7 @@ void Controller::postTextInput(QString& text) postControlMsg(controlMsg); } -void Controller::setScreenPowerMode(ControlMsg::ScreenPowerMode mode) +void Controller::onSetScreenPowerMode(ControlMsg::ScreenPowerMode mode) { ControlMsg* controlMsg = new ControlMsg(ControlMsg::CMT_SET_SCREEN_POWER_MODE); if (!controlMsg) { @@ -172,21 +172,21 @@ void Controller::setScreenPowerMode(ControlMsg::ScreenPowerMode mode) postControlMsg(controlMsg); } -void Controller::mouseEvent(const QMouseEvent *from, const QSize &frameSize, const QSize &showSize) +void Controller::onMouseEvent(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) +void Controller::onWheelEvent(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) +void Controller::onKeyEvent(const QKeyEvent *from, const QSize &frameSize, const QSize &showSize) { if (m_inputConvert) { m_inputConvert->keyEvent(from, frameSize, showSize); diff --git a/QtScrcpy/device/controller/controller.h b/QtScrcpy/device/controller/controller.h index d6b1730..9bf14d0 100644 --- a/QtScrcpy/device/controller/controller.h +++ b/QtScrcpy/device/controller/controller.h @@ -22,27 +22,29 @@ public: void updateScript(QString gameScript = ""); - // turn the screen on if it was off, press BACK otherwise - void postTurnOn(); - void postGoHome(); - void postGoMenu(); - void postGoBack(); - void postAppSwitch(); - void postPower(); - void postVolumeUp(); - void postVolumeDown(); - void expandNotificationPanel(); - void collapseNotificationPanel(); - void requestDeviceClipboard(); - void setDeviceClipboard(); - void clipboardPaste(); - void postTextInput(QString& text); - void setScreenPowerMode(ControlMsg::ScreenPowerMode mode); +public slots: + void onPostGoBack(); + void onPostGoHome(); + void onPostGoMenu(); + void onPostAppSwitch(); + void onPostPower(); + void onPostVolumeUp(); + void onPostVolumeDown(); + void onExpandNotificationPanel(); + void onCollapseNotificationPanel(); + void onSetScreenPowerMode(ControlMsg::ScreenPowerMode mode); // 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); + void onMouseEvent(const QMouseEvent* from, const QSize& frameSize, const QSize& showSize); + void onWheelEvent(const QWheelEvent* from, const QSize& frameSize, const QSize& showSize); + void onKeyEvent(const QKeyEvent* from, const QSize& frameSize, const QSize& showSize); + + // turn the screen on if it was off, press BACK otherwise + void onPostTurnOn(); + void onRequestDeviceClipboard(); + void onSetDeviceClipboard(); + void onClipboardPaste(); + void onPostTextInput(QString& text); signals: void grabCursor(bool grab); diff --git a/QtScrcpy/device/device.cpp b/QtScrcpy/device/device.cpp index 53304f5..bde630e 100644 --- a/QtScrcpy/device/device.cpp +++ b/QtScrcpy/device/device.cpp @@ -80,16 +80,6 @@ VideoForm *Device::getVideoForm() return m_videoForm; } -Controller *Device::getController() -{ - return m_controller; -} - -FileHandler *Device::getFileHandler() -{ - return m_fileHandler; -} - Server *Device::getServer() { return m_server; @@ -119,35 +109,84 @@ void Device::onScreenshot() m_vb->unLock(); } +void Device::onShowTouch(bool show) +{ + AdbProcess* adb = new AdbProcess(); + if (!adb) { + return; + } + connect(adb, &AdbProcess::adbProcessResult, this, [this](AdbProcess::ADB_EXEC_RESULT processResult){ + if (AdbProcess::AER_SUCCESS_START != processResult) { + sender()->deleteLater(); + } + }); + adb->setShowTouchesEnabled(getSerial(), show); + + qInfo() << getSerial() << " show touch " << (show ? "enable" : "disable"); +} + void Device::initSignals() { + connect(this, &Device::screenshot, this, &Device::onScreenshot); + connect(this, &Device::showTouch, this, &Device::onShowTouch); + connect(this, &Device::setMainControl, this, &Device::onSetMainControl); + if (m_controller && m_videoForm) { connect(m_controller, &Controller::grabCursor, m_videoForm, &VideoForm::onGrabCursor); - connect(m_videoForm, &VideoForm::screenshot, this, &Device::onScreenshot); + } + if (m_controller) { + connect(this, &Device::postGoBack, m_controller, &Controller::onPostGoBack); + connect(this, &Device::postGoHome, m_controller, &Controller::onPostGoHome); + connect(this, &Device::postGoMenu, m_controller, &Controller::onPostGoMenu); + connect(this, &Device::postAppSwitch, m_controller, &Controller::onPostAppSwitch); + connect(this, &Device::postPower, m_controller, &Controller::onPostPower); + connect(this, &Device::postVolumeUp, m_controller, &Controller::onPostVolumeUp); + connect(this, &Device::postVolumeDown, m_controller, &Controller::onPostVolumeDown); + connect(this, &Device::setScreenPowerMode, m_controller, &Controller::onSetScreenPowerMode); + connect(this, &Device::expandNotificationPanel, m_controller, &Controller::onExpandNotificationPanel); + connect(this, &Device::mouseEvent, m_controller, &Controller::onMouseEvent); + connect(this, &Device::wheelEvent, m_controller, &Controller::onWheelEvent); + connect(this, &Device::keyEvent, m_controller, &Controller::onKeyEvent); + + connect(this, &Device::postTurnOn, m_controller, &Controller::onPostTurnOn); + connect(this, &Device::requestDeviceClipboard, m_controller, &Controller::onRequestDeviceClipboard); + connect(this, &Device::setDeviceClipboard, m_controller, &Controller::onSetDeviceClipboard); + connect(this, &Device::clipboardPaste, m_controller, &Controller::onClipboardPaste); + connect(this, &Device::postTextInput, m_controller, &Controller::onPostTextInput); } if (m_videoForm) { connect(m_videoForm, &VideoForm::destroyed, this, [this](QObject *obj){ Q_UNUSED(obj) deleteLater(); }); + + connect(this, &Device::switchFullScreen, m_videoForm, &VideoForm::onSwitchFullScreen); } if (m_fileHandler) { + connect(this, &Device::pushFileRequest, m_fileHandler, &FileHandler::onPushFileRequest); + connect(this, &Device::installApkRequest, m_fileHandler, &FileHandler::onInstallApkRequest); connect(m_fileHandler, &FileHandler::fileHandlerResult, this, [this](FileHandler::FILE_HANDLER_RESULT processResult, bool isApk){ - QString tips = ""; + QString tipsType = ""; if (isApk) { - tips = tr("install apk"); + tipsType = tr("install apk"); } else { - tips = tr("file transfer"); + tipsType = tr("file transfer"); } + QString tips; if (FileHandler::FAR_IS_RUNNING == processResult && m_videoForm) { - QMessageBox::warning(m_videoForm, "QtScrcpy", tr("wait current %1 to complete").arg(tips), QMessageBox::Ok); + tips = tr("wait current %1 to complete").arg(tipsType); } if (FileHandler::FAR_SUCCESS_EXEC == processResult && m_videoForm) { - QMessageBox::information(m_videoForm, "QtScrcpy", tr("%1 complete, save in %2").arg(tips).arg(Config::getInstance().getPushFilePath()), QMessageBox::Ok); + tips = tr("%1 complete, save in %2").arg(tipsType).arg(Config::getInstance().getPushFilePath()); } if (FileHandler::FAR_ERROR_EXEC == processResult && m_videoForm) { - QMessageBox::information(m_videoForm, "QtScrcpy", tr("%1 failed").arg(tips), QMessageBox::Ok); + tips = tr("%1 failed").arg(tipsType); } + qInfo() << tips; + if (!m_mainControl) { + return; + } + QMessageBox::information(m_videoForm, "QtScrcpy", tips, QMessageBox::Ok); }); } @@ -186,7 +225,7 @@ void Device::initSignals() // 显示界面时才自动息屏(m_params.display) if (m_params.closeScreen && m_params.display && m_controller) { - m_controller->setScreenPowerMode(ControlMsg::SPM_OFF); + emit m_controller->onSetScreenPowerMode(ControlMsg::SPM_OFF); } } }); @@ -239,13 +278,13 @@ void Device::startServer() }); } -void Device::setMainControl(bool mainControl) +void Device::onSetMainControl(Device* device, bool mainControl) { + Q_UNUSED(device) if (m_mainControl == mainControl) { return; } m_mainControl = mainControl; - emit mainControlChange(this, m_mainControl); } bool Device::mainControl() diff --git a/QtScrcpy/device/device.h b/QtScrcpy/device/device.h index e45aa50..c5363b8 100644 --- a/QtScrcpy/device/device.h +++ b/QtScrcpy/device/device.h @@ -4,6 +4,11 @@ #include #include +#include "controlmsg.h" + +class QMouseEvent; +class QWheelEvent; +class QKeyEvent; class Recorder; class Server; class VideoBuffer; @@ -34,21 +39,46 @@ public: virtual ~Device(); VideoForm *getVideoForm(); - Controller *getController(); - FileHandler *getFileHandler(); Server *getServer(); const QString &getSerial(); void updateScript(QString script); - void setMainControl(bool mainControl); bool mainControl(); signals: void deviceDisconnect(QString serial); - void mainControlChange(Device* device, bool mainControl); + + void switchFullScreen(); + void postGoBack(); + void postGoHome(); + void postGoMenu(); + void postAppSwitch(); + void postPower(); + void postVolumeUp(); + void postVolumeDown(); + void setScreenPowerMode(ControlMsg::ScreenPowerMode mode); + void expandNotificationPanel(); + void screenshot(); + void showTouch(bool show); + void setMainControl(Device* device, bool mainControl); + + 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); + + void postTurnOn(); + void postTextInput(QString& text); + void requestDeviceClipboard(); + void setDeviceClipboard(); + void clipboardPaste(); + + void pushFileRequest(const QString& serial, const QString& file, const QString& devicePath = ""); + void installApkRequest(const QString& serial, const QString& apkFile); public slots: void onScreenshot(); + void onShowTouch(bool show); + void onSetMainControl(Device* device, bool mainControl); private: void initSignals(); diff --git a/QtScrcpy/device/filehandler/filehandler.cpp b/QtScrcpy/device/filehandler/filehandler.cpp index c92425d..4730f6c 100644 --- a/QtScrcpy/device/filehandler/filehandler.cpp +++ b/QtScrcpy/device/filehandler/filehandler.cpp @@ -24,7 +24,7 @@ FileHandler::~FileHandler() } -void FileHandler::pushFileRequest(const QString &serial, const QString &file, const QString& devicePath) +void FileHandler::onPushFileRequest(const QString &serial, const QString &file, const QString& devicePath) { if (m_adb.isRuning()) { emit fileHandlerResult(FAR_IS_RUNNING, false); @@ -35,7 +35,7 @@ void FileHandler::pushFileRequest(const QString &serial, const QString &file, co m_adb.push(serial, file, devicePath); } -void FileHandler::installApkRequest(const QString &serial, const QString &apkFile) +void FileHandler::onInstallApkRequest(const QString &serial, const QString &apkFile) { if (m_adb.isRuning()) { emit fileHandlerResult(FAR_IS_RUNNING, true); diff --git a/QtScrcpy/device/filehandler/filehandler.h b/QtScrcpy/device/filehandler/filehandler.h index 3a2023c..8c48db1 100644 --- a/QtScrcpy/device/filehandler/filehandler.h +++ b/QtScrcpy/device/filehandler/filehandler.h @@ -17,10 +17,12 @@ public: FileHandler(QObject *parent = nullptr); virtual ~FileHandler(); - void pushFileRequest(const QString& serial, const QString& file, const QString& devicePath = ""); - void installApkRequest(const QString& serial, const QString& apkFile); const QString &getDevicePath(); +public slots: + void onPushFileRequest(const QString& serial, const QString& file, const QString& devicePath = ""); + void onInstallApkRequest(const QString& serial, const QString& apkFile); + signals: void fileHandlerResult(FILE_HANDLER_RESULT processResult, bool isApk = false); diff --git a/QtScrcpy/device/ui/toolform.cpp b/QtScrcpy/device/ui/toolform.cpp index 9cceb5a..6fe898a 100644 --- a/QtScrcpy/device/ui/toolform.cpp +++ b/QtScrcpy/device/ui/toolform.cpp @@ -97,87 +97,91 @@ void ToolForm::hideEvent(QHideEvent *event) void ToolForm::on_fullScreenBtn_clicked() { - if (!m_device || !m_device->getVideoForm()) { + if (!m_device) { return; } - m_device->getVideoForm()->switchFullScreen(); + + emit m_device->switchFullScreen(); } void ToolForm::on_returnBtn_clicked() { - if (!m_device || !m_device->getController()) { + if (!m_device) { return; } - m_device->getController()->postGoBack(); + emit m_device->postGoBack(); } void ToolForm::on_homeBtn_clicked() { - if (!m_device || !m_device->getController()) { + if (!m_device) { return; } - m_device->getController()->postGoHome(); + emit m_device->postGoHome(); } void ToolForm::on_menuBtn_clicked() { - if (!m_device || !m_device->getController()) { + if (!m_device) { return; } - m_device->getController()->postGoMenu(); + emit m_device->postGoMenu(); } void ToolForm::on_appSwitchBtn_clicked() { - if (!m_device || !m_device->getController()) { + if (!m_device) { return; } - m_device->getController()->postAppSwitch(); + emit m_device->postAppSwitch(); } void ToolForm::on_powerBtn_clicked() { - if (!m_device || !m_device->getController()) { + if (!m_device) { return; } - m_device->getController()->postPower(); + emit m_device->postPower(); } void ToolForm::on_screenShotBtn_clicked() { - emit screenshot(); + if (!m_device) { + return; + } + emit m_device->screenshot(); } void ToolForm::on_volumeUpBtn_clicked() { - if (!m_device || !m_device->getController()) { + if (!m_device) { return; } - m_device->getController()->postVolumeUp(); + emit m_device->postVolumeUp(); } void ToolForm::on_volumeDownBtn_clicked() { - if (!m_device || !m_device->getController()) { + if (!m_device) { return; } - m_device->getController()->postVolumeDown(); + emit m_device->postVolumeDown(); } void ToolForm::on_closeScreenBtn_clicked() { - if (!m_device || !m_device->getController()) { + if (!m_device) { return; } - m_device->getController()->setScreenPowerMode(ControlMsg::SPM_OFF); + emit m_device->setScreenPowerMode(ControlMsg::SPM_OFF); } void ToolForm::on_expandNotifyBtn_clicked() { - if (!m_device || !m_device->getController()) { + if (!m_device) { return; } - m_device->getController()->expandNotificationPanel(); + emit m_device->expandNotificationPanel(); } void ToolForm::on_touchBtn_clicked() @@ -187,19 +191,7 @@ void ToolForm::on_touchBtn_clicked() } m_showTouch = !m_showTouch; - - AdbProcess* adb = new AdbProcess(); - if (!adb) { - return; - } - connect(adb, &AdbProcess::adbProcessResult, this, [this](AdbProcess::ADB_EXEC_RESULT processResult){ - if (AdbProcess::AER_SUCCESS_START != processResult) { - sender()->deleteLater(); - } - }); - adb->setShowTouchesEnabled(m_device->getSerial(), m_showTouch); - - qInfo() << "show touch " << (m_showTouch ? "enable" : "disable"); + emit m_device->showTouch(m_showTouch); } void ToolForm::on_groupControlBtn_clicked() @@ -207,6 +199,6 @@ void ToolForm::on_groupControlBtn_clicked() if (!m_device) { return; } - m_device->setMainControl(!m_device->mainControl()); + emit m_device->setMainControl(m_device, !m_device->mainControl()); updateGroupControl(); } diff --git a/QtScrcpy/device/ui/toolform.h b/QtScrcpy/device/ui/toolform.h index 678a984..28f38c5 100644 --- a/QtScrcpy/device/ui/toolform.h +++ b/QtScrcpy/device/ui/toolform.h @@ -29,34 +29,19 @@ protected: void showEvent(QShowEvent *event); void hideEvent(QHideEvent *event); -signals: - void screenshot(); - private slots: void on_fullScreenBtn_clicked(); - void on_returnBtn_clicked(); - void on_homeBtn_clicked(); - void on_menuBtn_clicked(); - void on_appSwitchBtn_clicked(); - void on_powerBtn_clicked(); - void on_screenShotBtn_clicked(); - void on_volumeUpBtn_clicked(); - void on_volumeDownBtn_clicked(); - void on_closeScreenBtn_clicked(); - void on_expandNotifyBtn_clicked(); - void on_touchBtn_clicked(); - void on_groupControlBtn_clicked(); private: diff --git a/QtScrcpy/device/ui/videoform.cpp b/QtScrcpy/device/ui/videoform.cpp index 63b2f4e..5972608 100644 --- a/QtScrcpy/device/ui/videoform.cpp +++ b/QtScrcpy/device/ui/videoform.cpp @@ -100,7 +100,6 @@ void VideoForm::showToolForm(bool show) if (!m_toolForm) { m_toolForm = new ToolForm(this, ToolForm::AP_OUTSIDE_RIGHT); m_toolForm->setDevice(m_device); - connect(m_toolForm, &ToolForm::screenshot, this, &VideoForm::screenshot); } m_toolForm->move(pos().x() + geometry().width(), pos().y() + 30); m_toolForm->setVisible(show); @@ -174,7 +173,7 @@ void VideoForm::updateShowSize(const QSize &newSize) } if (isFullScreen()) { - switchFullScreen(); + onSwitchFullScreen(); } if (m_skin) { QMargins m = getMargins(vertical); @@ -192,7 +191,7 @@ void VideoForm::updateShowSize(const QSize &newSize) } } -void VideoForm::switchFullScreen() +void VideoForm::onSwitchFullScreen() { if (isFullScreen()) { // 横屏全屏铺满全屏,恢复时,恢复保持宽高比 @@ -263,11 +262,11 @@ void VideoForm::setDevice(Device *device) void VideoForm::mousePressEvent(QMouseEvent *event) { if (m_videoWidget->geometry().contains(event->pos())) { - if (!m_device || !m_device->getController()) { + if (!m_device) { return; } event->setLocalPos(m_videoWidget->mapFrom(this, event->localPos().toPoint())); - m_device->getController()->mouseEvent(event, m_videoWidget->frameSize(), m_videoWidget->size()); + emit m_device->mouseEvent(event, m_videoWidget->frameSize(), m_videoWidget->size()); } else { if (event->button() == Qt::LeftButton) { m_dragPosition = event->globalPos() - frameGeometry().topLeft(); @@ -279,7 +278,7 @@ void VideoForm::mousePressEvent(QMouseEvent *event) void VideoForm::mouseReleaseEvent(QMouseEvent *event) { if (m_dragPosition.isNull()) { - if (!m_device || !m_device->getController()) { + if (!m_device) { return; } event->setLocalPos(m_videoWidget->mapFrom(this, event->localPos().toPoint())); @@ -298,7 +297,7 @@ void VideoForm::mouseReleaseEvent(QMouseEvent *event) local.setY(m_videoWidget->height()); } event->setLocalPos(local); - m_device->getController()->mouseEvent(event, m_videoWidget->frameSize(), m_videoWidget->size()); + emit m_device->mouseEvent(event, m_videoWidget->frameSize(), m_videoWidget->size()); } else { m_dragPosition = QPoint(0, 0); } @@ -307,11 +306,11 @@ void VideoForm::mouseReleaseEvent(QMouseEvent *event) void VideoForm::mouseMoveEvent(QMouseEvent *event) { if (m_videoWidget->geometry().contains(event->pos())) { - if (!m_device || !m_device->getController()) { + if (!m_device) { return; } event->setLocalPos(m_videoWidget->mapFrom(this, event->localPos().toPoint())); - m_device->getController()->mouseEvent(event, m_videoWidget->frameSize(), m_videoWidget->size()); + emit m_device->mouseEvent(event, m_videoWidget->frameSize(), m_videoWidget->size()); } else if (!m_dragPosition.isNull()){ if (event->buttons() & Qt::LeftButton) { move(event->globalPos() - m_dragPosition); @@ -323,7 +322,7 @@ void VideoForm::mouseMoveEvent(QMouseEvent *event) void VideoForm::wheelEvent(QWheelEvent *event) { if (m_videoWidget->geometry().contains(event->pos())) { - if (!m_device || !m_device->getController()) { + if (!m_device) { return; } QPointF pos = m_videoWidget->mapFrom(this, event->pos()); @@ -334,7 +333,7 @@ void VideoForm::wheelEvent(QWheelEvent *event) */ QWheelEvent wheelEvent(pos, event->globalPosF(), event->delta(), event->buttons(), event->modifiers(), event->orientation()); - m_device->getController()->wheelEvent(&wheelEvent, m_videoWidget->frameSize(), m_videoWidget->size()); + emit m_device->wheelEvent(&wheelEvent, m_videoWidget->frameSize(), m_videoWidget->size()); } } @@ -343,32 +342,32 @@ void VideoForm::keyPressEvent(QKeyEvent *event) if (Qt::Key_Escape == event->key() && !event->isAutoRepeat() && isFullScreen()) { - switchFullScreen(); + onSwitchFullScreen(); } - if (!m_device || !m_device->getController()) { + if (!m_device) { return; } if (event->key() == Qt::Key_C && (event->modifiers() & Qt::ControlModifier)) { - m_device->getController()->requestDeviceClipboard(); + emit m_device->requestDeviceClipboard(); } if (event->key() == Qt::Key_V && (event->modifiers() & Qt::ControlModifier)) { if (event->modifiers() & Qt::ShiftModifier) { - m_device->getController()->setDeviceClipboard(); + emit m_device->setDeviceClipboard(); } else { - m_device->getController()->clipboardPaste(); + emit m_device->clipboardPaste(); } return; } - m_device->getController()->keyEvent(event, m_videoWidget->frameSize(), m_videoWidget->size()); + emit m_device->keyEvent(event, m_videoWidget->frameSize(), m_videoWidget->size()); } void VideoForm::keyReleaseEvent(QKeyEvent *event) { - if (!m_device || !m_device->getController()) { + if (!m_device) { return; } - m_device->getController()->keyEvent(event, m_videoWidget->frameSize(), m_videoWidget->size()); + emit m_device->keyEvent(event, m_videoWidget->frameSize(), m_videoWidget->size()); } void VideoForm::paintEvent(QPaintEvent *paint) @@ -431,7 +430,7 @@ void VideoForm::dragLeaveEvent(QDragLeaveEvent *event) void VideoForm::dropEvent(QDropEvent *event) { - if (!m_device || !m_device->getFileHandler()) { + if (!m_device) { return; } const QMimeData* qm = event->mimeData(); @@ -444,8 +443,8 @@ void VideoForm::dropEvent(QDropEvent *event) } if (fileInfo.isFile() && fileInfo.suffix() == "apk") { - m_device->getFileHandler()->installApkRequest(m_device->getSerial(), file); + emit m_device->installApkRequest(m_device->getSerial(), file); return; } - m_device->getFileHandler()->pushFileRequest(m_device->getSerial(), file, Config::getInstance().getPushFilePath() + fileInfo.fileName()); + emit m_device->pushFileRequest(m_device->getSerial(), file, Config::getInstance().getPushFilePath() + fileInfo.fileName()); } diff --git a/QtScrcpy/device/ui/videoform.h b/QtScrcpy/device/ui/videoform.h index 26e5631..7df3248 100644 --- a/QtScrcpy/device/ui/videoform.h +++ b/QtScrcpy/device/ui/videoform.h @@ -20,17 +20,14 @@ public: explicit VideoForm(bool skin = true, QWidget *parent = 0); ~VideoForm(); - void switchFullScreen(); void staysOnTop(bool top = true); void updateShowSize(const QSize &newSize); void updateRender(const AVFrame *frame); void setDevice(Device *device); -signals: - void screenshot(); - public slots: void onGrabCursor(bool grab); + void onSwitchFullScreen(); private: void updateStyleSheet(bool vertical);