2023-04-27 09:38:57 +08:00
|
|
|
|
#include "FluApp.h"
|
2023-02-26 23:47:07 +08:00
|
|
|
|
|
|
|
|
|
#include <QQmlEngine>
|
|
|
|
|
#include <QGuiApplication>
|
|
|
|
|
#include <QQmlContext>
|
2023-02-27 18:46:39 +08:00
|
|
|
|
#include <QQuickItem>
|
2023-02-27 23:04:52 +08:00
|
|
|
|
#include <QTimer>
|
2023-03-30 17:16:57 +08:00
|
|
|
|
#include <QUuid>
|
2023-04-27 09:38:57 +08:00
|
|
|
|
#include <QFontDatabase>
|
2023-03-02 12:20:16 +08:00
|
|
|
|
#include <QClipboard>
|
|
|
|
|
#include "Def.h"
|
2023-04-27 17:29:39 +08:00
|
|
|
|
|
2023-05-11 18:24:58 +08:00
|
|
|
|
FluApp* FluApp::m_instance = nullptr;
|
2023-04-27 17:29:39 +08:00
|
|
|
|
|
2023-05-11 18:24:58 +08:00
|
|
|
|
FluApp *FluApp::getInstance()
|
|
|
|
|
{
|
|
|
|
|
if(FluApp::m_instance == nullptr){
|
|
|
|
|
FluApp::m_instance = new FluApp;
|
|
|
|
|
}
|
|
|
|
|
return FluApp::m_instance;
|
|
|
|
|
}
|
2023-04-27 17:29:39 +08:00
|
|
|
|
|
|
|
|
|
FluApp::FluApp(QObject *parent)
|
|
|
|
|
: QObject{parent}
|
|
|
|
|
{
|
|
|
|
|
QFontDatabase::addApplicationFont(":/FluentUI/Font/Segoe_Fluent_Icons.ttf");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FluApp::~FluApp(){
|
2023-02-26 23:47:07 +08:00
|
|
|
|
|
2023-02-27 18:46:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-11 23:12:31 +08:00
|
|
|
|
void FluApp::init(QQuickWindow *window){
|
2023-03-05 23:39:13 +08:00
|
|
|
|
this->appWindow = window;
|
2023-02-26 23:47:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FluApp::run(){
|
2023-02-27 23:04:52 +08:00
|
|
|
|
navigate(initialRoute());
|
2023-02-26 23:47:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-13 21:18:51 +08:00
|
|
|
|
void FluApp::navigate(const QString& route,const QJsonObject& argument,FluRegister* fluRegister){
|
2023-02-26 23:47:07 +08:00
|
|
|
|
if(!routes().contains(route)){
|
|
|
|
|
qErrnoWarning("没有找到当前路由");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-04-11 23:12:31 +08:00
|
|
|
|
QQmlEngine *engine = qmlEngine(appWindow);
|
|
|
|
|
QQmlComponent component(engine, routes().value(route).toString());
|
|
|
|
|
QVariantMap properties;
|
2023-04-13 17:41:34 +08:00
|
|
|
|
properties.insert("route",route);
|
2023-03-13 21:18:51 +08:00
|
|
|
|
if(fluRegister){
|
2023-04-11 23:12:31 +08:00
|
|
|
|
properties.insert("pageRegister",QVariant::fromValue(fluRegister));
|
2023-03-13 21:18:51 +08:00
|
|
|
|
}
|
2023-04-11 23:12:31 +08:00
|
|
|
|
properties.insert("argument",argument);
|
2023-05-10 10:32:37 +08:00
|
|
|
|
QQuickWindow *view=nullptr;
|
|
|
|
|
for (auto& pair : wnds) {
|
|
|
|
|
QString r = pair->property("route").toString();
|
|
|
|
|
if(r == route){
|
|
|
|
|
view = pair;
|
|
|
|
|
break;
|
2023-04-13 17:41:34 +08:00
|
|
|
|
}
|
2023-05-10 10:32:37 +08:00
|
|
|
|
}
|
|
|
|
|
if(view){
|
|
|
|
|
//如果窗口存在,则判断启动模式
|
|
|
|
|
int launchMode = view->property("launchMode").toInt();
|
|
|
|
|
if(launchMode == 1){
|
|
|
|
|
view->setProperty("argument",argument);
|
|
|
|
|
view->show();
|
|
|
|
|
view->raise();
|
|
|
|
|
view->requestActivate();
|
|
|
|
|
return;
|
|
|
|
|
}else if(launchMode == 2){
|
|
|
|
|
view->close();
|
2023-04-13 17:41:34 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-05-10 10:32:37 +08:00
|
|
|
|
view = qobject_cast<QQuickWindow*>(component.createWithInitialProperties(properties));
|
2023-04-11 23:12:31 +08:00
|
|
|
|
wnds.insert(view->winId(),view);
|
|
|
|
|
if(fluRegister){
|
|
|
|
|
fluRegister->to(view);
|
2023-03-05 23:39:13 +08:00
|
|
|
|
}
|
2023-03-02 23:58:50 +08:00
|
|
|
|
view->setColor(QColor(Qt::transparent));
|
2023-02-27 18:46:39 +08:00
|
|
|
|
}
|
2023-03-02 12:20:16 +08:00
|
|
|
|
|
2023-03-02 18:21:43 +08:00
|
|
|
|
QJsonArray FluApp::awesomelist(const QString& keyword)
|
2023-03-02 12:20:16 +08:00
|
|
|
|
{
|
|
|
|
|
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);
|
2023-03-02 18:21:43 +08:00
|
|
|
|
if(keyword.isEmpty()){
|
|
|
|
|
QJsonObject obj;
|
|
|
|
|
obj.insert("name",name);
|
|
|
|
|
obj.insert("icon",icon);
|
|
|
|
|
arr.append(obj);
|
|
|
|
|
}else{
|
2023-03-11 00:29:06 +08:00
|
|
|
|
if(name.contains(keyword)){
|
2023-03-02 18:21:43 +08:00
|
|
|
|
QJsonObject obj;
|
|
|
|
|
obj.insert("name",name);
|
|
|
|
|
obj.insert("icon",icon);
|
|
|
|
|
arr.append(obj);
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-03-02 12:20:16 +08:00
|
|
|
|
}
|
|
|
|
|
return arr;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-19 09:41:08 +08:00
|
|
|
|
void FluApp::closeApp(){
|
|
|
|
|
qApp->exit(0);
|
|
|
|
|
}
|