Skip to content

Commit

Permalink
添加自定义尺寸
Browse files Browse the repository at this point in the history
  • Loading branch information
czyt1988 committed Jan 4, 2024
1 parent d741b2f commit cb44eb8
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 13 deletions.
62 changes: 51 additions & 11 deletions src/SARibbonBar/SARibbonBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,15 @@ class SARibbonBar::PrivateData
bool mEnableUserDefineAccessBarIconSize { false }; ///< 允许用户自定义AccessBar的IconSize
bool mEnableUserDefineRightBarIconSize { false }; ///< 允许用户自定义RightBar的IconSize
SARibbonAlignment mRibbonAlignment { SARibbonAlignment::AlignLeft }; ///< 对齐方式
bool mEnableShowPannelTitle { true }; ///< 是否运行pannel的标题栏显示
int mTitleBarHeight { 30 }; ///< 标题栏高度
int mTabBarHeight { 28 }; ///< tabbar高度
bool mEnableShowPannelTitle { true }; ///< 是否运行pannel的标题栏显示
int mPannelTitleHeight { 15 }; ///< pannel的标题栏默认高度
int mCategoryHeight { 60 }; ///< Category的高度
std::unique_ptr< int > mUserDefTitleBarHeight; ///< 用户定义的标题栏高度,正常不使用用户设定的高度,而是使用自动计算的高度
std::unique_ptr< int > mUserDefTabBarHeight; ///< 用户定义的tabbar高度,正常不使用用户设定的高度,而是使用自动计算的高度
std::unique_ptr< int > mUserDefCategoryHeight; ///< 用户定义的Category的高度,正常不使用用户设定的高度,而是使用自动计算的高度

public:
PrivateData(SARibbonBar* par) : q_ptr(par)
{
Expand Down Expand Up @@ -1076,11 +1080,15 @@ int SARibbonBar::tabBarHeight() const
* @note 此函数不会自动刷新,如果需要刷新调用此函数后需要调用@ref updateRibbonGeometry
* @param h
*/
void SARibbonBar::setTabBarHeight(int h)
void SARibbonBar::setTabBarHeight(int h, bool resizeByNow)
{
d_ptr->mTabBarHeight = h;
if (h > 0) {
d_ptr->mRibbonTabBar->setFixedHeight(h);
if (nullptr == d_ptr->mUserDefTabBarHeight) {
d_ptr->mUserDefTabBarHeight = std::make_unique< int >(h);
} else {
*(d_ptr->mUserDefTabBarHeight) = h;
}
if (resizeByNow) {
updateRibbonGeometry();
}
}

Expand All @@ -1100,17 +1108,49 @@ int SARibbonBar::titleBarHeight() const
@note 此操作会发射@ref titleBarHeightChanged 信号
@param h
*/
void SARibbonBar::setTitleBarHeight(int h)
void SARibbonBar::setTitleBarHeight(int h, bool resizeByNow)
{
if (d_ptr->mTitleBarHeight == h) {
return;
int oldHeight = d_ptr->mTitleBarHeight;
if (nullptr == d_ptr->mUserDefTitleBarHeight) {
d_ptr->mUserDefTitleBarHeight = std::make_unique< int >(h);
} else {
*(d_ptr->mUserDefTitleBarHeight) = h;
//
oldHeight = *(d_ptr->mUserDefTitleBarHeight);
}

if (resizeByNow) {
updateRibbonGeometry();
}
int oldHeight = d_ptr->mTitleBarHeight;
d_ptr->mTitleBarHeight = h;
updateRibbonGeometry();
emit titleBarHeightChanged(oldHeight, h);
}

/**
* @brief category的高度
* @return
*/
int SARibbonBar::categoryHeight() const
{
return d_ptr->mStackedContainerWidget->height();
}

/**
* @brief 设置category的高度
* @param h
* @param resizeByNow
*/
void SARibbonBar::setCategoryHeight(int h, bool resizeByNow)
{
if (nullptr == d_ptr->mUserDefCategoryHeight) {
d_ptr->mUserDefCategoryHeight = std::make_unique< int >(h);
} else {
*(d_ptr->mUserDefCategoryHeight) = h;
}
if (resizeByNow) {
updateRibbonGeometry();
}
}

void SARibbonBar::onWindowTitleChanged(const QString& title)
{
Q_UNUSED(title);
Expand Down
8 changes: 6 additions & 2 deletions src/SARibbonBar/SARibbonBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,15 @@ class SA_RIBBON_EXPORT SARibbonBar : public QMenuBar

// ribbon tab的高度
int tabBarHeight() const;
void setTabBarHeight(int h);
void setTabBarHeight(int h, bool resizeByNow = true);

// 标题栏的高度
int titleBarHeight() const;
void setTitleBarHeight(int h);
void setTitleBarHeight(int h, bool resizeByNow = true);

// category的高度
int categoryHeight() const;
void setCategoryHeight(int h, bool resizeByNow = true);

// 获取正常模式下的mainBar的高度
int normalModeMainBarHeight() const;
Expand Down

0 comments on commit cb44eb8

Please sign in to comment.