[Libreoffice-commits] core.git: vcl/inc vcl/qt5
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Fri Nov 23 10:50:49 UTC 2018
vcl/inc/qt5/Qt5Menu.hxx | 5 +
vcl/qt5/Qt5Menu.cxx | 124 +++++++++++++++++++++++++-----------------------
2 files changed, 72 insertions(+), 57 deletions(-)
New commits:
commit e0d6fe0b55c91fd45531438dfc8a5ee28a99de94
Author: Aleksei Nikiforov <darktemplar at basealt.ru>
AuthorDate: Thu Nov 22 12:27:26 2018 +0300
Commit: Katarina Behrens <Katarina.Behrens at cib.de>
CommitDate: Fri Nov 23 11:48:22 2018 +0100
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 at cib.de>
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)
{
More information about the Libreoffice-commits
mailing list