commit 312418aded1134b5ebb01ffddb47736ce4311b8d Author: zhuzihcu Date: Fri Feb 24 18:44:29 2023 +0800 first commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4ef6145 --- /dev/null +++ b/.gitignore @@ -0,0 +1,43 @@ +# C++ objects and libs +*.slo +*.lo +*.o +*.a +*.la +*.lai +*.so +*.dll +*.dylib + +# Qt-es +object_script.*.Release +object_script.*.Debug +*_plugin_import.cpp +/.qmake.cache +/.qmake.stash +*.pro.user +*.pro.user.* +*.qbs.user +*.qbs.user.* +*.moc +moc_*.cpp +moc_*.h +qrc_*.cpp +ui_*.h +*.qmlc +*.jsc +Makefile* +#*build-* + +# Qt unit tests +target_wrapper.* + +# QtCreator +*.autosave + +# QtCreator Qml +*.qmlproject.user +*.qmlproject.user.* + +# QtCreator CMake +CMakeLists.txt.user* diff --git a/FluentUI.pro b/FluentUI.pro new file mode 100644 index 0000000..59eb6a4 --- /dev/null +++ b/FluentUI.pro @@ -0,0 +1,7 @@ +TEMPLATE = subdirs + +SUBDIRS += \ + src/FluentUI.pro \ + example + + example.depends = src/FluentUI.pro diff --git a/README.md b/README.md new file mode 100644 index 0000000..543d6ca Binary files /dev/null and b/README.md differ diff --git a/example/example.pro b/example/example.pro new file mode 100644 index 0000000..631da89 --- /dev/null +++ b/example/example.pro @@ -0,0 +1,46 @@ +QT += quick +CONFIG += c++11 + + +DEFINES += QT_DEPRECATED_WARNINGS QT_NO_WARNING_OUTPUT + +SOURCES += \ + main.cpp + +RESOURCES += qml.qrc + + +qnx: target.path = /tmp/$${TARGET}/bin +else: unix:!android: target.path = /opt/$${TARGET}/bin +!isEmpty(target.path): INSTALLS += target + + + +#### 如果你正在使用静态库.a 那么你还需要将下面的配置注释取消掉。 +#### 其它项目使用方法也是如此。 + +# DEFINES += STATICLIB + +# LIBNAME = FluentUI + +# CONFIG(debug, debug|release) { +# contains(QMAKE_HOST.os,Windows) { +# LIBNAME = FluentUI +# }else{ +# LIBNAME = FluentUI_debug +# } +# } + +# # Additional import path used to resolve QML modules in Qt Creator's code model +# QML_IMPORT_PATH = $$OUT_PWD/../bin/ + +# # Additional import path used to resolve QML modules just for Qt Quick Designer +# QML_DESIGNER_IMPORT_PATH = $$OUT_PWD/../bin/ + +# INCLUDEPATH += $$OUT_PWD/../bin/FluentUI/ +# DEPENDPATH += $$OUT_PWD/../bin/FluentUI/ + +# LIBS += -L$$OUT_PWD/../bin/FluentUI/ -l$${LIBNAME} +# PRE_TARGETDEPS += $$OUT_PWD/../bin/FluentUI/lib$${LIBNAME}.a + +### 注意:静态库 .so .dylib .dll 是自动安装的Qt qml plugin目录中,不需要此步配置 diff --git a/example/main.cpp b/example/main.cpp new file mode 100644 index 0000000..1bcd2cb --- /dev/null +++ b/example/main.cpp @@ -0,0 +1,22 @@ +#include +#include +#include +#include + +int main(int argc, char *argv[]) +{ + clock_t start,finish; + double totaltime; + start=clock(); + qputenv("QSG_RENDER_LOOP","basic"); + QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); + QGuiApplication app(argc, argv); + QQmlApplicationEngine engine; + engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); + if (engine.rootObjects().isEmpty()) + return -1; + finish=clock(); + totaltime=(double)(finish-start)/CLOCKS_PER_SEC; + qDebug() << "startup time :" << totaltime << "s"; + return app.exec(); +} diff --git a/example/main.qml b/example/main.qml new file mode 100644 index 0000000..009b412 --- /dev/null +++ b/example/main.qml @@ -0,0 +1,31 @@ +import QtQuick 2.15 +import QtQuick.Window 2.15 +import QtQuick.Layouts 1.15 +import FluentUI 1.0 + +Window { + id:rootwindow + visible: true + width: 480 + height: 700 + + ColumnLayout{ + spacing: 5 + + FluentUI{ + width: 20 + height: 20 + } + + StandardButton{ + + } + + FilledButton{ + + } + + } + + +} diff --git a/example/qml.qrc b/example/qml.qrc new file mode 100644 index 0000000..5f6483a --- /dev/null +++ b/example/qml.qrc @@ -0,0 +1,5 @@ + + + main.qml + + diff --git a/src/FluentUI.cpp b/src/FluentUI.cpp new file mode 100644 index 0000000..3a77c67 --- /dev/null +++ b/src/FluentUI.cpp @@ -0,0 +1,27 @@ +#include "FluentUI.h" + +#include + +FluentUI::FluentUI(QQuickItem *parent) + : QQuickPaintedItem(parent) +{ + // By default, QQuickItem does not draw anything. If you subclass + // QQuickItem to create a visual item, you will need to uncomment the + // following line and re-implement updatePaintNode() + + // setFlag(ItemHasContents, true); +} + +void FluentUI::paint(QPainter *painter) +{ + QPen pen(QColorConstants::Red, 2); + QBrush brush(QColorConstants::Red); + + painter->setPen(pen); + painter->setBrush(brush); + painter->drawRect(0, 0, 100, 100); +} + +FluentUI::~FluentUI() +{ +} diff --git a/src/FluentUI.h b/src/FluentUI.h new file mode 100644 index 0000000..f6383e7 --- /dev/null +++ b/src/FluentUI.h @@ -0,0 +1,19 @@ +#ifndef FLUENTUI_H +#define FLUENTUI_H + +#include + +class FluentUI : public QQuickPaintedItem +{ + Q_OBJECT + QML_ELEMENT + Q_DISABLE_COPY(FluentUI) +public: + explicit FluentUI(QQuickItem *parent = nullptr); + void paint(QPainter *painter) override; + ~FluentUI() override; +signals: + +}; + +#endif // FLUENTUI_H diff --git a/src/FluentUI.pro b/src/FluentUI.pro new file mode 100644 index 0000000..d4d3330 --- /dev/null +++ b/src/FluentUI.pro @@ -0,0 +1,44 @@ +QT += qml quick svg +CONFIG += plugin c++11 +TEMPLATE = lib +TARGET = FluentUI +TARGET = $$qtLibraryTarget($$TARGET) +uri = FluentUI + +########################################## +CONFIG += sharedlib # staticlib or sharedlib +#** 多次切换编译构建模式,建议先清理缓存。项目右键->清理 + +#*[staticlib] 构建静态库.a +#需要修改example.pro,请打开后按说明操作 + +#*[sharedlib] 构建动态库 .dll .so .dylib +#会自动安装到Qt qmlplugin目录中 +#无需其它配置即可运行demo以及其它项目中使用 +#发布目标平台前必须每个平台都要构建一次。 +########################################## + +RESOURCES += \ + res.qrc + + +# Input +HEADERS += \ + FluentUI.h \ + qml_plugin.h \ + + +SOURCES += \ + FluentUI.cpp \ + qml_plugin.cpp \ + + + +DEFINES += VERSION_IN=\\\"1.0.0\\\" +DEFINES += URI_STR=\\\"$$uri\\\" + +contains(QMAKE_HOST.os,Windows) { + include(./build_windows.pri) +}else{ + include(./build_macos.pri) +} diff --git a/src/build-preset/qmldir b/src/build-preset/qmldir new file mode 100644 index 0000000..8c51907 --- /dev/null +++ b/src/build-preset/qmldir @@ -0,0 +1,4 @@ +module FluentUI +plugin FluentUI +classname FluentUIQmlPlugin +typeinfo plugin.qmltypes diff --git a/src/build_macos.pri b/src/build_macos.pri new file mode 100644 index 0000000..dc26c30 --- /dev/null +++ b/src/build_macos.pri @@ -0,0 +1,17 @@ +OUTP = $$OUT_PWD/../bin/FluentUI/ + +DESTDIR += $$OUTP + +QMAKE_MOC_OPTIONS += -Muri=$$uri +QMAKE_PRE_LINK += chmod -R 777 $$PWD/macos_install.sh; +QMAKE_PRE_LINK += $$PWD/macos_install.sh PRESET $$PWD/ $$OUTP; + +CONFIG(sharedlib){ + INST_QMLPATH = $$[QT_INSTALL_QML]/$$replace(uri, \\., /) + + QMAKE_POST_LINK += $$PWD/macos_install.sh INSTALL $$PWD/ $$OUTP $$INST_QMLPATH; + + exists($$PWD/../../dev.pri){ + include($$PWD/../../dev.pri) + } +} diff --git a/src/build_windows.pri b/src/build_windows.pri new file mode 100644 index 0000000..0d2eba3 --- /dev/null +++ b/src/build_windows.pri @@ -0,0 +1,32 @@ +OUTP = $$OUT_PWD/../bin/FluentUI +BUILDBIN_PATH = $$replace(OUTP, src/../bin, bin) +QTQMLFLUENT_PATH = $$[QT_INSTALL_QML]/FluentUI +PRESET_PATH = $$PWD/build-preset +SOLIBFILE_PATH = $$OUT_PWD/libFluentUI.so +ANDROID = NO + +#QT_BIN_PATH = $$[QT_INSTALL_BINS] +#PLUGIN_NAME = $$uri +#PLUGIN_VERSION = "1.0" +#PLUGIN_PARENT_PATH = $$BUILD_ROOT/build-preset/plugins +#PLUGIN_QMLTYPES_PATH = $$BUILD_ROOT/build-preset/plugins/$$uri/plugin.qmltypes + +android{ + ANDROID=YES + QMAKE_PRE_LINK *= md $$replace(OUTP, /, \\) +}else{ + DESTDIR += $$OUTP +} + +#QMLTYPESSCRIPT = "$$PWD\create_qmltypes.bat" "$$QT_BIN_PATH" "$$PLUGIN_NAME" "$$PLUGIN_VERSION" "$$PLUGIN_PARENT_PATH" "$$PLUGIN_QMLTYPES_PATH" +SHAREDSCRIPT = "$$PWD\win_install.bat" SHARED "$$PWD" "$$PRESET_PATH" "$$BUILDBIN_PATH" "$$QTQMLFLUENT_PATH" $$ANDROID "$$SOLIBFILE_PATH" +STATICSCRIPT = "$$PWD\win_install.bat" STATIC "$$PWD" "$$PRESET_PATH" "$$BUILDBIN_PATH" "$$QTQMLFLUENT_PATH" $$ANDROID "$$SOLIBFILE_PATH" + +#QMAKE_POST_LINK *= $$replace(QMLTYPESSCRIPT, /, \\) + +CONFIG(sharedlib){ + QMAKE_POST_LINK *= $$replace(SHAREDSCRIPT, /, \\) +} +else{ + QMAKE_POST_LINK *= $$replace(STATICSCRIPT, /, \\) +} diff --git a/src/controls/FilledButton.qml b/src/controls/FilledButton.qml new file mode 100644 index 0000000..0591ae1 --- /dev/null +++ b/src/controls/FilledButton.qml @@ -0,0 +1,28 @@ +//@uri FluentUI +import QtQuick 2.15 +import QtQuick.Controls 2.15 +import QtQuick.Controls.Material 2.15 + +Rectangle { + id: button + width: 100 + height: 40 + radius: 4 + color: Material.accent + border.color: Material.accent + + Text { + id: buttonText + text: "Button" + color: "white" + font.pixelSize: 14 + anchors.centerIn: parent + } + + MouseArea { + anchors.fill: parent + onClicked: { + console.log("Button clicked") + } + } +} diff --git a/src/controls/StandardButton.qml b/src/controls/StandardButton.qml new file mode 100644 index 0000000..edd7f46 --- /dev/null +++ b/src/controls/StandardButton.qml @@ -0,0 +1,40 @@ +import QtQuick 2.15 +import QtQuick.Controls 2.15 +import QtQuick.Controls.Material 2.15 + +Rectangle { + id: button + + property int startPadding : 15 + property int endPadding : 15 + property int topPadding: 8 + property int bottomPadding: 8 + property bool disabled: false + radius: 4 + color: "#FFFFFF" + + width: childrenRect.width + height: childrenRect.height + + border.color: "#eeeeee" + border.width: 1 + + Text { + id: buttonText + text: "Standard Button" + color: "#000000" + font.pixelSize: 13 + leftPadding: button.startPadding + rightPadding: button.endPadding + topPadding: button.topPadding + bottomPadding: button.bottomPadding + anchors.centerIn: parent + } + + MouseArea { + anchors.fill: parent + onClicked: { + console.log("Button clicked") + } + } +} diff --git a/src/create_qmltypes.bat b/src/create_qmltypes.bat new file mode 100644 index 0000000..c336a48 --- /dev/null +++ b/src/create_qmltypes.bat @@ -0,0 +1,16 @@ + +SET QT_BIN_PATH=%1 +SET BAT_PLUGIN_NAME=%2 +SET BAT_PLUGIN_VERSION=%3 +SET BAT_PLUGIN_PARENT_PATH=%4 +SET BAT_PLUGIN_QMLTYPES_PATH=%5 + +echo "------create_qmltypes-------" +echo %QT_BIN_PATH% +echo %BAT_PLUGIN_NAME% +echo %BAT_PLUGIN_VERSION% +echo %BAT_PLUGIN_PARENT_PATH% +echo %BAT_PLUGIN_QMLTYPES_PATH% +echo "-------------" + +%QT_BIN_PATH%\qmlplugindump.exe -nonrelocatable %BAT_PLUGIN_NAME% %BAT_PLUGIN_VERSION% %BAT_PLUGIN_PARENT_PATH% > %BAT_PLUGIN_QMLTYPES_PATH% \ No newline at end of file diff --git a/src/macos_install.sh b/src/macos_install.sh new file mode 100644 index 0000000..ba24611 --- /dev/null +++ b/src/macos_install.sh @@ -0,0 +1,14 @@ +RUN_TYPE=$1 +PRESET_PATH=$2 +BUILDER_BIN_PATH=$3 +QT_QML_FLUENT_PATH=$4 + +echo ${RUN_TYPE} +if [ ${RUN_TYPE} = "PRESET" ]; then +cp -r ${PRESET_PATH}/FluentUI.h ${BUILDER_BIN_PATH} +cp -r ${PRESET_PATH}/build-preset/* ${BUILDER_BIN_PATH} +else +rm -rf ${QT_QML_FLUENT_PATH=} +mkdir -pv ${QT_QML_FLUENT_PATH=} +cp -r ${BUILDER_BIN_PATH}/* ${QT_QML_FLUENT_PATH=} +fi diff --git a/src/qml_plugin.cpp b/src/qml_plugin.cpp new file mode 100644 index 0000000..22f9f79 --- /dev/null +++ b/src/qml_plugin.cpp @@ -0,0 +1,16 @@ +#include "qml_plugin.h" + +void FluentUIQmlPlugin::registerTypes(const char *uri) +{ + int major = 1; + int minor = 0; + qmlRegisterType(uri, major, minor, "FluentUI"); + qmlRegisterType(QUrl("qrc:/com.zzc/controls/StandardButton.qml"),uri,major,minor,"StandardButton"); + qmlRegisterType(QUrl("qrc:/com.zzc/controls/FilledButton.qml"),uri,major,minor,"FilledButton"); +} + +void FluentUIQmlPlugin::initializeEngine(QQmlEngine *engine, const char *uri) +{ + +} + diff --git a/src/qml_plugin.h b/src/qml_plugin.h new file mode 100644 index 0000000..aed9d59 --- /dev/null +++ b/src/qml_plugin.h @@ -0,0 +1,15 @@ +#pragma once + +#include +#include + +class FluentUIQmlPlugin : public QQmlExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid) + +public: + void registerTypes(const char *uri) override; + + void initializeEngine(QQmlEngine *engine, const char *uri) override; +}; diff --git a/src/res.qrc b/src/res.qrc new file mode 100644 index 0000000..bfe82c2 --- /dev/null +++ b/src/res.qrc @@ -0,0 +1,6 @@ + + + controls/StandardButton.qml + controls/FilledButton.qml + + diff --git a/src/win_install.bat b/src/win_install.bat new file mode 100644 index 0000000..d551641 --- /dev/null +++ b/src/win_install.bat @@ -0,0 +1,25 @@ + +SET PWD_PATH=%2 +SET PRESET_PATH=%3 +SET BUILDER_BIN_PATH=%4 +SET QT_QML_FLUENT_PATH=%5 +SET ANDROID=%6 +SET LIBFILE_PATH=%7 + +echo "--------win_install-------" +echo %RUN_TYPE% +echo %PWD_PATH% +echo %PRESET_PATH% +echo %BUILDER_BIN_PATH% +echo %QT_QML_FLUENT_PATH% +echo "--------------------------" + +copy /y %PWD_PATH%\Toou2D.h %BUILDER_BIN_PATH% & copy /y %PRESET_PATH%\* %BUILDER_BIN_PATH%\ + +if %ANDROID% == YES copy /y %LIBFILE_PATH% %BUILDER_BIN_PATH% + +if %1 == SHARED ( + echo running install to qtqml folder + rmdir /s /q %QT_QML_FLUENT_PATH% & md %QT_QML_FLUENT_PATH% + copy /y %BUILDER_BIN_PATH% %QT_QML_FLUENT_PATH% +) \ No newline at end of file