-
Notifications
You must be signed in to change notification settings - Fork 3
/
RibbonGalleryGroup.h
131 lines (87 loc) · 3.2 KB
/
RibbonGalleryGroup.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
//
// Created by weiwu on 21-4-30.
//
#ifndef RIBBON_RIBBONGALLERYGROUP_H
#define RIBBON_RIBBONGALLERYGROUP_H
#include <QList>
#include <QListView>
#include <QStyledItemDelegate>
#include <RibbonGalleryItem.h>
/**
* RibbonGalleryGroup 对应的显示代理
*/
class RibbonGalleryGroupItemDelegate : public QStyledItemDelegate {
public:
RibbonGalleryGroupItemDelegate(RibbonGalleryGroup *group, QObject *parent = Q_NULLPTR);
virtual void
paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const Q_DECL_OVERRIDE;
virtual QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const Q_DECL_OVERRIDE;
virtual void paintIconOnly(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
virtual void
paintIconWithText(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
private:
RibbonGalleryGroup *m_group;
};
/**
* RibbonGalleryGroup 对应的model
*/
class RibbonGalleryGroupModel : public QAbstractListModel {
Q_OBJECT
public:
RibbonGalleryGroupModel(QObject *parent = Q_NULLPTR);
~RibbonGalleryGroupModel();
virtual int rowCount(const QModelIndex &parent) const Q_DECL_OVERRIDE;
virtual Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE;
virtual QVariant data(const QModelIndex &index, int role) const Q_DECL_OVERRIDE;
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const Q_DECL_OVERRIDE;
virtual bool setData(const QModelIndex &index, const QVariant &value, int role) Q_DECL_OVERRIDE;
void clear();
RibbonGalleryItem *at(int row) const;
void insert(int row, RibbonGalleryItem *item);
RibbonGalleryItem *take(int row);
void append(RibbonGalleryItem *item);
private:
QList<RibbonGalleryItem *> m_items;
};
class RibbonGalleryGroupPrivate;
/**
* 组负责显示管理Gallery Item
*/
class RibbonGalleryGroup : public QListView {
Q_OBJECT
Q_PROPERTY(bool enableIconText
READ
enableIconText
WRITE
setEnableIconText)
public:
///
/// \brief 预设样式
///
enum PreinstallStyle {
LargeIconWithText ///< 大图标带文字
, LargeIconOnly
};
RibbonGalleryGroup(QWidget *w = 0);
virtual ~RibbonGalleryGroup();
void setPreinstallStyle(PreinstallStyle style);
void addItem(const QIcon &icon);
void addItem(RibbonGalleryItem *item);
void addActionItem(QAction *act);
void addActionItemList(const QList<QAction *> &acts);
//构建一个model,这个model的父类是SARibbonGalleryGroup,如果要共享model,需要手动处理model的父类
void setupGroupModel();
RibbonGalleryGroupModel *groupModel();
//是否在Gallery的图标下显示文字
void setEnableIconText(bool enable);
bool enableIconText() const;
void setGroupTitle(const QString &title);
QString groupTitle() const;
private slots:
void onItemClicked(const QModelIndex &index);
signals:
void groupTitleChanged(const QString &title);
private:
RibbonGalleryGroupPrivate *m_d;
};
#endif //RIBBON_RIBBONGALLERYGROUP_H