refactor: videoForm Device ToolForm

This commit is contained in:
rankun 2020-03-03 10:37:13 +08:00
commit 4de26c7577
7 changed files with 127 additions and 73 deletions

View file

@ -35,13 +35,7 @@ Device::Device(DeviceParams params, QObject *parent)
m_fileHandler = new FileHandler(this); m_fileHandler = new FileHandler(this);
m_controller = new Controller(params.gameScript, this); m_controller = new Controller(params.gameScript, this);
m_videoForm = new VideoForm(Config::getInstance().getSkin()); m_videoForm = new VideoForm(Config::getInstance().getSkin());
m_videoForm->setSerial(m_params.serial); m_videoForm->setDevice(this);
if (m_controller) {
m_videoForm->setController(m_controller);
}
if (m_fileHandler) {
m_videoForm->setFileHandler(m_fileHandler);
}
m_videoForm->show(); m_videoForm->show();
} }
@ -91,11 +85,21 @@ Controller *Device::getController()
return m_controller; return m_controller;
} }
FileHandler *Device::getFileHandler()
{
return m_fileHandler;
}
Server *Device::getServer() Server *Device::getServer()
{ {
return m_server; return m_server;
} }
const QString &Device::getSerial()
{
return m_params.serial;
}
void Device::updateScript(QString script) void Device::updateScript(QString script)
{ {
if(m_controller){ if(m_controller){

View file

@ -35,7 +35,9 @@ public:
VideoForm *getVideoForm(); VideoForm *getVideoForm();
Controller *getController(); Controller *getController();
FileHandler *getFileHandler();
Server *getServer(); Server *getServer();
const QString &getSerial();
void updateScript(QString script); void updateScript(QString script);

View file

@ -6,6 +6,7 @@
#include "toolform.h" #include "toolform.h"
#include "ui_toolform.h" #include "ui_toolform.h"
#include "iconhelper.h" #include "iconhelper.h"
#include "device.h"
#include "videoform.h" #include "videoform.h"
#include "controller.h" #include "controller.h"
#include "adbprocess.h" #include "adbprocess.h"
@ -18,8 +19,6 @@ ToolForm::ToolForm(QWidget* adsorbWidget, AdsorbPositions adsorbPos)
setWindowFlags(windowFlags() | Qt::FramelessWindowHint); setWindowFlags(windowFlags() | Qt::FramelessWindowHint);
//setWindowFlags(windowFlags() & ~Qt::WindowMinMaxButtonsHint); //setWindowFlags(windowFlags() & ~Qt::WindowMinMaxButtonsHint);
m_videoForm = dynamic_cast<VideoForm*>(adsorbWidget);
initStyle(); initStyle();
} }
@ -28,6 +27,11 @@ ToolForm::~ToolForm()
delete ui; delete ui;
} }
void ToolForm::setDevice(Device *device)
{
m_device = device;
}
void ToolForm::initStyle() void ToolForm::initStyle()
{ {
IconHelper::Instance()->SetIcon(ui->fullScreenBtn, QChar(0xf0b2), 15); 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->expandNotifyBtn, QChar(0xf103), 15);
IconHelper::Instance()->SetIcon(ui->screenShotBtn, QChar(0xf0c4), 15); IconHelper::Instance()->SetIcon(ui->screenShotBtn, QChar(0xf0c4), 15);
IconHelper::Instance()->SetIcon(ui->touchBtn, QChar(0xf111), 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) void ToolForm::mousePressEvent(QMouseEvent *event)
@ -80,44 +97,50 @@ void ToolForm::hideEvent(QHideEvent *event)
void ToolForm::on_fullScreenBtn_clicked() void ToolForm::on_fullScreenBtn_clicked()
{ {
if (m_videoForm) { if (!m_device || !m_device->getVideoForm()) {
m_videoForm->switchFullScreen(); return;
} }
m_device->getVideoForm()->switchFullScreen();
} }
void ToolForm::on_returnBtn_clicked() void ToolForm::on_returnBtn_clicked()
{ {
if (m_videoForm && m_videoForm->getController()) { if (!m_device || !m_device->getController()) {
m_videoForm->getController()->postGoBack(); return;
} }
m_device->getController()->postGoBack();
} }
void ToolForm::on_homeBtn_clicked() void ToolForm::on_homeBtn_clicked()
{ {
if (m_videoForm && m_videoForm->getController()) { if (!m_device || !m_device->getController()) {
m_videoForm->getController()->postGoHome(); return;
} }
m_device->getController()->postGoHome();
} }
void ToolForm::on_menuBtn_clicked() void ToolForm::on_menuBtn_clicked()
{ {
if (m_videoForm && m_videoForm->getController()) { if (!m_device || !m_device->getController()) {
m_videoForm->getController()->postGoMenu(); return;
} }
m_device->getController()->postGoMenu();
} }
void ToolForm::on_appSwitchBtn_clicked() void ToolForm::on_appSwitchBtn_clicked()
{ {
if (m_videoForm && m_videoForm->getController()) { if (!m_device || !m_device->getController()) {
m_videoForm->getController()->postAppSwitch(); return;
} }
m_device->getController()->postAppSwitch();
} }
void ToolForm::on_powerBtn_clicked() void ToolForm::on_powerBtn_clicked()
{ {
if (m_videoForm && m_videoForm->getController()) { if (!m_device || !m_device->getController()) {
m_videoForm->getController()->postPower(); return;
} }
m_device->getController()->postPower();
} }
void ToolForm::on_screenShotBtn_clicked() void ToolForm::on_screenShotBtn_clicked()
@ -127,35 +150,39 @@ void ToolForm::on_screenShotBtn_clicked()
void ToolForm::on_volumeUpBtn_clicked() void ToolForm::on_volumeUpBtn_clicked()
{ {
if (m_videoForm && m_videoForm->getController()) { if (!m_device || !m_device->getController()) {
m_videoForm->getController()->postVolumeUp(); return;
} }
m_device->getController()->postVolumeUp();
} }
void ToolForm::on_volumeDownBtn_clicked() void ToolForm::on_volumeDownBtn_clicked()
{ {
if (m_videoForm && m_videoForm->getController()) { if (!m_device || !m_device->getController()) {
m_videoForm->getController()->postVolumeDown(); return;
} }
m_device->getController()->postVolumeDown();
} }
void ToolForm::on_closeScreenBtn_clicked() void ToolForm::on_closeScreenBtn_clicked()
{ {
if (m_videoForm && m_videoForm->getController()) { if (!m_device || !m_device->getController()) {
m_videoForm->getController()->setScreenPowerMode(ControlMsg::SPM_OFF); return;
} }
m_device->getController()->setScreenPowerMode(ControlMsg::SPM_OFF);
} }
void ToolForm::on_expandNotifyBtn_clicked() void ToolForm::on_expandNotifyBtn_clicked()
{ {
if (m_videoForm && m_videoForm->getController()) { if (!m_device || !m_device->getController()) {
m_videoForm->getController()->expandNotificationPanel(); return;
} }
m_device->getController()->expandNotificationPanel();
} }
void ToolForm::on_touchBtn_clicked() void ToolForm::on_touchBtn_clicked()
{ {
if (!m_videoForm) { if (!m_device) {
return; return;
} }
@ -170,7 +197,16 @@ void ToolForm::on_touchBtn_clicked()
sender()->deleteLater(); sender()->deleteLater();
} }
}); });
adb->setShowTouchesEnabled(m_videoForm->getSerial(), m_showTouch); adb->setShowTouchesEnabled(m_device->getSerial(), m_showTouch);
qInfo() << "show touch " << (m_showTouch ? "enable" : "disable"); 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();
}

View file

@ -10,7 +10,7 @@ namespace Ui {
class ToolForm; class ToolForm;
} }
class VideoForm; class Device;
class ToolForm : public MagneticWidget class ToolForm : public MagneticWidget
{ {
Q_OBJECT Q_OBJECT
@ -19,6 +19,8 @@ public:
explicit ToolForm(QWidget* adsorbWidget, AdsorbPositions adsorbPos); explicit ToolForm(QWidget* adsorbWidget, AdsorbPositions adsorbPos);
~ToolForm(); ~ToolForm();
void setDevice(Device *device);
protected: protected:
void mousePressEvent(QMouseEvent *event); void mousePressEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event); void mouseReleaseEvent(QMouseEvent *event);
@ -55,13 +57,16 @@ private slots:
void on_touchBtn_clicked(); void on_touchBtn_clicked();
void on_groupControlBtn_clicked();
private: private:
void initStyle(); void initStyle();
void updateGroupControl();
private: private:
Ui::ToolForm *ui; Ui::ToolForm *ui;
QPoint m_dragPosition; QPoint m_dragPosition;
QPointer<VideoForm> m_videoForm; QPointer<Device> m_device;
bool m_showTouch = false; bool m_showTouch = false;
}; };

View file

@ -20,6 +20,13 @@
<property name="topMargin"> <property name="topMargin">
<number>30</number> <number>30</number>
</property> </property>
<item>
<widget class="QPushButton" name="groupControlBtn">
<property name="text">
<string/>
</property>
</widget>
</item>
<item> <item>
<widget class="QPushButton" name="fullScreenBtn"> <widget class="QPushButton" name="fullScreenBtn">
<property name="toolTip"> <property name="toolTip">

View file

@ -15,6 +15,7 @@
#include "ui_videoform.h" #include "ui_videoform.h"
#include "iconhelper.h" #include "iconhelper.h"
#include "toolform.h" #include "toolform.h"
#include "device.h"
#include "controller.h" #include "controller.h"
#include "filehandler.h" #include "filehandler.h"
#include "config.h" #include "config.h"
@ -98,6 +99,7 @@ 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);
connect(m_toolForm, &ToolForm::screenshot, this, &VideoForm::screenshot); 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);
@ -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; m_device = device;
}
void VideoForm::setController(Controller *controller)
{
m_controller = controller;
} }
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_controller) { if (!m_device || !m_device->getController()) {
return; return;
} }
event->setLocalPos(m_videoWidget->mapFrom(this, event->localPos().toPoint())); 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 { } else {
if (event->button() == Qt::LeftButton) { if (event->button() == Qt::LeftButton) {
m_dragPosition = event->globalPos() - frameGeometry().topLeft(); m_dragPosition = event->globalPos() - frameGeometry().topLeft();
@ -297,7 +298,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_controller) { if (!m_device || !m_device->getController()) {
return; return;
} }
event->setLocalPos(m_videoWidget->mapFrom(this, event->localPos().toPoint())); event->setLocalPos(m_videoWidget->mapFrom(this, event->localPos().toPoint()));
@ -316,7 +317,7 @@ void VideoForm::mouseReleaseEvent(QMouseEvent *event)
local.setY(m_videoWidget->height()); local.setY(m_videoWidget->height());
} }
event->setLocalPos(local); 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 { } else {
m_dragPosition = QPoint(0, 0); m_dragPosition = QPoint(0, 0);
} }
@ -325,11 +326,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_controller) { if (!m_device || !m_device->getController()) {
return; return;
} }
event->setLocalPos(m_videoWidget->mapFrom(this, event->localPos().toPoint())); 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()){ } 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);
@ -341,7 +342,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_controller) { if (!m_device || !m_device->getController()) {
return; return;
} }
QPointF pos = m_videoWidget->mapFrom(this, event->pos()); QPointF pos = m_videoWidget->mapFrom(this, event->pos());
@ -352,7 +353,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_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()) { && isFullScreen()) {
switchFullScreen(); switchFullScreen();
} }
if (!m_controller) { if (!m_device || !m_device->getController()) {
return; return;
} }
if (event->key() == Qt::Key_C && (event->modifiers() & Qt::ControlModifier)) { 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->key() == Qt::Key_V && (event->modifiers() & Qt::ControlModifier)) {
if (event->modifiers() & Qt::ShiftModifier) { if (event->modifiers() & Qt::ShiftModifier) {
m_controller->setDeviceClipboard(); m_device->getController()->setDeviceClipboard();
} else { } else {
m_controller->clipboardPaste(); m_device->getController()->clipboardPaste();
} }
return; 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) void VideoForm::keyReleaseEvent(QKeyEvent *event)
{ {
if (!m_controller) { if (!m_device || !m_device->getController()) {
return; 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) void VideoForm::paintEvent(QPaintEvent *paint)
@ -449,7 +450,7 @@ void VideoForm::dragLeaveEvent(QDragLeaveEvent *event)
void VideoForm::dropEvent(QDropEvent *event) void VideoForm::dropEvent(QDropEvent *event)
{ {
if (!m_fileHandler) { if (!m_device || !m_device->getFileHandler()) {
return; return;
} }
const QMimeData* qm = event->mimeData(); const QMimeData* qm = event->mimeData();
@ -462,8 +463,8 @@ void VideoForm::dropEvent(QDropEvent *event)
} }
if (fileInfo.isFile() && fileInfo.suffix() == "apk") { if (fileInfo.isFile() && fileInfo.suffix() == "apk") {
m_fileHandler->installApkRequest(m_serial, file); m_device->getFileHandler()->installApkRequest(m_device->getSerial(), file);
return; 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());
} }

View file

@ -10,7 +10,7 @@ class videoForm;
struct AVFrame; struct AVFrame;
class ToolForm; class ToolForm;
class Controller; class Device;
class FileHandler; class FileHandler;
class QYUVOpenGLWidget; class QYUVOpenGLWidget;
class VideoForm : public QWidget class VideoForm : public QWidget
@ -24,14 +24,14 @@ public:
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 setController(Controller *controller); void setDevice(Device *device);
Controller* getController(); Device* getDevice();
void setFileHandler(FileHandler *fileHandler); void setMainControl(bool mainControl);
void setSerial(const QString &serial); bool mainControl();
const QString& getSerial();
signals: signals:
void screenshot(); void screenshot();
void mainControlChange(VideoForm* videoFrom, bool mainControl);
public slots: public slots:
void onGrabCursor(bool grab); void onGrabCursor(bool grab);
@ -74,11 +74,10 @@ private:
float m_widthHeightRatio = 0.5f; float m_widthHeightRatio = 0.5f;
bool m_skin = true; bool m_skin = true;
QPoint m_fullScreenBeforePos; QPoint m_fullScreenBeforePos;
bool m_mainControl = false;
//outside member //outside member
QString m_serial = ""; QPointer<Device> m_device;
QPointer<Controller> m_controller;
QPointer<FileHandler> m_fileHandler;
}; };
#endif // VIDEOFORM_H #endif // VIDEOFORM_H