From d14e766b58465a59ea12387ab39aff5a656671b2 Mon Sep 17 00:00:00 2001 From: czyt1988 Date: Thu, 23 May 2024 16:47:13 +0800 Subject: [PATCH] =?UTF-8?q?v2.1.0-=E6=B7=BB=E5=8A=A0SARibbonWidget,?= =?UTF-8?q?=E8=B0=83=E6=95=B4=E4=BA=86=E4=B8=BB=E9=A2=98=E6=9E=9A=E4=B8=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加actionTriggered信号 - 修正了滚动action显示效果 - 把SARibbonTheme从SARibbonMainWindow中转移到SARibbonGloabls.h中并作为枚举类(enum class) - 添加SARibbonWidget,同时调整example/widget示例 - 调整了布局移动的实现方式,不会出现压缩式移动 --- CMakeLists.txt | 13 +- changlog.md | 7 +- src/SARibbon.cpp | 1267 ++++++++++------- src/SARibbon.h | 568 ++++---- src/SARibbonBar/SARibbonBar.pri | 6 +- src/SARibbonBar/SARibbonGlobal.h | 11 +- .../WidgetWithRibbon/WidgetWithRibbon.pro | 11 +- tools/amalgamate/SARibbonAmalgamTemplate.cpp | 2 +- .../SARibbonAmalgamTemplatePublicHeaders.h | 2 +- 9 files changed, 1059 insertions(+), 828 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 68940e7..e964fbb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -150,18 +150,7 @@ set(SARIBBON_DOC_FILES ${CMAKE_CURRENT_SOURCE_DIR}/readme-cn.md ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE ) -# 复制doc目录到install目录 -install(DIRECTORY - ${CMAKE_CURRENT_SOURCE_DIR}/doc - DESTINATION doc/SARibbon - COMPONENT document -) -# 把文档复制过去 -install(FILES - ${SARIBBON_DOC_FILES} - DESTINATION doc/SARibbon - COMPONENT document -) + # 把针对cmake安装的两个pri文件复制到根目录下 set(SARIBBON_QMAKE_FILES diff --git a/changlog.md b/changlog.md index 1722b3e..1e9c039 100644 --- a/changlog.md +++ b/changlog.md @@ -1,9 +1,12 @@ # 版本记录(change log): -## 2024-04-16 + +## 2024-05-23 -> 2.1.0 - 添加actionTriggered信号 - 修正了滚动action显示效果 - +- 把SARibbonTheme从SARibbonMainWindow中转移到SARibbonGloabls.h中并作为枚举类(enum class) +- 添加SARibbonWidget,同时调整example/widget示例 +- 调整了布局移动的实现方式,不会出现压缩式移动 ## 2024-02-07 -> 2.0.3 - 调整SAColorToolButton的实现,使之更简单 diff --git a/src/SARibbon.cpp b/src/SARibbon.cpp index 0f37a12..84fa24c 100644 --- a/src/SARibbon.cpp +++ b/src/SARibbon.cpp @@ -1,13 +1,12 @@ -//定义此宏,将SA_RIBBON_EXPORT定义为空 +// 定义此宏,将SA_RIBBON_EXPORT定义为空 #ifndef SA_RIBBON_BAR_NO_EXPORT #define SA_RIBBON_BAR_NO_EXPORT #endif -//定义此宏,将SA_COLOR_WIDGETS_API定义为空 +// 定义此宏,将SA_COLOR_WIDGETS_API定义为空 #ifndef SA_COLOR_WIDGETS_NO_DLL #define SA_COLOR_WIDGETS_NO_DLL #endif - /*** Start of inlined file: SARibbonAmalgamTemplateHeaderGlue.h ***/ // This file provides an extra level of indirection for the @remap in the template #include "SARibbon.h" @@ -16,15 +15,14 @@ // disable warnings about unsafe standard library calls #ifdef _MSC_VER -#pragma push_macro ("_CRT_SECURE_NO_WARNINGS") +#pragma push_macro("_CRT_SECURE_NO_WARNINGS") #ifndef _CRT_SECURE_NO_WARNINGS #define _CRT_SECURE_NO_WARNINGS #endif -#pragma warning (push) -#pragma warning (disable: 4996) // deprecated POSIX names +#pragma warning(push) +#pragma warning(disable : 4996) // deprecated POSIX names #endif - /*** Start of inlined file: SAColorMenu.cpp ***/ #include #include @@ -41,7 +39,7 @@ class SAColorMenu::PrivateData QColor getColorByDialog(); void recordCustomColor(const QColor& c); QWidgetAction* addWidget(QWidget* w); - //创建一个无颜色的icon + // 创建一个无颜色的icon QIcon createNoneColorIcon(QSize baseSize = QSize(32, 32)); public: @@ -55,7 +53,7 @@ class SAColorMenu::PrivateData QAction* mNoneColorAction { nullptr }; ///< 无颜色action QList< QColor > mCustomColors; int mMaxCustomColorSize { 10 }; ///< 记录最多的自定义颜色数量 - QScopedPointer< QColorDialog > mColorDlg { nullptr }; ///<颜色对话框 + QScopedPointer< QColorDialog > mColorDlg { nullptr }; ///< 颜色对话框 }; SAColorMenu::PrivateData::PrivateData(SAColorMenu* p) : q_ptr(p) @@ -78,7 +76,7 @@ void SAColorMenu::PrivateData::recordCustomColor(const QColor& c) if (mCustomColors.size() < mMaxCustomColorSize) { mCustomColors.push_back(c); } else { - //超过数量,就左移动 + // 超过数量,就左移动 for (int i = 1; i < mCustomColors.size(); ++i) { mCustomColors[ i - 1 ] = mCustomColors[ i ]; } @@ -112,7 +110,7 @@ SAColorMenu::SAColorMenu(QWidget* parent) : QMenu(parent), d_ptr(new SAColorMenu } SAColorMenu::SAColorMenu(const QString& title, QWidget* parent) - : QMenu(title, parent), d_ptr(new SAColorMenu::PrivateData(this)) + : QMenu(title, parent), d_ptr(new SAColorMenu::PrivateData(this)) { init(SA::getStandardColorList()); } @@ -189,11 +187,11 @@ SAColorGridWidget* SAColorMenu::customColorsWidget() const */ void SAColorMenu::enableNoneColorAction(bool on) { - //无颜色默认是在自定义颜色的上方 + // 无颜色默认是在自定义颜色的上方 if (on) { if (d_ptr->mNoneColorAction) { if (actions().contains(d_ptr->mNoneColorAction)) { - //已经包含了NoneColorAction,退出 + // 已经包含了NoneColorAction,退出 return; } else { insertAction(d_ptr->mCustomColorAction, d_ptr->mNoneColorAction); @@ -286,7 +284,6 @@ void SAColorMenu::onNoneColorActionTriggered(bool on) /*** End of inlined file: SAColorMenu.cpp ***/ - /*** Start of inlined file: SAColorGridWidget.cpp ***/ #include #include @@ -497,21 +494,21 @@ bool SAColorGridWidget::PrivateData::isSpacer(int r, int c) const SAColorGridWidget::SAColorGridWidget(QWidget* par) : QWidget(par), d_ptr(new SAColorGridWidget::PrivateData(this)) { connect(d_ptr->mButtonGroup, - QOverload< QAbstractButton* >::of(&QButtonGroup::buttonClicked), - this, - &SAColorGridWidget::onButtonClicked); + QOverload< QAbstractButton* >::of(&QButtonGroup::buttonClicked), + this, + &SAColorGridWidget::onButtonClicked); connect(d_ptr->mButtonGroup, - QOverload< QAbstractButton* >::of(&QButtonGroup::buttonPressed), - this, - &SAColorGridWidget::onButtonPressed); + QOverload< QAbstractButton* >::of(&QButtonGroup::buttonPressed), + this, + &SAColorGridWidget::onButtonPressed); connect(d_ptr->mButtonGroup, - QOverload< QAbstractButton* >::of(&QButtonGroup::buttonReleased), - this, - &SAColorGridWidget::onButtonReleased); + QOverload< QAbstractButton* >::of(&QButtonGroup::buttonReleased), + this, + &SAColorGridWidget::onButtonReleased); connect(d_ptr->mButtonGroup, - QOverload< QAbstractButton*, bool >::of(&QButtonGroup::buttonToggled), - this, - &SAColorGridWidget::onButtonToggled); + QOverload< QAbstractButton*, bool >::of(&QButtonGroup::buttonToggled), + this, + &SAColorGridWidget::onButtonToggled); } SAColorGridWidget::~SAColorGridWidget() @@ -778,22 +775,21 @@ namespace SA QList< QColor > getStandardColorList() { static QList< QColor > s_standardColorList({ QColor(192, 0, 0), - QColor(255, 0, 0), - QColor(255, 192, 0), - QColor(255, 255, 0), - QColor(146, 208, 80), - QColor(0, 176, 80), - QColor(0, 176, 240), - QColor(0, 112, 192), - QColor(0, 32, 96), - QColor(112, 48, 160) }); + QColor(255, 0, 0), + QColor(255, 192, 0), + QColor(255, 255, 0), + QColor(146, 208, 80), + QColor(0, 176, 80), + QColor(0, 176, 240), + QColor(0, 112, 192), + QColor(0, 32, 96), + QColor(112, 48, 160) }); return s_standardColorList; } } /*** End of inlined file: SAColorGridWidget.cpp ***/ - /*** Start of inlined file: SAColorPaletteGridWidget.cpp ***/ // Qt #include @@ -807,7 +803,7 @@ class SAColorPaletteGridWidget::PrivateData SA_COLOR_WIDGETS_DECLARE_PUBLIC(SAColorPaletteGridWidget) public: PrivateData(SAColorPaletteGridWidget* p); - //生成color palette + // 生成color palette QList< QColor > makeColorPalette(const QList< QColor >& clrList) const; public: @@ -864,7 +860,7 @@ SAColorPaletteGridWidget::SAColorPaletteGridWidget(QWidget* par) : QWidget(par), * @param par */ SAColorPaletteGridWidget::SAColorPaletteGridWidget(const QList< QColor >& cls, QWidget* par) - : QWidget(par), d_ptr(new PrivateData(this)) + : QWidget(par), d_ptr(new PrivateData(this)) { init(); setColorList(cls); @@ -968,7 +964,6 @@ void SAColorPaletteGridWidget::onPaletteColorClicked(const QColor& c) /*** End of inlined file: SAColorPaletteGridWidget.cpp ***/ - /*** Start of inlined file: SAColorToolButton.cpp ***/ #include #include @@ -1010,9 +1005,9 @@ SAColorToolButton::PrivateData::PrivateData(SAColorToolButton* p) : q_ptr(p) } void SAColorToolButton::PrivateData::calcSizeOfToolButtonIconOnly(const QStyleOptionToolButton& opt, - QRect& iconRect, - QRect& textRect, - QRect& colorRect) + QRect& iconRect, + QRect& textRect, + QRect& colorRect) { // 确定文本区域 textRect = QRect(); @@ -1053,9 +1048,9 @@ void SAColorToolButton::PrivateData::calcSizeOfToolButtonIconOnly(const QStyleOp * @param colorRect 左边有5像素显示颜色 */ void SAColorToolButton::PrivateData::calcSizeOfToolButtonTextOnly(const QStyleOptionToolButton& opt, - QRect& iconRect, - QRect& textRect, - QRect& colorRect) + QRect& iconRect, + QRect& textRect, + QRect& colorRect) { QRect buttonRect = getButtonRect(opt); iconRect = QRect(); @@ -1065,16 +1060,16 @@ void SAColorToolButton::PrivateData::calcSizeOfToolButtonTextOnly(const QStyleOp } colorSize = buttonRect.size().boundedTo(colorSize); colorRect = QRect(buttonRect.left(), - buttonRect.top() + (buttonRect.height() - colorSize.height()) / 2, - colorSize.width(), - colorSize.height()); + buttonRect.top() + (buttonRect.height() - colorSize.height()) / 2, + colorSize.width(), + colorSize.height()); textRect = buttonRect.adjusted(colorRect.right() + mSpacing, 0, 0, 0); } void SAColorToolButton::PrivateData::calcSizeOfToolButtonTextBesideIcon(const QStyleOptionToolButton& opt, - QRect& iconRect, - QRect& textRect, - QRect& colorRect) + QRect& iconRect, + QRect& textRect, + QRect& colorRect) { QRect buttonRect = getButtonRect(opt); if (opt.icon.isNull()) { @@ -1088,9 +1083,9 @@ void SAColorToolButton::PrivateData::calcSizeOfToolButtonTextBesideIcon(const QS colorSize = buttonRect.size().boundedTo(colorSize); iconRect = QRect(); colorRect = QRect(buttonRect.left(), - buttonRect.top() + (buttonRect.height() - colorSize.height()) / 2, - colorSize.width(), - colorSize.height()); + buttonRect.top() + (buttonRect.height() - colorSize.height()) / 2, + colorSize.width(), + colorSize.height()); textRect = buttonRect.adjusted(colorRect.width() + mSpacing, 0, 0, 0); } else { // 有图标 QSize tmpSize = opt.iconSize; @@ -1115,9 +1110,9 @@ void SAColorToolButton::PrivateData::calcSizeOfToolButtonTextBesideIcon(const QS } void SAColorToolButton::PrivateData::calcSizeOfToolButtonTextUnderIcon(const QStyleOptionToolButton& opt, - QRect& iconRect, - QRect& textRect, - QRect& colorRect) + QRect& iconRect, + QRect& textRect, + QRect& colorRect) { QRect buttonRect = getButtonRect(opt); QSize tmpSize = opt.iconSize; @@ -1132,15 +1127,15 @@ void SAColorToolButton::PrivateData::calcSizeOfToolButtonTextUnderIcon(const QSt if (totalHeight < buttonRect.height()) { // 足够高 colorRect = QRect(buttonRect.left() + (buttonRect.width() - tmpSize.width()) / 2, - buttonRect.top() + (buttonRect.height() - totalHeight) / 2, - tmpSize.width(), - opt.iconSize.height()); + buttonRect.top() + (buttonRect.height() - totalHeight) / 2, + tmpSize.width(), + opt.iconSize.height()); } else { // 空间不足 colorRect = QRect(buttonRect.left() + (buttonRect.width() - tmpSize.width()) / 2, - buttonRect.top() + mSpacing, - tmpSize.width(), - opt.iconSize.height()); + buttonRect.top() + mSpacing, + tmpSize.width(), + opt.iconSize.height()); } iconRect = QRect(); textRect = QRect(buttonRect.left(), colorRect.bottom() + mSpacing, buttonRect.width(), textHeight); @@ -1153,16 +1148,16 @@ void SAColorToolButton::PrivateData::calcSizeOfToolButtonTextUnderIcon(const QSt // 高度空间足够 // 先布置icon iconRect = QRect(buttonRect.left() + (buttonRect.width() - tmpSize.width()) / 2, - buttonRect.top() + (buttonRect.height() - totalHeight) / 2, - tmpSize.width(), - opt.iconSize.height()); + buttonRect.top() + (buttonRect.height() - totalHeight) / 2, + tmpSize.width(), + opt.iconSize.height()); } else { // 空间不足 iconRect = QRect(buttonRect.left() + (buttonRect.width() - tmpSize.width()) / 2, - buttonRect.top() + mSpacing, - tmpSize.width(), - opt.iconSize.height()); + buttonRect.top() + mSpacing, + tmpSize.width(), + opt.iconSize.height()); } colorRect = QRect(iconRect.x(), iconRect.bottom() + mSpacing, iconRect.width(), colorHeight); textRect = QRect(buttonRect.left(), colorRect.bottom() + mSpacing, buttonRect.width(), textHeight); @@ -1273,7 +1268,7 @@ SAColorToolButton::SAColorToolButton(QWidget* parent) : QToolButton(parent), d_p } SAColorToolButton::SAColorToolButton(ColorToolButtonStyle style, QWidget* parent) - : QToolButton(parent), d_ptr(new PrivateData(this)) + : QToolButton(parent), d_ptr(new PrivateData(this)) { setColorToolButtonStyle(style); connect(this, &QToolButton::clicked, this, &SAColorToolButton::onButtonClicked); @@ -1568,12 +1563,12 @@ void SAColorToolButton::paintText(QStylePainter* p, const QRect& textRect, const } alignment |= Qt::AlignHCenter | Qt::AlignVCenter; style()->drawItemText(p, - QStyle::visualRect(opt.direction, opt.rect, textRect), - alignment, - opt.palette, - opt.state & QStyle::State_Enabled, - opt.text, - QPalette::ButtonText); + QStyle::visualRect(opt.direction, opt.rect, textRect), + alignment, + opt.palette, + opt.state & QStyle::State_Enabled, + opt.text, + QPalette::ButtonText); p->restore(); } @@ -1584,9 +1579,9 @@ void SAColorToolButton::paintText(QStylePainter* p, const QRect& textRect, const * @param opt */ void SAColorToolButton::paintColor(QStylePainter* p, - const QRect& colorRect, - const QColor& color, - const QStyleOptionToolButton& opt) + const QRect& colorRect, + const QColor& color, + const QStyleOptionToolButton& opt) { Q_UNUSED(opt); if (colorRect.isNull()) { @@ -1602,7 +1597,7 @@ void SAColorToolButton::paintColor(QStylePainter* p, /*** End of inlined file: SAColorToolButton.cpp ***/ -//sa ribbon +// sa ribbon /*** Start of inlined file: SAFramelessHelper.cpp ***/ #include @@ -1955,7 +1950,7 @@ bool SAPrivateFramelessWidgetData::handleMousePressEvent(QMouseEvent* event) m_bLeftButtonTitlePressed = event->pos().y() < m_moveMousePos.m_nTitleHeight; QRect frameRect = m_pWidget->frameGeometry(); - auto gp = SA_MOUSEEVENT_GLOBALPOS_POINT(event); + auto gp = SA_MOUSEEVENT_GLOBALPOS_POINT(event); m_pressedMousePos.recalculate(gp, frameRect); m_ptDragPos = gp - frameRect.topLeft(); @@ -2223,8 +2218,6 @@ uint SAFramelessHelper::titleHeight() /*** End of inlined file: SAFramelessHelper.cpp ***/ - - /*** Start of inlined file: SARibbonApplicationButton.cpp ***/ SARibbonApplicationButton::SARibbonApplicationButton(QWidget* parent) : QToolButton(parent) { @@ -2244,7 +2237,7 @@ SARibbonApplicationButton::SARibbonApplicationButton(const QString& text, QWidge } SARibbonApplicationButton::SARibbonApplicationButton(const QIcon& icon, const QString& text, QWidget* parent) - : QToolButton(parent) + : QToolButton(parent) { setFocusPolicy(Qt::NoFocus); setAutoRaise(true); @@ -2256,7 +2249,6 @@ SARibbonApplicationButton::SARibbonApplicationButton(const QIcon& icon, const QS /*** End of inlined file: SARibbonApplicationButton.cpp ***/ - /*** Start of inlined file: SARibbonSystemButtonBar.cpp ***/ #include #include @@ -2445,7 +2437,7 @@ SARibbonSystemToolButton::SARibbonSystemToolButton(QWidget* p) : QToolButton(p) // SARibbonSystemButtonBar //=================================================== SARibbonSystemButtonBar::SARibbonSystemButtonBar(QWidget* parent) - : QFrame(parent), d_ptr(new SARibbonSystemButtonBar::PrivateData(this)) + : QFrame(parent), d_ptr(new SARibbonSystemButtonBar::PrivateData(this)) { updateWindowFlag(); } @@ -2456,7 +2448,7 @@ SARibbonSystemButtonBar::SARibbonSystemButtonBar(QWidget* parent) * @param flags */ SARibbonSystemButtonBar::SARibbonSystemButtonBar(QWidget* parent, Qt::WindowFlags flags) - : QFrame(parent), d_ptr(new SARibbonSystemButtonBar::PrivateData(this)) + : QFrame(parent), d_ptr(new SARibbonSystemButtonBar::PrivateData(this)) { d_ptr->mFlags = flags; updateWindowFlag(); @@ -2627,9 +2619,9 @@ QAction* SARibbonSystemButtonBar::addAction(QAction* a, Qt::ToolButtonStyle butt } QAction* SARibbonSystemButtonBar::addAction(const QString& text, - const QIcon& icon, - Qt::ToolButtonStyle buttonStyle, - QToolButton::ToolButtonPopupMode popMode) + const QIcon& icon, + Qt::ToolButtonStyle buttonStyle, + QToolButton::ToolButtonPopupMode popMode) { return d_ptr->mButtonGroup->addAction(text, icon, buttonStyle, popMode); } @@ -2684,7 +2676,6 @@ void SARibbonSystemButtonBar::maximizeWindow() /*** End of inlined file: SARibbonSystemButtonBar.cpp ***/ - /*** Start of inlined file: SARibbonToolButton.cpp ***/ #include #include @@ -2754,19 +2745,19 @@ namespace SA QDebug operator<<(QDebug debug, const QStyleOptionToolButton& opt) { debug << "==============" - << "\nQStyleOption(" << (QStyleOption)opt << ")" - << "\n QStyleOptionComplex:" - "\n subControls(" - << opt.subControls - << " ) " - "\n activeSubControls(" - << opt.activeSubControls - << "\n QStyleOptionToolButton" - "\n features(" - << opt.features - << ")" - "\n toolButtonStyle(" - << opt.toolButtonStyle << ")"; + << "\nQStyleOption(" << (QStyleOption)opt << ")" + << "\n QStyleOptionComplex:" + "\n subControls(" + << opt.subControls + << " ) " + "\n activeSubControls(" + << opt.activeSubControls + << "\n QStyleOptionToolButton" + "\n features(" + << opt.features + << ")" + "\n toolButtonStyle(" + << opt.toolButtonStyle << ")"; return (debug); } @@ -2779,19 +2770,19 @@ QDebug operator<<(QDebug debug, const QStyleOptionToolButton& opt) class SARibbonToolButtonProxyStyle : public QProxyStyle { public: - void drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *widget = nullptr) const override + void drawPrimitive(PrimitiveElement pe, const QStyleOption* opt, QPainter* p, const QWidget* widget = nullptr) const override { - if(pe == PE_IndicatorArrowUp || pe == PE_IndicatorArrowDown || pe == PE_IndicatorArrowRight || pe == PE_IndicatorArrowLeft) - { + if (pe == PE_IndicatorArrowUp || pe == PE_IndicatorArrowDown || pe == PE_IndicatorArrowRight + || pe == PE_IndicatorArrowLeft) { if (opt->rect.width() <= 1 || opt->rect.height() <= 1) return; - QRect r = opt->rect; + QRect r = opt->rect; int size = qMin(r.height(), r.width()); QPixmap pixmap; qreal pixelRatio = p->device()->devicePixelRatio(); - int border = qRound(pixelRatio*(size/4)); - int sqsize = qRound(pixelRatio*(2*(size/2))); + int border = qRound(pixelRatio * (size / 4)); + int sqsize = qRound(pixelRatio * (2 * (size / 2))); QImage image(sqsize, sqsize, QImage::Format_ARGB32_Premultiplied); image.fill(Qt::transparent); QPainter imagePainter(&image); @@ -2799,16 +2790,16 @@ class SARibbonToolButtonProxyStyle : public QProxyStyle QPolygon a; switch (pe) { case PE_IndicatorArrowUp: - a.setPoints(3, border, sqsize/2, sqsize/2, border, sqsize - border, sqsize/2); + a.setPoints(3, border, sqsize / 2, sqsize / 2, border, sqsize - border, sqsize / 2); break; case PE_IndicatorArrowDown: - a.setPoints(3, border, sqsize/2, sqsize/2, sqsize - border, sqsize - border, sqsize/2); + a.setPoints(3, border, sqsize / 2, sqsize / 2, sqsize - border, sqsize - border, sqsize / 2); break; case PE_IndicatorArrowRight: - a.setPoints(3, sqsize - border, sqsize/2, sqsize/2, border, sqsize/2, sqsize - border); + a.setPoints(3, sqsize - border, sqsize / 2, sqsize / 2, border, sqsize / 2, sqsize - border); break; case PE_IndicatorArrowLeft: - a.setPoints(3, border, sqsize/2, sqsize/2, border, sqsize/2, sqsize - border); + a.setPoints(3, border, sqsize / 2, sqsize / 2, border, sqsize / 2, sqsize - border); break; default: break; @@ -2823,8 +2814,8 @@ class SARibbonToolButtonProxyStyle : public QProxyStyle } QRect bounds = a.boundingRect(); - int sx = sqsize / 2 - bounds.center().x() - 1; - int sy = sqsize / 2 - bounds.center().y() - 1; + int sx = sqsize / 2 - bounds.center().x() - 1; + int sy = sqsize / 2 - bounds.center().y() - 1; imagePainter.translate(sx + bsx, sy + bsy); imagePainter.setPen(QPen(opt->palette.buttonText().color(), 1.4)); imagePainter.setBrush(Qt::NoBrush); @@ -2842,12 +2833,10 @@ class SARibbonToolButtonProxyStyle : public QProxyStyle pixmap = QPixmap::fromImage(image); pixmap.setDevicePixelRatio(pixelRatio); - int xOffset = r.x() + (r.width() - size)/2; - int yOffset = r.y() + (r.height() - size)/2; + int xOffset = r.x() + (r.width() - size) / 2; + int yOffset = r.y() + (r.height() - size) / 2; p->drawPixmap(xOffset, yOffset, pixmap); - } - else - { + } else { QProxyStyle::drawPrimitive(pe, opt, p, widget); } } @@ -2870,25 +2859,25 @@ class SARibbonToolButton::PrivateData void updateSizeHint(const QStyleOptionToolButton& opt); // 计算涉及到的rect尺寸 void calcDrawRects(const QStyleOptionToolButton& opt, - QRect& iconRect, - QRect& textRect, - QRect& indicatorArrowRect, - int spacing, - int indicatorLen) const; + QRect& iconRect, + QRect& textRect, + QRect& indicatorArrowRect, + int spacing, + int indicatorLen) const; // 计算小按钮模式下的尺寸 void calcSmallButtonDrawRects(const QStyleOptionToolButton& opt, - QRect& iconRect, - QRect& textRect, - QRect& indicatorArrowRect, - int spacing, - int indicatorLen) const; + QRect& iconRect, + QRect& textRect, + QRect& indicatorArrowRect, + int spacing, + int indicatorLen) const; // 计算大按钮模式下的尺寸 void calcLargeButtonDrawRects(const QStyleOptionToolButton& opt, - QRect& iconRect, - QRect& textRect, - QRect& indicatorArrowRect, - int spacing, - int indicatorLen) const; + QRect& iconRect, + QRect& textRect, + QRect& indicatorArrowRect, + int spacing, + int indicatorLen) const; // 根据按钮的尺寸调节iconsize(注意这里的buttonRect是已经减去mSpacing的情况) QSize adjustIconSize(const QRect& buttonRect, const QSize& originIconSize) const; // 判断是否有Indicator @@ -2902,11 +2891,11 @@ class SARibbonToolButton::PrivateData int calcTextDrawRectHeight(const QStyleOptionToolButton& opt) const; // 估算一个最优的文本宽度 int estimateLargeButtonTextWidth(int buttonHeight, - int textDrawRectHeight, - const QString& text, - const QFontMetrics& fm, - float widthHeightRatio = SARIBBONTOOLBUTTON_WORDWRAP_WIDTH_PER_HEIGHT_RATIO, - int maxTrycount = 3); + int textDrawRectHeight, + const QString& text, + const QFontMetrics& fm, + float widthHeightRatio = SARIBBONTOOLBUTTON_WORDWRAP_WIDTH_PER_HEIGHT_RATIO, + int maxTrycount = 3); QPixmap createIconPixmap(const QStyleOptionToolButton& opt, const QSize& iconsize) const; // 获取文字的对其方式 int getTextAlignment() const; @@ -2937,7 +2926,7 @@ bool SARibbonToolButton::PrivateData::s_enableWordWrap = false; SARibbonToolButton::PrivateData::PrivateData(SARibbonToolButton* p) : q_ptr(p) { auto proxy = new SARibbonToolButtonProxyStyle(); - proxy->setParent(p); // take ownership to avoid memleak + proxy->setParent(p); // take ownership to avoid memleak p->setStyle(proxy); } @@ -3013,11 +3002,11 @@ void SARibbonToolButton::PrivateData::updateSizeHint(const QStyleOptionToolButto * @param indicatorLen */ void SARibbonToolButton::PrivateData::calcDrawRects(const QStyleOptionToolButton& opt, - QRect& iconRect, - QRect& textRect, - QRect& indicatorArrowRect, - int spacing, - int indicatorLen) const + QRect& iconRect, + QRect& textRect, + QRect& indicatorArrowRect, + int spacing, + int indicatorLen) const { if (SARibbonToolButton::LargeButton == mButtonType) { calcLargeButtonDrawRects(opt, iconRect, textRect, indicatorArrowRect, spacing, indicatorLen); @@ -3037,11 +3026,11 @@ void SARibbonToolButton::PrivateData::calcDrawRects(const QStyleOptionToolButton * @param indicatorLen */ void SARibbonToolButton::PrivateData::calcSmallButtonDrawRects(const QStyleOptionToolButton& opt, - QRect& iconRect, - QRect& textRect, - QRect& indicatorArrowRect, - int spacing, - int indicatorLen) const + QRect& iconRect, + QRect& textRect, + QRect& indicatorArrowRect, + int spacing, + int indicatorLen) const { switch (opt.toolButtonStyle) { case Qt::ToolButtonIconOnly: { @@ -3049,9 +3038,9 @@ void SARibbonToolButton::PrivateData::calcSmallButtonDrawRects(const QStyleOptio // 在仅有图标的小模式显示时,预留一个下拉箭头位置 iconRect = opt.rect.adjusted(spacing, spacing, -indicatorLen - spacing, -spacing); indicatorArrowRect = QRect(opt.rect.right() - indicatorLen - spacing, - iconRect.y(), - indicatorLen, - iconRect.height()); + iconRect.y(), + indicatorLen, + iconRect.height()); } else { iconRect = opt.rect.adjusted(spacing, spacing, -spacing, -spacing); indicatorArrowRect = QRect(); @@ -3090,7 +3079,7 @@ void SARibbonToolButton::PrivateData::calcSmallButtonDrawRects(const QStyleOptio } else { // 分有菜单和没菜单两种情况 int adjx = iconRect.isValid() ? (iconRect.width() + spacing) - : 0; // 在buttonRect上变换,因此如果没有图标是不用偏移spacing + : 0; // 在buttonRect上变换,因此如果没有图标是不用偏移spacing if (hasInd) { textRect = buttonRect.adjusted(adjx, 0, -indicatorLen, 0); } else { @@ -3101,14 +3090,14 @@ void SARibbonToolButton::PrivateData::calcSmallButtonDrawRects(const QStyleOptio if (hasInd) { if (textRect.isValid()) { indicatorArrowRect = QRect(buttonRect.right() - indicatorLen + 1, - textRect.y(), - indicatorLen, - textRect.height()); + textRect.y(), + indicatorLen, + textRect.height()); } else if (iconRect.isValid()) { indicatorArrowRect = QRect(buttonRect.right() - indicatorLen + 1, - iconRect.y(), - indicatorLen, - iconRect.height()); + iconRect.y(), + indicatorLen, + iconRect.height()); } else { indicatorArrowRect = buttonRect; } @@ -3129,11 +3118,11 @@ void SARibbonToolButton::PrivateData::calcSmallButtonDrawRects(const QStyleOptio * @param indicatorLen */ void SARibbonToolButton::PrivateData::calcLargeButtonDrawRects(const QStyleOptionToolButton& opt, - QRect& iconRect, - QRect& textRect, - QRect& indicatorArrowRect, - int spacing, - int indicatorLen) const + QRect& iconRect, + QRect& textRect, + QRect& indicatorArrowRect, + int spacing, + int indicatorLen) const { //! 3行模式的图标比较大,文字换行情况下,indicator会动态调整 // 先获取文字矩形的高度 @@ -3151,9 +3140,9 @@ void SARibbonToolButton::PrivateData::calcLargeButtonDrawRects(const QStyleOptio if (isTextNeedWrap()) { // 如果文字的确换行,indicator放在最右边 textRect = QRect(spacing, - opt.rect.bottom() - spacing - textHeight, - opt.rect.width() - 2 * spacing - indicatorLen, - textHeight); + 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); } @@ -3291,12 +3280,12 @@ QSize SARibbonToolButton::PrivateData::calcLargeButtonSizeHint(const QStyleOptio #if SA_RIBBON_TOOLBUTTON_DEBUG_PRINT && SA_DEBUG_PRINT_SIZE_HINT qDebug() << "| | |-SARibbonToolButton::PrivateData::calcLargeButtonSizeHint,text=" << opt.text - << "\n| | | |-lineSpacing*4.5=" << opt.fontMetrics.lineSpacing() * 4.5 // - << "\n| | | |-textHeight=" << textHeight // - << "\n| | | |-mDrawIconRect=" << mDrawIconRect // - << "\n| | | |-minW=" << minW // - << "\n| | | |-w=" << w // - ; + << "\n| | | |-lineSpacing*4.5=" << opt.fontMetrics.lineSpacing() * 4.5 // + << "\n| | | |-textHeight=" << textHeight // + << "\n| | | |-mDrawIconRect=" << mDrawIconRect // + << "\n| | | |-minW=" << minW // + << "\n| | | |-w=" << w // + ; #endif //! Qt6.4 取消了QApplication::globalStrut return QSize(w, h).expandedTo(QSize(minW, textHeight)); @@ -3330,11 +3319,11 @@ int SARibbonToolButton::PrivateData::calcTextDrawRectHeight(const QStyleOptionTo * @return */ int SARibbonToolButton::PrivateData::estimateLargeButtonTextWidth(int buttonHeight, - int textDrawRectHeight, - const QString& text, - const QFontMetrics& fm, - float widthHeightRatio, - int maxTrycount) + int textDrawRectHeight, + const QString& text, + const QFontMetrics& fm, + float widthHeightRatio, + int maxTrycount) { QSize textSize; int space = SA_FONTMETRICS_WIDTH(fm, (QLatin1Char(' '))) * 2; @@ -3379,7 +3368,7 @@ int SARibbonToolButton::PrivateData::estimateLargeButtonTextWidth(int buttonHeig #if SARIBBONTOOLBUTTON_DEBUG_DRAW if (trycount > 1) { qDebug() << "estimateLargeButtonTextWidth,origin textSize=" << textSize << ",trycount=" << trycount - << ",textRect=" << textRect; + << ",textRect=" << textRect; } #endif } while (trycount < 3); @@ -3463,7 +3452,7 @@ QString SARibbonToolButton::PrivateData::simplified(const QString& str) //=================================================== SARibbonToolButton::SARibbonToolButton(QWidget* parent) - : QToolButton(parent), d_ptr(new SARibbonToolButton::PrivateData(this)) + : QToolButton(parent), d_ptr(new SARibbonToolButton::PrivateData(this)) { setAutoRaise(true); setToolButtonStyle(Qt::ToolButtonTextBesideIcon); @@ -3472,7 +3461,7 @@ SARibbonToolButton::SARibbonToolButton(QWidget* parent) } SARibbonToolButton::SARibbonToolButton(QAction* defaultAction, QWidget* parent) - : QToolButton(parent), d_ptr(new SARibbonToolButton::PrivateData(this)) + : QToolButton(parent), d_ptr(new SARibbonToolButton::PrivateData(this)) { setAutoRaise(true); setToolButtonStyle(Qt::ToolButtonTextBesideIcon); @@ -3760,10 +3749,10 @@ void SARibbonToolButton::paintIndicator(QPainter& p, const QStyleOptionToolButto } void SARibbonToolButton::drawArrow(const QStyle* style, - const QStyleOptionToolButton* toolbutton, - const QRect& rect, - QPainter* painter, - const QWidget* widget) + const QStyleOptionToolButton* toolbutton, + const QRect& rect, + QPainter* painter, + const QWidget* widget) { QStyle::PrimitiveElement pe; @@ -3918,7 +3907,6 @@ void SARibbonToolButton::changeEvent(QEvent* e) /*** End of inlined file: SARibbonToolButton.cpp ***/ - /*** Start of inlined file: SARibbonColorToolButton.cpp ***/ #include #include @@ -3968,7 +3956,8 @@ QPixmap SARibbonColorToolButton::PrivateData::createIconPixmap(const QStyleOptio res.fill(Qt::transparent); QPainter painter(&res); int xpixmap = (res.width() - pixmap.width()) / 2; - int ypixmap = (res.height() - c_ribbonbutton_color_height - 2 - pixmap.height()) / 2; // 这里要减去2而不是1,这样奇数偶数都不会影响 + int ypixmap = (res.height() - c_ribbonbutton_color_height - 2 - pixmap.height()) + / 2; // 这里要减去2而不是1,这样奇数偶数都不会影响 int w = pixmap.width(); int h = pixmap.height(); QRect rpixmap = QRect(xpixmap, ypixmap, w, h); @@ -4015,13 +4004,13 @@ QIcon SARibbonColorToolButton::PrivateData::createColorIcon(const QColor& c, con //=================================================== SARibbonColorToolButton::SARibbonColorToolButton(QWidget* parent) - : SARibbonToolButton(parent), d_ptr(new SARibbonColorToolButton::PrivateData(this)) + : SARibbonToolButton(parent), d_ptr(new SARibbonColorToolButton::PrivateData(this)) { connect(this, &QAbstractButton::clicked, this, &SARibbonColorToolButton::onButtonClicked); } SARibbonColorToolButton::SARibbonColorToolButton(QAction* defaultAction, QWidget* parent) - : SARibbonToolButton(defaultAction, parent), d_ptr(new SARibbonColorToolButton::PrivateData(this)) + : SARibbonToolButton(defaultAction, parent), d_ptr(new SARibbonColorToolButton::PrivateData(this)) { connect(this, &QAbstractButton::clicked, this, &SARibbonColorToolButton::onButtonClicked); } @@ -4130,16 +4119,14 @@ void SARibbonColorToolButton::paintIcon(QPainter& p, const QStyleOptionToolButto /*** End of inlined file: SARibbonColorToolButton.cpp ***/ - /*** Start of inlined file: SARibbonLineWidgetContainer.cpp ***/ #include -SARibbonLineWidgetContainer::SARibbonLineWidgetContainer(QWidget *par) : QWidget(par) - , m_innerWidget(nullptr) +SARibbonLineWidgetContainer::SARibbonLineWidgetContainer(QWidget* par) : QWidget(par), m_innerWidget(nullptr) { - m_labelPrefix = new QLabel(this); - m_labelSuffix = new QLabel(this); - QHBoxLayout *lay = new QHBoxLayout(); + m_labelPrefix = new QLabel(this); + m_labelSuffix = new QLabel(this); + QHBoxLayout* lay = new QHBoxLayout(); lay->setContentsMargins(0, 0, 0, 0); lay->setSpacing(0); @@ -4148,13 +4135,13 @@ SARibbonLineWidgetContainer::SARibbonLineWidgetContainer(QWidget *par) : QWidget setLayout(lay); } -void SARibbonLineWidgetContainer::setWidget(QWidget *innerWidget) +void SARibbonLineWidgetContainer::setWidget(QWidget* innerWidget) { - QHBoxLayout *lay = static_cast(layout()); + QHBoxLayout* lay = static_cast< QHBoxLayout* >(layout()); if (m_innerWidget) { lay->replaceWidget(m_innerWidget, innerWidget); - }else{ + } else { lay->insertWidget(1, innerWidget); } m_innerWidget = innerWidget; @@ -4170,19 +4157,18 @@ void SARibbonLineWidgetContainer::setSuffix(const QString& str) m_labelSuffix->setText(str); } -QLabel *SARibbonLineWidgetContainer::labelPrefix() const +QLabel* SARibbonLineWidgetContainer::labelPrefix() const { return (m_labelPrefix); } -QLabel *SARibbonLineWidgetContainer::labelSuffix() const +QLabel* SARibbonLineWidgetContainer::labelSuffix() const { return (m_labelSuffix); } /*** End of inlined file: SARibbonLineWidgetContainer.cpp ***/ - /*** Start of inlined file: SARibbonActionsManager.cpp ***/ #include #include @@ -4218,7 +4204,7 @@ void SARibbonActionsManager::PrivateData::clear() } SARibbonActionsManager::SARibbonActionsManager(SARibbonBar* bar) - : QObject(bar), d_ptr(new SARibbonActionsManager::PrivateData(this)) + : QObject(bar), d_ptr(new SARibbonActionsManager::PrivateData(this)) { autoRegisteActions(bar); } @@ -4305,7 +4291,7 @@ bool SARibbonActionsManager::registeAction(QAction* act, int tag, const QString& } if (d_ptr->mKeyToAction.contains(k)) { qWarning() << "key: " - << k << " have been exist,you can set key in an unique value when use SARibbonActionsManager::registeAction"; + << k << " have been exist,you can set key in an unique value when use SARibbonActionsManager::registeAction"; return (false); } d_ptr->mKeyToAction[ k ] = act; @@ -4680,12 +4666,12 @@ bool SARibbonActionsManagerModel::PrivateData::isNull() const //=================================================== SARibbonActionsManagerModel::SARibbonActionsManagerModel(QObject* p) - : QAbstractListModel(p), d_ptr(new SARibbonActionsManagerModel::PrivateData(this)) + : QAbstractListModel(p), d_ptr(new SARibbonActionsManagerModel::PrivateData(this)) { } SARibbonActionsManagerModel::SARibbonActionsManagerModel(SARibbonActionsManager* m, QObject* p) - : QAbstractListModel(p), d_ptr(new SARibbonActionsManagerModel::PrivateData(this)) + : QAbstractListModel(p), d_ptr(new SARibbonActionsManagerModel::PrivateData(this)) { setupActionsManager(m); } @@ -4811,50 +4797,39 @@ void SARibbonActionsManagerModel::onActionTagChanged(int tag, bool isdelete) /*** End of inlined file: SARibbonActionsManager.cpp ***/ - /*** Start of inlined file: SARibbonLineEdit.cpp ***/ #include -SARibbonLineEdit::SARibbonLineEdit(QWidget *parent) - : QLineEdit(parent) +SARibbonLineEdit::SARibbonLineEdit(QWidget* parent) : QLineEdit(parent) { } -SARibbonLineEdit::SARibbonLineEdit(const QString &text, QWidget *parent) - : QLineEdit(text, parent) +SARibbonLineEdit::SARibbonLineEdit(const QString& text, QWidget* parent) : QLineEdit(text, parent) { - } /*** End of inlined file: SARibbonLineEdit.cpp ***/ - /*** Start of inlined file: SARibbonCheckBox.cpp ***/ #include -SARibbonCheckBox::SARibbonCheckBox(QWidget *parent) - : QCheckBox(parent) +SARibbonCheckBox::SARibbonCheckBox(QWidget* parent) : QCheckBox(parent) { } -SARibbonCheckBox::SARibbonCheckBox(const QString &text, QWidget *parent) - : QCheckBox(text, parent) +SARibbonCheckBox::SARibbonCheckBox(const QString& text, QWidget* parent) : QCheckBox(text, parent) { - } /*** End of inlined file: SARibbonCheckBox.cpp ***/ - /*** Start of inlined file: SARibbonComboBox.cpp ***/ -SARibbonComboBox::SARibbonComboBox(QWidget *parent) - : QComboBox(parent) +SARibbonComboBox::SARibbonComboBox(QWidget* parent) : QComboBox(parent) { } /*** End of inlined file: SARibbonComboBox.cpp ***/ - /*** Start of inlined file: SARibbonButtonGroupWidget.cpp ***/ #include #include @@ -4918,7 +4893,7 @@ void SARibbonButtonGroupWidget::PrivateData::removeAction(QAction* a) //=================================================== SARibbonButtonGroupWidget::SARibbonButtonGroupWidget(QWidget* parent) - : QFrame(parent), d_ptr(new SARibbonButtonGroupWidget::PrivateData(this)) + : QFrame(parent), d_ptr(new SARibbonButtonGroupWidget::PrivateData(this)) { d_ptr->init(); } @@ -4949,7 +4924,9 @@ QSize SARibbonButtonGroupWidget::iconSize() const return d_ptr->mIconSize; } -QAction* SARibbonButtonGroupWidget::addAction(QAction* a, Qt::ToolButtonStyle buttonStyle, QToolButton::ToolButtonPopupMode popMode) +QAction* SARibbonButtonGroupWidget::addAction(QAction* a, + Qt::ToolButtonStyle buttonStyle, + QToolButton::ToolButtonPopupMode popMode) { SARibbonPannel::setActionToolButtonStyleProperty(a, buttonStyle); SARibbonPannel::setActionToolButtonPopupModeProperty(a, popMode); @@ -4965,7 +4942,10 @@ QAction* SARibbonButtonGroupWidget::addAction(QAction* a, Qt::ToolButtonStyle bu * @param popMode * @return */ -QAction* SARibbonButtonGroupWidget::addAction(const QString& text, const QIcon& icon, Qt::ToolButtonStyle buttonStyle, QToolButton::ToolButtonPopupMode popMode) +QAction* SARibbonButtonGroupWidget::addAction(const QString& text, + const QIcon& icon, + Qt::ToolButtonStyle buttonStyle, + QToolButton::ToolButtonPopupMode popMode) { QAction* a = new QAction(icon, text, this); addAction(a, buttonStyle, popMode); @@ -5114,7 +5094,6 @@ void SARibbonButtonGroupWidget::actionEvent(QActionEvent* e) /*** End of inlined file: SARibbonButtonGroupWidget.cpp ***/ - /*** Start of inlined file: SARibbonStackedWidget.cpp ***/ #include #include @@ -5143,7 +5122,7 @@ class SARibbonStackedWidget::PrivateData }; SARibbonStackedWidget::SARibbonStackedWidget(QWidget* parent) - : QStackedWidget(parent), d_ptr(new SARibbonStackedWidget::PrivateData(this)) + : QStackedWidget(parent), d_ptr(new SARibbonStackedWidget::PrivateData(this)) { d_ptr->init(); setNormalMode(); @@ -5239,7 +5218,6 @@ void SARibbonStackedWidget::resizeEvent(QResizeEvent* e) /*** End of inlined file: SARibbonStackedWidget.cpp ***/ - /*** Start of inlined file: SARibbonSeparatorWidget.cpp ***/ #include #include @@ -5262,7 +5240,6 @@ QSize SARibbonSeparatorWidget::sizeHint() const /*** End of inlined file: SARibbonSeparatorWidget.cpp ***/ - /*** Start of inlined file: SARibbonCtrlContainer.cpp ***/ #include #include @@ -5339,7 +5316,7 @@ class SARibbonCtrlContainer::PrivateData // SARibbonCtrlContainer //=================================================== SARibbonCtrlContainer::SARibbonCtrlContainer(QWidget* parent) - : QWidget(parent), d_ptr(new SARibbonCtrlContainer::PrivateData(this)) + : QWidget(parent), d_ptr(new SARibbonCtrlContainer::PrivateData(this)) { } @@ -5435,7 +5412,6 @@ QWidget* SARibbonCtrlContainer::iconWidget() const /*** End of inlined file: SARibbonCtrlContainer.cpp ***/ - /*** Start of inlined file: SARibbonQuickAccessBar.cpp ***/ #include @@ -5460,7 +5436,7 @@ SARibbonQuickAccessBar::PrivateData::PrivateData(SARibbonQuickAccessBar* p) : q_ // SARibbonQuickAccessBar //=================================================== SARibbonQuickAccessBar::SARibbonQuickAccessBar(QWidget* parent) - : SARibbonCtrlContainer(parent), d_ptr(new SARibbonQuickAccessBar::PrivateData(this)) + : SARibbonCtrlContainer(parent), d_ptr(new SARibbonQuickAccessBar::PrivateData(this)) { d_ptr->groupWidget = new SARibbonButtonGroupWidget(this); d_ptr->groupWidget->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding)); @@ -5529,7 +5505,6 @@ QSize SARibbonQuickAccessBar::iconSize() const /*** End of inlined file: SARibbonQuickAccessBar.cpp ***/ - /*** Start of inlined file: SARibbonTabBar.cpp ***/ SARibbonTabBar::SARibbonTabBar(QWidget* parent) : QTabBar(parent), m_tabMargin(6, 0, 0, 0) { @@ -5548,7 +5523,6 @@ void SARibbonTabBar::setTabMargin(const QMargins& tabMargin) /*** End of inlined file: SARibbonTabBar.cpp ***/ - /*** Start of inlined file: SARibbonControlButton.cpp ***/ SARibbonControlButton::SARibbonControlButton(QWidget* parent) : QToolButton(parent) { @@ -5560,43 +5534,42 @@ SARibbonControlToolButton::SARibbonControlToolButton(QWidget* parent) : QToolBut /*** End of inlined file: SARibbonControlButton.cpp ***/ - /*** Start of inlined file: SARibbonMenu.cpp ***/ #include -SARibbonMenu::SARibbonMenu(QWidget *parent) : QMenu(parent) +SARibbonMenu::SARibbonMenu(QWidget* parent) : QMenu(parent) { setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); } -SARibbonMenu::SARibbonMenu(const QString& title, QWidget *parent) : QMenu(title, parent) +SARibbonMenu::SARibbonMenu(const QString& title, QWidget* parent) : QMenu(title, parent) { setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); } -QAction *SARibbonMenu::addRibbonMenu(SARibbonMenu *menu) +QAction* SARibbonMenu::addRibbonMenu(SARibbonMenu* menu) { return (QMenu::addMenu(menu)); } -SARibbonMenu *SARibbonMenu::addRibbonMenu(const QString& title) +SARibbonMenu* SARibbonMenu::addRibbonMenu(const QString& title) { - SARibbonMenu *menu = new SARibbonMenu(title, this); + SARibbonMenu* menu = new SARibbonMenu(title, this); return (menu); } -SARibbonMenu *SARibbonMenu::addRibbonMenu(const QIcon& icon, const QString& title) +SARibbonMenu* SARibbonMenu::addRibbonMenu(const QIcon& icon, const QString& title) { - SARibbonMenu *menu = new SARibbonMenu(title, this); + SARibbonMenu* menu = new SARibbonMenu(title, this); menu->setIcon(icon); return (menu); } -QAction *SARibbonMenu::addWidget(QWidget *w) +QAction* SARibbonMenu::addWidget(QWidget* w) { - QWidgetAction *action = new QWidgetAction(this); + QWidgetAction* action = new QWidgetAction(this); action->setDefaultWidget(w); addAction(action); @@ -5605,7 +5578,6 @@ QAction *SARibbonMenu::addWidget(QWidget *w) /*** End of inlined file: SARibbonMenu.cpp ***/ - /*** Start of inlined file: SARibbonPannelOptionButton.cpp ***/ #include @@ -5620,10 +5592,9 @@ SARibbonPannelOptionButton::SARibbonPannelOptionButton(QWidget* parent) : QToolB /*** End of inlined file: SARibbonPannelOptionButton.cpp ***/ - /*** Start of inlined file: SARibbonPannelItem.cpp ***/ SARibbonPannelItem::SARibbonPannelItem(QWidget* widget) - : QWidgetItem(widget), rowIndex(-1), columnIndex(-1), action(nullptr), customWidget(false), rowProportion(Large) + : QWidgetItem(widget), rowIndex(-1), columnIndex(-1), action(nullptr), customWidget(false), rowProportion(Large) { } @@ -5634,7 +5605,6 @@ bool SARibbonPannelItem::isEmpty() const /*** End of inlined file: SARibbonPannelItem.cpp ***/ - /*** Start of inlined file: SARibbonPannelLayout.cpp ***/ #include #include @@ -5652,7 +5622,7 @@ bool SARibbonPannelItem::isEmpty() const } while (0) SARibbonPannelLayout::SARibbonPannelLayout(QWidget* p) - : QLayout(p), m_columnCount(0), m_expandFlag(false), m_dirty(true) + : QLayout(p), m_columnCount(0), m_expandFlag(false), m_dirty(true) { setSpacing(1); SARibbonPannel* tb = qobject_cast< SARibbonPannel* >(p); @@ -6009,8 +5979,8 @@ SARibbonPannelItem* SARibbonPannelLayout::createItem(QAction* action, SARibbonPa // 不是widget,自动生成SARibbonToolbutton if (!widget) { SARibbonToolButton::RibbonButtonType buttonType = ((rp == SARibbonPannelItem::Large) - ? SARibbonToolButton::LargeButton - : SARibbonToolButton::SmallButton); + ? SARibbonToolButton::LargeButton + : SARibbonToolButton::SmallButton); SARibbonToolButton* button = RibbonSubElementFactory->createRibbonToolButton(pannel); button->setFocusPolicy(Qt::NoFocus); @@ -6068,7 +6038,7 @@ void SARibbonPannelLayout::updateGeomArray(const QRect& setrect) // Medium行的y位置 const int yMediumRow0 = (2 == rowCount) ? yBegin : (yBegin + ((largeHeight - 2 * smallHeight) / 3)); const int yMediumRow1 = (2 == rowCount) ? (yBegin + smallHeight + spacing) - : (yBegin + ((largeHeight - 2 * smallHeight) / 3) * 2 + smallHeight); + : (yBegin + ((largeHeight - 2 * smallHeight) / 3) * 2 + smallHeight); // Small行的y位置 const int ySmallRow0 = yBegin; const int ySmallRow1 = yBegin + smallHeight + spacing; @@ -6104,10 +6074,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(); @@ -6313,9 +6283,9 @@ void SARibbonPannelLayout::updateGeomArray(const QRect& setrect) if (isEnableShowPannelTitle()) { // 有标题 m_optionActionBtnGeometry.setRect(m_titleLabelGeometry.right() - m_titleLabelGeometry.height(), - m_titleLabelGeometry.y(), - m_titleLabelGeometry.height(), - m_titleLabelGeometry.height()); + m_titleLabelGeometry.y(), + m_titleLabelGeometry.height(), + m_titleLabelGeometry.height()); // 特殊情况,如果pannel的标题长度大于totalWidth,那么说明totalWidth比较短 // 这时候,optionActionBtn的宽度要加上到标题宽度上 @@ -6326,9 +6296,9 @@ void SARibbonPannelLayout::updateGeomArray(const QRect& setrect) } else { // 无标题 m_optionActionBtnGeometry.setRect(setrect.right() - optBtnSize.width() - mag.right(), - setrect.bottom() - optBtnSize.height() - mag.bottom(), - optBtnSize.width(), - optBtnSize.height()); + setrect.bottom() - optBtnSize.height() - mag.bottom(), + optBtnSize.width(), + optBtnSize.height()); totalWidth += optBtnSize.width(); } } @@ -6337,15 +6307,15 @@ void SARibbonPannelLayout::updateGeomArray(const QRect& setrect) this->m_sizeHint = QSize(totalWidth, heightHint); #if SARibbonPannelLayout_DEBUG_PRINT && SA_DEBUG_PRINT_SIZE_HINT qDebug() << "| |-SARibbonPannelLayout updateGeomArray(" << setrect << "),pannel name = " << pannel->pannelName() - << "\n| | |-size hint =" << this->m_sizeHint // - << "\n| | |-totalWidth=" << totalWidth // - << "\n| | |-last x=" << x // - << "\n| | |-columMaxWidth=" << columMaxWidth // - << "\n| | |-spacing=" << spacing // - << "\n| | |-mag=" << mag // - << "\n| | |-largeHeight=" << largeHeight // - << "\n| | |-smallHeight=" << smallHeight // - ; + << "\n| | |-size hint =" << this->m_sizeHint // + << "\n| | |-totalWidth=" << totalWidth // + << "\n| | |-last x=" << x // + << "\n| | |-columMaxWidth=" << columMaxWidth // + << "\n| | |-spacing=" << spacing // + << "\n| | |-mag=" << mag // + << "\n| | |-largeHeight=" << largeHeight // + << "\n| | |-smallHeight=" << smallHeight // + ; qDebug().noquote() << debug_print__log__; #endif } @@ -6434,9 +6404,9 @@ void SARibbonPannelLayout::recalcExpandGeomArray(const QRect& setrect) } #if SARibbonPannelLayout_DEBUG_PRINT && SA_DEBUG_PRINT_SIZE_HINT qDebug() << "| |-SARibbonPannelLayout recalcExpandGeomArray(" << setrect - << ") pannelName=" << ribbonPannel()->pannelName() // - << ",expandwidth=" << expandwidth // - ; + << ") pannelName=" << ribbonPannel()->pannelName() // + << ",expandwidth=" << expandwidth // + ; #endif } @@ -6575,7 +6545,6 @@ void SARibbonPannelLayout::setGeometry(const QRect& rect) /*** End of inlined file: SARibbonPannelLayout.cpp ***/ - /*** Start of inlined file: SARibbonPannel.cpp ***/ #include #include @@ -6724,7 +6693,7 @@ SARibbonPannel::SARibbonPannel(QWidget* parent) : QFrame(parent), d_ptr(new SARi } SARibbonPannel::SARibbonPannel(const QString& name, QWidget* parent) - : QFrame(parent), d_ptr(new SARibbonPannel::PrivateData(this)) + : QFrame(parent), d_ptr(new SARibbonPannel::PrivateData(this)) { setPannelLayoutMode(ThreeRowMode); setPannelName(name); @@ -6909,9 +6878,9 @@ void SARibbonPannel::addMediumAction(QAction* action, QToolButton::ToolButtonPop * @return 返回添加的action */ QAction* SARibbonPannel::addAction(const QString& text, - const QIcon& icon, - QToolButton::ToolButtonPopupMode popMode, - SARibbonPannelItem::RowProportion rp) + const QIcon& icon, + QToolButton::ToolButtonPopupMode popMode, + SARibbonPannelItem::RowProportion rp) { QAction* action = new QAction(icon, text, this); addAction(action, popMode, rp); @@ -7516,7 +7485,6 @@ const QList< SARibbonPannelItem* >& SARibbonPannel::ribbonPannelItem() const /*** End of inlined file: SARibbonPannel.cpp ***/ - /*** Start of inlined file: SARibbonCategory.cpp ***/ #include #include @@ -7626,6 +7594,8 @@ void SARibbonCategory::PrivateData::insertPannel(int index, SARibbonPannel* pann index = qMin(lay->pannelCount(), index); lay->insertPannel(index, pannel); pannel->setVisible(true); + + QObject::connect(pannel, &SARibbonPannel::actionTriggered, ribbonCategory(), &SARibbonCategory::actionTriggered); } bool SARibbonCategory::PrivateData::takePannel(SARibbonPannel* pannel) @@ -7735,7 +7705,7 @@ SARibbonCategory::SARibbonCategory(QWidget* p) : QFrame(p), d_ptr(new SARibbonCa } SARibbonCategory::SARibbonCategory(const QString& name, QWidget* p) - : QFrame(p), d_ptr(new SARibbonCategory::PrivateData(this)) + : QFrame(p), d_ptr(new SARibbonCategory::PrivateData(this)) { setCategoryName(name); d_ptr->init(this); @@ -8201,7 +8171,6 @@ SARibbonCategoryScrollButton::SARibbonCategoryScrollButton(Qt::ArrowType arr, QW /*** End of inlined file: SARibbonCategory.cpp ***/ - /*** Start of inlined file: SARibbonCategoryLayout.cpp ***/ #include @@ -8266,8 +8235,8 @@ int SARibbonCategoryLayout::PrivateData::totalSizeHintWidth() const #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()); + .arg(debug_i__) + .arg(item->toPannelWidget()->pannelName()); #endif continue; } @@ -8283,12 +8252,12 @@ int SARibbonCategoryLayout::PrivateData::totalSizeHintWidth() const #if SARibbonCategoryLayout_DEBUG_PRINT && SA_DEBUG_PRINT_SIZE_HINT ++debug_i__; debug_totalSizeHintWidth__ += QString("|-[%1]pannelSize=(%2,%3),SeparatorSize=(%4,%5),name=(%6) \n") - .arg(debug_i__) - .arg(pannelSize.width()) - .arg(pannelSize.height()) - .arg(SeparatorSize.width()) - .arg(SeparatorSize.height()) - .arg(item->toPannelWidget()->pannelName()); + .arg(debug_i__) + .arg(pannelSize.width()) + .arg(pannelSize.height()) + .arg(SeparatorSize.width()) + .arg(SeparatorSize.height()) + .arg(item->toPannelWidget()->pannelName()); #endif } #if SARibbonCategoryLayout_DEBUG_PRINT && SA_DEBUG_PRINT_SIZE_HINT @@ -8303,7 +8272,7 @@ int SARibbonCategoryLayout::PrivateData::totalSizeHintWidth() const //============================================================= SARibbonCategoryLayout::SARibbonCategoryLayout(SARibbonCategory* parent) - : QLayout(parent), d_ptr(new SARibbonCategoryLayout::PrivateData(this)) + : QLayout(parent), d_ptr(new SARibbonCategoryLayout::PrivateData(this)) { setContentsMargins(1, 1, 1, 1); d_ptr->mLeftScrollBtn = new SARibbonCategoryScrollButton(Qt::LeftArrow, parent); @@ -8512,12 +8481,12 @@ void SARibbonCategoryLayout::updateGeometryArr() // 判断是否超过总长度 #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 // - << "\n|-mag=" << mag; + << "\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) { // 超过总长度,需要显示滚动按钮 @@ -8610,7 +8579,7 @@ void SARibbonCategoryLayout::updateGeometryArr() d_ptr->mMinSizeHint = QSize(categoryWidth, height); #if SARibbonCategoryLayout_DEBUG_PRINT && SA_DEBUG_PRINT_SIZE_HINT qDebug() << "SARibbonCategoryLayout updateGeometryArr,SizeHint=" << d_ptr->mSizeHint - << ",Category name=" << category->categoryName(); + << ",Category name=" << category->categoryName(); #endif } @@ -8655,8 +8624,8 @@ void SARibbonCategoryLayout::doLayout() } #if SARibbonCategoryLayout_DEBUG_PRINT && SA_DEBUG_PRINT_SIZE_HINT qDebug() << "|-[" << debug_i__ << "]pannelName(" << item->toPannelWidget()->pannelName() - << "),willSetGeometry:" << item->mWillSetGeometry - << ",WillSetSeparatorGeometry:" << item->mWillSetSeparatorGeometry; + << "),willSetGeometry:" << item->mWillSetGeometry + << ",WillSetSeparatorGeometry:" << item->mWillSetSeparatorGeometry; ++debug_i__; #endif } @@ -8898,7 +8867,7 @@ void SARibbonCategoryLayout::setGeometry(const QRect& rect) } #if SARibbonCategoryLayout_DEBUG_PRINT && SA_DEBUG_PRINT_SIZE_HINT qDebug() << "===========SARibbonCategoryLayout.setGeometry(" << rect << "(" << ribbonCategory()->categoryName() - << ")======="; + << ")======="; #endif QLayout::setGeometry(rect); d_ptr->mDirty = false; @@ -8921,7 +8890,6 @@ SARibbonPannel* SARibbonCategoryLayoutItem::toPannelWidget() /*** End of inlined file: SARibbonCategoryLayout.cpp ***/ - /*** Start of inlined file: SARibbonContextCategory.cpp ***/ #include #include @@ -8960,7 +8928,7 @@ SARibbonContextCategory::PrivateData::PrivateData(SARibbonContextCategory* p) : // SARibbonContextCategory //=================================================== SARibbonContextCategory::SARibbonContextCategory(QWidget* parent) - : QObject(parent), d_ptr(new SARibbonContextCategory::PrivateData(this)) + : QObject(parent), d_ptr(new SARibbonContextCategory::PrivateData(this)) { } @@ -9137,14 +9105,13 @@ void SARibbonContextCategory::onCategoryTitleChanged(const QString& title) /*** End of inlined file: SARibbonContextCategory.cpp ***/ - /*** Start of inlined file: SARibbonGalleryItem.cpp ***/ SARibbonGalleryItem::SARibbonGalleryItem() : m_flags(Qt::ItemIsEnabled | Qt::ItemIsSelectable), m_action(nullptr) { } SARibbonGalleryItem::SARibbonGalleryItem(const QString& text, const QIcon& icon) - : m_flags(Qt::ItemIsEnabled | Qt::ItemIsSelectable), m_action(nullptr) + : m_flags(Qt::ItemIsEnabled | Qt::ItemIsSelectable), m_action(nullptr) { setText(text); setIcon(icon); @@ -9302,7 +9269,6 @@ Qt::Alignment SARibbonGalleryItem::textAlignment() const /*** End of inlined file: SARibbonGalleryItem.cpp ***/ - /*** Start of inlined file: SARibbonGalleryGroup.cpp ***/ #include #include @@ -9337,7 +9303,7 @@ class SARibbonGalleryGroup::PrivateData //=================================================== SARibbonGalleryGroupItemDelegate::SARibbonGalleryGroupItemDelegate(SARibbonGalleryGroup* group, QObject* parent) - : QStyledItemDelegate(parent), m_group(group) + : QStyledItemDelegate(parent), m_group(group) { } @@ -9362,7 +9328,9 @@ void SARibbonGalleryGroupItemDelegate::paint(QPainter* painter, const QStyleOpti } } -void SARibbonGalleryGroupItemDelegate::paintIconOnly(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const +void SARibbonGalleryGroupItemDelegate::paintIconOnly(QPainter* painter, + const QStyleOptionViewItem& option, + const QModelIndex& index) const { QStyle* style = m_group->style(); int sp = m_group->spacing(); @@ -9380,14 +9348,16 @@ void SARibbonGalleryGroupItemDelegate::paintIconOnly(QPainter* painter, const QS painter->restore(); } -void SARibbonGalleryGroupItemDelegate::paintIconWithText(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const +void SARibbonGalleryGroupItemDelegate::paintIconWithText(QPainter* painter, + const QStyleOptionViewItem& option, + const QModelIndex& index) const { QStyledItemDelegate::paint(painter, option, index); } void SARibbonGalleryGroupItemDelegate::paintIconWithTextWordWrap(QPainter* painter, - const QStyleOptionViewItem& option, - const QModelIndex& index) const + const QStyleOptionViewItem& option, + const QModelIndex& index) const { QStyledItemDelegate::paint(painter, option, index); } @@ -9499,7 +9469,7 @@ void SARibbonGalleryGroupModel::append(SARibbonGalleryItem* item) // SARibbonGalleryGroup //=================================================== SARibbonGalleryGroup::SARibbonGalleryGroup(QWidget* w) - : QListView(w), d_ptr(new SARibbonGalleryGroup::PrivateData(this)) + : QListView(w), d_ptr(new SARibbonGalleryGroup::PrivateData(this)) { setViewMode(QListView::IconMode); setResizeMode(QListView::Adjust); @@ -9798,7 +9768,6 @@ void SARibbonGalleryGroup::onItemEntered(const QModelIndex& index) /*** End of inlined file: SARibbonGalleryGroup.cpp ***/ - /*** Start of inlined file: SARibbonGallery.cpp ***/ #include #include @@ -10217,7 +10186,6 @@ void SARibbonGallery::paintEvent(QPaintEvent* event) /*** End of inlined file: SARibbonGallery.cpp ***/ - /*** Start of inlined file: SARibbonBar.cpp ***/ #include #include @@ -10355,18 +10323,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); // @@ -10386,8 +10354,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的横杠 @@ -10445,7 +10413,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 @@ -10724,14 +10696,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; } @@ -10877,6 +10849,8 @@ void SARibbonBar::insertCategoryPage(SARibbonCategory* category, int index) // 更新index信息 d_ptr->updateTabData(); QApplication::postEvent(this, new QResizeEvent(size(), size())); + + connect(category, &SARibbonCategory::actionTriggered, this, &SARibbonBar::actionTriggered); } /** @@ -11296,11 +11270,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); @@ -11488,8 +11464,8 @@ void SARibbonBar::onCurrentRibbonTabChanged(int index) 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())); + d_ptr->mRibbonTabBar->mapToGlobal(QCursor::pos()), + d_ptr->mRibbonTabBar->mapToGlobal(QCursor::pos())); QApplication::sendEvent(d_ptr->mRibbonTabBar, &ehl); resizeStackedContainerWidget(); d_ptr->mStackedContainerWidget->setFocus(); @@ -11519,8 +11495,8 @@ void SARibbonBar::onCurrentRibbonTabClicked(int index) if (this->d_ptr->mStackedContainerWidget->isPopupMode()) { // 在stackedContainerWidget弹出前,先给tabbar一个QHoverEvent,让tabbar知道鼠标已经移开 QHoverEvent ehl(QEvent::HoverLeave, - d_ptr->mRibbonTabBar->mapToGlobal(QCursor::pos()), - d_ptr->mRibbonTabBar->mapToGlobal(QCursor::pos())); + d_ptr->mRibbonTabBar->mapToGlobal(QCursor::pos()), + d_ptr->mRibbonTabBar->mapToGlobal(QCursor::pos())); QApplication::sendEvent(d_ptr->mRibbonTabBar, &ehl); // 弹出前都调整一下位置,避免移动后位置异常 resizeStackedContainerWidget(); @@ -11685,11 +11661,11 @@ void SARibbonBar::setRibbonStyle(SARibbonBar::RibbonStyles v) d_ptr->mRibbonStyle = v; #if SA_DEBUG_PRINT_SIZE_HINT qDebug() << "setRibbonStyle(" << v << ")" // - << "\n isThreeRowStyle=" << isThreeRowStyle() // - << "\n isTwoRowStyle=" << isTwoRowStyle() // - << "\n isLooseStyle=" << isLooseStyle() // - << "\n isCompactStyle=" << isCompactStyle() // - ; + << "\n isThreeRowStyle=" << isThreeRowStyle() // + << "\n isTwoRowStyle=" << isTwoRowStyle() // + << "\n isLooseStyle=" << isLooseStyle() // + << "\n isCompactStyle=" << isCompactStyle() // + ; #endif // 执行判断 setEnableWordWrap(isThreeRowStyle(v)); @@ -11835,11 +11811,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); } /** @@ -11997,7 +11973,7 @@ bool SARibbonBar::isTitleVisible() const /** @brief 设置上下文标签的颜色列表 - 上下文标签显示的时候,会从颜色列表中取颜色进行标签的渲染 + 上下文标签显示的时候,会从颜色列表中取颜色进行标签的渲染 @param cls */ void SARibbonBar::setContextCategoryColorList(const QList< QColor >& cls) @@ -12115,7 +12091,7 @@ bool SARibbonBar::eventFilter(QObject* obj, QEvent* e) // 调整多文档时在窗口模式下的按钮更新 if ((obj == cornerWidget(Qt::TopLeftCorner)) || (obj == cornerWidget(Qt::TopRightCorner))) { if ((QEvent::UpdateLater == e->type()) || (QEvent::MouseButtonRelease == e->type()) - || (QEvent::WindowActivate == e->type())) { + || (QEvent::WindowActivate == e->type())) { QApplication::postEvent(this, new QResizeEvent(size(), size())); } } else if (obj == d_ptr->mStackedContainerWidget) { @@ -12130,11 +12106,11 @@ bool SARibbonBar::eventFilter(QObject* obj, QEvent* e) if (clickedWidget == d_ptr->mRibbonTabBar) { const QPoint targetPoint = clickedWidget->mapFromGlobal(mouseEvent->globalPos()); QMouseEvent* evPress = new QMouseEvent(mouseEvent->type(), - targetPoint, - mouseEvent->globalPos(), - mouseEvent->button(), - mouseEvent->buttons(), - mouseEvent->modifiers()); + targetPoint, + mouseEvent->globalPos(), + mouseEvent->button(), + mouseEvent->buttons(), + mouseEvent->modifiers()); QApplication::postEvent(clickedWidget, evPress); return (true); } @@ -12283,12 +12259,13 @@ void SARibbonBar::paintInLooseStyle() QRect titleRegion; if (contextCategoryRegion.y() < 0) { 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, - titleBarHeight()); + border.top(), + width() - d_ptr->mIconRightBorderPosition - border.right() + - 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) { @@ -12297,9 +12274,9 @@ void SARibbonBar::paintInLooseStyle() } else { // 说明左边的大一点 titleRegion.setRect(d_ptr->mIconRightBorderPosition + d_ptr->mQuickAccessBar->geometry().right(), - border.top(), - leftwidth, - titleBarHeight()); + border.top(), + leftwidth, + titleBarHeight()); } } #ifdef SA_RIBBON_DEBUG_HELP_DRAW @@ -12429,9 +12406,9 @@ void SARibbonBar::paintContextCategoryTab(QPainter& painter, const QString& titl if (isLooseStyle()) { if (!title.isEmpty()) { QRect textRect = QRect(contextRect.x(), - contextRect.y() + contextLineWidth, - contextRect.width(), - contextRect.height() - contextLineWidth - d_ptr->mRibbonTabBar->height()); + contextRect.y() + contextLineWidth, + contextRect.width(), + contextRect.height() - contextLineWidth - d_ptr->mRibbonTabBar->height()); painter.setPen(contextCategoryTitleTextColor()); painter.drawText(textRect, Qt::AlignCenter, title); } @@ -12752,21 +12729,21 @@ QDebug operator<<(QDebug debug, const SARibbonBar& ribbon) QDebugStateSaver saver(debug); QFontMetrics fm = ribbon.fontMetrics(); debug.nospace() << "SARibbonBar(" << ribbon.versionString() << ")" // - << "\nribbon font metrics info:" // - << "\n - lineSpacing:" << fm.lineSpacing() // - << "\n - height:" << fm.height() // - << "\n - em:" << fm.boundingRect("M").width() // - << "\n - ex:" << fm.boundingRect("X").height() // - << "\nribbon info:" // - << "\n -mTitleBarHeight=" << ribbon.d_ptr->mTitleBarHeight // - << "\n -mTabBarHeight=" << ribbon.d_ptr->mTabBarHeight // - << "\n -mPannelTitleHeight=" << ribbon.d_ptr->mPannelTitleHeight // - << "\n -mCategoryHeight=" << ribbon.d_ptr->mCategoryHeight // - << "\n -mIsTabOnTitle=" << ribbon.d_ptr->mIsTabOnTitle // - << "\n -mEnableShowPannelTitle=" << ribbon.d_ptr->mEnableShowPannelTitle // - << "\n -mWindowButtonSize=" << ribbon.d_ptr->mWindowButtonSize // - << "\n -mIconRightBorderPosition=" << ribbon.d_ptr->mIconRightBorderPosition // - ; + << "\nribbon font metrics info:" // + << "\n - lineSpacing:" << fm.lineSpacing() // + << "\n - height:" << fm.height() // + << "\n - em:" << fm.boundingRect("M").width() // + << "\n - ex:" << fm.boundingRect("X").height() // + << "\nribbon info:" // + << "\n -mTitleBarHeight=" << ribbon.d_ptr->mTitleBarHeight // + << "\n -mTabBarHeight=" << ribbon.d_ptr->mTabBarHeight // + << "\n -mPannelTitleHeight=" << ribbon.d_ptr->mPannelTitleHeight // + << "\n -mCategoryHeight=" << ribbon.d_ptr->mCategoryHeight // + << "\n -mIsTabOnTitle=" << ribbon.d_ptr->mIsTabOnTitle // + << "\n -mEnableShowPannelTitle=" << ribbon.d_ptr->mEnableShowPannelTitle // + << "\n -mWindowButtonSize=" << ribbon.d_ptr->mWindowButtonSize // + << "\n -mIconRightBorderPosition=" << ribbon.d_ptr->mIconRightBorderPosition // + ; return debug; } @@ -12774,7 +12751,6 @@ QDebug operator<<(QDebug debug, const SARibbonBar& ribbon) /*** End of inlined file: SARibbonBar.cpp ***/ - /*** Start of inlined file: SARibbonElementFactory.cpp ***/ #include #include @@ -12875,7 +12851,6 @@ SARibbonPannelOptionButton* SARibbonElementFactory::createRibbonPannelOptionButt /*** End of inlined file: SARibbonElementFactory.cpp ***/ - /*** Start of inlined file: SARibbonElementManager.cpp ***/ SARibbonElementManager::SARibbonElementManager() { @@ -12905,7 +12880,6 @@ void SARibbonElementManager::setupFactory(SARibbonElementFactory* delegate) /*** End of inlined file: SARibbonElementManager.cpp ***/ - /*** Start of inlined file: SARibbonCustomizeData.cpp ***/ #include #include @@ -12914,12 +12888,15 @@ void SARibbonElementManager::setupFactory(SARibbonElementFactory* delegate) //////////////////////////////////////////////////////////////////////////////////////////////////////// SARibbonCustomizeData::SARibbonCustomizeData() - : indexValue(-1), actionRowProportionValue(SARibbonPannelItem::Large), m_type(UnknowActionType), m_actionsManagerPointer(nullptr) + : indexValue(-1) + , actionRowProportionValue(SARibbonPannelItem::Large) + , m_type(UnknowActionType) + , m_actionsManagerPointer(nullptr) { } SARibbonCustomizeData::SARibbonCustomizeData(ActionType type, SARibbonActionsManager* mgr) - : indexValue(-1), actionRowProportionValue(SARibbonPannelItem::Large), m_type(type), m_actionsManagerPointer(mgr) + : indexValue(-1), actionRowProportionValue(SARibbonPannelItem::Large), m_type(type), m_actionsManagerPointer(mgr) { } @@ -12967,7 +12944,7 @@ bool SARibbonCustomizeData::apply(SARibbonBar* bar) const return (false); case AddCategoryActionType: { - //添加标签 + // 添加标签 SARibbonCategory* c = bar->insertCategoryPage(keyValue, indexValue); if (nullptr == c) { return (false); @@ -12978,7 +12955,7 @@ bool SARibbonCustomizeData::apply(SARibbonBar* bar) const } case AddPannelActionType: { - //添加pannel + // 添加pannel SARibbonCategory* c = bar->categoryByObjectName(categoryObjNameValue); if (nullptr == c) { return (false); @@ -13186,9 +13163,9 @@ SARibbonCustomizeData SARibbonCustomizeData::makeAddCategoryCustomizeData(const * @return 返回AddPannelActionType的SARibbonCustomizeData */ SARibbonCustomizeData SARibbonCustomizeData::makeAddPannelCustomizeData(const QString& title, - int index, - const QString& categoryobjName, - const QString& objName) + int index, + const QString& categoryobjName, + const QString& objName) { SARibbonCustomizeData d(AddPannelActionType); @@ -13210,10 +13187,10 @@ SARibbonCustomizeData SARibbonCustomizeData::makeAddPannelCustomizeData(const QS * @return */ SARibbonCustomizeData 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) { SARibbonCustomizeData d(AddActionActionType, mgr); @@ -13231,15 +13208,16 @@ SARibbonCustomizeData SARibbonCustomizeData::makeAddActionCustomizeData(const QS * @param index category的索引 * @return 返回RenameCategoryActionType的SARibbonCustomizeData */ -SARibbonCustomizeData SARibbonCustomizeData::makeRenameCategoryCustomizeData(const QString& newname, const QString& categoryobjName) +SARibbonCustomizeData SARibbonCustomizeData::makeRenameCategoryCustomizeData(const QString& newname, + const QString& categoryobjName) { SARibbonCustomizeData d(RenameCategoryActionType); if (categoryobjName.isEmpty()) { qDebug() << QObject::tr("SARibbon Warning !!! customize rename category," - "but get an empty category object name," - "if you want to customize SARibbon," - "please make sure every element has been set object name."); + "but get an empty category object name," + "if you want to customize SARibbon," + "please make sure every element has been set object name."); } d.keyValue = newname; d.categoryObjNameValue = categoryobjName; @@ -13254,16 +13232,16 @@ SARibbonCustomizeData SARibbonCustomizeData::makeRenameCategoryCustomizeData(con * @return 返回RenamePannelActionType的SARibbonCustomizeData */ SARibbonCustomizeData SARibbonCustomizeData::makeRenamePannelCustomizeData(const QString& newname, - const QString& categoryobjName, - const QString& pannelObjName) + const QString& categoryobjName, + const QString& pannelObjName) { SARibbonCustomizeData d(RenamePannelActionType); if (pannelObjName.isEmpty() || categoryobjName.isEmpty()) { qDebug() << QObject::tr("SARibbon Warning !!! customize rename pannel," - "but get an empty category/pannel object name," - "if you want to customize SARibbon," - "please make sure every element has been set object name."); + "but get an empty category/pannel object name," + "if you want to customize SARibbon," + "please make sure every element has been set object name."); } d.keyValue = newname; d.pannelObjNameValue = pannelObjName; @@ -13277,15 +13255,16 @@ SARibbonCustomizeData SARibbonCustomizeData::makeRenamePannelCustomizeData(const * @param moveindex 移动位置,-1代表向上(向左)移动一个位置,1带表向下(向右)移动一个位置 * @return */ -SARibbonCustomizeData SARibbonCustomizeData::makeChangeCategoryOrderCustomizeData(const QString& categoryobjName, int moveindex) +SARibbonCustomizeData SARibbonCustomizeData::makeChangeCategoryOrderCustomizeData(const QString& categoryobjName, + int moveindex) { SARibbonCustomizeData d(ChangeCategoryOrderActionType); if (categoryobjName.isEmpty()) { qDebug() << QObject::tr("SARibbon Warning !!! customize change category order," - "but get an empty category object name," - "if you want to customize SARibbon," - "please make sure every element has been set object name."); + "but get an empty category object name," + "if you want to customize SARibbon," + "please make sure every element has been set object name."); } d.categoryObjNameValue = categoryobjName; d.indexValue = moveindex; @@ -13300,16 +13279,16 @@ SARibbonCustomizeData SARibbonCustomizeData::makeChangeCategoryOrderCustomizeDat * @return */ SARibbonCustomizeData SARibbonCustomizeData::makeChangePannelOrderCustomizeData(const QString& categoryobjName, - const QString& pannelObjName, - int moveindex) + const QString& pannelObjName, + int moveindex) { SARibbonCustomizeData d(ChangePannelOrderActionType); if (categoryobjName.isEmpty() || pannelObjName.isEmpty()) { qDebug() << QObject::tr("SARibbon Warning !!! customize change pannel order," - "but get an empty category/pannel object name," - "if you want to customize SARibbon," - "please make sure every element has been set object name."); + "but get an empty category/pannel object name," + "if you want to customize SARibbon," + "please make sure every element has been set object name."); } d.categoryObjNameValue = categoryobjName; d.pannelObjNameValue = pannelObjName; @@ -13327,18 +13306,18 @@ SARibbonCustomizeData SARibbonCustomizeData::makeChangePannelOrderCustomizeData( * @return */ SARibbonCustomizeData 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) { SARibbonCustomizeData d(ChangeActionOrderActionType, mgr); if (categoryobjName.isEmpty() || pannelObjName.isEmpty() || key.isEmpty()) { qDebug() << QObject::tr("SARibbon Warning !!! customize change action order," - "but get an empty category/pannel/action object name," - "if you want to customize SARibbon," - "please make sure every element has been set object name."); + "but get an empty category/pannel/action object name," + "if you want to customize SARibbon," + "please make sure every element has been set object name."); } d.categoryObjNameValue = categoryobjName; d.pannelObjNameValue = pannelObjName; @@ -13358,9 +13337,9 @@ SARibbonCustomizeData SARibbonCustomizeData::makeRemoveCategoryCustomizeData(con if (categoryobjName.isEmpty()) { qDebug() << QObject::tr("SARibbon Warning !!! customize remove category," - "but get an empty category object name," - "if you want to customize SARibbon," - "please make sure every element has been set object name."); + "but get an empty category object name," + "if you want to customize SARibbon," + "please make sure every element has been set object name."); } d.categoryObjNameValue = categoryobjName; return (d); @@ -13372,15 +13351,16 @@ SARibbonCustomizeData SARibbonCustomizeData::makeRemoveCategoryCustomizeData(con * @param pannelObjName pannel对应的 obj name * @return */ -SARibbonCustomizeData SARibbonCustomizeData::makeRemovePannelCustomizeData(const QString& categoryobjName, const QString& pannelObjName) +SARibbonCustomizeData SARibbonCustomizeData::makeRemovePannelCustomizeData(const QString& categoryobjName, + const QString& pannelObjName) { SARibbonCustomizeData d(RemovePannelActionType); if (categoryobjName.isEmpty() || pannelObjName.isEmpty()) { qDebug() << QObject::tr("SARibbon Warning !!! customize remove pannel," - "but get an empty category/pannel object name," - "if you want to customize SARibbon," - "please make sure every element has been set object name."); + "but get an empty category/pannel object name," + "if you want to customize SARibbon," + "please make sure every element has been set object name."); } d.categoryObjNameValue = categoryobjName; d.pannelObjNameValue = pannelObjName; @@ -13396,17 +13376,17 @@ SARibbonCustomizeData SARibbonCustomizeData::makeRemovePannelCustomizeData(const * @return */ SARibbonCustomizeData SARibbonCustomizeData::makeRemoveActionCustomizeData(const QString& categoryobjName, - const QString& pannelObjName, - const QString& key, - SARibbonActionsManager* mgr) + const QString& pannelObjName, + const QString& key, + SARibbonActionsManager* mgr) { SARibbonCustomizeData d(RemoveActionActionType, mgr); if (categoryobjName.isEmpty() || pannelObjName.isEmpty() || key.isEmpty()) { qDebug() << QObject::tr("SARibbon Warning !!! customize remove action," - "but get an empty category/pannel/action object name," - "if you want to customize SARibbon," - "please make sure every element has been set object name."); + "but get an empty category/pannel/action object name," + "if you want to customize SARibbon," + "please make sure every element has been set object name."); } d.categoryObjNameValue = categoryobjName; d.pannelObjNameValue = pannelObjName; @@ -13426,9 +13406,9 @@ SARibbonCustomizeData SARibbonCustomizeData::makeVisibleCategoryCustomizeData(co if (categoryobjName.isEmpty()) { qDebug() << QObject::tr("SARibbon Warning !!! customize visible category," - "but get an empty category object name," - "if you want to customize SARibbon," - "please make sure every element has been set object name."); + "but get an empty category object name," + "if you want to customize SARibbon," + "please make sure every element has been set object name."); } d.categoryObjNameValue = categoryobjName; d.indexValue = isShow ? 1 : 0; @@ -13498,7 +13478,7 @@ QList< SARibbonCustomizeData > SARibbonCustomizeData::simplify(const QList< SARi return (csd); } QList< SARibbonCustomizeData > res; - QList< int > willremoveIndex; //记录要删除的index + QList< int > willremoveIndex; // 记录要删除的index //! 首先针对连续出现的添加和删除操作进行优化 for (int i = 1; i < size; ++i) { @@ -13508,12 +13488,13 @@ QList< SARibbonCustomizeData > SARibbonCustomizeData::simplify(const QList< SARi } } else if ((csd[ i - 1 ].actionType() == AddPannelActionType) && (csd[ i ].actionType() == RemovePannelActionType)) { if ((csd[ i - 1 ].pannelObjNameValue == csd[ i ].pannelObjNameValue) - && (csd[ i - 1 ].categoryObjNameValue == csd[ i ].categoryObjNameValue)) { + && (csd[ i - 1 ].categoryObjNameValue == csd[ i ].categoryObjNameValue)) { willremoveIndex << i - 1 << i; } } else if ((csd[ i - 1 ].actionType() == AddActionActionType) && (csd[ i ].actionType() == RemoveActionActionType)) { - if ((csd[ i - 1 ].keyValue == csd[ i ].keyValue) && (csd[ i - 1 ].pannelObjNameValue == csd[ i ].pannelObjNameValue) - && (csd[ i - 1 ].categoryObjNameValue == csd[ i ].categoryObjNameValue)) { + if ((csd[ i - 1 ].keyValue == csd[ i ].keyValue) + && (csd[ i - 1 ].pannelObjNameValue == csd[ i ].pannelObjNameValue) + && (csd[ i - 1 ].categoryObjNameValue == csd[ i ].categoryObjNameValue)) { willremoveIndex << i - 1 << i; } } @@ -13524,10 +13505,11 @@ QList< SARibbonCustomizeData > SARibbonCustomizeData::simplify(const QList< SARi //! 筛选VisibleCategoryActionType,对于连续出现的操作只保留最后一步 size = res.size(); for (int i = 1; i < size; ++i) { - if ((res[ i - 1 ].actionType() == VisibleCategoryActionType) && (res[ i ].actionType() == VisibleCategoryActionType)) { + if ((res[ i - 1 ].actionType() == VisibleCategoryActionType) + && (res[ i ].actionType() == VisibleCategoryActionType)) { if (res[ i - 1 ].categoryObjNameValue == res[ i ].categoryObjNameValue) { - //要保证操作的是同一个内容 - willremoveIndex << i - 1; //删除前一个只保留最后一个 + // 要保证操作的是同一个内容 + willremoveIndex << i - 1; // 删除前一个只保留最后一个 } } } @@ -13538,18 +13520,19 @@ QList< SARibbonCustomizeData > SARibbonCustomizeData::simplify(const QList< SARi size = res.size(); for (int i = 0; i < size; ++i) { if (res[ i ].actionType() == RenameCategoryActionType) { - //向后查询,如果查询到有同一个Category改名,把这个索引加入删除队列 + // 向后查询,如果查询到有同一个Category改名,把这个索引加入删除队列 for (int j = i + 1; j < size; ++j) { if ((res[ j ].actionType() == RenameCategoryActionType) - && (res[ i ].categoryObjNameValue == res[ j ].categoryObjNameValue)) { + && (res[ i ].categoryObjNameValue == res[ j ].categoryObjNameValue)) { willremoveIndex << i; } } } else if (res[ i ].actionType() == RenamePannelActionType) { - //向后查询,如果查询到有同一个pannel改名,把这个索引加入删除队列 + // 向后查询,如果查询到有同一个pannel改名,把这个索引加入删除队列 for (int j = i + 1; j < size; ++j) { - if ((res[ j ].actionType() == RenamePannelActionType) && (res[ i ].pannelObjNameValue == res[ j ].pannelObjNameValue) - && (res[ i ].categoryObjNameValue == res[ j ].categoryObjNameValue)) { + if ((res[ j ].actionType() == RenamePannelActionType) + && (res[ i ].pannelObjNameValue == res[ j ].pannelObjNameValue) + && (res[ i ].categoryObjNameValue == res[ j ].categoryObjNameValue)) { willremoveIndex << i; } } @@ -13561,22 +13544,24 @@ QList< SARibbonCustomizeData > SARibbonCustomizeData::simplify(const QList< SARi //! 针对连续的ChangeCategoryOrderActionType,ChangePannelOrderActionType,ChangeActionOrderActionType进行合并 size = res.size(); for (int i = 1; i < size; ++i) { - if ((res[ i - 1 ].actionType() == ChangeCategoryOrderActionType) && (res[ i ].actionType() == ChangeCategoryOrderActionType) - && (res[ i - 1 ].categoryObjNameValue == res[ i ].categoryObjNameValue)) { - //说明连续两个顺序调整,把前一个indexvalue和后一个indexvalue相加,前一个删除 + if ((res[ i - 1 ].actionType() == ChangeCategoryOrderActionType) + && (res[ i ].actionType() == ChangeCategoryOrderActionType) + && (res[ i - 1 ].categoryObjNameValue == res[ i ].categoryObjNameValue)) { + // 说明连续两个顺序调整,把前一个indexvalue和后一个indexvalue相加,前一个删除 res[ i ].indexValue += res[ i - 1 ].indexValue; willremoveIndex << i - 1; - } else if ((res[ i - 1 ].actionType() == ChangePannelOrderActionType) && (res[ i ].actionType() == ChangePannelOrderActionType) - && (res[ i - 1 ].pannelObjNameValue == res[ i ].pannelObjNameValue) - && (res[ i - 1 ].categoryObjNameValue == res[ i ].categoryObjNameValue)) { - //说明连续两个顺序调整,把前一个indexvalue和后一个indexvalue相加,前一个删除 + } else if ((res[ i - 1 ].actionType() == ChangePannelOrderActionType) + && (res[ i ].actionType() == ChangePannelOrderActionType) + && (res[ i - 1 ].pannelObjNameValue == res[ i ].pannelObjNameValue) + && (res[ i - 1 ].categoryObjNameValue == res[ i ].categoryObjNameValue)) { + // 说明连续两个顺序调整,把前一个indexvalue和后一个indexvalue相加,前一个删除 res[ i ].indexValue += res[ i - 1 ].indexValue; willremoveIndex << i - 1; } else if ((res[ i - 1 ].actionType() == ChangeActionOrderActionType) - && (res[ i ].actionType() == ChangeActionOrderActionType) && (res[ i - 1 ].keyValue == res[ i ].keyValue) - && (res[ i - 1 ].pannelObjNameValue == res[ i ].pannelObjNameValue) - && (res[ i - 1 ].categoryObjNameValue == res[ i ].categoryObjNameValue)) { - //说明连续两个顺序调整,把前一个indexvalue和后一个indexvalue相加,前一个删除 + && (res[ i ].actionType() == ChangeActionOrderActionType) && (res[ i - 1 ].keyValue == res[ i ].keyValue) + && (res[ i - 1 ].pannelObjNameValue == res[ i ].pannelObjNameValue) + && (res[ i - 1 ].categoryObjNameValue == res[ i ].categoryObjNameValue)) { + // 说明连续两个顺序调整,把前一个indexvalue和后一个indexvalue相加,前一个删除 res[ i ].indexValue += res[ i - 1 ].indexValue; willremoveIndex << i - 1; } @@ -13588,7 +13573,7 @@ QList< SARibbonCustomizeData > SARibbonCustomizeData::simplify(const QList< SARi size = res.size(); for (int i = 0; i < size; ++i) { if ((res[ i ].actionType() == ChangeCategoryOrderActionType) || (res[ i ].actionType() == ChangePannelOrderActionType) - || (res[ i ].actionType() == ChangeActionOrderActionType)) { + || (res[ i ].actionType() == ChangeActionOrderActionType)) { if (0 == res[ i ].indexValue) { willremoveIndex << i; } @@ -13601,7 +13586,6 @@ QList< SARibbonCustomizeData > SARibbonCustomizeData::simplify(const QList< SARi /*** End of inlined file: SARibbonCustomizeData.cpp ***/ - /*** Start of inlined file: SARibbonCustomizeWidget.cpp ***/ #include #include @@ -13961,11 +13945,11 @@ class SARibbonCustomizeWidgetUi lineEditSearchAction->setInputMask(QString()); lineEditSearchAction->setText(QString()); lineEditSearchAction->setPlaceholderText( - QApplication::translate("SARibbonCustomizeWidget", "Find Command", Q_NULLPTR)); // cn:查找命令 + QApplication::translate("SARibbonCustomizeWidget", "Find Command", Q_NULLPTR)); // cn:查找命令 pushButtonAdd->setText(QApplication::translate("SARibbonCustomizeWidget", "Add >>", Q_NULLPTR)); // cn:添加 >> pushButtonDelete->setText(QApplication::translate("SARibbonCustomizeWidget", "<< Remove", Q_NULLPTR)); // cn:<< 移除 labelCustomize->setText( - QApplication::translate("SARibbonCustomizeWidget", "Customize the Ribbon", Q_NULLPTR)); // cn:自定义功能区 + QApplication::translate("SARibbonCustomizeWidget", "Customize the Ribbon", Q_NULLPTR)); // cn:自定义功能区 radioButtonMainCategory->setText(QApplication::translate("SARibbonCustomizeWidget", "Main Category", Q_NULLPTR)); // cn:主选项卡 radioButtonAllCategory->setText(QApplication::translate("SARibbonCustomizeWidget", "All Category", Q_NULLPTR)); // cn:所有选项卡 pushButtonNewCategory->setText(QApplication::translate("SARibbonCustomizeWidget", "New Category", Q_NULLPTR)); // cn:新建选项卡 @@ -14022,7 +14006,7 @@ class SARibbonCustomizeWidget::PrivateData }; SARibbonCustomizeWidget::PrivateData::PrivateData(SARibbonCustomizeWidget* p) - : q_ptr(p), mAcionModel(new SARibbonActionsManagerModel(p)), mRibbonModel(new QStandardItemModel(p)) + : q_ptr(p), mAcionModel(new SARibbonActionsManagerModel(p)), mRibbonModel(new QStandardItemModel(p)) { } @@ -14235,7 +14219,7 @@ QAction* SARibbonCustomizeWidget::PrivateData::itemToAction(QStandardItem* item) act = reinterpret_cast< QAction* >(item->data(SARibbonCustomizeWidget::PointerRole).value< qintptr >()); } else { SARibbonPannelItem* pi = reinterpret_cast< SARibbonPannelItem* >( - item->data(SARibbonCustomizeWidget::PointerRole).value< qintptr >()); + item->data(SARibbonCustomizeWidget::PointerRole).value< qintptr >()); act = (pi->action); } return (act); @@ -14251,13 +14235,13 @@ QAction* SARibbonCustomizeWidget::PrivateData::itemToAction(QStandardItem* item) * @param f 同QWidget::QWidget的第二个参数 */ SARibbonCustomizeWidget::SARibbonCustomizeWidget(SARibbonMainWindow* ribbonWindow, QWidget* parent, Qt::WindowFlags f) - : QWidget(parent, f), d_ptr(new SARibbonCustomizeWidget::PrivateData(this)), ui(new SARibbonCustomizeWidgetUi) + : QWidget(parent, f), d_ptr(new SARibbonCustomizeWidget::PrivateData(this)), ui(new SARibbonCustomizeWidgetUi) { init(ribbonWindow->ribbonBar()); } SARibbonCustomizeWidget::SARibbonCustomizeWidget(SARibbonBar* ribbonbar, QWidget* parent, Qt::WindowFlags f) - : QWidget(parent, f), d_ptr(new SARibbonCustomizeWidget::PrivateData(this)), ui(new SARibbonCustomizeWidgetUi) + : QWidget(parent, f), d_ptr(new SARibbonCustomizeWidget::PrivateData(this)), ui(new SARibbonCustomizeWidgetUi) { init(ribbonbar); } @@ -14283,16 +14267,16 @@ void SARibbonCustomizeWidget::initConnection() // connect(ui->comboBoxActionIndex, QOverload::of(&QComboBox::currentIndexChanged) // , this, &SARibbonCustomizeWidget::onComboBoxActionIndexCurrentIndexChanged); connect(ui->comboBoxActionIndex, - static_cast< void (QComboBox::*)(int) >(&QComboBox::currentIndexChanged), - this, - &SARibbonCustomizeWidget::onComboBoxActionIndexCurrentIndexChanged); + static_cast< void (QComboBox::*)(int) >(&QComboBox::currentIndexChanged), + this, + &SARibbonCustomizeWidget::onComboBoxActionIndexCurrentIndexChanged); // 这个需要qt5.8以上支持 // connect(ui->radioButtonGroup, QOverload::of(&QButtonGroup::buttonClicked) // , this, &SARibbonCustomizeWidget::onRadioButtonGroupButtonClicked); connect(ui->radioButtonGroup, - static_cast< void (QButtonGroup::*)(QAbstractButton*) >(&QButtonGroup::buttonClicked), - this, - &SARibbonCustomizeWidget::onRadioButtonGroupButtonClicked); + static_cast< void (QButtonGroup::*)(QAbstractButton*) >(&QButtonGroup::buttonClicked), + this, + &SARibbonCustomizeWidget::onRadioButtonGroupButtonClicked); connect(ui->pushButtonNewCategory, &QPushButton::clicked, this, &SARibbonCustomizeWidget::onPushButtonNewCategoryClicked); connect(ui->pushButtonNewPannel, &QPushButton::clicked, this, &SARibbonCustomizeWidget::onPushButtonNewPannelClicked); connect(ui->pushButtonRename, &QPushButton::clicked, this, &SARibbonCustomizeWidget::onPushButtonRenameClicked); @@ -14761,9 +14745,9 @@ void SARibbonCustomizeWidget::onPushButtonNewCategoryClicked() setSelectItem(ni); // 把动作插入动作列表中 SARibbonCustomizeData d = SARibbonCustomizeData::makeAddCategoryCustomizeData(ni->text(), - ni->row(), - SARibbonCustomizeWidget::PrivateData::makeRandomObjName( - "category")); + ni->row(), + SARibbonCustomizeWidget::PrivateData::makeRandomObjName( + "category")); d_ptr->mCustomizeDatasCache.append(d); ni->setData(true, SARibbonCustomizeWidget::CanCustomizeRole); // 有CustomizeRole,必有CanCustomizeRole @@ -14806,10 +14790,10 @@ void SARibbonCustomizeWidget::onPushButtonNewPannelClicked() categoryObjName = d_ptr->itemObjectName(categoryItem); SARibbonCustomizeData d = SARibbonCustomizeData::makeAddPannelCustomizeData(ni->text(), - ni->row(), - categoryObjName, - SARibbonCustomizeWidget::PrivateData::makeRandomObjName( - "pannel")); + ni->row(), + categoryObjName, + SARibbonCustomizeWidget::PrivateData::makeRandomObjName( + "pannel")); d_ptr->mCustomizeDatasCache.append(d); ni->setData(true, SARibbonCustomizeWidget::CanCustomizeRole); // 有CustomizeRole,必有CanCustomizeRole @@ -14874,10 +14858,10 @@ void SARibbonCustomizeWidget::onPushButtonAddClicked() QString key = d_ptr->mActionMgr->key(act); SARibbonCustomizeData d = SARibbonCustomizeData::makeAddActionCustomizeData(key, - d_ptr->mActionMgr, - selectedRowProportion(), - categoryObjName, - pannelObjName); + d_ptr->mActionMgr, + selectedRowProportion(), + categoryObjName, + pannelObjName); d_ptr->mCustomizeDatasCache.append(d); @@ -14924,9 +14908,9 @@ void SARibbonCustomizeWidget::onPushButtonDeleteClicked() } SARibbonCustomizeData d = SARibbonCustomizeData::makeRemoveActionCustomizeData(catObjName, - pannelObjName, - key, - d_ptr->mActionMgr); + pannelObjName, + key, + d_ptr->mActionMgr); d_ptr->mCustomizeDatasCache.append(d); } // 执行删除操作 @@ -14959,7 +14943,7 @@ void SARibbonCustomizeWidget::onTreeViewResultClicked(const QModelIndex& index) ui->pushButtonAdd->setEnabled(selectedAction() && (level > 0) && isItemCanCustomize(item)); ui->pushButtonDelete->setEnabled(isItemCanCustomize(item)); // 有CustomizeRole,必有CanCustomizeRole ui->pushButtonRename->setEnabled( - level != 2 || isItemCanCustomize(item)); // QAction 不能改名 , 有CustomizeRole,必有CanCustomizeRole + level != 2 || isItemCanCustomize(item)); // QAction 不能改名 , 有CustomizeRole,必有CanCustomizeRole } void SARibbonCustomizeWidget::onToolButtonUpClicked() @@ -14974,7 +14958,7 @@ void SARibbonCustomizeWidget::onToolButtonUpClicked() if (0 == level) { // 移动category SARibbonCustomizeData d = SARibbonCustomizeData::makeChangeCategoryOrderCustomizeData(d_ptr->itemObjectName(item), - -1); + -1); d_ptr->mCustomizeDatasCache.append(d); int r = item->row(); item = d_ptr->mRibbonModel->takeItem(r); @@ -14983,8 +14967,8 @@ void SARibbonCustomizeWidget::onToolButtonUpClicked() } else if (1 == level) { QStandardItem* paritem = item->parent(); SARibbonCustomizeData d = SARibbonCustomizeData::makeChangePannelOrderCustomizeData(d_ptr->itemObjectName(paritem), - d_ptr->itemObjectName(item), - -1); + d_ptr->itemObjectName(item), + -1); d_ptr->mCustomizeDatasCache.append(d); int r = item->row(); item = paritem->takeChild(r); @@ -14999,10 +14983,10 @@ void SARibbonCustomizeWidget::onToolButtonUpClicked() } 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->itemObjectName(pannelItem), + key, + d_ptr->mActionMgr, + -1); d_ptr->mCustomizeDatasCache.append(d); int r = item->row(); item = pannelItem->takeChild(r); @@ -15037,7 +15021,7 @@ void SARibbonCustomizeWidget::onToolButtonDownClicked() if (0 == level) { // 移动category SARibbonCustomizeData d = SARibbonCustomizeData::makeChangeCategoryOrderCustomizeData(d_ptr->itemObjectName(item), - 1); + 1); d_ptr->mCustomizeDatasCache.append(d); int r = item->row(); item = d_ptr->mRibbonModel->takeItem(item->row()); @@ -15046,8 +15030,8 @@ void SARibbonCustomizeWidget::onToolButtonDownClicked() } else if (1 == level) { QStandardItem* paritem = item->parent(); SARibbonCustomizeData d = SARibbonCustomizeData::makeChangePannelOrderCustomizeData(d_ptr->itemObjectName(paritem), - d_ptr->itemObjectName(item), - 1); + d_ptr->itemObjectName(item), + 1); d_ptr->mCustomizeDatasCache.append(d); int r = item->row(); item = paritem->takeChild(r); @@ -15062,10 +15046,10 @@ void SARibbonCustomizeWidget::onToolButtonDownClicked() } 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->itemObjectName(pannelItem), + key, + d_ptr->mActionMgr, + -1); d_ptr->mCustomizeDatasCache.append(d); int r = item->row(); item = pannelItem->takeChild(r); @@ -15089,8 +15073,8 @@ void SARibbonCustomizeWidget::onItemChanged(QStandardItem* item) if (item->isCheckable()) { QString objname = d_ptr->itemObjectName(item); SARibbonCustomizeData d = SARibbonCustomizeData::makeVisibleCategoryCustomizeData(objname, - item->checkState() - == Qt::Checked); + item->checkState() + == Qt::Checked); d_ptr->mCustomizeDatasCache.append(d); } } @@ -15104,10 +15088,10 @@ void SARibbonCustomizeWidget::onLineEditSearchActionTextEdited(const QString& te void SARibbonCustomizeWidget::onPushButtonResetClicked() { int btn = QMessageBox::warning(this, - tr("Warning"), - tr("Are you sure reset all customize setting?"), - QMessageBox::Yes | QMessageBox::No, - QMessageBox::No); + tr("Warning"), + tr("Are you sure reset all customize setting?"), + QMessageBox::Yes | QMessageBox::No, + QMessageBox::No); if (btn == QMessageBox::Yes) { clear(); @@ -15116,7 +15100,6 @@ void SARibbonCustomizeWidget::onPushButtonResetClicked() /*** End of inlined file: SARibbonCustomizeWidget.cpp ***/ - /*** Start of inlined file: SARibbonCustomizeDialog.cpp ***/ #include #include @@ -15126,15 +15109,16 @@ void SARibbonCustomizeWidget::onPushButtonResetClicked() /** * @brief The SARibbonCustomizeDialogUi class */ -class SARibbonCustomizeDialogUi { +class SARibbonCustomizeDialogUi +{ public: - SARibbonCustomizeWidget *customWidget; - QVBoxLayout *verticalLayoutMain; - QHBoxLayout *horizontalLayoutButtonGroup; - QPushButton *pushButtonCancel; - QPushButton *pushButtonOk; - QSpacerItem *spacerItemleft; - void setupUi(SARibbonMainWindow *ribbonWindow, QWidget *customizeDialog) + SARibbonCustomizeWidget* customWidget; + QVBoxLayout* verticalLayoutMain; + QHBoxLayout* horizontalLayoutButtonGroup; + QPushButton* pushButtonCancel; + QPushButton* pushButtonOk; + QSpacerItem* spacerItemleft; + void setupUi(SARibbonMainWindow* ribbonWindow, QWidget* customizeDialog) { if (customizeDialog->objectName().isEmpty()) { customizeDialog->setObjectName(QStringLiteral("SARibbonCustomizeDialog")); @@ -15164,7 +15148,7 @@ class SARibbonCustomizeDialogUi { retranslateUi(customizeDialog); } - void retranslateUi(QWidget *customizeDialog) + void retranslateUi(QWidget* customizeDialog) { customizeDialog->setWindowTitle(QApplication::translate("SARibbonCustomizeDialog", "Customize Dialog", Q_NULLPTR)); pushButtonCancel->setText(QApplication::translate("SARibbonCustomizeDialog", "Cancel", Q_NULLPTR)); @@ -15174,9 +15158,8 @@ class SARibbonCustomizeDialogUi { //////////////////////////////////////////////////////////////////// -SARibbonCustomizeDialog::SARibbonCustomizeDialog(SARibbonMainWindow *ribbonWindow, QWidget *p, Qt::WindowFlags f) - : QDialog(p, f) - , ui(new SARibbonCustomizeDialogUi) +SARibbonCustomizeDialog::SARibbonCustomizeDialog(SARibbonMainWindow* ribbonWindow, QWidget* p, Qt::WindowFlags f) + : QDialog(p, f), ui(new SARibbonCustomizeDialogUi) { ui->setupUi(ribbonWindow, this); initConnection(); @@ -15188,7 +15171,7 @@ SARibbonCustomizeDialog::SARibbonCustomizeDialog(SARibbonMainWindow *ribbonWindo * 等同@ref SARibbonCustomizeWidget::setupActionsManager * @param mgr */ -void SARibbonCustomizeDialog::setupActionsManager(SARibbonActionsManager *mgr) +void SARibbonCustomizeDialog::setupActionsManager(SARibbonActionsManager* mgr) { ui->customWidget->setupActionsManager(mgr); } @@ -15245,7 +15228,7 @@ void SARibbonCustomizeDialog::clear() * @param xml * @return */ -bool SARibbonCustomizeDialog::toXml(QXmlStreamWriter *xml) const +bool SARibbonCustomizeDialog::toXml(QXmlStreamWriter* xml) const { return (ui->customWidget->toXml(xml)); } @@ -15265,7 +15248,7 @@ bool SARibbonCustomizeDialog::toXml(const QString& xmlpath) const * @brief 等同SARibbonCustomizeWidget::fromXml * @param xml */ -void SARibbonCustomizeDialog::fromXml(QXmlStreamReader *xml) +void SARibbonCustomizeDialog::fromXml(QXmlStreamReader* xml) { ui->customWidget->fromXml(xml); } @@ -15286,14 +15269,13 @@ void SARibbonCustomizeDialog::fromXml(const QString& xmlpath) * * @return SARibbonCustomizeWidget指针,参考@ref SARibbonCustomizeWidget */ -SARibbonCustomizeWidget *SARibbonCustomizeDialog::customizeWidget() const +SARibbonCustomizeWidget* SARibbonCustomizeDialog::customizeWidget() const { return (ui->customWidget); } /*** End of inlined file: SARibbonCustomizeDialog.cpp ***/ - /*** Start of inlined file: SARibbonMainWindow.cpp ***/ #include #include @@ -15347,7 +15329,7 @@ void SARibbonMainWindow::PrivateData::installFrameless(SARibbonMainWindow* p) // SARibbonMainWindow //=================================================== SARibbonMainWindow::SARibbonMainWindow(QWidget* parent, bool useRibbon, const Qt::WindowFlags flags) - : QMainWindow(parent, flags), d_ptr(new SARibbonMainWindow::PrivateData(this)) + : QMainWindow(parent, flags), d_ptr(new SARibbonMainWindow::PrivateData(this)) { connect(qApp, &QApplication::primaryScreenChanged, this, &SARibbonMainWindow::onPrimaryScreenChanged); if (useRibbon) { @@ -15673,8 +15655,235 @@ void sa_set_ribbon_theme(QWidget* w, SARibbonTheme theme) /*** End of inlined file: SARibbonMainWindow.cpp ***/ +/*** Start of inlined file: SARibbonWidget.cpp ***/ +#include +#include +#include +#include + +/** + * @brief The SARibbonWidget::PrivateData class + */ +class SARibbonWidget::PrivateData +{ + SA_RIBBON_DECLARE_PUBLIC(SARibbonWidget) +public: + PrivateData(SARibbonWidget* p); + void installFrameless(SARibbonWidget* p); + +public: + SARibbonTheme mCurrentRibbonTheme { SARibbonTheme::RibbonThemeOffice2021Blue }; +}; + +SARibbonWidget::PrivateData::PrivateData(SARibbonWidget* p) : q_ptr(p) +{ +} + +//=================================================== +// SARibbonWidget +//=================================================== +SARibbonWidget::SARibbonWidget(QWidget* parent) : QWidget(parent), d_ptr(new SARibbonWidget::PrivateData(this)) +{ + // 直接创建SARibbonBar + QVBoxLayout* verticalLayout = new QVBoxLayout(this); + verticalLayout->setSpacing(1); + verticalLayout->setObjectName("verticalLayout"); + verticalLayout->setContentsMargins(0, 0, 0, 0); + SARibbonBar* ribbon = new SARibbonBar(this); + setRibbonBar(ribbon); + connect(qApp, &QApplication::primaryScreenChanged, this, &SARibbonWidget::onPrimaryScreenChanged); +} + +SARibbonWidget::~SARibbonWidget() +{ +} + +/** + * @brief 返回ribbonbar,如果不是使用ribbon模式,返回nullptr + * @return + */ +SARibbonBar* SARibbonWidget::ribbonBar() const +{ + QLayout* lay = layout(); + if (lay) { + return qobject_cast< SARibbonBar* >(lay->menuBar()); + } + return nullptr; +} + +/** + * @brief 设置ribbonbar + * @param bar + */ +void SARibbonWidget::setRibbonBar(SARibbonBar* bar) +{ + QLayout* lay = layout(); + if (lay) { + lay->setMenuBar(bar); + } +} + +/** + * @brief SARibbonMainWindow::setRibbonTheme + * + * 注意主题在构造函数设置主题会不完全生效,使用QTimer投放到队列最后执行即可 + * @code + * QTimer::singleShot(0, this, [ this ]() { this->setRibbonTheme(SARibbonMainWindow::RibbonThemeDark); }); + * @endcode + * @param theme + */ +void SARibbonWidget::setRibbonTheme(SARibbonTheme theme) +{ + sa_set_ribbon_theme(this, theme); + d_ptr->mCurrentRibbonTheme = theme; + if (SARibbonBar* bar = ribbonBar()) { + auto theme = ribbonTheme(); + // 尺寸修正 + switch (theme) { + case SARibbonTheme::RibbonThemeWindows7: + case SARibbonTheme::RibbonThemeOffice2013: + case SARibbonTheme::RibbonThemeOffice2016Blue: + case SARibbonTheme::RibbonThemeDark: + case SARibbonTheme::RibbonThemeDark2: { + //! 在设置qss后需要针对margin信息重新设置进SARibbonTabBar中 + //! office2013.qss的margin信息如下设置 + //! margin-top: 0px; + //! margin-right: 0px; + //! margin-left: 5px; + //! margin-bottom: 0px; + SARibbonTabBar* tab = bar->ribbonTabBar(); + if (!tab) { + break; + } + tab->setTabMargin(QMargins(5, 0, 0, 0)); + } break; + case SARibbonTheme::RibbonThemeOffice2021Blue: { + SARibbonTabBar* tab = bar->ribbonTabBar(); + if (!tab) { + break; + } + //! 在设置qss后需要针对margin信息重新设置进SARibbonTabBar中 + //! office2021.qss的margin信息如下设置 + //! margin-top: 0px; + //! margin-right: 5px; + //! margin-left: 5px; + //! margin-bottom: 0px; + tab->setTabMargin(QMargins(5, 0, 5, 0)); + } + default: + break; + } + // 上下文标签颜色设置,以及基线颜色设置 + switch (theme) { + case SARibbonTheme::RibbonThemeWindows7: + case SARibbonTheme::RibbonThemeOffice2013: + case SARibbonTheme::RibbonThemeDark: + bar->setContextCategoryColorList(QList< QColor >()); //< 设置空颜色列表会重置为默认色系 + break; + case SARibbonTheme::RibbonThemeOffice2016Blue: + bar->setContextCategoryColorList(QList< QColor >() << QColor(18, 64, 120)); //< 设置空颜色列表会重置为默认色系 + break; + case SARibbonTheme::RibbonThemeOffice2021Blue: + bar->setContextCategoryColorList(QList< QColor >() << QColor(209, 207, 209)); //< 设置空颜色列表会重置为默认色系 + break; + default: + break; + } + // 基线颜色设置 + if (SARibbonTheme::RibbonThemeOffice2013 == theme) { + bar->setTabBarBaseLineColor(QColor(186, 201, 219)); + } else { + bar->setTabBarBaseLineColor(QColor()); + } + } +} + +SARibbonTheme SARibbonWidget::ribbonTheme() const +{ + return (d_ptr->mCurrentRibbonTheme); +} + +bool SARibbonWidget::isUseRibbon() const +{ + return (nullptr != ribbonBar()); +} + +/** + @brief 设置窗口 + + @param 窗口指针 + @note 窗口的所有权归SARibbonWidget管理 + @sa widget + @note 原来设置的窗口会被delete + */ +void SARibbonWidget::setWidget(QWidget* w) +{ + QWidget* oldwidget = takeWidget(); + if (oldwidget) { + oldwidget->hide(); + oldwidget->deleteLater(); + } + if (QLayout* lay = layout()) { + lay->addWidget(w); + } +} + +/** + @brief 获取设置的窗口 + + @return 如果没有,返回nullptr + */ +QWidget* SARibbonWidget::widget() const +{ + QLayout* lay = layout(); + if (lay) { + if (lay->count() == 0) { + return nullptr; + } + return lay->itemAt(0)->widget(); + } + return nullptr; +} + +QWidget* SARibbonWidget::takeWidget() +{ + QLayout* lay = layout(); + if (nullptr == lay) { + return nullptr; + } + if (lay->count() == 0) { + return nullptr; + } + auto item = lay->itemAt(0); + if (nullptr == item) { + return nullptr; + } + lay->removeItem(item); + auto w = item->widget(); + delete item; + if (!w) { + return nullptr; + } + return w; +} + +/** + * @brief 主屏幕切换触发的信号 + * @param screen + */ +void SARibbonWidget::onPrimaryScreenChanged(QScreen* screen) +{ + Q_UNUSED(screen); + // 主屏幕切换后,从新计算所有尺寸 + if (SARibbonBar* bar = ribbonBar()) { + qDebug() << "Primary Screen Changed"; + bar->updateRibbonGeometry(); + } +} + +/*** End of inlined file: SARibbonWidget.cpp ***/ + #ifdef _MSC_VER -#pragma warning (pop) -#pragma pop_macro ("_CRT_SECURE_NO_WARNINGS") +#pragma warning(pop) +#pragma pop_macro("_CRT_SECURE_NO_WARNINGS") #endif - diff --git a/src/SARibbon.h b/src/SARibbon.h index e6a3e38..68f14ba 100644 --- a/src/SARibbon.h +++ b/src/SARibbon.h @@ -1,17 +1,16 @@ #ifndef SA_RIBBON_H #define SA_RIBBON_H -//定义此宏,将SA_RIBBON_EXPORT定义为空 +// 定义此宏,将SA_RIBBON_EXPORT定义为空 #ifndef SA_RIBBON_BAR_NO_EXPORT #define SA_RIBBON_BAR_NO_EXPORT #endif -//定义此宏,将SA_COLOR_WIDGETS_API定义为空 +// 定义此宏,将SA_COLOR_WIDGETS_API定义为空 #ifndef SA_COLOR_WIDGETS_NO_DLL #define SA_COLOR_WIDGETS_NO_DLL #endif - /*** Start of inlined file: SARibbonAmalgamTemplatePublicHeaders.h ***/ -//Global +// Global /*** Start of inlined file: SAColorWidgetsGlobal.h ***/ #ifndef SACOLORWIDGETSGLOBAL_H @@ -75,15 +74,13 @@ /*** End of inlined file: SAColorWidgetsGlobal.h ***/ - - /*** Start of inlined file: SARibbonGlobal.h ***/ #ifndef SARIBBONGLOBAL_H #define SARIBBONGLOBAL_H #include #include #include - +class QWidget; /** @file SARibbonGlobal.h */ @@ -98,13 +95,13 @@ * @def ribbon的数字版本 MAJ.{MIN}.PAT */ #ifndef SA_RIBBON_BAR_VERSION_MIN -#define SA_RIBBON_BAR_VERSION_MIN 0 +#define SA_RIBBON_BAR_VERSION_MIN 1 #endif /** * @def ribbon的数字版本 MAJ.MIN.{PAT} */ #ifndef SA_RIBBON_BAR_VERSION_PAT -#define SA_RIBBON_BAR_VERSION_PAT 3 +#define SA_RIBBON_BAR_VERSION_PAT 0 #endif #ifndef SA_RIBBON_BAR_NO_EXPORT @@ -208,7 +205,7 @@ enum class SARibbonTheme /** @def 定义此宏,将打印和尺寸刷新相关的信息 - 仅用于调试 + 仅用于调试 */ #ifndef SA_DEBUG_PRINT_SIZE_HINT #define SA_DEBUG_PRINT_SIZE_HINT 0 @@ -217,7 +214,7 @@ enum class SARibbonTheme /** @def 定义此宏,将打印事件 - 仅用于调试 + 仅用于调试 */ #ifndef SA_DEBUG_PRINT_EVENT #define SA_DEBUG_PRINT_EVENT 0 @@ -226,17 +223,31 @@ enum class SARibbonTheme /** @def 定义此宏,qDebug将支持SARibbonBar的属性打印 - 仅用于调试 + 仅用于调试 */ #ifndef SA_DEBUG_PRINT_SARIBBONBAR #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 /*** End of inlined file: SARibbonGlobal.h ***/ -//color widget +// color widget /*** Start of inlined file: SAColorMenu.h ***/ #ifndef SACOLORMENU_H @@ -295,8 +306,6 @@ private slots: /*** End of inlined file: SAColorMenu.h ***/ - - /*** Start of inlined file: SAColorGridWidget.h ***/ #ifndef SACOLORGRIDWIDGET_H #define SACOLORGRIDWIDGET_H @@ -394,7 +403,6 @@ SA_COLOR_WIDGETS_API QList< QColor > getStandardColorList(); /*** End of inlined file: SAColorGridWidget.h ***/ - /*** Start of inlined file: SAColorPaletteGridWidget.h ***/ #ifndef SACOLORPALETTEGRIDWIDGET_H #define SACOLORPALETTEGRIDWIDGET_H @@ -444,7 +452,6 @@ private slots: /*** End of inlined file: SAColorPaletteGridWidget.h ***/ - /*** Start of inlined file: SAColorToolButton.h ***/ #ifndef SACOLORTOOLBUTTON_H #define SACOLORTOOLBUTTON_H @@ -554,7 +561,7 @@ private slots: /*** End of inlined file: SAColorToolButton.h ***/ -//sa ribbon +// sa ribbon /*** Start of inlined file: SAFramelessHelper.h ***/ #ifndef SAFRAMELESSHELPER_H @@ -612,8 +619,6 @@ class SA_RIBBON_EXPORT SAFramelessHelper : public QObject /*** End of inlined file: SAFramelessHelper.h ***/ - - /*** Start of inlined file: SARibbonApplicationButton.h ***/ #ifndef SARIBBONAPPLICATIONBUTTON_H #define SARIBBONAPPLICATIONBUTTON_H @@ -637,7 +642,6 @@ class SA_RIBBON_EXPORT SARibbonApplicationButton : public QToolButton /*** End of inlined file: SARibbonApplicationButton.h ***/ - /*** Start of inlined file: SARibbonSystemButtonBar.h ***/ #ifndef SARIBBONSYSTEMBUTTONBAR_H #define SARIBBONSYSTEMBUTTONBAR_H @@ -691,15 +695,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); @@ -728,7 +732,6 @@ class SARibbonSystemToolButton : public QToolButton /*** End of inlined file: SARibbonSystemButtonBar.h ***/ - /*** Start of inlined file: SARibbonToolButton.h ***/ #ifndef SARIBBONTOOLBUTTON_H #define SARIBBONTOOLBUTTON_H @@ -761,25 +764,25 @@ class SA_RIBBON_EXPORT SARibbonToolButton : public QToolButton SARibbonToolButton(QWidget* parent = Q_NULLPTR); SARibbonToolButton(QAction* defaultAction, QWidget* parent = Q_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(); @@ -793,26 +796,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: }; @@ -825,7 +828,6 @@ QDebug operator<<(QDebug debug, const QStyleOptionToolButton& opt); /*** End of inlined file: SARibbonToolButton.h ***/ - /*** Start of inlined file: SARibbonColorToolButton.h ***/ #ifndef SARIBBONCOLORTOOLBUTTON_H #define SARIBBONCOLORTOOLBUTTON_H @@ -884,7 +886,6 @@ private slots: /*** End of inlined file: SARibbonColorToolButton.h ***/ - /*** Start of inlined file: SARibbonLineWidgetContainer.h ***/ #ifndef SARIBBONLINEWIDGETCONTAINER_H #define SARIBBONLINEWIDGETCONTAINER_H @@ -906,23 +907,23 @@ class SA_RIBBON_EXPORT SARibbonLineWidgetContainer : public QWidget public: SARibbonLineWidgetContainer(QWidget* par = nullptr); - //设置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; @@ -932,7 +933,6 @@ class SA_RIBBON_EXPORT SARibbonLineWidgetContainer : public QWidget /*** End of inlined file: SARibbonLineWidgetContainer.h ***/ - /*** Start of inlined file: SARibbonActionsManager.h ***/ #ifndef SARIBBONACTIONSMANAGER_H #define SARIBBONACTIONSMANAGER_H @@ -964,7 +964,8 @@ class SARibbonCategory; * @ref filter (等同@ref actions )函数用于提取标签管理的action list,@ref allActions 函数返回SARibbonActionsManager * 管理的所有标签。 * - * 通过@ref autoRegisteActions 函数可以快速的建立action的管理,此函数会遍历@ref SARibbonBar下所有@ref SARibbonPannel 添加的action,并给予Category建立tag,正常使用用户仅需关注此autoRegisteActions函数即可 + * 通过@ref autoRegisteActions 函数可以快速的建立action的管理,此函数会遍历@ref SARibbonBar下所有@ref SARibbonPannel + * 添加的action,并给予Category建立tag,正常使用用户仅需关注此autoRegisteActions函数即可 * * */ @@ -990,53 +991,53 @@ class SA_RIBBON_EXPORT SARibbonActionsManager : public QObject }; 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(); signals: @@ -1084,7 +1085,6 @@ private slots: /*** End of inlined file: SARibbonActionsManager.h ***/ - /*** Start of inlined file: SARibbonLineEdit.h ***/ #ifndef SARIBBONLINEEDIT_H #define SARIBBONLINEEDIT_H @@ -1098,15 +1098,14 @@ class SA_RIBBON_EXPORT SARibbonLineEdit : public QLineEdit { Q_OBJECT public: - SARibbonLineEdit(QWidget *parent = Q_NULLPTR); - SARibbonLineEdit(const QString &text, QWidget *parent = Q_NULLPTR); + SARibbonLineEdit(QWidget* parent = Q_NULLPTR); + SARibbonLineEdit(const QString& text, QWidget* parent = Q_NULLPTR); }; -#endif // SARIBBONLINEEDIT_H +#endif // SARIBBONLINEEDIT_H /*** End of inlined file: SARibbonLineEdit.h ***/ - /*** Start of inlined file: SARibbonCheckBox.h ***/ #ifndef SARIBBONCHECKBOX_H #define SARIBBONCHECKBOX_H @@ -1120,15 +1119,14 @@ class SA_RIBBON_EXPORT SARibbonCheckBox : public QCheckBox { Q_OBJECT public: - SARibbonCheckBox(QWidget *parent = Q_NULLPTR); - SARibbonCheckBox(const QString &text, QWidget *parent = Q_NULLPTR); + SARibbonCheckBox(QWidget* parent = Q_NULLPTR); + SARibbonCheckBox(const QString& text, QWidget* parent = Q_NULLPTR); }; -#endif // SARIBBONCHECKBOX_H +#endif // SARIBBONCHECKBOX_H /*** End of inlined file: SARibbonCheckBox.h ***/ - /*** Start of inlined file: SARibbonComboBox.h ***/ #ifndef SARIBBONCOMBOBOX_H #define SARIBBONCOMBOBOX_H @@ -1142,14 +1140,13 @@ class SA_RIBBON_EXPORT SARibbonComboBox : public QComboBox { Q_OBJECT public: - SARibbonComboBox(QWidget *parent = Q_NULLPTR); + SARibbonComboBox(QWidget* parent = Q_NULLPTR); }; -#endif // SARIBBONCOMBOBOX_H +#endif // SARIBBONCOMBOBOX_H /*** End of inlined file: SARibbonComboBox.h ***/ - /*** Start of inlined file: SARibbonButtonGroupWidget.h ***/ #ifndef SARIBBONBUTTONGROUPWIDGET_H #define SARIBBONBUTTONGROUPWIDGET_H @@ -1177,15 +1174,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 @@ -1212,7 +1209,6 @@ class SA_RIBBON_EXPORT SARibbonButtonGroupWidget : public QFrame /*** End of inlined file: SARibbonButtonGroupWidget.h ***/ - /*** Start of inlined file: SARibbonStackedWidget.h ***/ #ifndef SARIBBONSTACKEDWIDGET_H #define SARIBBONSTACKEDWIDGET_H @@ -1259,7 +1255,6 @@ class SA_RIBBON_EXPORT SARibbonStackedWidget : public QStackedWidget /*** End of inlined file: SARibbonStackedWidget.h ***/ - /*** Start of inlined file: SARibbonSeparatorWidget.h ***/ #ifndef SARIBBONSEPARATORWIDGET_H #define SARIBBONSEPARATORWIDGET_H @@ -1282,7 +1277,6 @@ class SA_RIBBON_EXPORT SARibbonSeparatorWidget : public QFrame /*** End of inlined file: SARibbonSeparatorWidget.h ***/ - /*** Start of inlined file: SARibbonCtrlContainer.h ***/ #ifndef SARIBBONCTROLCONTAINER_H #define SARIBBONCTROLCONTAINER_H @@ -1329,7 +1323,6 @@ class SA_RIBBON_EXPORT SARibbonCtrlContainer : public QWidget /*** End of inlined file: SARibbonCtrlContainer.h ***/ - /*** Start of inlined file: SARibbonQuickAccessBar.h ***/ #ifndef SARIBBONQUICKACCESSBAR_H #define SARIBBONQUICKACCESSBAR_H @@ -1350,12 +1343,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; @@ -1368,7 +1361,6 @@ class SA_RIBBON_EXPORT SARibbonQuickAccessBar : public SARibbonCtrlContainer /*** End of inlined file: SARibbonQuickAccessBar.h ***/ - /*** Start of inlined file: SARibbonTabBar.h ***/ #ifndef SARIBBONTABBAR_H #define SARIBBONTABBAR_H @@ -1395,7 +1387,6 @@ class SA_RIBBON_EXPORT SARibbonTabBar : public QTabBar /*** End of inlined file: SARibbonTabBar.h ***/ - /*** Start of inlined file: SARibbonControlButton.h ***/ #ifndef SARIBBONCONTROLBUTTON_H #define SARIBBONCONTROLBUTTON_H @@ -1429,7 +1420,6 @@ class SA_RIBBON_EXPORT SARibbonControlToolButton : public QToolButton /*** End of inlined file: SARibbonControlButton.h ***/ - /*** Start of inlined file: SARibbonMenu.h ***/ #ifndef SARIBBONMENU_H #define SARIBBONMENU_H @@ -1456,7 +1446,6 @@ class SA_RIBBON_EXPORT SARibbonMenu : public QMenu /*** End of inlined file: SARibbonMenu.h ***/ - /*** Start of inlined file: SARibbonPannelOptionButton.h ***/ #ifndef SARIBBONPANNELOPTIONBUTTON_H #define SARIBBONPANNELOPTIONBUTTON_H @@ -1484,7 +1473,6 @@ class SA_RIBBON_EXPORT SARibbonPannelOptionButton : public QToolButton /*** End of inlined file: SARibbonPannelOptionButton.h ***/ - /*** Start of inlined file: SARibbonPannelItem.h ***/ #ifndef SARIBBONPANNELITEM_H #define SARIBBONPANNELITEM_H @@ -1537,7 +1525,6 @@ class SA_RIBBON_EXPORT SARibbonPannelItem : public QWidgetItem /*** End of inlined file: SARibbonPannelItem.h ***/ - /*** Start of inlined file: SARibbonPannelLayout.h ***/ #ifndef SARIBBONPANNELLAYOUT_H #define SARIBBONPANNELLAYOUT_H @@ -1651,7 +1638,6 @@ class SA_RIBBON_EXPORT SARibbonPannelLayout : public QLayout /*** End of inlined file: SARibbonPannelLayout.h ***/ - /*** Start of inlined file: SARibbonPannel.h ***/ #ifndef SARIBBONPANNEL_H #define SARIBBONPANNEL_H @@ -1717,8 +1703,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,在三行模式下会以中图标显示 @@ -1734,14 +1720,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); @@ -1875,7 +1861,6 @@ class SA_RIBBON_EXPORT SARibbonPannel : public QFrame /*** End of inlined file: SARibbonPannel.h ***/ - /*** Start of inlined file: SARibbonCategory.h ***/ #ifndef SARIBBONCATEGORY_H #define SARIBBONCATEGORY_H @@ -1886,6 +1871,7 @@ class SA_RIBBON_EXPORT SARibbonPannel : public QFrame #include #include +class QAction; class QHBoxLayout; class QWheelEvent; class SARibbonBar; @@ -1998,6 +1984,12 @@ class SA_RIBBON_EXPORT SARibbonCategory : public QFrame */ void categoryNameChanged(const QString& n); + /** + * @brief 参考QToolBar::actionTriggered的信号 + * @param action + */ + void actionTriggered(QAction* action); + protected: virtual bool event(QEvent* e) Q_DECL_OVERRIDE; // 处理滚轮事件 @@ -2028,7 +2020,6 @@ class SA_RIBBON_EXPORT SARibbonCategoryScrollButton : public QToolButton /*** End of inlined file: SARibbonCategory.h ***/ - /*** Start of inlined file: SARibbonCategoryLayout.h ***/ #ifndef SARIBBONCATEGORYLAYOUT_H #define SARIBBONCATEGORYLAYOUT_H @@ -2126,7 +2117,6 @@ class SA_RIBBON_EXPORT SARibbonCategoryLayoutItem : public QWidgetItem /*** End of inlined file: SARibbonCategoryLayout.h ***/ - /*** Start of inlined file: SARibbonContextCategory.h ***/ #ifndef SARIBBONCONTEXTCATEGORY_H #define SARIBBONCONTEXTCATEGORY_H @@ -2143,34 +2133,34 @@ class SA_RIBBON_EXPORT SARibbonContextCategory : public QObject public: SARibbonContextCategory(QWidget* parent = 0); ~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; signals: /** @@ -2201,7 +2191,7 @@ private slots: void onCategoryTitleChanged(const QString& title); protected: - //获取父级窗口 + // 获取父级窗口 QWidget* parentWidget() const; virtual bool eventFilter(QObject* watched, QEvent* e) override; }; @@ -2210,7 +2200,6 @@ private slots: /*** End of inlined file: SARibbonContextCategory.h ***/ - /*** Start of inlined file: SARibbonGalleryItem.h ***/ #ifndef SARIBBONGALLERYITEM_H #define SARIBBONGALLERYITEM_H @@ -2278,7 +2267,6 @@ class SA_RIBBON_EXPORT SARibbonGalleryItem /*** End of inlined file: SARibbonGalleryItem.h ***/ - /*** Start of inlined file: SARibbonGalleryGroup.h ***/ #ifndef SARIBBONGALLERYGROUP_H #define SARIBBONGALLERYGROUP_H @@ -2419,7 +2407,6 @@ private slots: /*** End of inlined file: SARibbonGalleryGroup.h ***/ - /*** Start of inlined file: SARibbonGallery.h ***/ #ifndef SARIBBONGALLERY_H #define SARIBBONGALLERY_H @@ -2548,7 +2535,6 @@ public slots: /*** End of inlined file: SARibbonGallery.h ***/ - /*** Start of inlined file: SARibbonBar.h ***/ #ifndef SARIBBONBAR_H #define SARIBBONBAR_H @@ -2557,6 +2543,7 @@ public slots: #include #include +class QAction; class QAbstractButton; class SARibbonElementFactory; class SARibbonTabBar; @@ -2582,16 +2569,16 @@ class SARibbonStackedWidget; @code void MainWindow::MainWindow() { - QMenu *fileMenu = menuBar()->addMenu(tr("&File")); - QToolBar *fileToolBar = addToolBar(tr("File")); - //生成action - QAction *newAct = new QAction(newIcon, tr("&New"), this); - fileMenu->addAction(newAct); - fileToolBar->addAction(newAct); - - QAction *openAct = new QAction(openIcon, tr("&Open..."), this); - fileMenu->addAction(openAct); - fileToolBar->addAction(openAct); + QMenu *fileMenu = menuBar()->addMenu(tr("&File")); + QToolBar *fileToolBar = addToolBar(tr("File")); + //生成action + QAction *newAct = new QAction(newIcon, tr("&New"), this); + fileMenu->addAction(newAct); + fileToolBar->addAction(newAct); + + QAction *openAct = new QAction(openIcon, tr("&Open..."), this); + fileMenu->addAction(openAct); + fileToolBar->addAction(openAct); } @endcode @@ -2621,20 +2608,20 @@ class SARibbonStackedWidget; //建立ui void setupRibbonUi() { - ...... - //ribbonwindow为SARibbonMainWindow - SARibbonBar* ribbon = ribbonwindow->ribbonBar(); - ribbon->setRibbonStyle(SARibbonBar::WpsLiteStyle); - //添加一个Main标签 - categoryMain = ribbon->addCategoryPage(QStringLiteral("Main")); - //Main标签下添加一个File Pannel - FilePannel = categoryMain->addPannel(QStringLiteral("FilePannel")); - //开始为File Pannel添加action - FilePannel->addLargeAction(actionNew); - FilePannel->addLargeAction(actionOpen); - FilePannel->addLargeAction(actionSave); - FilePannel->addSmallAction(actionImportMesh); - FilePannel->addSmallAction(actionImportGeometry); + ...... + //ribbonwindow为SARibbonMainWindow + SARibbonBar* ribbon = ribbonwindow->ribbonBar(); + ribbon->setRibbonStyle(SARibbonBar::WpsLiteStyle); + //添加一个Main标签 + categoryMain = ribbon->addCategoryPage(QStringLiteral("Main")); + //Main标签下添加一个File Pannel + FilePannel = categoryMain->addPannel(QStringLiteral("FilePannel")); + //开始为File Pannel添加action + FilePannel->addLargeAction(actionNew); + FilePannel->addLargeAction(actionOpen); + FilePannel->addLargeAction(actionSave); + FilePannel->addSmallAction(actionImportMesh); + FilePannel->addSmallAction(actionImportGeometry); } @endcode */ @@ -2756,8 +2743,8 @@ class SA_RIBBON_EXPORT SARibbonBar : public QMenuBar // 添加一个上下文标签 SARibbonContextCategory* addContextCategory(const QString& title, - const QColor& color = QColor(), - const QVariant& id = QVariant()); + const QColor& color = QColor(), + const QVariant& id = QVariant()); void addContextCategory(SARibbonContextCategory* context); // 显示一个上下文标签 @@ -2942,6 +2929,12 @@ class SA_RIBBON_EXPORT SARibbonBar : public QMenuBar */ void titleBarHeightChanged(int oldHeight, int newHeight); + /** + * @brief 参考QToolBar::actionTriggered的信号 + * @param action + */ + void actionTriggered(QAction* action); + protected: bool eventFilter(QObject* obj, QEvent* e) override; // 根据情况重置tabbar的宽度,主要针对wps模式 @@ -2994,7 +2987,6 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(SARibbonBar::RibbonStyles) /*** End of inlined file: SARibbonBar.h ***/ - /*** Start of inlined file: SARibbonElementFactory.h ***/ #ifndef SARIBBONELEMENTFACTORY_H #define SARIBBONELEMENTFACTORY_H @@ -3056,7 +3048,6 @@ class SA_RIBBON_EXPORT SARibbonElementFactory /*** End of inlined file: SARibbonElementFactory.h ***/ - /*** Start of inlined file: SARibbonElementManager.h ***/ #ifndef SARIBBONELEMENTMANAGER_H #define SARIBBONELEMENTMANAGER_H @@ -3064,26 +3055,26 @@ class SA_RIBBON_EXPORT SARibbonElementFactory /** @brief 此类是一个全局单例,用于管理SARibbonElementFactory - 如果你有自己的某个部件要重写,首先你需要有自己的ElementFactory - @code - class MyRibbonElementFactory : public SARibbonElementFactory{ - public: - ... - virtual SARibbonPannel* createRibbonPannel(QWidget* parent){ - return new MyRibbonPannel(parent); - } - }; - @endcode + 如果你有自己的某个部件要重写,首先你需要有自己的ElementFactory + @code + class MyRibbonElementFactory : public SARibbonElementFactory{ + public: + ... + virtual SARibbonPannel* createRibbonPannel(QWidget* parent){ + return new MyRibbonPannel(parent); + } + }; + @endcode - 然后,你需要在ribbonbar创建之前把自己的ElementFactory设置进去 + 然后,你需要在ribbonbar创建之前把自己的ElementFactory设置进去 - 这个一般会在main函数中进行 + 这个一般会在main函数中进行 - @code - SARibbonElementManager::instance()->setupFactory(new MyRibbonElementFactory); - @endcode + @code + SARibbonElementManager::instance()->setupFactory(new MyRibbonElementFactory); + @endcode - 这样,SARibbon创建的pannel就是你自己重写的MyRibbonPannel + 这样,SARibbon创建的pannel就是你自己重写的MyRibbonPannel */ class SA_RIBBON_EXPORT SARibbonElementManager @@ -3111,7 +3102,6 @@ class SA_RIBBON_EXPORT SARibbonElementManager /*** End of inlined file: SARibbonElementManager.h ***/ - /*** Start of inlined file: SARibbonCustomizeData.h ***/ #ifndef SARIBBONCUSTOMIZEDATA_H #define SARIBBONCUSTOMIZEDATA_H @@ -3145,80 +3135,83 @@ class SA_RIBBON_EXPORT SARibbonCustomizeData }; SARibbonCustomizeData(); SARibbonCustomizeData(ActionType type, SARibbonActionsManager* mgr = nullptr); - //获取CustomizeData的action type + // 获取CustomizeData的action type ActionType actionType() const; - //设置CustomizeData的action type + // 设置CustomizeData的action type void setActionType(ActionType a); - //判断是否是一个正常的CustomizeData + // 判断是否是一个正常的CustomizeData bool isValid() const; - //应用SARibbonCustomizeData + // 应用SARibbonCustomizeData bool apply(SARibbonBar* bar) const; - //获取actionmanager指针 + // 获取actionmanager指针 SARibbonActionsManager* actionManager(); - //设置ActionsManager + // 设置ActionsManager void setActionsManager(SARibbonActionsManager* mgr); - //对应AddCategoryActionType + // 对应AddCategoryActionType 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); + // 对应AddPannelActionType + static SARibbonCustomizeData makeAddPannelCustomizeData(const QString& title, + int index, + const QString& categoryobjName, + const QString& objName); - //对应AddActionActionType + // 对应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 + // 对应RenameCategoryActionType static SARibbonCustomizeData makeRenameCategoryCustomizeData(const QString& newname, const QString& categoryobjName); - //对应RenamePannelActionType + // 对应RenamePannelActionType static SARibbonCustomizeData makeRenamePannelCustomizeData(const QString& newname, - const QString& categoryobjName, - const QString& pannelObjName); + const QString& categoryobjName, + const QString& pannelObjName); - //对应RemoveCategoryActionType + // 对应RemoveCategoryActionType static SARibbonCustomizeData makeRemoveCategoryCustomizeData(const QString& categoryobjName); - //对应ChangeCategoryOrderActionType + // 对应ChangeCategoryOrderActionType static SARibbonCustomizeData makeChangeCategoryOrderCustomizeData(const QString& categoryobjName, int moveindex); - //对应ChangePannelOrderActionType + // 对应ChangePannelOrderActionType static SARibbonCustomizeData makeChangePannelOrderCustomizeData(const QString& categoryobjName, - const QString& pannelObjName, - int moveindex); + const QString& pannelObjName, + int moveindex); - //对应ChangeActionOrderActionType + // 对应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 + // 对应RemovePannelActionType static SARibbonCustomizeData makeRemovePannelCustomizeData(const QString& categoryobjName, const QString& pannelObjName); - //对应RemoveActionActionType + // 对应RemoveActionActionType static SARibbonCustomizeData makeRemoveActionCustomizeData(const QString& categoryobjName, - const QString& pannelObjName, - const QString& key, - SARibbonActionsManager* mgr); + const QString& pannelObjName, + const QString& key, + SARibbonActionsManager* mgr); - //对应VisibleCategoryActionType + // 对应VisibleCategoryActionType static SARibbonCustomizeData makeVisibleCategoryCustomizeData(const QString& categoryobjName, bool isShow); - //判断是否可以自定义,如果某个action不想被编辑,可以通过此函数设置 + // 判断是否可以自定义,如果某个action不想被编辑,可以通过此函数设置 static bool isCanCustomize(QObject* obj); static void setCanCustomize(QObject* obj, bool canbe = true); - //对QList进行简化 + // 对QList进行简化 static QList< SARibbonCustomizeData > simplify(const QList< SARibbonCustomizeData >& csd); public: @@ -3263,7 +3256,6 @@ typedef QList< SARibbonCustomizeData > SARibbonCustomizeDataList; /*** End of inlined file: SARibbonCustomizeData.h ***/ - /*** Start of inlined file: SARibbonCustomizeWidget.h ***/ #ifndef SARIBBONCUSTOMIZEWIDGET_H #define SARIBBONCUSTOMIZEWIDGET_H @@ -3293,9 +3285,11 @@ class SA_RIBBON_EXPORT SARibbonCustomizeWidget : public QWidget Q_OBJECT SA_RIBBON_DECLARE_PRIVATE(SARibbonCustomizeWidget) public: - //保留接口 - SARibbonCustomizeWidget(SARibbonMainWindow* ribbonWindow, QWidget* parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); - //对于不使用SARibbonMainWindow的情况,使用此构造函数 + // 保留接口 + SARibbonCustomizeWidget(SARibbonMainWindow* ribbonWindow, + QWidget* parent = nullptr, + Qt::WindowFlags f = Qt::WindowFlags()); + // 对于不使用SARibbonMainWindow的情况,使用此构造函数 SARibbonCustomizeWidget(SARibbonBar* ribbonbar, QWidget* parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); ~SARibbonCustomizeWidget(); @@ -3313,57 +3307,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; @@ -3373,24 +3367,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 slots: @@ -3436,7 +3430,8 @@ bool SA_RIBBON_EXPORT sa_customize_datas_to_xml(QXmlStreamWriter* xml, const QLi * @param xml * @return QList */ -QList< SARibbonCustomizeData > SA_RIBBON_EXPORT sa_customize_datas_from_xml(QXmlStreamReader* xml, SARibbonActionsManager* mgr); +QList< SARibbonCustomizeData > SA_RIBBON_EXPORT sa_customize_datas_from_xml(QXmlStreamReader* xml, + SARibbonActionsManager* mgr); /** * @brief 应用QList @@ -3474,7 +3469,6 @@ bool SA_RIBBON_EXPORT sa_apply_customize_from_xml_file(const QString& filePath, /*** End of inlined file: SARibbonCustomizeWidget.h ***/ - /*** Start of inlined file: SARibbonCustomizeDialog.h ***/ #ifndef SARIBBONCUSTOMIZEDIALOG_H #define SARIBBONCUSTOMIZEDIALOG_H @@ -3498,44 +3492,43 @@ class SA_RIBBON_EXPORT SARibbonCustomizeDialog : public QDialog { Q_OBJECT public: - SARibbonCustomizeDialog(SARibbonMainWindow *ribbonWindow, QWidget *p = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); - //设置action管理器 - void setupActionsManager(SARibbonActionsManager *mgr); + SARibbonCustomizeDialog(SARibbonMainWindow* ribbonWindow, QWidget* p = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); + // 设置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 +#endif // SARIBBONCUSTOMIZEDIALOG_H /*** End of inlined file: SARibbonCustomizeDialog.h ***/ - /*** Start of inlined file: SARibbonMainWindow.h ***/ #ifndef SARIBBONMAINWINDOW_H #define SARIBBONMAINWINDOW_H @@ -3545,7 +3538,7 @@ class SA_RIBBON_EXPORT SARibbonCustomizeDialog : public QDialog #if !SARIBBON_USE_3RDPARTY_FRAMELESSHELPER class SAFramelessHelper; #endif - +class QAction; class SARibbonBar; class SARibbonSystemButtonBar; class QScreen; @@ -3616,23 +3609,58 @@ private slots: void onPrimaryScreenChanged(QScreen* screen); }; +#endif // SARIBBONMAINWINDOW_H + +/*** End of inlined file: SARibbonMainWindow.h ***/ + +/*** Start of inlined file: SARibbonWidget.h ***/ +#ifndef SARIBBONWIDGET_H +#define SARIBBONWIDGET_H + +#include + +class SARibbonBar; +class QScreen; /** - * @brief 全局的设置ribbon theme函数 + * @brief 带SARibbonBar的Widget * - * 之所以提供此函数,是因为在某些情况下,SARibbonBar不用在SARibbonMainWindow情况下的时候,也需要设置主题, - * 但主题设置是在SARibbonMainWindow下的为了能在非SARibbonMainWindow下也能设置主题,这里提供@sa sa_set_ribbon_theme函数, - * 可以这样使用: - * @code - * @endcode + * @note 注意,SARibbonWidget利用了布局来把ribbonbar放到最顶部,不要给此widget添加布局,否则会导致布局异常, + * 正确的做法是把布局的窗口通过setWidget设置进SARibbonWidget * - * @param w - * @param theme */ -void SA_RIBBON_EXPORT sa_set_ribbon_theme(QWidget* w, SARibbonTheme theme); +class SA_RIBBON_EXPORT SARibbonWidget : public QWidget +{ + Q_OBJECT + SA_RIBBON_DECLARE_PRIVATE(SARibbonWidget) + friend class SARibbonBar; + Q_PROPERTY(SARibbonTheme ribbonTheme READ ribbonTheme WRITE setRibbonTheme) -#endif // SARIBBONMAINWINDOW_H +public: + SARibbonWidget(QWidget* parent = nullptr); + ~SARibbonWidget() Q_DECL_OVERRIDE; + // 返回SARibbonBar + SARibbonBar* ribbonBar() const; + // 设置ribbonbar + void setRibbonBar(SARibbonBar* bar); -/*** End of inlined file: SARibbonMainWindow.h ***/ + // 注意主题在构造函数设置主题会不完全生效,使用QTimer投放到队列最后执行即可 + // QTimer::singleShot(0, this, [ this ]() { this->setRibbonTheme(SARibbonTheme::RibbonThemeDark); }); + void setRibbonTheme(SARibbonTheme theme); + SARibbonTheme ribbonTheme() const; + // 判断当前是否使用ribbon模式 + bool isUseRibbon() const; + // 设置窗口 + void setWidget(QWidget* w); + QWidget* widget() const; + // + QWidget* takeWidget(); +private slots: + void onPrimaryScreenChanged(QScreen* screen); +}; + +#endif // SARIBBONWIDGET_H + +/*** End of inlined file: SARibbonWidget.h ***/ /*** End of inlined file: SARibbonAmalgamTemplatePublicHeaders.h ***/ diff --git a/src/SARibbonBar/SARibbonBar.pri b/src/SARibbonBar/SARibbonBar.pri index 12b3e59..9609f35 100644 --- a/src/SARibbonBar/SARibbonBar.pri +++ b/src/SARibbonBar/SARibbonBar.pri @@ -68,7 +68,8 @@ SOURCES += \ $$PWD/SARibbonCtrlContainer.cpp \ $$PWD/SARibbonPannelLayout.cpp \ $$PWD/SARibbonPannelItem.cpp \ - $$PWD/SARibbonLineWidgetContainer.cpp + $$PWD/SARibbonLineWidgetContainer.cpp \ + $$PWD/SARibbonWidget.cpp HEADERS += \ $$PWD/SAFramelessHelper.h \ @@ -106,7 +107,8 @@ HEADERS += \ $$PWD/SARibbonCtrlContainer.h \ $$PWD/SARibbonPannelLayout.h \ $$PWD/SARibbonPannelItem.h \ - $$PWD/SARibbonLineWidgetContainer.h + $$PWD/SARibbonLineWidgetContainer.h \ + $$PWD/SARibbonWidget.h RESOURCES += \ $$PWD/resource.qrc diff --git a/src/SARibbonBar/SARibbonGlobal.h b/src/SARibbonBar/SARibbonGlobal.h index 4b53b1f..c774faa 100644 --- a/src/SARibbonBar/SARibbonGlobal.h +++ b/src/SARibbonBar/SARibbonGlobal.h @@ -18,13 +18,13 @@ class QWidget; * @def ribbon的数字版本 MAJ.{MIN}.PAT */ #ifndef SA_RIBBON_BAR_VERSION_MIN -#define SA_RIBBON_BAR_VERSION_MIN 0 +#define SA_RIBBON_BAR_VERSION_MIN 1 #endif /** * @def ribbon的数字版本 MAJ.MIN.{PAT} */ #ifndef SA_RIBBON_BAR_VERSION_PAT -#define SA_RIBBON_BAR_VERSION_PAT 4 +#define SA_RIBBON_BAR_VERSION_PAT 0 #endif #ifndef SA_RIBBON_BAR_NO_EXPORT @@ -70,7 +70,7 @@ enum class SARibbonAlignment /** * @brief ribbon主题 - * + * * 注意,由于有些qss的尺寸,在C++代码中无法获取到,因此针对用户自定义的qss主题,有些尺寸是需要手动设置进去的 * * 例如ribbon tab的margin信息,在QTabBar是无法获取到,而这个影响了SARibbonContextCategory的绘制, @@ -86,9 +86,6 @@ enum class SARibbonTheme RibbonThemeDark2 }; - - - /** * @def 属性,用于标记是否可以进行自定义,用于动态设置到@ref SARibbonCategory 和@ref SARibbonPannel * 值为bool,在为true时,可以通过@ref SARibbonCustomizeWidget 改变这个SARibbonCategory和SARibbonPannel的布局, @@ -155,7 +152,6 @@ enum class SARibbonTheme #define SA_DEBUG_PRINT_SARIBBONBAR 1 #endif - /** * @brief 全局的设置ribbon theme函数 * @@ -170,5 +166,4 @@ enum class SARibbonTheme */ void SA_RIBBON_EXPORT sa_set_ribbon_theme(QWidget* w, SARibbonTheme theme); - #endif // SARIBBONGLOBAL_H diff --git a/src/example/WidgetWithRibbon/WidgetWithRibbon.pro b/src/example/WidgetWithRibbon/WidgetWithRibbon.pro index f1674da..376bdfb 100644 --- a/src/example/WidgetWithRibbon/WidgetWithRibbon.pro +++ b/src/example/WidgetWithRibbon/WidgetWithRibbon.pro @@ -17,13 +17,18 @@ DEFINES += QT_DEPRECATED_WARNINGS SOURCES += \ main.cpp \ - Widget.cpp + RibbonWidget.cpp \ + MainWidget.cpp \ + InnerWidget.cpp HEADERS += \ - Widget.h + RibbonWidget.h \ + MainWidget.h \ + InnerWidget.h FORMS += \ - Widget.ui + InnerWidget.ui \ + MainWidget.ui # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin diff --git a/tools/amalgamate/SARibbonAmalgamTemplate.cpp b/tools/amalgamate/SARibbonAmalgamTemplate.cpp index 15cf8d1..391bc4a 100644 --- a/tools/amalgamate/SARibbonAmalgamTemplate.cpp +++ b/tools/amalgamate/SARibbonAmalgamTemplate.cpp @@ -61,7 +61,7 @@ #include "../../src/SARibbonBar/SARibbonCustomizeWidget.cpp" #include "../../src/SARibbonBar/SARibbonCustomizeDialog.cpp" #include "../../src/SARibbonBar/SARibbonMainWindow.cpp" - +#include "../../src/SARibbonBar/SARibbonWidget.cpp" #ifdef _MSC_VER #pragma warning (pop) #pragma pop_macro ("_CRT_SECURE_NO_WARNINGS") diff --git a/tools/amalgamate/SARibbonAmalgamTemplatePublicHeaders.h b/tools/amalgamate/SARibbonAmalgamTemplatePublicHeaders.h index e682bd1..831d6f1 100644 --- a/tools/amalgamate/SARibbonAmalgamTemplatePublicHeaders.h +++ b/tools/amalgamate/SARibbonAmalgamTemplatePublicHeaders.h @@ -43,4 +43,4 @@ #include "../../src/SARibbonBar/SARibbonCustomizeWidget.h" #include "../../src/SARibbonBar/SARibbonCustomizeDialog.h" #include "../../src/SARibbonBar/SARibbonMainWindow.h" - +#include "../../src/SARibbonBar/SARibbonWidget.h"