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-11 23:12:31 +08:00
|
|
|
|
#ifdef Q_OS_WIN
|
2023-04-22 19:25:10 +08:00
|
|
|
|
#pragma comment(lib, "Dwmapi.lib")
|
|
|
|
|
#pragma comment(lib, "User32.lib")
|
2023-04-11 23:12:31 +08:00
|
|
|
|
#include <dwmapi.h>
|
|
|
|
|
#include <Windows.h>
|
|
|
|
|
#include <windowsx.h>
|
|
|
|
|
static bool isCompositionEnabled()
|
|
|
|
|
{
|
|
|
|
|
BOOL composition_enabled = FALSE;
|
|
|
|
|
bool success = ::DwmIsCompositionEnabled(&composition_enabled) == S_OK;
|
|
|
|
|
return composition_enabled && success;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2023-02-26 23:47:07 +08:00
|
|
|
|
|
2023-04-27 09:38:57 +08:00
|
|
|
|
FluApp* FluApp::fluApp = nullptr;
|
2023-04-27 17:29:39 +08:00
|
|
|
|
|
2023-04-27 09:38:57 +08:00
|
|
|
|
FluTheme* FluApp::fluTheme = nullptr;
|
2023-04-27 17:29:39 +08:00
|
|
|
|
|
|
|
|
|
FluColors* FluApp::fluColors = nullptr;
|
|
|
|
|
|
|
|
|
|
FluTools* FluApp::fluTools = nullptr;
|
|
|
|
|
|
|
|
|
|
FluApp::FluApp(QObject *parent)
|
|
|
|
|
: QObject{parent}
|
|
|
|
|
{
|
|
|
|
|
QFontDatabase::addApplicationFont(":/FluentUI/Font/Segoe_Fluent_Icons.ttf");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FluApp::~FluApp(){
|
|
|
|
|
if (nativeEvent != Q_NULLPTR) {
|
|
|
|
|
delete nativeEvent;
|
|
|
|
|
nativeEvent = Q_NULLPTR;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-02-26 23:47:07 +08:00
|
|
|
|
|
2023-04-27 09:38:57 +08:00
|
|
|
|
void FluApp::setFluApp(FluApp* val){
|
|
|
|
|
FluApp::fluApp = val;
|
|
|
|
|
}
|
2023-04-27 17:29:39 +08:00
|
|
|
|
|
2023-04-27 09:38:57 +08:00
|
|
|
|
void FluApp::setFluTheme(FluTheme* val){
|
|
|
|
|
FluApp::fluTheme = val;
|
|
|
|
|
}
|
2023-04-27 17:29:39 +08:00
|
|
|
|
|
2023-04-27 09:38:57 +08:00
|
|
|
|
void FluApp::setFluColors(FluColors* val){
|
2023-04-27 17:29:39 +08:00
|
|
|
|
FluApp::fluColors = val;
|
2023-02-26 23:47:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-27 17:29:39 +08:00
|
|
|
|
void FluApp::setFluTools(FluTools* val){
|
|
|
|
|
FluApp::fluTools = val;
|
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-04-27 09:38:57 +08:00
|
|
|
|
QQmlEngine *engine = qmlEngine(appWindow);
|
|
|
|
|
QQmlComponent component(engine, ":/FluentUI/Controls/FluSingleton.qml");
|
|
|
|
|
component.create();
|
|
|
|
|
nativeEvent = new NativeEventFilter();
|
|
|
|
|
qApp->installNativeEventFilter(nativeEvent);
|
2023-02-26 23:47:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FluApp::run(){
|
2023-04-11 23:12:31 +08:00
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
|
if(!isCompositionEnabled()){
|
2023-04-27 09:38:57 +08:00
|
|
|
|
fluTheme->frameless(false);
|
2023-04-13 17:41:34 +08:00
|
|
|
|
}
|
2023-04-11 23:12:31 +08:00
|
|
|
|
#endif
|
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-27 09:38:57 +08:00
|
|
|
|
if(fluTheme->frameless()){
|
2023-04-12 00:15:38 +08:00
|
|
|
|
view->setFlag(Qt::FramelessWindowHint,true);
|
|
|
|
|
}
|
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-04-11 23:12:31 +08:00
|
|
|
|
view->show();
|
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);
|
|
|
|
|
}
|