LibreOffice Module vcl (master)  1
Qt5Menu.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  */
9 
10 #pragma once
11 
12 #include <salmenu.hxx>
13 
14 #include <QtCore/QObject>
15 
16 #include <memory>
17 
18 class MenuItemList;
19 class QAction;
20 class QActionGroup;
21 class QPushButton;
22 class QMenu;
23 class QMenuBar;
24 class Qt5MenuItem;
25 class Qt5Frame;
26 
27 class Qt5Menu : public QObject, public SalMenu
28 {
29  Q_OBJECT
30 private:
31  std::vector<Qt5MenuItem*> maItems;
35  bool mbMenuBar;
36  QMenuBar* mpQMenuBar;
37  QMenu* mpQMenu;
38  QPushButton* mpCloseButton;
39  QMetaObject::Connection maCloseButtonConnection;
40 
41  void DoFullMenuUpdate(Menu* pMenuBar);
42  static void NativeItemText(OUString& rItemText);
43 
44  void InsertMenuItem(Qt5MenuItem* pSalMenuItem, unsigned nPos);
45 
46  void ReinitializeActionGroup(unsigned nPos);
47  void ResetAllActionGroups();
48  void UpdateActionGroupItem(const Qt5MenuItem* pSalMenuItem);
49 
50 public:
51  Qt5Menu(bool bMenuBar);
52 
53  virtual bool VisibleMenuBar() override; // must return TRUE to actually DISPLAY native menu bars
54 
55  virtual void InsertItem(SalMenuItem* pSalMenuItem, unsigned nPos) override;
56  virtual void RemoveItem(unsigned nPos) override;
57  virtual void SetSubMenu(SalMenuItem* pSalMenuItem, SalMenu* pSubMenu, unsigned nPos) override;
58  virtual void SetFrame(const SalFrame* pFrame) override;
59  const Qt5Frame* GetFrame() const;
60  virtual void ShowMenuBar(bool bVisible) override;
62  virtual void SetItemBits(unsigned nPos, MenuItemBits nBits) override;
63  virtual void CheckItem(unsigned nPos, bool bCheck) override;
64  virtual void EnableItem(unsigned nPos, bool bEnable) override;
65  virtual void ShowItem(unsigned nPos, bool bShow) override;
66  virtual void SetItemText(unsigned nPos, SalMenuItem* pSalMenuItem,
67  const OUString& rText) override;
68  virtual void SetItemImage(unsigned nPos, SalMenuItem* pSalMenuItem,
69  const Image& rImage) override;
70  virtual void SetAccelerator(unsigned nPos, SalMenuItem* pSalMenuItem,
71  const vcl::KeyCode& rKeyCode, const OUString& rKeyName) override;
72  virtual void GetSystemMenuData(SystemMenuData* pData) override;
73  virtual void ShowCloseButton(bool bShow) override;
74 
75  void SetMenu(Menu* pMenu) { mpVCLMenu = pMenu; }
76  Menu* GetMenu() { return mpVCLMenu; }
77  unsigned GetItemCount() const { return maItems.size(); }
78  Qt5MenuItem* GetItemAtPos(unsigned nPos) { return maItems[nPos]; }
79 
80 private slots:
81  static void slotMenuTriggered(Qt5MenuItem* pQItem);
82  static void slotMenuAboutToShow(Qt5MenuItem* pQItem);
83  static void slotMenuAboutToHide(Qt5MenuItem* pQItem);
84  void slotCloseDocument();
85 };
86 
87 class Qt5MenuItem : public SalMenuItem
88 {
89 public:
90  Qt5MenuItem(const SalItemParams*);
91 
92  QAction* getAction() const;
93 
94  Qt5Menu* mpParentMenu; // The menu into which this menu item is inserted
95  Qt5Menu* mpSubMenu; // Submenu of this item (if defined)
96  std::unique_ptr<QAction> mpAction; // action corresponding to this item
97  std::unique_ptr<QMenu> mpMenu; // menu corresponding to this item
98  std::shared_ptr<QActionGroup> mpActionGroup; // empty if it's a separator element
99  sal_uInt16 mnId; // Item ID
100  MenuItemType mnType; // Item type
101  bool mbVisible; // Item visibility.
102  bool mbEnabled; // Item active.
103  Image maImage; // Item image
104 };
105 
106 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void ShowCloseButton(bool bShow) override
MenuItemType mnType
Definition: Qt5Menu.hxx:100
QMenu * mpQMenu
Definition: Qt5Menu.hxx:37
MenuItemType
Definition: vclenum.hxx:30
Qt5MenuItem * GetItemAtPos(unsigned nPos)
Definition: Qt5Menu.hxx:78
void SetMenu(Menu *pMenu)
Definition: Qt5Menu.hxx:75
Qt5Menu * mpParentMenu
Definition: Qt5Menu.hxx:94
QMenuBar * mpQMenuBar
Definition: Qt5Menu.hxx:36
static void NativeItemText(OUString &rItemText)
virtual void ShowMenuBar(bool bVisible) override
const Qt5Frame * GetFrame() const
unsigned GetItemCount() const
Definition: Qt5Menu.hxx:77
bool mbMenuBar
Definition: Qt5Menu.hxx:35
QMetaObject::Connection maCloseButtonConnection
Definition: Qt5Menu.hxx:39
virtual void ShowItem(unsigned nPos, bool bShow) override
MenuItemBits
Definition: vclenum.hxx:32
std::vector< Qt5MenuItem * > maItems
Definition: Qt5Menu.hxx:31
void InsertMenuItem(Qt5MenuItem *pSalMenuItem, unsigned nPos)
QAction * getAction() const
void DoFullMenuUpdate(Menu *pMenuBar)
virtual void GetSystemMenuData(SystemMenuData *pData) override
virtual void SetItemImage(unsigned nPos, SalMenuItem *pSalMenuItem, const Image &rImage) override
virtual void SetFrame(const SalFrame *pFrame) override
void UpdateActionGroupItem(const Qt5MenuItem *pSalMenuItem)
virtual void SetSubMenu(SalMenuItem *pSalMenuItem, SalMenu *pSubMenu, unsigned nPos) override
void ResetAllActionGroups()
Image maImage
Definition: Qt5Menu.hxx:103
Qt5Menu * mpSubMenu
Definition: Qt5Menu.hxx:95
virtual bool VisibleMenuBar() override
virtual void RemoveItem(unsigned nPos) override
virtual void SetItemText(unsigned nPos, SalMenuItem *pSalMenuItem, const OUString &rText) override
std::unique_ptr< QMenu > mpMenu
Definition: Qt5Menu.hxx:97
Menu * GetMenu()
Definition: Qt5Menu.hxx:76
QPushButton * mpCloseButton
Definition: Qt5Menu.hxx:38
std::unique_ptr< QAction > mpAction
Definition: Qt5Menu.hxx:96
static void slotMenuAboutToShow(Qt5MenuItem *pQItem)
virtual void InsertItem(SalMenuItem *pSalMenuItem, unsigned nPos) override
A SalFrame is a system window (e.g. an X11 window).
Definition: salframe.hxx:112
Definition: menu.hxx:121
void slotCloseDocument()
sal_uInt16 mnId
Definition: Qt5Menu.hxx:99
std::shared_ptr< QActionGroup > mpActionGroup
Definition: Qt5Menu.hxx:98
void ReinitializeActionGroup(unsigned nPos)
virtual void SetAccelerator(unsigned nPos, SalMenuItem *pSalMenuItem, const vcl::KeyCode &rKeyCode, const OUString &rKeyName) override
Definition: image.hxx:40
Qt5Menu(bool bMenuBar)
Qt5Menu * GetTopLevel()
static void slotMenuAboutToHide(Qt5MenuItem *pQItem)
Qt5MenuItem(const SalItemParams *)
virtual void EnableItem(unsigned nPos, bool bEnable) override
static void slotMenuTriggered(Qt5MenuItem *pQItem)
bool mbEnabled
Definition: Qt5Menu.hxx:102
virtual void SetItemBits(unsigned nPos, MenuItemBits nBits) override
VclPtr< Menu > mpVCLMenu
Definition: Qt5Menu.hxx:32
Qt5Menu * mpParentSalMenu
Definition: Qt5Menu.hxx:33
virtual void CheckItem(unsigned nPos, bool bCheck) override
bool mbVisible
Definition: Qt5Menu.hxx:101
Qt5Frame * mpFrame
Definition: Qt5Menu.hxx:34