Skip to content

Commit

Permalink
添加snap layout的开关
Browse files Browse the repository at this point in the history
  • Loading branch information
czyt1988 committed Jun 7, 2024
1 parent ecce4f7 commit e3ab4d6
Show file tree
Hide file tree
Showing 13 changed files with 233 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ project(SARibbon VERSION ${SARIBBON_VERSION} LANGUAGES CXX)
option(SARIBBON_BUILD_EXAMPLES "build the examples" ON)
# frameless能提供windows的窗口特效,如边缘吸附,且对高分屏多屏幕的支持更好,默认开启
option(SARIBBON_USE_FRAMELESS_LIB "Using the QWindowKit library as a frameless solution" OFF)
# frameless能提供windows的窗口特效,如边缘吸附,且对高分屏多屏幕的支持更好,默认开启
option(SARIBBON_ENABLE_SNAPLAYOUT "Whether to enable the Snap Layout effect in Windows 11, this option only takes effect when SARIBBON_USE_FRAMELESS_LIB=ON" OFF)

# load Qt library, minimum version required is 5.8
# cn:Qt库加载,最低版本要求为5.8
Expand Down
2 changes: 1 addition & 1 deletion SARibbonBar.pri
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ DEPENDPATH += $$PWD/src/SARibbonBar

######################################
#SA_RIBBON_CONFIG 用于定义一些编译选项:
# SA_RIBBON_CONFIG+=use_frameless 此选项在common.pri种定义,注意必须保证编译和使用统一,否则会发生不可预估的异常
# SA_RIBBON_CONFIG+=use_frameless 此选项在common.pri中定义,注意必须保证编译和使用统一,否则会发生不可预估的异常
######################################

contains( SA_RIBBON_CONFIG, use_frameless ) {
Expand Down
5 changes: 5 additions & 0 deletions common.pri
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,10 @@ SARIBBON_LIB_NAME=$$saRibbonLibNameMake(SARibbonBar)
# frameless库能实现Ubuntu下和mac下的显示,同时多屏幕的支持也较好
# 使用frameless库,需要定义QWindowKit的安装目录,默认在SARIBBON_BIN_DIR
# SA_RIBBON_QWindowKit_Install_DIR = $$SARIBBON_BIN_DIR
#
# SA_RIBBON_CONFIG+=enable_snap_layout
# 此选项将允许开启windows11的snap layout效果,目前在qt6.5下是正常显示位置,其它已知qt版本的snap layout位置会有偏移
# 此选项必须在 SA_RIBBON_CONFIG+=use_frameless 下才有效
######################################
# SA_RIBBON_CONFIG += use_frameless
# SA_RIBBON_CONFIG += enable_snap_layout
13 changes: 11 additions & 2 deletions doc/how-to-build-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# 准备工作

SARibbon使用了[QWindowkit](https://github.com/stdware/qwindowkit)作为无边框方案,同时也支持简单的无边框方案,如果你需要操作系统原生的窗口支持,如windows7以后的贴边处理,windows11的最大化按钮悬停的效果,建议开启[QWindowkit](https://github.com/stdware/qwindowkit)库,[QWindowkit](https://github.com/stdware/qwindowkit)库还能较好解决多屏幕移动问题
SARibbon使用了[QWindowkit](https://github.com/stdware/qwindowkit)作为无边框方案,同时也支持简单的无边框方案,如果你需要操作系统原生的窗口支持,如windows7以后的贴边处理,windows11的Snap Layout效果,建议开启[QWindowkit](https://github.com/stdware/qwindowkit)库,[QWindowkit](https://github.com/stdware/qwindowkit)库还能较好解决多屏幕移动问题

开启QWindowkit将能实现如下效果:

Expand Down Expand Up @@ -195,4 +195,13 @@ include($$PWD/3rdparty/SARibbon/importSARibbonBarLib.pri)

`importSARibbonBarLib.pri``SARibbonBar.pri``common.pri`这三个文件是引入工程的关键文件

> Qt6.0版本后已经放弃qmake,建议使用cmake来管理工程
> Qt6.0版本后已经放弃qmake,建议使用cmake来管理工程
# 公开的预定义宏

SARibbon在编译过程中有些预定义宏,这些宏在基于visual studio的库引入是必须的

`SARIBBON_USE_3RDPARTY_FRAMELESSHELPER=1/0`,此宏用来定义是否引入了`QWindowkit`

`SARIBBON_ENABLE_SNAP_LAYOUT=1/0`,此宏在SARIBBON_USE_3RDPARTY_FRAMELESSHELPER=1时才有用,用于定义是否开始windows11的snap layout效果

8 changes: 4 additions & 4 deletions src/SARibbonBar/3rdparty/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ endif()
# 第三方库参数设置
########################################################
#
set(QWINDOWKIT_BUILD_WIDGETS ON)
set(QWINDOWKIT_BUILD_EXAMPLES OFF)
set(QWINDOWKIT_BUILD_QUICK OFF)
set(QWINDOWKIT_INSTALL ON)
set(QWINDOWKIT_BUILD_WIDGETS ON CACHE BOOL "force set QWINDOWKIT_BUILD_WIDGETS ON" FORCE)
set(QWINDOWKIT_BUILD_EXAMPLES OFF CACHE BOOL "force set QWINDOWKIT_BUILD_EXAMPLES OFF" FORCE)
set(QWINDOWKIT_BUILD_QUICK OFF CACHE BOOL "force set QWINDOWKIT_BUILD_QUICK OFF" FORCE)
set(QWINDOWKIT_INSTALL ON CACHE BOOL "force set QWINDOWKIT_INSTALL ON" FORCE)
########################################################
# 安装第三方库
########################################################
Expand Down
2 changes: 1 addition & 1 deletion src/SARibbonBar/3rdparty/qwindowkit
Submodule qwindowkit updated 51 files
+1 −1 .gitignore
+28 −3 CMakeLists.txt
+82 −51 README.md
+ docs/images/vs-guide-1.png
+ docs/images/vs-guide-2.png
+ docs/images/vs-guide-3.png
+15 −0 docs/visual-studio-guide.md
+2 −7 examples/mainwindow/CMakeLists.txt
+7 −1 examples/mainwindow/main.cpp
+27 −22 examples/mainwindow/mainwindow.cpp
+2 −0 examples/mainwindow/mainwindow.h
+1 −1 examples/qml/main.qml
+1 −1 examples/shared/widgetframe/windowbar.cpp
+1 −1 qmsetup
+6 −0 share/install.cmake
+2 −0 share/qmake/QWKCore.pri.in
+2 −0 share/qmake/QWKQuick.pri.in
+2 −0 share/qmake/QWKWidgets.pri.in
+7 −29 src/CMakeLists.txt
+10 −0 src/QWindowKitConfig.cmake.in
+7 −8 src/core/CMakeLists.txt
+38 −66 src/core/contexts/abstractwindowcontext.cpp
+31 −5 src/core/contexts/abstractwindowcontext_p.h
+20 −25 src/core/contexts/cocoawindowcontext.mm
+1 −3 src/core/contexts/cocoawindowcontext_p.h
+5 −3 src/core/contexts/qtwindowcontext.cpp
+1 −1 src/core/contexts/qtwindowcontext_p.h
+542 −210 src/core/contexts/win32windowcontext.cpp
+6 −4 src/core/contexts/win32windowcontext_p.h
+43 −0 src/core/kernel/winidchangeeventfilter.cpp
+53 −0 src/core/kernel/winidchangeeventfilter_p.h
+2 −8 src/core/qwindowkit_windows.h
+43 −0 src/core/qwkglobal.cpp
+4 −11 src/core/qwkglobal_p.h
+1 −1 src/core/shared/qwkwindowsextra_p.h
+121 −0 src/core/shared/windows10borderhandler_p.h
+4 −0 src/core/windowagentbase.cpp
+7 −1 src/core/windowitemdelegate.cpp
+7 −1 src/core/windowitemdelegate_p.h
+2 −6 src/quick/CMakeLists.txt
+8 −7 src/quick/quickitemdelegate.cpp
+2 −1 src/quick/quickitemdelegate_p.h
+9 −2 src/quick/quickwindowagent.cpp
+8 −3 src/quick/quickwindowagent.h
+53 −66 src/quick/quickwindowagent_win.cpp
+2 −6 src/widgets/CMakeLists.txt
+40 −16 src/widgets/widgetitemdelegate.cpp
+5 −1 src/widgets/widgetitemdelegate_p.h
+1 −1 src/widgets/widgetwindowagent.cpp
+2 −2 src/widgets/widgetwindowagent.h
+52 −89 src/widgets/widgetwindowagent_win.cpp
6 changes: 6 additions & 0 deletions src/SARibbonBar/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@ target_compile_definitions(${SARIBBON_LIB_NAME} PRIVATE SA_COLOR_WIDGETS_MAKE_LI
if(SARIBBON_USE_FRAMELESS_LIB)
#使用frameless必须设置SARIBBON_USE_3RDPARTY_FRAMELESSHELPER宏为1,此宏必须为PUBLIC
target_compile_definitions(${SARIBBON_LIB_NAME} PUBLIC SARIBBON_USE_3RDPARTY_FRAMELESSHELPER=1)
if(SARIBBON_ENABLE_SNAPLAYOUT)
# 是否开启windows11的snap layout效果,目前这个在不同qt版本下有bug
target_compile_definitions(${SARIBBON_LIB_NAME} PUBLIC SARIBBON_ENABLE_SNAP_LAYOUT=1)
else()
target_compile_definitions(${SARIBBON_LIB_NAME} PUBLIC SARIBBON_ENABLE_SNAP_LAYOUT=0)
endif()
else()
#不使用frameless必须设置SARIBBON_USE_3RDPARTY_FRAMELESSHELPER宏为0,此宏必须为PUBLIC
target_compile_definitions(${SARIBBON_LIB_NAME} PUBLIC SARIBBON_USE_3RDPARTY_FRAMELESSHELPER=0)
Expand Down
3 changes: 3 additions & 0 deletions src/SARibbonBar/SARibbonBar.pri
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ contains( SA_RIBBON_CONFIG, use_frameless ) {
include($$SA_RIBBON_QWindowKit_QMake_DIR/QWKWidgets.pri)
# 定义SARIBBON_USE_3RDPARTY_FRAMELESSHELPER=1是的使用framelss库
DEFINES += SARIBBON_USE_3RDPARTY_FRAMELESSHELPER=1
contains( SA_RIBBON_CONFIG, enable_snap_layout ) {
DEFINES += SARIBBON_ENABLE_SNAP_LAYOUT=1
}
}else{
message("do not use_frameless lib,compile with c+=14")
!contains(CONFIG,C++14){
Expand Down
2 changes: 2 additions & 0 deletions src/SARibbonBar/SARibbonMainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ void SARibbonMainWindow::setRibbonBar(SARibbonBar* bar)
helper->setHitTestVisible(bar->applicationButton()); // IMPORTANT!
helper->setHitTestVisible(bar->quickAccessBar()); // IMPORTANT!
helper->setHitTestVisible(bar->ribbonStackedWidget()); // IMPORTANT!
#if SARIBBON_ENABLE_SNAP_LAYOUT
if (wg->closeButton()) {
helper->setSystemButton(QWK::WindowAgentBase::Close, wg->closeButton());
}
Expand All @@ -120,6 +121,7 @@ void SARibbonMainWindow::setRibbonBar(SARibbonBar* bar)
if (wg->maximizeButton()) {
helper->setSystemButton(QWK::WindowAgentBase::Maximize, wg->maximizeButton());
}
#endif
#else
bar->installEventFilter(this);
// 设置窗体的标题栏高度
Expand Down
58 changes: 58 additions & 0 deletions src/example/MdiAreaWindowExample/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
cmake_minimum_required(VERSION 3.5)
SET(VERSION_SHORT 0.1)
project(MainWindowExample VERSION ${VERSION_SHORT})
set(SARIBBON_EXPAMPLE_NAME MainWindowExample)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# qt库加载,最低要求5.8
find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} 5.8 COMPONENTS Core Gui Widgets REQUIRED)

add_executable(${SARIBBON_EXPAMPLE_NAME} WIN32
mainwindow.h
mainwindow.cpp
main.cpp
saribbonresouce.qrc
)

target_include_directories(${SARIBBON_EXPAMPLE_NAME} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../../SARibbonBar")

target_link_libraries(${SARIBBON_EXPAMPLE_NAME} PRIVATE SARibbonBar)
target_link_libraries(${SARIBBON_EXPAMPLE_NAME} PUBLIC
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::Gui
Qt${QT_VERSION_MAJOR}::Widgets)

set_target_properties(${SARIBBON_EXPAMPLE_NAME} PROPERTIES
AUTOMOC ON
AUTORCC ON
AUTOUIC ON
CXX_EXTENSIONS OFF
DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX}
VERSION ${SARIBBON_VERSION}
EXPORT_NAME ${SARIBBON_EXPAMPLE_NAME}
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
)

install(TARGETS ${SARIBBON_EXPAMPLE_NAME} RUNTIME DESTINATION bin LIBRARY DESTINATION bin ARCHIVE DESTINATION lib)

# 会有一个FAILED: src/example/MainWindowExample/CMakeFiles/MainWindowExample.dir/MainWindowExample.rc.res
# 暂时注释
#
# if(WIN32)
# add_custom_command(TARGET ${SARIBBON_EXPAMPLE_NAME}
# POST_BUILD
# COMMAND ${CMAKE_COMMAND} -E
# copy_if_different
# "$<TARGET_FILE:SARibbonBar>"
# "$<TARGET_FILE_DIR:${SARIBBON_EXPAMPLE_NAME}>"
# )
# create_win32_resource_version(
# TARGET ${SARIBBON_EXPAMPLE_NAME}
# FILENAME ${SARIBBON_EXPAMPLE_NAME}
# EXT "exe"
# DESCRIPTION "Example application for Qt Ribbon Control"
# )
# visual_studio_qt_helper(${SARIBBON_EXPAMPLE_NAME})
# endif()
64 changes: 64 additions & 0 deletions src/example/MdiAreaWindowExample/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#include "mainwindow.h"
#include <QApplication>
#include <QDebug>
#include <QElapsedTimer>
#include "SARibbonBar.h"
// 重定向qdebug的打印
void log_out_put(QtMsgType type, const QMessageLogContext& context, const QString& msg);

/**
* @brief 重定向qdebug的打印
* @param type
* @param context
* @param msg
*/
void log_out_put(QtMsgType type, const QMessageLogContext& context, const QString& msg)
{
QByteArray localMsg = msg.toLocal8Bit();

switch (type) {
case QtDebugMsg:
fprintf(stdout, "%s |[Debug] (%s[%u],%s)\n", localMsg.constData(), context.function, context.line, context.file);
break;

case QtWarningMsg:
fprintf(stdout, "%s |[Warning] (%s[%u],%s)\n", localMsg.constData(), context.function, context.line, context.file);
break;

case QtCriticalMsg:
fprintf(stdout, "%s |[Critical] (%s[%u],%s)\n", localMsg.constData(), context.function, context.line, context.file);
break;

case QtFatalMsg:
fprintf(stdout, "%s |[Fatal] (%s[%u],%s)\n", localMsg.constData(), context.function, context.line, context.file);
abort();
break;

default:
fprintf(stdout, "%s |[Debug](%s[%u],%s)\n", localMsg.constData(), context.function, context.line, context.file);
break;
}
#ifndef QT_NO_DEBUG_OUTPUT
fflush(stdout);
#endif
}

int main(int argc, char* argv[])
{
// 以下是针对高分屏的设置,有高分屏需求都需要按照下面进行设置
SARibbonBar::initHighDpi();

QApplication a(argc, argv);
qInstallMessageHandler(log_out_put);
QFont f = a.font();
f.setFamily(u8"微软雅黑");
a.setFont(f);
QElapsedTimer cost;

cost.start();
MainWindow w;
qDebug() << "window build cost:" << cost.elapsed() << " ms";
w.show();

return (a.exec());
}
53 changes: 53 additions & 0 deletions src/example/MdiAreaWindowExample/mainwindow.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include "mainwindow.h"
#if !SARIBBON_USE_3RDPARTY_FRAMELESSHELPER
#include "SAFramelessHelper.h"
#endif
#include "SARibbonApplicationButton.h"
#include "SARibbonBar.h"
#include "SARibbonButtonGroupWidget.h"
#include "SARibbonCategory.h"
#include "SARibbonCheckBox.h"
#include "SARibbonColorToolButton.h"
#include "SARibbonComboBox.h"
#include "SARibbonCustomizeDialog.h"
#include "SARibbonCustomizeWidget.h"
#include "SARibbonGallery.h"
#include "SARibbonLineEdit.h"
#include "SARibbonMenu.h"
#include "SARibbonPannel.h"
#include "SARibbonQuickAccessBar.h"
#include "SARibbonToolButton.h"
#include "colorWidgets/SAColorGridWidget.h"
#include "colorWidgets/SAColorPaletteGridWidget.h"
#include "SARibbonSystemButtonBar.h"
#include <QAbstractButton>
#include <QAction>
#include <QApplication>
#include <QButtonGroup>
#include <QCalendarWidget>
#include <QDebug>
#include <QElapsedTimer>
#include <QFile>
#include <QFileDialog>
#include <QFontComboBox>
#include <QLabel>
#include <QLineEdit>
#include <QMenu>
#include <QMessageBox>
#include <QPushButton>
#include <QRadioButton>
#include <QSpinBox>
#include <QStatusBar>
#include <QTextEdit>
#include <QTextStream>
#include <QXmlStreamWriter>
#include <QMessageBox>
#include <QShortcut>
#include <QLineEdit>
#include <QDialogButtonBox>

MainWindow::MainWindow(QWidget* par)
: SARibbonMainWindow(par), mWidgetForCustomize(nullptr), mMenuApplicationBtn(nullptr)
{
showMaximized();
}
23 changes: 23 additions & 0 deletions src/example/MdiAreaWindowExample/mainwindow.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include "SARibbonMainWindow.h"
class SARibbonCategory;
class SARibbonContextCategory;
class SARibbonCustomizeWidget;
class SARibbonActionsManager;
class SARibbonQuickAccessBar;
class SARibbonButtonGroupWidget;
class SARibbonPannel;
class QTextEdit;
class QComboBox;
class QCloseEvent;
class QLineEdit;

class MainWindow : public SARibbonMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget* par = nullptr);
};

#endif // MAINWINDOW_H

0 comments on commit e3ab4d6

Please sign in to comment.