Skip to content

Commit

Permalink
SARibbonMainWindow的createRibbon改为虚函数
Browse files Browse the repository at this point in the history
  • Loading branch information
czyt1988 committed Aug 9, 2024
1 parent e759b3f commit 66f47cd
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
2 changes: 1 addition & 1 deletion doc/Doxyfile-wiki-cn
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ PROJECT_NAME = SARibbon
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = 2.0.2
PROJECT_NUMBER = 2.2.3

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand Down
8 changes: 5 additions & 3 deletions src/SARibbonBar/SARibbonMainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ void SARibbonMainWindow::setRibbonBar(SARibbonBar* ribbon)
// 设置window按钮
if (nullptr == d_ptr->mWindowButtonGroup) {
d_ptr->mWindowButtonGroup = RibbonSubElementFactory->createWindowButtonGroup(this);
// SARibbonSystemButtonBar的eventfilter捕获mainwindow的事件
// 通过eventerfilter来处理mainwindow的事件,避免用户错误的继承resizeEvent导致systembar的位置异常
installEventFilter(d_ptr->mWindowButtonGroup);
}
SARibbonSystemButtonBar* sysBar = d_ptr->mWindowButtonGroup;
sysBar->setWindowStates(windowState());
Expand Down Expand Up @@ -130,9 +133,6 @@ void SARibbonMainWindow::setRibbonBar(SARibbonBar* ribbon)
d_ptr->mFramelessHelper->setTitleHeight(th);
d_ptr->mFramelessHelper->setRubberBandOnResize(false);
#endif
// SARibbonSystemButtonBar的eventfilter捕获mainwindow的事件
// 通过eventerfilter来处理mainwindow的事件,避免用户错误的继承resizeEvent导致systembar的位置异常
installEventFilter(sysBar);
if (!d_ptr->mEventFilter) {
d_ptr->mEventFilter = new SARibbonMainWindowEventFilter(this);
installEventFilter(d_ptr->mEventFilter);
Expand Down Expand Up @@ -292,6 +292,8 @@ bool SARibbonMainWindow::isUseRibbon() const

/**
* @brief 创建ribbonbar的工厂函数
*
* 用户如果重写了SARibbonBar,可以通过重新此虚函数返回自己的Ribbon实例
* @return
*/
SARibbonBar* SARibbonMainWindow::createRibbonBar()
Expand Down
26 changes: 23 additions & 3 deletions src/SARibbonBar/SARibbonMainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,34 @@ class QScreen;
* @endcode
*
* 如果想换回非ribbon风格,只需要把useRibbon设置为false即可,
* 成员函数isUseRibbon用于判断当前是否为ribbon模式,这个函数在兼容传统Toolbar风格和ribbon风格时非常有用。
* 成员函数isUseRibbon用于判断当前是否为ribbon模式,这个函数在兼容传统Toolbar风格和ribbon风格时非常有用
*
* 但这个不支持动态切换,因此,实际工程中,你若要进行切换,需要写配置文件,程序在构造时传入模式,
* 并且,你的程序要做好判断,因为非Ribbon模式下,所有Ribbon相关的接口都会返回空指针
*
* @code
* bool isUseRibbon() const;
* @endcode
*
* @ref SARibbonMainWindow 提供了几种常用的ribbon样式,样式可见@ref RibbonTheme
* @ref SARibbonMainWindow 提供了几种常用的ribbon样式
* 通过@ref setRibbonTheme 可改变ribbon的样式,用户也可通过qss自己定义自己的样式
*
* 如果你自己继承了SARibbonBar,你可以通过重写@ref createRibbonBar 来实现SARibbonMainWindow安装新的ribbonbar
*
* @code
* class MyMainWindow : public SARibbonMainWindow
* {
* public:
* ...
* protected:
* virtual SARibbonBar* createRibbonBar() override;
* };
*
* SARibbonBar* MyMainWindow::createRibbonBar(){
* return new MyRibbonBar(this);
* }
* @endcode
*
*
*/
class SA_RIBBON_EXPORT SARibbonMainWindow : public QMainWindow
Expand Down Expand Up @@ -70,7 +90,7 @@ class SA_RIBBON_EXPORT SARibbonMainWindow : public QMainWindow

protected:
// 创建ribbonbar的工厂函数
SARibbonBar* createRibbonBar();
virtual SARibbonBar* createRibbonBar();
private slots:
void onPrimaryScreenChanged(QScreen* screen);
};
Expand Down

0 comments on commit 66f47cd

Please sign in to comment.