This commit is contained in:
zhuzichu
2023-09-27 15:18:10 +08:00
parent 9354b8c0bf
commit 8e1e8a9db5
32 changed files with 495 additions and 318 deletions

View File

@ -8,7 +8,6 @@
#include <QUuid>
#include <QFontDatabase>
#include <QClipboard>
#include "Def.h"
FluApp::FluApp(QObject *parent):QObject{parent}{
httpInterceptor(nullptr);
@ -18,7 +17,7 @@ FluApp::~FluApp(){
}
void FluApp::init(QQuickWindow *window){
this->appWindow = window;
this->_application = window;
}
void FluApp::run(){
@ -30,7 +29,7 @@ void FluApp::navigate(const QString& route,const QJsonObject& argument,FluRegist
qCritical()<<"No route found "<<route;
return;
}
QQmlEngine *engine = qmlEngine(appWindow);
QQmlEngine *engine = qmlEngine(_application);
QQmlComponent component(engine, routes().value(route).toString());
if (component.isError()) {
qCritical() << component.errors();
@ -42,65 +41,47 @@ void FluApp::navigate(const QString& route,const QJsonObject& argument,FluRegist
properties.insert("_pageRegister",QVariant::fromValue(fluRegister));
}
properties.insert("argument",argument);
QQuickWindow *view=nullptr;
for (auto& pair : wnds) {
QString r = pair->property("_route").toString();
QQuickWindow *win=nullptr;
for (const auto& pair : _windows.toStdMap()) {
QString r = pair.second->property("_route").toString();
if(r == route){
view = pair;
win = pair.second;
break;
}
}
if(view){
//如果窗口存在,则判断启动模式
int launchMode = view->property("launchMode").toInt();
if(win){
int launchMode = win->property("launchMode").toInt();
if(launchMode == 1){
view->setProperty("argument",argument);
view->show();
view->raise();
view->requestActivate();
win->setProperty("argument",argument);
win->show();
win->raise();
win->requestActivate();
return;
}else if(launchMode == 2){
view->close();
win->close();
}
}
view = qobject_cast<QQuickWindow*>(component.createWithInitialProperties(properties));
wnds.insert(view->winId(),view);
win = qobject_cast<QQuickWindow*>(component.createWithInitialProperties(properties));
if(fluRegister){
fluRegister->to(view);
fluRegister->to(win);
}
view->setColor(QColor(Qt::transparent));
win->setColor(QColor(Qt::transparent));
}
QJsonArray FluApp::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){
QString name = enumType.key(i);
int icon = enumType.value(i);
if(keyword.isEmpty()){
QJsonObject obj;
obj.insert("name",name);
obj.insert("icon",icon);
arr.append(obj);
}else{
if(name.contains(keyword)){
QJsonObject obj;
obj.insert("name",name);
obj.insert("icon",icon);
arr.append(obj);
}
}
void FluApp::exit(int retCode){
for (const auto& pair : _windows.toStdMap()) {
removeWindow(pair.second);
}
return arr;
qApp->exit(retCode);
}
void FluApp::closeApp(){
qApp->exit(0);
void FluApp::addWindow(QQuickWindow* window){
_windows.insert(window->winId(),window);
}
void FluApp::deleteWindow(QQuickWindow* window){
void FluApp::removeWindow(QQuickWindow* window){
if(window){
wnds.remove(window->winId());
_windows.remove(window->winId());
window->deleteLater();
window = nullptr;
}

View File

@ -33,13 +33,12 @@ public:
Q_INVOKABLE void run();
Q_INVOKABLE void navigate(const QString& route,const QJsonObject& argument = {},FluRegister* fluRegister = nullptr);
Q_INVOKABLE void init(QQuickWindow *window);
Q_INVOKABLE QJsonArray awesomelist(const QString& keyword = "");
Q_INVOKABLE void closeApp();
Q_INVOKABLE void deleteWindow(QQuickWindow* window);
public:
QMap<quint64, QQuickWindow*> wnds;
Q_INVOKABLE void exit(int retCode = 0);
void addWindow(QQuickWindow* window);
void removeWindow(QQuickWindow* window);
private:
QWindow *appWindow;
QMap<quint64, QQuickWindow*> _windows;
QWindow* _application;
};
#endif // FLUAPP_H

View File

@ -110,11 +110,16 @@ void FluHttp::post(HttpRequest* r,HttpCallable* c){
part.setBody(value.toUtf8());
multiPart.append(part);
}
QEventLoop loop;
QNetworkReply* reply = manager.post(req,&multiPart);
if(!QPointer(qApp)){
reply->deleteLater();
reply = nullptr;
return;
}
_cacheReply.append(reply);
QEventLoop loop;
connect(&manager,&QNetworkAccessManager::finished,&manager,[&loop](QNetworkReply *reply){loop.quit();});
connect(qApp,&QGuiApplication::aboutToQuit,&manager, [&loop](){loop.quit();});
connect(qApp,&QGuiApplication::aboutToQuit,&manager, [&loop,reply](){reply->abort(),loop.quit();});
loop.exec();
QString result = QString::fromUtf8(reply->readAll());
int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
@ -169,11 +174,16 @@ void FluHttp::postString(HttpRequest* r,HttpCallable* c){
addHeaders(&req,data["headers"].toMap());
QString contentType = QString("text/plain;charset=utf-8");
req.setHeader(QNetworkRequest::ContentTypeHeader, contentType);
QEventLoop loop;
QNetworkReply* reply = manager.post(req,params.toUtf8());
if(!QPointer(qApp)){
reply->deleteLater();
reply = nullptr;
return;
}
_cacheReply.append(reply);
QEventLoop loop;
connect(&manager,&QNetworkAccessManager::finished,&manager,[&loop](QNetworkReply *reply){loop.quit();});
connect(qApp,&QGuiApplication::aboutToQuit,&manager, [&loop](){loop.quit();});
connect(qApp,&QGuiApplication::aboutToQuit,&manager, [&loop,reply](){reply->abort(),loop.quit();});
loop.exec();
QString result = QString::fromUtf8(reply->readAll());
int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
@ -227,11 +237,16 @@ void FluHttp::postJson(HttpRequest* r,HttpCallable* c){
addHeaders(&req,data["headers"].toMap());
QString contentType = QString("application/json;charset=utf-8");
req.setHeader(QNetworkRequest::ContentTypeHeader, contentType);
QEventLoop loop;
QNetworkReply* reply = manager.post(req,QJsonDocument::fromVariant(data["params"]).toJson());
if(!QPointer(qApp)){
reply->deleteLater();
reply = nullptr;
return;
}
_cacheReply.append(reply);
QEventLoop loop;
connect(&manager,&QNetworkAccessManager::finished,&manager,[&loop](QNetworkReply *reply){loop.quit();});
connect(qApp,&QGuiApplication::aboutToQuit,&manager, [&loop](){loop.quit();});
connect(qApp,&QGuiApplication::aboutToQuit,&manager, [&loop,reply](){reply->abort(),loop.quit();});
loop.exec();
QString result = QString::fromUtf8(reply->readAll());
int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
@ -284,11 +299,16 @@ void FluHttp::get(HttpRequest* r,HttpCallable* c){
addQueryParam(&url,data["params"].toMap());
QNetworkRequest req(url);
addHeaders(&req,data["headers"].toMap());
QEventLoop loop;
auto reply = QPointer(manager.get(req));
QNetworkReply* reply = manager.get(req);
if(!QPointer(qApp)){
reply->deleteLater();
reply = nullptr;
return;
}
_cacheReply.append(reply);
QEventLoop loop;
connect(&manager,&QNetworkAccessManager::finished,&manager,[&loop](QNetworkReply *reply){loop.quit();});
connect(qApp,&QGuiApplication::aboutToQuit,&manager, [&loop](){loop.quit();});
connect(qApp,&QGuiApplication::aboutToQuit,&manager, [&loop,reply](){reply->abort(),loop.quit();});
loop.exec();
int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
QString errorString = reply->errorString();
@ -337,9 +357,6 @@ void FluHttp::download(HttpRequest* r,HttpCallable* c){
if (!dir.exists(dir.path())){
dir.mkpath(dir.path());
}
QEventLoop loop;
connect(&manager,&QNetworkAccessManager::finished,&manager,[&loop](QNetworkReply *reply){loop.quit();});
connect(qApp,&QGuiApplication::aboutToQuit,&manager, [&loop](){loop.quit();});
qint64 seek = 0;
auto filePath = getCacheFilePath(httpId);
QSharedPointer<QFile> fileCache(new QFile(filePath));
@ -364,7 +381,15 @@ void FluHttp::download(HttpRequest* r,HttpCallable* c){
file->open(QIODevice::WriteOnly|QIODevice::Truncate);
}
QNetworkReply* reply = manager.get(req);
if(!QPointer(qApp)){
reply->deleteLater();
reply = nullptr;
return;
}
_cacheReply.append(reply);
QEventLoop loop;
connect(&manager,&QNetworkAccessManager::finished,&manager,[&loop](QNetworkReply *reply){loop.quit();});
connect(qApp,&QGuiApplication::aboutToQuit,&manager, [&loop,reply](){reply->abort(),loop.quit();});
if (!fileCache->open(QIODevice::WriteOnly|QIODevice::Truncate))
{
qDebug()<<"FileCache Error";
@ -411,7 +436,6 @@ void FluHttp::upload(HttpRequest* request,HttpCallable* callable){
QNetworkRequest req(url);
addHeaders(&req,data["headers"].toMap());
QHttpMultiPart multiPart(QHttpMultiPart::FormDataType);
qDebug()<<data["params"].toMap();
for (const auto& each : data["params"].toMap().toStdMap())
{
const QString& key = each.first;
@ -426,11 +450,16 @@ void FluHttp::upload(HttpRequest* request,HttpCallable* callable){
part.setBodyDevice(file);
multiPart.append(part);
}
QEventLoop loop;
QNetworkReply* reply = manager.post(req,&multiPart);
if(!QPointer(qApp)){
reply->deleteLater();
reply = nullptr;
return;
}
_cacheReply.append(reply);
QEventLoop loop;
connect(&manager,&QNetworkAccessManager::finished,&manager,[&loop](QNetworkReply *reply){loop.quit();});
connect(qApp,&QGuiApplication::aboutToQuit,&manager, [&loop](){loop.quit();});
connect(qApp,&QGuiApplication::aboutToQuit,&manager, [&loop,reply](){reply->abort(),loop.quit();});
connect(reply,&QNetworkReply::uploadProgress,reply,[=](qint64 bytesSent, qint64 bytesTotal){
onUploadProgress(callable,bytesSent,bytesTotal);
});

View File

@ -36,6 +36,22 @@ bool FluTheme::eventFilter(QObject *obj, QEvent *event){
return false;
}
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){
QString name = enumType.key(i);
int icon = enumType.value(i);
if(keyword.isEmpty() || name.contains(keyword)){
QJsonObject obj;
obj.insert("name",name);
obj.insert("icon",icon);
arr.append(obj);
}
}
return arr;
}
bool FluTheme::systemDark(){
#if (QT_VERSION >= QT_VERSION_CHECK(6, 5, 0))
return (QGuiApplication::styleHints()->colorScheme() == Qt::ColorScheme::Dark);

View File

@ -3,6 +3,8 @@
#include <QObject>
#include <QtQml/qqml.h>
#include <QJsonArray>
#include <QJsonObject>
#include "FluColorSet.h"
#include "stdafx.h"
#include "singleton.h"
@ -26,9 +28,10 @@ private:
bool systemDark();
public:
SINGLETONG(FluTheme)
Q_INVOKABLE QJsonArray awesomeList(const QString& keyword = "");
Q_SIGNAL void darkChanged();
static FluTheme *create(QQmlEngine *qmlEngine, QJSEngine *jsEngine){return getInstance();}
bool dark();
Q_SIGNAL void darkChanged();
private:
bool _dark;
bool _systemDark;

View File

@ -1,7 +1,7 @@
#include "FluentUI.h"
#include <QGuiApplication>
#include "WindowHelper.h"
#include "WindowLifecycle.h"
#include "Def.h"
#include "FluApp.h"
#include "FluColors.h"
@ -42,7 +42,7 @@ void FluentUI::registerTypes(const char *uri){
#if (QT_VERSION < QT_VERSION_CHECK(6, 2, 0))
Q_INIT_RESOURCE(fluentui);
#endif
qmlRegisterType<WindowHelper>(uri,major,minor,"WindowHelper");
qmlRegisterType<WindowLifecycle>(uri,major,minor,"WindowLifecycle");
qmlRegisterType<QRCode>(uri,major,minor,"QRCode");
qmlRegisterType<FluCaptcha>(uri,major,minor,"FluCaptcha");
qmlRegisterType<FluWatermark>(uri,major,minor,"FluWatermark");

View File

@ -202,7 +202,6 @@ Item {
d.dropIndex = -1
return
}
console.debug(index)
if(tree_model.hitHasChildrenExpanded(index) && y>index*control.cellHeight+control.cellHeight/2){
d.dropIndex = index + 1
d.isDropTopArea = true

View File

@ -19,9 +19,9 @@ Window {
}
property var _pageRegister
property string _route
property var closeFunc: function(event){
property var closeListener: function(event){
if(closeDestory){
deleteWindow()
destoryOnClose()
}else{
visible = false
event.accepted = false
@ -31,12 +31,18 @@ Window {
id:window
color:"transparent"
Component.onCompleted: {
helper.initWindow(window)
lifecycle.onCompleted(window)
initArgument(argument)
}
Component.onDestruction: {
lifecycle.onDestruction()
}
onVisibleChanged: {
lifecycle.onVisible(visible)
}
Connections{
target: window
function onClosing(event){closeFunc(event)}
function onClosing(event){closeListener(event)}
}
Component{
id:com_background
@ -126,8 +132,11 @@ Window {
}
}
}
WindowHelper{
id:helper
WindowLifecycle{
id:lifecycle
}
function destoryOnClose(){
lifecycle.onDestoryOnClose()
}
function showLoading(text = "加载中...",cancel = true){
loader_loading.loadingText = text
@ -150,10 +159,7 @@ Window {
infoBar.showError(text,duration,moremsg)
}
function registerForWindowResult(path){
return helper.createRegister(window,path)
}
function deleteWindow(){
FluApp.deleteWindow(window)
return lifecycle.createRegister(window,path)
}
function onResult(data){
if(_pageRegister){

View File

@ -4,7 +4,7 @@ import QtQuick.tooling 1.2
// It is used for QML tooling purposes only.
//
// This file was auto-generated by:
// 'qmlplugindump -nonrelocatable FluentUI 1.0 D:\QtProjects\build-FluentUI-Desktop_Qt_5_15_2_MSVC2019_64bit-Release\src'
// 'qmlplugindump -nonrelocatable FluentUI 1.0 D:/QtProjects/build-FluentUI-Desktop_Qt_5_15_2_MSVC2019_64bit-Release/src'
Module {
dependencies: ["QtQuick 2.0"]
@ -288,10 +288,11 @@ Module {
}
Component {
name: "FluTreeModel"
prototype: "QAbstractTableModel"
prototype: "QAbstractItemModel"
exports: ["FluentUI/FluTreeModel 1.0"]
exportMetaObjectRevisions: [0]
Property { name: "dataSourceSize"; type: "int" }
Property { name: "selectionModel"; type: "QList<Node*>" }
Method {
name: "removeRows"
Parameter { name: "row"; type: "int" }
@ -327,7 +328,29 @@ Module {
name: "dragAnddrop"
Parameter { name: "dragIndex"; type: "int" }
Parameter { name: "dropIndex"; type: "int" }
Parameter { name: "isDropTopArea"; type: "bool" }
}
Method {
name: "getNode"
type: "Node*"
Parameter { name: "row"; type: "int" }
}
Method {
name: "refreshNode"
Parameter { name: "row"; type: "int" }
}
Method {
name: "checkRow"
Parameter { name: "row"; type: "int" }
Parameter { name: "chekced"; type: "bool" }
}
Method {
name: "hitHasChildrenExpanded"
type: "bool"
Parameter { name: "row"; type: "int" }
}
Method { name: "allExpand" }
Method { name: "allCollapse" }
}
Component {
name: "FluTreeViewType"
@ -2123,7 +2146,6 @@ Module {
Parameter { name: "value"; type: "QVariant" }
}
}
Component { name: "QAbstractTableModel"; prototype: "QAbstractItemModel" }
Component {
name: "QRCode"
defaultProperty: "data"
@ -2168,14 +2190,20 @@ Module {
}
}
Component {
name: "WindowHelper"
name: "WindowLifecycle"
prototype: "QObject"
exports: ["FluentUI/WindowHelper 1.0"]
exports: ["FluentUI/WindowLifecycle 1.0"]
exportMetaObjectRevisions: [0]
Method {
name: "initWindow"
name: "onCompleted"
Parameter { name: "window"; type: "QQuickWindow"; isPointer: true }
}
Method { name: "onDestruction" }
Method {
name: "onVisible"
Parameter { name: "visible"; type: "bool" }
}
Method { name: "onDestoryOnClose" }
Method {
name: "createRegister"
type: "QVariant"
@ -2286,10 +2314,13 @@ Module {
Property { name: "textColor"; type: "QColor" }
Property { name: "minimizeNormalColor"; type: "QColor" }
Property { name: "minimizeHoverColor"; type: "QColor" }
Property { name: "minimizePressColor"; type: "QColor" }
Property { name: "maximizeNormalColor"; type: "QColor" }
Property { name: "maximizeHoverColor"; type: "QColor" }
Property { name: "maximizePressColor"; type: "QColor" }
Property { name: "closeNormalColor"; type: "QColor" }
Property { name: "closeHoverColor"; type: "QColor" }
Property { name: "closePressColor"; type: "QColor" }
Property { name: "showDark"; type: "bool" }
Property { name: "showClose"; type: "bool" }
Property { name: "showMinimize"; type: "bool" }
@ -2549,6 +2580,7 @@ Module {
Property { name: "size"; type: "double" }
Property { name: "textRight"; type: "bool" }
Property { name: "textSpacing"; type: "double" }
Property { name: "enableAnimation"; type: "bool" }
Property { name: "clickListener"; type: "QVariant" }
Property { name: "textColor"; type: "QColor" }
}
@ -2959,16 +2991,17 @@ Module {
defaultProperty: "data"
Property { name: "logo"; type: "QUrl" }
Property { name: "title"; type: "string" }
Property { name: "items"; type: "FluObject_QMLTYPE_148"; isPointer: true }
Property { name: "footerItems"; type: "FluObject_QMLTYPE_148"; isPointer: true }
Property { name: "items"; type: "FluObject_QMLTYPE_140"; isPointer: true }
Property { name: "footerItems"; type: "FluObject_QMLTYPE_140"; isPointer: true }
Property { name: "displayMode"; type: "int" }
Property { name: "autoSuggestBox"; type: "QQmlComponent"; isPointer: true }
Property { name: "actionItem"; type: "QQmlComponent"; isPointer: true }
Property { name: "topPadding"; type: "int" }
Property { name: "navWidth"; type: "int" }
Property { name: "pageMode"; type: "int" }
Property { name: "navItemRightMenu"; type: "FluMenu_QMLTYPE_52"; isPointer: true }
Property { name: "navItemExpanderRightMenu"; type: "FluMenu_QMLTYPE_52"; isPointer: true }
Property { name: "cellHeight"; type: "int" }
Property { name: "cellWidth"; type: "int" }
Signal { name: "logoClicked" }
Method { name: "collapseAll"; type: "QVariant" }
Method {
@ -3053,6 +3086,7 @@ Module {
Property { name: "order"; type: "int" }
Property { name: "icon"; type: "int" }
Property { name: "url"; type: "QVariant" }
Property { name: "disabled"; type: "bool" }
Property { name: "cusIcon"; type: "QQmlComponent"; isPointer: true }
Property { name: "infoBadge"; type: "QQmlComponent"; isPointer: true }
Property { name: "recentlyAdded"; type: "bool" }
@ -3093,6 +3127,7 @@ Module {
Property { name: "_idx"; type: "int" }
Property { name: "title"; type: "string" }
Property { name: "icon"; type: "QVariant" }
Property { name: "disabled"; type: "bool" }
Property { name: "cusIcon"; type: "QQmlComponent"; isPointer: true }
Property { name: "isExpand"; type: "bool" }
Property { name: "parent"; type: "QVariant" }
@ -3676,9 +3711,25 @@ Module {
Property { name: "dataSource"; type: "QVariant" }
Property { name: "showLine"; type: "bool" }
Property { name: "draggable"; type: "bool" }
Property { name: "cellHeight"; type: "int" }
Property { name: "depthPadding"; type: "int" }
Property { name: "checkable"; type: "bool" }
Property { name: "lineColor"; type: "QColor" }
Method { name: "selectionModel"; type: "QVariant" }
Method { name: "count"; type: "QVariant" }
Method { name: "visibleCount"; type: "QVariant" }
Method {
name: "collapse"
type: "QVariant"
Parameter { name: "rowIndex"; type: "QVariant" }
}
Method {
name: "expand"
type: "QVariant"
Parameter { name: "rowIndex"; type: "QVariant" }
}
Method { name: "allExpand"; type: "QVariant" }
Method { name: "allCollapse"; type: "QVariant" }
}
Component {
prototype: "QQuickWindowQmlImpl"
@ -3695,12 +3746,13 @@ Module {
Property { name: "backgroundColor"; type: "QColor" }
Property { name: "_pageRegister"; type: "QVariant" }
Property { name: "_route"; type: "string" }
Property { name: "closeFunc"; type: "QVariant" }
Property { name: "closeListener"; type: "QVariant" }
Property { name: "content"; type: "QObject"; isList: true; isReadonly: true }
Signal {
name: "initArgument"
Parameter { name: "argument"; type: "QVariant" }
}
Method { name: "destoryOnClose"; type: "QVariant" }
Method {
name: "showLoading"
type: "QVariant"
@ -3741,7 +3793,6 @@ Module {
type: "QVariant"
Parameter { name: "path"; type: "QVariant" }
}
Method { name: "deleteWindow"; type: "QVariant" }
Method {
name: "onResult"
type: "QVariant"

View File

@ -202,7 +202,6 @@ Item {
d.dropIndex = -1
return
}
console.debug(index)
if(tree_model.hitHasChildrenExpanded(index) && y>index*control.cellHeight+control.cellHeight/2){
d.dropIndex = index + 1
d.isDropTopArea = true

View File

@ -18,9 +18,9 @@ Window {
}
property var _pageRegister
property string _route
property var closeFunc: function(event){
property var closeListener: function(event){
if(closeDestory){
deleteWindow()
destoryOnClose()
}else{
visible = false
event.accepted = false
@ -30,12 +30,18 @@ Window {
id:window
color:"transparent"
Component.onCompleted: {
helper.initWindow(window)
lifecycle.onCompleted(window)
initArgument(argument)
}
Component.onDestruction: {
lifecycle.onDestruction()
}
onVisibleChanged: {
lifecycle.onVisible(visible)
}
Connections{
target: window
function onClosing(event){closeFunc(event)}
function onClosing(event){closeListener(event)}
}
Component{
id:com_background
@ -125,8 +131,11 @@ Window {
}
}
}
WindowHelper{
id:helper
WindowLifecycle{
id:lifecycle
}
function destoryOnClose(){
lifecycle.onDestoryOnClose()
}
function showLoading(text = "加载中...",cancel = true){
loader_loading.loadingText = text
@ -149,10 +158,7 @@ Window {
infoBar.showError(text,duration,moremsg)
}
function registerForWindowResult(path){
return helper.createRegister(window,path)
}
function deleteWindow(){
FluApp.deleteWindow(window)
return lifecycle.createRegister(window,path)
}
function onResult(data){
if(_pageRegister){

View File

@ -1,17 +0,0 @@
#include "WindowHelper.h"
#include "FluRegister.h"
WindowHelper::WindowHelper(QObject *parent):QObject{parent}{
}
void WindowHelper::initWindow(QQuickWindow* window){
this->window = window;
}
QVariant WindowHelper::createRegister(QQuickWindow* window,const QString& path){
FluRegister *p = new FluRegister(window);
p->from(window);
p->path(path);
return QVariant::fromValue(p);
}

View File

@ -1,26 +0,0 @@
#ifndef WINDOWHELPER_H
#define WINDOWHELPER_H
#include <QObject>
#include <QQuickWindow>
#include <QtQml/qqml.h>
#include <QQuickItem>
#include <QWindow>
#include <QJsonObject>
/**
* @brief The WindowHelper class
*/
class WindowHelper : public QObject
{
Q_OBJECT
QML_NAMED_ELEMENT(WindowHelper)
public:
explicit WindowHelper(QObject *parent = nullptr);
Q_INVOKABLE void initWindow(QQuickWindow* window);
Q_INVOKABLE QVariant createRegister(QQuickWindow* window,const QString& path);
private:
QQuickWindow* window;
};
#endif // WINDOWHELPER_H

29
src/WindowLifecycle.cpp Normal file
View File

@ -0,0 +1,29 @@
#include "WindowLifecycle.h"
#include "FluApp.h"
#include "FluRegister.h"
WindowLifecycle::WindowLifecycle(QObject *parent):QObject{parent}{
}
void WindowLifecycle::onCompleted(QQuickWindow* window){
this->_window = window;
FluApp::getInstance()->addWindow(this->_window);
}
void WindowLifecycle::onDestoryOnClose(){
FluApp::getInstance()->removeWindow(this->_window);
}
void WindowLifecycle::onDestruction(){
}
void WindowLifecycle::onVisible(bool visible){
}
QVariant WindowLifecycle::createRegister(QQuickWindow* window,const QString& path){
FluRegister *p = new FluRegister(window);
p->from(window);
p->path(path);
return QVariant::fromValue(p);
}

29
src/WindowLifecycle.h Normal file
View File

@ -0,0 +1,29 @@
#ifndef WINDOWLIFECYCLE_H
#define WINDOWLIFECYCLE_H
#include <QObject>
#include <QQuickWindow>
#include <QtQml/qqml.h>
#include <QQuickItem>
#include <QWindow>
#include <QJsonObject>
/**
* @brief The WindowLifecycle class
*/
class WindowLifecycle : public QObject
{
Q_OBJECT
QML_NAMED_ELEMENT(WindowLifecycle)
public:
explicit WindowLifecycle(QObject *parent = nullptr);
Q_INVOKABLE void onCompleted(QQuickWindow* window);
Q_INVOKABLE void onDestruction();
Q_INVOKABLE void onVisible(bool visible);
Q_INVOKABLE void onDestoryOnClose();
Q_INVOKABLE QVariant createRegister(QQuickWindow* window,const QString& path);
private:
QQuickWindow* _window;
};
#endif // WINDOWLIFECYCLE_H