QSkinny 0.8.0
C++/Qt UI toolkit
Loading...
Searching...
No Matches
QskShortcutMap.h
1/******************************************************************************
2 * QSkinny - Copyright (C) The authors
3 * SPDX-License-Identifier: BSD-3-Clause
4 *****************************************************************************/
5
6#ifndef QSK_SHORTCUT_MAP_H
7#define QSK_SHORTCUT_MAP_H
8
9#include "QskMetaFunction.h"
10#include <qquickwindow.h>
11
12class QQuickItem;
13class QKeySequence;
14
15class QSK_EXPORT QskShortcutMap
16{
17 public:
18 static void setAutoRepeat( int, bool on );
19 static void setEnabled( int, bool on );
20 static void setEnabled( const QKeySequence&, bool on );
21
22 static void removeShortcut( int );
23
24 // string based slots
25 static int addShortcut( const QKeySequence&,
26 bool autoRepeat, const QObject* receiver, const char* method );
27
28 static int addShortcut( QQuickWindow*, const QKeySequence&,
29 bool autoRepeat, const QObject* receiver, const char* method );
30
31 static int addShortcut( QQuickItem*, const QKeySequence&,
32 bool autoRepeat, const QObject* receiver, const char* method );
33
34 // functor based slots
35 template< typename T, QskMetaFunctionTraits::IsFunctorOrStaticFunction< T >* = nullptr >
36 static int addShortcut( const QKeySequence&, bool autoRepeat, T function );
37
38 template< typename T, QskMetaFunctionTraits::IsFunctorOrStaticFunction< T >* = nullptr >
39 static int addShortcut( QQuickItem*, const QKeySequence&, bool autoRepeat, T function );
40
41 template< typename T, QskMetaFunctionTraits::IsFunctorOrStaticFunction< T >* = nullptr >
42 static int addShortcut( QQuickWindow*, const QKeySequence&, bool autoRepeat, T function );
43
44 template< typename T, QskMetaFunctionTraits::IsFunctorOrStaticFunction< T >* = nullptr >
45 static int addShortcut( const QKeySequence&, bool autoRepeat,
46 const QObject* context, T function );
47
48 template< typename T, QskMetaFunctionTraits::IsFunctorOrStaticFunction< T >* = nullptr >
49 static int addShortcut( QQuickItem*, const QKeySequence&,
50 bool autoRepeat, const QObject* context, T function );
51
52 template< typename T, QskMetaFunctionTraits::IsFunctorOrStaticFunction< T >* = nullptr >
53 static int addShortcut( QQuickWindow*, const QKeySequence&,
54 bool autoRepeat, const QObject* context, T function );
55
56 template< typename T, QskMetaFunctionTraits::IsMemberFunction< T >* = nullptr >
57 static int addShortcut( const QKeySequence&, bool autoRepeat,
58 const typename QtPrivate::FunctionPointer< T >::Object* receiver, T function );
59
60 template< typename T, QskMetaFunctionTraits::IsMemberFunction< T >* = nullptr >
61 static int addShortcut( QQuickItem*, const QKeySequence&, bool autoRepeat,
62 const typename QtPrivate::FunctionPointer< T >::Object* receiver, T function );
63
64 template< typename T, QskMetaFunctionTraits::IsMemberFunction< T >* = nullptr >
65 static int addShortcut( QQuickWindow*, const QKeySequence&, bool autoRepeat,
66 const typename QtPrivate::FunctionPointer< T >::Object* receiver, T function );
67
68 // calling the registered callbacks manually
69 static bool invokeCallback( const QKeySequence& );
70 static bool invokeCallback( QQuickWindow*, const QKeySequence& );
71 static bool invokeCallback( QQuickItem*, const QKeySequence& );
72
73 static bool contextMatcher( const QQuickItem*, Qt::ShortcutContext );
74
75 private:
76 QskShortcutMap() = delete;
77 ~QskShortcutMap() = delete;
78
79 template< typename T >
80 static int addFunctionT(
81 QQuickItem*, const QKeySequence&, bool autoRepeat,
82 const QObject* receiver, T );
83
84 static int addFunction(
85 QQuickItem*, const QKeySequence&, bool autoRepeat,
86 const QObject* receiver, const QskMetaFunction& );
87
88 static int addMethod(
89 QQuickItem*, const QKeySequence&, bool autoRepeat,
90 const QObject* receiver, const char* );
91};
92
93inline int QskShortcutMap::addShortcut(
94 const QKeySequence& sequence, bool autoRepeat,
95 const QObject* receiver, const char* method )
96{
97 return addMethod( nullptr, sequence, autoRepeat, receiver, method );
98}
99
100inline int QskShortcutMap::addShortcut(
101 QQuickWindow* window, const QKeySequence& sequence,
102 bool autoRepeat, const QObject* receiver, const char* method )
103{
104 auto item = window ? window->contentItem() : nullptr;
105 return addMethod( item, sequence, autoRepeat, receiver, method );
106}
107
108template< typename T, QskMetaFunctionTraits::IsFunctorOrStaticFunction< T >* >
109inline int QskShortcutMap::addShortcut(
110 const QKeySequence& sequence, bool autoRepeat, T function )
111{
112 return addFunctionT( nullptr, sequence, autoRepeat, nullptr, function );
113}
114
115template< typename T, QskMetaFunctionTraits::IsFunctorOrStaticFunction< T >* >
116inline int QskShortcutMap::addShortcut(
117 QQuickItem* item, const QKeySequence& sequence,
118 bool autoRepeat, T function )
119{
120 return addFunctionT( item, sequence, autoRepeat, nullptr, function );
121}
122
123template< typename T, QskMetaFunctionTraits::IsFunctorOrStaticFunction< T >* >
124inline int QskShortcutMap::addShortcut(
125 QQuickWindow* window, const QKeySequence& sequence,
126 bool autoRepeat, T function )
127{
128 auto item = window ? window->contentItem() : nullptr;
129 return addFunctionT( item, sequence, autoRepeat, nullptr, function );
130}
131
132template< typename T, QskMetaFunctionTraits::IsFunctorOrStaticFunction< T >* >
133inline int QskShortcutMap::addShortcut(
134 const QKeySequence& sequence, bool autoRepeat,
135 const QObject* context, T function )
136{
137 return addFunctionT( nullptr, sequence, autoRepeat, context, function );
138}
139
140template< typename T, QskMetaFunctionTraits::IsFunctorOrStaticFunction< T >* >
141inline int QskShortcutMap::addShortcut(
142 QQuickItem* item, const QKeySequence& sequence, bool autoRepeat,
143 const QObject* context, T function )
144{
145 return addFunctionT( item, sequence, autoRepeat, context, function );
146}
147
148template< typename T, QskMetaFunctionTraits::IsFunctorOrStaticFunction< T >* >
149inline int QskShortcutMap::addShortcut(
150 QQuickWindow* window, const QKeySequence& sequence,
151 bool autoRepeat, const QObject* context, T function )
152{
153 auto item = window ? window->contentItem() : nullptr;
154 return addFunctionT( item, sequence, autoRepeat, context, function );
155}
156
157template< typename T, QskMetaFunctionTraits::IsMemberFunction< T >* >
158inline int QskShortcutMap::addShortcut(
159 const QKeySequence& sequence, bool autoRepeat,
160 const typename QtPrivate::FunctionPointer< T >::Object* receiver, T function )
161{
162 return addFunctionT( nullptr, sequence, autoRepeat, receiver, function );
163}
164
165template< typename T, QskMetaFunctionTraits::IsMemberFunction< T >* >
166inline int QskShortcutMap::addShortcut(
167 QQuickItem* item, const QKeySequence& sequence, bool autoRepeat,
168 const typename QtPrivate::FunctionPointer< T >::Object* receiver, T function )
169{
170 return addFunctionT( item, sequence, autoRepeat, receiver, function );
171}
172
173template< typename T, QskMetaFunctionTraits::IsMemberFunction< T >* >
174inline int QskShortcutMap::addShortcut(
175 QQuickWindow* window, const QKeySequence& sequence, bool autoRepeat,
176 const typename QtPrivate::FunctionPointer< T >::Object* receiver, T function )
177{
178 auto item = window ? window->contentItem() : nullptr;
179 return addFunctionT( item, sequence, autoRepeat, receiver, function );
180}
181
182template< typename T >
183inline int QskShortcutMap::addFunctionT(
184 QQuickItem* item, const QKeySequence& sequence, bool autoRepeat,
185 const QObject* context, T function )
186{
187 static_assert( QskMetaFunctionTraits::argumentCount< T >() == 0,
188 "QskShortcutMap::addShortcut: #number of arguments need to be 0." );
189
190 return addFunction( item, sequence, autoRepeat, context, function );
191}
192
193#endif