This commit is contained in:
zhuzichu 2023-12-21 18:12:43 +08:00
parent 83a66b3f15
commit 217ceabbaa
17 changed files with 38 additions and 20 deletions

Binary file not shown.

Binary file not shown.

View File

@ -26,6 +26,7 @@ endif()
add_subdirectory(src) add_subdirectory(src)
#Release
target_compile_definitions(fluentuiplugin target_compile_definitions(fluentuiplugin
PRIVATE PRIVATE
QT_MESSAGELOGCONTEXT QT_MESSAGELOGCONTEXT

View File

@ -24,6 +24,7 @@ endif()
# #
file(TO_CMAKE_PATH "/" PATH_SEPARATOR) file(TO_CMAKE_PATH "/" PATH_SEPARATOR)
#Qt
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Quick Svg Network) find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Quick Svg Network)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Quick Svg Network) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Quick Svg Network)
@ -51,22 +52,28 @@ endforeach(filepath)
if(QT_VERSION VERSION_GREATER_EQUAL "6.2") if(QT_VERSION VERSION_GREATER_EQUAL "6.2")
#qml #qml
file(GLOB_RECURSE QML_PATHS *.qml) file(GLOB_RECURSE QML_PATHS *.qml qmldir)
foreach(filepath ${QML_PATHS}) foreach(filepath ${QML_PATHS})
string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/" "" filename ${filepath}) string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/" "" filename ${filepath})
if(${filepath} MATCHES "Qt${QT_VERSION_MAJOR}/") if(${filepath} MATCHES "qml-Qt6")
string(REPLACE "qml-Qt${QT_VERSION_MAJOR}" "qml" filealias ${filename}) string(REPLACE "qml-Qt6" "qml" filealias ${filename})
set_source_files_properties(${filename} PROPERTIES QT_RESOURCE_ALIAS ${filealias}) set_source_files_properties(${filename} PROPERTIES QT_RESOURCE_ALIAS ${filealias})
list(APPEND qml_files ${filename}) if(${filename} MATCHES "qmldir")
list(APPEND resource_files ${filename})
else()
list(APPEND qml_files ${filename})
endif()
endif() endif()
endforeach(filepath) endforeach(filepath)
# #
file(GLOB_RECURSE RES_PATHS *.png *.jpg *.svg *.ico *.ttf *.webp *.obj qmldir) file(GLOB_RECURSE RES_PATHS *.png *.jpg *.svg *.ico *.ttf *.webp *.obj)
foreach(filepath ${RES_PATHS}) foreach(filepath ${RES_PATHS})
string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/" "" filename ${filepath}) string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/" "" filename ${filepath})
message(${filename})
list(APPEND resource_files ${filename}) list(APPEND resource_files ${filename})
endforeach(filepath) endforeach(filepath)
endif() endif()
#Windowsrcinno setup #Windowsrcinno setup
@ -95,20 +102,19 @@ else ()
) )
endif () endif ()
#
if(WIN32) if(WIN32)
#
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
set(3RDPARTY_ARCH_DIR ${CMAKE_SOURCE_DIR}/3rdparty/Win_x86)
elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(3RDPARTY_ARCH_DIR ${CMAKE_SOURCE_DIR}/3rdparty/Win_x64)
endif()
if(MSVC) if(MSVC)
set(DLLPATH ${3RDPARTY_ARCH_DIR}/msvc/*.dll) if(CMAKE_SIZEOF_VOID_P EQUAL 4)
set(3RDPARTY_DLL_DIR ${CMAKE_SOURCE_DIR}/3rdparty/msvc/x86/*.dll)
elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(3RDPARTY_DLL_DIR ${CMAKE_SOURCE_DIR}/3rdparty/msvc/x64/*.dll)
endif()
elseif(MINGW) elseif(MINGW)
set(DLLPATH ${3RDPARTY_ARCH_DIR}/mingw/*.dll) set(3RDPARTY_DLL_DIR ${CMAKE_SOURCE_DIR}/3rdparty/mingw/*.dll)
endif() endif()
string(REPLACE "/" ${PATH_SEPARATOR} DLLPATH "${DLLPATH}") string(REPLACE "/" ${PATH_SEPARATOR} 3RDPARTY_DLL_DIR "${3RDPARTY_DLL_DIR}")
file(GLOB DLL_FILES ${DLLPATH}) file(GLOB DLL_FILES ${3RDPARTY_DLL_DIR})
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy COMMAND ${CMAKE_COMMAND} -E copy
${DLL_FILES} ${DLL_FILES}
@ -117,7 +123,7 @@ if(WIN32)
endif() endif()
if(QT_VERSION VERSION_GREATER_EQUAL "6.2") if(QT_VERSION VERSION_GREATER_EQUAL "6.2")
#qml #Qt6.2使qt_add_qml_module
qt_add_qml_module(example qt_add_qml_module(example
URI "example" URI "example"
VERSION 1.0 VERSION 1.0
@ -126,10 +132,11 @@ if(QT_VERSION VERSION_GREATER_EQUAL "6.2")
RESOURCE_PREFIX "/" RESOURCE_PREFIX "/"
) )
else() else()
#Qt6.2使qrc
target_include_directories(example PRIVATE target_include_directories(example PRIVATE
${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}
) )
target_sources(example PRIVATE example.qrc) target_sources(example PRIVATE example.qrc)
endif() endif()
#component,QML_NAMED_ELEMENTc++ #component,QML_NAMED_ELEMENTc++
@ -153,11 +160,13 @@ set_target_properties(example PROPERTIES
WIN32_EXECUTABLE TRUE WIN32_EXECUTABLE TRUE
) )
#Release
target_compile_definitions(example target_compile_definitions(example
PRIVATE PRIVATE
QT_MESSAGELOGCONTEXT QT_MESSAGELOGCONTEXT
) )
#
target_link_libraries(example PRIVATE target_link_libraries(example PRIVATE
Qt${QT_VERSION_MAJOR}::Quick Qt${QT_VERSION_MAJOR}::Quick
Qt${QT_VERSION_MAJOR}::Svg Qt${QT_VERSION_MAJOR}::Svg

View File

@ -14,6 +14,7 @@ if (FLUENTUI_BUILD_STATIC_LIB)
add_definitions(-DFLUENTUI_BUILD_STATIC_LIB) add_definitions(-DFLUENTUI_BUILD_STATIC_LIB)
endif() endif()
#Qt
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Quick Qml) find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Quick Qml)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Quick Qml) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Quick Qml)
@ -89,6 +90,7 @@ if(WIN32)
endif() 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
if(FLUENTUI_BUILD_STATIC_LIB) if(FLUENTUI_BUILD_STATIC_LIB)
set(FLUENTUI_QML_PLUGIN_DIRECTORY ${CMAKE_BINARY_DIR}/FluentUI) set(FLUENTUI_QML_PLUGIN_DIRECTORY ${CMAKE_BINARY_DIR}/FluentUI)
endif() endif()
@ -106,6 +108,7 @@ if(QT_VERSION VERSION_GREATER_EQUAL "6.2")
RESOURCE_PREFIX "/qt/qml" RESOURCE_PREFIX "/qt/qml"
) )
else() else()
#Qt6.2使add_qmlplugin.cmake/QmlPlugin.cmake
include(QmlPlugin) include(QmlPlugin)
add_qmlplugin(${PROJECT_NAME} add_qmlplugin(${PROJECT_NAME}
URI "FluentUI" URI "FluentUI"
@ -120,6 +123,7 @@ endif()
target_compile_definitions(${PROJECT_NAME} target_compile_definitions(${PROJECT_NAME}
PRIVATE PRIVATE
#qrcode
HAVE_CONFIG_H HAVE_CONFIG_H
) )

View File

@ -39,7 +39,7 @@ public:
void removeWindow(QQuickWindow* window); void removeWindow(QQuickWindow* window);
private: private:
QMap<quint64, QQuickWindow*> _windows; QMap<quint64, QQuickWindow*> _windows;
QObject* _application; QObject* _application = nullptr;
}; };
#endif // FLUAPP_H #endif // FLUAPP_H

View File

@ -4,6 +4,7 @@
#include "FluRegister.h" #include "FluRegister.h"
WindowLifecycle::WindowLifecycle(QObject *parent):QObject{parent}{ WindowLifecycle::WindowLifecycle(QObject *parent):QObject{parent}{
} }
void WindowLifecycle::onCompleted(QQuickWindow* window){ void WindowLifecycle::onCompleted(QQuickWindow* window){
@ -12,7 +13,10 @@ void WindowLifecycle::onCompleted(QQuickWindow* window){
} }
void WindowLifecycle::onDestoryOnClose(){ void WindowLifecycle::onDestoryOnClose(){
FluApp::getInstance()->removeWindow(this->_window); if(_window){
FluApp::getInstance()->removeWindow(this->_window);
_window = nullptr;
}
} }
void WindowLifecycle::onDestruction(){ void WindowLifecycle::onDestruction(){

View File

@ -23,7 +23,7 @@ public:
Q_INVOKABLE void onDestoryOnClose(); Q_INVOKABLE void onDestoryOnClose();
Q_INVOKABLE QVariant createRegister(QQuickWindow* window,const QString& path); Q_INVOKABLE QVariant createRegister(QQuickWindow* window,const QString& path);
private: private:
QQuickWindow* _window; QQuickWindow* _window = nullptr;
}; };
#endif // WINDOWLIFECYCLE_H #endif // WINDOWLIFECYCLE_H