### Build uiform Example Source: https://github.com/czyt1988/saribbon/blob/master/example/uiform/README.md Builds the uiform example using CMake. Ensure you are in the build directory. ```bash cmake --build . --target uiform ``` -------------------------------- ### Installation Rules Source: https://github.com/czyt1988/saribbon/blob/master/example/StaticExample/CMakeLists.txt Defines installation rules for the StaticExample target, specifying destinations for executables, libraries, and archives. ```cmake include(GNUInstallDirs) install(TARGETS StaticExample BUNDLE DESTINATION . LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} ) ``` -------------------------------- ### Project Installation Rules Source: https://github.com/czyt1988/saribbon/blob/master/example/uiform/CMakeLists.txt Defines the installation rules for the 'uiform' target, specifying where the executable, libraries, and other artifacts should be placed on the system after installation. ```cmake include(GNUInstallDirs) install(TARGETS uiform BUNDLE DESTINATION . LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} ) ``` -------------------------------- ### Install Configuration Files Source: https://github.com/czyt1988/saribbon/blob/master/src/SARibbonBar/CMakeLists.txt Installs the SARibbonBar configuration and version files to the specified destination. ```cmake install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${SARIBBON_LIB_NAME}Config.cmake" "${CMAKE_CURRENT_BINARY_DIR}/${SARIBBON_LIB_NAME}ConfigVersion.cmake" DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${SARIBBON_LIB_NAME} ) ``` -------------------------------- ### Installation Rules Source: https://github.com/czyt1988/saribbon/blob/master/example/MainWindowExample/CMakeLists.txt Defines installation rules for the MainWindowExample executable, specifying destinations for bundles, libraries, runtime files, and archives. ```cmake include(GNUInstallDirs) install(TARGETS MainWindowExample BUNDLE DESTINATION . LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} ) ``` -------------------------------- ### Code Example with Comment Source: https://github.com/czyt1988/saribbon/blob/master/docs/en/doc-writing-guide.md Standard format for code examples, including explanatory comments. ```cpp // Comment code example ``` -------------------------------- ### Build and Install QWindowkit via Command Line Source: https://github.com/czyt1988/saribbon/blob/master/docs/en/build-guide/build-3rdparty.md Build and install QWindowkit using CMake from the command line, suitable for Qt 5 and older Visual Studio versions. Specify the build generator and Qt5_DIR. ```cmd cmake -B build -S . -G "Visual Studio 15 2017" -A x64 \ -DQt5_DIR=C:\Qt\Qt5.14.2\5.14.2\msvc2017_64\lib\cmake\Qt5 ``` ```cmd cmake --build build --target install --config Debug cmake --build build --target install --config Release ``` -------------------------------- ### Install Ubuntu 24.04 (WSL) apt Dependencies Source: https://github.com/czyt1988/saribbon/blob/master/build.md Installs essential Qt6 development packages and Ninja build tool for faster compilation on Ubuntu 24.04 via apt. ```bash # Qt6 核心开发包 sudo apt install qt6-base-dev qt6-base-dev-tools qt6-svg-dev # Qt6 扩展模块(翻译需要 LinguistTools) sudo apt install qt6-tools-dev # Ninja(编译更快) sudo apt install ninja-build ``` -------------------------------- ### Define Installation Paths Source: https://github.com/czyt1988/saribbon/blob/master/src/SARibbonBar/3rdparty/CMakeLists.txt Constructs the installation directory path based on Qt version, compiler ID, and platform architecture. For Windows, it sets CMAKE_INSTALL_PREFIX if the installation option is enabled. ```cmake # The bin file directory is one level above the current directory # cn:bin文件目录在当前目录的上上一级 set(SARIBBON_BIN_NAME bin_qt${QT_VERSION}_${CMAKE_CXX_COMPILER_ID}_${SARIBBON_PLATFORM}) set(SARIBBON_BIN_DIR ${CMAKE_CURRENT_LIST_DIR}/../../../${SARIBBON_BIN_NAME}) # windows系统下,默认直接安装到当前文件夹下 if(WIN32) if(QWK_INSTALL_IN_CURRENT_DIR) set(CMAKE_INSTALL_PREFIX "${SARIBBON_BIN_DIR}") endif() endif() ``` -------------------------------- ### Install Header Files Source: https://github.com/czyt1988/saribbon/blob/master/src/SARibbonBar/CMakeLists.txt Installs the main SARIBBON header files and SAColorWidgets header files to their respective destinations within the installation directory, categorized under the 'headers' component. ```cmake # 头文件 install(FILES ${SARIBBON_HEADER_FILES} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${SARIBBON_LIB_NAME} COMPONENT headers ) # SAColorWidget的头文件 install(FILES ${SACOLOR_HEADER_FILES} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${SARIBBON_LIB_NAME}/colorWidgets COMPONENT headers ) ``` -------------------------------- ### Installation Rules Source: https://github.com/czyt1988/saribbon/blob/master/example/MdiAreaWindowExample/CMakeLists.txt Defines the installation rules for the MdiAreaWindowExample executable, specifying its destination directories for bundles, libraries, runtimes, and archives based on standard installation directories. ```cmake include(GNUInstallDirs) install(TARGETS MdiAreaWindowExample BUNDLE DESTINATION . LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} ) ``` -------------------------------- ### Set QWindowKit Build Options Source: https://github.com/czyt1988/saribbon/blob/master/src/SARibbonBar/3rdparty/CMakeLists.txt Forces specific build options for QWindowKit, enabling widgets and installation, while disabling examples and Quick. ```cmake 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) ``` -------------------------------- ### Build QWindowkit with CMake via Qt Creator Source: https://github.com/czyt1988/saribbon/blob/master/docs/en/build-guide/build-3rdparty.md Use this method to build and install the QWindowkit library when using Qt Creator. Ensure the 'install' build step is selected. ```text cmake -B build -S . -G "Visual Studio 15 2017" -A x64 \ -DQt5_DIR=C:\Qt\Qt5.14.2\5.14.2\msvc2017_64\lib\cmake\Qt5 ``` -------------------------------- ### Installation Rules Source: https://github.com/czyt1988/saribbon/blob/master/example/WidgetWithRibbon/CMakeLists.txt Defines the installation rules for the WidgetWithRibbon target, specifying where libraries, runtime files, and archives should be placed. ```cmake include(GNUInstallDirs) install(TARGETS WidgetWithRibbon BUNDLE DESTINATION . LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} ) ``` -------------------------------- ### CMake Configuration Example Source: https://github.com/czyt1988/saribbon/blob/master/docs/en/doc-writing-guide.md Example CMake configuration for adding module dependencies, source files, and creating a library with specified link libraries. ```cmake # Add module dependencies find_package(Qt6 REQUIRED COMPONENTS Core Widgets) # Add source files set(SOURCES src/main.cpp src/workflow.cpp ) # Create library add_library(DAWorkflow ${SOURCES}) target_link_libraries(DAWorkflow PRIVATE Qt6::Core Qt6::Widgets ) ``` -------------------------------- ### Basic CMake Project Setup Source: https://github.com/czyt1988/saribbon/blob/master/example/NormalMenuBarExample/CMakeLists.txt Sets the minimum CMake version and project name with a version number. ```cmake cmake_minimum_required(VERSION 3.5) SET(VERSION_SHORT 0.1) project(NormalMenuBarExample VERSION ${VERSION_SHORT}) ``` -------------------------------- ### Installation Rules Source: https://github.com/czyt1988/saribbon/blob/master/example/NormalMenuBarExample/CMakeLists.txt Specifies the installation rules for the 'NormalMenuBarExample' target, defining where the executable, libraries, and archives should be placed on the system. ```cmake include(GNUInstallDirs) install(TARGETS NormalMenuBarExample BUNDLE DESTINATION . LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} ) ``` -------------------------------- ### Build WidgetWithRibbon Source: https://github.com/czyt1988/saribbon/blob/master/example/WidgetWithRibbon/README.md Builds the WidgetWithRibbon example from the SARibbon build directory. ```bash cmake --build . --target WidgetWithRibbon ``` -------------------------------- ### Complete Native Frame Example Source: https://github.com/czyt1988/saribbon/blob/master/docs/en/use-guide/create-ribbon-style-window.md Demonstrates using SARibbonMainWindow with native frame and ribbon menu bar enabled. Compact mode is recommended for native frames. ```cpp #include "SARibbon.h" class MainWindow : public SARibbonMainWindow { Q_OBJECT public: MainWindow(QWidget* par = nullptr) : SARibbonMainWindow(par, SARibbonMainWindowStyleFlag::UseNativeFrame | SARibbonMainWindowStyleFlag::UseRibbonMenuBar) { SARibbonBar* ribbon = ribbonBar(); // Compact mode is recommended when using the native frame ribbon->setRibbonStyle(SARibbonBar::RibbonStyleCompactThreeRow); // Disable vertical expansion of the Application Button ribbon->setApplicationButtonVerticalExpansion(false); // Create category pages and panels SARibbonCategory* category = ribbon->addCategoryPage(tr("Main")); SARibbonPanel* panel = category->addPanel(tr("Operations")); QAction* act = new QAction(QIcon(":/icon/save.svg"), tr("Save"), this); panel->addLargeAction(act); resize(800, 600); } }; ``` -------------------------------- ### Detailed SARibbonMenu Usage Example Source: https://github.com/czyt1988/saribbon/blob/master/docs/en/use-guide/create-ribbon-ui.md Demonstrates creating a `SARibbonMenu` with regular actions, submenus (including one with an icon), and a custom QLabel widget. The menu is then associated with an action and added to a panel. ```cpp // Create SARibbonMenu SARibbonMenu* mainMenu = new SARibbonMenu(tr("File Operations"), panel); // Add regular actions mainMenu->addAction("New"); mainMenu->addAction("Open"); mainMenu->addSeparator(); // Add a submenu (using addRibbonMenu) SARibbonMenu* recentSubmenu = mainMenu->addRibbonMenu(tr("Recent Files")); recentSubmenu->addAction("document1.docx"); recentSubmenu->addAction("document2.docx"); // Add a submenu with an icon SARibbonMenu* exportSubmenu = mainMenu->addRibbonMenu( QIcon(":/icon/export.svg"), tr("Export")); exportSubmenu->addAction("PDF"); exportSubmenu->addAction("HTML"); // Add a custom widget to the menu QLabel* label = new QLabel(tr("Custom Content")); label->setStyleSheet("padding: 8px;"); mainMenu->addWidget(label); // Associate the menu with a panel button actionExport->setMenu(mainMenu); panel->addLargeAction(actionExport, QToolButton::MenuButtonPopup); ``` -------------------------------- ### Set Local Install Bin Name Source: https://github.com/czyt1988/saribbon/blob/master/CMakeLists.txt Defines the name for the local installation binary directory based on Qt version, compiler, and platform. ```cmake set(SARIBBON_LOCAL_INSTALL_BIN_NAME bin_qt${QT_VERSION}_${CMAKE_CXX_COMPILER_ID}_${SARIBBON_PLATFORM}) set(SARIBBON_LOCAL_INSTALL_BIN_DIR ${CMAKE_CURRENT_LIST_DIR}/${SARIBBON_LOCAL_INSTALL_BIN_NAME}) ``` -------------------------------- ### Build UseNativeFrameExample Source: https://github.com/czyt1988/saribbon/blob/master/example/UseNativeFrameExample/README.md Builds the UseNativeFrameExample using CMake. Ensure you have the necessary build tools installed. ```bash cmake --build . --target UseNativeFrameExample ``` -------------------------------- ### Configure Installation Directory Option Source: https://github.com/czyt1988/saribbon/blob/master/src/SARibbonBar/3rdparty/CMakeLists.txt Sets an option to control whether libraries are installed in the current directory or the default system location. ```cmake option(QWK_INSTALL_IN_CURRENT_DIR "Whether to install in the current directory" ON) ``` -------------------------------- ### Include Directories Configuration Source: https://github.com/czyt1988/saribbon/blob/master/example/StaticExample/CMakeLists.txt Configures include directories for installation, build, and SARibbon source files. ```cmake target_include_directories(StaticExample PUBLIC $ $ $ ) ``` -------------------------------- ### Basic CMake Project Setup Source: https://github.com/czyt1988/saribbon/blob/master/example/MdiAreaWindowExample/CMakeLists.txt Sets the minimum CMake version, project name, and version. It also enables including the current directory for headers. ```cmake cmake_minimum_required(VERSION 3.5) SET(VERSION_SHORT 0.1) project(MdiAreaWindowExample VERSION ${VERSION_SHORT}) set(CMAKE_INCLUDE_CURRENT_DIR ON) ``` -------------------------------- ### Build SARibbon Static Example Source: https://github.com/czyt1988/saribbon/blob/master/example/StaticExample/README.md Builds the SARibbon static example using CMake. This approach compiles SARibbon source files directly into the application, eliminating the need for a pre-built library. ```bash cd example/StaticExample # StaticExample can be built standalone, no SARibbon library pre-built cmake -S . -B build -DCMAKE_PREFIX_PATH="/path/to/Qt" cmake --build build ``` ```bash cmake --build . --target StaticExample ``` -------------------------------- ### Add Subdirectories for Build Source: https://github.com/czyt1988/saribbon/blob/master/CMakeLists.txt Includes subdirectories for building the main source code, examples, and tests based on configuration options. ```cmake add_subdirectory(src) if(SARIBBON_BUILD_EXAMPLES) message(STATUS "build example") add_subdirectory(example) endif() if(BUILD_TESTS) message(STATUS "build tests") enable_testing() add_subdirectory(tests) endif() ``` -------------------------------- ### C++ Version Compatibility Example Source: https://github.com/czyt1988/saribbon/blob/master/docs/en/doc-writing-guide.md Use preprocessor directives to provide different implementations based on Qt version, such as choosing between QRegExp (Qt5) and QRegularExpression (Qt6). ```cpp #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) // Qt5 implementation QRegExp rx(pattern); #else // Qt6 implementation QRegularExpression rx(pattern); #endif ``` -------------------------------- ### Qt and SARibbonBar Dependency Setup Source: https://github.com/czyt1988/saribbon/blob/master/example/MainWindowExample/CMakeLists.txt Finds and configures Qt (version 5.8 or higher) and SARibbonBar, setting up include directories and build flags. ```cmake set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC 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) ``` ```cmake if(NOT TARGET SARibbonBar) # 说明这个例子是单独加载 message(STATUS "NOT TARGET SARibbonBar find_package(SARibbonBar REQUIRED)") find_package(SARibbonBar REQUIRED) endif() target_link_libraries(MainWindowExample PUBLIC SARibbonBar::SARibbonBar) target_link_libraries(MainWindowExample PUBLIC Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Gui Qt${QT_VERSION_MAJOR}::Widgets) ``` -------------------------------- ### Find QWindowKit Package Source: https://github.com/czyt1988/saribbon/blob/master/CMakeLists.txt Configures the search paths for the QWindowKit package, prioritizing user-specified paths, then local installation, and finally system defaults. ```cmake if(_SARIBBON_USE_FRAMELESS_LIB) set(_qwk_search_paths) if(QWindowKit_DIR) list(APPEND _qwk_search_paths ${QWindowKit_DIR}) message(STATUS "Using user-specified QWindowKit_DIR: ${QWindowKit_DIR}") endif() set(_local_qwk_dir ${SARIBBON_LOCAL_INSTALL_BIN_DIR}/lib/cmake/QWindowKit) if(EXISTS "${_local_qwk_dir}") list(APPEND _qwk_search_paths ${_local_qwk_dir}) message(STATUS "Adding local install path for QWindowKit: ${_local_qwk_dir}") endif() find_package(QWindowKit QUIET PATHS ${_qwk_search_paths} NO_DEFAULT_PATH ) if(NOT QWindowKit_FOUND) message(STATUS "QWindowKit not found in specified paths, trying system default...") find_package(QWindowKit QUIET) endif() if(QWindowKit_FOUND) message(STATUS "QWindowKit found at: ${QWindowKit_DIR}") else() set(_SARIBBON_USE_FRAMELESS_LIB OFF) message(WARNING "QWindowKit not found - disabling frameless support. Searched paths:\n ${_qwk_search_paths}") endif() endif() ``` -------------------------------- ### Apply Customization from XML on Startup Source: https://github.com/czyt1988/saribbon/blob/master/docs/en/use-guide/persistence-configuration-ribbon.md Use the provided helper function to apply customization settings from an XML file to the ribbon bar and actions manager at the end of the main window's constructor. ```cpp // At the end of MainWindow's constructor sa_apply_customize_from_xml_file("customization.xml", ribbonBar(), m_ribbonActionMgr); ``` -------------------------------- ### Build SARibbon on Windows with Ninja Generator Source: https://github.com/czyt1988/saribbon/blob/master/build.md Configures and builds SARibbon using the Ninja generator after initializing the MSVC environment. Specify the correct Qt installation path using CMAKE_PREFIX_PATH. ```powershell # 然后使用 Ninja 构建 cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH="C:/Qt/6.7.3/msvc2019_64" cmake --build build ``` -------------------------------- ### Usage of SA_D Macro in Non-Const Function Source: https://github.com/czyt1988/saribbon/blob/master/docs/en/dev-guide/pimpl-dev-guide.md Example demonstrating how to use the SA_D macro to get a non-const pointer to private data within a non-const member function. ```cpp void SARibbonBar::showMinimumModeButton(bool isShow) { SA_D(d); // Expands to PrivateData* d = d_ptr.get() if (isShow && !(d->mMinimumCategoryButtonAction)) { // Access private members directly through d d->mMinimumCategoryButtonAction = new QAction(this); } } ``` -------------------------------- ### MkDocs Serve Command Source: https://github.com/czyt1988/saribbon/blob/master/docs/en/doc-writing-guide.md Use this command to preview documentation locally during development. ```bash mkdocs serve ``` -------------------------------- ### Create SARibbonGalleryItem Examples Source: https://github.com/czyt1988/saribbon/blob/master/docs/en/use-guide/create-ribbon-ui.md Demonstrates three methods for creating SARibbonGalleryItem instances: direct construction, creation from QAction, and creation with subsequent data setting. These items are used within SARibbonGallery groups. ```cpp // Method 1: Direct construction SARibbonGalleryItem* item1 = new SARibbonGalleryItem( tr("Heading Style 1"), QIcon(":/icons/style1.svg")); item1->setToolTip(tr("Apply Heading Style 1")); group->addItem(item1); // Method 2: Create from QAction QAction* act = new QAction(QIcon(":/icons/style2.svg"), tr("Style 2"), this); SARibbonGalleryItem* item2 = new SARibbonGalleryItem(act); item2->setTextAlignment(Qt::AlignHCenter | Qt::AlignBottom); group->addItem(item2); // Method 3: Create and set data afterwards SARibbonGalleryItem* item3 = new SARibbonGalleryItem(); item3->setText(tr("Custom Style")); item3->setIcon(QIcon(":/icons/style3.svg")); item3->setToolTip(tr("Apply Custom Heading Style")); item3->setSelectable(true); group->addItem(item3); ``` -------------------------------- ### Example: Adding Menu Buttons with Different Popup Modes Source: https://github.com/czyt1988/saribbon/blob/master/docs/en/use-guide/create-ribbon-ui.md Demonstrates how to add three menu buttons to a SARibbon panel, each configured with a different popup mode (DelayedPopup, MenuButtonPopup, InstantPopup). Ensure the QMenu is constructed and actions are connected to appropriate slots. ```cpp SARibbonPanel* panelToolButtonStyle = page->addPanel(("sa ribbon toolbutton style")); QMenu* menu = new QMenu; //... construct the menu // DelayedPopup mode QAction* act = createAction(tr("Delayed\nPopup"), ":/icon/icon/folder-cog.svg"); act->setMenu(menu); panelToolButtonStyle->addLargeAction(act, QToolButton::DelayedPopup); connect(act, &QAction::triggered, this, &MainWindow::onDelayedPopupTriggered); act = createAction(tr("Menu Button Popup"), ":/icon/icon/folder-star.svg"); act->setMenu(menu); panelToolButtonStyle->addLargeAction(act, QToolButton::MenuButtonPopup); connect(act, &QAction::triggered, this, &MainWindow::onMenuButtonPopupTriggered); act = createAction(tr("Instant Popup"), ":/icon/icon/folder-stats.svg"); act->setMenu(menu); panelToolButtonStyle->addLargeAction(act, QToolButton::InstantPopup); connect(act, &QAction::triggered, this, &MainWindow::onInstantPopupTriggered); ``` -------------------------------- ### Quick Start: Basic SARibbon Application Source: https://github.com/czyt1988/saribbon/blob/master/docs/en/use-guide/SARibbon-user-guide.md Demonstrates the minimal code required to set up a SARibbon interface, including window creation, adding a category, panel, and a simple action. Ensure SARibbon.h and SARibbon.cpp are statically embedded in your project. ```cpp #include "SARibbon.h" #include int main(int argc, char* argv[]) { #if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)) QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); #endif SARibbonBar::initHighDpi(); QApplication a(argc, argv); SARibbonMainWindow w; w.setWindowTitle("SARibbon Quick Start"); SARibbonBar* ribbon = w.ribbonBar(); SARibbonCategory* cat = ribbon->addCategoryPage("Home"); SARibbonPanel* panel = cat->addPanel("Actions"); panel->addLargeAction(new QAction(QIcon(":/icon.svg"), "Click Me", &w)); w.show(); return a.exec(); } ``` -------------------------------- ### Basic CMake Project Setup Source: https://github.com/czyt1988/saribbon/blob/master/example/uiform/CMakeLists.txt Initializes the CMake version and project name. Sets include directories and enables automatic handling of UI, Moc, and Rcc files. Specifies the C++ standard to C++17. ```cmake cmake_minimum_required(VERSION 3.16) project(uiform VERSION 0.1 LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) ``` -------------------------------- ### Install Exported Targets Source: https://github.com/czyt1988/saribbon/blob/master/src/SARibbonBar/CMakeLists.txt Installs the exported targets for the SARibbonBar library, including the CMake configuration files. ```cmake install(EXPORT ${SARIBBON_LIB_NAME}Targets FILE ${SARIBBON_LIB_NAME}Targets.cmake NAMESPACE ${SARIBBON_LIB_NAME}:: DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${SARIBBON_LIB_NAME} ) ``` -------------------------------- ### Install SARibbonBar Target Source: https://github.com/czyt1988/saribbon/blob/master/src/SARibbonBar/CMakeLists.txt Installs the SARibbonBar target with specified runtime, library, archive, and include destinations. ```cmake install(TARGETS ${SARIBBON_LIB_NAME} EXPORT ${SARIBBON_LIB_NAME}Targets RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${SARIBBON_LIB_NAME} ) ``` -------------------------------- ### Executable Target Creation Source: https://github.com/czyt1988/saribbon/blob/master/example/StaticExample/CMakeLists.txt Creates the executable target 'StaticExample', with different commands for Qt6 and older versions, including special handling for Android builds. ```cmake if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) qt_add_executable(StaticExample ${PROJECT_SOURCES} ) else() if(ANDROID) add_library(StaticExample SHARED ${PROJECT_SOURCES} ) else() add_executable(StaticExample WIN32 ${PROJECT_SOURCES} ) endif() endif() ``` -------------------------------- ### Configure Install Prefix for Local Installation Source: https://github.com/czyt1988/saribbon/blob/master/CMakeLists.txt Sets the CMAKE_INSTALL_PREFIX to the local binary directory when SARIBBON_INSTALL_IN_CURRENT_DIR is enabled, primarily for Windows. ```cmake if(SARIBBON_INSTALL_IN_CURRENT_DIR) set(CMAKE_INSTALL_PREFIX "${SARIBBON_LOCAL_INSTALL_BIN_DIR}") message(STATUS "SARIBBON_INSTALL_IN_CURRENT_DIR=ON,will install in:${CMAKE_INSTALL_PREFIX}") endif() ``` -------------------------------- ### Create Panel and Add Actions Source: https://github.com/czyt1988/saribbon/blob/master/docs/en/use-guide/create-ribbon-ui.md Demonstrates creating a panel within a category and adding different types of actions (large and small buttons) to it. Actions can be configured with icons, text, and shortcuts. ```cpp // Create a "File" panel under the "Home" category SARibbonPanel* filePanel = homeCategory->addPanel("File"); filePanel->setObjectName("filePanel"); // Create an action QAction* newAction = new QAction(QIcon(":/new.svg"), "New", this); newAction->setObjectName("action_new"); newAction->setShortcut(QKeySequence::New); // Add the action to the panel // addLargeAction: Large button with icon + text filePanel->addLargeAction(newAction); // addSmallAction: Small button, usually only with icon QAction* saveAction = new QAction(QIcon(":/save.svg"), "Save", this); saveAction->setObjectName("action_save"); filePanel->addSmallAction(saveAction); // Connect signal and slot connect(newAction, &QAction::triggered, [] { qDebug() << "New document created."; }); ``` -------------------------------- ### MainWindow Implementation for Ribbon Customization Source: https://github.com/czyt1988/saribbon/blob/master/docs/en/use-guide/persistence-configuration-ribbon.md Initializes the ribbon, creates and registers actions using SARibbonActionsManager, and loads existing custom configurations from an XML file. ```cpp // === MainWindow.cpp === MainWindow::MainWindow(QWidget* par) : SARibbonMainWindow(par) { initRibbon(); // Create ActionsManager and auto-register (SARibbonActionsManager and autoRegisteActions require SARibbonBar*, use ribbonBar() to get it) m_ribbonActionMgr = new SARibbonActionsManager(ribbonBar()); m_ribbonActionMgr->autoRegisteActions(ribbonBar()); // Load existing custom configuration sa_apply_customize_from_xml_file("customization.xml", ribbonBar(), m_ribbonActionMgr); } ``` -------------------------------- ### Install Amalgamated Source Files Source: https://github.com/czyt1988/saribbon/blob/master/src/SARibbonBar/CMakeLists.txt Installs the amalgamated SARibbon header and source files into a specific directory under share, facilitating integration as a single-file library. ```cmake # 生成单一文件 # 单一文件是把整个SARibbon打包为一个h和一个cpp,方便集成 set(SARIBBON_AMALGAMATE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/../SARibbon.h ${CMAKE_CURRENT_SOURCE_DIR}/../SARibbon.cpp ) install(FILES ${SARIBBON_AMALGAMATE_FILES} DESTINATION share/${SARIBBON_LIB_NAME}_amalgamate ) ``` -------------------------------- ### Conditional Install Directory Option Source: https://github.com/czyt1988/saribbon/blob/master/CMakeLists.txt Conditionally sets the option for installing in the current directory based on the operating system. It is enabled on Windows and disabled on other platforms. ```cmake if(WIN32) option(SARIBBON_INSTALL_IN_CURRENT_DIR "Whether to install in the current directory" ON) else() option(SARIBBON_INSTALL_IN_CURRENT_DIR "Whether to install in the current directory" OFF) endif() ``` -------------------------------- ### MkDocs Build Command Source: https://github.com/czyt1988/saribbon/blob/master/docs/en/doc-writing-guide.md Use this command to build the static site into the 'site/' directory for deployment. ```bash mkdocs build ``` -------------------------------- ### Configure CMake for SARibbon Source: https://github.com/czyt1988/saribbon/blob/master/docs/en/use-guide/import-SARibbon.md Steps to integrate SARibbon into a CMake project after building and installing it. This involves setting the installation directory, loading the package, and linking the library to your target. ```cmake set(SARibbonBar_DIR "C:/src/Qt/SARibbon/bin_qt5.14.2_MSVC_x64/lib/cmake/SARibbonBar") ``` ```cmake find_package(SARibbonBar REQUIRED) ``` ```cmake target_link_libraries(${YOUR_TARGET} PUBLIC SARibbonBar::SARibbonBar) ``` -------------------------------- ### Specify QWindowKit Directory in CMake Source: https://github.com/czyt1988/saribbon/blob/master/docs/en/build-guide/common-build-errors.md When QWindowKit is not found, use this CMake configuration option to manually specify its installation directory. Replace '' with the actual installation path of QWindowKit. ```bash -DQWindowKit_DIR=/lib/cmake/QWindowKit ``` -------------------------------- ### Initializing SAColorPaletteGridWidget Source: https://github.com/czyt1988/saribbon/blob/master/docs/en/use-guide/color-widgets.md Shows how to initialize SAColorPaletteGridWidget with either a standard color list or a custom list of QColors. Also demonstrates setting variant factors, enabling checkable mode, and setting icon size. ```cpp #include "colorWidgets/SAColorPaletteGridWidget.h" // Initialize with standard color list SAColorPaletteGridWidget* palette = new SAColorPaletteGridWidget( SA::getStandardColorList(), parent); // Or use a custom color list QList myColors; myColors << Qt::red << Qt::blue << Qt::green << Qt::yellow << Qt::magenta; SAColorPaletteGridWidget* palette2 = new SAColorPaletteGridWidget(myColors, parent); // Set light/dark variant factors (default {180, 160, 140, 75, 50}) // Values > 100 mean lighter, < 100 mean darker palette->setFactor({75, 120}); // Enable checkable mode palette->setColorCheckable(true); // Set color icon size palette->setColorIconSize(QSize(16, 16)); // Connect click signal connect(palette, &SAColorPaletteGridWidget::colorClicked, this, [](const QColor& c) { qDebug() << "Palette color clicked:" << c.name(); }); ``` -------------------------------- ### Load SARibbon Translation File Source: https://github.com/czyt1988/saribbon/blob/master/docs/en/build-guide/i18n.md Demonstrates how to load a SARibbon translation file (.qm) at application startup using QTranslator. Ensure the .qm file is accessible in the specified path. ```cpp int main(int argc, char* argv[]) { QApplication a(argc, argv); // Load SARibbon translation file QTranslator translator; if (translator.load("SARibbon_zh_CN.qm", ":/i18n/")) { a.installTranslator(&translator); } MainWindow w; w.show(); return a.exec(); } ``` -------------------------------- ### Git Commit Message Example Source: https://github.com/czyt1988/saribbon/blob/master/docs/en/dev-guide/coding-standards.md Commit messages should include task type, a brief description, relevant files, and optionally, a link to a plan. This example shows a fix for a layout calculation error. ```text 修复:SARibbonCategory布局计算错误 - 修复了在紧凑模式下面板高度计算不正确的问题 - 调整了SARibbonCategoryLayout中的minimumSizeHint计算 - 更新了SARibbonPanel的sizeHint以适应新的布局逻辑 - 添加了对TwoRowMode的特殊处理 关联计划:Ribbon布局优化计划 ``` -------------------------------- ### Creating and Configuring SAColorMenu Source: https://github.com/czyt1988/saribbon/blob/master/docs/en/use-guide/color-widgets.md Demonstrates how to create an SAColorMenu, optionally with a title, enable the no-color option, bind it to a tool button, and access its internal widgets. Connects to the selected color signal. ```cpp #include "colorWidgets/SAColorMenu.h" // Create menu SAColorMenu* menu = new SAColorMenu(parent); // Or with a title SAColorMenu* menuWithTitle = new SAColorMenu("Font Color", parent); // Enable no-color option menu->enableNoneColorAction(true); // Quick bind to SAColorToolButton SAColorToolButton* btn = new SAColorToolButton(parent); menu->bindToColorToolButton(btn); // Get internal widgets SAColorPaletteGridWidget* palette = menu->colorPaletteGridWidget(); SAColorGridWidget* customGrid = menu->customColorsWidget(); QAction* customAction = menu->customColorAction(); QAction* noneAction = menu->noneColorAction(); // Connect color selection signal connect(menu, &SAColorMenu::selectedColor, this, [](const QColor& c) { qDebug() << "Selected color:" << c.name(); }); ``` -------------------------------- ### Load Custom QSS Stylesheet Source: https://github.com/czyt1988/saribbon/blob/master/docs/en/use-guide/design-your-theme.md Load a custom QSS theme from a resource file and apply it to the main window. Use QTimer::singleShot to defer application until after the constructor completes. ```c++ MainWindow::MainWindow(QWidget* par) : SARibbonMainWindow(par, SARibbonMainWindowStyleFlag::UseNativeFrame | SARibbonMainWindowStyleFlag::UseRibbonMenuBar) { SARibbonBar* ribbon = ribbonBar(); ... // Load theme from resource file QFile file(":/ribbon-theme/theme-matlab.qss"); if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { QString qss = QString::fromUtf8(file.readAll()); // Apply stylesheet after construction completes QTimer::singleShot(0, [ this, qss ]() { this->setStyleSheet(qss); }); } } ``` -------------------------------- ### Create Compact Ribbon Interface Source: https://github.com/czyt1988/saribbon/blob/master/docs/en/use-guide/SARibbon-size-settings.md Demonstrates setting up a compact three-row Ribbon interface by adjusting various height and spacing properties. Use this to create a denser UI layout. ```cpp #include "SARibbonMainWindow.h" #include "SARibbonBar.h" #include "SARibbonCategory.h" #include "SARibbonPanel.h" class MainWindow : public SARibbonMainWindow { public: MainWindow(QWidget* parent = nullptr) : SARibbonMainWindow(parent) { SARibbonBar* ribbon = ribbonBar(); // Use compact three-row mode ribbon->setRibbonStyle(SARibbonBar::RibbonStyleCompactThreeRow); // Adjust heights of each part for a more compact interface ribbon->setTabBarHeight(28); ribbon->setCategoryHeight(80); ribbon->setPanelTitleHeight(16); // Set icon sizes (small icon, large icon) ribbon->setPanelToolButtonIconSize(QSize(16, 16), QSize(24, 24)); // Set panel spacing for better visual separation ribbon->setPanelSpacing(4); // Add category and panel SARibbonCategory* cat = ribbon->addCategoryPage(tr("&File")); SARibbonPanel* panel = cat->addPanel(tr("Operations")); panel->addLargeAction(new QAction(tr("New"), this)); panel->addSmallAction(new QAction(tr("Open"), this)); } }; ``` -------------------------------- ### Create and Configure SARibbon Application Button Source: https://github.com/czyt1988/saribbon/blob/master/docs/en/use-guide/create-ribbon-ui.md Demonstrates how to obtain the default application button from SARibbonBar, set its text, and assign a QMenu to it. ```cpp void MainWindow::createRibbonApplicationButton() { SARibbonBar* ribbon = ribbonBar(); QAbstractButton* btn = ribbon->applicationButton(); btn->setText( ("&File")); SARibbonApplicationButton* appBtn = qobject_cast< SARibbonApplicationButton* >(btn); if (appBtn) { QMenu* menu = new QMenu(this); ... appBtn->setMenu(menu); } } ``` -------------------------------- ### Mermaid Flowchart Example Source: https://github.com/czyt1988/saribbon/blob/master/docs/en/doc-writing-guide.md Use Mermaid syntax to create flowcharts for visualizing usage flows and workflows. ```mermaid flowchart TD A[Create workflow] --> B[Add nodes] B --> C[Connect nodes] C --> D[Configure parameters] D --> E[Execute workflow] E --> F[View results] ``` -------------------------------- ### Create and Configure SARibbonGallery Source: https://github.com/czyt1988/saribbon/blob/master/docs/en/use-guide/create-ribbon-ui.md Demonstrates how to create a SARibbonGallery, add multiple action groups with icons and text, set group styles, and define minimum grid widths. Use this to display a variety of actions in a compact grid. ```cpp QAction MyRibbonMainWindow::createAction(const QString& text, const QString& iconurl){ QAction* act = new QAction(this); act->setText(text); act->setIcon(QIcon(iconurl)); return act; } void MyRibbonMainWindow::buildGalleryExample(){ SARibbonPanel* panelWithGallery = ...; ... // Create a Gallery SARibbonGallery* gallery = panelWithGallery->addGallery(); // Add action group 1 QList< QAction* > galleryActions1; galleryActions1.append(createAction("Document File", ":/gallery-icon/icon/gallery/Document-File.svg")); galleryActions1.append(createAction("Download File", ":/gallery-icon/icon/gallery/Download-File.svg")); ...... galleryActions1.append(createAction("File Settings", ":/gallery-icon/icon/gallery/File-Settings.svg")); galleryActions1.append(createAction("Presentation File", ":/gallery-icon/icon/gallery/Presentation-File.svg")); SARibbonGalleryGroup* group1 = gallery->addCategoryActions(tr("Files"), galleryActions1); group1->setGalleryGroupStyle(SARibbonGalleryGroup::IconWithWordWrapText); group1->setGridMinimumWidth(80); // Add action group 2 QList< QAction* > galleryActions2; galleryActions2.append(createAction("Photoshop", ":/gallery-icon/icon/gallery/Photoshop.svg")); galleryActions2.append(createAction("Internet-Explorer", ":/gallery-icon/icon/gallery/Internet-Explorer.svg")); galleryActions2.append(createAction("Illustrator", ":/gallery-icon/icon/gallery/Illustrator.svg")); galleryActions2.append(createAction("Google-Maps", ":/gallery-icon/icon/gallery/Google-Maps.svg")); galleryActions2.append(createAction("Adobe", ":/gallery-icon/icon/gallery/Adobe.svg")); galleryActions2.append(createAction("Word", ":/gallery-icon/icon/gallery/Word.svg")); SARibbonGalleryGroup* group2 = gallery->addCategoryActions(tr("Apps"), galleryActions2); group2->setGridMinimumWidth(80); // Set the currently displayed group gallery->setCurrentViewGroup(group1); } ``` -------------------------------- ### Qt6 Finalize Executable Source: https://github.com/czyt1988/saribbon/blob/master/example/MdiAreaWindowExample/CMakeLists.txt Calls qt_finalize_executable for Qt6 projects to perform final setup steps for the executable. ```cmake if(QT_VERSION_MAJOR EQUAL 6) qt_finalize_executable(MdiAreaWindowExample) endif() ``` -------------------------------- ### Dynamic Theme Switching with Custom QSS Source: https://github.com/czyt1988/saribbon/blob/master/docs/en/use-guide/SARibbon-theme.md Example of dynamically switching SARibbon themes based on a ComboBox selection. It also shows how to append custom QSS after applying a built-in theme to merge styles without overwriting. ```cpp void MainWindow::onThemeChanged(int index) { SARibbonTheme theme = static_cast(index); setRibbonTheme(theme); if (!m_customStyleSheet.isEmpty()) { this->setStyleSheet(m_customStyleSheet); } } ``` -------------------------------- ### Initialize SARibbonMainWindow Source: https://github.com/czyt1988/saribbon/blob/master/docs/en/use-guide/ribbon-interface-hierarchy.md The constructor initializes the Ribbon interface by calling setupRibbon(). Ensure all necessary SARibbon headers are included. ```cpp // mainwindow.cpp #include "mainwindow.h" #include "SARibbonBar.h" #include "SARibbonCategory.h" #include "SARibbonPanel.h" #include "SARibbonGallery.h" #include "SARibbonButtonGroupWidget.h" #include "SARibbonQuickAccessBar.h" #include "SARibbonContextCategory.h" #include #include MainWindow::MainWindow(QWidget* parent) : SARibbonMainWindow(parent) { setupRibbon(); } ``` -------------------------------- ### Markdown Code Highlighting Examples Source: https://github.com/czyt1988/saribbon/blob/master/docs/en/doc-writing-guide.md Use fenced code blocks with language specifiers for syntax highlighting in markdown. ```markdown ```cpp // C++ code ``` ``` ```markdown ```python # Python code ``` ``` ```markdown ```cmake # CMake code ``` ``` -------------------------------- ### MkDocs-Material Extended Syntax for Notes Source: https://github.com/czyt1988/saribbon/blob/master/docs/en/doc-writing-guide.md Examples of using mkdocs-material extended syntax for different types of notes and warnings. ```markdown !!! warning "Important Warning" Notes about potentially serious issues !!! info "Note" Supplementary information !!! tip "Tip" Tips and suggestions !!! example "Example" Example code path: `examples/xxx` !!! bug "Known Issue" Known defects and workaround methods !!! note "Qt Version Compatibility" Differences between Qt5 and Qt6 ``` -------------------------------- ### Enable QWindowKit in qmake Static Inclusion Source: https://github.com/czyt1988/saribbon/blob/master/docs/en/use-guide/import-SARibbon.md Define preprocessor macros in your qmake project file to enable QWindowKit and optional snap layout support when SARibbon is statically included. ```shell DEFINES += SARIBBON_USE_3RDPARTY_FRAMELESSHELPER=1 \ SARIBBON_ENABLE_SNAP_LAYOUT=1 ``` -------------------------------- ### Get Main Bar Height in Minimum Mode Source: https://github.com/czyt1988/saribbon/blob/master/docs/en/use-guide/SARibbon-size-settings.md Retrieves the main bar height when the ribbon is in minimum mode. ```cpp int minimumModeMainBarHeight() const; ``` -------------------------------- ### Get Main Bar Height in Normal Mode Source: https://github.com/czyt1988/saribbon/blob/master/docs/en/use-guide/SARibbon-size-settings.md Retrieves the main bar height when the ribbon is in normal mode. ```cpp int normalModeMainBarHeight() const; ```