|
| 1 | +#include "QtWidgets/QDesktopWidget/qdesktopwidget_wrap.h" |
| 2 | + |
| 3 | +#include "Extras/Utils/nutils.h" |
| 4 | +#include "QtWidgets/QWidget/qwidget_wrap.h" |
| 5 | +#include "QtCore/QRect/qrect_wrap.h" |
| 6 | + |
| 7 | +#include <QWidget> |
| 8 | + |
| 9 | +Napi::FunctionReference QDesktopWidgetWrap::constructor; |
| 10 | + |
| 11 | +Napi::Object QDesktopWidgetWrap::init(Napi::Env env, Napi::Object exports) { |
| 12 | + Napi::HandleScope scope(env); |
| 13 | + char CLASSNAME[] = "QDesktopWidget"; |
| 14 | + Napi::Function func = |
| 15 | + DefineClass(env, CLASSNAME, |
| 16 | + {InstanceMethod("screenGeometry", &QDesktopWidgetWrap::screenGeometry), |
| 17 | + InstanceMethod("availableGeometry", &QDesktopWidgetWrap::availableGeometry), |
| 18 | + InstanceMethod("screenNumber", &QDesktopWidgetWrap::screenNumber), |
| 19 | + QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QDesktopWidgetWrap)}); |
| 20 | + constructor = Napi::Persistent(func); |
| 21 | + exports.Set(CLASSNAME, func); |
| 22 | + return exports; |
| 23 | +} |
| 24 | + |
| 25 | +NQDesktopWidget *QDesktopWidgetWrap::getInternalInstance() { return this->instance; } |
| 26 | + |
| 27 | +QDesktopWidgetWrap::QDesktopWidgetWrap(const Napi::CallbackInfo &info) |
| 28 | + : Napi::ObjectWrap<QDesktopWidgetWrap>(info) { |
| 29 | + Napi::Env env = info.Env(); |
| 30 | + Napi::HandleScope scope(env); |
| 31 | + |
| 32 | + if (info.Length() == 0) { |
| 33 | + this->instance = new NQDesktopWidget(); |
| 34 | + } else { |
| 35 | + Napi::TypeError::New(env, "Wrong number of arguments") |
| 36 | + .ThrowAsJavaScriptException(); |
| 37 | + } |
| 38 | + this->rawData = extrautils::configureQWidget( |
| 39 | + this->getInternalInstance(), this->getInternalInstance()->getFlexNode(), |
| 40 | + true); |
| 41 | +} |
| 42 | + |
| 43 | +QDesktopWidgetWrap::~QDesktopWidgetWrap() { extrautils::safeDelete(this->instance); } |
| 44 | + |
| 45 | +Napi::Value QDesktopWidgetWrap::screenGeometry(const Napi::CallbackInfo &info) { |
| 46 | + Napi::Env env = info.Env(); |
| 47 | + Napi::HandleScope scope(env); |
| 48 | + |
| 49 | + Napi::Number screen = info[0].As<Napi::Number>(); |
| 50 | + QRect rect = this->instance->screenGeometry(screen); |
| 51 | + auto instance = QRectWrap::constructor.New({Napi::External<QRect>::New(env, new QRect(rect))}); |
| 52 | + return instance; |
| 53 | +} |
| 54 | + |
| 55 | +Napi::Value QDesktopWidgetWrap::availableGeometry(const Napi::CallbackInfo &info) { |
| 56 | + Napi::Env env = info.Env(); |
| 57 | + Napi::HandleScope scope(env); |
| 58 | + |
| 59 | + Napi::Number screen = info[0].As<Napi::Number>(); |
| 60 | + QRect rect = this->instance->availableGeometry(screen); |
| 61 | + auto instance = QRectWrap::constructor.New({Napi::External<QRect>::New(env, new QRect(rect))}); |
| 62 | + return instance; |
| 63 | +} |
| 64 | + |
| 65 | +Napi::Value QDesktopWidgetWrap::screenNumber(const Napi::CallbackInfo &info) { |
| 66 | + Napi::Env env = info.Env(); |
| 67 | + Napi::HandleScope scope(env); |
| 68 | + int value = this->instance->screenNumber(); |
| 69 | + return Napi::Value::From(env, value); |
| 70 | +} |
0 commit comments