Coverage Report

Created: 2026-03-12 07:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/qtbase/src/gui/kernel/qplatformmenu.h
Line
Count
Source
1
// Copyright (C) 2016 The Qt Company Ltd.
2
// Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author James Turner <james.turner@kdab.com>
3
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
// Qt-Security score:significant reason:default
5
6
#ifndef QPLATFORMMENU_H
7
#define QPLATFORMMENU_H
8
//
9
//  W A R N I N G
10
//  -------------
11
//
12
// This file is part of the QPA API and is not meant to be used
13
// in applications. Usage of this API may make your code
14
// source and binary incompatible with future versions of Qt.
15
//
16
17
#include <QtCore/qobject.h>
18
#include <QtGui/qtguiglobal.h>
19
#include <QtCore/qpointer.h>
20
#include <QtGui/qfont.h>
21
#if QT_CONFIG(shortcut)
22
#  include <QtGui/qkeysequence.h>
23
#endif
24
#include <QtGui/qicon.h>
25
26
QT_BEGIN_NAMESPACE
27
28
class QPlatformMenu;
29
class Q_GUI_EXPORT QPlatformMenuItem : public QObject
30
{
31
0
Q_OBJECT
32
0
public:
33
0
    QPlatformMenuItem();
34
0
35
0
    // copied from, and must stay in sync with, QAction menu roles.
36
0
    enum MenuRole { NoRole = 0, TextHeuristicRole, ApplicationSpecificRole, AboutQtRole,
37
0
                    AboutRole, PreferencesRole, QuitRole,
38
0
                    // However these roles are private, perhaps temporarily.
39
0
                    // They could be added as public QAction roles if necessary.
40
0
                    CutRole, CopyRole, PasteRole, SelectAllRole,
41
0
                    RoleCount };
42
0
    Q_ENUM(MenuRole)
Unexecuted instantiation: qt_getEnumMetaObject(QPlatformMenuItem::MenuRole)
Unexecuted instantiation: qt_getEnumName(QPlatformMenuItem::MenuRole)
43
0
44
0
    virtual void setTag(quintptr tag);
45
0
    virtual quintptr tag() const;
46
0
47
0
    virtual void setText(const QString &text) = 0;
48
0
    virtual void setIcon(const QIcon &icon) = 0;
49
0
    virtual void setMenu(QPlatformMenu *menu) = 0;
50
0
    virtual void setVisible(bool isVisible) = 0;
51
0
    virtual void setIsSeparator(bool isSeparator) = 0;
52
0
    virtual void setFont(const QFont &font) = 0;
53
0
    virtual void setRole(MenuRole role) = 0;
54
0
    virtual void setCheckable(bool checkable) = 0;
55
0
    virtual void setChecked(bool isChecked) = 0;
56
0
#if QT_CONFIG(shortcut)
57
0
    virtual void setShortcut(const QKeySequence& shortcut) = 0;
58
0
#endif
59
0
    virtual void setEnabled(bool enabled) = 0;
60
0
    virtual void setIconSize(int size) = 0;
61
0
    virtual void setNativeContents(WId item) { Q_UNUSED(item); }
62
0
    virtual void setHasExclusiveGroup(bool hasExclusiveGroup) { Q_UNUSED(hasExclusiveGroup); }
63
64
Q_SIGNALS:
65
    void activated();
66
    void hovered();
67
68
private:
69
    quintptr m_tag;
70
};
71
72
class Q_GUI_EXPORT QPlatformMenu : public QObject
73
{
74
0
Q_OBJECT
75
0
public:
76
0
    QPlatformMenu();
77
0
78
0
    enum MenuType { DefaultMenu = 0, EditMenu };
79
0
    Q_ENUM(MenuType)
Unexecuted instantiation: qt_getEnumMetaObject(QPlatformMenu::MenuType)
Unexecuted instantiation: qt_getEnumName(QPlatformMenu::MenuType)
80
0
81
0
    virtual void insertMenuItem(QPlatformMenuItem *menuItem, QPlatformMenuItem *before) = 0;
82
0
    virtual void removeMenuItem(QPlatformMenuItem *menuItem) = 0;
83
0
    virtual void syncMenuItem(QPlatformMenuItem *menuItem) = 0;
84
0
    virtual void syncSeparatorsCollapsible(bool enable) = 0;
85
0
86
0
    virtual void setTag(quintptr tag);
87
0
    virtual quintptr tag() const;
88
0
89
0
    virtual void setText(const QString &text) = 0;
90
0
    virtual void setIcon(const QIcon &icon) = 0;
91
0
    virtual void setEnabled(bool enabled) = 0;
92
0
    virtual bool isEnabled() const { return true; }
93
    virtual void setVisible(bool visible) = 0;
94
0
    virtual void setMinimumWidth(int width) { Q_UNUSED(width); }
95
0
    virtual void setFont(const QFont &font) { Q_UNUSED(font); }
96
0
    virtual void setMenuType(MenuType type) { Q_UNUSED(type); }
97
98
    virtual void showPopup(const QWindow *parentWindow, const QRect &targetRect, const QPlatformMenuItem *item)
99
0
    {
100
0
        Q_UNUSED(parentWindow);
101
0
        Q_UNUSED(targetRect);
102
0
        Q_UNUSED(item);
103
0
        setVisible(true);
104
0
    }
105
106
0
    virtual void dismiss() { } // Closes this and all its related menu popups
107
108
    virtual QPlatformMenuItem *menuItemAt(int position) const = 0;
109
    virtual QPlatformMenuItem *menuItemForTag(quintptr tag) const = 0;
110
111
    virtual QPlatformMenuItem *createMenuItem() const;
112
    virtual QPlatformMenu *createSubMenu() const;
113
Q_SIGNALS:
114
    void aboutToShow();
115
    void aboutToHide();
116
117
private:
118
    quintptr m_tag;
119
};
120
121
class Q_GUI_EXPORT QPlatformMenuBar : public QObject
122
{
123
0
Q_OBJECT
124
0
public:
125
0
    virtual void insertMenu(QPlatformMenu *menu, QPlatformMenu *before) = 0;
126
0
    virtual void removeMenu(QPlatformMenu *menu) = 0;
127
0
    virtual void syncMenu(QPlatformMenu *menuItem) = 0;
128
0
    virtual void handleReparent(QWindow *newParentWindow) = 0;
129
0
    virtual QWindow *parentWindow() const { return nullptr; }
130
131
    virtual QPlatformMenu *menuForTag(quintptr tag) const = 0;
132
    virtual QPlatformMenu *createMenu() const;
133
};
134
135
QT_END_NAMESPACE
136
137
#endif
138