nodeguy/src/cpp/lib/QtWidgets/QShortcut/qshortcut_wrap.cpp
Atul R c742712f6f
Qwidget wrap fix (#433)
* skip setting up miniqt if customQt is on

* adds opengl context

* adds NodeWidgetWrap

* changed the mode of qode.js to make it executable

* 0.15.3
2020-03-08 16:47:56 +01:00

84 lines
2.9 KiB
C++

#include "QtWidgets/QShortcut/qshortcut_wrap.h"
#include <QWidget>
#include "Extras/Utils/nutils.h"
#include "QtGui/QKeySequence/qkeysequence_wrap.h"
#include "QtWidgets/QMenu/qmenu_wrap.h"
#include "QtWidgets/QWidget/qwidget_wrap.h"
Napi::FunctionReference QShortcutWrap::constructor;
Napi::Object QShortcutWrap::init(Napi::Env env, Napi::Object exports) {
Napi::HandleScope scope(env);
char CLASSNAME[] = "QShortcut";
Napi::Function func = DefineClass(
env, CLASSNAME,
{InstanceMethod("setEnabled", &QShortcutWrap::setEnabled),
InstanceMethod("setAutoRepeat", &QShortcutWrap::setAutoRepeat),
InstanceMethod("setKey", &QShortcutWrap::setKey),
InstanceMethod("setContext", &QShortcutWrap::setContext),
QOBJECT_WRAPPED_METHODS_EXPORT_DEFINE(QShortcutWrap)});
constructor = Napi::Persistent(func);
exports.Set(CLASSNAME, func);
return exports;
}
NShortcut* QShortcutWrap::getInternalInstance() { return this->instance; }
QShortcutWrap::QShortcutWrap(const Napi::CallbackInfo& info)
: Napi::ObjectWrap<QShortcutWrap>(info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
if (info.Length() == 1) {
Napi::Object parentObject = info[0].As<Napi::Object>();
NodeWidgetWrap* parentWidgetWrap =
Napi::ObjectWrap<NodeWidgetWrap>::Unwrap(parentObject);
this->instance = new NShortcut(parentWidgetWrap->getInternalInstance());
} else {
Napi::TypeError::New(env, "Wrong number of arguments")
.ThrowAsJavaScriptException();
}
this->rawData = extrautils::configureQObject(this->getInternalInstance());
}
QShortcutWrap::~QShortcutWrap() { extrautils::safeDelete(this->instance); }
Napi::Value QShortcutWrap::setEnabled(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
Napi::Boolean enabled = info[0].As<Napi::Boolean>();
this->instance->setEnabled(enabled.Value());
return env.Null();
}
Napi::Value QShortcutWrap::setAutoRepeat(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
Napi::Boolean enabled = info[0].As<Napi::Boolean>();
this->instance->setAutoRepeat(enabled.Value());
return env.Null();
}
Napi::Value QShortcutWrap::setKey(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
Napi::Object shortcutSequence = info[0].As<Napi::Object>();
QKeySequenceWrap* keysequence =
Napi::ObjectWrap<QKeySequenceWrap>::Unwrap(shortcutSequence);
this->instance->setKey(*keysequence->getInternalInstance());
return env.Null();
}
Napi::Value QShortcutWrap::setContext(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
Napi::Number shortcutContextEnum = info[0].As<Napi::Number>();
int shortCutContext = shortcutContextEnum.Int32Value();
this->instance->setContext(static_cast<Qt::ShortcutContext>(shortCutContext));
return env.Null();
}