diff --git a/config/application.gypi b/config/application.gypi index 4d8b95ca1..d3348c057 100644 --- a/config/application.gypi +++ b/config/application.gypi @@ -5,6 +5,7 @@ "targets": [ { "target_name": "qtnode", + 'include_dirs': ['<(module_root_dir)'], "sources": [ "../src/cpp/main.cpp", # non-wrapped cpps diff --git a/src/cpp/QtGui/QWidget/qwidget_macro.h b/src/cpp/QtGui/QWidget/qwidget_macro.h new file mode 100644 index 000000000..58bb41f4c --- /dev/null +++ b/src/cpp/QtGui/QWidget/qwidget_macro.h @@ -0,0 +1,58 @@ +#ifndef QWIDGET_MACRO_H +#define QWIDGET_MACRO_H + +#include "../../QtWidgets/QLayout/qlayout_wrap.h" + +#define QWIDGET_WRAPPED_METHODS_DECLARATION \ +\ +Napi::Value show(const Napi::CallbackInfo& info) { \ + Napi::Env env = info.Env(); \ + Napi::HandleScope scope(env); \ + this->instance->show(); \ + return env.Null(); \ +} \ +\ +Napi::Value resize(const Napi::CallbackInfo& info) { \ + Napi::Env env = info.Env(); \ + Napi::HandleScope scope(env); \ + Napi::Number width = info[0].As(); \ + Napi::Number height = info[1].As(); \ + this->instance->resize(width.Int32Value(), height.Int32Value()); \ + return env.Null(); \ +} \ +\ +Napi::Value close(const Napi::CallbackInfo& info) { \ + Napi::Env env = info.Env(); \ + Napi::HandleScope scope(env); \ + this->instance->close(); \ + return env.Null(); \ +} \ +\ +Napi::Value setLayout(const Napi::CallbackInfo& info){ \ + Napi::Env env = info.Env(); \ + Napi::HandleScope scope(env); \ + Napi::Object layoutObject = info[0].As(); \ + QLayoutWrap* layoutParent = Napi::ObjectWrap::Unwrap(layoutObject); \ + this->instance->setLayout(layoutParent->getInternalInstance()); \ + return env.Null(); \ +} \ +\ +Napi::Value setStyleSheet(const Napi::CallbackInfo& info) { \ + Napi::Env env = info.Env(); \ + Napi::HandleScope scope(env); \ + Napi::String text = info[0].As(); \ + std::string style = text.Utf8Value(); \ + this->instance->setStyleSheet(style.c_str()); \ + return env.Null(); \ +} + +#define QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(WidgetWrapName) \ +\ + InstanceMethod("show", &WidgetWrapName::show), \ + InstanceMethod("resize",&WidgetWrapName::resize), \ + InstanceMethod("close",&WidgetWrapName::close), \ + InstanceMethod("setLayout",&WidgetWrapName::setLayout), \ + InstanceMethod("setStyleSheet",&WidgetWrapName::setStyleSheet), \ + + +#endif \ No newline at end of file diff --git a/src/cpp/QtGui/QWidget/qwidget_wrap.cpp b/src/cpp/QtGui/QWidget/qwidget_wrap.cpp index 36776c017..94e1f428f 100644 --- a/src/cpp/QtGui/QWidget/qwidget_wrap.cpp +++ b/src/cpp/QtGui/QWidget/qwidget_wrap.cpp @@ -8,11 +8,7 @@ Napi::Object QWidgetWrap::init(Napi::Env env, Napi::Object exports) { Napi::HandleScope scope(env); char CLASSNAME[] = "QWidget"; Napi::Function func = DefineClass(env, CLASSNAME, { - InstanceMethod("show", &QWidgetWrap::show), - InstanceMethod("resize",&QWidgetWrap::resize), - InstanceMethod("close",&QWidgetWrap::close), - InstanceMethod("setLayout",&QWidgetWrap::setLayout), - InstanceMethod("setStyleSheet",&QWidgetWrap::setStyleSheet), + QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QWidgetWrap) }); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); @@ -46,54 +42,3 @@ QWidgetWrap::~QWidgetWrap() { delete this->instance; } -Napi::Value QWidgetWrap::show(const Napi::CallbackInfo& info) { - Napi::Env env = info.Env(); - Napi::HandleScope scope(env); - - this->instance->show(); - - return env.Null(); -} - -Napi::Value QWidgetWrap::resize(const Napi::CallbackInfo& info) { - Napi::Env env = info.Env(); - Napi::HandleScope scope(env); - - Napi::Number width = info[0].As(); - Napi::Number height = info[1].As(); - this->instance->resize(width.Int32Value(), height.Int32Value()); - - return env.Null(); -} - -Napi::Value QWidgetWrap::close(const Napi::CallbackInfo& info) { - Napi::Env env = info.Env(); - Napi::HandleScope scope(env); - - this->instance->close(); - - return env.Null(); -} - -Napi::Value QWidgetWrap::setLayout(const Napi::CallbackInfo& info){ - Napi::Env env = info.Env(); - Napi::HandleScope scope(env); - - Napi::Object layoutObject = info[0].As(); - QLayoutWrap* layoutParent = Napi::ObjectWrap::Unwrap(layoutObject); - this->instance->setLayout(layoutParent->getInternalInstance()); - - return env.Null(); -} - - -Napi::Value QWidgetWrap::setStyleSheet(const Napi::CallbackInfo& info) { - Napi::Env env = info.Env(); - Napi::HandleScope scope(env); - - Napi::String text = info[0].As(); - std::string style = text.Utf8Value(); - this->instance->setStyleSheet(style.c_str()); - - return env.Null(); -} diff --git a/src/cpp/QtGui/QWidget/qwidget_wrap.h b/src/cpp/QtGui/QWidget/qwidget_wrap.h index 23f7ac774..4454c97ab 100644 --- a/src/cpp/QtGui/QWidget/qwidget_wrap.h +++ b/src/cpp/QtGui/QWidget/qwidget_wrap.h @@ -1,6 +1,7 @@ #ifndef QWIDGET_WRAP_H #define QWIDGET_WRAP_H +#include "qwidget_macro.h" #include #include @@ -15,11 +16,7 @@ class QWidgetWrap : public Napi::ObjectWrap{ //class constructor static Napi::FunctionReference constructor; //wrapped methods - Napi::Value show(const Napi::CallbackInfo& info); - Napi::Value resize(const Napi::CallbackInfo& info); - Napi::Value close(const Napi::CallbackInfo& info); - Napi::Value setLayout(const Napi::CallbackInfo& info); - Napi::Value setStyleSheet(const Napi::CallbackInfo& info); + QWIDGET_WRAPPED_METHODS_DECLARATION }; #endif \ No newline at end of file diff --git a/src/cpp/QtWidgets/QLabel/qlabel_wrap.cpp b/src/cpp/QtWidgets/QLabel/qlabel_wrap.cpp index f831f09e0..f85b91a40 100644 --- a/src/cpp/QtWidgets/QLabel/qlabel_wrap.cpp +++ b/src/cpp/QtWidgets/QLabel/qlabel_wrap.cpp @@ -12,7 +12,7 @@ Napi::Object QLabelWrap::init(Napi::Env env, Napi::Object exports) { Napi::Function func = DefineClass(env, CLASSNAME, { InstanceMethod("setWordWrap", &QLabelWrap::setWordWrap), InstanceMethod("setText", &QLabelWrap::setText), - InstanceMethod("setStyleSheet", &QLabelWrap::setStyleSheet) + QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QLabelWrap) }); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); @@ -67,13 +67,3 @@ Napi::Value QLabelWrap::setText(const Napi::CallbackInfo& info) { return env.Null(); } -Napi::Value QLabelWrap::setStyleSheet(const Napi::CallbackInfo& info) { - Napi::Env env = info.Env(); - Napi::HandleScope scope(env); - - Napi::String text = info[0].As(); - std::string style = text.Utf8Value(); - this->instance->setStyleSheet(style.c_str()); - - return env.Null(); -} diff --git a/src/cpp/QtWidgets/QLabel/qlabel_wrap.h b/src/cpp/QtWidgets/QLabel/qlabel_wrap.h index 04f53918c..93a33fd98 100644 --- a/src/cpp/QtWidgets/QLabel/qlabel_wrap.h +++ b/src/cpp/QtWidgets/QLabel/qlabel_wrap.h @@ -2,6 +2,7 @@ #define QLABEL_WRAP_H #include #include +#include "src/cpp/QtGui/QWidget/qwidget_macro.h" class QLabelWrap : public Napi::ObjectWrap{ private: @@ -16,7 +17,8 @@ class QLabelWrap : public Napi::ObjectWrap{ //wrapped methods Napi::Value setWordWrap(const Napi::CallbackInfo& info); Napi::Value setText(const Napi::CallbackInfo& info); - Napi::Value setStyleSheet(const Napi::CallbackInfo& info); + + QWIDGET_WRAPPED_METHODS_DECLARATION }; #endif \ No newline at end of file diff --git a/src/cpp/QtWidgets/QMainWindow/qmainwindow_wrap.cpp b/src/cpp/QtWidgets/QMainWindow/qmainwindow_wrap.cpp index 1c17dec98..839b6d36e 100644 --- a/src/cpp/QtWidgets/QMainWindow/qmainwindow_wrap.cpp +++ b/src/cpp/QtWidgets/QMainWindow/qmainwindow_wrap.cpp @@ -8,10 +8,7 @@ Napi::Object QMainWindowWrap::init(Napi::Env env, Napi::Object exports) { Napi::HandleScope scope(env); char CLASSNAME[] = "QMainWindow"; Napi::Function func = DefineClass(env, CLASSNAME, { - InstanceMethod("setStyleSheet", &QMainWindowWrap::setStyleSheet), - InstanceMethod("show", &QMainWindowWrap::show), - InstanceMethod("resize",&QMainWindowWrap::resize), - InstanceMethod("close",&QMainWindowWrap::close), + QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QMainWindowWrap) InstanceMethod("setCentralWidget",&QMainWindowWrap::setCentralWidget), }); constructor = Napi::Persistent(func); @@ -46,46 +43,6 @@ QMainWindowWrap::~QMainWindowWrap() { delete this->instance; } -Napi::Value QMainWindowWrap::setStyleSheet(const Napi::CallbackInfo& info) { - Napi::Env env = info.Env(); - Napi::HandleScope scope(env); - - Napi::String text = info[0].As(); - std::string style = text.Utf8Value(); - this->instance->setStyleSheet(style.c_str()); - - return env.Null(); -} - -Napi::Value QMainWindowWrap::show(const Napi::CallbackInfo& info) { - Napi::Env env = info.Env(); - Napi::HandleScope scope(env); - - this->instance->show(); - - return env.Null(); -} - -Napi::Value QMainWindowWrap::resize(const Napi::CallbackInfo& info) { - Napi::Env env = info.Env(); - Napi::HandleScope scope(env); - - Napi::Number width = info[0].As(); - Napi::Number height = info[1].As(); - this->instance->resize(width.Int32Value(), height.Int32Value()); - - return env.Null(); -} - -Napi::Value QMainWindowWrap::close(const Napi::CallbackInfo& info) { - Napi::Env env = info.Env(); - Napi::HandleScope scope(env); - - this->instance->close(); - - return env.Null(); -} - Napi::Value QMainWindowWrap::setCentralWidget(const Napi::CallbackInfo& info){ Napi::Env env = info.Env(); Napi::HandleScope scope(env); diff --git a/src/cpp/QtWidgets/QMainWindow/qmainwindow_wrap.h b/src/cpp/QtWidgets/QMainWindow/qmainwindow_wrap.h index 19b609ee5..fddd6c32d 100644 --- a/src/cpp/QtWidgets/QMainWindow/qmainwindow_wrap.h +++ b/src/cpp/QtWidgets/QMainWindow/qmainwindow_wrap.h @@ -3,6 +3,7 @@ #include #include +#include "src/cpp/QtGui/QWidget/qwidget_macro.h" class QMainWindowWrap : public Napi::ObjectWrap{ private: @@ -16,11 +17,9 @@ public: //class constructor static Napi::FunctionReference constructor; //wrapped methods - Napi::Value setStyleSheet(const Napi::CallbackInfo& info); - Napi::Value show(const Napi::CallbackInfo& info); - Napi::Value resize(const Napi::CallbackInfo& info); - Napi::Value close(const Napi::CallbackInfo& info); Napi::Value setCentralWidget(const Napi::CallbackInfo& info); + + QWIDGET_WRAPPED_METHODS_DECLARATION }; #endif \ No newline at end of file diff --git a/src/cpp/QtWidgets/QPushButton/qpushbutton_wrap.cpp b/src/cpp/QtWidgets/QPushButton/qpushbutton_wrap.cpp index f8fbb3106..4e5a2cde8 100644 --- a/src/cpp/QtWidgets/QPushButton/qpushbutton_wrap.cpp +++ b/src/cpp/QtWidgets/QPushButton/qpushbutton_wrap.cpp @@ -8,8 +8,8 @@ Napi::Object QPushButtonWrap::init(Napi::Env env, Napi::Object exports) { Napi::HandleScope scope(env); char CLASSNAME[] = "QPushButton"; Napi::Function func = DefineClass(env, CLASSNAME, { - InstanceMethod("setStyleSheet", &QPushButtonWrap::setStyleSheet), InstanceMethod("setText", &QPushButtonWrap::setText), + QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QPushButtonWrap) }); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); @@ -43,17 +43,6 @@ QPushButtonWrap::~QPushButtonWrap() { delete this->instance; } -Napi::Value QPushButtonWrap::setStyleSheet(const Napi::CallbackInfo& info) { - Napi::Env env = info.Env(); - Napi::HandleScope scope(env); - - Napi::String text = info[0].As(); - std::string style = text.Utf8Value(); - this->instance->setStyleSheet(style.c_str()); - // this->instance->repaint(); - - return env.Null(); -} Napi::Value QPushButtonWrap::setText(const Napi::CallbackInfo& info) { Napi::Env env = info.Env(); diff --git a/src/cpp/QtWidgets/QPushButton/qpushbutton_wrap.h b/src/cpp/QtWidgets/QPushButton/qpushbutton_wrap.h index 30ef79802..f4c6513c0 100644 --- a/src/cpp/QtWidgets/QPushButton/qpushbutton_wrap.h +++ b/src/cpp/QtWidgets/QPushButton/qpushbutton_wrap.h @@ -2,6 +2,7 @@ #define QPUSHBUTTON_WRAP_H #include #include +#include "src/cpp/QtGui/QWidget/qwidget_macro.h" class QPushButtonWrap : public Napi::ObjectWrap { private: @@ -14,9 +15,10 @@ class QPushButtonWrap : public Napi::ObjectWrap { //class constructor static Napi::FunctionReference constructor; //wrapped methods - Napi::Value setStyleSheet(const Napi::CallbackInfo& info); Napi::Value setText(const Napi::CallbackInfo& info); Napi::Value setEventListener(const Napi::CallbackInfo& info); + + QWIDGET_WRAPPED_METHODS_DECLARATION }; #endif diff --git a/src/cpp/core/FlexLayout/flexItem.cpp b/src/cpp/core/FlexLayout/flexItem.cpp new file mode 100644 index 000000000..524a6d96e --- /dev/null +++ b/src/cpp/core/FlexLayout/flexItem.cpp @@ -0,0 +1,6 @@ +#include "flexitem.h" + +FlexItem::FlexItem() +{ + +} diff --git a/src/cpp/core/FlexLayout/flexItem.h b/src/cpp/core/FlexLayout/flexItem.h new file mode 100644 index 000000000..070a3a4ec --- /dev/null +++ b/src/cpp/core/FlexLayout/flexItem.h @@ -0,0 +1,11 @@ +#ifndef FLEXITEM_H +#define FLEXITEM_H + + +class FlexItem +{ +public: + FlexItem(); +}; + +#endif // FLEXITEM_H