vcl/inc/qt5/QtFrame.hxx | 1 + vcl/qt5/QtFrame.cxx | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-)
New commits: commit ca28826a087245686d7fca3ffc8ca1f03307924d Author: Jan-Marek Glogowski <glo...@fbihome.de> AuthorDate: Mon Dec 20 13:32:52 2021 +0100 Commit: Jan-Marek Glogowski <glo...@fbihome.de> CommitDate: Tue Dec 21 13:35:49 2021 +0100 tdf#131467 Qt set default position on first resize Setting the position in Show() is too late, because LO will try to set the mouse pointer to the default button, if configured. That obviously needs the window position. And also take the menubar offset into account. Change-Id: Ia280539c082ff6f675966869fb6643a41a17d696 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127154 Tested-by: Jenkins Reviewed-by: Jan-Marek Glogowski <glo...@fbihome.de> diff --git a/vcl/inc/qt5/QtFrame.hxx b/vcl/inc/qt5/QtFrame.hxx index 61d175cf2625..9aa31504bcd3 100644 --- a/vcl/inc/qt5/QtFrame.hxx +++ b/vcl/inc/qt5/QtFrame.hxx @@ -129,6 +129,7 @@ class VCLPLUG_QT_PUBLIC QtFrame : public QObject, public SalFrame bool isMinimized() const; bool isMaximized() const; void SetWindowStateImpl(Qt::WindowStates eState); + int menuBarOffset() const; void fixICCCMwindowGroup(); void modalReparent(bool bVisible); diff --git a/vcl/qt5/QtFrame.cxx b/vcl/qt5/QtFrame.cxx index 15795b3e84e6..19d9c826f625 100644 --- a/vcl/qt5/QtFrame.cxx +++ b/vcl/qt5/QtFrame.cxx @@ -469,7 +469,6 @@ void QtFrame::Show(bool bVisible, bool bNoActivate) // show SetDefaultSize(); - SetDefaultPos(); pSalInst->RunInMainThread([this, bNoActivate]() { QWidget* const pChild = asChild(); @@ -503,6 +502,14 @@ void QtFrame::SetMaxClientSize(tools::Long nWidth, tools::Long nHeight) } } +int QtFrame::menuBarOffset() const +{ + QtMainWindow* pTopLevel = m_pParent->GetTopLevelWindow(); + if (pTopLevel && pTopLevel->menuBar() && pTopLevel->menuBar()->isVisible()) + return round(pTopLevel->menuBar()->geometry().height() * devicePixelRatioF()); + return 0; +} + void QtFrame::SetDefaultPos() { if (!m_bDefaultPos) @@ -515,6 +522,7 @@ void QtFrame::SetDefaultPos() QWidget* const pParentWin = m_pParent->asChild()->window(); QWidget* const pChildWin = asChild()->window(); QPoint aPos = (pParentWin->rect().center() - pChildWin->rect().center()) * fRatio; + aPos.ry() -= menuBarOffset(); SetPosSize(aPos.x(), aPos.y(), 0, 0, SAL_FRAME_POSSIZE_X | SAL_FRAME_POSSIZE_Y); assert(!m_bDefaultPos); } @@ -603,7 +611,11 @@ void QtFrame::SetPosSize(tools::Long nX, tools::Long nY, tools::Long nWidth, too } if (!(nFlags & (SAL_FRAME_POSSIZE_X | SAL_FRAME_POSSIZE_Y))) + { + if (nFlags & (SAL_FRAME_POSSIZE_WIDTH | SAL_FRAME_POSSIZE_HEIGHT)) + SetDefaultPos(); return; + } if (m_pParent) { @@ -612,11 +624,7 @@ void QtFrame::SetPosSize(tools::Long nX, tools::Long nY, tools::Long nWidth, too nX = aParentGeometry.nX + aParentGeometry.nWidth - nX - maGeometry.nWidth - 1; else nX += aParentGeometry.nX; - nY += aParentGeometry.nY; - - QtMainWindow* pTopLevel = m_pParent->GetTopLevelWindow(); - if (pTopLevel && pTopLevel->menuBar() && pTopLevel->menuBar()->isVisible()) - nY += round(pTopLevel->menuBar()->geometry().height() * devicePixelRatioF()); + nY += aParentGeometry.nY + menuBarOffset(); } if (!(nFlags & SAL_FRAME_POSSIZE_X))