2023-02-26 23:47:07 +08:00
|
|
|
|
#include "FluApp.h"
|
|
|
|
|
|
|
|
|
|
#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-03-02 12:20:16 +08:00
|
|
|
|
#include <QClipboard>
|
2023-04-11 23:12:31 +08:00
|
|
|
|
#include "FluTheme.h"
|
2023-03-02 12:20:16 +08:00
|
|
|
|
#include "Def.h"
|
2023-02-26 23:47:07 +08:00
|
|
|
|
|
2023-04-11 23:12:31 +08:00
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
|
#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
|
|
|
|
|
|
|
|
|
FluApp* FluApp::m_instance = nullptr;
|
|
|
|
|
|
|
|
|
|
FluApp *FluApp::getInstance()
|
|
|
|
|
{
|
|
|
|
|
if(FluApp::m_instance == nullptr){
|
|
|
|
|
FluApp::m_instance = new FluApp;
|
|
|
|
|
}
|
|
|
|
|
return FluApp::m_instance;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-27 18:46:39 +08:00
|
|
|
|
FluApp::FluApp(QObject *parent)
|
|
|
|
|
: QObject{parent}
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
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-04-11 23:12:31 +08:00
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
|
if(!isCompositionEnabled()){
|
|
|
|
|
FluTheme::getInstance()->frameless(false);
|
|
|
|
|
}
|
|
|
|
|
#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-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);
|
|
|
|
|
QQuickWindow *view = qobject_cast<QQuickWindow*>(component.createWithInitialProperties(properties));
|
|
|
|
|
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
|
|
|
|
if(view->maximumWidth()==view->minimumWidth()&&view->maximumHeight()==view->minimumHeight()){
|
|
|
|
|
view->resize(view->minimumSize());
|
2023-02-27 23:04:52 +08:00
|
|
|
|
}
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FluApp::clipText(const QString& text){
|
|
|
|
|
QGuiApplication::clipboard()->setText(text);
|
|
|
|
|
}
|
2023-03-30 17:16:57 +08:00
|
|
|
|
|
|
|
|
|
QString FluApp::uuid(){
|
|
|
|
|
return QUuid::createUuid().toString();
|
|
|
|
|
}
|