-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathcpp_qt_live_coding_plugin.cpp
More file actions
59 lines (49 loc) · 1.61 KB
/
Copy pathcpp_qt_live_coding_plugin.cpp
File metadata and controls
59 lines (49 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "cpp_qt_live_coding_plugin.h"
#include "filewatcher.h"
#include "livecoding.h"
#include "projectbrowser.h"
#include <QFile>
#include <qqml.h>
static void initResources()
{
Q_INIT_RESOURCE(com_machinekoder_livecoding);
}
static const struct {
const char* type;
int major, minor;
} qmldir[] = {
{ "LiveCodingPanel", 1, 0 },
{ "FileSelectionDialog", 1, 0 },
};
void CppQtLiveCodingPlugin::registerTypes(const char* uri)
{
initResources();
// @uri com.machinekoder.live
qmlRegisterType<FileWatcher>(uri, 1, 0, "FileWatcher");
qmlRegisterType<ProjectBrowser>(uri, 1, 0, "ProjectBrowser");
qmlRegisterSingletonType<LiveCoding>(uri, 1, 0, "LiveCoding", LiveCoding::qmlSingletonProvider);
const QString filesLocation = fileLocation();
for (int i = 0; i < int(sizeof(qmldir) / sizeof(qmldir[0])); i++) {
qmlRegisterType(QUrl(filesLocation + "/" + qmldir[i].type + ".qml"), uri, qmldir[i].major, qmldir[i].minor, qmldir[i].type);
}
}
void CppQtLiveCodingPlugin::initializeEngine(QQmlEngine* engine, const char* uri)
{
Q_UNUSED(uri)
if (isLoadedFromResource())
engine->addImportPath(QStringLiteral("qrc:/"));
}
QString CppQtLiveCodingPlugin::fileLocation() const
{
if (isLoadedFromResource())
return QStringLiteral("qrc:/com/machinekoder/live");
return baseUrl().toString();
}
bool CppQtLiveCodingPlugin::isLoadedFromResource() const
{
// If one file is missing, it will load all the files from the resource
QFile file(baseUrl().toLocalFile() + "/" + qmldir[0].type + ".qml");
if (!file.exists())
return true;
return false;
}