Merge pull request #10 from master-atul/feature/evennts
Added events support
This commit is contained in:
commit
75cfa52836
@ -13,6 +13,8 @@
|
||||
"../src/cpp/core/FlexLayout/flexlayout.cpp",
|
||||
"../src/cpp/core/FlexLayout/flexitem.cpp",
|
||||
"../src/cpp/core/YogaWidget/nodestyle.cpp",
|
||||
"../src/cpp/core/Events/eventsmap.cpp",
|
||||
"../src/cpp/core/Events/eventwidget.cpp",
|
||||
"../src/cpp/core/YogaWidget/yogawidget.cpp",
|
||||
# wrapped cpps
|
||||
"../src/cpp/QtGui/QApplication/qapplication_wrap.cpp",
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
{
|
||||
"include": "src/cpp/core/YogaWidget/yogawidget.h",
|
||||
"include": "src/cpp/core/NodeWidget/nodewidget.h",
|
||||
"headers": [
|
||||
"src/cpp/QtGui/QWidget/nwidget.h",
|
||||
"src/cpp/QtWidgets/QLabel/nlabel.h",
|
||||
|
||||
15
demo.ts
15
demo.ts
@ -4,7 +4,7 @@ import { QGridLayout } from "./src/lib/QtWidgets/QGridLayout";
|
||||
import { QLabel } from "./src/lib/QtWidgets/QLabel";
|
||||
import {
|
||||
QPushButton,
|
||||
QPushButtonSignal
|
||||
QPushButtonEvents
|
||||
} from "./src/lib/QtWidgets/QPushButton";
|
||||
import { QCheckBox } from "./src/lib/QtWidgets/QCheckBox";
|
||||
import { QProgressBar } from "./src/lib/QtWidgets/QProgressBar";
|
||||
@ -25,16 +25,16 @@ const testGridLayout = () => {
|
||||
label.setStyleSheet("background-color:blue; color:white;");
|
||||
|
||||
const button1 = new QPushButton();
|
||||
button1.setSignalListener(QPushButtonSignal.clicked, isChecked => {
|
||||
button1.addEventListener(QPushButtonEvents.clicked, isChecked => {
|
||||
console.log("clicked", isChecked);
|
||||
});
|
||||
button1.setSignalListener(QPushButtonSignal.pressed, (...args) => {
|
||||
button1.addEventListener(QPushButtonEvents.pressed, (...args) => {
|
||||
console.log("pressed", ...args);
|
||||
});
|
||||
button1.setSignalListener(QPushButtonSignal.released, (...args) => {
|
||||
button1.addEventListener(QPushButtonEvents.released, (...args) => {
|
||||
console.log("released", ...args);
|
||||
});
|
||||
button1.setSignalListener(QPushButtonSignal.toggled, isToggled => {
|
||||
button1.addEventListener(QPushButtonEvents.toggled, isToggled => {
|
||||
console.log("toggled", isToggled);
|
||||
});
|
||||
|
||||
@ -71,7 +71,7 @@ const testFlexLayout = () => {
|
||||
|
||||
const win = new QMainWindow();
|
||||
win.setObjectName("win");
|
||||
win.resize(300,300);
|
||||
win.resize(300, 300);
|
||||
const rootView = new QWidget();
|
||||
rootView.setStyleSheet(`
|
||||
* {
|
||||
@ -127,6 +127,9 @@ const testFlexLayout = () => {
|
||||
const button = new QPushButton(view2);
|
||||
button.setObjectName("button");
|
||||
button.setText("Hululu");
|
||||
button.addEventListener("pressed", () => {
|
||||
console.log("pressed");
|
||||
});
|
||||
flayout2.addWidget(button, button.getFlexNode());
|
||||
|
||||
rootLayout.addWidget(view, view.getFlexNode());
|
||||
|
||||
@ -3,7 +3,7 @@ import { QWidget } from "../../src/lib/QtGui/QWidget";
|
||||
import { FlexLayout } from "../../src/lib/core/FlexLayout";
|
||||
import {
|
||||
QPushButton,
|
||||
QPushButtonSignal
|
||||
QPushButtonEvents
|
||||
} from "../../src/lib/QtWidgets/QPushButton";
|
||||
import { QLabel } from "../../src/lib/QtWidgets/QLabel";
|
||||
|
||||
@ -20,7 +20,7 @@ const getButton = (
|
||||
const button = new QPushButton();
|
||||
button.setText(label);
|
||||
button.setObjectName(`btn${value}`);
|
||||
button.setSignalListener(QPushButtonSignal.clicked, () => {
|
||||
button.addEventListener(QPushButtonEvents.clicked, () => {
|
||||
onBtnClick(value, type);
|
||||
});
|
||||
return {
|
||||
|
||||
@ -2,8 +2,9 @@
|
||||
#include <QWidget>
|
||||
#include <QWidget>
|
||||
#include "src/cpp/core/YogaWidget/yogawidget.h"
|
||||
#include "src/cpp/core/Events/eventwidget.h"
|
||||
|
||||
class NWidget: public QWidget, public YogaWidget
|
||||
class NWidget: public QWidget, public YogaWidget, public EventWidget
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
#include "src/cpp/QtWidgets/QLayout/qlayout_wrap.h"
|
||||
#include "src/cpp/core/YogaWidget/yogawidget_macro.h"
|
||||
#include "src/cpp/core/Events/eventwidget_macro.h"
|
||||
/*
|
||||
|
||||
This macro adds common QWidgets exported methods
|
||||
@ -12,6 +13,7 @@
|
||||
#define QWIDGET_WRAPPED_METHODS_DECLARATION \
|
||||
\
|
||||
YOGAWIDGET_WRAPPED_METHODS_DECLARATION \
|
||||
EVENTWIDGET_WRAPPED_METHODS_DECLARATION \
|
||||
\
|
||||
Napi::Value show(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
@ -75,6 +77,7 @@ Napi::Value setObjectName(const Napi::CallbackInfo& info){ \
|
||||
#define QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(WidgetWrapName) \
|
||||
\
|
||||
YOGAWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(WidgetWrapName) \
|
||||
EVENTWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(WidgetWrapName) \
|
||||
InstanceMethod("show", &WidgetWrapName::show), \
|
||||
InstanceMethod("resize",&WidgetWrapName::resize), \
|
||||
InstanceMethod("close",&WidgetWrapName::close), \
|
||||
|
||||
@ -1,16 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <QWidget>
|
||||
#include <QCheckBox>
|
||||
#include "src/cpp/core/YogaWidget/yogawidget.h"
|
||||
#include "src/cpp/core/NodeWidget/nodewidget.h"
|
||||
|
||||
class NCheckBox: public QCheckBox, public YogaWidget
|
||||
class NCheckBox: public QCheckBox, public NodeWidget
|
||||
{
|
||||
|
||||
NODEWIDGET_IMPLEMENTATIONS
|
||||
public:
|
||||
SET_YOGA_WIDGET_Q_PROPERTIES
|
||||
using QCheckBox::QCheckBox; //inherit all constructors of QCheckBox
|
||||
Q_OBJECT
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -1,16 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <QWidget>
|
||||
#include <QLabel>
|
||||
#include "src/cpp/core/YogaWidget/yogawidget.h"
|
||||
#include "src/cpp/core/NodeWidget/nodewidget.h"
|
||||
|
||||
class NLabel: public QLabel, public YogaWidget
|
||||
class NLabel: public QLabel, public NodeWidget
|
||||
{
|
||||
|
||||
NODEWIDGET_IMPLEMENTATIONS
|
||||
public:
|
||||
SET_YOGA_WIDGET_Q_PROPERTIES
|
||||
using QLabel::QLabel; //inherit all constructors of QLabel
|
||||
Q_OBJECT
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -1,16 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <QWidget>
|
||||
#include <QLineEdit>
|
||||
#include "src/cpp/core/YogaWidget/yogawidget.h"
|
||||
#include "src/cpp/core/NodeWidget/nodewidget.h"
|
||||
|
||||
class NLineEdit: public QLineEdit, public YogaWidget
|
||||
class NLineEdit: public QLineEdit, public NodeWidget
|
||||
{
|
||||
|
||||
NODEWIDGET_IMPLEMENTATIONS
|
||||
public:
|
||||
SET_YOGA_WIDGET_Q_PROPERTIES
|
||||
using QLineEdit::QLineEdit; //inherit all constructors of QLineEdit
|
||||
Q_OBJECT
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -1,14 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <QWidget>
|
||||
#include <QMainWindow>
|
||||
#include "src/cpp/core/YogaWidget/yogawidget.h"
|
||||
#include "deps/spdlog/spdlog.h"
|
||||
#include "src/cpp/core/NodeWidget/nodewidget.h"
|
||||
#include <QEvent>
|
||||
|
||||
class NMainWindow: public QMainWindow, public YogaWidget
|
||||
class NMainWindow: public QMainWindow, public NodeWidget
|
||||
{
|
||||
|
||||
NODEWIDGET_IMPLEMENTATIONS
|
||||
public:
|
||||
using QMainWindow::QMainWindow; //inherit all constructors of QMainWindow
|
||||
private:
|
||||
void calculateLayout(){
|
||||
YGDirection direction = YGNodeStyleGetDirection(this->getFlexNode());
|
||||
@ -27,10 +27,6 @@ private:
|
||||
void resizeEvent(QResizeEvent * event){
|
||||
calculateLayout();
|
||||
}
|
||||
public:
|
||||
SET_YOGA_WIDGET_Q_PROPERTIES
|
||||
using QMainWindow::QMainWindow; //inherit all constructors of QMainWindow
|
||||
Q_OBJECT
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -1,16 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <QWidget>
|
||||
#include <QProgressBar>
|
||||
#include "src/cpp/core/YogaWidget/yogawidget.h"
|
||||
#include "src/cpp/core/NodeWidget/nodewidget.h"
|
||||
|
||||
class NProgressBar: public QProgressBar, public YogaWidget
|
||||
class NProgressBar: public QProgressBar, public NodeWidget
|
||||
{
|
||||
|
||||
NODEWIDGET_IMPLEMENTATIONS
|
||||
public:
|
||||
SET_YOGA_WIDGET_Q_PROPERTIES
|
||||
using QProgressBar::QProgressBar; //inherit all constructors of QProgressBar
|
||||
Q_OBJECT
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -1,16 +1,38 @@
|
||||
#pragma once
|
||||
|
||||
#include <QWidget>
|
||||
#include <QPushButton>
|
||||
#include "src/cpp/core/YogaWidget/yogawidget.h"
|
||||
#include "src/cpp/core/NodeWidget/nodewidget.h"
|
||||
#include "napi.h"
|
||||
|
||||
class NPushButton: public QPushButton, public YogaWidget
|
||||
class NPushButton: public QPushButton, public NodeWidget
|
||||
{
|
||||
NODEWIDGET_IMPLEMENTATIONS
|
||||
public:
|
||||
SET_YOGA_WIDGET_Q_PROPERTIES
|
||||
using QPushButton::QPushButton; //inherit all constructors of QPushButton
|
||||
Q_OBJECT
|
||||
|
||||
void connectWidgetSignalsToEventEmitter() {
|
||||
// Qt Connects: Implement all signal connects here
|
||||
QObject::connect(this, &QPushButton::clicked, [=](bool checked) {
|
||||
this->emitOnNode->call([=](Napi::Env env, std::vector<napi_value>& args) {
|
||||
args = { Napi::String::New(env, "clicked"), Napi::Value::From(env, checked) };
|
||||
});
|
||||
});
|
||||
QObject::connect(this, &QPushButton::released, [=]() {
|
||||
this->emitOnNode->call([=](Napi::Env env, std::vector<napi_value>& args) {
|
||||
args = { Napi::String::New(env, "released") };
|
||||
});
|
||||
});
|
||||
QObject::connect(this, &QPushButton::pressed, [=]() {
|
||||
this->emitOnNode->call([=](Napi::Env env, std::vector<napi_value>& args) {
|
||||
args = { Napi::String::New(env, "pressed") };
|
||||
});
|
||||
});
|
||||
QObject::connect(this, &QPushButton::toggled, [=](bool checked) {
|
||||
this->emitOnNode->call([=](Napi::Env env, std::vector<napi_value>& args) {
|
||||
args = { Napi::String::New(env, "toggled"), Napi::Value::From(env, checked) };
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -9,7 +9,6 @@ Napi::Object QPushButtonWrap::init(Napi::Env env, Napi::Object exports) {
|
||||
char CLASSNAME[] = "QPushButton";
|
||||
Napi::Function func = DefineClass(env, CLASSNAME, {
|
||||
InstanceMethod("setText", &QPushButtonWrap::setText),
|
||||
InstanceMethod("setupSignalListeners",&QPushButtonWrap::setupSignalListeners),
|
||||
QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QPushButtonWrap)
|
||||
});
|
||||
constructor = Napi::Persistent(func);
|
||||
@ -39,37 +38,9 @@ QPushButtonWrap::QPushButtonWrap(const Napi::CallbackInfo& info): Napi::ObjectWr
|
||||
}
|
||||
|
||||
QPushButtonWrap::~QPushButtonWrap() {
|
||||
this->emitOnNode.release(); //cleanup emitOnNode
|
||||
delete this->instance;
|
||||
}
|
||||
|
||||
Napi::Value QPushButtonWrap::setupSignalListeners(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
this->emitOnNode = std::make_unique<ThreadSafeCallback>(info[0].As<Napi::Function>());
|
||||
// Qt Connects: Implement all signal connects here
|
||||
QObject::connect(this->instance, &QPushButton::clicked, [=](bool checked) {
|
||||
this->emitOnNode->call([=](Napi::Env env, std::vector<napi_value>& args) {
|
||||
args = { Napi::String::New(env, "clicked"), Napi::Value::From(env, checked) };
|
||||
});
|
||||
});
|
||||
QObject::connect(this->instance, &QPushButton::released, [=]() {
|
||||
this->emitOnNode->call([=](Napi::Env env, std::vector<napi_value>& args) {
|
||||
args = { Napi::String::New(env, "released") };
|
||||
});
|
||||
});
|
||||
QObject::connect(this->instance, &QPushButton::pressed, [=]() {
|
||||
this->emitOnNode->call([=](Napi::Env env, std::vector<napi_value>& args) {
|
||||
args = { Napi::String::New(env, "pressed") };
|
||||
});
|
||||
});
|
||||
QObject::connect(this->instance, &QPushButton::toggled, [=](bool checked) {
|
||||
this->emitOnNode->call([=](Napi::Env env, std::vector<napi_value>& args) {
|
||||
args = { Napi::String::New(env, "toggled"), Napi::Value::From(env, checked) };
|
||||
});
|
||||
});
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
|
||||
Napi::Value QPushButtonWrap::setText(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <napi.h>
|
||||
#include <napi-thread-safe-callback.hpp>
|
||||
#include "npushbutton.h"
|
||||
#include "src/cpp/QtGui/QWidget/qwidget_macro.h"
|
||||
|
||||
@ -10,7 +9,7 @@
|
||||
class QPushButtonWrap : public Napi::ObjectWrap<QPushButtonWrap> {
|
||||
private:
|
||||
NPushButton* instance;
|
||||
std::unique_ptr<ThreadSafeCallback> emitOnNode;
|
||||
// std::unique_ptr<ThreadSafeCallback> emitOnNode;
|
||||
public:
|
||||
static Napi::Object init(Napi::Env env, Napi::Object exports);
|
||||
QPushButtonWrap(const Napi::CallbackInfo& info);
|
||||
@ -21,6 +20,7 @@ class QPushButtonWrap : public Napi::ObjectWrap<QPushButtonWrap> {
|
||||
static Napi::FunctionReference constructor;
|
||||
//wrapped methods
|
||||
Napi::Value setText(const Napi::CallbackInfo& info);
|
||||
Napi::Value subscribeToEvent(const Napi::CallbackInfo& info);
|
||||
|
||||
QWIDGET_WRAPPED_METHODS_DECLARATION
|
||||
|
||||
|
||||
@ -1,16 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <QWidget>
|
||||
#include <QRadioButton>
|
||||
#include "src/cpp/core/YogaWidget/yogawidget.h"
|
||||
|
||||
class NRadioButton: public QRadioButton, public YogaWidget
|
||||
{
|
||||
#include "src/cpp/core/NodeWidget/nodewidget.h"
|
||||
|
||||
class NRadioButton: public QRadioButton, public NodeWidget
|
||||
{
|
||||
NODEWIDGET_IMPLEMENTATIONS
|
||||
public:
|
||||
SET_YOGA_WIDGET_Q_PROPERTIES
|
||||
using QRadioButton::QRadioButton; //inherit all constructors of QRadioButton
|
||||
Q_OBJECT
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -292,8 +292,8 @@ void *NCheckBox::qt_metacast(const char *_clname)
|
||||
if (!_clname) return nullptr;
|
||||
if (!strcmp(_clname, qt_meta_stringdata_NCheckBox.stringdata0))
|
||||
return static_cast<void*>(this);
|
||||
if (!strcmp(_clname, "YogaWidget"))
|
||||
return static_cast< YogaWidget*>(this);
|
||||
if (!strcmp(_clname, "NodeWidget"))
|
||||
return static_cast< NodeWidget*>(this);
|
||||
return QCheckBox::qt_metacast(_clname);
|
||||
}
|
||||
|
||||
|
||||
@ -292,8 +292,8 @@ void *NLabel::qt_metacast(const char *_clname)
|
||||
if (!_clname) return nullptr;
|
||||
if (!strcmp(_clname, qt_meta_stringdata_NLabel.stringdata0))
|
||||
return static_cast<void*>(this);
|
||||
if (!strcmp(_clname, "YogaWidget"))
|
||||
return static_cast< YogaWidget*>(this);
|
||||
if (!strcmp(_clname, "NodeWidget"))
|
||||
return static_cast< NodeWidget*>(this);
|
||||
return QLabel::qt_metacast(_clname);
|
||||
}
|
||||
|
||||
|
||||
@ -292,8 +292,8 @@ void *NLineEdit::qt_metacast(const char *_clname)
|
||||
if (!_clname) return nullptr;
|
||||
if (!strcmp(_clname, qt_meta_stringdata_NLineEdit.stringdata0))
|
||||
return static_cast<void*>(this);
|
||||
if (!strcmp(_clname, "YogaWidget"))
|
||||
return static_cast< YogaWidget*>(this);
|
||||
if (!strcmp(_clname, "NodeWidget"))
|
||||
return static_cast< NodeWidget*>(this);
|
||||
return QLineEdit::qt_metacast(_clname);
|
||||
}
|
||||
|
||||
|
||||
@ -292,8 +292,8 @@ void *NMainWindow::qt_metacast(const char *_clname)
|
||||
if (!_clname) return nullptr;
|
||||
if (!strcmp(_clname, qt_meta_stringdata_NMainWindow.stringdata0))
|
||||
return static_cast<void*>(this);
|
||||
if (!strcmp(_clname, "YogaWidget"))
|
||||
return static_cast< YogaWidget*>(this);
|
||||
if (!strcmp(_clname, "NodeWidget"))
|
||||
return static_cast< NodeWidget*>(this);
|
||||
return QMainWindow::qt_metacast(_clname);
|
||||
}
|
||||
|
||||
|
||||
@ -292,8 +292,8 @@ void *NProgressBar::qt_metacast(const char *_clname)
|
||||
if (!_clname) return nullptr;
|
||||
if (!strcmp(_clname, qt_meta_stringdata_NProgressBar.stringdata0))
|
||||
return static_cast<void*>(this);
|
||||
if (!strcmp(_clname, "YogaWidget"))
|
||||
return static_cast< YogaWidget*>(this);
|
||||
if (!strcmp(_clname, "NodeWidget"))
|
||||
return static_cast< NodeWidget*>(this);
|
||||
return QProgressBar::qt_metacast(_clname);
|
||||
}
|
||||
|
||||
|
||||
@ -292,8 +292,8 @@ void *NPushButton::qt_metacast(const char *_clname)
|
||||
if (!_clname) return nullptr;
|
||||
if (!strcmp(_clname, qt_meta_stringdata_NPushButton.stringdata0))
|
||||
return static_cast<void*>(this);
|
||||
if (!strcmp(_clname, "YogaWidget"))
|
||||
return static_cast< YogaWidget*>(this);
|
||||
if (!strcmp(_clname, "NodeWidget"))
|
||||
return static_cast< NodeWidget*>(this);
|
||||
return QPushButton::qt_metacast(_clname);
|
||||
}
|
||||
|
||||
|
||||
@ -292,8 +292,8 @@ void *NRadioButton::qt_metacast(const char *_clname)
|
||||
if (!_clname) return nullptr;
|
||||
if (!strcmp(_clname, qt_meta_stringdata_NRadioButton.stringdata0))
|
||||
return static_cast<void*>(this);
|
||||
if (!strcmp(_clname, "YogaWidget"))
|
||||
return static_cast< YogaWidget*>(this);
|
||||
if (!strcmp(_clname, "NodeWidget"))
|
||||
return static_cast< NodeWidget*>(this);
|
||||
return QRadioButton::qt_metacast(_clname);
|
||||
}
|
||||
|
||||
|
||||
@ -294,6 +294,8 @@ void *NWidget::qt_metacast(const char *_clname)
|
||||
return static_cast<void*>(this);
|
||||
if (!strcmp(_clname, "YogaWidget"))
|
||||
return static_cast< YogaWidget*>(this);
|
||||
if (!strcmp(_clname, "EventWidget"))
|
||||
return static_cast< EventWidget*>(this);
|
||||
return QWidget::qt_metacast(_clname);
|
||||
}
|
||||
|
||||
|
||||
149
src/cpp/core/Events/eventsmap.cpp
Normal file
149
src/cpp/core/Events/eventsmap.cpp
Normal file
@ -0,0 +1,149 @@
|
||||
#include "eventsmap.h"
|
||||
|
||||
std::unordered_map<std::string, int> EventsMap::events {
|
||||
{ "None", QEvent::None },
|
||||
{ "ActionAdded", QEvent::ActionAdded },
|
||||
{ "ActionChanged", QEvent::ActionChanged },
|
||||
{ "ActionRemoved", QEvent::ActionRemoved },
|
||||
{ "ActivationChange", QEvent::ActivationChange },
|
||||
{ "ApplicationActivate", QEvent::ApplicationActivate },
|
||||
{ "ApplicationActivated", QEvent::ApplicationActivated },
|
||||
{ "ApplicationDeactivate", QEvent::ApplicationDeactivate },
|
||||
{ "ApplicationFontChange", QEvent::ApplicationFontChange },
|
||||
{ "ApplicationLayoutDirectionChange", QEvent::ApplicationLayoutDirectionChange },
|
||||
{ "ApplicationPaletteChange", QEvent::ApplicationPaletteChange },
|
||||
{ "ApplicationStateChange", QEvent::ApplicationStateChange },
|
||||
{ "ApplicationWindowIconChange", QEvent::ApplicationWindowIconChange },
|
||||
{ "ChildAdded", QEvent::ChildAdded },
|
||||
{ "ChildPolished", QEvent::ChildPolished },
|
||||
{ "ChildRemoved", QEvent::ChildRemoved },
|
||||
{ "Clipboard", QEvent::Clipboard },
|
||||
{ "Close", QEvent::Close },
|
||||
{ "CloseSoftwareInputPanel", QEvent::CloseSoftwareInputPanel },
|
||||
{ "ContentsRectChange", QEvent::ContentsRectChange },
|
||||
{ "ContextMenu", QEvent::ContextMenu },
|
||||
{ "CursorChange", QEvent::CursorChange },
|
||||
{ "DeferredDelete", QEvent::DeferredDelete },
|
||||
{ "DragEnter", QEvent::DragEnter },
|
||||
{ "DragLeave", QEvent::DragLeave },
|
||||
{ "DragMove", QEvent::DragMove },
|
||||
{ "Drop", QEvent::Drop },
|
||||
{ "DynamicPropertyChange", QEvent::DynamicPropertyChange },
|
||||
{ "EnabledChange", QEvent::EnabledChange },
|
||||
{ "Enter", QEvent::Enter },
|
||||
{ "EnterWhatsThisMode", QEvent::EnterWhatsThisMode },
|
||||
{ "Expose", QEvent::Expose },
|
||||
{ "FileOpen", QEvent::FileOpen },
|
||||
{ "FocusIn", QEvent::FocusIn },
|
||||
{ "FocusOut", QEvent::FocusOut },
|
||||
{ "FocusAboutToChange", QEvent::FocusAboutToChange },
|
||||
{ "FontChange", QEvent::FontChange },
|
||||
{ "Gesture", QEvent::Gesture },
|
||||
{ "GestureOverride", QEvent::GestureOverride },
|
||||
{ "GrabKeyboard", QEvent::GrabKeyboard },
|
||||
{ "GrabMouse", QEvent::GrabMouse },
|
||||
{ "GraphicsSceneContextMenu", QEvent::GraphicsSceneContextMenu },
|
||||
{ "GraphicsSceneDragEnter", QEvent::GraphicsSceneDragEnter },
|
||||
{ "GraphicsSceneDragLeave", QEvent::GraphicsSceneDragLeave },
|
||||
{ "GraphicsSceneDragMove", QEvent::GraphicsSceneDragMove },
|
||||
{ "GraphicsSceneDrop", QEvent::GraphicsSceneDrop },
|
||||
{ "GraphicsSceneHelp", QEvent::GraphicsSceneHelp },
|
||||
{ "GraphicsSceneHoverEnter", QEvent::GraphicsSceneHoverEnter },
|
||||
{ "GraphicsSceneHoverLeave", QEvent::GraphicsSceneHoverLeave },
|
||||
{ "GraphicsSceneHoverMove", QEvent::GraphicsSceneHoverMove },
|
||||
{ "GraphicsSceneMouseDoubleClick", QEvent::GraphicsSceneMouseDoubleClick },
|
||||
{ "GraphicsSceneMouseMove", QEvent::GraphicsSceneMouseMove },
|
||||
{ "GraphicsSceneMousePress", QEvent::GraphicsSceneMousePress },
|
||||
{ "GraphicsSceneMouseRelease", QEvent::GraphicsSceneMouseRelease },
|
||||
{ "GraphicsSceneMove", QEvent::GraphicsSceneMove },
|
||||
{ "GraphicsSceneResize", QEvent::GraphicsSceneResize },
|
||||
{ "GraphicsSceneWheel", QEvent::GraphicsSceneWheel },
|
||||
{ "Hide", QEvent::Hide },
|
||||
{ "HideToParent", QEvent::HideToParent },
|
||||
{ "HoverEnter", QEvent::HoverEnter },
|
||||
{ "HoverLeave", QEvent::HoverLeave },
|
||||
{ "HoverMove", QEvent::HoverMove },
|
||||
{ "IconDrag", QEvent::IconDrag },
|
||||
{ "IconTextChange", QEvent::IconTextChange },
|
||||
{ "InputMethod", QEvent::InputMethod },
|
||||
{ "InputMethodQuery", QEvent::InputMethodQuery },
|
||||
{ "KeyboardLayoutChange", QEvent::KeyboardLayoutChange },
|
||||
{ "KeyPress", QEvent::KeyPress },
|
||||
{ "KeyRelease", QEvent::KeyRelease },
|
||||
{ "LanguageChange", QEvent::LanguageChange },
|
||||
{ "LayoutDirectionChange", QEvent::LayoutDirectionChange },
|
||||
{ "LayoutRequest", QEvent::LayoutRequest },
|
||||
{ "Leave", QEvent::Leave },
|
||||
{ "LeaveWhatsThisMode", QEvent::LeaveWhatsThisMode },
|
||||
{ "LocaleChange", QEvent::LocaleChange },
|
||||
{ "NonClientAreaMouseButtonDblClick", QEvent::NonClientAreaMouseButtonDblClick },
|
||||
{ "NonClientAreaMouseButtonPress", QEvent::NonClientAreaMouseButtonPress },
|
||||
{ "NonClientAreaMouseButtonRelease", QEvent::NonClientAreaMouseButtonRelease },
|
||||
{ "NonClientAreaMouseMove", QEvent::NonClientAreaMouseMove },
|
||||
{ "MacSizeChange", QEvent::MacSizeChange },
|
||||
{ "MetaCall", QEvent::MetaCall },
|
||||
{ "ModifiedChange", QEvent::ModifiedChange },
|
||||
{ "MouseButtonDblClick", QEvent::MouseButtonDblClick },
|
||||
{ "MouseButtonPress", QEvent::MouseButtonPress },
|
||||
{ "MouseButtonRelease", QEvent::MouseButtonRelease },
|
||||
{ "MouseMove", QEvent::MouseMove },
|
||||
{ "MouseTrackingChange", QEvent::MouseTrackingChange },
|
||||
{ "Move", QEvent::Move },
|
||||
{ "NativeGesture", QEvent::NativeGesture },
|
||||
{ "OrientationChange", QEvent::OrientationChange },
|
||||
{ "Paint", QEvent::Paint },
|
||||
{ "PaletteChange", QEvent::PaletteChange },
|
||||
{ "ParentAboutToChange", QEvent::ParentAboutToChange },
|
||||
{ "ParentChange", QEvent::ParentChange },
|
||||
{ "PlatformPanel", QEvent::PlatformPanel },
|
||||
{ "PlatformSurface", QEvent::PlatformSurface },
|
||||
{ "Polish", QEvent::Polish },
|
||||
{ "PolishRequest", QEvent::PolishRequest },
|
||||
{ "QueryWhatsThis", QEvent::QueryWhatsThis },
|
||||
{ "ReadOnlyChange", QEvent::ReadOnlyChange },
|
||||
{ "RequestSoftwareInputPanel", QEvent::RequestSoftwareInputPanel },
|
||||
{ "Resize", QEvent::Resize },
|
||||
{ "ScrollPrepare", QEvent::ScrollPrepare },
|
||||
{ "Scroll", QEvent::Scroll },
|
||||
{ "Shortcut", QEvent::Shortcut },
|
||||
{ "ShortcutOverride", QEvent::ShortcutOverride },
|
||||
{ "Show", QEvent::Show },
|
||||
{ "ShowToParent", QEvent::ShowToParent },
|
||||
{ "SockAct", QEvent::SockAct },
|
||||
{ "StateMachineSignal", QEvent::StateMachineSignal },
|
||||
{ "StateMachineWrapped", QEvent::StateMachineWrapped },
|
||||
{ "StatusTip", QEvent::StatusTip },
|
||||
{ "StyleChange", QEvent::StyleChange },
|
||||
{ "TabletMove", QEvent::TabletMove },
|
||||
{ "TabletPress", QEvent::TabletPress },
|
||||
{ "TabletRelease", QEvent::TabletRelease },
|
||||
{ "TabletEnterProximity", QEvent::TabletEnterProximity },
|
||||
{ "TabletLeaveProximity", QEvent::TabletLeaveProximity },
|
||||
{ "TabletTrackingChange", QEvent::TabletTrackingChange },
|
||||
{ "ThreadChange", QEvent::ThreadChange },
|
||||
{ "Timer", QEvent::Timer },
|
||||
{ "ToolBarChange", QEvent::ToolBarChange },
|
||||
{ "ToolTip", QEvent::ToolTip },
|
||||
{ "ToolTipChange", QEvent::ToolTipChange },
|
||||
{ "TouchBegin", QEvent::TouchBegin },
|
||||
{ "TouchCancel", QEvent::TouchCancel },
|
||||
{ "TouchEnd", QEvent::TouchEnd },
|
||||
{ "TouchUpdate", QEvent::TouchUpdate },
|
||||
{ "UngrabKeyboard", QEvent::UngrabKeyboard },
|
||||
{ "UngrabMouse", QEvent::UngrabMouse },
|
||||
{ "UpdateLater", QEvent::UpdateLater },
|
||||
{ "UpdateRequest", QEvent::UpdateRequest },
|
||||
{ "WhatsThis", QEvent::WhatsThis },
|
||||
{ "WhatsThisClicked", QEvent::WhatsThisClicked },
|
||||
{ "Wheel", QEvent::Wheel },
|
||||
{ "WinEventAct", QEvent::WinEventAct },
|
||||
{ "WindowActivate", QEvent::WindowActivate },
|
||||
{ "WindowBlocked", QEvent::WindowBlocked },
|
||||
{ "WindowDeactivate", QEvent::WindowDeactivate },
|
||||
{ "WindowIconChange", QEvent::WindowIconChange },
|
||||
{ "WindowStateChange", QEvent::WindowStateChange },
|
||||
{ "WindowTitleChange", QEvent::WindowTitleChange },
|
||||
{ "WindowUnblocked", QEvent::WindowUnblocked },
|
||||
{ "WinIdChange", QEvent::WinIdChange },
|
||||
{ "ZOrderChange", QEvent::ZOrderChange },
|
||||
};
|
||||
@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
#include <unordered_map>
|
||||
#include <QEvent>
|
||||
|
||||
class EventsMap {
|
||||
public:
|
||||
static std::unordered_map<std::string, int> events;
|
||||
};
|
||||
36
src/cpp/core/Events/eventwidget.cpp
Normal file
36
src/cpp/core/Events/eventwidget.cpp
Normal file
@ -0,0 +1,36 @@
|
||||
#include "eventwidget.h"
|
||||
#include "deps/spdlog/spdlog.h"
|
||||
|
||||
void EventWidget::subscribeToEvent(std::string evtString){
|
||||
try {
|
||||
int evtType = EventsMap::events.at(evtString);
|
||||
this->subscribedEvents.insert({static_cast<QEvent::Type>(evtType), evtString});
|
||||
} catch (...) {
|
||||
spdlog::info("EventWidget: Couldn't subscribe to qt event {}. If this is a signal you can safely ignore this warning", evtString.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void EventWidget::event(QEvent* event){
|
||||
if(this->emitOnNode){
|
||||
try {
|
||||
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) };
|
||||
});
|
||||
} catch (...) {
|
||||
// Do nothing
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EventWidget::connectWidgetSignalsToEventEmitter(){
|
||||
// Do nothing
|
||||
// This method should be overriden in sub classes to connect all signals to event emiiter of node. See Push button
|
||||
}
|
||||
|
||||
EventWidget::~EventWidget(){
|
||||
if(this->emitOnNode){
|
||||
this->emitOnNode.release();
|
||||
}
|
||||
}
|
||||
19
src/cpp/core/Events/eventwidget.h
Normal file
19
src/cpp/core/Events/eventwidget.h
Normal file
@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include <QEvent>
|
||||
#include <napi-thread-safe-callback.hpp>
|
||||
#include "src/cpp/core/Events/eventsmap.h"
|
||||
|
||||
class EventWidget {
|
||||
public:
|
||||
std::unique_ptr<ThreadSafeCallback> emitOnNode = nullptr;
|
||||
std::unordered_map<QEvent::Type, std::string> subscribedEvents;
|
||||
|
||||
void subscribeToEvent(std::string evtString);
|
||||
|
||||
void event(QEvent* event);
|
||||
|
||||
void connectWidgetSignalsToEventEmitter();
|
||||
|
||||
~EventWidget();
|
||||
};
|
||||
38
src/cpp/core/Events/eventwidget_macro.h
Normal file
38
src/cpp/core/Events/eventwidget_macro.h
Normal file
@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
|
||||
#include "eventwidget.h"
|
||||
|
||||
/*
|
||||
|
||||
This macro adds common YogaWidget's exported methods
|
||||
The exported methods are taken into this macro to avoid writing them in each and every widget we export.
|
||||
*/
|
||||
|
||||
#ifndef EVENTWIDGET_WRAPPED_METHODS_DECLARATION
|
||||
#define EVENTWIDGET_WRAPPED_METHODS_DECLARATION \
|
||||
\
|
||||
Napi::Value initNodeEventEmitter(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
this->instance->emitOnNode = std::make_unique<ThreadSafeCallback>(info[0].As<Napi::Function>()); \
|
||||
this->instance->connectWidgetSignalsToEventEmitter(); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
\
|
||||
Napi::Value subscribeToQtEvent(const Napi::CallbackInfo& info){ \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::String eventString = info[0].As<Napi::String>(); \
|
||||
this->instance->subscribeToEvent(eventString.Utf8Value()); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
|
||||
#endif //EVENTWIDGET_WRAPPED_METHODS_DECLARATION
|
||||
|
||||
#ifndef EVENTWIDGET_WRAPPED_METHODS_EXPORT_DEFINE
|
||||
#define EVENTWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(WidgetWrapName) \
|
||||
\
|
||||
InstanceMethod("initNodeEventEmitter",&WidgetWrapName::initNodeEventEmitter), \
|
||||
InstanceMethod("subscribeToQtEvent",&WidgetWrapName::subscribeToQtEvent), \
|
||||
|
||||
|
||||
#endif // EVENTWIDGET_WRAPPED_METHODS_EXPORT_DEFINE
|
||||
|
||||
25
src/cpp/core/NodeWidget/nodewidget.h
Normal file
25
src/cpp/core/NodeWidget/nodewidget.h
Normal file
@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
#include "src/cpp/core/YogaWidget/yogawidget.h"
|
||||
#include "src/cpp/core/Events/eventwidget.h"
|
||||
|
||||
// class to unify all the custom features + add extra features if needed
|
||||
class NodeWidget : public YogaWidget, public EventWidget {
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#ifndef NODEWIDGET_IMPLEMENTATIONS
|
||||
#define NODEWIDGET_IMPLEMENTATIONS \
|
||||
\
|
||||
Q_OBJECT \
|
||||
public: \
|
||||
SET_YOGA_WIDGET_Q_PROPERTIES \
|
||||
bool event(QEvent* event) { \
|
||||
EventWidget::event(event); \
|
||||
return QWidget::event(event); \
|
||||
} \
|
||||
|
||||
#endif //NODEWIDGET_IMPLEMENTATIONS
|
||||
|
||||
|
||||
@ -11,7 +11,6 @@
|
||||
|
||||
*/
|
||||
|
||||
|
||||
struct NodeValueUnit{
|
||||
YGUnit unit;
|
||||
float value;
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
import addon from "../../core/addon";
|
||||
import { YogaWidget } from "../../core/YogaWidget";
|
||||
import { NodeLayout } from "../../QtWidgets/QLayout";
|
||||
import { EventWidget } from "../../core/EventWidget";
|
||||
|
||||
// All Widgets should extend from NodeWidget
|
||||
// Implement all native QWidget methods here so that all widgets get access to those aswell
|
||||
export abstract class NodeWidget extends YogaWidget {
|
||||
export abstract class NodeWidget extends EventWidget {
|
||||
type = "widget";
|
||||
layout?: NodeLayout;
|
||||
show = () => {
|
||||
@ -34,12 +34,14 @@ export abstract class NodeWidget extends YogaWidget {
|
||||
export class QWidget extends NodeWidget {
|
||||
native: any;
|
||||
constructor(parent?: QWidget) {
|
||||
super();
|
||||
let native;
|
||||
if (parent) {
|
||||
this.native = new addon.QWidget(parent.native);
|
||||
this.parent = parent;
|
||||
native = new addon.QWidget(parent.native);
|
||||
} else {
|
||||
this.native = new addon.QWidget();
|
||||
native = new addon.QWidget();
|
||||
}
|
||||
super(native);
|
||||
this.parent = parent;
|
||||
this.native = native;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,17 +1,27 @@
|
||||
import addon from "../../core/addon";
|
||||
import { NodeWidget } from "../../QtGui/QWidget";
|
||||
import { BaseWidgetEvents } from "../../core/EventWidget";
|
||||
|
||||
export const QCheckBoxEvents = Object.freeze({
|
||||
...BaseWidgetEvents
|
||||
});
|
||||
export class QCheckBox extends NodeWidget {
|
||||
native: any;
|
||||
constructor(parent?: NodeWidget) {
|
||||
super();
|
||||
let native;
|
||||
if (parent) {
|
||||
this.native = new addon.QCheckBox(parent.native);
|
||||
this.parent = parent;
|
||||
native = new addon.QCheckBox(parent.native);
|
||||
} else {
|
||||
this.native = new addon.QCheckBox();
|
||||
native = new addon.QCheckBox();
|
||||
}
|
||||
super(native);
|
||||
this.native = native;
|
||||
this.parent = parent;
|
||||
// bind member functions
|
||||
this.setText.bind(this);
|
||||
}
|
||||
setText = (text: string) => {
|
||||
|
||||
setText(text: string) {
|
||||
this.native.setText(text);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,24 +1,34 @@
|
||||
import addon from "../../core/addon";
|
||||
import { NodeWidget } from "../../QtGui/QWidget";
|
||||
import { BaseWidgetEvents } from "../../core/EventWidget";
|
||||
|
||||
export const QLabelEvents = Object.freeze({
|
||||
...BaseWidgetEvents
|
||||
});
|
||||
export class QLabel extends NodeWidget {
|
||||
native: any;
|
||||
constructor(parent?: NodeWidget) {
|
||||
super();
|
||||
let native;
|
||||
if (parent) {
|
||||
this.native = new addon.QLabel(parent.native);
|
||||
this.parent = parent;
|
||||
native = new addon.QLabel(parent.native);
|
||||
} else {
|
||||
this.native = new addon.QLabel();
|
||||
native = new addon.QLabel();
|
||||
}
|
||||
super(native);
|
||||
this.native = native;
|
||||
this.parent = parent;
|
||||
// bind member functions
|
||||
this.setWordWrap.bind(this);
|
||||
this.setText.bind(this);
|
||||
this.text.bind(this);
|
||||
}
|
||||
setWordWrap = (on: boolean) => {
|
||||
setWordWrap(on: boolean) {
|
||||
this.native.setWordWrap(on);
|
||||
};
|
||||
setText = (text: string | number) => {
|
||||
}
|
||||
setText(text: string | number) {
|
||||
this.native.setText(`${text}`);
|
||||
};
|
||||
text = () => {
|
||||
}
|
||||
text() {
|
||||
return this.native.text();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,15 +1,22 @@
|
||||
import addon from "../../core/addon";
|
||||
import { NodeWidget } from "../../QtGui/QWidget";
|
||||
import { BaseWidgetEvents } from "../../core/EventWidget";
|
||||
|
||||
export const QLineEditEvents = Object.freeze({
|
||||
...BaseWidgetEvents
|
||||
});
|
||||
export class QLineEdit extends NodeWidget {
|
||||
native: any;
|
||||
constructor(parent?: NodeWidget) {
|
||||
super();
|
||||
let native;
|
||||
if (parent) {
|
||||
this.native = new addon.QLineEdit(parent.native);
|
||||
this.parent = parent;
|
||||
native = new addon.QLineEdit(parent.native);
|
||||
} else {
|
||||
this.native = new addon.QLineEdit();
|
||||
native = new addon.QLineEdit();
|
||||
}
|
||||
super(native);
|
||||
this.native = native;
|
||||
this.parent = parent;
|
||||
// bind member functions
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,28 +1,39 @@
|
||||
import addon from "../../core/addon";
|
||||
import { NodeWidget } from "../../QtGui/QWidget";
|
||||
import { FlexNode } from "../../core/FlexLayout/FlexNode";
|
||||
import { BaseWidgetEvents } from "../../core/EventWidget";
|
||||
|
||||
export const QMainWindowEvents = Object.freeze({
|
||||
...BaseWidgetEvents
|
||||
});
|
||||
export class QMainWindow extends NodeWidget {
|
||||
native: any;
|
||||
protected centralWidget?: NodeWidget;
|
||||
protected centralWidgetFlexNode?: FlexNode;
|
||||
constructor(parent?: NodeWidget) {
|
||||
super();
|
||||
let native;
|
||||
if (parent) {
|
||||
this.native = new addon.QMainWindow(parent.native);
|
||||
this.parent = parent;
|
||||
native = new addon.QMainWindow(parent.native);
|
||||
} else {
|
||||
this.native = new addon.QMainWindow();
|
||||
native = new addon.QMainWindow();
|
||||
}
|
||||
super(native);
|
||||
this.native = native;
|
||||
this.parent = parent;
|
||||
// bind member functions
|
||||
this.setCentralWidget.bind(this);
|
||||
this.setFixedSize.bind(this);
|
||||
}
|
||||
setCentralWidget = (widget: NodeWidget) => {
|
||||
|
||||
setCentralWidget(widget: NodeWidget) {
|
||||
this.centralWidgetFlexNode = widget.getFlexNode();
|
||||
this.centralWidget = widget;
|
||||
this.native.setCentralWidget(
|
||||
this.centralWidget.native,
|
||||
this.centralWidgetFlexNode.native
|
||||
);
|
||||
};
|
||||
setFixedSize = (width: number, height: number) => {
|
||||
}
|
||||
setFixedSize(width: number, height: number) {
|
||||
this.native.setFixedSize(width, height);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,15 +1,22 @@
|
||||
import addon from "../../core/addon";
|
||||
import { NodeWidget } from "../../QtGui/QWidget";
|
||||
import { BaseWidgetEvents } from "../../core/EventWidget";
|
||||
|
||||
export const QProgressBarEvents = Object.freeze({
|
||||
...BaseWidgetEvents
|
||||
});
|
||||
export class QProgressBar extends NodeWidget {
|
||||
native: any;
|
||||
constructor(parent?: NodeWidget) {
|
||||
super();
|
||||
let native;
|
||||
if (parent) {
|
||||
this.native = new addon.QProgressBar(parent.native);
|
||||
this.parent = parent;
|
||||
native = new addon.QProgressBar(parent.native);
|
||||
} else {
|
||||
this.native = new addon.QProgressBar();
|
||||
native = new addon.QProgressBar();
|
||||
}
|
||||
super(native);
|
||||
this.native = native;
|
||||
this.parent = parent;
|
||||
// bind member functions
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,15 +1,16 @@
|
||||
import addon from "../../core/addon";
|
||||
import { NodeWidget } from "../../QtGui/QWidget";
|
||||
import { SignalNodeWidget } from "../../core/SignalNodeWidget";
|
||||
import { BaseWidgetEvents } from "../../core/EventWidget";
|
||||
|
||||
export enum QPushButtonSignal {
|
||||
clicked = "clicked",
|
||||
pressed = "pressed",
|
||||
released = "released",
|
||||
toggled = "toggled"
|
||||
}
|
||||
export const QPushButtonEvents = Object.freeze({
|
||||
...BaseWidgetEvents,
|
||||
clicked: "clicked",
|
||||
pressed: "pressed",
|
||||
released: "released",
|
||||
toggled: "toggled"
|
||||
});
|
||||
|
||||
export class QPushButton extends SignalNodeWidget {
|
||||
export class QPushButton extends NodeWidget {
|
||||
native: any;
|
||||
constructor(parent?: NodeWidget) {
|
||||
let native;
|
||||
@ -21,6 +22,7 @@ export class QPushButton extends SignalNodeWidget {
|
||||
super(native);
|
||||
this.parent = parent;
|
||||
this.native = native;
|
||||
// bind member functions
|
||||
this.setText.bind(this);
|
||||
}
|
||||
|
||||
|
||||
@ -1,15 +1,22 @@
|
||||
import addon from "../../core/addon";
|
||||
import { NodeWidget } from "../../QtGui/QWidget";
|
||||
import { BaseWidgetEvents } from "../../core/EventWidget";
|
||||
|
||||
export const QRadioButtonEvents = Object.freeze({
|
||||
...BaseWidgetEvents
|
||||
});
|
||||
export class QRadioButton extends NodeWidget {
|
||||
native: any;
|
||||
constructor(parent?: NodeWidget) {
|
||||
super();
|
||||
let native;
|
||||
if (parent) {
|
||||
this.native = new addon.QRadioButton(parent.native);
|
||||
this.parent = parent;
|
||||
native = new addon.QRadioButton(parent.native);
|
||||
} else {
|
||||
this.native = new addon.QRadioButton();
|
||||
native = new addon.QRadioButton();
|
||||
}
|
||||
super(native);
|
||||
this.native = native;
|
||||
this.parent = parent;
|
||||
// bind member functions
|
||||
}
|
||||
}
|
||||
|
||||
168
src/lib/core/EventWidget/index.ts
Normal file
168
src/lib/core/EventWidget/index.ts
Normal file
@ -0,0 +1,168 @@
|
||||
import { EventEmitter } from "events";
|
||||
import { YogaWidget } from "../YogaWidget";
|
||||
|
||||
export abstract class EventWidget extends YogaWidget {
|
||||
private emitter: EventEmitter;
|
||||
constructor(native: any) {
|
||||
super();
|
||||
if (native.initNodeEventEmitter) {
|
||||
this.emitter = new EventEmitter();
|
||||
native.initNodeEventEmitter(this.emitter.emit.bind(this.emitter));
|
||||
} else {
|
||||
throw new Error("initNodeEventEmitter not implemented on native side");
|
||||
}
|
||||
}
|
||||
|
||||
addEventListener = (eventType: string, callback: (payload?: any) => void) => {
|
||||
this.native.subscribeToQtEvent(eventType);
|
||||
this.emitter.on(eventType, callback);
|
||||
};
|
||||
}
|
||||
|
||||
export const BaseWidgetEvents = Object.freeze({
|
||||
None: "None",
|
||||
ActionAdded: "ActionAdded",
|
||||
ActionChanged: "ActionChanged",
|
||||
ActionRemoved: "ActionRemoved",
|
||||
ActivationChange: "ActivationChange",
|
||||
ApplicationActivate: "ApplicationActivate",
|
||||
ApplicationActivated: "ApplicationActivated",
|
||||
ApplicationDeactivate: "ApplicationDeactivate",
|
||||
ApplicationFontChange: "ApplicationFontChange",
|
||||
ApplicationLayoutDirectionChange: "ApplicationLayoutDirectionChange",
|
||||
ApplicationPaletteChange: "ApplicationPaletteChange",
|
||||
ApplicationStateChange: "ApplicationStateChange",
|
||||
ApplicationWindowIconChange: "ApplicationWindowIconChange",
|
||||
ChildAdded: "ChildAdded",
|
||||
ChildPolished: "ChildPolished",
|
||||
ChildRemoved: "ChildRemoved",
|
||||
Clipboard: "Clipboard",
|
||||
Close: "Close",
|
||||
CloseSoftwareInputPanel: "CloseSoftwareInputPanel",
|
||||
ContentsRectChange: "ContentsRectChange",
|
||||
ContextMenu: "ContextMenu",
|
||||
CursorChange: "CursorChange",
|
||||
DeferredDelete: "DeferredDelete",
|
||||
DragEnter: "DragEnter",
|
||||
DragLeave: "DragLeave",
|
||||
DragMove: "DragMove",
|
||||
Drop: "Drop",
|
||||
DynamicPropertyChange: "DynamicPropertyChange",
|
||||
EnabledChange: "EnabledChange",
|
||||
Enter: "Enter",
|
||||
EnterWhatsThisMode: "EnterWhatsThisMode",
|
||||
Expose: "Expose",
|
||||
FileOpen: "FileOpen",
|
||||
FocusIn: "FocusIn",
|
||||
FocusOut: "FocusOut",
|
||||
FocusAboutToChange: "FocusAboutToChange",
|
||||
FontChange: "FontChange",
|
||||
Gesture: "Gesture",
|
||||
GestureOverride: "GestureOverride",
|
||||
GrabKeyboard: "GrabKeyboard",
|
||||
GrabMouse: "GrabMouse",
|
||||
GraphicsSceneContextMenu: "GraphicsSceneContextMenu",
|
||||
GraphicsSceneDragEnter: "GraphicsSceneDragEnter",
|
||||
GraphicsSceneDragLeave: "GraphicsSceneDragLeave",
|
||||
GraphicsSceneDragMove: "GraphicsSceneDragMove",
|
||||
GraphicsSceneDrop: "GraphicsSceneDrop",
|
||||
GraphicsSceneHelp: "GraphicsSceneHelp",
|
||||
GraphicsSceneHoverEnter: "GraphicsSceneHoverEnter",
|
||||
GraphicsSceneHoverLeave: "GraphicsSceneHoverLeave",
|
||||
GraphicsSceneHoverMove: "GraphicsSceneHoverMove",
|
||||
GraphicsSceneMouseDoubleClick: "GraphicsSceneMouseDoubleClick",
|
||||
GraphicsSceneMouseMove: "GraphicsSceneMouseMove",
|
||||
GraphicsSceneMousePress: "GraphicsSceneMousePress",
|
||||
GraphicsSceneMouseRelease: "GraphicsSceneMouseRelease",
|
||||
GraphicsSceneMove: "GraphicsSceneMove",
|
||||
GraphicsSceneResize: "GraphicsSceneResize",
|
||||
GraphicsSceneWheel: "GraphicsSceneWheel",
|
||||
Hide: "Hide",
|
||||
HideToParent: "HideToParent",
|
||||
HoverEnter: "HoverEnter",
|
||||
HoverLeave: "HoverLeave",
|
||||
HoverMove: "HoverMove",
|
||||
IconDrag: "IconDrag",
|
||||
IconTextChange: "IconTextChange",
|
||||
InputMethod: "InputMethod",
|
||||
InputMethodQuery: "InputMethodQuery",
|
||||
KeyboardLayoutChange: "KeyboardLayoutChange",
|
||||
KeyPress: "KeyPress",
|
||||
KeyRelease: "KeyRelease",
|
||||
LanguageChange: "LanguageChange",
|
||||
LayoutDirectionChange: "LayoutDirectionChange",
|
||||
LayoutRequest: "LayoutRequest",
|
||||
Leave: "Leave",
|
||||
LeaveWhatsThisMode: "LeaveWhatsThisMode",
|
||||
LocaleChange: "LocaleChange",
|
||||
NonClientAreaMouseButtonDblClick: "NonClientAreaMouseButtonDblClick",
|
||||
NonClientAreaMouseButtonPress: "NonClientAreaMouseButtonPress",
|
||||
NonClientAreaMouseButtonRelease: "NonClientAreaMouseButtonRelease",
|
||||
NonClientAreaMouseMove: "NonClientAreaMouseMove",
|
||||
MacSizeChange: "MacSizeChange",
|
||||
MetaCall: "MetaCall",
|
||||
ModifiedChange: "ModifiedChange",
|
||||
MouseButtonDblClick: "MouseButtonDblClick",
|
||||
MouseButtonPress: "MouseButtonPress",
|
||||
MouseButtonRelease: "MouseButtonRelease",
|
||||
MouseMove: "MouseMove",
|
||||
MouseTrackingChange: "MouseTrackingChange",
|
||||
Move: "Move",
|
||||
NativeGesture: "NativeGesture",
|
||||
OrientationChange: "OrientationChange",
|
||||
Paint: "Paint",
|
||||
PaletteChange: "PaletteChange",
|
||||
ParentAboutToChange: "ParentAboutToChange",
|
||||
ParentChange: "ParentChange",
|
||||
PlatformPanel: "PlatformPanel",
|
||||
PlatformSurface: "PlatformSurface",
|
||||
Polish: "Polish",
|
||||
PolishRequest: "PolishRequest",
|
||||
QueryWhatsThis: "QueryWhatsThis",
|
||||
ReadOnlyChange: "ReadOnlyChange",
|
||||
RequestSoftwareInputPanel: "RequestSoftwareInputPanel",
|
||||
Resize: "Resize",
|
||||
ScrollPrepare: "ScrollPrepare",
|
||||
Scroll: "Scroll",
|
||||
Shortcut: "Shortcut",
|
||||
ShortcutOverride: "ShortcutOverride",
|
||||
Show: "Show",
|
||||
ShowToParent: "ShowToParent",
|
||||
SockAct: "SockAct",
|
||||
StateMachineSignal: "StateMachineSignal",
|
||||
StateMachineWrapped: "StateMachineWrapped",
|
||||
StatusTip: "StatusTip",
|
||||
StyleChange: "StyleChange",
|
||||
TabletMove: "TabletMove",
|
||||
TabletPress: "TabletPress",
|
||||
TabletRelease: "TabletRelease",
|
||||
TabletEnterProximity: "TabletEnterProximity",
|
||||
TabletLeaveProximity: "TabletLeaveProximity",
|
||||
TabletTrackingChange: "TabletTrackingChange",
|
||||
ThreadChange: "ThreadChange",
|
||||
Timer: "Timer",
|
||||
ToolBarChange: "ToolBarChange",
|
||||
ToolTip: "ToolTip",
|
||||
ToolTipChange: "ToolTipChange",
|
||||
TouchBegin: "TouchBegin",
|
||||
TouchCancel: "TouchCancel",
|
||||
TouchEnd: "TouchEnd",
|
||||
TouchUpdate: "TouchUpdate",
|
||||
UngrabKeyboard: "UngrabKeyboard",
|
||||
UngrabMouse: "UngrabMouse",
|
||||
UpdateLater: "UpdateLater",
|
||||
UpdateRequest: "UpdateRequest",
|
||||
WhatsThis: "WhatsThis",
|
||||
WhatsThisClicked: "WhatsThisClicked",
|
||||
Wheel: "Wheel",
|
||||
WinEventAct: "WinEventAct",
|
||||
WindowActivate: "WindowActivate",
|
||||
WindowBlocked: "WindowBlocked",
|
||||
WindowDeactivate: "WindowDeactivate",
|
||||
WindowIconChange: "WindowIconChange",
|
||||
WindowStateChange: "WindowStateChange",
|
||||
WindowTitleChange: "WindowTitleChange",
|
||||
WindowUnblocked: "WindowUnblocked",
|
||||
WinIdChange: "WinIdChange",
|
||||
ZOrderChange: "ZOrderChange"
|
||||
});
|
||||
@ -1,22 +0,0 @@
|
||||
import { NodeWidget } from "../../QtGui/QWidget";
|
||||
import { EventEmitter } from "events";
|
||||
|
||||
export abstract class SignalNodeWidget extends NodeWidget {
|
||||
private emitter: EventEmitter;
|
||||
constructor(native: any) {
|
||||
super();
|
||||
if (native.setupSignalListeners) {
|
||||
this.emitter = new EventEmitter();
|
||||
native.setupSignalListeners(this.emitter.emit.bind(this.emitter));
|
||||
} else {
|
||||
throw new Error("Signal Listeners not implemented on native side");
|
||||
}
|
||||
}
|
||||
|
||||
setSignalListener = (
|
||||
signalType: string,
|
||||
callback: (payload?: any) => void
|
||||
) => {
|
||||
this.emitter.on(signalType, callback);
|
||||
};
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user