203 lines
5.3 KiB
C++
203 lines
5.3 KiB
C++
/**
|
||
* @file VecViewCommand.h
|
||
* @brief 窗口工具栏上的Action插件集合管理类
|
||
* @date 2014-5-26
|
||
* @author: liyonggang
|
||
*/
|
||
#ifndef PAI_FRAME_OSGVIEWCOMMAND_H
|
||
#define PAI_FRAME_OSGVIEWCOMMAND_H
|
||
#pragma warning( push ,0)
|
||
|
||
#include <QAction>
|
||
#include "OSGFramework.h"
|
||
#include "BaseObject.h"
|
||
|
||
#pragma warning( pop )
|
||
#pragma warning( disable: 4251 )
|
||
|
||
|
||
BEGIN_OSGGRAPHICS_NAMESPACE;
|
||
class CVecSceneManager;
|
||
|
||
/**
|
||
* @class Action的数据描述
|
||
*/
|
||
struct OSGFRAMEWORK_EXPORT sAction
|
||
{
|
||
public:
|
||
sAction();
|
||
|
||
sAction( QString strIcon1,std::wstring strText1,bool bChecked1,bool bCheckAble1 ,QUuid DigitizerIDOrBuilderOjectID,QString slotFunctionName1,QKeySequence keyShortcut1 = QKeySequence () );
|
||
|
||
public:
|
||
QString strIcon;
|
||
std::wstring strText;
|
||
bool bChecked;
|
||
bool bCheckAble;
|
||
QUuid m_DigitizerIDOrBuilderOjectID;//(开关digitizer ID) 或 (显示隐藏UI builder的object ID)
|
||
QKeySequence keyShortcut;
|
||
QString slotFunctionName;
|
||
};
|
||
|
||
/**
|
||
* @class 窗口工具栏上的Action插件集合管理类
|
||
*/
|
||
class OSGFRAMEWORK_EXPORT CVecViewCommand : public QObject
|
||
{
|
||
Q_OBJECT
|
||
public:
|
||
|
||
/**
|
||
* @brief 初始化
|
||
*/
|
||
CVecViewCommand( );
|
||
void InitSceneManager( CVecSceneManager *pSceneManager );
|
||
CVecSceneManager* GetSceneManager();
|
||
|
||
/**
|
||
* @brief 执行Action,模拟用户点击此Actioin
|
||
* @param viewCommandID : command ID
|
||
* @bChecked : 如果是Checkable的Action,是否Checked
|
||
*/
|
||
bool DoAction( QUuid viewCommandID,bool bChecked );
|
||
|
||
/**
|
||
* @brief 根据Command ID查找QAction
|
||
*/
|
||
QAction* GetAction( QUuid viewCommandID,bool bCreateIfNotExist = true );
|
||
|
||
/**
|
||
* @brief Action 是否checked and Enabled
|
||
*/
|
||
bool GetActionVisble( QUuid viewCommandID );
|
||
|
||
//返回当前视口安装的所有的Action
|
||
QMap<QUuid,QObject* >& GetAllActions();
|
||
|
||
/**
|
||
* @brief 创建QAction
|
||
*/
|
||
static void BuildActionGeneral( CVecViewCommand &viewCommand,QUuid viewCommandID );
|
||
|
||
|
||
/**
|
||
* @brief 根据view commandID查找Digitizer ID
|
||
*/
|
||
static QUuid GetDigitizerIDByViewCommandID( QUuid viewCommandID );
|
||
// Action槽函数
|
||
private slots:
|
||
void slotActionClicked(bool bChecked);
|
||
|
||
private:
|
||
|
||
//批量的根据插件注册的元数据创建QAction
|
||
void CreatActions( QList<QUuid> listviewCommandID );
|
||
|
||
// Cache Action
|
||
void AddUIElementToMap( QUuid viewCommandID,QObject *pAction );
|
||
|
||
// 根据插件注册的元数据创建QAction
|
||
QAction* _CreateAction( QUuid viewCommandID );
|
||
|
||
private:
|
||
CVecSceneManager *m_pSceneMgr;
|
||
QMap<QUuid/*Action ID*/,QObject* /*Action*/ >m_mapUIElement; //cache Action
|
||
};
|
||
|
||
typedef void (*BUILDUIELEMENT_FUNC )(CVecViewCommand &,QUuid);
|
||
typedef void (*UIELEMENTACTION_FUNC )(CVecViewCommand &,QUuid,bool);
|
||
|
||
/**
|
||
* @class 创建Action函数指针,Action"槽"函数指针
|
||
*/
|
||
struct OSGFRAMEWORK_EXPORT sUIELEMENTFunction
|
||
{
|
||
public:
|
||
sUIELEMENTFunction()
|
||
{
|
||
buildFunc = NULL;
|
||
ActionSlot = NULL;
|
||
}
|
||
sUIELEMENTFunction( BUILDUIELEMENT_FUNC buildFunc1,UIELEMENTACTION_FUNC ActionSlot1 )
|
||
{
|
||
buildFunc = buildFunc1;
|
||
ActionSlot = ActionSlot1;
|
||
}
|
||
BUILDUIELEMENT_FUNC buildFunc;
|
||
UIELEMENTACTION_FUNC ActionSlot;
|
||
};
|
||
|
||
/**
|
||
* @brief ViewComand的创建和槽的函数指针
|
||
*/
|
||
OSGFRAMEWORK_EXPORT QMap< QUuid/*Action ID*/,sUIELEMENTFunction >& GetmapUIElementFunc();
|
||
|
||
/**
|
||
* @brief 注册View Command
|
||
* @param viewCommandID :Command ID
|
||
* @param s : Command 的元数据描述(文本,图标等)
|
||
* @param pSlotAction: Command对应的"槽"函数
|
||
*/
|
||
OSGFRAMEWORK_EXPORT void RegisterViewAction( QUuid viewCommandID,sAction s,UIELEMENTACTION_FUNC pSlotAction);
|
||
|
||
/**
|
||
* @brief ViewComand的元数据:图标,文本等
|
||
*/
|
||
OSGFRAMEWORK_EXPORT QMap<QUuid/*Action ID*/,sAction >& _GetMapActionData();
|
||
|
||
OSGFRAMEWORK_EXPORT CVecViewCommand& GetGlobalCommand();
|
||
|
||
/**
|
||
* @class View Command注册的元数据
|
||
*/
|
||
struct OSGFRAMEWORK_EXPORT sRegisterViewAction
|
||
{
|
||
QUuid actionID;
|
||
sAction s;
|
||
UIELEMENTACTION_FUNC pSlotAction;
|
||
};
|
||
|
||
/**
|
||
* @class 实现View Command自动注册的辅助类
|
||
*/
|
||
class OSGFRAMEWORK_EXPORT CRegisterViewActionAuto
|
||
{
|
||
public:
|
||
CRegisterViewActionAuto( sRegisterViewAction *pRegisterViewAction )
|
||
{
|
||
while( pRegisterViewAction )
|
||
{
|
||
if( (*pRegisterViewAction).actionID.isNull() ) break;
|
||
|
||
RegisterViewAction( pRegisterViewAction->actionID, pRegisterViewAction->s, pRegisterViewAction->pSlotAction );
|
||
++pRegisterViewAction;
|
||
}
|
||
}
|
||
};
|
||
|
||
//view Comand 插件注册宏
|
||
#define BEGIN_REGISTER_VIEWCOMMAND()\
|
||
sRegisterViewAction g_sRegisterViewActionData[]={\
|
||
|
||
|
||
#define END_REGISTER_VIEWCOMMAND()\
|
||
,{QUuid(),sAction(),NULL } };\
|
||
CRegisterViewActionAuto g_CRegisterViewActionAuto( g_sRegisterViewActionData );
|
||
|
||
//自动注册示例代码
|
||
//BEGIN_REGISTER_VIEWCOMMAND()
|
||
//VIEW_COMMAND_ITEM( GetViewCmdID_ViewAll(),"viewall.png" , "View All",false,false,"",_SlotViewAll)
|
||
//END_REGISTER_VIEWCOMMAND()
|
||
#define VIEW_COMMAND_ITEM( viewCommandID,actionIcon,actionText, actionbChecked, actionbCheckAble,DigitizerIDOrBuilderOjectID,slotFunction )\
|
||
{ viewCommandID,sAction( actionIcon,actionText,actionbChecked,actionbCheckAble,DigitizerIDOrBuilderOjectID,#slotFunction),slotFunction }
|
||
|
||
#define VIEW_COMMAND_ITEM_SHORCUT( viewCommandID,actionIcon,actionText, actionbChecked, actionbCheckAble,DigitizerIDOrBuilderOjectID,slotFunction,actionshortcut )\
|
||
{ viewCommandID,sAction( actionIcon,actionText,actionbChecked,actionbCheckAble,DigitizerIDOrBuilderOjectID,#slotFunction,actionshortcut),slotFunction }
|
||
|
||
|
||
END_OSGGRAPHICS_NAMESPACE;
|
||
|
||
using namespace pai::graphics;
|
||
|
||
#endif
|