LibreOffice Module vcl (master) 1
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
8 */
10#pragma once
12#include <salmenu.hxx>
14#include <QtCore/QObject>
16#include <memory>
18class MenuItemList;
19class QAbstractButton;
20class QAction;
21class QActionGroup;
22class QButtonGroup;
23class QMenu;
24class QMenuBar;
25class QPushButton;
26class QtMenuItem;
27class QtFrame;
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
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;
56 void DoFullMenuUpdate(Menu* pMenuBar);
57 static void NativeItemText(OUString& rItemText);
59 void InsertMenuItem(QtMenuItem* pSalMenuItem, unsigned nPos);
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);
70 QtMenu(bool bMenuBar);
72 virtual bool HasNativeMenuBar() override;
73 virtual int GetMenuBarHeight() const override;
74 virtual void ShowMenuBar(bool bVisible) override;
76 virtual void InsertItem(SalMenuItem* pSalMenuItem, unsigned nPos) override;
77 virtual void RemoveItem(unsigned nPos) override;
78 virtual void SetSubMenu(SalMenuItem* pSalMenuItem, SalMenu* pSubMenu, unsigned nPos) override;
79 virtual void SetFrame(const SalFrame* pFrame) override;
80 const QtFrame* GetFrame() const;
81 virtual bool ShowNativePopupMenu(FloatingWindow* pWin, const tools::Rectangle& rRect,
82 FloatWinPopupFlags nFlags) override;
84 virtual void SetItemBits(unsigned nPos, MenuItemBits nBits) override;
85 virtual void CheckItem(unsigned nPos, bool bCheck) override;
86 virtual void EnableItem(unsigned nPos, bool bEnable) override;
87 virtual void ShowItem(unsigned nPos, bool bShow) override;
88 virtual void SetItemText(unsigned nPos, SalMenuItem* pSalMenuItem,
89 const OUString& rText) override;
90 virtual void SetItemImage(unsigned nPos, SalMenuItem* pSalMenuItem,
91 const Image& rImage) override;
92 virtual void SetAccelerator(unsigned nPos, SalMenuItem* pSalMenuItem,
93 const vcl::KeyCode& rKeyCode, const OUString& rKeyName) override;
94 virtual void GetSystemMenuData(SystemMenuData* pData) override;
95 virtual void ShowCloseButton(bool bShow) override;
96 virtual bool AddMenuBarButton(const SalMenuButtonItem&) override;
97 virtual void RemoveMenuBarButton(sal_uInt16 nId) override;
98 virtual tools::Rectangle GetMenuBarButtonRectPixel(sal_uInt16 nId, SalFrame*) override;
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]; }
105private slots:
106 static void slotMenuTriggered(QtMenuItem* pQItem);
107 static void slotMenuAboutToShow(QtMenuItem* pQItem);
108 static void slotMenuAboutToHide(QtMenuItem* pQItem);
110 void slotMenuBarButtonClicked(QAbstractButton*);
118 QAction* getAction() const;
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
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
Change visibility of the native menu bar.
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 HasNativeMenuBar() override
Return true, if the implementation supports a native menu bar (or wants to suppress LO's menu bar,...
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
Return the height of the native menu bar.
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
Definition: vclenum.hxx:30
Definition: vclenum.hxx:33
Definition: vclenum.hxx:330