/
qprogressbar_wrap.cpp
88 lines (75 loc) 路 3.1 KB
/
qprogressbar_wrap.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
#include "qprogressbar_wrap.h"
#include "src/cpp/QtWidgets/QWidget/qwidget_wrap.h"
#include "src/cpp/Extras/Utils/nutils.h"
#include <QWidget>
Napi::FunctionReference QProgressBarWrap::constructor;
Napi::Object QProgressBarWrap::init(Napi::Env env, Napi::Object exports) {
Napi::HandleScope scope(env);
char CLASSNAME[] = "QProgressBar";
Napi::Function func = DefineClass(env, CLASSNAME, {
InstanceMethod("setValue", &QProgressBarWrap::setValue),
InstanceMethod("setMaximum", &QProgressBarWrap::setMaximum),
InstanceMethod("setMinimum", &QProgressBarWrap::setMinimum),
InstanceMethod("setOrientation", &QProgressBarWrap::setOrientation),
InstanceMethod("value", &QProgressBarWrap::value),
QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QProgressBarWrap)
});
constructor = Napi::Persistent(func);
exports.Set(CLASSNAME, func);
return exports;
}
NProgressBar* QProgressBarWrap::getInternalInstance() {
return this->instance;
}
QProgressBarWrap::QProgressBarWrap(const Napi::CallbackInfo& info): Napi::ObjectWrap<QProgressBarWrap>(info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
if(info.Length() == 1) {
Napi::Object parentObject = info[0].As<Napi::Object>();
QWidgetWrap* parentWidgetWrap = Napi::ObjectWrap<QWidgetWrap>::Unwrap(parentObject);
this->instance = new NProgressBar(parentWidgetWrap->getInternalInstance()); //this sets the parent to current widget
}else if (info.Length() == 0){
this->instance = new NProgressBar();
}else {
Napi::TypeError::New(env, "Wrong number of arguments").ThrowAsJavaScriptException();
}
// Adds measure function on yoga node so that widget size is calculated based on its own size.
YGNodeSetMeasureFunc(this->instance->getFlexNode(), &extrautils::measureQtWidget);
}
QProgressBarWrap::~QProgressBarWrap() {
delete this->instance;
}
Napi::Value QProgressBarWrap::setValue(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
Napi::Number value = info[0].As<Napi::Number>();
this->instance->setValue(value.Int32Value());
return env.Null();
}
Napi::Value QProgressBarWrap::setMaximum(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
Napi::Number value = info[0].As<Napi::Number>();
this->instance->setMaximum(value.Int32Value());
return env.Null();
}
Napi::Value QProgressBarWrap::setMinimum(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
Napi::Number value = info[0].As<Napi::Number>();
this->instance->setMinimum(value.Int32Value());
return env.Null();
}
Napi::Value QProgressBarWrap::setOrientation(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
Napi::Number value = info[0].As<Napi::Number>();
this->instance->setOrientation(static_cast<Qt::Orientation>(value.Int32Value()));
return env.Null();
}
Napi::Value QProgressBarWrap::value(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
int value = this->instance->value();
return Napi::Number::New(env, value);
}