#include "qmainwindow_wrap.h" #include "src/cpp/QtGui/QWidget/qwidget_wrap.h" #include "src/cpp/Extras/Utils/utils.h" Napi::FunctionReference QMainWindowWrap::constructor; Napi::Object QMainWindowWrap::init(Napi::Env env, Napi::Object exports) { Napi::HandleScope scope(env); char CLASSNAME[] = "QMainWindow"; Napi::Function func = DefineClass(env, CLASSNAME, { QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QMainWindowWrap) InstanceMethod("setCentralWidget",&QMainWindowWrap::setCentralWidget), }); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); return exports; } NMainWindow* QMainWindowWrap::getInternalInstance() { return this->instance; } QMainWindowWrap::QMainWindowWrap(const Napi::CallbackInfo& info): Napi::ObjectWrap(info) { Napi::Env env = info.Env(); Napi::HandleScope scope(env); SuppressDestruct(); if(info.Length() == 1) { Napi::Object parentObject = info[0].As(); QWidgetWrap* parentWidgetWrap = Napi::ObjectWrap::Unwrap(parentObject); this->instance = new NMainWindow(parentWidgetWrap->getInternalInstance()); //this sets the parent to current widget }else if (info.Length() == 0){ this->instance = new NMainWindow(); }else { extrautils::throwTypeError(env, "Wrong number of arguments"); } } QMainWindowWrap::~QMainWindowWrap() { delete this->instance; } Napi::Value QMainWindowWrap::setCentralWidget(const Napi::CallbackInfo& info){ Napi::Env env = info.Env(); Napi::HandleScope scope(env); Napi::Object widgetObject = info[0].As(); QWidgetWrap* centralWidget = Napi::ObjectWrap::Unwrap(widgetObject); this->instance->setCentralWidget(centralWidget->getInternalInstance()); return env.Null(); }