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#ifndef QQUICKACTION_P_P_H
5#define QQUICKACTION_P_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtCore/private/qobject_p.h>
19#include <QtCore/qvariant.h>
20#include <QtCore/qstring.h>
21#if QT_CONFIG(shortcut)
22# include <QtGui/qkeysequence.h>
23#endif
24#include <QtQuick/private/qquickitemchangelistener_p.h>
25
26QT_BEGIN_NAMESPACE
27
28class QShortcutEvent;
29class QQuickActionGroup;
30
31class QQuickActionPrivate : public QObjectPrivate,
32 public QSafeQuickItemChangeListener<QQuickActionPrivate>
33{
34 Q_DECLARE_PUBLIC(QQuickAction)
35
36public:
37 static QQuickActionPrivate *get(QQuickAction *action)
38 {
39 return action->d_func();
40 }
41
42#if QT_CONFIG(shortcut)
43 QVariant shortcut() const;
44 void setShortcut(const QVariant &shortcut);
45#endif
46
47 void setEnabled(bool enable);
48
49 bool watchItem(QQuickItem *item);
50 bool unwatchItem(QQuickItem *item);
51
52 void registerItem(QQuickItem *item);
53 void unregisterItem(QQuickItem *item);
54
55 void itemVisibilityChanged(QQuickItem *item) override;
56 void itemDestroyed(QQuickItem *item) override;
57
58 bool handleShortcutEvent(QObject *object, QShortcutEvent *event);
59
60 void trigger(QObject*, bool doToggle);
61
62#if QT_CONFIG(shortcut)
63 class ShortcutEntry
64 {
65 public:
66 explicit ShortcutEntry(QObject *target);
67 ~ShortcutEntry();
68
69 QObject *target() const;
70 int shortcutId() const;
71
72 void grab(const QKeySequence &vshortcut, bool enabled);
73 void ungrab();
74
75 void setEnabled(bool enabled);
76
77 private:
78 int m_shortcutId = 0;
79 QObject *m_target = nullptr;
80 };
81
82 ShortcutEntry *findShortcutEntry(QObject *target) const;
83 void updateDefaultShortcutEntry();
84#endif // QT_CONFIG(shortcut)
85
86 bool explicitEnabled = false;
87 bool enabled = true;
88 bool checked = false;
89 bool checkable = false;
90 QString text;
91 QQuickIcon icon;
92#if QT_CONFIG(shortcut)
93 QKeySequence keySequence;
94 QVariant vshortcut;
95 ShortcutEntry *defaultShortcutEntry = nullptr;
96 QList<ShortcutEntry *> shortcutEntries;
97#endif
98 QQuickActionGroup *group = nullptr;
99};
100
101QT_END_NAMESPACE
102
103#endif // QQUICKACTION_P_P_H
104

source code of qtdeclarative/src/quicktemplates/qquickaction_p_p.h