Skip to content

Commit

Permalink
Merge branch 'feature/widget' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
czyt1988 committed May 23, 2024
2 parents 76b6089 + 929dccf commit c78cfb4
Show file tree
Hide file tree
Showing 16 changed files with 490 additions and 126 deletions.
2 changes: 2 additions & 0 deletions src/SARibbonBar/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ SET(SARIBBON_HEADER_FILES
SARibbonCustomizeDialog.h
SARibbonCustomizeWidget.h
SARibbonMainWindow.h
SARibbonWidget.h
SARibbonSystemButtonBar.h
SARibbonApplicationButton.h
SARibbonTabBar.h
Expand Down Expand Up @@ -79,6 +80,7 @@ SET(SARIBBON_SOURCE_FILES
SARibbonCustomizeDialog.cpp
SARibbonCustomizeWidget.cpp
SARibbonMainWindow.cpp
SARibbonWidget.cpp
SARibbonSystemButtonBar.cpp
SARibbonApplicationButton.cpp
SARibbonTabBar.cpp
Expand Down
59 changes: 33 additions & 26 deletions src/SARibbonBar/SARibbonBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,18 +141,18 @@ class SARibbonBar::PrivateData
void SARibbonBar::PrivateData::init()
{
mApplicationButton = RibbonSubElementFactory->createRibbonApplicationButton(q_ptr);
q_ptr->connect(mApplicationButton, &QAbstractButton::clicked, q_ptr, &SARibbonBar::applicationButtonClicked);
q_ptr->connect(mApplicationButton.data(), &QAbstractButton::clicked, q_ptr, &SARibbonBar::applicationButtonClicked);
mRibbonTabBar = RibbonSubElementFactory->createRibbonTabBar(q_ptr);
mRibbonTabBar->setObjectName(QStringLiteral("objSARibbonTabBar"));
mRibbonTabBar->setDrawBase(false);
q_ptr->connect(mRibbonTabBar, &QTabBar::currentChanged, q_ptr, &SARibbonBar::onCurrentRibbonTabChanged);
q_ptr->connect(mRibbonTabBar, &QTabBar::tabBarClicked, q_ptr, &SARibbonBar::onCurrentRibbonTabClicked);
q_ptr->connect(mRibbonTabBar, &QTabBar::tabBarDoubleClicked, q_ptr, &SARibbonBar::onCurrentRibbonTabDoubleClicked);
q_ptr->connect(mRibbonTabBar, &QTabBar::tabMoved, q_ptr, &SARibbonBar::onTabMoved);
q_ptr->connect(mRibbonTabBar.data(), &QTabBar::currentChanged, q_ptr, &SARibbonBar::onCurrentRibbonTabChanged);
q_ptr->connect(mRibbonTabBar.data(), &QTabBar::tabBarClicked, q_ptr, &SARibbonBar::onCurrentRibbonTabClicked);
q_ptr->connect(mRibbonTabBar.data(), &QTabBar::tabBarDoubleClicked, q_ptr, &SARibbonBar::onCurrentRibbonTabDoubleClicked);
q_ptr->connect(mRibbonTabBar.data(), &QTabBar::tabMoved, q_ptr, &SARibbonBar::onTabMoved);
//
mStackedContainerWidget = RibbonSubElementFactory->createRibbonStackedWidget(q_ptr);
mStackedContainerWidget->setObjectName(QStringLiteral("objSARibbonStackedContainerWidget"));
mStackedContainerWidget->connect(mStackedContainerWidget, &SARibbonStackedWidget::hidWindow, q_ptr, &SARibbonBar::onStackWidgetHided);
q_ptr->connect(mStackedContainerWidget.data(), &SARibbonStackedWidget::hidWindow, q_ptr, &SARibbonBar::onStackWidgetHided);
// 捕获事件,在popmode时必须用到
mStackedContainerWidget->installEventFilter(q_ptr);
//
Expand All @@ -172,8 +172,8 @@ void SARibbonBar::PrivateData::init()
*/
int SARibbonBar::PrivateData::calcTabBarHeight()
{
int defaultHeight = q_ptr->style()->pixelMetric(QStyle::PM_TabBarBaseHeight);
int fontHeight = q_ptr->fontMetrics().lineSpacing(); // 不要用height,像宋体这种字体,height=12,lineSpacing=14,有些就无法显示
int defaultHeight = q_ptr->style()->pixelMetric(QStyle::PM_TabBarBaseHeight);
int fontHeight = q_ptr->fontMetrics().lineSpacing(); // 不要用height,像宋体这种字体,height=12,lineSpacing=14,有些就无法显示
int defaultHeight2 = fontHeight * 1.6;
if (defaultHeight2 < fontHeight + 10) {
defaultHeight2 = fontHeight + 10; // 主要为了满足office2021主题,tab下有个4px的横杠
Expand Down Expand Up @@ -231,7 +231,11 @@ int SARibbonBar::PrivateData::calcCategoryHeight()
* @param categoryHeight
* @return
*/
int SARibbonBar::PrivateData::calcMainBarHeight(int tabHegith, int titleHeight, int categoryHeight, bool tabOnTitle, SARibbonBar::RibbonMode rMode)
int SARibbonBar::PrivateData::calcMainBarHeight(int tabHegith,
int titleHeight,
int categoryHeight,
bool tabOnTitle,
SARibbonBar::RibbonMode rMode)
{
if (rMode == MinimumRibbonMode) {
// 最小模式,没有categoryHeight
Expand Down Expand Up @@ -510,14 +514,14 @@ QString SARibbonBar::versionString()
QList< QColor > SARibbonBar::defaultContextCategoryColorList()
{
QList< QColor > res;
res //
<< QColor(206, 232, 252) //
<< QColor(253, 238, 179) //
<< QColor(212, 255, 174) // 绿
<< QColor(255, 196, 214) //
<< QColor(255, 216, 153) //
<< QColor(255, 224, 243) // 玫红
;
res //
<< QColor(206, 232, 252) //
<< QColor(253, 238, 179) //
<< QColor(212, 255, 174) // 绿
<< QColor(255, 196, 214) //
<< QColor(255, 216, 153) //
<< QColor(255, 224, 243) // 玫红
;
return res;
}

Expand Down Expand Up @@ -1084,11 +1088,13 @@ void SARibbonBar::showMinimumModeButton(bool isShow)

d_ptr->mMinimumCategoryButtonAction = new QAction(this);
d_ptr->mMinimumCategoryButtonAction->setIcon(
style()->standardIcon(isMinimumMode() ? QStyle::SP_TitleBarUnshadeButton : QStyle::SP_TitleBarShadeButton, nullptr));
style()->standardIcon(isMinimumMode() ? QStyle::SP_TitleBarUnshadeButton : QStyle::SP_TitleBarShadeButton,
nullptr));
connect(d_ptr->mMinimumCategoryButtonAction, &QAction::triggered, this, [ this ]() {
this->setMinimumMode(!isMinimumMode());
this->d_ptr->mMinimumCategoryButtonAction->setIcon(
style()->standardIcon(isMinimumMode() ? QStyle::SP_TitleBarUnshadeButton : QStyle::SP_TitleBarShadeButton, nullptr));
style()->standardIcon(isMinimumMode() ? QStyle::SP_TitleBarUnshadeButton : QStyle::SP_TitleBarShadeButton,
nullptr));
});
d_ptr->mRightButtonGroup->addAction(d_ptr->mMinimumCategoryButtonAction);

Expand Down Expand Up @@ -1477,7 +1483,7 @@ void SARibbonBar::setRibbonStyle(SARibbonBar::RibbonStyles v)
<< "\n isTwoRowStyle=" << isTwoRowStyle() //
<< "\n isLooseStyle=" << isLooseStyle() //
<< "\n isCompactStyle=" << isCompactStyle() //
;
;
#endif
// 执行判断
setEnableWordWrap(isThreeRowStyle(v));
Expand Down Expand Up @@ -1623,11 +1629,11 @@ void SARibbonBar::updateRibbonGeometry()
c->updateItemGeometry();
return true;
});
//!主题变更后,tabbar的长度需要进行刷新
// !主题变更后,tabbar的长度需要进行刷新

//! 直接给一个resizeevent,让所有刷新
QResizeEvent* e = new QResizeEvent(size(), QSize());
QApplication::postEvent(this, e);
QResizeEvent* e = new QResizeEvent(size(), QSize());
QApplication::postEvent(this, e);
}

/**
Expand Down Expand Up @@ -2073,10 +2079,11 @@ void SARibbonBar::paintInLooseStyle()
titleRegion.setRect(d_ptr->mQuickAccessBar->geometry().right() + 1,
border.top(),
width() - d_ptr->mIconRightBorderPosition - border.right()
- d_ptr->mWindowButtonSize.width() - d_ptr->mQuickAccessBar->geometry().right() - 1,
- d_ptr->mWindowButtonSize.width() - d_ptr->mQuickAccessBar->geometry().right() - 1,
titleBarHeight());
} else {
int leftwidth = contextCategoryRegion.x() - d_ptr->mQuickAccessBar->geometry().right() - d_ptr->mIconRightBorderPosition;
int leftwidth = contextCategoryRegion.x() - d_ptr->mQuickAccessBar->geometry().right()
- d_ptr->mIconRightBorderPosition;
int rightwidth = width() - contextCategoryRegion.y() - d_ptr->mWindowButtonSize.width();
// if (width() - contextCategoryRegion.y() > contextCategoryRegion.x()-x) {
if (rightwidth > leftwidth) {
Expand Down Expand Up @@ -2554,7 +2561,7 @@ QDebug operator<<(QDebug debug, const SARibbonBar& ribbon)
<< "\n -mEnableShowPannelTitle=" << ribbon.d_ptr->mEnableShowPannelTitle //
<< "\n -mWindowButtonSize=" << ribbon.d_ptr->mWindowButtonSize //
<< "\n -mIconRightBorderPosition=" << ribbon.d_ptr->mIconRightBorderPosition //
;
;

return debug;
}
Expand Down
21 changes: 20 additions & 1 deletion src/SARibbonBar/SARibbonGlobal.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <memory>
#include <QtGlobal>
#include <QObject>

class QWidget;
/**
@file SARibbonGlobal.h
*/
Expand Down Expand Up @@ -86,6 +86,9 @@ enum class SARibbonTheme
RibbonThemeDark2
};




/**
* @def 属性,用于标记是否可以进行自定义,用于动态设置到@ref SARibbonCategory 和@ref SARibbonPannel
* 值为bool,在为true时,可以通过@ref SARibbonCustomizeWidget 改变这个SARibbonCategory和SARibbonPannel的布局,
Expand Down Expand Up @@ -152,4 +155,20 @@ enum class SARibbonTheme
#define SA_DEBUG_PRINT_SARIBBONBAR 1
#endif


/**
* @brief 全局的设置ribbon theme函数
*
* 之所以提供此函数,是因为在某些情况下,SARibbonBar不用在SARibbonMainWindow情况下的时候,也需要设置主题,
* 但主题设置是在SARibbonMainWindow下的为了能在非SARibbonMainWindow下也能设置主题,这里提供@sa sa_set_ribbon_theme函数,
* 可以这样使用:
* @code
* @endcode
*
* @param w
* @param theme
*/
void SA_RIBBON_EXPORT sa_set_ribbon_theme(QWidget* w, SARibbonTheme theme);


#endif // SARIBBONGLOBAL_H
14 changes: 1 addition & 13 deletions src/SARibbonBar/SARibbonMainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,6 @@ private slots:
void onPrimaryScreenChanged(QScreen* screen);
};

/**
* @brief 全局的设置ribbon theme函数
*
* 之所以提供此函数,是因为在某些情况下,SARibbonBar不用在SARibbonMainWindow情况下的时候,也需要设置主题,
* 但主题设置是在SARibbonMainWindow下的为了能在非SARibbonMainWindow下也能设置主题,这里提供@sa sa_set_ribbon_theme函数,
* 可以这样使用:
* @code
* @endcode
*
* @param w
* @param theme
*/
void SA_RIBBON_EXPORT sa_set_ribbon_theme(QWidget* w, SARibbonTheme theme);


#endif // SARIBBONMAINWINDOW_H
Loading

0 comments on commit c78cfb4

Please sign in to comment.