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