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 /*
28  * Qt5Menu can represent
29  * (1) the top-level menu of a menubar, in which case 'mbMenuBar' is true and
30  * 'mpQMenuBar' refers to the corresponding QMenuBar
31  * (2) another kind of menu (like a PopupMenu), in which case the corresponding QMenu
32  * object is instantiated and owned by this Qt5Menu (held in 'mpOwnedQMenu').
33  * (3) a "submenu" in an existing menu (like (1)), in which case the corresponding
34  * QMenu object is owned by the corresponding Qt5MenuItem.
35  *
36  * For (2) and (3), member 'mpQMenu' points to the corresponding QMenu object.
37  */
38 class Qt5Menu : public QObject, public SalMenu
39 {
40  Q_OBJECT
41 private:
42  std::vector<Qt5MenuItem*> maItems;
46  bool mbMenuBar;
47  QMenuBar* mpQMenuBar;
48  // self-created QMenu that this Qt5Menu represents, if applicable (s. comment for class)
49  std::unique_ptr<QMenu> mpOwnedQMenu;
50  // pointer to QMenu owned by the corresponding Qt5MenuItem or self (-> mpOwnedQMenu)
51  QMenu* mpQMenu;
52  QPushButton* mpCloseButton;
53  QMetaObject::Connection maCloseButtonConnection;
54 
55  void DoFullMenuUpdate(Menu* pMenuBar);
56  static void NativeItemText(OUString& rItemText);
57 
58  void InsertMenuItem(Qt5MenuItem* pSalMenuItem, unsigned nPos);
59 
60  void ReinitializeActionGroup(unsigned nPos);
61  void ResetAllActionGroups();
62  void UpdateActionGroupItem(const Qt5MenuItem* pSalMenuItem);
63 
64 public:
65  Qt5Menu(bool bMenuBar);
66 
67  virtual bool VisibleMenuBar() override; // must return TRUE to actually DISPLAY native menu bars
68 
69  virtual void InsertItem(SalMenuItem* pSalMenuItem, unsigned nPos) override;
70  virtual void RemoveItem(unsigned nPos) override;
71  virtual void SetSubMenu(SalMenuItem* pSalMenuItem, SalMenu* pSubMenu, unsigned nPos) override;
72  virtual void SetFrame(const SalFrame* pFrame) override;
73  const Qt5Frame* GetFrame() const;
74  virtual void ShowMenuBar(bool bVisible) override;
75  virtual bool ShowNativePopupMenu(FloatingWindow* pWin, const tools::Rectangle& rRect,
76  FloatWinPopupFlags nFlags) override;
78  virtual void SetItemBits(unsigned nPos, MenuItemBits nBits) override;
79  virtual void CheckItem(unsigned nPos, bool bCheck) override;
80  virtual void EnableItem(unsigned nPos, bool bEnable) override;
81  virtual void ShowItem(unsigned nPos, bool bShow) override;
82  virtual void SetItemText(unsigned nPos, SalMenuItem* pSalMenuItem,
83  const OUString& rText) override;
84  virtual void SetItemImage(unsigned nPos, SalMenuItem* pSalMenuItem,
85  const Image& rImage) override;
86  virtual void SetAccelerator(unsigned nPos, SalMenuItem* pSalMenuItem,
87  const vcl::KeyCode& rKeyCode, const OUString& rKeyName) override;
88  virtual void GetSystemMenuData(SystemMenuData* pData) override;
89  virtual void ShowCloseButton(bool bShow) override;
90 
91  void SetMenu(Menu* pMenu) { mpVCLMenu = pMenu; }
92  Menu* GetMenu() { return mpVCLMenu; }
93  unsigned GetItemCount() const { return maItems.size(); }
94  Qt5MenuItem* GetItemAtPos(unsigned nPos) { return maItems[nPos]; }
95 
96 private slots:
97  static void slotMenuTriggered(Qt5MenuItem* pQItem);
98  static void slotMenuAboutToShow(Qt5MenuItem* pQItem);
99  static void slotMenuAboutToHide(Qt5MenuItem* pQItem);
100  void slotCloseDocument();
101 };
102 
103 class Qt5MenuItem : public SalMenuItem
104 {
105 public:
106  Qt5MenuItem(const SalItemParams*);
107 
108  QAction* getAction() const;
109 
110  Qt5Menu* mpParentMenu; // The menu into which this menu item is inserted
111  Qt5Menu* mpSubMenu; // Submenu of this item (if defined)
112  std::unique_ptr<QAction> mpAction; // action corresponding to this item
113  std::unique_ptr<QMenu> mpMenu; // menu corresponding to this item
114  std::shared_ptr<QActionGroup> mpActionGroup; // empty if it's a separator element
115  sal_uInt16 mnId; // Item ID
116  MenuItemType mnType; // Item type
117  bool mbVisible; // Item visibility.
118  bool mbEnabled; // Item active.
119  Image maImage; // Item image
120 };
121 
122 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void ShowCloseButton(bool bShow) override
MenuItemType mnType
Definition: Qt5Menu.hxx:116
QMenu * mpQMenu
Definition: Qt5Menu.hxx:51
MenuItemType
Definition: vclenum.hxx:30
Qt5MenuItem * GetItemAtPos(unsigned nPos)
Definition: Qt5Menu.hxx:94
void SetMenu(Menu *pMenu)
Definition: Qt5Menu.hxx:91
Qt5Menu * mpParentMenu
Definition: Qt5Menu.hxx:110
QMenuBar * mpQMenuBar
Definition: Qt5Menu.hxx:47
static void NativeItemText(OUString &rItemText)
virtual void ShowMenuBar(bool bVisible) override
const Qt5Frame * GetFrame() const
unsigned GetItemCount() const
Definition: Qt5Menu.hxx:93
bool mbMenuBar
Definition: Qt5Menu.hxx:46
QMetaObject::Connection maCloseButtonConnection
Definition: Qt5Menu.hxx:53
virtual void ShowItem(unsigned nPos, bool bShow) override
MenuItemBits
Definition: vclenum.hxx:32
std::vector< Qt5MenuItem * > maItems
Definition: Qt5Menu.hxx:42
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:119
Qt5Menu * mpSubMenu
Definition: Qt5Menu.hxx:111
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:113
Menu * GetMenu()
Definition: Qt5Menu.hxx:92
QPushButton * mpCloseButton
Definition: Qt5Menu.hxx:52
std::unique_ptr< QAction > mpAction
Definition: Qt5Menu.hxx:112
FloatWinPopupFlags
Definition: floatwin.hxx:31
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:115
std::unique_ptr< QMenu > mpOwnedQMenu
Definition: Qt5Menu.hxx:49
std::shared_ptr< QActionGroup > mpActionGroup
Definition: Qt5Menu.hxx:114
virtual bool ShowNativePopupMenu(FloatingWindow *pWin, const tools::Rectangle &rRect, FloatWinPopupFlags nFlags) override
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:118
virtual void SetItemBits(unsigned nPos, MenuItemBits nBits) override
VclPtr< Menu > mpVCLMenu
Definition: Qt5Menu.hxx:43
Qt5Menu * mpParentSalMenu
Definition: Qt5Menu.hxx:44
virtual void CheckItem(unsigned nPos, bool bCheck) override
bool mbVisible
Definition: Qt5Menu.hxx:117
Qt5Frame * mpFrame
Definition: Qt5Menu.hxx:45