Skip to content

Commit

Permalink
SARibbonBar增加setWindowTitleBackgroundBrush
Browse files Browse the repository at this point in the history
- `SARibbonBar`增加`setWindowTitleBackgroundBrush`/`windowTitleBackgroundBrush`函数,允许用户设置标题栏的背景色
- 修正了`SARibbonBar`针对标题的渲染方式,能根据父窗口的`isWindowModified`状态,针对`[*]`占位符进行渲染
- 例子中增加了标题栏背景颜色周期改变的示例
  • Loading branch information
czyt1988 committed Feb 4, 2025
1 parent 18499a1 commit 68509da
Show file tree
Hide file tree
Showing 8 changed files with 435 additions and 334 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ cmake_minimum_required(VERSION 3.5)

set(SARIBBON_VERSION_MAJOR 2)
set(SARIBBON_VERSION_MINOR 2)
set(SARIBBON_VERSION_PATCH 8)
set(SARIBBON_VERSION_PATCH 9)
set(SARIBBON_VERSION "${SARIBBON_VERSION_MAJOR}.${SARIBBON_VERSION_MINOR}.${SARIBBON_VERSION_PATCH}")
message(STATUS "SARibbon v${SARIBBON_VERSION}")
project(SARibbon VERSION ${SARIBBON_VERSION} LANGUAGES CXX)
Expand Down
59 changes: 34 additions & 25 deletions changlog.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
# 版本记录(change log):

## 2025-02-05 -> 2.2.9

- `SARibbonBar`增加`setWindowTitleBackgroundBrush`/`windowTitleBackgroundBrush`函数,允许用户设置标题栏的背景色

![](./doc/screenshot/SARibbonBar-setWindowTitleBackgroundBrush.png)

- 修正了`SARibbonBar`针对标题的渲染方式,能根据父窗口的`isWindowModified`状态,针对`[*]`占位符进行渲染
- 例子中增加了标题栏背景颜色周期改变的示例

## 2025-01-04 -> 2.2.8 [hotfix]

- 修正合并文件会存在宏重复定义问题-2.2.7遗漏了一个调试宏
- SARibbonSeparatorWidget的宽度增加了最小1像素的判断
- SARibbonToolButton添加了textEllipsisAspectFactor相关接口,用户可以通过设置文字省略显示的长宽比,来调整按钮的最宽宽度
- `SARibbonSeparatorWidget`的宽度增加了最小1像素的判断
- `SARibbonToolButton`添加了`textEllipsisAspectFactor`相关函数,用户可以通过设置文字省略显示的长宽比,来调整按钮的最宽宽度
- 优化了一些cmake的内容

## 2024-12-23 -> 2.2.7 [hotfix]
Expand All @@ -20,54 +29,54 @@

## 2024-10-17 -> 2.2.5

- 原有的qt关键宏替换为Q_SIGNAL\Q_SLOT\Q_EMIT,以适应no_keywords设置
- 原有的qt关键宏替换为`Q_SIGNAL` / `Q_SLOT` / `Q_EMIT`,以适应no_keywords设置
- 调整目录结构,单独把example提取出来
- 完善mdi窗口的例子,可以结合qwk实现mdi窗口的最大最小化按钮的显示

## 2024-09-12 -> 2.2.4

- 修正自定义过程调用setRibbonBar后,会导致最大最小化按钮被遮挡的问题
- 修正自定义`SARibbonMainWindow`调用`setRibbonBar`,会导致最大最小化按钮被遮挡的问题
- 调整Mdi例子中cmake的文件大小写,避免在linux系统下大小写敏感
- 修正qwk开启后,eventfilter没有捕获的问题
- 修正qwk开启后,`SARibbonMainWindow::eventfilter`没有捕获的问题

## 2024-07-25 -> 2.2.1

- 增加setPannelSpacing接口,可调节pannel按钮的间距
- SARibbonToolButton的icon尺寸可设置,在小按钮模式下,用户可指定icon尺寸
- 把SARibbonMainWindow的事件处理通过eventfilter实现,避免用户在重写事件时误操作
- 修正SARibbonGalleryButton的样式错误
- 增加`setPannelSpacing`接口,可调节pannel按钮的间距
- `SARibbonToolButton`的icon尺寸可设置,在小按钮模式下,用户可指定icon尺寸
- `SARibbonMainWindow`的事件处理通过`eventfilter`实现,避免用户在重写事件时误操作
- 修正`SARibbonGalleryButton`的样式错误
- 修正SystemBar在qwk下会位置有偏离的问题

## 2024-07-15 -> 2.2.0

- 增加了mdi窗口的示例
- 增加了SARibbonTabBar的tab尺寸计算方式,可以让tab高度按照tabbar高度自动调整
- 增加了`SARibbonTabBar`的tab尺寸计算方式,可以让tab高度按照tabbar高度自动调整
- 示例增加了尺寸设置的配置,可以任意调整titlebar,tabbar,pannel title height的高度
- 修正调整category高度后,pannel高度不跟着改变的问题
- 添加snap layout的开关,在依赖qwk下,可以设置是否开启snap layout

## 2024-05-23 -> 2.1.0

- 添加actionTriggered信号
- 添加`actionTriggered`信号
- 修正了滚动action显示效果
- 把SARibbonTheme从SARibbonMainWindow中转移到SARibbonGloabls.h中并作为枚举类(enum class)
- 添加SARibbonWidget,同时调整example/widget示例
- `SARibbonTheme`从SARibbonMainWindow中转移到`SARibbonGloabls.h`中并作为枚举类(enum class)
- 添加`SARibbonWidget`,同时调整example/widget示例
- 调整了布局移动的实现方式,不会出现压缩式移动

## 2024-02-07 -> 2.0.3

- 调整SAColorToolButton的实现,使之更简单
- 调整`SAColorToolButton`的实现,使之更简单
- 修正qwk库引入的cmake
- 调整文档

## 2024-02-07 -> 2.0.2

- 修正SARibbonSystemButtonBar的编码问题,可能会导致vs下无法编译成功
- SARibbonContextCategory的标签颜色调整
- 修正`SARibbonSystemButtonBar`的编码问题,可能会导致vs下无法编译成功
- `SARibbonContextCategory`的标签颜色调整

## 2024-01-27 -> 2.0.1【失效,请使用v2.0.2及以上版本】

- 调整qss,让SARibbonApplicationButton的下拉箭头不显示
- 调整qss,`SARibbonApplicationButton`的下拉箭头不显示
- 文档添加gallery
- 修正了一个布局可能异常的点

Expand Down Expand Up @@ -101,20 +110,20 @@
## 2023-12-29 -> 1.1.2

- 合并了lixinchang的修改(https://gitee.com/lixinchang)
- 添加了SARibbonControlToolButton,ControlBar不再使用QToolButton,避免和QToolButton的qss冲突
- 添加了`SARibbonControlToolButton`,ControlBar不再使用QToolButton,避免和QToolButton的qss冲突
- ControlBar支持按钮菜单样式的指定
- 调整了默认样式的内容

## 2023-12-25 -> 1.1.1

- 修正了SARibbonBar的布局过程对窗体隐藏的判断方式,使得在窗口没显示时也能正确布局
- 修正了`SARibbonBar`的布局过程对窗体隐藏的判断方式,使得在窗口没显示时也能正确布局

## 2023-12-25 -> 1.1.0

- 修正了尺寸刷新的问题,在首次显示不会出现控件跳动的状态
- 修正了一些问题
- 调整了创建RibbonButton的方式
- 调整了SARibbonPannel一些接口,使得创建更加规范
- 调整了`SARibbonPannel`一些接口,使得创建更加规范
- 调整了ToolButton的渲染方式

------------------------
Expand Down Expand Up @@ -189,16 +198,16 @@ en(machine translation):

## 2023-05-28 -> 0.5.0

- 调整了大按钮模式下的显示方案,去除了原来SARibbonToolButton的Lite和Normal模式,以WordWrap来表征
- 调整了大按钮模式下的显示方案,去除了原来`SARibbonToolButton`的Lite和Normal模式,以WordWrap来表征
- 支持文字自定义换行
- 调整了RibbonPannel的标题栏的高度计算方案

## 0.5.1

- 不使用QString::simplified,而是简单的仅仅替换\n的simplified,这样中文换行不会多出空格
- 不使用`QString::simplified`,而是简单的仅仅替换\n的simplified,这样中文换行不会多出空格

## 0.5.2

- SARibbonColorToolButton\SARibbonToolButton修正&操作在三项表达式未加括号问题
- SARibbonStyleOption添加虚析构函数
- 原来SARibbonElementCreateDelegate类改名为SARibbonElementFactory
- `SARibbonColorToolButton` / `SARibbonToolButton`修正&操作在三项表达式未加括号问题
- `SARibbonStyleOption`添加虚析构函数
- 原来`SARibbonElementCreateDelegate`类改名为`SARibbonElementFactory`
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 31 additions & 6 deletions example/MainWindowExample/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ MainWindow::MainWindow(QWidget* par)
{

PRINT_COST_START();
setWindowTitle(("ribbon mainwindow test"));
setWindowTitle(("ribbon mainwindow test[*]"));
setWindowModified(true);
mTextedit = new QTextEdit(this);
setCentralWidget(mTextedit);
setStatusBar(new QStatusBar());
Expand Down Expand Up @@ -171,7 +172,11 @@ MainWindow::MainWindow(QWidget* par)
connect(ribbon, &SARibbonBar::currentRibbonTabChanged, this, [ this ](int v) {
mTextedit->append(QString("SARibbonBar::currentRibbonTabChanged(%1)").arg(v));
});
//! 这个定时器10秒触发一次,用于改变标题颜色
connect(&mChangeTitleBkColorTimer, &QTimer::timeout, this, &MainWindow::onTitleBackgroundBrushChangedTimeout);
mChangeTitleBkColorTimer.start(10000);

//! 全屏显示
showMaximized();
}

Expand Down Expand Up @@ -669,6 +674,23 @@ void MainWindow::onSpinBoxRibbonPannelToolBtnIconSizeChanged(int h)
ribbonBar()->setPannelToolButtonIconSize(QSize(h, h));
}

/**
* @brief 此函数用来演示标题栏颜色改变
*/
void MainWindow::onTitleBackgroundBrushChangedTimeout()
{
static bool s_setNoBrush = true;
s_setNoBrush = (!s_setNoBrush);
if (s_setNoBrush) {
ribbonBar()->setWindowTitleTextColor(Qt::black);
ribbonBar()->setWindowTitleBackgroundBrush(Qt::NoBrush);
} else {
ribbonBar()->setWindowTitleTextColor(Qt::white);
ribbonBar()->setWindowTitleBackgroundBrush(Qt::red);
}
ribbonBar()->repaint();
}

/**
* @brief 创建其它actions,这些actions并不在SARibbonBar管理
*/
Expand Down Expand Up @@ -702,16 +724,19 @@ void MainWindow::createCategoryMain(SARibbonCategory* page)
SARibbonPannel* pannelStyle = page->addPannel(("ribbon style"));

QAction* actSave = createAction(tr("Save"), ":/icon/icon/save.svg");
connect(actSave, &QAction::triggered, this, [ this ](bool b) {
Q_UNUSED(b);
this->mTextedit->append("actSaveion clicked");
this->setWindowModified(false);
// 更新状态后,需要手动调用ribbonbar刷新重绘标题,目前ribbonbar不会自动检测WindowModified状态
this->ribbonBar()->repaint();
});
// 这样设置快捷键
QShortcut* shortCut = new QShortcut(QKeySequence(QLatin1String("Ctrl+S")), this);
connect(shortCut, &QShortcut::activated, this, [ actSave ]() { actSave->trigger(); });
// 这样设置是无效的
// 这样设置如果切换到其它标签,快捷键是不生效的
// actSave->setShortcut(QKeySequence(QLatin1String("Ctrl+S")));

connect(actSave, &QAction::triggered, this, [ this ](bool b) {
Q_UNUSED(b);
this->mTextedit->append("actSaveion clicked");
});
pannelStyle->addLargeAction(actSave);

QAction* actHideRibbon = createAction(tr("hide ribbon"), ":/icon/icon/hideRibbon.svg", "actHideRibbon");
Expand Down
6 changes: 5 additions & 1 deletion example/MainWindowExample/mainwindow.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include "SARibbonMainWindow.h"
#include <QTimer>
class SARibbonCategory;
class SARibbonContextCategory;
class SARibbonCustomizeWidget;
Expand Down Expand Up @@ -75,6 +76,8 @@ private Q_SLOTS:
void onSpinBoxRibbonPannelTtitleHeightChanged(int h);
void onSpinBoxRibbonPannelSpacingChanged(int h);
void onSpinBoxRibbonPannelToolBtnIconSizeChanged(int h);
// 此函数用来演示标题栏颜色改变
void onTitleBackgroundBrushChangedTimeout();

private:
// 创建其它actions,这些actions并不在SARibbonBar管理
Expand Down Expand Up @@ -115,7 +118,8 @@ private Q_SLOTS:
SARibbonPannel* mPannelVisbileExample { nullptr };
//
QAction* mActionVisibleAll { nullptr }; ///< 控制所有action是否可见的开关
bool mHasApplyCustomizeXmlFile { false }; /// 程序启动后是否应用上次修改
bool mHasApplyCustomizeXmlFile { false }; ///< 程序启动后是否应用上次修改
QTimer mChangeTitleBkColorTimer; ///< 用于周期改变标题颜色的一个定时器
};

#endif // MAINWINDOW_H
Loading

0 comments on commit 68509da

Please sign in to comment.