diff --git a/config/application.gypi b/config/application.gypi index 032ffe23c..ee54b02dd 100644 --- a/config/application.gypi +++ b/config/application.gypi @@ -16,6 +16,7 @@ "../src/cpp/core/YogaWidget/yogawidget.cpp", # wrapped cpps "../src/cpp/QtGui/QApplication/qapplication_wrap.cpp", + "../src/cpp/QtGui/QWidget/nwidget.cpp", "../src/cpp/QtGui/QWidget/qwidget_wrap.cpp", '../src/cpp/core/FlexLayout/flexnode_wrap.cpp', '../src/cpp/core/FlexLayout/flexlayout_wrap.cpp', diff --git a/src/cpp/QtGui/QWidget/nwidget.cpp b/src/cpp/QtGui/QWidget/nwidget.cpp new file mode 100644 index 000000000..9ee4cc97f --- /dev/null +++ b/src/cpp/QtGui/QWidget/nwidget.cpp @@ -0,0 +1 @@ +#include "nwidget_moc.h" \ No newline at end of file diff --git a/src/cpp/QtGui/QWidget/nwidget.h b/src/cpp/QtGui/QWidget/nwidget.h new file mode 100644 index 000000000..3f34f299c --- /dev/null +++ b/src/cpp/QtGui/QWidget/nwidget.h @@ -0,0 +1,15 @@ +#pragma once +#include +#include +#include "src/cpp/core/YogaWidget/yogawidget.h" + +class NWidget: public QWidget, public YogaWidget +{ + +public: + using QWidget::QWidget; //inherit all constructors of QWidget + SET_YOGA_WIDGET_Q_PROPERTIES + Q_OBJECT +}; + + diff --git a/src/cpp/QtGui/QWidget/nwidget_moc.h b/src/cpp/QtGui/QWidget/nwidget_moc.h new file mode 100644 index 000000000..3fcd052e5 --- /dev/null +++ b/src/cpp/QtGui/QWidget/nwidget_moc.h @@ -0,0 +1,96 @@ +/**************************************************************************** +** Meta object code from reading C++ file 'nwidget.h' +** +** Created by: The Qt Meta Object Compiler version 67 (Qt 5.12.1) +** +** WARNING! All changes made in this file will be lost! +*****************************************************************************/ + +#include "nwidget.h" +#include +#include +#if !defined(Q_MOC_OUTPUT_REVISION) +#error "The header file 'nwidget.h' doesn't include ." +#elif Q_MOC_OUTPUT_REVISION != 67 +#error "This file was generated using the moc from 5.12.1. It" +#error "cannot be used with the include files from this version of Qt." +#error "(The moc has changed too much.)" +#endif + +QT_BEGIN_MOC_NAMESPACE +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED +struct qt_meta_stringdata_NWidget_t { + QByteArrayData data[1]; + char stringdata0[8]; +}; +#define QT_MOC_LITERAL(idx, ofs, len) \ + Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(len, \ + qptrdiff(offsetof(qt_meta_stringdata_NWidget_t, stringdata0) + ofs \ + - idx * sizeof(QByteArrayData)) \ + ) +static const qt_meta_stringdata_NWidget_t qt_meta_stringdata_NWidget = { + { +QT_MOC_LITERAL(0, 0, 7) // "NWidget" + + }, + "NWidget" +}; +#undef QT_MOC_LITERAL + +static const uint qt_meta_data_NWidget[] = { + + // content: + 8, // revision + 0, // classname + 0, 0, // classinfo + 0, 0, // methods + 0, 0, // properties + 0, 0, // enums/sets + 0, 0, // constructors + 0, // flags + 0, // signalCount + + 0 // eod +}; + +void NWidget::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a) +{ + Q_UNUSED(_o); + Q_UNUSED(_id); + Q_UNUSED(_c); + Q_UNUSED(_a); +} + +QT_INIT_METAOBJECT const QMetaObject NWidget::staticMetaObject = { { + &QWidget::staticMetaObject, + qt_meta_stringdata_NWidget.data, + qt_meta_data_NWidget, + qt_static_metacall, + nullptr, + nullptr +} }; + + +const QMetaObject *NWidget::metaObject() const +{ + return QObject::d_ptr->metaObject ? QObject::d_ptr->dynamicMetaObject() : &staticMetaObject; +} + +void *NWidget::qt_metacast(const char *_clname) +{ + if (!_clname) return nullptr; + if (!strcmp(_clname, qt_meta_stringdata_NWidget.stringdata0)) + return static_cast(this); + if (!strcmp(_clname, "YogaWidget")) + return static_cast< YogaWidget*>(this); + return QWidget::qt_metacast(_clname); +} + +int NWidget::qt_metacall(QMetaObject::Call _c, int _id, void **_a) +{ + _id = QWidget::qt_metacall(_c, _id, _a); + return _id; +} +QT_WARNING_POP +QT_END_MOC_NAMESPACE diff --git a/src/cpp/QtGui/QWidget/qwidget_macro.h b/src/cpp/QtGui/QWidget/qwidget_macro.h index fa82df0a4..50de0d723 100644 --- a/src/cpp/QtGui/QWidget/qwidget_macro.h +++ b/src/cpp/QtGui/QWidget/qwidget_macro.h @@ -3,6 +3,12 @@ #include "src/cpp/QtWidgets/QLayout/qlayout_wrap.h" +/* + + This macro adds common QWidgets exported methods + The exported methods are taken into this macro to avoid writing them in each and every widget we export. + */ + #ifndef QWIDGET_WRAPPED_METHODS_DECLARATION #define QWIDGET_WRAPPED_METHODS_DECLARATION \ \ diff --git a/src/cpp/QtGui/QWidget/qwidget_wrap.cpp b/src/cpp/QtGui/QWidget/qwidget_wrap.cpp index c7ed924d1..17206d4a7 100644 --- a/src/cpp/QtGui/QWidget/qwidget_wrap.cpp +++ b/src/cpp/QtGui/QWidget/qwidget_wrap.cpp @@ -9,13 +9,14 @@ 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); return exports; } -QWidget* QWidgetWrap::getInternalInstance() { +NWidget* QWidgetWrap::getInternalInstance() { return this->instance; } @@ -27,12 +28,12 @@ QWidgetWrap::QWidgetWrap(const Napi::CallbackInfo& info): Napi::ObjectWrap(); QWidgetWrap* w_parent = Napi::ObjectWrap::Unwrap(object_parent); - this->instance = new QWidget(w_parent->getInternalInstance()); //this sets the parent to current widget + this->instance = new NWidget(w_parent->getInternalInstance()); //this sets the parent to current widget }else{ extrautils::throwTypeError(env, "Wrong type of arguments"); } }else if (info.Length() == 0){ - this->instance = new QWidget(); + this->instance = new NWidget(); }else { extrautils::throwTypeError(env, "Wrong number of arguments"); } diff --git a/src/cpp/QtGui/QWidget/qwidget_wrap.h b/src/cpp/QtGui/QWidget/qwidget_wrap.h index 4454c97ab..b0758afac 100644 --- a/src/cpp/QtGui/QWidget/qwidget_wrap.h +++ b/src/cpp/QtGui/QWidget/qwidget_wrap.h @@ -1,22 +1,22 @@ -#ifndef QWIDGET_WRAP_H -#define QWIDGET_WRAP_H +#pragma once #include "qwidget_macro.h" +#include "src/cpp/core/YogaWidget/yogawidget_macro.h" #include -#include +#include "nwidget.h" class QWidgetWrap : public Napi::ObjectWrap{ private: - QWidget* instance; + NWidget* instance; public: static Napi::Object init(Napi::Env env, Napi::Object exports); QWidgetWrap(const Napi::CallbackInfo& info); ~QWidgetWrap(); - QWidget* getInternalInstance(); + NWidget* getInternalInstance(); //class constructor static Napi::FunctionReference constructor; //wrapped methods QWIDGET_WRAPPED_METHODS_DECLARATION + YOGAWIDGET_WRAPPED_METHODS_DECLARATION }; -#endif \ No newline at end of file diff --git a/src/cpp/QtWidgets/QLabel/nlabel.h b/src/cpp/QtWidgets/QLabel/nlabel.h index 6a70cbc80..3a3198fa8 100644 --- a/src/cpp/QtWidgets/QLabel/nlabel.h +++ b/src/cpp/QtWidgets/QLabel/nlabel.h @@ -1,5 +1,5 @@ -#ifndef N_LABEL_H -#define N_LABEL_H +#pragma once + #include #include #include "src/cpp/core/YogaWidget/yogawidget.h" @@ -14,4 +14,3 @@ public: }; -#endif // N_LABEL_H diff --git a/src/cpp/QtWidgets/QLabel/qlabel_wrap.cpp b/src/cpp/QtWidgets/QLabel/qlabel_wrap.cpp index 7877860a6..2495d86f1 100644 --- a/src/cpp/QtWidgets/QLabel/qlabel_wrap.cpp +++ b/src/cpp/QtWidgets/QLabel/qlabel_wrap.cpp @@ -15,6 +15,7 @@ Napi::Object QLabelWrap::init(Napi::Env env, Napi::Object exports) { InstanceMethod("setText", &QLabelWrap::setText), InstanceMethod("getFlexNode", &QLabelWrap::getFlexNode), QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QLabelWrap) + YOGAWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QLabelWrap) }); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); @@ -69,12 +70,3 @@ Napi::Value QLabelWrap::setText(const Napi::CallbackInfo& info) { return env.Null(); } - - Napi::Value QLabelWrap::getFlexNode(const Napi::CallbackInfo& info) { - Napi::EscapableHandleScope scope(info.Env()); - Napi::Value arg = info[0]; - Napi::Object flexNodeObject = FlexNodeWrap::constructor.New({ arg }); - FlexNodeWrap* flexNodeWrap = FlexNodeWrap::Unwrap(flexNodeObject); - flexNodeWrap->instance = this->instance->getFlexNode(); - return scope.Escape(napi_value(flexNodeObject)).ToObject(); - } diff --git a/src/cpp/QtWidgets/QLabel/qlabel_wrap.h b/src/cpp/QtWidgets/QLabel/qlabel_wrap.h index 5cee0f620..f348f32b6 100644 --- a/src/cpp/QtWidgets/QLabel/qlabel_wrap.h +++ b/src/cpp/QtWidgets/QLabel/qlabel_wrap.h @@ -1,8 +1,9 @@ -#ifndef QLABEL_WRAP_H -#define QLABEL_WRAP_H +#pragma once + #include #include "nlabel.h" #include "src/cpp/QtGui/QWidget/qwidget_macro.h" +#include "src/cpp/core/YogaWidget/yogawidget_macro.h" class QLabelWrap : public Napi::ObjectWrap{ private: @@ -17,9 +18,8 @@ class QLabelWrap : public Napi::ObjectWrap{ //wrapped methods Napi::Value setWordWrap(const Napi::CallbackInfo& info); Napi::Value setText(const Napi::CallbackInfo& info); - Napi::Value getFlexNode(const Napi::CallbackInfo& info); QWIDGET_WRAPPED_METHODS_DECLARATION + YOGAWIDGET_WRAPPED_METHODS_DECLARATION }; -#endif \ No newline at end of file diff --git a/src/cpp/core/YogaWidget/yogawidget_macro.h b/src/cpp/core/YogaWidget/yogawidget_macro.h new file mode 100644 index 000000000..e7935416b --- /dev/null +++ b/src/cpp/core/YogaWidget/yogawidget_macro.h @@ -0,0 +1,32 @@ +#pragma once + +#include "src/cpp/core/FlexLayout/flexnode_wrap.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 YOGAWIDGET_WRAPPED_METHODS_DECLARATION +#define YOGAWIDGET_WRAPPED_METHODS_DECLARATION \ +\ +Napi::Value getFlexNode(const Napi::CallbackInfo& info) {\ + Napi::EscapableHandleScope scope(info.Env());\ + Napi::Value arg = info[0];\ + Napi::Object flexNodeObject = FlexNodeWrap::constructor.New({ arg });\ + FlexNodeWrap* flexNodeWrap = FlexNodeWrap::Unwrap(flexNodeObject);\ + flexNodeWrap->instance = this->instance->getFlexNode();\ + return scope.Escape(napi_value(flexNodeObject)).ToObject();\ +}\ + +#endif //YOGAWIDGET_WRAPPED_METHODS_DECLARATION + +#ifndef YOGAWIDGET_WRAPPED_METHODS_EXPORT_DEFINE +#define YOGAWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(WidgetWrapName) \ +\ + InstanceMethod("getFlexNode", &WidgetWrapName::getFlexNode), \ + + +#endif // YOGAWIDGET_WRAPPED_METHODS_EXPORT_DEFINE +