From 618b21854f44f563d938097fc68d34fde6e50e05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=AD=90=E6=A5=9A=5Czhuzi?= Date: Sat, 9 Sep 2023 20:09:20 +0800 Subject: [PATCH] Compatible with static build --- .cmake/QmlPlugin.cmake | 4 +- .cmake/Version.h.in | 2 - example/CMakeLists.txt | 38 +++--- example/{resource.qrc => example.qrc} | 0 example/src/main.cpp | 15 ++- src/CMakeLists.txt | 15 ++- src/FluentUI.cpp | 182 ++++++++++++++++++++++++++ src/FluentUI.h | 19 +++ src/Qt5/imports/fluentui.qrc | 99 ++++++++++++++ src/fluentuiplugin.cpp | 79 +---------- src/fluentuiplugin.h | 5 - src/resource.qrc | 99 -------------- 12 files changed, 345 insertions(+), 212 deletions(-) rename example/{resource.qrc => example.qrc} (100%) create mode 100644 src/FluentUI.cpp create mode 100644 src/FluentUI.h create mode 100644 src/Qt5/imports/fluentui.qrc delete mode 100644 src/resource.qrc diff --git a/.cmake/QmlPlugin.cmake b/.cmake/QmlPlugin.cmake index 29aec2fc..da9994ef 100644 --- a/.cmake/QmlPlugin.cmake +++ b/.cmake/QmlPlugin.cmake @@ -1,5 +1,6 @@ include(CMakeParseArguments) -find_package(Qt5 REQUIRED COMPONENTS Core) +find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core) +find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core) function(FindQmlPluginDump) get_target_property (QT_QMAKE_EXECUTABLE Qt5::qmake IMPORTED_LOCATION) @@ -35,7 +36,6 @@ function(add_qmlplugin TARGET) ${QMLPLUGIN_SOURCES} ) set(LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/lib) -add_custom_target("${TARGET}-qmlfiles" SOURCES ${QMLPLUGIN_QMLFILES}) if(QMLPLUGIN_NO_AUTORCC) set_target_properties(${TARGET} PROPERTIES AUTOMOC OFF) diff --git a/.cmake/Version.h.in b/.cmake/Version.h.in index 939b2a8b..e2ee4b8c 100644 --- a/.cmake/Version.h.in +++ b/.cmake/Version.h.in @@ -1,5 +1,3 @@ -// 应用程序版本信息 -// 请勿修改此头文件,因为这个文件是自动生成的 #ifndef VERSION_H #define VERSION_H diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 57e86631..11aec7e4 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -122,7 +122,7 @@ else() target_include_directories(example PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ) - target_sources(example PRIVATE resource.qrc) +target_sources(example PRIVATE example.qrc) endif() #导入component头文件,不然通过QML_NAMED_ELEMENT生成的c++类会找不到头文件报错 @@ -130,6 +130,13 @@ target_include_directories(example PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/component ) +#如何是静态库则需要手动注册插件,导入FluentUI.h头文件 +if(FLUENTUI_BUILD_STATIC_LIB) + target_include_directories(example PRIVATE + ${CMAKE_SOURCE_DIR}/src + ) +endif() + #设置属性 set_target_properties(example PROPERTIES MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com @@ -139,27 +146,14 @@ set_target_properties(example PROPERTIES WIN32_EXECUTABLE TRUE ) -#链接库 -if (FLUENTUI_BUILD_STATIC_LIB) - target_link_libraries(example PRIVATE - Qt${QT_VERSION_MAJOR}::Quick - Qt${QT_VERSION_MAJOR}::Svg - Qt${QT_VERSION_MAJOR}::Network - fluentui - fluentuiplugin - FramelessHelper::Core - FramelessHelper::Quick - ) -else() - target_link_libraries(example PRIVATE - Qt${QT_VERSION_MAJOR}::Quick - Qt${QT_VERSION_MAJOR}::Svg - Qt${QT_VERSION_MAJOR}::Network - fluentuiplugin - FramelessHelper::Core - FramelessHelper::Quick - ) -endif() +target_link_libraries(example PRIVATE + Qt${QT_VERSION_MAJOR}::Quick + Qt${QT_VERSION_MAJOR}::Svg + Qt${QT_VERSION_MAJOR}::Network + fluentuiplugin + FramelessHelper::Core + FramelessHelper::Quick +) #安装 install(TARGETS example diff --git a/example/resource.qrc b/example/example.qrc similarity index 100% rename from example/resource.qrc rename to example/example.qrc diff --git a/example/src/main.cpp b/example/src/main.cpp index 1cbe1648..e8e04832 100644 --- a/example/src/main.cpp +++ b/example/src/main.cpp @@ -8,14 +8,21 @@ #include #include #include +#include #include "AppInfo.h" #include "src/component/CircularReveal.h" #include "src/component/FileWatcher.h" #include "src/component/FpsItem.h" +#ifdef FLUENTUI_BUILD_STATIC_LIB +#if (QT_VERSION > QT_VERSION_CHECK(6, 2, 0)) +Q_IMPORT_QML_PLUGIN(FluentUIPlugin) +#endif +#include +#endif FRAMELESSHELPER_USE_NAMESPACE -int main(int argc, char *argv[]) + int main(int argc, char *argv[]) { #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling); @@ -24,7 +31,6 @@ int main(int argc, char *argv[]) QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough); #endif #endif - //将样式设置为Basic,不然会导致组件显示异常 qputenv("QT_QUICK_CONTROLS_STYLE","Basic"); FramelessHelper::Quick::initialize(); QGuiApplication::setOrganizationName("ZhuZiChu"); @@ -35,7 +41,7 @@ int main(int argc, char *argv[]) FramelessConfig::instance()->set(Global::Option::CenterWindowBeforeShow); FramelessConfig::instance()->set(Global::Option::ForceNonNativeBackgroundBlur); FramelessConfig::instance()->set(Global::Option::EnableBlurBehindWindow); -#ifdef Q_OS_WIN // 此设置仅在Windows下生效 +#ifdef Q_OS_WIN FramelessConfig::instance()->set(Global::Option::ForceHideWindowFrameBorder); FramelessConfig::instance()->set(Global::Option::EnableBlurBehindWindow,false); #endif @@ -46,8 +52,9 @@ int main(int argc, char *argv[]) QQmlApplicationEngine engine; FramelessHelper::Quick::registerTypes(&engine); #ifdef FLUENTUI_BUILD_STATIC_LIB - engine.addImportPath("qrc:/"); // 让静态资源可以被QML引擎搜索到 + FluentUI::getInstance()->registerTypes(&engine); #endif + qDebug()<("example", 1, 0, "CircularReveal"); qmlRegisterType("example", 1, 0, "FileWatcher"); qmlRegisterType("example", 1, 0, "FpsItem"); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 54856caf..284ea970 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,16 +1,21 @@ cmake_minimum_required(VERSION 3.20) -if (FLUENTUI_BUILD_STATIC_LIB) +if (FLUENTUI_BUILD_STATIC_LIB AND (QT_VERSION VERSION_GREATER_EQUAL "6.2")) project(fluentui LANGUAGES CXX) else() project(fluentuiplugin LANGUAGES CXX) endif() + #配置通用编译 set(CMAKE_CXX_STANDARD_REQUIRED ON) if(APPLE) set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64" CACHE STRING "" FORCE) endif() +if (FLUENTUI_BUILD_STATIC_LIB) + add_definitions(-DFLUENTUI_BUILD_STATIC_LIB) +endif() + find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Quick Qml) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Quick Qml) @@ -63,6 +68,7 @@ if (FLUENTUI_BUILD_STATIC_LIB) set(LIB_TYPE "STATIC") else() set(LIB_TYPE "SHARED") + list(REMOVE_ITEM sources_files FluentUI.h FluentUI.cpp) endif() if (FLUENTUI_BUILD_STATIC_LIB) @@ -83,6 +89,9 @@ if(WIN32) endif() if(QT_VERSION VERSION_GREATER_EQUAL "6.2") + if(FLUENTUI_BUILD_STATIC_LIB) + set(FLUENTUI_QML_PLUGIN_DIRECTORY ${CMAKE_BINARY_DIR}/FluentUI) + endif() qt_add_library(${PROJECT_NAME} ${LIB_TYPE}) qt_add_qml_module(${PROJECT_NAME} PLUGIN_TARGET ${PLUGIN_TARGET_NAME} @@ -94,14 +103,14 @@ if(QT_VERSION VERSION_GREATER_EQUAL "6.2") SOURCES ${sources_files} ${FLUENTUI_VERSION_RC_PATH} QML_FILES ${qml_files} RESOURCES ${resource_files} - RESOURCE_PREFIX "/" + RESOURCE_PREFIX "/qt/qml" ) else() include(QmlPlugin) add_qmlplugin(${PROJECT_NAME} URI "FluentUI" VERSION 1.0 - SOURCES ${sources_files} ${FLUENTUI_VERSION_RC_PATH} resource.qrc + SOURCES ${sources_files} ${FLUENTUI_VERSION_RC_PATH} Qt5/imports/fluentui.qrc QMLFILES ${qml_files} QMLDIR imports/FluentUI BINARY_DIR ${FLUENTUI_QML_PLUGIN_DIRECTORY} diff --git a/src/FluentUI.cpp b/src/FluentUI.cpp new file mode 100644 index 00000000..6a1cf92c --- /dev/null +++ b/src/FluentUI.cpp @@ -0,0 +1,182 @@ +#include "FluentUI.h" + +#include +#include "WindowHelper.h" +#include "Def.h" +#include "FluApp.h" +#include "FluColors.h" +#include "FluTheme.h" +#include "FluTools.h" +#include "FluTextStyle.h" +#include "FluHttp.h" +#include "FluHttpInterceptor.h" +#include "FluWatermark.h" +#include "FluCaptcha.h" +#include "Screenshot.h" +#include "QRCode.h" + +int major = 1; +int minor = 0; +auto uri = "FluentUI"; + +FluentUI* FluentUI::m_instance = nullptr; + +FluentUI *FluentUI::getInstance() +{ + if(FluentUI::m_instance == nullptr){ + FluentUI::m_instance = new FluentUI; + } + return FluentUI::m_instance; +} + +void FluentUI::registerTypes(QQmlEngine *engine){ + initializeEngine(engine,uri); + registerTypes(uri); +} + +void FluentUI::registerTypes(const char *uri){ +#if (QT_VERSION < QT_VERSION_CHECK(6, 2, 0)) + Q_INIT_RESOURCE(fluentui); +#endif + qmlRegisterType(uri,major,minor,"WindowHelper"); + qmlRegisterType(uri,major,minor,"QRCode"); + qmlRegisterType(uri,major,minor,"FluCaptcha"); + qmlRegisterType(uri,major,minor,"FluWatermark"); + qmlRegisterType(uri,major,minor,"ScreenshotBackground"); + qmlRegisterType(uri,major,minor,"Screenshot"); + qmlRegisterType(uri,major,minor,"FluColorSet"); + qmlRegisterType(uri,major,minor,"FluHttpInterceptor"); + qmlRegisterType(uri,major,minor,"FluHttp"); + qmlRegisterType(uri,major,minor,"HttpCallable"); + qmlRegisterType(uri,major,minor,"HttpRequest"); + + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/ColorPicker/ColorPicker.qml"),uri,major,minor,"ColorPicker"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/ColorPicker/Content/Checkerboard.qml"),uri,major,minor,"Checkerboard"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/ColorPicker/Content/ColorSlider.qml"),uri,major,minor,"ColorSlider"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/ColorPicker/Content/NumberBox.qml"),uri,major,minor,"NumberBox"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/ColorPicker/Content/PanelBorder.qml"),uri,major,minor,"PanelBorder"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/ColorPicker/Content/SBPicker.qml"),uri,major,minor,"SBPicker"); + + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluAcrylic.qml"),uri,major,minor,"FluAcrylic"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluAppBar.qml"),uri,major,minor,"FluAppBar"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluArea.qml"),uri,major,minor,"FluArea"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluAutoSuggestBox.qml"),uri,major,minor,"FluAutoSuggestBox"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluBadge.qml"),uri,major,minor,"FluBadge"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluBreadcrumbBar.qml"),uri,major,minor,"FluBreadcrumbBar"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluButton.qml"),uri,major,minor,"FluButton"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluCalendarPicker.qml"),uri,major,minor,"FluCalendarPicker"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluCalendarView.qml"),uri,major,minor,"FluCalendarView"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluCarousel.qml"),uri,major,minor,"FluCarousel"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluChart.qml"),uri,major,minor,"FluChart"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluCheckBox.qml"),uri,major,minor,"FluCheckBox"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluColorPicker.qml"),uri,major,minor,"FluColorPicker"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluColorView.qml"),uri,major,minor,"FluColorView"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluComboBox.qml"),uri,major,minor,"FluComboBox"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluContentDialog.qml"),uri,major,minor,"FluContentDialog"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluContentPage.qml"),uri,major,minor,"FluContentPage"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluControl.qml"),uri,major,minor,"FluControl"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluCopyableText.qml"),uri,major,minor,"FluCopyableText"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluDatePicker.qml"),uri,major,minor,"FluDatePicker"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluDivider.qml"),uri,major,minor,"FluDivider"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluDropDownButton.qml"),uri,major,minor,"FluDropDownButton"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluExpander.qml"),uri,major,minor,"FluExpander"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluFilledButton.qml"),uri,major,minor,"FluFilledButton"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluFlipView.qml"),uri,major,minor,"FluFlipView"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluFocusRectangle.qml"),uri,major,minor,"FluFocusRectangle"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluIcon.qml"),uri,major,minor,"FluIcon"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluIconButton.qml"),uri,major,minor,"FluIconButton"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluImage.qml"),uri,major,minor,"FluImage"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluInfoBar.qml"),uri,major,minor,"FluInfoBar"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluItem.qml"),uri,major,minor,"FluItem"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluItemDelegate.qml"),uri,major,minor,"FluItemDelegate"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluMenu.qml"),uri,major,minor,"FluMenu"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluMenuBar.qml"),uri,major,minor,"FluMenuBar"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluMenuBarItem.qml"),uri,major,minor,"FluMenuBarItem"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluMenuItem.qml"),uri,major,minor,"FluMenuItem"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluMenuSeparator.qml"),uri,major,minor,"FluMenuSeparator"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluMultilineTextBox.qml"),uri,major,minor,"FluMultilineTextBox"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluNavigationView.qml"),uri,major,minor,"FluNavigationView"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluObject.qml"),uri,major,minor,"FluObject"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluPage.qml"),uri,major,minor,"FluPage"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluPagination.qml"),uri,major,minor,"FluPagination"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluPaneItem.qml"),uri,major,minor,"FluPaneItem"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluPaneItemEmpty.qml"),uri,major,minor,"FluPaneItemEmpty"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluPaneItemExpander.qml"),uri,major,minor,"FluPaneItemExpander"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluPaneItemHeader.qml"),uri,major,minor,"FluPaneItemHeader"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluPaneItemSeparator.qml"),uri,major,minor,"FluPaneItemSeparator"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluPasswordBox.qml"),uri,major,minor,"FluPasswordBox"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluPivot.qml"),uri,major,minor,"FluPivot"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluPivotItem.qml"),uri,major,minor,"FluPivotItem"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluPopup.qml"),uri,major,minor,"FluPopup"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluProgressBar.qml"),uri,major,minor,"FluProgressBar"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluProgressRing.qml"),uri,major,minor,"FluProgressRing"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluQRCode.qml"),uri,major,minor,"FluQRCode"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluRadioButton.qml"),uri,major,minor,"FluRadioButton"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluRadioButtons.qml"),uri,major,minor,"FluRadioButtons"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluRatingControl.qml"),uri,major,minor,"FluRatingControl"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluRectangle.qml"),uri,major,minor,"FluRectangle"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluRemoteLoader.qml"),uri,major,minor,"FluRemoteLoader"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluScreenshot.qml"),uri,major,minor,"FluScreenshot"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluScrollBar.qml"),uri,major,minor,"FluScrollBar"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluScrollIndicator.qml"),uri,major,minor,"FluScrollIndicator"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluScrollablePage.qml"),uri,major,minor,"FluScrollablePage"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluShadow.qml"),uri,major,minor,"FluShadow"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluSlider.qml"),uri,major,minor,"FluSlider"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluSpinBox.qml"),uri,major,minor,"FluSpinBox"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluStatusView.qml"),uri,major,minor,"FluStatusView"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluTabView.qml"),uri,major,minor,"FluTabView"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluTableModelColumn.qml"),uri,major,minor,"FluTableModelColumn"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluTableView.qml"),uri,major,minor,"FluTableView"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluText.qml"),uri,major,minor,"FluText"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluTextBox.qml"),uri,major,minor,"FluTextBox"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluTextBoxBackground.qml"),uri,major,minor,"FluTextBoxBackground"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluTextBoxMenu.qml"),uri,major,minor,"FluTextBoxMenu"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluTextButton.qml"),uri,major,minor,"FluTextButton"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluTimePicker.qml"),uri,major,minor,"FluTimePicker"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluTimeline.qml"),uri,major,minor,"FluTimeline"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluToggleButton.qml"),uri,major,minor,"FluToggleButton"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluToggleSwitch.qml"),uri,major,minor,"FluToggleSwitch"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluTooltip.qml"),uri,major,minor,"FluTooltip"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluTour.qml"),uri,major,minor,"FluTour"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluTreeView.qml"),uri,major,minor,"FluTreeView"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluWindow.qml"),uri,major,minor,"FluWindow"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluRangeSlider.qml"),uri,major,minor,"FluRangeSlider"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluStaggeredView.qml"),uri,major,minor,"FluStaggeredView"); + qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluProgressButton.qml"),uri,major,minor,"FluProgressButton"); + + qmlRegisterUncreatableMetaObject(Fluent_Awesome::staticMetaObject, uri,major,minor,"FluentIcons", "Access to enums & flags only"); + qmlRegisterUncreatableMetaObject(FluHttpType::staticMetaObject, uri,major,minor,"FluHttpType", "Access to enums & flags only"); + qmlRegisterUncreatableMetaObject(FluThemeType::staticMetaObject, uri,major,minor,"FluThemeType", "Access to enums & flags only"); + qmlRegisterUncreatableMetaObject(FluPageType::staticMetaObject, uri,major,minor,"FluPageType", "Access to enums & flags only"); + qmlRegisterUncreatableMetaObject(FluWindowType::staticMetaObject, uri,major,minor,"FluWindowType", "Access to enums & flags only"); + qmlRegisterUncreatableMetaObject(FluTreeViewType::staticMetaObject, uri,major,minor,"FluTreeViewType", "Access to enums & flags only"); + qmlRegisterUncreatableMetaObject(FluStatusViewType::staticMetaObject, uri,major,minor,"FluStatusViewType", "Access to enums & flags only"); + qmlRegisterUncreatableMetaObject(FluContentDialogType::staticMetaObject, uri,major,minor,"FluContentDialogType", "Access to enums & flags only"); + qmlRegisterUncreatableMetaObject(FluTimePickerType::staticMetaObject, uri,major,minor,"FluTimePickerType", "Access to enums & flags only"); + qmlRegisterUncreatableMetaObject(FluCalendarViewType::staticMetaObject, uri,major,minor,"FluCalendarViewType", "Access to enums & flags only"); + qmlRegisterUncreatableMetaObject(FluTabViewType::staticMetaObject, uri,major,minor,"FluTabViewType", "Access to enums & flags only"); + qmlRegisterUncreatableMetaObject(FluNavigationViewType::staticMetaObject, uri,major,minor,"FluNavigationViewType", "Access to enums & flags only"); + qmlRegisterUncreatableMetaObject(FluTimelineType::staticMetaObject, uri,major,minor,"FluTimelineType", "Access to enums & flags only"); + qmlRegisterUncreatableMetaObject(FluScreenshotType::staticMetaObject, uri,major,minor,"FluScreenshotType", "Access to enums & flags only"); + + qmlRegisterModule(uri,major,minor); +} + +void FluentUI::initializeEngine(QQmlEngine *engine, const char *uri){ +#ifdef Q_OS_WIN + QFont font; + font.setFamily("Microsoft YaHei"); + QGuiApplication::setFont(font); +#endif + FluApp* app = FluApp::getInstance(); + engine->rootContext()->setContextProperty("FluApp",app); + FluColors* colors = FluColors::getInstance(); + engine->rootContext()->setContextProperty("FluColors",colors); + FluTheme* theme = FluTheme::getInstance(); + engine->rootContext()->setContextProperty("FluTheme",theme); + FluTools* tools = FluTools::getInstance(); + engine->rootContext()->setContextProperty("FluTools",tools); + FluTextStyle* textStyle = FluTextStyle::getInstance(); + engine->rootContext()->setContextProperty("FluTextStyle",textStyle); + engine->addImportPath("qrc:/qt/qml"); +} diff --git a/src/FluentUI.h b/src/FluentUI.h new file mode 100644 index 00000000..ba6654f8 --- /dev/null +++ b/src/FluentUI.h @@ -0,0 +1,19 @@ +#ifndef FLUENTUI_H +#define FLUENTUI_H + +#include +#include + +class FluentUI : public QObject +{ + Q_OBJECT +public: + static FluentUI *getInstance(); + Q_DECL_EXPORT void registerTypes(QQmlEngine *engine); + void registerTypes(const char *uri); + void initializeEngine(QQmlEngine *engine, const char *uri); +private: + static FluentUI* m_instance; +}; + +#endif // FLUENTUI_H diff --git a/src/Qt5/imports/fluentui.qrc b/src/Qt5/imports/fluentui.qrc new file mode 100644 index 00000000..31c5f1fa --- /dev/null +++ b/src/Qt5/imports/fluentui.qrc @@ -0,0 +1,99 @@ + + + FluentUI/JS/Chart.js + FluentUI/Image/noise.png + FluentUI/Font/Segoe_Fluent_Icons.ttf + FluentUI/Controls/FluAcrylic.qml + FluentUI/Controls/FluAppBar.qml + FluentUI/Controls/FluArea.qml + FluentUI/Controls/FluAutoSuggestBox.qml + FluentUI/Controls/FluBadge.qml + FluentUI/Controls/FluBreadcrumbBar.qml + FluentUI/Controls/FluButton.qml + FluentUI/Controls/FluCalendarPicker.qml + FluentUI/Controls/FluCalendarView.qml + FluentUI/Controls/FluCarousel.qml + FluentUI/Controls/FluChart.qml + FluentUI/Controls/FluCheckBox.qml + FluentUI/Controls/FluColorPicker.qml + FluentUI/Controls/FluColorView.qml + FluentUI/Controls/FluComboBox.qml + FluentUI/Controls/FluContentDialog.qml + FluentUI/Controls/FluContentPage.qml + FluentUI/Controls/FluControl.qml + FluentUI/Controls/FluCopyableText.qml + FluentUI/Controls/FluDatePicker.qml + FluentUI/Controls/FluDivider.qml + FluentUI/Controls/FluDropDownButton.qml + FluentUI/Controls/FluExpander.qml + FluentUI/Controls/FluFilledButton.qml + FluentUI/Controls/FluFlipView.qml + FluentUI/Controls/FluFocusRectangle.qml + FluentUI/Controls/FluIcon.qml + FluentUI/Controls/FluIconButton.qml + FluentUI/Controls/FluImage.qml + FluentUI/Controls/FluInfoBar.qml + FluentUI/Controls/FluItem.qml + FluentUI/Controls/FluItemDelegate.qml + FluentUI/Controls/FluMenu.qml + FluentUI/Controls/FluMenuBar.qml + FluentUI/Controls/FluMenuBarItem.qml + FluentUI/Controls/FluMenuItem.qml + FluentUI/Controls/FluMenuSeparator.qml + FluentUI/Controls/FluMultilineTextBox.qml + FluentUI/Controls/FluNavigationView.qml + FluentUI/Controls/FluObject.qml + FluentUI/Controls/FluPage.qml + FluentUI/Controls/FluPagination.qml + FluentUI/Controls/FluPaneItem.qml + FluentUI/Controls/FluPaneItemEmpty.qml + FluentUI/Controls/FluPaneItemExpander.qml + FluentUI/Controls/FluPaneItemHeader.qml + FluentUI/Controls/FluPaneItemSeparator.qml + FluentUI/Controls/FluPasswordBox.qml + FluentUI/Controls/FluPivot.qml + FluentUI/Controls/FluPivotItem.qml + FluentUI/Controls/FluPopup.qml + FluentUI/Controls/FluProgressBar.qml + FluentUI/Controls/FluProgressButton.qml + FluentUI/Controls/FluProgressRing.qml + FluentUI/Controls/FluQRCode.qml + FluentUI/Controls/FluRadioButton.qml + FluentUI/Controls/FluRadioButtons.qml + FluentUI/Controls/FluRangeSlider.qml + FluentUI/Controls/FluRatingControl.qml + FluentUI/Controls/FluRectangle.qml + FluentUI/Controls/FluRemoteLoader.qml + FluentUI/Controls/FluScreenshot.qml + FluentUI/Controls/FluScrollablePage.qml + FluentUI/Controls/FluScrollBar.qml + FluentUI/Controls/FluScrollIndicator.qml + FluentUI/Controls/FluShadow.qml + FluentUI/Controls/FluSlider.qml + FluentUI/Controls/FluSpinBox.qml + FluentUI/Controls/FluStaggeredView.qml + FluentUI/Controls/FluStatusView.qml + FluentUI/Controls/FluTableModelColumn.qml + FluentUI/Controls/FluTableView.qml + FluentUI/Controls/FluTabView.qml + FluentUI/Controls/FluText.qml + FluentUI/Controls/FluTextBox.qml + FluentUI/Controls/FluTextBoxBackground.qml + FluentUI/Controls/FluTextBoxMenu.qml + FluentUI/Controls/FluTextButton.qml + FluentUI/Controls/FluTimeline.qml + FluentUI/Controls/FluTimePicker.qml + FluentUI/Controls/FluToggleButton.qml + FluentUI/Controls/FluToggleSwitch.qml + FluentUI/Controls/FluTooltip.qml + FluentUI/Controls/FluTour.qml + FluentUI/Controls/FluTreeView.qml + FluentUI/Controls/FluWindow.qml + FluentUI/Controls/ColorPicker/ColorPicker.qml + FluentUI/Controls/ColorPicker/Content/Checkerboard.qml + FluentUI/Controls/ColorPicker/Content/ColorSlider.qml + FluentUI/Controls/ColorPicker/Content/NumberBox.qml + FluentUI/Controls/ColorPicker/Content/PanelBorder.qml + FluentUI/Controls/ColorPicker/Content/SBPicker.qml + + diff --git a/src/fluentuiplugin.cpp b/src/fluentuiplugin.cpp index 35b88a9c..59eac0a5 100644 --- a/src/fluentuiplugin.cpp +++ b/src/fluentuiplugin.cpp @@ -1,90 +1,19 @@ #include "fluentuiplugin.h" -#include -#include -#include -#include "WindowHelper.h" -#include "Def.h" -#include "FluApp.h" -#include "FluColors.h" -#include "FluTheme.h" -#include "FluTools.h" -#include "FluTextStyle.h" -#include "FluHttp.h" -#include "FluHttpInterceptor.h" -#include "FluWatermark.h" -#include "FluCaptcha.h" -#include "Screenshot.h" -#include "QRCode.h" -int major = 1; -int minor = 0; -static FluentUIPlugin instance; +#include "FluentUI.h" FluentUIPlugin::FluentUIPlugin() { -#ifdef FLUENTUI_BUILD_STATIC_LIB - Q_INIT_RESOURCE(fluentui); -#endif + } void FluentUIPlugin::registerTypes(const char *uri) { - qmlRegisterType(uri,major,minor,"WindowHelper"); - qmlRegisterType(uri,major,minor,"QRCode"); - qmlRegisterType(uri,major,minor,"FluCaptcha"); - qmlRegisterType(uri,major,minor,"FluWatermark"); - qmlRegisterType(uri,major,minor,"ScreenshotBackground"); - qmlRegisterType(uri,major,minor,"Screenshot"); - qmlRegisterType(uri,major,minor,"FluColorSet"); - qmlRegisterType(uri,major,minor,"FluHttpInterceptor"); - qmlRegisterType(uri,major,minor,"FluHttp"); - qmlRegisterType(uri,major,minor,"HttpCallable"); - qmlRegisterType(uri,major,minor,"HttpRequest"); - qmlRegisterUncreatableMetaObject(Fluent_Awesome::staticMetaObject, uri,major,minor,"FluentIcons", "Access to enums & flags only"); - qmlRegisterUncreatableMetaObject(FluHttpType::staticMetaObject, uri,major,minor,"FluHttpType", "Access to enums & flags only"); - qmlRegisterUncreatableMetaObject(FluThemeType::staticMetaObject, uri,major,minor,"FluThemeType", "Access to enums & flags only"); - qmlRegisterUncreatableMetaObject(FluPageType::staticMetaObject, uri,major,minor,"FluPageType", "Access to enums & flags only"); - qmlRegisterUncreatableMetaObject(FluWindowType::staticMetaObject, uri,major,minor,"FluWindowType", "Access to enums & flags only"); - qmlRegisterUncreatableMetaObject(FluTreeViewType::staticMetaObject, uri,major,minor,"FluTreeViewType", "Access to enums & flags only"); - qmlRegisterUncreatableMetaObject(FluStatusViewType::staticMetaObject, uri,major,minor,"FluStatusViewType", "Access to enums & flags only"); - qmlRegisterUncreatableMetaObject(FluContentDialogType::staticMetaObject, uri,major,minor,"FluContentDialogType", "Access to enums & flags only"); - qmlRegisterUncreatableMetaObject(FluTimePickerType::staticMetaObject, uri,major,minor,"FluTimePickerType", "Access to enums & flags only"); - qmlRegisterUncreatableMetaObject(FluCalendarViewType::staticMetaObject, uri,major,minor,"FluCalendarViewType", "Access to enums & flags only"); - qmlRegisterUncreatableMetaObject(FluTabViewType::staticMetaObject, uri,major,minor,"FluTabViewType", "Access to enums & flags only"); - qmlRegisterUncreatableMetaObject(FluNavigationViewType::staticMetaObject, uri,major,minor,"FluNavigationViewType", "Access to enums & flags only"); - qmlRegisterUncreatableMetaObject(FluTimelineType::staticMetaObject, uri,major,minor,"FluTimelineType", "Access to enums & flags only"); - qmlRegisterUncreatableMetaObject(FluScreenshotType::staticMetaObject, uri,major,minor,"FluScreenshotType", "Access to enums & flags only"); + FluentUI::getInstance()->registerTypes(uri); } -#ifdef FLUENTUI_BUILD_STATIC_LIB -void FluentUIPlugin::registerTypes() -{ - instance()->registerTypes("FluentUI"); -} - -FluentUIPlugin* FluentUIPlugin::instance() -{ - static FluentUIPlugin instance; - return &instance; -} -#endif void FluentUIPlugin::initializeEngine(QQmlEngine *engine, const char *uri) { Q_UNUSED(uri) -#ifdef Q_OS_WIN - QFont font; - font.setFamily("Microsoft YaHei"); - QGuiApplication::setFont(font); -#endif - FluApp* app = FluApp::getInstance(); - engine->rootContext()->setContextProperty("FluApp",app); - FluColors* colors = FluColors::getInstance(); - engine->rootContext()->setContextProperty("FluColors",colors); - FluTheme* theme = FluTheme::getInstance(); - engine->rootContext()->setContextProperty("FluTheme",theme); - FluTools* tools = FluTools::getInstance(); - engine->rootContext()->setContextProperty("FluTools",tools); - FluTextStyle* textStyle = FluTextStyle::getInstance(); - engine->rootContext()->setContextProperty("FluTextStyle",textStyle); - engine->addImportPath("qrc:/FluentUI/imports/"); + FluentUI::getInstance()->initializeEngine(engine,uri); } diff --git a/src/fluentuiplugin.h b/src/fluentuiplugin.h index f5546388..7cd6542e 100644 --- a/src/fluentuiplugin.h +++ b/src/fluentuiplugin.h @@ -7,14 +7,9 @@ class FluentUIPlugin : public QQmlExtensionPlugin { Q_OBJECT Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid) - public: FluentUIPlugin(); void registerTypes(const char *uri) Q_DECL_OVERRIDE; -#ifdef FLUENTUI_BUILD_STATIC_LIB - static void registerTypes(); - static FluentUIPlugin* instance(); -#endif void initializeEngine(QQmlEngine *engine, const char *uri) Q_DECL_OVERRIDE; }; diff --git a/src/resource.qrc b/src/resource.qrc deleted file mode 100644 index b00cf1a7..00000000 --- a/src/resource.qrc +++ /dev/null @@ -1,99 +0,0 @@ - - - Qt5/imports/FluentUI/JS/Chart.js - Qt5/imports/FluentUI/Image/noise.png - Qt5/imports/FluentUI/Controls/FluAcrylic.qml - Qt5/imports/FluentUI/Controls/FluAppBar.qml - Qt5/imports/FluentUI/Controls/FluArea.qml - Qt5/imports/FluentUI/Controls/FluAutoSuggestBox.qml - Qt5/imports/FluentUI/Controls/FluBadge.qml - Qt5/imports/FluentUI/Controls/FluBreadcrumbBar.qml - Qt5/imports/FluentUI/Controls/FluButton.qml - Qt5/imports/FluentUI/Controls/FluCalendarPicker.qml - Qt5/imports/FluentUI/Controls/FluCalendarView.qml - Qt5/imports/FluentUI/Controls/FluCarousel.qml - Qt5/imports/FluentUI/Controls/FluChart.qml - Qt5/imports/FluentUI/Controls/FluCheckBox.qml - Qt5/imports/FluentUI/Controls/FluColorPicker.qml - Qt5/imports/FluentUI/Controls/FluColorView.qml - Qt5/imports/FluentUI/Controls/FluComboBox.qml - Qt5/imports/FluentUI/Controls/FluContentDialog.qml - Qt5/imports/FluentUI/Controls/FluContentPage.qml - Qt5/imports/FluentUI/Controls/FluControl.qml - Qt5/imports/FluentUI/Controls/FluCopyableText.qml - Qt5/imports/FluentUI/Controls/FluDatePicker.qml - Qt5/imports/FluentUI/Controls/FluDivider.qml - Qt5/imports/FluentUI/Controls/FluDropDownButton.qml - Qt5/imports/FluentUI/Controls/FluExpander.qml - Qt5/imports/FluentUI/Controls/FluFilledButton.qml - Qt5/imports/FluentUI/Controls/FluFlipView.qml - Qt5/imports/FluentUI/Controls/FluFocusRectangle.qml - Qt5/imports/FluentUI/Controls/FluIcon.qml - Qt5/imports/FluentUI/Controls/FluIconButton.qml - Qt5/imports/FluentUI/Controls/FluImage.qml - Qt5/imports/FluentUI/Controls/FluInfoBar.qml - Qt5/imports/FluentUI/Controls/FluItem.qml - Qt5/imports/FluentUI/Controls/FluItemDelegate.qml - Qt5/imports/FluentUI/Controls/FluMenu.qml - Qt5/imports/FluentUI/Controls/FluMenuBar.qml - Qt5/imports/FluentUI/Controls/FluMenuBarItem.qml - Qt5/imports/FluentUI/Controls/FluMenuItem.qml - Qt5/imports/FluentUI/Controls/FluMenuSeparator.qml - Qt5/imports/FluentUI/Controls/FluMultilineTextBox.qml - Qt5/imports/FluentUI/Controls/FluNavigationView.qml - Qt5/imports/FluentUI/Controls/FluObject.qml - Qt5/imports/FluentUI/Controls/FluPage.qml - Qt5/imports/FluentUI/Controls/FluPagination.qml - Qt5/imports/FluentUI/Controls/FluPaneItem.qml - Qt5/imports/FluentUI/Controls/FluPaneItemEmpty.qml - Qt5/imports/FluentUI/Controls/FluPaneItemExpander.qml - Qt5/imports/FluentUI/Controls/FluPaneItemHeader.qml - Qt5/imports/FluentUI/Controls/FluPaneItemSeparator.qml - Qt5/imports/FluentUI/Controls/FluPasswordBox.qml - Qt5/imports/FluentUI/Controls/FluPivot.qml - Qt5/imports/FluentUI/Controls/FluPivotItem.qml - Qt5/imports/FluentUI/Controls/FluPopup.qml - Qt5/imports/FluentUI/Controls/FluProgressBar.qml - Qt5/imports/FluentUI/Controls/FluProgressRing.qml - Qt5/imports/FluentUI/Controls/FluQRCode.qml - Qt5/imports/FluentUI/Controls/FluRadioButton.qml - Qt5/imports/FluentUI/Controls/FluRadioButtons.qml - Qt5/imports/FluentUI/Controls/FluRatingControl.qml - Qt5/imports/FluentUI/Controls/FluRectangle.qml - Qt5/imports/FluentUI/Controls/FluRemoteLoader.qml - Qt5/imports/FluentUI/Controls/FluScreenshot.qml - Qt5/imports/FluentUI/Controls/FluScrollablePage.qml - Qt5/imports/FluentUI/Controls/FluScrollBar.qml - Qt5/imports/FluentUI/Controls/FluScrollIndicator.qml - Qt5/imports/FluentUI/Controls/FluShadow.qml - Qt5/imports/FluentUI/Controls/FluSlider.qml - Qt5/imports/FluentUI/Controls/FluSpinBox.qml - Qt5/imports/FluentUI/Controls/FluStatusView.qml - Qt5/imports/FluentUI/Controls/FluTableModelColumn.qml - Qt5/imports/FluentUI/Controls/FluTableView.qml - Qt5/imports/FluentUI/Controls/FluTabView.qml - Qt5/imports/FluentUI/Controls/FluText.qml - Qt5/imports/FluentUI/Controls/FluTextBox.qml - Qt5/imports/FluentUI/Controls/FluTextBoxBackground.qml - Qt5/imports/FluentUI/Controls/FluTextBoxMenu.qml - Qt5/imports/FluentUI/Controls/FluTextButton.qml - Qt5/imports/FluentUI/Controls/FluTimeline.qml - Qt5/imports/FluentUI/Controls/FluTimePicker.qml - Qt5/imports/FluentUI/Controls/FluToggleButton.qml - Qt5/imports/FluentUI/Controls/FluToggleSwitch.qml - Qt5/imports/FluentUI/Controls/FluTooltip.qml - Qt5/imports/FluentUI/Controls/FluTour.qml - Qt5/imports/FluentUI/Controls/FluTreeView.qml - Qt5/imports/FluentUI/Controls/FluWindow.qml - Qt5/imports/FluentUI/Font/Segoe_Fluent_Icons.ttf - Qt5/imports/FluentUI/Controls/ColorPicker/ColorPicker.qml - Qt5/imports/FluentUI/Controls/ColorPicker/Content/Checkerboard.qml - Qt5/imports/FluentUI/Controls/ColorPicker/Content/ColorSlider.qml - Qt5/imports/FluentUI/Controls/ColorPicker/Content/NumberBox.qml - Qt5/imports/FluentUI/Controls/ColorPicker/Content/PanelBorder.qml - Qt5/imports/FluentUI/Controls/ColorPicker/Content/SBPicker.qml - Qt5/imports/FluentUI/Controls/FluRangeSlider.qml - Qt5/imports/FluentUI/Controls/FluStaggeredView.qml - Qt5/imports/FluentUI/Controls/FluProgressButton.qml - -