This commit is contained in:
ZHUZICHU\zhuzi 2025-03-12 09:55:58 +08:00
parent 1990203f3b
commit 80dd3ebd35
5 changed files with 13 additions and 14 deletions

View File

@ -13,7 +13,7 @@ list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/.cmake/)
include(GetGitRevisionDescription) include(GetGitRevisionDescription)
option(FLUENTUI_BUILD_EXAMPLES "Build FluentUI demo applications." ON) option(FLUENTUI_BUILD_EXAMPLES "Build FluentUI demo applications." ON)
option(FLUENTUI_BUILD_STATIC_LIB "Build static library." OFF) option(FLUENTUI_BUILD_STATIC_LIB "Build static library." ON)
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core) find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core)

View File

@ -90,7 +90,7 @@ int main(int argc, char *argv[]) {
engine.rootContext()->setContextProperty("TranslateHelper", TranslateHelper::getInstance()); engine.rootContext()->setContextProperty("TranslateHelper", TranslateHelper::getInstance());
engine.rootContext()->setContextProperty("Network", Network::getInstance()); engine.rootContext()->setContextProperty("Network", Network::getInstance());
#ifdef FLUENTUI_BUILD_STATIC_LIB #ifdef FLUENTUI_BUILD_STATIC_LIB
FluentUI::getInstance()->registerTypes(&engine); FluentUI::registerTypes(&engine);
#endif #endif
const QUrl url(QStringLiteral("qrc:/example/qml/App.qml")); const QUrl url(QStringLiteral("qrc:/example/qml/App.qml"));
QObject::connect( QObject::connect(

View File

@ -145,7 +145,7 @@ endif ()
if (QT_VERSION VERSION_GREATER_EQUAL "6.2") if (QT_VERSION VERSION_GREATER_EQUAL "6.2")
#Qt6.2使qt_add_libraryqt_add_qml_module #Qt6.2使qt_add_libraryqt_add_qml_module
if (FLUENTUI_BUILD_STATIC_LIB) if (FLUENTUI_BUILD_STATIC_LIB)
set(FLUENTUI_QML_PLUGIN_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/FluentUI) set(FLUENTUI_QML_PLUGIN_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/FluentUI)
endif () endif ()
qt_add_library(${PROJECT_NAME} ${LIB_TYPE}) qt_add_library(${PROJECT_NAME} ${LIB_TYPE})
qt_add_qml_module(${PROJECT_NAME} qt_add_qml_module(${PROJECT_NAME}

View File

@ -23,12 +23,14 @@
#include "qmlcustomplot/ticker.h" #include "qmlcustomplot/ticker.h"
#include "qmlcustomplot/grid.h" #include "qmlcustomplot/grid.h"
const char* FluentUI::_uri = "FluentUI";
void FluentUI::registerTypes(QQmlEngine *engine) { void FluentUI::registerTypes(QQmlEngine *engine) {
initializeEngine(engine, _uri); initializeEngine(engine, _uri);
registerTypes(_uri); registerTypes(_uri);
} }
void FluentUI::registerTypes(const char *uri) const { void FluentUI::registerTypes(const char *uri) {
#if (QT_VERSION < QT_VERSION_CHECK(6, 2, 0)) #if (QT_VERSION < QT_VERSION_CHECK(6, 2, 0))
Q_INIT_RESOURCE(fluentui); Q_INIT_RESOURCE(fluentui);
int major = _major; int major = _major;

View File

@ -2,25 +2,22 @@
#include <QObject> #include <QObject>
#include <QQmlEngine> #include <QQmlEngine>
#include "singleton.h"
/** /**
* @brief The FluentUI class * @brief The FluentUI class
*/ */
class FluentUI : public QObject { class FluentUI{
Q_OBJECT
public: public:
SINGLETON(FluentUI)
Q_DECL_EXPORT void registerTypes(QQmlEngine *engine); static Q_DECL_EXPORT void registerTypes(QQmlEngine *engine);
void registerTypes(const char *uri) const; static void registerTypes(const char *uri);
void initializeEngine(QQmlEngine *engine, [[maybe_unused]] const char *uri); static void initializeEngine(QQmlEngine *engine, [[maybe_unused]] const char *uri);
private: private:
const int _major = 1; static const int _major = 1;
const int _minor = 0; static const int _minor = 0;
const char *_uri = "FluentUI"; static const char *_uri;
}; };