-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathqctime.cpp
78 lines (57 loc) · 1.29 KB
/
qctime.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
#include <QTime>
#include <QtCore>
#include "qctime.h"
#include "priv/qcutils.h"
static QTime toTime(QJSValue value) {
QTime res;
if (value.hasProperty("value")) {
res = value.property("value").toVariant().value<QTime>();
} else {
res = value.toVariant().value<QTime>();
}
return res;
}
QCTime::QCTime(QObject *parent) : QObject(parent)
{
}
QJSValue QCTime::create()
{
QJSValueList args;
return creator.call(args);
}
QJSValue QCTime::_createValue()
{
QTime time;
QJSValue value = m_engine->toScriptValue<QTime>(time);
return value;
}
void QCTime::start(QJSValue object)
{
QTime time = toTime(object);
time.start();
object.setProperty("value",m_engine->toScriptValue<QTime>(time));
}
int QCTime::elapsed(QJSValue object)
{
QTime time = toTime(object);
return time.elapsed();
}
int QCTime::restart(QJSValue object)
{
QTime time = toTime(object);
int ret = time.restart();
object.setProperty("value",m_engine->toScriptValue<QTime>(time));
return ret;
}
QQmlEngine *QCTime::engine() const
{
return m_engine;
}
void QCTime::setEngine(QQmlEngine *engine)
{
m_engine = engine;
if (!m_engine) {
return;
}
creator = QCUtils::loadJavascript(m_engine, "qrc:///QuickCross/js/time.js","create");
}