1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the plugins of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39 
40 #ifndef QIOSMENU_H
41 #define QIOSMENU_H
42 
43 #import <UIKit/UIKit.h>
44 
45 #include <QtCore/QtCore>
46 #include <qpa/qplatformmenu.h>
47 
48 #import "quiview.h"
49 
50 class QIOSMenu;
51 @class QUIMenuController;
52 @class QUIPickerView;
53 
54 class QIOSMenuItem : public QPlatformMenuItem
55 {
56 public:
57     QIOSMenuItem();
58 
59     void setText(const QString &text) override;
setIcon(const QIcon &)60     void setIcon(const QIcon &) override {}
61     void setMenu(QPlatformMenu *) override;
62     void setVisible(bool isVisible) override;
63     void setIsSeparator(bool) override;
setFont(const QFont &)64     void setFont(const QFont &) override {}
65     void setRole(MenuRole role) override;
setCheckable(bool)66     void setCheckable(bool) override {}
setChecked(bool)67     void setChecked(bool) override {}
68 #ifndef QT_NO_SHORTCUT
69     void setShortcut(const QKeySequence&) override;
70 #endif
71     void setEnabled(bool enabled) override;
setIconSize(int)72     void setIconSize(int) override {}
73 
74     bool m_visible;
75     QString m_text;
76     MenuRole m_role;
77     bool m_enabled;
78     bool m_separator;
79     QIOSMenu *m_menu;
80     QKeySequence m_shortcut;
81 };
82 
83 typedef QList<QIOSMenuItem *> QIOSMenuItemList;
84 
85 class QIOSMenu : public QPlatformMenu
86 {
87 public:
88     QIOSMenu();
89     ~QIOSMenu();
90 
91     void insertMenuItem(QPlatformMenuItem *menuItem, QPlatformMenuItem *before) override;
92     void removeMenuItem(QPlatformMenuItem *menuItem) override;
93     void syncMenuItem(QPlatformMenuItem *) override;
syncSeparatorsCollapsible(bool)94     void syncSeparatorsCollapsible(bool) override {}
95 
96     void setText(const QString &) override;
setIcon(const QIcon &)97     void setIcon(const QIcon &) override {}
98     void setEnabled(bool enabled) override;
99     void setVisible(bool visible) override;
100     void setMenuType(MenuType type) override;
101 
102     void showPopup(const QWindow *parentWindow, const QRect &targetRect, const QPlatformMenuItem *item) override;
103     void dismiss() override;
104 
105     QPlatformMenuItem *menuItemAt(int position) const override;
106     QPlatformMenuItem *menuItemForTag(quintptr tag) const override;
107 
108     void handleItemSelected(QIOSMenuItem *menuItem);
109 
currentMenu()110     static QIOSMenu *currentMenu() { return m_currentMenu; }
menuActionTarget()111     static id menuActionTarget() { return m_currentMenu ? m_currentMenu->m_menuController : 0; }
112 
113 protected:
114     bool eventFilter(QObject *obj, QEvent *event) override;
115 
116 private:
117     bool m_enabled;
118     bool m_visible;
119     QString m_text;
120     MenuType m_menuType;
121     MenuType m_effectiveMenuType;
122     QPointer<QWindow> m_parentWindow;
123     QRect m_targetRect;
124     const QIOSMenuItem *m_targetItem;
125     QUIMenuController *m_menuController;
126     QUIPickerView *m_pickerView;
127     QIOSMenuItemList m_menuItems;
128 
129     static QIOSMenu *m_currentMenu;
130 
131     void updateVisibility();
132     void toggleShowUsingUIMenuController(bool show);
133     void toggleShowUsingUIPickerView(bool show);
134     QIOSMenuItemList visibleMenuItems() const;
135     QIOSMenuItemList filterFirstResponderActions(const QIOSMenuItemList &menuItems);
136     void repositionMenu();
137 };
138 
139 #endif // QIOSMENU_H
140