-
Notifications
You must be signed in to change notification settings - Fork 3
/
RibbonActionsManager.h
152 lines (101 loc) · 4.15 KB
/
RibbonActionsManager.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
//
// Created by weiwu on 21-5-2.
//
#ifndef RIBBON_RIBBONACTIONSMANAGER_H
#define RIBBON_RIBBONACTIONSMANAGER_H
#include <QtCore/QObject>
#include <QtWidgets/QAction>
#include "RibbonCategory.h"
#include "RibbonMainWindow.h"
class RibbonActionsManagerPrivate;
class RibbonActionsModelPrivate;
class RibbonActionsManager : public QObject {
Q_OBJECT
friend class RibbonActionsManagerModel;
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以及RibbonMainWindow下的action,如果两个
,
UserDefineActionTag = 0x8000 ///< 自定义标签,所有用户自定义tag要大于此tag
};
RibbonActionsManager(QObject *p = nullptr);
~RibbonActionsManager();
//设置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, RibbonCategory *> autoRegisteActions(RibbonMainWindow *w);
//自动加载widget下的actions函数返回的action,返回加载的数量,这些
QSet<QAction *> autoRegisteWidgetActions(QWidget *w, int tag, bool enableEmit = false);
//根据标题查找action
QList<QAction *> search(const QString &text);
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);
private:
RibbonActionsManagerPrivate *m_d;
};
class RibbonActionsManagerModel : public QAbstractListModel {
Q_OBJECT
public:
explicit RibbonActionsManagerModel(QObject *p = nullptr);
explicit RibbonActionsManagerModel(RibbonActionsManager *m, QObject *p = nullptr);
~RibbonActionsManagerModel();
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(RibbonActionsManager *m);
void uninstallActionsManager();
QAction *indexToAction(QModelIndex index) const;
void search(const QString &text);
private slots:
void onActionTagChanged(int tag, bool isdelete);
private:
RibbonActionsModelPrivate *m_d;
};
#endif //RIBBON_RIBBONACTIONSMANAGER_H