Skip to content

Commit

Permalink
添加了另外一个frameless方案
Browse files Browse the repository at this point in the history
  • Loading branch information
czyt1988 committed Nov 20, 2023
1 parent 7724fad commit d2c66b9
Show file tree
Hide file tree
Showing 8 changed files with 781 additions and 58 deletions.
20 changes: 10 additions & 10 deletions SARibbonBar.pri
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ INCLUDEPATH += $$PWD/src/SARibbonBar
DEPENDPATH += $$PWD/src/SARibbonBar


equals(QT_MAJOR_VERSION, 5){
greaterThan(QT_MINOR_VERSION, 13){
SA_RIBBON_CONFIG += use_frameless
}
}else{
# qt6.0不支持
greaterThan(QT_MINOR_VERSION, 0){
SA_RIBBON_CONFIG += use_frameless
}
}
#equals(QT_MAJOR_VERSION, 5){
# greaterThan(QT_MINOR_VERSION, 13){
# SA_RIBBON_CONFIG += use_frameless
# }
#}else{
## qt6.0不支持
# greaterThan(QT_MINOR_VERSION, 0){
# SA_RIBBON_CONFIG += use_frameless
# }
#}

contains( SA_RIBBON_CONFIG, use_frameless ) {
!contains(CONFIG,C++17){
Expand Down
31 changes: 21 additions & 10 deletions src/SARibbonBar/SARibbonBar.pri
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
# 2.要预定义FRAMELESSHELPER_CORE_LIBRARY宏,这样才能导出符号
# 3.要预定义FRAMELESSHELPER_WIDGETS_LIBRARY宏,这样才能导出符号

equals(QT_MAJOR_VERSION, 5){
greaterThan(QT_MINOR_VERSION, 13){
SA_RIBBON_CONFIG += use_frameless
}
}else{
# qt6.0不支持
greaterThan(QT_MINOR_VERSION, 0){
SA_RIBBON_CONFIG += use_frameless
}
}
#equals(QT_MAJOR_VERSION, 5){
# greaterThan(QT_MINOR_VERSION, 13){
# SA_RIBBON_CONFIG += use_frameless
# }
#}else{
## qt6.0不支持
# greaterThan(QT_MINOR_VERSION, 0){
# SA_RIBBON_CONFIG += use_frameless
# }
#}

contains( SA_RIBBON_CONFIG, use_frameless ) {
message("use frameless lib,compile with c+=17")
Expand All @@ -32,6 +32,17 @@ contains( SA_RIBBON_CONFIG, use_frameless ) {
message("do not use_frameless lib,compile with c+=11")
CONFIG += c++11
DEFINES += SARIBBON_USE_3RDPARTY_FRAMELESSHELPER=0
HEADERS += \
$$PWD/framelesswindow.h
win32{
SOURCES += \
$$PWD/framelesswindow.cpp
}
macx{
LIBS += -framework Cocoa
OBJECTIVE_SOURCES += \
$$PWD/framelesswindow.mm
}
}
message("SA_RIBBON_CONFIG="$${SA_RIBBON_CONFIG})
#-------------------------------------------------
Expand Down
31 changes: 12 additions & 19 deletions src/SARibbonBar/SARibbonMainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class SARibbonMainWindow::PrivateData
#if SARIBBON_USE_3RDPARTY_FRAMELESSHELPER
FRAMELESSHELPER_PREPEND_NAMESPACE(StandardTitleBar) * mTitleBar = nullptr;
#else
SAFramelessHelper* mFramelessHelper { nullptr };

#endif
};

Expand All @@ -59,7 +59,7 @@ SARibbonMainWindow::SARibbonMainWindow(QWidget* parent, bool useRibbon, const Qt
#if SARIBBON_USE_3RDPARTY_FRAMELESSHELPER
: FramelessMainWindow(parent, flags)
#else
: QMainWindow(parent, flags)
: CFramelessWindow(parent)
#endif
, d_ptr(new SARibbonMainWindow::PrivateData(this))
{
Expand All @@ -85,15 +85,11 @@ SARibbonBar* SARibbonMainWindow::ribbonBar() const
}

#if !SARIBBON_USE_3RDPARTY_FRAMELESSHELPER
SAFramelessHelper* SARibbonMainWindow::framelessHelper()
{
return (d_ptr->mFramelessHelper);
}

bool SARibbonMainWindow::eventFilter(QObject* obj, QEvent* e)
{
//这个过滤是为了把ribbonBar上的动作传递到mainwindow,再传递到frameless,
//由于ribbonbar会遮挡刁frameless的区域,导致frameless无法捕获这些消息
// 这个过滤是为了把ribbonBar上的动作传递到mainwindow,再传递到frameless,
// 由于ribbonbar会遮挡刁frameless的区域,导致frameless无法捕获这些消息
if (obj == ribbonBar()) {
switch (e->type()) {
case QEvent::MouseButtonPress:
Expand Down Expand Up @@ -140,7 +136,7 @@ void SARibbonMainWindow::setRibbonTheme(SARibbonMainWindow::RibbonTheme theme)
sa_set_ribbon_theme(this, theme);
d_ptr->mCurrentRibbonTheme = theme;
if (SARibbonBar* bar = ribbonBar()) {
//尺寸修正
// 尺寸修正
switch (ribbonTheme()) {
case RibbonThemeWindows7:
break;
Expand All @@ -165,7 +161,7 @@ void SARibbonMainWindow::setRibbonTheme(SARibbonMainWindow::RibbonTheme theme)
default:
break;
}
//上下文标签颜色设置
// 上下文标签颜色设置
switch (ribbonTheme()) {
case RibbonThemeWindows7:
case RibbonThemeOffice2013:
Expand Down Expand Up @@ -238,15 +234,15 @@ void SARibbonMainWindow::installRibbonBar(SARibbonBar* bar)
{
QWidget* old = QMainWindow::menuWidget();
if (old) {
//如果之前已经设置了menubar,要把之前的删除
// 如果之前已经设置了menubar,要把之前的删除
old->deleteLater();
}
#if SARIBBON_USE_3RDPARTY_FRAMELESSHELPER
auto helper = FramelessWidgetsHelper::get(this);
QMainWindow::setMenuWidget(bar);
helper->setTitleBarWidget(bar);

//设置window按钮
// 设置window按钮
if (nullptr == d_ptr->mWindowButtonGroup) {
d_ptr->mWindowButtonGroup = new SAWindowButtonGroup(this);
}
Expand All @@ -266,12 +262,9 @@ void SARibbonMainWindow::installRibbonBar(SARibbonBar* bar)

QMainWindow::setMenuWidget(bar);
bar->installEventFilter(this);
//设置窗体的标题栏高度
if (nullptr == d_ptr->mFramelessHelper) {
d_ptr->mFramelessHelper = new SAFramelessHelper(this);
}
d_ptr->mFramelessHelper->setTitleHeight(bar->titleBarHeight());
//设置window按钮
setTitleBar(bar);

// 设置window按钮
if (nullptr == d_ptr->mWindowButtonGroup) {
d_ptr->mWindowButtonGroup = new SAWindowButtonGroup(this);
}
Expand All @@ -280,7 +273,7 @@ void SARibbonMainWindow::installRibbonBar(SARibbonBar* bar)
d_ptr->mWindowButtonGroup->setFixedSize(s);
d_ptr->mWindowButtonGroup->setWindowStates(windowState());
d_ptr->mWindowButtonGroup->show();

addHitTestVisibleWidgets(d_ptr->mWindowButtonGroup);
#endif
}

Expand Down
20 changes: 9 additions & 11 deletions src/SARibbonBar/SARibbonMainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ FRAMELESSHELPER_BEGIN_NAMESPACE
class StandardTitleBar;
FRAMELESSHELPER_END_NAMESPACE
#else
class SAFramelessHelper;
#include "framelesswindow.h"
#endif

class SARibbonBar;
Expand Down Expand Up @@ -40,7 +40,7 @@ class SARibbonBar;
#if SARIBBON_USE_3RDPARTY_FRAMELESSHELPER
class SA_RIBBON_EXPORT SARibbonMainWindow : public FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessMainWindow)
#else
class SA_RIBBON_EXPORT SARibbonMainWindow : public QMainWindow
class SA_RIBBON_EXPORT SARibbonMainWindow : public CFramelessWindow
#endif
{
Q_OBJECT
Expand All @@ -66,31 +66,29 @@ class SA_RIBBON_EXPORT SARibbonMainWindow : public QMainWindow
public:
SARibbonMainWindow(QWidget* parent = nullptr, bool useRibbon = true, const Qt::WindowFlags flags = {});
~SARibbonMainWindow() Q_DECL_OVERRIDE;
//返回SARibbonBar
// 返回SARibbonBar
SARibbonBar* ribbonBar() const;
#if !SARIBBON_USE_3RDPARTY_FRAMELESSHELPER
//返回SAFramelessHelper
SAFramelessHelper* framelessHelper();
//把ribbonbar的事件传递到frameless
// 把ribbonbar的事件传递到frameless
virtual bool eventFilter(QObject* obj, QEvent* e) Q_DECL_OVERRIDE;
#endif
//此函数仅用于控制最小最大化和关闭按钮的显示
// 此函数仅用于控制最小最大化和关闭按钮的显示
void updateWindowFlag(Qt::WindowFlags flags);
//获取系统按钮的状态
// 获取系统按钮的状态
Qt::WindowFlags windowButtonFlags() const;
void setRibbonTheme(RibbonTheme theme);
RibbonTheme ribbonTheme() const;
//判断当前是否使用ribbon模式
// 判断当前是否使用ribbon模式
bool isUseRibbon() const;

protected:
//创建ribbonbar的工厂函数
// 创建ribbonbar的工厂函数
SARibbonBar* createRibbonBar();
virtual void resizeEvent(QResizeEvent* event) Q_DECL_OVERRIDE;
virtual bool event(QEvent* e) Q_DECL_OVERRIDE;

private:
//安装ribbon
// 安装ribbon
void installRibbonBar(SARibbonBar* bar);
};

Expand Down
Loading

0 comments on commit d2c66b9

Please sign in to comment.