🐞 fix(手机投屏): 修改手机投屏尺寸变化逻辑

This commit is contained in:
huheng@kylinos.cn 2023-04-12 09:50:04 +08:00
parent bb94b31c19
commit 36098a469d
2 changed files with 51 additions and 53 deletions

View File

@ -162,8 +162,11 @@ void VideoForm::updateRender(const AVFrame *frame)
QRect VideoForm::getScreenRect()
{
QRect screenRect;
QDesktopWidget *desktop = QApplication::desktop();
if (m_isTable) {
return desktop->screenGeometry();
}
QRect screenRect;
if (m_screenIndex == 0) {
screenRect = desktop->availableGeometry();
if ((desktop->screenCount() > 1) && m_panelSetting) {
@ -496,7 +499,7 @@ bool VideoForm::eventFilter(QObject *watch, QEvent *event)
m_cursorPos = calCursorPos(mouseEvent->pos(), calCursorX(mouseEvent->pos()));
if (mouseEvent->button() == Qt::LeftButton) {
if (m_cursorPos != CENTER) {
resizeFlag = true;
m_resizeFlag = true;
}
m_preGeometry = geometry();
m_viewMousePos = mouseEvent->globalPos();
@ -504,14 +507,16 @@ bool VideoForm::eventFilter(QObject *watch, QEvent *event)
return true;
}
case QEvent::MouseButtonRelease: {
resizeFlag = false;
m_resizeFlag = false;
return true;
}
case QEvent::MouseMove: {
QMouseEvent *mouseEvent = (QMouseEvent *)event;
if (!(m_isMax || m_isFull)) {
setCursorShape(calCursorPos(mouseEvent->pos(), calCursorX(mouseEvent->pos())));
windowZoom();
if (m_resizeFlag) {
windowZoom();
}
}
return true;
}
@ -755,45 +760,41 @@ void VideoForm::windowZoom()
int desktopWidth = (desktopHeight - m_titleHeight) * m_widthHeightRatio;
this->setMinimumSize(0, 0);
this->setMaximumSize(desktopWidth, desktopHeight);
if (resizeFlag) {
switch (m_cursorPos) {
case WindowEdge::LEFT:
tempGeometry.setLeft(m_preGeometry.left() + moveSize.x());
tempGeometry.setHeight((tempGeometry.width() / m_widthHeightRatio) + m_titleHeight);
break;
case WindowEdge::RIGHT:
tempGeometry.setRight(m_preGeometry.right() + moveSize.x());
tempGeometry.setHeight((tempGeometry.width() / m_widthHeightRatio) + m_titleHeight);
break;
case WindowEdge::BUTTOMLEFT:
tempGeometry.setBottomLeft(m_preGeometry.bottomLeft() + moveSize);
tempGeometry.setHeight((tempGeometry.width() / m_widthHeightRatio) + m_titleHeight);
break;
case WindowEdge::BUTTOM:
tempGeometry.setBottom(m_preGeometry.bottom() + moveSize.y());
tempGeometry.setWidth((tempGeometry.height() - m_titleHeight) * m_widthHeightRatio);
break;
case WindowEdge::BUTTOMRIGHT:
tempGeometry.setBottomRight(m_preGeometry.bottomRight() + moveSize);
tempGeometry.setWidth((tempGeometry.height() - m_titleHeight) * m_widthHeightRatio);
break;
default:
break;
}
if (tempGeometry.height() >= screenRect.height()) {
tempGeometry.setHeight(screenRect.height());
tempGeometry.setWidth((tempGeometry.height() - m_titleHeight) * m_widthHeightRatio - ERROR_LENGTH);
kdk::WindowManager::setGeometry(windowHandle(), tempGeometry);
this->resizeFlag = false;
} else if (tempGeometry.height() <= (screenRect.height() / 2)) {
tempGeometry.setHeight(screenRect.height() / 2);
tempGeometry.setWidth((tempGeometry.height() - m_titleHeight) * m_widthHeightRatio + ERROR_LENGTH);
kdk::WindowManager::setGeometry(windowHandle(), tempGeometry);
this->resizeFlag = false;
}
switch (m_cursorPos) {
case WindowEdge::LEFT:
tempGeometry.setLeft(m_preGeometry.left() + moveSize.x());
tempGeometry.setHeight((tempGeometry.width() / m_widthHeightRatio) + m_titleHeight);
break;
case WindowEdge::RIGHT:
tempGeometry.setRight(m_preGeometry.right() + moveSize.x());
tempGeometry.setHeight((tempGeometry.width() / m_widthHeightRatio) + m_titleHeight);
break;
case WindowEdge::BUTTOMLEFT:
tempGeometry.setBottomLeft(m_preGeometry.bottomLeft() + moveSize);
tempGeometry.setHeight((tempGeometry.width() / m_widthHeightRatio) + m_titleHeight);
break;
case WindowEdge::BUTTOM:
tempGeometry.setBottom(m_preGeometry.bottom() + moveSize.y());
tempGeometry.setWidth((tempGeometry.height() - m_titleHeight) * m_widthHeightRatio);
break;
case WindowEdge::BUTTOMRIGHT:
tempGeometry.setBottomRight(m_preGeometry.bottomRight() + moveSize);
tempGeometry.setWidth((tempGeometry.height() - m_titleHeight) * m_widthHeightRatio);
break;
default:
break;
}
if (tempGeometry.height() >= screenRect.height()) {
tempGeometry.setHeight(screenRect.height());
tempGeometry.setWidth((tempGeometry.height() - m_titleHeight) * m_widthHeightRatio - ERROR_LENGTH);
kdk::WindowManager::setGeometry(windowHandle(), tempGeometry);
} else if (tempGeometry.height() <= (screenRect.height() / 2)) {
tempGeometry.setHeight(screenRect.height() / 2);
tempGeometry.setWidth((tempGeometry.height() - m_titleHeight) * m_widthHeightRatio + ERROR_LENGTH);
kdk::WindowManager::setGeometry(windowHandle(), tempGeometry);
}
this->setFixedSize(this->width(), this->height());
kdk::WindowManager::setGeometry(windowHandle(), tempGeometry);
setFixedSize(tempGeometry.width(), tempGeometry.height());
}
void VideoForm::showToolForm(bool show)
@ -846,16 +847,14 @@ void VideoForm::setWindowSize()
void VideoForm::onModeChanged(bool isTable)
{
m_isTable = isTable;
setWindowSize();
moveCenter();
ui->title->changeMode(m_isTable);
}
void VideoForm::onModeRotationsChange(QString rotaion)
{
if (rotaion == NORMAL) {
m_isNormal = true;
} else {
m_isNormal = false;
}
Q_UNUSED(rotaion)
setWindowSize();
moveCenter();
}

View File

@ -110,12 +110,12 @@ private:
QSize m_frameSize;
QPoint m_dragPosition;
float m_widthHeightRatio = 0.5f;
bool resizeFlag = false; //窗口大小重置标志
const int frameShape = 6; //用于鼠标区域判断
int m_cursorPos; // 鼠标在窗口的位置
QPoint m_viewMousePos; // 鼠标在全局的位置
QRect m_preGeometry; // 每次窗口的坐标和宽高
int m_titleHeight; // 标题栏与导航栏高度
bool m_resizeFlag = false; //窗口大小重置标志
const int frameShape = 6; //用于鼠标区域判断
int m_cursorPos; // 鼠标在窗口的位置
QPoint m_viewMousePos; // 鼠标在全局的位置
QRect m_preGeometry; // 每次窗口的坐标和宽高
int m_titleHeight; // 标题栏与导航栏高度
bool m_isVertical = false; // 手机横竖屏
bool m_isToolFormShow = true; // 是否展示导航栏
@ -134,7 +134,6 @@ private:
QTimer *m_loadTimer = nullptr;
TableModeListener *m_tableModeListener = nullptr;
bool m_isTable = false;
bool m_isNormal = true;
};
#endif // VIDEOFORM_H