mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-03 07:35:48 +08:00
refs #617, CActionItem supports icon
* standard paths for applications * support for Qt::DecorationRole * QMap<QString, QPixmap> m_availableActions * Constructor for icon only * only leafs support actions
This commit is contained in:
committed by
Mathew Sutcliffe
parent
6a96d14baa
commit
a34be02e07
@@ -11,6 +11,20 @@
|
||||
|
||||
namespace BlackCore
|
||||
{
|
||||
CActionBind::CActionBind(const QString &action, const QPixmap &icon)
|
||||
{
|
||||
CActionBind::registerAction(action, icon);
|
||||
}
|
||||
|
||||
QString CActionBind::registerAction(const QString &action, const QPixmap &icon)
|
||||
{
|
||||
const QString a = CActionBind::normalizeAction(action);
|
||||
auto inputManger = CInputManager::instance();
|
||||
Q_ASSERT_X(inputManger, Q_FUNC_INFO, "Missing input manager");
|
||||
inputManger->registerAction(a, icon);
|
||||
return a;
|
||||
}
|
||||
|
||||
CActionBind::~CActionBind()
|
||||
{
|
||||
unbind();
|
||||
@@ -31,7 +45,8 @@ namespace BlackCore
|
||||
QString CActionBind::normalizeAction(const QString &action)
|
||||
{
|
||||
QString n = action.trimmed();
|
||||
if (!n.startsWith('/')) { return n.insert(0, QChar('/')); }
|
||||
if (!n.startsWith('/')) { n.insert(0, QChar('/')); }
|
||||
if (n.endsWith('/')) { n.remove(n.length() - 1 , 1);}
|
||||
return n;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
#include "blackcore/inputmanager.h"
|
||||
#include "blackcoreexport.h"
|
||||
#include <QPixmap>
|
||||
|
||||
namespace BlackCore
|
||||
{
|
||||
@@ -29,15 +30,18 @@ namespace BlackCore
|
||||
|
||||
//! Constructor
|
||||
template <typename Receiver>
|
||||
CActionBind(const QString &action, Receiver *receiver, MembFunc<Receiver> slot = nullptr, const std::function<void()> &deleteCallback = {}) :
|
||||
CActionBind(const QString &action, const QPixmap &icon, Receiver *receiver,
|
||||
MembFunc<Receiver> slot = nullptr,
|
||||
const std::function<void()> &deleteCallback = {}) :
|
||||
m_deleteCallback(deleteCallback)
|
||||
{
|
||||
const QString a = CActionBind::normalizeAction(action);
|
||||
auto inputManger = CInputManager::instance();
|
||||
inputManger->registerAction(a);
|
||||
m_index = inputManger->bind(a, receiver, slot);
|
||||
const QString a = CActionBind::registerAction(action, icon);
|
||||
m_index = CInputManager::instance()->bind(a, receiver, slot);
|
||||
}
|
||||
|
||||
//! Signature just to set an icon for an action
|
||||
CActionBind(const QString &action, const QPixmap &icon);
|
||||
|
||||
//! Destructor
|
||||
~CActionBind();
|
||||
|
||||
@@ -51,9 +55,12 @@ namespace BlackCore
|
||||
int getIndex() const { return m_index; }
|
||||
|
||||
private:
|
||||
//! normalize the name string
|
||||
//! Normalize the action string
|
||||
static QString normalizeAction(const QString &action);
|
||||
|
||||
//! Register action
|
||||
static QString registerAction(const QString &action, const QPixmap &icon);
|
||||
|
||||
int m_index = -1; //!< action indexx (unique)
|
||||
std::function<void()> m_deleteCallback; //!< called when deleted
|
||||
};
|
||||
|
||||
@@ -37,12 +37,12 @@ namespace BlackCore
|
||||
return &instance;
|
||||
}
|
||||
|
||||
void CInputManager::registerAction(const QString &action)
|
||||
void CInputManager::registerAction(const QString &action, const QPixmap &icon)
|
||||
{
|
||||
if (!m_availableActions.contains(action))
|
||||
{
|
||||
m_availableActions.push_back(action);
|
||||
emit hotkeyActionRegistered( { action } );
|
||||
m_availableActions.insert(action, icon);
|
||||
emit hotkeyActionRegistered({ action });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,15 +52,15 @@ namespace BlackCore
|
||||
{
|
||||
if (!m_availableActions.contains(action))
|
||||
{
|
||||
m_availableActions.push_back(action);
|
||||
emit hotkeyActionRegistered( { action } );
|
||||
m_availableActions.insert(action, {});
|
||||
emit hotkeyActionRegistered({ action });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CInputManager::unbind(int index)
|
||||
{
|
||||
auto info = std::find_if (m_boundActions.begin(), m_boundActions.end(), [index] (const BindInfo &info) { return info.m_index == index; });
|
||||
auto info = std::find_if(m_boundActions.begin(), m_boundActions.end(), [index](const BindInfo & info) { return info.m_index == index; });
|
||||
if (info != m_boundActions.end())
|
||||
{
|
||||
m_boundActions.erase(info);
|
||||
@@ -104,7 +104,7 @@ namespace BlackCore
|
||||
void CInputManager::callFunctionsBy(const QString &action, bool isKeyDown)
|
||||
{
|
||||
if (action.isEmpty()) { return; }
|
||||
if(m_actionRelayingEnabled) emit remoteActionFromLocal(action, isKeyDown);
|
||||
if (m_actionRelayingEnabled) emit remoteActionFromLocal(action, isKeyDown);
|
||||
|
||||
for (const auto &boundAction : m_boundActions)
|
||||
{
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include "blackinput/keyboard.h"
|
||||
#include "blackmisc/input/hotkeycombination.h"
|
||||
#include "blackmisc/settingscache.h"
|
||||
#include "blackmisc/icons.h"
|
||||
|
||||
#include <QHash>
|
||||
#include <QObject>
|
||||
@@ -38,7 +39,7 @@ namespace BlackCore
|
||||
|
||||
public:
|
||||
//! Register new action
|
||||
void registerAction(const QString &action);
|
||||
void registerAction(const QString &action, const QPixmap &icon = BlackMisc::CIcons::empty16());
|
||||
|
||||
//! Register remote actions
|
||||
void registerRemoteActions(const QStringList &actions);
|
||||
@@ -72,7 +73,10 @@ namespace BlackCore
|
||||
void resetAllActions() { m_configuredActions.clear(); }
|
||||
|
||||
//! Get all available and known actions
|
||||
QStringList allAvailableActions() const { return m_availableActions; }
|
||||
QStringList allAvailableActions() const { return m_availableActions.keys(); }
|
||||
|
||||
//! All actions and their icons (if any)
|
||||
QMap<QString, QPixmap> allAvailableActionsAndIcons() const { return m_availableActions; }
|
||||
|
||||
//! Enable event forwarding to core
|
||||
void setForwarding(bool enabled) { m_actionRelayingEnabled = enabled; }
|
||||
@@ -129,7 +133,7 @@ namespace BlackCore
|
||||
std::unique_ptr<BlackInput::IKeyboard> m_keyboard;
|
||||
std::unique_ptr<BlackInput::IJoystick> m_joystick;
|
||||
|
||||
QStringList m_availableActions;
|
||||
QMap<QString, QPixmap> m_availableActions;
|
||||
QHash<BlackMisc::Input::CHotkeyCombination, QString> m_configuredActions;
|
||||
QVector<BindInfo> m_boundActions;
|
||||
|
||||
@@ -142,4 +146,4 @@ namespace BlackCore
|
||||
};
|
||||
}
|
||||
|
||||
#endif //BLACKCORE_INPUTMANAGER_H
|
||||
#endif //guard
|
||||
|
||||
Reference in New Issue
Block a user