diff options
author | Jan-Marek Glogowski <glogow@fbihome.de> | 2022-04-05 16:49:38 +0200 |
---|---|---|
committer | Jan-Marek Glogowski <glogow@fbihome.de> | 2022-04-06 11:27:35 +0200 |
commit | 9c4ef8ce3183e27ca174475cf4a8d15cc0368f60 (patch) | |
tree | 07a1dd289666abd5356a5d714bd5779268facf86 /vcl/qt5 | |
parent | 51431559bda9a81293d502328982452caeeba6c6 (diff) |
tdf#145954 Qt unshare QMenubar usage
The Qt code was sharing the menu bar from the top level frame, but
LO expects independent menu bars per SetFrame calls. So instead of
showing the new bar and then hiding the old one, this was always
show and hiding the same menu bar, resulting in a hidden menu bar.
As a result of unsharing, LO now must check that its menu bar
pointer is still valid for usage. The QMainWindows takes ownership
when a QMenuBar is assigned and destroy old ones.
Change-Id: I2c6b12199a1e17a5d9f88686a4b27b1413beda47
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132581
Tested-by: Jenkins
Reviewed-by: Jan-Marek Glogowski <glogow@fbihome.de>
Diffstat (limited to 'vcl/qt5')
-rw-r--r-- | vcl/qt5/QtMenu.cxx | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/vcl/qt5/QtMenu.cxx b/vcl/qt5/QtMenu.cxx index d9279fb9389a..71b81c22ba3e 100644 --- a/vcl/qt5/QtMenu.cxx +++ b/vcl/qt5/QtMenu.cxx @@ -59,7 +59,7 @@ void QtMenu::InsertMenuItem(QtMenuItem* pSalMenuItem, unsigned nPos) if (mbMenuBar) { // top-level menu - if (mpQMenuBar) + if (validateQMenuBar()) { QMenu* pQMenu = new QMenu(toQString(aText), nullptr); pSalMenuItem->mpMenu.reset(pQMenu); @@ -428,20 +428,10 @@ void QtMenu::SetFrame(const SalFrame* pFrame) if (!pMainWindow) return; - mpQMenuBar = pMainWindow->menuBar(); - if (mpQMenuBar) - { - mpQMenuBar->clear(); - QPushButton* pButton - = static_cast<QPushButton*>(mpQMenuBar->cornerWidget(Qt::TopRightCorner)); - if (pButton && ((mpCloseButton != pButton) || !maCloseButtonConnection)) - { - maCloseButtonConnection - = connect(pButton, &QPushButton::clicked, this, &QtMenu::slotCloseDocument); - mpCloseButton = pButton; - } - } + mpQMenuBar = new QMenuBar(); + pMainWindow->setMenuBar(mpQMenuBar); + mpCloseButton = nullptr; mpQMenu = nullptr; DoFullMenuUpdate(mpVCLMenu); @@ -565,9 +555,22 @@ QtMenu* QtMenu::GetTopLevel() return pMenu; } +bool QtMenu::validateQMenuBar() +{ + if (!mpQMenuBar) + return false; + assert(mpFrame); + QtMainWindow* pMainWindow = mpFrame->GetTopLevelWindow(); + assert(pMainWindow); + const bool bValid = mpQMenuBar == pMainWindow->menuBar(); + if (!bValid) + mpQMenuBar = nullptr; + return bValid; +} + void QtMenu::ShowMenuBar(bool bVisible) { - if (mpQMenuBar) + if (validateQMenuBar()) mpQMenuBar->setVisible(bVisible); } @@ -643,7 +646,7 @@ void QtMenu::slotCloseDocument() void QtMenu::ShowCloseButton(bool bShow) { - if (!mpQMenuBar) + if (!validateQMenuBar()) return; QPushButton* pButton = static_cast<QPushButton*>(mpQMenuBar->cornerWidget(Qt::TopRightCorner)); @@ -661,8 +664,7 @@ void QtMenu::ShowCloseButton(bool bShow) pButton->setFocusPolicy(Qt::NoFocus); pButton->setToolTip(toQString(VclResId(SV_HELPTEXT_CLOSEDOCUMENT))); mpQMenuBar->setCornerWidget(pButton, Qt::TopRightCorner); - maCloseButtonConnection - = connect(pButton, &QPushButton::clicked, this, &QtMenu::slotCloseDocument); + connect(pButton, &QPushButton::clicked, this, &QtMenu::slotCloseDocument); mpCloseButton = pButton; } |