mirror of
https://github.com/barry-ran/QtScrcpy.git
synced 2025-04-20 03:25:02 +00:00
refactor: videoForm Device ToolForm
This commit is contained in:
parent
0f6be80e2f
commit
4de26c7577
7 changed files with 127 additions and 73 deletions
|
@ -35,13 +35,7 @@ Device::Device(DeviceParams params, QObject *parent)
|
|||
m_fileHandler = new FileHandler(this);
|
||||
m_controller = new Controller(params.gameScript, this);
|
||||
m_videoForm = new VideoForm(Config::getInstance().getSkin());
|
||||
m_videoForm->setSerial(m_params.serial);
|
||||
if (m_controller) {
|
||||
m_videoForm->setController(m_controller);
|
||||
}
|
||||
if (m_fileHandler) {
|
||||
m_videoForm->setFileHandler(m_fileHandler);
|
||||
}
|
||||
m_videoForm->setDevice(this);
|
||||
m_videoForm->show();
|
||||
}
|
||||
|
||||
|
@ -91,11 +85,21 @@ Controller *Device::getController()
|
|||
return m_controller;
|
||||
}
|
||||
|
||||
FileHandler *Device::getFileHandler()
|
||||
{
|
||||
return m_fileHandler;
|
||||
}
|
||||
|
||||
Server *Device::getServer()
|
||||
{
|
||||
return m_server;
|
||||
}
|
||||
|
||||
const QString &Device::getSerial()
|
||||
{
|
||||
return m_params.serial;
|
||||
}
|
||||
|
||||
void Device::updateScript(QString script)
|
||||
{
|
||||
if(m_controller){
|
||||
|
|
|
@ -35,7 +35,9 @@ public:
|
|||
|
||||
VideoForm *getVideoForm();
|
||||
Controller *getController();
|
||||
FileHandler *getFileHandler();
|
||||
Server *getServer();
|
||||
const QString &getSerial();
|
||||
|
||||
void updateScript(QString script);
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include "toolform.h"
|
||||
#include "ui_toolform.h"
|
||||
#include "iconhelper.h"
|
||||
#include "device.h"
|
||||
#include "videoform.h"
|
||||
#include "controller.h"
|
||||
#include "adbprocess.h"
|
||||
|
@ -18,8 +19,6 @@ ToolForm::ToolForm(QWidget* adsorbWidget, AdsorbPositions adsorbPos)
|
|||
setWindowFlags(windowFlags() | Qt::FramelessWindowHint);
|
||||
//setWindowFlags(windowFlags() & ~Qt::WindowMinMaxButtonsHint);
|
||||
|
||||
m_videoForm = dynamic_cast<VideoForm*>(adsorbWidget);
|
||||
|
||||
initStyle();
|
||||
}
|
||||
|
||||
|
@ -28,6 +27,11 @@ ToolForm::~ToolForm()
|
|||
delete ui;
|
||||
}
|
||||
|
||||
void ToolForm::setDevice(Device *device)
|
||||
{
|
||||
m_device = device;
|
||||
}
|
||||
|
||||
void ToolForm::initStyle()
|
||||
{
|
||||
IconHelper::Instance()->SetIcon(ui->fullScreenBtn, QChar(0xf0b2), 15);
|
||||
|
@ -43,6 +47,19 @@ void ToolForm::initStyle()
|
|||
IconHelper::Instance()->SetIcon(ui->expandNotifyBtn, QChar(0xf103), 15);
|
||||
IconHelper::Instance()->SetIcon(ui->screenShotBtn, QChar(0xf0c4), 15);
|
||||
IconHelper::Instance()->SetIcon(ui->touchBtn, QChar(0xf111), 15);
|
||||
IconHelper::Instance()->SetIcon(ui->groupControlBtn, QChar(0xf0c0), 15);
|
||||
}
|
||||
|
||||
void ToolForm::updateGroupControl()
|
||||
{
|
||||
if (!m_device || !m_device->getVideoForm()) {
|
||||
return;
|
||||
}
|
||||
if (m_device->getVideoForm()->mainControl()) {
|
||||
ui->groupControlBtn->setStyleSheet("color: red");
|
||||
} else {
|
||||
ui->groupControlBtn->setStyleSheet("color: #DCDCDC");
|
||||
}
|
||||
}
|
||||
|
||||
void ToolForm::mousePressEvent(QMouseEvent *event)
|
||||
|
@ -80,44 +97,50 @@ void ToolForm::hideEvent(QHideEvent *event)
|
|||
|
||||
void ToolForm::on_fullScreenBtn_clicked()
|
||||
{
|
||||
if (m_videoForm) {
|
||||
m_videoForm->switchFullScreen();
|
||||
if (!m_device || !m_device->getVideoForm()) {
|
||||
return;
|
||||
}
|
||||
m_device->getVideoForm()->switchFullScreen();
|
||||
}
|
||||
|
||||
void ToolForm::on_returnBtn_clicked()
|
||||
{
|
||||
if (m_videoForm && m_videoForm->getController()) {
|
||||
m_videoForm->getController()->postGoBack();
|
||||
if (!m_device || !m_device->getController()) {
|
||||
return;
|
||||
}
|
||||
m_device->getController()->postGoBack();
|
||||
}
|
||||
|
||||
void ToolForm::on_homeBtn_clicked()
|
||||
{
|
||||
if (m_videoForm && m_videoForm->getController()) {
|
||||
m_videoForm->getController()->postGoHome();
|
||||
if (!m_device || !m_device->getController()) {
|
||||
return;
|
||||
}
|
||||
m_device->getController()->postGoHome();
|
||||
}
|
||||
|
||||
void ToolForm::on_menuBtn_clicked()
|
||||
{
|
||||
if (m_videoForm && m_videoForm->getController()) {
|
||||
m_videoForm->getController()->postGoMenu();
|
||||
if (!m_device || !m_device->getController()) {
|
||||
return;
|
||||
}
|
||||
m_device->getController()->postGoMenu();
|
||||
}
|
||||
|
||||
void ToolForm::on_appSwitchBtn_clicked()
|
||||
{
|
||||
if (m_videoForm && m_videoForm->getController()) {
|
||||
m_videoForm->getController()->postAppSwitch();
|
||||
if (!m_device || !m_device->getController()) {
|
||||
return;
|
||||
}
|
||||
m_device->getController()->postAppSwitch();
|
||||
}
|
||||
|
||||
void ToolForm::on_powerBtn_clicked()
|
||||
{
|
||||
if (m_videoForm && m_videoForm->getController()) {
|
||||
m_videoForm->getController()->postPower();
|
||||
if (!m_device || !m_device->getController()) {
|
||||
return;
|
||||
}
|
||||
m_device->getController()->postPower();
|
||||
}
|
||||
|
||||
void ToolForm::on_screenShotBtn_clicked()
|
||||
|
@ -127,35 +150,39 @@ void ToolForm::on_screenShotBtn_clicked()
|
|||
|
||||
void ToolForm::on_volumeUpBtn_clicked()
|
||||
{
|
||||
if (m_videoForm && m_videoForm->getController()) {
|
||||
m_videoForm->getController()->postVolumeUp();
|
||||
if (!m_device || !m_device->getController()) {
|
||||
return;
|
||||
}
|
||||
m_device->getController()->postVolumeUp();
|
||||
}
|
||||
|
||||
void ToolForm::on_volumeDownBtn_clicked()
|
||||
{
|
||||
if (m_videoForm && m_videoForm->getController()) {
|
||||
m_videoForm->getController()->postVolumeDown();
|
||||
if (!m_device || !m_device->getController()) {
|
||||
return;
|
||||
}
|
||||
m_device->getController()->postVolumeDown();
|
||||
}
|
||||
|
||||
void ToolForm::on_closeScreenBtn_clicked()
|
||||
{
|
||||
if (m_videoForm && m_videoForm->getController()) {
|
||||
m_videoForm->getController()->setScreenPowerMode(ControlMsg::SPM_OFF);
|
||||
if (!m_device || !m_device->getController()) {
|
||||
return;
|
||||
}
|
||||
m_device->getController()->setScreenPowerMode(ControlMsg::SPM_OFF);
|
||||
}
|
||||
|
||||
void ToolForm::on_expandNotifyBtn_clicked()
|
||||
{
|
||||
if (m_videoForm && m_videoForm->getController()) {
|
||||
m_videoForm->getController()->expandNotificationPanel();
|
||||
if (!m_device || !m_device->getController()) {
|
||||
return;
|
||||
}
|
||||
m_device->getController()->expandNotificationPanel();
|
||||
}
|
||||
|
||||
void ToolForm::on_touchBtn_clicked()
|
||||
{
|
||||
if (!m_videoForm) {
|
||||
if (!m_device) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -170,7 +197,16 @@ void ToolForm::on_touchBtn_clicked()
|
|||
sender()->deleteLater();
|
||||
}
|
||||
});
|
||||
adb->setShowTouchesEnabled(m_videoForm->getSerial(), m_showTouch);
|
||||
adb->setShowTouchesEnabled(m_device->getSerial(), m_showTouch);
|
||||
|
||||
qInfo() << "show touch " << (m_showTouch ? "enable" : "disable");
|
||||
}
|
||||
|
||||
void ToolForm::on_groupControlBtn_clicked()
|
||||
{
|
||||
if (!m_device || !m_device->getVideoForm()) {
|
||||
return;
|
||||
}
|
||||
m_device->getVideoForm()->setMainControl(!m_device->getVideoForm()->mainControl());
|
||||
updateGroupControl();
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace Ui {
|
|||
class ToolForm;
|
||||
}
|
||||
|
||||
class VideoForm;
|
||||
class Device;
|
||||
class ToolForm : public MagneticWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@ -19,6 +19,8 @@ public:
|
|||
explicit ToolForm(QWidget* adsorbWidget, AdsorbPositions adsorbPos);
|
||||
~ToolForm();
|
||||
|
||||
void setDevice(Device *device);
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QMouseEvent *event);
|
||||
void mouseReleaseEvent(QMouseEvent *event);
|
||||
|
@ -55,13 +57,16 @@ private slots:
|
|||
|
||||
void on_touchBtn_clicked();
|
||||
|
||||
void on_groupControlBtn_clicked();
|
||||
|
||||
private:
|
||||
void initStyle();
|
||||
void updateGroupControl();
|
||||
|
||||
private:
|
||||
Ui::ToolForm *ui;
|
||||
QPoint m_dragPosition;
|
||||
QPointer<VideoForm> m_videoForm;
|
||||
QPointer<Device> m_device;
|
||||
bool m_showTouch = false;
|
||||
};
|
||||
|
||||
|
|
|
@ -20,6 +20,13 @@
|
|||
<property name="topMargin">
|
||||
<number>30</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QPushButton" name="groupControlBtn">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="fullScreenBtn">
|
||||
<property name="toolTip">
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include "ui_videoform.h"
|
||||
#include "iconhelper.h"
|
||||
#include "toolform.h"
|
||||
#include "device.h"
|
||||
#include "controller.h"
|
||||
#include "filehandler.h"
|
||||
#include "config.h"
|
||||
|
@ -98,6 +99,7 @@ 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);
|
||||
|
@ -253,39 +255,38 @@ void VideoForm::staysOnTop(bool top)
|
|||
}
|
||||
}
|
||||
|
||||
Controller *VideoForm::getController()
|
||||
Device *VideoForm::getDevice()
|
||||
{
|
||||
return m_controller;
|
||||
return m_device;
|
||||
}
|
||||
|
||||
void VideoForm::setFileHandler(FileHandler *fileHandler)
|
||||
void VideoForm::setMainControl(bool mainControl)
|
||||
{
|
||||
m_fileHandler = fileHandler;
|
||||
if (m_mainControl == mainControl) {
|
||||
return;
|
||||
}
|
||||
m_mainControl = mainControl;
|
||||
emit mainControlChange(this, m_mainControl);
|
||||
}
|
||||
|
||||
void VideoForm::setSerial(const QString &serial)
|
||||
bool VideoForm::mainControl()
|
||||
{
|
||||
m_serial = serial;
|
||||
return m_mainControl;
|
||||
}
|
||||
|
||||
const QString &VideoForm::getSerial()
|
||||
void VideoForm::setDevice(Device *device)
|
||||
{
|
||||
return m_serial;
|
||||
}
|
||||
|
||||
void VideoForm::setController(Controller *controller)
|
||||
{
|
||||
m_controller = controller;
|
||||
m_device = device;
|
||||
}
|
||||
|
||||
void VideoForm::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
if (m_videoWidget->geometry().contains(event->pos())) {
|
||||
if (!m_controller) {
|
||||
if (!m_device || !m_device->getController()) {
|
||||
return;
|
||||
}
|
||||
event->setLocalPos(m_videoWidget->mapFrom(this, event->localPos().toPoint()));
|
||||
m_controller->mouseEvent(event, m_videoWidget->frameSize(), m_videoWidget->size());
|
||||
m_device->getController()->mouseEvent(event, m_videoWidget->frameSize(), m_videoWidget->size());
|
||||
} else {
|
||||
if (event->button() == Qt::LeftButton) {
|
||||
m_dragPosition = event->globalPos() - frameGeometry().topLeft();
|
||||
|
@ -297,7 +298,7 @@ void VideoForm::mousePressEvent(QMouseEvent *event)
|
|||
void VideoForm::mouseReleaseEvent(QMouseEvent *event)
|
||||
{
|
||||
if (m_dragPosition.isNull()) {
|
||||
if (!m_controller) {
|
||||
if (!m_device || !m_device->getController()) {
|
||||
return;
|
||||
}
|
||||
event->setLocalPos(m_videoWidget->mapFrom(this, event->localPos().toPoint()));
|
||||
|
@ -316,7 +317,7 @@ void VideoForm::mouseReleaseEvent(QMouseEvent *event)
|
|||
local.setY(m_videoWidget->height());
|
||||
}
|
||||
event->setLocalPos(local);
|
||||
m_controller->mouseEvent(event, m_videoWidget->frameSize(), m_videoWidget->size());
|
||||
m_device->getController()->mouseEvent(event, m_videoWidget->frameSize(), m_videoWidget->size());
|
||||
} else {
|
||||
m_dragPosition = QPoint(0, 0);
|
||||
}
|
||||
|
@ -325,11 +326,11 @@ void VideoForm::mouseReleaseEvent(QMouseEvent *event)
|
|||
void VideoForm::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
if (m_videoWidget->geometry().contains(event->pos())) {
|
||||
if (!m_controller) {
|
||||
if (!m_device || !m_device->getController()) {
|
||||
return;
|
||||
}
|
||||
event->setLocalPos(m_videoWidget->mapFrom(this, event->localPos().toPoint()));
|
||||
m_controller->mouseEvent(event, m_videoWidget->frameSize(), m_videoWidget->size());
|
||||
m_device->getController()->mouseEvent(event, m_videoWidget->frameSize(), m_videoWidget->size());
|
||||
} else if (!m_dragPosition.isNull()){
|
||||
if (event->buttons() & Qt::LeftButton) {
|
||||
move(event->globalPos() - m_dragPosition);
|
||||
|
@ -341,7 +342,7 @@ void VideoForm::mouseMoveEvent(QMouseEvent *event)
|
|||
void VideoForm::wheelEvent(QWheelEvent *event)
|
||||
{
|
||||
if (m_videoWidget->geometry().contains(event->pos())) {
|
||||
if (!m_controller) {
|
||||
if (!m_device || !m_device->getController()) {
|
||||
return;
|
||||
}
|
||||
QPointF pos = m_videoWidget->mapFrom(this, event->pos());
|
||||
|
@ -352,7 +353,7 @@ void VideoForm::wheelEvent(QWheelEvent *event)
|
|||
*/
|
||||
QWheelEvent wheelEvent(pos, event->globalPosF(), event->delta(),
|
||||
event->buttons(), event->modifiers(), event->orientation());
|
||||
m_controller->wheelEvent(&wheelEvent, m_videoWidget->frameSize(), m_videoWidget->size());
|
||||
m_device->getController()->wheelEvent(&wheelEvent, m_videoWidget->frameSize(), m_videoWidget->size());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -363,30 +364,30 @@ void VideoForm::keyPressEvent(QKeyEvent *event)
|
|||
&& isFullScreen()) {
|
||||
switchFullScreen();
|
||||
}
|
||||
if (!m_controller) {
|
||||
if (!m_device || !m_device->getController()) {
|
||||
return;
|
||||
}
|
||||
if (event->key() == Qt::Key_C && (event->modifiers() & Qt::ControlModifier)) {
|
||||
m_controller->requestDeviceClipboard();
|
||||
m_device->getController()->requestDeviceClipboard();
|
||||
}
|
||||
if (event->key() == Qt::Key_V && (event->modifiers() & Qt::ControlModifier)) {
|
||||
if (event->modifiers() & Qt::ShiftModifier) {
|
||||
m_controller->setDeviceClipboard();
|
||||
m_device->getController()->setDeviceClipboard();
|
||||
} else {
|
||||
m_controller->clipboardPaste();
|
||||
m_device->getController()->clipboardPaste();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
m_controller->keyEvent(event, m_videoWidget->frameSize(), m_videoWidget->size());
|
||||
m_device->getController()->keyEvent(event, m_videoWidget->frameSize(), m_videoWidget->size());
|
||||
}
|
||||
|
||||
void VideoForm::keyReleaseEvent(QKeyEvent *event)
|
||||
{
|
||||
if (!m_controller) {
|
||||
if (!m_device || !m_device->getController()) {
|
||||
return;
|
||||
}
|
||||
m_controller->keyEvent(event, m_videoWidget->frameSize(), m_videoWidget->size());
|
||||
m_device->getController()->keyEvent(event, m_videoWidget->frameSize(), m_videoWidget->size());
|
||||
}
|
||||
|
||||
void VideoForm::paintEvent(QPaintEvent *paint)
|
||||
|
@ -449,7 +450,7 @@ void VideoForm::dragLeaveEvent(QDragLeaveEvent *event)
|
|||
|
||||
void VideoForm::dropEvent(QDropEvent *event)
|
||||
{
|
||||
if (!m_fileHandler) {
|
||||
if (!m_device || !m_device->getFileHandler()) {
|
||||
return;
|
||||
}
|
||||
const QMimeData* qm = event->mimeData();
|
||||
|
@ -462,8 +463,8 @@ void VideoForm::dropEvent(QDropEvent *event)
|
|||
}
|
||||
|
||||
if (fileInfo.isFile() && fileInfo.suffix() == "apk") {
|
||||
m_fileHandler->installApkRequest(m_serial, file);
|
||||
m_device->getFileHandler()->installApkRequest(m_device->getSerial(), file);
|
||||
return;
|
||||
}
|
||||
m_fileHandler->pushFileRequest(m_serial, file, Config::getInstance().getPushFilePath() + fileInfo.fileName());
|
||||
m_device->getFileHandler()->pushFileRequest(m_device->getSerial(), file, Config::getInstance().getPushFilePath() + fileInfo.fileName());
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ class videoForm;
|
|||
|
||||
struct AVFrame;
|
||||
class ToolForm;
|
||||
class Controller;
|
||||
class Device;
|
||||
class FileHandler;
|
||||
class QYUVOpenGLWidget;
|
||||
class VideoForm : public QWidget
|
||||
|
@ -24,14 +24,14 @@ public:
|
|||
void staysOnTop(bool top = true);
|
||||
void updateShowSize(const QSize &newSize);
|
||||
void updateRender(const AVFrame *frame);
|
||||
void setController(Controller *controller);
|
||||
Controller* getController();
|
||||
void setFileHandler(FileHandler *fileHandler);
|
||||
void setSerial(const QString &serial);
|
||||
const QString& getSerial();
|
||||
void setDevice(Device *device);
|
||||
Device* getDevice();
|
||||
void setMainControl(bool mainControl);
|
||||
bool mainControl();
|
||||
|
||||
signals:
|
||||
void screenshot();
|
||||
void mainControlChange(VideoForm* videoFrom, bool mainControl);
|
||||
|
||||
public slots:
|
||||
void onGrabCursor(bool grab);
|
||||
|
@ -74,11 +74,10 @@ private:
|
|||
float m_widthHeightRatio = 0.5f;
|
||||
bool m_skin = true;
|
||||
QPoint m_fullScreenBeforePos;
|
||||
bool m_mainControl = false;
|
||||
|
||||
//outside member
|
||||
QString m_serial = "";
|
||||
QPointer<Controller> m_controller;
|
||||
QPointer<FileHandler> m_fileHandler;
|
||||
QPointer<Device> m_device;
|
||||
};
|
||||
|
||||
#endif // VIDEOFORM_H
|
||||
|
|
Loading…
Add table
Reference in a new issue