1 | // Copyright (C) 2017 The Qt Company Ltd. |
---|---|
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #include "qwidgetplatformmenuitem_p.h" |
5 | #include "qwidgetplatformmenu_p.h" |
6 | |
7 | #include <QtGui/qaction.h> |
8 | #include <QtWidgets/qmenu.h> |
9 | |
10 | QT_BEGIN_NAMESPACE |
11 | |
12 | QWidgetPlatformMenuItem::QWidgetPlatformMenuItem(QObject *parent) |
13 | : m_action(new QAction) |
14 | { |
15 | setParent(parent); |
16 | connect(sender: m_action.data(), signal: &QAction::hovered, context: this, slot: &QPlatformMenuItem::hovered); |
17 | connect(sender: m_action.data(), signal: &QAction::triggered, context: this, slot: &QPlatformMenuItem::activated); |
18 | } |
19 | |
20 | QWidgetPlatformMenuItem::~QWidgetPlatformMenuItem() |
21 | { |
22 | } |
23 | |
24 | QAction *QWidgetPlatformMenuItem::action() const |
25 | { |
26 | return m_action.data(); |
27 | } |
28 | |
29 | void QWidgetPlatformMenuItem::setText(const QString &text) |
30 | { |
31 | m_action->setText(text); |
32 | } |
33 | |
34 | void QWidgetPlatformMenuItem::setIcon(const QIcon &icon) |
35 | { |
36 | m_action->setIcon(icon); |
37 | } |
38 | |
39 | void QWidgetPlatformMenuItem::setMenu(QPlatformMenu *menu) |
40 | { |
41 | QWidgetPlatformMenu *widgetMenu = qobject_cast<QWidgetPlatformMenu *>(object: menu); |
42 | m_action->setMenu(widgetMenu ? widgetMenu->menu() : nullptr); |
43 | } |
44 | |
45 | void QWidgetPlatformMenuItem::setVisible(bool visible) |
46 | { |
47 | m_action->setVisible(visible); |
48 | } |
49 | |
50 | void QWidgetPlatformMenuItem::setIsSeparator(bool separator) |
51 | { |
52 | m_action->setSeparator(separator); |
53 | } |
54 | |
55 | void QWidgetPlatformMenuItem::setFont(const QFont &font) |
56 | { |
57 | m_action->setFont(font); |
58 | } |
59 | |
60 | void QWidgetPlatformMenuItem::setRole(MenuRole role) |
61 | { |
62 | m_action->setMenuRole(static_cast<QAction::MenuRole>(role)); |
63 | } |
64 | |
65 | void QWidgetPlatformMenuItem::setCheckable(bool checkable) |
66 | { |
67 | m_action->setCheckable(checkable); |
68 | } |
69 | |
70 | void QWidgetPlatformMenuItem::setChecked(bool checked) |
71 | { |
72 | m_action->setChecked(checked); |
73 | } |
74 | |
75 | #if QT_CONFIG(shortcut) |
76 | void QWidgetPlatformMenuItem::setShortcut(const QKeySequence &shortcut) |
77 | { |
78 | m_action->setShortcut(shortcut); |
79 | } |
80 | #endif |
81 | |
82 | void QWidgetPlatformMenuItem::setEnabled(bool enabled) |
83 | { |
84 | m_action->setEnabled(enabled); |
85 | } |
86 | |
87 | void QWidgetPlatformMenuItem::setIconSize(int size) |
88 | { |
89 | Q_UNUSED(size); |
90 | } |
91 | |
92 | QT_END_NAMESPACE |
93 | |
94 | #include "moc_qwidgetplatformmenuitem_p.cpp" |
95 |