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 e14015edd9fb090bf7444f850dff42c84321bb35 Author: Aleksei Nikiforov <darktemp...@basealt.ru> AuthorDate: Wed Feb 27 15:03:07 2019 +0300 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Thu Feb 28 09:27:56 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.behr...@cib.de> (cherry picked from commit f341921825370fb98ad896a20d823c5f0cb537f6) Reviewed-on: https://gerrit.libreoffice.org/68458 Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> diff --git a/vcl/inc/qt5/Qt5Menu.hxx b/vcl/inc/qt5/Qt5Menu.hxx index ea4369263f62..1ad62a82b9bd 100644 --- a/vcl/inc/qt5/Qt5Menu.hxx +++ b/vcl/inc/qt5/Qt5Menu.hxx @@ -39,6 +39,7 @@ private: void ReinitializeActionGroup(unsigned nPos); void ResetAllActionGroups(); + void UpdateActionGroupItem(Qt5MenuItem* pSalMenuItem); public: Qt5Menu(bool bMenuBar); @@ -51,6 +52,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 65abfd7ec85e..5b56a929aaeb 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 _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits