Skip to content

Commit

Permalink
调整clangformat,添加widget主题设置
Browse files Browse the repository at this point in the history
  • Loading branch information
czyt1988 committed Mar 26, 2024
1 parent 67e1707 commit e698b59
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 20 deletions.
7 changes: 1 addition & 6 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ AlwaysBreakTemplateDeclarations: true
# clang-format does not handle that.
AllowShortFunctionsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: false
AllowShortLambdasOnASingleLine: false
AllowShortLoopsOnASingleLine: false
#
BinPackParameters: false
BinPackArguments: false
Expand All @@ -74,7 +72,6 @@ AlwaysBreakAfterReturnType: None
PenaltyReturnTypeOnItsOwnLine: 5000
PenaltyBreakAssignment: 5000
PenaltyBreakBeforeFirstCallParameter: 5000
PenaltyExcessCharacter: 1

# The coding style specifies some include order categories, but also tells to
# separate categories with an empty line. It does not specify the order within
Expand All @@ -98,6 +95,4 @@ ReflowComments: true
SpacesInSquareBrackets: true
SpacesInAngles: true

KeepEmptyLinesAtTheStartOfBlocks: true

AllowShortCaseLabelsOnASingleLine: true
KeepEmptyLinesAtTheStartOfBlocks: true
13 changes: 9 additions & 4 deletions doc/how-to-build-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,17 @@ build步骤选择install

![](./pic/build-cmake-vs-01.png)

选中CMake菜单->全部生成
选中CMake菜单->全部生成(有些版本没有CMake菜单,可以在CMakeLists.txt点右键)

![](./pic/build-cmake-vs-03.png)

选中CMake菜单->安装
选中CMake菜单->安装(有些版本没有CMake菜单,可以在CMakeLists.txt点右键)

![](./pic/build-cmake-vs-04.png)

> 不同的vs操作有点不一样,没有CMake菜单的,可以在CMakeLists.txt点右键
![](./pic/build-cmake-vs-04-other.png)

这时你会在SARibbon根目录下看到形如`bin_qt5.14.2_MSVC_x64`这样的安装目录,这里自动把`QWindowkit`库安装在此目录下

![](./pic/build-cmake-qwk-qtc-04.png)
Expand Down Expand Up @@ -135,9 +138,9 @@ qmake构建SARibbonBar只需使用Qt Creator打开SARibbon.pro文件即可

## 基于cmake引入SARibbonBar库

首先要通过cmake编译并执行安装,在自己的工程按照如下步骤执行
首先要通过cmake编译并执行安装,在自己的工程CMakeLists.txt按照如下步骤执行

1. 指定SARibbonBar的安装目录,把安装目录下的`lib/cmake/SARibbonBar`位置设置给`SARibbonBar_DIR`变量
1. 指定SARibbonBar的安装目录,把安装目录下的`lib/cmake/SARibbonBar`位置设置给`SARibbonBar_DIR`变量(CMake在执行`find_package(xx)`时,会先查看是否有`xx_DIR`变量,如果有,会先查询`xx_DIR`下是否有对应的`xxConfig.cmake`文件)

```cmake
set(SARibbonBar_DIR "C:\src\Qt\SARibbon\bin_qt5.14.2_MSVC_x64\lib\cmake\SARibbonBar")
Expand All @@ -159,6 +162,8 @@ target_link_libraries(${myapp_target_name} PUBLIC

## 基于qmake引入SARibbonBar库

> Qt6开始,不再推荐使用qmake,SARibbon未来的版本有可能会取消qmake的支持
qmake的编译过程会在SARibbon下生成`bin_qt{Qt version}_{MSVC/GNU}_x{32/64}`文件夹,库文件和dll文件都在此文件夹下,importSARibbonBarLib.pri会自动把这个文件夹下的库引用进来

步骤如下:
Expand Down
Binary file added doc/pic/build-cmake-vs-04-other.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 4 additions & 2 deletions src/SARibbonBar/SARibbonBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1621,9 +1621,11 @@ void SARibbonBar::updateRibbonGeometry()
c->updateItemGeometry();
return true;
});
//!主题变更后,tabbar的长度需要进行刷新

//! 直接给一个resizeevent,让所有刷新
// QResizeEvent* e = new QResizeEvent(size(), QSize());
// QApplication::postEvent(this, e);
QResizeEvent* e = new QResizeEvent(size(), QSize());
QApplication::postEvent(this, e);
}

/**
Expand Down
22 changes: 22 additions & 0 deletions src/example/WidgetWithRibbon/Widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,21 @@ void Widget::buildRibbon(SARibbonBar* bar)
pannel2->addLargeAction(createAction("setting", ":/icon/icon/customize0.svg"));
pannel2->addLargeAction(createAction("windowsflag", ":/icon/icon/windowsflag-normal.svg"));
bar->addCategoryPage(page1);
//加入主题
mComboTheme = new QComboBox();
mComboTheme->addItem("Theme Win7", SARibbonMainWindow::RibbonThemeWindows7);
mComboTheme->addItem("Theme Office2013", SARibbonMainWindow::RibbonThemeOffice2013);
mComboTheme->addItem("Theme Office2016 Blue", SARibbonMainWindow::RibbonThemeOffice2016Blue);
mComboTheme->addItem("Theme Office2021 Blue", SARibbonMainWindow::RibbonThemeOffice2021Blue);
mComboTheme->addItem("Theme Dark", SARibbonMainWindow::RibbonThemeDark);
mComboTheme->addItem("Theme Dark2", SARibbonMainWindow::RibbonThemeDark2);
mComboTheme->setCurrentIndex(mComboTheme->findData(static_cast< int >(SARibbonMainWindow::RibbonThemeOffice2013)));
connect(mComboTheme,
QOverload< int >::of(&QComboBox::currentIndexChanged),
this,
&Widget::onRibbonThemeComboBoxCurrentIndexChanged);
pannel2->addSeparator();
pannel2->addSmallWidget(mComboTheme);

SARibbonQuickAccessBar* qbar = mRibbonBar->quickAccessBar();
qbar->addAction(createAction("undo", ":/icon/icon/undo.svg"));
Expand All @@ -67,3 +82,10 @@ QAction* Widget::createAction(const QString& text, const QString& iconurl)
act->setObjectName(text);
return act;
}

void Widget::onRibbonThemeComboBoxCurrentIndexChanged(int index)
{
SARibbonMainWindow::RibbonTheme t = static_cast< SARibbonMainWindow::RibbonTheme >(mComboTheme->itemData(index).toInt());
sa_set_ribbon_theme(mRibbonBar, t);
mRibbonBar->updateRibbonGeometry();
}
19 changes: 11 additions & 8 deletions src/example/WidgetWithRibbon/Widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define WIDGET_H

#include <QWidget>

#include <QComboBox>
QT_BEGIN_NAMESPACE
namespace Ui
{
Expand All @@ -13,18 +13,21 @@ QT_END_NAMESPACE
class SARibbonBar;
class Widget : public QWidget
{
Q_OBJECT
Q_OBJECT

public:
Widget(QWidget* parent = nullptr);
~Widget();
Widget(QWidget* parent = nullptr);
~Widget();

private:
void buildRibbon(SARibbonBar* bar);
QAction* createAction(const QString& text, const QString& iconurl);
void buildRibbon(SARibbonBar* bar);
QAction* createAction(const QString& text, const QString& iconurl);
private slots:
void onRibbonThemeComboBoxCurrentIndexChanged(int index);

private:
Ui::Widget* ui;
SARibbonBar* mRibbonBar { nullptr };
Ui::Widget* ui;
SARibbonBar* mRibbonBar { nullptr };
QComboBox* mComboTheme { nullptr };
};
#endif // WIDGET_H

0 comments on commit e698b59

Please sign in to comment.