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-02 12:20:16 +08:00
|
|
|
|
#include <QClipboard>
|
|
|
|
|
#include "Def.h"
|
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-03-05 23:39:13 +08:00
|
|
|
|
void FluApp::init(QWindow *window,QMap<QString, QVariant> properties){
|
|
|
|
|
this->appWindow = window;
|
|
|
|
|
this->properties = properties;
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FluApp::navigate(const QString& route){
|
|
|
|
|
if(!routes().contains(route)){
|
|
|
|
|
qErrnoWarning("没有找到当前路由");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-03-03 18:19:48 +08:00
|
|
|
|
bool isAppWindow = route == initialRoute();
|
2023-02-26 23:47:07 +08:00
|
|
|
|
FramelessView *view = new FramelessView();
|
2023-03-05 23:39:13 +08:00
|
|
|
|
|
|
|
|
|
QMapIterator<QString, QVariant> iterator(properties);
|
|
|
|
|
while (iterator.hasNext()) {
|
|
|
|
|
iterator.next();
|
|
|
|
|
QString key = iterator.key();
|
|
|
|
|
QVariant value = iterator.value();
|
|
|
|
|
view->engine()->rootContext()->setContextProperty(key,value);
|
|
|
|
|
}
|
2023-03-02 23:58:50 +08:00
|
|
|
|
view->setColor(QColor(Qt::transparent));
|
2023-02-27 23:04:52 +08:00
|
|
|
|
QObject::connect(view, &QQuickView::statusChanged, view, [&](QQuickView::Status status) {
|
|
|
|
|
if (status == QQuickView::Status::Ready) {
|
|
|
|
|
Q_EMIT windowReady(view);
|
2023-03-01 22:06:48 +08:00
|
|
|
|
view->moveToScreenCenter();
|
|
|
|
|
view->show();
|
2023-02-27 23:04:52 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
2023-02-26 23:47:07 +08:00
|
|
|
|
view->setSource((routes().value(route).toString()));
|
2023-02-27 23:04:52 +08:00
|
|
|
|
if(isAppWindow){
|
|
|
|
|
QObject::connect(view->engine(), &QQmlEngine::quit, qApp, &QCoreApplication::quit);
|
|
|
|
|
QObject::connect(qApp, &QGuiApplication::aboutToQuit, qApp, [&view](){view->setSource({});});
|
|
|
|
|
}else{
|
|
|
|
|
view->closeDeleteLater();
|
|
|
|
|
}
|
2023-02-26 23:47:07 +08:00
|
|
|
|
}
|
2023-02-27 18:46:39 +08:00
|
|
|
|
|
2023-02-27 23:04:52 +08:00
|
|
|
|
bool FluApp::equalsWindow(FramelessView *view,QWindow *window){
|
|
|
|
|
return view->winId() == window->winId();
|
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{
|
|
|
|
|
if(name.mid(3).contains(keyword)){
|
|
|
|
|
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);
|
|
|
|
|
}
|