Skip to content

Commit

Permalink
调整SARibbonStackWidget的实现
Browse files Browse the repository at this point in the history
  • Loading branch information
czyt1988 committed Mar 15, 2024
1 parent 577bb64 commit d7e0beb
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 174 deletions.
2 changes: 1 addition & 1 deletion src/SARibbonBar/3rdparty/qwindowkit
87 changes: 38 additions & 49 deletions src/SARibbonBar/SARibbonBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,7 @@ void SARibbonBar::PrivateData::init()
//
mStackedContainerWidget = RibbonSubElementFactory->createRibbonStackedWidget(q_ptr);
mStackedContainerWidget->setObjectName(QStringLiteral("objSARibbonStackedContainerWidget"));
mStackedContainerWidget->connect(mStackedContainerWidget,
&SARibbonStackedWidget::hidWindow,
q_ptr,
&SARibbonBar::onStackWidgetHided);
mStackedContainerWidget->connect(mStackedContainerWidget, &SARibbonStackedWidget::hidWindow, q_ptr, &SARibbonBar::onStackWidgetHided);
// 捕获事件,在popmode时必须用到
mStackedContainerWidget->installEventFilter(q_ptr);
//
Expand All @@ -175,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 @@ -234,11 +231,7 @@ 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 @@ -517,14 +510,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 @@ -1089,13 +1082,11 @@ 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 @@ -1270,30 +1261,29 @@ void SARibbonBar::onCurrentRibbonTabChanged(int index)
_SARibbonTabData p = var.value< _SARibbonTabData >();
category = p.category;
}
if (category) {
if (d_ptr->mStackedContainerWidget->currentWidget() != category) {
d_ptr->mStackedContainerWidget->setCurrentWidget(category);
}
if (isMinimumMode()) {
d_ptr->mRibbonTabBar->clearFocus();
if (!d_ptr->mStackedContainerWidget->isVisible()) {
if (d_ptr->mStackedContainerWidget->isPopupMode()) {
// 在stackedContainerWidget弹出前,先给tabbar一个QHoverEvent,让tabbar知道鼠标已经移开
QHoverEvent ehl(QEvent::HoverLeave,
d_ptr->mRibbonTabBar->mapToGlobal(QCursor::pos()),
d_ptr->mRibbonTabBar->mapToGlobal(QCursor::pos()));
QApplication::sendEvent(d_ptr->mRibbonTabBar, &ehl);
resizeStackedContainerWidget();
d_ptr->mStackedContainerWidget->setFocus();
d_ptr->mStackedContainerWidget->exec();
// 在最小模式下,每次显示完stackedContainerWidget后把tab的
// 的index设置为-1,这样每次点击都会触发onCurrentRibbonTabChanged
}
} else {
if (!category) {
return;
}
if (d_ptr->mStackedContainerWidget->currentWidget() != category) {
d_ptr->mStackedContainerWidget->setCurrentWidget(category);
}
emit currentRibbonTabChanged(index);
if (isMinimumMode()) {
d_ptr->mRibbonTabBar->clearFocus();
if (!d_ptr->mStackedContainerWidget->isVisible()) {
if (d_ptr->mStackedContainerWidget->isPopupMode()) {
// 在stackedContainerWidget弹出前,先给tabbar一个QHoverEvent,让tabbar知道鼠标已经移开
QHoverEvent ehl(QEvent::HoverLeave,
d_ptr->mRibbonTabBar->mapToGlobal(QCursor::pos()),
d_ptr->mRibbonTabBar->mapToGlobal(QCursor::pos()));
QApplication::sendEvent(d_ptr->mRibbonTabBar, &ehl);
resizeStackedContainerWidget();
d_ptr->mStackedContainerWidget->setFocus();
// exec之前先发射信息号,否则会被exec阻塞
d_ptr->mStackedContainerWidget->show();
}
}
}
emit currentRibbonTabChanged(index);
}

/**
Expand Down Expand Up @@ -1485,7 +1475,7 @@ void SARibbonBar::setRibbonStyle(SARibbonBar::RibbonStyles v)
<< "\n isTwoRowStyle=" << isTwoRowStyle() //
<< "\n isLooseStyle=" << isLooseStyle() //
<< "\n isCompactStyle=" << isCompactStyle() //
;
;
#endif
// 执行判断
setEnableWordWrap(isThreeRowStyle(v));
Expand Down Expand Up @@ -2079,11 +2069,10 @@ 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 @@ -2561,7 +2550,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
Loading

0 comments on commit d7e0beb

Please sign in to comment.