refactor: for group control

This commit is contained in:
rankun 2020-03-06 22:12:37 +08:00
commit 09331711c8
10 changed files with 188 additions and 142 deletions

View file

@ -62,7 +62,7 @@ void Controller::updateScript(QString gameScript)
connect(m_inputConvert, &InputConvertBase::grabCursor, this, &Controller::grabCursor); connect(m_inputConvert, &InputConvertBase::grabCursor, this, &Controller::grabCursor);
} }
void Controller::postTurnOn() void Controller::onPostTurnOn()
{ {
ControlMsg* controlMsg = new ControlMsg(ControlMsg::CMT_BACK_OR_SCREEN_ON); ControlMsg* controlMsg = new ControlMsg(ControlMsg::CMT_BACK_OR_SCREEN_ON);
if (!controlMsg) { if (!controlMsg) {
@ -71,42 +71,42 @@ void Controller::postTurnOn()
postControlMsg(controlMsg); postControlMsg(controlMsg);
} }
void Controller::postGoHome() void Controller::onPostGoHome()
{ {
postKeyCodeClick(AKEYCODE_HOME); postKeyCodeClick(AKEYCODE_HOME);
} }
void Controller::postGoMenu() void Controller::onPostGoMenu()
{ {
postKeyCodeClick(AKEYCODE_MENU); postKeyCodeClick(AKEYCODE_MENU);
} }
void Controller::postGoBack() void Controller::onPostGoBack()
{ {
postKeyCodeClick(AKEYCODE_BACK); postKeyCodeClick(AKEYCODE_BACK);
} }
void Controller::postAppSwitch() void Controller::onPostAppSwitch()
{ {
postKeyCodeClick(AKEYCODE_APP_SWITCH); postKeyCodeClick(AKEYCODE_APP_SWITCH);
} }
void Controller::postPower() void Controller::onPostPower()
{ {
postKeyCodeClick(AKEYCODE_POWER); postKeyCodeClick(AKEYCODE_POWER);
} }
void Controller::postVolumeUp() void Controller::onPostVolumeUp()
{ {
postKeyCodeClick(AKEYCODE_VOLUME_UP); postKeyCodeClick(AKEYCODE_VOLUME_UP);
} }
void Controller::postVolumeDown() void Controller::onPostVolumeDown()
{ {
postKeyCodeClick(AKEYCODE_VOLUME_DOWN); postKeyCodeClick(AKEYCODE_VOLUME_DOWN);
} }
void Controller::expandNotificationPanel() void Controller::onExpandNotificationPanel()
{ {
ControlMsg* controlMsg = new ControlMsg(ControlMsg::CMT_EXPAND_NOTIFICATION_PANEL); ControlMsg* controlMsg = new ControlMsg(ControlMsg::CMT_EXPAND_NOTIFICATION_PANEL);
if (!controlMsg) { if (!controlMsg) {
@ -115,7 +115,7 @@ void Controller::expandNotificationPanel()
postControlMsg(controlMsg); postControlMsg(controlMsg);
} }
void Controller::collapseNotificationPanel() void Controller::onCollapseNotificationPanel()
{ {
ControlMsg* controlMsg = new ControlMsg(ControlMsg::CMT_COLLAPSE_NOTIFICATION_PANEL); ControlMsg* controlMsg = new ControlMsg(ControlMsg::CMT_COLLAPSE_NOTIFICATION_PANEL);
if (!controlMsg) { if (!controlMsg) {
@ -124,7 +124,7 @@ void Controller::collapseNotificationPanel()
postControlMsg(controlMsg); postControlMsg(controlMsg);
} }
void Controller::requestDeviceClipboard() void Controller::onRequestDeviceClipboard()
{ {
ControlMsg* controlMsg = new ControlMsg(ControlMsg::CMT_GET_CLIPBOARD); ControlMsg* controlMsg = new ControlMsg(ControlMsg::CMT_GET_CLIPBOARD);
if (!controlMsg) { if (!controlMsg) {
@ -133,7 +133,7 @@ void Controller::requestDeviceClipboard()
postControlMsg(controlMsg); postControlMsg(controlMsg);
} }
void Controller::setDeviceClipboard() void Controller::onSetDeviceClipboard()
{ {
QClipboard *board = QApplication::clipboard(); QClipboard *board = QApplication::clipboard();
QString text = board->text(); QString text = board->text();
@ -145,14 +145,14 @@ void Controller::setDeviceClipboard()
postControlMsg(controlMsg); postControlMsg(controlMsg);
} }
void Controller::clipboardPaste() void Controller::onClipboardPaste()
{ {
QClipboard *board = QApplication::clipboard(); QClipboard *board = QApplication::clipboard();
QString text = board->text(); 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); ControlMsg* controlMsg = new ControlMsg(ControlMsg::CMT_INJECT_TEXT);
if (!controlMsg) { if (!controlMsg) {
@ -162,7 +162,7 @@ void Controller::postTextInput(QString& text)
postControlMsg(controlMsg); postControlMsg(controlMsg);
} }
void Controller::setScreenPowerMode(ControlMsg::ScreenPowerMode mode) void Controller::onSetScreenPowerMode(ControlMsg::ScreenPowerMode mode)
{ {
ControlMsg* controlMsg = new ControlMsg(ControlMsg::CMT_SET_SCREEN_POWER_MODE); ControlMsg* controlMsg = new ControlMsg(ControlMsg::CMT_SET_SCREEN_POWER_MODE);
if (!controlMsg) { if (!controlMsg) {
@ -172,21 +172,21 @@ void Controller::setScreenPowerMode(ControlMsg::ScreenPowerMode mode)
postControlMsg(controlMsg); 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) { if (m_inputConvert) {
m_inputConvert->mouseEvent(from, frameSize, showSize); 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) { if (m_inputConvert) {
m_inputConvert->wheelEvent(from, frameSize, showSize); 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) { if (m_inputConvert) {
m_inputConvert->keyEvent(from, frameSize, showSize); m_inputConvert->keyEvent(from, frameSize, showSize);

View file

@ -22,27 +22,29 @@ public:
void updateScript(QString gameScript = ""); void updateScript(QString gameScript = "");
// turn the screen on if it was off, press BACK otherwise public slots:
void postTurnOn(); void onPostGoBack();
void postGoHome(); void onPostGoHome();
void postGoMenu(); void onPostGoMenu();
void postGoBack(); void onPostAppSwitch();
void postAppSwitch(); void onPostPower();
void postPower(); void onPostVolumeUp();
void postVolumeUp(); void onPostVolumeDown();
void postVolumeDown(); void onExpandNotificationPanel();
void expandNotificationPanel(); void onCollapseNotificationPanel();
void collapseNotificationPanel(); void onSetScreenPowerMode(ControlMsg::ScreenPowerMode mode);
void requestDeviceClipboard();
void setDeviceClipboard();
void clipboardPaste();
void postTextInput(QString& text);
void setScreenPowerMode(ControlMsg::ScreenPowerMode mode);
// for input convert // for input convert
void mouseEvent(const QMouseEvent* from, const QSize& frameSize, const QSize& showSize); void onMouseEvent(const QMouseEvent* from, const QSize& frameSize, const QSize& showSize);
void wheelEvent(const QWheelEvent* from, const QSize& frameSize, const QSize& showSize); void onWheelEvent(const QWheelEvent* from, const QSize& frameSize, const QSize& showSize);
void keyEvent(const QKeyEvent* 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: signals:
void grabCursor(bool grab); void grabCursor(bool grab);

View file

@ -80,16 +80,6 @@ VideoForm *Device::getVideoForm()
return m_videoForm; return m_videoForm;
} }
Controller *Device::getController()
{
return m_controller;
}
FileHandler *Device::getFileHandler()
{
return m_fileHandler;
}
Server *Device::getServer() Server *Device::getServer()
{ {
return m_server; return m_server;
@ -119,35 +109,84 @@ void Device::onScreenshot()
m_vb->unLock(); 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() 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) { if (m_controller && m_videoForm) {
connect(m_controller, &Controller::grabCursor, m_videoForm, &VideoForm::onGrabCursor); 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) { if (m_videoForm) {
connect(m_videoForm, &VideoForm::destroyed, this, [this](QObject *obj){ connect(m_videoForm, &VideoForm::destroyed, this, [this](QObject *obj){
Q_UNUSED(obj) Q_UNUSED(obj)
deleteLater(); deleteLater();
}); });
connect(this, &Device::switchFullScreen, m_videoForm, &VideoForm::onSwitchFullScreen);
} }
if (m_fileHandler) { 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){ connect(m_fileHandler, &FileHandler::fileHandlerResult, this, [this](FileHandler::FILE_HANDLER_RESULT processResult, bool isApk){
QString tips = ""; QString tipsType = "";
if (isApk) { if (isApk) {
tips = tr("install apk"); tipsType = tr("install apk");
} else { } else {
tips = tr("file transfer"); tipsType = tr("file transfer");
} }
QString tips;
if (FileHandler::FAR_IS_RUNNING == processResult && m_videoForm) { 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) { 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) { 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 // 显示界面时才自动息屏m_params.display
if (m_params.closeScreen && m_params.display && m_controller) { 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) { if (m_mainControl == mainControl) {
return; return;
} }
m_mainControl = mainControl; m_mainControl = mainControl;
emit mainControlChange(this, m_mainControl);
} }
bool Device::mainControl() bool Device::mainControl()

View file

@ -4,6 +4,11 @@
#include <QPointer> #include <QPointer>
#include <QTime> #include <QTime>
#include "controlmsg.h"
class QMouseEvent;
class QWheelEvent;
class QKeyEvent;
class Recorder; class Recorder;
class Server; class Server;
class VideoBuffer; class VideoBuffer;
@ -34,21 +39,46 @@ public:
virtual ~Device(); virtual ~Device();
VideoForm *getVideoForm(); VideoForm *getVideoForm();
Controller *getController();
FileHandler *getFileHandler();
Server *getServer(); Server *getServer();
const QString &getSerial(); const QString &getSerial();
void updateScript(QString script); void updateScript(QString script);
void setMainControl(bool mainControl);
bool mainControl(); bool mainControl();
signals: signals:
void deviceDisconnect(QString serial); 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: public slots:
void onScreenshot(); void onScreenshot();
void onShowTouch(bool show);
void onSetMainControl(Device* device, bool mainControl);
private: private:
void initSignals(); void initSignals();

View file

@ -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()) { if (m_adb.isRuning()) {
emit fileHandlerResult(FAR_IS_RUNNING, false); 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); 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()) { if (m_adb.isRuning()) {
emit fileHandlerResult(FAR_IS_RUNNING, true); emit fileHandlerResult(FAR_IS_RUNNING, true);

View file

@ -17,10 +17,12 @@ public:
FileHandler(QObject *parent = nullptr); FileHandler(QObject *parent = nullptr);
virtual ~FileHandler(); virtual ~FileHandler();
void pushFileRequest(const QString& serial, const QString& file, const QString& devicePath = "");
void installApkRequest(const QString& serial, const QString& apkFile);
const QString &getDevicePath(); 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: signals:
void fileHandlerResult(FILE_HANDLER_RESULT processResult, bool isApk = false); void fileHandlerResult(FILE_HANDLER_RESULT processResult, bool isApk = false);

View file

@ -97,87 +97,91 @@ void ToolForm::hideEvent(QHideEvent *event)
void ToolForm::on_fullScreenBtn_clicked() void ToolForm::on_fullScreenBtn_clicked()
{ {
if (!m_device || !m_device->getVideoForm()) { if (!m_device) {
return; return;
} }
m_device->getVideoForm()->switchFullScreen();
emit m_device->switchFullScreen();
} }
void ToolForm::on_returnBtn_clicked() void ToolForm::on_returnBtn_clicked()
{ {
if (!m_device || !m_device->getController()) { if (!m_device) {
return; return;
} }
m_device->getController()->postGoBack(); emit m_device->postGoBack();
} }
void ToolForm::on_homeBtn_clicked() void ToolForm::on_homeBtn_clicked()
{ {
if (!m_device || !m_device->getController()) { if (!m_device) {
return; return;
} }
m_device->getController()->postGoHome(); emit m_device->postGoHome();
} }
void ToolForm::on_menuBtn_clicked() void ToolForm::on_menuBtn_clicked()
{ {
if (!m_device || !m_device->getController()) { if (!m_device) {
return; return;
} }
m_device->getController()->postGoMenu(); emit m_device->postGoMenu();
} }
void ToolForm::on_appSwitchBtn_clicked() void ToolForm::on_appSwitchBtn_clicked()
{ {
if (!m_device || !m_device->getController()) { if (!m_device) {
return; return;
} }
m_device->getController()->postAppSwitch(); emit m_device->postAppSwitch();
} }
void ToolForm::on_powerBtn_clicked() void ToolForm::on_powerBtn_clicked()
{ {
if (!m_device || !m_device->getController()) { if (!m_device) {
return; return;
} }
m_device->getController()->postPower(); emit m_device->postPower();
} }
void ToolForm::on_screenShotBtn_clicked() void ToolForm::on_screenShotBtn_clicked()
{ {
emit screenshot(); if (!m_device) {
return;
}
emit m_device->screenshot();
} }
void ToolForm::on_volumeUpBtn_clicked() void ToolForm::on_volumeUpBtn_clicked()
{ {
if (!m_device || !m_device->getController()) { if (!m_device) {
return; return;
} }
m_device->getController()->postVolumeUp(); emit m_device->postVolumeUp();
} }
void ToolForm::on_volumeDownBtn_clicked() void ToolForm::on_volumeDownBtn_clicked()
{ {
if (!m_device || !m_device->getController()) { if (!m_device) {
return; return;
} }
m_device->getController()->postVolumeDown(); emit m_device->postVolumeDown();
} }
void ToolForm::on_closeScreenBtn_clicked() void ToolForm::on_closeScreenBtn_clicked()
{ {
if (!m_device || !m_device->getController()) { if (!m_device) {
return; return;
} }
m_device->getController()->setScreenPowerMode(ControlMsg::SPM_OFF); emit m_device->setScreenPowerMode(ControlMsg::SPM_OFF);
} }
void ToolForm::on_expandNotifyBtn_clicked() void ToolForm::on_expandNotifyBtn_clicked()
{ {
if (!m_device || !m_device->getController()) { if (!m_device) {
return; return;
} }
m_device->getController()->expandNotificationPanel(); emit m_device->expandNotificationPanel();
} }
void ToolForm::on_touchBtn_clicked() void ToolForm::on_touchBtn_clicked()
@ -187,19 +191,7 @@ void ToolForm::on_touchBtn_clicked()
} }
m_showTouch = !m_showTouch; m_showTouch = !m_showTouch;
emit m_device->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");
} }
void ToolForm::on_groupControlBtn_clicked() void ToolForm::on_groupControlBtn_clicked()
@ -207,6 +199,6 @@ void ToolForm::on_groupControlBtn_clicked()
if (!m_device) { if (!m_device) {
return; return;
} }
m_device->setMainControl(!m_device->mainControl()); emit m_device->setMainControl(m_device, !m_device->mainControl());
updateGroupControl(); updateGroupControl();
} }

View file

@ -29,34 +29,19 @@ protected:
void showEvent(QShowEvent *event); void showEvent(QShowEvent *event);
void hideEvent(QHideEvent *event); void hideEvent(QHideEvent *event);
signals:
void screenshot();
private slots: private slots:
void on_fullScreenBtn_clicked(); void on_fullScreenBtn_clicked();
void on_returnBtn_clicked(); void on_returnBtn_clicked();
void on_homeBtn_clicked(); void on_homeBtn_clicked();
void on_menuBtn_clicked(); void on_menuBtn_clicked();
void on_appSwitchBtn_clicked(); void on_appSwitchBtn_clicked();
void on_powerBtn_clicked(); void on_powerBtn_clicked();
void on_screenShotBtn_clicked(); void on_screenShotBtn_clicked();
void on_volumeUpBtn_clicked(); void on_volumeUpBtn_clicked();
void on_volumeDownBtn_clicked(); void on_volumeDownBtn_clicked();
void on_closeScreenBtn_clicked(); void on_closeScreenBtn_clicked();
void on_expandNotifyBtn_clicked(); void on_expandNotifyBtn_clicked();
void on_touchBtn_clicked(); void on_touchBtn_clicked();
void on_groupControlBtn_clicked(); void on_groupControlBtn_clicked();
private: private:

View file

@ -100,7 +100,6 @@ void VideoForm::showToolForm(bool show)
if (!m_toolForm) { if (!m_toolForm) {
m_toolForm = new ToolForm(this, ToolForm::AP_OUTSIDE_RIGHT); m_toolForm = new ToolForm(this, ToolForm::AP_OUTSIDE_RIGHT);
m_toolForm->setDevice(m_device); 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->move(pos().x() + geometry().width(), pos().y() + 30);
m_toolForm->setVisible(show); m_toolForm->setVisible(show);
@ -174,7 +173,7 @@ void VideoForm::updateShowSize(const QSize &newSize)
} }
if (isFullScreen()) { if (isFullScreen()) {
switchFullScreen(); onSwitchFullScreen();
} }
if (m_skin) { if (m_skin) {
QMargins m = getMargins(vertical); QMargins m = getMargins(vertical);
@ -192,7 +191,7 @@ void VideoForm::updateShowSize(const QSize &newSize)
} }
} }
void VideoForm::switchFullScreen() void VideoForm::onSwitchFullScreen()
{ {
if (isFullScreen()) { if (isFullScreen()) {
// 横屏全屏铺满全屏,恢复时,恢复保持宽高比 // 横屏全屏铺满全屏,恢复时,恢复保持宽高比
@ -263,11 +262,11 @@ void VideoForm::setDevice(Device *device)
void VideoForm::mousePressEvent(QMouseEvent *event) void VideoForm::mousePressEvent(QMouseEvent *event)
{ {
if (m_videoWidget->geometry().contains(event->pos())) { if (m_videoWidget->geometry().contains(event->pos())) {
if (!m_device || !m_device->getController()) { if (!m_device) {
return; return;
} }
event->setLocalPos(m_videoWidget->mapFrom(this, event->localPos().toPoint())); 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 { } else {
if (event->button() == Qt::LeftButton) { if (event->button() == Qt::LeftButton) {
m_dragPosition = event->globalPos() - frameGeometry().topLeft(); m_dragPosition = event->globalPos() - frameGeometry().topLeft();
@ -279,7 +278,7 @@ void VideoForm::mousePressEvent(QMouseEvent *event)
void VideoForm::mouseReleaseEvent(QMouseEvent *event) void VideoForm::mouseReleaseEvent(QMouseEvent *event)
{ {
if (m_dragPosition.isNull()) { if (m_dragPosition.isNull()) {
if (!m_device || !m_device->getController()) { if (!m_device) {
return; return;
} }
event->setLocalPos(m_videoWidget->mapFrom(this, event->localPos().toPoint())); event->setLocalPos(m_videoWidget->mapFrom(this, event->localPos().toPoint()));
@ -298,7 +297,7 @@ void VideoForm::mouseReleaseEvent(QMouseEvent *event)
local.setY(m_videoWidget->height()); local.setY(m_videoWidget->height());
} }
event->setLocalPos(local); 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 { } else {
m_dragPosition = QPoint(0, 0); m_dragPosition = QPoint(0, 0);
} }
@ -307,11 +306,11 @@ void VideoForm::mouseReleaseEvent(QMouseEvent *event)
void VideoForm::mouseMoveEvent(QMouseEvent *event) void VideoForm::mouseMoveEvent(QMouseEvent *event)
{ {
if (m_videoWidget->geometry().contains(event->pos())) { if (m_videoWidget->geometry().contains(event->pos())) {
if (!m_device || !m_device->getController()) { if (!m_device) {
return; return;
} }
event->setLocalPos(m_videoWidget->mapFrom(this, event->localPos().toPoint())); 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()){ } else if (!m_dragPosition.isNull()){
if (event->buttons() & Qt::LeftButton) { if (event->buttons() & Qt::LeftButton) {
move(event->globalPos() - m_dragPosition); move(event->globalPos() - m_dragPosition);
@ -323,7 +322,7 @@ void VideoForm::mouseMoveEvent(QMouseEvent *event)
void VideoForm::wheelEvent(QWheelEvent *event) void VideoForm::wheelEvent(QWheelEvent *event)
{ {
if (m_videoWidget->geometry().contains(event->pos())) { if (m_videoWidget->geometry().contains(event->pos())) {
if (!m_device || !m_device->getController()) { if (!m_device) {
return; return;
} }
QPointF pos = m_videoWidget->mapFrom(this, event->pos()); QPointF pos = m_videoWidget->mapFrom(this, event->pos());
@ -334,7 +333,7 @@ void VideoForm::wheelEvent(QWheelEvent *event)
*/ */
QWheelEvent wheelEvent(pos, event->globalPosF(), event->delta(), QWheelEvent wheelEvent(pos, event->globalPosF(), event->delta(),
event->buttons(), event->modifiers(), event->orientation()); 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() if (Qt::Key_Escape == event->key()
&& !event->isAutoRepeat() && !event->isAutoRepeat()
&& isFullScreen()) { && isFullScreen()) {
switchFullScreen(); onSwitchFullScreen();
} }
if (!m_device || !m_device->getController()) { if (!m_device) {
return; return;
} }
if (event->key() == Qt::Key_C && (event->modifiers() & Qt::ControlModifier)) { 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->key() == Qt::Key_V && (event->modifiers() & Qt::ControlModifier)) {
if (event->modifiers() & Qt::ShiftModifier) { if (event->modifiers() & Qt::ShiftModifier) {
m_device->getController()->setDeviceClipboard(); emit m_device->setDeviceClipboard();
} else { } else {
m_device->getController()->clipboardPaste(); emit m_device->clipboardPaste();
} }
return; 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) void VideoForm::keyReleaseEvent(QKeyEvent *event)
{ {
if (!m_device || !m_device->getController()) { if (!m_device) {
return; 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) void VideoForm::paintEvent(QPaintEvent *paint)
@ -431,7 +430,7 @@ void VideoForm::dragLeaveEvent(QDragLeaveEvent *event)
void VideoForm::dropEvent(QDropEvent *event) void VideoForm::dropEvent(QDropEvent *event)
{ {
if (!m_device || !m_device->getFileHandler()) { if (!m_device) {
return; return;
} }
const QMimeData* qm = event->mimeData(); const QMimeData* qm = event->mimeData();
@ -444,8 +443,8 @@ void VideoForm::dropEvent(QDropEvent *event)
} }
if (fileInfo.isFile() && fileInfo.suffix() == "apk") { if (fileInfo.isFile() && fileInfo.suffix() == "apk") {
m_device->getFileHandler()->installApkRequest(m_device->getSerial(), file); emit m_device->installApkRequest(m_device->getSerial(), file);
return; 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());
} }

View file

@ -20,17 +20,14 @@ public:
explicit VideoForm(bool skin = true, QWidget *parent = 0); explicit VideoForm(bool skin = true, QWidget *parent = 0);
~VideoForm(); ~VideoForm();
void switchFullScreen();
void staysOnTop(bool top = true); void staysOnTop(bool top = true);
void updateShowSize(const QSize &newSize); void updateShowSize(const QSize &newSize);
void updateRender(const AVFrame *frame); void updateRender(const AVFrame *frame);
void setDevice(Device *device); void setDevice(Device *device);
signals:
void screenshot();
public slots: public slots:
void onGrabCursor(bool grab); void onGrabCursor(bool grab);
void onSwitchFullScreen();
private: private:
void updateStyleSheet(bool vertical); void updateStyleSheet(bool vertical);