add files from main project

This commit is contained in:
pengfei.zhou
2019-12-04 15:51:46 +08:00
parent 2ca38388f3
commit dbdd1770ef
19 changed files with 579 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
#ifndef NATIVE_BRIDGE_H
#define NATIVE_BRIDGE_H
#include <QObject>
#include <QDebug>
class NativeBridge : public QObject {
Q_OBJECT
public:
NativeBridge(QObject *parent = nullptr) : QObject(parent) {}
Q_INVOKABLE void function() {
}
};
#endif // NATIVE_BRIDGE_H

View File

@@ -0,0 +1,18 @@
#ifndef NATIVE_EMPTY_H
#define NATIVE_EMPTY_H
#include <QObject>
#include <QDebug>
class NativeEmpty : public QObject {
Q_OBJECT
public:
NativeEmpty(QObject *parent = nullptr) : QObject(parent) {}
Q_INVOKABLE void function() {
qDebug() << "nativeEmpty";
}
};
#endif // NATIVE_EMPTY_H

24
doric/native/native_log.h Normal file
View File

@@ -0,0 +1,24 @@
#ifndef NATIVELOG_H
#define NATIVELOG_H
#include <QObject>
#include <QDebug>
class NativeLog : public QObject {
Q_OBJECT
public:
NativeLog(QObject *parent = nullptr) : QObject(parent) {}
Q_INVOKABLE void function(QString level, QString content) {
if (level == 'w') {
qWarning() << content;
} else if (level == 'd') {
qDebug() << content;
} else if (level == 'e') {
qCritical() << content;
}
}
};
#endif // NATIVELOG_H

View File

@@ -0,0 +1,51 @@
#ifndef NATIVE_TIMER_H
#define NATIVE_TIMER_H
#include <QJSEngine>
#include <QObject>
#include <QSet>
#include <QTimer>
#include "constant.h"
class NativeTimer : public QObject {
Q_OBJECT
private:
QSet<long> *deletedTimerIds = new QSet<long>();
QJSEngine* engine;
public:
NativeTimer(QJSEngine* engine, QObject *parent = nullptr) : QObject(parent) {
this->engine = engine;
}
Q_INVOKABLE void setTimer(long timerId, int time, bool repeat) {
QTimer* timer = new QTimer(this);
timer->setSingleShot(!repeat);
connect(timer, &QTimer::timeout, this, [=] () {
if (deletedTimerIds->contains(timerId)) {
deletedTimerIds->remove(timerId);
delete timer;
} else {
engine->evaluate(
Constant::GLOBAL_DORIC + "." +
Constant::DORIC_TIMER_CALLBACK + "(" +
QString::number(timerId) + ")"
);
if (!repeat) {
deletedTimerIds->remove(timerId);
delete timer;
}
}
});
timer->start(time);
}
Q_INVOKABLE void clearTimer(long timerId) {
deletedTimerIds->insert(timerId);
}
};
#endif // NATIVE_TIMER_H