not needed to include yogawidget macro separately.
This commit is contained in:
parent
7a39ee0fd3
commit
3fe22cdc12
@ -1,3 +1,10 @@
|
||||
In Qt you can respond to an external event like a key press via event handling. Events always are processed by the event loop. Alongside events Qt also has a concept of Signals/Slots. Signals and slots are used to primarily communicate between widgets (more precisely QObjects). So the most common way of interacting between Qt Widgets is done through signals/slots. (More details here: https://doc.qt.io/qt-5/signalsandslots.html). Hence we would be implementing support for both events and signals.
|
||||
|
||||
**Technicals:**
|
||||
|
||||
> An event is a message encapsulated in a class (QEvent) which is processed in an event loop and dispatched to a recipient that can either accept the message or pass it along to others to process. They are usually created in response to external system events like mouse clicks.
|
||||
> Signals and Slots are a convenient way for QObjects to communicate with one another and are more similar to callback functions. In most circumstances, when a "signal" is emitted, any slot function connected to it is called directly. The exception is when signals and slots cross thread boundaries. In this case, the signal will essentially be converted into an event.
|
||||
|
||||
# Implementing Signal handling
|
||||
|
||||
In Qt signals and slots are used to communicate between different qt widgets. So they can be used to implement things like
|
||||
@ -1,8 +1,7 @@
|
||||
#ifndef QWIDGET_MACRO_H
|
||||
#define QWIDGET_MACRO_H
|
||||
#pragma once
|
||||
|
||||
#include "src/cpp/QtWidgets/QLayout/qlayout_wrap.h"
|
||||
|
||||
#include "src/cpp/core/YogaWidget/yogawidget_macro.h"
|
||||
/*
|
||||
|
||||
This macro adds common QWidgets exported methods
|
||||
@ -12,6 +11,8 @@
|
||||
#ifndef QWIDGET_WRAPPED_METHODS_DECLARATION
|
||||
#define QWIDGET_WRAPPED_METHODS_DECLARATION \
|
||||
\
|
||||
YOGAWIDGET_WRAPPED_METHODS_DECLARATION \
|
||||
\
|
||||
Napi::Value show(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
@ -73,6 +74,7 @@ Napi::Value setObjectName(const Napi::CallbackInfo& info){ \
|
||||
#ifndef QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE
|
||||
#define QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(WidgetWrapName) \
|
||||
\
|
||||
YOGAWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(WidgetWrapName) \
|
||||
InstanceMethod("show", &WidgetWrapName::show), \
|
||||
InstanceMethod("resize",&WidgetWrapName::resize), \
|
||||
InstanceMethod("close",&WidgetWrapName::close), \
|
||||
@ -86,4 +88,3 @@ Napi::Value setObjectName(const Napi::CallbackInfo& info){ \
|
||||
|
||||
|
||||
|
||||
#endif // QWIDGET_MACRO_H
|
||||
@ -9,7 +9,6 @@ Napi::Object QWidgetWrap::init(Napi::Env env, Napi::Object exports) {
|
||||
char CLASSNAME[] = "QWidget";
|
||||
Napi::Function func = DefineClass(env, CLASSNAME, {
|
||||
QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QWidgetWrap)
|
||||
YOGAWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QWidgetWrap)
|
||||
});
|
||||
constructor = Napi::Persistent(func);
|
||||
exports.Set(CLASSNAME, func);
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "src/cpp/QtGui/QWidget/qwidget_macro.h"
|
||||
#include "src/cpp/core/YogaWidget/yogawidget_macro.h"
|
||||
|
||||
#include <napi.h>
|
||||
#include "nwidget.h"
|
||||
|
||||
@ -17,6 +17,5 @@ class QWidgetWrap : public Napi::ObjectWrap<QWidgetWrap>{
|
||||
static Napi::FunctionReference constructor;
|
||||
//wrapped methods
|
||||
QWIDGET_WRAPPED_METHODS_DECLARATION
|
||||
YOGAWIDGET_WRAPPED_METHODS_DECLARATION
|
||||
};
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
#include <napi.h>
|
||||
#include "ncheckbox.h"
|
||||
#include "src/cpp/QtGui/QWidget/qwidget_macro.h"
|
||||
#include "src/cpp/core/YogaWidget/yogawidget_macro.h"
|
||||
|
||||
|
||||
class QCheckBoxWrap : public Napi::ObjectWrap<QCheckBoxWrap>{
|
||||
private:
|
||||
@ -19,6 +19,5 @@ class QCheckBoxWrap : public Napi::ObjectWrap<QCheckBoxWrap>{
|
||||
Napi::Value setText(const Napi::CallbackInfo& info);
|
||||
|
||||
QWIDGET_WRAPPED_METHODS_DECLARATION
|
||||
YOGAWIDGET_WRAPPED_METHODS_DECLARATION
|
||||
};
|
||||
|
||||
|
||||
@ -15,7 +15,6 @@ Napi::Object QLabelWrap::init(Napi::Env env, Napi::Object exports) {
|
||||
InstanceMethod("text", &QLabelWrap::text),
|
||||
InstanceMethod("getFlexNode", &QLabelWrap::getFlexNode),
|
||||
QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QLabelWrap)
|
||||
YOGAWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QLabelWrap)
|
||||
});
|
||||
constructor = Napi::Persistent(func);
|
||||
exports.Set(CLASSNAME, func);
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
#include <napi.h>
|
||||
#include "nlabel.h"
|
||||
#include "src/cpp/QtGui/QWidget/qwidget_macro.h"
|
||||
#include "src/cpp/core/YogaWidget/yogawidget_macro.h"
|
||||
|
||||
|
||||
class QLabelWrap : public Napi::ObjectWrap<QLabelWrap>{
|
||||
private:
|
||||
@ -21,7 +21,6 @@ class QLabelWrap : public Napi::ObjectWrap<QLabelWrap>{
|
||||
Napi::Value text(const Napi::CallbackInfo &info);
|
||||
|
||||
QWIDGET_WRAPPED_METHODS_DECLARATION
|
||||
YOGAWIDGET_WRAPPED_METHODS_DECLARATION
|
||||
|
||||
};
|
||||
|
||||
|
||||
@ -12,7 +12,6 @@ Napi::Object QLineEditWrap::init(Napi::Env env, Napi::Object exports) {
|
||||
char CLASSNAME[] = "QLineEdit";
|
||||
Napi::Function func = DefineClass(env, CLASSNAME, {
|
||||
QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QLineEditWrap)
|
||||
YOGAWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QLineEditWrap)
|
||||
});
|
||||
constructor = Napi::Persistent(func);
|
||||
exports.Set(CLASSNAME, func);
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
#include <napi.h>
|
||||
#include "nlineedit.h"
|
||||
#include "src/cpp/QtGui/QWidget/qwidget_macro.h"
|
||||
#include "src/cpp/core/YogaWidget/yogawidget_macro.h"
|
||||
|
||||
|
||||
class QLineEditWrap : public Napi::ObjectWrap<QLineEditWrap>{
|
||||
private:
|
||||
@ -18,7 +18,6 @@ class QLineEditWrap : public Napi::ObjectWrap<QLineEditWrap>{
|
||||
//wrapped methods
|
||||
|
||||
QWIDGET_WRAPPED_METHODS_DECLARATION
|
||||
YOGAWIDGET_WRAPPED_METHODS_DECLARATION
|
||||
|
||||
};
|
||||
|
||||
|
||||
@ -9,28 +9,28 @@
|
||||
class NMainWindow: public QMainWindow, public YogaWidget
|
||||
{
|
||||
|
||||
public:
|
||||
SET_YOGA_WIDGET_Q_PROPERTIES
|
||||
using QMainWindow::QMainWindow; //inherit all constructors of QMainWindow
|
||||
|
||||
private:
|
||||
void calculateLayout(){
|
||||
YGDirection direction = YGNodeStyleGetDirection(this->getFlexNode());
|
||||
YGNodeCalculateLayout(this->getFlexNode(),width(),height(),direction);
|
||||
}
|
||||
|
||||
Q_OBJECT
|
||||
public:
|
||||
bool eventFilter(QObject *object, QEvent *event)
|
||||
{
|
||||
if (event->type() == QEvent::LayoutRequest || event->type() == QEvent::ChildRemoved) {
|
||||
calculateLayout();
|
||||
bool eventFilter(QObject *object, QEvent *event) { // This will be installed on mainwidgetwrap
|
||||
switch(event->type()) {
|
||||
case QEvent::LayoutRequest:
|
||||
case QEvent::ChildRemoved: {
|
||||
calculateLayout(); break;
|
||||
}
|
||||
default: ; // do nothing
|
||||
}
|
||||
return false;
|
||||
}
|
||||
void resizeEvent(QResizeEvent * event){
|
||||
calculateLayout();
|
||||
}
|
||||
|
||||
public:
|
||||
SET_YOGA_WIDGET_Q_PROPERTIES
|
||||
using QMainWindow::QMainWindow; //inherit all constructors of QMainWindow
|
||||
Q_OBJECT
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -9,7 +9,6 @@ Napi::Object QMainWindowWrap::init(Napi::Env env, Napi::Object exports) {
|
||||
char CLASSNAME[] = "QMainWindow";
|
||||
Napi::Function func = DefineClass(env, CLASSNAME, {
|
||||
QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QMainWindowWrap)
|
||||
YOGAWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QMainWindowWrap)
|
||||
InstanceMethod("setCentralWidget",&QMainWindowWrap::setCentralWidget),
|
||||
InstanceMethod("setFixedSize",&QMainWindowWrap::setFixedSize),
|
||||
});
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
#include <napi.h>
|
||||
#include "nmainwindow.h"
|
||||
#include "src/cpp/QtGui/QWidget/qwidget_macro.h"
|
||||
#include "src/cpp/core/YogaWidget/yogawidget_macro.h"
|
||||
|
||||
|
||||
class QMainWindowWrap : public Napi::ObjectWrap<QMainWindowWrap>{
|
||||
private:
|
||||
@ -21,6 +21,5 @@ public:
|
||||
Napi::Value setFixedSize(const Napi::CallbackInfo& info);
|
||||
|
||||
QWIDGET_WRAPPED_METHODS_DECLARATION
|
||||
YOGAWIDGET_WRAPPED_METHODS_DECLARATION
|
||||
};
|
||||
|
||||
|
||||
@ -12,7 +12,6 @@ Napi::Object QProgressBarWrap::init(Napi::Env env, Napi::Object exports) {
|
||||
char CLASSNAME[] = "QProgressBar";
|
||||
Napi::Function func = DefineClass(env, CLASSNAME, {
|
||||
QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QProgressBarWrap)
|
||||
YOGAWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QProgressBarWrap)
|
||||
});
|
||||
constructor = Napi::Persistent(func);
|
||||
exports.Set(CLASSNAME, func);
|
||||
|
||||
@ -3,7 +3,6 @@
|
||||
#include <napi.h>
|
||||
#include "nprogressbar.h"
|
||||
#include "src/cpp/QtGui/QWidget/qwidget_macro.h"
|
||||
#include "src/cpp/core/YogaWidget/yogawidget_macro.h"
|
||||
|
||||
class QProgressBarWrap : public Napi::ObjectWrap<QProgressBarWrap>{
|
||||
private:
|
||||
@ -18,7 +17,6 @@ class QProgressBarWrap : public Napi::ObjectWrap<QProgressBarWrap>{
|
||||
//wrapped methods
|
||||
|
||||
QWIDGET_WRAPPED_METHODS_DECLARATION
|
||||
YOGAWIDGET_WRAPPED_METHODS_DECLARATION
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -11,7 +11,6 @@ Napi::Object QPushButtonWrap::init(Napi::Env env, Napi::Object exports) {
|
||||
InstanceMethod("setText", &QPushButtonWrap::setText),
|
||||
InstanceMethod("setupSignalListeners",&QPushButtonWrap::setupSignalListeners),
|
||||
QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QPushButtonWrap)
|
||||
YOGAWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QPushButtonWrap)
|
||||
});
|
||||
constructor = Napi::Persistent(func);
|
||||
exports.Set(CLASSNAME, func);
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
#include <napi-thread-safe-callback.hpp>
|
||||
#include "npushbutton.h"
|
||||
#include "src/cpp/QtGui/QWidget/qwidget_macro.h"
|
||||
#include "src/cpp/core/YogaWidget/yogawidget_macro.h"
|
||||
|
||||
#include "src/cpp/Extras/Utils/utils.h"
|
||||
|
||||
class QPushButtonWrap : public Napi::ObjectWrap<QPushButtonWrap> {
|
||||
@ -23,7 +23,6 @@ class QPushButtonWrap : public Napi::ObjectWrap<QPushButtonWrap> {
|
||||
Napi::Value setText(const Napi::CallbackInfo& info);
|
||||
|
||||
QWIDGET_WRAPPED_METHODS_DECLARATION
|
||||
YOGAWIDGET_WRAPPED_METHODS_DECLARATION
|
||||
|
||||
};
|
||||
|
||||
|
||||
@ -12,7 +12,6 @@ Napi::Object QRadioButtonWrap::init(Napi::Env env, Napi::Object exports) {
|
||||
char CLASSNAME[] = "QRadioButton";
|
||||
Napi::Function func = DefineClass(env, CLASSNAME, {
|
||||
QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QRadioButtonWrap)
|
||||
YOGAWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QRadioButtonWrap)
|
||||
});
|
||||
constructor = Napi::Persistent(func);
|
||||
exports.Set(CLASSNAME, func);
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
#include <napi.h>
|
||||
#include "nradiobutton.h"
|
||||
#include "src/cpp/QtGui/QWidget/qwidget_macro.h"
|
||||
#include "src/cpp/core/YogaWidget/yogawidget_macro.h"
|
||||
|
||||
|
||||
class QRadioButtonWrap : public Napi::ObjectWrap<QRadioButtonWrap>{
|
||||
private:
|
||||
@ -17,9 +17,7 @@ class QRadioButtonWrap : public Napi::ObjectWrap<QRadioButtonWrap>{
|
||||
static Napi::FunctionReference constructor;
|
||||
//wrapped methods
|
||||
|
||||
QWIDGET_WRAPPED_METHODS_DECLARATION
|
||||
YOGAWIDGET_WRAPPED_METHODS_DECLARATION
|
||||
|
||||
QWIDGET_WRAPPED_METHODS_DECLARATION
|
||||
};
|
||||
|
||||
|
||||
0
src/cpp/core/Events/eventsmap.h
Normal file
0
src/cpp/core/Events/eventsmap.h
Normal file
@ -1,5 +1,4 @@
|
||||
#ifndef NODESTYLE_H
|
||||
#define NODESTYLE_H
|
||||
#pragma once
|
||||
|
||||
#include <QString>
|
||||
#include <unordered_map>
|
||||
@ -43,4 +42,4 @@ static std::unordered_map<std::string, int> NodeWrap;
|
||||
static NodeValueUnit parseMeasurement(QString rawValue);
|
||||
};
|
||||
|
||||
#endif // NODESTYLE_H
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user