mirror of
https://github.com/zhuzichu520/FluentUI.git
synced 2024-11-23 11:17:15 +08:00
107 lines
3.1 KiB
C++
107 lines
3.1 KiB
C++
#include "FluApp.h"
|
|
|
|
#include <QQmlEngine>
|
|
#include <QGuiApplication>
|
|
#include <QQmlContext>
|
|
#include <QQuickItem>
|
|
#include <QTimer>
|
|
#include <QUuid>
|
|
#include <QFontDatabase>
|
|
#include <QClipboard>
|
|
#include <FramelessHelper/Quick/framelessquickmodule.h>
|
|
#include <FramelessHelper/Core/private/framelessconfig_p.h>
|
|
|
|
FRAMELESSHELPER_USE_NAMESPACE
|
|
|
|
FluApp::FluApp(QObject *parent):QObject{parent}{
|
|
httpInterceptor(nullptr);
|
|
}
|
|
|
|
FluApp::~FluApp(){
|
|
}
|
|
|
|
void FluApp::init(QQuickWindow *window){
|
|
this->_application = window;
|
|
qputenv("QT_QUICK_CONTROLS_STYLE","Basic");
|
|
FramelessHelper::Quick::initialize();
|
|
FramelessConfig::instance()->set(Global::Option::DisableLazyInitializationForMicaMaterial);
|
|
FramelessConfig::instance()->set(Global::Option::CenterWindowBeforeShow);
|
|
FramelessConfig::instance()->set(Global::Option::ForceNonNativeBackgroundBlur);
|
|
FramelessConfig::instance()->set(Global::Option::EnableBlurBehindWindow);
|
|
#ifdef Q_OS_WIN
|
|
FramelessConfig::instance()->set(Global::Option::EnableBlurBehindWindow,false);
|
|
#endif
|
|
#ifdef Q_OS_MACOS
|
|
FramelessConfig::instance()->set(Global::Option::ForceNonNativeBackgroundBlur,false);
|
|
#endif
|
|
QQmlEngine *engine = qmlEngine(_application);
|
|
FramelessHelper::Quick::registerTypes(engine);
|
|
}
|
|
|
|
void FluApp::run(){
|
|
navigate(initialRoute());
|
|
}
|
|
|
|
void FluApp::navigate(const QString& route,const QJsonObject& argument,FluRegister* fluRegister){
|
|
if(!routes().contains(route)){
|
|
qCritical()<<"No route found "<<route;
|
|
return;
|
|
}
|
|
QQmlEngine *engine = qmlEngine(_application);
|
|
QQmlComponent component(engine, routes().value(route).toString());
|
|
if (component.isError()) {
|
|
qCritical() << component.errors();
|
|
return;
|
|
}
|
|
QVariantMap properties;
|
|
properties.insert("_route",route);
|
|
if(fluRegister){
|
|
properties.insert("_pageRegister",QVariant::fromValue(fluRegister));
|
|
}
|
|
properties.insert("argument",argument);
|
|
QQuickWindow *win=nullptr;
|
|
for (const auto& pair : _windows.toStdMap()) {
|
|
QString r = pair.second->property("_route").toString();
|
|
if(r == route){
|
|
win = pair.second;
|
|
break;
|
|
}
|
|
}
|
|
if(win){
|
|
int launchMode = win->property("launchMode").toInt();
|
|
if(launchMode == 1){
|
|
win->setProperty("argument",argument);
|
|
win->show();
|
|
win->raise();
|
|
win->requestActivate();
|
|
return;
|
|
}else if(launchMode == 2){
|
|
win->close();
|
|
}
|
|
}
|
|
win = qobject_cast<QQuickWindow*>(component.createWithInitialProperties(properties));
|
|
if(fluRegister){
|
|
fluRegister->to(win);
|
|
}
|
|
win->setColor(QColor(Qt::transparent));
|
|
}
|
|
|
|
void FluApp::exit(int retCode){
|
|
for (const auto& pair : _windows.toStdMap()) {
|
|
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;
|
|
}
|
|
}
|