mirror of
https://github.com/barry-ran/QtScrcpy.git
synced 2025-04-20 19:44:59 +00:00
refactor: device signal to method
This commit is contained in:
parent
687b146f6d
commit
767bb71e7a
10 changed files with 248 additions and 323 deletions
|
@ -67,7 +67,7 @@ bool Controller::isCurrentCustomKeymap()
|
|||
return m_inputConvert->isCurrentCustomKeymap();
|
||||
}
|
||||
|
||||
void Controller::onPostBackOrScreenOn(bool down)
|
||||
void Controller::postBackOrScreenOn(bool down)
|
||||
{
|
||||
ControlMsg *controlMsg = new ControlMsg(ControlMsg::CMT_BACK_OR_SCREEN_ON);
|
||||
controlMsg->setBackOrScreenOnData(down);
|
||||
|
@ -77,52 +77,52 @@ void Controller::onPostBackOrScreenOn(bool down)
|
|||
postControlMsg(controlMsg);
|
||||
}
|
||||
|
||||
void Controller::onPostGoHome()
|
||||
void Controller::postGoHome()
|
||||
{
|
||||
postKeyCodeClick(AKEYCODE_HOME);
|
||||
}
|
||||
|
||||
void Controller::onPostGoMenu()
|
||||
void Controller::postGoMenu()
|
||||
{
|
||||
postKeyCodeClick(AKEYCODE_MENU);
|
||||
}
|
||||
|
||||
void Controller::onPostGoBack()
|
||||
void Controller::postGoBack()
|
||||
{
|
||||
postKeyCodeClick(AKEYCODE_BACK);
|
||||
}
|
||||
|
||||
void Controller::onPostAppSwitch()
|
||||
void Controller::postAppSwitch()
|
||||
{
|
||||
postKeyCodeClick(AKEYCODE_APP_SWITCH);
|
||||
}
|
||||
|
||||
void Controller::onPostPower()
|
||||
void Controller::postPower()
|
||||
{
|
||||
postKeyCodeClick(AKEYCODE_POWER);
|
||||
}
|
||||
|
||||
void Controller::onPostVolumeUp()
|
||||
void Controller::postVolumeUp()
|
||||
{
|
||||
postKeyCodeClick(AKEYCODE_VOLUME_UP);
|
||||
}
|
||||
|
||||
void Controller::onPostVolumeDown()
|
||||
void Controller::postVolumeDown()
|
||||
{
|
||||
postKeyCodeClick(AKEYCODE_VOLUME_DOWN);
|
||||
}
|
||||
|
||||
void Controller::onCopy()
|
||||
void Controller::copy()
|
||||
{
|
||||
postKeyCodeClick(AKEYCODE_COPY);
|
||||
}
|
||||
|
||||
void Controller::onCut()
|
||||
void Controller::cut()
|
||||
{
|
||||
postKeyCodeClick(AKEYCODE_CUT);
|
||||
}
|
||||
|
||||
void Controller::onExpandNotificationPanel()
|
||||
void Controller::expandNotificationPanel()
|
||||
{
|
||||
ControlMsg *controlMsg = new ControlMsg(ControlMsg::CMT_EXPAND_NOTIFICATION_PANEL);
|
||||
if (!controlMsg) {
|
||||
|
@ -131,7 +131,7 @@ void Controller::onExpandNotificationPanel()
|
|||
postControlMsg(controlMsg);
|
||||
}
|
||||
|
||||
void Controller::onCollapsePanel()
|
||||
void Controller::collapsePanel()
|
||||
{
|
||||
ControlMsg *controlMsg = new ControlMsg(ControlMsg::CMT_COLLAPSE_PANELS);
|
||||
if (!controlMsg) {
|
||||
|
@ -140,7 +140,7 @@ void Controller::onCollapsePanel()
|
|||
postControlMsg(controlMsg);
|
||||
}
|
||||
|
||||
void Controller::onRequestDeviceClipboard()
|
||||
void Controller::requestDeviceClipboard()
|
||||
{
|
||||
ControlMsg *controlMsg = new ControlMsg(ControlMsg::CMT_GET_CLIPBOARD);
|
||||
if (!controlMsg) {
|
||||
|
@ -149,7 +149,7 @@ void Controller::onRequestDeviceClipboard()
|
|||
postControlMsg(controlMsg);
|
||||
}
|
||||
|
||||
void Controller::onGetDeviceClipboard(bool cut)
|
||||
void Controller::getDeviceClipboard(bool cut)
|
||||
{
|
||||
ControlMsg *controlMsg = new ControlMsg(ControlMsg::CMT_GET_CLIPBOARD);
|
||||
if (!controlMsg) {
|
||||
|
@ -160,7 +160,7 @@ void Controller::onGetDeviceClipboard(bool cut)
|
|||
postControlMsg(controlMsg);
|
||||
}
|
||||
|
||||
void Controller::onSetDeviceClipboard(bool pause)
|
||||
void Controller::setDeviceClipboard(bool pause)
|
||||
{
|
||||
QClipboard *board = QApplication::clipboard();
|
||||
QString text = board->text();
|
||||
|
@ -172,14 +172,14 @@ void Controller::onSetDeviceClipboard(bool pause)
|
|||
postControlMsg(controlMsg);
|
||||
}
|
||||
|
||||
void Controller::onClipboardPaste()
|
||||
void Controller::clipboardPaste()
|
||||
{
|
||||
QClipboard *board = QApplication::clipboard();
|
||||
QString text = board->text();
|
||||
onPostTextInput(text);
|
||||
postTextInput(text);
|
||||
}
|
||||
|
||||
void Controller::onPostTextInput(QString &text)
|
||||
void Controller::postTextInput(QString &text)
|
||||
{
|
||||
ControlMsg *controlMsg = new ControlMsg(ControlMsg::CMT_INJECT_TEXT);
|
||||
if (!controlMsg) {
|
||||
|
@ -189,7 +189,7 @@ void Controller::onPostTextInput(QString &text)
|
|||
postControlMsg(controlMsg);
|
||||
}
|
||||
|
||||
void Controller::onSetScreenPowerMode(ControlMsg::ScreenPowerMode mode)
|
||||
void Controller::setScreenPowerMode(ControlMsg::ScreenPowerMode mode)
|
||||
{
|
||||
ControlMsg *controlMsg = new ControlMsg(ControlMsg::CMT_SET_SCREEN_POWER_MODE);
|
||||
if (!controlMsg) {
|
||||
|
@ -199,21 +199,21 @@ void Controller::onSetScreenPowerMode(ControlMsg::ScreenPowerMode mode)
|
|||
postControlMsg(controlMsg);
|
||||
}
|
||||
|
||||
void Controller::onMouseEvent(const QMouseEvent *from, const QSize &frameSize, const QSize &showSize)
|
||||
void Controller::mouseEvent(const QMouseEvent *from, const QSize &frameSize, const QSize &showSize)
|
||||
{
|
||||
if (m_inputConvert) {
|
||||
m_inputConvert->mouseEvent(from, frameSize, showSize);
|
||||
}
|
||||
}
|
||||
|
||||
void Controller::onWheelEvent(const QWheelEvent *from, const QSize &frameSize, const QSize &showSize)
|
||||
void Controller::wheelEvent(const QWheelEvent *from, const QSize &frameSize, const QSize &showSize)
|
||||
{
|
||||
if (m_inputConvert) {
|
||||
m_inputConvert->wheelEvent(from, frameSize, showSize);
|
||||
}
|
||||
}
|
||||
|
||||
void Controller::onKeyEvent(const QKeyEvent *from, const QSize &frameSize, const QSize &showSize)
|
||||
void Controller::keyEvent(const QKeyEvent *from, const QSize &frameSize, const QSize &showSize)
|
||||
{
|
||||
if (m_inputConvert) {
|
||||
m_inputConvert->keyEvent(from, frameSize, showSize);
|
||||
|
|
|
@ -25,33 +25,32 @@ public:
|
|||
void updateScript(QString gameScript = "");
|
||||
bool isCurrentCustomKeymap();
|
||||
|
||||
public slots:
|
||||
void onPostGoBack();
|
||||
void onPostGoHome();
|
||||
void onPostGoMenu();
|
||||
void onPostAppSwitch();
|
||||
void onPostPower();
|
||||
void onPostVolumeUp();
|
||||
void onPostVolumeDown();
|
||||
void onCopy();
|
||||
void onCut();
|
||||
void onExpandNotificationPanel();
|
||||
void onCollapsePanel();
|
||||
void onSetScreenPowerMode(ControlMsg::ScreenPowerMode mode);
|
||||
void postGoBack();
|
||||
void postGoHome();
|
||||
void postGoMenu();
|
||||
void postAppSwitch();
|
||||
void postPower();
|
||||
void postVolumeUp();
|
||||
void postVolumeDown();
|
||||
void copy();
|
||||
void cut();
|
||||
void expandNotificationPanel();
|
||||
void collapsePanel();
|
||||
void setScreenPowerMode(ControlMsg::ScreenPowerMode mode);
|
||||
|
||||
// for input convert
|
||||
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);
|
||||
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);
|
||||
|
||||
// turn the screen on if it was off, press BACK otherwise
|
||||
// If the screen is off, it is turned on only on down
|
||||
void onPostBackOrScreenOn(bool down);
|
||||
void onRequestDeviceClipboard();
|
||||
void onGetDeviceClipboard(bool cut = false);
|
||||
void onSetDeviceClipboard(bool pause = true);
|
||||
void onClipboardPaste();
|
||||
void onPostTextInput(QString &text);
|
||||
void postBackOrScreenOn(bool down);
|
||||
void requestDeviceClipboard();
|
||||
void getDeviceClipboard(bool cut = false);
|
||||
void setDeviceClipboard(bool pause = true);
|
||||
void clipboardPaste();
|
||||
void postTextInput(QString &text);
|
||||
|
||||
signals:
|
||||
void grabCursor(bool grab);
|
||||
|
|
|
@ -91,7 +91,7 @@ void Device::updateScript(QString script)
|
|||
}
|
||||
}
|
||||
|
||||
void Device::onScreenshot()
|
||||
void Device::screenshot()
|
||||
{
|
||||
if (!m_decoder) {
|
||||
return;
|
||||
|
@ -103,7 +103,7 @@ void Device::onScreenshot()
|
|||
});
|
||||
}
|
||||
|
||||
void Device::onShowTouch(bool show)
|
||||
void Device::showTouch(bool show)
|
||||
{
|
||||
AdbProcess *adb = new AdbProcess();
|
||||
if (!adb) {
|
||||
|
@ -121,18 +121,11 @@ void Device::onShowTouch(bool show)
|
|||
|
||||
void Device::initSignals()
|
||||
{
|
||||
connect(this, &Device::screenshot, this, &Device::onScreenshot);
|
||||
connect(this, &Device::showTouch, this, &Device::onShowTouch);
|
||||
connect(this, &Device::setControlState, this, &Device::onSetControlState);
|
||||
connect(this, &Device::grabCursor, this, &Device::onGrabCursor);
|
||||
|
||||
if (m_controller) {
|
||||
connect(m_controller, &Controller::grabCursor, this, &Device::grabCursor);
|
||||
}
|
||||
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);
|
||||
|
@ -150,15 +143,9 @@ void Device::initSignals()
|
|||
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(this, &Device::switchFullScreen, m_videoForm, &VideoForm::onSwitchFullScreen);
|
||||
*/
|
||||
}
|
||||
if (m_fileHandler) {
|
||||
connect(this, &Device::pushFileRequest, this, [this](const QString &file, const QString &devicePath) {
|
||||
m_fileHandler->onPushFileRequest(getSerial(), file, devicePath);
|
||||
});
|
||||
connect(this, &Device::installApkRequest, this, [this](const QString &apkFile) { m_fileHandler->onInstallApkRequest(getSerial(), apkFile); });
|
||||
connect(m_fileHandler, &FileHandler::fileHandlerResult, this, [this](FileHandler::FILE_HANDLER_RESULT processResult, bool isApk) {
|
||||
QString tipsType = "";
|
||||
if (isApk) {
|
||||
|
@ -177,9 +164,6 @@ void Device::initSignals()
|
|||
tips = tr("%1 failed").arg(tipsType);
|
||||
}
|
||||
qInfo() << tips;
|
||||
if (m_controlState == GCS_CLIENT) {
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -254,7 +238,7 @@ void Device::initSignals()
|
|||
|
||||
// 显示界面时才自动息屏(m_params.display)
|
||||
if (m_params.closeScreen && m_params.display && m_controller) {
|
||||
emit m_controller->onSetScreenPowerMode(ControlMsg::SPM_OFF);
|
||||
m_controller->setScreenPowerMode(ControlMsg::SPM_OFF);
|
||||
}
|
||||
} else {
|
||||
m_server->stop();
|
||||
|
@ -357,34 +341,191 @@ void Device::disconnectDevice()
|
|||
emit deviceDisconnected(m_params.serial);
|
||||
}
|
||||
|
||||
void Device::onSetControlState(Device *device, Device::GroupControlState state)
|
||||
void Device::postGoBack()
|
||||
{
|
||||
Q_UNUSED(device)
|
||||
if (m_controlState == state) {
|
||||
if (!m_controller) {
|
||||
return;
|
||||
}
|
||||
GroupControlState oldState = m_controlState;
|
||||
m_controlState = state;
|
||||
emit controlStateChange(this, oldState, m_controlState);
|
||||
m_controller->postGoBack();
|
||||
}
|
||||
|
||||
void Device::onGrabCursor(bool grab)
|
||||
void Device::postGoHome()
|
||||
{
|
||||
if (!m_controller) {
|
||||
return;
|
||||
}
|
||||
m_controller->postGoHome();
|
||||
}
|
||||
|
||||
void Device::postGoMenu()
|
||||
{
|
||||
if (!m_controller) {
|
||||
return;
|
||||
}
|
||||
m_controller->postGoMenu();
|
||||
}
|
||||
|
||||
void Device::postAppSwitch()
|
||||
{
|
||||
if (!m_controller) {
|
||||
return;
|
||||
}
|
||||
m_controller->postAppSwitch();
|
||||
}
|
||||
|
||||
void Device::postPower()
|
||||
{
|
||||
if (!m_controller) {
|
||||
return;
|
||||
}
|
||||
m_controller->postPower();
|
||||
}
|
||||
|
||||
void Device::postVolumeUp()
|
||||
{
|
||||
if (!m_controller) {
|
||||
return;
|
||||
}
|
||||
m_controller->postVolumeUp();
|
||||
}
|
||||
|
||||
void Device::postVolumeDown()
|
||||
{
|
||||
if (!m_controller) {
|
||||
return;
|
||||
}
|
||||
m_controller->postVolumeDown();
|
||||
}
|
||||
|
||||
void Device::postCopy()
|
||||
{
|
||||
if (!m_controller) {
|
||||
return;
|
||||
}
|
||||
m_controller->copy();
|
||||
}
|
||||
|
||||
void Device::postCut()
|
||||
{
|
||||
if (!m_controller) {
|
||||
return;
|
||||
}
|
||||
m_controller->cut();
|
||||
}
|
||||
|
||||
void Device::setScreenPowerMode(ControlMsg::ScreenPowerMode mode)
|
||||
{
|
||||
if (!m_controller) {
|
||||
return;
|
||||
}
|
||||
m_controller->setScreenPowerMode(mode);
|
||||
}
|
||||
|
||||
void Device::expandNotificationPanel()
|
||||
{
|
||||
if (!m_controller) {
|
||||
return;
|
||||
}
|
||||
m_controller->expandNotificationPanel();
|
||||
}
|
||||
|
||||
void Device::collapsePanel()
|
||||
{
|
||||
if (!m_controller) {
|
||||
return;
|
||||
}
|
||||
m_controller->collapsePanel();
|
||||
}
|
||||
|
||||
void Device::postBackOrScreenOn(bool down)
|
||||
{
|
||||
if (!m_controller) {
|
||||
return;
|
||||
}
|
||||
m_controller->postBackOrScreenOn(down);
|
||||
}
|
||||
|
||||
void Device::postTextInput(QString &text)
|
||||
{
|
||||
if (!m_controller) {
|
||||
return;
|
||||
}
|
||||
m_controller->postTextInput(text);
|
||||
}
|
||||
|
||||
void Device::requestDeviceClipboard()
|
||||
{
|
||||
if (!m_controller) {
|
||||
return;
|
||||
}
|
||||
m_controller->requestDeviceClipboard();
|
||||
}
|
||||
|
||||
void Device::setDeviceClipboard(bool pause)
|
||||
{
|
||||
if (!m_controller) {
|
||||
return;
|
||||
}
|
||||
m_controller->setDeviceClipboard(pause);
|
||||
}
|
||||
|
||||
void Device::clipboardPaste()
|
||||
{
|
||||
if (!m_controller) {
|
||||
return;
|
||||
}
|
||||
m_controller->clipboardPaste();
|
||||
}
|
||||
|
||||
void Device::pushFileRequest(const QString &file, const QString &devicePath)
|
||||
{
|
||||
if (!m_fileHandler) {
|
||||
return;
|
||||
}
|
||||
m_fileHandler->onPushFileRequest(getSerial(), file, devicePath);
|
||||
}
|
||||
|
||||
void Device::installApkRequest(const QString &apkFile)
|
||||
{
|
||||
if (!m_fileHandler) {
|
||||
return;
|
||||
}
|
||||
m_fileHandler->onInstallApkRequest(getSerial(), apkFile);
|
||||
}
|
||||
|
||||
void Device::mouseEvent(const QMouseEvent *from, const QSize &frameSize, const QSize &showSize)
|
||||
{
|
||||
if (!m_controller) {
|
||||
return;
|
||||
}
|
||||
m_controller->mouseEvent(from, frameSize, showSize);
|
||||
}
|
||||
|
||||
void Device::wheelEvent(const QWheelEvent *from, const QSize &frameSize, const QSize &showSize)
|
||||
{
|
||||
if (!m_controller) {
|
||||
return;
|
||||
}
|
||||
m_controller->wheelEvent(from, frameSize, showSize);
|
||||
}
|
||||
|
||||
void Device::keyEvent(const QKeyEvent *from, const QSize &frameSize, const QSize &showSize)
|
||||
{
|
||||
if (!m_controller) {
|
||||
return;
|
||||
}
|
||||
m_controller->keyEvent(from, frameSize, showSize);
|
||||
}
|
||||
|
||||
void Device::grabCursor(bool grab)
|
||||
{
|
||||
if (!m_videoForm) {
|
||||
return;
|
||||
}
|
||||
if (m_controlState == GCS_CLIENT) {
|
||||
return;
|
||||
}
|
||||
QRect rc = m_videoForm->getGrabCursorRect();
|
||||
MouseTap::getInstance()->enableMouseEventTap(rc, grab);
|
||||
}
|
||||
|
||||
Device::GroupControlState Device::controlState()
|
||||
{
|
||||
return m_controlState;
|
||||
}
|
||||
|
||||
bool Device::isCurrentCustomKeymap()
|
||||
{
|
||||
if (!m_controller) {
|
||||
|
|
|
@ -43,34 +43,11 @@ public:
|
|||
bool stayAwake = false; // 是否保持唤醒
|
||||
bool framelessWindow = false; // 是否无边框窗口
|
||||
};
|
||||
enum GroupControlState
|
||||
{
|
||||
GCS_FREE = 0,
|
||||
GCS_HOST,
|
||||
GCS_CLIENT,
|
||||
};
|
||||
explicit Device(DeviceParams params, QObject *parent = nullptr);
|
||||
virtual ~Device();
|
||||
|
||||
bool connectDevice();
|
||||
void disconnectDevice();
|
||||
|
||||
VideoForm *getVideoForm();
|
||||
Server *getServer();
|
||||
const QString &getSerial();
|
||||
const QSize frameSize();
|
||||
|
||||
void updateScript(QString script);
|
||||
Device::GroupControlState controlState();
|
||||
|
||||
bool isCurrentCustomKeymap();
|
||||
|
||||
signals:
|
||||
void deviceConnected(bool success, const QString& serial, const QString& deviceName, const QSize& size);
|
||||
void deviceDisconnected(QString serial);
|
||||
|
||||
// tool bar
|
||||
void switchFullScreen();
|
||||
void postGoBack();
|
||||
void postGoHome();
|
||||
void postGoMenu();
|
||||
|
@ -95,21 +72,23 @@ signals:
|
|||
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);
|
||||
|
||||
|
||||
// self connect signal and slots
|
||||
void screenshot();
|
||||
void showTouch(bool show);
|
||||
void setControlState(Device *device, Device::GroupControlState state);
|
||||
void grabCursor(bool grab);
|
||||
|
||||
// for notify
|
||||
void controlStateChange(Device *device, Device::GroupControlState oldState, Device::GroupControlState newState);
|
||||
VideoForm *getVideoForm();
|
||||
Server *getServer();
|
||||
const QString &getSerial();
|
||||
const QSize frameSize();
|
||||
|
||||
public slots:
|
||||
void onScreenshot();
|
||||
void onShowTouch(bool show);
|
||||
void onSetControlState(Device *device, Device::GroupControlState state);
|
||||
void onGrabCursor(bool grab);
|
||||
void updateScript(QString script);
|
||||
bool isCurrentCustomKeymap();
|
||||
|
||||
signals:
|
||||
void deviceConnected(bool success, const QString& serial, const QString& deviceName, const QSize& size);
|
||||
void deviceDisconnected(QString serial);
|
||||
|
||||
private:
|
||||
void initSignals();
|
||||
|
@ -129,8 +108,6 @@ private:
|
|||
|
||||
QElapsedTimer m_startTimeCount;
|
||||
DeviceParams m_params;
|
||||
|
||||
GroupControlState m_controlState = GCS_FREE;
|
||||
};
|
||||
|
||||
#endif // DEVICE_H
|
||||
|
|
|
@ -42,7 +42,6 @@ bool DeviceManage::connectDevice(Device::DeviceParams params)
|
|||
Device *device = new Device(params);
|
||||
connect(device, &Device::deviceConnected, this, &DeviceManage::onDeviceConnected);
|
||||
connect(device, &Device::deviceDisconnected, this, &DeviceManage::onDeviceDisconnected);
|
||||
connect(device, &Device::controlStateChange, this, &DeviceManage::onControlStateChange);
|
||||
if (!device->connectDevice()) {
|
||||
delete device;
|
||||
return false;
|
||||
|
@ -120,77 +119,6 @@ void DeviceManage::disconnectAllDevice()
|
|||
}
|
||||
}
|
||||
|
||||
void DeviceManage::setGroupControlSignals(Device *host, Device *client, bool install)
|
||||
{
|
||||
if (!host || !client) {
|
||||
return;
|
||||
}
|
||||
if (install) {
|
||||
connect(host, &Device::postGoBack, client, &Device::postGoBack);
|
||||
connect(host, &Device::postGoHome, client, &Device::postGoHome);
|
||||
connect(host, &Device::postGoMenu, client, &Device::postGoMenu);
|
||||
connect(host, &Device::postAppSwitch, client, &Device::postAppSwitch);
|
||||
connect(host, &Device::postPower, client, &Device::postPower);
|
||||
connect(host, &Device::postVolumeUp, client, &Device::postVolumeUp);
|
||||
connect(host, &Device::postVolumeDown, client, &Device::postVolumeDown);
|
||||
connect(host, &Device::setScreenPowerMode, client, &Device::setScreenPowerMode);
|
||||
connect(host, &Device::expandNotificationPanel, client, &Device::expandNotificationPanel);
|
||||
connect(host, &Device::collapsePanel, client, &Device::collapsePanel);
|
||||
connect(host, &Device::postBackOrScreenOn, client, &Device::postBackOrScreenOn);
|
||||
connect(host, &Device::postTextInput, client, &Device::postTextInput);
|
||||
connect(host, &Device::setDeviceClipboard, client, &Device::setDeviceClipboard);
|
||||
connect(host, &Device::clipboardPaste, client, &Device::clipboardPaste);
|
||||
connect(host, &Device::pushFileRequest, client, &Device::pushFileRequest);
|
||||
connect(host, &Device::installApkRequest, client, &Device::installApkRequest);
|
||||
connect(host, &Device::screenshot, client, &Device::screenshot);
|
||||
connect(host, &Device::showTouch, client, &Device::showTouch);
|
||||
} else {
|
||||
disconnect(host, &Device::postGoBack, client, &Device::postGoBack);
|
||||
disconnect(host, &Device::postGoHome, client, &Device::postGoHome);
|
||||
disconnect(host, &Device::postGoMenu, client, &Device::postGoMenu);
|
||||
disconnect(host, &Device::postAppSwitch, client, &Device::postAppSwitch);
|
||||
disconnect(host, &Device::postPower, client, &Device::postPower);
|
||||
disconnect(host, &Device::postVolumeUp, client, &Device::postVolumeUp);
|
||||
disconnect(host, &Device::postVolumeDown, client, &Device::postVolumeDown);
|
||||
disconnect(host, &Device::setScreenPowerMode, client, &Device::setScreenPowerMode);
|
||||
disconnect(host, &Device::expandNotificationPanel, client, &Device::expandNotificationPanel);
|
||||
disconnect(host, &Device::collapsePanel, client, &Device::collapsePanel);
|
||||
disconnect(host, &Device::postBackOrScreenOn, client, &Device::postBackOrScreenOn);
|
||||
disconnect(host, &Device::postTextInput, client, &Device::postTextInput);
|
||||
disconnect(host, &Device::setDeviceClipboard, client, &Device::setDeviceClipboard);
|
||||
disconnect(host, &Device::clipboardPaste, client, &Device::clipboardPaste);
|
||||
disconnect(host, &Device::pushFileRequest, client, &Device::pushFileRequest);
|
||||
disconnect(host, &Device::installApkRequest, client, &Device::installApkRequest);
|
||||
disconnect(host, &Device::screenshot, client, &Device::screenshot);
|
||||
disconnect(host, &Device::showTouch, client, &Device::showTouch);
|
||||
}
|
||||
}
|
||||
|
||||
void DeviceManage::setGroupControlHost(Device *host, bool install)
|
||||
{
|
||||
QMapIterator<QString, QPointer<Device>> i(m_devices);
|
||||
while (i.hasNext()) {
|
||||
i.next();
|
||||
if (!i.value()) {
|
||||
continue;
|
||||
}
|
||||
if (i.value() == host) {
|
||||
continue;
|
||||
}
|
||||
if (install) {
|
||||
if (host) {
|
||||
setGroupControlSignals(host, i.value(), true);
|
||||
}
|
||||
emit i.value()->setControlState(i.value(), Device::GroupControlState::GCS_CLIENT);
|
||||
} else {
|
||||
if (host) {
|
||||
setGroupControlSignals(host, i.value(), false);
|
||||
}
|
||||
emit i.value()->setControlState(i.value(), Device::GroupControlState::GCS_FREE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DeviceManage::onDeviceConnected(bool success, const QString &serial, const QString &deviceName, const QSize &size)
|
||||
{
|
||||
if (!success) {
|
||||
|
@ -205,84 +133,6 @@ void DeviceManage::onDeviceDisconnected(QString serial)
|
|||
emit deviceDisconnected(serial);
|
||||
}
|
||||
|
||||
void DeviceManage::onControlStateChange(Device *device, Device::GroupControlState oldState, Device::GroupControlState newState)
|
||||
{
|
||||
if (!device) {
|
||||
return;
|
||||
}
|
||||
// free to host
|
||||
if (oldState == Device::GroupControlState::GCS_FREE && newState == Device::GroupControlState::GCS_HOST) {
|
||||
// install direct control signals
|
||||
setGroupControlHost(device, true);
|
||||
// install convert control signals(frameSize need convert)
|
||||
connect(device, &Device::mouseEvent, this, &DeviceManage::onMouseEvent, Qt::UniqueConnection);
|
||||
connect(device, &Device::wheelEvent, this, &DeviceManage::onWheelEvent, Qt::UniqueConnection);
|
||||
connect(device, &Device::keyEvent, this, &DeviceManage::onKeyEvent, Qt::UniqueConnection);
|
||||
return;
|
||||
}
|
||||
// host to free
|
||||
if (oldState == Device::GroupControlState::GCS_HOST && newState == Device::GroupControlState::GCS_FREE) {
|
||||
// uninstall direct control signals
|
||||
setGroupControlHost(device, false);
|
||||
// uninstall convert control signals(frameSize need convert)
|
||||
disconnect(device, &Device::mouseEvent, this, &DeviceManage::onMouseEvent);
|
||||
disconnect(device, &Device::wheelEvent, this, &DeviceManage::onWheelEvent);
|
||||
disconnect(device, &Device::keyEvent, this, &DeviceManage::onKeyEvent);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void DeviceManage::onMouseEvent(const QMouseEvent *from, const QSize &frameSize, const QSize &showSize)
|
||||
{
|
||||
Q_UNUSED(frameSize)
|
||||
QMapIterator<QString, QPointer<Device>> i(m_devices);
|
||||
while (i.hasNext()) {
|
||||
i.next();
|
||||
if (!i.value()) {
|
||||
continue;
|
||||
}
|
||||
if (i.value() == sender()) {
|
||||
continue;
|
||||
}
|
||||
// neend convert frameSize to its frameSize
|
||||
emit i.value()->mouseEvent(from, i.value()->frameSize(), showSize);
|
||||
}
|
||||
}
|
||||
|
||||
void DeviceManage::onWheelEvent(const QWheelEvent *from, const QSize &frameSize, const QSize &showSize)
|
||||
{
|
||||
Q_UNUSED(frameSize)
|
||||
QMapIterator<QString, QPointer<Device>> i(m_devices);
|
||||
while (i.hasNext()) {
|
||||
i.next();
|
||||
if (!i.value()) {
|
||||
continue;
|
||||
}
|
||||
if (i.value() == sender()) {
|
||||
continue;
|
||||
}
|
||||
// neend convert frameSize to its frameSize
|
||||
emit i.value()->wheelEvent(from, i.value()->frameSize(), showSize);
|
||||
}
|
||||
}
|
||||
|
||||
void DeviceManage::onKeyEvent(const QKeyEvent *from, const QSize &frameSize, const QSize &showSize)
|
||||
{
|
||||
Q_UNUSED(frameSize)
|
||||
QMapIterator<QString, QPointer<Device>> i(m_devices);
|
||||
while (i.hasNext()) {
|
||||
i.next();
|
||||
if (!i.value()) {
|
||||
continue;
|
||||
}
|
||||
if (i.value() == sender()) {
|
||||
continue;
|
||||
}
|
||||
// neend convert frameSize to its frameSize
|
||||
emit i.value()->keyEvent(from, i.value()->frameSize(), showSize);
|
||||
}
|
||||
}
|
||||
|
||||
quint16 DeviceManage::getFreePort()
|
||||
{
|
||||
quint16 port = m_localPortStart;
|
||||
|
@ -308,9 +158,6 @@ quint16 DeviceManage::getFreePort()
|
|||
void DeviceManage::removeDevice(const QString &serial)
|
||||
{
|
||||
if (!serial.isEmpty() && m_devices.contains(serial)) {
|
||||
if (m_devices[serial]->controlState() == Device::GroupControlState::GCS_HOST) {
|
||||
setGroupControlHost(nullptr, false);
|
||||
}
|
||||
m_devices[serial]->deleteLater();
|
||||
m_devices.remove(serial);
|
||||
}
|
||||
|
|
|
@ -25,19 +25,9 @@ signals:
|
|||
void deviceConnected(bool success, const QString& serial, const QString& deviceName, const QSize& size);
|
||||
void deviceDisconnected(QString serial);
|
||||
|
||||
protected:
|
||||
void setGroupControlSignals(Device *host, Device *client, bool install);
|
||||
void setGroupControlHost(Device *host, bool install);
|
||||
|
||||
protected slots:
|
||||
void onDeviceConnected(bool success, const QString& serial, const QString& deviceName, const QSize& size);
|
||||
void onDeviceDisconnected(QString serial);
|
||||
void onControlStateChange(Device *device, Device::GroupControlState oldState, Device::GroupControlState newState);
|
||||
|
||||
// neend convert frameSize to its frameSize
|
||||
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);
|
||||
|
||||
private:
|
||||
quint16 getFreePort();
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include "iconhelper.h"
|
||||
#include "toolform.h"
|
||||
#include "ui_toolform.h"
|
||||
#include "videoform.h"
|
||||
|
||||
ToolForm::ToolForm(QWidget *adsorbWidget, AdsorbPositions adsorbPos) : MagneticWidget(adsorbWidget, adsorbPos), ui(new Ui::ToolForm)
|
||||
{
|
||||
|
@ -28,7 +29,6 @@ void ToolForm::setDevice(Device *device)
|
|||
return;
|
||||
}
|
||||
m_device = device;
|
||||
connect(m_device, &Device::controlStateChange, this, &ToolForm::onControlStateChange);
|
||||
}
|
||||
|
||||
void ToolForm::initStyle()
|
||||
|
@ -55,17 +55,6 @@ void ToolForm::updateGroupControl()
|
|||
if (!m_device) {
|
||||
return;
|
||||
}
|
||||
switch (m_device->controlState()) {
|
||||
case Device::GroupControlState::GCS_FREE:
|
||||
ui->groupControlBtn->setStyleSheet("color: #DCDCDC");
|
||||
break;
|
||||
case Device::GroupControlState::GCS_HOST:
|
||||
ui->groupControlBtn->setStyleSheet("color: red");
|
||||
break;
|
||||
case Device::GroupControlState::GCS_CLIENT:
|
||||
ui->groupControlBtn->setStyleSheet("color: green");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void ToolForm::mousePressEvent(QMouseEvent *event)
|
||||
|
@ -107,7 +96,7 @@ void ToolForm::on_fullScreenBtn_clicked()
|
|||
return;
|
||||
}
|
||||
|
||||
emit m_device->switchFullScreen();
|
||||
dynamic_cast<VideoForm*>(parent())->switchFullScreen();
|
||||
}
|
||||
|
||||
void ToolForm::on_returnBtn_clicked()
|
||||
|
@ -115,7 +104,7 @@ void ToolForm::on_returnBtn_clicked()
|
|||
if (!m_device) {
|
||||
return;
|
||||
}
|
||||
emit m_device->postGoBack();
|
||||
m_device->postGoBack();
|
||||
}
|
||||
|
||||
void ToolForm::on_homeBtn_clicked()
|
||||
|
@ -123,7 +112,7 @@ void ToolForm::on_homeBtn_clicked()
|
|||
if (!m_device) {
|
||||
return;
|
||||
}
|
||||
emit m_device->postGoHome();
|
||||
m_device->postGoHome();
|
||||
}
|
||||
|
||||
void ToolForm::on_menuBtn_clicked()
|
||||
|
@ -131,7 +120,7 @@ void ToolForm::on_menuBtn_clicked()
|
|||
if (!m_device) {
|
||||
return;
|
||||
}
|
||||
emit m_device->postGoMenu();
|
||||
m_device->postGoMenu();
|
||||
}
|
||||
|
||||
void ToolForm::on_appSwitchBtn_clicked()
|
||||
|
@ -155,7 +144,7 @@ void ToolForm::on_screenShotBtn_clicked()
|
|||
if (!m_device) {
|
||||
return;
|
||||
}
|
||||
emit m_device->screenshot();
|
||||
m_device->screenshot();
|
||||
}
|
||||
|
||||
void ToolForm::on_volumeUpBtn_clicked()
|
||||
|
@ -197,7 +186,7 @@ void ToolForm::on_touchBtn_clicked()
|
|||
}
|
||||
|
||||
m_showTouch = !m_showTouch;
|
||||
emit m_device->showTouch(m_showTouch);
|
||||
m_device->showTouch(m_showTouch);
|
||||
}
|
||||
|
||||
void ToolForm::on_groupControlBtn_clicked()
|
||||
|
@ -205,21 +194,6 @@ void ToolForm::on_groupControlBtn_clicked()
|
|||
if (!m_device) {
|
||||
return;
|
||||
}
|
||||
Device::GroupControlState state = m_device->controlState();
|
||||
if (state == Device::GroupControlState::GCS_FREE) {
|
||||
emit m_device->setControlState(m_device, Device::GroupControlState::GCS_HOST);
|
||||
}
|
||||
if (state == Device::GroupControlState::GCS_HOST) {
|
||||
emit m_device->setControlState(m_device, Device::GroupControlState::GCS_FREE);
|
||||
}
|
||||
}
|
||||
|
||||
void ToolForm::onControlStateChange(Device *device, Device::GroupControlState oldState, Device::GroupControlState newState)
|
||||
{
|
||||
Q_UNUSED(device)
|
||||
Q_UNUSED(oldState)
|
||||
Q_UNUSED(newState)
|
||||
updateGroupControl();
|
||||
}
|
||||
|
||||
void ToolForm::on_openScreenBtn_clicked()
|
||||
|
|
|
@ -45,9 +45,6 @@ private slots:
|
|||
void on_expandNotifyBtn_clicked();
|
||||
void on_touchBtn_clicked();
|
||||
void on_groupControlBtn_clicked();
|
||||
|
||||
void onControlStateChange(Device *device, Device::GroupControlState oldState, Device::GroupControlState newState);
|
||||
|
||||
void on_openScreenBtn_clicked();
|
||||
|
||||
private:
|
||||
|
|
|
@ -193,7 +193,7 @@ void VideoForm::installShortcut()
|
|||
if (!m_device) {
|
||||
return;
|
||||
}
|
||||
emit m_device->switchFullScreen();
|
||||
switchFullScreen();
|
||||
});
|
||||
|
||||
// resizeSquare
|
||||
|
@ -213,7 +213,7 @@ void VideoForm::installShortcut()
|
|||
if (!m_device) {
|
||||
return;
|
||||
}
|
||||
emit m_device->postGoHome();
|
||||
m_device->postGoHome();
|
||||
});
|
||||
|
||||
// postGoBack
|
||||
|
@ -223,7 +223,7 @@ void VideoForm::installShortcut()
|
|||
if (!m_device) {
|
||||
return;
|
||||
}
|
||||
emit m_device->postGoBack();
|
||||
m_device->postGoBack();
|
||||
});
|
||||
|
||||
// postAppSwitch
|
||||
|
@ -243,7 +243,7 @@ void VideoForm::installShortcut()
|
|||
if (!m_device) {
|
||||
return;
|
||||
}
|
||||
emit m_device->postGoMenu();
|
||||
m_device->postGoMenu();
|
||||
});
|
||||
|
||||
// postVolumeUp
|
||||
|
@ -421,7 +421,7 @@ void VideoForm::updateShowSize(const QSize &newSize)
|
|||
}
|
||||
|
||||
if (isFullScreen() && m_device) {
|
||||
emit m_device->switchFullScreen();
|
||||
switchFullScreen();
|
||||
}
|
||||
|
||||
if (isMaximized()) {
|
||||
|
@ -444,7 +444,7 @@ void VideoForm::updateShowSize(const QSize &newSize)
|
|||
}
|
||||
}
|
||||
|
||||
void VideoForm::onSwitchFullScreen()
|
||||
void VideoForm::switchFullScreen()
|
||||
{
|
||||
if (isFullScreen()) {
|
||||
// 横屏全屏铺满全屏,恢复时,恢复保持宽高比
|
||||
|
@ -525,14 +525,14 @@ void VideoForm::mousePressEvent(QMouseEvent *event)
|
|||
{
|
||||
if (event->button() == Qt::MiddleButton) {
|
||||
if (m_device && !m_device->isCurrentCustomKeymap()) {
|
||||
emit m_device->postGoHome();
|
||||
m_device->postGoHome();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (event->button() == Qt::RightButton) {
|
||||
if (m_device && !m_device->isCurrentCustomKeymap()) {
|
||||
emit m_device->postGoBack();
|
||||
m_device->postGoBack();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -655,7 +655,7 @@ void VideoForm::keyPressEvent(QKeyEvent *event)
|
|||
return;
|
||||
}
|
||||
if (Qt::Key_Escape == event->key() && !event->isAutoRepeat() && isFullScreen()) {
|
||||
emit m_device->switchFullScreen();
|
||||
switchFullScreen();
|
||||
}
|
||||
|
||||
emit m_device->keyEvent(event, m_videoWidget->frameSize(), m_videoWidget->size());
|
||||
|
|
|
@ -30,9 +30,9 @@ public:
|
|||
void resizeSquare();
|
||||
void removeBlackRect();
|
||||
void showFPS(bool show);
|
||||
void switchFullScreen();
|
||||
|
||||
public slots:
|
||||
void onSwitchFullScreen();
|
||||
void updateFPS(quint32 fps);
|
||||
|
||||
private:
|
||||
|
|
Loading…
Add table
Reference in a new issue