SARibbon 2.5.2
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& smallSize, const QSize& largeSize);
85 // Gets the default icon size for tool buttons / 获取工具按钮的默认图标尺寸
86 QPair< QSize, QSize > toolButtonIconSize() const;
87
88 // 大按钮图标尺寸
89 void setLargeIconSize(const QSize& largeSize);
90 QSize largeIconSize() const;
91
92 // 小按钮图标尺寸
93 void setSmallIconSize(const QSize& largeSize);
94 QSize smallIconSize() const;
95
96 // 是否允许文字换行
97 bool isEnableWordWrap() const;
98 // 按钮的最大宽高比,这个系数决定按钮的最大宽度
99 qreal buttonMaximumAspectRatio() const;
100
101public:
102 // Adds an item to the layout (SARibbonPanelLayout not supported) / 向布局添加一个项目(SARibbonPanelLayout不支持)
103 void addItem(QLayoutItem* item) Q_DECL_OVERRIDE;
104
105 // QLayout 所必须的重载函数
106 QLayoutItem* itemAt(int index) const Q_DECL_OVERRIDE;
107
108 // Removes and returns the item at the specified index / 移除并返回指定索引处的项目
109 QLayoutItem* takeAt(int index) Q_DECL_OVERRIDE;
110
111 // Gets the number of items in the layout / 获取布局中项目的数量
112 int count() const Q_DECL_OVERRIDE;
113
114 // Checks if the layout is empty / 检查布局是否为空
115 bool isEmpty() const Q_DECL_OVERRIDE;
116
117 // Invalidates the layout, marking it as dirty / 使布局失效,将其标记为“脏”
118 void invalidate() Q_DECL_OVERRIDE;
119
120 // Returns the directions in which the layout can expand / 返回布局可以扩展的方向
121 Qt::Orientations expandingDirections() const Q_DECL_OVERRIDE;
122 void setGeometry(const QRect& rect) Q_DECL_OVERRIDE;
123 QSize minimumSize() const Q_DECL_OVERRIDE;
124 QSize sizeHint() const Q_DECL_OVERRIDE;
125
126protected:
127 // Gets the size of the option action button / 获取选项action按钮的尺寸
128 QSize optionActionButtonSize() const;
129 // 布局action
130 void doLayout();
131 // 把action转换为item,对于纯Action,此函数会创建SARibbonToolButton,
132 // rp用于告诉Layout生成什么样的窗口,详细见SARibbonPanelItem::RowProportion
134 void updateGeomArray(const QRect& setrect);
135 // 重新计算扩展条码,此函数必须在updateGeomArray函数之后调用
136 void recalcExpandGeomArray(const QRect& setrect);
137 // 设置文字允许换行
138 void setEnableWordWrap(bool on);
139 // 按钮的最大宽高比,这个系数决定按钮的最大宽度
140 void setButtonMaximumAspectRatio(qreal fac = 1.4);
141
142private:
143 // 根据列数,计算窗口的宽度,以及最大宽度
144 void columnWidthInfo(int colindex, int& width, int& maximum) const;
145
146 // Sets the panel's title label / 设置面板的标题标签
147 void setPanelTitleLabel(SARibbonPanelLabel* newTitleLabel);
148
149private:
150 QList< SARibbonPanelItem* > mItems;
151 int mColumnCount { 0 };
152 bool mExpandFlag { false };
153 QSize mSizeHint;
154 QSize mSmallToolButtonIconSize { 22, 22 };
155 QSize mLargeToolButtonIconSize { 32, 32 };
156 bool mDirty { true };
157 int mLargeHeight { 0 };
158 int mTitleHeight { 15 };
159 int mTitleSpace { 2 };
160 bool mEnableShowTitle { true };
161 SARibbonPanelLabel* mTitleLabel { nullptr };
162 QRect mTitleLabelGeometry;
163 QToolButton* mOptionActionBtn { nullptr };
164 QRect mOptionActionBtnGeometry;
165 bool mEnableWordWrap { true };
166 qreal mButtonMaximumAspectRatio { 1.4 };
167};
168
169#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