diff options
author | Aleksei Nikiforov <darktemplar@basealt.ru> | 2018-11-22 12:27:26 +0300 |
---|---|---|
committer | Katarina Behrens <Katarina.Behrens@cib.de> | 2018-11-23 11:48:22 +0100 |
commit | e0d6fe0b55c91fd45531438dfc8a5ee28a99de94 (patch) | |
tree | 81b895bd133f64ebf6bc6ed0640924f99d18a51c | |
parent | 8d53e34c52ae2604da4cb1dafd24bcb1d42d251d (diff) |
Move menu item insertion into separate function
Change-Id: I721910bbbd558827e9a5de1f8763426b460f08fa
Reviewed-on: https://gerrit.libreoffice.org/63861
Tested-by: Jenkins
Reviewed-by: Katarina Behrens <Katarina.Behrens@cib.de>
-rw-r--r-- | vcl/inc/qt5/Qt5Menu.hxx | 5 | ||||
-rw-r--r-- | vcl/qt5/Qt5Menu.cxx | 124 |
2 files changed, 72 insertions, 57 deletions
diff --git a/vcl/inc/qt5/Qt5Menu.hxx b/vcl/inc/qt5/Qt5Menu.hxx index e31c44fa8b55..92d2e18b9c5c 100644 --- a/vcl/inc/qt5/Qt5Menu.hxx +++ b/vcl/inc/qt5/Qt5Menu.hxx @@ -12,6 +12,7 @@ #include <salmenu.hxx> class MenuItemList; +class QActionGroup; class QMenu; class QMenuBar; class Qt5MenuItem; @@ -27,10 +28,14 @@ private: Qt5Frame* mpFrame; bool mbMenuBar; QMenuBar* mpQMenuBar; + QMenu* mpQMenu; + QActionGroup* mpQActionGroup; void DoFullMenuUpdate(Menu* pMenuBar, QMenu* pParentMenu = nullptr); static void NativeItemText(OUString& rItemText); + QMenu* InsertMenuItem(Qt5MenuItem* pSalMenuItem); + public: Qt5Menu(bool bMenuBar); virtual ~Qt5Menu() override; diff --git a/vcl/qt5/Qt5Menu.cxx b/vcl/qt5/Qt5Menu.cxx index c3228bdd90c0..ed26f31f2761 100644 --- a/vcl/qt5/Qt5Menu.cxx +++ b/vcl/qt5/Qt5Menu.cxx @@ -23,6 +23,9 @@ Qt5Menu::Qt5Menu(bool bMenuBar) , mpParentSalMenu(nullptr) , mpFrame(nullptr) , mbMenuBar(bMenuBar) + , mpQMenuBar(nullptr) + , mpQMenu(nullptr) + , mpQActionGroup(nullptr) { connect(this, &Qt5Menu::setFrameSignal, this, &Qt5Menu::SetFrame, Qt::BlockingQueuedConnection); } @@ -31,6 +34,67 @@ Qt5Menu::~Qt5Menu() { maItems.clear(); } bool Qt5Menu::VisibleMenuBar() { return true; } +QMenu* Qt5Menu::InsertMenuItem(Qt5MenuItem* pSalMenuItem) +{ + QMenu* pQMenu = mpQMenu; + sal_uInt16 nId = pSalMenuItem->mnId; + OUString aText = mpVCLMenu->GetItemText(nId); + NativeItemText(aText); + vcl::KeyCode nAccelKey = mpVCLMenu->GetAccelKey(nId); + bool bChecked = mpVCLMenu->IsItemChecked(nId); + MenuItemBits itemBits = mpVCLMenu->GetItemBits(nId); + + if (mbMenuBar && mpQMenuBar) + // top-level menu + pQMenu = mpQMenuBar->addMenu(toQString(aText)); + else + { + if (pSalMenuItem->mpSubMenu) + { + // submenu + pQMenu = pQMenu->addMenu(toQString(aText)); + mpQActionGroup = new QActionGroup(pQMenu); + } + else + { + if (pSalMenuItem->mnType == MenuItemType::SEPARATOR) + pQMenu->addSeparator(); + else + { + // leaf menu + QAction* pAction = pQMenu->addAction(toQString(aText)); + pSalMenuItem->mpAction = pAction; + pAction->setShortcut(toQString(nAccelKey.GetName(GetFrame()->GetWindow()))); + + if (itemBits & MenuItemBits::CHECKABLE) + { + pAction->setCheckable(true); + pAction->setChecked(bChecked); + } + else if (itemBits & MenuItemBits::RADIOCHECK) + { + pAction->setCheckable(true); + if (!mpQActionGroup) + { + mpQActionGroup = new QActionGroup(pQMenu); + mpQActionGroup->setExclusive(true); + } + mpQActionGroup->addAction(pAction); + pAction->setChecked(bChecked); + } + + pAction->setEnabled(pSalMenuItem->mbEnabled); + pAction->setVisible(pSalMenuItem->mbVisible); + + connect(pAction, &QAction::triggered, this, + [pSalMenuItem] { slotMenuTriggered(pSalMenuItem); }); + } + } + } + + return pQMenu; +} + void Qt5Menu::InsertItem(SalMenuItem* pSalMenuItem, unsigned nPos) { SolarMutexGuard aGuard; @@ -88,70 +152,16 @@ void Qt5Menu::SetFrame(const SalFrame* pFrame) void Qt5Menu::DoFullMenuUpdate(Menu* pMenuBar, QMenu* pParentMenu) { - Menu* pVCLMenu = mpVCLMenu; + mpQMenu = pParentMenu; if (mbMenuBar && mpQMenuBar) mpQMenuBar->clear(); - QActionGroup* pQAG = nullptr; + mpQActionGroup = nullptr; for (sal_Int32 nItem = 0; nItem < static_cast<sal_Int32>(GetItemCount()); nItem++) { Qt5MenuItem* pSalMenuItem = GetItemAtPos(nItem); - sal_uInt16 nId = pSalMenuItem->mnId; - OUString aText = pVCLMenu->GetItemText(nId); - QMenu* pQMenu = pParentMenu; - NativeItemText(aText); - vcl::KeyCode nAccelKey = pVCLMenu->GetAccelKey(nId); - bool bChecked = pVCLMenu->IsItemChecked(nId); - MenuItemBits itemBits = pVCLMenu->GetItemBits(nId); - - if (mbMenuBar && mpQMenuBar) - // top-level menu - pQMenu = mpQMenuBar->addMenu(toQString(aText)); - else - { - if (pSalMenuItem->mpSubMenu) - { - // submenu - pQMenu = pQMenu->addMenu(toQString(aText)); - pQAG = new QActionGroup(pQMenu); - } - else - { - if (pSalMenuItem->mnType == MenuItemType::SEPARATOR) - pQMenu->addSeparator(); - else - { - // leaf menu - QAction* pAction = pQMenu->addAction(toQString(aText)); - pSalMenuItem->mpAction = pAction; - pAction->setShortcut(toQString(nAccelKey.GetName(GetFrame()->GetWindow()))); - - if (itemBits & MenuItemBits::CHECKABLE) - { - pAction->setCheckable(true); - pAction->setChecked(bChecked); - } - else if (itemBits & MenuItemBits::RADIOCHECK) - { - pAction->setCheckable(true); - if (!pQAG) - { - pQAG = new QActionGroup(pQMenu); - pQAG->setExclusive(true); - } - pQAG->addAction(pAction); - pAction->setChecked(bChecked); - } - - pAction->setEnabled(pSalMenuItem->mbEnabled); - pAction->setVisible(pSalMenuItem->mbVisible); - - connect(pAction, &QAction::triggered, this, - [pSalMenuItem] { slotMenuTriggered(pSalMenuItem); }); - } - } - } + QMenu* pQMenu = InsertMenuItem(pSalMenuItem); if (pSalMenuItem->mpSubMenu != nullptr) { |