From 16497cab0df41364a9f6934fa0e52086a394a15d Mon Sep 17 00:00:00 2001 From: rankun Date: Tue, 17 Sep 2019 00:27:38 +0800 Subject: [PATCH] feat: skin 1 --- QtScrcpy/device/device.cpp | 7 ++++++ QtScrcpy/device/ui/videoform.cpp | 43 ++++++++++++++++++++------------ QtScrcpy/device/ui/videoform.h | 3 ++- QtScrcpy/device/ui/videoform.ui | 8 +++--- 4 files changed, 40 insertions(+), 21 deletions(-) diff --git a/QtScrcpy/device/device.cpp b/QtScrcpy/device/device.cpp index 87ffe34..5567f45 100644 --- a/QtScrcpy/device/device.cpp +++ b/QtScrcpy/device/device.cpp @@ -27,6 +27,7 @@ Device::Device(DeviceParams params, QObject *parent) m_decoder = new Decoder(m_vb, this); m_fileHandler = new FileHandler(this); m_controller = new Controller(params.gameScript, this); + //m_videoForm = new VideoForm(false); m_videoForm = new VideoForm(); m_videoForm->setSerial(m_params.serial); if (m_controller) { @@ -94,6 +95,12 @@ void Device::initSignals() if (m_controller && m_videoForm) { connect(m_controller, &Controller::grabCursor, m_videoForm, &VideoForm::onGrabCursor); } + if (m_videoForm) { + connect(m_videoForm, &VideoForm::destroyed, this, [this](QObject *obj){ + Q_UNUSED(obj); + deleteLater(); + }); + } if (m_fileHandler) { connect(m_fileHandler, &FileHandler::fileHandlerResult, this, [this](FileHandler::FILE_HANDLER_RESULT processResult, bool isApk){ QString tips = ""; diff --git a/QtScrcpy/device/ui/videoform.cpp b/QtScrcpy/device/ui/videoform.cpp index a558414..18fbff4 100644 --- a/QtScrcpy/device/ui/videoform.cpp +++ b/QtScrcpy/device/ui/videoform.cpp @@ -21,15 +21,18 @@ extern "C" #include "libavutil/frame.h" } -VideoForm::VideoForm(QWidget *parent) : - QWidget(parent), - ui(new Ui::videoForm) +VideoForm::VideoForm(bool skin, QWidget *parent) + : QWidget(parent) + , ui(new Ui::videoForm) + , m_skin(skin) { ui->setupUi(this); initUI(); updateShowSize(size()); bool vertical = size().height() > size().width(); - updateStyleSheet(vertical); + if (m_skin) { + updateStyleSheet(vertical); + } } VideoForm::~VideoForm() @@ -40,18 +43,20 @@ VideoForm::~VideoForm() void VideoForm::initUI() { setAttribute(Qt::WA_DeleteOnClose); - QPixmap phone; - if (phone.load(":/res/phone.png")) { - m_widthHeightRatio = 1.0f * phone.width() / phone.height(); - } + if (m_skin) { + QPixmap phone; + if (phone.load(":/res/phone.png")) { + m_widthHeightRatio = 1.0f * phone.width() / phone.height(); + } - // mac下去掉标题栏影响showfullscreen #ifndef Q_OS_OSX - // 去掉标题栏 - setWindowFlags(windowFlags() | Qt::FramelessWindowHint); - // 根据图片构造异形窗口 - setAttribute(Qt::WA_TranslucentBackground); + // mac下去掉标题栏影响showfullscreen + // 去掉标题栏 + setWindowFlags(windowFlags() | Qt::FramelessWindowHint); + // 根据图片构造异形窗口 + setAttribute(Qt::WA_TranslucentBackground); #endif + } setMouseTracking(true); ui->videoWidget->setMouseTracking(true); @@ -167,7 +172,9 @@ void VideoForm::updateShowSize(const QSize &newSize) #else resize(showSize); #endif - updateStyleSheet(vertical); + if (m_skin) { + updateStyleSheet(vertical); + } } } } @@ -181,7 +188,9 @@ void VideoForm::switchFullScreen() //setWindowFlags(windowFlags() | Qt::FramelessWindowHint); //show(); #endif - updateStyleSheet(height() > width()); + if (m_skin) { + updateStyleSheet(height() > width()); + } showToolForm(true); #ifdef Q_OS_WIN32 ::SetThreadExecutionState(ES_CONTINUOUS); @@ -193,7 +202,9 @@ void VideoForm::switchFullScreen() //setWindowFlags(windowFlags() & ~Qt::FramelessWindowHint); #endif showToolForm(false); - layout()->setContentsMargins(0, 0, 0, 0); + if (m_skin) { + layout()->setContentsMargins(0, 0, 0, 0); + } showFullScreen(); // 全屏状态禁止电脑休眠、息屏 diff --git a/QtScrcpy/device/ui/videoform.h b/QtScrcpy/device/ui/videoform.h index d817115..31229d8 100644 --- a/QtScrcpy/device/ui/videoform.h +++ b/QtScrcpy/device/ui/videoform.h @@ -16,7 +16,7 @@ class VideoForm : public QWidget { Q_OBJECT public: - explicit VideoForm(QWidget *parent = 0); + explicit VideoForm(bool skin = true, QWidget *parent = 0); ~VideoForm(); void switchFullScreen(); @@ -65,6 +65,7 @@ private: QSize m_frameSize; QPoint m_dragPosition; float m_widthHeightRatio = 0.5f; + bool m_skin = true; //outside member QString m_serial = ""; diff --git a/QtScrcpy/device/ui/videoform.ui b/QtScrcpy/device/ui/videoform.ui index 9c393cc..e0e2230 100644 --- a/QtScrcpy/device/ui/videoform.ui +++ b/QtScrcpy/device/ui/videoform.ui @@ -27,16 +27,16 @@ 0 - 10 + 0 - 68 + 0 - 12 + 0 - 62 + 0