Added native event payload on the event listener
This commit is contained in:
parent
9f6ecc19dc
commit
1bdf06c4c4
@ -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',
|
||||
],
|
||||
|
||||
3
demo.ts
3
demo.ts
@ -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();
|
||||
|
||||
@ -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 },
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user