Added native event payload on the event listener

This commit is contained in:
Atul R 2019-06-22 20:00:44 +02:00
parent 9f6ecc19dc
commit 1bdf06c4c4
4 changed files with 11 additions and 5 deletions

View File

@ -2,7 +2,7 @@
'includes': [],
'type': 'shared_library',
'variables': {
'qt_home_dir': 'C:\\Users\\atula\\Tools\\qt\\5.13.0\\msvc2017_64',
'qt_home_dir': '/usr/local/Cellar/qt/5.12.1',
},
'target_defaults': {
'cflags!': ['-fno-exceptions'],
@ -79,7 +79,7 @@
'<(qt_home_dir)\\include\\QtWidgets',
],
'libraries': [
'<(qt_home_dir)\\lib\\Qt5Core.lib',
'<(qt_home_dir)\\lib\\Qt5Core.lib',
'<(qt_home_dir)\\lib\\Qt5Gui.lib',
'<(qt_home_dir)\\lib\\Qt5Widgets.lib',
],

View File

@ -70,6 +70,9 @@ const testFlexLayout = () => {
// -> view2 -> button
const win = new QMainWindow();
win.addEventListener("MouseMove", (...args) => {
console.log(...args);
});
win.setObjectName("win");
win.resize(300, 300);
const rootView = new QWidget();

View File

@ -1,6 +1,6 @@
#include "eventsmap.h"
std::unordered_map<std::string, int> EventsMap::events {
std::unordered_map<std::string, int> EventsMap::eventTypes {
{ "None", QEvent::None },
{ "ActionAdded", QEvent::ActionAdded },
{ "ActionChanged", QEvent::ActionChanged },

View File

@ -1,10 +1,12 @@
#include "eventwidget.h"
#include "deps/spdlog/spdlog.h"
#include <napi.h>
void EventWidget::subscribeToQtEvent(std::string evtString){
try {
int evtType = EventsMap::events.at(evtString);
int evtType = EventsMap::eventTypes.at(evtString);
this->subscribedEvents.insert({static_cast<QEvent::Type>(evtType), evtString});
spdlog::info("EventWidget: subscribed to {}", evtString.c_str());
} catch (...) {
spdlog::info("EventWidget: Couldn't subscribe to qt event {}. If this is a signal you can safely ignore this warning", evtString.c_str());
}
@ -16,7 +18,8 @@ void EventWidget::event(QEvent* event){
QEvent::Type evtType = event->type();
std::string eventTypeString = subscribedEvents.at(evtType);
this->emitOnNode->call([=](Napi::Env env, std::vector<napi_value>& args) {
args = { Napi::String::New(env, eventTypeString) };
Napi::Value nativeEvent = Napi::External<QEvent>::New(env, event);
args = { Napi::String::New(env, eventTypeString), nativeEvent };
});
} catch (...) {
// Do nothing