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
|
# 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
|
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
|
#pragma once
|
||||||
#define QWIDGET_MACRO_H
|
|
||||||
|
|
||||||
#include "src/cpp/QtWidgets/QLayout/qlayout_wrap.h"
|
#include "src/cpp/QtWidgets/QLayout/qlayout_wrap.h"
|
||||||
|
#include "src/cpp/core/YogaWidget/yogawidget_macro.h"
|
||||||
/*
|
/*
|
||||||
|
|
||||||
This macro adds common QWidgets exported methods
|
This macro adds common QWidgets exported methods
|
||||||
@ -12,6 +11,8 @@
|
|||||||
#ifndef QWIDGET_WRAPPED_METHODS_DECLARATION
|
#ifndef QWIDGET_WRAPPED_METHODS_DECLARATION
|
||||||
#define QWIDGET_WRAPPED_METHODS_DECLARATION \
|
#define QWIDGET_WRAPPED_METHODS_DECLARATION \
|
||||||
\
|
\
|
||||||
|
YOGAWIDGET_WRAPPED_METHODS_DECLARATION \
|
||||||
|
\
|
||||||
Napi::Value show(const Napi::CallbackInfo& info) { \
|
Napi::Value show(const Napi::CallbackInfo& info) { \
|
||||||
Napi::Env env = info.Env(); \
|
Napi::Env env = info.Env(); \
|
||||||
Napi::HandleScope scope(env); \
|
Napi::HandleScope scope(env); \
|
||||||
@ -73,6 +74,7 @@ Napi::Value setObjectName(const Napi::CallbackInfo& info){ \
|
|||||||
#ifndef QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE
|
#ifndef QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE
|
||||||
#define QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(WidgetWrapName) \
|
#define QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(WidgetWrapName) \
|
||||||
\
|
\
|
||||||
|
YOGAWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(WidgetWrapName) \
|
||||||
InstanceMethod("show", &WidgetWrapName::show), \
|
InstanceMethod("show", &WidgetWrapName::show), \
|
||||||
InstanceMethod("resize",&WidgetWrapName::resize), \
|
InstanceMethod("resize",&WidgetWrapName::resize), \
|
||||||
InstanceMethod("close",&WidgetWrapName::close), \
|
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";
|
char CLASSNAME[] = "QWidget";
|
||||||
Napi::Function func = DefineClass(env, CLASSNAME, {
|
Napi::Function func = DefineClass(env, CLASSNAME, {
|
||||||
QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QWidgetWrap)
|
QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QWidgetWrap)
|
||||||
YOGAWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QWidgetWrap)
|
|
||||||
});
|
});
|
||||||
constructor = Napi::Persistent(func);
|
constructor = Napi::Persistent(func);
|
||||||
exports.Set(CLASSNAME, func);
|
exports.Set(CLASSNAME, func);
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "src/cpp/QtGui/QWidget/qwidget_macro.h"
|
#include "src/cpp/QtGui/QWidget/qwidget_macro.h"
|
||||||
#include "src/cpp/core/YogaWidget/yogawidget_macro.h"
|
|
||||||
#include <napi.h>
|
#include <napi.h>
|
||||||
#include "nwidget.h"
|
#include "nwidget.h"
|
||||||
|
|
||||||
@ -17,6 +17,5 @@ class QWidgetWrap : public Napi::ObjectWrap<QWidgetWrap>{
|
|||||||
static Napi::FunctionReference constructor;
|
static Napi::FunctionReference constructor;
|
||||||
//wrapped methods
|
//wrapped methods
|
||||||
QWIDGET_WRAPPED_METHODS_DECLARATION
|
QWIDGET_WRAPPED_METHODS_DECLARATION
|
||||||
YOGAWIDGET_WRAPPED_METHODS_DECLARATION
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
#include <napi.h>
|
#include <napi.h>
|
||||||
#include "ncheckbox.h"
|
#include "ncheckbox.h"
|
||||||
#include "src/cpp/QtGui/QWidget/qwidget_macro.h"
|
#include "src/cpp/QtGui/QWidget/qwidget_macro.h"
|
||||||
#include "src/cpp/core/YogaWidget/yogawidget_macro.h"
|
|
||||||
|
|
||||||
class QCheckBoxWrap : public Napi::ObjectWrap<QCheckBoxWrap>{
|
class QCheckBoxWrap : public Napi::ObjectWrap<QCheckBoxWrap>{
|
||||||
private:
|
private:
|
||||||
@ -19,6 +19,5 @@ class QCheckBoxWrap : public Napi::ObjectWrap<QCheckBoxWrap>{
|
|||||||
Napi::Value setText(const Napi::CallbackInfo& info);
|
Napi::Value setText(const Napi::CallbackInfo& info);
|
||||||
|
|
||||||
QWIDGET_WRAPPED_METHODS_DECLARATION
|
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("text", &QLabelWrap::text),
|
||||||
InstanceMethod("getFlexNode", &QLabelWrap::getFlexNode),
|
InstanceMethod("getFlexNode", &QLabelWrap::getFlexNode),
|
||||||
QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QLabelWrap)
|
QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QLabelWrap)
|
||||||
YOGAWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QLabelWrap)
|
|
||||||
});
|
});
|
||||||
constructor = Napi::Persistent(func);
|
constructor = Napi::Persistent(func);
|
||||||
exports.Set(CLASSNAME, func);
|
exports.Set(CLASSNAME, func);
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
#include <napi.h>
|
#include <napi.h>
|
||||||
#include "nlabel.h"
|
#include "nlabel.h"
|
||||||
#include "src/cpp/QtGui/QWidget/qwidget_macro.h"
|
#include "src/cpp/QtGui/QWidget/qwidget_macro.h"
|
||||||
#include "src/cpp/core/YogaWidget/yogawidget_macro.h"
|
|
||||||
|
|
||||||
class QLabelWrap : public Napi::ObjectWrap<QLabelWrap>{
|
class QLabelWrap : public Napi::ObjectWrap<QLabelWrap>{
|
||||||
private:
|
private:
|
||||||
@ -21,7 +21,6 @@ class QLabelWrap : public Napi::ObjectWrap<QLabelWrap>{
|
|||||||
Napi::Value text(const Napi::CallbackInfo &info);
|
Napi::Value text(const Napi::CallbackInfo &info);
|
||||||
|
|
||||||
QWIDGET_WRAPPED_METHODS_DECLARATION
|
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";
|
char CLASSNAME[] = "QLineEdit";
|
||||||
Napi::Function func = DefineClass(env, CLASSNAME, {
|
Napi::Function func = DefineClass(env, CLASSNAME, {
|
||||||
QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QLineEditWrap)
|
QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QLineEditWrap)
|
||||||
YOGAWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QLineEditWrap)
|
|
||||||
});
|
});
|
||||||
constructor = Napi::Persistent(func);
|
constructor = Napi::Persistent(func);
|
||||||
exports.Set(CLASSNAME, func);
|
exports.Set(CLASSNAME, func);
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
#include <napi.h>
|
#include <napi.h>
|
||||||
#include "nlineedit.h"
|
#include "nlineedit.h"
|
||||||
#include "src/cpp/QtGui/QWidget/qwidget_macro.h"
|
#include "src/cpp/QtGui/QWidget/qwidget_macro.h"
|
||||||
#include "src/cpp/core/YogaWidget/yogawidget_macro.h"
|
|
||||||
|
|
||||||
class QLineEditWrap : public Napi::ObjectWrap<QLineEditWrap>{
|
class QLineEditWrap : public Napi::ObjectWrap<QLineEditWrap>{
|
||||||
private:
|
private:
|
||||||
@ -18,7 +18,6 @@ class QLineEditWrap : public Napi::ObjectWrap<QLineEditWrap>{
|
|||||||
//wrapped methods
|
//wrapped methods
|
||||||
|
|
||||||
QWIDGET_WRAPPED_METHODS_DECLARATION
|
QWIDGET_WRAPPED_METHODS_DECLARATION
|
||||||
YOGAWIDGET_WRAPPED_METHODS_DECLARATION
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -9,28 +9,28 @@
|
|||||||
class NMainWindow: public QMainWindow, public YogaWidget
|
class NMainWindow: public QMainWindow, public YogaWidget
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
private:
|
||||||
SET_YOGA_WIDGET_Q_PROPERTIES
|
|
||||||
using QMainWindow::QMainWindow; //inherit all constructors of QMainWindow
|
|
||||||
|
|
||||||
void calculateLayout(){
|
void calculateLayout(){
|
||||||
YGDirection direction = YGNodeStyleGetDirection(this->getFlexNode());
|
YGDirection direction = YGNodeStyleGetDirection(this->getFlexNode());
|
||||||
YGNodeCalculateLayout(this->getFlexNode(),width(),height(),direction);
|
YGNodeCalculateLayout(this->getFlexNode(),width(),height(),direction);
|
||||||
}
|
}
|
||||||
|
bool eventFilter(QObject *object, QEvent *event) { // This will be installed on mainwidgetwrap
|
||||||
Q_OBJECT
|
switch(event->type()) {
|
||||||
public:
|
case QEvent::LayoutRequest:
|
||||||
bool eventFilter(QObject *object, QEvent *event)
|
case QEvent::ChildRemoved: {
|
||||||
{
|
calculateLayout(); break;
|
||||||
if (event->type() == QEvent::LayoutRequest || event->type() == QEvent::ChildRemoved) {
|
}
|
||||||
calculateLayout();
|
default: ; // do nothing
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
void resizeEvent(QResizeEvent * event){
|
void resizeEvent(QResizeEvent * event){
|
||||||
calculateLayout();
|
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";
|
char CLASSNAME[] = "QMainWindow";
|
||||||
Napi::Function func = DefineClass(env, CLASSNAME, {
|
Napi::Function func = DefineClass(env, CLASSNAME, {
|
||||||
QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QMainWindowWrap)
|
QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QMainWindowWrap)
|
||||||
YOGAWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QMainWindowWrap)
|
|
||||||
InstanceMethod("setCentralWidget",&QMainWindowWrap::setCentralWidget),
|
InstanceMethod("setCentralWidget",&QMainWindowWrap::setCentralWidget),
|
||||||
InstanceMethod("setFixedSize",&QMainWindowWrap::setFixedSize),
|
InstanceMethod("setFixedSize",&QMainWindowWrap::setFixedSize),
|
||||||
});
|
});
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
#include <napi.h>
|
#include <napi.h>
|
||||||
#include "nmainwindow.h"
|
#include "nmainwindow.h"
|
||||||
#include "src/cpp/QtGui/QWidget/qwidget_macro.h"
|
#include "src/cpp/QtGui/QWidget/qwidget_macro.h"
|
||||||
#include "src/cpp/core/YogaWidget/yogawidget_macro.h"
|
|
||||||
|
|
||||||
class QMainWindowWrap : public Napi::ObjectWrap<QMainWindowWrap>{
|
class QMainWindowWrap : public Napi::ObjectWrap<QMainWindowWrap>{
|
||||||
private:
|
private:
|
||||||
@ -21,6 +21,5 @@ public:
|
|||||||
Napi::Value setFixedSize(const Napi::CallbackInfo& info);
|
Napi::Value setFixedSize(const Napi::CallbackInfo& info);
|
||||||
|
|
||||||
QWIDGET_WRAPPED_METHODS_DECLARATION
|
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";
|
char CLASSNAME[] = "QProgressBar";
|
||||||
Napi::Function func = DefineClass(env, CLASSNAME, {
|
Napi::Function func = DefineClass(env, CLASSNAME, {
|
||||||
QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QProgressBarWrap)
|
QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QProgressBarWrap)
|
||||||
YOGAWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QProgressBarWrap)
|
|
||||||
});
|
});
|
||||||
constructor = Napi::Persistent(func);
|
constructor = Napi::Persistent(func);
|
||||||
exports.Set(CLASSNAME, func);
|
exports.Set(CLASSNAME, func);
|
||||||
|
|||||||
@ -3,7 +3,6 @@
|
|||||||
#include <napi.h>
|
#include <napi.h>
|
||||||
#include "nprogressbar.h"
|
#include "nprogressbar.h"
|
||||||
#include "src/cpp/QtGui/QWidget/qwidget_macro.h"
|
#include "src/cpp/QtGui/QWidget/qwidget_macro.h"
|
||||||
#include "src/cpp/core/YogaWidget/yogawidget_macro.h"
|
|
||||||
|
|
||||||
class QProgressBarWrap : public Napi::ObjectWrap<QProgressBarWrap>{
|
class QProgressBarWrap : public Napi::ObjectWrap<QProgressBarWrap>{
|
||||||
private:
|
private:
|
||||||
@ -18,7 +17,6 @@ class QProgressBarWrap : public Napi::ObjectWrap<QProgressBarWrap>{
|
|||||||
//wrapped methods
|
//wrapped methods
|
||||||
|
|
||||||
QWIDGET_WRAPPED_METHODS_DECLARATION
|
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("setText", &QPushButtonWrap::setText),
|
||||||
InstanceMethod("setupSignalListeners",&QPushButtonWrap::setupSignalListeners),
|
InstanceMethod("setupSignalListeners",&QPushButtonWrap::setupSignalListeners),
|
||||||
QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QPushButtonWrap)
|
QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QPushButtonWrap)
|
||||||
YOGAWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QPushButtonWrap)
|
|
||||||
});
|
});
|
||||||
constructor = Napi::Persistent(func);
|
constructor = Napi::Persistent(func);
|
||||||
exports.Set(CLASSNAME, func);
|
exports.Set(CLASSNAME, func);
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
#include <napi-thread-safe-callback.hpp>
|
#include <napi-thread-safe-callback.hpp>
|
||||||
#include "npushbutton.h"
|
#include "npushbutton.h"
|
||||||
#include "src/cpp/QtGui/QWidget/qwidget_macro.h"
|
#include "src/cpp/QtGui/QWidget/qwidget_macro.h"
|
||||||
#include "src/cpp/core/YogaWidget/yogawidget_macro.h"
|
|
||||||
#include "src/cpp/Extras/Utils/utils.h"
|
#include "src/cpp/Extras/Utils/utils.h"
|
||||||
|
|
||||||
class QPushButtonWrap : public Napi::ObjectWrap<QPushButtonWrap> {
|
class QPushButtonWrap : public Napi::ObjectWrap<QPushButtonWrap> {
|
||||||
@ -23,7 +23,6 @@ class QPushButtonWrap : public Napi::ObjectWrap<QPushButtonWrap> {
|
|||||||
Napi::Value setText(const Napi::CallbackInfo& info);
|
Napi::Value setText(const Napi::CallbackInfo& info);
|
||||||
|
|
||||||
QWIDGET_WRAPPED_METHODS_DECLARATION
|
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";
|
char CLASSNAME[] = "QRadioButton";
|
||||||
Napi::Function func = DefineClass(env, CLASSNAME, {
|
Napi::Function func = DefineClass(env, CLASSNAME, {
|
||||||
QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QRadioButtonWrap)
|
QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QRadioButtonWrap)
|
||||||
YOGAWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QRadioButtonWrap)
|
|
||||||
});
|
});
|
||||||
constructor = Napi::Persistent(func);
|
constructor = Napi::Persistent(func);
|
||||||
exports.Set(CLASSNAME, func);
|
exports.Set(CLASSNAME, func);
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
#include <napi.h>
|
#include <napi.h>
|
||||||
#include "nradiobutton.h"
|
#include "nradiobutton.h"
|
||||||
#include "src/cpp/QtGui/QWidget/qwidget_macro.h"
|
#include "src/cpp/QtGui/QWidget/qwidget_macro.h"
|
||||||
#include "src/cpp/core/YogaWidget/yogawidget_macro.h"
|
|
||||||
|
|
||||||
class QRadioButtonWrap : public Napi::ObjectWrap<QRadioButtonWrap>{
|
class QRadioButtonWrap : public Napi::ObjectWrap<QRadioButtonWrap>{
|
||||||
private:
|
private:
|
||||||
@ -18,8 +18,6 @@ class QRadioButtonWrap : public Napi::ObjectWrap<QRadioButtonWrap>{
|
|||||||
//wrapped methods
|
//wrapped methods
|
||||||
|
|
||||||
QWIDGET_WRAPPED_METHODS_DECLARATION
|
QWIDGET_WRAPPED_METHODS_DECLARATION
|
||||||
YOGAWIDGET_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
|
#pragma once
|
||||||
#define NODESTYLE_H
|
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
@ -43,4 +42,4 @@ static std::unordered_map<std::string, int> NodeWrap;
|
|||||||
static NodeValueUnit parseMeasurement(QString rawValue);
|
static NodeValueUnit parseMeasurement(QString rawValue);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // NODESTYLE_H
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user