refs #617, CGuiActionBindHandler to use QAction with hotkeys

* QMenu can be automatically turned into a list of CActionBind objects for hotkeys
* trigger QAction from hotkeys
This commit is contained in:
Klaus Basan
2017-02-03 03:00:46 +01:00
committed by Mathew Sutcliffe
parent 8c81f2bea3
commit 5be38086b8
2 changed files with 145 additions and 0 deletions

View File

@@ -0,0 +1,60 @@
/* Copyright (C) 2017
* 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 BLACKGUI_GUIACTIONBIND_H
#define BLACKGUI_GUIACTIONBIND_H
#include "blackgui/blackguiexport.h"
#include "blackcore/actionbind.h"
#include <QMenu>
#include <QList>
#include <QScopedPointer>
namespace BlackGui
{
//! QObject derived handler to be registered with BlackCore::CActionBind
class BLACKGUI_EXPORT CGuiActionBindHandler : public QObject
{
Q_OBJECT
public:
//! Constructor
CGuiActionBindHandler(QAction *action);
//! Destructor
virtual ~CGuiActionBindHandler();
//! Bound function for BlackCore::CActionBind
void boundFunction(bool enabled);
//! Bind whole menu
static BlackCore::CActionBindings bindMenu(QMenu *menu, const QString &path = {});
private:
//! Corresponding action destroyed
void destroyed();
//! Set the action
void setAction(QAction *action);
//! Unbind this action
void unbind();
//! Append path for action
static QString appendPath(const QString &path, const QString &name);
int m_index = -1;
QAction *m_action = nullptr;
};
} // namespace
#endif // guard