From 50041ce3e19aa80bb0502f39f2d5f7afd6d12d28 Mon Sep 17 00:00:00 2001 From: czyt1988 Date: Sun, 5 Jan 2025 20:26:07 +0800 Subject: [PATCH] v2.2.8 --- changlog.md | 2 + src/SARibbon.cpp | 326 +++++++++++++++++++++++++++-------------------- src/SARibbon.h | 318 ++++++++++++++++++++++----------------------- 3 files changed, 351 insertions(+), 295 deletions(-) diff --git a/changlog.md b/changlog.md index 0f7265e..ce18877 100644 --- a/changlog.md +++ b/changlog.md @@ -4,6 +4,8 @@ - 修正合并文件会存在宏重复定义问题-2.2.7遗漏了一个调试宏 - SARibbonSeparatorWidget的宽度增加了最小1像素的判断 +- SARibbonToolButton添加了textEllipsisAspectFactor相关接口,用户可以通过设置文字省略显示的长宽比,来调整按钮的最宽宽度 +- 优化了一些cmake的内容 ## 2024-12-23 -> 2.2.7 [hotfix] diff --git a/src/SARibbon.cpp b/src/SARibbon.cpp index 382b2be..8750a9b 100644 --- a/src/SARibbon.cpp +++ b/src/SARibbon.cpp @@ -1,4 +1,4 @@ -// 定义此宏,将SA_RIBBON_EXPORT定义为空 +// 定义此宏,将SA_RIBBON_EXPORT定义为空 #ifndef SA_RIBBON_BAR_NO_EXPORT #define SA_RIBBON_BAR_NO_EXPORT #endif @@ -2735,42 +2735,19 @@ void SARibbonSystemButtonBar::maximizeWindow() #include #include -/** - * @def 定义文字换行时2行文本的矩形高度系数,此系数决定文字区域的高度 - * - * fontMetrics.lineSpacing*系数 = 文本区域高度 - */ -#define SARIBBONTOOLBUTTON_WORDWRAP_TEXT_FACTOR 2.05 - -/** - * @def 定义文字不换行时单行文本的矩形高度系数,此系数决定文字区域的高度 - * - * fontMetrics.lineSpacing*系数 = 文本区域高度 - */ -#define SARIBBONTOOLBUTTON_NOWORDWRAP_TEXT_FACTOR 1.2 - -/** - * @def 定义小按钮的矩形高度系数,此系数决定文字区域的高度 - * - * fontMetrics.lineSpacing*系数 = 文本区域高度 - */ -#define SARIBBONTOOLBUTTON_SMALLBUTTON_TEXT_FACTOR 1.4 - -/** - * @def 文本宽度估算时的宽度比高度系数 - * - * 超过此系数的宽度时,开始尝试换行,例如按钮高度为h,如果单行文本的宽度大于h*系数,则触发换行估算 - */ -#define SARIBBONTOOLBUTTON_WORDWRAP_WIDTH_PER_HEIGHT_RATIO 1.4 - /** * @def 开启此宏会打印一些常见信息 */ +#ifndef SA_RIBBON_TOOLBUTTON_DEBUG_PRINT #define SA_RIBBON_TOOLBUTTON_DEBUG_PRINT 0 +#endif +#ifndef SARIBBONTOOLBUTTON_DEBUG_DRAW #define SARIBBONTOOLBUTTON_DEBUG_DRAW 0 +#endif #if SARIBBONTOOLBUTTON_DEBUG_DRAW +#ifndef SARIBBONTOOLBUTTON_DEBUG_DRAW_RECT #define SARIBBONTOOLBUTTON_DEBUG_DRAW_RECT(p, rect) \ do { \ p.save(); \ @@ -2779,10 +2756,12 @@ void SARibbonSystemButtonBar::maximizeWindow() p.drawRect(rect); \ p.restore(); \ } while (0) - +#endif #else +#ifndef SARIBBONTOOLBUTTON_DEBUG_DRAW_RECT #define SARIBBONTOOLBUTTON_DEBUG_DRAW_RECT(p, rect) #endif +#endif namespace SA { @@ -2937,8 +2916,7 @@ class SARibbonToolButton::PrivateData int textDrawRectHeight, const QString& text, const QFontMetrics& fm, - float widthHeightRatio = SARIBBONTOOLBUTTON_WORDWRAP_WIDTH_PER_HEIGHT_RATIO, - int maxTrycount = 3); + int maxTrycount = 3); QPixmap createIconPixmap(const QStyleOptionToolButton& opt, const QSize& iconsize) const; // 获取文字的对其方式 int getTextAlignment() const; @@ -2960,11 +2938,56 @@ class SARibbonToolButton::PrivateData QSize mSizeHint; ///< 保存计算好的sizehint bool mIsTextNeedWrap { false }; ///< 标记文字是否需要换行显示 public: - static bool s_enableWordWrap; ///< 在lite模式下是否允许文字换行,如果允许,则图标相对比较小,默认不允许 + /** + * @brief 在lite模式下是否允许文字换行 + * + * 如果允许,则图标相对比较小,默认不允许 + */ + static bool s_enableWordWrap; + + /** + * @brief 这个系数决定了文字换行时2行文本的矩形高度 + * + * 此值应该大于2 + * + * 文本区域高度 = fontMetrics.lineSpacing*系数 + */ + static qreal s_twoLineHeightFactor; + + /** + * @brief 这个系数决定了单行文本的行高度 + * + * 此值应该大于1 + * + * 文本区域高度 = fontMetrics.lineSpacing*系数 + */ + static qreal s_oneLineHeightFactor; + + /** + * @brief 这个系数决定了小按钮文本的行高度 + * + * 此值应该大于1 + * + * 文本区域高度 = fontMetrics.lineSpacing*系数 + */ + static qreal s_smallButtonHeightFactor; + + /** + * @brief 文本宽度估算时的宽度比高度系数 + * + * 超过此系数的宽度时,开始尝试换行,例如按钮高度为h,如果单行文本的宽度大于h*系数,则按钮将不进行横向拉伸,类似于maxwidth效果 + * + * 此系数和maxwidth取最小值 + */ + static qreal s_textEllipsisAspectFactor; }; // 静态参数初始化 -bool SARibbonToolButton::PrivateData::s_enableWordWrap = false; +bool SARibbonToolButton::PrivateData::s_enableWordWrap = false; +qreal SARibbonToolButton::PrivateData::s_twoLineHeightFactor = 2.05; +qreal SARibbonToolButton::PrivateData::s_oneLineHeightFactor = 1.2; +qreal SARibbonToolButton::PrivateData::s_smallButtonHeightFactor = 1.4; +qreal SARibbonToolButton::PrivateData::s_textEllipsisAspectFactor = 1.4; SARibbonToolButton::PrivateData::PrivateData(SARibbonToolButton* p) : q_ptr(p) { @@ -3079,11 +3102,9 @@ void SARibbonToolButton::PrivateData::calcSmallButtonDrawRects(const QStyleOptio case Qt::ToolButtonIconOnly: { if (hasIndicator(opt)) { // 在仅有图标的小模式显示时,预留一个下拉箭头位置 - iconRect = opt.rect.adjusted(spacing, spacing, -indicatorLen - spacing, -spacing); - indicatorArrowRect = QRect(opt.rect.right() - indicatorLen - spacing, - iconRect.y(), - indicatorLen, - iconRect.height()); + 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); indicatorArrowRect = QRect(); @@ -3114,7 +3135,8 @@ void SARibbonToolButton::PrivateData::calcSmallButtonDrawRects(const QStyleOptio iconRect = QRect(); } else { QSize iconSize = adjustIconSize(buttonRect, opt.iconSize); - iconRect = QRect(buttonRect.x(), buttonRect.y(), iconSize.width(), qMax(iconSize.height(), buttonRect.height())); + iconRect = + QRect(buttonRect.x(), buttonRect.y(), iconSize.width(), qMax(iconSize.height(), buttonRect.height())); } // 后设置TextRect if (opt.text.isEmpty()) { @@ -3132,15 +3154,11 @@ void SARibbonToolButton::PrivateData::calcSmallButtonDrawRects(const QStyleOptio // 最后设置Indicator if (hasInd) { if (textRect.isValid()) { - indicatorArrowRect = QRect(buttonRect.right() - indicatorLen + 1, - textRect.y(), - indicatorLen, - textRect.height()); + indicatorArrowRect = + QRect(buttonRect.right() - indicatorLen + 1, textRect.y(), indicatorLen, textRect.height()); } else if (iconRect.isValid()) { - indicatorArrowRect = QRect(buttonRect.right() - indicatorLen + 1, - iconRect.y(), - indicatorLen, - iconRect.height()); + indicatorArrowRect = + QRect(buttonRect.right() - indicatorLen + 1, iconRect.y(), indicatorLen, iconRect.height()); } else { indicatorArrowRect = buttonRect; } @@ -3182,12 +3200,11 @@ void SARibbonToolButton::PrivateData::calcLargeButtonDrawRects(const QStyleOptio // 在换行模式下 if (isTextNeedWrap()) { // 如果文字的确换行,indicator放在最右边 - textRect = QRect(spacing, - opt.rect.bottom() - spacing - textHeight, - opt.rect.width() - 2 * spacing - indicatorLen, - textHeight); + textRect = QRect( + spacing, opt.rect.bottom() - spacing - textHeight, opt.rect.width() - 2 * spacing - indicatorLen, textHeight); if (hIndicator) { - indicatorArrowRect = QRect(textRect.right(), textRect.y() + textRect.height() / 2, indicatorLen, textHeight / 2); + indicatorArrowRect = + QRect(textRect.right(), textRect.y() + textRect.height() / 2, indicatorLen, textHeight / 2); } } else { // 如果文字不需要换行,indicator在下板行 @@ -3343,13 +3360,13 @@ int SARibbonToolButton::PrivateData::calcTextDrawRectHeight(const QStyleOptionTo { if (SARibbonToolButton::LargeButton == mButtonType) { if (isEnableWordWrap()) { - return opt.fontMetrics.lineSpacing() * SARIBBONTOOLBUTTON_WORDWRAP_TEXT_FACTOR + opt.fontMetrics.leading(); + return opt.fontMetrics.lineSpacing() * s_twoLineHeightFactor + opt.fontMetrics.leading(); } else { - return opt.fontMetrics.lineSpacing() * SARIBBONTOOLBUTTON_NOWORDWRAP_TEXT_FACTOR; + return opt.fontMetrics.lineSpacing() * s_oneLineHeightFactor; } } // 小按钮 - return opt.fontMetrics.lineSpacing() * SARIBBONTOOLBUTTON_SMALLBUTTON_TEXT_FACTOR; + return opt.fontMetrics.lineSpacing() * s_smallButtonHeightFactor; } /** @@ -3365,12 +3382,12 @@ int SARibbonToolButton::PrivateData::estimateLargeButtonTextWidth(int buttonHeig int textDrawRectHeight, const QString& text, const QFontMetrics& fm, - float widthHeightRatio, int maxTrycount) { QSize textSize; - int space = SA_FONTMETRICS_WIDTH(fm, (QLatin1Char(' '))) * 2; - int hintMaxWidth = buttonHeight * widthHeightRatio; ///< 建议的宽度 + int space = SA_FONTMETRICS_WIDTH(fm, (QLatin1Char(' '))) * 2; + int hintMaxWidth = qMin(static_cast< int >(buttonHeight * SARibbonToolButton::PrivateData::s_textEllipsisAspectFactor), + q_ptr->maximumWidth()); ///< 建议的宽度 if (isEnableWordWrap()) { textSize = fm.size(Qt::TextShowMnemonic, text); textSize.setWidth(textSize.width() + space); @@ -3429,10 +3446,6 @@ int SARibbonToolButton::PrivateData::estimateLargeButtonTextWidth(int buttonHeig // 范围合理,直接返回 return textSize.width(); } - if (textSize.width() > q_ptr->maximumWidth()) { - // 超出了极限,就返回极限 - return q_ptr->maximumWidth(); - } return hintMaxWidth; } @@ -3550,7 +3563,7 @@ void SARibbonToolButton::mousePressEvent(QMouseEvent* e) d_ptr->mMenuButtonPressed = false; //! 注意这里要用QAbstractButton的mousePressEvent,而不是QToolButton的mousePressEvent //! QToolButton的mousePressEvent主要是为了弹出菜单,这里弹出菜单的方式是不一样的,因此不能执行QToolButton的mousePressEvent - QAbstractButton::mousePressEvent(e); + QToolButton::mousePressEvent(e); } void SARibbonToolButton::mouseReleaseEvent(QMouseEvent* e) @@ -3749,7 +3762,8 @@ void SARibbonToolButton::paintText(QPainter& p, const QStyleOptionToolButton& op text = opt.fontMetrics.elidedText(PrivateData::simplified(opt.text), Qt::ElideRight, textDrawRect.width(), alignment); } else { if (!isEnableWordWrap()) { - text = opt.fontMetrics.elidedText(PrivateData::simplified(opt.text), Qt::ElideRight, textDrawRect.width(), alignment); + text = opt.fontMetrics.elidedText( + PrivateData::simplified(opt.text), Qt::ElideRight, textDrawRect.width(), alignment); } else { text = opt.text; } @@ -3770,7 +3784,8 @@ void SARibbonToolButton::paintText(QPainter& p, const QStyleOptionToolButton& op } QStyleOptionToolButton label = opt; label.state = bflags; - style()->drawItemText(&p, textDrawRect, alignment, label.palette, label.state & QStyle::State_Enabled, text, QPalette::ButtonText); + style()->drawItemText( + &p, textDrawRect, alignment, label.palette, label.state & QStyle::State_Enabled, text, QPalette::ButtonText); SARIBBONTOOLBUTTON_DEBUG_DRAW_RECT(p, textDrawRect); } @@ -3918,6 +3933,35 @@ bool SARibbonToolButton::isEnableWordWrap() return SARibbonToolButton::PrivateData::s_enableWordWrap; } +/** + * @brief 文本宽度估算时的宽度比高度系数 + * @param fac 系数,默认为1.4,此系数越大,按钮允许的宽度越宽 + * + * 超过此系数的宽度时,开始尝试换行,例如按钮高度为h,如果单行文本的宽度大于h*系数,则按钮将不进行横向拉伸,类似于maxwidth效果 + * + * 此系数和maxwidth取最小值 + */ +void SARibbonToolButton::setTextEllipsisAspectFactor(qreal fac) +{ + if (fac < 0 && qFuzzyIsNull(fac)) { + qWarning() << tr("The TextEllipsisAspectFactor parameter cannot be set to 0 or a negative number"); // cn:textEllipsisAspectFactor不能设置为0或者负数 + fac = 1.0; + } + SARibbonToolButton::PrivateData::s_textEllipsisAspectFactor = fac; +} + +/** + * @brief 文本宽度估算时的宽度比高度系数 + * + * 超过此系数的宽度时,开始尝试换行,例如按钮高度为h,如果单行文本的宽度大于h*系数,则按钮将不进行横向拉伸,类似于maxwidth效果 + * + * 此系数和maxwidth取最小值 + */ +qreal SARibbonToolButton::textEllipsisAspectFactor() +{ + return SARibbonToolButton::PrivateData::s_textEllipsisAspectFactor; +} + bool SARibbonToolButton::event(QEvent* e) { switch (e->type()) { @@ -4813,7 +4857,8 @@ void SARibbonActionsManagerModel::setupActionsManager(SARibbonActionsManager* m) void SARibbonActionsManagerModel::uninstallActionsManager() { if (!d_ptr->isNull()) { - disconnect(d_ptr->mMgr, &SARibbonActionsManager::actionTagChanged, this, &SARibbonActionsManagerModel::onActionTagChanged); + disconnect( + d_ptr->mMgr, &SARibbonActionsManager::actionTagChanged, this, &SARibbonActionsManagerModel::onActionTagChanged); d_ptr->mMgr = nullptr; d_ptr->mTag = SARibbonActionsManager::CommonlyUsedActionTag; } @@ -6118,9 +6163,8 @@ SARibbonPannelItem* SARibbonPannelLayout::createItem(QAction* action, SARibbonPa } // 不是widget,自动生成SARibbonToolbutton if (!widget) { - SARibbonToolButton::RibbonButtonType buttonType = ((rp == SARibbonPannelItem::Large) - ? SARibbonToolButton::LargeButton - : SARibbonToolButton::SmallButton); + SARibbonToolButton::RibbonButtonType buttonType = + ((rp == SARibbonPannelItem::Large) ? SARibbonToolButton::LargeButton : SARibbonToolButton::SmallButton); SARibbonToolButton* button = RibbonSubElementFactory->createRibbonToolButton(pannel); button->setFocusPolicy(Qt::NoFocus); @@ -8516,9 +8560,8 @@ int SARibbonCategoryLayout::PrivateData::totalSizeHintWidth() const // 如果是hide就直接跳过 #if SARibbonCategoryLayout_DEBUG_PRINT && SA_DEBUG_PRINT_SIZE_HINT ++debug_i__; - debug_totalSizeHintWidth__ += QString(" [%1](%2)is empty skip\n") - .arg(debug_i__) - .arg(item->toPannelWidget()->pannelName()); + debug_totalSizeHintWidth__ += + QString(" [%1](%2)is empty skip\n").arg(debug_i__).arg(item->toPannelWidget()->pannelName()); #endif continue; } @@ -8763,12 +8806,11 @@ void SARibbonCategoryLayout::updateGeometryArr() // 如果total < categoryWidth,m_d->mXBase可以设置为0 // 判断是否超过总长度 #if SARibbonCategoryLayout_DEBUG_PRINT && SA_DEBUG_PRINT_SIZE_HINT - qDebug() << "SARibbonCategoryLayout::updateGeometryArr" - << "\n|-category name=" << category->categoryName() // - << "\n|-category height=" << height // - << "\n|-totalSizeHintWidth=" << total // - << "\n|-y=" << y // - << "\n|-expandWidth:" << expandWidth // + qDebug() << "SARibbonCategoryLayout::updateGeometryArr" << "\n|-category name=" << category->categoryName() // + << "\n|-category height=" << height // + << "\n|-totalSizeHintWidth=" << total // + << "\n|-y=" << y // + << "\n|-expandWidth:" << expandWidth // << "\n|-mag=" << mag; #endif if (total > categoryWidth) { @@ -9828,7 +9870,8 @@ void SARibbonGalleryGroup::recalcGridSize(int galleryHeight) } setGridSize(QSize(w, h)); // 在通过GalleryGroupStyle确定icon的尺寸 - const int shiftpix = 4; // 这个是移动像素,qt在鼠标移动到图标上时会移动一下,给用户明确的动态,导致如果布局很满会超出显示范围,因此要在此基础上缩放一点 + const int shiftpix = + 4; // 这个是移动像素,qt在鼠标移动到图标上时会移动一下,给用户明确的动态,导致如果布局很满会超出显示范围,因此要在此基础上缩放一点 switch (galleryGroupStyle()) { case IconWithText: { int textHeight = fontMetrics().lineSpacing(); @@ -10584,7 +10627,8 @@ class SARibbonBar::PrivateData // 根据字体信息计算category的高度 int calcCategoryHeight(); // 计算tabbar高度 - static int calcMainBarHeight(int tabHegith, int titleHeight, int categoryHeight, bool tabOnTitle, SARibbonBar::RibbonMode rMode); + static int + calcMainBarHeight(int tabHegith, int titleHeight, int categoryHeight, bool tabOnTitle, SARibbonBar::RibbonMode rMode); // 获取当前最小模式下的高度 int getCurrentMinimumModeMainBarHeight() const; // 获取当前正常模式下的高度 @@ -10661,8 +10705,8 @@ int SARibbonBar::PrivateData::systemTabBarHeight() const */ int SARibbonBar::PrivateData::calcTabBarHeight() { - int defaultHeight = systemTabBarHeight(); - int fontHeight = q_ptr->fontMetrics().lineSpacing(); // 不要用height,像宋体这种字体,height=12,lineSpacing=14,有些就无法显示 + int defaultHeight = systemTabBarHeight(); + 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的横杠 @@ -10745,7 +10789,8 @@ int SARibbonBar::PrivateData::calcMainBarHeight(int tabHegith, int SARibbonBar::PrivateData::getCurrentMinimumModeMainBarHeight() const { - return calcMainBarHeight(tabBarHeigth(), titleBarHeight(), categoryHeight(), mIsTabOnTitle, SARibbonBar::MinimumRibbonMode); + return calcMainBarHeight( + tabBarHeigth(), titleBarHeight(), categoryHeight(), mIsTabOnTitle, SARibbonBar::MinimumRibbonMode); } int SARibbonBar::PrivateData::getCurrentNormalModeMainBarHeight() const @@ -11580,14 +11625,12 @@ void SARibbonBar::showMinimumModeButton(bool isShow) activeRightButtonGroup(); d_ptr->mMinimumCategoryButtonAction = new QAction(this); - d_ptr->mMinimumCategoryButtonAction->setIcon( - style()->standardIcon(isMinimumMode() ? QStyle::SP_TitleBarUnshadeButton : QStyle::SP_TitleBarShadeButton, - nullptr)); + d_ptr->mMinimumCategoryButtonAction->setIcon(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)); + this->d_ptr->mMinimumCategoryButtonAction->setIcon(style()->standardIcon( + isMinimumMode() ? QStyle::SP_TitleBarUnshadeButton : QStyle::SP_TitleBarShadeButton, nullptr)); }); d_ptr->mRightButtonGroup->addAction(d_ptr->mMinimumCategoryButtonAction); @@ -12211,6 +12254,32 @@ bool SARibbonBar::isEnableWordWrap() const return SARibbonToolButton::isEnableWordWrap(); } +/** + * @brief 文本宽度估算时的宽度比高度系数 + * @param fac 系数,默认为1.4,此系数越大,按钮允许的宽度越宽 + * + * 超过此系数的宽度时,开始尝试换行,例如按钮高度为h,如果单行文本的宽度大于h*系数,则按钮将不进行横向拉伸,类似于maxwidth效果 + * + * 此系数和maxwidth取最小值 + */ +void SARibbonBar::setButtonTextEllipsisAspectFactor(qreal fac) +{ + SARibbonToolButton::setTextEllipsisAspectFactor(fac); + updateRibbonGeometry(); +} + +/** + * @brief 文本宽度估算时的宽度比高度系数 + * + * 超过此系数的宽度时,开始尝试换行,例如按钮高度为h,如果单行文本的宽度大于h*系数,则按钮将不进行横向拉伸,类似于maxwidth效果 + * + * 此系数和maxwidth取最小值 + */ +qreal SARibbonBar::buttonTextEllipsisAspectFactor() const +{ + return SARibbonToolButton::textEllipsisAspectFactor(); +} + /** * @brief pannel标题栏的高度 * @return @@ -14588,8 +14657,8 @@ QAction* SARibbonCustomizeWidget::PrivateData::itemToAction(QStandardItem* item) if (item->data(SARibbonCustomizeWidget::CustomizeRole).toBool()) { act = reinterpret_cast< QAction* >(item->data(SARibbonCustomizeWidget::PointerRole).value< qintptr >()); } else { - SARibbonPannelItem* pi = reinterpret_cast< SARibbonPannelItem* >( - item->data(SARibbonCustomizeWidget::PointerRole).value< qintptr >()); + SARibbonPannelItem* pi = + reinterpret_cast< SARibbonPannelItem* >(item->data(SARibbonCustomizeWidget::PointerRole).value< qintptr >()); act = (pi->action); } return (act); @@ -15114,10 +15183,8 @@ void SARibbonCustomizeWidget::onPushButtonNewCategoryClicked() // 设置新增的为选中 setSelectItem(ni); // 把动作插入动作列表中 - SARibbonCustomizeData d = SARibbonCustomizeData::makeAddCategoryCustomizeData(ni->text(), - ni->row(), - SARibbonCustomizeWidget::PrivateData::makeRandomObjName( - "category")); + SARibbonCustomizeData d = SARibbonCustomizeData::makeAddCategoryCustomizeData( + ni->text(), ni->row(), SARibbonCustomizeWidget::PrivateData::makeRandomObjName("category")); d_ptr->mCustomizeDatasCache.append(d); ni->setData(true, SARibbonCustomizeWidget::CanCustomizeRole); // 有CustomizeRole,必有CanCustomizeRole @@ -15159,11 +15226,8 @@ void SARibbonCustomizeWidget::onPushButtonNewPannelClicked() QString categoryObjName = ""; categoryObjName = d_ptr->itemObjectName(categoryItem); - SARibbonCustomizeData d = SARibbonCustomizeData::makeAddPannelCustomizeData(ni->text(), - ni->row(), - categoryObjName, - SARibbonCustomizeWidget::PrivateData::makeRandomObjName( - "pannel")); + SARibbonCustomizeData d = SARibbonCustomizeData::makeAddPannelCustomizeData( + ni->text(), ni->row(), categoryObjName, SARibbonCustomizeWidget::PrivateData::makeRandomObjName("pannel")); d_ptr->mCustomizeDatasCache.append(d); ni->setData(true, SARibbonCustomizeWidget::CanCustomizeRole); // 有CustomizeRole,必有CanCustomizeRole @@ -15227,11 +15291,8 @@ void SARibbonCustomizeWidget::onPushButtonAddClicked() QString categoryObjName = d_ptr->itemObjectName(item->parent()); QString key = d_ptr->mActionMgr->key(act); - SARibbonCustomizeData d = SARibbonCustomizeData::makeAddActionCustomizeData(key, - d_ptr->mActionMgr, - selectedRowProportion(), - categoryObjName, - pannelObjName); + SARibbonCustomizeData d = SARibbonCustomizeData::makeAddActionCustomizeData( + key, d_ptr->mActionMgr, selectedRowProportion(), categoryObjName, pannelObjName); d_ptr->mCustomizeDatasCache.append(d); @@ -15277,10 +15338,8 @@ void SARibbonCustomizeWidget::onPushButtonDeleteClicked() return; } - SARibbonCustomizeData d = SARibbonCustomizeData::makeRemoveActionCustomizeData(catObjName, - pannelObjName, - key, - d_ptr->mActionMgr); + SARibbonCustomizeData d = + SARibbonCustomizeData::makeRemoveActionCustomizeData(catObjName, pannelObjName, key, d_ptr->mActionMgr); d_ptr->mCustomizeDatasCache.append(d); } // 执行删除操作 @@ -15327,18 +15386,17 @@ void SARibbonCustomizeWidget::onToolButtonUpClicked() if (0 == level) { // 移动category - SARibbonCustomizeData d = SARibbonCustomizeData::makeChangeCategoryOrderCustomizeData(d_ptr->itemObjectName(item), - -1); + SARibbonCustomizeData d = + SARibbonCustomizeData::makeChangeCategoryOrderCustomizeData(d_ptr->itemObjectName(item), -1); d_ptr->mCustomizeDatasCache.append(d); int r = item->row(); item = d_ptr->mRibbonModel->takeItem(r); d_ptr->mRibbonModel->removeRow(r); d_ptr->mRibbonModel->insertRow(r - 1, item); } else if (1 == level) { - QStandardItem* paritem = item->parent(); - SARibbonCustomizeData d = SARibbonCustomizeData::makeChangePannelOrderCustomizeData(d_ptr->itemObjectName(paritem), - d_ptr->itemObjectName(item), - -1); + QStandardItem* paritem = item->parent(); + SARibbonCustomizeData d = SARibbonCustomizeData::makeChangePannelOrderCustomizeData( + d_ptr->itemObjectName(paritem), d_ptr->itemObjectName(item), -1); d_ptr->mCustomizeDatasCache.append(d); int r = item->row(); item = paritem->takeChild(r); @@ -15351,12 +15409,9 @@ void SARibbonCustomizeWidget::onToolButtonUpClicked() if (!act) { return; } - QString key = d_ptr->mActionMgr->key(act); - SARibbonCustomizeData d = SARibbonCustomizeData::makeChangeActionOrderCustomizeData(d_ptr->itemObjectName(categoryItem), - d_ptr->itemObjectName(pannelItem), - key, - d_ptr->mActionMgr, - -1); + QString key = d_ptr->mActionMgr->key(act); + SARibbonCustomizeData d = SARibbonCustomizeData::makeChangeActionOrderCustomizeData( + d_ptr->itemObjectName(categoryItem), d_ptr->itemObjectName(pannelItem), key, d_ptr->mActionMgr, -1); d_ptr->mCustomizeDatasCache.append(d); int r = item->row(); item = pannelItem->takeChild(r); @@ -15390,18 +15445,17 @@ void SARibbonCustomizeWidget::onToolButtonDownClicked() if (0 == level) { // 移动category - SARibbonCustomizeData d = SARibbonCustomizeData::makeChangeCategoryOrderCustomizeData(d_ptr->itemObjectName(item), - 1); + SARibbonCustomizeData d = + SARibbonCustomizeData::makeChangeCategoryOrderCustomizeData(d_ptr->itemObjectName(item), 1); d_ptr->mCustomizeDatasCache.append(d); int r = item->row(); item = d_ptr->mRibbonModel->takeItem(item->row()); d_ptr->mRibbonModel->removeRow(r); d_ptr->mRibbonModel->insertRow(r + 1, item); } else if (1 == level) { - QStandardItem* paritem = item->parent(); - SARibbonCustomizeData d = SARibbonCustomizeData::makeChangePannelOrderCustomizeData(d_ptr->itemObjectName(paritem), - d_ptr->itemObjectName(item), - 1); + QStandardItem* paritem = item->parent(); + SARibbonCustomizeData d = SARibbonCustomizeData::makeChangePannelOrderCustomizeData( + d_ptr->itemObjectName(paritem), d_ptr->itemObjectName(item), 1); d_ptr->mCustomizeDatasCache.append(d); int r = item->row(); item = paritem->takeChild(r); @@ -15414,12 +15468,9 @@ void SARibbonCustomizeWidget::onToolButtonDownClicked() if (!act) { return; } - QString key = d_ptr->mActionMgr->key(act); - SARibbonCustomizeData d = SARibbonCustomizeData::makeChangeActionOrderCustomizeData(d_ptr->itemObjectName(categoryItem), - d_ptr->itemObjectName(pannelItem), - key, - d_ptr->mActionMgr, - -1); + QString key = d_ptr->mActionMgr->key(act); + SARibbonCustomizeData d = SARibbonCustomizeData::makeChangeActionOrderCustomizeData( + d_ptr->itemObjectName(categoryItem), d_ptr->itemObjectName(pannelItem), key, d_ptr->mActionMgr, -1); d_ptr->mCustomizeDatasCache.append(d); int r = item->row(); item = pannelItem->takeChild(r); @@ -15441,10 +15492,9 @@ void SARibbonCustomizeWidget::onItemChanged(QStandardItem* item) if (0 == level) { if (item->isCheckable()) { - QString objname = d_ptr->itemObjectName(item); - SARibbonCustomizeData d = SARibbonCustomizeData::makeVisibleCategoryCustomizeData(objname, - item->checkState() - == Qt::Checked); + QString objname = d_ptr->itemObjectName(item); + SARibbonCustomizeData d = + SARibbonCustomizeData::makeVisibleCategoryCustomizeData(objname, item->checkState() == Qt::Checked); d_ptr->mCustomizeDatasCache.append(d); } } diff --git a/src/SARibbon.h b/src/SARibbon.h index 69e8e23..522a174 100644 --- a/src/SARibbon.h +++ b/src/SARibbon.h @@ -1,4 +1,4 @@ -#ifndef SA_RIBBON_H +#ifndef SA_RIBBON_H #define SA_RIBBON_H // 定义此宏,将SA_RIBBON_EXPORT定义为空 #ifndef SA_RIBBON_BAR_NO_EXPORT @@ -97,14 +97,14 @@ * @def ribbon的数字版本 MAJ.MIN.{PAT} */ #ifndef SA_RIBBON_BAR_VERSION_PAT -#define SA_RIBBON_BAR_VERSION_PAT 5 +#define SA_RIBBON_BAR_VERSION_PAT 8 #endif /** * @def 版本号(字符串) */ #ifndef SARIBBON_VERSION -#define SARIBBON_VERSION "2.2.5" +#define SARIBBON_VERSION "2.2.8" #endif #endif // SARIBBONVERSIONINFO_H @@ -722,15 +722,15 @@ class SA_RIBBON_EXPORT SARibbonSystemButtonBar : public QFrame QSize iconSize() const; // 生成并添加一个action QAction* addAction(QAction* a, - Qt::ToolButtonStyle buttonStyle = Qt::ToolButtonIconOnly, - QToolButton::ToolButtonPopupMode popMode = QToolButton::DelayedPopup); + Qt::ToolButtonStyle buttonStyle = Qt::ToolButtonIconOnly, + QToolButton::ToolButtonPopupMode popMode = QToolButton::DelayedPopup); QAction* addAction(const QString& text, - const QIcon& icon, - Qt::ToolButtonStyle buttonStyle = Qt::ToolButtonIconOnly, - QToolButton::ToolButtonPopupMode popMode = QToolButton::DelayedPopup); + const QIcon& icon, + Qt::ToolButtonStyle buttonStyle = Qt::ToolButtonIconOnly, + QToolButton::ToolButtonPopupMode popMode = QToolButton::DelayedPopup); QAction* addMenu(QMenu* menu, - Qt::ToolButtonStyle buttonStyle = Qt::ToolButtonIconOnly, - QToolButton::ToolButtonPopupMode popMode = QToolButton::InstantPopup); + Qt::ToolButtonStyle buttonStyle = Qt::ToolButtonIconOnly, + QToolButton::ToolButtonPopupMode popMode = QToolButton::InstantPopup); QAction* addSeparator(); QAction* addWidget(QWidget* w); @@ -793,27 +793,30 @@ class SA_RIBBON_EXPORT SARibbonToolButton : public QToolButton explicit SARibbonToolButton(QWidget* parent = nullptr); explicit SARibbonToolButton(QAction* defaultAction, QWidget* parent = nullptr); ~SARibbonToolButton(); - // 标记按钮的样式,按钮的样式有不同的渲染方式 + // 标记按钮的样式,按钮的样式有不同的渲染方式 RibbonButtonType buttonType() const; void setButtonType(const RibbonButtonType& buttonType); - // 是否是小按钮 + // 是否是小按钮 bool isSmallRibbonButton() const; - // 是否是大按钮 + // 是否是大按钮 bool isLargeRibbonButton() const; - // 最小尺寸提示 + // 最小尺寸提示 virtual QSize minimumSizeHint() const Q_DECL_OVERRIDE; - // 获取间距 + // 获取间距 int spacing() const; - // 更新尺寸 + // 更新尺寸 void updateRect(); virtual QSize sizeHint() const Q_DECL_OVERRIDE; public: - // 在lite模式下是否允许文字换行 + // 在lite模式下是否允许文字换行 static void setEnableWordWrap(bool on); static bool isEnableWordWrap(); + // 文本宽度估算时的宽度比高度系数,超过此系数的宽度时,开始尝试换行或者省略号显示 + static void setTextEllipsisAspectFactor(qreal fac = 1.4); + static qreal textEllipsisAspectFactor(); protected: virtual void paintEvent(QPaintEvent* e) Q_DECL_OVERRIDE; @@ -825,26 +828,26 @@ class SA_RIBBON_EXPORT SARibbonToolButton : public QToolButton virtual void leaveEvent(QEvent* e) Q_DECL_OVERRIDE; virtual bool hitButton(const QPoint& pos) const Q_DECL_OVERRIDE; virtual bool event(QEvent* e) Q_DECL_OVERRIDE; - // 事件改变 - 主要为了捕获字体的改变 + // 事件改变 - 主要为了捕获字体的改变 virtual void changeEvent(QEvent* e) Q_DECL_OVERRIDE; virtual void actionEvent(QActionEvent* e) Q_DECL_OVERRIDE; protected: - // 绘制按钮 + // 绘制按钮 virtual void paintButton(QPainter& p, const QStyleOptionToolButton& opt); - // 绘制图标 + // 绘制图标 virtual void paintIcon(QPainter& p, const QStyleOptionToolButton& opt, const QRect& iconDrawRect); - // 绘制文本 + // 绘制文本 virtual void paintText(QPainter& p, const QStyleOptionToolButton& opt, const QRect& textDrawRect); - // 绘制Indicator + // 绘制Indicator virtual void paintIndicator(QPainter& p, const QStyleOptionToolButton& opt, const QRect& indicatorDrawRect); private: static void drawArrow(const QStyle* style, - const QStyleOptionToolButton* toolbutton, - const QRect& rect, - QPainter* painter, - const QWidget* widget = 0); + const QStyleOptionToolButton* toolbutton, + const QRect& rect, + QPainter* painter, + const QWidget* widget = 0); protected: }; @@ -936,23 +939,23 @@ class SA_RIBBON_EXPORT SARibbonLineWidgetContainer : public QWidget public: explicit SARibbonLineWidgetContainer(QWidget* par = nullptr); ~SARibbonLineWidgetContainer(); - // 设置widget,不允许设置一个nullptr + // 设置widget,不允许设置一个nullptr void setWidget(QWidget* innerWidget); - // 设置前缀 + // 设置前缀 void setPrefix(const QString& str); - // 设置后缀 + // 设置后缀 void setSuffix(const QString& str); - // 前缀文本框 + // 前缀文本框 QLabel* labelPrefix() const; - // 后缀文本框 + // 后缀文本框 QLabel* labelSuffix() const; private: - // 两个文本 + // 两个文本 QLabel* m_labelPrefix; QLabel* m_labelSuffix; QWidget* m_innerWidget; @@ -1020,53 +1023,53 @@ class SA_RIBBON_EXPORT SARibbonActionsManager : public QObject }; explicit SARibbonActionsManager(SARibbonBar* bar); ~SARibbonActionsManager(); - // 设置tag对应的名字 + // 设置tag对应的名字 void setTagName(int tag, const QString& name); - // 获取tag对应的名字 + // 获取tag对应的名字 QString tagName(int tag) const; - // 移除tag,注意,这个函数非常耗时 + // 移除tag,注意,这个函数非常耗时 void removeTag(int tag); - // 注册action + // 注册action bool registeAction(QAction* act, int tag, const QString& key = QString(), bool enableEmit = true); - // 取消action的注册 + // 取消action的注册 void unregisteAction(QAction* act, bool enableEmit = true); - // 过滤得到actions对应的引用,实际是一个迭代器 + // 过滤得到actions对应的引用,实际是一个迭代器 QList< QAction* >& filter(int tag); - // 通过tag筛选出系列action + // 通过tag筛选出系列action QList< QAction* >& actions(int tag); const QList< QAction* > actions(int tag) const; - // 获取所有的标签 + // 获取所有的标签 QList< int > actionTags() const; - // 通过key获取action + // 通过key获取action QAction* action(const QString& key) const; - // 通过action找到key + // 通过action找到key QString key(QAction* act) const; - // 返回所有管理的action数 + // 返回所有管理的action数 int count() const; - // 返回所有管理的actions + // 返回所有管理的actions QList< QAction* > allActions() const; - // 自动加载action,返回tag对应的Category指针 + // 自动加载action,返回tag对应的Category指针 QMap< int, SARibbonCategory* > autoRegisteActions(SARibbonBar* bar); - // 自动加载widget下的actions函数返回的action,返回加载的数量,这些 + // 自动加载widget下的actions函数返回的action,返回加载的数量,这些 QSet< QAction* > autoRegisteWidgetActions(QWidget* w, int tag, bool enableEmit = false); - // 根据标题查找action + // 根据标题查找action QList< QAction* > search(const QString& text); - // 清除 + // 清除 void clear(); Q_SIGNALS: @@ -1127,8 +1130,8 @@ class SA_RIBBON_EXPORT SARibbonLineEdit : public QLineEdit { Q_OBJECT public: - explicit SARibbonLineEdit(QWidget* parent = nullptr); - explicit SARibbonLineEdit(const QString& text, QWidget* parent = nullptr); + explicit SARibbonLineEdit(QWidget* parent = nullptr); + explicit SARibbonLineEdit(const QString& text, QWidget* parent = nullptr); ~SARibbonLineEdit(); }; @@ -1149,8 +1152,8 @@ class SA_RIBBON_EXPORT SARibbonCheckBox : public QCheckBox { Q_OBJECT public: - explicit SARibbonCheckBox(QWidget* parent = nullptr); - explicit SARibbonCheckBox(const QString& text, QWidget* parent = nullptr); + explicit SARibbonCheckBox(QWidget* parent = nullptr); + explicit SARibbonCheckBox(const QString& text, QWidget* parent = nullptr); ~SARibbonCheckBox(); }; @@ -1171,7 +1174,7 @@ class SA_RIBBON_EXPORT SARibbonComboBox : public QComboBox { Q_OBJECT public: - explicit SARibbonComboBox(QWidget* parent = nullptr); + explicit SARibbonComboBox(QWidget* parent = nullptr); ~SARibbonComboBox(); }; @@ -1206,15 +1209,15 @@ class SA_RIBBON_EXPORT SARibbonButtonGroupWidget : public QFrame QSize iconSize() const; // 生成并添加一个action QAction* addAction(QAction* a, - Qt::ToolButtonStyle buttonStyle = Qt::ToolButtonIconOnly, - QToolButton::ToolButtonPopupMode popMode = QToolButton::DelayedPopup); + Qt::ToolButtonStyle buttonStyle = Qt::ToolButtonIconOnly, + QToolButton::ToolButtonPopupMode popMode = QToolButton::DelayedPopup); QAction* addAction(const QString& text, - const QIcon& icon, - Qt::ToolButtonStyle buttonStyle = Qt::ToolButtonIconOnly, - QToolButton::ToolButtonPopupMode popMode = QToolButton::DelayedPopup); + const QIcon& icon, + Qt::ToolButtonStyle buttonStyle = Qt::ToolButtonIconOnly, + QToolButton::ToolButtonPopupMode popMode = QToolButton::DelayedPopup); QAction* addMenu(QMenu* menu, - Qt::ToolButtonStyle buttonStyle = Qt::ToolButtonIconOnly, - QToolButton::ToolButtonPopupMode popMode = QToolButton::InstantPopup); + Qt::ToolButtonStyle buttonStyle = Qt::ToolButtonIconOnly, + QToolButton::ToolButtonPopupMode popMode = QToolButton::InstantPopup); QAction* addSeparator(); QAction* addWidget(QWidget* w); // 从ButtonGroupWidget中把action对应的button提取出来,如果action没有对应的button,就返回nullptr @@ -1376,12 +1379,12 @@ class SA_RIBBON_EXPORT SARibbonQuickAccessBar : public SARibbonCtrlContainer ~SARibbonQuickAccessBar(); void addSeparator(); void addAction(QAction* act, - Qt::ToolButtonStyle buttonStyle = Qt::ToolButtonIconOnly, - QToolButton::ToolButtonPopupMode popMode = QToolButton::DelayedPopup); + Qt::ToolButtonStyle buttonStyle = Qt::ToolButtonIconOnly, + QToolButton::ToolButtonPopupMode popMode = QToolButton::DelayedPopup); void addWidget(QWidget* w); void addMenu(QMenu* m, - Qt::ToolButtonStyle buttonStyle = Qt::ToolButtonIconOnly, - QToolButton::ToolButtonPopupMode popMode = QToolButton::InstantPopup); + Qt::ToolButtonStyle buttonStyle = Qt::ToolButtonIconOnly, + QToolButton::ToolButtonPopupMode popMode = QToolButton::InstantPopup); // 获取内部管理的ButtonGroupWidget SARibbonButtonGroupWidget* buttonGroupWidget(); const SARibbonButtonGroupWidget* buttonGroupWidget() const; @@ -1753,8 +1756,8 @@ class SA_RIBBON_EXPORT SARibbonPannel : public QFrame void addAction(QAction* action, SARibbonPannelItem::RowProportion rp); // 生成并添加一个action void addAction(QAction* act, - QToolButton::ToolButtonPopupMode popMode, - SARibbonPannelItem::RowProportion rp = SARibbonPannelItem::Large); + QToolButton::ToolButtonPopupMode popMode, + SARibbonPannelItem::RowProportion rp = SARibbonPannelItem::Large); // 把action加入到pannel,并以大图标显示 void addLargeAction(QAction* action); // 把action加入到pannel,在三行模式下会以中图标显示 @@ -1770,14 +1773,14 @@ class SA_RIBBON_EXPORT SARibbonPannel : public QFrame void addMediumAction(QAction* action, QToolButton::ToolButtonPopupMode popMode); QAction* addAction(const QString& text, - const QIcon& icon, - QToolButton::ToolButtonPopupMode popMode, - SARibbonPannelItem::RowProportion rp = SARibbonPannelItem::Large); + const QIcon& icon, + QToolButton::ToolButtonPopupMode popMode, + SARibbonPannelItem::RowProportion rp = SARibbonPannelItem::Large); // 添加menu void addMenu(QMenu* menu, - SARibbonPannelItem::RowProportion rp, - QToolButton::ToolButtonPopupMode popMode = QToolButton::InstantPopup); + SARibbonPannelItem::RowProportion rp, + QToolButton::ToolButtonPopupMode popMode = QToolButton::InstantPopup); // 添加普通大菜单 void addLargeMenu(QMenu* menu, QToolButton::ToolButtonPopupMode popMode = QToolButton::InstantPopup); @@ -2205,34 +2208,34 @@ class SA_RIBBON_EXPORT SARibbonContextCategory : public QObject public: explicit SARibbonContextCategory(QWidget* parent = nullptr); ~SARibbonContextCategory(); - // 上下文目录添加下属目录 + // 上下文目录添加下属目录 SARibbonCategory* addCategoryPage(const QString& title); void addCategoryPage(SARibbonCategory* category); - // 获取上下文标签下管理的标签个数 + // 获取上下文标签下管理的标签个数 int categoryCount() const; - // 设置id + // 设置id void setId(const QVariant& id); QVariant id() const; - // 设置上下文颜色 + // 设置上下文颜色 void setContextColor(const QColor color); QColor contextColor() const; - // 上下文标签的内容 + // 上下文标签的内容 QString contextTitle() const; void setContextTitle(const QString& contextTitle); - // 获取对应的tab页 + // 获取对应的tab页 SARibbonCategory* categoryPage(int index); - // 获取所有的SARibbonCategory* + // 获取所有的SARibbonCategory* QList< SARibbonCategory* > categoryList() const; - // 移除category + // 移除category bool takeCategory(SARibbonCategory* category); - // 判断上下文是否维护了此SARibbonCategory + // 判断上下文是否维护了此SARibbonCategory bool isHaveCategory(SARibbonCategory* category) const; Q_SIGNALS: /** @@ -2263,7 +2266,7 @@ private Q_SLOTS: void onCategoryTitleChanged(const QString& title); protected: - // 获取父级窗口 + // 获取父级窗口 QWidget* parentWidget() const; virtual bool eventFilter(QObject* watched, QEvent* e) override; }; @@ -2361,7 +2364,8 @@ class SA_RIBBON_EXPORT SARibbonGalleryGroupItemDelegate : public QStyledItemDele virtual QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const override; virtual void paintIconOnly(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const; virtual void paintIconWithText(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const; - virtual void paintIconWithTextWordWrap(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const; + virtual void + paintIconWithTextWordWrap(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const; private: SARibbonGalleryGroup* mGroup; @@ -2818,9 +2822,8 @@ class SA_RIBBON_EXPORT SARibbonBar : public QMenuBar void removeCategory(SARibbonCategory* category); // 添加一个上下文标签 - SARibbonContextCategory* addContextCategory(const QString& title, - const QColor& color = QColor(), - const QVariant& id = QVariant()); + SARibbonContextCategory* + addContextCategory(const QString& title, const QColor& color = QColor(), const QVariant& id = QVariant()); void addContextCategory(SARibbonContextCategory* context); // 显示一个上下文标签 @@ -2937,6 +2940,10 @@ class SA_RIBBON_EXPORT SARibbonBar : public QMenuBar void setEnableWordWrap(bool on); bool isEnableWordWrap() const; + // 文本宽度估算时的宽度比高度系数,超过此系数的宽度时,开始尝试换行或者省略号显示 + void setButtonTextEllipsisAspectFactor(qreal fac = 1.4); + qreal buttonTextEllipsisAspectFactor() const; + // 设置pannel的标题栏高度 int pannelTitleHeight() const; void setPannelTitleHeight(int h); @@ -3060,7 +3067,8 @@ protected Q_SLOTS: virtual bool event(QEvent* e) override; virtual void paintTabbarBaseLine(QPainter& painter); virtual void paintWindowTitle(QPainter& painter, const QString& title, const QRect& titleRegion); - virtual void paintContextCategoryTab(QPainter& painter, const QString& title, const QRect& contextRect, const QColor& color); + virtual void + paintContextCategoryTab(QPainter& painter, const QString& title, const QRect& contextRect, const QColor& color); #if SA_DEBUG_PRINT_SARIBBONBAR SA_RIBBON_EXPORT friend QDebug operator<<(QDebug debug, const SARibbonBar& ribbon); #endif @@ -3242,25 +3250,22 @@ class SA_RIBBON_EXPORT SARibbonCustomizeData static SARibbonCustomizeData makeAddCategoryCustomizeData(const QString& title, int index, const QString& objName); // 对应AddPannelActionType - static SARibbonCustomizeData makeAddPannelCustomizeData(const QString& title, - int index, - const QString& categoryobjName, - const QString& objName); + static SARibbonCustomizeData + makeAddPannelCustomizeData(const QString& title, int index, const QString& categoryobjName, const QString& objName); // 对应AddActionActionType static SARibbonCustomizeData makeAddActionCustomizeData(const QString& key, - SARibbonActionsManager* mgr, - SARibbonPannelItem::RowProportion rp, - const QString& categoryObjName, - const QString& pannelObjName); + SARibbonActionsManager* mgr, + SARibbonPannelItem::RowProportion rp, + const QString& categoryObjName, + const QString& pannelObjName); // 对应RenameCategoryActionType static SARibbonCustomizeData makeRenameCategoryCustomizeData(const QString& newname, const QString& categoryobjName); // 对应RenamePannelActionType - static SARibbonCustomizeData makeRenamePannelCustomizeData(const QString& newname, - const QString& categoryobjName, - const QString& pannelObjName); + static SARibbonCustomizeData + makeRenamePannelCustomizeData(const QString& newname, const QString& categoryobjName, const QString& pannelObjName); // 对应RemoveCategoryActionType static SARibbonCustomizeData makeRemoveCategoryCustomizeData(const QString& categoryobjName); @@ -3269,25 +3274,24 @@ class SA_RIBBON_EXPORT SARibbonCustomizeData static SARibbonCustomizeData makeChangeCategoryOrderCustomizeData(const QString& categoryobjName, int moveindex); // 对应ChangePannelOrderActionType - static SARibbonCustomizeData makeChangePannelOrderCustomizeData(const QString& categoryobjName, - const QString& pannelObjName, - int moveindex); + static SARibbonCustomizeData + makeChangePannelOrderCustomizeData(const QString& categoryobjName, const QString& pannelObjName, int moveindex); // 对应ChangeActionOrderActionType static SARibbonCustomizeData makeChangeActionOrderCustomizeData(const QString& categoryobjName, - const QString& pannelObjName, - const QString& key, - SARibbonActionsManager* mgr, - int moveindex); + const QString& pannelObjName, + const QString& key, + SARibbonActionsManager* mgr, + int moveindex); // 对应RemovePannelActionType static SARibbonCustomizeData makeRemovePannelCustomizeData(const QString& categoryobjName, const QString& pannelObjName); // 对应RemoveActionActionType static SARibbonCustomizeData makeRemoveActionCustomizeData(const QString& categoryobjName, - const QString& pannelObjName, - const QString& key, - SARibbonActionsManager* mgr); + const QString& pannelObjName, + const QString& key, + SARibbonActionsManager* mgr); // 对应VisibleCategoryActionType static SARibbonCustomizeData makeVisibleCategoryCustomizeData(const QString& categoryobjName, bool isShow); @@ -3370,14 +3374,14 @@ class SA_RIBBON_EXPORT SARibbonCustomizeWidget : public QWidget Q_OBJECT SA_RIBBON_DECLARE_PRIVATE(SARibbonCustomizeWidget) public: - // 保留接口 - explicit SARibbonCustomizeWidget(SARibbonMainWindow* ribbonWindow, - QWidget* parent = nullptr, - Qt::WindowFlags f = Qt::WindowFlags()); - // 对于不使用SARibbonMainWindow的情况,使用此构造函数 - explicit SARibbonCustomizeWidget(SARibbonBar* ribbonbar, - QWidget* parent = nullptr, - Qt::WindowFlags f = Qt::WindowFlags()); + // 保留接口 + explicit SARibbonCustomizeWidget(SARibbonMainWindow* ribbonWindow, + QWidget* parent = nullptr, + Qt::WindowFlags f = Qt::WindowFlags()); + // 对于不使用SARibbonMainWindow的情况,使用此构造函数 + explicit SARibbonCustomizeWidget(SARibbonBar* ribbonbar, + QWidget* parent = nullptr, + Qt::WindowFlags f = Qt::WindowFlags()); ~SARibbonCustomizeWidget(); /** @@ -3394,57 +3398,57 @@ class SA_RIBBON_EXPORT SARibbonCustomizeWidget : public QWidget */ enum ItemRole { - LevelRole = Qt::UserRole + 1, ///< 代表这是层级,有0:category 1:pannel 2:item - PointerRole = Qt::UserRole + 2, ///< 代表这是存放指针。根据LevelRole来进行转 - CanCustomizeRole = Qt::UserRole + 3, ///< 代表个item是可以自定义的.bool - CustomizeRole = Qt::UserRole + 4, ///< 代表这个是自定义的item,bool,主要用于那些自己添加的标签和pannel,有此角色必有CanCustomizeRole - CustomizeObjNameRole = Qt::UserRole + 5 ///< 记录了临时的自定义内容的obj名 QString + LevelRole = Qt::UserRole + 1, ///< 代表这是层级,有0:category 1:pannel 2:item + PointerRole = Qt::UserRole + 2, ///< 代表这是存放指针。根据LevelRole来进行转 + CanCustomizeRole = Qt::UserRole + 3, ///< 代表个item是可以自定义的.bool + CustomizeRole = Qt::UserRole + 4, ///< 代表这个是自定义的item,bool,主要用于那些自己添加的标签和pannel,有此角色必有CanCustomizeRole + CustomizeObjNameRole = Qt::UserRole + 5 ///< 记录了临时的自定义内容的obj名 QString }; - // 设置action管理器 + // 设置action管理器 void setupActionsManager(SARibbonActionsManager* mgr); - // 判断用户是否有要存储的内容,对应save动作 + // 判断用户是否有要存储的内容,对应save动作 bool isApplied() const; - // 判断用户是否有改动内容,对应apply动作 + // 判断用户是否有改动内容,对应apply动作 bool isCached() const; - // 获取model + // 获取model const QStandardItemModel* model() const; - // 根据当前的radiobutton选项来更新model + // 根据当前的radiobutton选项来更新model void updateModel(); - // 更新model + // 更新model void updateModel(RibbonTreeShowType type); - // 应用所有的设定 + // 应用所有的设定 bool applys(); - // 转换为xml + // 转换为xml bool toXml(QXmlStreamWriter* xml) const; bool toXml(const QString& xmlpath) const; - // 从xml中加载QList,对于基于配置文件的设置,对话框显示前建议调用此函数,保证叠加设置的正确记录 + // 从xml中加载QList,对于基于配置文件的设置,对话框显示前建议调用此函数,保证叠加设置的正确记录 void fromXml(QXmlStreamReader* xml); void fromXml(const QString& xmlpath); - // 应用xml配置,可以结合customize_datas_from_xml和customize_datas_apply函数 + // 应用xml配置,可以结合customize_datas_from_xml和customize_datas_apply函数 static bool fromXml(QXmlStreamReader* xml, SARibbonBar* bar, SARibbonActionsManager* mgr); - // 缓存应用的动作,这些动作不会被clear清除,用于本地存储 + // 缓存应用的动作,这些动作不会被clear清除,用于本地存储 void makeActionsApplied(); - // 清除applied的动作,cancel操作后需要清空已应用的动作 + // 清除applied的动作,cancel操作后需要清空已应用的动作 void clearApplied(); - // 清除缓存动作,在执行applys函数后,如果要继续调用,应该clear,否则会导致异常 + // 清除缓存动作,在执行applys函数后,如果要继续调用,应该clear,否则会导致异常 void clearCache(); - // 清除所有动作,不包含本地读取的数据 + // 清除所有动作,不包含本地读取的数据 void clear(); protected: - // 把QList进行裁剪,把一些动作合并 + // 把QList进行裁剪,把一些动作合并 void simplify(); SARibbonPannelItem::RowProportion selectedRowProportion() const; @@ -3454,24 +3458,24 @@ class SA_RIBBON_EXPORT SARibbonCustomizeWidget : public QWidget QStandardItem* selectedItem() const; - // 获取选中的ribbon tree 的level + // 获取选中的ribbon tree 的level int selectedRibbonLevel() const; - // 根据选中的item判断 + // 根据选中的item判断 int itemLevel(QStandardItem* item) const; - // 设置某个item被选中 + // 设置某个item被选中 void setSelectItem(QStandardItem* item, bool ensureVisible = true); - // 判断itemn能否改动,可以改动返回true + // 判断itemn能否改动,可以改动返回true bool isItemCanCustomize(QStandardItem* item) const; bool isSelectedItemCanCustomize() const; - // 判断item是否是自定义的item + // 判断item是否是自定义的item bool isCustomizeItem(QStandardItem* item) const; bool isSelectedItemIsCustomize() const; - // 删除一个item + // 删除一个item void removeItem(QStandardItem* item); private Q_SLOTS: @@ -3579,40 +3583,40 @@ class SA_RIBBON_EXPORT SARibbonCustomizeDialog : public QDialog { Q_OBJECT public: - explicit SARibbonCustomizeDialog(SARibbonMainWindow* ribbonWindow, - QWidget* p = nullptr, - Qt::WindowFlags f = Qt::WindowFlags()); + explicit SARibbonCustomizeDialog(SARibbonMainWindow* ribbonWindow, + QWidget* p = nullptr, + Qt::WindowFlags f = Qt::WindowFlags()); ~SARibbonCustomizeDialog(); - // 设置action管理器 - void setupActionsManager(SARibbonActionsManager* mgr); + // 设置action管理器 + void setupActionsManager(SARibbonActionsManager* mgr); - // 判断用户是否有要存储的内容,对应save动作 + // 判断用户是否有要存储的内容,对应save动作 bool isApplied() const; - // 判断用户是否有改动内容,对应apply动作 + // 判断用户是否有改动内容,对应apply动作 bool isCached() const; - // 应用所有的设定 + // 应用所有的设定 bool applys(); - // 清除所有动作 + // 清除所有动作 void clear(); - // 转换为xml - bool toXml(QXmlStreamWriter* xml) const; + // 转换为xml + bool toXml(QXmlStreamWriter* xml) const; bool toXml(const QString& xmlpath) const; - // 从xml中加载QList,对于基于配置文件的设置,对话框显示前建议调用此函数,保证叠加设置的正确记录 - void fromXml(QXmlStreamReader* xml); + // 从xml中加载QList,对于基于配置文件的设置,对话框显示前建议调用此函数,保证叠加设置的正确记录 + void fromXml(QXmlStreamReader* xml); void fromXml(const QString& xmlpath); - // 返回SARibbonCustomizeWidget窗口指针 - SARibbonCustomizeWidget* customizeWidget() const; + // 返回SARibbonCustomizeWidget窗口指针 + SARibbonCustomizeWidget* customizeWidget() const; private: void initConnection(); - SARibbonCustomizeDialogUi* ui; + SARibbonCustomizeDialogUi* ui; }; #endif // SARIBBONCUSTOMIZEDIALOG_H