🐞 fix(手机投屏): 重新整理投屏窗口切换逻辑
外部窗口跟随主题变动,不设置固定大小,内部屏幕跟随分辨率比例变化 148933 【多端协同】【平板】手机端与电脑端链接后,竖屏模式下进行手机投屏,切换到横屏模式,手机投屏窗口显示不全(必现); https://gitee.com/openkylin/kylin-connectivity/issues/I5XLF0?from=project-issue
This commit is contained in:
parent
a8354f69ed
commit
91a15f1b5c
|
@ -65,7 +65,7 @@ void VideoForm::initUI()
|
|||
{
|
||||
if (m_screenIndex != 0) {
|
||||
QDesktopWidget *desktop = QApplication::desktop();
|
||||
kdk::WindowManager::setGeometry(windowHandle(), desktop->screenGeometry(m_screenIndex));
|
||||
setGeometry(desktop->screenGeometry(m_screenIndex));
|
||||
}
|
||||
ui->setupUi(this);
|
||||
|
||||
|
@ -79,7 +79,6 @@ void VideoForm::initUI()
|
|||
m_loadingWidget->setHighLight();
|
||||
ui->keepRatioWidget->setWidget(m_loadingWidget);
|
||||
ui->keepRatioWidget->setWidget(m_videoWidget);
|
||||
ui->keepRatioWidget->setWidthHeightRatio(m_widthHeightRatio);
|
||||
ui->keepRatioWidget->setParent(this);
|
||||
|
||||
installEventFilter(this);
|
||||
|
@ -135,6 +134,7 @@ void VideoForm::updateRender(const AVFrame *frame)
|
|||
show();
|
||||
activateWindow();
|
||||
setFocus();
|
||||
m_resizeAuto = false;
|
||||
updateShowSize(QSize(frame->width, frame->height));
|
||||
if (m_loadTimer) {
|
||||
m_loadTimer->start(500);
|
||||
|
@ -145,13 +145,17 @@ void VideoForm::updateRender(const AVFrame *frame)
|
|||
m_loadingWidget->deleteLater();
|
||||
m_loadingWidget = nullptr;
|
||||
}
|
||||
m_resizeAuto = false;
|
||||
m_videoWidget->show();
|
||||
} else {
|
||||
m_resizeAuto = false;
|
||||
m_loadingWidget->resize(this->size());
|
||||
m_loadingWidget->show();
|
||||
}
|
||||
} else {
|
||||
m_resizeAuto = false;
|
||||
updateShowSize(QSize(frame->width, frame->height));
|
||||
}
|
||||
updateShowSize(QSize(frame->width, frame->height));
|
||||
|
||||
m_videoWidget->setFrameSize(QSize(frame->width, frame->height));
|
||||
m_videoWidget->updateTextures(frame->data[0], frame->data[1], frame->data[2], frame->linesize[0],
|
||||
|
@ -195,7 +199,6 @@ QRect VideoForm::getScreenRect()
|
|||
screenRect.setWidth(screenRect.width() - panelWidth);
|
||||
}
|
||||
} else {
|
||||
kdk::WindowManager::setGeometry(windowHandle(), desktop->screenGeometry(m_screenIndex));
|
||||
QList<QScreen *> screenList = QGuiApplication::screens();
|
||||
screenRect = screenList[m_screenIndex]->geometry();
|
||||
}
|
||||
|
@ -226,8 +229,6 @@ void VideoForm::moveCenter()
|
|||
kdk::WindowManager::setGeometry(
|
||||
windowHandle(),
|
||||
QRect((screenRect.topRight() - QRect(0, 0, size().width(), size().height()).topRight()), size()));
|
||||
} else if (m_isTable && !m_isVertical) {
|
||||
kdk::WindowManager::setGeometry(windowHandle(), QRect((QRect(QPoint(0, 0), size()))));
|
||||
} else {
|
||||
kdk::WindowManager::setGeometry(
|
||||
windowHandle(),
|
||||
|
@ -397,7 +398,7 @@ void VideoForm::updateShowSize(const QSize &newSize)
|
|||
m_isVertical = m_widthHeightRatio < 1.0f;
|
||||
if (m_frameSize != newSize) {
|
||||
m_frameSize = newSize;
|
||||
setWindowSize();
|
||||
windowZoom();
|
||||
moveCenter();
|
||||
}
|
||||
}
|
||||
|
@ -460,11 +461,15 @@ bool VideoForm::eventFilter(QObject *watch, QEvent *event)
|
|||
}
|
||||
case QEvent::Resize: {
|
||||
if (windowState() != Qt::WindowNoState) {
|
||||
return QWidget::eventFilter(watch, event);
|
||||
return true;
|
||||
}
|
||||
if (m_isMax || m_isFull) {
|
||||
return true;
|
||||
}
|
||||
if (!m_resizeAuto) {
|
||||
m_oldSize = size();
|
||||
m_resizeAuto = true;
|
||||
return QWidget::eventFilter(watch, event);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (m_timerId) {
|
||||
|
@ -473,9 +478,8 @@ bool VideoForm::eventFilter(QObject *watch, QEvent *event)
|
|||
}
|
||||
m_timerId = startTimer(400);
|
||||
if (m_toolForm) {
|
||||
kdk::WindowManager::setGeometry(m_toolForm->windowHandle(),
|
||||
QRect(QPoint(0, height() - 40), m_toolForm->size()));
|
||||
m_toolForm->setFixedWidth(width());
|
||||
// m_toolForm->setFixedWidth(width());
|
||||
setGeometry(QRect(QPoint(0, height() - 40), m_toolForm->size()));
|
||||
}
|
||||
}
|
||||
default:
|
||||
|
@ -527,8 +531,7 @@ bool VideoForm::eventFilter(QObject *watch, QEvent *event)
|
|||
Q_EMIT m_device->mouseEvent(mouseEvent, m_videoWidget->frameSize(), m_videoWidget->size());
|
||||
} else if (!m_dragPosition.isNull()) {
|
||||
if (mouseEvent->buttons() & Qt::LeftButton) {
|
||||
kdk::WindowManager::setGeometry(windowHandle(),
|
||||
QRect((mouseEvent->globalPos() - m_dragPosition), size()));
|
||||
setGeometry(QRect((mouseEvent->globalPos() - m_dragPosition), size()));
|
||||
mouseEvent->accept();
|
||||
}
|
||||
}
|
||||
|
@ -620,19 +623,10 @@ void VideoForm::timerEvent(QTimerEvent *event)
|
|||
void VideoForm::changeEvent(QEvent *event)
|
||||
{
|
||||
if (QEvent::WindowStateChange == event->type()) {
|
||||
if (!m_resizeAuto) {
|
||||
return;
|
||||
}
|
||||
m_normalVertical = m_isVertical;
|
||||
Qt::WindowStates state = windowState();
|
||||
qInfo() << "VideoForm state change: " << state;
|
||||
switch (state) {
|
||||
case Qt::WindowNoState: {
|
||||
m_resizeAuto = false;
|
||||
if (m_isWindeStateChanged) {
|
||||
m_isWindeStateChanged = false;
|
||||
windowZoom();
|
||||
}
|
||||
m_isMax = false;
|
||||
m_isFull = false;
|
||||
ui->title->show();
|
||||
|
@ -640,6 +634,11 @@ void VideoForm::changeEvent(QEvent *event)
|
|||
ui->toolform->show();
|
||||
}
|
||||
ui->title->setMaxBtnMode(false);
|
||||
if (m_isWindeStateChanged) {
|
||||
m_isWindeStateChanged = false;
|
||||
windowZoom();
|
||||
moveCenter();
|
||||
}
|
||||
} break;
|
||||
case Qt::WindowMaximized: {
|
||||
m_isMax = true;
|
||||
|
@ -715,16 +714,32 @@ QPoint VideoForm::cursorPoint()
|
|||
|
||||
void VideoForm::windowZoom()
|
||||
{
|
||||
QRect tempGeometry = geometry();
|
||||
// QSize currentSize = size();
|
||||
int w = width();
|
||||
int h = height();
|
||||
if (m_oldHeight == h) {
|
||||
setScreenIndex();
|
||||
QRect screenRect = getScreenRect();
|
||||
if (m_oldSize.height() == 0 || (m_isVertical != m_normalVertical)) {
|
||||
if (m_isMax || m_isFull) {
|
||||
m_isWindeStateChanged = true;
|
||||
m_resizeAuto = false;
|
||||
} else {
|
||||
h = screenRect.height();
|
||||
w = (screenRect.height() - m_titleHeight) * m_widthHeightRatio;
|
||||
m_resizeAuto = false;
|
||||
resize(w, h);
|
||||
}
|
||||
m_normalVertical = m_isVertical;
|
||||
return;
|
||||
}
|
||||
if (m_oldSize == size()) {
|
||||
return;
|
||||
}
|
||||
if (m_oldSize.height() == h) {
|
||||
h = (w / m_widthHeightRatio) + m_titleHeight;
|
||||
} else {
|
||||
w = (h - m_titleHeight) * m_widthHeightRatio;
|
||||
}
|
||||
setScreenIndex();
|
||||
QRect screenRect = getScreenRect();
|
||||
if (h >= screenRect.height()) {
|
||||
h = screenRect.height();
|
||||
w = (screenRect.height() - m_titleHeight) * m_widthHeightRatio;
|
||||
|
@ -732,15 +747,11 @@ void VideoForm::windowZoom()
|
|||
h = screenRect.height() / 2;
|
||||
w = (h - m_titleHeight) * m_widthHeightRatio;
|
||||
}
|
||||
tempGeometry.setWidth(w);
|
||||
tempGeometry.setHeight(h);
|
||||
if (m_toolForm) {
|
||||
setGeometry(QRect(QPoint(0, h - TITLE_HEIGHT), m_toolForm->size()));
|
||||
m_toolForm->setFixedWidth(w);
|
||||
}
|
||||
kdk::WindowManager::setGeometry(windowHandle(), tempGeometry);
|
||||
setSize(w, h);
|
||||
m_oldHeight = h;
|
||||
m_resizeAuto = false;
|
||||
resize(w, h);
|
||||
}
|
||||
|
||||
void VideoForm::showToolForm(bool show)
|
||||
|
@ -767,53 +778,6 @@ void VideoForm::onToolFormStatusChange()
|
|||
}
|
||||
}
|
||||
|
||||
void VideoForm::setWindowSize()
|
||||
{
|
||||
m_resizeAuto = false;
|
||||
QSize showSize = size();
|
||||
setScreenIndex();
|
||||
QRect screenRect = getScreenRect();
|
||||
int height = screenRect.height();
|
||||
int width = screenRect.width();
|
||||
int desktopHeight = QApplication::desktop()->availableGeometry().height();
|
||||
setMinimumSize((desktopHeight / 2) * m_widthHeightRatio, desktopHeight / 2);
|
||||
setMaximumSize(desktopHeight * m_widthHeightRatio, desktopHeight);
|
||||
if (m_isVertical != m_normalVertical) {
|
||||
if (m_isMax) {
|
||||
if (m_isTable) {
|
||||
setSize(desktopHeight * m_widthHeightRatio, desktopHeight);
|
||||
} else {
|
||||
showNormal();
|
||||
}
|
||||
showMaximized();
|
||||
m_isWindeStateChanged = true;
|
||||
return;
|
||||
}
|
||||
if (m_isFull) {
|
||||
showNormal();
|
||||
showFullScreen();
|
||||
m_isWindeStateChanged = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
m_resizeAuto = false;
|
||||
if (m_isVertical) {
|
||||
showSize.setHeight(height);
|
||||
showSize.setWidth((height - m_titleHeight) * m_widthHeightRatio);
|
||||
} else {
|
||||
// 防止横屏后超出屏幕
|
||||
if ((width / m_widthHeightRatio) <= height) {
|
||||
showSize.setWidth(width);
|
||||
showSize.setHeight(width / m_widthHeightRatio + m_titleHeight);
|
||||
} else {
|
||||
showSize.setHeight(height);
|
||||
showSize.setWidth((height - m_titleHeight) * m_widthHeightRatio);
|
||||
}
|
||||
}
|
||||
m_oldHeight = showSize.height();
|
||||
resize(showSize);
|
||||
}
|
||||
|
||||
void VideoForm::onModeChanged(bool isTable)
|
||||
{
|
||||
m_isTable = isTable;
|
||||
|
@ -822,9 +786,7 @@ void VideoForm::onModeChanged(bool isTable)
|
|||
|
||||
void VideoForm::onModeRotationsChange(QString rotaion)
|
||||
{
|
||||
Q_UNUSED(rotaion)
|
||||
setWindowSize();
|
||||
moveCenter();
|
||||
m_isWindeStateChanged = true;
|
||||
}
|
||||
|
||||
void VideoForm::onScrollTrigger()
|
||||
|
@ -839,13 +801,4 @@ void VideoForm::initPanelSetting()
|
|||
qInfo() << "init panel gsettings";
|
||||
m_panelSetting = new QGSettings(UKUI_TASK_GSETTING_PATH);
|
||||
}
|
||||
}
|
||||
|
||||
void VideoForm::setSize(int width, int height)
|
||||
{
|
||||
m_resizeAuto = false;
|
||||
setFixedSize(width, height);
|
||||
int desktopHeight = QApplication::desktop()->availableGeometry().height();
|
||||
setMinimumSize((desktopHeight / 2) * m_widthHeightRatio, desktopHeight / 2);
|
||||
setMaximumSize(desktopHeight * m_widthHeightRatio, desktopHeight);
|
||||
}
|
|
@ -74,16 +74,13 @@ private:
|
|||
// 窗口缩放
|
||||
void windowZoom();
|
||||
|
||||
// 设置窗口大小
|
||||
void setWindowSize();
|
||||
|
||||
void changeInputBoxPos();
|
||||
|
||||
QPoint cursorPoint();
|
||||
QRect getScreenRect();
|
||||
void setScreenIndex();
|
||||
void initPanelSetting();
|
||||
void setSize(int width, int height);
|
||||
void checkScreenRect(QRect &rect);
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *watch, QEvent *event) override;
|
||||
|
@ -120,9 +117,10 @@ private:
|
|||
bool m_isMax = false;
|
||||
bool m_isFull = false;
|
||||
int m_timerId = 0;
|
||||
int m_oldHeight = 0;
|
||||
QSize m_oldSize = QSize(0, 0);
|
||||
int m_resizeAuto = false;
|
||||
bool m_isWindeStateChanged = false;
|
||||
bool m_isNormal = true;
|
||||
};
|
||||
|
||||
#endif // VIDEOFORM_H
|
||||
|
|
Loading…
Reference in New Issue