SARibbon 2.5.2
SARibbon wiki
载入中...
搜索中...
未找到
SARibbonBar.h
1#ifndef SARIBBONBAR_H
2#define SARIBBONBAR_H
3#include "SARibbonCategory.h"
4#include "SARibbonContextCategory.h"
5#include "SARibbonGlobal.h"
6#include <QMenuBar>
7#include <QScopedPointer>
8#include <QVariant>
9
10class QAction;
11class QAbstractButton;
13class SARibbonTabBar;
18
170class SA_RIBBON_EXPORT SARibbonBar : public QMenuBar
171{
172 Q_OBJECT
173 SA_RIBBON_DECLARE_PRIVATE(SARibbonBar)
174 friend class SARibbonMainWindow;
175 friend class SARibbonSystemButtonBar;
176 Q_PROPERTY(RibbonStyles ribbonStyle READ currentRibbonStyle WRITE setRibbonStyle)
177 Q_PROPERTY(bool minimumMode READ isMinimumMode WRITE setMinimumMode)
178 Q_PROPERTY(bool minimumModeButton READ haveShowMinimumModeButton WRITE showMinimumModeButton)
179 Q_PROPERTY(QColor windowTitleTextColor READ windowTitleTextColor WRITE setWindowTitleTextColor)
180 Q_PROPERTY(QColor tabBarBaseLineColor READ tabBarBaseLineColor WRITE setTabBarBaseLineColor)
181 Q_PROPERTY(Qt::Alignment windowTitleAligment READ windowTitleAligment WRITE setWindowTitleAligment)
182 Q_PROPERTY(bool enableWordWrap READ isEnableWordWrap WRITE setEnableWordWrap)
183 Q_PROPERTY(bool enableShowPanelTitle READ isEnableShowPanelTitle WRITE setEnableShowPanelTitle)
184 Q_PROPERTY(bool tabOnTitle READ isTabOnTitle WRITE setTabOnTitle)
185 Q_PROPERTY(SARibbonPanel::PanelLayoutMode panelLayoutMode READ panelLayoutMode WRITE setPanelLayoutMode)
186
187public:
189 {
190 RibbonStyleLoose = 0x0001, // bit:0000 0001
191 RibbonStyleCompact = 0x0002, // bit:0000 0010
192 RibbonStyleThreeRow = 0x0010, // bit:0001 0000
193 RibbonStyleTwoRow = 0x0020, // bit:0010 0000
194
195 RibbonStyleLooseThreeRow = RibbonStyleLoose | RibbonStyleThreeRow,
196 RibbonStyleCompactThreeRow = RibbonStyleCompact | RibbonStyleThreeRow,
197 RibbonStyleLooseTwoRow = RibbonStyleLoose | RibbonStyleTwoRow,
198 RibbonStyleCompactTwoRow = RibbonStyleCompact | RibbonStyleTwoRow
199 };
200 Q_ENUM(RibbonStyleFlag)
201 Q_DECLARE_FLAGS(RibbonStyles, RibbonStyleFlag)
202 Q_FLAG(RibbonStyles)
203
204
208 {
210 NormalRibbonMode
211 };
212 Q_ENUM(RibbonMode)
213public:
214 using FpCategoryIterate = std::function< bool(SARibbonCategory*) >;
215 using FpPanelIterate = SARibbonCategory::FpPanelIterate;
219 using FpContextCategoryHighlight = std::function< QColor(const QColor&) >;
220
221public:
223 static bool isTwoRowStyle(RibbonStyles s);
225 static bool isThreeRowStyle(RibbonStyles s);
227 static bool isLooseStyle(RibbonStyles s);
229 static bool isCompactStyle(RibbonStyles s);
231 static QString versionString();
232
234 static QList< QColor > defaultContextCategoryColorList();
235
237 static void initHighDpi();
238
239public:
241 explicit SARibbonBar(QWidget* parent = nullptr);
243 ~SARibbonBar();
245 QAbstractButton* applicationButton();
246
248 void setApplicationButton(QAbstractButton* btn);
249
251 SARibbonTabBar* ribbonTabBar();
252
254 SARibbonCategory* addCategoryPage(const QString& title);
256 void addCategoryPage(SARibbonCategory* category);
257
259 Q_INVOKABLE void addCategoryPage(QWidget* category);
260
262 SARibbonCategory* insertCategoryPage(const QString& title, int index);
264 void insertCategoryPage(SARibbonCategory* category, int index);
265
267 SARibbonCategory* categoryByName(const QString& title) const;
268
270 SARibbonCategory* categoryByObjectName(const QString& objname) const;
271
273 SARibbonCategory* categoryByIndex(int index) const;
274
276 void hideCategory(SARibbonCategory* category);
277
279 void showCategory(SARibbonCategory* category);
280
282 bool isCategoryVisible(const SARibbonCategory* c) const;
283
285 int categoryIndex(const SARibbonCategory* c) const;
286
288 void moveCategory(int from, int to);
289
291 QList< SARibbonCategory* > categoryPages(bool getAll = true) const;
292
294 void removeCategory(SARibbonCategory* category);
295
298 addContextCategory(const QString& title, const QColor& color = QColor(), const QVariant& id = QVariant());
300 void addContextCategory(SARibbonContextCategory* context);
301
303 void showContextCategory(SARibbonContextCategory* context);
304
306 void hideContextCategory(SARibbonContextCategory* context);
307
309 bool isContextCategoryVisible(SARibbonContextCategory* context);
310
312 void setContextCategoryVisible(SARibbonContextCategory* context, bool visible);
313
315 QList< SARibbonContextCategory* > contextCategoryList() const;
316
318 void destroyContextCategory(SARibbonContextCategory* context);
319
321 QList< int > currentVisibleContextCategoryTabIndexs() const;
322
324 void setMinimumMode(bool isHide);
325
327 bool isMinimumMode() const;
328
330 void showMinimumModeButton(bool isShow = true);
331
333 bool haveShowMinimumModeButton() const;
334
336 QAction* minimumModeAction() const;
337
339 bool isEnableTabDoubleClickToMinimumMode() const;
341 void setTabDoubleClickToMinimumMode(bool on = true) const;
342
344 RibbonMode currentRibbonState() const;
345
347 int tabBarHeight() const;
349 void setTabBarHeight(int h, bool resizeByNow = true);
350
352 int titleBarHeight() const;
354 void setTitleBarHeight(int h, bool resizeByNow = true);
355
357 int categoryHeight() const;
359 void setCategoryHeight(int h, bool resizeByNow = true);
360
362 int normalModeMainBarHeight() const;
363
365 int minimumModeMainBarHeight() const;
366
368 SARibbonButtonGroupWidget* activeRightButtonGroup();
369
371 SARibbonButtonGroupWidget* rightButtonGroup();
372
374 SARibbonQuickAccessBar* activeQuickAccessBar();
375
377 SARibbonQuickAccessBar* quickAccessBar();
378
380 SARibbonTitleIconWidget* titleIconWidget() const;
381
383 void setTitleIconVisible(bool on = true);
385 bool isTitleIconVisible() const;
386
388 void setRibbonStyle(RibbonStyles v);
390 RibbonStyles currentRibbonStyle() const;
391
393 void setCurrentIndex(int index);
394
396 int currentIndex();
397
399 void raiseCategory(SARibbonCategory* category);
400
402 bool isTwoRowStyle() const;
404 bool isThreeRowStyle() const;
405
407 bool isLooseStyle() const;
409 bool isCompactStyle() const;
410
412 void updateRibbonGeometry();
413
415 SARibbonPanel::PanelLayoutMode panelLayoutMode() const;
417 void setPanelLayoutMode(SARibbonPanel::PanelLayoutMode m);
418
420 void setTabOnTitle(bool on);
422 bool isTabOnTitle() const;
423
425 void setTabBarBaseLineColor(const QColor& clr);
427 QColor tabBarBaseLineColor() const;
428
430 void setWindowTitleTextColor(const QColor& clr);
432 QColor windowTitleTextColor() const;
433
435 void setTitleVisible(bool on = false);
437 bool isTitleVisible() const;
438
440 void setWindowTitleBackgroundBrush(const QBrush& bk);
442 QBrush windowTitleBackgroundBrush() const;
443
445 void setWindowTitleAligment(Qt::Alignment al);
447 Qt::Alignment windowTitleAligment() const;
448
450 void setEnableWordWrap(bool on);
452 bool isEnableWordWrap() const;
453
455 void setButtonMaximumAspectRatio(qreal fac = 1.4);
457 qreal buttonMaximumAspectRatio() const;
458
460 void setPanelTitleHeight(int h);
462 int panelTitleHeight() const;
463
465 void setEnableShowPanelTitle(bool on);
467 bool isEnableShowPanelTitle() const;
468
470 void setPanelSpacing(int n);
472 int panelSpacing() const;
473
475 void setPanelToolButtonIconSize(const QSize& smallSize, const QSize& largeSize);
477 QPair< QSize, QSize > panelToolButtonIconSize() const;
478
480 void setPanelLargeIconSize(const QSize& largeSize);
482 QSize panelLargeIconSize() const;
483
485 void setPanelSmallIconSize(const QSize& smallSize);
487 QSize panelSmallIconSize() const;
488
490 SARibbonStackedWidget* ribbonStackedWidget();
491
493 void setContextCategoryColorList(const QList< QColor >& cls);
495 QList< QColor > contextCategoryColorList() const;
496
498 void setContextCategoryTitleTextColor(const QColor& clr);
500 QColor contextCategoryTitleTextColor() const;
501
503 void setContextCategoryColorHighLight(FpContextCategoryHighlight fp);
504
506 void setRibbonAlignment(SARibbonAlignment al);
508 SARibbonAlignment ribbonAlignment() const;
509
511 bool iterateCategory(FpCategoryIterate fp) const;
513 bool iteratePanel(FpPanelIterate fp) const;
514
516 void setCornerWidgetVisible(bool on, Qt::Corner c = Qt::TopLeftCorner);
517
519 void setApplicationButtonVerticalExpansion(bool on = true);
521 bool isApplicationButtonVerticalExpansion() const;
522
524 QList< QAction* > allActions() const;
526 bool isUseRibbonFrame() const;
527Q_SIGNALS:
528
543
555 void currentRibbonTabChanged(int index);
556
569
581 void ribbonStyleChanged(SARibbonBar::RibbonStyles nowStyle);
582
596 void titleBarHeightChanged(int oldHeight, int newHeight);
597
609 void actionTriggered(QAction* action);
610
611protected:
613 bool eventFilter(QObject* obj, QEvent* e) override;
615 int calcMinTabBarWidth() const;
617 void updateCategoryTitleToTabName();
619 void setSystemButtonGroupSize(const QSize& s);
621 void setMainWindowStyles(SARibbonMainWindowStyles s);
622protected Q_SLOTS:
624 void onWindowTitleChanged(const QString& title);
626 void onWindowIconChanged(const QIcon& i);
628 void onCategoryWindowTitleChanged(const QString& title);
630 void onStackWidgetHided();
632 virtual void onCurrentRibbonTabChanged(int index);
634 virtual void onCurrentRibbonTabClicked(int index);
636 virtual void onCurrentRibbonTabDoubleClicked(int index);
638 void onContextsCategoryPageAdded(SARibbonCategory* category);
640 void onContextsCategoryCategoryNameChanged(SARibbonCategory* category, const QString& title);
642 void onTabMoved(int from, int to);
643
644private:
645 int tabIndex(SARibbonCategory* obj);
646 void paintInLooseStyle();
647 void paintInCompactStyle();
648
649 // 刷新所有ContextCategoryManagerData,这个在单独一个Category删除时调用
650 void updateContextCategoryManagerData();
651 void synchronousCategoryData(bool autoUpdate = true);
652 // 把窗口标题文字转换为显示的文字,这里主要针对[*]占位符进行替换
653 QString toDisplayTitleText(const QString& title) const;
654 // 获取标题显示的区域
655 QRect getWindowTitleRect() const;
656
657protected:
661 virtual void paintEvent(QPaintEvent* e) override;
663 virtual void moveEvent(QMoveEvent* e) override;
665 virtual void changeEvent(QEvent* e) override;
666
668 virtual void paintTabbarBaseLine(QPainter& painter);
670 virtual void paintWindowTitle(QPainter& painter, const QString& title, const QRect& titleRegion);
672 virtual void
673 paintContextCategoryTab(QPainter& painter, const QString& title, const QRect& contextRect, const QColor& color);
674#if SA_DEBUG_PRINT_SARIBBONBAR
675 SA_RIBBON_EXPORT friend QDebug operator<<(QDebug debug, const SARibbonBar& ribbon);
676#endif
677};
678Q_DECLARE_OPERATORS_FOR_FLAGS(SARibbonBar::RibbonStyles)
679
680#endif // SARIBBONBAR_H
Definition SARibbonBar.h:171
RibbonMode
定义当前ribbon 的状态
Definition SARibbonBar.h:208
@ MinimumRibbonMode
缩小模式
Definition SARibbonBar.h:209
void ribbonStyleChanged(SARibbonBar::RibbonStyles nowStyle)
void ribbonModeChanged(SARibbonBar::RibbonMode nowState)
std::function< QColor(const QColor &) > FpContextCategoryHighlight
这是针对上下文标签的高亮颜色绘制,用户可以设置一个函数指针,来针对上下文标签的高亮颜色进行调整
Definition SARibbonBar.h:219
void titleBarHeightChanged(int oldHeight, int newHeight)
void currentRibbonTabChanged(int index)
void actionTriggered(QAction *action)
static bool isLooseStyle(RibbonStyles s)
Check if the ribbon style is loose (Office) style
RibbonStyleFlag
Definition SARibbonBar.h:189
void applicationButtonClicked()
void setRibbonMainwindowStyle()
Set ribbon main window style
Definition SARibbonButtonGroupWidget.h:19
Definition SARibbonCategory.h:32
Definition SARibbonContextCategory.h:19
Definition SARibbonElementFactory.h:43
Definition SARibbonMainWindow.h:86
PanelLayoutMode
Layout mode for the panel / 面板的布局模式
Definition SARibbonPanel.h:116
Definition SARibbonQuickAccessBar.h:67
Definition SARibbonStackedWidget.h:34
Definition SARibbonSystemButtonBar.h:41
Definition SARibbonTabBar.h:17
Ribbon风格的标题栏图标控件 模拟Windows原生窗口左上角的程序图标功能,支持右键菜单和窗口控制操作
Definition SARibbonTitleIconWidget.h:13