2021-05-04 18:31:15 +00:00
|
|
|
#include "sandboxapp.h"
|
|
|
|
|
|
|
|
#include <QQmlContext>
|
2021-05-12 08:11:25 +00:00
|
|
|
#include <QWindow>
|
2021-05-04 18:31:15 +00:00
|
|
|
#include <QDebug>
|
|
|
|
|
2021-05-20 06:25:52 +00:00
|
|
|
#include "statuswindow.h"
|
2021-09-13 13:18:05 +00:00
|
|
|
#include "spellchecker.h"
|
2021-05-20 06:25:52 +00:00
|
|
|
|
2021-05-04 18:31:15 +00:00
|
|
|
SandboxApp::SandboxApp(int &argc, char **argv)
|
|
|
|
: QGuiApplication(argc, argv),
|
|
|
|
m_handler(new Handler(this))
|
|
|
|
{
|
|
|
|
connect(m_handler, &Handler::restartQml, this, &SandboxApp::restartEngine, Qt::QueuedConnection);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SandboxApp::startEngine()
|
|
|
|
{
|
2021-05-20 06:25:52 +00:00
|
|
|
qmlRegisterType<StatusWindow>("Sandbox", 0, 1, "StatusWindow");
|
2021-09-13 13:18:05 +00:00
|
|
|
qmlRegisterType<SpellChecker>("Sandbox", 0, 1, "Spellchecker");
|
2021-05-20 06:25:52 +00:00
|
|
|
|
2021-06-15 09:16:22 +00:00
|
|
|
#ifdef QT_DEBUG
|
2022-07-19 10:29:18 +00:00
|
|
|
const QUrl url = QUrl::fromLocalFile(SRC_DIR + QStringLiteral("/main.qml"));
|
2021-06-15 09:16:22 +00:00
|
|
|
#else
|
|
|
|
const QUrl url(QStringLiteral("qrc:/main.qml"));
|
|
|
|
#endif
|
2021-05-04 18:31:15 +00:00
|
|
|
|
|
|
|
m_engine.rootContext()->setContextProperty("app", m_handler);
|
|
|
|
|
2021-06-15 09:16:22 +00:00
|
|
|
|
|
|
|
#ifdef QT_DEBUG
|
2022-07-19 10:29:18 +00:00
|
|
|
m_engine.addImportPath(SRC_DIR + QStringLiteral("/../src"));
|
2021-06-15 09:16:22 +00:00
|
|
|
#else
|
2022-07-19 07:28:07 +00:00
|
|
|
m_engine.addImportPath(QStringLiteral(":/"));
|
2021-06-15 09:16:22 +00:00
|
|
|
#endif
|
2021-05-04 18:31:15 +00:00
|
|
|
qDebug() << m_engine.importPathList();
|
|
|
|
QObject::connect(&m_engine, &QQmlApplicationEngine::objectCreated,
|
|
|
|
this, [url](QObject *obj, const QUrl &objUrl) {
|
|
|
|
if (!obj && url == objUrl)
|
|
|
|
QCoreApplication::exit(-1);
|
|
|
|
}, Qt::QueuedConnection);
|
|
|
|
m_engine.load(url);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SandboxApp::restartEngine()
|
|
|
|
{
|
|
|
|
const QUrl url(applicationDirPath() + "/../main.qml");
|
2021-05-12 08:11:25 +00:00
|
|
|
QWindow *rootWindow = qobject_cast<QWindow*>(m_engine.rootObjects().at(0));
|
|
|
|
if (rootWindow) {
|
|
|
|
rootWindow->close();
|
2021-06-01 10:01:47 +00:00
|
|
|
rootWindow->deleteLater();
|
2021-05-12 08:11:25 +00:00
|
|
|
}
|
2021-05-04 18:31:15 +00:00
|
|
|
m_engine.clearComponentCache();
|
|
|
|
m_engine.load(url);
|
|
|
|
}
|