FluentUI/src/FluApp.cpp

73 lines
1.9 KiB
C++
Raw Normal View History

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-26 23:47:07 +08:00
#include "FramelessView.h"
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}
{
isDark(true);
}
2023-02-26 23:47:07 +08:00
void FluApp::setAppWindow(QWindow *window){
appWindow = window;
}
void FluApp::run(){
if(!routes().contains(initialRoute())){
qErrnoWarning("没有找到当前路由");
return;
}
FramelessView *view = new FramelessView();
view->engine()->rootContext()->setContextProperty("FluApp",FluApp::getInstance());
2023-02-27 18:46:39 +08:00
view->setColor(QColor(255,0,0,1));
2023-02-26 23:47:07 +08:00
const QUrl url(routes().value(initialRoute()).toString());
QObject::connect(view, &QQuickView::statusChanged, view, [&](QQuickView::Status status) {
if (status == QQuickView::Status::Ready) {
2023-02-27 18:46:39 +08:00
qDebug()<<"-----------winId:"<<view->winId();
2023-02-26 23:47:07 +08:00
}
});
QObject::connect(view->engine(), &QQmlEngine::quit, qApp, &QCoreApplication::quit);
QObject::connect(qApp, &QGuiApplication::aboutToQuit, qApp, [&view](){view->setSource({});});
2023-02-27 18:46:39 +08:00
// view->setTitle("FluentUI");
2023-02-26 23:47:07 +08:00
view->setSource(url);
view->moveToScreenCenter();
view->show();
}
void FluApp::navigate(const QString& route){
if(!routes().contains(route)){
qErrnoWarning("没有找到当前路由");
return;
}
FramelessView *view = new FramelessView();
view->engine()->rootContext()->setContextProperty("FluApp",FluApp::getInstance());
2023-02-27 18:46:39 +08:00
view->setColor(isDark() ? QColor(0,0,0,1) : QColor(255, 255, 255, 1));
2023-02-26 23:47:07 +08:00
view->setSource((routes().value(route).toString()));
view->closeDeleteLater();
view->moveToScreenCenter();
view->show();
}
2023-02-27 18:46:39 +08:00
void FluApp::getWIdByWindow(QWindow *window){
qDebug()<< window->winId();
window->winId();
}