Skip to content

Commit

Permalink
v1.1.0 fix 修正设置文字换行不重新计算矩形区域问题
Browse files Browse the repository at this point in the history
  • Loading branch information
czyt1988 committed Dec 25, 2023
1 parent 0194fee commit a4a8f58
Show file tree
Hide file tree
Showing 9 changed files with 9,082 additions and 9,045 deletions.
14,758 changes: 7,387 additions & 7,371 deletions src/SARibbon.cpp

Large diffs are not rendered by default.

3,308 changes: 1,656 additions & 1,652 deletions src/SARibbon.h

Large diffs are not rendered by default.

9 changes: 4 additions & 5 deletions src/SARibbonBar/SARibbonBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ QList< QColor > SARibbonBar::getDefaultContextCategoryColorList()
<< QColor(14, 81, 167) //
<< QColor(228, 0, 69) //
<< QColor(67, 148, 0) // 绿
;
;
return res;
}

Expand Down Expand Up @@ -967,11 +967,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 @@ -1458,7 +1458,6 @@ QColor SARibbonBar::tabBarBaseLineColor() const
*/
void SARibbonBar::updateRibbonGeometry()
{
updateGeometry();
d_ptr->resetSize();

QList< SARibbonCategory* > categorys = categoryPages();
Expand Down Expand Up @@ -1822,7 +1821,7 @@ void SARibbonBar::paintInNormalStyle()
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;
Expand Down
11 changes: 9 additions & 2 deletions src/SARibbonBar/SARibbonCategory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,16 @@ void SARibbonCategory::PrivateData::updateItemGeometry()
#if SA_DEBUG_PRINT_SIZE_HINT
qDebug() << "SARibbonCategory::PrivateData::updateItemGeometry,categoryName=" << q_ptr->categoryName();
#endif
if (SARibbonCategoryLayout* lay = qobject_cast< SARibbonCategoryLayout* >(q_ptr->layout())) {
lay->invalidate();
SARibbonCategoryLayout* lay = qobject_cast< SARibbonCategoryLayout* >(q_ptr->layout());
if (!lay) {
return;
}
const QList< SARibbonPannel* > pannels = lay->pannelList();
for (auto pannel : pannels) {
pannel->updateItemGeometry();
}
lay->invalidate();

return;
}

Expand Down
3 changes: 2 additions & 1 deletion src/SARibbonBar/SARibbonGlobal.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
#define SA_RIBBON_DECLARE_PUBLIC(classname) \
friend class classname; \
classname* q_ptr { nullptr }; \
PrivateData(const PrivateData&) = delete; \
PrivateData(const PrivateData&) = delete; \
PrivateData& operator=(const PrivateData&) = delete;
#endif

Expand Down Expand Up @@ -196,6 +196,7 @@ enum class SARibbonAlignment
*/
#define SA_DEBUG_PRINT_SIZE_HINT 0
#endif

#ifndef SA_DEBUG_PRINT_EVENT
/**
@def 定义此宏,将打印事件
Expand Down
7 changes: 5 additions & 2 deletions src/SARibbonBar/SARibbonPannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -676,8 +676,11 @@ void SARibbonPannel::updateItemGeometry()
#if SA_DEBUG_PRINT_SIZE_HINT
qDebug() << "SARibbonPannel updateItemGeometry,pannelName=" << pannelName();
#endif
if (QLayout* lay = layout()) {
//此函数需要添加,否则SARibbonBar::setEnableWordWrap无法刷新按钮
resetLargeToolButtonStyle();
if (SARibbonPannelLayout* lay = pannelLayout()) {
lay->invalidate();
lay->updateGeomArray();
}
}

Expand Down Expand Up @@ -758,7 +761,7 @@ void SARibbonPannel::resizeEvent(QResizeEvent* e)
if (ThreeRowMode == pannelLayoutMode()) {
d_ptr->m_optionActionButton->move(width() - d_ptr->m_optionActionButton->width() - 2,
height() - titleHeight()
+ (titleHeight() - d_ptr->m_optionActionButton->height()) / 2);
+ (titleHeight() - d_ptr->m_optionActionButton->height()) / 2);
} else {
d_ptr->m_optionActionButton->move(width() - d_ptr->m_optionActionButton->width(),
height() - d_ptr->m_optionActionButton->height());
Expand Down
19 changes: 11 additions & 8 deletions src/SARibbonBar/SARibbonPannelLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,14 @@ void SARibbonPannelLayout::move(int from, int to)
*/
bool SARibbonPannelLayout::isDirty() const
{
SARibbonPannelLayout* that = const_cast< SARibbonPannelLayout* >(this);
that->updateGeomArray(QRect());
return (m_dirty);
}

void SARibbonPannelLayout::updateGeomArray()
{
updateGeomArray(geometry());
}

/**
* @brief 计算大图标的高度
* @param setrect
Expand Down Expand Up @@ -428,10 +431,10 @@ void SARibbonPannelLayout::updateGeomArray(const QRect& setrect)
if (SARibbonToolButton* tb = qobject_cast< SARibbonToolButton* >(item->widget())) {
auto ss__ = tb->sizeHint();
debug_print__log__ += QString("| | |-[%1]SARibbonToolButton.sizeHint=(%2,%3),ButtonText=%4\n")
.arg(i)
.arg(ss__.width())
.arg(ss__.height())
.arg(tb->text());
.arg(i)
.arg(ss__.width())
.arg(ss__.height())
.arg(tb->text());
}
#endif
Qt::Orientations exp = item->expandingDirections();
Expand Down Expand Up @@ -633,7 +636,7 @@ void SARibbonPannelLayout::updateGeomArray(const QRect& setrect)
<< "\n| | |-mag=" << mag //
<< "\n| | |-largeHeight=" << largeHeight //
<< "\n| | |-smallHeight=" << smallHeight //
;
;
qDebug().noquote() << debug_print__log__;
#endif
}
Expand Down Expand Up @@ -724,7 +727,7 @@ void SARibbonPannelLayout::recalcExpandGeomArray(const QRect& setrect)
qDebug() << "| |-SARibbonPannelLayout recalcExpandGeomArray(" << setrect
<< ") pannelName=" << ribbonPannel()->pannelName() //
<< ",expandwidth=" << expandwidth //
;
;
#endif
}

Expand Down
3 changes: 3 additions & 0 deletions src/SARibbonBar/SARibbonPannelLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ class SA_RIBBON_EXPORT SARibbonPannelLayout : public QLayout
// 判断是否需要重新布局
bool isDirty() const;

//
void updateGeomArray();

// 计算大图标的高度
static int calcLargeHeight(const QRect& setrect, const SARibbonPannel* pannel);

Expand Down
9 changes: 5 additions & 4 deletions src/SARibbonBar/SARibbonToolButton.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "SARibbonToolButton.h"
#include "SARibbonElementManager.h"
#include <QAction>
#include <QApplication>
#include <QCursor>
Expand All @@ -12,6 +11,8 @@
#include <QTextOption>
#include <QApplication>
#include <QScreen>
#include "SARibbonPannel.h"

/**
* @def 定义文字换行时2行文本的矩形高度系数,此系数决定文字区域的高度
*
Expand Down Expand Up @@ -269,7 +270,7 @@ void SARibbonToolButton::PrivateData::calcSmallButtonDrawRects(const QStyleOptio
case Qt::ToolButtonIconOnly: {
if (hasIndicator(opt)) {
// 在仅有图标的小模式显示时,预留一个下拉箭头位置
iconRect = opt.rect.adjusted(spacing, spacing, -indicatorLen - spacing, -spacing);
iconRect = opt.rect.adjusted(spacing, spacing, -indicatorLen - spacing, -spacing);
indicatorArrowRect = QRect(opt.rect.right() - indicatorLen - spacing, iconRect.y(), indicatorLen, iconRect.height());
} else {
iconRect = opt.rect.adjusted(spacing, spacing, -spacing, -spacing);
Expand All @@ -281,7 +282,7 @@ void SARibbonToolButton::PrivateData::calcSmallButtonDrawRects(const QStyleOptio
case Qt::ToolButtonTextOnly: {
if (hasIndicator(opt)) {
// 在仅有图标的小模式显示时,预留一个下拉箭头位置
textRect = opt.rect.adjusted(spacing, spacing, -indicatorLen - spacing, -spacing);
textRect = opt.rect.adjusted(spacing, spacing, -indicatorLen - spacing, -spacing);
indicatorArrowRect = QRect(opt.rect.right() - indicatorLen - spacing, spacing, indicatorLen, textRect.height());
} else {
textRect = opt.rect.adjusted(spacing, spacing, -spacing, -spacing);
Expand Down Expand Up @@ -505,7 +506,7 @@ QSize SARibbonToolButton::PrivateData::calcLargeButtonSizeHint(const QStyleOptio
<< "\n| | | |-mDrawIconRect=" << mDrawIconRect //
<< "\n| | | |-minW=" << minW //
<< "\n| | | |-w=" << w //
;
;
#endif
//! Qt6.4 取消了QApplication::globalStrut
return QSize(w, h).expandedTo(QSize(minW, textHeight));
Expand Down

0 comments on commit a4a8f58

Please sign in to comment.