forked from nodegui/nodegui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqicon_wrap.cpp
More file actions
47 lines (42 loc) · 1.16 KB
/
qicon_wrap.cpp
File metadata and controls
47 lines (42 loc) · 1.16 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
#include "qicon_wrap.h"
#include "src/cpp/Extras/Utils/nutils.h"
#include "deps/spdlog/spdlog.h"
Napi::FunctionReference QIconWrap::constructor;
Napi::Object QIconWrap::init(Napi::Env env, Napi::Object exports)
{
Napi::HandleScope scope(env);
char CLASSNAME[] = "QIcon";
Napi::Function func = DefineClass(env, CLASSNAME, {
COMPONENT_WRAPPED_METHODS_EXPORT_DEFINE
});
constructor = Napi::Persistent(func);
exports.Set(CLASSNAME, func);
return exports;
}
QIconWrap::QIconWrap(const Napi::CallbackInfo &info) : Napi::ObjectWrap<QIconWrap>(info)
{
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
if (info.Length() == 1)
{
Napi::String url = info[0].As<Napi::String>();
QString imageUrl = QString::fromUtf8(url.Utf8Value().c_str());
this->instance = new QIcon(imageUrl);
}
else if (info.Length() == 0)
{
this->instance = new QIcon();
}
else
{
Napi::TypeError::New(env, "Wrong number of arguments").ThrowAsJavaScriptException();
}
}
QIconWrap::~QIconWrap()
{
delete this->instance;
}
QIcon *QIconWrap::getInternalInstance()
{
return this->instance;
}