forked from nodegui/nodegui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqsize_wrap.cpp
More file actions
154 lines (147 loc) · 6.06 KB
/
qsize_wrap.cpp
File metadata and controls
154 lines (147 loc) · 6.06 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
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#include "QtCore/QSize/qsize_wrap.h"
#include "Extras/Utils/nutils.h"
#include "QtCore/QVariant/qvariant_wrap.h"
Napi::FunctionReference QSizeWrap::constructor;
Napi::Object QSizeWrap::init(Napi::Env env, Napi::Object exports) {
Napi::HandleScope scope(env);
char CLASSNAME[] = "QSize";
Napi::Function func = DefineClass(
env, CLASSNAME,
{InstanceMethod("boundedTo", &QSizeWrap::boundedTo),
InstanceMethod("expandedTo", &QSizeWrap::expandedTo),
InstanceMethod("isEmpty", &QSizeWrap::isEmpty),
InstanceMethod("isNull", &QSizeWrap::isNull),
InstanceMethod("isValid", &QSizeWrap::isValid),
InstanceMethod("height", &QSizeWrap::height),
InstanceMethod("scale", &QSizeWrap::scale),
InstanceMethod("scaled", &QSizeWrap::scaled),
InstanceMethod("setHeight", &QSizeWrap::setHeight),
InstanceMethod("setWidth", &QSizeWrap::setWidth),
InstanceMethod("transpose", &QSizeWrap::transpose),
InstanceMethod("transposed", &QSizeWrap::transposed),
InstanceMethod("width", &QSizeWrap::width),
StaticMethod("fromQVariant", &StaticQSizeWrapMethods::fromQVariant),
COMPONENT_WRAPPED_METHODS_EXPORT_DEFINE(QSizeWrap)});
constructor = Napi::Persistent(func);
exports.Set(CLASSNAME, func);
return exports;
}
QSizeWrap::QSizeWrap(const Napi::CallbackInfo& info)
: Napi::ObjectWrap<QSizeWrap>(info) {
Napi::Env env = info.Env();
if (info.Length() == 2) {
int width = info[0].As<Napi::Number>().Int32Value();
int height = info[1].As<Napi::Number>().Int32Value();
this->instance = std::make_unique<QSize>(width, height);
} else if (info.Length() == 1) {
this->instance =
std::unique_ptr<QSize>(info[0].As<Napi::External<QSize>>().Data());
} else if (info.Length() == 0) {
this->instance = std::make_unique<QSize>();
} else {
Napi::TypeError::New(env, "Wrong number of arguments")
.ThrowAsJavaScriptException();
}
this->rawData = extrautils::configureComponent(this->getInternalInstance());
}
QSizeWrap::~QSizeWrap() { this->instance.reset(); }
QSize* QSizeWrap::getInternalInstance() { return this->instance.get(); }
Napi::Value QSizeWrap::setHeight(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
int height = info[0].As<Napi::Number>().Int32Value();
this->instance->setHeight(height);
return env.Null();
}
Napi::Value QSizeWrap::setWidth(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
int width = info[0].As<Napi::Number>().Int32Value();
this->instance->setWidth(width);
return env.Null();
}
Napi::Value QSizeWrap::height(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
return Napi::Value::From(env, this->instance->height());
}
Napi::Value QSizeWrap::width(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
return Napi::Value::From(env, this->instance->width());
}
Napi::Value StaticQSizeWrapMethods::fromQVariant(
const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::Object variantObject = info[0].As<Napi::Object>();
QVariantWrap* variantWrap =
Napi::ObjectWrap<QVariantWrap>::Unwrap(variantObject);
QVariant* variant = variantWrap->getInternalInstance();
QSize size = variant->value<QSize>();
auto instance = QSizeWrap::constructor.New({Napi::External<QSize>::New(
env, new QSize(size.width(), size.height()))});
return instance;
}
Napi::Value QSizeWrap::boundedTo(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
QSizeWrap* otherSizeWrap =
Napi::ObjectWrap<QSizeWrap>::Unwrap(info[0].As<Napi::Object>());
QSize* otherSize = otherSizeWrap->getInternalInstance();
QSize result = this->instance->boundedTo(*otherSize);
auto resultInstance = QSizeWrap::constructor.New(
{Napi::External<QSize>::New(env, new QSize(result))});
return resultInstance;
}
Napi::Value QSizeWrap::expandedTo(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
QSizeWrap* otherSizeWrap =
Napi::ObjectWrap<QSizeWrap>::Unwrap(info[0].As<Napi::Object>());
QSize* otherSize = otherSizeWrap->getInternalInstance();
QSize result = this->instance->expandedTo(*otherSize);
auto resultInstance = QSizeWrap::constructor.New(
{Napi::External<QSize>::New(env, new QSize(result))});
return resultInstance;
}
Napi::Value QSizeWrap::isEmpty(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
bool result = this->instance->isEmpty();
return Napi::Boolean::New(env, result);
}
Napi::Value QSizeWrap::isNull(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
bool result = this->instance->isNull();
return Napi::Boolean::New(env, result);
}
Napi::Value QSizeWrap::isValid(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
bool result = this->instance->isValid();
return Napi::Boolean::New(env, result);
}
Napi::Value QSizeWrap::scale(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
int width = info[0].As<Napi::Number>().Int32Value();
int height = info[1].As<Napi::Number>().Int32Value();
Qt::AspectRatioMode mode =
static_cast<Qt::AspectRatioMode>(info[2].As<Napi::Number>().Int32Value());
this->instance->scale(width, height, mode);
return env.Null();
}
Napi::Value QSizeWrap::scaled(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
int width = info[0].As<Napi::Number>().Int32Value();
int height = info[1].As<Napi::Number>().Int32Value();
Qt::AspectRatioMode mode =
static_cast<Qt::AspectRatioMode>(info[2].As<Napi::Number>().Int32Value());
QSize result = this->instance->scaled(width, height, mode);
auto resultInstance = QSizeWrap::constructor.New(
{Napi::External<QSize>::New(env, new QSize(result))});
return resultInstance;
}
Napi::Value QSizeWrap::transpose(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
this->instance->transpose();
return env.Null();
}
Napi::Value QSizeWrap::transposed(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
QSize result = this->instance->transposed();
auto resultInstance = QSizeWrap::constructor.New(
{Napi::External<QSize>::New(env, new QSize(result))});
return resultInstance;
}