mirror of
https://github.com/barry-ran/QtScrcpy.git
synced 2025-08-01 13:28:38 +00:00
feat: set useskin=0 to default
1. set useskin=0 to default 2. fix fullscreen after pos change to (0,0)
This commit is contained in:
parent
e76c58a26e
commit
18c2db767c
4 changed files with 40 additions and 34 deletions
|
@ -163,7 +163,6 @@ void Device::initSignals()
|
||||||
// update ui
|
// update ui
|
||||||
if (m_videoForm) {
|
if (m_videoForm) {
|
||||||
m_videoForm->setWindowTitle(deviceName);
|
m_videoForm->setWindowTitle(deviceName);
|
||||||
m_videoForm->updateScreenRatio(size);
|
|
||||||
m_videoForm->updateShowSize(size);
|
m_videoForm->updateShowSize(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -98,6 +98,18 @@ void VideoForm::showToolForm(bool show)
|
||||||
m_toolForm->setVisible(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)
|
void VideoForm::updateStyleSheet(bool vertical)
|
||||||
{
|
{
|
||||||
if (vertical) {
|
if (vertical) {
|
||||||
|
@ -129,45 +141,35 @@ QMargins VideoForm::getMargins(bool vertical)
|
||||||
return margins;
|
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)
|
void VideoForm::updateShowSize(const QSize &newSize)
|
||||||
{
|
{
|
||||||
if (m_frameSize != newSize) {
|
if (m_frameSize != newSize) {
|
||||||
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;
|
QSize showSize = newSize;
|
||||||
QDesktopWidget* desktop = QApplication::desktop();
|
QDesktopWidget* desktop = QApplication::desktop();
|
||||||
if (desktop) {
|
if (!desktop) {
|
||||||
QRect screenRect = desktop->availableGeometry();
|
qWarning() << "QApplication::desktop() is nullptr";
|
||||||
if (vertical) {
|
return;
|
||||||
showSize.setHeight(qMin(newSize.height(), screenRect.height() - 200));
|
}
|
||||||
showSize.setWidth(showSize.height() * m_widthHeightRatio);
|
QRect screenRect = desktop->availableGeometry();
|
||||||
} else {
|
if (vertical) {
|
||||||
showSize.setWidth(qMin(newSize.width(), screenRect.width()/2));
|
showSize.setHeight(qMin(newSize.height(), screenRect.height() - 200));
|
||||||
showSize.setHeight(showSize.width() * m_widthHeightRatio);
|
showSize.setWidth(showSize.height() * m_widthHeightRatio);
|
||||||
}
|
} else {
|
||||||
|
showSize.setWidth(qMin(newSize.width(), screenRect.width()/2));
|
||||||
if (isFullScreen()) {
|
showSize.setHeight(showSize.width() / m_widthHeightRatio);
|
||||||
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 (!m_skin) {
|
if (isFullScreen()) {
|
||||||
// 减去标题栏高度
|
switchFullScreen();
|
||||||
int titleBarHeight = style()->pixelMetric(QStyle::PM_TitleBarHeight);
|
}
|
||||||
showSize.setHeight(showSize.height() - titleBarHeight);
|
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()) {
|
if (showSize != size()) {
|
||||||
|
@ -175,6 +177,7 @@ void VideoForm::updateShowSize(const QSize &newSize)
|
||||||
if (m_skin) {
|
if (m_skin) {
|
||||||
updateStyleSheet(vertical);
|
updateStyleSheet(vertical);
|
||||||
}
|
}
|
||||||
|
moveCenter();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -183,6 +186,8 @@ void VideoForm::switchFullScreen()
|
||||||
{
|
{
|
||||||
if (isFullScreen()) {
|
if (isFullScreen()) {
|
||||||
showNormal();
|
showNormal();
|
||||||
|
// fullscreen window will move (0,0). qt bug?
|
||||||
|
move(m_fullScreenBeforePos);
|
||||||
|
|
||||||
#ifdef Q_OS_OSX
|
#ifdef Q_OS_OSX
|
||||||
//setWindowFlags(windowFlags() | Qt::FramelessWindowHint);
|
//setWindowFlags(windowFlags() | Qt::FramelessWindowHint);
|
||||||
|
@ -196,6 +201,7 @@ void VideoForm::switchFullScreen()
|
||||||
::SetThreadExecutionState(ES_CONTINUOUS);
|
::SetThreadExecutionState(ES_CONTINUOUS);
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
|
m_fullScreenBeforePos = pos();
|
||||||
// 这种临时增加标题栏再全屏的方案会导致收不到mousemove事件,导致setmousetrack失效
|
// 这种临时增加标题栏再全屏的方案会导致收不到mousemove事件,导致setmousetrack失效
|
||||||
// mac fullscreen must show title bar
|
// mac fullscreen must show title bar
|
||||||
#ifdef Q_OS_OSX
|
#ifdef Q_OS_OSX
|
||||||
|
|
|
@ -21,7 +21,6 @@ public:
|
||||||
|
|
||||||
void switchFullScreen();
|
void switchFullScreen();
|
||||||
void staysOnTop(bool top = true);
|
void staysOnTop(bool top = true);
|
||||||
void updateScreenRatio(const QSize &newSize);
|
|
||||||
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 setController(Controller *controller);
|
||||||
|
@ -42,6 +41,7 @@ private:
|
||||||
void initUI();
|
void initUI();
|
||||||
|
|
||||||
void showToolForm(bool show = true);
|
void showToolForm(bool show = true);
|
||||||
|
void moveCenter();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void mousePressEvent(QMouseEvent *event);
|
void mousePressEvent(QMouseEvent *event);
|
||||||
|
@ -70,6 +70,7 @@ private:
|
||||||
QPoint m_dragPosition;
|
QPoint m_dragPosition;
|
||||||
float m_widthHeightRatio = 0.5f;
|
float m_widthHeightRatio = 0.5f;
|
||||||
bool m_skin = true;
|
bool m_skin = true;
|
||||||
|
QPoint m_fullScreenBeforePos;
|
||||||
|
|
||||||
//outside member
|
//outside member
|
||||||
QString m_serial = "";
|
QString m_serial = "";
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
[common]
|
[common]
|
||||||
# 窗口标题
|
# 窗口标题
|
||||||
WindowTitle=QtScrcpy
|
WindowTitle=QtScrcpy
|
||||||
# 录制文件保存路径(必须以/作为分隔符)
|
# 录制文件保存路径(必须以/作为分隔符)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue