qskinny/src/controls/QskShortcutMap.h

189 lines
7.3 KiB
C
Raw Normal View History

/******************************************************************************
* QSkinny - Copyright (C) 2016 Uwe Rathmann
* This file may be used under the terms of the QSkinny License, Version 1.0
*****************************************************************************/
#ifndef QSK_SHORTCUT_MAP_H
#define QSK_SHORTCUT_MAP_H
2018-03-12 09:27:54 +01:00
#include "QskMetaFunction.h"
2018-07-19 14:10:48 +02:00
#include <qquickwindow.h>
class QQuickItem;
class QKeySequence;
class QSK_EXPORT QskShortcutMap
{
2018-08-03 08:15:28 +02:00
public:
static void setAutoRepeat( int, bool on );
static void setEnabled( int, bool on );
static void removeShortcut( int );
2018-03-12 09:27:54 +01:00
// string based slots
static int addShortcut( const QKeySequence&,
bool autoRepeat, const QObject* receiver, const char* method );
2018-03-12 09:27:54 +01:00
static int addShortcut( QQuickWindow*, const QKeySequence&,
bool autoRepeat, const QObject* receiver, const char* method );
2018-03-12 09:27:54 +01:00
static int addShortcut( QQuickItem*, const QKeySequence&,
bool autoRepeat, const QObject* receiver, const char* method );
2018-03-12 09:27:54 +01:00
// functor based slots
2018-11-03 17:14:09 +01:00
template< typename T, QskMetaFunctionTraits::IsFunctorOrStaticFunction< T >* = nullptr >
static int addShortcut( const QKeySequence&, bool autoRepeat, T function );
2018-11-03 17:14:09 +01:00
template< typename T, QskMetaFunctionTraits::IsFunctorOrStaticFunction< T >* = nullptr >
static int addShortcut( QQuickItem*, const QKeySequence&, bool autoRepeat, T function );
2018-11-03 17:14:09 +01:00
template< typename T, QskMetaFunctionTraits::IsFunctorOrStaticFunction< T >* = nullptr >
static int addShortcut( QQuickWindow*, const QKeySequence&, bool autoRepeat, T function );
2018-11-03 17:14:09 +01:00
template< typename T, QskMetaFunctionTraits::IsFunctorOrStaticFunction< T >* = nullptr >
static int addShortcut( const QKeySequence&, bool autoRepeat,
const QObject* context, T function );
template< typename T, QskMetaFunctionTraits::IsFunctorOrStaticFunction< T >* = nullptr >
2018-03-12 09:27:54 +01:00
static int addShortcut( QQuickItem*, const QKeySequence&,
bool autoRepeat, const QObject* context, T function );
2018-11-03 17:14:09 +01:00
template< typename T, QskMetaFunctionTraits::IsFunctorOrStaticFunction< T >* = nullptr >
2018-03-12 09:27:54 +01:00
static int addShortcut( QQuickWindow*, const QKeySequence&,
bool autoRepeat, const QObject* context, T function );
2018-11-03 17:14:09 +01:00
template< typename T, QskMetaFunctionTraits::IsMemberFunction< T >* = nullptr >
static int addShortcut( const QKeySequence&, bool autoRepeat,
const typename QtPrivate::FunctionPointer< T >::Object* receiver, T function );
template< typename T, QskMetaFunctionTraits::IsMemberFunction< T >* = nullptr >
static int addShortcut( QQuickItem*, const QKeySequence&, bool autoRepeat,
const typename QtPrivate::FunctionPointer< T >::Object* receiver, T function );
template< typename T, QskMetaFunctionTraits::IsMemberFunction< T >* = nullptr >
static int addShortcut( QQuickWindow*, const QKeySequence&, bool autoRepeat,
const typename QtPrivate::FunctionPointer< T >::Object* receiver, T function );
static bool contextMatcher( const QQuickItem*, Qt::ShortcutContext );
2018-08-03 08:15:28 +02:00
private:
QskShortcutMap() = delete;
~QskShortcutMap() = delete;
template< typename T >
static int addFunctionT(
QQuickItem* item, const QKeySequence&, bool autoRepeat,
const QObject* receiver, T );
2018-03-12 09:27:54 +01:00
static int addFunction(
QQuickItem* item, const QKeySequence&, bool autoRepeat,
const QObject* receiver, const QskMetaFunction& );
2018-03-12 09:27:54 +01:00
static int addMethod(
QQuickItem* item, const QKeySequence&, bool autoRepeat,
2018-03-12 09:27:54 +01:00
const QObject* receiver, const char* );
};
inline int QskShortcutMap::addShortcut(
const QKeySequence& sequence, bool autoRepeat,
const QObject* receiver, const char* method )
{
return addMethod( nullptr, sequence, autoRepeat, receiver, method );
}
inline int QskShortcutMap::addShortcut(
2018-03-12 09:27:54 +01:00
QQuickWindow* window, const QKeySequence& sequence,
bool autoRepeat, const QObject* receiver, const char* method )
{
auto item = window ? window->contentItem() : nullptr;
return addMethod( item, sequence, autoRepeat, receiver, method );
}
2018-11-03 17:14:09 +01:00
template< typename T, QskMetaFunctionTraits::IsFunctorOrStaticFunction< T >* >
inline int QskShortcutMap::addShortcut(
const QKeySequence& sequence, bool autoRepeat, T function )
{
return addFunctionT( nullptr, sequence, autoRepeat, nullptr, function );
}
2018-11-03 17:14:09 +01:00
template< typename T, QskMetaFunctionTraits::IsFunctorOrStaticFunction< T >* >
inline int QskShortcutMap::addShortcut(
2018-11-03 17:14:09 +01:00
QQuickItem* item, const QKeySequence& sequence,
bool autoRepeat, T function )
2019-01-04 13:42:16 +01:00
{
2018-11-03 17:14:09 +01:00
return addFunctionT( item, sequence, autoRepeat, nullptr, function );
}
2018-11-03 17:14:09 +01:00
template< typename T, QskMetaFunctionTraits::IsFunctorOrStaticFunction< T >* >
inline int QskShortcutMap::addShortcut(
2018-11-03 17:14:09 +01:00
QQuickWindow* window, const QKeySequence& sequence,
bool autoRepeat, T function )
{
2018-11-03 17:14:09 +01:00
auto item = window ? window->contentItem() : nullptr;
return addFunctionT( item, sequence, autoRepeat, nullptr, function );
}
2018-11-03 17:14:09 +01:00
template< typename T, QskMetaFunctionTraits::IsFunctorOrStaticFunction< T >* >
inline int QskShortcutMap::addShortcut(
2018-11-03 17:14:09 +01:00
const QKeySequence& sequence, bool autoRepeat,
const QObject* context, T function )
{
2018-11-03 17:14:09 +01:00
return addFunctionT( nullptr, sequence, autoRepeat, context, function );
}
2018-11-03 17:14:09 +01:00
template< typename T, QskMetaFunctionTraits::IsFunctorOrStaticFunction< T >* >
inline int QskShortcutMap::addShortcut(
2018-11-03 17:14:09 +01:00
QQuickItem* item, const QKeySequence& sequence, bool autoRepeat,
const QObject* context, T function )
{
2018-11-03 17:14:09 +01:00
return addFunctionT( item, sequence, autoRepeat, context, function );
}
2018-11-03 17:14:09 +01:00
template< typename T, QskMetaFunctionTraits::IsFunctorOrStaticFunction< T >* >
inline int QskShortcutMap::addShortcut(
QQuickWindow* window, const QKeySequence& sequence,
bool autoRepeat, const QObject* context, T function )
{
auto item = window ? window->contentItem() : nullptr;
return addFunctionT( item, sequence, autoRepeat, context, function );
}
2018-11-03 17:14:09 +01:00
template< typename T, QskMetaFunctionTraits::IsMemberFunction< T >* >
inline int QskShortcutMap::addShortcut(
const QKeySequence& sequence, bool autoRepeat,
const typename QtPrivate::FunctionPointer< T >::Object* receiver, T function )
2019-01-04 13:42:16 +01:00
{
2018-11-03 17:14:09 +01:00
return addFunctionT( nullptr, sequence, autoRepeat, receiver, function );
2019-01-04 13:42:16 +01:00
}
2018-11-03 17:14:09 +01:00
template< typename T, QskMetaFunctionTraits::IsMemberFunction< T >* >
inline int QskShortcutMap::addShortcut(
QQuickItem* item, const QKeySequence& sequence, bool autoRepeat,
const typename QtPrivate::FunctionPointer< T >::Object* receiver, T function )
2019-01-04 13:42:16 +01:00
{
2018-11-03 17:14:09 +01:00
return addFunctionT( item, sequence, autoRepeat, receiver, function );
2019-01-04 13:42:16 +01:00
}
2018-11-03 17:14:09 +01:00
template< typename T, QskMetaFunctionTraits::IsMemberFunction< T >* >
inline int QskShortcutMap::addShortcut(
QQuickWindow* window, const QKeySequence& sequence, bool autoRepeat,
const typename QtPrivate::FunctionPointer< T >::Object* receiver, T function )
2019-01-04 13:42:16 +01:00
{
2018-11-03 17:14:09 +01:00
auto item = window ? window->contentItem() : nullptr;
return addFunctionT( item, sequence, autoRepeat, receiver, function );
2019-01-04 13:42:16 +01:00
}
2018-11-03 17:14:09 +01:00
template< typename T >
inline int QskShortcutMap::addFunctionT(
QQuickItem* item, const QKeySequence& sequence, bool autoRepeat,
const QObject* context, T function )
{
static_assert( QskMetaFunctionTraits::argumentCount< T >() == 0,
"QskShortcutMap::addShortcut: #number of arguments need to be 0." );
2018-03-12 09:27:54 +01:00
return addFunction( item, sequence, autoRepeat, context, function );
}
#endif