diff --git a/QtScrcpy/device/ui/videoform.cpp b/QtScrcpy/device/ui/videoform.cpp index 20c9602..c0b1bdf 100644 --- a/QtScrcpy/device/ui/videoform.cpp +++ b/QtScrcpy/device/ui/videoform.cpp @@ -66,8 +66,8 @@ void VideoForm::initUI() m_videoWidget = new QYUVOpenGLWidget(); m_videoWidget->hide(); - ui->keepRadioWidget->setWidget(m_videoWidget); - ui->keepRadioWidget->setWidthHeightRadio(m_widthHeightRatio); + ui->keepRatioWidget->setWidget(m_videoWidget); + ui->keepRatioWidget->setWidthHeightRatio(m_widthHeightRatio); m_fpsLabel = new QLabel(m_videoWidget); QFont ft; @@ -81,14 +81,14 @@ void VideoForm::initUI() setMouseTracking(true); m_videoWidget->setMouseTracking(true); - ui->keepRadioWidget->setMouseTracking(true); + ui->keepRatioWidget->setMouseTracking(true); } QRect VideoForm::getGrabCursorRect() { QRect rc; #if defined(Q_OS_WIN32) - rc = QRect(ui->keepRadioWidget->mapToGlobal(m_videoWidget->pos()), m_videoWidget->size()); + rc = QRect(ui->keepRatioWidget->mapToGlobal(m_videoWidget->pos()), m_videoWidget->size()); // high dpi support rc.setTopLeft(rc.topLeft() * m_videoWidget->devicePixelRatio()); rc.setBottomRight(rc.bottomRight() * m_videoWidget->devicePixelRatio()); @@ -99,15 +99,15 @@ QRect VideoForm::getGrabCursorRect() rc.setHeight(rc.height() - 20); #elif defined(Q_OS_OSX) rc = m_videoWidget->geometry(); - rc.setTopLeft(ui->keepRadioWidget->mapToGlobal(rc.topLeft())); - rc.setBottomRight(ui->keepRadioWidget->mapToGlobal(rc.bottomRight())); + rc.setTopLeft(ui->keepRatioWidget->mapToGlobal(rc.topLeft())); + rc.setBottomRight(ui->keepRatioWidget->mapToGlobal(rc.bottomRight())); rc.setX(rc.x() + 10); rc.setY(rc.y() + 10); rc.setWidth(rc.width() - 20); rc.setHeight(rc.height() - 20); #elif defined(Q_OS_LINUX) - rc = QRect(ui->keepRadioWidget->mapToGlobal(m_videoWidget->pos()), m_videoWidget->size()); + rc = QRect(ui->keepRatioWidget->mapToGlobal(m_videoWidget->pos()), m_videoWidget->size()); // high dpi support -- taken from the WIN32 section and untested rc.setTopLeft(rc.topLeft() * m_videoWidget->devicePixelRatio()); rc.setBottomRight(rc.bottomRight() * m_videoWidget->devicePixelRatio()); @@ -137,7 +137,7 @@ void VideoForm::resizeSquare() void VideoForm::removeBlackRect() { - resize(ui->keepRadioWidget->goodSize()); + resize(ui->keepRatioWidget->goodSize()); } void VideoForm::showFPS(bool show) @@ -380,7 +380,7 @@ void VideoForm::updateShowSize(const QSize &newSize) m_frameSize = newSize; m_widthHeightRatio = 1.0f * newSize.width() / newSize.height(); - ui->keepRadioWidget->setWidthHeightRadio(m_widthHeightRatio); + ui->keepRatioWidget->setWidthHeightRatio(m_widthHeightRatio); bool vertical = m_widthHeightRatio < 1.0f ? true : false; QSize showSize = newSize; @@ -426,7 +426,7 @@ void VideoForm::onSwitchFullScreen() if (isFullScreen()) { // 横屏全屏铺满全屏,恢复时,恢复保持宽高比 if (m_widthHeightRatio > 1.0f) { - ui->keepRadioWidget->setWidthHeightRadio(m_widthHeightRatio); + ui->keepRatioWidget->setWidthHeightRatio(m_widthHeightRatio); } showNormal(); @@ -447,7 +447,7 @@ void VideoForm::onSwitchFullScreen() } else { // 横屏全屏铺满全屏,不保持宽高比 if (m_widthHeightRatio > 1.0f) { - ui->keepRadioWidget->setWidthHeightRadio(-1.0f); + ui->keepRatioWidget->setWidthHeightRatio(-1.0f); } m_fullScreenBeforePos = pos(); @@ -646,12 +646,12 @@ void VideoForm::showEvent(QShowEvent *event) void VideoForm::resizeEvent(QResizeEvent *event) { Q_UNUSED(event) - QSize goodSize = ui->keepRadioWidget->goodSize(); + QSize goodSize = ui->keepRatioWidget->goodSize(); if (goodSize.isEmpty()) { return; } QSize curSize = size(); - // 限制VideoForm尺寸不能小于keepRadioWidget good size + // 限制VideoForm尺寸不能小于keepRatioWidget good size if (m_widthHeightRatio > 1.0f) { // hor if (curSize.height() <= goodSize.height()) { diff --git a/QtScrcpy/device/ui/videoform.ui b/QtScrcpy/device/ui/videoform.ui index 6de4468..405386d 100644 --- a/QtScrcpy/device/ui/videoform.ui +++ b/QtScrcpy/device/ui/videoform.ui @@ -39,15 +39,15 @@ 0 - + - KeepRadioWidget + KeepRatioWidget QWidget -
keepradiowidget.h
+
keepratiowidget.h
1
diff --git a/QtScrcpy/uibase/keepradiowidget.h b/QtScrcpy/uibase/keepradiowidget.h deleted file mode 100644 index ef0877a..0000000 --- a/QtScrcpy/uibase/keepradiowidget.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef KEEPRADIOWIDGET_H -#define KEEPRADIOWIDGET_H - -#include -#include - -class KeepRadioWidget : public QWidget -{ - Q_OBJECT -public: - explicit KeepRadioWidget(QWidget *parent = nullptr); - ~KeepRadioWidget(); - - void setWidget(QWidget *w); - void setWidthHeightRadio(float widthHeightRadio); - const QSize goodSize(); - -protected: - void resizeEvent(QResizeEvent *event); - void adjustSubWidget(); - -private: - float m_widthHeightRadio = -1.0f; - QPointer m_subWidget; - QSize m_goodSize; -}; - -#endif // KEEPRADIOWIDGET_H diff --git a/QtScrcpy/uibase/keepradiowidget.cpp b/QtScrcpy/uibase/keepratiowidget.cpp similarity index 53% rename from QtScrcpy/uibase/keepradiowidget.cpp rename to QtScrcpy/uibase/keepratiowidget.cpp index 4e88ab0..4f22b3e 100644 --- a/QtScrcpy/uibase/keepradiowidget.cpp +++ b/QtScrcpy/uibase/keepratiowidget.cpp @@ -1,13 +1,13 @@ #include #include -#include "keepradiowidget.h" +#include "keepratiowidget.h" -KeepRadioWidget::KeepRadioWidget(QWidget *parent) : QWidget(parent) {} +KeepRatioWidget::KeepRatioWidget(QWidget *parent) : QWidget(parent) {} -KeepRadioWidget::~KeepRadioWidget() {} +KeepRatioWidget::~KeepRatioWidget() {} -void KeepRadioWidget::setWidget(QWidget *w) +void KeepRatioWidget::setWidget(QWidget *w) { if (!w) { return; @@ -16,30 +16,30 @@ void KeepRadioWidget::setWidget(QWidget *w) m_subWidget = w; } -void KeepRadioWidget::setWidthHeightRadio(float widthHeightRadio) +void KeepRatioWidget::setWidthHeightRatio(float widthHeightRatio) { - if (fabs(m_widthHeightRadio - widthHeightRadio) < 0.000001f) { + if (fabs(m_widthHeightRatio - widthHeightRatio) < 0.000001f) { return; } - m_widthHeightRadio = widthHeightRadio; + m_widthHeightRatio = widthHeightRatio; adjustSubWidget(); } -const QSize KeepRadioWidget::goodSize() +const QSize KeepRatioWidget::goodSize() { - if (!m_subWidget || m_widthHeightRadio < 0.0f) { + if (!m_subWidget || m_widthHeightRatio < 0.0f) { return QSize(); } return m_subWidget->size(); } -void KeepRadioWidget::resizeEvent(QResizeEvent *event) +void KeepRatioWidget::resizeEvent(QResizeEvent *event) { Q_UNUSED(event) adjustSubWidget(); } -void KeepRadioWidget::adjustSubWidget() +void KeepRatioWidget::adjustSubWidget() { if (!m_subWidget) { return; @@ -49,15 +49,15 @@ void KeepRadioWidget::adjustSubWidget() QPoint pos(0, 0); int width = 0; int height = 0; - if (m_widthHeightRadio > 1.0f) { + if (m_widthHeightRatio > 1.0f) { // base width width = curSize.width(); - height = curSize.width() / m_widthHeightRadio; + height = curSize.width() / m_widthHeightRatio; pos.setY((curSize.height() - height) / 2); - } else if (m_widthHeightRadio > 0.0f) { + } else if (m_widthHeightRatio > 0.0f) { // base height height = curSize.height(); - width = curSize.height() * m_widthHeightRadio; + width = curSize.height() * m_widthHeightRatio; pos.setX((curSize.width() - width) / 2); } else { // full widget diff --git a/QtScrcpy/uibase/keepratiowidget.h b/QtScrcpy/uibase/keepratiowidget.h new file mode 100644 index 0000000..8cca3fe --- /dev/null +++ b/QtScrcpy/uibase/keepratiowidget.h @@ -0,0 +1,28 @@ +#ifndef KEEPRATIOWIDGET_H +#define KEEPRATIOWIDGET_H + +#include +#include + +class KeepRatioWidget : public QWidget +{ + Q_OBJECT +public: + explicit KeepRatioWidget(QWidget *parent = nullptr); + ~KeepRatioWidget(); + + void setWidget(QWidget *w); + void setWidthHeightRatio(float widthHeightRatio); + const QSize goodSize(); + +protected: + void resizeEvent(QResizeEvent *event); + void adjustSubWidget(); + +private: + float m_widthHeightRatio = -1.0f; + QPointer m_subWidget; + QSize m_goodSize; +}; + +#endif // KEEPRATIOWIDGET_H diff --git a/QtScrcpy/uibase/uibase.pri b/QtScrcpy/uibase/uibase.pri index ae4858b..cac526a 100644 --- a/QtScrcpy/uibase/uibase.pri +++ b/QtScrcpy/uibase/uibase.pri @@ -1,9 +1,9 @@ FORMS += HEADERS += \ - $$PWD/keepradiowidget.h \ + $$PWD/keepratiowidget.h \ $$PWD/magneticwidget.h SOURCES += \ - $$PWD/keepradiowidget.cpp \ + $$PWD/keepratiowidget.cpp \ $$PWD/magneticwidget.cpp