SARibbon 2.5.2
SARibbon wiki
载入中...
搜索中...
未找到
SARibbonPanel.h
1#ifndef SARIBBONPANEL_H
2#define SARIBBONPANEL_H
3#include "SARibbonGlobal.h"
4#include "SARibbonPanelItem.h"
5#include "SARibbonToolButton.h"
6#include <QLayout>
7#include <QWidget>
8#include <QLabel>
9class SARibbonMenu;
10class SARibbonGallery;
11class QGridLayout;
15class SARibbonBar;
16
20class SA_RIBBON_EXPORT SARibbonPanelLabel : public QLabel
21{
22 Q_OBJECT
23public:
24 SARibbonPanelLabel(QWidget* parent = nullptr);
25};
26
92class SA_RIBBON_EXPORT SARibbonPanel : public QFrame
93{
94 Q_OBJECT
95 SA_RIBBON_DECLARE_PRIVATE(SARibbonPanel)
96 friend class SARibbonBar;
97 friend class SARibbonCategory;
98 friend class SARibbonCategoryPrivate;
99 friend class SARibbonCustomizeWidgetPrivate;
100 friend class SARibbonPanelLayout;
101 Q_PROPERTY(bool isCanCustomize READ isCanCustomize WRITE setCanCustomize)
102 Q_PROPERTY(bool isExpanding READ isExpanding WRITE setExpanding)
103 Q_PROPERTY(QString panelName READ panelName WRITE setPanelName)
104public:
109 {
120
130 TwoRowMode
131 };
132 Q_ENUM(PanelLayoutMode)
133public:
134 using FpRibbonToolButtonIterate = std::function< bool(SARibbonToolButton*) >;
135
136public:
137 explicit SARibbonPanel(QWidget* parent = nullptr);
138 explicit SARibbonPanel(const QString& name, QWidget* parent = nullptr);
139 ~SARibbonPanel() Q_DECL_OVERRIDE;
140 using QWidget::addAction;
141
142 // 把action加入到panel
143 void addAction(QAction* action, SARibbonPanelItem::RowProportion rowProportion);
144 // 生成并添加一个action
145 void addAction(QAction* act,
146 QToolButton::ToolButtonPopupMode popMode,
147 SARibbonPanelItem::RowProportion rowProportion = SARibbonPanelItem::Large);
148 // 把action加入到panel,并以大图标显示
149 void addLargeAction(QAction* action);
150 // 把action加入到panel,在三行模式下会以中图标显示
151 void addMediumAction(QAction* action);
152 // 把action加入到panel,并以小图标显示
153 void addSmallAction(QAction* action);
154
155 // 把action加入到panel,并以小图标显示
156 void addSmallAction(QAction* action, QToolButton::ToolButtonPopupMode popMode);
157 // 把action加入到panel,并以大图标显示
158 void addLargeAction(QAction* action, QToolButton::ToolButtonPopupMode popMode);
159 // 把action加入到panel,在三行模式下会以中图标显示
160 void addMediumAction(QAction* action, QToolButton::ToolButtonPopupMode popMode);
161 // 生成并添加一个action
162 QAction* addAction(const QString& text,
163 const QIcon& icon,
164 QToolButton::ToolButtonPopupMode popMode,
165 SARibbonPanelItem::RowProportion rowProportion = SARibbonPanelItem::Large);
166
167 // 添加menu
168 void addMenu(QMenu* menu,
169 SARibbonPanelItem::RowProportion rowProportion,
170 QToolButton::ToolButtonPopupMode popMode = QToolButton::InstantPopup);
171 // 添加普通大菜单
172 void addLargeMenu(QMenu* menu, QToolButton::ToolButtonPopupMode popMode = QToolButton::InstantPopup);
173 // 添加普通小按钮菜单
174 void addMediumMenu(QMenu* menu, QToolButton::ToolButtonPopupMode popMode = QToolButton::InstantPopup);
175 // 添加普通小按钮菜单
176 void addSmallMenu(QMenu* menu, QToolButton::ToolButtonPopupMode popMode = QToolButton::InstantPopup);
177
178 // 添加窗口
179 QAction* addWidget(QWidget* w, SARibbonPanelItem::RowProportion rowProportion);
180
181 // 添加窗口,占用ribbon的一行
182 QAction* addSmallWidget(QWidget* w);
183
184 // 添加窗口,占用ribbon的一行
185 QAction* addMediumWidget(QWidget* w);
186
187 // 添加窗口,占用所有行
188 QAction* addLargeWidget(QWidget* w);
189
190 // 添加一个Gallery
191 SARibbonGallery* addGallery(bool expanding = true);
192
193 // 添加分割线
194 QAction* addSeparator();
195
196 // 从panel中把action对应的button提取出来,如果action没有对应的button,就返回nullptr
197 SARibbonToolButton* actionToRibbonToolButton(QAction* action);
198
199 // 设置操作action,如果要去除,传入nullptr指针即可,SARibbonPanel不会对QAction的所有权进行管理
200 // OptionAction也会触发actionTriggered信号
201 void setOptionAction(QAction* action);
202
203 // 判断是否存在OptionAction
204 bool isHaveOptionAction() const;
205
206 // 获取所有的buttons
207 QList< SARibbonToolButton* > ribbonToolButtons() const;
208
209 // 获取PanelLayoutMode
210 PanelLayoutMode panelLayoutMode() const;
211 void setPanelLayoutMode(PanelLayoutMode mode);
212
213 // 更新按钮的尺寸,这个函数在panel的布局状态变换后需要调用刷新
214 void resetToolButtonSize();
215
216 // 判断是否为2行模式
217 bool isTwoRow() const;
218
219 // 把panel设置为扩展模式,此时会撑大水平区域
220 void setExpanding(bool isExpanding = true);
221 // 是否是扩展模式
222 bool isExpanding() const;
223
224 // 标题栏高度
225 int titleHeight() const;
226
227 // 是否显示标题,显示标题后,标题的高度需要设置,默认高度为15
228 bool isEnableShowTitle() const;
229
230 // action对应的布局index,此操作一般用于移动moveAction,其他意义不大
231 int actionIndex(QAction* act) const;
232
233 // 移动action
234 void moveAction(int from, int to);
235
236 // 判断是否可以自定义
237 bool isCanCustomize() const;
238 void setCanCustomize(bool b);
239
240 // 标题
241 QString panelName() const;
242 void setPanelName(const QString& title);
243
244 // 大图标的高度
245 int largeButtonHeight() const;
246
247 // 获取布局对应的item,此函数目前仅仅在自定义过程中用到
248 const QList< SARibbonPanelItem* >& ribbonPanelItem() const;
249
250 // 获取panel layout
251 SARibbonPanelLayout* panelLayout() const;
252
253 // 更新布局
254 void updateItemGeometry();
255
256 // 获取category指针,如果没有parent,或者不在category管理,返回nullptr
257 SARibbonCategory* category() const;
258
259 // 获取ribbonBar指针,如果没有返回nullptr
260 SARibbonBar* ribbonBar() const;
261
262 // 按钮之间的间隔
263 int spacing() const;
264
265 // 设置按钮的icon尺寸
266 void setToolButtonIconSize(const QSize& smallSize, const QSize& largeSize);
267 QPair< QSize, QSize > toolButtonIconSize() const;
268
269 // 大按钮图标尺寸
270 void setLargeIconSize(const QSize& largeSize);
271 QSize largeIconSize() const;
272
273 // 小按钮图标尺寸
274 void setSmallIconSize(const QSize& smallSize);
275 QSize smallIconSize() const;
276
277 // 获取最近添加的按钮
278 SARibbonToolButton* lastAddActionButton();
279
280 // 获取panel标题的label控件
281 SARibbonPanelLabel* titleLabel() const;
282
283 // 是否允许换行
284 bool isEnableWordWrap() const;
285
286 // 按钮的最大宽高比,这个系数决定按钮的最大宽度
287 qreal buttonMaximumAspectRatio() const;
288
289 // 此函数会遍历SARibbonPanel下的所有RibbonToolButton,执行函数指针(bool(SARibbonRibbonToolButton*)),函数指针返回false则停止迭代
290 bool iterateButton(FpRibbonToolButtonIterate fp) const;
291
292public:
293 virtual QSize sizeHint() const Q_DECL_OVERRIDE;
294 virtual QSize minimumSizeHint() const Q_DECL_OVERRIDE;
295
296public:
297 // panel高度推荐
298 static int panelHeightHint(const QFontMetrics& fm, PanelLayoutMode layMode, int panelTitleHeight);
299 // 把action的行属性设置进action中,action自身携带了行属性
300 static void setActionRowProportionProperty(QAction* action, SARibbonPanelItem::RowProportion rp);
301 // 获取action的行属性
302 static SARibbonPanelItem::RowProportion getActionRowProportionProperty(QAction* action);
303 // 把action的PopupMode属性设置进action中,action自身携带了PopupMode属性
304 static void setActionToolButtonPopupModeProperty(QAction* action, QToolButton::ToolButtonPopupMode popMode);
305 // 获取action的PopupMode属性
306 static QToolButton::ToolButtonPopupMode getActionToolButtonPopupModeProperty(QAction* action);
307 // 把action的ToolButtonStyle属性设置进action中,action自身携带了ToolButtonStyle属性
308 static void setActionToolButtonStyleProperty(QAction* action, Qt::ToolButtonStyle buttonStyle);
309 // 获取action的ToolButtonStyle属性
310 static Qt::ToolButtonStyle getActionToolButtonStyleProperty(QAction* action);
311
312Q_SIGNALS:
313
318 void actionTriggered(QAction* action);
319
324 void panelNameChanged(const QString& n);
325
326protected:
327 virtual void actionEvent(QActionEvent* e) Q_DECL_OVERRIDE;
328 virtual void changeEvent(QEvent* e) Q_DECL_OVERRIDE;
329
330protected:
331 // 以下这些方法是为了接收SARibbonBar的对应接口的参数,用户在操作SARibbonPanel的时候不需要进行设置
332 // SARibbonPanel在被设置到SARibbonCategory的时候,SARibbonCategory会重新把自身的这些参数同步到panel中
333 // 同理,SARibbonCategory加入SARibbonBar的时候,SARibbonBar会重新把自身的这些参数同步到category
334
335 // 设置标题栏高度
336 void setTitleHeight(int h);
337
338 // 设置按钮之间的间隔
339 void setSpacing(int n);
340
341 // 是否显示标题,显示标题后,标题的高度需要设置,默认高度为15
342 void setEnableShowTitle(bool on);
343
344 // 设置按钮允许换行,注意图标大小是由文字决定的,两行文字会让图标变小,如果想图标变大,文字不换行是最好的
345 void setEnableWordWrap(bool on);
346
347 // 按钮的最大宽高比,这个系数决定按钮的最大宽度
348 void setButtonMaximumAspectRatio(qreal fac = 1.4);
349};
350
351#endif // SARIBBONPANEL_H
SARibbonBar继承于QMenuBar,在SARibbonMainWindow中直接替换了原来的QMenuBar
Definition SARibbonBar.h:94
Ribbon控件中的分类选项卡页面(Category)
Definition SARibbonCategory.h:66
Gallery控件
Definition SARibbonGallery.h:48
用在ribbon的menu 可以通过StyleSheet设置样式而不影响QMenu
Definition SARibbonMenu.h:11
是对panel所有子窗口的抽象,参考qt的toolbar
Definition SARibbonPanelItem.h:17
SARibbonPanel的标题label,此类用于qss
Definition SARibbonPanel.h:21
Layout manager for SARibbonPanel / SARibbonPanel的布局管理器
Definition SARibbonPanelLayout.h:21
Panel右下角的操作按钮
Definition SARibbonPanelOptionButton.h:17
panel页窗口,panel是ribbon的面板用于承放控件 / Ribbon panel container, used to hold controls
Definition SARibbonPanel.h:93
PanelLayoutMode
Layout mode for the panel / 面板的布局模式
Definition SARibbonPanel.h:109
@ ThreeRowMode
Three-row layout mode / 三行布局模式
Definition SARibbonPanel.h:119
Ribbon interface adapted tool button / Ribbon界面适用的toolButton
Definition SARibbonToolButton.h:20