-
Notifications
You must be signed in to change notification settings - Fork 3
/
qcqmltypes.cpp
99 lines (70 loc) · 2.58 KB
/
qcqmltypes.cpp
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/* QuickCross Project
* License: APACHE-2.0
* Author: Ben Lau
* Project Site: https://github.com/benlau/quickcross
*
*/
#include <QtQml>
#include <QCImageLoader>
#include "qcdevice.h"
#include "qcstandardpaths.h"
#include "qcrect.h"
#include "qcline.h"
#include "qcimagereader.h"
#include "qcjsonreader.h"
#include "qceasingcurve.h"
#include "qcrefresher.h"
#include "qctime.h"
template<typename T>
static QObject* providerWithEngine(QQmlEngine *engine, QJSEngine *scriptEngine) {
Q_UNUSED(engine);
Q_UNUSED(scriptEngine);
T* object = new T();
object->setEngine(engine);
return object;
}
template<typename T>
static QObject* provider(QQmlEngine *engine, QJSEngine *scriptEngine) {
Q_UNUSED(engine);
Q_UNUSED(scriptEngine);
T* object = new T();
return object;
}
static QObject *rectProvider(QQmlEngine *engine, QJSEngine *scriptEngine) {
Q_UNUSED(engine);
Q_UNUSED(scriptEngine);
QCRect* object = new QCRect();
return object;
}
static QObject *deviceProvider(QQmlEngine *engine, QJSEngine *scriptEngine) {
Q_UNUSED(engine);
Q_UNUSED(scriptEngine);
QCDevice* object = new QCDevice();
return object;
}
static QObject *standardPathsProvider(QQmlEngine *engine, QJSEngine *scriptEngine) {
Q_UNUSED(engine);
Q_UNUSED(scriptEngine);
QCStandardPaths* object = new QCStandardPaths();
return object;
}
static void registerQmlTypes() {
qmlRegisterSingletonType<QCDevice>("QuickCross", 1, 0,
"Device", deviceProvider);
qmlRegisterSingletonType<QCDevice>("QuickCross", 1, 0,
"StandardPaths", standardPathsProvider);
qmlRegisterSingletonType<QCDevice>("QuickCross", 1, 0,
"Rect", rectProvider);
qmlRegisterSingletonType<QCDevice>("QuickCross", 1, 0,
"Line", provider<QCLine> );
qmlRegisterType<QCImageLoader>("QuickCross", 1, 0, "ImageLoader");
qmlRegisterType<QCImageReader>("QuickCross", 1, 0, "ImageReader");
qmlRegisterType<QCJsonReader>("QuickCross", 1, 0, "JsonReader");
qmlRegisterSingletonType<QCEasingCurve>("QuickCross", 1, 0,
"EasingCurve", providerWithEngine<QCEasingCurve> );
qmlRegisterSingletonType<QCRefresher>("QuickCross", 1, 0,
"Refresher", provider<QCRefresher> );
qmlRegisterSingletonType<QCTime>("QuickCross", 1, 0,
"Time", providerWithEngine<QCTime>);
}
Q_COREAPP_STARTUP_FUNCTION(registerQmlTypes)