From 18c2db767c7cf3386110ac18d5ca977f68187e16 Mon Sep 17 00:00:00 2001 From: rankun Date: Sat, 29 Feb 2020 22:37:17 +0800 Subject: [PATCH] feat: set useskin=0 to default 1. set useskin=0 to default 2. fix fullscreen after pos change to (0,0) --- QtScrcpy/device/device.cpp | 1 - QtScrcpy/device/ui/videoform.cpp | 68 +++++++++++++++++--------------- QtScrcpy/device/ui/videoform.h | 3 +- config/config.ini | 2 +- 4 files changed, 40 insertions(+), 34 deletions(-) diff --git a/QtScrcpy/device/device.cpp b/QtScrcpy/device/device.cpp index 83e057f..9b4f0e5 100644 --- a/QtScrcpy/device/device.cpp +++ b/QtScrcpy/device/device.cpp @@ -163,7 +163,6 @@ void Device::initSignals() // update ui if (m_videoForm) { m_videoForm->setWindowTitle(deviceName); - m_videoForm->updateScreenRatio(size); m_videoForm->updateShowSize(size); } diff --git a/QtScrcpy/device/ui/videoform.cpp b/QtScrcpy/device/ui/videoform.cpp index 834703d..3c5dae7 100644 --- a/QtScrcpy/device/ui/videoform.cpp +++ b/QtScrcpy/device/ui/videoform.cpp @@ -98,6 +98,18 @@ void VideoForm::showToolForm(bool show) m_toolForm->setVisible(show); } +void VideoForm::moveCenter() +{ + QDesktopWidget* desktop = QApplication::desktop(); + if (!desktop) { + qWarning() << "QApplication::desktop() is nullptr"; + return; + } + QRect screenRect = desktop->availableGeometry(); + // 窗口居中 + move(screenRect.center() - QRect(0, 0, size().width(), size().height()).center()); +} + void VideoForm::updateStyleSheet(bool vertical) { if (vertical) { @@ -129,45 +141,35 @@ QMargins VideoForm::getMargins(bool vertical) return margins; } -void VideoForm::updateScreenRatio(const QSize &newSize) -{ - m_widthHeightRatio = 1.0f * qMin(newSize.width(),newSize.height()) / qMax(newSize.width(),newSize.height()); -} - void VideoForm::updateShowSize(const QSize &newSize) { if (m_frameSize != newSize) { m_frameSize = newSize; - bool vertical = newSize.height() > newSize.width(); + m_widthHeightRatio = 1.0f * newSize.width() / newSize.height(); + + bool vertical = m_widthHeightRatio < 1 ? true : false; QSize showSize = newSize; QDesktopWidget* desktop = QApplication::desktop(); - if (desktop) { - QRect screenRect = desktop->availableGeometry(); - if (vertical) { - showSize.setHeight(qMin(newSize.height(), screenRect.height() - 200)); - showSize.setWidth(showSize.height() * m_widthHeightRatio); - } else { - showSize.setWidth(qMin(newSize.width(), screenRect.width()/2)); - showSize.setHeight(showSize.width() * m_widthHeightRatio); - } - - if (isFullScreen()) { - switchFullScreen(); - } - if (m_skin) { - QMargins m = getMargins(vertical); - showSize.setWidth(showSize.width() + m.left() + m.right()); - showSize.setHeight(showSize.height() + m.top() + m.bottom()); - } - - // 窗口居中 - move(screenRect.center() - QRect(0, 0, showSize.width(), showSize.height()).center()); + if (!desktop) { + qWarning() << "QApplication::desktop() is nullptr"; + return; + } + QRect screenRect = desktop->availableGeometry(); + if (vertical) { + showSize.setHeight(qMin(newSize.height(), screenRect.height() - 200)); + showSize.setWidth(showSize.height() * m_widthHeightRatio); + } else { + showSize.setWidth(qMin(newSize.width(), screenRect.width()/2)); + showSize.setHeight(showSize.width() / m_widthHeightRatio); } - if (!m_skin) { - // 减去标题栏高度 - int titleBarHeight = style()->pixelMetric(QStyle::PM_TitleBarHeight); - showSize.setHeight(showSize.height() - titleBarHeight); + if (isFullScreen()) { + switchFullScreen(); + } + if (m_skin) { + QMargins m = getMargins(vertical); + showSize.setWidth(showSize.width() + m.left() + m.right()); + showSize.setHeight(showSize.height() + m.top() + m.bottom()); } if (showSize != size()) { @@ -175,6 +177,7 @@ void VideoForm::updateShowSize(const QSize &newSize) if (m_skin) { updateStyleSheet(vertical); } + moveCenter(); } } } @@ -183,6 +186,8 @@ void VideoForm::switchFullScreen() { if (isFullScreen()) { showNormal(); + // fullscreen window will move (0,0). qt bug? + move(m_fullScreenBeforePos); #ifdef Q_OS_OSX //setWindowFlags(windowFlags() | Qt::FramelessWindowHint); @@ -196,6 +201,7 @@ void VideoForm::switchFullScreen() ::SetThreadExecutionState(ES_CONTINUOUS); #endif } else { + m_fullScreenBeforePos = pos(); // 这种临时增加标题栏再全屏的方案会导致收不到mousemove事件,导致setmousetrack失效 // mac fullscreen must show title bar #ifdef Q_OS_OSX diff --git a/QtScrcpy/device/ui/videoform.h b/QtScrcpy/device/ui/videoform.h index 782775d..7e52eab 100644 --- a/QtScrcpy/device/ui/videoform.h +++ b/QtScrcpy/device/ui/videoform.h @@ -21,7 +21,6 @@ public: void switchFullScreen(); void staysOnTop(bool top = true); - void updateScreenRatio(const QSize &newSize); void updateShowSize(const QSize &newSize); void updateRender(const AVFrame *frame); void setController(Controller *controller); @@ -42,6 +41,7 @@ private: void initUI(); void showToolForm(bool show = true); + void moveCenter(); protected: void mousePressEvent(QMouseEvent *event); @@ -70,6 +70,7 @@ private: QPoint m_dragPosition; float m_widthHeightRatio = 0.5f; bool m_skin = true; + QPoint m_fullScreenBeforePos; //outside member QString m_serial = ""; diff --git a/config/config.ini b/config/config.ini index d13d8cd..cce9f9a 100644 --- a/config/config.ini +++ b/config/config.ini @@ -1,4 +1,4 @@ -[common] +[common] # 窗口标题 WindowTitle=QtScrcpy # 录制文件保存路径(必须以/作为分隔符)