You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

148 lines
5.4 KiB
C

#ifndef SARIBBONACTIONSMANAGER_H
#define SARIBBONACTIONSMANAGER_H
#include "SARibbonGlobal.h"
#include <QObject>
#include <QAbstractListModel>
#include <QAction>
#include <QMap>
#include <QString>
#include <QSet>
class SARibbonBar;
class SARibbonCategory;
/**
* @brief SARibbonAction
*
* SARibbonActionsManagertagAction list
* SARibbonActionsManageraction list
*
* SARibbonActionsManageractionsaction
* SARibbonActionsManageraction listaction
*
* tagaction listtag@ref setTagName
* setTagName
*
* SARibbonActionsManager6@ref SARibbonActionsManager::ActionTag
* SARibbonActionsManager::UserDefineActionTag
*
* @ref filter @ref actions action list@ref allActions SARibbonActionsManager
*
*
* @ref autoRegisteActions action@ref SARibbonBar@ref SARibbonPannel action,Categorytag使autoRegisteActions
*
*
*/
class SA_RIBBON_EXPORT SARibbonActionsManager : public QObject
{
Q_OBJECT
SA_RIBBON_DECLARE_PRIVATE(SARibbonActionsManager)
friend class SARibbonActionsManagerModel;
public:
/**
* @brief action
*/
enum ActionTag
{
UnknowActionTag = 0, ///< 未知的tag
CommonlyUsedActionTag = 0x01, ///< 预设tag-常用命令
NotInFunctionalAreaActionTag = 0x02, ///< 预设tag-不在功能区命令
AutoCategoryDistinguishBeginTag = 0x1000, ///< 自动按Category划分的标签起始在@ref autoRegisteActions 函数会用到
AutoCategoryDistinguishEndTag = 0x2000, ///< 自动按Category划分的标签结束在@ref autoRegisteActions 函数会用到
NotInRibbonCategoryTag = 0x2001, ///< 不在功能区的标签@ref autoRegisteActions 函数会遍历所有category的action
UserDefineActionTag = 0x8000 ///< 自定义标签所有用户自定义tag要大于此tag
};
SARibbonActionsManager(SARibbonBar* bar);
~SARibbonActionsManager();
//设置tag对应的名字
void setTagName(int tag, const QString& name);
//获取tag对应的名字
QString tagName(int tag) const;
//移除tag注意这个函数非常耗时
void removeTag(int tag);
//注册action
bool registeAction(QAction* act, int tag, const QString& key = QString(), bool enableEmit = true);
//取消action的注册
void unregisteAction(QAction* act, bool enableEmit = true);
//过滤得到actions对应的引用实际是一个迭代器
QList< QAction* >& filter(int tag);
//通过tag筛选出系列action
QList< QAction* >& actions(int tag);
const QList< QAction* > actions(int tag) const;
//获取所有的标签
QList< int > actionTags() const;
//通过key获取action
QAction* action(const QString& key) const;
//通过action找到key
QString key(QAction* act) const;
//返回所有管理的action数
int count() const;
//返回所有管理的actions
QList< QAction* > allActions() const;
//自动加载action,返回tag对应的Category指针
QMap< int, SARibbonCategory* > autoRegisteActions(SARibbonBar* bar);
//自动加载widget下的actions函数返回的action,返回加载的数量,这些
QSet< QAction* > autoRegisteWidgetActions(QWidget* w, int tag, bool enableEmit = false);
//根据标题查找action
QList< QAction* > search(const QString& text);
//清除
void clear();
signals:
/**
* @brief
*/
void actionTagChanged(int tag, bool isdelete);
private slots:
void onActionDestroyed(QObject* o);
void onCategoryTitleChanged(const QString& title);
private:
void removeAction(QAction* act, bool enableEmit = true);
};
/**
* @brief SARibbonActionsManager model
*/
class SA_RIBBON_EXPORT SARibbonActionsManagerModel : public QAbstractListModel
{
Q_OBJECT
SA_RIBBON_DECLARE_PRIVATE(SARibbonActionsManagerModel)
public:
explicit SARibbonActionsManagerModel(QObject* p = nullptr);
explicit SARibbonActionsManagerModel(SARibbonActionsManager* m, QObject* p = nullptr);
~SARibbonActionsManagerModel();
virtual int rowCount(const QModelIndex& parent) const override;
virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
virtual Qt::ItemFlags flags(const QModelIndex& index) const override;
virtual QVariant data(const QModelIndex& index, int role) const override;
void setFilter(int tag);
void update();
void setupActionsManager(SARibbonActionsManager* m);
void uninstallActionsManager();
QAction* indexToAction(QModelIndex index) const;
void search(const QString& text);
private slots:
void onActionTagChanged(int tag, bool isdelete);
};
#endif // SARIBBONACTIONSMANAGER_H