mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-07 19:35:32 +08:00
refs #453 Simplify hotkey action registration and relaying
This commit is contained in:
committed by
Mathew Sutcliffe
parent
199a1e5fcb
commit
6644c73703
51
src/blackcore/actionbind.h
Normal file
51
src/blackcore/actionbind.h
Normal file
@@ -0,0 +1,51 @@
|
||||
/* Copyright (C) 2015
|
||||
* swift project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef BLACKCORE_ACTIONBIND_H
|
||||
#define BLACKCORE_ACTIONBIND_H
|
||||
|
||||
#include "blackcore/input_manager.h"
|
||||
|
||||
namespace BlackCore
|
||||
{
|
||||
/*!
|
||||
* CActionBind binds a member function to an action
|
||||
*/
|
||||
class CActionBind
|
||||
{
|
||||
public:
|
||||
//! Signature of receiving member function
|
||||
template <typename U>
|
||||
using MembFunc = void (U::*)(bool);
|
||||
|
||||
//! Constructor
|
||||
template <typename Receiver>
|
||||
CActionBind(const QString &action, Receiver *receiver, MembFunc<Receiver> slot = nullptr)
|
||||
{
|
||||
auto inputManger = CInputManager::instance();
|
||||
inputManger->registerAction(action);
|
||||
m_index = inputManger->bind(action, receiver, slot);
|
||||
}
|
||||
|
||||
//! Destructor
|
||||
~CActionBind()
|
||||
{
|
||||
auto inputManger = CInputManager::instance();
|
||||
inputManger->unbind(m_index);
|
||||
}
|
||||
|
||||
private:
|
||||
int m_index;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user