Compare commits

..

2 Commits

Author SHA1 Message Date
Dylan Liu
e4765ab706
Merge a67c05d763 into 5cfd9824a8 2024-05-30 01:25:47 +00:00
Mentalflow
a67c05d763
Project: Add Qt5QMLPlugin and optimize CMakeLists. 2024-05-30 09:24:28 +08:00
14 changed files with 160 additions and 231 deletions

View File

@ -1,4 +1,4 @@
VS_VERSION_INFO VERSIONINFO
1 VERSIONINFO
FILEVERSION ${GIT_TAG_WITH_COMMA},${GIT_COMMIT_COUNT}
PRODUCTVERSION ${GIT_TAG_WITH_COMMA},${GIT_COMMIT_COUNT}
FILEFLAGSMASK 0x3fL

@ -1 +1 @@
Subproject commit 414c8c3696e2db036a58b8929a69f6e63a1fe8dc
Subproject commit f056abc43282cb7b652aa04e3ee3b0a60f2b85f6

View File

@ -144,7 +144,6 @@ target_link_libraries(${PROJECT_NAME} PRIVATE
Qt${QT_VERSION_MAJOR}::Network
fluentuiplugin
)
#
if (CMAKE_BUILD_TYPE MATCHES "Release")
if (APPLE)

View File

@ -19,20 +19,51 @@
#include "src/helper/InitializrHelper.h"
#include "src/helper/TranslateHelper.h"
#include "src/helper/Network.h"
#include <QDirIterator>
#ifdef FLUENTUI_BUILD_STATIC_LIB
#if (QT_VERSION > QT_VERSION_CHECK(6, 2, 0))
Q_IMPORT_QML_PLUGIN(FluentUIPlugin)
#elif(QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
#include "fluentuiplugin.h"
#if (QT_VERSION < QT_VERSION_CHECK(6, 2, 0))
#define Q_IMPORT_QML_PLUGIN(PLUGIN) \
Q_IMPORT_PLUGIN(PLUGIN)
extern void qml_static_register_types_FluentUI();
#endif
#include <fluentui.h>
Q_IMPORT_QML_PLUGIN(FluentUIPlugin)
#endif
#ifdef WIN32
#include "app_dmp.h"
#endif
void listFiles(const QString &path) {
QDir dir(path);
// 设置过滤器以包括目录和文件,排除符号链接
dir.setFilter(QDir::Files | QDir::Dirs);
// 获取目录和文件信息列表
QFileInfoList list = dir.entryInfoList();
for (const QFileInfo &fileInfo : list) {
if (fileInfo.isDir()) {
// 如果是目录则递归调用listFiles
listFiles(fileInfo.absoluteFilePath());
} else {
// 输出文件名称
qDebug() << "文件名: " << fileInfo.fileName();
QFile file(fileInfo.absoluteFilePath());
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
continue;
QTextStream in(&file);
// 输出文件内容
qDebug() << "文件内容: ";
while (!in.atEnd()) {
QString line = in.readLine();
qDebug() << line;
}
file.close();
}
}
}
int main(int argc, char *argv[])
{
const char *uri = "example";
@ -80,17 +111,16 @@ int main(int argc, char *argv[])
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;
#ifdef FLUENTUI_BUILD_STATIC_LIB
qml_static_register_types_FluentUI();
#endif
TranslateHelper::getInstance()->init(&engine);
engine.rootContext()->setContextProperty("AppInfo",AppInfo::getInstance());
engine.rootContext()->setContextProperty("SettingsHelper",SettingsHelper::getInstance());
engine.rootContext()->setContextProperty("InitializrHelper",InitializrHelper::getInstance());
engine.rootContext()->setContextProperty("TranslateHelper",TranslateHelper::getInstance());
engine.rootContext()->setContextProperty("Network",Network::getInstance());
#ifdef FLUENTUI_BUILD_STATIC_LIB
FluentUI::getInstance()->registerTypes("FluentUI");
#endif
const QUrl url(QStringLiteral("qrc:/example/qml/App.qml"));
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
&app, [url](QObject *obj, const QUrl &objUrl) {

View File

@ -1,5 +1,4 @@
#ifndef SINGLETON_H
#define SINGLETON_H
#pragma once
/**
* @brief The Singleton class
@ -23,5 +22,3 @@ private: \
static Class* getInstance() { \
return Singleton<Class>::getInstance(); \
}
#endif

View File

@ -139,6 +139,7 @@ endif ()
if (${QT_VERSION_MAJOR} LESS 6)
set(__qml_plugin_no_generate_typeinfo ON)
set(__qml_plugin_no_public_sources ON)
include(Qt5QMLPlugin)
endif()
if (FLUENTUI_BUILD_STATIC_LIB)
@ -159,7 +160,7 @@ qt_add_qml_module(${PROJECT_NAME}
)
target_compile_definitions(${PROJECT_NAME}
PUBLIC
PRIVATE
#qrcode
HAVE_CONFIG_H
)
@ -182,7 +183,7 @@ target_link_libraries(${PROJECT_NAME} PUBLIC
)
if(APPLE)
find_library(CARBON_LIBRARY Carbon)
target_link_libraries(${PROJECT_NAME} PUBLIC ${CARBON_LIBRARY})
target_link_libraries(${PROJECT_NAME} PRIVATE ${CARBON_LIBRARY})
elseif(WIN32)
target_link_libraries(${PROJECT_NAME} PUBLIC user32)
elseif(UNIX)
@ -199,7 +200,5 @@ elseif(UNIX)
target_link_libraries(${PROJECT_NAME} PRIVATE X11)
endif()
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
#
install(DIRECTORY ${FLUENTUI_QML_PLUGIN_DIRECTORY} DESTINATION ${CMAKE_INSTALL_PREFIX}/imports)

View File

@ -25,16 +25,20 @@ Q_PROPERTY_AUTO_P(QObject*,launcher)
QML_NAMED_ELEMENT(FluApp)
QML_SINGLETON
#if (QT_VERSION < QT_VERSION_CHECK(6, 2, 0))
public:
#else
private:
#endif
explicit FluApp(QObject *parent = nullptr);
~FluApp() override;
public:
SINGLETON(FluApp)
#if (QT_VERSION >= QT_VERSION_CHECK(6, 2, 0))
static FluApp *create(QQmlEngine *, QJSEngine *) { return getInstance(); }
#endif
Q_INVOKABLE void init(QObject *launcher, QLocale locale = QLocale::system());
[[maybe_unused]] Q_INVOKABLE static QJsonArray iconData(const QString &keyword = "");

View File

@ -49,13 +49,17 @@ Q_PROPERTY_AUTO_P(FluAccentColor*, Green);
QML_NAMED_ELEMENT(FluColors)
QML_SINGLETON
#if (QT_VERSION < QT_VERSION_CHECK(6, 2, 0))
public:
#else
private:
#endif
explicit FluColors(QObject *parent = nullptr);
public:
SINGLETON(FluColors)
[[maybe_unused]] Q_INVOKABLE FluAccentColor *createAccentColor(const QColor &primaryColor);
#if (QT_VERSION >= QT_VERSION_CHECK(6, 2, 0))
static FluColors *create(QQmlEngine *, QJSEngine *) { return getInstance(); }
#endif
[[maybe_unused]] Q_INVOKABLE FluAccentColor *createAccentColor(const QColor &primaryColor);
};

View File

@ -23,11 +23,15 @@ Q_PROPERTY_AUTO(QFont, Display);
QML_NAMED_ELEMENT(FluTextStyle)
QML_SINGLETON
private:
explicit FluTextStyle(QObject *parent = nullptr);
#if (QT_VERSION < QT_VERSION_CHECK(6, 2, 0))
public:
#else
private:
#endif
explicit FluTextStyle(QObject *parent = nullptr);
SINGLETON(FluTextStyle)
#if (QT_VERSION >= QT_VERSION_CHECK(6, 2, 0))
public:
static FluTextStyle *create(QQmlEngine *, QJSEngine *) { return getInstance(); }
#endif
};

View File

@ -41,9 +41,15 @@ Q_PROPERTY_AUTO(bool, blurBehindWindowEnabled);
QML_NAMED_ELEMENT(FluTheme)
QML_SINGLETON
#if (QT_VERSION < QT_VERSION_CHECK(6, 2, 0))
public:
#else
private:
#endif
explicit FluTheme(QObject *parent = nullptr);
#if (QT_VERSION < QT_VERSION_CHECK(6, 2, 0))
private:
#endif
bool eventFilter(QObject *obj, QEvent *event) override;
void refreshColors();
@ -56,10 +62,10 @@ protected:
public:
SINGLETON(FluTheme)
Q_SIGNAL void darkChanged();
#if (QT_VERSION >= QT_VERSION_CHECK(6, 2, 0))
static FluTheme *create(QQmlEngine *, QJSEngine *) { return getInstance(); }
#endif
Q_SIGNAL void darkChanged();
bool dark() const;

View File

@ -15,14 +15,18 @@ Q_OBJECT
QML_NAMED_ELEMENT(FluTools)
QML_SINGLETON
#if (QT_VERSION < QT_VERSION_CHECK(6, 2, 0))
public:
#else
private:
#endif
explicit FluTools(QObject *parent = nullptr);
public:
SINGLETON(FluTools)
#if (QT_VERSION >= QT_VERSION_CHECK(6, 2, 0))
static FluTools *create(QQmlEngine *, QJSEngine *) { return getInstance(); }
#endif
Q_INVOKABLE int qtMajor();
Q_INVOKABLE int qtMinor();

View File

@ -1,87 +0,0 @@
#include "fluentui.h"
#include <QGuiApplication>
#include "Def.h"
#include "FluentIconDef.h"
#include "FluApp.h"
#include "FluColors.h"
#include "FluTheme.h"
#include "FluTools.h"
#include "FluTextStyle.h"
#include "FluWatermark.h"
#include "FluCaptcha.h"
#include "FluTreeModel.h"
#include "FluRectangle.h"
#include "FluQrCodeItem.h"
#include "FluTableSortProxyModel.h"
#include "FluFrameless.h"
#include "FluTableModel.h"
#include "FluHotkey.h"
void FluentUI::registerTypes(QQmlEngine *engine) {
initializeEngine(engine, _uri);
registerTypes(_uri);
}
void FluentUI::registerTypes(const char *uri) const {
#if (QT_VERSION < QT_VERSION_CHECK(6, 2, 0))
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<FluTableModel>(uri, major, minor, "FluTableModel");
qmlRegisterType<FluRectangle>(uri, major, minor, "FluRectangle");
qmlRegisterType<FluFrameless>(uri, major, minor, "FluFrameless");
qmlRegisterType<FluHotkey>(uri, major, minor, "FluHotkey");
qmlRegisterType<FluTableSortProxyModel>(uri, major, minor, "FluTableSortProxyModel");
qmlRegisterUncreatableMetaObject(FluentIcons::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");
qmlRegisterSingletonType(uri, major, minor, "FluApp", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QJSValue {
Q_UNUSED(engine)
return scriptEngine->newQObject(FluApp::getInstance());
});
qmlRegisterSingletonType(uri, major, minor, "FluColors", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QJSValue {
Q_UNUSED(engine)
return scriptEngine->newQObject(FluColors::getInstance());
});
qmlRegisterSingletonType(uri, major, minor, "FluTheme", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QJSValue {
Q_UNUSED(engine)
return scriptEngine->newQObject(FluTheme::getInstance());
});
qmlRegisterSingletonType(uri, major, minor, "FluTools", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QJSValue {
Q_UNUSED(engine)
return scriptEngine->newQObject(FluTools::getInstance());
});
qmlRegisterSingletonType(uri, major, minor, "FluTextStyle", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QJSValue {
Q_UNUSED(engine)
return scriptEngine->newQObject(FluTextStyle::getInstance());
});
// qmlRegisterSingletonInstance(uri, major, minor, "FluApp", FluApp::getInstance());
// qmlRegisterSingletonInstance(uri, major, minor, "FluColors", FluColors::getInstance());
// qmlRegisterSingletonInstance(uri, major, minor, "FluTheme", FluTheme::getInstance());
// qmlRegisterSingletonInstance(uri, major, minor, "FluTools", FluTools::getInstance());
// qmlRegisterSingletonInstance(uri, major, minor, "FluTextStyle", FluTextStyle::getInstance());
#endif
}
void FluentUI::initializeEngine(QQmlEngine *engine, [[maybe_unused]] const char *uri) {
Q_UNUSED(engine)
}

View File

@ -1,28 +0,0 @@
#pragma once
#include <QObject>
#include <QQmlEngine>
#include "singleton.h"
/**
* @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) const;
void initializeEngine(QQmlEngine *engine, [[maybe_unused]] const char *uri);
static FluentUI* instance(){return getInstance();}
private:
const int _major = 1;
const int _minor = 0;
const char *_uri = "FluentUI";
};

View File

@ -1,5 +1,4 @@
#ifndef SINGLETON_H
#define SINGLETON_H
#pragma once
/**
* @brief The Singleton class
@ -23,5 +22,3 @@ private: \
static Class* getInstance() { \
return Singleton<Class>::getInstance(); \
}
#endif