Skip to content

Commit

Permalink
调整可见性判断
Browse files Browse the repository at this point in the history
  • Loading branch information
czyt1988 committed Dec 26, 2023
1 parent 2937ea0 commit 6f74dd3
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 32 deletions.
4 changes: 0 additions & 4 deletions src/SARibbonBar/SARibbonApplicationButton.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#include "SARibbonApplicationButton.h"

#define SARIBBON_APPLICATION_BUTTON_MINIMUM_WIDTH 40
SARibbonApplicationButton::SARibbonApplicationButton(QWidget* parent) : QToolButton(parent)
{
setFocusPolicy(Qt::NoFocus);
setAutoRaise(true);
setPopupMode(QToolButton::InstantPopup);
setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
setMinimumWidth(SARIBBON_APPLICATION_BUTTON_MINIMUM_WIDTH);
}

SARibbonApplicationButton::SARibbonApplicationButton(const QString& text, QWidget* parent) : QToolButton(parent)
Expand All @@ -17,7 +15,6 @@ SARibbonApplicationButton::SARibbonApplicationButton(const QString& text, QWidge
setPopupMode(QToolButton::InstantPopup);
setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
setText(text);
setMinimumWidth(SARIBBON_APPLICATION_BUTTON_MINIMUM_WIDTH);
}

SARibbonApplicationButton::SARibbonApplicationButton(const QIcon& icon, const QString& text, QWidget* parent)
Expand All @@ -29,5 +26,4 @@ SARibbonApplicationButton::SARibbonApplicationButton(const QIcon& icon, const QS
setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
setIcon(icon);
setText(text);
setMinimumWidth(SARIBBON_APPLICATION_BUTTON_MINIMUM_WIDTH);
}
28 changes: 14 additions & 14 deletions src/SARibbonBar/SARibbonBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ QList< QColor > SARibbonBar::getDefaultContextCategoryColorList()
<< QColor(14, 81, 167) //
<< QColor(228, 0, 69) //
<< QColor(67, 148, 0) // 绿
;
;
return res;
}

Expand Down Expand Up @@ -967,11 +967,11 @@ void SARibbonBar::showMinimumModeButton(bool isShow)

d_ptr->mMinimumCategoryButtonAction = new QAction(this);
d_ptr->mMinimumCategoryButtonAction->setIcon(
style()->standardIcon(isMinimumMode() ? QStyle::SP_TitleBarUnshadeButton : QStyle::SP_TitleBarShadeButton, nullptr));
style()->standardIcon(isMinimumMode() ? QStyle::SP_TitleBarUnshadeButton : QStyle::SP_TitleBarShadeButton, nullptr));
connect(d_ptr->mMinimumCategoryButtonAction, &QAction::triggered, this, [ this ]() {
this->setMinimumMode(!isMinimumMode());
this->d_ptr->mMinimumCategoryButtonAction->setIcon(
style()->standardIcon(isMinimumMode() ? QStyle::SP_TitleBarUnshadeButton : QStyle::SP_TitleBarShadeButton, nullptr));
style()->standardIcon(isMinimumMode() ? QStyle::SP_TitleBarUnshadeButton : QStyle::SP_TitleBarShadeButton, nullptr));
});
d_ptr->mRightButtonGroup->addAction(d_ptr->mMinimumCategoryButtonAction);

Expand Down Expand Up @@ -1821,7 +1821,7 @@ void SARibbonBar::paintInNormalStyle()
titleRegion.setRect(d_ptr->mQuickAccessBar->geometry().right() + 1,
border.top(),
width() - d_ptr->mIconRightBorderPosition - border.right()
- d_ptr->mWindowButtonSize.width() - d_ptr->mQuickAccessBar->geometry().right() - 1,
- d_ptr->mWindowButtonSize.width() - d_ptr->mQuickAccessBar->geometry().right() - 1,
titleBarHeight());
} else {
int leftwidth = contextCategoryRegion.x() - d_ptr->mQuickAccessBar->geometry().right() - d_ptr->mIconRightBorderPosition;
Expand Down Expand Up @@ -2054,7 +2054,7 @@ void SARibbonBar::resizeInOfficeStyle()

x += d_ptr->mIconRightBorderPosition + 5;
if (QWidget* connerL = cornerWidget(Qt::TopLeftCorner)) {
if (connerL->isVisible()) {
if (connerL->isVisibleTo(this)) {
QSize connerSize = connerL->sizeHint();
if (connerSize.height() < validTitleBarHeight) {
int detal = (validTitleBarHeight - connerSize.height()) / 2;
Expand All @@ -2067,7 +2067,7 @@ void SARibbonBar::resizeInOfficeStyle()
}
// quick access bar定位
if (d_ptr->mQuickAccessBar) {
if (d_ptr->mQuickAccessBar->isVisible()) {
if (d_ptr->mQuickAccessBar->isVisibleTo(this)) {
if (d_ptr->mQuickAccessBar->height() != validTitleBarHeight) {
d_ptr->mQuickAccessBar->setFixedHeight(validTitleBarHeight);
}
Expand All @@ -2081,8 +2081,8 @@ void SARibbonBar::resizeInOfficeStyle()
y += validTitleBarHeight;
// applicationButton 定位
if (d_ptr->mApplicationButton) {
if (d_ptr->mApplicationButton->isVisible()) {
d_ptr->mApplicationButton->setGeometry(x, y, d_ptr->mApplicationButton->size().width(), tabH);
if (d_ptr->mApplicationButton->isVisibleTo(this)) {
d_ptr->mApplicationButton->setGeometry(x, y, d_ptr->mApplicationButton->sizeHint().width(), tabH);
x = d_ptr->mApplicationButton->geometry().right();
}
}
Expand All @@ -2093,7 +2093,7 @@ void SARibbonBar::resizeInOfficeStyle()
int endX = width() - border.right();

if (QWidget* connerW = cornerWidget(Qt::TopRightCorner)) {
if (connerW->isVisible()) {
if (connerW->isVisibleTo(this)) {
QSize connerSize = connerW->sizeHint();
endX -= connerSize.width();
if (connerSize.height() < tabH) {
Expand Down Expand Up @@ -2149,7 +2149,7 @@ void SARibbonBar::resizeInWpsLiteStyle()
int endX = width() - border.right() - d_ptr->mWindowButtonSize.width();

if (QWidget* connerW = cornerWidget(Qt::TopRightCorner)) {
if (connerW->isVisible()) {
if (connerW->isVisibleTo(this)) {
QSize connerSize = connerW->sizeHint();
endX -= connerSize.width();
if (connerSize.height() < validTitleBarHeight) {
Expand All @@ -2171,7 +2171,7 @@ void SARibbonBar::resizeInWpsLiteStyle()
}
// quick access bar定位
if (d_ptr->mQuickAccessBar) {
if (d_ptr->mQuickAccessBar->isVisible()) {
if (d_ptr->mQuickAccessBar->isVisibleTo(this)) {
QSize quickAccessBarSize = d_ptr->mQuickAccessBar->sizeHint();
endX -= quickAccessBarSize.width();
// 上下留1px的边线
Expand All @@ -2180,7 +2180,7 @@ void SARibbonBar::resizeInWpsLiteStyle()
}
// cornerWidget - TopLeftCorner
if (QWidget* connerL = cornerWidget(Qt::TopLeftCorner)) {
if (connerL->isVisible()) {
if (connerL->isVisibleTo(this)) {
QSize connerSize = connerL->sizeHint();
endX -= connerSize.width();
if (connerSize.height() < validTitleBarHeight) {
Expand All @@ -2203,8 +2203,8 @@ void SARibbonBar::resizeInWpsLiteStyle()

// applicationButton 定位,与TabBar同高
if (d_ptr->mApplicationButton) {
if (d_ptr->mApplicationButton->isVisible()) {
d_ptr->mApplicationButton->setGeometry(x, y, d_ptr->mApplicationButton->size().width(), tabH);
if (d_ptr->mApplicationButton->isVisibleTo(this)) {
d_ptr->mApplicationButton->setGeometry(x, y, d_ptr->mApplicationButton->sizeHint().width(), tabH);
x = d_ptr->mApplicationButton->geometry().right() + 2;
}
}
Expand Down
9 changes: 9 additions & 0 deletions src/SARibbonBar/SARibbonMainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,15 @@ Qt::WindowFlags SARibbonMainWindow::windowButtonFlags() const
return (windowFlags());
}

/**
* @brief SARibbonMainWindow::setRibbonTheme
*
* 注意主题在构造函数设置主题会不完全生效,使用QTimer投放到队列最后执行即可
* @code
* QTimer::singleShot(0, this, [ this ]() { this->setRibbonTheme(SARibbonMainWindow::RibbonThemeDark); });
* @endcode
* @param theme
*/
void SARibbonMainWindow::setRibbonTheme(SARibbonMainWindow::RibbonTheme theme)
{
sa_set_ribbon_theme(this, theme);
Expand Down
3 changes: 3 additions & 0 deletions src/SARibbonBar/SARibbonMainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ class SA_RIBBON_EXPORT SARibbonMainWindow : public QMainWindow
void updateWindowFlag(Qt::WindowFlags flags);
// 获取系统按钮的状态
Qt::WindowFlags windowButtonFlags() const;

// 注意主题在构造函数设置主题会不完全生效,使用QTimer投放到队列最后执行即可
// QTimer::singleShot(0, this, [ this ]() { this->setRibbonTheme(SARibbonMainWindow::RibbonThemeDark); });
void setRibbonTheme(RibbonTheme theme);
RibbonTheme ribbonTheme() const;
// 判断当前是否使用ribbon模式
Expand Down
26 changes: 13 additions & 13 deletions src/example/MainWindowExample/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ MainWindow::MainWindow(QWidget* par)
//! 添加主标签页,这里演示通过SARibbonBar::addCategoryPage函数添加一个标签页
//! en:
//! Add the main tab. Here we show how to add a tab through the SARibbonBar::addCategoryPage function
SARibbonCategory* categoryMain = ribbon->addCategoryPage(tr("Main"));
SARibbonCategory* categoryMain = ribbon->addCategoryPage(tr("&Main"));

//! cn: SARibbonBar的Category和Pannel,以及对应的Action都应该设置ObjectName,因为如果要自定义action,这些ObjectName是必不可少的
//! en: The category , pannel and actions of SARibbonBar, should be set with Object Names, as these Object Names are essential for customizing actions
Expand Down Expand Up @@ -176,7 +176,7 @@ void MainWindow::createRibbonApplicationButton()
btn = new SARibbonApplicationButton(this);
ribbon->setApplicationButton(btn);
}
ribbon->applicationButton()->setText((" File ")); // 文字两边留有间距,好看一点
ribbon->applicationButton()->setText((" &File ")); // 文字两边留有间距,好看一点
// cn: SARibbonMenu和QMenu的操作是一样的
// en: The operations of SARibbonMenu and QMenu are the same
if (!mMenuApplicationBtn) {
Expand Down Expand Up @@ -214,14 +214,14 @@ void MainWindow::onStyleClicked(int id)
switch (ribbonStyle) {
case SARibbonBar::RibbonStyleLooseThreeRow:
mTextedit->append(
tr("\nchange ribbon style to office style,The standard office style text display is line wrapped, "
"and you can also control whether it wrap through SARibbonToolButton::setEnableWordWrap")); // cn:标准的office样式的文字显示是换行的,你也可以通过SARibbonToolButton::setEnableWordWrap来控制它是否换行
tr("\nchange ribbon style to office style,The standard office style text display is line wrapped, "
"and you can also control whether it wrap through SARibbonToolButton::setEnableWordWrap")); // cn:标准的office样式的文字显示是换行的,你也可以通过SARibbonToolButton::setEnableWordWrap来控制它是否换行
mTextedit->append(tr("ribbonBar()->setRibbonStyle(SARibbonBar::OfficeStyle);"));
break;
case SARibbonBar::RibbonStyleLooseTwoRow:
mTextedit->append(
tr("\nchange ribbon style to office style 2 row,All text in 2-line mode does not wrap, and you "
"can also control whether it wraps through SARibbonToolButton: setEnableWordWrap")); // cn:所有2行模式的文字都是不换行的,你也可以通过SARibbonToolButton::setEnableWordWrap来控制它是否换行
tr("\nchange ribbon style to office style 2 row,All text in 2-line mode does not wrap, and you "
"can also control whether it wraps through SARibbonToolButton: setEnableWordWrap")); // cn:所有2行模式的文字都是不换行的,你也可以通过SARibbonToolButton::setEnableWordWrap来控制它是否换行
mTextedit->append(tr("ribbonBar()->setRibbonStyle(SARibbonBar::OfficeStyleTwoRow);"));
break;
case SARibbonBar::RibbonStyleCompactThreeRow:
Expand Down Expand Up @@ -295,7 +295,7 @@ void MainWindow::onActionHelpTriggered()
"\n Author:czy"
"\n Email:[email protected]"
"\n ===============")
.arg(SARibbonBar::versionString()));
.arg(SARibbonBar::versionString()));
}

void MainWindow::onActionRemoveAppBtnTriggered(bool b)
Expand All @@ -304,7 +304,7 @@ void MainWindow::onActionRemoveAppBtnTriggered(bool b)
ribbonBar()->setApplicationButton(nullptr);
} else {
SARibbonApplicationButton* actionRemoveAppBtn = new SARibbonApplicationButton();
actionRemoveAppBtn->setText(tr(" File "));
actionRemoveAppBtn->setText(tr(" &File "));
this->ribbonBar()->setApplicationButton(actionRemoveAppBtn);
createRibbonApplicationButton();
}
Expand Down Expand Up @@ -427,7 +427,7 @@ void MainWindow::onColorButtonColorClicked(const QColor& c, bool on)
void MainWindow::onRibbonThemeComboBoxCurrentIndexChanged(int index)
{
SARibbonMainWindow::RibbonTheme t = static_cast< SARibbonMainWindow::RibbonTheme >(
mComboboxRibbonTheme->itemData(index).toInt());
mComboboxRibbonTheme->itemData(index).toInt());
setRibbonTheme(t);
}

Expand Down Expand Up @@ -511,11 +511,11 @@ void MainWindow::createCategoryMain(SARibbonCategory* page)
SARibbonPannel* pannelStyle = page->addPannel(("ribbon style"));

QAction* actSave = createAction(tr("Save"), ":/icon/icon/save.svg");
//这样设置快捷键
// 这样设置快捷键
QShortcut* shortCut = new QShortcut(QKeySequence(QLatin1String("Ctrl+S")), this);
connect(shortCut, &QShortcut::activated, this, [ actSave ]() { actSave->trigger(); });
//这样设置是无效的
// actSave->setShortcut(QKeySequence(QLatin1String("Ctrl+S")));
// 这样设置是无效的
// actSave->setShortcut(QKeySequence(QLatin1String("Ctrl+S")));

connect(actSave, &QAction::triggered, this, [ this ](bool b) {
Q_UNUSED(b);
Expand Down Expand Up @@ -1096,7 +1096,7 @@ void MainWindow::createContextCategoryPage1(SARibbonCategory* page)
pannel->addLargeAction(mActionShowTest);

mPannelVisbileExample = page->addPannel(tr("show/hide"));
//重复添加
// 重复添加
mPannelVisbileExample->addLargeAction(mActionSetTextTest);

connect(mActionShowTest, &QAction::toggled, this, [ this ](bool b) {
Expand Down
19 changes: 18 additions & 1 deletion src/example/StaticExample/MainWindow.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "MainWindow.h"
#include "SARibbon.h"
#include <QComboBox>
#include <QTimer>
MainWindow::MainWindow(QWidget* parent) : SARibbonMainWindow(parent)
{
setWindowIcon(QIcon(":/app/icon/SA.svg"));
Expand All @@ -14,8 +16,23 @@ MainWindow::MainWindow(QWidget* parent) : SARibbonMainWindow(parent)
pannel->addAction(tr("action5"), QIcon(":/app/icon/folder-star.svg"), QToolButton::InstantPopup, SARibbonPannelItem::Small);
pannel->addAction(tr("action6"), QIcon(":/app/icon/test1.svg"), QToolButton::InstantPopup, SARibbonPannelItem::Small);
SARibbonCategory* otherCate = bar->addCategoryPage(tr("Other"));
Q_UNUSED(otherCate);
SARibbonPannel* pannel2 = otherCate->addPannel(tr("other"));
pannel2->addAction(tr("action1"), QIcon(":/app/icon/action.svg"), QToolButton::InstantPopup);
QComboBox* combo = new QComboBox(this);
pannel2->addMediumWidget(combo);
combo->addItem("RibbonThemeWindows7", static_cast< int >(SARibbonMainWindow::RibbonThemeWindows7));
combo->addItem("RibbonThemeOffice2013", static_cast< int >(SARibbonMainWindow::RibbonThemeOffice2013));
combo->addItem("RibbonThemeOffice2016Blue", static_cast< int >(SARibbonMainWindow::RibbonThemeOffice2016Blue));
combo->addItem("RibbonThemeOffice2021Blue", static_cast< int >(SARibbonMainWindow::RibbonThemeOffice2021Blue));
combo->addItem("RibbonThemeDark", static_cast< int >(SARibbonMainWindow::RibbonThemeDark));
connect(combo, QOverload< int >::of(&QComboBox::currentIndexChanged), [ this, combo ](int index) {
SARibbonMainWindow::RibbonTheme th = static_cast< SARibbonMainWindow::RibbonTheme >(combo->itemData(index).toInt());
this->setRibbonTheme(th);
});
resize(800, 600);
// 在构造函数设置主题会不完全生效
QTimer::singleShot(0, this, [ this ]() { this->setRibbonTheme(SARibbonMainWindow::RibbonThemeDark); });

// more example see MainWindowExample
}

Expand Down
1 change: 1 addition & 0 deletions src/example/WidgetWithRibbon/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ add_executable(${SARIBBON_EXPAMPLE_NAME}
Widget.cpp
main.cpp
icon.qrc
Widget.ui
)

target_include_directories(${SARIBBON_EXPAMPLE_NAME} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../../SARibbonBar")
Expand Down
15 changes: 15 additions & 0 deletions src/example/WidgetWithRibbon/Widget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,24 @@
</property>
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="tabShape">
<enum>QTabWidget::Triangular</enum>
</property>
<property name="currentIndex">
<number>0</number>
</property>
<property name="iconSize">
<size>
<width>22</width>
<height>22</height>
</size>
</property>
<property name="documentMode">
<bool>true</bool>
</property>
<property name="tabsClosable">
<bool>true</bool>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
<string>Tab 1</string>
Expand Down

0 comments on commit 6f74dd3

Please sign in to comment.