mirror of
https://github.com/zhuzichu520/FluentUI.git
synced 2024-11-22 02:34:32 +08:00
update
This commit is contained in:
parent
6a31e86505
commit
a3f375c9ef
@ -2,11 +2,11 @@ cmake_minimum_required(VERSION 3.20)
|
||||
|
||||
project(FluentUI VERSION 1.0)
|
||||
|
||||
if(MSVC)
|
||||
if (MSVC)
|
||||
#让Release也生成pdb文件
|
||||
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /DEBUG /OPT:REF /OPT:ICF")
|
||||
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /DEBUG /OPT:REF /OPT:ICF")
|
||||
endif()
|
||||
endif ()
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/.cmake/)
|
||||
|
||||
@ -22,8 +22,8 @@ add_subdirectory(src)
|
||||
|
||||
#Release也支持日志打印代码位置
|
||||
target_compile_definitions(fluentuiplugin
|
||||
PRIVATE
|
||||
QT_MESSAGELOGCONTEXT
|
||||
PRIVATE
|
||||
QT_MESSAGELOGCONTEXT
|
||||
)
|
||||
|
||||
if (FLUENTUI_BUILD_EXAMPLES)
|
||||
|
@ -10,18 +10,18 @@ set(CMAKE_AUTORCC ON)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
#判断FluentUI库类型
|
||||
if(FLUENTUI_BUILD_STATIC_LIB)
|
||||
if (FLUENTUI_BUILD_STATIC_LIB)
|
||||
add_definitions(-DFLUENTUI_BUILD_STATIC_LIB)
|
||||
endif()
|
||||
endif ()
|
||||
|
||||
#设置可执行文件输出目录
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin/${CMAKE_BUILD_TYPE})
|
||||
|
||||
if(APPLE)
|
||||
if (APPLE)
|
||||
set(APPLICATION_DIR_PATH ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${PROJECT_NAME}.app/Contents/MacOS)
|
||||
else()
|
||||
else ()
|
||||
set(APPLICATION_DIR_PATH ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
|
||||
endif()
|
||||
endif ()
|
||||
|
||||
#导入Qt相关依赖包
|
||||
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Quick Svg Network)
|
||||
@ -32,46 +32,46 @@ find_program(QT_LUPDATE NAMES lupdate)
|
||||
find_program(QT_LRELEASE NAMES lrelease)
|
||||
file(GLOB TS_FILE_PATHS ${CMAKE_CURRENT_LIST_DIR}/ *.ts)
|
||||
add_custom_target(Script-UpdateTranslations
|
||||
COMMAND ${QT_LUPDATE} ${CMAKE_CURRENT_LIST_DIR} -ts ${PROJECT_NAME}_en_US.ts WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
|
||||
COMMAND ${QT_LUPDATE} ${CMAKE_CURRENT_LIST_DIR} -ts ${PROJECT_NAME}_zh_CN.ts WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
|
||||
COMMAND ${QT_LRELEASE} ${PROJECT_NAME}_en_US.ts WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
|
||||
COMMAND ${QT_LRELEASE} ${PROJECT_NAME}_zh_CN.ts WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
|
||||
COMMAND ${CMAKE_COMMAND} -E make_directory ${APPLICATION_DIR_PATH}/i18n
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_NAME}_en_US.qm ${PROJECT_NAME}_zh_CN.qm ${APPLICATION_DIR_PATH}/i18n
|
||||
SOURCES ${TS_FILE_PATHS}
|
||||
COMMAND ${QT_LUPDATE} ${CMAKE_CURRENT_LIST_DIR} -ts ${PROJECT_NAME}_en_US.ts WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
|
||||
COMMAND ${QT_LUPDATE} ${CMAKE_CURRENT_LIST_DIR} -ts ${PROJECT_NAME}_zh_CN.ts WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
|
||||
COMMAND ${QT_LRELEASE} ${PROJECT_NAME}_en_US.ts WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
|
||||
COMMAND ${QT_LRELEASE} ${PROJECT_NAME}_zh_CN.ts WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
|
||||
COMMAND ${CMAKE_COMMAND} -E make_directory ${APPLICATION_DIR_PATH}/i18n
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_NAME}_en_US.qm ${PROJECT_NAME}_zh_CN.qm ${APPLICATION_DIR_PATH}/i18n
|
||||
SOURCES ${TS_FILE_PATHS}
|
||||
)
|
||||
|
||||
##生成版本信息头文件
|
||||
set(HEADER_FILE_VERSION_PATH ${CMAKE_SOURCE_DIR}/${PROJECT_NAME}/Version.h)
|
||||
configure_file(
|
||||
${CMAKE_SOURCE_DIR}/.cmake/Version.h.in
|
||||
${HEADER_FILE_VERSION_PATH}
|
||||
${CMAKE_SOURCE_DIR}/.cmake/Version.h.in
|
||||
${HEADER_FILE_VERSION_PATH}
|
||||
)
|
||||
|
||||
#遍历所有Cpp文件
|
||||
file(GLOB_RECURSE CPP_FILES *.cpp *.h)
|
||||
foreach(filepath ${CPP_FILES})
|
||||
foreach (filepath ${CPP_FILES})
|
||||
string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/" "" filename ${filepath})
|
||||
list(APPEND sources_files ${filename})
|
||||
endforeach(filepath)
|
||||
endforeach (filepath)
|
||||
|
||||
if(WIN32)
|
||||
if (WIN32)
|
||||
list(APPEND sources_files "src/app_dmp.h")
|
||||
endif()
|
||||
endif ()
|
||||
|
||||
#如果是Windows平台,则生成rc文件,还有inno setup脚本文件
|
||||
set(EXAMPLE_VERSION_RC_PATH "")
|
||||
if(WIN32)
|
||||
if (WIN32)
|
||||
set(EXAMPLE_VERSION_RC_PATH ${CMAKE_CURRENT_BINARY_DIR}/version_${PROJECT_NAME}.rc)
|
||||
configure_file(
|
||||
${CMAKE_SOURCE_DIR}/.cmake/version_exe.rc.in
|
||||
${EXAMPLE_VERSION_RC_PATH}
|
||||
${CMAKE_SOURCE_DIR}/.cmake/version_exe.rc.in
|
||||
${EXAMPLE_VERSION_RC_PATH}
|
||||
)
|
||||
configure_file(
|
||||
${CMAKE_SOURCE_DIR}/.cmake/InstallerScript.iss.in
|
||||
${CMAKE_SOURCE_DIR}/action-cli/InstallerScript.iss
|
||||
)
|
||||
endif()
|
||||
configure_file(
|
||||
${CMAKE_SOURCE_DIR}/.cmake/InstallerScript.iss.in
|
||||
${CMAKE_SOURCE_DIR}/action-cli/InstallerScript.iss
|
||||
)
|
||||
endif ()
|
||||
|
||||
#加快qrc编译
|
||||
qt_add_big_resources(QRC_RESOURCES ${PROJECT_NAME}.qrc)
|
||||
@ -80,34 +80,34 @@ set_property(SOURCE ${PROJECT_NAME}.qrc PROPERTY SKIP_AUTORCC ON)
|
||||
list(APPEND sources_files ${QRC_RESOURCES})
|
||||
|
||||
#添加可执行文件
|
||||
if(WIN32)
|
||||
if (WIN32)
|
||||
list(APPEND sources_files ${EXAMPLE_VERSION_RC_PATH})
|
||||
endif()
|
||||
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
|
||||
endif ()
|
||||
if (${QT_VERSION_MAJOR} GREATER_EQUAL 6)
|
||||
qt_add_executable(${PROJECT_NAME}
|
||||
MANUAL_FINALIZATION
|
||||
${sources_files}
|
||||
MANUAL_FINALIZATION
|
||||
${sources_files}
|
||||
)
|
||||
else()
|
||||
else ()
|
||||
add_executable(${PROJECT_NAME}
|
||||
${sources_files}
|
||||
${sources_files}
|
||||
)
|
||||
endif()
|
||||
endif ()
|
||||
add_dependencies(${PROJECT_NAME} Script-UpdateTranslations)
|
||||
|
||||
#复制程序运行所需要的动态库
|
||||
if(WIN32)
|
||||
if(MSVC)
|
||||
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
|
||||
if (WIN32)
|
||||
if (MSVC)
|
||||
if (CMAKE_SIZEOF_VOID_P EQUAL 4)
|
||||
file(GLOB_RECURSE 3RDPARTY_DLL_DIR ${CMAKE_SOURCE_DIR}/3rdparty/msvc/x86/*.dll)
|
||||
elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||
elseif (CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||
file(GLOB_RECURSE 3RDPARTY_DLL_DIR ${CMAKE_SOURCE_DIR}/3rdparty/msvc/x64/*.dll)
|
||||
endif()
|
||||
elseif(MINGW)
|
||||
endif ()
|
||||
elseif (MINGW)
|
||||
file(GLOB_RECURSE 3RDPARTY_DLL_DIR ${CMAKE_SOURCE_DIR}/3rdparty/mingw/*.dll)
|
||||
endif()
|
||||
endif ()
|
||||
file(COPY ${3RDPARTY_DLL_DIR} DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
|
||||
endif()
|
||||
endif ()
|
||||
|
||||
#复制FluentUI源码到运行目录下,用于脚手架生成
|
||||
file(MAKE_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/source/)
|
||||
@ -115,37 +115,37 @@ file(COPY ${CMAKE_SOURCE_DIR}/src/ DESTINATION ${APPLICATION_DIR_PATH}/source/)
|
||||
|
||||
#导入component头文件,不然通过QML_NAMED_ELEMENT生成的c++类会找不到头文件报错
|
||||
target_include_directories(${PROJECT_NAME} PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/component
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/component
|
||||
)
|
||||
|
||||
#如果是静态库则需要手动注册插件,导入FluentUI.h头文件
|
||||
if(FLUENTUI_BUILD_STATIC_LIB)
|
||||
if (FLUENTUI_BUILD_STATIC_LIB)
|
||||
target_include_directories(${PROJECT_NAME} PRIVATE
|
||||
${CMAKE_SOURCE_DIR}/src
|
||||
${CMAKE_SOURCE_DIR}/src
|
||||
)
|
||||
endif()
|
||||
endif ()
|
||||
|
||||
#设置属性
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES
|
||||
MACOSX_BUNDLE_GUI_IDENTIFIER my.${PROJECT_NAME}.com
|
||||
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
|
||||
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
|
||||
MACOSX_BUNDLE TRUE
|
||||
WIN32_EXECUTABLE TRUE
|
||||
MACOSX_BUNDLE_GUI_IDENTIFIER my.${PROJECT_NAME}.com
|
||||
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
|
||||
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
|
||||
MACOSX_BUNDLE TRUE
|
||||
WIN32_EXECUTABLE TRUE
|
||||
)
|
||||
|
||||
#Release也支持日志打印代码位置
|
||||
target_compile_definitions(${PROJECT_NAME}
|
||||
PRIVATE
|
||||
QT_MESSAGELOGCONTEXT
|
||||
PRIVATE
|
||||
QT_MESSAGELOGCONTEXT
|
||||
)
|
||||
|
||||
#目标文件链接库
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE
|
||||
Qt${QT_VERSION_MAJOR}::Quick
|
||||
Qt${QT_VERSION_MAJOR}::Svg
|
||||
Qt${QT_VERSION_MAJOR}::Network
|
||||
fluentuiplugin
|
||||
Qt${QT_VERSION_MAJOR}::Quick
|
||||
Qt${QT_VERSION_MAJOR}::Svg
|
||||
Qt${QT_VERSION_MAJOR}::Network
|
||||
fluentuiplugin
|
||||
)
|
||||
|
||||
#添加部署脚本
|
||||
@ -153,23 +153,28 @@ if (CMAKE_BUILD_TYPE MATCHES "Release")
|
||||
if (APPLE)
|
||||
find_program(QT_DEPLOY_QT NAMES macdeployqt)
|
||||
add_custom_target(Script-DeployRelease
|
||||
COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_SOURCE_DIR}/dist
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${CMAKE_SOURCE_DIR}/dist
|
||||
COMMAND ${QT_DEPLOY_QT} ${CMAKE_SOURCE_DIR}/dist/${PROJECT_NAME}.app -qmldir=${CMAKE_CURRENT_LIST_DIR}
|
||||
COMMENT "MacOs Deploying Qt Dependencies After Build........."
|
||||
SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_SOURCE_DIR}/dist
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${CMAKE_SOURCE_DIR}/dist
|
||||
COMMAND ${QT_DEPLOY_QT} ${CMAKE_SOURCE_DIR}/dist/${PROJECT_NAME}.app -qmldir=${CMAKE_CURRENT_LIST_DIR}
|
||||
COMMENT "MacOs Deploying Qt Dependencies After Build........."
|
||||
SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
endif()
|
||||
if(WIN32)
|
||||
endif ()
|
||||
if (WIN32)
|
||||
find_program(QT_DEPLOY_QT NAMES windeployqt)
|
||||
add_custom_target(Script-DeployRelease
|
||||
COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_SOURCE_DIR}/dist
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${CMAKE_SOURCE_DIR}/dist
|
||||
COMMAND ${QT_DEPLOY_QT} --qmldir=${CMAKE_CURRENT_LIST_DIR} --plugindir ${CMAKE_SOURCE_DIR}/dist/plugins --no-translations --compiler-runtime ${CMAKE_SOURCE_DIR}/dist/${PROJECT_NAME}.exe
|
||||
COMMENT "Windows Deploying Qt Dependencies After Build........."
|
||||
SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_SOURCE_DIR}/dist
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${CMAKE_SOURCE_DIR}/dist
|
||||
COMMAND ${QT_DEPLOY_QT} --qmldir=${CMAKE_CURRENT_LIST_DIR} --plugindir ${CMAKE_SOURCE_DIR}/dist/plugins --no-translations --compiler-runtime ${CMAKE_SOURCE_DIR}/dist/${PROJECT_NAME}.exe
|
||||
COMMENT "Windows Deploying Qt Dependencies After Build........."
|
||||
SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
target_sources(Script-DeployRelease
|
||||
PRIVATE
|
||||
src/component/OpenGLItem.h src/component/OpenGLItem.cpp
|
||||
)
|
||||
endif ()
|
||||
endif ()
|
||||
|
@ -209,5 +209,7 @@
|
||||
<file>qml/page/T_GroupBox.qml</file>
|
||||
<file>res/image/bg_scenic.jpg</file>
|
||||
<file>qml/window/FluentInitializrWindow.qml</file>
|
||||
<file>qml/page/T_OpenGL.qml</file>
|
||||
</qresource>
|
||||
<qresource prefix="/"/>
|
||||
</RCC>
|
||||
|
@ -87,22 +87,22 @@
|
||||
<context>
|
||||
<name>InitializrHelper</name>
|
||||
<message>
|
||||
<location filename="src/helper/InitializrHelper.cpp" line="77"/>
|
||||
<location filename="src/helper/InitializrHelper.cpp" line="69"/>
|
||||
<source>The name cannot be empty</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="src/helper/InitializrHelper.cpp" line="81"/>
|
||||
<location filename="src/helper/InitializrHelper.cpp" line="73"/>
|
||||
<source>The creation path cannot be empty</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="src/helper/InitializrHelper.cpp" line="86"/>
|
||||
<location filename="src/helper/InitializrHelper.cpp" line="78"/>
|
||||
<source>The path does not exist</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="src/helper/InitializrHelper.cpp" line="92"/>
|
||||
<location filename="src/helper/InitializrHelper.cpp" line="84"/>
|
||||
<source>%1 folder already exists</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
@ -475,7 +475,7 @@
|
||||
</message>
|
||||
<message>
|
||||
<location filename="qml/global/ItemsOriginal.qml" line="430"/>
|
||||
<source>CodeEditor</source>
|
||||
<source>OpenGL</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
@ -550,11 +550,6 @@
|
||||
</context>
|
||||
<context>
|
||||
<name>MainWindow</name>
|
||||
<message>
|
||||
<location filename="qml/window/MainWindow.qml" line="307"/>
|
||||
<source>Dark Mode</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="qml/window/MainWindow.qml" line="83"/>
|
||||
<location filename="qml/window/MainWindow.qml" line="91"/>
|
||||
@ -617,6 +612,11 @@
|
||||
<source>Previous</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="qml/window/MainWindow.qml" line="307"/>
|
||||
<source>Dark Mode</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="qml/window/MainWindow.qml" line="307"/>
|
||||
<source>Here you can switch to night mode.</source>
|
||||
@ -1626,6 +1626,14 @@ My only desire is to be permitted to drive out the traitors and restore the Han.
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>T_OpenGL</name>
|
||||
<message>
|
||||
<location filename="qml/page/T_OpenGL.qml" line="11"/>
|
||||
<source>OpenGL</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>T_Pagination</name>
|
||||
<message>
|
||||
|
@ -87,22 +87,22 @@
|
||||
<context>
|
||||
<name>InitializrHelper</name>
|
||||
<message>
|
||||
<location filename="src/helper/InitializrHelper.cpp" line="77"/>
|
||||
<location filename="src/helper/InitializrHelper.cpp" line="69"/>
|
||||
<source>The name cannot be empty</source>
|
||||
<translation type="unfinished">名称不能为空</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="src/helper/InitializrHelper.cpp" line="81"/>
|
||||
<location filename="src/helper/InitializrHelper.cpp" line="73"/>
|
||||
<source>The creation path cannot be empty</source>
|
||||
<translation type="unfinished">创建路径不能为空</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="src/helper/InitializrHelper.cpp" line="86"/>
|
||||
<location filename="src/helper/InitializrHelper.cpp" line="78"/>
|
||||
<source>The path does not exist</source>
|
||||
<translation type="unfinished">路径不存在</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="src/helper/InitializrHelper.cpp" line="92"/>
|
||||
<location filename="src/helper/InitializrHelper.cpp" line="84"/>
|
||||
<source>%1 folder already exists</source>
|
||||
<translation type="unfinished">%1 文件夹已经存在</translation>
|
||||
</message>
|
||||
@ -475,7 +475,7 @@
|
||||
</message>
|
||||
<message>
|
||||
<location filename="qml/global/ItemsOriginal.qml" line="430"/>
|
||||
<source>CodeEditor</source>
|
||||
<source>OpenGL</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
@ -1665,6 +1665,14 @@ My only desire is to be permitted to drive out the traitors and restore the Han.
|
||||
<translation type="unfinished">网络</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>T_OpenGL</name>
|
||||
<message>
|
||||
<location filename="qml/page/T_OpenGL.qml" line="11"/>
|
||||
<source>OpenGL</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>T_Pagination</name>
|
||||
<message>
|
||||
|
@ -427,9 +427,9 @@ FluObject{
|
||||
title: qsTr("Other")
|
||||
icon: FluentIcons.Shop
|
||||
FluPaneItem{
|
||||
title: qsTr("CodeEditor")
|
||||
title: qsTr("OpenGL")
|
||||
menuDelegate: paneItemMenu
|
||||
url: "qrc:/example/qml/page/T_CodeEditor.qml"
|
||||
url: "qrc:/example/qml/page/T_OpenGL.qml"
|
||||
onTap: { navigationView.push(url) }
|
||||
}
|
||||
FluPaneItem{
|
||||
|
@ -1,17 +1,15 @@
|
||||
#include "AppInfo.h"
|
||||
|
||||
#include <QQmlContext>
|
||||
#include <QDebug>
|
||||
#include <QGuiApplication>
|
||||
#include "Version.h"
|
||||
|
||||
AppInfo::AppInfo(QObject *parent)
|
||||
: QObject{parent}
|
||||
{
|
||||
: QObject{parent} {
|
||||
version(APPLICATION_VERSION);
|
||||
}
|
||||
|
||||
void AppInfo::testCrash(){
|
||||
[[maybe_unused]] void AppInfo::testCrash() {
|
||||
auto *crash = reinterpret_cast<volatile int *>(0);
|
||||
*crash = 0;
|
||||
}
|
||||
|
@ -1,20 +1,18 @@
|
||||
#ifndef APPINFO_H
|
||||
#define APPINFO_H
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QQmlApplicationEngine>
|
||||
#include "stdafx.h"
|
||||
#include "singleton.h"
|
||||
|
||||
class AppInfo : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY_AUTO(QString,version)
|
||||
class AppInfo : public QObject {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY_AUTO(QString, version)
|
||||
private:
|
||||
explicit AppInfo(QObject *parent = nullptr);
|
||||
public:
|
||||
SINGLETON(AppInfo)
|
||||
Q_INVOKABLE void testCrash();
|
||||
};
|
||||
|
||||
#endif // APPINFO_H
|
||||
public:
|
||||
SINGLETON(AppInfo)
|
||||
|
||||
Q_INVOKABLE [[maybe_unused]] void testCrash();
|
||||
};
|
||||
|
@ -1,5 +1,6 @@
|
||||
#ifndef APP_DUMP_H
|
||||
#define APP_DUMP_H
|
||||
#pragma once
|
||||
#pragma clang diagnostic push
|
||||
#pragma ide diagnostic ignored "misc-misplaced-const"
|
||||
|
||||
#include <Windows.h>
|
||||
#include <DbgHelp.h>
|
||||
@ -12,71 +13,71 @@
|
||||
|
||||
#pragma comment(lib, "Dbghelp.lib")
|
||||
|
||||
static void miniDumpWriteDump(HANDLE hProcess,DWORD ProcessId,HANDLE hFile,MINIDUMP_TYPE DumpType,CONST PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam,CONST PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam,CONST PMINIDUMP_CALLBACK_INFORMATION CallbackParam){
|
||||
typedef HRESULT (WINAPI* MiniDumpWriteDumpPtr)(HANDLE hProcess,DWORD ProcessId,HANDLE hFile,MINIDUMP_TYPE DumpType,CONST PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam,CONST PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam,CONST PMINIDUMP_CALLBACK_INFORMATION CallbackParam);
|
||||
static void
|
||||
miniDumpWriteDump(HANDLE hProcess, DWORD ProcessId, HANDLE hFile, CONST PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam, CONST PMINIDUMP_CALLBACK_INFORMATION CallbackParam) {
|
||||
typedef HRESULT (WINAPI *MiniDumpWriteDumpPtr)(HANDLE hProcess, DWORD ProcessId, HANDLE hFile, MINIDUMP_TYPE DumpType, CONST PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam,
|
||||
CONST PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam, CONST PMINIDUMP_CALLBACK_INFORMATION CallbackParam);
|
||||
HMODULE module = LoadLibraryW(L"Dbghelp.dll");
|
||||
if (module)
|
||||
{
|
||||
if (module) {
|
||||
MiniDumpWriteDumpPtr mini_dump_write_dump;
|
||||
mini_dump_write_dump= reinterpret_cast<MiniDumpWriteDumpPtr>(GetProcAddress(module, "MiniDumpWriteDump"));
|
||||
if (mini_dump_write_dump)
|
||||
{
|
||||
mini_dump_write_dump(hProcess,ProcessId,hFile,DumpType,ExceptionParam,UserStreamParam,CallbackParam);
|
||||
mini_dump_write_dump = reinterpret_cast<MiniDumpWriteDumpPtr>(GetProcAddress(module, "MiniDumpWriteDump"));
|
||||
if (mini_dump_write_dump) {
|
||||
mini_dump_write_dump(hProcess, ProcessId, hFile, static_cast<MINIDUMP_TYPE>(80), ExceptionParam, nullptr, CallbackParam);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BOOL CALLBACK MyMiniDumpCallback(PVOID, const PMINIDUMP_CALLBACK_INPUT input, PMINIDUMP_CALLBACK_OUTPUT output) {
|
||||
if (input == NULL || output == NULL)
|
||||
if (input == nullptr || output == nullptr)
|
||||
return FALSE;
|
||||
|
||||
BOOL ret = FALSE;
|
||||
switch (input->CallbackType) {
|
||||
case IncludeModuleCallback:
|
||||
case IncludeThreadCallback:
|
||||
case ThreadCallback:
|
||||
case ThreadExCallback:
|
||||
ret = TRUE;
|
||||
break;
|
||||
case ModuleCallback: {
|
||||
if (!(output->ModuleWriteFlags & ModuleReferencedByMemory)) {
|
||||
output->ModuleWriteFlags &= ~ModuleWriteModule;
|
||||
case IncludeModuleCallback:
|
||||
case IncludeThreadCallback:
|
||||
case ThreadCallback:
|
||||
case ThreadExCallback:
|
||||
ret = TRUE;
|
||||
break;
|
||||
case ModuleCallback: {
|
||||
if (!(output->ModuleWriteFlags & ModuleReferencedByMemory)) {
|
||||
output->ModuleWriteFlags &= ~ModuleWriteModule;
|
||||
}
|
||||
ret = TRUE;
|
||||
}
|
||||
ret = TRUE;
|
||||
} break;
|
||||
default:
|
||||
break;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void WriteDump(EXCEPTION_POINTERS* exp, const std::wstring& path) {
|
||||
HANDLE h = ::CreateFileW(path.c_str(), GENERIC_WRITE | GENERIC_READ, FILE_SHARE_WRITE | FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
void WriteDump(EXCEPTION_POINTERS *exp, const std::wstring &path) {
|
||||
HANDLE h = ::CreateFileW(path.c_str(), GENERIC_WRITE | GENERIC_READ, FILE_SHARE_WRITE | FILE_SHARE_READ, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
|
||||
MINIDUMP_EXCEPTION_INFORMATION info;
|
||||
info.ThreadId = ::GetCurrentThreadId();
|
||||
info.ExceptionPointers = exp;
|
||||
info.ClientPointers = FALSE;
|
||||
MINIDUMP_CALLBACK_INFORMATION mci;
|
||||
mci.CallbackRoutine = (MINIDUMP_CALLBACK_ROUTINE)MyMiniDumpCallback;
|
||||
mci.CallbackParam = 0;
|
||||
MINIDUMP_TYPE mdt = (MINIDUMP_TYPE)(MiniDumpWithIndirectlyReferencedMemory | MiniDumpScanMemory);
|
||||
miniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), h, mdt, &info, NULL, &mci);
|
||||
mci.CallbackRoutine = (MINIDUMP_CALLBACK_ROUTINE) MyMiniDumpCallback;
|
||||
mci.CallbackParam = nullptr;
|
||||
miniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), h, &info, &mci);
|
||||
::CloseHandle(h);
|
||||
}
|
||||
|
||||
LONG WINAPI MyUnhandledExceptionFilter(EXCEPTION_POINTERS* exp) {
|
||||
const QString dumpFileName = QString("%1_%2.dmp").arg("crash",QDateTime::currentDateTime().toString("yyyyMMdd_hhmmss"));
|
||||
const QString dumpDirPath = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation)+"/dmp";
|
||||
LONG WINAPI MyUnhandledExceptionFilter(EXCEPTION_POINTERS *exp) {
|
||||
const QString dumpFileName = QString("%1_%2.dmp").arg("crash", QDateTime::currentDateTime().toString("yyyyMMdd_hhmmss"));
|
||||
const QString dumpDirPath = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + "/dmp";
|
||||
const QDir dumpDir(dumpDirPath);
|
||||
if(!dumpDir.exists()){
|
||||
if (!dumpDir.exists()) {
|
||||
dumpDir.mkpath(dumpDirPath);
|
||||
}
|
||||
QString dumpFilePath = dumpDir.filePath(dumpFileName);
|
||||
WriteDump(exp, dumpFilePath.toStdWString());
|
||||
QStringList arguments;
|
||||
arguments << "-crashed=" + dumpFilePath;
|
||||
QProcess::startDetached(qApp->applicationFilePath(), arguments);
|
||||
QProcess::startDetached(QGuiApplication::applicationFilePath(), arguments);
|
||||
return EXCEPTION_EXECUTE_HANDLER;
|
||||
}
|
||||
|
||||
#endif // APP_DUMP_H
|
||||
#pragma clang diagnostic pop
|
@ -3,43 +3,43 @@
|
||||
#include <QQuickItemGrabResult>
|
||||
#include <QPainterPath>
|
||||
|
||||
CircularReveal::CircularReveal(QQuickItem* parent) : QQuickPaintedItem(parent)
|
||||
{
|
||||
CircularReveal::CircularReveal(QQuickItem *parent) : QQuickPaintedItem(parent) {
|
||||
_target = nullptr;
|
||||
_radius = 0;
|
||||
_anim = new QPropertyAnimation(this, "radius", this);
|
||||
setVisible(false);
|
||||
_anim->setDuration(333);
|
||||
_anim->setEasingCurve(QEasingCurve::OutCubic);
|
||||
connect(_anim, &QPropertyAnimation::finished,this,[=](){
|
||||
setVisible(false);
|
||||
connect(_anim, &QPropertyAnimation::finished, this, [=]() {
|
||||
update();
|
||||
setVisible(false);
|
||||
Q_EMIT animationFinished();
|
||||
});
|
||||
connect(this,&CircularReveal::radiusChanged,this,[=](){
|
||||
connect(this, &CircularReveal::radiusChanged, this, [=]() {
|
||||
update();
|
||||
});
|
||||
}
|
||||
|
||||
void CircularReveal::paint(QPainter* painter)
|
||||
{
|
||||
void CircularReveal::paint(QPainter *painter) {
|
||||
painter->save();
|
||||
painter->drawImage(QRect(0, 0, static_cast<int>(width()), static_cast<int>(height())), _source);
|
||||
QPainterPath path;
|
||||
path.moveTo(_center.x(),_center.y());
|
||||
path.addEllipse(QPointF(_center.x(),_center.y()), _radius, _radius);
|
||||
path.moveTo(_center.x(), _center.y());
|
||||
path.addEllipse(QPointF(_center.x(), _center.y()), _radius, _radius);
|
||||
painter->setCompositionMode(QPainter::CompositionMode_Clear);
|
||||
painter->fillPath(path, Qt::black);
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
void CircularReveal::start(int w,int h,const QPoint& center,int radius){
|
||||
[[maybe_unused]] void CircularReveal::start(int w, int h, const QPoint ¢er, int radius) {
|
||||
_anim->setStartValue(0);
|
||||
_anim->setEndValue(radius);
|
||||
_center = center;
|
||||
_grabResult = _target->grabToImage(QSize(w,h));
|
||||
_grabResult = _target->grabToImage(QSize(w, h));
|
||||
connect(_grabResult.data(), &QQuickItemGrabResult::ready, this, &CircularReveal::handleGrabResult);
|
||||
}
|
||||
|
||||
void CircularReveal::handleGrabResult(){
|
||||
void CircularReveal::handleGrabResult() {
|
||||
_grabResult.data()->image().swap(_source);
|
||||
update();
|
||||
setVisible(true);
|
||||
|
@ -1,5 +1,6 @@
|
||||
#ifndef CIRCULARREVEAL_H
|
||||
#define CIRCULARREVEAL_H
|
||||
#pragma once
|
||||
#pragma clang diagnostic push
|
||||
#pragma ide diagnostic ignored "NotImplementedFunctions"
|
||||
|
||||
#include <QQuickItem>
|
||||
#include <QQuickPaintedItem>
|
||||
@ -7,23 +8,28 @@
|
||||
#include <QPropertyAnimation>
|
||||
#include "src/stdafx.h"
|
||||
|
||||
class CircularReveal : public QQuickPaintedItem
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY_AUTO(QQuickItem*,target)
|
||||
Q_PROPERTY_AUTO(int,radius)
|
||||
class CircularReveal : public QQuickPaintedItem {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY_AUTO_P(QQuickItem*, target)
|
||||
Q_PROPERTY_AUTO(int, radius)
|
||||
public:
|
||||
CircularReveal(QQuickItem* parent = nullptr);
|
||||
void paint(QPainter* painter) override;
|
||||
Q_INVOKABLE void start(int w,int h,const QPoint& center,int radius);
|
||||
explicit CircularReveal(QQuickItem *parent = nullptr);
|
||||
|
||||
void paint(QPainter *painter) override;
|
||||
|
||||
Q_INVOKABLE [[maybe_unused]] void start(int w, int h, const QPoint ¢er, int radius);
|
||||
|
||||
Q_SIGNAL void imageChanged();
|
||||
|
||||
Q_SIGNAL void animationFinished();
|
||||
|
||||
Q_SLOT void handleGrabResult();
|
||||
|
||||
private:
|
||||
QPropertyAnimation* _anim = nullptr;
|
||||
QPropertyAnimation *_anim = nullptr;
|
||||
QImage _source;
|
||||
QPoint _center;
|
||||
QSharedPointer<QQuickItemGrabResult> _grabResult;
|
||||
QSharedPointer<QQuickItemGrabResult> _grabResult;
|
||||
};
|
||||
|
||||
#endif // CIRCULARREVEAL_H
|
||||
#pragma clang diagnostic pop
|
@ -1,24 +1,23 @@
|
||||
#include "FileWatcher.h"
|
||||
|
||||
FileWatcher::FileWatcher(QObject *parent)
|
||||
: QObject{parent}
|
||||
{
|
||||
connect(&_watcher, &QFileSystemWatcher::fileChanged, this, [=](const QString &path){
|
||||
FileWatcher::FileWatcher(QObject *parent) : QObject{parent} {
|
||||
connect(&_watcher, &QFileSystemWatcher::fileChanged, this, [=](const QString &path) {
|
||||
Q_EMIT fileChanged();
|
||||
clean();
|
||||
_watcher.addPath(_path);
|
||||
});
|
||||
connect(this,&FileWatcher::pathChanged,this,[=](){
|
||||
connect(this, &FileWatcher::pathChanged, this, [=]() {
|
||||
clean();
|
||||
_watcher.addPath(_path.replace("file:///",""));
|
||||
_watcher.addPath(_path.replace("file:///", ""));
|
||||
});
|
||||
if(!_path.isEmpty()){
|
||||
if (!_path.isEmpty()) {
|
||||
_watcher.addPath(_path);
|
||||
}
|
||||
}
|
||||
|
||||
void FileWatcher::clean(){
|
||||
foreach (const QString &item, _watcher.files()) {
|
||||
void FileWatcher::clean() {
|
||||
for (int i = 0; i <= _watcher.files().size() - 1; ++i) {
|
||||
auto item = _watcher.files().at(i);
|
||||
_watcher.removePath(item);
|
||||
}
|
||||
}
|
||||
|
@ -1,22 +1,25 @@
|
||||
#ifndef FILEWATCHER_H
|
||||
#define FILEWATCHER_H
|
||||
#pragma once
|
||||
#pragma clang diagnostic push
|
||||
#pragma ide diagnostic ignored "NotImplementedFunctions"
|
||||
|
||||
#include <QObject>
|
||||
#include <QFileSystemWatcher>
|
||||
#include <QtQml/qqml.h>
|
||||
#include "src/stdafx.h"
|
||||
|
||||
class FileWatcher : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY_AUTO(QString,path);
|
||||
class FileWatcher : public QObject {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY_AUTO(QString, path);
|
||||
public:
|
||||
explicit FileWatcher(QObject *parent = nullptr);
|
||||
|
||||
Q_SIGNAL void fileChanged();
|
||||
|
||||
private:
|
||||
void clean();
|
||||
|
||||
private:
|
||||
QFileSystemWatcher _watcher;
|
||||
};
|
||||
|
||||
#endif // FILEWATCHER_H
|
||||
#pragma clang diagnostic pop
|
@ -3,16 +3,16 @@
|
||||
#include <QTimer>
|
||||
#include <QQuickWindow>
|
||||
|
||||
FpsItem::FpsItem()
|
||||
{
|
||||
QTimer *timer = new QTimer(this);
|
||||
connect(timer, &QTimer::timeout, this, [this]{
|
||||
FpsItem::FpsItem() {
|
||||
_fps = 0;
|
||||
auto *timer = new QTimer(this);
|
||||
connect(timer, &QTimer::timeout, this, [this] {
|
||||
fps(_frameCount);
|
||||
_frameCount = 0;
|
||||
});
|
||||
connect(this, &QQuickItem::windowChanged, this, [this]{
|
||||
if (window()){
|
||||
connect(window(), &QQuickWindow::afterRendering, this, [this]{ _frameCount++; }, Qt::DirectConnection);
|
||||
connect(this, &QQuickItem::windowChanged, this, [this] {
|
||||
if (window()) {
|
||||
connect(window(), &QQuickWindow::afterRendering, this, [this] { _frameCount++; }, Qt::DirectConnection);
|
||||
}
|
||||
});
|
||||
timer->start(1000);
|
||||
|
@ -1,19 +1,15 @@
|
||||
#ifndef FPSITEM_H
|
||||
#define FPSITEM_H
|
||||
#pragma once
|
||||
|
||||
#include <QQuickItem>
|
||||
#include "src/stdafx.h"
|
||||
|
||||
class FpsItem : public QQuickItem
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY_AUTO(int,fps)
|
||||
class FpsItem : public QQuickItem {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY_AUTO(int, fps)
|
||||
public:
|
||||
FpsItem();
|
||||
|
||||
private:
|
||||
int _frameCount = 0;
|
||||
|
||||
};
|
||||
|
||||
#endif // FPSITEM_H
|
||||
};
|
@ -3,55 +3,47 @@
|
||||
#include <QDir>
|
||||
#include <QGuiApplication>
|
||||
|
||||
InitializrHelper::InitializrHelper(QObject *parent) : QObject(parent)
|
||||
{
|
||||
[[maybe_unused]] InitializrHelper::InitializrHelper(QObject *parent) : QObject(parent) {
|
||||
|
||||
}
|
||||
|
||||
InitializrHelper::~InitializrHelper() = default;
|
||||
|
||||
bool InitializrHelper::copyDir(const QDir& fromDir, const QDir& toDir, bool coverIfFileExists){
|
||||
QDir _formDir = fromDir;
|
||||
bool InitializrHelper::copyDir(const QDir &fromDir, const QDir &toDir, bool coverIfFileExists) {
|
||||
const QDir &_formDir = fromDir;
|
||||
QDir _toDir = toDir;
|
||||
if(!_toDir.exists())
|
||||
{
|
||||
if(!_toDir.mkdir(toDir.absolutePath()))
|
||||
if (!_toDir.exists()) {
|
||||
if (!_toDir.mkdir(toDir.absolutePath()))
|
||||
return false;
|
||||
}
|
||||
QFileInfoList fileInfoList = _formDir.entryInfoList();
|
||||
foreach(QFileInfo fileInfo, fileInfoList)
|
||||
{
|
||||
if(fileInfo.fileName() == "." || fileInfo.fileName() == "..")
|
||||
continue;
|
||||
if(fileInfo.isDir())
|
||||
{
|
||||
if(!copyDir(fileInfo.filePath(), _toDir.filePath(fileInfo.fileName()),true))
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(coverIfFileExists && _toDir.exists(fileInfo.fileName()))
|
||||
{
|
||||
_toDir.remove(fileInfo.fileName());
|
||||
}
|
||||
if(!QFile::copy(fileInfo.filePath(), _toDir.filePath(fileInfo.fileName())))
|
||||
{
|
||||
return false;
|
||||
foreach(QFileInfo fileInfo, fileInfoList) {
|
||||
if (fileInfo.fileName() == "." || fileInfo.fileName() == "..")
|
||||
continue;
|
||||
if (fileInfo.isDir()) {
|
||||
if (!copyDir(fileInfo.filePath(), _toDir.filePath(fileInfo.fileName()), true))
|
||||
return false;
|
||||
} else {
|
||||
if (coverIfFileExists && _toDir.exists(fileInfo.fileName())) {
|
||||
_toDir.remove(fileInfo.fileName());
|
||||
}
|
||||
if (!QFile::copy(fileInfo.filePath(), _toDir.filePath(fileInfo.fileName()))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename...Args>
|
||||
void InitializrHelper::templateToFile(const QString& source,const QString& dest,Args &&...args){
|
||||
template<typename...Args>
|
||||
void InitializrHelper::templateToFile(const QString &source, const QString &dest, Args &&...args) {
|
||||
QFile file(source);
|
||||
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
QTextStream in(&file);
|
||||
QString content = in.readAll().arg(std::forward<Args>(args)...);
|
||||
file.close();
|
||||
QDir outputDir = QFileInfo(dest).absoluteDir();
|
||||
if(!outputDir.exists()){
|
||||
if (!outputDir.exists()) {
|
||||
outputDir.mkpath(outputDir.absolutePath());
|
||||
}
|
||||
QFile outputFile(dest);
|
||||
@ -67,43 +59,43 @@ void InitializrHelper::templateToFile(const QString& source,const QString& dest,
|
||||
}
|
||||
}
|
||||
|
||||
void InitializrHelper::copyFile(const QString& source,const QString& dest){
|
||||
QFile::copy(source,dest);
|
||||
void InitializrHelper::copyFile(const QString &source, const QString &dest) {
|
||||
QFile::copy(source, dest);
|
||||
QFile::setPermissions(dest, QFile::WriteOwner | QFile::WriteUser | QFile::WriteGroup | QFile::WriteOther);
|
||||
}
|
||||
|
||||
void InitializrHelper::generate(const QString& name,const QString& path){
|
||||
if(name.isEmpty()){
|
||||
[[maybe_unused]] void InitializrHelper::generate(const QString &name, const QString &path) {
|
||||
if (name.isEmpty()) {
|
||||
error(tr("The name cannot be empty"));
|
||||
return;
|
||||
}
|
||||
if(path.isEmpty()){
|
||||
if (path.isEmpty()) {
|
||||
error(tr("The creation path cannot be empty"));
|
||||
return;
|
||||
}
|
||||
QDir projectRootDir(path);
|
||||
if(!projectRootDir.exists()){
|
||||
if (!projectRootDir.exists()) {
|
||||
error(tr("The path does not exist"));
|
||||
return;
|
||||
}
|
||||
QString projectPath = projectRootDir.filePath(name);
|
||||
QDir projectDir(projectPath);
|
||||
if(projectDir.exists()){
|
||||
if (projectDir.exists()) {
|
||||
error(tr("%1 folder already exists").arg(name));
|
||||
return;
|
||||
}
|
||||
projectDir.mkpath(projectPath);
|
||||
QDir fluentDir(projectDir.filePath("FluentUI"));
|
||||
copyDir(QDir(QGuiApplication::applicationDirPath()+"/source"),fluentDir);
|
||||
templateToFile(":/example/res/template/CMakeLists.txt.in",projectDir.filePath("CMakeLists.txt"),name);
|
||||
templateToFile(":/example/res/template/src/CMakeLists.txt.in",projectDir.filePath("src/CMakeLists.txt"),name);
|
||||
templateToFile(":/example/res/template/src/main.cpp.in",projectDir.filePath("src/main.cpp"),name);
|
||||
templateToFile(":/example/res/template/src/main.qml.in",projectDir.filePath("src/main.qml"),name);
|
||||
templateToFile(":/example/res/template/src/en_US.ts.in",projectDir.filePath("src/"+name+"_en_US.ts"),name);
|
||||
templateToFile(":/example/res/template/src/zh_CN.ts.in",projectDir.filePath("src/"+name+"_zh_CN.ts"),name);
|
||||
copyFile(":/example/res/template/src/App.qml.in",projectDir.filePath("src/App.qml"));
|
||||
copyFile(":/example/res/template/src/qml.qrc.in",projectDir.filePath("src/qml.qrc"));
|
||||
copyFile(":/example/res/template/src/logo.ico.in",projectDir.filePath("src/logo.ico"));
|
||||
copyFile(":/example/res/template/src/README.md.in",projectDir.filePath("src/README.md"));
|
||||
copyDir(QDir(QGuiApplication::applicationDirPath() + "/source"), fluentDir);
|
||||
templateToFile(":/example/res/template/CMakeLists.txt.in", projectDir.filePath("CMakeLists.txt"), name);
|
||||
templateToFile(":/example/res/template/src/CMakeLists.txt.in", projectDir.filePath("src/CMakeLists.txt"), name);
|
||||
templateToFile(":/example/res/template/src/main.cpp.in", projectDir.filePath("src/main.cpp"), name);
|
||||
templateToFile(":/example/res/template/src/main.qml.in", projectDir.filePath("src/main.qml"), name);
|
||||
templateToFile(":/example/res/template/src/en_US.ts.in", projectDir.filePath("src/" + name + "_en_US.ts"), name);
|
||||
templateToFile(":/example/res/template/src/zh_CN.ts.in", projectDir.filePath("src/" + name + "_zh_CN.ts"), name);
|
||||
copyFile(":/example/res/template/src/App.qml.in", projectDir.filePath("src/App.qml"));
|
||||
copyFile(":/example/res/template/src/qml.qrc.in", projectDir.filePath("src/qml.qrc"));
|
||||
copyFile(":/example/res/template/src/logo.ico.in", projectDir.filePath("src/logo.ico"));
|
||||
copyFile(":/example/res/template/src/README.md.in", projectDir.filePath("src/README.md"));
|
||||
return this->success(projectPath);
|
||||
}
|
||||
|
@ -1,26 +1,34 @@
|
||||
#ifndef INITIALIZRHELPER_H
|
||||
#define INITIALIZRHELPER_H
|
||||
#pragma clang diagnostic push
|
||||
#pragma ide diagnostic ignored "NotImplementedFunctions"
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QtQml/qqml.h>
|
||||
#include <QDir>
|
||||
#include "src/singleton.h"
|
||||
|
||||
class InitializrHelper : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
class InitializrHelper : public QObject {
|
||||
Q_OBJECT
|
||||
private:
|
||||
explicit InitializrHelper(QObject* parent = nullptr);
|
||||
bool copyDir(const QDir& fromDir, const QDir& toDir, bool coverIfFileExists = true);
|
||||
void copyFile(const QString& source,const QString& dest);
|
||||
template <typename...Args>
|
||||
void templateToFile(const QString& source,const QString& dest,Args &&...args);
|
||||
[[maybe_unused]] explicit InitializrHelper(QObject *parent = nullptr);
|
||||
|
||||
bool copyDir(const QDir &fromDir, const QDir &toDir, bool coverIfFileExists = true);
|
||||
|
||||
static void copyFile(const QString &source, const QString &dest);
|
||||
|
||||
template<typename...Args>
|
||||
void templateToFile(const QString &source, const QString &dest, Args &&...args);
|
||||
|
||||
public:
|
||||
SINGLETON(InitializrHelper)
|
||||
SINGLETON(InitializrHelper)
|
||||
|
||||
~InitializrHelper() override;
|
||||
Q_INVOKABLE void generate(const QString& name,const QString& path);
|
||||
Q_SIGNAL void error(const QString& message);
|
||||
Q_SIGNAL void success(const QString& path);
|
||||
|
||||
Q_INVOKABLE [[maybe_unused]] void generate(const QString &name, const QString &path);
|
||||
|
||||
Q_SIGNAL void error(const QString &message);
|
||||
|
||||
Q_SIGNAL void success(const QString &path);
|
||||
};
|
||||
|
||||
#endif // INITIALIZRHELPER_H
|
||||
#pragma clang diagnostic pop
|
@ -11,8 +11,11 @@
|
||||
#include <QSettings>
|
||||
#include <QRegularExpression>
|
||||
#include "Version.h"
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
#include <process.h>
|
||||
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
@ -26,7 +29,7 @@
|
||||
#endif
|
||||
|
||||
static QString g_app = {};
|
||||
static QString g_file_path= {};
|
||||
static QString g_file_path = {};
|
||||
static bool g_logError = false;
|
||||
|
||||
static std::unique_ptr<QFile> g_logFile = nullptr;
|
||||
@ -35,15 +38,14 @@ static std::unique_ptr<QTextStream> g_logStream = nullptr;
|
||||
static int g_logLevel = 4;
|
||||
|
||||
std::map<QtMsgType, int> logLevelMap = {
|
||||
{QtFatalMsg,0},
|
||||
{QtCriticalMsg,1},
|
||||
{QtWarningMsg,2},
|
||||
{QtInfoMsg,3},
|
||||
{QtDebugMsg,4}
|
||||
{QtFatalMsg, 0},
|
||||
{QtCriticalMsg, 1},
|
||||
{QtWarningMsg, 2},
|
||||
{QtInfoMsg, 3},
|
||||
{QtDebugMsg, 4}
|
||||
};
|
||||
|
||||
QString Log::prettyProductInfoWrapper()
|
||||
{
|
||||
QString Log::prettyProductInfoWrapper() {
|
||||
auto productName = QSysInfo::prettyProductName();
|
||||
#if QT_VERSION < QT_VERSION_CHECK(6, 5, 0)
|
||||
#if defined(Q_OS_MACOS)
|
||||
@ -70,20 +72,17 @@ QString Log::prettyProductInfoWrapper()
|
||||
#endif
|
||||
#endif
|
||||
#if defined(Q_OS_WIN)
|
||||
QSettings regKey {QString::fromUtf8("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"), QSettings::NativeFormat};
|
||||
QSettings regKey{QString::fromUtf8(R"(HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion)"), QSettings::NativeFormat};
|
||||
if (regKey.contains(QString::fromUtf8("CurrentBuildNumber"))) {
|
||||
auto buildNumber = regKey.value(QString::fromUtf8("CurrentBuildNumber")).toInt();
|
||||
if (buildNumber > 0) {
|
||||
if (buildNumber < 9200) {
|
||||
productName = QString::fromUtf8("Windows 7 build %1").arg(buildNumber);
|
||||
}
|
||||
else if (buildNumber < 10240) {
|
||||
} else if (buildNumber < 10240) {
|
||||
productName = QString::fromUtf8("Windows 8 build %1").arg(buildNumber);
|
||||
}
|
||||
else if (buildNumber < 22000) {
|
||||
} else if (buildNumber < 22000) {
|
||||
productName = QString::fromUtf8("Windows 10 build %1").arg(buildNumber);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
productName = QString::fromUtf8("Windows 11 build %1").arg(buildNumber);
|
||||
}
|
||||
}
|
||||
@ -92,56 +91,55 @@ QString Log::prettyProductInfoWrapper()
|
||||
return productName;
|
||||
}
|
||||
|
||||
static inline void messageHandler(const QtMsgType type, const QMessageLogContext &context, const QString &message)
|
||||
{
|
||||
if(message == "Could not get the INetworkConnection instance for the adapter GUID."){
|
||||
static inline void messageHandler(const QtMsgType type, const QMessageLogContext &context, const QString &message) {
|
||||
if (message == "Could not get the INetworkConnection instance for the adapter GUID.") {
|
||||
return;
|
||||
}
|
||||
if(logLevelMap[type]>g_logLevel){
|
||||
if (logLevelMap[type] > g_logLevel) {
|
||||
return;
|
||||
}
|
||||
if (!message.isEmpty()) {
|
||||
QString levelName;
|
||||
switch (type) {
|
||||
case QtDebugMsg:
|
||||
levelName = QStringLiteral("Debug");
|
||||
break;
|
||||
case QtInfoMsg:
|
||||
levelName = QStringLiteral("Info");
|
||||
break;
|
||||
case QtWarningMsg:
|
||||
levelName = QStringLiteral("Warning");
|
||||
break;
|
||||
case QtCriticalMsg:
|
||||
levelName = QStringLiteral("Critical");
|
||||
break;
|
||||
case QtFatalMsg:
|
||||
levelName = QStringLiteral("Fatal");
|
||||
break;
|
||||
case QtDebugMsg:
|
||||
levelName = QStringLiteral("Debug");
|
||||
break;
|
||||
case QtInfoMsg:
|
||||
levelName = QStringLiteral("Info");
|
||||
break;
|
||||
case QtWarningMsg:
|
||||
levelName = QStringLiteral("Warning");
|
||||
break;
|
||||
case QtCriticalMsg:
|
||||
levelName = QStringLiteral("Critical");
|
||||
break;
|
||||
case QtFatalMsg:
|
||||
levelName = QStringLiteral("Fatal");
|
||||
break;
|
||||
}
|
||||
QString fileAndLineLogStr;
|
||||
if(context.file){
|
||||
if (context.file) {
|
||||
std::string strFileTmp = context.file;
|
||||
const char* ptr = strrchr(strFileTmp.c_str(), '/');
|
||||
const char *ptr = strrchr(strFileTmp.c_str(), '/');
|
||||
if (nullptr != ptr) {
|
||||
char fn[512] = {0};
|
||||
sprintf(fn, "%s", ptr + 1);
|
||||
strFileTmp = fn;
|
||||
}
|
||||
const char* ptrTmp = strrchr(strFileTmp.c_str(), '\\');
|
||||
const char *ptrTmp = strrchr(strFileTmp.c_str(), '\\');
|
||||
if (nullptr != ptrTmp) {
|
||||
char fn[512] = {0};
|
||||
sprintf(fn, "%s", ptrTmp + 1);
|
||||
strFileTmp = fn;
|
||||
}
|
||||
fileAndLineLogStr = QString::fromStdString("[%1:%2]").arg(QString::fromStdString(strFileTmp),QString::number(context.line));
|
||||
fileAndLineLogStr = QString::fromStdString("[%1:%2]").arg(QString::fromStdString(strFileTmp), QString::number(context.line));
|
||||
}
|
||||
const QString finalMessage = QString::fromStdString("%1[%2]%3[%4]:%5").arg(
|
||||
QDateTime::currentDateTime().toString("yyyy/MM/dd hh:mm:ss.zzz"),
|
||||
levelName,
|
||||
fileAndLineLogStr,
|
||||
QString::number(reinterpret_cast<quintptr>(QThread::currentThreadId())),
|
||||
message);
|
||||
QDateTime::currentDateTime().toString("yyyy/MM/dd hh:mm:ss.zzz"),
|
||||
levelName,
|
||||
fileAndLineLogStr,
|
||||
QString::number(reinterpret_cast<quintptr>(QThread::currentThreadId())),
|
||||
message);
|
||||
if ((type == QtInfoMsg) || (type == QtDebugMsg)) {
|
||||
std::cout << qPrintable(finalMessage) << std::endl;
|
||||
} else {
|
||||
@ -168,8 +166,7 @@ static inline void messageHandler(const QtMsgType type, const QMessageLogContext
|
||||
}
|
||||
}
|
||||
|
||||
void Log::setup(char *argv[],const QString &app,int level)
|
||||
{
|
||||
void Log::setup(char *argv[], const QString &app, int level) {
|
||||
Q_ASSERT(!app.isEmpty());
|
||||
if (app.isEmpty()) {
|
||||
return;
|
||||
@ -182,30 +179,30 @@ void Log::setup(char *argv[],const QString &app,int level)
|
||||
QString applicationPath = QString::fromStdString(argv[0]);
|
||||
once = true;
|
||||
g_app = app;
|
||||
const QString logFileName = QString("%1_%2.log").arg(g_app,QDateTime::currentDateTime().toString("yyyyMMdd"));
|
||||
const QString logDirPath = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation)+"/log";
|
||||
const QString logFileName = QString("%1_%2.log").arg(g_app, QDateTime::currentDateTime().toString("yyyyMMdd"));
|
||||
const QString logDirPath = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + "/log";
|
||||
const QDir logDir(logDirPath);
|
||||
if(!logDir.exists()){
|
||||
if (!logDir.exists()) {
|
||||
logDir.mkpath(logDirPath);
|
||||
}
|
||||
g_file_path = logDir.filePath(logFileName);
|
||||
qInstallMessageHandler(messageHandler);
|
||||
qInfo()<<"===================================================";
|
||||
qInfo()<<"[AppName]"<<g_app;
|
||||
qInfo()<<"[AppVersion]"<<APPLICATION_VERSION;
|
||||
qInfo()<<"[AppPath]"<<applicationPath;
|
||||
qInfo()<<"[QtVersion]"<<QT_VERSION_STR;
|
||||
qInfo() << "===================================================";
|
||||
qInfo() << "[AppName]" << g_app;
|
||||
qInfo() << "[AppVersion]" << APPLICATION_VERSION;
|
||||
qInfo() << "[AppPath]" << applicationPath;
|
||||
qInfo() << "[QtVersion]" << QT_VERSION_STR;
|
||||
#ifdef WIN32
|
||||
qInfo()<<"[ProcessId]"<<QString::number(_getpid());
|
||||
qInfo() << "[ProcessId]" << QString::number(_getpid());
|
||||
#else
|
||||
qInfo()<<"[ProcessId]"<<QString::number(getpid());
|
||||
#endif
|
||||
qInfo()<<"[GitHashCode]"<<COMMIT_HASH;
|
||||
qInfo()<<"[DeviceInfo]";
|
||||
qInfo()<<" [DeviceId]"<<QSysInfo::machineUniqueId();
|
||||
qInfo()<<" [Manufacturer]"<<prettyProductInfoWrapper();
|
||||
qInfo()<<" [CPU_ABI]"<<QSysInfo::currentCpuArchitecture();
|
||||
qInfo()<<"[LOG_LEVEL]"<<g_logLevel;
|
||||
qInfo()<<"[LOG_PATH]"<<g_file_path;
|
||||
qInfo()<<"===================================================";
|
||||
qInfo() << "[GitHashCode]" << COMMIT_HASH;
|
||||
qInfo() << "[DeviceInfo]";
|
||||
qInfo() << " [DeviceId]" << QSysInfo::machineUniqueId();
|
||||
qInfo() << " [Manufacturer]" << prettyProductInfoWrapper();
|
||||
qInfo() << " [CPU_ABI]" << QSysInfo::currentCpuArchitecture();
|
||||
qInfo() << "[LOG_LEVEL]" << g_logLevel;
|
||||
qInfo() << "[LOG_PATH]" << g_file_path;
|
||||
qInfo() << "===================================================";
|
||||
}
|
||||
|
@ -1,11 +1,9 @@
|
||||
#ifndef LOG_H
|
||||
#define LOG_H
|
||||
#pragma once
|
||||
|
||||
#include <QtCore/qstring.h>
|
||||
|
||||
namespace Log
|
||||
{
|
||||
namespace Log {
|
||||
QString prettyProductInfoWrapper();
|
||||
void setup(char *argv[], const QString &app,int level = 4);
|
||||
}
|
||||
|
||||
#endif // LOG_H
|
||||
void setup(char *argv[], const QString &app, int level = 4);
|
||||
}
|
@ -1,3 +1,7 @@
|
||||
#pragma clang diagnostic push
|
||||
#pragma ide diagnostic ignored "UnusedParameter"
|
||||
#pragma ide diagnostic ignored "OCUnusedGlobalDeclarationInspection"
|
||||
|
||||
#include "Network.h"
|
||||
|
||||
#include <QUrlQuery>
|
||||
@ -17,175 +21,174 @@
|
||||
#include <QCryptographicHash>
|
||||
#include <QEventLoop>
|
||||
#include <QGuiApplication>
|
||||
#include <utility>
|
||||
|
||||
NetworkCallable::NetworkCallable(QObject *parent):QObject{parent}{
|
||||
|
||||
NetworkCallable::NetworkCallable(QObject *parent) : QObject{parent} {
|
||||
|
||||
}
|
||||
|
||||
QString NetworkParams::method2String(){
|
||||
QString NetworkParams::method2String() const {
|
||||
switch (_method) {
|
||||
case METHOD_GET:
|
||||
return "GET";
|
||||
case METHOD_HEAD:
|
||||
return "HEAD";
|
||||
case METHOD_POST:
|
||||
return "POST";
|
||||
case METHOD_PUT:
|
||||
return "PUT";
|
||||
case METHOD_PATCH:
|
||||
return "PATCH";
|
||||
case METHOD_DELETE:
|
||||
return "DELETE";
|
||||
default:
|
||||
return "";
|
||||
case METHOD_GET:
|
||||
return "GET";
|
||||
case METHOD_HEAD:
|
||||
return "HEAD";
|
||||
case METHOD_POST:
|
||||
return "POST";
|
||||
case METHOD_PUT:
|
||||
return "PUT";
|
||||
case METHOD_PATCH:
|
||||
return "PATCH";
|
||||
case METHOD_DELETE:
|
||||
return "DELETE";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
int NetworkParams::getTimeout(){
|
||||
if(_timeout != -1){
|
||||
int NetworkParams::getTimeout() const {
|
||||
if (_timeout != -1) {
|
||||
return _timeout;
|
||||
}
|
||||
return Network::getInstance()->timeout();
|
||||
}
|
||||
|
||||
int NetworkParams::getRetry(){
|
||||
if(_retry != -1){
|
||||
int NetworkParams::getRetry() const {
|
||||
if (_retry != -1) {
|
||||
return _retry;
|
||||
}
|
||||
return Network::getInstance()->retry();
|
||||
}
|
||||
|
||||
bool NetworkParams::getOpenLog(){
|
||||
if(!_openLog.isNull()){
|
||||
bool NetworkParams::getOpenLog() const {
|
||||
if (!_openLog.isNull()) {
|
||||
return _openLog.toBool();
|
||||
}
|
||||
return Network::getInstance()->openLog();
|
||||
}
|
||||
|
||||
FluDownloadParam::FluDownloadParam(QObject *parent)
|
||||
: QObject{parent}
|
||||
{
|
||||
: QObject{parent} {
|
||||
}
|
||||
|
||||
FluDownloadParam::FluDownloadParam(QString destPath,bool append,QObject *parent)
|
||||
: QObject{parent}
|
||||
{
|
||||
this->_destPath = destPath;
|
||||
FluDownloadParam::FluDownloadParam(QString destPath, bool append, QObject *parent)
|
||||
: QObject{parent} {
|
||||
this->_destPath = std::move(destPath);
|
||||
this->_append = append;
|
||||
}
|
||||
|
||||
NetworkParams::NetworkParams(QObject *parent)
|
||||
: QObject{parent}
|
||||
{
|
||||
NetworkParams::NetworkParams(QObject *parent) : QObject{parent} {
|
||||
_method = NetworkParams::Method::METHOD_GET;
|
||||
_type = NetworkParams::Type::TYPE_BODY;
|
||||
}
|
||||
|
||||
NetworkParams::NetworkParams(QString url,Type type,Method method,QObject *parent)
|
||||
: QObject{parent}
|
||||
{
|
||||
NetworkParams::NetworkParams(QString url, Type type, Method method, QObject *parent)
|
||||
: QObject{parent} {
|
||||
this->_method = method;
|
||||
this->_url = url;
|
||||
this->_url = std::move(url);
|
||||
this->_type = type;
|
||||
}
|
||||
|
||||
NetworkParams* NetworkParams::add(QString key,QVariant val){
|
||||
_paramMap.insert(key,val);
|
||||
NetworkParams *NetworkParams::add(const QString &key, const QVariant &val) {
|
||||
_paramMap.insert(key, val);
|
||||
return this;
|
||||
}
|
||||
|
||||
NetworkParams* NetworkParams::addFile(QString key,QVariant val){
|
||||
_fileMap.insert(key,val);
|
||||
NetworkParams *NetworkParams::addFile(const QString &key, const QVariant &val) {
|
||||
_fileMap.insert(key, val);
|
||||
return this;
|
||||
}
|
||||
|
||||
NetworkParams* NetworkParams::addHeader(QString key,QVariant val){
|
||||
_headerMap.insert(key,val);
|
||||
NetworkParams *NetworkParams::addHeader(const QString &key, const QVariant &val) {
|
||||
_headerMap.insert(key, val);
|
||||
return this;
|
||||
}
|
||||
|
||||
NetworkParams* NetworkParams::addQuery(QString key,QVariant val){
|
||||
_queryMap.insert(key,val);
|
||||
NetworkParams *NetworkParams::addQuery(const QString &key, const QVariant &val) {
|
||||
_queryMap.insert(key, val);
|
||||
return this;
|
||||
}
|
||||
|
||||
NetworkParams* NetworkParams::setBody(QString val){
|
||||
_body = val;
|
||||
NetworkParams *NetworkParams::setBody(QString val) {
|
||||
_body = std::move(val);
|
||||
return this;
|
||||
}
|
||||
|
||||
NetworkParams* NetworkParams::setTimeout(int val){
|
||||
NetworkParams *NetworkParams::setTimeout(int val) {
|
||||
_timeout = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
NetworkParams* NetworkParams::setRetry(int val){
|
||||
NetworkParams *NetworkParams::setRetry(int val) {
|
||||
_retry = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
NetworkParams* NetworkParams::setCacheMode(int val){
|
||||
NetworkParams *NetworkParams::setCacheMode(int val) {
|
||||
_cacheMode = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
NetworkParams* NetworkParams::toDownload(QString destPath,bool append){
|
||||
_downloadParam = new FluDownloadParam(destPath,append,this);
|
||||
NetworkParams *NetworkParams::toDownload(QString destPath, bool append) {
|
||||
_downloadParam = new FluDownloadParam(std::move(destPath), append, this);
|
||||
return this;
|
||||
}
|
||||
|
||||
NetworkParams* NetworkParams::bind(QObject* target){
|
||||
NetworkParams *NetworkParams::bind(QObject *target) {
|
||||
_target = target;
|
||||
return this;
|
||||
}
|
||||
|
||||
NetworkParams* NetworkParams::openLog(QVariant val){
|
||||
_openLog = val;
|
||||
NetworkParams *NetworkParams::openLog(QVariant val) {
|
||||
_openLog = std::move(val);
|
||||
return this;
|
||||
}
|
||||
|
||||
QString NetworkParams::buildCacheKey(){
|
||||
QString NetworkParams::buildCacheKey() const {
|
||||
QJsonObject obj;
|
||||
obj.insert("url",_url);
|
||||
obj.insert("method",method2String());
|
||||
obj.insert("body",_body);
|
||||
obj.insert("query",QJsonDocument::fromVariant(_queryMap).object());
|
||||
obj.insert("param",QJsonDocument::fromVariant(_paramMap).object());
|
||||
obj.insert("header",QJsonDocument::fromVariant(_headerMap).object());
|
||||
obj.insert("file",QJsonDocument::fromVariant(_fileMap).object());
|
||||
if(_downloadParam){
|
||||
obj.insert("url", _url);
|
||||
obj.insert("method", method2String());
|
||||
obj.insert("body", _body);
|
||||
obj.insert("query", QJsonDocument::fromVariant(_queryMap).object());
|
||||
obj.insert("param", QJsonDocument::fromVariant(_paramMap).object());
|
||||
obj.insert("header", QJsonDocument::fromVariant(_headerMap).object());
|
||||
obj.insert("file", QJsonDocument::fromVariant(_fileMap).object());
|
||||
if (_downloadParam) {
|
||||
QJsonObject downObj;
|
||||
downObj.insert("destPath",_downloadParam->_destPath);
|
||||
downObj.insert("append",_downloadParam->_append);
|
||||
obj.insert("download",downObj);
|
||||
downObj.insert("destPath", _downloadParam->_destPath);
|
||||
downObj.insert("append", _downloadParam->_append);
|
||||
obj.insert("download", downObj);
|
||||
}
|
||||
QByteArray data = QJsonDocument(obj).toJson(QJsonDocument::Compact);
|
||||
return QCryptographicHash::hash(data, QCryptographicHash::Sha256).toHex();
|
||||
}
|
||||
|
||||
void NetworkParams::go(NetworkCallable* callable){
|
||||
void NetworkParams::go(NetworkCallable *callable) {
|
||||
QJSValueList data;
|
||||
data<<qjsEngine(callable)->newQObject(this);
|
||||
data << qjsEngine(callable)->newQObject(this);
|
||||
Network::getInstance()->_interceptor.call(data);
|
||||
if(_downloadParam){
|
||||
Network::getInstance()->handleDownload(this,callable);
|
||||
}else{
|
||||
Network::getInstance()->handle(this,callable);
|
||||
if (_downloadParam) {
|
||||
Network::getInstance()->handleDownload(this, callable);
|
||||
} else {
|
||||
Network::getInstance()->handle(this, callable);
|
||||
}
|
||||
}
|
||||
|
||||
void Network::handle(NetworkParams* params,NetworkCallable* c){
|
||||
void Network::handle(NetworkParams *params, NetworkCallable *c) {
|
||||
QPointer<NetworkCallable> callable(c);
|
||||
QThreadPool::globalInstance()->start([=](){
|
||||
if(!callable.isNull()){
|
||||
QThreadPool::globalInstance()->start([=]() {
|
||||
if (!callable.isNull()) {
|
||||
callable->start();
|
||||
}
|
||||
QString cacheKey = params->buildCacheKey();
|
||||
if(params->_cacheMode == NetworkType::CacheMode::FirstCacheThenRequest && cacheExists(cacheKey)){
|
||||
if(!callable.isNull()){
|
||||
if (params->_cacheMode == NetworkType::CacheMode::FirstCacheThenRequest && cacheExists(cacheKey)) {
|
||||
if (!callable.isNull()) {
|
||||
callable->cache(readCache(cacheKey));
|
||||
}
|
||||
}
|
||||
if(params->_cacheMode == NetworkType::CacheMode::IfNoneCacheRequest && cacheExists(cacheKey)){
|
||||
if(!callable.isNull()){
|
||||
if (params->_cacheMode == NetworkType::CacheMode::IfNoneCacheRequest && cacheExists(cacheKey)) {
|
||||
if (!callable.isNull()) {
|
||||
callable->cache(readCache(cacheKey));
|
||||
callable->finish();
|
||||
params->deleteLater();
|
||||
@ -195,131 +198,130 @@ void Network::handle(NetworkParams* params,NetworkCallable* c){
|
||||
QNetworkAccessManager manager;
|
||||
manager.setTransferTimeout(params->getTimeout());
|
||||
QEventLoop loop;
|
||||
connect(&manager,&QNetworkAccessManager::finished,&manager,[&loop](QNetworkReply *reply){loop.quit();});
|
||||
for (int i = 0; i < params->getRetry(); ++i) {
|
||||
connect(&manager, &QNetworkAccessManager::finished, &manager, [&loop](QNetworkReply *reply) { loop.quit(); });
|
||||
for (int i = 0; i <= params->getRetry() - 1; ++i) {
|
||||
QUrl url(params->_url);
|
||||
addQueryParam(&url,params->_queryMap);
|
||||
addQueryParam(&url, params->_queryMap);
|
||||
QNetworkRequest request(url);
|
||||
addHeaders(&request,params->_headerMap);
|
||||
QNetworkReply* reply;
|
||||
sendRequest(&manager,request,params,reply,i==0,callable);
|
||||
if(!QPointer<QGuiApplication>(qApp)){
|
||||
addHeaders(&request, params->_headerMap);
|
||||
QNetworkReply *reply;
|
||||
sendRequest(&manager, request, params, reply, i == 0, callable);
|
||||
if (!QPointer<QCoreApplication>(QGuiApplication::instance())) {
|
||||
reply->deleteLater();
|
||||
reply = nullptr;
|
||||
return;
|
||||
}
|
||||
auto abortCallable = [&loop,reply,&i,params]{
|
||||
if(reply){
|
||||
auto abortCallable = [reply, &i, params] {
|
||||
if (reply) {
|
||||
i = params->getRetry();
|
||||
reply->abort();
|
||||
}
|
||||
};
|
||||
QMetaObject::Connection conn_destroyed = {};
|
||||
QMetaObject::Connection conn_quit = {};
|
||||
if(params->_target){
|
||||
conn_destroyed = connect(params->_target,&QObject::destroyed,&manager,abortCallable);
|
||||
if (params->_target) {
|
||||
conn_destroyed = connect(params->_target, &QObject::destroyed, &manager, abortCallable);
|
||||
}
|
||||
conn_quit = connect(qApp,&QGuiApplication::aboutToQuit,&manager, abortCallable);
|
||||
conn_quit = connect(QGuiApplication::instance(), &QGuiApplication::aboutToQuit, &manager, abortCallable);
|
||||
loop.exec();
|
||||
if(conn_destroyed){
|
||||
if (conn_destroyed) {
|
||||
disconnect(conn_destroyed);
|
||||
}
|
||||
if(conn_quit){
|
||||
if (conn_quit) {
|
||||
disconnect(conn_quit);
|
||||
}
|
||||
QString response;
|
||||
if(params->_method == NetworkParams::METHOD_HEAD){
|
||||
if (params->_method == NetworkParams::METHOD_HEAD) {
|
||||
response = headerList2String(reply->rawHeaderPairs());
|
||||
}else{
|
||||
if(reply->isOpen()){
|
||||
} else {
|
||||
if (reply->isOpen()) {
|
||||
response = QString::fromUtf8(reply->readAll());
|
||||
}
|
||||
}
|
||||
int httpStatus = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||
if(httpStatus == 200){
|
||||
if(!callable.isNull()){
|
||||
if(params->_cacheMode != NetworkType::CacheMode::NoCache){
|
||||
saveResponse(cacheKey,response);
|
||||
if (httpStatus == 200) {
|
||||
if (!callable.isNull()) {
|
||||
if (params->_cacheMode != NetworkType::CacheMode::NoCache) {
|
||||
saveResponse(cacheKey, response);
|
||||
}
|
||||
callable->success(response);
|
||||
}
|
||||
printRequestEndLog(request,params,reply,response);
|
||||
printRequestEndLog(request, params, reply, response);
|
||||
break;
|
||||
}else{
|
||||
if(i == params->getRetry()-1){
|
||||
if(!callable.isNull()){
|
||||
if(params->_cacheMode == NetworkType::CacheMode::RequestFailedReadCache && cacheExists(cacheKey)){
|
||||
if(!callable.isNull()){
|
||||
} else {
|
||||
if (i == params->getRetry() - 1) {
|
||||
if (!callable.isNull()) {
|
||||
if (params->_cacheMode == NetworkType::CacheMode::RequestFailedReadCache && cacheExists(cacheKey)) {
|
||||
if (!callable.isNull()) {
|
||||
callable->cache(readCache(cacheKey));
|
||||
}
|
||||
}
|
||||
callable->error(httpStatus,reply->errorString(),response);
|
||||
callable->error(httpStatus, reply->errorString(), response);
|
||||
}
|
||||
printRequestEndLog(request,params,reply,response);
|
||||
printRequestEndLog(request, params, reply, response);
|
||||
}
|
||||
}
|
||||
reply->deleteLater();
|
||||
}
|
||||
params->deleteLater();
|
||||
if(!callable.isNull()){
|
||||
if (!callable.isNull()) {
|
||||
callable->finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void Network::handleDownload(NetworkParams* params,NetworkCallable* c){
|
||||
void Network::handleDownload(NetworkParams *params, NetworkCallable *c) {
|
||||
QPointer<NetworkCallable> callable(c);
|
||||
QThreadPool::globalInstance()->start([=](){
|
||||
if(!callable.isNull()){
|
||||
QThreadPool::globalInstance()->start([=]() {
|
||||
if (!callable.isNull()) {
|
||||
callable->start();
|
||||
}
|
||||
QString cacheKey = params->buildCacheKey();
|
||||
QUrl url(params->_url);
|
||||
QNetworkAccessManager manager;
|
||||
manager.setTransferTimeout(params->getTimeout());
|
||||
addQueryParam(&url,params->_queryMap);
|
||||
addQueryParam(&url, params->_queryMap);
|
||||
QNetworkRequest request(url);
|
||||
addHeaders(&request,params->_headerMap);
|
||||
addHeaders(&request, params->_headerMap);
|
||||
QString cachePath = getCacheFilePath(cacheKey);
|
||||
QString destPath = params->_downloadParam->_destPath;
|
||||
QFile* destFile = new QFile(destPath);
|
||||
QFile* cacheFile = new QFile(cachePath);
|
||||
bool isOpen = false;
|
||||
qint64 seek = 0;
|
||||
if(cacheFile->exists() && destFile->exists() && params->_downloadParam->_append){
|
||||
auto *destFile = new QFile(destPath);
|
||||
auto *cacheFile = new QFile(cachePath);
|
||||
bool isOpen;
|
||||
qint64 seek;
|
||||
if (cacheFile->exists() && destFile->exists() && params->_downloadParam->_append) {
|
||||
QJsonObject cacheInfo = QJsonDocument::fromJson(readCache(cacheKey).toUtf8()).object();
|
||||
qint64 fileSize = cacheInfo.value("fileSize").toDouble();
|
||||
qint64 contentLength = cacheInfo.value("contentLength").toDouble();
|
||||
if(fileSize == contentLength && destFile->size() == contentLength){
|
||||
if(!callable.isNull()){
|
||||
callable->downloadProgress(fileSize,contentLength);
|
||||
qint64 fileSize = qRound(cacheInfo.value("fileSize").toDouble());
|
||||
qint64 contentLength = qRound(cacheInfo.value("contentLength").toDouble());
|
||||
if (fileSize == contentLength && destFile->size() == contentLength) {
|
||||
if (!callable.isNull()) {
|
||||
callable->downloadProgress(fileSize, contentLength);
|
||||
callable->success(destPath);
|
||||
callable->finish();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if(fileSize==destFile->size()){
|
||||
if (fileSize == destFile->size()) {
|
||||
request.setRawHeader("Range", QString("bytes=%1-").arg(fileSize).toUtf8());
|
||||
seek = fileSize;
|
||||
isOpen = destFile->open(QIODevice::WriteOnly|QIODevice::Append);
|
||||
}else{
|
||||
isOpen = destFile->open(QIODevice::WriteOnly|QIODevice::Truncate);
|
||||
isOpen = destFile->open(QIODevice::WriteOnly | QIODevice::Append);
|
||||
} else {
|
||||
isOpen = destFile->open(QIODevice::WriteOnly | QIODevice::Truncate);
|
||||
}
|
||||
}else{
|
||||
isOpen = destFile->open(QIODevice::WriteOnly|QIODevice::Truncate);
|
||||
} else {
|
||||
isOpen = destFile->open(QIODevice::WriteOnly | QIODevice::Truncate);
|
||||
}
|
||||
if(!isOpen){
|
||||
if(!callable.isNull()){
|
||||
callable->error(-1,"device not open","");
|
||||
if (!isOpen) {
|
||||
if (!callable.isNull()) {
|
||||
callable->error(-1, "device not open", "");
|
||||
callable->finish();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if(params->_downloadParam->_append){
|
||||
if (!cacheFile->open(QIODevice::WriteOnly|QIODevice::Truncate))
|
||||
{
|
||||
if(!callable.isNull()){
|
||||
callable->error(-1,"cache file device not open","");
|
||||
if (params->_downloadParam->_append) {
|
||||
if (!cacheFile->open(QIODevice::WriteOnly | QIODevice::Truncate)) {
|
||||
if (!callable.isNull()) {
|
||||
callable->error(-1, "cache file device not open", "");
|
||||
callable->finish();
|
||||
}
|
||||
return;
|
||||
@ -329,73 +331,72 @@ void Network::handleDownload(NetworkParams* params,NetworkCallable* c){
|
||||
QNetworkReply *reply = manager.get(request);
|
||||
destFile->setParent(reply);
|
||||
cacheFile->setParent(reply);
|
||||
auto abortCallable = [&loop,reply,params]{
|
||||
if(reply){
|
||||
auto abortCallable = [reply] {
|
||||
if (reply) {
|
||||
reply->abort();
|
||||
}
|
||||
};
|
||||
connect(&manager,&QNetworkAccessManager::finished,&manager,[&loop](QNetworkReply *reply){loop.quit();});
|
||||
connect(qApp,&QGuiApplication::aboutToQuit,&manager, [&loop,reply](){reply->abort(),loop.quit();});
|
||||
connect(&manager, &QNetworkAccessManager::finished, &manager, [&loop](QNetworkReply *reply) { loop.quit(); });
|
||||
connect(QGuiApplication::instance(), &QGuiApplication::aboutToQuit, &manager, [&loop, reply]() { reply->abort(), loop.quit(); });
|
||||
QMetaObject::Connection conn_destroyed = {};
|
||||
QMetaObject::Connection conn_quit = {};
|
||||
if(params->_target){
|
||||
conn_destroyed = connect(params->_target,&QObject::destroyed,&manager,abortCallable);
|
||||
if (params->_target) {
|
||||
conn_destroyed = connect(params->_target, &QObject::destroyed, &manager, abortCallable);
|
||||
}
|
||||
conn_quit = connect(qApp,&QGuiApplication::aboutToQuit,&manager, abortCallable);
|
||||
connect(reply,&QNetworkReply::readyRead,reply,[reply,seek,destFile,cacheFile,callable]{
|
||||
if (!reply || !destFile || reply->error() != QNetworkReply::NoError)
|
||||
{
|
||||
conn_quit = connect(QGuiApplication::instance(), &QGuiApplication::aboutToQuit, &manager, abortCallable);
|
||||
connect(reply, &QNetworkReply::readyRead, reply, [reply, seek, destFile, cacheFile, callable] {
|
||||
if (!reply || !destFile || reply->error() != QNetworkReply::NoError) {
|
||||
return;
|
||||
}
|
||||
QMap<QString, QVariant> downInfo;
|
||||
qint64 contentLength = reply->header(QNetworkRequest::ContentLengthHeader).toLongLong()+seek;
|
||||
downInfo.insert("contentLength",contentLength);
|
||||
qint64 contentLength = reply->header(QNetworkRequest::ContentLengthHeader).toLongLong() + seek;
|
||||
downInfo.insert("contentLength", contentLength);
|
||||
QString eTag = reply->header(QNetworkRequest::ETagHeader).toString();
|
||||
downInfo.insert("eTag",eTag);
|
||||
downInfo.insert("eTag", eTag);
|
||||
destFile->write(reply->readAll());
|
||||
destFile->flush();
|
||||
downInfo.insert("fileSize",destFile->size());
|
||||
if(cacheFile->isOpen()){
|
||||
downInfo.insert("fileSize", destFile->size());
|
||||
if (cacheFile->isOpen()) {
|
||||
cacheFile->resize(0);
|
||||
cacheFile->write(QJsonDocument::fromVariant(QVariant(downInfo)).toJson().toBase64());
|
||||
cacheFile->flush();
|
||||
}
|
||||
if(!callable.isNull()){
|
||||
callable->downloadProgress(destFile->size(),contentLength);
|
||||
if (!callable.isNull()) {
|
||||
callable->downloadProgress(destFile->size(), contentLength);
|
||||
}
|
||||
});
|
||||
loop.exec();
|
||||
int httpStatus = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||
if(httpStatus == 200){
|
||||
if(!callable.isNull()){
|
||||
if (httpStatus == 200) {
|
||||
if (!callable.isNull()) {
|
||||
callable->success(destPath);
|
||||
}
|
||||
printRequestEndLog(request,params,reply,destPath);
|
||||
}else{
|
||||
if(!callable.isNull()){
|
||||
callable->error(httpStatus,reply->errorString(),destPath);
|
||||
printRequestEndLog(request, params, reply, destPath);
|
||||
} else {
|
||||
if (!callable.isNull()) {
|
||||
callable->error(httpStatus, reply->errorString(), destPath);
|
||||
}
|
||||
printRequestEndLog(request,params,reply,destPath);
|
||||
printRequestEndLog(request, params, reply, destPath);
|
||||
}
|
||||
if(conn_destroyed){
|
||||
if (conn_destroyed) {
|
||||
disconnect(conn_destroyed);
|
||||
}
|
||||
if(conn_quit){
|
||||
if (conn_quit) {
|
||||
disconnect(conn_quit);
|
||||
}
|
||||
params->deleteLater();
|
||||
reply->deleteLater();
|
||||
if(!callable.isNull()){
|
||||
if (!callable.isNull()) {
|
||||
callable->finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
QString Network::readCache(const QString& key){
|
||||
QString Network::readCache(const QString &key) {
|
||||
auto filePath = getCacheFilePath(key);
|
||||
QString result;
|
||||
QFile file(filePath);
|
||||
if(!file.exists()){
|
||||
if (!file.exists()) {
|
||||
return result;
|
||||
}
|
||||
if (file.open(QIODevice::ReadOnly)) {
|
||||
@ -405,27 +406,27 @@ QString Network::readCache(const QString& key){
|
||||
return result;
|
||||
}
|
||||
|
||||
bool Network::cacheExists(const QString& key){
|
||||
bool Network::cacheExists(const QString &key) {
|
||||
return QFile(getCacheFilePath(key)).exists();
|
||||
}
|
||||
|
||||
QString Network::getCacheFilePath(const QString& key){
|
||||
QString Network::getCacheFilePath(const QString &key) {
|
||||
QDir cacheDir(_cacheDir);
|
||||
if(!cacheDir.exists()){
|
||||
if (!cacheDir.exists()) {
|
||||
cacheDir.mkpath(_cacheDir);
|
||||
}
|
||||
return cacheDir.absoluteFilePath(key);
|
||||
}
|
||||
|
||||
QString Network::headerList2String(const QList<QNetworkReply::RawHeaderPair>& data){
|
||||
QString Network::headerList2String(const QList<QNetworkReply::RawHeaderPair> &data) {
|
||||
QJsonObject object;
|
||||
for (auto it = data.constBegin(); it != data.constEnd(); ++it) {
|
||||
object.insert(QString(it->first),QString(it->second));
|
||||
object.insert(QString(it->first), QString(it->second));
|
||||
}
|
||||
return QJsonDocument(object).toJson(QJsonDocument::Compact);
|
||||
}
|
||||
|
||||
QString Network::map2String(const QMap<QString, QVariant>& map){
|
||||
QString Network::map2String(const QMap<QString, QVariant> &map) {
|
||||
QStringList parameters;
|
||||
for (auto it = map.constBegin(); it != map.constEnd(); ++it) {
|
||||
parameters << QString("%1=%2").arg(it.key(), it.value().toString());
|
||||
@ -433,244 +434,237 @@ QString Network::map2String(const QMap<QString, QVariant>& map){
|
||||
return parameters.join(" ");
|
||||
}
|
||||
|
||||
void Network::sendRequest(QNetworkAccessManager* manager,QNetworkRequest request,NetworkParams* params,QNetworkReply*& reply,bool isFirst,QPointer<NetworkCallable> callable){
|
||||
void Network::sendRequest(QNetworkAccessManager *manager, QNetworkRequest request, NetworkParams *params, QNetworkReply *&reply, bool isFirst, const QPointer<NetworkCallable> &callable) {
|
||||
QByteArray verb = params->method2String().toUtf8();
|
||||
switch (params->_type) {
|
||||
case NetworkParams::TYPE_FORM:{
|
||||
bool isFormData = !params->_fileMap.isEmpty();
|
||||
if(isFormData){
|
||||
QHttpMultiPart *multiPart = new QHttpMultiPart();
|
||||
multiPart->setContentType(QHttpMultiPart::FormDataType);
|
||||
for (const auto& each : params->_paramMap.toStdMap())
|
||||
{
|
||||
QHttpPart part;
|
||||
part.setHeader(QNetworkRequest::ContentDispositionHeader, QString("form-data; name=\"%1\"").arg(each.first));
|
||||
part.setBody(each.second.toByteArray());
|
||||
multiPart->append(part);
|
||||
}
|
||||
for (const auto& each : params->_fileMap.toStdMap())
|
||||
{
|
||||
QString filePath = each.second.toString();
|
||||
QString name = each.first;
|
||||
QFile *file = new QFile(filePath);
|
||||
QString fileName = QFileInfo(filePath).fileName();
|
||||
file->open(QIODevice::ReadOnly);
|
||||
file->setParent(multiPart);
|
||||
QHttpPart part;
|
||||
part.setHeader(QNetworkRequest::ContentDispositionHeader, QString("form-data; name=\"%1\"; filename=\"%2\"").arg(name,fileName));
|
||||
part.setBodyDevice(file);
|
||||
multiPart->append(part);
|
||||
}
|
||||
reply = manager->sendCustomRequest(request,verb,multiPart);
|
||||
multiPart->setParent(reply);
|
||||
connect(reply,&QNetworkReply::uploadProgress,reply,[callable](qint64 bytesSent, qint64 bytesTotal){
|
||||
if(!callable.isNull() && bytesSent!=0 && bytesTotal!=0){
|
||||
Q_EMIT callable->uploadProgress(bytesSent,bytesTotal);
|
||||
case NetworkParams::TYPE_FORM: {
|
||||
bool isFormData = !params->_fileMap.isEmpty();
|
||||
if (isFormData) {
|
||||
auto *multiPart = new QHttpMultiPart();
|
||||
multiPart->setContentType(QHttpMultiPart::FormDataType);
|
||||
for (const auto &each: params->_paramMap.toStdMap()) {
|
||||
QHttpPart part;
|
||||
part.setHeader(QNetworkRequest::ContentDispositionHeader, QString("form-data; name=\"%1\"").arg(each.first));
|
||||
part.setBody(each.second.toByteArray());
|
||||
multiPart->append(part);
|
||||
}
|
||||
});
|
||||
}else{
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, QString("application/x-www-form-urlencoded"));
|
||||
QString value;
|
||||
for (const auto& each : params->_paramMap.toStdMap())
|
||||
{
|
||||
value += QString("%1=%2").arg(each.first,each.second.toString());
|
||||
value += "&";
|
||||
for (const auto &each: params->_fileMap.toStdMap()) {
|
||||
QString filePath = each.second.toString();
|
||||
QString name = each.first;
|
||||
auto *file = new QFile(filePath);
|
||||
QString fileName = QFileInfo(filePath).fileName();
|
||||
file->open(QIODevice::ReadOnly);
|
||||
file->setParent(multiPart);
|
||||
QHttpPart part;
|
||||
part.setHeader(QNetworkRequest::ContentDispositionHeader, QString(R"(form-data; name="%1"; filename="%2")").arg(name, fileName));
|
||||
part.setBodyDevice(file);
|
||||
multiPart->append(part);
|
||||
}
|
||||
reply = manager->sendCustomRequest(request, verb, multiPart);
|
||||
multiPart->setParent(reply);
|
||||
connect(reply, &QNetworkReply::uploadProgress, reply, [callable](qint64 bytesSent, qint64 bytesTotal) {
|
||||
if (!callable.isNull() && bytesSent != 0 && bytesTotal != 0) {
|
||||
Q_EMIT callable->uploadProgress(bytesSent, bytesTotal);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, QString("application/x-www-form-urlencoded"));
|
||||
QString value;
|
||||
for (const auto &each: params->_paramMap.toStdMap()) {
|
||||
value += QString("%1=%2").arg(each.first, each.second.toString());
|
||||
value += "&";
|
||||
}
|
||||
if (!params->_paramMap.isEmpty()) {
|
||||
value.chop(1);
|
||||
}
|
||||
QByteArray data = value.toUtf8();
|
||||
reply = manager->sendCustomRequest(request, verb, data);
|
||||
}
|
||||
if(!params->_paramMap.isEmpty()){
|
||||
value.chop(1);
|
||||
}
|
||||
QByteArray data = value.toUtf8();
|
||||
reply = manager->sendCustomRequest(request,verb,data);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case NetworkParams::TYPE_JSON:{
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, QString("application/json;charset=utf-8"));
|
||||
QJsonObject json;
|
||||
for (const auto& each : params->_paramMap.toStdMap())
|
||||
{
|
||||
json.insert(each.first,each.second.toJsonValue());
|
||||
}
|
||||
QByteArray data = QJsonDocument(json).toJson(QJsonDocument::Compact);
|
||||
reply = manager->sendCustomRequest(request,verb,data);
|
||||
break;
|
||||
}
|
||||
case NetworkParams::TYPE_JSONARRAY:{
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, QString("application/json;charset=utf-8"));
|
||||
QJsonArray jsonArray;
|
||||
for (const auto& each : params->_paramMap.toStdMap())
|
||||
{
|
||||
case NetworkParams::TYPE_JSON: {
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, QString("application/json;charset=utf-8"));
|
||||
QJsonObject json;
|
||||
json.insert(each.first,each.second.toJsonValue());
|
||||
jsonArray.append(json);
|
||||
for (const auto &each: params->_paramMap.toStdMap()) {
|
||||
json.insert(each.first, each.second.toJsonValue());
|
||||
}
|
||||
QByteArray data = QJsonDocument(json).toJson(QJsonDocument::Compact);
|
||||
reply = manager->sendCustomRequest(request, verb, data);
|
||||
break;
|
||||
}
|
||||
QByteArray data = QJsonDocument(jsonArray).toJson(QJsonDocument::Compact);
|
||||
reply = manager->sendCustomRequest(request,params->method2String().toUtf8(),data);
|
||||
break;
|
||||
case NetworkParams::TYPE_JSONARRAY: {
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, QString("application/json;charset=utf-8"));
|
||||
QJsonArray jsonArray;
|
||||
for (const auto &each: params->_paramMap.toStdMap()) {
|
||||
QJsonObject json;
|
||||
json.insert(each.first, each.second.toJsonValue());
|
||||
jsonArray.append(json);
|
||||
}
|
||||
QByteArray data = QJsonDocument(jsonArray).toJson(QJsonDocument::Compact);
|
||||
reply = manager->sendCustomRequest(request, params->method2String().toUtf8(), data);
|
||||
break;
|
||||
}
|
||||
case NetworkParams::TYPE_BODY: {
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, QString("text/plain;charset=utf-8"));
|
||||
QByteArray data = params->_body.toUtf8();
|
||||
reply = manager->sendCustomRequest(request, verb, data);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
reply = manager->sendCustomRequest(request, verb);
|
||||
break;
|
||||
}
|
||||
case NetworkParams::TYPE_BODY:{
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, QString("text/plain;charset=utf-8"));
|
||||
QByteArray data = params->_body.toUtf8();
|
||||
reply = manager->sendCustomRequest(request,verb,data);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
reply = manager->sendCustomRequest(request,verb);
|
||||
break;
|
||||
}
|
||||
if(isFirst){
|
||||
printRequestStartLog(request,params);
|
||||
if (isFirst) {
|
||||
printRequestStartLog(request, params);
|
||||
}
|
||||
}
|
||||
|
||||
void Network::printRequestStartLog(QNetworkRequest request,NetworkParams* params){
|
||||
if(!params->getOpenLog()){
|
||||
void Network::printRequestStartLog(const QNetworkRequest &request, NetworkParams *params) {
|
||||
if (!params->getOpenLog()) {
|
||||
return;
|
||||
}
|
||||
qDebug()<<"<------"<<qUtf8Printable(request.header(QNetworkRequest::UserAgentHeader).toString())<<"Request Start ------>";
|
||||
qDebug()<<qUtf8Printable(QString::fromStdString("<%1>").arg(params->method2String()))<<qUtf8Printable(params->_url);
|
||||
qDebug() << "<------" << qUtf8Printable(request.header(QNetworkRequest::UserAgentHeader).toString()) << "Request Start ------>";
|
||||
qDebug() << qUtf8Printable(QString::fromStdString("<%1>").arg(params->method2String())) << qUtf8Printable(params->_url);
|
||||
auto contentType = request.header(QNetworkRequest::ContentTypeHeader).toString();
|
||||
if(!contentType.isEmpty()){
|
||||
qDebug()<<qUtf8Printable(QString::fromStdString("<Header> %1=%2").arg("Content-Type",contentType));
|
||||
if (!contentType.isEmpty()) {
|
||||
qDebug() << qUtf8Printable(QString::fromStdString("<Header> %1=%2").arg("Content-Type", contentType));
|
||||
}
|
||||
QList<QByteArray> headers = request.rawHeaderList();
|
||||
for(const QByteArray& header:headers){
|
||||
qDebug()<<qUtf8Printable(QString::fromStdString("<Header> %1=%2").arg(header,request.rawHeader(header)));
|
||||
for (const QByteArray &header: headers) {
|
||||
qDebug() << qUtf8Printable(QString::fromStdString("<Header> %1=%2").arg(header, request.rawHeader(header)));
|
||||
}
|
||||
if(!params->_queryMap.isEmpty()){
|
||||
qDebug()<<"<Query>"<<qUtf8Printable(map2String(params->_queryMap));
|
||||
if (!params->_queryMap.isEmpty()) {
|
||||
qDebug() << "<Query>" << qUtf8Printable(map2String(params->_queryMap));
|
||||
}
|
||||
if(!params->_paramMap.isEmpty()){
|
||||
qDebug()<<"<Param>"<<qUtf8Printable(map2String(params->_paramMap));
|
||||
if (!params->_paramMap.isEmpty()) {
|
||||
qDebug() << "<Param>" << qUtf8Printable(map2String(params->_paramMap));
|
||||
}
|
||||
if(!params->_fileMap.isEmpty()){
|
||||
qDebug()<<"<File>"<<qUtf8Printable(map2String(params->_fileMap));
|
||||
if (!params->_fileMap.isEmpty()) {
|
||||
qDebug() << "<File>" << qUtf8Printable(map2String(params->_fileMap));
|
||||
}
|
||||
if(!params->_body.isEmpty()){
|
||||
qDebug()<<"<Body>"<<qUtf8Printable(params->_body);
|
||||
if (!params->_body.isEmpty()) {
|
||||
qDebug() << "<Body>" << qUtf8Printable(params->_body);
|
||||
}
|
||||
}
|
||||
|
||||
void Network::printRequestEndLog(QNetworkRequest request,NetworkParams* params,QNetworkReply*& reply,const QString& response){
|
||||
if(!params->getOpenLog()){
|
||||
void Network::printRequestEndLog(const QNetworkRequest &request, NetworkParams *params, QNetworkReply *&reply, const QString &response) {
|
||||
if (!params->getOpenLog()) {
|
||||
return;
|
||||
}
|
||||
qDebug()<<"<------"<<qUtf8Printable(request.header(QNetworkRequest::UserAgentHeader).toString())<<"Request End ------>";
|
||||
qDebug()<<qUtf8Printable(QString::fromStdString("<%1>").arg(params->method2String()))<<qUtf8Printable(params->_url);
|
||||
qDebug()<<"<Result>"<<qUtf8Printable(response);
|
||||
qDebug() << "<------" << qUtf8Printable(request.header(QNetworkRequest::UserAgentHeader).toString()) << "Request End ------>";
|
||||
qDebug() << qUtf8Printable(QString::fromStdString("<%1>").arg(params->method2String())) << qUtf8Printable(params->_url);
|
||||
qDebug() << "<Result>" << qUtf8Printable(response);
|
||||
}
|
||||
|
||||
void Network::saveResponse(QString key,QString response){
|
||||
void Network::saveResponse(const QString &key, const QString &response) {
|
||||
QSharedPointer<QFile> file(new QFile(getCacheFilePath(key)));
|
||||
QIODevice::OpenMode mode = QIODevice::WriteOnly|QIODevice::Truncate;
|
||||
if (!file->open(mode))
|
||||
{
|
||||
QIODevice::OpenMode mode = QIODevice::WriteOnly | QIODevice::Truncate;
|
||||
if (!file->open(mode)) {
|
||||
return;
|
||||
}
|
||||
file->write(response.toUtf8().toBase64());
|
||||
}
|
||||
|
||||
void Network::addHeaders(QNetworkRequest* request,const QMap<QString, QVariant>& headers){
|
||||
request->setHeader(QNetworkRequest::UserAgentHeader,QString::fromStdString("Mozilla/5.0 %1/%2").arg(QGuiApplication::applicationName(),QGuiApplication::applicationVersion()));
|
||||
void Network::addHeaders(QNetworkRequest *request, const QMap<QString, QVariant> &headers) {
|
||||
request->setHeader(QNetworkRequest::UserAgentHeader, QString::fromStdString("Mozilla/5.0 %1/%2").arg(QGuiApplication::applicationName(), QGuiApplication::applicationVersion()));
|
||||
QMapIterator<QString, QVariant> iter(headers);
|
||||
while (iter.hasNext())
|
||||
{
|
||||
while (iter.hasNext()) {
|
||||
iter.next();
|
||||
request->setRawHeader(iter.key().toUtf8(), iter.value().toString().toUtf8());
|
||||
}
|
||||
}
|
||||
|
||||
void Network::addQueryParam(QUrl* url,const QMap<QString, QVariant>& params){
|
||||
void Network::addQueryParam(QUrl *url, const QMap<QString, QVariant> ¶ms) {
|
||||
QMapIterator<QString, QVariant> iter(params);
|
||||
QUrlQuery urlQuery(*url);
|
||||
while (iter.hasNext())
|
||||
{
|
||||
while (iter.hasNext()) {
|
||||
iter.next();
|
||||
urlQuery.addQueryItem(iter.key(), iter.value().toString());
|
||||
}
|
||||
url->setQuery(urlQuery);
|
||||
}
|
||||
|
||||
Network::Network(QObject *parent): QObject{parent}
|
||||
{
|
||||
timeout(5000);
|
||||
retry(3);
|
||||
openLog(false);
|
||||
cacheDir(QStandardPaths::writableLocation(QStandardPaths::CacheLocation).append(QDir::separator()).append("network"));
|
||||
Network::Network(QObject *parent) : QObject{parent} {
|
||||
_timeout = 5000;
|
||||
_retry = 3;
|
||||
_openLog = false;
|
||||
_cacheDir = QStandardPaths::writableLocation(QStandardPaths::CacheLocation).append(QDir::separator()).append("network");
|
||||
}
|
||||
|
||||
NetworkParams* Network::get(const QString& url){
|
||||
return new NetworkParams(url,NetworkParams::TYPE_NONE,NetworkParams::METHOD_GET,this);
|
||||
NetworkParams *Network::get(const QString &url) {
|
||||
return new NetworkParams(url, NetworkParams::TYPE_NONE, NetworkParams::METHOD_GET, this);
|
||||
}
|
||||
|
||||
NetworkParams* Network::head(const QString& url){
|
||||
return new NetworkParams(url,NetworkParams::TYPE_NONE,NetworkParams::METHOD_HEAD,this);
|
||||
NetworkParams *Network::head(const QString &url) {
|
||||
return new NetworkParams(url, NetworkParams::TYPE_NONE, NetworkParams::METHOD_HEAD, this);
|
||||
}
|
||||
|
||||
NetworkParams* Network::postBody(const QString& url){
|
||||
return new NetworkParams(url,NetworkParams::TYPE_BODY,NetworkParams::METHOD_POST,this);
|
||||
NetworkParams *Network::postBody(const QString &url) {
|
||||
return new NetworkParams(url, NetworkParams::TYPE_BODY, NetworkParams::METHOD_POST, this);
|
||||
}
|
||||
|
||||
NetworkParams* Network::putBody(const QString& url){
|
||||
return new NetworkParams(url,NetworkParams::TYPE_BODY,NetworkParams::METHOD_PUT,this);
|
||||
NetworkParams *Network::putBody(const QString &url) {
|
||||
return new NetworkParams(url, NetworkParams::TYPE_BODY, NetworkParams::METHOD_PUT, this);
|
||||
}
|
||||
|
||||
NetworkParams* Network::patchBody(const QString& url){
|
||||
return new NetworkParams(url,NetworkParams::TYPE_BODY,NetworkParams::METHOD_PATCH,this);
|
||||
NetworkParams *Network::patchBody(const QString &url) {
|
||||
return new NetworkParams(url, NetworkParams::TYPE_BODY, NetworkParams::METHOD_PATCH, this);
|
||||
}
|
||||
|
||||
NetworkParams* Network::deleteBody(const QString& url){
|
||||
return new NetworkParams(url,NetworkParams::TYPE_BODY,NetworkParams::METHOD_DELETE,this);
|
||||
NetworkParams *Network::deleteBody(const QString &url) {
|
||||
return new NetworkParams(url, NetworkParams::TYPE_BODY, NetworkParams::METHOD_DELETE, this);
|
||||
}
|
||||
|
||||
NetworkParams* Network::postForm(const QString& url){
|
||||
return new NetworkParams(url,NetworkParams::TYPE_FORM,NetworkParams::METHOD_POST,this);
|
||||
NetworkParams *Network::postForm(const QString &url) {
|
||||
return new NetworkParams(url, NetworkParams::TYPE_FORM, NetworkParams::METHOD_POST, this);
|
||||
}
|
||||
|
||||
NetworkParams* Network::putForm(const QString& url){
|
||||
return new NetworkParams(url,NetworkParams::TYPE_FORM,NetworkParams::METHOD_PUT,this);
|
||||
NetworkParams *Network::putForm(const QString &url) {
|
||||
return new NetworkParams(url, NetworkParams::TYPE_FORM, NetworkParams::METHOD_PUT, this);
|
||||
}
|
||||
|
||||
NetworkParams* Network::patchForm(const QString& url){
|
||||
return new NetworkParams(url,NetworkParams::TYPE_FORM,NetworkParams::METHOD_PATCH,this);
|
||||
NetworkParams *Network::patchForm(const QString &url) {
|
||||
return new NetworkParams(url, NetworkParams::TYPE_FORM, NetworkParams::METHOD_PATCH, this);
|
||||
}
|
||||
|
||||
NetworkParams* Network::deleteForm(const QString& url){
|
||||
return new NetworkParams(url,NetworkParams::TYPE_FORM,NetworkParams::METHOD_DELETE,this);
|
||||
NetworkParams *Network::deleteForm(const QString &url) {
|
||||
return new NetworkParams(url, NetworkParams::TYPE_FORM, NetworkParams::METHOD_DELETE, this);
|
||||
}
|
||||
|
||||
NetworkParams* Network::postJson(const QString& url){
|
||||
return new NetworkParams(url,NetworkParams::TYPE_JSON,NetworkParams::METHOD_POST,this);
|
||||
NetworkParams *Network::postJson(const QString &url) {
|
||||
return new NetworkParams(url, NetworkParams::TYPE_JSON, NetworkParams::METHOD_POST, this);
|
||||
}
|
||||
|
||||
NetworkParams* Network::putJson(const QString& url){
|
||||
return new NetworkParams(url,NetworkParams::TYPE_JSON,NetworkParams::METHOD_PUT,this);
|
||||
NetworkParams *Network::putJson(const QString &url) {
|
||||
return new NetworkParams(url, NetworkParams::TYPE_JSON, NetworkParams::METHOD_PUT, this);
|
||||
}
|
||||
|
||||
NetworkParams* Network::patchJson(const QString& url){
|
||||
return new NetworkParams(url,NetworkParams::TYPE_JSON,NetworkParams::METHOD_PATCH,this);
|
||||
NetworkParams *Network::patchJson(const QString &url) {
|
||||
return new NetworkParams(url, NetworkParams::TYPE_JSON, NetworkParams::METHOD_PATCH, this);
|
||||
}
|
||||
|
||||
NetworkParams* Network::deleteJson(const QString& url){
|
||||
return new NetworkParams(url,NetworkParams::TYPE_JSON,NetworkParams::METHOD_DELETE,this);
|
||||
NetworkParams *Network::deleteJson(const QString &url) {
|
||||
return new NetworkParams(url, NetworkParams::TYPE_JSON, NetworkParams::METHOD_DELETE, this);
|
||||
}
|
||||
|
||||
NetworkParams* Network::postJsonArray(const QString& url){
|
||||
return new NetworkParams(url,NetworkParams::TYPE_JSONARRAY,NetworkParams::METHOD_POST,this);
|
||||
NetworkParams *Network::postJsonArray(const QString &url) {
|
||||
return new NetworkParams(url, NetworkParams::TYPE_JSONARRAY, NetworkParams::METHOD_POST, this);
|
||||
}
|
||||
|
||||
NetworkParams* Network::putJsonArray(const QString& url){
|
||||
return new NetworkParams(url,NetworkParams::TYPE_JSONARRAY,NetworkParams::METHOD_PUT,this);
|
||||
NetworkParams *Network::putJsonArray(const QString &url) {
|
||||
return new NetworkParams(url, NetworkParams::TYPE_JSONARRAY, NetworkParams::METHOD_PUT, this);
|
||||
}
|
||||
|
||||
NetworkParams* Network::patchJsonArray(const QString& url){
|
||||
return new NetworkParams(url,NetworkParams::TYPE_JSONARRAY,NetworkParams::METHOD_PATCH,this);
|
||||
NetworkParams *Network::patchJsonArray(const QString &url) {
|
||||
return new NetworkParams(url, NetworkParams::TYPE_JSONARRAY, NetworkParams::METHOD_PATCH, this);
|
||||
}
|
||||
|
||||
NetworkParams* Network::deleteJsonArray(const QString& url){
|
||||
return new NetworkParams(url,NetworkParams::TYPE_JSONARRAY,NetworkParams::METHOD_DELETE,this);
|
||||
NetworkParams *Network::deleteJsonArray(const QString &url) {
|
||||
return new NetworkParams(url, NetworkParams::TYPE_JSONARRAY, NetworkParams::METHOD_DELETE, this);
|
||||
}
|
||||
|
||||
void Network::setInterceptor(QJSValue interceptor){
|
||||
this->_interceptor = interceptor;
|
||||
void Network::setInterceptor(QJSValue interceptor) {
|
||||
this->_interceptor = std::move(interceptor);
|
||||
}
|
||||
|
||||
#pragma clang diagnostic pop
|
@ -1,5 +1,6 @@
|
||||
#ifndef NETWORK_H
|
||||
#define NETWORK_H
|
||||
#pragma once
|
||||
#pragma clang diagnostic push
|
||||
#pragma ide diagnostic ignored "NotImplementedFunctions"
|
||||
|
||||
#include <QObject>
|
||||
#include <QtQml/qqml.h>
|
||||
@ -12,56 +13,66 @@
|
||||
#include "src/singleton.h"
|
||||
|
||||
namespace NetworkType {
|
||||
Q_NAMESPACE
|
||||
enum CacheMode {
|
||||
NoCache = 0x0000,
|
||||
RequestFailedReadCache = 0x0001,
|
||||
IfNoneCacheRequest = 0x0002,
|
||||
FirstCacheThenRequest = 0x0004,
|
||||
};
|
||||
Q_ENUM_NS(CacheMode)
|
||||
QML_NAMED_ELEMENT(NetworkType)
|
||||
Q_NAMESPACE
|
||||
enum CacheMode {
|
||||
NoCache = 0x0000,
|
||||
RequestFailedReadCache = 0x0001,
|
||||
IfNoneCacheRequest = 0x0002,
|
||||
FirstCacheThenRequest = 0x0004,
|
||||
};
|
||||
|
||||
Q_ENUM_NS(CacheMode)
|
||||
|
||||
QML_NAMED_ELEMENT(NetworkType)
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief The NetworkCallable class
|
||||
*/
|
||||
class NetworkCallable : public QObject{
|
||||
Q_OBJECT
|
||||
class NetworkCallable : public QObject {
|
||||
Q_OBJECT
|
||||
QML_NAMED_ELEMENT(NetworkCallable)
|
||||
public:
|
||||
explicit NetworkCallable(QObject *parent = nullptr);
|
||||
|
||||
Q_SIGNAL void start();
|
||||
|
||||
Q_SIGNAL void finish();
|
||||
Q_SIGNAL void error(int status,QString errorString,QString result);
|
||||
|
||||
Q_SIGNAL void error(int status, QString errorString, QString result);
|
||||
|
||||
Q_SIGNAL void success(QString result);
|
||||
|
||||
Q_SIGNAL void cache(QString result);
|
||||
|
||||
Q_SIGNAL void uploadProgress(qint64 sent, qint64 total);
|
||||
|
||||
Q_SIGNAL void downloadProgress(qint64 recv, qint64 total);
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief The FluDownloadParam class
|
||||
*/
|
||||
class FluDownloadParam : public QObject{
|
||||
Q_OBJECT
|
||||
class FluDownloadParam : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit FluDownloadParam(QObject *parent = nullptr);
|
||||
FluDownloadParam(QString destPath,bool append,QObject *parent = nullptr);
|
||||
|
||||
FluDownloadParam(QString destPath, bool append, QObject *parent = nullptr);
|
||||
|
||||
public:
|
||||
QString _destPath;
|
||||
bool _append;
|
||||
bool _append{};
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief The NetworkParams class
|
||||
*/
|
||||
class NetworkParams : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
class NetworkParams : public QObject {
|
||||
Q_OBJECT
|
||||
QML_NAMED_ELEMENT(NetworkParams)
|
||||
public:
|
||||
enum Method{
|
||||
enum Method {
|
||||
METHOD_GET,
|
||||
METHOD_HEAD,
|
||||
METHOD_POST,
|
||||
@ -69,35 +80,55 @@ public:
|
||||
METHOD_PATCH,
|
||||
METHOD_DELETE
|
||||
};
|
||||
enum Type{
|
||||
enum Type {
|
||||
TYPE_NONE,
|
||||
TYPE_FORM,
|
||||
TYPE_JSON,
|
||||
TYPE_JSONARRAY,
|
||||
TYPE_BODY
|
||||
};
|
||||
|
||||
explicit NetworkParams(QObject *parent = nullptr);
|
||||
NetworkParams(QString url,Type type,Method method,QObject *parent = nullptr);
|
||||
Q_INVOKABLE NetworkParams* addQuery(QString key,QVariant val);
|
||||
Q_INVOKABLE NetworkParams* addHeader(QString key,QVariant val);
|
||||
Q_INVOKABLE NetworkParams* add(QString key,QVariant val);
|
||||
Q_INVOKABLE NetworkParams* addFile(QString key,QVariant val);
|
||||
Q_INVOKABLE NetworkParams* setBody(QString val);
|
||||
Q_INVOKABLE NetworkParams* setTimeout(int val);
|
||||
Q_INVOKABLE NetworkParams* setRetry(int val);
|
||||
Q_INVOKABLE NetworkParams* setCacheMode(int val);
|
||||
Q_INVOKABLE NetworkParams* toDownload(QString destPath,bool append = false);
|
||||
Q_INVOKABLE NetworkParams* bind(QObject* target);
|
||||
Q_INVOKABLE NetworkParams* openLog(QVariant val);
|
||||
Q_INVOKABLE void go(NetworkCallable* result);
|
||||
QString buildCacheKey();
|
||||
QString method2String();
|
||||
int getTimeout();
|
||||
int getRetry();
|
||||
bool getOpenLog();
|
||||
|
||||
NetworkParams(QString url, Type type, Method method, QObject *parent = nullptr);
|
||||
|
||||
Q_INVOKABLE NetworkParams *addQuery(const QString &key, const QVariant &val);
|
||||
|
||||
Q_INVOKABLE NetworkParams *addHeader(const QString &key, const QVariant &val);
|
||||
|
||||
Q_INVOKABLE NetworkParams *add(const QString &key, const QVariant &val);
|
||||
|
||||
Q_INVOKABLE NetworkParams *addFile(const QString &key, const QVariant &val);
|
||||
|
||||
Q_INVOKABLE NetworkParams *setBody(QString val);
|
||||
|
||||
Q_INVOKABLE NetworkParams *setTimeout(int val);
|
||||
|
||||
Q_INVOKABLE NetworkParams *setRetry(int val);
|
||||
|
||||
Q_INVOKABLE NetworkParams *setCacheMode(int val);
|
||||
|
||||
Q_INVOKABLE NetworkParams *toDownload(QString destPath, bool append = false);
|
||||
|
||||
Q_INVOKABLE NetworkParams *bind(QObject *target);
|
||||
|
||||
Q_INVOKABLE NetworkParams *openLog(QVariant val);
|
||||
|
||||
Q_INVOKABLE void go(NetworkCallable *result);
|
||||
|
||||
QString buildCacheKey() const;
|
||||
|
||||
QString method2String() const;
|
||||
|
||||
int getTimeout() const;
|
||||
|
||||
int getRetry() const;
|
||||
|
||||
bool getOpenLog() const;
|
||||
|
||||
public:
|
||||
FluDownloadParam* _downloadParam = nullptr;
|
||||
QObject* _target = nullptr;
|
||||
FluDownloadParam *_downloadParam = nullptr;
|
||||
QObject *_target = nullptr;
|
||||
Method _method;
|
||||
Type _type;
|
||||
QString _url;
|
||||
@ -115,55 +146,90 @@ public:
|
||||
/**
|
||||
* @brief The Network class
|
||||
*/
|
||||
class Network : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY_AUTO(int,timeout)
|
||||
Q_PROPERTY_AUTO(int,retry)
|
||||
Q_PROPERTY_AUTO(QString,cacheDir)
|
||||
Q_PROPERTY_AUTO(bool,openLog)
|
||||
class Network : public QObject {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY_AUTO(int, timeout)
|
||||
Q_PROPERTY_AUTO(int, retry)
|
||||
Q_PROPERTY_AUTO(QString, cacheDir)
|
||||
Q_PROPERTY_AUTO(bool, openLog)
|
||||
QML_NAMED_ELEMENT(Network)
|
||||
QML_SINGLETON
|
||||
|
||||
private:
|
||||
explicit Network(QObject *parent = nullptr);
|
||||
|
||||
public:
|
||||
SINGLETON(Network)
|
||||
static Network *create(QQmlEngine *qmlEngine, QJSEngine *jsEngine){return getInstance();}
|
||||
Q_INVOKABLE NetworkParams* get(const QString& url);
|
||||
Q_INVOKABLE NetworkParams* head(const QString& url);
|
||||
Q_INVOKABLE NetworkParams* postBody(const QString& url);
|
||||
Q_INVOKABLE NetworkParams* putBody(const QString& url);
|
||||
Q_INVOKABLE NetworkParams* patchBody(const QString& url);
|
||||
Q_INVOKABLE NetworkParams* deleteBody(const QString& url);
|
||||
Q_INVOKABLE NetworkParams* postForm(const QString& url);
|
||||
Q_INVOKABLE NetworkParams* putForm(const QString& url);
|
||||
Q_INVOKABLE NetworkParams* patchForm(const QString& url);
|
||||
Q_INVOKABLE NetworkParams* deleteForm(const QString& url);
|
||||
Q_INVOKABLE NetworkParams* postJson(const QString& url);
|
||||
Q_INVOKABLE NetworkParams* putJson(const QString& url);
|
||||
Q_INVOKABLE NetworkParams* patchJson(const QString& url);
|
||||
Q_INVOKABLE NetworkParams* deleteJson(const QString& url);
|
||||
Q_INVOKABLE NetworkParams* postJsonArray(const QString& url);
|
||||
Q_INVOKABLE NetworkParams* putJsonArray(const QString& url);
|
||||
Q_INVOKABLE NetworkParams* patchJsonArray(const QString& url);
|
||||
Q_INVOKABLE NetworkParams* deleteJsonArray(const QString& url);
|
||||
SINGLETON(Network)
|
||||
|
||||
static Network *create(QQmlEngine *qmlEngine, QJSEngine *jsEngine) { return getInstance(); }
|
||||
|
||||
Q_INVOKABLE NetworkParams *get(const QString &url);
|
||||
|
||||
Q_INVOKABLE NetworkParams *head(const QString &url);
|
||||
|
||||
Q_INVOKABLE NetworkParams *postBody(const QString &url);
|
||||
|
||||
Q_INVOKABLE NetworkParams *putBody(const QString &url);
|
||||
|
||||
Q_INVOKABLE NetworkParams *patchBody(const QString &url);
|
||||
|
||||
Q_INVOKABLE NetworkParams *deleteBody(const QString &url);
|
||||
|
||||
Q_INVOKABLE NetworkParams *postForm(const QString &url);
|
||||
|
||||
Q_INVOKABLE NetworkParams *putForm(const QString &url);
|
||||
|
||||
Q_INVOKABLE NetworkParams *patchForm(const QString &url);
|
||||
|
||||
Q_INVOKABLE NetworkParams *deleteForm(const QString &url);
|
||||
|
||||
Q_INVOKABLE NetworkParams *postJson(const QString &url);
|
||||
|
||||
Q_INVOKABLE NetworkParams *putJson(const QString &url);
|
||||
|
||||
Q_INVOKABLE NetworkParams *patchJson(const QString &url);
|
||||
|
||||
Q_INVOKABLE NetworkParams *deleteJson(const QString &url);
|
||||
|
||||
Q_INVOKABLE NetworkParams *postJsonArray(const QString &url);
|
||||
|
||||
Q_INVOKABLE NetworkParams *putJsonArray(const QString &url);
|
||||
|
||||
Q_INVOKABLE NetworkParams *patchJsonArray(const QString &url);
|
||||
|
||||
Q_INVOKABLE NetworkParams *deleteJsonArray(const QString &url);
|
||||
|
||||
Q_INVOKABLE void setInterceptor(QJSValue interceptor);
|
||||
void handle(NetworkParams* params,NetworkCallable* result);
|
||||
void handleDownload(NetworkParams* params,NetworkCallable* result);
|
||||
|
||||
void handle(NetworkParams *params, NetworkCallable *result);
|
||||
|
||||
void handleDownload(NetworkParams *params, NetworkCallable *result);
|
||||
|
||||
private:
|
||||
void sendRequest(QNetworkAccessManager* manager,QNetworkRequest request,NetworkParams* params,QNetworkReply*& reply,bool isFirst,QPointer<NetworkCallable> callable);
|
||||
void addQueryParam(QUrl* url,const QMap<QString, QVariant>& params);
|
||||
void addHeaders(QNetworkRequest* request,const QMap<QString, QVariant>& headers);
|
||||
void saveResponse(QString key,QString response);
|
||||
QString readCache(const QString& key);
|
||||
bool cacheExists(const QString& key);
|
||||
QString getCacheFilePath(const QString& key);
|
||||
QString map2String(const QMap<QString, QVariant>& map);
|
||||
QString headerList2String(const QList<QNetworkReply::RawHeaderPair>& data);
|
||||
void printRequestStartLog(QNetworkRequest request,NetworkParams* params);
|
||||
void printRequestEndLog(QNetworkRequest request,NetworkParams* params,QNetworkReply*& reply,const QString& response);
|
||||
static void sendRequest(QNetworkAccessManager *manager, QNetworkRequest request, NetworkParams *params, QNetworkReply *&reply, bool isFirst, const QPointer<NetworkCallable>& callable);
|
||||
|
||||
static void addQueryParam(QUrl *url, const QMap<QString, QVariant> ¶ms);
|
||||
|
||||
static void addHeaders(QNetworkRequest *request, const QMap<QString, QVariant> &headers);
|
||||
|
||||
void saveResponse(const QString& key, const QString& response);
|
||||
|
||||
QString readCache(const QString &key);
|
||||
|
||||
bool cacheExists(const QString &key);
|
||||
|
||||
QString getCacheFilePath(const QString &key);
|
||||
|
||||
static QString headerList2String(const QList<QNetworkReply::RawHeaderPair> &data);
|
||||
|
||||
static void printRequestStartLog(const QNetworkRequest& request, NetworkParams *params);
|
||||
|
||||
static void printRequestEndLog(const QNetworkRequest& request, NetworkParams *params, QNetworkReply *&reply, const QString &response);
|
||||
|
||||
static QString map2String(const QMap<QString, QVariant> &map);
|
||||
|
||||
public:
|
||||
QJSValue _interceptor;
|
||||
};
|
||||
|
||||
#endif // Network_H
|
||||
#pragma clang diagnostic pop
|
@ -1,21 +1,22 @@
|
||||
#pragma clang diagnostic push
|
||||
#pragma ide diagnostic ignored "OCUnusedGlobalDeclarationInspection"
|
||||
|
||||
#include "SettingsHelper.h"
|
||||
|
||||
#include <QDataStream>
|
||||
#include <QStandardPaths>
|
||||
|
||||
SettingsHelper::SettingsHelper(QObject *parent) : QObject(parent)
|
||||
{
|
||||
SettingsHelper::SettingsHelper(QObject *parent) : QObject(parent) {
|
||||
|
||||
}
|
||||
|
||||
SettingsHelper::~SettingsHelper() = default;
|
||||
|
||||
void SettingsHelper::save(const QString& key,QVariant val)
|
||||
{
|
||||
void SettingsHelper::save(const QString &key, QVariant val) {
|
||||
m_settings->setValue(key, val);
|
||||
}
|
||||
|
||||
QVariant SettingsHelper::get(const QString& key,QVariant def){
|
||||
QVariant SettingsHelper::get(const QString &key, QVariant def) {
|
||||
QVariant data = m_settings->value(key);
|
||||
if (!data.isNull() && data.isValid()) {
|
||||
return data;
|
||||
@ -23,10 +24,12 @@ QVariant SettingsHelper::get(const QString& key,QVariant def){
|
||||
return def;
|
||||
}
|
||||
|
||||
void SettingsHelper::init(char *argv[]){
|
||||
void SettingsHelper::init(char *argv[]) {
|
||||
QString applicationPath = QString::fromStdString(argv[0]);
|
||||
const QFileInfo fileInfo(applicationPath);
|
||||
const QString iniFileName = fileInfo.completeBaseName() + ".ini";
|
||||
const QString iniFilePath = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + "/" + iniFileName;
|
||||
m_settings.reset(new QSettings(iniFilePath, QSettings::IniFormat));
|
||||
}
|
||||
|
||||
#pragma clang diagnostic pop
|
@ -1,5 +1,6 @@
|
||||
#ifndef SETTINGSHELPER_H
|
||||
#define SETTINGSHELPER_H
|
||||
#pragma clang diagnostic push
|
||||
#pragma ide diagnostic ignored "OCUnusedGlobalDeclarationInspection"
|
||||
#pragma once
|
||||
|
||||
#include <QtCore/qobject.h>
|
||||
#include <QtQml/qqml.h>
|
||||
@ -10,26 +11,36 @@
|
||||
#include <QDir>
|
||||
#include "src/singleton.h"
|
||||
|
||||
class SettingsHelper : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
class SettingsHelper : public QObject {
|
||||
Q_OBJECT
|
||||
private:
|
||||
explicit SettingsHelper(QObject* parent = nullptr);
|
||||
explicit SettingsHelper(QObject *parent = nullptr);
|
||||
|
||||
public:
|
||||
SINGLETON(SettingsHelper)
|
||||
SINGLETON(SettingsHelper)
|
||||
|
||||
~SettingsHelper() override;
|
||||
|
||||
void init(char *argv[]);
|
||||
Q_INVOKABLE void saveDarkMode(int darkModel){save("darkMode",darkModel);}
|
||||
Q_INVOKABLE int getDarkMode(){return get("darkMode",QVariant(0)).toInt();}
|
||||
Q_INVOKABLE void saveUseSystemAppBar(bool useSystemAppBar){save("useSystemAppBar",useSystemAppBar);}
|
||||
Q_INVOKABLE bool getUseSystemAppBar(){return get("useSystemAppBar",QVariant(false)).toBool();}
|
||||
Q_INVOKABLE void saveLanguage(QString language){save("language",language);}
|
||||
Q_INVOKABLE QString getLanguage(){return get("language",QVariant("en_US")).toString();}
|
||||
|
||||
Q_INVOKABLE void saveDarkMode(int darkModel) { save("darkMode", darkModel); }
|
||||
|
||||
Q_INVOKABLE int getDarkMode() { return get("darkMode", QVariant(0)).toInt(); }
|
||||
|
||||
Q_INVOKABLE void saveUseSystemAppBar(bool useSystemAppBar) { save("useSystemAppBar", useSystemAppBar); }
|
||||
|
||||
Q_INVOKABLE bool getUseSystemAppBar() { return get("useSystemAppBar", QVariant(false)).toBool(); }
|
||||
|
||||
Q_INVOKABLE void saveLanguage(const QString &language) { save("language", language); }
|
||||
|
||||
Q_INVOKABLE QString getLanguage() { return get("language", QVariant("en_US")).toString(); }
|
||||
|
||||
private:
|
||||
void save(const QString& key,QVariant val);
|
||||
QVariant get(const QString& key,QVariant def={});
|
||||
void save(const QString &key, QVariant val);
|
||||
|
||||
QVariant get(const QString &key, QVariant def = {});
|
||||
|
||||
private:
|
||||
QScopedPointer<QSettings> m_settings;
|
||||
};
|
||||
|
||||
#endif // SETTINGSHELPER_H
|
||||
#pragma clang diagnostic pop
|
@ -5,21 +5,20 @@
|
||||
|
||||
#include "SettingsHelper.h"
|
||||
|
||||
TranslateHelper::TranslateHelper(QObject *parent) : QObject(parent)
|
||||
{
|
||||
_languages<<"en_US";
|
||||
_languages<<"zh_CN";
|
||||
[[maybe_unused]] TranslateHelper::TranslateHelper(QObject *parent) : QObject(parent) {
|
||||
_languages << "en_US";
|
||||
_languages << "zh_CN";
|
||||
_current = SettingsHelper::getInstance()->getLanguage();
|
||||
}
|
||||
|
||||
TranslateHelper::~TranslateHelper() = default;
|
||||
|
||||
void TranslateHelper::init(QQmlEngine* engine){
|
||||
void TranslateHelper::init(QQmlEngine *engine) {
|
||||
_engine = engine;
|
||||
_translator = new QTranslator(this);
|
||||
qApp->installTranslator(_translator);
|
||||
QString translatorPath = QGuiApplication::applicationDirPath()+"/i18n";
|
||||
if(_translator->load(QString::fromStdString("%1/example_%2.qm").arg(translatorPath,_current))){
|
||||
QGuiApplication::installTranslator(_translator);
|
||||
QString translatorPath = QGuiApplication::applicationDirPath() + "/i18n";
|
||||
if (_translator->load(QString::fromStdString("%1/example_%2.qm").arg(translatorPath, _current))) {
|
||||
_engine->retranslate();
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
#ifndef TRANSLATEHELPER_H
|
||||
#define TRANSLATEHELPER_H
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QtQml/qqml.h>
|
||||
@ -7,20 +6,21 @@
|
||||
#include "src/singleton.h"
|
||||
#include "src/stdafx.h"
|
||||
|
||||
class TranslateHelper : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY_AUTO(QString,current)
|
||||
Q_PROPERTY_READONLY_AUTO(QStringList,languages)
|
||||
class TranslateHelper : public QObject {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY_AUTO(QString, current)
|
||||
Q_PROPERTY_READONLY_AUTO(QStringList, languages)
|
||||
private:
|
||||
explicit TranslateHelper(QObject* parent = nullptr);
|
||||
public:
|
||||
SINGLETON(TranslateHelper)
|
||||
~TranslateHelper() override;
|
||||
void init(QQmlEngine* engine);
|
||||
private:
|
||||
QQmlEngine* _engine = nullptr;
|
||||
QTranslator* _translator = nullptr;
|
||||
};
|
||||
[[maybe_unused]] explicit TranslateHelper(QObject *parent = nullptr);
|
||||
|
||||
#endif // TRANSLATEHELPER_H
|
||||
public:
|
||||
SINGLETON(TranslateHelper)
|
||||
|
||||
~TranslateHelper() override;
|
||||
|
||||
void init(QQmlEngine *engine);
|
||||
|
||||
private:
|
||||
QQmlEngine *_engine = nullptr;
|
||||
QTranslator *_translator = nullptr;
|
||||
};
|
@ -14,6 +14,7 @@
|
||||
#include "src/component/CircularReveal.h"
|
||||
#include "src/component/FileWatcher.h"
|
||||
#include "src/component/FpsItem.h"
|
||||
#include "src/component/OpenGLItem.h"
|
||||
#include "src/helper/SettingsHelper.h"
|
||||
#include "src/helper/InitializrHelper.h"
|
||||
#include "src/helper/TranslateHelper.h"
|
||||
@ -75,6 +76,9 @@ int main(int argc, char *argv[])
|
||||
qmlRegisterType<FpsItem>(uri, major, minor, "FpsItem");
|
||||
qmlRegisterType<NetworkCallable>(uri,major,minor,"NetworkCallable");
|
||||
qmlRegisterType<NetworkParams>(uri,major,minor,"NetworkParams");
|
||||
qmlRegisterType<OpenGLItem>(uri,major,minor,"OpenGLItem");
|
||||
qmlRegisterUncreatableMetaObject(NetworkType::staticMetaObject, uri, major, minor, "NetworkType", "Access to enums & flags only");
|
||||
|
||||
QQmlApplicationEngine engine;
|
||||
TranslateHelper::getInstance()->init(&engine);
|
||||
engine.rootContext()->setContextProperty("AppInfo",AppInfo::getInstance());
|
||||
|
@ -1,18 +1,17 @@
|
||||
#ifndef SINGLETON_H
|
||||
#define SINGLETON_H
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* @brief The Singleton class
|
||||
*/
|
||||
template <typename T>
|
||||
template<typename T>
|
||||
class Singleton {
|
||||
public:
|
||||
static T* getInstance();
|
||||
static T *getInstance();
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
T* Singleton<T>::getInstance() {
|
||||
static T* instance = new T();
|
||||
template<typename T>
|
||||
T *Singleton<T>::getInstance() {
|
||||
static T *instance = new T();
|
||||
return instance;
|
||||
}
|
||||
|
||||
@ -23,5 +22,3 @@ private: \
|
||||
static Class* getInstance() { \
|
||||
return Singleton<Class>::getInstance(); \
|
||||
}
|
||||
|
||||
#endif // SINGLETON_H
|
||||
|
@ -1,37 +1,50 @@
|
||||
#ifndef STDAFX_H
|
||||
#define STDAFX_H
|
||||
#pragma once
|
||||
|
||||
#define Q_PROPERTY_AUTO(TYPE, M) \
|
||||
#define Q_PROPERTY_AUTO_P(TYPE, M) \
|
||||
Q_PROPERTY(TYPE M MEMBER _##M NOTIFY M##Changed) \
|
||||
public: \
|
||||
Q_SIGNAL void M##Changed(); \
|
||||
void M(TYPE in_##M) \
|
||||
public: \
|
||||
Q_SIGNAL void M##Changed(); \
|
||||
void M(TYPE in_##M) \
|
||||
{ \
|
||||
_##M = in_##M; \
|
||||
Q_EMIT M##Changed(); \
|
||||
_##M = in_##M; \
|
||||
Q_EMIT M##Changed(); \
|
||||
} \
|
||||
TYPE M() \
|
||||
TYPE M() \
|
||||
{ \
|
||||
return _##M; \
|
||||
return _##M; \
|
||||
} \
|
||||
private: \
|
||||
TYPE _##M; \
|
||||
private: \
|
||||
TYPE _##M; \
|
||||
|
||||
#define Q_PROPERTY_AUTO(TYPE, M) \
|
||||
Q_PROPERTY(TYPE M MEMBER _##M NOTIFY M##Changed) \
|
||||
public: \
|
||||
Q_SIGNAL void M##Changed(); \
|
||||
void M(const TYPE& in_##M) \
|
||||
{ \
|
||||
_##M = in_##M; \
|
||||
Q_EMIT M##Changed(); \
|
||||
} \
|
||||
TYPE M() \
|
||||
{ \
|
||||
return _##M; \
|
||||
} \
|
||||
private: \
|
||||
TYPE _##M; \
|
||||
|
||||
|
||||
#define Q_PROPERTY_READONLY_AUTO(TYPE, M) \
|
||||
#define Q_PROPERTY_READONLY_AUTO(TYPE, M) \
|
||||
Q_PROPERTY(TYPE M READ M NOTIFY M##Changed FINAL) \
|
||||
public: \
|
||||
Q_SIGNAL void M##Changed(); \
|
||||
void M(TYPE in_##M) \
|
||||
public: \
|
||||
Q_SIGNAL void M##Changed(); \
|
||||
void M(const TYPE& in_##M) \
|
||||
{ \
|
||||
_##M = in_##M; \
|
||||
Q_EMIT M##Changed(); \
|
||||
_##M = in_##M; \
|
||||
Q_EMIT M##Changed(); \
|
||||
} \
|
||||
TYPE M() \
|
||||
TYPE M() \
|
||||
{ \
|
||||
return _##M; \
|
||||
return _##M; \
|
||||
} \
|
||||
private: \
|
||||
TYPE _##M; \
|
||||
|
||||
#endif // STDAFX_H
|
||||
private: \
|
||||
TYPE _##M; \
|
||||
|
@ -2,9 +2,9 @@ cmake_minimum_required(VERSION 3.20)
|
||||
|
||||
if (FLUENTUI_BUILD_STATIC_LIB AND (QT_VERSION VERSION_GREATER_EQUAL "6.2"))
|
||||
project(fluentui VERSION 1.0)
|
||||
else()
|
||||
else ()
|
||||
project(fluentuiplugin VERSION 1.0)
|
||||
endif()
|
||||
endif ()
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/.cmake/)
|
||||
|
||||
@ -17,31 +17,31 @@ add_definitions(-DFLUENTUI_VERSION=1,7,4,0)
|
||||
|
||||
if (FLUENTUI_BUILD_STATIC_LIB)
|
||||
add_definitions(-DFLUENTUI_BUILD_STATIC_LIB)
|
||||
endif()
|
||||
endif ()
|
||||
|
||||
#编译参数设置
|
||||
option(FLUENTUI_BUILD_STATIC_LIB "Build static library." OFF)
|
||||
|
||||
#导入Qt相关依赖包
|
||||
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)
|
||||
|
||||
set(QT_SDK_DIR "${Qt${QT_VERSION_MAJOR}_DIR}/../../..")
|
||||
cmake_path(SET QT_SDK_DIR NORMALIZE ${QT_SDK_DIR})
|
||||
|
||||
#设置QML插件输出目录,可以通过外部设置,如果外部没有设置就默认到<QT_SDK_DIR_PATH>\qml\FluentUI目录下
|
||||
set(FLUENTUI_QML_PLUGIN_DIRECTORY "" CACHE PATH "Path to FluentUI plugin")
|
||||
if(NOT FLUENTUI_QML_PLUGIN_DIRECTORY)
|
||||
if (NOT FLUENTUI_QML_PLUGIN_DIRECTORY)
|
||||
set(FLUENTUI_QML_PLUGIN_DIRECTORY ${QT_SDK_DIR}/qml/FluentUI)
|
||||
endif()
|
||||
endif ()
|
||||
|
||||
if(QT_VERSION VERSION_GREATER_EQUAL "6.3")
|
||||
if (QT_VERSION VERSION_GREATER_EQUAL "6.3")
|
||||
qt_standard_project_setup()
|
||||
else()
|
||||
else ()
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
set(CMAKE_AUTORCC ON)
|
||||
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||
endif()
|
||||
endif ()
|
||||
|
||||
#国际化
|
||||
find_program(QT_LUPDATE NAMES lupdate)
|
||||
@ -59,90 +59,90 @@ file(GLOB QM_FILE_PATHS ${CMAKE_CURRENT_LIST_DIR}/ *.qm)
|
||||
file(COPY ${QM_FILE_PATHS} DESTINATION "${CMAKE_CURRENT_SOURCE_DIR}/Qt${QT_VERSION_MAJOR}/imports/FluentUI/i18n")
|
||||
|
||||
#遍历所有Cpp文件
|
||||
file(GLOB_RECURSE CPP_FILES *.cpp *.h)
|
||||
foreach(filepath ${CPP_FILES})
|
||||
file(GLOB_RECURSE CPP_FILES *.cpp *.h *.cxx)
|
||||
foreach (filepath ${CPP_FILES})
|
||||
string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/" "" filename ${filepath})
|
||||
list(APPEND sources_files ${filename})
|
||||
endforeach(filepath)
|
||||
endforeach (filepath)
|
||||
|
||||
if(QT_VERSION VERSION_GREATER_EQUAL "6.2")
|
||||
if (QT_VERSION VERSION_GREATER_EQUAL "6.2")
|
||||
#删除fluentuiplugin.cpp与fluentuiplugin.h,这些只要Qt5使用,Qt6不需要
|
||||
list(REMOVE_ITEM sources_files fluentuiplugin.h fluentuiplugin.cpp)
|
||||
if (NOT FLUENTUI_BUILD_STATIC_LIB)
|
||||
list(REMOVE_ITEM sources_files FluentUI.h FluentUI.cpp)
|
||||
endif()
|
||||
endif ()
|
||||
|
||||
#遍历所有qml文件
|
||||
file(GLOB_RECURSE QML_PATHS *.qml qmldir)
|
||||
foreach(filepath ${QML_PATHS})
|
||||
if(${filepath} MATCHES "Qt${QT_VERSION_MAJOR}/")
|
||||
foreach (filepath ${QML_PATHS})
|
||||
if (${filepath} MATCHES "Qt${QT_VERSION_MAJOR}/")
|
||||
string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/" "" filename ${filepath})
|
||||
if(${filename} MATCHES "qmldir")
|
||||
if (${filename} MATCHES "qmldir")
|
||||
list(APPEND resource_files ${filename})
|
||||
else()
|
||||
else ()
|
||||
list(APPEND qml_files ${filename})
|
||||
endif()
|
||||
endif()
|
||||
endforeach(filepath)
|
||||
endif ()
|
||||
endif ()
|
||||
endforeach (filepath)
|
||||
|
||||
#遍历所有资源文件
|
||||
file(GLOB_RECURSE RES_PATHS *.png *.jpg *.svg *.ico *.ttf *.webp *.js *.qm)
|
||||
foreach(filepath ${RES_PATHS})
|
||||
if(${filepath} MATCHES "Qt${QT_VERSION_MAJOR}/")
|
||||
foreach (filepath ${RES_PATHS})
|
||||
if (${filepath} MATCHES "Qt${QT_VERSION_MAJOR}/")
|
||||
string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/" "" filename ${filepath})
|
||||
list(APPEND resource_files ${filename})
|
||||
endif()
|
||||
endforeach(filepath)
|
||||
endif ()
|
||||
endforeach (filepath)
|
||||
|
||||
#修改资源文件导出路径
|
||||
foreach(filepath IN LISTS qml_files resource_files)
|
||||
foreach (filepath IN LISTS qml_files resource_files)
|
||||
string(REPLACE "Qt${QT_VERSION_MAJOR}/imports/FluentUI/" "" filename ${filepath})
|
||||
set_source_files_properties(${filepath} PROPERTIES QT_RESOURCE_ALIAS ${filename})
|
||||
endforeach()
|
||||
endif()
|
||||
endforeach ()
|
||||
endif ()
|
||||
|
||||
if (FLUENTUI_BUILD_STATIC_LIB)
|
||||
set(LIB_TYPE "STATIC")
|
||||
else()
|
||||
else ()
|
||||
set(LIB_TYPE "SHARED")
|
||||
endif()
|
||||
endif ()
|
||||
|
||||
if (FLUENTUI_BUILD_STATIC_LIB)
|
||||
set(PLUGIN_TARGET_NAME "")
|
||||
else()
|
||||
else ()
|
||||
#如果是动态库,则使用插件目标作为其自己的支持目标来定义 QML 模块,在这种情况下,模块必须在运行时动态加载,并且不能由其他目标直接链接到
|
||||
set(PLUGIN_TARGET_NAME ${PROJECT_NAME})
|
||||
endif()
|
||||
endif ()
|
||||
|
||||
#如果是Windows平台,则生成rc文件
|
||||
set(FLUENTUI_VERSION_RC_PATH "")
|
||||
if(WIN32)
|
||||
if (WIN32)
|
||||
set(FLUENTUI_VERSION_RC_PATH ${CMAKE_CURRENT_BINARY_DIR}/version_${PROJECT_NAME}.rc)
|
||||
configure_file(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/.cmake/version_dll.rc.in
|
||||
${FLUENTUI_VERSION_RC_PATH}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/.cmake/version_dll.rc.in
|
||||
${FLUENTUI_VERSION_RC_PATH}
|
||||
)
|
||||
endif()
|
||||
endif ()
|
||||
|
||||
if(QT_VERSION VERSION_GREATER_EQUAL "6.2")
|
||||
if (QT_VERSION VERSION_GREATER_EQUAL "6.2")
|
||||
#如果是Qt6.2版本以上,则使用qt_add_library,qt_add_qml_module函数添加资源文件
|
||||
if(FLUENTUI_BUILD_STATIC_LIB)
|
||||
if (FLUENTUI_BUILD_STATIC_LIB)
|
||||
set(FLUENTUI_QML_PLUGIN_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/FluentUI)
|
||||
endif()
|
||||
endif ()
|
||||
qt_add_library(${PROJECT_NAME} ${LIB_TYPE})
|
||||
qt_add_qml_module(${PROJECT_NAME}
|
||||
PLUGIN_TARGET ${PLUGIN_TARGET_NAME}
|
||||
OUTPUT_DIRECTORY ${FLUENTUI_QML_PLUGIN_DIRECTORY}
|
||||
VERSION 1.0
|
||||
URI "FluentUI"
|
||||
#修改qmltypes文件名称。默认fluentuiplugin.qmltypes,使用默认名称有时候import FluentUI 1.0会爆红,所以修改成plugins.qmltypes
|
||||
TYPEINFO "plugins.qmltypes"
|
||||
SOURCES ${sources_files} ${FLUENTUI_VERSION_RC_PATH}
|
||||
QML_FILES ${qml_files}
|
||||
RESOURCES ${resource_files}
|
||||
RESOURCE_PREFIX "/qt/qml"
|
||||
PLUGIN_TARGET ${PLUGIN_TARGET_NAME}
|
||||
OUTPUT_DIRECTORY ${FLUENTUI_QML_PLUGIN_DIRECTORY}
|
||||
VERSION 1.0
|
||||
URI "FluentUI"
|
||||
#修改qmltypes文件名称。默认fluentuiplugin.qmltypes,使用默认名称有时候import FluentUI 1.0会爆红,所以修改成plugins.qmltypes
|
||||
TYPEINFO "plugins.qmltypes"
|
||||
SOURCES ${sources_files} ${FLUENTUI_VERSION_RC_PATH}
|
||||
QML_FILES ${qml_files}
|
||||
RESOURCES ${resource_files}
|
||||
RESOURCE_PREFIX "/qt/qml"
|
||||
)
|
||||
else()
|
||||
else ()
|
||||
#加快qrc编译
|
||||
set(QRC_FILE Qt5/imports/fluentui.qrc)
|
||||
qt_add_big_resources(QRC_RESOURCES ${QRC_FILE})
|
||||
@ -151,37 +151,37 @@ else()
|
||||
#如果是Qt6.2版本以下,则使用add_qmlplugin函数添加资源文件,这是个自定义的函数,详情见.cmake/QmlPlugin.cmake
|
||||
include(QmlPlugin)
|
||||
add_qmlplugin(${PROJECT_NAME}
|
||||
URI "FluentUI"
|
||||
VERSION 1.0
|
||||
SOURCES ${sources_files} ${FLUENTUI_VERSION_RC_PATH} ${QRC_RESOURCES}
|
||||
QMLFILES ${qml_files}
|
||||
QMLDIR imports/FluentUI
|
||||
BINARY_DIR ${FLUENTUI_QML_PLUGIN_DIRECTORY}
|
||||
LIBTYPE ${LIB_TYPE}
|
||||
URI "FluentUI"
|
||||
VERSION 1.0
|
||||
SOURCES ${sources_files} ${FLUENTUI_VERSION_RC_PATH} ${QRC_RESOURCES}
|
||||
QMLFILES ${qml_files}
|
||||
QMLDIR imports/FluentUI
|
||||
BINARY_DIR ${FLUENTUI_QML_PLUGIN_DIRECTORY}
|
||||
LIBTYPE ${LIB_TYPE}
|
||||
)
|
||||
endif()
|
||||
endif ()
|
||||
|
||||
target_compile_definitions(${PROJECT_NAME}
|
||||
PRIVATE
|
||||
#导入qrcode配置文件
|
||||
HAVE_CONFIG_H
|
||||
PRIVATE
|
||||
#导入qrcode配置文件
|
||||
HAVE_CONFIG_H
|
||||
)
|
||||
|
||||
#去掉mingw生成的动态库libxxx前缀lib,不去掉前缀会导致 module "FluentUI" plugin "fluentuiplugin" not found
|
||||
if(MINGW)
|
||||
if (MINGW)
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "")
|
||||
endif()
|
||||
endif ()
|
||||
|
||||
#MSVC Debug 添加后缀d,与Qt插件风格保持一致
|
||||
if(MSVC)
|
||||
if (MSVC)
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES DEBUG_POSTFIX "d")
|
||||
endif()
|
||||
endif ()
|
||||
|
||||
#链接库
|
||||
target_link_libraries(${PROJECT_NAME} PUBLIC
|
||||
Qt${QT_VERSION_MAJOR}::Core
|
||||
Qt${QT_VERSION_MAJOR}::Quick
|
||||
Qt${QT_VERSION_MAJOR}::Qml
|
||||
Qt${QT_VERSION_MAJOR}::Core
|
||||
Qt${QT_VERSION_MAJOR}::Quick
|
||||
Qt${QT_VERSION_MAJOR}::Qml
|
||||
)
|
||||
|
||||
#安装
|
||||
|
@ -1 +0,0 @@
|
||||
#include "Def.h"
|
@ -1,4 +1,5 @@
|
||||
#include "FluAccentColor.h"
|
||||
|
||||
FluAccentColor::FluAccentColor(QObject *parent):QObject{parent}{
|
||||
FluAccentColor::FluAccentColor(QObject *parent) : QObject{parent} {
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
#ifndef FLUACCENTCOLOR_H
|
||||
#define FLUACCENTCOLOR_H
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QtQml/qqml.h>
|
||||
@ -9,19 +8,17 @@
|
||||
/**
|
||||
* @brief The FluAccentColor class
|
||||
*/
|
||||
class FluAccentColor : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY_AUTO(QColor,darkest)
|
||||
Q_PROPERTY_AUTO(QColor,darker)
|
||||
Q_PROPERTY_AUTO(QColor,dark)
|
||||
Q_PROPERTY_AUTO(QColor,normal)
|
||||
Q_PROPERTY_AUTO(QColor,light)
|
||||
Q_PROPERTY_AUTO(QColor,lighter)
|
||||
Q_PROPERTY_AUTO(QColor,lightest)
|
||||
class FluAccentColor : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY_AUTO(QColor, darkest)
|
||||
Q_PROPERTY_AUTO(QColor, darker)
|
||||
Q_PROPERTY_AUTO(QColor, dark)
|
||||
Q_PROPERTY_AUTO(QColor, normal)
|
||||
Q_PROPERTY_AUTO(QColor, light)
|
||||
Q_PROPERTY_AUTO(QColor, lighter)
|
||||
Q_PROPERTY_AUTO(QColor, lightest)
|
||||
QML_NAMED_ELEMENT(FluAccentColor)
|
||||
public:
|
||||
explicit FluAccentColor(QObject *parent = nullptr);
|
||||
};
|
||||
|
||||
#endif // FLUACCENTCOLOR_H
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
#include <QQmlEngine>
|
||||
#include <QGuiApplication>
|
||||
#include <QQmlContext>
|
||||
#include <QQuickItem>
|
||||
#include <QTimer>
|
||||
#include <QUuid>
|
||||
@ -10,22 +9,21 @@
|
||||
#include <QClipboard>
|
||||
#include <QTranslator>
|
||||
|
||||
FluApp::FluApp(QObject *parent):QObject{parent}{
|
||||
useSystemAppBar(false);
|
||||
FluApp::FluApp(QObject *parent) : QObject{parent} {
|
||||
_useSystemAppBar = false;
|
||||
}
|
||||
|
||||
FluApp::~FluApp(){
|
||||
}
|
||||
FluApp::~FluApp() = default;
|
||||
|
||||
void FluApp::init(QObject *target,QLocale locale){
|
||||
void FluApp::init(QObject *target, QLocale locale) {
|
||||
_locale = locale;
|
||||
_engine = qmlEngine(target);
|
||||
_translator = new QTranslator(this);
|
||||
qApp->installTranslator(_translator);
|
||||
const QStringList uiLanguages = _locale.uiLanguages();
|
||||
for (const QString &name : uiLanguages) {
|
||||
for (const QString &name: uiLanguages) {
|
||||
const QString baseName = "fluentui_" + QLocale(name).name();
|
||||
if (_translator->load(":/qt/qml/FluentUI/i18n/"+ baseName)) {
|
||||
if (_translator->load(":/qt/qml/FluentUI/i18n/" + baseName)) {
|
||||
_engine->retranslate();
|
||||
break;
|
||||
}
|
||||
|
39
src/FluApp.h
39
src/FluApp.h
@ -1,5 +1,4 @@
|
||||
#ifndef FLUAPP_H
|
||||
#define FLUAPP_H
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QWindow>
|
||||
@ -15,24 +14,28 @@
|
||||
/**
|
||||
* @brief The FluApp class
|
||||
*/
|
||||
class FluApp : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY_AUTO(bool,useSystemAppBar);
|
||||
Q_PROPERTY_AUTO(QString,windowIcon);
|
||||
Q_PROPERTY_AUTO(QLocale,locale);
|
||||
class FluApp : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY_AUTO(bool, useSystemAppBar)
|
||||
Q_PROPERTY_AUTO(QString, windowIcon)
|
||||
Q_PROPERTY_AUTO(QLocale, locale)
|
||||
QML_NAMED_ELEMENT(FluApp)
|
||||
QML_SINGLETON
|
||||
|
||||
private:
|
||||
explicit FluApp(QObject *parent = nullptr);
|
||||
~FluApp();
|
||||
public:
|
||||
SINGLETON(FluApp)
|
||||
static FluApp *create(QQmlEngine *qmlEngine, QJSEngine *jsEngine){return getInstance();}
|
||||
Q_INVOKABLE void init(QObject *target,QLocale locale = QLocale::system());
|
||||
private:
|
||||
QQmlEngine *_engine;
|
||||
QTranslator* _translator = nullptr;
|
||||
};
|
||||
|
||||
#endif // FLUAPP_H
|
||||
~FluApp() override;
|
||||
|
||||
public:
|
||||
SINGLETON(FluApp)
|
||||
|
||||
static FluApp *create(QQmlEngine *, QJSEngine *) { return getInstance(); }
|
||||
|
||||
Q_INVOKABLE void init(QObject *target, QLocale locale = QLocale::system());
|
||||
|
||||
private:
|
||||
QQmlEngine *_engine{};
|
||||
QTranslator *_translator = nullptr;
|
||||
};
|
@ -3,74 +3,64 @@
|
||||
#include <QChar>
|
||||
#include <QPainter>
|
||||
#include <QRandomGenerator>
|
||||
#include <qmath.h>
|
||||
|
||||
FluCaptcha::FluCaptcha(QQuickItem *parent):QQuickPaintedItem(parent){
|
||||
ignoreCase(true);
|
||||
QFont fontStype;
|
||||
fontStype.setPixelSize(28);
|
||||
fontStype.setBold(true);
|
||||
font(fontStype);
|
||||
int generaNumber(int number) {
|
||||
return QRandomGenerator::global()->bounded(0, number);
|
||||
}
|
||||
|
||||
FluCaptcha::FluCaptcha(QQuickItem *parent) : QQuickPaintedItem(parent) {
|
||||
_ignoreCase = false;
|
||||
QFont fontStyle;
|
||||
fontStyle.setPixelSize(28);
|
||||
fontStyle.setBold(true);
|
||||
font(fontStyle);
|
||||
setWidth(180);
|
||||
setHeight(80);
|
||||
refresh();
|
||||
}
|
||||
|
||||
void FluCaptcha::paint(QPainter* painter){
|
||||
void FluCaptcha::paint(QPainter *painter) {
|
||||
painter->save();
|
||||
painter->fillRect(boundingRect().toRect(),QColor(255,255,255,255));
|
||||
painter->fillRect(boundingRect().toRect(), QColor(255, 255, 255, 255));
|
||||
QPen pen;
|
||||
painter->setFont(_font);
|
||||
for(int i=0;i<100;i++)
|
||||
{
|
||||
pen = QPen(QColor(_generaNumber(256),_generaNumber(256),_generaNumber(256)));
|
||||
for (int i = 0; i < 100; i++) {
|
||||
pen = QPen(QColor(generaNumber(256), generaNumber(256), generaNumber(256)));
|
||||
painter->setPen(pen);
|
||||
painter->drawPoint(_generaNumber(180),_generaNumber(80));
|
||||
painter->drawPoint(generaNumber(180), generaNumber(80));
|
||||
}
|
||||
for(int i=0;i<5;i++)
|
||||
{
|
||||
pen = QPen(QColor(_generaNumber(256),_generaNumber(256),_generaNumber(256)));
|
||||
for (int i = 0; i < 5; i++) {
|
||||
pen = QPen(QColor(generaNumber(256), generaNumber(256), generaNumber(256)));
|
||||
painter->setPen(pen);
|
||||
painter->drawLine(_generaNumber(180),_generaNumber(80),_generaNumber(180),_generaNumber(80));
|
||||
painter->drawLine(generaNumber(180), generaNumber(80), generaNumber(180), generaNumber(80));
|
||||
}
|
||||
for(int i=0;i<4;i++)
|
||||
{
|
||||
pen = QPen(QColor(_generaNumber(255),_generaNumber(255),_generaNumber(255)));
|
||||
for (int i = 0; i < 4; i++) {
|
||||
pen = QPen(QColor(generaNumber(255), generaNumber(255), generaNumber(255)));
|
||||
painter->setPen(pen);
|
||||
painter->drawText(15+35*i,10+_generaNumber(15),30,40,Qt::AlignCenter, QString(_code[i]));
|
||||
painter->drawText(15 + 35 * i, 10 + generaNumber(15), 30, 40, Qt::AlignCenter, QString(_code[i]));
|
||||
}
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
int FluCaptcha::_generaNumber(int number){
|
||||
return QRandomGenerator::global()->bounded(0,number);
|
||||
}
|
||||
|
||||
void FluCaptcha::refresh(){
|
||||
void FluCaptcha::refresh() {
|
||||
this->_code.clear();
|
||||
for(int i = 0;i < 4;++i)
|
||||
{
|
||||
int num = _generaNumber(3);
|
||||
if(num == 0)
|
||||
{
|
||||
this->_code += QString::number(_generaNumber(10));
|
||||
}
|
||||
else if(num == 1)
|
||||
{
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
int num = generaNumber(3);
|
||||
if (num == 0) {
|
||||
this->_code += QString::number(generaNumber(10));
|
||||
} else if (num == 1) {
|
||||
int temp = 'A';
|
||||
this->_code += static_cast<QChar>(temp + _generaNumber(26));
|
||||
}
|
||||
else if(num == 2)
|
||||
{
|
||||
this->_code += static_cast<QChar>(temp + generaNumber(26));
|
||||
} else if (num == 2) {
|
||||
int temp = 'a';
|
||||
this->_code += static_cast<QChar>(temp + _generaNumber(26));
|
||||
this->_code += static_cast<QChar>(temp + generaNumber(26));
|
||||
}
|
||||
}
|
||||
update();
|
||||
}
|
||||
|
||||
bool FluCaptcha::verify(const QString& code){
|
||||
if(_ignoreCase){
|
||||
[[maybe_unused]] bool FluCaptcha::verify(const QString &code) {
|
||||
if (_ignoreCase) {
|
||||
return this->_code.toUpper() == code.toUpper();
|
||||
}
|
||||
return this->_code == code;
|
||||
|
@ -1,5 +1,4 @@
|
||||
#ifndef FLUCAPTCHA_H
|
||||
#define FLUCAPTCHA_H
|
||||
#pragma once
|
||||
|
||||
#include <QQuickItem>
|
||||
#include <QQuickPaintedItem>
|
||||
@ -9,21 +8,22 @@
|
||||
/**
|
||||
* @brief The FluCaptcha class
|
||||
*/
|
||||
class FluCaptcha : public QQuickPaintedItem
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY_AUTO(QFont,font);
|
||||
Q_PROPERTY_AUTO(bool,ignoreCase);
|
||||
class FluCaptcha : public QQuickPaintedItem {
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY_AUTO(QFont, font);
|
||||
Q_PROPERTY_AUTO(bool, ignoreCase);
|
||||
QML_NAMED_ELEMENT(FluCaptcha)
|
||||
private:
|
||||
int _generaNumber(int number);
|
||||
|
||||
public:
|
||||
explicit FluCaptcha(QQuickItem *parent = nullptr);
|
||||
void paint(QPainter* painter) override;
|
||||
|
||||
void paint(QPainter *painter) override;
|
||||
|
||||
Q_INVOKABLE void refresh();
|
||||
Q_INVOKABLE bool verify(const QString& code);
|
||||
|
||||
Q_INVOKABLE [[maybe_unused]] bool verify(const QString &code);
|
||||
|
||||
private:
|
||||
QString _code;
|
||||
};
|
||||
|
||||
#endif // FLUCAPTCHA_H
|
||||
|
@ -1,35 +1,34 @@
|
||||
#include "FluColors.h"
|
||||
#include "FluTools.h"
|
||||
|
||||
FluColors::FluColors(QObject *parent):QObject{parent}{
|
||||
Transparent(QColor(0, 0, 0, 0));
|
||||
Black(QColor(0, 0, 0));
|
||||
White(QColor(255, 255, 255));
|
||||
Grey10(QColor(250, 249, 248));
|
||||
Grey20(QColor(243, 242, 241));
|
||||
Grey30(QColor(237, 235, 233));
|
||||
Grey40(QColor(225, 223, 221));
|
||||
Grey50(QColor(210, 208, 206));
|
||||
Grey60(QColor(200, 198, 196));
|
||||
Grey70(QColor(190, 185, 184));
|
||||
Grey80(QColor(179, 176, 173));
|
||||
Grey90(QColor(161, 159, 157));
|
||||
Grey100(QColor(151, 149, 146));
|
||||
Grey110(QColor(138, 136, 134));
|
||||
Grey120(QColor(121, 119, 117));
|
||||
Grey130(QColor(96, 94, 92));
|
||||
Grey140(QColor(72, 70, 68));
|
||||
Grey150(QColor(59, 58, 57));
|
||||
Grey160(QColor(50, 49, 48));
|
||||
Grey170(QColor(41, 40, 39));
|
||||
Grey180(QColor(37, 36, 35));
|
||||
Grey190(QColor(32, 31, 30));
|
||||
Grey200(QColor(27, 26, 25));
|
||||
Grey210(QColor(22, 21, 20));
|
||||
Grey220(QColor(17, 16, 15));
|
||||
FluColors::FluColors(QObject *parent) : QObject{parent} {
|
||||
_Transparent = QColor(0, 0, 0, 0);
|
||||
_Black = QColor(0, 0, 0);
|
||||
_White = QColor(255, 255, 255);
|
||||
_Grey10 = QColor(250, 249, 248);
|
||||
_Grey20 = QColor(243, 242, 241);
|
||||
_Grey30 = QColor(237, 235, 233);
|
||||
_Grey40 = QColor(225, 223, 221);
|
||||
_Grey50 = QColor(210, 208, 206);
|
||||
_Grey60 = QColor(200, 198, 196);
|
||||
_Grey70 = QColor(190, 185, 184);
|
||||
_Grey80 = QColor(179, 176, 173);
|
||||
_Grey90 = QColor(161, 159, 157);
|
||||
_Grey100 = QColor(151, 149, 146);
|
||||
_Grey110 = QColor(138, 136, 134);
|
||||
_Grey120 = QColor(121, 119, 117);
|
||||
_Grey130 = QColor(96, 94, 92);
|
||||
_Grey140 = QColor(72, 70, 68);
|
||||
_Grey150 = QColor(59, 58, 57);
|
||||
_Grey160 = QColor(50, 49, 48);
|
||||
_Grey170 = QColor(41, 40, 39);
|
||||
_Grey180 = QColor(37, 36, 35);
|
||||
_Grey190 = QColor(32, 31, 30);
|
||||
_Grey200 = QColor(27, 26, 25);
|
||||
_Grey210 = QColor(22, 21, 20);
|
||||
_Grey220 = QColor(17, 16, 15);
|
||||
|
||||
|
||||
FluAccentColor *yellow = new FluAccentColor(this);
|
||||
auto yellow = new FluAccentColor(this);
|
||||
yellow->darkest(QColor(249, 168, 37));
|
||||
yellow->darker(QColor(251, 192, 45));
|
||||
yellow->dark(QColor(253, 212, 53));
|
||||
@ -37,9 +36,9 @@ FluColors::FluColors(QObject *parent):QObject{parent}{
|
||||
yellow->light(QColor(255, 238, 88));
|
||||
yellow->lighter(QColor(255, 241, 118));
|
||||
yellow->lightest(QColor(255, 245, 155));
|
||||
Yellow(yellow);
|
||||
_Yellow = yellow;
|
||||
|
||||
FluAccentColor *orange = new FluAccentColor(this);
|
||||
auto orange = new FluAccentColor(this);
|
||||
orange->darkest(QColor(153, 61, 7));
|
||||
orange->darker(QColor(172, 68, 8));
|
||||
orange->dark(QColor(209, 88, 10));
|
||||
@ -47,9 +46,9 @@ FluColors::FluColors(QObject *parent):QObject{parent}{
|
||||
orange->light(QColor(248, 122, 48));
|
||||
orange->lighter(QColor(249, 145, 84));
|
||||
orange->lightest(QColor(250, 192, 106));
|
||||
Orange(orange);
|
||||
_Orange = orange;
|
||||
|
||||
FluAccentColor *red = new FluAccentColor(this);
|
||||
auto red = new FluAccentColor(this);
|
||||
red->darkest(QColor(143, 10, 21));
|
||||
red->darker(QColor(162, 11, 24));
|
||||
red->dark(QColor(185, 13, 28));
|
||||
@ -57,9 +56,9 @@ FluColors::FluColors(QObject *parent):QObject{parent}{
|
||||
red->light(QColor(236, 64, 79));
|
||||
red->lighter(QColor(238, 88, 101));
|
||||
red->lightest(QColor(240, 107, 118));
|
||||
Red(red);
|
||||
_Red = red;
|
||||
|
||||
FluAccentColor *magenta = new FluAccentColor(this);
|
||||
auto magenta = new FluAccentColor(this);
|
||||
magenta->darkest(QColor(111, 0, 79));
|
||||
magenta->darker(QColor(160, 7, 108));
|
||||
magenta->dark(QColor(181, 13, 125));
|
||||
@ -67,9 +66,9 @@ FluColors::FluColors(QObject *parent):QObject{parent}{
|
||||
magenta->light(QColor(234, 77, 168));
|
||||
magenta->lighter(QColor(238, 110, 193));
|
||||
magenta->lightest(QColor(241, 140, 213));
|
||||
Magenta(magenta);
|
||||
_Magenta = magenta;
|
||||
|
||||
FluAccentColor *purple = new FluAccentColor(this);
|
||||
auto purple = new FluAccentColor(this);
|
||||
purple->darkest(QColor(44, 15, 118));
|
||||
purple->darker(QColor(61, 15, 153));
|
||||
purple->dark(QColor(78, 17, 174));
|
||||
@ -77,9 +76,9 @@ FluColors::FluColors(QObject *parent):QObject{parent}{
|
||||
purple->light(QColor(123, 76, 157));
|
||||
purple->lighter(QColor(141, 110, 189));
|
||||
purple->lightest(QColor(158, 142, 217));
|
||||
Purple(purple);
|
||||
_Purple = purple;
|
||||
|
||||
FluAccentColor *blue = new FluAccentColor(this);
|
||||
auto blue = new FluAccentColor(this);
|
||||
blue->darkest(QColor(0, 74, 131));
|
||||
blue->darker(QColor(0, 84, 148));
|
||||
blue->dark(QColor(0, 102, 180));
|
||||
@ -87,9 +86,9 @@ FluColors::FluColors(QObject *parent):QObject{parent}{
|
||||
blue->light(QColor(38, 140, 220));
|
||||
blue->lighter(QColor(76, 160, 224));
|
||||
blue->lightest(QColor(96, 171, 228));
|
||||
Blue(blue);
|
||||
_Blue = blue;
|
||||
|
||||
FluAccentColor *teal = new FluAccentColor(this);
|
||||
auto teal = new FluAccentColor(this);
|
||||
teal->darkest(QColor(0, 110, 91));
|
||||
teal->darker(QColor(0, 124, 103));
|
||||
teal->dark(QColor(0, 151, 125));
|
||||
@ -97,9 +96,9 @@ FluColors::FluColors(QObject *parent):QObject{parent}{
|
||||
teal->light(QColor(38, 189, 164));
|
||||
teal->lighter(QColor(77, 201, 180));
|
||||
teal->lightest(QColor(96, 207, 188));
|
||||
Teal(teal);
|
||||
_Teal = teal;
|
||||
|
||||
FluAccentColor *green = new FluAccentColor(this);
|
||||
auto green = new FluAccentColor(this);
|
||||
green->darkest(QColor(9, 76, 9));
|
||||
green->darker(QColor(12, 93, 12));
|
||||
green->dark(QColor(14, 111, 14));
|
||||
@ -107,17 +106,17 @@ FluColors::FluColors(QObject *parent):QObject{parent}{
|
||||
green->light(QColor(39, 137, 57));
|
||||
green->lighter(QColor(76, 156, 76));
|
||||
green->lightest(QColor(106, 173, 106));
|
||||
Green(green);
|
||||
_Green = green;
|
||||
}
|
||||
|
||||
FluAccentColor* FluColors::createAccentColor(QColor primaryColor){
|
||||
FluAccentColor *accentColor = new FluAccentColor(this);
|
||||
accentColor->darkest(FluTools::getInstance()->withOpacity(primaryColor,0.7));
|
||||
accentColor->darker(FluTools::getInstance()->withOpacity(primaryColor,0.8));
|
||||
accentColor->dark(FluTools::getInstance()->withOpacity(primaryColor,0.9));
|
||||
[[maybe_unused]] FluAccentColor *FluColors::createAccentColor(QColor primaryColor) {
|
||||
auto accentColor = new FluAccentColor(this);
|
||||
accentColor->darkest(FluTools::getInstance()->withOpacity(primaryColor, 0.7));
|
||||
accentColor->darker(FluTools::getInstance()->withOpacity(primaryColor, 0.8));
|
||||
accentColor->dark(FluTools::getInstance()->withOpacity(primaryColor, 0.9));
|
||||
accentColor->normal(primaryColor);
|
||||
accentColor->light(FluTools::getInstance()->withOpacity(primaryColor,0.9));
|
||||
accentColor->lighter(FluTools::getInstance()->withOpacity(primaryColor,0.8));
|
||||
accentColor->lightest(FluTools::getInstance()->withOpacity(primaryColor,0.7));
|
||||
accentColor->light(FluTools::getInstance()->withOpacity(primaryColor, 0.9));
|
||||
accentColor->lighter(FluTools::getInstance()->withOpacity(primaryColor, 0.8));
|
||||
accentColor->lightest(FluTools::getInstance()->withOpacity(primaryColor, 0.7));
|
||||
return accentColor;
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
#ifndef FLUCOLORS_H
|
||||
#define FLUCOLORS_H
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QtQml/qqml.h>
|
||||
@ -11,50 +10,52 @@
|
||||
/**
|
||||
* @brief The FluColors class
|
||||
*/
|
||||
class FluColors : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY_AUTO(QColor,Transparent);
|
||||
Q_PROPERTY_AUTO(QColor,Black);
|
||||
Q_PROPERTY_AUTO(QColor,White);
|
||||
Q_PROPERTY_AUTO(QColor,Grey10);
|
||||
Q_PROPERTY_AUTO(QColor,Grey20);
|
||||
Q_PROPERTY_AUTO(QColor,Grey30);
|
||||
Q_PROPERTY_AUTO(QColor,Grey40);
|
||||
Q_PROPERTY_AUTO(QColor,Grey50);
|
||||
Q_PROPERTY_AUTO(QColor,Grey60);
|
||||
Q_PROPERTY_AUTO(QColor,Grey70);
|
||||
Q_PROPERTY_AUTO(QColor,Grey80);
|
||||
Q_PROPERTY_AUTO(QColor,Grey90);
|
||||
Q_PROPERTY_AUTO(QColor,Grey100);
|
||||
Q_PROPERTY_AUTO(QColor,Grey110);
|
||||
Q_PROPERTY_AUTO(QColor,Grey120);
|
||||
Q_PROPERTY_AUTO(QColor,Grey130);
|
||||
Q_PROPERTY_AUTO(QColor,Grey140);
|
||||
Q_PROPERTY_AUTO(QColor,Grey150);
|
||||
Q_PROPERTY_AUTO(QColor,Grey160);
|
||||
Q_PROPERTY_AUTO(QColor,Grey170);
|
||||
Q_PROPERTY_AUTO(QColor,Grey180);
|
||||
Q_PROPERTY_AUTO(QColor,Grey190);
|
||||
Q_PROPERTY_AUTO(QColor,Grey200);
|
||||
Q_PROPERTY_AUTO(QColor,Grey210);
|
||||
Q_PROPERTY_AUTO(QColor,Grey220);
|
||||
Q_PROPERTY_AUTO(FluAccentColor*,Yellow);
|
||||
Q_PROPERTY_AUTO(FluAccentColor*,Orange);
|
||||
Q_PROPERTY_AUTO(FluAccentColor*,Red);
|
||||
Q_PROPERTY_AUTO(FluAccentColor*,Magenta);
|
||||
Q_PROPERTY_AUTO(FluAccentColor*,Purple);
|
||||
Q_PROPERTY_AUTO(FluAccentColor*,Blue);
|
||||
Q_PROPERTY_AUTO(FluAccentColor*,Teal);
|
||||
Q_PROPERTY_AUTO(FluAccentColor*,Green);
|
||||
class FluColors : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY_AUTO(QColor, Transparent);
|
||||
Q_PROPERTY_AUTO(QColor, Black);
|
||||
Q_PROPERTY_AUTO(QColor, White);
|
||||
Q_PROPERTY_AUTO(QColor, Grey10);
|
||||
Q_PROPERTY_AUTO(QColor, Grey20);
|
||||
Q_PROPERTY_AUTO(QColor, Grey30);
|
||||
Q_PROPERTY_AUTO(QColor, Grey40);
|
||||
Q_PROPERTY_AUTO(QColor, Grey50);
|
||||
Q_PROPERTY_AUTO(QColor, Grey60);
|
||||
Q_PROPERTY_AUTO(QColor, Grey70);
|
||||
Q_PROPERTY_AUTO(QColor, Grey80);
|
||||
Q_PROPERTY_AUTO(QColor, Grey90);
|
||||
Q_PROPERTY_AUTO(QColor, Grey100);
|
||||
Q_PROPERTY_AUTO(QColor, Grey110);
|
||||
Q_PROPERTY_AUTO(QColor, Grey120);
|
||||
Q_PROPERTY_AUTO(QColor, Grey130);
|
||||
Q_PROPERTY_AUTO(QColor, Grey140);
|
||||
Q_PROPERTY_AUTO(QColor, Grey150);
|
||||
Q_PROPERTY_AUTO(QColor, Grey160);
|
||||
Q_PROPERTY_AUTO(QColor, Grey170);
|
||||
Q_PROPERTY_AUTO(QColor, Grey180);
|
||||
Q_PROPERTY_AUTO(QColor, Grey190);
|
||||
Q_PROPERTY_AUTO(QColor, Grey200);
|
||||
Q_PROPERTY_AUTO(QColor, Grey210);
|
||||
Q_PROPERTY_AUTO(QColor, Grey220);
|
||||
Q_PROPERTY_AUTO_P(FluAccentColor*, Yellow);
|
||||
Q_PROPERTY_AUTO_P(FluAccentColor*, Orange);
|
||||
Q_PROPERTY_AUTO_P(FluAccentColor*, Red);
|
||||
Q_PROPERTY_AUTO_P(FluAccentColor*, Magenta);
|
||||
Q_PROPERTY_AUTO_P(FluAccentColor*, Purple);
|
||||
Q_PROPERTY_AUTO_P(FluAccentColor*, Blue);
|
||||
Q_PROPERTY_AUTO_P(FluAccentColor*, Teal);
|
||||
Q_PROPERTY_AUTO_P(FluAccentColor*, Green);
|
||||
QML_NAMED_ELEMENT(FluColors)
|
||||
QML_SINGLETON
|
||||
|
||||
private:
|
||||
explicit FluColors(QObject *parent = nullptr);
|
||||
public:
|
||||
SINGLETON(FluColors)
|
||||
Q_INVOKABLE FluAccentColor* createAccentColor(QColor primaryColor);
|
||||
static FluColors *create(QQmlEngine *qmlEngine, QJSEngine *jsEngine){return getInstance();}
|
||||
};
|
||||
|
||||
#endif // FLUCOLORS_H
|
||||
public:
|
||||
SINGLETON(FluColors)
|
||||
|
||||
Q_INVOKABLE [[maybe_unused]] FluAccentColor *createAccentColor(QColor primaryColor);
|
||||
|
||||
static FluColors *create(QQmlEngine *, QJSEngine *) { return getInstance(); }
|
||||
};
|
@ -6,130 +6,140 @@
|
||||
#include <QDateTime>
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
#pragma comment (lib,"user32.lib")
|
||||
#pragma comment (lib,"dwmapi.lib")
|
||||
#pragma comment (lib, "user32.lib")
|
||||
#pragma comment (lib, "dwmapi.lib")
|
||||
|
||||
#include <windows.h>
|
||||
#include <windowsx.h>
|
||||
#include <dwmapi.h>
|
||||
static inline QByteArray qtNativeEventType()
|
||||
{
|
||||
|
||||
static inline QByteArray qtNativeEventType() {
|
||||
static const auto result = "windows_generic_MSG";
|
||||
return result;
|
||||
}
|
||||
static inline bool isCompositionEnabled(){
|
||||
typedef HRESULT (WINAPI* DwmIsCompositionEnabledPtr)(BOOL *pfEnabled);
|
||||
|
||||
static inline bool isCompositionEnabled() {
|
||||
typedef HRESULT (WINAPI *DwmIsCompositionEnabledPtr)(BOOL *pfEnabled);
|
||||
HMODULE module = ::LoadLibraryW(L"dwmapi.dll");
|
||||
if (module)
|
||||
{
|
||||
if (module) {
|
||||
BOOL composition_enabled = false;
|
||||
DwmIsCompositionEnabledPtr dwm_is_composition_enabled;
|
||||
dwm_is_composition_enabled= reinterpret_cast<DwmIsCompositionEnabledPtr>(::GetProcAddress(module, "DwmIsCompositionEnabled"));
|
||||
if (dwm_is_composition_enabled)
|
||||
{
|
||||
dwm_is_composition_enabled = reinterpret_cast<DwmIsCompositionEnabledPtr>(::GetProcAddress(module, "DwmIsCompositionEnabled"));
|
||||
if (dwm_is_composition_enabled) {
|
||||
dwm_is_composition_enabled(&composition_enabled);
|
||||
}
|
||||
return composition_enabled;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
FluFrameless::FluFrameless(QQuickItem *parent)
|
||||
: QQuickItem{parent}
|
||||
{
|
||||
appbar(nullptr);
|
||||
maximizeButton(nullptr);
|
||||
minimizedButton(nullptr);
|
||||
closeButton(nullptr);
|
||||
topmost(false);
|
||||
disabled(false);
|
||||
bool containsCursorToItem(QQuickItem *item) {
|
||||
if (!item || !item->isVisible()) {
|
||||
return false;
|
||||
}
|
||||
auto point = QCursor::pos();
|
||||
auto rect = QRectF(item->mapToGlobal(QPoint(0, 0)), item->size());
|
||||
if (point.x() > rect.x() && point.x() < (rect.x() + rect.width()) && point.y() > rect.y() && point.y() < (rect.y() + rect.height())) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
FluFrameless::~FluFrameless(){
|
||||
FluFrameless::FluFrameless(QQuickItem *parent) : QQuickItem{parent} {
|
||||
_fixSize = false;
|
||||
_appbar = nullptr;
|
||||
_maximizeButton = nullptr;
|
||||
_minimizedButton = nullptr;
|
||||
_closeButton = nullptr;
|
||||
_topmost = false;
|
||||
_disabled = false;
|
||||
}
|
||||
|
||||
void FluFrameless::onDestruction(){
|
||||
qApp->removeNativeEventFilter(this);
|
||||
FluFrameless::~FluFrameless() = default;
|
||||
|
||||
[[maybe_unused]] void FluFrameless::onDestruction() {
|
||||
QGuiApplication::instance()->removeNativeEventFilter(this);
|
||||
}
|
||||
|
||||
void FluFrameless::componentComplete(){
|
||||
if(_disabled){
|
||||
void FluFrameless::componentComplete() {
|
||||
if (_disabled) {
|
||||
return;
|
||||
}
|
||||
_current = window()->winId();
|
||||
window()->setFlags(( window()->flags()) | Qt::CustomizeWindowHint | Qt::WindowMinimizeButtonHint | Qt::WindowCloseButtonHint | Qt::FramelessWindowHint);
|
||||
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
|
||||
if(QQuickWindow::sceneGraphBackend() == "software"){
|
||||
window()->setFlag(Qt::FramelessWindowHint,false);
|
||||
window()->setFlags((window()->flags()) | Qt::CustomizeWindowHint | Qt::WindowMinimizeButtonHint | Qt::WindowCloseButtonHint | Qt::FramelessWindowHint);
|
||||
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
||||
if (QQuickWindow::sceneGraphBackend() == "software") {
|
||||
window()->setFlag(Qt::FramelessWindowHint, false);
|
||||
}
|
||||
#endif
|
||||
if(!_fixSize){
|
||||
if (!_fixSize) {
|
||||
window()->setFlag(Qt::WindowMaximizeButtonHint);
|
||||
}
|
||||
window()->installEventFilter(this);
|
||||
qApp->installNativeEventFilter(this);
|
||||
if(_maximizeButton){
|
||||
QGuiApplication::instance()->installNativeEventFilter(this);
|
||||
if (_maximizeButton) {
|
||||
setHitTestVisible(_maximizeButton);
|
||||
}
|
||||
if(_minimizedButton){
|
||||
if (_minimizedButton) {
|
||||
setHitTestVisible(_minimizedButton);
|
||||
}
|
||||
if(_closeButton){
|
||||
if (_closeButton) {
|
||||
setHitTestVisible(_closeButton);
|
||||
}
|
||||
#ifdef Q_OS_WIN
|
||||
HWND hwnd = reinterpret_cast<HWND>(window()->winId());
|
||||
DWORD style = ::GetWindowLongPtr(hwnd, GWL_STYLE);
|
||||
if(_fixSize){
|
||||
if (_fixSize) {
|
||||
::SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_THICKFRAME);
|
||||
for (int i = 0; i < qApp->screens().count(); ++i) {
|
||||
connect( qApp->screens().at(i),&QScreen::logicalDotsPerInchChanged,this,[=]{
|
||||
SetWindowPos(hwnd,nullptr,0,0,0,0,SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_FRAMECHANGED);
|
||||
for (int i = 0; i <= QGuiApplication::screens().count() - 1; ++i) {
|
||||
connect(QGuiApplication::screens().at(i), &QScreen::logicalDotsPerInchChanged, this, [=] {
|
||||
SetWindowPos(hwnd, nullptr, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_FRAMECHANGED);
|
||||
});
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
::SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_MAXIMIZEBOX | WS_THICKFRAME);
|
||||
}
|
||||
SetWindowPos(hwnd,nullptr,0,0,0,0,SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED);
|
||||
connect(window(),&QQuickWindow::screenChanged,this,[hwnd]{
|
||||
::SetWindowPos(hwnd,0,0,0,0,0,SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED | SWP_NOOWNERZORDER);
|
||||
::RedrawWindow(hwnd, NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
|
||||
SetWindowPos(hwnd, nullptr, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED);
|
||||
connect(window(), &QQuickWindow::screenChanged, this, [hwnd] {
|
||||
::SetWindowPos(hwnd, nullptr, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED | SWP_NOOWNERZORDER);
|
||||
::RedrawWindow(hwnd, nullptr, nullptr, RDW_INVALIDATE | RDW_UPDATENOW);
|
||||
});
|
||||
#endif
|
||||
connect(this,&FluFrameless::topmostChanged,this,[this]{
|
||||
connect(this, &FluFrameless::topmostChanged, this, [this] {
|
||||
_setWindowTopmost(topmost());
|
||||
});
|
||||
_setWindowTopmost(topmost());
|
||||
}
|
||||
|
||||
bool FluFrameless::nativeEventFilter(const QByteArray &eventType, void *message, QT_NATIVE_EVENT_RESULT_TYPE *result){
|
||||
[[maybe_unused]] bool FluFrameless::nativeEventFilter(const QByteArray &eventType, void *message, QT_NATIVE_EVENT_RESULT_TYPE *result) {
|
||||
#ifdef Q_OS_WIN
|
||||
if ((eventType != qtNativeEventType()) || !message) {
|
||||
return false;
|
||||
}
|
||||
const auto msg = static_cast<const MSG *>(message);
|
||||
const HWND hwnd = msg->hwnd;
|
||||
if (!hwnd || !msg) {
|
||||
auto hwnd = msg->hwnd;
|
||||
if (!hwnd) {
|
||||
return false;
|
||||
}
|
||||
const qint64 wid = reinterpret_cast<qint64>(hwnd);
|
||||
if(wid != _current){
|
||||
const quint64 wid = reinterpret_cast<qint64>(hwnd);
|
||||
if (wid != _current) {
|
||||
return false;
|
||||
}
|
||||
const UINT uMsg = msg->message;
|
||||
const WPARAM wParam = msg->wParam;
|
||||
const LPARAM lParam = msg->lParam;
|
||||
const auto uMsg = msg->message;
|
||||
const auto wParam = msg->wParam;
|
||||
const auto lParam = msg->lParam;
|
||||
static QPoint offsetXY;
|
||||
if(uMsg == WM_WINDOWPOSCHANGING){
|
||||
WINDOWPOS* wp = reinterpret_cast<WINDOWPOS*>(lParam);
|
||||
if (wp != nullptr && (wp->flags & SWP_NOSIZE) == 0)
|
||||
{
|
||||
if (uMsg == WM_WINDOWPOSCHANGING) {
|
||||
auto *wp = reinterpret_cast<WINDOWPOS *>(lParam);
|
||||
if (wp != nullptr && (wp->flags & SWP_NOSIZE) == 0) {
|
||||
wp->flags |= SWP_NOCOPYBITS;
|
||||
*result = ::DefWindowProcW(hwnd, uMsg, wParam, lParam);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}else if(uMsg == WM_NCCALCSIZE){
|
||||
} else if (uMsg == WM_NCCALCSIZE) {
|
||||
const auto clientRect = ((wParam == FALSE) ? reinterpret_cast<LPRECT>(lParam) : &(reinterpret_cast<LPNCCALCSIZE_PARAMS>(lParam))->rgrc[0]);
|
||||
const LONG originalTop = clientRect->top;
|
||||
const LONG originalLeft = clientRect->left;
|
||||
@ -140,28 +150,35 @@ bool FluFrameless::nativeEventFilter(const QByteArray &eventType, void *message,
|
||||
*result = hitTestResult;
|
||||
return true;
|
||||
}
|
||||
int offsetSize = 0;
|
||||
int offsetSize;
|
||||
bool isMaximum = ::IsZoomed(hwnd);
|
||||
offsetXY = QPoint(abs(clientRect->left - originalLeft),abs(clientRect->top - originalTop));
|
||||
if(isMaximum || _isFullScreen()){
|
||||
offsetXY = QPoint(abs(clientRect->left - originalLeft), abs(clientRect->top - originalTop));
|
||||
if (isMaximum || _isFullScreen()) {
|
||||
offsetSize = 0;
|
||||
}else{
|
||||
} else {
|
||||
offsetSize = 1;
|
||||
}
|
||||
if(!isCompositionEnabled()){
|
||||
if (!isCompositionEnabled()) {
|
||||
offsetSize = 0;
|
||||
}
|
||||
if (!isMaximum || QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) {
|
||||
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
||||
if (!isMaximum) {
|
||||
clientRect->top = originalTop + offsetSize;
|
||||
clientRect->bottom = originalBottom - offsetSize;
|
||||
clientRect->left = originalLeft + offsetSize;
|
||||
clientRect->right = originalRight - offsetSize;
|
||||
}
|
||||
#else
|
||||
clientRect->top = originalTop + offsetSize;
|
||||
clientRect->bottom = originalBottom - offsetSize;
|
||||
clientRect->left = originalLeft + offsetSize;
|
||||
clientRect->right = originalRight - offsetSize;
|
||||
#endif
|
||||
_setMaximizeHovered(false);
|
||||
*result = WVR_REDRAW;
|
||||
return true;
|
||||
}else if(uMsg == WM_NCHITTEST){
|
||||
if(_hitMaximizeButton()){
|
||||
} else if (uMsg == WM_NCHITTEST) {
|
||||
if (_hitMaximizeButton()) {
|
||||
if (*result == HTNOWHERE) {
|
||||
*result = HTZOOM;
|
||||
}
|
||||
@ -176,8 +193,8 @@ bool FluFrameless::nativeEventFilter(const QByteArray &eventType, void *message,
|
||||
::ScreenToClient(hwnd, &nativeLocalPos);
|
||||
RECT clientRect{0, 0, 0, 0};
|
||||
::GetClientRect(hwnd, &clientRect);
|
||||
auto clientWidth = clientRect.right-clientRect.left;
|
||||
auto clientHeight = clientRect.bottom-clientRect.top;
|
||||
auto clientWidth = clientRect.right - clientRect.left;
|
||||
auto clientHeight = clientRect.bottom - clientRect.top;
|
||||
bool left = nativeLocalPos.x < _margins;
|
||||
bool right = nativeLocalPos.x > clientWidth - _margins;
|
||||
bool top = nativeLocalPos.y < _margins;
|
||||
@ -205,59 +222,59 @@ bool FluFrameless::nativeEventFilter(const QByteArray &eventType, void *message,
|
||||
if (0 != *result) {
|
||||
return true;
|
||||
}
|
||||
if(_hitAppBar()){
|
||||
if (_hitAppBar()) {
|
||||
*result = HTCAPTION;
|
||||
return true;
|
||||
}
|
||||
*result = HTCLIENT;
|
||||
return true;
|
||||
}else if(uMsg == WM_NCLBUTTONDBLCLK || uMsg == WM_NCLBUTTONDOWN){
|
||||
if(_hitMaximizeButton()){
|
||||
} else if (uMsg == WM_NCLBUTTONDBLCLK || uMsg == WM_NCLBUTTONDOWN) {
|
||||
if (_hitMaximizeButton()) {
|
||||
QMouseEvent event = QMouseEvent(QEvent::MouseButtonPress, QPoint(), QPoint(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
|
||||
QGuiApplication::sendEvent(_maximizeButton,&event);
|
||||
QGuiApplication::sendEvent(_maximizeButton, &event);
|
||||
_setMaximizePressed(true);
|
||||
return true;
|
||||
}
|
||||
}else if(uMsg == WM_NCLBUTTONUP || uMsg == WM_NCRBUTTONUP){
|
||||
if(_hitMaximizeButton()){
|
||||
} else if (uMsg == WM_NCLBUTTONUP || uMsg == WM_NCRBUTTONUP) {
|
||||
if (_hitMaximizeButton()) {
|
||||
QMouseEvent event = QMouseEvent(QEvent::MouseButtonRelease, QPoint(), QPoint(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
|
||||
QGuiApplication::sendEvent(_maximizeButton,&event);
|
||||
QGuiApplication::sendEvent(_maximizeButton, &event);
|
||||
_setMaximizePressed(false);
|
||||
return true;
|
||||
}
|
||||
}else if(uMsg == WM_NCPAINT){
|
||||
} else if (uMsg == WM_NCPAINT) {
|
||||
*result = FALSE;
|
||||
return true;
|
||||
}else if(uMsg == WM_NCACTIVATE){
|
||||
} else if (uMsg == WM_NCACTIVATE) {
|
||||
*result = ::DefWindowProcW(hwnd, WM_NCACTIVATE, wParam, -1);
|
||||
return true;
|
||||
}else if(uMsg == WM_GETMINMAXINFO){
|
||||
MINMAXINFO* minmaxInfo = reinterpret_cast<MINMAXINFO *>(lParam);
|
||||
} else if (uMsg == WM_GETMINMAXINFO) {
|
||||
auto *minmaxInfo = reinterpret_cast<MINMAXINFO *>(lParam);
|
||||
auto pixelRatio = window()->devicePixelRatio();
|
||||
auto geometry = window()->screen()->availableGeometry();
|
||||
RECT rect;
|
||||
SystemParametersInfo(SPI_GETWORKAREA, 0, &rect, 0);
|
||||
minmaxInfo->ptMaxPosition.x = rect.left - offsetXY.x();
|
||||
minmaxInfo->ptMaxPosition.y = rect.top - offsetXY.x();
|
||||
minmaxInfo->ptMaxSize.x = geometry.width()*pixelRatio + offsetXY.x() * 2;
|
||||
minmaxInfo->ptMaxSize.y = geometry.height()*pixelRatio + offsetXY.y() * 2;
|
||||
minmaxInfo->ptMaxSize.x = qRound(geometry.width() * pixelRatio) + offsetXY.x() * 2;
|
||||
minmaxInfo->ptMaxSize.y = qRound(geometry.height() * pixelRatio) + offsetXY.y() * 2;
|
||||
return false;
|
||||
}else if(uMsg == WM_NCRBUTTONDOWN){
|
||||
} else if (uMsg == WM_NCRBUTTONDOWN) {
|
||||
if (wParam == HTCAPTION) {
|
||||
_showSystemMenu(QCursor::pos());
|
||||
}
|
||||
}else if(uMsg == WM_KEYDOWN || uMsg == WM_SYSKEYDOWN){
|
||||
} else if (uMsg == WM_KEYDOWN || uMsg == WM_SYSKEYDOWN) {
|
||||
const bool altPressed = ((wParam == VK_MENU) || (::GetKeyState(VK_MENU) < 0));
|
||||
const bool spacePressed = ((wParam == VK_SPACE) || (::GetKeyState(VK_SPACE) < 0));
|
||||
if (altPressed && spacePressed) {
|
||||
auto pos = window()->position();
|
||||
_showSystemMenu(QPoint(pos.x(),pos.y()+_appbar->height()));
|
||||
_showSystemMenu(QPoint(pos.x(), qRound(pos.y() + _appbar->height())));
|
||||
}
|
||||
}else if(uMsg == WM_SYSCOMMAND){
|
||||
if(wParam == SC_MINIMIZE){
|
||||
if(window()->transientParent()){
|
||||
} else if (uMsg == WM_SYSCOMMAND) {
|
||||
if (wParam == SC_MINIMIZE) {
|
||||
if (window()->transientParent()) {
|
||||
window()->transientParent()->showMinimized();
|
||||
}else{
|
||||
} else {
|
||||
window()->showMinimized();
|
||||
}
|
||||
return true;
|
||||
@ -265,143 +282,136 @@ bool FluFrameless::nativeEventFilter(const QByteArray &eventType, void *message,
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
#endif
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool FluFrameless::_isMaximized(){
|
||||
bool FluFrameless::_isMaximized() {
|
||||
return window()->visibility() == QWindow::Maximized;
|
||||
}
|
||||
|
||||
bool FluFrameless::_isFullScreen(){
|
||||
bool FluFrameless::_isFullScreen() {
|
||||
return window()->visibility() == QWindow::FullScreen;
|
||||
}
|
||||
|
||||
void FluFrameless::_showSystemMenu(QPoint point){
|
||||
void FluFrameless::_showSystemMenu(QPoint point) {
|
||||
#ifdef Q_OS_WIN
|
||||
HWND hwnd = reinterpret_cast<HWND>(window()->winId());
|
||||
DWORD style = ::GetWindowLongPtr(hwnd,GWL_STYLE);
|
||||
DWORD style = ::GetWindowLongPtr(hwnd, GWL_STYLE);
|
||||
::SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_SYSMENU);
|
||||
const HMENU hMenu = ::GetSystemMenu(hwnd, FALSE);
|
||||
if(_isMaximized() || _isFullScreen()){
|
||||
::EnableMenuItem(hMenu,SC_MOVE,MFS_DISABLED);
|
||||
::EnableMenuItem(hMenu,SC_RESTORE,MFS_ENABLED);
|
||||
}else{
|
||||
::EnableMenuItem(hMenu,SC_MOVE,MFS_ENABLED);
|
||||
::EnableMenuItem(hMenu,SC_RESTORE,MFS_DISABLED);
|
||||
auto hMenu = ::GetSystemMenu(hwnd, FALSE);
|
||||
if (_isMaximized() || _isFullScreen()) {
|
||||
::EnableMenuItem(hMenu, SC_MOVE, MFS_DISABLED);
|
||||
::EnableMenuItem(hMenu, SC_RESTORE, MFS_ENABLED);
|
||||
} else {
|
||||
::EnableMenuItem(hMenu, SC_MOVE, MFS_ENABLED);
|
||||
::EnableMenuItem(hMenu, SC_RESTORE, MFS_DISABLED);
|
||||
}
|
||||
if(!_fixSize && !_isMaximized() && !_isFullScreen()){
|
||||
::EnableMenuItem(hMenu,SC_SIZE,MFS_ENABLED);
|
||||
::EnableMenuItem(hMenu,SC_MAXIMIZE,MFS_ENABLED);
|
||||
}else{
|
||||
::EnableMenuItem(hMenu,SC_SIZE,MFS_DISABLED);
|
||||
::EnableMenuItem(hMenu,SC_MAXIMIZE,MFS_DISABLED);
|
||||
if (!_fixSize && !_isMaximized() && !_isFullScreen()) {
|
||||
::EnableMenuItem(hMenu, SC_SIZE, MFS_ENABLED);
|
||||
::EnableMenuItem(hMenu, SC_MAXIMIZE, MFS_ENABLED);
|
||||
} else {
|
||||
::EnableMenuItem(hMenu, SC_SIZE, MFS_DISABLED);
|
||||
::EnableMenuItem(hMenu, SC_MAXIMIZE, MFS_DISABLED);
|
||||
}
|
||||
const int result = ::TrackPopupMenu(hMenu, (TPM_RETURNCMD | (QGuiApplication::isRightToLeft() ? TPM_RIGHTALIGN : TPM_LEFTALIGN)), point.x()*window()->devicePixelRatio(), point.y()*window()->devicePixelRatio(), 0, hwnd, nullptr);
|
||||
const int result = ::TrackPopupMenu(hMenu, (TPM_RETURNCMD | (QGuiApplication::isRightToLeft() ? TPM_RIGHTALIGN : TPM_LEFTALIGN)), qRound(point.x() * window()->devicePixelRatio()),
|
||||
qRound(point.y() * window()->devicePixelRatio()), 0, hwnd, nullptr);
|
||||
if (result != FALSE) {
|
||||
::PostMessageW(hwnd, WM_SYSCOMMAND, result, 0);
|
||||
}
|
||||
::SetWindowLongPtr(hwnd, GWL_STYLE, style &~ WS_SYSMENU);
|
||||
::SetWindowLongPtr(hwnd, GWL_STYLE, style & ~WS_SYSMENU);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool FluFrameless::_containsCursorToItem(QQuickItem* item){
|
||||
if(!item || !item->isVisible()){
|
||||
return false;
|
||||
}
|
||||
auto point = QCursor::pos();
|
||||
auto rect = QRectF(item->mapToGlobal(QPoint(0,0)),item->size());
|
||||
if(point.x()>rect.x() && point.x()<(rect.x()+rect.width()) && point.y()>rect.y() && point.y()<(rect.y()+rect.height())){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool FluFrameless::_hitAppBar(){
|
||||
foreach (auto item, _hitTestList) {
|
||||
if(_containsCursorToItem(item)){
|
||||
bool FluFrameless::_hitAppBar() {
|
||||
for (int i = 0; i <= _hitTestList.size() - 1; ++i) {
|
||||
auto item = _hitTestList.at(i);
|
||||
if (containsCursorToItem(item)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if(_containsCursorToItem(_appbar)){
|
||||
if (containsCursorToItem(_appbar)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool FluFrameless::_hitMaximizeButton(){
|
||||
if(_containsCursorToItem(_maximizeButton)){
|
||||
bool FluFrameless::_hitMaximizeButton() {
|
||||
if (containsCursorToItem(_maximizeButton)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void FluFrameless::_setMaximizePressed(bool val){
|
||||
_maximizeButton->setProperty("down",val);
|
||||
void FluFrameless::_setMaximizePressed(bool val) {
|
||||
_maximizeButton->setProperty("down", val);
|
||||
}
|
||||
|
||||
void FluFrameless::_setMaximizeHovered(bool val){
|
||||
_maximizeButton->setProperty("hover",val);
|
||||
void FluFrameless::_setMaximizeHovered(bool val) {
|
||||
_maximizeButton->setProperty("hover", val);
|
||||
}
|
||||
|
||||
void FluFrameless::_updateCursor(int edges){
|
||||
void FluFrameless::_updateCursor(int edges) {
|
||||
switch (edges) {
|
||||
case 0:
|
||||
window()->setCursor(Qt::ArrowCursor);
|
||||
break;
|
||||
case Qt::LeftEdge:
|
||||
case Qt::RightEdge:
|
||||
window()->setCursor(Qt::SizeHorCursor);
|
||||
break;
|
||||
case Qt::TopEdge:
|
||||
case Qt::BottomEdge:
|
||||
window()->setCursor(Qt::SizeVerCursor);
|
||||
break;
|
||||
case Qt::LeftEdge | Qt::TopEdge:
|
||||
case Qt::RightEdge | Qt::BottomEdge:
|
||||
window()->setCursor(Qt::SizeFDiagCursor);
|
||||
break;
|
||||
case Qt::RightEdge | Qt::TopEdge:
|
||||
case Qt::LeftEdge | Qt::BottomEdge:
|
||||
window()->setCursor(Qt::SizeBDiagCursor);
|
||||
break;
|
||||
case 0:
|
||||
window()->setCursor(Qt::ArrowCursor);
|
||||
break;
|
||||
case Qt::LeftEdge:
|
||||
case Qt::RightEdge:
|
||||
window()->setCursor(Qt::SizeHorCursor);
|
||||
break;
|
||||
case Qt::TopEdge:
|
||||
case Qt::BottomEdge:
|
||||
window()->setCursor(Qt::SizeVerCursor);
|
||||
break;
|
||||
case Qt::LeftEdge | Qt::TopEdge:
|
||||
case Qt::RightEdge | Qt::BottomEdge:
|
||||
window()->setCursor(Qt::SizeFDiagCursor);
|
||||
break;
|
||||
case Qt::RightEdge | Qt::TopEdge:
|
||||
case Qt::LeftEdge | Qt::BottomEdge:
|
||||
window()->setCursor(Qt::SizeBDiagCursor);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void FluFrameless::showFullScreen(){
|
||||
[[maybe_unused]] void FluFrameless::showFullScreen() {
|
||||
window()->showFullScreen();
|
||||
}
|
||||
|
||||
void FluFrameless::showMaximized(){
|
||||
void FluFrameless::showMaximized() {
|
||||
#ifdef Q_OS_WIN
|
||||
HWND hwnd = reinterpret_cast<HWND>(window()->winId());
|
||||
::ShowWindow(hwnd,3);
|
||||
::ShowWindow(hwnd, 3);
|
||||
#else
|
||||
window()->showMaximized();
|
||||
#endif
|
||||
}
|
||||
|
||||
void FluFrameless::showMinimized(){
|
||||
[[maybe_unused]] void FluFrameless::showMinimized() {
|
||||
window()->showMinimized();
|
||||
}
|
||||
|
||||
void FluFrameless::showNormal(){
|
||||
void FluFrameless::showNormal() {
|
||||
window()->showNormal();
|
||||
}
|
||||
|
||||
void FluFrameless::setHitTestVisible(QQuickItem* val){
|
||||
if(!_hitTestList.contains(val)){
|
||||
void FluFrameless::setHitTestVisible(QQuickItem *val) {
|
||||
if (!_hitTestList.contains(val)) {
|
||||
_hitTestList.append(val);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void FluFrameless::_setWindowTopmost(bool topmost){
|
||||
void FluFrameless::_setWindowTopmost(bool topmost) {
|
||||
#ifdef Q_OS_WIN
|
||||
HWND hwnd = reinterpret_cast<HWND>(window()->winId());
|
||||
if(topmost){
|
||||
if (topmost) {
|
||||
::SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
|
||||
}else{
|
||||
} else {
|
||||
::SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
|
||||
}
|
||||
#else
|
||||
@ -409,7 +419,7 @@ void FluFrameless::_setWindowTopmost(bool topmost){
|
||||
#endif
|
||||
}
|
||||
|
||||
bool FluFrameless::eventFilter(QObject *obj, QEvent *ev){
|
||||
bool FluFrameless::eventFilter(QObject *obj, QEvent *ev) {
|
||||
#ifndef Q_OS_WIN
|
||||
switch (ev->type()) {
|
||||
case QEvent::MouseButtonPress:
|
||||
|
@ -1,5 +1,4 @@
|
||||
#ifndef FLUFRAMELESS_H
|
||||
#define FLUFRAMELESS_H
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QQuickItem>
|
||||
@ -15,47 +14,63 @@ using QT_ENTER_EVENT_TYPE = QEvent;
|
||||
#endif
|
||||
|
||||
|
||||
class FluFrameless : public QQuickItem,QAbstractNativeEventFilter
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY_AUTO(QQuickItem*,appbar)
|
||||
Q_PROPERTY_AUTO(bool,topmost)
|
||||
Q_PROPERTY_AUTO(QQuickItem*,maximizeButton)
|
||||
Q_PROPERTY_AUTO(QQuickItem*,minimizedButton)
|
||||
Q_PROPERTY_AUTO(QQuickItem*,closeButton)
|
||||
Q_PROPERTY_AUTO(bool,disabled)
|
||||
Q_PROPERTY_AUTO(bool,fixSize)
|
||||
class FluFrameless : public QQuickItem, QAbstractNativeEventFilter {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY_AUTO_P(QQuickItem*, appbar)
|
||||
Q_PROPERTY_AUTO_P(QQuickItem*, maximizeButton)
|
||||
Q_PROPERTY_AUTO_P(QQuickItem*, minimizedButton)
|
||||
Q_PROPERTY_AUTO_P(QQuickItem*, closeButton)
|
||||
Q_PROPERTY_AUTO(bool, topmost)
|
||||
Q_PROPERTY_AUTO(bool, disabled)
|
||||
Q_PROPERTY_AUTO(bool, fixSize)
|
||||
QML_NAMED_ELEMENT(FluFrameless)
|
||||
public:
|
||||
explicit FluFrameless(QQuickItem* parent = nullptr);
|
||||
~FluFrameless();
|
||||
explicit FluFrameless(QQuickItem *parent = nullptr);
|
||||
|
||||
~FluFrameless() override;
|
||||
|
||||
void componentComplete() override;
|
||||
bool nativeEventFilter(const QByteArray &eventType, void *message, QT_NATIVE_EVENT_RESULT_TYPE *result) override;
|
||||
Q_INVOKABLE void showFullScreen();
|
||||
|
||||
[[maybe_unused]] bool nativeEventFilter(const QByteArray &eventType, void *message, QT_NATIVE_EVENT_RESULT_TYPE *result) override;
|
||||
|
||||
Q_INVOKABLE [[maybe_unused]] void showFullScreen();
|
||||
|
||||
Q_INVOKABLE void showMaximized();
|
||||
Q_INVOKABLE void showMinimized();
|
||||
|
||||
Q_INVOKABLE [[maybe_unused]] void showMinimized();
|
||||
|
||||
Q_INVOKABLE void showNormal();
|
||||
Q_INVOKABLE void setHitTestVisible(QQuickItem*);
|
||||
Q_INVOKABLE void onDestruction();
|
||||
|
||||
Q_INVOKABLE void setHitTestVisible(QQuickItem *);
|
||||
|
||||
Q_INVOKABLE [[maybe_unused]] void onDestruction();
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *obj, QEvent *event) override;
|
||||
|
||||
private:
|
||||
bool _isFullScreen();
|
||||
|
||||
bool _isMaximized();
|
||||
|
||||
void _updateCursor(int edges);
|
||||
|
||||
void _setWindowTopmost(bool topmost);
|
||||
|
||||
void _showSystemMenu(QPoint point);
|
||||
bool _containsCursorToItem(QQuickItem* item);
|
||||
|
||||
bool _hitAppBar();
|
||||
|
||||
bool _hitMaximizeButton();
|
||||
|
||||
void _setMaximizePressed(bool val);
|
||||
|
||||
void _setMaximizeHovered(bool val);
|
||||
|
||||
private:
|
||||
qint64 _current;
|
||||
quint64 _current = 0;
|
||||
int _edges = 0;
|
||||
int _margins = 8;
|
||||
qint64 _clickTimer = 0;
|
||||
quint64 _clickTimer = 0;
|
||||
QList<QPointer<QQuickItem>> _hitTestList;
|
||||
};
|
||||
|
||||
#endif // FLUFRAMELESS_H
|
||||
};
|
@ -2,51 +2,47 @@
|
||||
|
||||
#include "qrcode/qrencode.h"
|
||||
|
||||
FluQrCodeItem::FluQrCodeItem(QQuickItem* parent):QQuickPaintedItem(parent){
|
||||
color(QColor(0,0,0,255));
|
||||
bgColor(QColor(255,255,255,255));
|
||||
size(100);
|
||||
FluQrCodeItem::FluQrCodeItem(QQuickItem *parent) : QQuickPaintedItem(parent) {
|
||||
_color = QColor(0, 0, 0, 255);
|
||||
_bgColor = QColor(255, 255, 255, 255);
|
||||
_size = 100;
|
||||
setWidth(_size);
|
||||
setHeight(_size);
|
||||
connect(this,&FluQrCodeItem::textChanged,this,[=]{update();});
|
||||
connect(this,&FluQrCodeItem::colorChanged,this,[=]{update();});
|
||||
connect(this,&FluQrCodeItem::bgColorChanged,this,[=]{update();});
|
||||
connect(this,&FluQrCodeItem::sizeChanged,this,[=]{
|
||||
connect(this, &FluQrCodeItem::textChanged, this, [=] { update(); });
|
||||
connect(this, &FluQrCodeItem::colorChanged, this, [=] { update(); });
|
||||
connect(this, &FluQrCodeItem::bgColorChanged, this, [=] { update(); });
|
||||
connect(this, &FluQrCodeItem::sizeChanged, this, [=] {
|
||||
setWidth(_size);
|
||||
setHeight(_size);
|
||||
update();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
void FluQrCodeItem::paint(QPainter* painter){
|
||||
if(_text.isEmpty()){
|
||||
void FluQrCodeItem::paint(QPainter *painter) {
|
||||
if (_text.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
if(_text.length()>1024){
|
||||
if (_text.length() > 1024) {
|
||||
return;
|
||||
}
|
||||
painter->save();
|
||||
QRcode *qrcode = QRcode_encodeString(_text.toUtf8().constData(), 2, QR_ECLEVEL_Q, QR_MODE_8, 1);
|
||||
qint32 w = width();
|
||||
qint32 h = height();
|
||||
auto w = qint32(width());
|
||||
auto h = qint32(height());
|
||||
qint32 qrcodeW = qrcode->width > 0 ? qrcode->width : 1;
|
||||
double scaleX = (double)w / (double)qrcodeW;
|
||||
double scaleY = (double)h / (double)qrcodeW;
|
||||
double scaleX = (double) w / (double) qrcodeW;
|
||||
double scaleY = (double) h / (double) qrcodeW;
|
||||
QImage image = QImage(w, h, QImage::Format_ARGB32);
|
||||
QPainter p(&image);
|
||||
p.setBrush(_bgColor);
|
||||
p.setPen(Qt::NoPen);
|
||||
p.drawRect(0, 0, w, h);
|
||||
p.setBrush(_color);
|
||||
for (qint32 y = 0; y < qrcodeW; y++)
|
||||
{
|
||||
for (qint32 x = 0; x < qrcodeW; x++)
|
||||
{
|
||||
unsigned char b = qrcode->data[y*qrcodeW + x];
|
||||
if (b & 0x01)
|
||||
{
|
||||
QRectF r(x * scaleX,y * scaleY, scaleX, scaleY);
|
||||
for (qint32 y = 0; y < qrcodeW; y++) {
|
||||
for (qint32 x = 0; x < qrcodeW; x++) {
|
||||
unsigned char b = qrcode->data[y * qrcodeW + x];
|
||||
if (b & 0x01) {
|
||||
QRectF r(x * scaleX, y * scaleY, scaleX, scaleY);
|
||||
p.drawRects(&r, 1);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
#ifndef FLUQRCODEITEM_H
|
||||
#define FLUQRCODEITEM_H
|
||||
#pragma once
|
||||
|
||||
#include <QQuickItem>
|
||||
#include <QQuickPaintedItem>
|
||||
@ -9,17 +8,16 @@
|
||||
/**
|
||||
* @brief The FluQrCodeItem class
|
||||
*/
|
||||
class FluQrCodeItem : public QQuickPaintedItem
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY_AUTO(QString,text)
|
||||
Q_PROPERTY_AUTO(QColor,color)
|
||||
Q_PROPERTY_AUTO(QColor,bgColor)
|
||||
Q_PROPERTY_AUTO(int,size);
|
||||
class FluQrCodeItem : public QQuickPaintedItem {
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY_AUTO(QString, text)
|
||||
Q_PROPERTY_AUTO(QColor, color)
|
||||
Q_PROPERTY_AUTO(QColor, bgColor)
|
||||
Q_PROPERTY_AUTO(int, size);
|
||||
QML_NAMED_ELEMENT(FluQrCodeItem)
|
||||
public:
|
||||
explicit FluQrCodeItem(QQuickItem *parent = nullptr);
|
||||
void paint(QPainter* painter) override;
|
||||
};
|
||||
|
||||
#endif // FLUQRCODEITEM_H
|
||||
void paint(QPainter *painter) override;
|
||||
};
|
@ -1,14 +1,14 @@
|
||||
#include "FluRectangle.h"
|
||||
#include <QPainterPath>
|
||||
|
||||
FluRectangle::FluRectangle(QQuickItem* parent) : QQuickPaintedItem(parent){
|
||||
color(QColor(255,255,255,255));
|
||||
radius({0,0,0,0});
|
||||
connect(this,&FluRectangle::colorChanged,this,[=]{update();});
|
||||
connect(this,&FluRectangle::radiusChanged,this,[=]{update();});
|
||||
FluRectangle::FluRectangle(QQuickItem *parent) : QQuickPaintedItem(parent) {
|
||||
color(QColor(255, 255, 255, 255));
|
||||
radius({0, 0, 0, 0});
|
||||
connect(this, &FluRectangle::colorChanged, this, [=] { update(); });
|
||||
connect(this, &FluRectangle::radiusChanged, this, [=] { update(); });
|
||||
}
|
||||
|
||||
void FluRectangle::paint(QPainter* painter){
|
||||
void FluRectangle::paint(QPainter *painter) {
|
||||
painter->save();
|
||||
painter->setRenderHint(QPainter::Antialiasing);
|
||||
QPainterPath path;
|
||||
@ -22,6 +22,6 @@ void FluRectangle::paint(QPainter* painter){
|
||||
path.arcTo(QRectF(QPointF(rect.bottomLeft() - QPointF(0, _radius[3] * 2)), QSize(_radius[3] * 2, _radius[3] * 2)), 180, 90);
|
||||
path.lineTo(rect.bottomRight() - QPointF(_radius[2], 0));
|
||||
path.arcTo(QRectF(QPointF(rect.bottomRight() - QPointF(_radius[2] * 2, _radius[2] * 2)), QSize(_radius[2] * 2, _radius[2] * 2)), 270, 90);
|
||||
painter->fillPath(path,_color);
|
||||
painter->fillPath(path, _color);
|
||||
painter->restore();
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
#ifndef FLURECTANGLE_H
|
||||
#define FLURECTANGLE_H
|
||||
#pragma once
|
||||
|
||||
#include <QQuickItem>
|
||||
#include <QQuickPaintedItem>
|
||||
@ -9,15 +8,13 @@
|
||||
/**
|
||||
* @brief The FluRectangle class
|
||||
*/
|
||||
class FluRectangle : public QQuickPaintedItem
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY_AUTO(QColor,color)
|
||||
Q_PROPERTY_AUTO(QList<int>,radius)
|
||||
class FluRectangle : public QQuickPaintedItem {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY_AUTO(QColor, color)
|
||||
Q_PROPERTY_AUTO(QList<int>, radius)
|
||||
QML_NAMED_ELEMENT(FluRectangle)
|
||||
public:
|
||||
explicit FluRectangle(QQuickItem *parent = nullptr);
|
||||
void paint(QPainter* painter) override;
|
||||
};
|
||||
|
||||
#endif // FLURECTANGLE_H
|
||||
void paint(QPainter *painter) override;
|
||||
};
|
@ -2,74 +2,72 @@
|
||||
|
||||
#include <QJSValueList>
|
||||
|
||||
FluTableSortProxyModel::FluTableSortProxyModel(QSortFilterProxyModel *parent)
|
||||
: QSortFilterProxyModel {parent}
|
||||
{
|
||||
FluTableSortProxyModel::FluTableSortProxyModel(QSortFilterProxyModel *parent) : QSortFilterProxyModel{parent} {
|
||||
_model = nullptr;
|
||||
connect(this,&FluTableSortProxyModel::modelChanged,this,[=]{
|
||||
connect(this, &FluTableSortProxyModel::modelChanged, this, [=] {
|
||||
setSourceModel(this->model());
|
||||
});
|
||||
}
|
||||
|
||||
bool FluTableSortProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const{
|
||||
bool FluTableSortProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const {
|
||||
QJSValue filter = _filter;
|
||||
if(filter.isUndefined()){
|
||||
if (filter.isUndefined()) {
|
||||
return true;
|
||||
}
|
||||
QJSValueList data;
|
||||
data<<source_row;
|
||||
data << source_row;
|
||||
return filter.call(data).toBool();
|
||||
}
|
||||
|
||||
bool FluTableSortProxyModel::filterAcceptsColumn(int source_column, const QModelIndex &source_parent) const{
|
||||
bool FluTableSortProxyModel::filterAcceptsColumn(int source_column, const QModelIndex &source_parent) const {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FluTableSortProxyModel::lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const{
|
||||
bool FluTableSortProxyModel::lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const {
|
||||
QJSValue comparator = _comparator;
|
||||
if(comparator.isUndefined()){
|
||||
if (comparator.isUndefined()) {
|
||||
return true;
|
||||
}
|
||||
QJSValueList data;
|
||||
data<<source_left.row();
|
||||
data<<source_right.row();
|
||||
data << source_left.row();
|
||||
data << source_right.row();
|
||||
bool flag = comparator.call(data).toBool();
|
||||
if(sortOrder()==Qt::AscendingOrder){
|
||||
if (sortOrder() == Qt::AscendingOrder) {
|
||||
return !flag;
|
||||
}else{
|
||||
} else {
|
||||
return flag;
|
||||
}
|
||||
}
|
||||
|
||||
void FluTableSortProxyModel::setComparator(QJSValue comparator){
|
||||
[[maybe_unused]] void FluTableSortProxyModel::setComparator(const QJSValue &comparator) {
|
||||
int column = 0;
|
||||
if(comparator.isUndefined()){
|
||||
if (comparator.isUndefined()) {
|
||||
column = -1;
|
||||
}
|
||||
this->_comparator = comparator;
|
||||
if(sortOrder()==Qt::AscendingOrder){
|
||||
sort(column,Qt::DescendingOrder);
|
||||
}else{
|
||||
sort(column,Qt::AscendingOrder);
|
||||
if (sortOrder() == Qt::AscendingOrder) {
|
||||
sort(column, Qt::DescendingOrder);
|
||||
} else {
|
||||
sort(column, Qt::AscendingOrder);
|
||||
}
|
||||
}
|
||||
|
||||
void FluTableSortProxyModel::setFilter(QJSValue filter){
|
||||
[[maybe_unused]] void FluTableSortProxyModel::setFilter(const QJSValue &filter) {
|
||||
this->_filter = filter;
|
||||
invalidateFilter();
|
||||
}
|
||||
|
||||
QVariant FluTableSortProxyModel::getRow(int rowIndex){
|
||||
[[maybe_unused]] QVariant FluTableSortProxyModel::getRow(int rowIndex) {
|
||||
QVariant result;
|
||||
QMetaObject::invokeMethod(_model, "getRow",Q_RETURN_ARG(QVariant, result),Q_ARG(int, mapToSource(index(rowIndex,0)).row()));
|
||||
QMetaObject::invokeMethod(_model, "getRow", Q_RETURN_ARG(QVariant, result), Q_ARG(int, mapToSource(index(rowIndex, 0)).row()));
|
||||
return result;
|
||||
}
|
||||
|
||||
void FluTableSortProxyModel::setRow(int rowIndex,QVariant val){
|
||||
QMetaObject::invokeMethod(_model, "setRow",Q_ARG(int, mapToSource(index(rowIndex,0)).row()),Q_ARG(QVariant,val));
|
||||
[[maybe_unused]] void FluTableSortProxyModel::setRow(int rowIndex, const QVariant &val) {
|
||||
QMetaObject::invokeMethod(_model, "setRow", Q_ARG(int, mapToSource(index(rowIndex, 0)).row()), Q_ARG(QVariant, val));
|
||||
}
|
||||
|
||||
void FluTableSortProxyModel::removeRow(int rowIndex,int rows){
|
||||
QMetaObject::invokeMethod(_model, "removeRow",Q_ARG(int, mapToSource(index(rowIndex,0)).row()),Q_ARG(int,rows));
|
||||
[[maybe_unused]] void FluTableSortProxyModel::removeRow(int rowIndex, int rows) {
|
||||
QMetaObject::invokeMethod(_model, "removeRow", Q_ARG(int, mapToSource(index(rowIndex, 0)).row()), Q_ARG(int, rows));
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
#ifndef FLUTABLESORTPROXYMODEL_H
|
||||
#define FLUTABLESORTPROXYMODEL_H
|
||||
#pragma once
|
||||
|
||||
#include <QSortFilterProxyModel>
|
||||
#include <QAbstractTableModel>
|
||||
@ -7,24 +6,30 @@
|
||||
#include <QJSValue>
|
||||
#include "stdafx.h"
|
||||
|
||||
class FluTableSortProxyModel : public QSortFilterProxyModel
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY_AUTO(QAbstractTableModel*,model)
|
||||
class FluTableSortProxyModel : public QSortFilterProxyModel {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY_AUTO_P(QAbstractTableModel*, model)
|
||||
QML_NAMED_ELEMENT(FluTableSortProxyModel)
|
||||
public:
|
||||
explicit FluTableSortProxyModel(QSortFilterProxyModel *parent = nullptr);
|
||||
|
||||
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
|
||||
|
||||
bool filterAcceptsColumn(int sourceColumn, const QModelIndex &sourceParent) const override;
|
||||
|
||||
bool lessThan(const QModelIndex &sourceLeft, const QModelIndex &sourceRight) const override;
|
||||
Q_INVOKABLE QVariant getRow(int rowIndex);
|
||||
Q_INVOKABLE void setRow(int rowIndex,QVariant val);
|
||||
Q_INVOKABLE void removeRow(int rowIndex,int rows);
|
||||
Q_INVOKABLE void setComparator(QJSValue comparator);
|
||||
Q_INVOKABLE void setFilter(QJSValue filter);
|
||||
|
||||
Q_INVOKABLE [[maybe_unused]] QVariant getRow(int rowIndex);
|
||||
|
||||
Q_INVOKABLE [[maybe_unused]] void setRow(int rowIndex, const QVariant &val);
|
||||
|
||||
Q_INVOKABLE [[maybe_unused]] void removeRow(int rowIndex, int rows);
|
||||
|
||||
Q_INVOKABLE [[maybe_unused]] [[maybe_unused]] void setComparator(const QJSValue &comparator);
|
||||
|
||||
Q_INVOKABLE [[maybe_unused]] void setFilter(const QJSValue &filter);
|
||||
|
||||
private:
|
||||
QJSValue _filter;
|
||||
QJSValue _comparator;
|
||||
};
|
||||
|
||||
#endif // FLUTABLESORTPROXYMODEL_H
|
||||
};
|
@ -1,6 +1,6 @@
|
||||
#include "FluTextStyle.h"
|
||||
|
||||
FluTextStyle::FluTextStyle(QObject *parent):QObject{parent}{
|
||||
FluTextStyle::FluTextStyle(QObject *parent) : QObject{parent} {
|
||||
_family = QFont().defaultFamily();
|
||||
#ifdef Q_OS_WIN
|
||||
_family = "微软雅黑";
|
||||
|
@ -1,5 +1,4 @@
|
||||
#ifndef FLUTEXTSTYLE_H
|
||||
#define FLUTEXTSTYLE_H
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QtQml/qqml.h>
|
||||
@ -10,25 +9,25 @@
|
||||
/**
|
||||
* @brief The FluTextStyle class
|
||||
*/
|
||||
class FluTextStyle : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
class FluTextStyle : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Q_PROPERTY_AUTO(QString,family)
|
||||
Q_PROPERTY_AUTO(QFont,Caption);
|
||||
Q_PROPERTY_AUTO(QFont,Body);
|
||||
Q_PROPERTY_AUTO(QFont,BodyStrong);
|
||||
Q_PROPERTY_AUTO(QFont,Subtitle);
|
||||
Q_PROPERTY_AUTO(QFont,Title);
|
||||
Q_PROPERTY_AUTO(QFont,TitleLarge);
|
||||
Q_PROPERTY_AUTO(QFont,Display);
|
||||
Q_PROPERTY_AUTO(QString, family)
|
||||
Q_PROPERTY_AUTO(QFont, Caption);
|
||||
Q_PROPERTY_AUTO(QFont, Body);
|
||||
Q_PROPERTY_AUTO(QFont, BodyStrong);
|
||||
Q_PROPERTY_AUTO(QFont, Subtitle);
|
||||
Q_PROPERTY_AUTO(QFont, Title);
|
||||
Q_PROPERTY_AUTO(QFont, TitleLarge);
|
||||
Q_PROPERTY_AUTO(QFont, Display);
|
||||
QML_NAMED_ELEMENT(FluTextStyle)
|
||||
QML_SINGLETON
|
||||
|
||||
private:
|
||||
explicit FluTextStyle(QObject *parent = nullptr);
|
||||
public:
|
||||
SINGLETON(FluTextStyle)
|
||||
static FluTextStyle *create(QQmlEngine *qmlEngine, QJSEngine *jsEngine){return getInstance();}
|
||||
};
|
||||
|
||||
#endif // FLUTEXTSTYLE_H
|
||||
public:
|
||||
SINGLETON(FluTextStyle)
|
||||
|
||||
static FluTextStyle *create(QQmlEngine *, QJSEngine *) { return getInstance(); }
|
||||
};
|
@ -5,40 +5,45 @@
|
||||
#include "Def.h"
|
||||
#include "FluColors.h"
|
||||
|
||||
FluTheme::FluTheme(QObject *parent):QObject{parent}{
|
||||
connect(this,&FluTheme::darkModeChanged,this,[=]{
|
||||
bool systemDark() {
|
||||
QPalette palette = QGuiApplication::palette();
|
||||
QColor color = palette.color(QPalette::Window).rgb();
|
||||
return color.red() * 0.2126 + color.green() * 0.7152 + color.blue() * 0.0722 <= 255.0f / 2;
|
||||
}
|
||||
|
||||
FluTheme::FluTheme(QObject *parent) : QObject{parent} {
|
||||
_accentColor = FluColors::getInstance()->Blue();
|
||||
_darkMode = FluThemeType::DarkMode::Light;
|
||||
_nativeText = false;
|
||||
_animationEnabled = true;
|
||||
_systemDark = systemDark();
|
||||
QGuiApplication::instance()->installEventFilter(this);
|
||||
connect(this, &FluTheme::darkModeChanged, this, [=] {
|
||||
Q_EMIT darkChanged();
|
||||
});
|
||||
connect(this,&FluTheme::darkChanged,this,[=]{refreshColors();});
|
||||
connect(this,&FluTheme::accentColorChanged,this,[=]{refreshColors();});
|
||||
accentColor(FluColors::getInstance()->Blue());
|
||||
darkMode(FluThemeType::DarkMode::Light);
|
||||
nativeText(false);
|
||||
animationEnabled(true);
|
||||
_systemDark = systemDark();
|
||||
qApp->installEventFilter(this);
|
||||
connect(this, &FluTheme::darkChanged, this, [=] { refreshColors(); });
|
||||
connect(this, &FluTheme::accentColorChanged, this, [=] { refreshColors(); });
|
||||
refreshColors();
|
||||
}
|
||||
|
||||
void FluTheme::refreshColors(){
|
||||
void FluTheme::refreshColors() {
|
||||
auto isDark = dark();
|
||||
primaryColor(isDark ? _accentColor->lighter() : _accentColor->dark());
|
||||
backgroundColor(isDark ? QColor(0,0,0,255) : QColor(255,255,255,255));
|
||||
dividerColor(isDark ? QColor(80,80,80,255) : QColor(210,210,210,255));
|
||||
windowBackgroundColor(isDark ? QColor(32,32,32,255) : QColor(237,237,237,255));
|
||||
windowActiveBackgroundColor(isDark ? QColor(26,26,26,255) : QColor(243,243,243,255));
|
||||
fontPrimaryColor(isDark ? QColor(248,248,248,255) : QColor(7,7,7,255));
|
||||
fontSecondaryColor(isDark ? QColor(222,222,222,255) : QColor(102,102,102,255));
|
||||
fontTertiaryColor(isDark ? QColor(200,200,200,255) : QColor(153,153,153,255));
|
||||
itemNormalColor(isDark ? QColor(255,255,255,0) : QColor(0,0,0,0));
|
||||
itemHoverColor(isDark ? QColor(255,255,255,255*0.06) : QColor(0,0,0,255*0.03));
|
||||
itemPressColor(isDark ? QColor(255,255,255,255*0.09) : QColor(0,0,0,255*0.06));
|
||||
itemCheckColor(isDark ? QColor(255,255,255,255*0.12) : QColor(0,0,0,255*0.09));
|
||||
backgroundColor(isDark ? QColor(0, 0, 0, 255) : QColor(255, 255, 255, 255));
|
||||
dividerColor(isDark ? QColor(80, 80, 80, 255) : QColor(210, 210, 210, 255));
|
||||
windowBackgroundColor(isDark ? QColor(32, 32, 32, 255) : QColor(237, 237, 237, 255));
|
||||
windowActiveBackgroundColor(isDark ? QColor(26, 26, 26, 255) : QColor(243, 243, 243, 255));
|
||||
fontPrimaryColor(isDark ? QColor(248, 248, 248, 255) : QColor(7, 7, 7, 255));
|
||||
fontSecondaryColor(isDark ? QColor(222, 222, 222, 255) : QColor(102, 102, 102, 255));
|
||||
fontTertiaryColor(isDark ? QColor(200, 200, 200, 255) : QColor(153, 153, 153, 255));
|
||||
itemNormalColor(isDark ? QColor(255, 255, 255, 0) : QColor(0, 0, 0, 0));
|
||||
itemHoverColor(isDark ? QColor(255, 255, 255, qRound(255 * 0.06)) : QColor(0, 0, 0, qRound(255 * 0.03)));
|
||||
itemPressColor(isDark ? QColor(255, 255, 255, qRound(255 * 0.09)) : QColor(0, 0, 0, qRound(255 * 0.06)));
|
||||
itemCheckColor(isDark ? QColor(255, 255, 255, qRound(255 * 0.12)) : QColor(0, 0, 0, qRound(255 * 0.09)));
|
||||
}
|
||||
|
||||
bool FluTheme::eventFilter(QObject *obj, QEvent *event){
|
||||
Q_UNUSED(obj);
|
||||
if (event->type() == QEvent::ApplicationPaletteChange || event->type() == QEvent::ThemeChange)
|
||||
{
|
||||
bool FluTheme::eventFilter(QObject *, QEvent *event) {
|
||||
if (event->type() == QEvent::ApplicationPaletteChange || event->type() == QEvent::ThemeChange) {
|
||||
_systemDark = systemDark();
|
||||
Q_EMIT darkChanged();
|
||||
event->accept();
|
||||
@ -47,36 +52,28 @@ bool FluTheme::eventFilter(QObject *obj, QEvent *event){
|
||||
return false;
|
||||
}
|
||||
|
||||
QJsonArray FluTheme::awesomeList(const QString& keyword){
|
||||
[[maybe_unused]] QJsonArray FluTheme::awesomeList(const QString &keyword) {
|
||||
QJsonArray arr;
|
||||
QMetaEnum enumType = Fluent_Awesome::staticMetaObject.enumerator(Fluent_Awesome::staticMetaObject.indexOfEnumerator("Fluent_AwesomeType"));
|
||||
for(int i=0; i < enumType.keyCount(); ++i){
|
||||
for (int i = 0; i <= enumType.keyCount() - 1; ++i) {
|
||||
QString name = enumType.key(i);
|
||||
int icon = enumType.value(i);
|
||||
if(keyword.isEmpty() || name.contains(keyword)){
|
||||
if (keyword.isEmpty() || name.contains(keyword)) {
|
||||
QJsonObject obj;
|
||||
obj.insert("name",name);
|
||||
obj.insert("icon",icon);
|
||||
obj.insert("name", name);
|
||||
obj.insert("icon", icon);
|
||||
arr.append(obj);
|
||||
}
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
bool FluTheme::systemDark(){
|
||||
QPalette palette = qApp->palette();
|
||||
QColor color = palette.color(QPalette::Window).rgb();
|
||||
return !(color.red() * 0.2126 + color.green() * 0.7152 + color.blue() * 0.0722 > 255 / 2);
|
||||
}
|
||||
|
||||
bool FluTheme::dark(){
|
||||
if(_darkMode == FluThemeType::DarkMode::Dark){
|
||||
bool FluTheme::dark() const {
|
||||
if (_darkMode == FluThemeType::DarkMode::Dark) {
|
||||
return true;
|
||||
}else if(_darkMode == FluThemeType::DarkMode::Light){
|
||||
return false;
|
||||
}else if(_darkMode == FluThemeType::DarkMode::System){
|
||||
} else if (_darkMode == FluThemeType::DarkMode::System) {
|
||||
return _systemDark;
|
||||
}else{
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -13,39 +13,46 @@
|
||||
/**
|
||||
* @brief The FluTheme class
|
||||
*/
|
||||
class FluTheme : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
class FluTheme : public QObject {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(bool dark READ dark NOTIFY darkChanged)
|
||||
Q_PROPERTY_AUTO(FluAccentColor*,accentColor);
|
||||
Q_PROPERTY_AUTO(QColor,primaryColor);
|
||||
Q_PROPERTY_AUTO(QColor,backgroundColor);
|
||||
Q_PROPERTY_AUTO(QColor,dividerColor);
|
||||
Q_PROPERTY_AUTO(QColor,windowBackgroundColor);
|
||||
Q_PROPERTY_AUTO(QColor,windowActiveBackgroundColor);
|
||||
Q_PROPERTY_AUTO(QColor,fontPrimaryColor);
|
||||
Q_PROPERTY_AUTO(QColor,fontSecondaryColor);
|
||||
Q_PROPERTY_AUTO(QColor,fontTertiaryColor);
|
||||
Q_PROPERTY_AUTO(QColor,itemNormalColor);
|
||||
Q_PROPERTY_AUTO(QColor,itemHoverColor);
|
||||
Q_PROPERTY_AUTO(QColor,itemPressColor);
|
||||
Q_PROPERTY_AUTO(QColor,itemCheckColor);
|
||||
Q_PROPERTY_AUTO(int,darkMode);
|
||||
Q_PROPERTY_AUTO(bool,nativeText);
|
||||
Q_PROPERTY_AUTO(bool,animationEnabled);
|
||||
Q_PROPERTY_AUTO_P(FluAccentColor*, accentColor);
|
||||
Q_PROPERTY_AUTO(QColor, primaryColor);
|
||||
Q_PROPERTY_AUTO(QColor, backgroundColor);
|
||||
Q_PROPERTY_AUTO(QColor, dividerColor);
|
||||
Q_PROPERTY_AUTO(QColor, windowBackgroundColor);
|
||||
Q_PROPERTY_AUTO(QColor, windowActiveBackgroundColor);
|
||||
Q_PROPERTY_AUTO(QColor, fontPrimaryColor);
|
||||
Q_PROPERTY_AUTO(QColor, fontSecondaryColor);
|
||||
Q_PROPERTY_AUTO(QColor, fontTertiaryColor);
|
||||
Q_PROPERTY_AUTO(QColor, itemNormalColor);
|
||||
Q_PROPERTY_AUTO(QColor, itemHoverColor);
|
||||
Q_PROPERTY_AUTO(QColor, itemPressColor);
|
||||
Q_PROPERTY_AUTO(QColor, itemCheckColor);
|
||||
Q_PROPERTY_AUTO(int, darkMode);
|
||||
Q_PROPERTY_AUTO(bool, nativeText);
|
||||
Q_PROPERTY_AUTO(bool, animationEnabled);
|
||||
QML_NAMED_ELEMENT(FluTheme)
|
||||
QML_SINGLETON
|
||||
|
||||
private:
|
||||
explicit FluTheme(QObject *parent = nullptr);
|
||||
bool eventFilter(QObject *obj, QEvent *event);
|
||||
bool systemDark();
|
||||
|
||||
bool eventFilter(QObject *obj, QEvent *event) override;
|
||||
|
||||
void refreshColors();
|
||||
|
||||
public:
|
||||
SINGLETON(FluTheme)
|
||||
Q_INVOKABLE QJsonArray awesomeList(const QString& keyword = "");
|
||||
SINGLETON(FluTheme)
|
||||
|
||||
Q_INVOKABLE [[maybe_unused]] static QJsonArray awesomeList(const QString &keyword = "");
|
||||
|
||||
Q_SIGNAL void darkChanged();
|
||||
static FluTheme *create(QQmlEngine *qmlEngine, QJSEngine *jsEngine){return getInstance();}
|
||||
bool dark();
|
||||
|
||||
static FluTheme *create(QQmlEngine *, QJSEngine *) { return getInstance(); }
|
||||
|
||||
bool dark() const;
|
||||
|
||||
private:
|
||||
bool _systemDark;
|
||||
};
|
||||
|
115
src/FluTools.cpp
115
src/FluTools.cpp
@ -1,3 +1,7 @@
|
||||
#pragma clang diagnostic push
|
||||
#pragma ide diagnostic ignored "OCUnusedGlobalDeclarationInspection"
|
||||
#pragma ide diagnostic ignored "readability-convert-member-functions-to-static"
|
||||
|
||||
#include "FluTools.h"
|
||||
|
||||
#include <QGuiApplication>
|
||||
@ -16,19 +20,19 @@
|
||||
#include <QDateTime>
|
||||
#include <QSettings>
|
||||
|
||||
FluTools::FluTools(QObject *parent):QObject{parent}{
|
||||
FluTools::FluTools(QObject *parent) : QObject{parent} {
|
||||
|
||||
}
|
||||
|
||||
void FluTools::clipText(const QString& text){
|
||||
void FluTools::clipText(const QString &text) {
|
||||
QGuiApplication::clipboard()->setText(text);
|
||||
}
|
||||
|
||||
QString FluTools::uuid(){
|
||||
QString FluTools::uuid() {
|
||||
return QUuid::createUuid().toString().remove('-').remove('{').remove('}');
|
||||
}
|
||||
|
||||
QString FluTools::readFile(const QString &fileName){
|
||||
QString FluTools::readFile(const QString &fileName) {
|
||||
QString content;
|
||||
QFile file(fileName);
|
||||
if (file.open(QIODevice::ReadOnly)) {
|
||||
@ -38,7 +42,7 @@ QString FluTools::readFile(const QString &fileName){
|
||||
return content;
|
||||
}
|
||||
|
||||
bool FluTools::isMacos(){
|
||||
bool FluTools::isMacos() {
|
||||
#if defined(Q_OS_MACOS)
|
||||
return true;
|
||||
#else
|
||||
@ -46,7 +50,7 @@ bool FluTools::isMacos(){
|
||||
#endif
|
||||
}
|
||||
|
||||
bool FluTools::isLinux(){
|
||||
bool FluTools::isLinux() {
|
||||
#if defined(Q_OS_LINUX)
|
||||
return true;
|
||||
#else
|
||||
@ -54,7 +58,7 @@ bool FluTools::isLinux(){
|
||||
#endif
|
||||
}
|
||||
|
||||
bool FluTools::isWin(){
|
||||
bool FluTools::isWin() {
|
||||
#if defined(Q_OS_WIN)
|
||||
return true;
|
||||
#else
|
||||
@ -62,95 +66,94 @@ bool FluTools::isWin(){
|
||||
#endif
|
||||
}
|
||||
|
||||
int FluTools::qtMajor(){
|
||||
int FluTools::qtMajor() {
|
||||
const QString qtVersion = QString::fromLatin1(qVersion());
|
||||
const QStringList versionParts = qtVersion.split('.');
|
||||
return versionParts[0].toInt();
|
||||
}
|
||||
|
||||
int FluTools::qtMinor(){
|
||||
int FluTools::qtMinor() {
|
||||
const QString qtVersion = QString::fromLatin1(qVersion());
|
||||
const QStringList versionParts = qtVersion.split('.');
|
||||
return versionParts[1].toInt();
|
||||
}
|
||||
|
||||
void FluTools::setQuitOnLastWindowClosed(bool val){
|
||||
qApp->setQuitOnLastWindowClosed(val);
|
||||
void FluTools::setQuitOnLastWindowClosed(bool val) {
|
||||
QGuiApplication::setQuitOnLastWindowClosed(val);
|
||||
}
|
||||
|
||||
void FluTools::setOverrideCursor(Qt::CursorShape shape){
|
||||
qApp->setOverrideCursor(QCursor(shape));
|
||||
void FluTools::setOverrideCursor(Qt::CursorShape shape) {
|
||||
QGuiApplication::setOverrideCursor(QCursor(shape));
|
||||
}
|
||||
|
||||
void FluTools::restoreOverrideCursor(){
|
||||
qApp->restoreOverrideCursor();
|
||||
void FluTools::restoreOverrideCursor() {
|
||||
QGuiApplication::restoreOverrideCursor();
|
||||
}
|
||||
|
||||
void FluTools::deleteLater(QObject *p){
|
||||
if(p){
|
||||
void FluTools::deleteLater(QObject *p) {
|
||||
if (p) {
|
||||
p->deleteLater();
|
||||
p = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
QString FluTools::toLocalPath(const QUrl& url){
|
||||
QString FluTools::toLocalPath(const QUrl &url) {
|
||||
return url.toLocalFile();
|
||||
}
|
||||
|
||||
QString FluTools::getFileNameByUrl(const QUrl& url){
|
||||
QString FluTools::getFileNameByUrl(const QUrl &url) {
|
||||
return QFileInfo(url.toLocalFile()).fileName();
|
||||
}
|
||||
|
||||
QString FluTools::html2PlantText(const QString& html){
|
||||
QString FluTools::html2PlantText(const QString &html) {
|
||||
QTextDocument textDocument;
|
||||
textDocument.setHtml(html);
|
||||
return textDocument.toPlainText();
|
||||
}
|
||||
|
||||
QRect FluTools::getVirtualGeometry(){
|
||||
return qApp->primaryScreen()->virtualGeometry();
|
||||
QRect FluTools::getVirtualGeometry() {
|
||||
return QGuiApplication::primaryScreen()->virtualGeometry();
|
||||
}
|
||||
|
||||
QString FluTools::getApplicationDirPath(){
|
||||
return qApp->applicationDirPath();
|
||||
QString FluTools::getApplicationDirPath() {
|
||||
return QGuiApplication::applicationDirPath();
|
||||
}
|
||||
|
||||
QUrl FluTools::getUrlByFilePath(const QString& path){
|
||||
QUrl FluTools::getUrlByFilePath(const QString &path) {
|
||||
return QUrl::fromLocalFile(path);
|
||||
}
|
||||
|
||||
QColor FluTools::withOpacity(const QColor& color,qreal opacity){
|
||||
QColor FluTools::withOpacity(const QColor &color, qreal opacity) {
|
||||
int alpha = qRound(opacity * 255) & 0xff;
|
||||
return QColor::fromRgba((alpha << 24) | (color.rgba() & 0xffffff));
|
||||
}
|
||||
|
||||
QString FluTools::md5(QString text){
|
||||
QString FluTools::md5(const QString &text) {
|
||||
return QCryptographicHash::hash(text.toUtf8(), QCryptographicHash::Md5).toHex();
|
||||
}
|
||||
|
||||
QString FluTools::toBase64(QString text){
|
||||
QString FluTools::toBase64(const QString &text) {
|
||||
return text.toUtf8().toBase64();
|
||||
}
|
||||
|
||||
QString FluTools::fromBase64(QString text){
|
||||
QString FluTools::fromBase64(const QString &text) {
|
||||
return QByteArray::fromBase64(text.toUtf8());
|
||||
}
|
||||
|
||||
bool FluTools::removeDir(QString dirPath){
|
||||
bool FluTools::removeDir(const QString &dirPath) {
|
||||
QDir qDir(dirPath);
|
||||
return qDir.removeRecursively();
|
||||
}
|
||||
|
||||
bool FluTools::removeFile(QString filePath){
|
||||
bool FluTools::removeFile(const QString &filePath) {
|
||||
QFile file(filePath);
|
||||
return file.remove();
|
||||
}
|
||||
|
||||
QString FluTools::sha256(QString text){
|
||||
QString FluTools::sha256(const QString &text) {
|
||||
return QCryptographicHash::hash(text.toUtf8(), QCryptographicHash::Sha256).toHex();
|
||||
}
|
||||
|
||||
void FluTools::showFileInFolder(QString path){
|
||||
void FluTools::showFileInFolder(const QString &path) {
|
||||
#if defined(Q_OS_WIN)
|
||||
QProcess::startDetached("explorer.exe", {"/select,", QDir::toNativeSeparators(path)});
|
||||
#endif
|
||||
@ -166,29 +169,29 @@ void FluTools::showFileInFolder(QString path){
|
||||
#endif
|
||||
}
|
||||
|
||||
bool FluTools::isSoftware(){
|
||||
bool FluTools::isSoftware() {
|
||||
return QQuickWindow::sceneGraphBackend() == "software";
|
||||
}
|
||||
|
||||
QPoint FluTools::cursorPos(){
|
||||
QPoint FluTools::cursorPos() {
|
||||
return QCursor::pos();
|
||||
}
|
||||
|
||||
qint64 FluTools::currentTimestamp(){
|
||||
qint64 FluTools::currentTimestamp() {
|
||||
return QDateTime::currentMSecsSinceEpoch();
|
||||
}
|
||||
|
||||
QIcon FluTools::windowIcon(){
|
||||
QIcon FluTools::windowIcon() {
|
||||
return QGuiApplication::windowIcon();
|
||||
}
|
||||
|
||||
int FluTools::cursorScreenIndex(){
|
||||
int FluTools::cursorScreenIndex() {
|
||||
int screenIndex = 0;
|
||||
int screenCount = qApp->screens().count();
|
||||
int screenCount = QGuiApplication::screens().count();
|
||||
if (screenCount > 1) {
|
||||
QPoint pos = QCursor::pos();
|
||||
for (int i = 0; i < screenCount; ++i) {
|
||||
if (qApp->screens().at(i)->geometry().contains(pos)) {
|
||||
for (int i = 0; i <= screenCount - 1; ++i) {
|
||||
if (QGuiApplication::screens().at(i)->geometry().contains(pos)) {
|
||||
screenIndex = i;
|
||||
break;
|
||||
}
|
||||
@ -197,9 +200,9 @@ int FluTools::cursorScreenIndex(){
|
||||
return screenIndex;
|
||||
}
|
||||
|
||||
int FluTools::windowBuildNumber(){
|
||||
int FluTools::windowBuildNumber() {
|
||||
#if defined(Q_OS_WIN)
|
||||
QSettings regKey {QString::fromUtf8("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"), QSettings::NativeFormat};
|
||||
QSettings regKey{QString::fromUtf8(R"(HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion)"), QSettings::NativeFormat};
|
||||
if (regKey.contains(QString::fromUtf8("CurrentBuildNumber"))) {
|
||||
auto buildNumber = regKey.value(QString::fromUtf8("CurrentBuildNumber")).toInt();
|
||||
return buildNumber;
|
||||
@ -208,40 +211,42 @@ int FluTools::windowBuildNumber(){
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool FluTools::isWindows11OrGreater(){
|
||||
bool FluTools::isWindows11OrGreater() {
|
||||
static QVariant var;
|
||||
if(var.isNull()){
|
||||
if (var.isNull()) {
|
||||
#if defined(Q_OS_WIN)
|
||||
auto buildNumber = windowBuildNumber();
|
||||
if(buildNumber>=22000){
|
||||
if (buildNumber >= 22000) {
|
||||
var = QVariant::fromValue(true);
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
var = QVariant::fromValue(false);
|
||||
return false;
|
||||
}else{
|
||||
return false;
|
||||
} else {
|
||||
return var.toBool();
|
||||
}
|
||||
}
|
||||
|
||||
bool FluTools::isWindows10OrGreater(){
|
||||
bool FluTools::isWindows10OrGreater() {
|
||||
static QVariant var;
|
||||
if(var.isNull()){
|
||||
if (var.isNull()) {
|
||||
#if defined(Q_OS_WIN)
|
||||
auto buildNumber = windowBuildNumber();
|
||||
if(buildNumber>=10240){
|
||||
if (buildNumber >= 10240) {
|
||||
var = QVariant::fromValue(true);
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
var = QVariant::fromValue(false);
|
||||
return false;
|
||||
}else{
|
||||
return false;
|
||||
} else {
|
||||
return var.toBool();
|
||||
}
|
||||
}
|
||||
|
||||
QRect FluTools::desktopAvailableGeometry(QQuickWindow* window){
|
||||
QRect FluTools::desktopAvailableGeometry(QQuickWindow *window) {
|
||||
return window->screen()->availableGeometry();
|
||||
}
|
||||
|
||||
#pragma clang diagnostic pop
|
@ -1,5 +1,6 @@
|
||||
#ifndef FLUTOOLS_H
|
||||
#define FLUTOOLS_H
|
||||
#pragma clang diagnostic push
|
||||
#pragma ide diagnostic ignored "OCUnusedGlobalDeclarationInspection"
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QFile>
|
||||
@ -11,51 +12,88 @@
|
||||
/**
|
||||
* @brief The FluTools class
|
||||
*/
|
||||
class FluTools : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
class FluTools : public QObject {
|
||||
Q_OBJECT
|
||||
QML_NAMED_ELEMENT(FluTools)
|
||||
QML_SINGLETON
|
||||
|
||||
private:
|
||||
explicit FluTools(QObject *parent = nullptr);
|
||||
|
||||
public:
|
||||
SINGLETON(FluTools)
|
||||
static FluTools *create(QQmlEngine *qmlEngine, QJSEngine *jsEngine){return getInstance();}
|
||||
SINGLETON(FluTools)
|
||||
|
||||
static FluTools *create(QQmlEngine *, QJSEngine *) { return getInstance(); }
|
||||
|
||||
Q_INVOKABLE int qtMajor();
|
||||
|
||||
Q_INVOKABLE int qtMinor();
|
||||
|
||||
Q_INVOKABLE bool isMacos();
|
||||
|
||||
Q_INVOKABLE bool isLinux();
|
||||
|
||||
Q_INVOKABLE bool isWin();
|
||||
Q_INVOKABLE void clipText(const QString& text);
|
||||
|
||||
Q_INVOKABLE void clipText(const QString &text);
|
||||
|
||||
Q_INVOKABLE QString uuid();
|
||||
Q_INVOKABLE QString readFile(const QString& fileName);
|
||||
|
||||
Q_INVOKABLE QString readFile(const QString &fileName);
|
||||
|
||||
Q_INVOKABLE void setQuitOnLastWindowClosed(bool val);
|
||||
|
||||
Q_INVOKABLE void setOverrideCursor(Qt::CursorShape shape);
|
||||
|
||||
Q_INVOKABLE void restoreOverrideCursor();
|
||||
Q_INVOKABLE QString html2PlantText(const QString& html);
|
||||
Q_INVOKABLE QString toLocalPath(const QUrl& url);
|
||||
|
||||
Q_INVOKABLE QString html2PlantText(const QString &html);
|
||||
|
||||
Q_INVOKABLE QString toLocalPath(const QUrl &url);
|
||||
|
||||
Q_INVOKABLE void deleteLater(QObject *p);
|
||||
Q_INVOKABLE QString getFileNameByUrl(const QUrl& url);
|
||||
|
||||
Q_INVOKABLE QString getFileNameByUrl(const QUrl &url);
|
||||
|
||||
Q_INVOKABLE QRect getVirtualGeometry();
|
||||
|
||||
Q_INVOKABLE QString getApplicationDirPath();
|
||||
Q_INVOKABLE QUrl getUrlByFilePath(const QString& path);
|
||||
Q_INVOKABLE QColor withOpacity(const QColor&,qreal alpha);
|
||||
Q_INVOKABLE QString md5(QString text);
|
||||
Q_INVOKABLE QString sha256(QString text);
|
||||
Q_INVOKABLE QString toBase64(QString text);
|
||||
Q_INVOKABLE QString fromBase64(QString text);
|
||||
Q_INVOKABLE bool removeDir(QString dirPath);
|
||||
Q_INVOKABLE bool removeFile(QString filePath);
|
||||
Q_INVOKABLE void showFileInFolder(QString path);
|
||||
|
||||
Q_INVOKABLE QUrl getUrlByFilePath(const QString &path);
|
||||
|
||||
Q_INVOKABLE QColor withOpacity(const QColor &, qreal alpha);
|
||||
|
||||
Q_INVOKABLE QString md5(const QString &text);
|
||||
|
||||
Q_INVOKABLE QString sha256(const QString &text);
|
||||
|
||||
Q_INVOKABLE QString toBase64(const QString &text);
|
||||
|
||||
Q_INVOKABLE QString fromBase64(const QString &text);
|
||||
|
||||
Q_INVOKABLE bool removeDir(const QString &dirPath);
|
||||
|
||||
Q_INVOKABLE bool removeFile(const QString &filePath);
|
||||
|
||||
Q_INVOKABLE void showFileInFolder(const QString &path);
|
||||
|
||||
Q_INVOKABLE bool isSoftware();
|
||||
|
||||
Q_INVOKABLE qint64 currentTimestamp();
|
||||
|
||||
Q_INVOKABLE QPoint cursorPos();
|
||||
|
||||
Q_INVOKABLE QIcon windowIcon();
|
||||
|
||||
Q_INVOKABLE int cursorScreenIndex();
|
||||
|
||||
Q_INVOKABLE int windowBuildNumber();
|
||||
|
||||
Q_INVOKABLE bool isWindows11OrGreater();
|
||||
|
||||
Q_INVOKABLE bool isWindows10OrGreater();
|
||||
Q_INVOKABLE QRect desktopAvailableGeometry(QQuickWindow* window);
|
||||
|
||||
Q_INVOKABLE QRect desktopAvailableGeometry(QQuickWindow *window);
|
||||
};
|
||||
|
||||
#endif // FLUTOOLS_H
|
||||
#pragma clang diagnostic pop
|
@ -1,75 +1,80 @@
|
||||
#pragma clang diagnostic push
|
||||
#pragma ide diagnostic ignored "OCUnusedGlobalDeclarationInspection"
|
||||
#pragma ide diagnostic ignored "google-default-arguments"
|
||||
|
||||
#include "FluTreeModel.h"
|
||||
|
||||
#include <QMetaEnum>
|
||||
#include <utility>
|
||||
|
||||
FluTreeNode::FluTreeNode(QObject *parent): QObject{parent}{
|
||||
FluTreeNode::FluTreeNode(QObject *parent) : QObject{parent} {
|
||||
}
|
||||
|
||||
FluTreeModel::FluTreeModel(QObject *parent): QAbstractItemModel{parent}{
|
||||
dataSourceSize(0);
|
||||
FluTreeModel::FluTreeModel(QObject *parent) : QAbstractItemModel{parent} {
|
||||
_dataSourceSize = 0;
|
||||
}
|
||||
|
||||
QModelIndex FluTreeModel::parent(const QModelIndex &child) const{
|
||||
return QModelIndex();
|
||||
QModelIndex FluTreeModel::parent(const QModelIndex &child) const {
|
||||
return {};
|
||||
}
|
||||
|
||||
QModelIndex FluTreeModel::index(int row, int column,const QModelIndex &parent) const{
|
||||
QModelIndex FluTreeModel::index(int row, int column, const QModelIndex &parent) const {
|
||||
if (!hasIndex(row, column, parent) || parent.isValid())
|
||||
return QModelIndex();
|
||||
return {};
|
||||
return createIndex(row, column, _rows.at(row));
|
||||
}
|
||||
|
||||
int FluTreeModel::rowCount(const QModelIndex &parent) const {
|
||||
return _rows.count();
|
||||
};
|
||||
}
|
||||
|
||||
int FluTreeModel::columnCount(const QModelIndex &parent) const {
|
||||
return this->_columnSource.size();
|
||||
};
|
||||
}
|
||||
|
||||
QVariant FluTreeModel::data(const QModelIndex &index, int role) const {
|
||||
switch (role) {
|
||||
case TreeModelRoles::RowModel:
|
||||
return QVariant::fromValue(_rows.at(index.row()));
|
||||
case TreeModelRoles::ColumnModel:
|
||||
return QVariant::fromValue(_columnSource.at(index.column()));
|
||||
default:
|
||||
break;
|
||||
case TreeModelRoles::RowModel:
|
||||
return QVariant::fromValue(_rows.at(index.row()));
|
||||
case TreeModelRoles::ColumnModel:
|
||||
return QVariant::fromValue(_columnSource.at(index.column()));
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return QVariant();
|
||||
};
|
||||
return {};
|
||||
}
|
||||
|
||||
QHash<int, QByteArray> FluTreeModel::roleNames() const {
|
||||
return {
|
||||
{TreeModelRoles::RowModel, "rowModel"},
|
||||
{TreeModelRoles::ColumnModel, "columnModel"}
|
||||
{TreeModelRoles::RowModel, "rowModel"},
|
||||
{TreeModelRoles::ColumnModel, "columnModel"}
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
void FluTreeModel::setData(QList<FluTreeNode*> data){
|
||||
void FluTreeModel::setData(QList<FluTreeNode *> data) {
|
||||
beginResetModel();
|
||||
_rows = data;
|
||||
_rows = std::move(data);
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
void FluTreeModel::removeRows(int row,int count){
|
||||
if (row < 0 || row + count > _rows.size() || count==0)
|
||||
void FluTreeModel::removeRows(int row, int count) {
|
||||
if (row < 0 || row + count > _rows.size() || count == 0)
|
||||
return;
|
||||
beginRemoveRows(QModelIndex(),row, row + count - 1);
|
||||
QList<FluTreeNode*> firstPart = _rows.mid(0,row);
|
||||
QList<FluTreeNode*> secondPart = _rows.mid(row + count);
|
||||
beginRemoveRows(QModelIndex(), row, row + count - 1);
|
||||
QList<FluTreeNode *> firstPart = _rows.mid(0, row);
|
||||
QList<FluTreeNode *> secondPart = _rows.mid(row + count);
|
||||
_rows.clear();
|
||||
_rows.append(firstPart);
|
||||
_rows.append(secondPart);
|
||||
endRemoveRows();
|
||||
}
|
||||
|
||||
void FluTreeModel::insertRows(int row,QList<FluTreeNode*> data){
|
||||
if (row < 0 || row > _rows.size() || data.size() == 0)
|
||||
return;;
|
||||
void FluTreeModel::insertRows(int row, const QList<FluTreeNode *> &data) {
|
||||
if (row < 0 || row > _rows.size() || data.empty())
|
||||
return;
|
||||
beginInsertRows(QModelIndex(), row, row + data.size() - 1);
|
||||
QList<FluTreeNode*> firstPart = _rows.mid(0, row);
|
||||
QList<FluTreeNode*> secondPart = _rows.mid(row);
|
||||
QList<FluTreeNode *> firstPart = _rows.mid(0, row);
|
||||
QList<FluTreeNode *> secondPart = _rows.mid(row);
|
||||
_rows.clear();
|
||||
_rows.append(firstPart);
|
||||
_rows.append(data);
|
||||
@ -77,83 +82,83 @@ void FluTreeModel::insertRows(int row,QList<FluTreeNode*> data){
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
QObject* FluTreeModel::getRow(int row){
|
||||
QObject *FluTreeModel::getRow(int row) {
|
||||
return _rows.at(row);
|
||||
}
|
||||
|
||||
void FluTreeModel::setRow(int row,QVariantMap data){
|
||||
_rows.at(row)->_data = data;
|
||||
Q_EMIT dataChanged(index(row,0),index(row,columnCount()-1));
|
||||
void FluTreeModel::setRow(int row, QVariantMap data) {
|
||||
_rows.at(row)->_data = std::move(data);
|
||||
Q_EMIT dataChanged(index(row, 0), index(row, columnCount() - 1));
|
||||
}
|
||||
|
||||
void FluTreeModel::checkRow(int row,bool checked){
|
||||
void FluTreeModel::checkRow(int row, bool checked) {
|
||||
auto itemData = _rows.at(row);
|
||||
if(itemData->hasChildren()){
|
||||
QList<FluTreeNode*> stack = itemData->_children;
|
||||
if (itemData->hasChildren()) {
|
||||
QList<FluTreeNode *> stack = itemData->_children;
|
||||
std::reverse(stack.begin(), stack.end());
|
||||
while (stack.count() > 0) {
|
||||
auto item = stack.at(stack.count()-1);
|
||||
auto item = stack.at(stack.count() - 1);
|
||||
stack.pop_back();
|
||||
if(!item->hasChildren()){
|
||||
if (!item->hasChildren()) {
|
||||
item->_checked = checked;
|
||||
}
|
||||
QList<FluTreeNode*> children = item->_children;
|
||||
if(!children.isEmpty()){
|
||||
QList<FluTreeNode *> children = item->_children;
|
||||
if (!children.isEmpty()) {
|
||||
std::reverse(children.begin(), children.end());
|
||||
foreach (auto c, children) {
|
||||
stack.append(c);
|
||||
}
|
||||
foreach (auto c, children) {
|
||||
stack.append(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
}else{
|
||||
if(itemData->_checked == checked){
|
||||
} else {
|
||||
if (itemData->_checked == checked) {
|
||||
return;
|
||||
}
|
||||
itemData->_checked = checked;
|
||||
}
|
||||
Q_EMIT dataChanged(index(0,0),index(rowCount()-1,0));
|
||||
QList<FluTreeNode*> data;
|
||||
foreach (auto item, _dataSource) {
|
||||
if(!item->hasChildren()){
|
||||
if(item->_checked){
|
||||
data.append(item);
|
||||
Q_EMIT dataChanged(index(0, 0), index(rowCount() - 1, 0));
|
||||
QList<FluTreeNode *> data;
|
||||
foreach (auto item, _dataSource) {
|
||||
if (!item->hasChildren()) {
|
||||
if (item->_checked) {
|
||||
data.append(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
selectionModel(data);
|
||||
}
|
||||
|
||||
void FluTreeModel::setDataSource(QList<QMap<QString,QVariant>> data){
|
||||
void FluTreeModel::setDataSource(QList<QMap<QString, QVariant>> data) {
|
||||
_dataSource.clear();
|
||||
if(_root){
|
||||
if (_root) {
|
||||
delete _root;
|
||||
_root = nullptr;
|
||||
}
|
||||
_root = new FluTreeNode(this);
|
||||
std::reverse(data.begin(), data.end());
|
||||
while (data.count() > 0) {
|
||||
auto item = data.at(data.count()-1);
|
||||
auto item = data.at(data.count() - 1);
|
||||
data.pop_back();
|
||||
FluTreeNode* node = new FluTreeNode(this);
|
||||
auto *node = new FluTreeNode(this);
|
||||
node->_depth = item.value("__depth").toInt();
|
||||
node->_parent = item.value("__parent").value<FluTreeNode*>();
|
||||
node->_parent = item.value("__parent").value<FluTreeNode *>();
|
||||
node->_data = item;
|
||||
node->_isExpanded = true;
|
||||
if(node->_parent){
|
||||
if (node->_parent) {
|
||||
node->_parent->_children.append(node);
|
||||
}else{
|
||||
} else {
|
||||
node->_parent = _root;
|
||||
_root->_children.append(node);
|
||||
}
|
||||
_dataSource.append(node);
|
||||
if (item.contains("children")) {
|
||||
QList<QVariant> children = item.value("children").toList();
|
||||
if(!children.isEmpty()){
|
||||
if (!children.isEmpty()) {
|
||||
std::reverse(children.begin(), children.end());
|
||||
for (int i = 0; i < children.count(); ++i) {
|
||||
for (int i = 0; i <= children.count() - 1; ++i) {
|
||||
auto child = children.at(i).toMap();
|
||||
child.insert("__depth",item.value("__depth").toInt(0)+1);
|
||||
child.insert("__parent",QVariant::fromValue(node));
|
||||
child.insert("__depth", item.value("__depth").toInt(nullptr) + 1);
|
||||
child.insert("__parent", QVariant::fromValue(node));
|
||||
data.append(child);
|
||||
}
|
||||
}
|
||||
@ -165,108 +170,111 @@ void FluTreeModel::setDataSource(QList<QMap<QString,QVariant>> data){
|
||||
dataSourceSize(_dataSource.size());
|
||||
}
|
||||
|
||||
void FluTreeModel::collapse(int row){
|
||||
if(!_rows.at(row)->_isExpanded){
|
||||
void FluTreeModel::collapse(int row) {
|
||||
if (!_rows.at(row)->_isExpanded) {
|
||||
return;
|
||||
}
|
||||
_rows.at(row)->_isExpanded = false;
|
||||
Q_EMIT dataChanged(index(row,0),index(row,0));
|
||||
Q_EMIT dataChanged(index(row, 0), index(row, 0));
|
||||
auto modelData = _rows.at(row);
|
||||
int removeCount = 0;
|
||||
for(int i=row+1;i<_rows.count();i++){
|
||||
for (int i = row + 1; i < _rows.count(); i++) {
|
||||
auto obj = _rows[i];
|
||||
if(obj->_depth<=modelData->_depth){
|
||||
if (obj->_depth <= modelData->_depth) {
|
||||
break;
|
||||
}
|
||||
removeCount = removeCount + 1;
|
||||
}
|
||||
removeRows(row+1,removeCount);
|
||||
removeRows(row + 1, removeCount);
|
||||
}
|
||||
|
||||
void FluTreeModel::expand(int row){
|
||||
if(_rows.at(row)->_isExpanded){
|
||||
void FluTreeModel::expand(int row) {
|
||||
if (_rows.at(row)->_isExpanded) {
|
||||
return;
|
||||
}
|
||||
_rows.at(row)->_isExpanded = true;
|
||||
Q_EMIT dataChanged(index(row,0),index(row,0));
|
||||
Q_EMIT dataChanged(index(row, 0), index(row, 0));
|
||||
auto modelData = _rows.at(row);
|
||||
QList<FluTreeNode*> insertData;
|
||||
QList<FluTreeNode*> stack = modelData->_children;
|
||||
QList<FluTreeNode *> insertData;
|
||||
QList<FluTreeNode *> stack = modelData->_children;
|
||||
std::reverse(stack.begin(), stack.end());
|
||||
while (stack.count() > 0) {
|
||||
auto item = stack.at(stack.count()-1);
|
||||
auto item = stack.at(stack.count() - 1);
|
||||
stack.pop_back();
|
||||
if(item->isShown()){
|
||||
if (item->isShown()) {
|
||||
insertData.append(item);
|
||||
}
|
||||
QList<FluTreeNode*> children = item->_children;
|
||||
if(!children.isEmpty()){
|
||||
QList<FluTreeNode *> children = item->_children;
|
||||
if (!children.isEmpty()) {
|
||||
std::reverse(children.begin(), children.end());
|
||||
foreach (auto c, children) {
|
||||
stack.append(c);
|
||||
}
|
||||
foreach (auto c, children) {
|
||||
stack.append(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
insertRows(row+1,insertData);
|
||||
insertRows(row + 1, insertData);
|
||||
}
|
||||
|
||||
bool FluTreeModel::hitHasChildrenExpanded(int row){
|
||||
bool FluTreeModel::hitHasChildrenExpanded(int row) {
|
||||
auto itemData = _rows.at(row);
|
||||
if(itemData->hasChildren() && itemData->_isExpanded){
|
||||
if (itemData->hasChildren() && itemData->_isExpanded) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void FluTreeModel::refreshNode(int row){
|
||||
Q_EMIT dataChanged(index(row,0),index(row,0));
|
||||
};
|
||||
void FluTreeModel::refreshNode(int row) {
|
||||
Q_EMIT dataChanged(index(row, 0), index(row, 0));
|
||||
}
|
||||
|
||||
FluTreeNode* FluTreeModel::getNode(int row){
|
||||
FluTreeNode *FluTreeModel::getNode(int row) {
|
||||
return _rows.at(row);
|
||||
}
|
||||
|
||||
void FluTreeModel::allExpand(){
|
||||
void FluTreeModel::allExpand() {
|
||||
beginResetModel();
|
||||
QList<FluTreeNode*> data;
|
||||
QList<FluTreeNode*> stack = _root->_children;
|
||||
QList<FluTreeNode *> data;
|
||||
QList<FluTreeNode *> stack = _root->_children;
|
||||
std::reverse(stack.begin(), stack.end());
|
||||
while (stack.count() > 0) {
|
||||
auto item = stack.at(stack.count()-1);
|
||||
auto item = stack.at(stack.count() - 1);
|
||||
stack.pop_back();
|
||||
if(item->hasChildren()){
|
||||
if (item->hasChildren()) {
|
||||
item->_isExpanded = true;
|
||||
}
|
||||
data.append(item);
|
||||
QList<FluTreeNode*> children = item->_children;
|
||||
if(!children.isEmpty()){
|
||||
QList<FluTreeNode *> children = item->_children;
|
||||
if (!children.isEmpty()) {
|
||||
std::reverse(children.begin(), children.end());
|
||||
foreach (auto c, children) {
|
||||
stack.append(c);
|
||||
}
|
||||
foreach (auto c, children) {
|
||||
stack.append(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
_rows = data;
|
||||
endResetModel();
|
||||
}
|
||||
void FluTreeModel::allCollapse(){
|
||||
|
||||
void FluTreeModel::allCollapse() {
|
||||
beginResetModel();
|
||||
QList<FluTreeNode*> stack = _root->_children;
|
||||
QList<FluTreeNode *> stack = _root->_children;
|
||||
std::reverse(stack.begin(), stack.end());
|
||||
while (stack.count() > 0) {
|
||||
auto item = stack.at(stack.count()-1);
|
||||
auto item = stack.at(stack.count() - 1);
|
||||
stack.pop_back();
|
||||
if(item->hasChildren()){
|
||||
if (item->hasChildren()) {
|
||||
item->_isExpanded = false;
|
||||
}
|
||||
QList<FluTreeNode*> children = item->_children;
|
||||
if(!children.isEmpty()){
|
||||
QList<FluTreeNode *> children = item->_children;
|
||||
if (!children.isEmpty()) {
|
||||
std::reverse(children.begin(), children.end());
|
||||
foreach (auto c, children) {
|
||||
stack.append(c);
|
||||
}
|
||||
foreach (auto c, children) {
|
||||
stack.append(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
_rows = _root->_children;
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
#pragma clang diagnostic pop
|
@ -1,5 +1,7 @@
|
||||
#ifndef FLUTREEMODEL_H
|
||||
#define FLUTREEMODEL_H
|
||||
#pragma clang diagnostic push
|
||||
#pragma ide diagnostic ignored "OCUnusedGlobalDeclarationInspection"
|
||||
#pragma ide diagnostic ignored "google-default-arguments"
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QAbstractTableModel>
|
||||
@ -11,79 +13,82 @@
|
||||
/**
|
||||
* @brief The FluTreeNode class
|
||||
*/
|
||||
class FluTreeNode : public QObject{
|
||||
Q_OBJECT
|
||||
class FluTreeNode : public QObject {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QVariantMap data READ data CONSTANT)
|
||||
Q_PROPERTY(int depth READ depth CONSTANT)
|
||||
Q_PROPERTY(bool isExpanded READ isExpanded CONSTANT)
|
||||
Q_PROPERTY(bool checked READ checked CONSTANT)
|
||||
public:
|
||||
explicit FluTreeNode(QObject *parent = nullptr);
|
||||
Q_INVOKABLE int depth(){return _depth;};
|
||||
Q_INVOKABLE bool isExpanded(){return _isExpanded;};
|
||||
Q_INVOKABLE QVariantMap data(){return _data;};
|
||||
Q_INVOKABLE bool hasChildren(){ return !_children.isEmpty();};
|
||||
Q_INVOKABLE bool hasNextNodeByIndex(int index){
|
||||
FluTreeNode* p = this;
|
||||
for(int i=0;i<(_depth - index -1);i++){
|
||||
|
||||
Q_INVOKABLE [[nodiscard]] int depth() const { return _depth; };
|
||||
Q_INVOKABLE [[nodiscard]] bool isExpanded() const { return _isExpanded; };
|
||||
Q_INVOKABLE [[nodiscard]] QVariantMap data() const { return _data; };
|
||||
Q_INVOKABLE [[nodiscard]] bool hasChildren() const { return !_children.isEmpty(); };
|
||||
Q_INVOKABLE bool hasNextNodeByIndex(int index) {
|
||||
FluTreeNode *p = this;
|
||||
for (int i = 0; i <= _depth - index - 1; i++) {
|
||||
p = p->_parent;
|
||||
}
|
||||
if(p->_parent->_children.indexOf(p) == p->_parent->_children.count()-1){
|
||||
if (p->_parent->_children.indexOf(p) == p->_parent->_children.count() - 1) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
Q_INVOKABLE bool checked(){
|
||||
if(!hasChildren()){
|
||||
|
||||
Q_INVOKABLE [[nodiscard]] bool checked() const {
|
||||
if (!hasChildren()) {
|
||||
return _checked;
|
||||
}
|
||||
foreach (auto item, _children) {
|
||||
if(!item->checked()){
|
||||
|
||||
for (int i = 0; i <= _children.size() - 1; ++i) {
|
||||
auto item = _children.at(i);
|
||||
if (!item->checked()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
Q_INVOKABLE bool hideLineFooter(){
|
||||
if(_parent){
|
||||
auto childIndex = _parent->_children.indexOf(this);
|
||||
if(childIndex==_parent->_children.count()-1){
|
||||
Q_INVOKABLE bool hideLineFooter() {
|
||||
if (_parent) {
|
||||
auto childIndex = _parent->_children.indexOf(this);
|
||||
if (childIndex == _parent->_children.count() - 1) {
|
||||
return true;
|
||||
}
|
||||
if(_parent->_children.at(childIndex+1)->hasChildren()){
|
||||
if (_parent->_children.at(childIndex + 1)->hasChildren()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
bool isShown(){
|
||||
|
||||
[[nodiscard]] bool isShown() const {
|
||||
auto p = _parent;
|
||||
while (p) {
|
||||
if(!p->_isExpanded){
|
||||
if (!p->_isExpanded) {
|
||||
return false;
|
||||
}
|
||||
p = p->_parent;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public:
|
||||
QString _title="";
|
||||
int _depth=0;
|
||||
QString _title = "";
|
||||
int _depth = 0;
|
||||
bool _checked = false;
|
||||
bool _isExpanded=true;
|
||||
bool _isExpanded = true;
|
||||
QVariantMap _data;
|
||||
QList<FluTreeNode*> _children;
|
||||
FluTreeNode* _parent = nullptr;
|
||||
QList<FluTreeNode *> _children;
|
||||
FluTreeNode *_parent = nullptr;
|
||||
};
|
||||
|
||||
class FluTreeModel : public QAbstractItemModel
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY_AUTO(int,dataSourceSize)
|
||||
Q_PROPERTY_AUTO(QList<FluTreeNode*>,selectionModel)
|
||||
Q_PROPERTY_AUTO(QList<QVariantMap>,columnSource)
|
||||
class FluTreeModel : public QAbstractItemModel {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY_AUTO(int, dataSourceSize)
|
||||
Q_PROPERTY_AUTO(QList<FluTreeNode *>, selectionModel)
|
||||
Q_PROPERTY_AUTO(QList<QVariantMap>, columnSource)
|
||||
QML_NAMED_ELEMENT(FluTreeModel)
|
||||
QML_ADDED_IN_MINOR_VERSION(1)
|
||||
public:
|
||||
@ -91,32 +96,53 @@ public:
|
||||
RowModel = 0x0101,
|
||||
ColumnModel = 0x0102
|
||||
};
|
||||
explicit FluTreeModel(QObject *parent = nullptr);
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
QHash<int, QByteArray> roleNames() const override;
|
||||
QModelIndex parent(const QModelIndex &child) const override;
|
||||
QModelIndex index(int row, int column,const QModelIndex &parent = QModelIndex()) const override;
|
||||
|
||||
Q_INVOKABLE void removeRows(int row,int count);
|
||||
Q_INVOKABLE void insertRows(int row,QList<FluTreeNode*> data);
|
||||
Q_INVOKABLE QObject* getRow(int row);
|
||||
Q_INVOKABLE void setRow(int row,QVariantMap data);
|
||||
Q_INVOKABLE void setData(QList<FluTreeNode*> data);
|
||||
Q_INVOKABLE void setDataSource(QList<QMap<QString,QVariant>> data);
|
||||
explicit FluTreeModel(QObject *parent = nullptr);
|
||||
|
||||
[[nodiscard]] int rowCount(const QModelIndex &parent = {}) const override;
|
||||
|
||||
[[nodiscard]] int columnCount(const QModelIndex &parent = {}) const override;
|
||||
|
||||
[[nodiscard]] QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
|
||||
[[nodiscard]] QHash<int, QByteArray> roleNames() const override;
|
||||
|
||||
[[nodiscard]] QModelIndex parent(const QModelIndex &child) const override;
|
||||
|
||||
[[nodiscard]] QModelIndex index(int row, int column, const QModelIndex &parent = {}) const override;
|
||||
|
||||
Q_INVOKABLE void removeRows(int row, int count);
|
||||
|
||||
Q_INVOKABLE void insertRows(int row, const QList<FluTreeNode *> &data);
|
||||
|
||||
Q_INVOKABLE QObject *getRow(int row);
|
||||
|
||||
Q_INVOKABLE void setRow(int row, QVariantMap data);
|
||||
|
||||
Q_INVOKABLE void setData(QList<FluTreeNode *> data);
|
||||
|
||||
Q_INVOKABLE void setDataSource(QList<QMap<QString, QVariant>> data);
|
||||
|
||||
Q_INVOKABLE void collapse(int row);
|
||||
|
||||
Q_INVOKABLE void expand(int row);
|
||||
Q_INVOKABLE FluTreeNode* getNode(int row);
|
||||
|
||||
Q_INVOKABLE FluTreeNode *getNode(int row);
|
||||
|
||||
Q_INVOKABLE void refreshNode(int row);
|
||||
Q_INVOKABLE void checkRow(int row,bool checked);
|
||||
|
||||
Q_INVOKABLE void checkRow(int row, bool checked);
|
||||
|
||||
Q_INVOKABLE bool hitHasChildrenExpanded(int row);
|
||||
|
||||
Q_INVOKABLE void allExpand();
|
||||
|
||||
Q_INVOKABLE void allCollapse();
|
||||
|
||||
private:
|
||||
QList<FluTreeNode*> _rows;
|
||||
QList<FluTreeNode*> _dataSource;
|
||||
FluTreeNode* _root = nullptr;
|
||||
QList<FluTreeNode *> _rows;
|
||||
QList<FluTreeNode *> _dataSource;
|
||||
FluTreeNode *_root = nullptr;
|
||||
};
|
||||
|
||||
#endif // FLUTREEMODEL_H
|
||||
#pragma clang diagnostic pop
|
@ -2,22 +2,22 @@
|
||||
|
||||
#include "FluTextStyle.h"
|
||||
|
||||
FluWatermark::FluWatermark(QQuickItem* parent) : QQuickPaintedItem(parent){
|
||||
gap(QPoint(100,100));
|
||||
offset(QPoint(_gap.x()/2,_gap.y()/2));
|
||||
rotate(22);
|
||||
FluWatermark::FluWatermark(QQuickItem *parent) : QQuickPaintedItem(parent) {
|
||||
_gap = QPoint(100, 100);
|
||||
_offset = QPoint(_gap.x() / 2, _gap.y() / 2);
|
||||
_rotate = 22;
|
||||
_textColor = QColor(222, 222, 222, 222);
|
||||
_textSize = 16;
|
||||
setZ(9999);
|
||||
textColor(QColor(222,222,222,222));
|
||||
textSize(16);
|
||||
connect(this,&FluWatermark::textColorChanged,this,[=]{update();});
|
||||
connect(this,&FluWatermark::gapChanged,this,[=]{update();});
|
||||
connect(this,&FluWatermark::offsetChanged,this,[=]{update();});
|
||||
connect(this,&FluWatermark::textChanged,this,[=]{update();});
|
||||
connect(this,&FluWatermark::rotateChanged,this,[=]{update();});
|
||||
connect(this,&FluWatermark::textSizeChanged,this,[=]{update();});
|
||||
connect(this, &FluWatermark::textColorChanged, this, [=] { update(); });
|
||||
connect(this, &FluWatermark::gapChanged, this, [=] { update(); });
|
||||
connect(this, &FluWatermark::offsetChanged, this, [=] { update(); });
|
||||
connect(this, &FluWatermark::textChanged, this, [=] { update(); });
|
||||
connect(this, &FluWatermark::rotateChanged, this, [=] { update(); });
|
||||
connect(this, &FluWatermark::textSizeChanged, this, [=] { update(); });
|
||||
}
|
||||
|
||||
void FluWatermark::paint(QPainter* painter){
|
||||
void FluWatermark::paint(QPainter *painter) {
|
||||
QFont font;
|
||||
font.setFamily(FluTextStyle::getInstance()->family());
|
||||
font.setPixelSize(_textSize);
|
||||
@ -26,14 +26,12 @@ void FluWatermark::paint(QPainter* painter){
|
||||
QFontMetricsF fontMetrics(font);
|
||||
qreal fontWidth = fontMetrics.horizontalAdvance(_text);
|
||||
qreal fontHeight = fontMetrics.height();
|
||||
int stepX = fontWidth + _gap.x();
|
||||
int stepY = fontHeight + _gap.y();
|
||||
int rowCount = width() / stepX+1;
|
||||
int colCount = height() / stepY+1;
|
||||
for (int r = 0; r < rowCount; r++)
|
||||
{
|
||||
for (int c = 0; c < colCount; c++)
|
||||
{
|
||||
int stepX = qRound(fontWidth + _gap.x());
|
||||
int stepY = qRound(fontHeight + _gap.y());
|
||||
int rowCount = qRound(width() / stepX + 1);
|
||||
int colCount = qRound(height() / stepY + 1);
|
||||
for (int r = 0; r < rowCount; r++) {
|
||||
for (int c = 0; c < colCount; c++) {
|
||||
qreal centerX = stepX * r + _offset.x() + fontWidth / 2.0;
|
||||
qreal centerY = stepY * c + _offset.y() + fontHeight / 2.0;
|
||||
painter->save();
|
||||
|
@ -1,5 +1,4 @@
|
||||
#ifndef FLUWATERMARK_H
|
||||
#define FLUWATERMARK_H
|
||||
#pragma once
|
||||
|
||||
#include <QQuickItem>
|
||||
#include <QQuickPaintedItem>
|
||||
@ -9,19 +8,17 @@
|
||||
/**
|
||||
* @brief The FluWatermark class
|
||||
*/
|
||||
class FluWatermark : public QQuickPaintedItem
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY_AUTO(QString,text)
|
||||
Q_PROPERTY_AUTO(QPoint,gap)
|
||||
Q_PROPERTY_AUTO(QPoint,offset);
|
||||
Q_PROPERTY_AUTO(QColor,textColor);
|
||||
Q_PROPERTY_AUTO(int,rotate);
|
||||
Q_PROPERTY_AUTO(int,textSize);
|
||||
class FluWatermark : public QQuickPaintedItem {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY_AUTO(QString, text)
|
||||
Q_PROPERTY_AUTO(QPoint, gap)
|
||||
Q_PROPERTY_AUTO(QPoint, offset);
|
||||
Q_PROPERTY_AUTO(QColor, textColor);
|
||||
Q_PROPERTY_AUTO(int, rotate);
|
||||
Q_PROPERTY_AUTO(int, textSize);
|
||||
QML_NAMED_ELEMENT(FluWatermark)
|
||||
public:
|
||||
explicit FluWatermark(QQuickItem *parent = nullptr);
|
||||
void paint(QPainter* painter) override;
|
||||
};
|
||||
|
||||
#endif // FLUWATERMARK_H
|
||||
void paint(QPainter *painter) override;
|
||||
};
|
||||
|
257
src/FluentUI.cpp
257
src/FluentUI.cpp
@ -15,143 +15,144 @@
|
||||
#include "FluTableSortProxyModel.h"
|
||||
#include "FluFrameless.h"
|
||||
|
||||
void FluentUI::registerTypes(QQmlEngine *engine){
|
||||
initializeEngine(engine,uri);
|
||||
registerTypes(uri);
|
||||
void FluentUI::registerTypes(QQmlEngine *engine) {
|
||||
initializeEngine(engine, _uri);
|
||||
registerTypes(_uri);
|
||||
}
|
||||
|
||||
void FluentUI::registerTypes(const char *uri){
|
||||
void FluentUI::registerTypes(const char *uri) const {
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(6, 2, 0))
|
||||
Q_INIT_RESOURCE(fluentui);
|
||||
|
||||
int major = _major;
|
||||
int minor = _minor;
|
||||
//@uri FluentUI
|
||||
qmlRegisterType<FluQrCodeItem>(uri,major,minor,"FluQrCodeItem");
|
||||
qmlRegisterType<FluCaptcha>(uri,major,minor,"FluCaptcha");
|
||||
qmlRegisterType<FluWatermark>(uri,major,minor,"FluWatermark");
|
||||
qmlRegisterType<FluAccentColor>(uri,major,minor,"FluAccentColor");
|
||||
qmlRegisterType<FluTreeModel>(uri,major,minor,"FluTreeModel");
|
||||
qmlRegisterType<FluRectangle>(uri,major,minor,"FluRectangle");
|
||||
qmlRegisterType<FluFrameless>(uri,major,minor,"FluFrameless");
|
||||
qmlRegisterType<FluTableSortProxyModel>(uri,major,minor,"FluTableSortProxyModel");
|
||||
qmlRegisterType<FluQrCodeItem>(uri, major, minor, "FluQrCodeItem");
|
||||
qmlRegisterType<FluCaptcha>(uri, major, minor, "FluCaptcha");
|
||||
qmlRegisterType<FluWatermark>(uri, major, minor, "FluWatermark");
|
||||
qmlRegisterType<FluAccentColor>(uri, major, minor, "FluAccentColor");
|
||||
qmlRegisterType<FluTreeModel>(uri, major, minor, "FluTreeModel");
|
||||
qmlRegisterType<FluRectangle>(uri, major, minor, "FluRectangle");
|
||||
qmlRegisterType<FluFrameless>(uri, major, minor, "FluFrameless");
|
||||
qmlRegisterType<FluTableSortProxyModel>(uri, major, minor, "FluTableSortProxyModel");
|
||||
|
||||
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/FluFrame.qml"),uri,major,minor,"FluFrame");
|
||||
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/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/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/FluImageButton.qml"),uri,major,minor,"FluImageButton");
|
||||
qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluInfoBar.qml"),uri,major,minor,"FluInfoBar");
|
||||
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/FluRemoteLoader.qml"),uri,major,minor,"FluRemoteLoader");
|
||||
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/FluStatusLayout.qml"),uri,major,minor,"FluStatusLayout");
|
||||
qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluTabView.qml"),uri,major,minor,"FluTabView");
|
||||
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/FluWindowDialog.qml"),uri,major,minor,"FluWindowDialog");
|
||||
qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluRangeSlider.qml"),uri,major,minor,"FluRangeSlider");
|
||||
qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluStaggeredLayout.qml"),uri,major,minor,"FluStaggeredLayout");
|
||||
qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluProgressButton.qml"),uri,major,minor,"FluProgressButton");
|
||||
qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluLoadingButton.qml"),uri,major,minor,"FluLoadingButton");
|
||||
qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluClip.qml"),uri,major,minor,"FluClip");
|
||||
qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluLoader.qml"),uri,major,minor,"FluLoader");
|
||||
qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluShortcutPicker.qml"),uri,major,minor,"FluShortcutPicker");
|
||||
qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluSplitLayout.qml"),uri,major,minor,"FluSplitLayout");
|
||||
qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluWindowResultLauncher.qml"),uri,major,minor,"FluWindowResultLauncher");
|
||||
qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluLauncher.qml"),uri,major,minor,"FluLauncher");
|
||||
qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluEvent.qml"),uri,major,minor,"FluEvent");
|
||||
qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluSheet.qml"),uri,major,minor,"FluSheet");
|
||||
qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluGroupBox.qml"),uri,major,minor,"FluGroupBox");
|
||||
qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluControlBackground.qml"),uri,major,minor,"FluControlBackground");
|
||||
qmlRegisterSingletonType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluRouter.qml"),uri,major,minor,"FluRouter");
|
||||
qmlRegisterSingletonType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluEventBus.qml"),uri,major,minor,"FluEventBus");
|
||||
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/FluFrame.qml"), uri, major, minor, "FluFrame");
|
||||
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/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/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/FluImageButton.qml"), uri, major, minor, "FluImageButton");
|
||||
qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluInfoBar.qml"), uri, major, minor, "FluInfoBar");
|
||||
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/FluRemoteLoader.qml"), uri, major, minor, "FluRemoteLoader");
|
||||
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/FluStatusLayout.qml"), uri, major, minor, "FluStatusLayout");
|
||||
qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluTabView.qml"), uri, major, minor, "FluTabView");
|
||||
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/FluWindowDialog.qml"), uri, major, minor, "FluWindowDialog");
|
||||
qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluRangeSlider.qml"), uri, major, minor, "FluRangeSlider");
|
||||
qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluStaggeredLayout.qml"), uri, major, minor, "FluStaggeredLayout");
|
||||
qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluProgressButton.qml"), uri, major, minor, "FluProgressButton");
|
||||
qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluLoadingButton.qml"), uri, major, minor, "FluLoadingButton");
|
||||
qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluClip.qml"), uri, major, minor, "FluClip");
|
||||
qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluLoader.qml"), uri, major, minor, "FluLoader");
|
||||
qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluShortcutPicker.qml"), uri, major, minor, "FluShortcutPicker");
|
||||
qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluSplitLayout.qml"), uri, major, minor, "FluSplitLayout");
|
||||
qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluWindowResultLauncher.qml"), uri, major, minor, "FluWindowResultLauncher");
|
||||
qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluLauncher.qml"), uri, major, minor, "FluLauncher");
|
||||
qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluEvent.qml"), uri, major, minor, "FluEvent");
|
||||
qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluSheet.qml"), uri, major, minor, "FluSheet");
|
||||
qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluGroupBox.qml"), uri, major, minor, "FluGroupBox");
|
||||
qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluControlBackground.qml"), uri, major, minor, "FluControlBackground");
|
||||
qmlRegisterSingletonType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluRouter.qml"), uri, major, minor, "FluRouter");
|
||||
qmlRegisterSingletonType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluEventBus.qml"), uri, major, minor, "FluEventBus");
|
||||
|
||||
qmlRegisterUncreatableMetaObject(Fluent_Awesome::staticMetaObject, uri,major,minor,"FluentIcons", "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(FluStatusLayoutType::staticMetaObject, uri,major,minor,"FluStatusLayoutType", "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(FluSheetType::staticMetaObject, uri,major,minor,"FluSheetType", "Access to enums & flags only");
|
||||
qmlRegisterUncreatableMetaObject(Fluent_Awesome::staticMetaObject, uri, major, minor, "FluentIcons", "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(FluStatusLayoutType::staticMetaObject, uri, major, minor, "FluStatusLayoutType", "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(FluSheetType::staticMetaObject, uri, major, minor, "FluSheetType", "Access to enums & flags only");
|
||||
|
||||
qmlRegisterModule(uri,major,minor);
|
||||
qmlRegisterModule(uri, major, minor);
|
||||
#endif
|
||||
}
|
||||
|
||||
void FluentUI::initializeEngine(QQmlEngine *engine, const char *uri){
|
||||
engine->rootContext()->setContextProperty("FluApp",FluApp::getInstance());
|
||||
engine->rootContext()->setContextProperty("FluColors",FluColors::getInstance());
|
||||
engine->rootContext()->setContextProperty("FluTheme",FluTheme::getInstance());
|
||||
engine->rootContext()->setContextProperty("FluTools",FluTools::getInstance());
|
||||
engine->rootContext()->setContextProperty("FluTextStyle",FluTextStyle::getInstance());
|
||||
void FluentUI::initializeEngine(QQmlEngine *engine, [[maybe_unused]] const char *uri) {
|
||||
engine->rootContext()->setContextProperty("FluApp", FluApp::getInstance());
|
||||
engine->rootContext()->setContextProperty("FluColors", FluColors::getInstance());
|
||||
engine->rootContext()->setContextProperty("FluTheme", FluTheme::getInstance());
|
||||
engine->rootContext()->setContextProperty("FluTools", FluTools::getInstance());
|
||||
engine->rootContext()->setContextProperty("FluTextStyle", FluTextStyle::getInstance());
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
#ifndef FLUENTUI_H
|
||||
#define FLUENTUI_H
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QQmlEngine>
|
||||
@ -8,18 +7,20 @@
|
||||
/**
|
||||
* @brief The FluentUI class
|
||||
*/
|
||||
class FluentUI : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
SINGLETON(FluentUI)
|
||||
Q_DECL_EXPORT void registerTypes(QQmlEngine *engine);
|
||||
void registerTypes(const char *uri);
|
||||
void initializeEngine(QQmlEngine *engine, const char *uri);
|
||||
private:
|
||||
const int major = 1;
|
||||
const int minor = 0;
|
||||
const char *uri = "FluentUI";
|
||||
};
|
||||
class FluentUI : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
#endif // FLUENTUI_H
|
||||
public:
|
||||
SINGLETON(FluentUI)
|
||||
|
||||
Q_DECL_EXPORT void registerTypes(QQmlEngine *engine);
|
||||
|
||||
void registerTypes(const char *uri) const;
|
||||
|
||||
void initializeEngine(QQmlEngine *engine, [[maybe_unused]] const char *uri);
|
||||
|
||||
private:
|
||||
const int _major = 1;
|
||||
const int _minor = 0;
|
||||
const char *_uri = "FluentUI";
|
||||
};
|
@ -2,18 +2,12 @@
|
||||
|
||||
#include "FluentUI.h"
|
||||
|
||||
FluentUIPlugin::FluentUIPlugin()
|
||||
{
|
||||
FluentUIPlugin::FluentUIPlugin() = default;
|
||||
|
||||
}
|
||||
|
||||
void FluentUIPlugin::registerTypes(const char *uri)
|
||||
{
|
||||
void FluentUIPlugin::registerTypes(const char *uri) {
|
||||
FluentUI::getInstance()->registerTypes(uri);
|
||||
}
|
||||
|
||||
void FluentUIPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
|
||||
{
|
||||
Q_UNUSED(uri)
|
||||
FluentUI::getInstance()->initializeEngine(engine,uri);
|
||||
void FluentUIPlugin::initializeEngine(QQmlEngine *engine, const char *uri) {
|
||||
FluentUI::getInstance()->initializeEngine(engine, uri);
|
||||
}
|
||||
|
@ -1,19 +1,18 @@
|
||||
#ifndef FLUENTUIPLUGIN_H
|
||||
#define FLUENTUIPLUGIN_H
|
||||
#pragma once
|
||||
|
||||
#include <QQmlExtensionPlugin>
|
||||
|
||||
/**
|
||||
* @brief The FluentUIPlugin class
|
||||
*/
|
||||
class FluentUIPlugin : public QQmlExtensionPlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
class FluentUIPlugin : public QQmlExtensionPlugin {
|
||||
Q_OBJECT
|
||||
|
||||
Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid)
|
||||
public:
|
||||
FluentUIPlugin();
|
||||
void registerTypes(const char *uri) Q_DECL_OVERRIDE;
|
||||
void initializeEngine(QQmlEngine *engine, const char *uri) Q_DECL_OVERRIDE;
|
||||
};
|
||||
|
||||
#endif // FLUENTUIPLUGIN_H
|
||||
void registerTypes(const char *uri) Q_DECL_OVERRIDE;
|
||||
|
||||
void initializeEngine(QQmlEngine *engine, const char *uri) Q_DECL_OVERRIDE;
|
||||
};
|
@ -1,18 +1,17 @@
|
||||
#ifndef SINGLETON_H
|
||||
#define SINGLETON_H
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* @brief The Singleton class
|
||||
*/
|
||||
template <typename T>
|
||||
template<typename T>
|
||||
class Singleton {
|
||||
public:
|
||||
static T* getInstance();
|
||||
static T *getInstance();
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
T* Singleton<T>::getInstance() {
|
||||
static T* instance = new T();
|
||||
template<typename T>
|
||||
T *Singleton<T>::getInstance() {
|
||||
static T *instance = new T();
|
||||
return instance;
|
||||
}
|
||||
|
||||
@ -23,5 +22,3 @@ private: \
|
||||
static Class* getInstance() { \
|
||||
return Singleton<Class>::getInstance(); \
|
||||
}
|
||||
|
||||
#endif // SINGLETON_H
|
||||
|
61
src/stdafx.h
61
src/stdafx.h
@ -1,37 +1,50 @@
|
||||
#ifndef STDAFX_H
|
||||
#define STDAFX_H
|
||||
#pragma once
|
||||
|
||||
#define Q_PROPERTY_AUTO(TYPE, M) \
|
||||
#define Q_PROPERTY_AUTO_P(TYPE, M) \
|
||||
Q_PROPERTY(TYPE M MEMBER _##M NOTIFY M##Changed) \
|
||||
public: \
|
||||
Q_SIGNAL void M##Changed(); \
|
||||
void M(TYPE in_##M) \
|
||||
public: \
|
||||
Q_SIGNAL void M##Changed(); \
|
||||
void M(TYPE in_##M) \
|
||||
{ \
|
||||
_##M = in_##M; \
|
||||
Q_EMIT M##Changed(); \
|
||||
_##M = in_##M; \
|
||||
Q_EMIT M##Changed(); \
|
||||
} \
|
||||
TYPE M() \
|
||||
TYPE M() \
|
||||
{ \
|
||||
return _##M; \
|
||||
return _##M; \
|
||||
} \
|
||||
private: \
|
||||
TYPE _##M; \
|
||||
private: \
|
||||
TYPE _##M; \
|
||||
|
||||
#define Q_PROPERTY_AUTO(TYPE, M) \
|
||||
Q_PROPERTY(TYPE M MEMBER _##M NOTIFY M##Changed) \
|
||||
public: \
|
||||
Q_SIGNAL void M##Changed(); \
|
||||
void M(const TYPE& in_##M) \
|
||||
{ \
|
||||
_##M = in_##M; \
|
||||
Q_EMIT M##Changed(); \
|
||||
} \
|
||||
TYPE M() \
|
||||
{ \
|
||||
return _##M; \
|
||||
} \
|
||||
private: \
|
||||
TYPE _##M; \
|
||||
|
||||
|
||||
#define Q_PROPERTY_READONLY_AUTO(TYPE, M) \
|
||||
#define Q_PROPERTY_READONLY_AUTO(TYPE, M) \
|
||||
Q_PROPERTY(TYPE M READ M NOTIFY M##Changed FINAL) \
|
||||
public: \
|
||||
Q_SIGNAL void M##Changed(); \
|
||||
void M(TYPE in_##M) \
|
||||
public: \
|
||||
Q_SIGNAL void M##Changed(); \
|
||||
void M(const TYPE& in_##M) \
|
||||
{ \
|
||||
_##M = in_##M; \
|
||||
Q_EMIT M##Changed(); \
|
||||
_##M = in_##M; \
|
||||
Q_EMIT M##Changed(); \
|
||||
} \
|
||||
TYPE M() \
|
||||
TYPE M() \
|
||||
{ \
|
||||
return _##M; \
|
||||
return _##M; \
|
||||
} \
|
||||
private: \
|
||||
TYPE _##M; \
|
||||
|
||||
#endif // STDAFX_H
|
||||
private: \
|
||||
TYPE _##M; \
|
||||
|
Loading…
Reference in New Issue
Block a user