mirror of
https://github.com/barry-ran/QtScrcpy.git
synced 2025-04-21 12:04:59 +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
|
||||
if (m_videoForm) {
|
||||
m_videoForm->setWindowTitle(deviceName);
|
||||
m_videoForm->updateScreenRatio(size);
|
||||
m_videoForm->updateShowSize(size);
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 = "";
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
[common]
|
||||
[common]
|
||||
# 窗口标题
|
||||
WindowTitle=QtScrcpy
|
||||
# 录制文件保存路径(必须以/作为分隔符)
|
||||
|
|
Loading…
Add table
Reference in a new issue