mirror of
https://github.com/barry-ran/QtScrcpy.git
synced 2025-08-03 14:18:45 +00:00
Fix a misspelling, keep radio
-> keep ratio
This commit is contained in:
parent
33deb958cf
commit
8e6488ae43
6 changed files with 61 additions and 61 deletions
|
@ -66,8 +66,8 @@ void VideoForm::initUI()
|
||||||
|
|
||||||
m_videoWidget = new QYUVOpenGLWidget();
|
m_videoWidget = new QYUVOpenGLWidget();
|
||||||
m_videoWidget->hide();
|
m_videoWidget->hide();
|
||||||
ui->keepRadioWidget->setWidget(m_videoWidget);
|
ui->keepRatioWidget->setWidget(m_videoWidget);
|
||||||
ui->keepRadioWidget->setWidthHeightRadio(m_widthHeightRatio);
|
ui->keepRatioWidget->setWidthHeightRatio(m_widthHeightRatio);
|
||||||
|
|
||||||
m_fpsLabel = new QLabel(m_videoWidget);
|
m_fpsLabel = new QLabel(m_videoWidget);
|
||||||
QFont ft;
|
QFont ft;
|
||||||
|
@ -81,14 +81,14 @@ void VideoForm::initUI()
|
||||||
|
|
||||||
setMouseTracking(true);
|
setMouseTracking(true);
|
||||||
m_videoWidget->setMouseTracking(true);
|
m_videoWidget->setMouseTracking(true);
|
||||||
ui->keepRadioWidget->setMouseTracking(true);
|
ui->keepRatioWidget->setMouseTracking(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
QRect VideoForm::getGrabCursorRect()
|
QRect VideoForm::getGrabCursorRect()
|
||||||
{
|
{
|
||||||
QRect rc;
|
QRect rc;
|
||||||
#if defined(Q_OS_WIN32)
|
#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
|
// high dpi support
|
||||||
rc.setTopLeft(rc.topLeft() * m_videoWidget->devicePixelRatio());
|
rc.setTopLeft(rc.topLeft() * m_videoWidget->devicePixelRatio());
|
||||||
rc.setBottomRight(rc.bottomRight() * m_videoWidget->devicePixelRatio());
|
rc.setBottomRight(rc.bottomRight() * m_videoWidget->devicePixelRatio());
|
||||||
|
@ -99,15 +99,15 @@ QRect VideoForm::getGrabCursorRect()
|
||||||
rc.setHeight(rc.height() - 20);
|
rc.setHeight(rc.height() - 20);
|
||||||
#elif defined(Q_OS_OSX)
|
#elif defined(Q_OS_OSX)
|
||||||
rc = m_videoWidget->geometry();
|
rc = m_videoWidget->geometry();
|
||||||
rc.setTopLeft(ui->keepRadioWidget->mapToGlobal(rc.topLeft()));
|
rc.setTopLeft(ui->keepRatioWidget->mapToGlobal(rc.topLeft()));
|
||||||
rc.setBottomRight(ui->keepRadioWidget->mapToGlobal(rc.bottomRight()));
|
rc.setBottomRight(ui->keepRatioWidget->mapToGlobal(rc.bottomRight()));
|
||||||
|
|
||||||
rc.setX(rc.x() + 10);
|
rc.setX(rc.x() + 10);
|
||||||
rc.setY(rc.y() + 10);
|
rc.setY(rc.y() + 10);
|
||||||
rc.setWidth(rc.width() - 20);
|
rc.setWidth(rc.width() - 20);
|
||||||
rc.setHeight(rc.height() - 20);
|
rc.setHeight(rc.height() - 20);
|
||||||
#elif defined(Q_OS_LINUX)
|
#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
|
// high dpi support -- taken from the WIN32 section and untested
|
||||||
rc.setTopLeft(rc.topLeft() * m_videoWidget->devicePixelRatio());
|
rc.setTopLeft(rc.topLeft() * m_videoWidget->devicePixelRatio());
|
||||||
rc.setBottomRight(rc.bottomRight() * m_videoWidget->devicePixelRatio());
|
rc.setBottomRight(rc.bottomRight() * m_videoWidget->devicePixelRatio());
|
||||||
|
@ -137,7 +137,7 @@ void VideoForm::resizeSquare()
|
||||||
|
|
||||||
void VideoForm::removeBlackRect()
|
void VideoForm::removeBlackRect()
|
||||||
{
|
{
|
||||||
resize(ui->keepRadioWidget->goodSize());
|
resize(ui->keepRatioWidget->goodSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
void VideoForm::showFPS(bool show)
|
void VideoForm::showFPS(bool show)
|
||||||
|
@ -380,7 +380,7 @@ void VideoForm::updateShowSize(const QSize &newSize)
|
||||||
m_frameSize = newSize;
|
m_frameSize = newSize;
|
||||||
|
|
||||||
m_widthHeightRatio = 1.0f * newSize.width() / newSize.height();
|
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;
|
bool vertical = m_widthHeightRatio < 1.0f ? true : false;
|
||||||
QSize showSize = newSize;
|
QSize showSize = newSize;
|
||||||
|
@ -426,7 +426,7 @@ void VideoForm::onSwitchFullScreen()
|
||||||
if (isFullScreen()) {
|
if (isFullScreen()) {
|
||||||
// 横屏全屏铺满全屏,恢复时,恢复保持宽高比
|
// 横屏全屏铺满全屏,恢复时,恢复保持宽高比
|
||||||
if (m_widthHeightRatio > 1.0f) {
|
if (m_widthHeightRatio > 1.0f) {
|
||||||
ui->keepRadioWidget->setWidthHeightRadio(m_widthHeightRatio);
|
ui->keepRatioWidget->setWidthHeightRatio(m_widthHeightRatio);
|
||||||
}
|
}
|
||||||
|
|
||||||
showNormal();
|
showNormal();
|
||||||
|
@ -447,7 +447,7 @@ void VideoForm::onSwitchFullScreen()
|
||||||
} else {
|
} else {
|
||||||
// 横屏全屏铺满全屏,不保持宽高比
|
// 横屏全屏铺满全屏,不保持宽高比
|
||||||
if (m_widthHeightRatio > 1.0f) {
|
if (m_widthHeightRatio > 1.0f) {
|
||||||
ui->keepRadioWidget->setWidthHeightRadio(-1.0f);
|
ui->keepRatioWidget->setWidthHeightRatio(-1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_fullScreenBeforePos = pos();
|
m_fullScreenBeforePos = pos();
|
||||||
|
@ -646,12 +646,12 @@ void VideoForm::showEvent(QShowEvent *event)
|
||||||
void VideoForm::resizeEvent(QResizeEvent *event)
|
void VideoForm::resizeEvent(QResizeEvent *event)
|
||||||
{
|
{
|
||||||
Q_UNUSED(event)
|
Q_UNUSED(event)
|
||||||
QSize goodSize = ui->keepRadioWidget->goodSize();
|
QSize goodSize = ui->keepRatioWidget->goodSize();
|
||||||
if (goodSize.isEmpty()) {
|
if (goodSize.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
QSize curSize = size();
|
QSize curSize = size();
|
||||||
// 限制VideoForm尺寸不能小于keepRadioWidget good size
|
// 限制VideoForm尺寸不能小于keepRatioWidget good size
|
||||||
if (m_widthHeightRatio > 1.0f) {
|
if (m_widthHeightRatio > 1.0f) {
|
||||||
// hor
|
// hor
|
||||||
if (curSize.height() <= goodSize.height()) {
|
if (curSize.height() <= goodSize.height()) {
|
||||||
|
|
|
@ -39,15 +39,15 @@
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<item>
|
<item>
|
||||||
<widget class="KeepRadioWidget" name="keepRadioWidget" native="true"/>
|
<widget class="KeepRatioWidget" name="keepRatioWidget" native="true"/>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
<class>KeepRadioWidget</class>
|
<class>KeepRatioWidget</class>
|
||||||
<extends>QWidget</extends>
|
<extends>QWidget</extends>
|
||||||
<header location="global">keepradiowidget.h</header>
|
<header location="global">keepratiowidget.h</header>
|
||||||
<container>1</container>
|
<container>1</container>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
</customwidgets>
|
</customwidgets>
|
||||||
|
|
|
@ -1,28 +0,0 @@
|
||||||
#ifndef KEEPRADIOWIDGET_H
|
|
||||||
#define KEEPRADIOWIDGET_H
|
|
||||||
|
|
||||||
#include <QPointer>
|
|
||||||
#include <QWidget>
|
|
||||||
|
|
||||||
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<QWidget> m_subWidget;
|
|
||||||
QSize m_goodSize;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // KEEPRADIOWIDGET_H
|
|
|
@ -1,13 +1,13 @@
|
||||||
#include <QResizeEvent>
|
#include <QResizeEvent>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
#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) {
|
if (!w) {
|
||||||
return;
|
return;
|
||||||
|
@ -16,30 +16,30 @@ void KeepRadioWidget::setWidget(QWidget *w)
|
||||||
m_subWidget = 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;
|
return;
|
||||||
}
|
}
|
||||||
m_widthHeightRadio = widthHeightRadio;
|
m_widthHeightRatio = widthHeightRatio;
|
||||||
adjustSubWidget();
|
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 QSize();
|
||||||
}
|
}
|
||||||
return m_subWidget->size();
|
return m_subWidget->size();
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeepRadioWidget::resizeEvent(QResizeEvent *event)
|
void KeepRatioWidget::resizeEvent(QResizeEvent *event)
|
||||||
{
|
{
|
||||||
Q_UNUSED(event)
|
Q_UNUSED(event)
|
||||||
adjustSubWidget();
|
adjustSubWidget();
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeepRadioWidget::adjustSubWidget()
|
void KeepRatioWidget::adjustSubWidget()
|
||||||
{
|
{
|
||||||
if (!m_subWidget) {
|
if (!m_subWidget) {
|
||||||
return;
|
return;
|
||||||
|
@ -49,15 +49,15 @@ void KeepRadioWidget::adjustSubWidget()
|
||||||
QPoint pos(0, 0);
|
QPoint pos(0, 0);
|
||||||
int width = 0;
|
int width = 0;
|
||||||
int height = 0;
|
int height = 0;
|
||||||
if (m_widthHeightRadio > 1.0f) {
|
if (m_widthHeightRatio > 1.0f) {
|
||||||
// base width
|
// base width
|
||||||
width = curSize.width();
|
width = curSize.width();
|
||||||
height = curSize.width() / m_widthHeightRadio;
|
height = curSize.width() / m_widthHeightRatio;
|
||||||
pos.setY((curSize.height() - height) / 2);
|
pos.setY((curSize.height() - height) / 2);
|
||||||
} else if (m_widthHeightRadio > 0.0f) {
|
} else if (m_widthHeightRatio > 0.0f) {
|
||||||
// base height
|
// base height
|
||||||
height = curSize.height();
|
height = curSize.height();
|
||||||
width = curSize.height() * m_widthHeightRadio;
|
width = curSize.height() * m_widthHeightRatio;
|
||||||
pos.setX((curSize.width() - width) / 2);
|
pos.setX((curSize.width() - width) / 2);
|
||||||
} else {
|
} else {
|
||||||
// full widget
|
// full widget
|
28
QtScrcpy/uibase/keepratiowidget.h
Normal file
28
QtScrcpy/uibase/keepratiowidget.h
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
#ifndef KEEPRATIOWIDGET_H
|
||||||
|
#define KEEPRATIOWIDGET_H
|
||||||
|
|
||||||
|
#include <QPointer>
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
|
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<QWidget> m_subWidget;
|
||||||
|
QSize m_goodSize;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // KEEPRATIOWIDGET_H
|
|
@ -1,9 +1,9 @@
|
||||||
FORMS +=
|
FORMS +=
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
$$PWD/keepradiowidget.h \
|
$$PWD/keepratiowidget.h \
|
||||||
$$PWD/magneticwidget.h
|
$$PWD/magneticwidget.h
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
$$PWD/keepradiowidget.cpp \
|
$$PWD/keepratiowidget.cpp \
|
||||||
$$PWD/magneticwidget.cpp
|
$$PWD/magneticwidget.cpp
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue