From fa31f4f8217a8f2b7956c9a66ce90094b778d328 Mon Sep 17 00:00:00 2001 From: dela Date: Wed, 10 Jun 2026 17:15:34 +0800 Subject: [PATCH] fix: avoid resizing login transition --- src/qEmbyApp/mainwindow.cpp | 304 ++++++------------------------------ src/qEmbyApp/mainwindow.h | 4 +- 2 files changed, 52 insertions(+), 256 deletions(-) diff --git a/src/qEmbyApp/mainwindow.cpp b/src/qEmbyApp/mainwindow.cpp index c0bc68e..8db4c22 100644 --- a/src/qEmbyApp/mainwindow.cpp +++ b/src/qEmbyApp/mainwindow.cpp @@ -30,12 +30,10 @@ #include #include #include -#include #include #include #include "components/themetransitionwidget.h" #include "components/moderntoast.h" -#include #include #include #include @@ -48,36 +46,6 @@ #include #include -namespace { -bool canAnimateTopLevelWindowPosition() -{ -#if defined(Q_OS_LINUX) - return !QGuiApplication::platformName().contains(QStringLiteral("wayland"), - Qt::CaseInsensitive); -#else - return true; -#endif -} - -QRect centeredRectWithin(const QRect &sourceGeometry, const QSize &targetSize, - const QRect &bounds) -{ - QRect target(QPoint(0, 0), targetSize); - target.moveCenter(sourceGeometry.center()); - - if (target.left() < bounds.left()) - target.moveLeft(bounds.left()); - if (target.top() < bounds.top()) - target.moveTop(bounds.top()); - if (target.right() > bounds.right()) - target.moveRight(bounds.right()); - if (target.bottom() > bounds.bottom()) - target.moveBottom(bounds.bottom()); - - return target; -} -} - static inline void emulateLeaveEvent(QWidget *widget) { Q_ASSERT(widget); if (!widget) return; @@ -742,7 +710,15 @@ MainWindow::MainWindow(QWidget *parent) macTitlebarNavSpacer->hide(); } #endif - resize(m_defaultWidth, m_defaultHeight); + setMinimumSize(900, 600); + setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); + const QString startupWindowState = ConfigStore::instance()->get( + ConfigKeys::StartupWindowState, "normal"); + if (startupWindowState == "maximized") { + setWindowState(windowState() | Qt::WindowMaximized); + } else { + resize(m_defaultWidth, m_defaultHeight); + } @@ -969,162 +945,43 @@ void MainWindow::navigateToHome() bool reduceAnimations = ConfigStore::instance()->get(ConfigKeys::UiAnimations, false); if (reduceAnimations) { setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); - - QString windowState = ConfigStore::instance()->get( - ConfigKeys::StartupWindowState, "normal"); - bool shouldMaximize = (windowState == "maximized"); - setMinimumSize(900, 600); #if !defined(Q_OS_MACOS) && !defined(Q_OS_MAC) if (auto* minBtn = findChild("min-button")) minBtn->show(); if (auto* maxBtn = findChild("max-button")) maxBtn->show(); #endif - m_viewStack->setCurrentWidget(m_homeView); - - if (shouldMaximize) { - showMaximized(); - } else { - QRect screenGeo = screen()->availableGeometry(); - int w = 1280, h = 800; - setGeometry( - screenGeo.x() + (screenGeo.width() - w) / 2, - screenGeo.y() + (screenGeo.height() - h) / 2, - w, h); - } - m_viewTransitionInProgress = false; - return; - } - - if (!canAnimateTopLevelWindowPosition()) { - hide(); - setWindowOpacity(0.0); - setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); - setMinimumSize(0, 0); - - const QString windowState = ConfigStore::instance()->get( - ConfigKeys::StartupWindowState, "normal"); - const bool shouldMaximize = (windowState == "maximized"); - m_loginView->setGraphicsEffect(nullptr); m_homeView->setGraphicsEffect(nullptr); m_viewStack->setCurrentWidget(m_homeView); - -#if !defined(Q_OS_MACOS) && !defined(Q_OS_MAC) - if (auto* minBtn = findChild("min-button")) minBtn->show(); - if (auto* maxBtn = findChild("max-button")) maxBtn->show(); -#endif - - if (shouldMaximize) { - showMaximized(); - } else { - resize(1280, 800); - } - setMinimumSize(900, 600); - show(); - raise(); - activateWindow(); - - auto *fadeIn = new QPropertyAnimation(this, "windowOpacity", this); - fadeIn->setDuration(180); - fadeIn->setStartValue(0.0); - fadeIn->setEndValue(1.0); - fadeIn->setEasingCurve(QEasingCurve::OutCubic); - - connect(fadeIn, &QPropertyAnimation::finished, this, [this]() { - setWindowOpacity(1.0); - m_viewTransitionInProgress = false; - }); - QTimer::singleShot(0, fadeIn, [fadeIn]() { - fadeIn->start(QAbstractAnimation::DeleteWhenStopped); - }); + m_viewTransitionInProgress = false; return; } - - auto *loginOpacity = new QGraphicsOpacityEffect(m_loginView); - loginOpacity->setOpacity(1.0); - m_loginView->setGraphicsEffect(loginOpacity); - - auto *fadeOut = new QPropertyAnimation(loginOpacity, "opacity", this); - fadeOut->setDuration(120); - fadeOut->setStartValue(1.0); - fadeOut->setEndValue(0.0); - - connect(fadeOut, &QPropertyAnimation::finished, this, [this]() { - - setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); - setMinimumSize(0, 0); - - - QString windowState = ConfigStore::instance()->get( - ConfigKeys::StartupWindowState, "normal"); - bool shouldMaximize = (windowState == "maximized"); - - QRect startGeo = this->geometry(); - QRect targetGeo; - if (shouldMaximize) { - - targetGeo = screen()->availableGeometry(); - } else { - - int targetWidth = 1280; - int targetHeight = 800; - QRect screenGeo = screen()->availableGeometry(); - targetGeo = centeredRectWithin(startGeo, - QSize(targetWidth, targetHeight), - screenGeo); - } - - auto finishWindowTransition = [this, shouldMaximize]() { - - setMinimumSize(900, 600); - + setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); + setMinimumSize(900, 600); #if !defined(Q_OS_MACOS) && !defined(Q_OS_MAC) - if (auto* minBtn = findChild("min-button")) minBtn->show(); - if (auto* maxBtn = findChild("max-button")) maxBtn->show(); + if (auto* minBtn = findChild("min-button")) minBtn->show(); + if (auto* maxBtn = findChild("max-button")) maxBtn->show(); #endif - - m_loginView->setGraphicsEffect(nullptr); + m_loginView->setGraphicsEffect(nullptr); + auto *homeOpacity = new QGraphicsOpacityEffect(m_homeView); + homeOpacity->setOpacity(0.0); + m_homeView->setGraphicsEffect(homeOpacity); + m_viewStack->setCurrentWidget(m_homeView); - - if (shouldMaximize) { - showMaximized(); - } + auto *fadeIn = new QPropertyAnimation(homeOpacity, "opacity", this); + fadeIn->setDuration(250); + fadeIn->setStartValue(0.0); + fadeIn->setEndValue(1.0); + fadeIn->setEasingCurve(QEasingCurve::OutQuad); - - auto *homeOpacity = new QGraphicsOpacityEffect(m_homeView); - homeOpacity->setOpacity(0.0); - m_homeView->setGraphicsEffect(homeOpacity); - - - m_viewStack->setCurrentWidget(m_homeView); - - auto *fadeIn = new QPropertyAnimation(homeOpacity, "opacity", this); - fadeIn->setDuration(250); - fadeIn->setStartValue(0.0); - fadeIn->setEndValue(1.0); - fadeIn->setEasingCurve(QEasingCurve::OutQuad); - - connect(fadeIn, &QPropertyAnimation::finished, this, [this]() { - m_homeView->setGraphicsEffect(nullptr); - m_viewTransitionInProgress = false; - }); - fadeIn->start(QAbstractAnimation::DeleteWhenStopped); - }; - - auto *geoAnim = new QPropertyAnimation(this, "geometry", this); - - geoAnim->setDuration(shouldMaximize ? 500 : 350); - geoAnim->setStartValue(startGeo); - geoAnim->setEndValue(targetGeo); - geoAnim->setEasingCurve(QEasingCurve::InOutCubic); - connect(geoAnim, &QPropertyAnimation::finished, this, - finishWindowTransition); - geoAnim->start(QAbstractAnimation::DeleteWhenStopped); + connect(fadeIn, &QPropertyAnimation::finished, this, [this]() { + m_homeView->setGraphicsEffect(nullptr); + m_viewTransitionInProgress = false; }); - fadeOut->start(QAbstractAnimation::DeleteWhenStopped); + fadeIn->start(QAbstractAnimation::DeleteWhenStopped); } void MainWindow::navigateToLogin() { @@ -1149,104 +1006,43 @@ void MainWindow::navigateToLogin() { if (auto* x = findChild("max-button")) x->hide(); #endif - if (isMaximized()) showNormal(); - - setMinimumSize(0, 0); + setMinimumSize(900, 600); setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); + m_homeView->setGraphicsEffect(nullptr); + m_loginView->setGraphicsEffect(nullptr); m_viewStack->setCurrentWidget(m_loginView); - resize(m_defaultWidth, m_defaultHeight); - - - QRect screenGeo = screen()->availableGeometry(); - move(screenGeo.x() + (screenGeo.width() - m_defaultWidth) / 2, - screenGeo.y() + (screenGeo.height() - m_defaultHeight) / 2); m_core->authService()->logout(); m_viewTransitionInProgress = false; return; } - - auto *homeOpacity = new QGraphicsOpacityEffect(m_homeView); - homeOpacity->setOpacity(1.0); - m_homeView->setGraphicsEffect(homeOpacity); - - auto *fadeOut = new QPropertyAnimation(homeOpacity, "opacity", this); - fadeOut->setDuration(120); - fadeOut->setStartValue(1.0); - fadeOut->setEndValue(0.0); - - connect(fadeOut, &QPropertyAnimation::finished, this, [this]() { - + setMinimumSize(900, 600); + setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); #if !defined(Q_OS_MACOS) && !defined(Q_OS_MAC) - if (auto* m = findChild("min-button")) m->hide(); - if (auto* x = findChild("max-button")) x->hide(); + if (auto* m = findChild("min-button")) m->hide(); + if (auto* x = findChild("max-button")) x->hide(); #endif - - if (isMaximized()) { - QRect maxGeo = geometry(); - showNormal(); - setGeometry(maxGeo); - } + m_homeView->setGraphicsEffect(nullptr); + auto *loginOpacity = new QGraphicsOpacityEffect(m_loginView); + loginOpacity->setOpacity(0.0); + m_loginView->setGraphicsEffect(loginOpacity); + m_viewStack->setCurrentWidget(m_loginView); - - setMinimumSize(0, 0); - setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); - - QRect startGeo = geometry(); - int targetWidth = m_defaultWidth; - int targetHeight = m_defaultHeight; - QRect targetGeo = centeredRectWithin( - startGeo, QSize(targetWidth, targetHeight), - screen()->availableGeometry()); + auto *fadeIn = new QPropertyAnimation(loginOpacity, "opacity", this); + fadeIn->setDuration(250); + fadeIn->setStartValue(0.0); + fadeIn->setEndValue(1.0); + fadeIn->setEasingCurve(QEasingCurve::OutQuad); - auto finishWindowTransition = [this]() { - - - - m_homeView->setGraphicsEffect(nullptr); - - - auto *loginOpacity = new QGraphicsOpacityEffect(m_loginView); - loginOpacity->setOpacity(0.0); - m_loginView->setGraphicsEffect(loginOpacity); - - m_viewStack->setCurrentWidget(m_loginView); - - auto *fadeIn = new QPropertyAnimation(loginOpacity, "opacity", this); - fadeIn->setDuration(250); - fadeIn->setStartValue(0.0); - fadeIn->setEndValue(1.0); - fadeIn->setEasingCurve(QEasingCurve::OutQuad); - - connect(fadeIn, &QPropertyAnimation::finished, this, [this]() { - m_loginView->setGraphicsEffect(nullptr); - - - m_core->authService()->logout(); - m_viewTransitionInProgress = false; - }); - fadeIn->start(QAbstractAnimation::DeleteWhenStopped); - }; - - if (canAnimateTopLevelWindowPosition()) { - auto *geoAnim = new QPropertyAnimation(this, "geometry", this); - - geoAnim->setDuration(startGeo.width() > 1300 ? 500 : 350); - geoAnim->setStartValue(startGeo); - geoAnim->setEndValue(targetGeo); - geoAnim->setEasingCurve(QEasingCurve::InOutCubic); - connect(geoAnim, &QPropertyAnimation::finished, this, - finishWindowTransition); - geoAnim->start(QAbstractAnimation::DeleteWhenStopped); - } else { - resize(targetGeo.size()); - finishWindowTransition(); - } + connect(fadeIn, &QPropertyAnimation::finished, this, [this]() { + m_loginView->setGraphicsEffect(nullptr); + m_core->authService()->logout(); + m_viewTransitionInProgress = false; }); - fadeOut->start(QAbstractAnimation::DeleteWhenStopped); + fadeIn->start(QAbstractAnimation::DeleteWhenStopped); } bool MainWindow::eventFilter(QObject *watched, QEvent *event) diff --git a/src/qEmbyApp/mainwindow.h b/src/qEmbyApp/mainwindow.h index b5a75d0..90a3660 100644 --- a/src/qEmbyApp/mainwindow.h +++ b/src/qEmbyApp/mainwindow.h @@ -53,8 +53,8 @@ private: QElapsedTimer m_backClickTimer; - quint32 m_defaultWidth{450}; - quint32 m_defaultHeight{320}; + quint32 m_defaultWidth{1280}; + quint32 m_defaultHeight{800}; bool m_realQuit{false}; bool m_themeAnimating{false}; bool m_wasPausedByTray{false};