Feature/key events (#188)

* Added key property to QKeyEvent

* Custom handling for KeyPress and KeyRelease events

* Added modifiers, count, isAutoRepeat to QKeyEvent

* Fixed typings

* Revereted eventwidget.cpp redundant changes
This commit is contained in:
Mikko Sairio 2019-11-10 22:20:35 +02:00 committed by Atul R
parent ece01d3803
commit cd7906710a
3 changed files with 44 additions and 0 deletions

View File

@ -20,6 +20,10 @@ class QKeyEventWrap : public Napi::ObjectWrap<QKeyEventWrap> {
static Napi::FunctionReference constructor;
// wrapped methods
Napi::Value text(const Napi::CallbackInfo& info);
Napi::Value key(const Napi::CallbackInfo& info);
Napi::Value modifiers(const Napi::CallbackInfo& info);
Napi::Value count(const Napi::CallbackInfo& info);
Napi::Value isAutoRepeat(const Napi::CallbackInfo& info);
COMPONENT_WRAPPED_METHODS_DECLARATION
};

View File

@ -12,6 +12,10 @@ Napi::Object QKeyEventWrap::init(Napi::Env env, Napi::Object exports) {
Napi::Function func =
DefineClass(env, CLASSNAME,
{InstanceMethod("text", &QKeyEventWrap::text),
InstanceMethod("key", &QKeyEventWrap::key),
InstanceMethod("modifiers", &QKeyEventWrap::modifiers),
InstanceMethod("count", &QKeyEventWrap::count),
InstanceMethod("isAutoRepeat", &QKeyEventWrap::isAutoRepeat),
COMPONENT_WRAPPED_METHODS_EXPORT_DEFINE});
constructor = Napi::Persistent(func);
exports.Set(CLASSNAME, func);
@ -44,4 +48,28 @@ Napi::Value QKeyEventWrap::text(const Napi::CallbackInfo& info) {
QString text = this->instance->text();
Napi::String keyValue = Napi::String::New(env, text.toStdString());
return keyValue;
}
Napi::Value QKeyEventWrap::key(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
int key = static_cast<int>(this->instance->key());
return Napi::Number::From(env, key);
}
Napi::Value QKeyEventWrap::modifiers(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
int key = static_cast<int>(this->instance->modifiers());
return Napi::Number::From(env, key);
}
Napi::Value QKeyEventWrap::count(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
int count = static_cast<int>(this->instance->count());
return Napi::Number::From(env, count);
}
Napi::Value QKeyEventWrap::isAutoRepeat(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
bool isAutoRepeat = static_cast<bool>(this->instance->isAutoRepeat());
return Napi::Boolean::From(env, isAutoRepeat);
}

View File

@ -10,4 +10,16 @@ export class QKeyEvent {
text = (): string => {
return this.native.text();
};
key = (): number => {
return this.native.key();
};
modifiers = (): number => {
return this.native.modifiers();
};
count = (): number => {
return this.native.count();
};
isAutoRepeat = (): boolean => {
return this.native.isAutoRepeat();
};
}