diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index c0453234..c1e8f99a 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -49,13 +49,9 @@ configure_file( ) #遍历所有Cpp文件 - -message("---------->${filename}") file(GLOB_RECURSE CPP_FILES *.cpp *.h) foreach(filepath ${CPP_FILES}) string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/" "" filename ${filepath}) - - message(${filename}) list(APPEND sources_files ${filename}) endforeach(filepath) diff --git a/example/example.qrc b/example/example.qrc index 88bdf47f..b2584b92 100644 --- a/example/example.qrc +++ b/example/example.qrc @@ -181,8 +181,6 @@ res/image/image_1.jpg qml/window/PageWindow.qml qml/page/T_StaggeredLayout.qml - qml/viewmodel/SettingsViewModel.qml - qml/viewmodel/TextBoxViewModel.qml qml/page/T_Clip.qml qml/page/T_3D.qml qml/page/T_Network.qml @@ -208,5 +206,6 @@ res/template/src/qml.qrc.in res/template/src/zh_CN.ts.in res/template/src/README.md.in + qml/global/GlobalModel.qml diff --git a/example/example_en_US.ts b/example/example_en_US.ts index e3d09e49..b93f39d1 100644 --- a/example/example_en_US.ts +++ b/example/example_en_US.ts @@ -535,104 +535,104 @@ MainWindow - + Dark Mode - - + + Quit - + Are you sure you want to exit the program? - + Minimize - + Friendly Reminder - + FluentUI is hidden from the tray, click on the tray to activate the window again - - + + Cancel - + Open in Separate Window - + Click Time - + Search - + Finish - + Next - + Previous - + Here you can switch to night mode. - + Hide Easter eggs - + Try a few more clicks!! - + Upgrade Tips - + FluentUI is currently up to date - + -- The current app version - + Now go and download the new version? @@ -641,17 +641,17 @@ Updated content: - + OK - + The current version is already the latest - + The network is abnormal @@ -1521,46 +1521,46 @@ My only desire is to be permitted to drive out the traitors and restore the Han. T_MultiWindow - + MultiWindow - + <font color='red'>Standard</font> mode window,a new window is created every time - - - - - + + + + + Create Window - + <font color='red'>SingleTask</font> mode window,If a window exists, this activates the window - + <font color='red'>SingleInstance</font> mode window,If the window exists, destroy the window and create a new window - + Create the window without carrying any parameters - + Create a window with the parameter username: zhuzichu - + Login Window Returned Password - > @@ -1735,97 +1735,97 @@ My only desire is to be permitted to drive out the traitors and restore the Han. T_Settings - + Settings - + Current Version - + Check for Updates - + Use System AppBar - + Fits AppBar Windows - + Friendly Reminder - + This action requires a restart of the program to take effect, is it restarted? - + Cancel - + OK - + Dark Mode - + System - + Light - + Dark - + Navigation View Display Mode - + Open - + Compact - + Minimal - + Auto - + Language @@ -2023,36 +2023,36 @@ My only desire is to be permitted to drive out the traitors and restore the Han. T_TextBox - + TextBox - + Single-line Input Box - - - - - + + + + + Disabled - + Please enter your password - + Multi-line Input Box - + AutoSuggestBox diff --git a/example/example_zh_CN.ts b/example/example_zh_CN.ts index 01ca4e79..9413d3de 100644 --- a/example/example_zh_CN.ts +++ b/example/example_zh_CN.ts @@ -535,104 +535,104 @@ MainWindow - + Dark Mode 夜间模式 - - + + Quit 退出 - + Are you sure you want to exit the program? 您确定要退出程序吗 - + Minimize 最小化 - + Friendly Reminder 友情提示 - + FluentUI is hidden from the tray, click on the tray to activate the window again FluentUI 在托盘中处于隐藏状态,单击托盘以再次激活窗口 - - + + Cancel 取消 - + Open in Separate Window 在独立窗口中打开 - + Click Time 点击次数 - + Search 搜索 - + Finish 完成 - + Next 下一步 - + Previous 上一步 - + Here you can switch to night mode. 在这里,您可以切换到夜间模式。 - + Hide Easter eggs 隐藏彩蛋 - + Try a few more clicks!! 再试几下!! - + Upgrade Tips 升级提示 - + FluentUI is currently up to date FluentUI 目前最新版本 - + -- The current app version -- 当前应用版本 - + Now go and download the new version? @@ -645,17 +645,17 @@ Updated content: - + OK 确定 - + The current version is already the latest 当前版本已经是最新版本 - + The network is abnormal 网络异常 @@ -1561,46 +1561,46 @@ My only desire is to be permitted to drive out the traitors and restore the Han. T_MultiWindow - + MultiWindow 多窗口 - + <font color='red'>Standard</font> mode window,a new window is created every time <font color='red'>Standard</font> 模式窗口,每次都会创建新窗口 - - - - - + + + + + Create Window 创建窗口 - + <font color='red'>SingleTask</font> mode window,If a window exists, this activates the window <font color='red'>SingleTask</font> 模式窗口,如果窗口存在,这激活该窗口 - + <font color='red'>SingleInstance</font> mode window,If the window exists, destroy the window and create a new window <font color='red'>SingleInstance</font> 模式窗口,如果窗口存在,则销毁窗口,然后新建窗口 - + Create the window without carrying any parameters 创建一个窗口,不携带任何参数 - + Create a window with the parameter username: zhuzichu 创建一个窗口,并携带参数用户名:zhuzichu - + Login Window Returned Password - > 登录窗口返回过来的密码 - > @@ -1785,97 +1785,97 @@ My only desire is to be permitted to drive out the traitors and restore the Han. T_Settings - + Settings 设置 - + Current Version 当前版本 - + Check for Updates 检查更新 - + Use System AppBar 使用系统应用栏 - + Fits AppBar Windows 沉浸式应用栏 - + Friendly Reminder 友情提示 - + This action requires a restart of the program to take effect, is it restarted? 此操作需要重启程序才能生效,是否重新启动? - + Cancel 取消 - + OK 确定 - + Dark Mode 夜间模式 - + System 跟随系统 - + Light 浅色 - + Dark 深色 - + Navigation View Display Mode 导航视图 - + Open 开放 - + Compact 紧凑 - + Minimal 极简 - + Auto 自动 - + Language 语言 @@ -2093,36 +2093,36 @@ My only desire is to be permitted to drive out the traitors and restore the Han. T_TextBox - + TextBox 文本框 - + Single-line Input Box 单行输入框 - - - - - + + + + + Disabled 禁用 - + Please enter your password 请输入您的密码 - + Multi-line Input Box 多行输入框 - + AutoSuggestBox 自动建议框 diff --git a/example/qml/App.qml b/example/qml/App.qml index afd57f81..65022265 100644 --- a/example/qml/App.qml +++ b/example/qml/App.qml @@ -4,30 +4,26 @@ import QtQuick.Controls 2.15 import QtQuick.Layouts 1.15 import FluentUI 1.0 -Item { +FluLauncher { id: app - Connections{ target: FluTheme function onDarkModeChanged(){ SettingsHelper.saveDarkMode(FluTheme.darkMode) } } - Connections{ target: FluApp function onUseSystemAppBarChanged(){ SettingsHelper.saveUseSystemAppBar(FluApp.useSystemAppBar) } } - Connections{ target: TranslateHelper function onCurrentChanged(){ SettingsHelper.saveLanguage(TranslateHelper.current) } } - Component.onCompleted: { FluNetwork.openLog = false FluNetwork.setInterceptor(function(param){ @@ -38,7 +34,7 @@ Item { FluApp.useSystemAppBar = SettingsHelper.getUseSystemAppBar() FluTheme.darkMode = SettingsHelper.getDarkMode() FluTheme.enableAnimation = true - FluApp.routes = { + FluRouter.routes = { "/":"qrc:/example/qml/window/MainWindow.qml", "/about":"qrc:/example/qml/window/AboutWindow.qml", "/login":"qrc:/example/qml/window/LoginWindow.qml", @@ -51,9 +47,9 @@ Item { } var args = Qt.application.arguments if(args.length>=2 && args[1].startsWith("-crashed=")){ - FluApp.navigate("/crash",{crashFilePath:args[1].replace("-crashed=","")}) + FluRouter.navigate("/crash",{crashFilePath:args[1].replace("-crashed=","")}) }else{ - FluApp.navigate("/") + FluRouter.navigate("/") } } } diff --git a/example/qml/global/GlobalModel.qml b/example/qml/global/GlobalModel.qml new file mode 100644 index 00000000..c266cb77 --- /dev/null +++ b/example/qml/global/GlobalModel.qml @@ -0,0 +1,10 @@ +pragma Singleton + +import QtQuick 2.15 +import FluentUI 1.0 + +QtObject{ + + property int displayMode: FluNavigationViewType.Auto + +} diff --git a/example/qml/global/ItemsFooter.qml b/example/qml/global/ItemsFooter.qml index 7b510e5f..2a8e6d1d 100644 --- a/example/qml/global/ItemsFooter.qml +++ b/example/qml/global/ItemsFooter.qml @@ -16,7 +16,7 @@ FluObject{ title:qsTr("About") icon:FluentIcons.Contact onTapListener:function(){ - FluApp.navigate("/about") + FluRouter.navigate("/about") } } diff --git a/example/qml/global/ItemsOriginal.qml b/example/qml/global/ItemsOriginal.qml index 25f6fb2a..6c63cc20 100644 --- a/example/qml/global/ItemsOriginal.qml +++ b/example/qml/global/ItemsOriginal.qml @@ -462,7 +462,7 @@ FluObject{ FluPaneItem{ title: qsTr("Hot Loader") onTapListener: function(){ - FluApp.navigate("/hotload") + FluRouter.navigate("/hotload") } } FluPaneItem{ diff --git a/example/qml/global/qmldir b/example/qml/global/qmldir index eb6bfeaf..f8f31759 100644 --- a/example/qml/global/qmldir +++ b/example/qml/global/qmldir @@ -1,2 +1,3 @@ -singleton ItemsOriginal 1.0 ItemsOriginal.qml +singleton ItemsOriginal 1.0 ItemsOriginal.qml singleton ItemsFooter 1.0 ItemsFooter.qml +singleton GlobalModel 1.0 GlobalModel.qml diff --git a/example/qml/page/T_MultiWindow.qml b/example/qml/page/T_MultiWindow.qml index cdde41c2..ee98b72d 100644 --- a/example/qml/page/T_MultiWindow.qml +++ b/example/qml/page/T_MultiWindow.qml @@ -8,16 +8,17 @@ import "../component" FluScrollablePage{ property string password: "" - property var loginPageRegister: registerForWindowResult("/login") title: qsTr("MultiWindow") - Connections{ - target: loginPageRegister - function onResult(data) - { - password = data.password - } + FluWindowResultLauncher{ + id:loginResultLauncher + path: "/login" + onResult: + (data)=>{ + password = data.password + } + } FluArea{ @@ -37,7 +38,7 @@ FluScrollablePage{ FluButton{ text: qsTr("Create Window") onClicked: { - FluApp.navigate("/standardWindow") + FluRouter.navigate("/standardWindow") } } } @@ -61,7 +62,7 @@ FluScrollablePage{ FluButton{ text: qsTr("Create Window") onClicked: { - FluApp.navigate("/singleTaskWindow") + FluRouter.navigate("/singleTaskWindow") } } } @@ -84,7 +85,7 @@ FluScrollablePage{ FluButton{ text: qsTr("Create Window") onClicked: { - FluApp.navigate("/singleInstanceWindow") + FluRouter.navigate("/singleInstanceWindow") } } } @@ -118,7 +119,7 @@ FluScrollablePage{ FluButton{ text: qsTr("Create Window") onClicked: { - FluApp.navigate("/about") + FluRouter.navigate("/about") } } } @@ -129,7 +130,7 @@ FluScrollablePage{ code:'FluButton{ text: qsTr("Create Window") onClicked: { - FluApp.navigate("/about") + FluRouter.navigate("/about") } } ' @@ -153,7 +154,7 @@ FluScrollablePage{ FluButton{ text: qsTr("Create Window") onClicked: { - loginPageRegister.launch({username:"zhuzichu"}) + loginResultLauncher.launch({username:"zhuzichu"}) } } FluText{ diff --git a/example/qml/page/T_Settings.qml b/example/qml/page/T_Settings.qml index 85e93fab..a36fd0e1 100644 --- a/example/qml/page/T_Settings.qml +++ b/example/qml/page/T_Settings.qml @@ -4,17 +4,12 @@ import QtQuick.Window 2.15 import QtQuick.Controls 2.15 import FluentUI 1.0 import "../component" -import "../viewmodel" import "../global" FluScrollablePage{ title: qsTr("Settings") - SettingsViewModel{ - id:viewmodel_settings - } - FluEvent{ id:event_checkupdate_finish name: "checkUpdateFinish" @@ -95,7 +90,7 @@ FluScrollablePage{ negativeText: qsTr("Cancel") positiveText: qsTr("OK") onPositiveClicked: { - FluApp.exit(931) + FluRouter.exit(931) } } @@ -149,10 +144,10 @@ FluScrollablePage{ Repeater{ model: [{title:qsTr("Open"),mode:FluNavigationViewType.Open},{title:qsTr("Compact"),mode:FluNavigationViewType.Compact},{title:qsTr("Minimal"),mode:FluNavigationViewType.Minimal},{title:qsTr("Auto"),mode:FluNavigationViewType.Auto}] delegate: FluRadioButton{ - checked : viewmodel_settings.displayMode===modelData.mode - text:modelData.title + text: modelData.title + checked: GlobalModel.displayMode === modelData.mode clickListener:function(){ - viewmodel_settings.displayMode = modelData.mode + GlobalModel.displayMode = modelData.mode } } } diff --git a/example/qml/page/T_TextBox.qml b/example/qml/page/T_TextBox.qml index 6517b0ad..a76dcf92 100644 --- a/example/qml/page/T_TextBox.qml +++ b/example/qml/page/T_TextBox.qml @@ -4,16 +4,11 @@ import QtQuick.Layouts 1.15 import QtQuick.Window 2.15 import FluentUI 1.0 import "../component" -import "../viewmodel" FluScrollablePage{ title: qsTr("TextBox") - TextBoxViewModel{ - id:viewModel - } - FluArea{ Layout.fillWidth: true height: 68 @@ -24,10 +19,6 @@ FluScrollablePage{ placeholderText: qsTr("Single-line Input Box") disabled: text_box_switch.checked cleanEnabled: true - text: viewModel.text1 - onTextChanged: { - viewModel.text1 = text - } anchors{ verticalCenter: parent.verticalCenter left: parent.left @@ -82,7 +73,6 @@ FluScrollablePage{ }' } - FluArea{ Layout.fillWidth: true height: 36+multiine_textbox.height @@ -92,10 +82,6 @@ FluScrollablePage{ FluMultilineTextBox{ id: multiine_textbox placeholderText: qsTr("Multi-line Input Box") - text:viewModel.text2 - onTextChanged: { - viewModel.text2 = text - } disabled: text_box_multi_switch.checked anchors{ verticalCenter: parent.verticalCenter diff --git a/example/qml/viewmodel/SettingsViewModel.qml b/example/qml/viewmodel/SettingsViewModel.qml deleted file mode 100644 index c88de599..00000000 --- a/example/qml/viewmodel/SettingsViewModel.qml +++ /dev/null @@ -1,14 +0,0 @@ -import QtQuick 2.15 -import FluentUI 1.0 - -FluViewModel{ - - objectName: "SettingsViewModel" - scope: FluViewModelType.Application - property int displayMode - - onInitData: { - displayMode = FluNavigationViewType.Auto - } - -} diff --git a/example/qml/viewmodel/TextBoxViewModel.qml b/example/qml/viewmodel/TextBoxViewModel.qml deleted file mode 100644 index 4dbaa97e..00000000 --- a/example/qml/viewmodel/TextBoxViewModel.qml +++ /dev/null @@ -1,8 +0,0 @@ -import QtQuick 2.15 -import FluentUI 1.0 - -FluViewModel { - objectName: "TextBoxView" - property string text1 - property string text2 -} diff --git a/example/qml/window/AboutWindow.qml b/example/qml/window/AboutWindow.qml index 747f4a71..a58a2c90 100644 --- a/example/qml/window/AboutWindow.qml +++ b/example/qml/window/AboutWindow.qml @@ -31,7 +31,7 @@ FluWindow { MouseArea{ anchors.fill: parent onClicked: { - FluApp.navigate("/") + FluRouter.navigate("/") } } } diff --git a/example/qml/window/CrashWindow.qml b/example/qml/window/CrashWindow.qml index 254c8330..b70fa0d5 100644 --- a/example/qml/window/CrashWindow.qml +++ b/example/qml/window/CrashWindow.qml @@ -71,7 +71,7 @@ FluWindow { FluFilledButton{ text: qsTr("Restart Program") onClicked: { - FluApp.exit(931) + FluRouter.exit(931) } } } diff --git a/example/qml/window/LoginWindow.qml b/example/qml/window/LoginWindow.qml index abdcd51b..48c1fd34 100644 --- a/example/qml/window/LoginWindow.qml +++ b/example/qml/window/LoginWindow.qml @@ -51,7 +51,7 @@ FluWindow { showError(qsTr("Please feel free to enter a password")) return } - onResult({password:textbox_password.text}) + setResult({password:textbox_password.text}) window.close() } } diff --git a/example/qml/window/MainWindow.qml b/example/qml/window/MainWindow.qml index fafed3b8..df673acc 100644 --- a/example/qml/window/MainWindow.qml +++ b/example/qml/window/MainWindow.qml @@ -7,7 +7,6 @@ import Qt.labs.platform 1.1 import FluentUI 1.0 import example 1.0 import "../component" -import "../viewmodel" import "../global" FluWindow { @@ -29,10 +28,6 @@ FluWindow { z:7 } - SettingsViewModel{ - id:viewmodel_settings - } - FluEvent{ id:event_checkupdate name: "checkUpdate" @@ -60,6 +55,7 @@ FluWindow { Component.onDestruction: { FluEventBus.unRegisterEvent(event_checkupdate) + FluRouter.exit() } SystemTrayIcon { @@ -71,7 +67,7 @@ FluWindow { MenuItem { text: "退出" onTriggered: { - FluApp.exit() + FluRouter.exit() } } } @@ -106,7 +102,7 @@ FluWindow { positiveText: qsTr("Quit") neutralText: qsTr("Cancel") onPositiveClicked:{ - FluApp.exit(0) + FluRouter.exit(0) } } @@ -118,7 +114,7 @@ FluWindow { text: qsTr("Open in Separate Window") font.pixelSize: 12 onClicked: { - FluApp.navigate("/pageWindow",{title:modelData.title,url:modelData.url}) + FluRouter.navigate("/pageWindow",{title:modelData.title,url:modelData.url}) } } } @@ -197,7 +193,7 @@ FluWindow { z:999 //Stack模式,每次切换都会将页面压入栈中,随着栈的页面增多,消耗的内存也越多,内存消耗多就会卡顿,这时候就需要按返回将页面pop掉,释放内存。该模式可以配合FluPage中的launchMode属性,设置页面的启动模式 // pageMode: FluNavigationViewType.Stack - //NoStack模式,每次切换都会销毁之前的页面然后创建一个新的页面,只需消耗少量内存,可以配合FluViewModel保存页面数据(推荐) + //NoStack模式,每次切换都会销毁之前的页面然后创建一个新的页面,只需消耗少量内存 pageMode: FluNavigationViewType.NoStack items: ItemsOriginal footerItems:ItemsFooter @@ -207,7 +203,7 @@ FluWindow { } return FluTools.isMacos() ? 20 : 0 } - displayMode:viewmodel_settings.displayMode + displayMode: GlobalModel.displayMode logo: "qrc:/example/res/image/favicon.ico" title:"FluentUI" onLogoClicked:{ diff --git a/example/res/template/src/App.qml.in b/example/res/template/src/App.qml.in index c4c2b66c..a79eba28 100644 --- a/example/res/template/src/App.qml.in +++ b/example/res/template/src/App.qml.in @@ -12,6 +12,6 @@ Item { FluApp.routes = { "/":"qrc:/main.qml", } - FluApp.navigate("/") + FluRouter.navigate("/") } } diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8d789d51..fee94def 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -73,11 +73,15 @@ if(QT_VERSION VERSION_GREATER_EQUAL "6.2") endif() #遍历所有qml文件 - file(GLOB_RECURSE QML_PATHS *.qml) + file(GLOB_RECURSE QML_PATHS *.qml qmldir) foreach(filepath ${QML_PATHS}) if(${filepath} MATCHES "Qt${QT_VERSION_MAJOR}/") string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/" "" filename ${filepath}) - list(APPEND qml_files ${filename}) + if(${filename} MATCHES "qmldir") + list(APPEND resource_files ${filename}) + else() + list(APPEND qml_files ${filename}) + endif() endif() endforeach(filepath) diff --git a/src/Def.h b/src/Def.h index 1ede0054..827eb344 100644 --- a/src/Def.h +++ b/src/Def.h @@ -4,16 +4,6 @@ #include #include -namespace FluViewModelType { -Q_NAMESPACE -enum Scope { - Window = 0x0000, - Application = 0x0001 -}; -Q_ENUM_NS(Scope) -QML_NAMED_ELEMENT(FluViewModelType) -} - namespace FluNetworkType { Q_NAMESPACE enum CacheMode { diff --git a/src/FluApp.cpp b/src/FluApp.cpp index a1ea49fe..0c5c5b41 100644 --- a/src/FluApp.cpp +++ b/src/FluApp.cpp @@ -10,20 +10,6 @@ #include #include -FluWindowRegister::FluWindowRegister(QObject *parent):QObject{parent}{ - from(nullptr); - to(nullptr); - path(""); -} - -void FluWindowRegister::launch(const QJsonObject& argument){ - FluApp::getInstance()->navigate(path(),argument,this); -} - -void FluWindowRegister::onResult(const QJsonObject& data){ - Q_EMIT result(data); -} - FluApp::FluApp(QObject *parent):QObject{parent}{ useSystemAppBar(false); } @@ -45,76 +31,3 @@ void FluApp::init(QObject *target,QLocale locale){ } } } - -void FluApp::run(){ - navigate(initialRoute()); -} - -void FluApp::navigate(const QString& route,const QJsonObject& argument,FluWindowRegister* windowRegister){ - if(!routes().contains(route)){ - qCritical()<<"Not Found Route "<property("_route").toString(); - if(r == route){ - win = pair.second; - break; - } - } - if(win){ - int launchMode = win->property("launchMode").toInt(); - if(launchMode == 1){ - win->setProperty("",argument); - win->show(); - win->raise(); - win->requestActivate(); - return; - }else if(launchMode == 2){ - win->close(); - } - } - win = qobject_cast(component.createWithInitialProperties(properties)); - if(windowRegister){ - windowRegister->to(win); - } -} - -void FluApp::exit(int retCode){ - for (const auto& pair : _windows.toStdMap()) { - pair.second->close(); - removeWindow(pair.second); - } - qApp->exit(retCode); -} - -void FluApp::addWindow(QQuickWindow* window){ - _windows.insert(window->winId(),window); -} - -void FluApp::removeWindow(QQuickWindow* window){ - if(window){ - _windows.remove(window->winId()); - window->deleteLater(); - window = nullptr; - } -} - -QVariant FluApp::createWindowRegister(QQuickWindow* window,const QString& path){ - FluWindowRegister *p = new FluWindowRegister(window); - p->from(window); - p->path(path); - return QVariant::fromValue(p); -} diff --git a/src/FluApp.h b/src/FluApp.h index 9ef317a8..3af53db1 100644 --- a/src/FluApp.h +++ b/src/FluApp.h @@ -4,7 +4,6 @@ #include #include #include -#include #include #include #include @@ -13,31 +12,12 @@ #include "stdafx.h" #include "singleton.h" - -/** - * @brief The FluWindowRegister class - */ -class FluWindowRegister : public QObject -{ - Q_OBJECT - Q_PROPERTY_AUTO(QQuickWindow*,from) - Q_PROPERTY_AUTO(QQuickWindow*,to) - Q_PROPERTY_AUTO(QString,path); -public: - explicit FluWindowRegister(QObject *parent = nullptr); - Q_INVOKABLE void launch(const QJsonObject& argument = {}); - Q_INVOKABLE void onResult(const QJsonObject& data = {}); - Q_SIGNAL void result(const QJsonObject& data); -}; - /** * @brief The FluApp class */ class FluApp : public QObject { Q_OBJECT - Q_PROPERTY_AUTO(QString,initialRoute); - Q_PROPERTY_AUTO(QJsonObject,routes); Q_PROPERTY_AUTO(bool,useSystemAppBar); Q_PROPERTY_AUTO(QString,windowIcon); Q_PROPERTY_AUTO(QLocale,locale); @@ -49,15 +29,8 @@ private: public: SINGLETON(FluApp) static FluApp *create(QQmlEngine *qmlEngine, QJSEngine *jsEngine){return getInstance();} - Q_INVOKABLE void run(); - Q_INVOKABLE void navigate(const QString& route,const QJsonObject& argument = {},FluWindowRegister* windowRegister = nullptr); Q_INVOKABLE void init(QObject *target,QLocale locale = QLocale::system()); - Q_INVOKABLE void exit(int retCode = 0); - Q_INVOKABLE QVariant createWindowRegister(QQuickWindow* window,const QString& path); - void addWindow(QQuickWindow* window); - void removeWindow(QQuickWindow* window); private: - QMap _windows; QQmlEngine *_engine; QTranslator* _translator = nullptr; }; diff --git a/src/FluTools.cpp b/src/FluTools.cpp index f468836c..4c3cdf7c 100644 --- a/src/FluTools.cpp +++ b/src/FluTools.cpp @@ -86,9 +86,9 @@ void FluTools::restoreOverrideCursor(){ qApp->restoreOverrideCursor(); } -void FluTools::deleteItem(QObject *p){ +void FluTools::deleteLater(QObject *p){ if(p){ - delete p; + p->deleteLater(); p = nullptr; } } diff --git a/src/FluTools.h b/src/FluTools.h index 6dccbd3c..1561fb69 100644 --- a/src/FluTools.h +++ b/src/FluTools.h @@ -34,7 +34,7 @@ public: Q_INVOKABLE void restoreOverrideCursor(); Q_INVOKABLE QString html2PlantText(const QString& html); Q_INVOKABLE QString toLocalPath(const QUrl& url); - Q_INVOKABLE void deleteItem(QObject *p); + Q_INVOKABLE void deleteLater(QObject *p); Q_INVOKABLE QString getFileNameByUrl(const QUrl& url); Q_INVOKABLE QRect getVirtualGeometry(); Q_INVOKABLE QString getApplicationDirPath(); diff --git a/src/FluViewModel.cpp b/src/FluViewModel.cpp deleted file mode 100644 index 8a05bfd5..00000000 --- a/src/FluViewModel.cpp +++ /dev/null @@ -1,113 +0,0 @@ -#include "FluViewModel.h" - -#include -#include "Def.h" - -FluViewModelManager::FluViewModelManager(QObject *parent): QObject{parent}{ -} - -void FluViewModelManager::insertViewModel(FluViewModel* value){ - _viewmodel.append(value); -} - -void FluViewModelManager::deleteViewModel(FluViewModel* value){ - _viewmodel.removeOne(value); -} - -QObject* FluViewModelManager::getModel(const QString& key){ - return _data.value(key); -} - -void FluViewModelManager::insert(const QString& key,QObject* value){ - _data.insert(key,value); -} - -bool FluViewModelManager::exist(const QString& key){ - return _data.contains(key); -} - -void FluViewModelManager::refreshViewModel(FluViewModel* viewModel,QString key,QVariant value){ - foreach (auto item, _viewmodel) { - if(item->getKey() == viewModel->getKey()){ - item->enablePropertyChange = false; - item->setProperty(key.toLatin1().constData(),value); - item->enablePropertyChange = true; - } - } -} - -FluPropertyObserver::FluPropertyObserver(QString name,QObject* model,QObject *parent):QObject{parent}{ - _name = name; - _model = model; - _property = QQmlProperty(parent,_name); - _property.connectNotifySignal(this,SLOT(_propertyChange())); -} - -FluPropertyObserver::~FluPropertyObserver(){ -} - -void FluPropertyObserver::_propertyChange(){ - auto viewModel = (FluViewModel*)parent(); - if(viewModel->enablePropertyChange){ - auto value = _property.read(); - _model->setProperty(_name.toLatin1().constData(),value); - FluViewModelManager::getInstance()->refreshViewModel(viewModel,_name,value); - } -} - -FluViewModel::FluViewModel(QObject *parent):QObject{parent}{ - scope(FluViewModelType::Scope::Window); - FluViewModelManager::getInstance()->insertViewModel(this); -} - -FluViewModel::~FluViewModel(){ - FluViewModelManager::getInstance()->deleteViewModel(this); -} - -void FluViewModel::classBegin(){ -} - -void FluViewModel::componentComplete(){ - auto o = parent(); - while (nullptr != o) { - _window = o; - o = o->parent(); - } - const QMetaObject* obj = metaObject(); - if(_scope == FluViewModelType::Scope::Window){ - _key = property("objectName").toString()+"-"+QString::number(reinterpret_cast(_window), 16); - }else{ - _key = property("objectName").toString(); - } - QObject * model; - if(!FluViewModelManager::getInstance()->exist(_key)){ - if(_scope == FluViewModelType::Scope::Window){ - model = new QObject(_window); - }else{ - model = new QObject(); - } - Q_EMIT initData(); - for (int i = 0; i < obj->propertyCount(); ++i) { - const QMetaProperty property = obj->property(i); - QString propertyName = property.name(); - auto value = property.read(this); - model->setProperty(propertyName.toLatin1().constData(),value); - new FluPropertyObserver(propertyName,model,this); - } - FluViewModelManager::getInstance()->insert(_key,model); - }else{ - model = FluViewModelManager::getInstance()->getModel(_key); - for (int i = 0; i < obj->propertyCount(); ++i) { - const QMetaProperty property = obj->property(i); - QString propertyName = property.name(); - new FluPropertyObserver(propertyName,model,this); - } - } - foreach (auto key, model->dynamicPropertyNames()) { - setProperty(key,model->property(key)); - } -} - -QString FluViewModel::getKey(){ - return _key; -} diff --git a/src/FluViewModel.h b/src/FluViewModel.h deleted file mode 100644 index 4f90d50e..00000000 --- a/src/FluViewModel.h +++ /dev/null @@ -1,69 +0,0 @@ -#ifndef FLUVIEWMODEL_H -#define FLUVIEWMODEL_H - -#include -#include -#include -#include -#include "stdafx.h" -#include "singleton.h" - -/** - * @brief The FluViewModel class - */ -class FluViewModel : public QObject, public QQmlParserStatus -{ - Q_OBJECT - Q_INTERFACES(QQmlParserStatus) - Q_PROPERTY_AUTO(int,scope); - QML_NAMED_ELEMENT(FluViewModel) -public: - explicit FluViewModel(QObject *parent = nullptr); - ~FluViewModel(); - void classBegin() override; - void componentComplete() override; - Q_SIGNAL void initData(); - QString getKey(); - bool enablePropertyChange = true; -private: - QObject* _window = nullptr; - QString _key = ""; -}; - -/** - * @brief The FluPropertyObserver class - */ -class FluPropertyObserver: public QObject{ - Q_OBJECT -public: - explicit FluPropertyObserver(QString name,QObject* model,QObject *parent = nullptr); - ~FluPropertyObserver(); -private: - Q_SLOT void _propertyChange(); -private: - QString _name = ""; - QQmlProperty _property; - QObject* _model = nullptr; -}; - -/** - * @brief The FluViewModelManager class - */ -class FluViewModelManager:public QObject{ - Q_OBJECT -private: - explicit FluViewModelManager(QObject *parent = nullptr); -public: - SINGLETON(FluViewModelManager) - bool exist(const QString& key); - void insert(const QString& key,QObject* value); - QObject* getModel(const QString& key); - void insertViewModel(FluViewModel* value); - void deleteViewModel(FluViewModel* value); - void refreshViewModel(FluViewModel* viewModel,QString key,QVariant value); -private: - QMap _data; - QList _viewmodel; -}; - -#endif // FLUVIEWMODEL_H diff --git a/src/FluWindowLifecycle.cpp b/src/FluWindowLifecycle.cpp deleted file mode 100644 index c45b0003..00000000 --- a/src/FluWindowLifecycle.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include "FluWindowLifecycle.h" - -#include "FluApp.h" - -FluWindowLifecycle::FluWindowLifecycle(QObject *parent):QObject{parent}{ - -} - -void FluWindowLifecycle::onCompleted(QQuickWindow* window){ - _window = window; - if(_window && _window->transientParent() == nullptr){ - FluApp::getInstance()->addWindow(_window); - } -} - -void FluWindowLifecycle::onDestroyOnClose(){ - if(_window && _window->transientParent() == nullptr){ - FluApp::getInstance()->removeWindow(_window); - _window = nullptr; - } -} - -void FluWindowLifecycle::onDestruction(){ - -} - -void FluWindowLifecycle::onVisible(bool visible){ -} diff --git a/src/FluWindowLifecycle.h b/src/FluWindowLifecycle.h deleted file mode 100644 index 15374047..00000000 --- a/src/FluWindowLifecycle.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef FLUWINDOWLIFECYCLE_H -#define FLUWINDOWLIFECYCLE_H - -#include -#include -#include -#include -#include -#include - -/** - * @brief The FluWindowLifecycle class - */ -class FluWindowLifecycle : public QObject -{ - Q_OBJECT - QML_NAMED_ELEMENT(FluWindowLifecycle) -public: - explicit FluWindowLifecycle(QObject *parent = nullptr); - Q_INVOKABLE void onCompleted(QQuickWindow* window); - Q_INVOKABLE void onDestruction(); - Q_INVOKABLE void onVisible(bool visible); - Q_INVOKABLE void onDestroyOnClose(); -private: - QQuickWindow* _window = nullptr; -}; - -#endif // FLUWINDOWLIFECYCLE_H diff --git a/src/FluentUI.cpp b/src/FluentUI.cpp index a5427fa6..16ea6aae 100644 --- a/src/FluentUI.cpp +++ b/src/FluentUI.cpp @@ -1,7 +1,6 @@ #include "FluentUI.h" #include -#include "FluWindowLifecycle.h" #include "Def.h" #include "FluApp.h" #include "FluColors.h" @@ -12,7 +11,6 @@ #include "FluCaptcha.h" #include "FluEventBus.h" #include "FluTreeModel.h" -#include "FluViewModel.h" #include "FluRectangle.h" #include "FluNetwork.h" #include "FluFramelessHelper.h" @@ -27,13 +25,11 @@ void FluentUI::registerTypes(QQmlEngine *engine){ void FluentUI::registerTypes(const char *uri){ #if (QT_VERSION < QT_VERSION_CHECK(6, 2, 0)) Q_INIT_RESOURCE(fluentui); - qmlRegisterType(uri,major,minor,"FluWindowLifecycle"); qmlRegisterType(uri,major,minor,"FluQrCodeItem"); qmlRegisterType(uri,major,minor,"FluCaptcha"); qmlRegisterType(uri,major,minor,"FluWatermark"); qmlRegisterType(uri,major,minor,"FluAccentColor"); qmlRegisterType(uri,major,minor,"FluEvent"); - qmlRegisterType(uri,major,minor,"FluViewModel"); qmlRegisterType(uri,major,minor,"FluTreeModel"); qmlRegisterType(uri,major,minor,"FluRectangle"); qmlRegisterType(uri,major,minor,"FluNetworkCallable"); @@ -128,6 +124,9 @@ void FluentUI::registerTypes(const char *uri){ 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"); + qmlRegisterSingletonType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluRouter.qml"),uri,major,minor,"FluRouter"); 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"); @@ -141,7 +140,6 @@ void FluentUI::registerTypes(const char *uri){ 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(FluViewModelType::staticMetaObject, uri,major,minor,"FluViewModelType", "Access to enums & flags only"); qmlRegisterUncreatableMetaObject(FluNetworkType::staticMetaObject, uri,major,minor,"FluNetworkType", "Access to enums & flags only"); qmlRegisterModule(uri,major,minor); @@ -154,18 +152,11 @@ void FluentUI::initializeEngine(QQmlEngine *engine, const char *uri){ font.setFamily("微软雅黑"); QGuiApplication::setFont(font); #endif - FluApp* app = FluApp::getInstance(); - engine->rootContext()->setContextProperty("FluApp",app); - FluColors* colors = FluColors::getInstance(); - engine->rootContext()->setContextProperty("FluColors",colors); - FluTheme* theme = FluTheme::getInstance(); - engine->rootContext()->setContextProperty("FluTheme",theme); - FluTools* tools = FluTools::getInstance(); - engine->rootContext()->setContextProperty("FluTools",tools); - FluTextStyle* textStyle = FluTextStyle::getInstance(); - engine->rootContext()->setContextProperty("FluTextStyle",textStyle); - FluEventBus* eventBus = FluEventBus::getInstance(); - engine->rootContext()->setContextProperty("FluEventBus",eventBus); - FluNetwork* network = FluNetwork::getInstance(); - engine->rootContext()->setContextProperty("FluNetwork",network); + 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()); + engine->rootContext()->setContextProperty("FluEventBus",FluEventBus::getInstance()); + engine->rootContext()->setContextProperty("FluNetwork",FluNetwork::getInstance()); } diff --git a/src/Qt5/imports/FluentUI/Controls/FluLauncher.qml b/src/Qt5/imports/FluentUI/Controls/FluLauncher.qml new file mode 100644 index 00000000..5867eb3b --- /dev/null +++ b/src/Qt5/imports/FluentUI/Controls/FluLauncher.qml @@ -0,0 +1,6 @@ +import QtQuick 2.15 +import FluentUI 1.0 +import "." + +FluObject { +} diff --git a/src/Qt5/imports/FluentUI/Controls/FluRouter.qml b/src/Qt5/imports/FluentUI/Controls/FluRouter.qml new file mode 100644 index 00000000..1687fd98 --- /dev/null +++ b/src/Qt5/imports/FluentUI/Controls/FluRouter.qml @@ -0,0 +1,71 @@ +pragma Singleton + +import QtQuick 2.15 + +QtObject { + property var routes : ({}) + property var windows: [] + function addWindow(window){ + if(!window.transientParent){ + windows.push(window) + } + } + function removeWindow(window) { + if(!window.transientParent){ + var index = windows.indexOf(window) + if (index !== -1) { + windows.splice(index, 1) + FluTools.deleteLater(window) + } + } + } + function exit(retCode){ + for(var i =0 ;i< windows.length; i++){ + var item = windows[i] + FluTools.deleteLater(item) + } + windows = [] + Qt.exit(retCode) + } + function navigate(route,argument={},windowRegister = undefined){ + if(!routes.hasOwnProperty(route)){ + console.error("Not Found Route",route) + return + } + var windowComponent = Qt.createComponent(routes[route]) + if (windowComponent.status !== Component.Ready) { + console.error(windowComponent.errorString()) + return + } + var properties = {} + properties._route = route + if(windowRegister){ + properties._windowRegister = windowRegister + } + properties.argument = argument + var win = undefined + for(var i =0 ;i< windows.length; i++){ + var item = windows[i] + if(route === item._route){ + win = item + break + } + } + if(win){ + var launchMode = win.launchMode + if(launchMode === 1){ + win.argument = argument + win.show() + win.raise() + win.requestActivate() + return + }else if(launchMode === 2){ + win.close() + } + } + win = windowComponent.createObject(null,properties) + if(windowRegister){ + windowRegister._to = win + } + } +} diff --git a/src/Qt5/imports/FluentUI/Controls/FluWindow.qml b/src/Qt5/imports/FluentUI/Controls/FluWindow.qml index b2c4bdde..4e85b4f8 100644 --- a/src/Qt5/imports/FluentUI/Controls/FluWindow.qml +++ b/src/Qt5/imports/FluentUI/Controls/FluWindow.qml @@ -50,7 +50,7 @@ Window { property int resizeBorderWidth: 1 property var closeListener: function(event){ if(autoDestroy){ - destroyOnClose() + FluRouter.removeWindow(window) }else{ window.visibility = Window.Hidden event.accepted = false @@ -67,6 +67,7 @@ Window { id:window color:"transparent" Component.onCompleted: { + FluRouter.addWindow(window) _realHeight = height _realWidth = width useSystemAppBar = FluApp.useSystemAppBar @@ -74,7 +75,6 @@ Window { moveWindowToDesktopCenter() } fixWindowSize() - lifecycle.onCompleted(window) initArgument(argument) if(!useSystemAppBar){ loader_frameless_helper.sourceComponent = com_frameless_helper @@ -87,9 +87,6 @@ Window { } } } - Component.onDestruction: { - lifecycle.onDestruction() - } onShowSystemMenu: { if(loader_frameless_helper.item){ loader_frameless_helper.item.showSystemMenu() @@ -100,7 +97,6 @@ Window { window.firstVisible() d.isFirstVisible = false } - lifecycle.onVisible(visible) } QtObject{ id:d @@ -244,9 +240,6 @@ Window { id:info_bar root: window } - FluWindowLifecycle{ - id:lifecycle - } FluLoader{ id:loader_border anchors.fill: parent @@ -263,9 +256,6 @@ Window { return com_border } } - function destroyOnClose(){ - lifecycle.onDestroyOnClose() - } function showLoading(text = qsTr("Loading..."),cancel = true){ loader_loading.loadingText = text loader_loading.cancel = cancel @@ -302,9 +292,9 @@ Window { function registerForWindowResult(path){ return FluApp.createWindowRegister(window,path) } - function onResult(data){ + function setResult(data){ if(_windowRegister){ - _windowRegister.onResult(data) + _windowRegister.setResult(data) } } function showMaximized(){ diff --git a/src/Qt5/imports/FluentUI/Controls/FluWindowResultLauncher.qml b/src/Qt5/imports/FluentUI/Controls/FluWindowResultLauncher.qml new file mode 100644 index 00000000..2ce36f94 --- /dev/null +++ b/src/Qt5/imports/FluentUI/Controls/FluWindowResultLauncher.qml @@ -0,0 +1,21 @@ +import QtQuick 2.15 +import QtQuick.Window 2.15 +import FluentUI 1.0 + +Item { + + id:control + property var _from : Window.window + property var _to + property var path + signal result(var data) + + function launch(argument = {}){ + FluRouter.navigate(control.path,argument,control) + } + + function setResult(data = {}){ + control.result(data) + } + +} diff --git a/src/Qt5/imports/FluentUI/Controls/qmldir b/src/Qt5/imports/FluentUI/Controls/qmldir new file mode 100644 index 00000000..672e5b90 --- /dev/null +++ b/src/Qt5/imports/FluentUI/Controls/qmldir @@ -0,0 +1 @@ +singleton FluRouter 1.0 FluRouter.qml diff --git a/src/Qt5/imports/FluentUI/qmldir b/src/Qt5/imports/FluentUI/qmldir index 2fd994dc..af7552eb 100644 --- a/src/Qt5/imports/FluentUI/qmldir +++ b/src/Qt5/imports/FluentUI/qmldir @@ -90,5 +90,7 @@ FluTour 1.0 Controls/FluTour.qml FluTreeView 1.0 Controls/FluTreeView.qml FluWindow 1.0 Controls/FluWindow.qml FluWindowDialog 1.0 Controls/FluWindowDialog.qml +FluWindowResultLauncher 1.0 Controls/FluWindowResultLauncher.qml +FluLauncher 1.0 Controls/FluLauncher.qml plugin fluentuiplugin diff --git a/src/Qt5/imports/fluentui.qrc b/src/Qt5/imports/fluentui.qrc index 8f7be040..b146e3fa 100644 --- a/src/Qt5/imports/fluentui.qrc +++ b/src/Qt5/imports/fluentui.qrc @@ -101,5 +101,10 @@ FluentUI/Controls/FluWindowDialog.qml FluentUI/i18n/fluentui_en_US.qm FluentUI/i18n/fluentui_zh_CN.qm + FluentUI/Controls/FluLauncher.qml + FluentUI/Controls/FluRouter.qml + FluentUI/Controls/FluWindowResultLauncher.qml + FluentUI/JS/Global.js + FluentUI/Controls/qmldir diff --git a/src/Qt6/imports/FluentUI/Controls/FluLauncher.qml b/src/Qt6/imports/FluentUI/Controls/FluLauncher.qml new file mode 100644 index 00000000..16364e72 --- /dev/null +++ b/src/Qt6/imports/FluentUI/Controls/FluLauncher.qml @@ -0,0 +1,7 @@ +import QtQuick +import FluentUI +import "." + +FluObject { + +} diff --git a/src/Qt6/imports/FluentUI/Controls/FluRouter.qml b/src/Qt6/imports/FluentUI/Controls/FluRouter.qml new file mode 100644 index 00000000..178d64a8 --- /dev/null +++ b/src/Qt6/imports/FluentUI/Controls/FluRouter.qml @@ -0,0 +1,72 @@ +pragma Singleton + +import QtQuick +import FluentUI + +QtObject { + property var routes : ({}) + property var windows: [] + function addWindow(window){ + if(!window.transientParent){ + windows.push(window) + } + } + function removeWindow(window) { + if(!window.transientParent){ + var index = windows.indexOf(window) + if (index !== -1) { + windows.splice(index, 1) + FluTools.deleteLater(window) + } + } + } + function exit(retCode){ + for(var i =0 ;i< windows.length; i++){ + var item = windows[i] + FluTools.deleteLater(item) + } + windows = [] + Qt.exit(retCode) + } + function navigate(route,argument={},windowRegister = undefined){ + if(!routes.hasOwnProperty(route)){ + console.error("Not Found Route",route) + return + } + var windowComponent = Qt.createComponent(routes[route]) + if (windowComponent.status !== Component.Ready) { + console.error(windowComponent.errorString()) + return + } + var properties = {} + properties._route = route + if(windowRegister){ + properties._windowRegister = windowRegister + } + properties.argument = argument + var win = undefined + for(var i =0 ;i< windows.length; i++){ + var item = windows[i] + if(route === item._route){ + win = item + break + } + } + if(win){ + var launchMode = win.launchMode + if(launchMode === 1){ + win.argument = argument + win.show() + win.raise() + win.requestActivate() + return + }else if(launchMode === 2){ + win.close() + } + } + win = windowComponent.createObject(null,properties) + if(windowRegister){ + windowRegister._to = win + } + } +} diff --git a/src/Qt6/imports/FluentUI/Controls/FluWindow.qml b/src/Qt6/imports/FluentUI/Controls/FluWindow.qml index a568aaf1..65106e6e 100644 --- a/src/Qt6/imports/FluentUI/Controls/FluWindow.qml +++ b/src/Qt6/imports/FluentUI/Controls/FluWindow.qml @@ -49,7 +49,7 @@ Window { property int resizeBorderWidth: 1 property var closeListener: function(event){ if(autoDestroy){ - destroyOnClose() + FluRouter.removeWindow(window) }else{ window.visibility = Window.Hidden event.accepted = false @@ -66,6 +66,7 @@ Window { id:window color:"transparent" Component.onCompleted: { + FluRouter.addWindow(window) _realHeight = height _realWidth = width useSystemAppBar = FluApp.useSystemAppBar @@ -73,7 +74,6 @@ Window { moveWindowToDesktopCenter() } fixWindowSize() - lifecycle.onCompleted(window) initArgument(argument) if(!useSystemAppBar){ loader_frameless_helper.sourceComponent = com_frameless_helper @@ -86,9 +86,6 @@ Window { } } } - Component.onDestruction: { - lifecycle.onDestruction() - } onShowSystemMenu: { if(loader_frameless_helper.item){ loader_frameless_helper.item.showSystemMenu() @@ -99,7 +96,6 @@ Window { window.firstVisible() d.isFirstVisible = false } - lifecycle.onVisible(visible) } QtObject{ id:d @@ -243,9 +239,6 @@ Window { id:info_bar root: window } - FluWindowLifecycle{ - id:lifecycle - } FluLoader{ id:loader_border anchors.fill: parent @@ -262,9 +255,6 @@ Window { return com_border } } - function destroyOnClose(){ - lifecycle.onDestroyOnClose() - } function showLoading(text = qsTr("Loading..."),cancel = true){ loader_loading.loadingText = text loader_loading.cancel = cancel @@ -301,9 +291,9 @@ Window { function registerForWindowResult(path){ return FluApp.createWindowRegister(window,path) } - function onResult(data){ + function setResult(data){ if(_windowRegister){ - _windowRegister.onResult(data) + _windowRegister.setResult(data) } } function showMaximized(){ diff --git a/src/Qt6/imports/FluentUI/Controls/FluWindowResultLauncher.qml b/src/Qt6/imports/FluentUI/Controls/FluWindowResultLauncher.qml new file mode 100644 index 00000000..a3058e12 --- /dev/null +++ b/src/Qt6/imports/FluentUI/Controls/FluWindowResultLauncher.qml @@ -0,0 +1,20 @@ +import QtQuick +import FluentUI + +Item { + + id:control + property var _from : Window.window + property var _to + property var path + signal result(var data) + + function launch(argument = {}){ + FluRouter.navigate(control.path,argument,control) + } + + function setResult(data = {}){ + control.result(data) + } + +} diff --git a/src/Qt6/imports/FluentUI/Controls/qmldir b/src/Qt6/imports/FluentUI/Controls/qmldir new file mode 100644 index 00000000..5db69e7f --- /dev/null +++ b/src/Qt6/imports/FluentUI/Controls/qmldir @@ -0,0 +1 @@ +singleton FluRouter FluRouter.qml