SARibbon 2.5.1
SARibbon wiki
载入中...
搜索中...
未找到
SARibbonPanelLayout.h
1#ifndef SARIBBONPANELLAYOUT_H
2#define SARIBBONPANELLAYOUT_H
3#include "SARibbonGlobal.h"
4#include <QLayout>
5#include "SARibbonPanelItem.h"
6class QToolButton;
7class SARibbonPanel;
9
20class SA_RIBBON_EXPORT SARibbonPanelLayout : public QLayout
21{
22 Q_OBJECT
23 friend class SARibbonPanel;
24
25public:
26 explicit SARibbonPanelLayout(QWidget* p = nullptr);
28 // Gets the SARibbonPanel that owns this layout / 获取拥有此布局的SARibbonPanel
29 SARibbonPanel* ribbonPanel() const;
30
31 // Inserts an action at a specific index / 在指定索引处插入一个action
32 void insertAction(int index, QAction* act, SARibbonPanelItem::RowProportion rp = SARibbonPanelItem::None);
33
34 // Sets the option action for the panel / 为面板设置选项action
35 void setOptionAction(QAction* action);
36
37 // Checks if an option action is set / 检查是否设置了选项action
38 bool isHaveOptionAction() const;
39
40 // Retrieves the SARibbonPanelItem associated with an action / 获取与action关联的SARibbonPanelItem
41 SARibbonPanelItem* panelItem(QAction* action) const;
42
43 // Gets the last item added to the layout / 获取最后添加到布局的项目
44 SARibbonPanelItem* lastItem() const;
45
46 // Gets the widget associated with the last item / 获取与最后一个项目关联的窗口部件
47 QWidget* lastWidget() const;
48
49 // Moves an item from one index to another / 将一个项目从一个索引移动到另一个索引
50 void move(int from, int to);
51 // 判断是否需要重新布局
52 bool isDirty() const;
53 // 更新尺寸
54 void updateGeomArray();
55
56 // Finds the index of an action in the layout / 在布局中查找一个action的索引
57 int indexByAction(QAction* action) const;
58
59 // Gets the height of the panel's title / 获取面板标题的高度
60 int panelTitleHeight() const;
61
62 // Sets the height of the panel's title / 设置面板标题的高度
63 void setPanelTitleHeight(int newTitleHeight);
64
65 // Checks if the panel's title is enabled for display / 检查面板标题是否启用显示
66 bool isEnableShowPanelTitle() const;
67
68 // Sets whether the panel's title is enabled for display / 设置面板标题是否启用显示
69 void setEnableShowPanelTitle(bool on);
70
71 // Gets the height of large buttons / 获取大按钮的高度
72 int largeButtonHeight() const;
73
74 // Gets the spacing between the title and the buttons / 获取标题与按钮之间的间距
75 int panelTitleSpace() const;
76
77 // Sets the spacing between the title and the buttons / 设置标题与按钮之间的间距
78 void setPanelTitleSpace(int newTitleSpace);
79
80 // Gets the panel's title label / 获取面板的标题标签
81 SARibbonPanelLabel* panelTitleLabel() const;
82
83 // Sets the default icon size for tool buttons / 设置工具按钮的默认图标尺寸
84 void setToolButtonIconSize(const QSize& s);
85
86 // Gets the default icon size for tool buttons / 获取工具按钮的默认图标尺寸
87 QSize toolButtonIconSize() const;
88
89 // 是否允许文字换行
90 bool isEnableWordWrap() const;
91 // 按钮的最大宽高比,这个系数决定按钮的最大宽度
92 qreal buttonMaximumAspectRatio() const;
93
94public:
95 // Adds an item to the layout (SARibbonPanelLayout not supported) / 向布局添加一个项目(SARibbonPanelLayout不支持)
96 void addItem(QLayoutItem* item) Q_DECL_OVERRIDE;
97
98 // QLayout 所必须的重载函数
99 QLayoutItem* itemAt(int index) const Q_DECL_OVERRIDE;
100
101 // Removes and returns the item at the specified index / 移除并返回指定索引处的项目
102 QLayoutItem* takeAt(int index) Q_DECL_OVERRIDE;
103
104 // Gets the number of items in the layout / 获取布局中项目的数量
105 int count() const Q_DECL_OVERRIDE;
106
107 // Checks if the layout is empty / 检查布局是否为空
108 bool isEmpty() const Q_DECL_OVERRIDE;
109
110 // Invalidates the layout, marking it as dirty / 使布局失效,将其标记为“脏”
111 void invalidate() Q_DECL_OVERRIDE;
112
113 // Returns the directions in which the layout can expand / 返回布局可以扩展的方向
114 Qt::Orientations expandingDirections() const Q_DECL_OVERRIDE;
115 void setGeometry(const QRect& rect) Q_DECL_OVERRIDE;
116 QSize minimumSize() const Q_DECL_OVERRIDE;
117 QSize sizeHint() const Q_DECL_OVERRIDE;
118
119protected:
120 // Gets the size of the option action button / 获取选项action按钮的尺寸
121 QSize optionActionButtonSize() const;
122 // 布局action
123 void doLayout();
124 // 把action转换为item,对于纯Action,此函数会创建SARibbonToolButton,
125 // rp用于告诉Layout生成什么样的窗口,详细见SARibbonPanelItem::RowProportion
127 void updateGeomArray(const QRect& setrect);
128 // 重新计算扩展条码,此函数必须在updateGeomArray函数之后调用
129 void recalcExpandGeomArray(const QRect& setrect);
130 // 设置文字允许换行
131 void setEnableWordWrap(bool on);
132 // 按钮的最大宽高比,这个系数决定按钮的最大宽度
133 void setButtonMaximumAspectRatio(qreal fac = 1.4);
134
135private:
136 // 根据列数,计算窗口的宽度,以及最大宽度
137 void columnWidthInfo(int colindex, int& width, int& maximum) const;
138
139 // Sets the panel's title label / 设置面板的标题标签
140 void setPanelTitleLabel(SARibbonPanelLabel* newTitleLabel);
141
142private:
143 QList< SARibbonPanelItem* > mItems;
144 int mColumnCount { 0 };
145 bool mExpandFlag { false };
146 QSize mSizeHint;
147 QSize mDefaultToolButtonIconSize { 22, 22 };
148 bool mDirty { true };
149 int mLargeHeight { 0 };
150 int mTitleHeight { 15 };
151 int mTitleSpace { 2 };
152 bool mEnableShowTitle { true };
153 SARibbonPanelLabel* mTitleLabel { nullptr };
154 QRect mTitleLabelGeometry;
155 QToolButton* mOptionActionBtn { nullptr };
156 QRect mOptionActionBtnGeometry;
157 bool mEnableWordWrap { true };
158 qreal mButtonMaximumAspectRatio { 1.4 };
159};
160
161#endif // SARIBBONPANELLAYOUT_H
是对panel所有子窗口的抽象,参考qt的toolbar
Definition SARibbonPanelItem.h:17
RowProportion
定义了行的占比,ribbon中有large,media和small三种占比
Definition SARibbonPanelItem.h:23
@ None
为定义占比,这时候将会依据expandingDirections来判断,如果能有Qt::Vertical,就等同于Large,否则就是Small
Definition SARibbonPanelItem.h:24
SARibbonPanel的标题label,此类用于qss
Definition SARibbonPanel.h:21
Layout manager for SARibbonPanel / SARibbonPanel的布局管理器
Definition SARibbonPanelLayout.h:21
panel页窗口,panel是ribbon的面板用于承放控件 / Ribbon panel container, used to hold controls
Definition SARibbonPanel.h:93