[Libreoffice-commits] core.git: vcl/inc vcl/qt5 vcl/source
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Wed Feb 27 19:53:41 UTC 2019
vcl/inc/qt5/Qt5Menu.hxx | 2
vcl/inc/salmenu.hxx | 1
vcl/qt5/Qt5Menu.cxx | 92 +++++++++++++++++++++++++++++++++------------
vcl/source/window/menu.cxx | 12 ++++-
4 files changed, 82 insertions(+), 25 deletions(-)
New commits:
commit f341921825370fb98ad896a20d823c5f0cb537f6
Author: Aleksei Nikiforov <darktemplar at basealt.ru>
AuthorDate: Wed Feb 27 15:03:07 2019 +0300
Commit: Thorsten Behrens <Thorsten.Behrens at CIB.de>
CommitDate: Wed Feb 27 20:53:11 2019 +0100
tdf#121970 KDE5: Regenerate menu when it's set as submenu
Also add item bits change notification function
for SalMenu to properly convert regenerated menu items
to check or radiocheck items.
Change-Id: I61f16a771b484644bbefd9afaf2776232d38a2f9
Reviewed-on: https://gerrit.libreoffice.org/68438
Tested-by: Jenkins
Reviewed-by: Thorsten Behrens <Thorsten.Behrens at CIB.de>
diff --git a/vcl/inc/qt5/Qt5Menu.hxx b/vcl/inc/qt5/Qt5Menu.hxx
index 91e1c3e116d5..a11fbd186575 100644
--- a/vcl/inc/qt5/Qt5Menu.hxx
+++ b/vcl/inc/qt5/Qt5Menu.hxx
@@ -42,6 +42,7 @@ private:
void ReinitializeActionGroup(unsigned nPos);
void ResetAllActionGroups();
+ void UpdateActionGroupItem(Qt5MenuItem* pSalMenuItem);
public:
Qt5Menu(bool bMenuBar);
@@ -54,6 +55,7 @@ public:
virtual void SetFrame(const SalFrame* pFrame) override;
const Qt5Frame* GetFrame() const;
Qt5Menu* GetTopLevel();
+ virtual void SetItemBits(unsigned nPos, MenuItemBits nBits) override;
virtual void CheckItem(unsigned nPos, bool bCheck) override;
virtual void EnableItem(unsigned nPos, bool bEnable) override;
virtual void ShowItem(unsigned nPos, bool bShow) override;
diff --git a/vcl/inc/salmenu.hxx b/vcl/inc/salmenu.hxx
index 0b6cd9e22481..6829e3a623d1 100644
--- a/vcl/inc/salmenu.hxx
+++ b/vcl/inc/salmenu.hxx
@@ -68,6 +68,7 @@ public:
virtual void RemoveItem( unsigned nPos ) = 0;
virtual void SetSubMenu( SalMenuItem* pSalMenuItem, SalMenu* pSubMenu, unsigned nPos ) = 0;
virtual void SetFrame( const SalFrame* pFrame ) = 0;
+ virtual void SetItemBits( unsigned /*nPos*/, MenuItemBits /*nBits*/ ) {}
virtual void CheckItem( unsigned nPos, bool bCheck ) = 0;
virtual void EnableItem( unsigned nPos, bool bEnable ) = 0;
virtual void SetItemText( unsigned nPos, SalMenuItem* pSalMenuItem, const OUString& rText )= 0;
diff --git a/vcl/qt5/Qt5Menu.cxx b/vcl/qt5/Qt5Menu.cxx
index 049d90b7b4da..a00cce02dffa 100644
--- a/vcl/qt5/Qt5Menu.cxx
+++ b/vcl/qt5/Qt5Menu.cxx
@@ -40,8 +40,6 @@ QMenu* Qt5Menu::InsertMenuItem(Qt5MenuItem* pSalMenuItem, unsigned nPos)
OUString aText = mpVCLMenu->GetItemText(nId);
NativeItemText(aText);
vcl::KeyCode nAccelKey = mpVCLMenu->GetAccelKey(nId);
- bool bChecked = mpVCLMenu->IsItemChecked(nId);
- MenuItemBits itemBits = mpVCLMenu->GetItemBits(nId);
pSalMenuItem->mpAction.reset();
pSalMenuItem->mpMenu.reset();
@@ -138,24 +136,9 @@ QMenu* Qt5Menu::InsertMenuItem(Qt5MenuItem* pSalMenuItem, unsigned nPos)
ReinitializeActionGroup(nPos);
- pAction->setShortcut(toQString(nAccelKey.GetName(GetFrame()->GetWindow())));
+ UpdateActionGroupItem(pSalMenuItem);
- if (itemBits & MenuItemBits::CHECKABLE)
- {
- pAction->setCheckable(true);
- pAction->setChecked(bChecked);
- }
- else if (itemBits & MenuItemBits::RADIOCHECK)
- {
- pAction->setCheckable(true);
-
- if (pSalMenuItem->mpActionGroup)
- {
- pSalMenuItem->mpActionGroup->addAction(pAction);
- }
-
- pAction->setChecked(bChecked);
- }
+ pAction->setShortcut(toQString(nAccelKey.GetName(GetFrame()->GetWindow())));
connect(pAction, &QAction::triggered, this,
[pSalMenuItem] { slotMenuTriggered(pSalMenuItem); });
@@ -297,6 +280,43 @@ void Qt5Menu::ResetAllActionGroups()
}
}
+void Qt5Menu::UpdateActionGroupItem(Qt5MenuItem* pSalMenuItem)
+{
+ QAction* pAction = pSalMenuItem->getAction();
+ if (!pAction)
+ return;
+
+ bool bChecked = mpVCLMenu->IsItemChecked(pSalMenuItem->mnId);
+ MenuItemBits itemBits = mpVCLMenu->GetItemBits(pSalMenuItem->mnId);
+
+ if (itemBits & MenuItemBits::RADIOCHECK)
+ {
+ pAction->setCheckable(true);
+
+ if (pSalMenuItem->mpActionGroup)
+ {
+ pSalMenuItem->mpActionGroup->addAction(pAction);
+ }
+
+ pAction->setChecked(bChecked);
+ }
+ else
+ {
+ pAction->setActionGroup(nullptr);
+
+ if (itemBits & MenuItemBits::CHECKABLE)
+ {
+ pAction->setCheckable(true);
+ pAction->setChecked(bChecked);
+ }
+ else
+ {
+ pAction->setChecked(false);
+ pAction->setCheckable(false);
+ }
+ }
+}
+
void Qt5Menu::InsertItem(SalMenuItem* pSalMenuItem, unsigned nPos)
{
SolarMutexGuard aGuard;
@@ -334,17 +354,34 @@ void Qt5Menu::RemoveItem(unsigned nPos)
}
}
-void Qt5Menu::SetSubMenu(SalMenuItem* pSalMenuItem, SalMenu* pSubMenu, unsigned)
+void Qt5Menu::SetSubMenu(SalMenuItem* pSalMenuItem, SalMenu* pSubMenu, unsigned nPos)
{
SolarMutexGuard aGuard;
Qt5MenuItem* pItem = static_cast<Qt5MenuItem*>(pSalMenuItem);
Qt5Menu* pQSubMenu = static_cast<Qt5Menu*>(pSubMenu);
- if (pQSubMenu == nullptr)
+ pItem->mpSubMenu = pQSubMenu;
+ // at this point the pointer to parent menu may be outdated, update it too
+ pItem->mpParentMenu = this;
+
+ if (pQSubMenu != nullptr)
+ {
+ pQSubMenu->mpParentSalMenu = this;
+ pQSubMenu->mpQMenu = pItem->mpMenu.get();
+ }
+
+ // if it's not a menu bar item, then convert it to corresponding item if type if necessary.
+ // If submenu is present and it's an action, convert it to menu.
+ // If submenu is not present and it's a menu, convert it to action.
+ // It may be fine to proceed in any case, but by skipping other cases
+ // amount of unneeded actions taken should be reduced.
+ if (pItem->mpParentMenu->mbMenuBar || (pQSubMenu && pItem->mpMenu)
+ || ((!pQSubMenu) && pItem->mpAction))
+ {
return;
+ }
- pQSubMenu->mpParentSalMenu = this;
- pItem->mpSubMenu = pQSubMenu;
+ InsertMenuItem(pItem, nPos);
}
void Qt5Menu::SetFrame(const SalFrame* pFrame)
@@ -409,6 +446,15 @@ void Qt5Menu::ShowItem(unsigned nPos, bool bShow)
}
}
+void Qt5Menu::SetItemBits(unsigned nPos, MenuItemBits)
+{
+ if (nPos < maItems.size())
+ {
+ Qt5MenuItem* pSalMenuItem = GetItemAtPos(nPos);
+ UpdateActionGroupItem(pSalMenuItem);
+ }
+}
+
void Qt5Menu::CheckItem(unsigned nPos, bool bChecked)
{
if (nPos < maItems.size())
diff --git a/vcl/source/window/menu.cxx b/vcl/source/window/menu.cxx
index 2f9b87822c00..9d7c5cc9e3d2 100644
--- a/vcl/source/window/menu.cxx
+++ b/vcl/source/window/menu.cxx
@@ -695,9 +695,17 @@ OString Menu::GetItemIdent(sal_uInt16 nId) const
void Menu::SetItemBits( sal_uInt16 nItemId, MenuItemBits nBits )
{
- MenuItemData* pData = pItemList->GetData( nItemId );
- if ( pData )
+ size_t nPos;
+ MenuItemData* pData = pItemList->GetData(nItemId, nPos);
+
+ if (pData && (pData->nBits != nBits))
+ {
pData->nBits = nBits;
+
+ // update native menu
+ if (ImplGetSalMenu())
+ ImplGetSalMenu()->SetItemBits(nPos, nBits);
+ }
}
MenuItemBits Menu::GetItemBits( sal_uInt16 nItemId ) const
More information about the Libreoffice-commits
mailing list