From 9d3de073c0027195676831155f537eea6d3247f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=AD=90=E6=A5=9A=5Czhuzi?= Date: Mon, 13 Mar 2023 21:18:51 +0800 Subject: [PATCH] update --- example/T_Multiwindow.qml | 29 +++++++++++++++++++++-------- example/page/LoginPage.qml | 1 + src/FluApp.cpp | 7 +++++-- src/FluApp.h | 6 +++--- src/FluRegister.cpp | 20 ++++++++++++++++++++ src/FluRegister.h | 24 ++++++++++++++++++++++++ src/FluentUI.pro | 2 ++ src/WindowHelper.cpp | 19 +++++++++++++++++-- src/WindowHelper.h | 5 ++++- src/controls/FluWindow.qml | 18 ++++++++++++++++-- 10 files changed, 113 insertions(+), 18 deletions(-) create mode 100644 src/FluRegister.cpp create mode 100644 src/FluRegister.h diff --git a/example/T_Multiwindow.qml b/example/T_Multiwindow.qml index 7f930d6a..81e1e23a 100644 --- a/example/T_Multiwindow.qml +++ b/example/T_Multiwindow.qml @@ -9,6 +9,18 @@ FluScrollablePage{ title:"MultiWindow" + property string password: "" + + property var loginPageRegister: registerForPageResult("/login") + + Connections{ + target: loginPageRegister + function onResult(data) + { + password = data.password + } + } + FluArea{ width: parent.width height: 68 @@ -33,30 +45,31 @@ FluScrollablePage{ } } - - - FluArea{ width: parent.width - height: 68 + height: 130 paddings: 10 Layout.topMargin: 20 Column{ - spacing: 5 + spacing: 15 anchors{ verticalCenter: parent.verticalCenter left: parent.left } FluText{ - text:"页面跳转,并携带参数" + text:"页面跳转,并携带参数用户名:zhuzichu" } FluButton{ - text:"点击跳转" + text:"点击跳转到登录" onClicked: { - FluApp.navigate("/login",{username:"zhuzichu"}) + loginPageRegister.launch({username:"zhuzichu"}) } } + + FluText{ + text:"登录窗口返回过来的密码->"+password + } } } diff --git a/example/page/LoginPage.qml b/example/page/LoginPage.qml index d0d0c676..15a7da4f 100644 --- a/example/page/LoginPage.qml +++ b/example/page/LoginPage.qml @@ -60,6 +60,7 @@ FluWindow { showError("请随便输入一个密码") return } + onResult({password:textbox_password.text}) window.close() } } diff --git a/src/FluApp.cpp b/src/FluApp.cpp index 2ea23bb2..d68dec4d 100644 --- a/src/FluApp.cpp +++ b/src/FluApp.cpp @@ -33,13 +33,17 @@ void FluApp::run(){ navigate(initialRoute()); } -void FluApp::navigate(const QString& route,const QJsonObject& argument){ +void FluApp::navigate(const QString& route,const QJsonObject& argument,FluRegister* fluRegister){ if(!routes().contains(route)){ qErrnoWarning("没有找到当前路由"); return; } bool isAppWindow = route == initialRoute(); FramelessView *view = new FramelessView(); + if(fluRegister){ + fluRegister->to(view); + view->setProperty("pageRegister",QVariant::fromValue(fluRegister)); + } view->setProperty("argument",argument); QMapIterator iterator(properties); while (iterator.hasNext()) { @@ -59,7 +63,6 @@ void FluApp::navigate(const QString& route,const QJsonObject& argument){ view->setSource((routes().value(route).toString())); if(isAppWindow){ QObject::connect(view->engine(), &QQmlEngine::quit, qApp, &QCoreApplication::quit); - // QObject::connect(qApp, &QGuiApplication::aboutToQuit, qApp, [&view](){view->setSource({});}); }else{ view->closeDeleteLater(); } diff --git a/src/FluApp.h b/src/FluApp.h index 047ea7b1..38c30046 100644 --- a/src/FluApp.h +++ b/src/FluApp.h @@ -7,6 +7,7 @@ #include #include #include +#include "FluRegister.h" #include "FramelessView.h" #include "stdafx.h" @@ -24,7 +25,7 @@ public: Q_INVOKABLE void run(); - Q_INVOKABLE void navigate(const QString& route,const QJsonObject& argument = {}); + Q_INVOKABLE void navigate(const QString& route,const QJsonObject& argument = {},FluRegister* fluRegister = nullptr); Q_INVOKABLE void init(QWindow *window,QMap properties); @@ -37,9 +38,8 @@ public: Q_INVOKABLE void clipText(const QString& text); private: - - static FluApp* m_instance; QMap properties; + static FluApp* m_instance; QWindow *appWindow; }; diff --git a/src/FluRegister.cpp b/src/FluRegister.cpp new file mode 100644 index 00000000..4cc8c6da --- /dev/null +++ b/src/FluRegister.cpp @@ -0,0 +1,20 @@ +#include "FluRegister.h" + +#include "FluApp.h" +#include + +FluRegister::FluRegister(QObject *parent) + : QObject{parent} +{ + from(nullptr); + to(nullptr); + path(""); +} + +void FluRegister::launch(const QJsonObject& argument){ + FluApp::getInstance()->navigate(path(),argument,this); +} + +void FluRegister::onResult(const QJsonObject& data){ + Q_EMIT result(data); +} diff --git a/src/FluRegister.h b/src/FluRegister.h new file mode 100644 index 00000000..ba4231b9 --- /dev/null +++ b/src/FluRegister.h @@ -0,0 +1,24 @@ +#ifndef FLUREGISTER_H +#define FLUREGISTER_H + +#include +#include +#include +#include "stdafx.h" + +class FluRegister : public QObject +{ + Q_OBJECT + Q_PROPERTY_AUTO(FramelessView*,from) + Q_PROPERTY_AUTO(FramelessView*,to) + Q_PROPERTY_AUTO(QString,path); +public: + explicit FluRegister(QObject *parent = nullptr); + + Q_INVOKABLE void launch(const QJsonObject& argument = {}); + Q_INVOKABLE void onResult(const QJsonObject& data = {}); + Q_SIGNAL void result(const QJsonObject& data); + +}; + +#endif // FLUREGISTER_H diff --git a/src/FluentUI.pro b/src/FluentUI.pro index 9476f93f..ffe10367 100644 --- a/src/FluentUI.pro +++ b/src/FluentUI.pro @@ -15,6 +15,7 @@ HEADERS += \ FluApp.h \ FluColorSet.h \ FluColors.h \ + FluRegister.h \ FluTheme.h \ Fluent.h \ FluentUI.h \ @@ -28,6 +29,7 @@ SOURCES += \ FluApp.cpp \ FluColorSet.cpp \ FluColors.cpp \ + FluRegister.cpp \ FluTheme.cpp \ Fluent.cpp \ FluentUI.cpp \ diff --git a/src/WindowHelper.cpp b/src/WindowHelper.cpp index 4ee2aa77..72a4edf1 100644 --- a/src/WindowHelper.cpp +++ b/src/WindowHelper.cpp @@ -1,5 +1,7 @@ #include "WindowHelper.h" +#include "FluRegister.h" + WindowHelper::WindowHelper(QObject *parent) : QObject{parent} { @@ -10,11 +12,18 @@ void WindowHelper::setTitle(const QString& text){ window->setTitle(text); } -QJsonObject WindowHelper::initWindow(FramelessView* window){ +void WindowHelper::initWindow(FramelessView* window){ this->window = window; +} + +QJsonObject WindowHelper::getArgument(){ return window->property("argument").toJsonObject(); } +QVariant WindowHelper::getPageRegister(){ + return window->property("pageRegister"); +} + void WindowHelper::setMinimumWidth(int width){ this->window->setMinimumWidth(width); } @@ -31,7 +40,6 @@ void WindowHelper::updateWindow(){ this->window->setFlag(Qt::Window,false); this->window->setFlag(Qt::Window,true); } - void WindowHelper::setModality(int type){ if(type == 0){ this->window->setModality(Qt::NonModal); @@ -43,3 +51,10 @@ void WindowHelper::setModality(int type){ this->window->setModality(Qt::NonModal); } } + +QVariant WindowHelper::createRegister(const QString& path){ + FluRegister *p = new FluRegister(this->window); + p->from(this->window); + p->path(path); + return QVariant::fromValue(p); +} diff --git a/src/WindowHelper.h b/src/WindowHelper.h index 639cb5b6..c31184b9 100644 --- a/src/WindowHelper.h +++ b/src/WindowHelper.h @@ -15,14 +15,17 @@ class WindowHelper : public QObject public: explicit WindowHelper(QObject *parent = nullptr); - Q_INVOKABLE QJsonObject initWindow(FramelessView* window); + Q_INVOKABLE void initWindow(FramelessView* window); Q_INVOKABLE void setTitle(const QString& text); Q_INVOKABLE void setMinimumWidth(int width); Q_INVOKABLE void setMaximumWidth(int width); Q_INVOKABLE void setMinimumHeight(int height); Q_INVOKABLE void setMaximumHeight(int height); + Q_INVOKABLE QJsonObject getArgument(); + Q_INVOKABLE QVariant getPageRegister(); Q_INVOKABLE void updateWindow(); Q_INVOKABLE void setModality(int type); + Q_INVOKABLE QVariant createRegister(const QString& path); private: FramelessView* window; diff --git a/src/controls/FluWindow.qml b/src/controls/FluWindow.qml index 5ee23915..595dfbae 100644 --- a/src/controls/FluWindow.qml +++ b/src/controls/FluWindow.qml @@ -30,6 +30,8 @@ Item { signal initArgument(var argument) + property var pageRegister + property int borderless:{ if(!FluTheme.isFrameless){ return 0 @@ -79,7 +81,9 @@ Item { target: FluApp function onWindowReady(view){ if(FluApp.equalsWindow(view,window)){ - initArgument(helper.initWindow(view)) + helper.initWindow(view) + initArgument(helper.getArgument()) + pageRegister = helper.getPageRegister() helper.setTitle(title) if(minimumWidth){ helper.setMinimumWidth(minimumWidth) @@ -111,21 +115,31 @@ Item { function showSuccess(text,duration,moremsg){ infoBar.showSuccess(text,duration,moremsg); } + function showInfo(text,duration,moremsg){ infoBar.showInfo(text,duration,moremsg); } + function showWarning(text,duration,moremsg){ infoBar.showWarning(text,duration,moremsg); } + function showError(text,duration,moremsg){ infoBar.showError(text,duration,moremsg); } + function close(){ window.close() } - function onResult(data){ + function registerForPageResult(path){ + return helper.createRegister(path) + } + function onResult(data){ + if(pageRegister){ + pageRegister.onResult(data) + } } }