summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan-Marek Glogowski <glogow@fbihome.de>2022-04-05 16:49:38 +0200
committerJan-Marek Glogowski <glogow@fbihome.de>2022-04-06 11:27:35 +0200
commit9c4ef8ce3183e27ca174475cf4a8d15cc0368f60 (patch)
tree07a1dd289666abd5356a5d714bd5779268facf86
parent51431559bda9a81293d502328982452caeeba6c6 (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>
-rw-r--r--vcl/inc/qt5/QtMenu.hxx2
-rw-r--r--vcl/qt5/QtMenu.cxx38
2 files changed, 21 insertions, 19 deletions
diff --git a/vcl/inc/qt5/QtMenu.hxx b/vcl/inc/qt5/QtMenu.hxx
index 55275ae6e099..f39be7e8d506 100644
--- a/vcl/inc/qt5/QtMenu.hxx
+++ b/vcl/inc/qt5/QtMenu.hxx
@@ -50,7 +50,6 @@ private:
// pointer to QMenu owned by the corresponding QtMenuItem or self (-> mpOwnedQMenu)
QMenu* mpQMenu;
QPushButton* mpCloseButton;
- QMetaObject::Connection maCloseButtonConnection;
void DoFullMenuUpdate(Menu* pMenuBar);
static void NativeItemText(OUString& rItemText);
@@ -60,6 +59,7 @@ private:
void ReinitializeActionGroup(unsigned nPos);
void ResetAllActionGroups();
void UpdateActionGroupItem(const QtMenuItem* pSalMenuItem);
+ bool validateQMenuBar();
public:
QtMenu(bool bMenuBar);
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;
}